Torque3D Documentation / _generateds / guiTabPageCtrl.cpp

guiTabPageCtrl.cpp

Engine/source/gui/controls/guiTabPageCtrl.cpp

More...

Public Functions

ConsoleDocClass(GuiTabPageCtrl , "@brief A single page in <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiTabBookCtrl.\n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n\n</a>" "<a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> <a href="/coding/class/classguitabpagectrl/">GuiTabPageCtrl</a>()\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "{\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "   fitBook = \"1\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "   //Properties not specific <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> this <a href="/coding/file/guieditctrl_8cpp/#guieditctrl_8cpp_1abb04e3738c4c5a96b3ade6fa47013a6c">control</a> have been omitted from this <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">example.\n</a>" "};\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" "@ingroup GuiContainers" )
DefineEngineMethod(GuiTabPageCtrl , select , void , () , "Select this page in its tab book." )

Detailed Description

Public Functions

ConsoleDocClass(GuiTabPageCtrl , "@brief A single page in <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiTabBookCtrl.\n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n\n</a>" "<a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> <a href="/coding/class/classguitabpagectrl/">GuiTabPageCtrl</a>()\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "{\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "   fitBook = \"1\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "   //Properties not specific <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> this <a href="/coding/file/guieditctrl_8cpp/#guieditctrl_8cpp_1abb04e3738c4c5a96b3ade6fa47013a6c">control</a> have been omitted from this <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">example.\n</a>" "};\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" "@ingroup GuiContainers" )

DefineEngineMethod(GuiTabPageCtrl , select , void , () , "Select this page in its tab book." )

IMPLEMENT_CONOBJECT(GuiTabPageCtrl )

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#include "console/consoleTypes.h"
 25#include "console/console.h"
 26#include "console/engineAPI.h"
 27#include "gfx/gfxDevice.h"
 28#include "gui/core/guiCanvas.h"
 29#include "gui/controls/guiTabPageCtrl.h"
 30#include "gui/containers/guiTabBookCtrl.h"
 31#include "gui/core/guiDefaultControlRender.h"
 32#include "gui/editor/guiEditCtrl.h"
 33
 34IMPLEMENT_CONOBJECT(GuiTabPageCtrl);
 35
 36ConsoleDocClass( GuiTabPageCtrl,
 37   "@brief A single page in a GuiTabBookCtrl.\n\n"
 38
 39   "@tsexample\n\n"
 40   "new GuiTabPageCtrl()\n"
 41   "{\n"
 42   "   fitBook = \"1\";\n"
 43   "   //Properties not specific to this control have been omitted from this example.\n"
 44   "};\n"
 45   "@endtsexample\n\n"
 46
 47   "@ingroup GuiContainers"
 48);
 49
 50GuiTabPageCtrl::GuiTabPageCtrl(void)
 51{
 52   setExtent(Point2I(100, 200));
 53   mFitBook = false;
 54   dStrcpy(mText,(UTF8*)"TabPage", MAX_STRING_LENGTH);
 55   mActive = true;
 56   mIsContainer = true;
 57   mTabIndex = -1;
 58}
 59
 60void GuiTabPageCtrl::initPersistFields()
 61{
 62   addField( "fitBook", TypeBool, Offset( mFitBook, GuiTabPageCtrl ),
 63      "Determines whether to resize this page when it is added to the tab book. "
 64      "If true, the page will be resized according to the tab book extents and "
 65      "<i>tabPosition</i> property." );
 66
 67   Parent::initPersistFields();
 68}
 69
 70bool GuiTabPageCtrl::onWake()
 71{
 72   if (! Parent::onWake())
 73      return false;
 74
 75   return true;
 76}
 77
 78void GuiTabPageCtrl::onSleep()
 79{
 80   Parent::onSleep();
 81}
 82
 83GuiControl* GuiTabPageCtrl::findHitControl(const Point2I &pt, S32 initialLayer)
 84{
 85   return Parent::findHitControl(pt, initialLayer);
 86}
 87
 88void GuiTabPageCtrl::onMouseDown(const GuiEvent &event)
 89{
 90   setUpdate();
 91   Point2I localPoint = globalToLocalCoord( event.mousePoint );
 92
 93   GuiControl *ctrl = findHitControl(localPoint);
 94   if (ctrl && ctrl != this)
 95   {
 96      ctrl->onMouseDown(event);
 97   }
 98}
 99
100bool GuiTabPageCtrl::onMouseDownEditor(const GuiEvent &event, Point2I offset )
101{
102#ifdef TORQUE_TOOLS
103   // This shouldn't be called if it's not design time, but check just incase
104   if ( GuiControl::smDesignTime )
105   {
106      GuiEditCtrl* edit = GuiControl::smEditorHandle;
107      if( edit )
108         edit->select( this );
109   }
110
111   return Parent::onMouseDownEditor( event, offset );
112#else
113   return false;
114#endif
115}
116
117
118GuiControl *GuiTabPageCtrl::findNextTabable(GuiControl *curResponder, bool firstCall)
119{
120   //set the global if this is the first call (directly from the canvas)
121   if (firstCall)
122   {
123      GuiControl::smCurResponder = NULL;
124   }
125
126   //if the window does not already contain the first responder, return false
127   //ie.  Can't tab into or out of a window
128   if (! controlIsChild(curResponder))
129   {
130      return NULL;
131   }
132
133   //loop through, checking each child to see if it is the one that follows the firstResponder
134   GuiControl *tabCtrl = NULL;
135   iterator i;
136   for (i = begin(); i != end(); i++)
137   {
138      GuiControl *ctrl = static_cast<GuiControl *>(*i);
139      tabCtrl = ctrl->findNextTabable(curResponder, false);
140      if (tabCtrl) break;
141   }
142
143   //to ensure the tab cycles within the current window...
144   if (! tabCtrl)
145   {
146      tabCtrl = findFirstTabable();
147   }
148
149   mFirstResponder = tabCtrl;
150   return tabCtrl;
151}
152
153GuiControl *GuiTabPageCtrl::findPrevTabable(GuiControl *curResponder, bool firstCall)
154{
155   if (firstCall)
156   {
157      GuiControl::smPrevResponder = NULL;
158   }
159
160   //if the window does not already contain the first responder, return false
161   //ie.  Can't tab into or out of a window
162   if (! controlIsChild(curResponder))
163   {
164      return NULL;
165   }
166
167   //loop through, checking each child to see if it is the one that follows the firstResponder
168   GuiControl *tabCtrl = NULL;
169   iterator i;
170   for (i = begin(); i != end(); i++)
171   {
172      GuiControl *ctrl = static_cast<GuiControl *>(*i);
173      tabCtrl = ctrl->findPrevTabable(curResponder, false);
174      if (tabCtrl) break;
175   }
176
177   //to ensure the tab cycles within the current window...
178   if (! tabCtrl)
179   {
180      tabCtrl = findLastTabable();
181   }
182
183   mFirstResponder = tabCtrl;
184   return tabCtrl;
185}
186
187void GuiTabPageCtrl::setText(const char *txt)
188{
189   Parent::setText( txt );
190
191   GuiControl *parent = getParent();
192   if( parent )
193      parent->setUpdate();
194};
195
196
197void GuiTabPageCtrl::selectWindow(void)
198{
199   //first make sure this window is the front most of its siblings
200   GuiControl *parent = getParent();
201   if (parent)
202   {
203      parent->pushObjectToBack(this);
204   }
205
206   //also set the first responder to be the one within this window
207   setFirstResponder(mFirstResponder);
208}
209
210void GuiTabPageCtrl::onRender(Point2I offset,const RectI &updateRect)
211{
212   // Call directly into GuiControl to skip the GuiTextCtrl parent render
213   GuiControl::onRender( offset, updateRect );
214}
215
216void GuiTabPageCtrl::inspectPostApply()
217{
218   Parent::inspectPostApply();
219   
220   if( mFitBook )
221   {
222      GuiTabBookCtrl* book = dynamic_cast< GuiTabBookCtrl* >( getParent() );
223      if( book )
224         book->fitPage( this );
225   }
226}
227
228DefineEngineMethod( GuiTabPageCtrl, select, void, (),,
229   "Select this page in its tab book." )
230{
231   GuiTabBookCtrl* book = dynamic_cast< GuiTabBookCtrl* >( object->getParent() );
232   if( !book )
233      return;
234
235   book->selectPage( object );
236}
237