/indra/llui/lldockablefloater.cpp

https://bitbucket.org/lindenlab/viewer-beta/ · C++ · 263 lines · 196 code · 31 blank · 36 comment · 44 complexity · f5c731013a203121ba97568dbbb27daa MD5 · raw file

  1. /**
  2. * @file lldockablefloater.cpp
  3. * @brief Creates a panel of a specific kind for a toast
  4. *
  5. * $LicenseInfo:firstyear=2000&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #include "linden_common.h"
  27. #include "lldockablefloater.h"
  28. #include "llfloaterreg.h"
  29. //static
  30. LLHandle<LLFloater> LLDockableFloater::sInstanceHandle;
  31. //static
  32. void LLDockableFloater::init(LLDockableFloater* thiz)
  33. {
  34. thiz->setDocked(thiz->mDockControl.get() != NULL
  35. && thiz->mDockControl.get()->isDockVisible());
  36. thiz->resetInstance();
  37. // all dockable floaters should have close, dock and minimize buttons
  38. thiz->setCanClose(TRUE);
  39. thiz->setCanDock(true);
  40. thiz->setCanMinimize(TRUE);
  41. thiz->setOverlapsScreenChannel(false);
  42. thiz->mForceDocking = false;
  43. }
  44. LLDockableFloater::LLDockableFloater(LLDockControl* dockControl,
  45. const LLSD& key, const Params& params) :
  46. LLFloater(key, params), mDockControl(dockControl), mUniqueDocking(true)
  47. {
  48. init(this);
  49. mUseTongue = true;
  50. }
  51. LLDockableFloater::LLDockableFloater(LLDockControl* dockControl, bool uniqueDocking,
  52. const LLSD& key, const Params& params) :
  53. LLFloater(key, params), mDockControl(dockControl), mUniqueDocking(uniqueDocking)
  54. {
  55. init(this);
  56. mUseTongue = true;
  57. }
  58. LLDockableFloater::LLDockableFloater(LLDockControl* dockControl, bool uniqueDocking,
  59. bool useTongue, const LLSD& key, const Params& params) :
  60. LLFloater(key, params), mDockControl(dockControl), mUseTongue(useTongue), mUniqueDocking(uniqueDocking)
  61. {
  62. init(this);
  63. }
  64. LLDockableFloater::~LLDockableFloater()
  65. {
  66. }
  67. BOOL LLDockableFloater::postBuild()
  68. {
  69. // Remember we should force docking when the floater is opened for the first time
  70. if (mIsDockedStateForcedCallback != NULL && mIsDockedStateForcedCallback())
  71. {
  72. mForceDocking = true;
  73. }
  74. mDockTongue = LLUI::getUIImage("Flyout_Pointer");
  75. LLFloater::setDocked(true);
  76. return LLView::postBuild();
  77. }
  78. //static
  79. void LLDockableFloater::toggleInstance(const LLSD& sdname)
  80. {
  81. LLSD key;
  82. std::string name = sdname.asString();
  83. LLDockableFloater* instance =
  84. dynamic_cast<LLDockableFloater*> (LLFloaterReg::findInstance(name));
  85. // if floater closed or docked
  86. if (instance == NULL || (instance && instance->isDocked()))
  87. {
  88. LLFloaterReg::toggleInstance(name, key);
  89. // restore button toggle state
  90. if (instance != NULL)
  91. {
  92. instance->storeVisibilityControl();
  93. }
  94. }
  95. // if floater undocked
  96. else if (instance != NULL)
  97. {
  98. instance->setMinimized(FALSE);
  99. if (instance->getVisible())
  100. {
  101. instance->setVisible(FALSE);
  102. }
  103. else
  104. {
  105. instance->setVisible(TRUE);
  106. gFloaterView->bringToFront(instance);
  107. }
  108. }
  109. }
  110. void LLDockableFloater::resetInstance()
  111. {
  112. if (mUniqueDocking && sInstanceHandle.get() != this)
  113. {
  114. if (sInstanceHandle.get() != NULL && sInstanceHandle.get()->isDocked())
  115. {
  116. sInstanceHandle.get()->setVisible(FALSE);
  117. }
  118. sInstanceHandle = getHandle();
  119. }
  120. }
  121. void LLDockableFloater::setVisible(BOOL visible)
  122. {
  123. // Force docking if requested
  124. if (visible && mForceDocking)
  125. {
  126. setCanDock(true);
  127. setDocked(true);
  128. mForceDocking = false;
  129. }
  130. if(visible && isDocked())
  131. {
  132. resetInstance();
  133. }
  134. if (visible && mDockControl.get() != NULL)
  135. {
  136. mDockControl.get()->repositionDockable();
  137. }
  138. if (visible)
  139. {
  140. LLFloater::setFrontmost(getAutoFocus());
  141. }
  142. LLFloater::setVisible(visible);
  143. }
  144. void LLDockableFloater::setMinimized(BOOL minimize)
  145. {
  146. if(minimize && isDocked())
  147. {
  148. // minimizing a docked floater just hides it
  149. setVisible(FALSE);
  150. }
  151. else
  152. {
  153. LLFloater::setMinimized(minimize);
  154. }
  155. }
  156. LLView * LLDockableFloater::getDockWidget()
  157. {
  158. LLView * res = NULL;
  159. if (getDockControl() != NULL) {
  160. res = getDockControl()->getDock();
  161. }
  162. return res;
  163. }
  164. void LLDockableFloater::onDockHidden()
  165. {
  166. setCanDock(FALSE);
  167. }
  168. void LLDockableFloater::onDockShown()
  169. {
  170. if (!isMinimized())
  171. {
  172. setCanDock(TRUE);
  173. }
  174. }
  175. void LLDockableFloater::setDocked(bool docked, bool pop_on_undock)
  176. {
  177. if (mDockControl.get() != NULL && mDockControl.get()->isDockVisible())
  178. {
  179. if (docked)
  180. {
  181. resetInstance();
  182. mDockControl.get()->on();
  183. }
  184. else
  185. {
  186. mDockControl.get()->off();
  187. }
  188. if (!docked && pop_on_undock)
  189. {
  190. // visually pop up a little bit to emphasize the undocking
  191. translate(0, UNDOCK_LEAP_HEIGHT);
  192. }
  193. }
  194. LLFloater::setDocked(docked, pop_on_undock);
  195. }
  196. void LLDockableFloater::draw()
  197. {
  198. if (mDockControl.get() != NULL)
  199. {
  200. mDockControl.get()->repositionDockable();
  201. if (isDocked())
  202. {
  203. mDockControl.get()->drawToungue();
  204. }
  205. }
  206. LLFloater::draw();
  207. }
  208. void LLDockableFloater::setDockControl(LLDockControl* dockControl)
  209. {
  210. mDockControl.reset(dockControl);
  211. setDocked(isDocked());
  212. }
  213. const LLUIImagePtr& LLDockableFloater::getDockTongue(LLDockControl::DocAt dock_side)
  214. {
  215. switch(dock_side)
  216. {
  217. case LLDockControl::LEFT:
  218. mDockTongue = LLUI::getUIImage("Flyout_Left");
  219. break;
  220. case LLDockControl::RIGHT:
  221. mDockTongue = LLUI::getUIImage("Flyout_Right");
  222. break;
  223. default:
  224. mDockTongue = LLUI::getUIImage("Flyout_Pointer");
  225. break;
  226. }
  227. return mDockTongue;
  228. }
  229. LLDockControl* LLDockableFloater::getDockControl()
  230. {
  231. return mDockControl.get();
  232. }