guiTabPageCtrl.cc 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "console/consoleTypes.h"
  23. #include "console/console.h"
  24. #include "graphics/dgl.h"
  25. #include "gui/guiCanvas.h"
  26. #include "gui/guiTabPageCtrl.h"
  27. #include "gui/guiDefaultControlRender.h"
  28. #include "gui/editor/guiEditCtrl.h"
  29. IMPLEMENT_CONOBJECT(GuiTabPageCtrl);
  30. GuiTabPageCtrl::GuiTabPageCtrl(void)
  31. {
  32. mBounds.extent.set(100, 200);
  33. mMinSize.set(50, 50);
  34. dStrcpy(mText,(UTF8*)"TabPage");
  35. mActive = true;
  36. mIsContainer = true;
  37. }
  38. void GuiTabPageCtrl::initPersistFields()
  39. {
  40. Parent::initPersistFields();
  41. }
  42. bool GuiTabPageCtrl::onWake()
  43. {
  44. if (! Parent::onWake())
  45. return false;
  46. return true;
  47. }
  48. void GuiTabPageCtrl::onSleep()
  49. {
  50. Parent::onSleep();
  51. }
  52. GuiControl* GuiTabPageCtrl::findHitControl(const Point2I &pt, S32 initialLayer)
  53. {
  54. return Parent::findHitControl(pt, initialLayer);
  55. }
  56. void GuiTabPageCtrl::onMouseDown(const GuiEvent &event)
  57. {
  58. setUpdate();
  59. Point2I localPoint = globalToLocalCoord( event.mousePoint );
  60. GuiControl *ctrl = findHitControl(localPoint);
  61. if (ctrl && ctrl != this)
  62. {
  63. ctrl->onMouseDown(event);
  64. }
  65. }
  66. bool GuiTabPageCtrl::onMouseDownEditor(const GuiEvent &event, Point2I offset )
  67. {
  68. // This shouldn't be called if it's not design time, but check just incase
  69. if ( GuiControl::smDesignTime )
  70. {
  71. GuiEditCtrl* edit = GuiControl::smEditorHandle;
  72. if( edit )
  73. edit->select( this );
  74. }
  75. return Parent::onMouseDownEditor( event, offset );
  76. }
  77. GuiControl *GuiTabPageCtrl::findNextTabable(GuiControl *curResponder, bool firstCall)
  78. {
  79. //set the global if this is the first call (directly from the canvas)
  80. if (firstCall)
  81. {
  82. GuiControl::smCurResponder = NULL;
  83. }
  84. //if the window does not already contain the first responder, return false
  85. //ie. Can't tab into or out of a window
  86. if (! ControlIsChild(curResponder))
  87. {
  88. return NULL;
  89. }
  90. //loop through, checking each child to see if it is the one that follows the firstResponder
  91. GuiControl *tabCtrl = NULL;
  92. iterator i;
  93. for (i = begin(); i != end(); i++)
  94. {
  95. GuiControl *ctrl = static_cast<GuiControl *>(*i);
  96. tabCtrl = ctrl->findNextTabable(curResponder, false);
  97. if (tabCtrl) break;
  98. }
  99. //to ensure the tab cycles within the current window...
  100. if (! tabCtrl)
  101. {
  102. tabCtrl = findFirstTabable();
  103. }
  104. mFirstResponder = tabCtrl;
  105. return tabCtrl;
  106. }
  107. GuiControl *GuiTabPageCtrl::findPrevTabable(GuiControl *curResponder, bool firstCall)
  108. {
  109. if (firstCall)
  110. {
  111. GuiControl::smPrevResponder = NULL;
  112. }
  113. //if the window does not already contain the first responder, return false
  114. //ie. Can't tab into or out of a window
  115. if (! ControlIsChild(curResponder))
  116. {
  117. return NULL;
  118. }
  119. //loop through, checking each child to see if it is the one that follows the firstResponder
  120. GuiControl *tabCtrl = NULL;
  121. iterator i;
  122. for (i = begin(); i != end(); i++)
  123. {
  124. GuiControl *ctrl = static_cast<GuiControl *>(*i);
  125. tabCtrl = ctrl->findPrevTabable(curResponder, false);
  126. if (tabCtrl) break;
  127. }
  128. //to ensure the tab cycles within the current window...
  129. if (! tabCtrl)
  130. {
  131. tabCtrl = findLastTabable();
  132. }
  133. mFirstResponder = tabCtrl;
  134. return tabCtrl;
  135. }
  136. void GuiTabPageCtrl::setText(const char *txt)
  137. {
  138. Parent::setText( txt );
  139. GuiControl *parent = getParent();
  140. if( parent )
  141. parent->setUpdate();
  142. };
  143. void GuiTabPageCtrl::selectWindow(void)
  144. {
  145. //first make sure this window is the front most of its siblings
  146. GuiControl *parent = getParent();
  147. if (parent)
  148. {
  149. parent->pushObjectToBack(this);
  150. }
  151. //also set the first responder to be the one within this window
  152. setFirstResponder(mFirstResponder);
  153. }
  154. void GuiTabPageCtrl::onRender(Point2I offset,const RectI &updateRect)
  155. {
  156. GuiControl::onRender( offset, updateRect );
  157. }