/indra/newview/lltransientfloatermgr.cpp

https://bitbucket.org/lindenlab/viewer-beta/ · C++ · 169 lines · 112 code · 27 blank · 30 comment · 18 complexity · 29257b0b7dbe73443aac2c9f2df1a4c7 MD5 · raw file

  1. /**
  2. * @file lltransientfloatermgr.cpp
  3. * @brief LLFocusMgr base class
  4. *
  5. * $LicenseInfo:firstyear=2002&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 "llviewerprecompiledheaders.h"
  27. #include "lltransientfloatermgr.h"
  28. #include "llfocusmgr.h"
  29. #include "llrootview.h"
  30. #include "llviewerwindow.h"
  31. #include "lldockablefloater.h"
  32. #include "llmenugl.h"
  33. LLTransientFloaterMgr::LLTransientFloaterMgr()
  34. {
  35. if(gViewerWindow)
  36. {
  37. gViewerWindow->getRootView()->getChild<LLUICtrl>("popup_holder")->setMouseDownCallback(boost::bind(
  38. &LLTransientFloaterMgr::leftMouseClickCallback, this, _2, _3, _4));
  39. }
  40. mGroupControls.insert(std::pair<ETransientGroup, controls_set_t >(GLOBAL, controls_set_t()));
  41. mGroupControls.insert(std::pair<ETransientGroup, controls_set_t >(DOCKED, controls_set_t()));
  42. mGroupControls.insert(std::pair<ETransientGroup, controls_set_t >(IM, controls_set_t()));
  43. }
  44. void LLTransientFloaterMgr::registerTransientFloater(LLTransientFloater* floater)
  45. {
  46. mTransSet.insert(floater);
  47. }
  48. void LLTransientFloaterMgr::unregisterTransientFloater(LLTransientFloater* floater)
  49. {
  50. mTransSet.erase(floater);
  51. }
  52. void LLTransientFloaterMgr::addControlView(ETransientGroup group, LLView* view)
  53. {
  54. if (!view) return;
  55. mGroupControls.find(group)->second.insert(view->getHandle());
  56. }
  57. void LLTransientFloaterMgr::removeControlView(ETransientGroup group, LLView* view)
  58. {
  59. if (!view) return;
  60. mGroupControls.find(group)->second.erase(view->getHandle());
  61. }
  62. void LLTransientFloaterMgr::addControlView(LLView* view)
  63. {
  64. addControlView(GLOBAL, view);
  65. }
  66. void LLTransientFloaterMgr::removeControlView(LLView* view)
  67. {
  68. // we will still get focus lost callbacks on this view, but that's ok
  69. // since we run sanity checking logic every time
  70. removeControlView(GLOBAL, view);
  71. }
  72. void LLTransientFloaterMgr::hideTransientFloaters(S32 x, S32 y)
  73. {
  74. for (std::set<LLTransientFloater*>::iterator it = mTransSet.begin(); it
  75. != mTransSet.end(); it++)
  76. {
  77. LLTransientFloater* floater = *it;
  78. if (floater->isTransientDocked())
  79. {
  80. ETransientGroup group = floater->getGroup();
  81. bool hide = isControlClicked(group, mGroupControls.find(group)->second, x, y);
  82. if (hide)
  83. {
  84. floater->setTransientVisible(FALSE);
  85. }
  86. }
  87. }
  88. }
  89. bool LLTransientFloaterMgr::isControlClicked(ETransientGroup group, controls_set_t& set, S32 x, S32 y)
  90. {
  91. std::list< LLHandle<LLView> > dead_handles;
  92. bool res = true;
  93. for (controls_set_t::iterator it = set.begin(); it
  94. != set.end(); it++)
  95. {
  96. LLView* control_view = NULL;
  97. LLHandle<LLView> handle = *it;
  98. if (handle.isDead())
  99. {
  100. dead_handles.push_back(handle);
  101. continue;
  102. }
  103. control_view = handle.get();
  104. if (!control_view->getVisible())
  105. {
  106. continue;
  107. }
  108. LLRect rect = control_view->calcScreenRect();
  109. // if click inside view rect
  110. if (rect.pointInRect(x, y))
  111. {
  112. res = false;
  113. break;
  114. }
  115. }
  116. for (std::list< LLHandle<LLView> >::iterator it = dead_handles.begin(); it != dead_handles.end(); ++it)
  117. {
  118. LLHandle<LLView> handle = *it;
  119. mGroupControls.find(group)->second.erase(handle);
  120. }
  121. return res;
  122. }
  123. void LLTransientFloaterMgr::leftMouseClickCallback(S32 x, S32 y,
  124. MASK mask)
  125. {
  126. // don't hide transient floater if any context menu opened
  127. if (LLMenuGL::sMenuContainer->getVisibleMenu() != NULL)
  128. {
  129. return;
  130. }
  131. bool hide = isControlClicked(DOCKED, mGroupControls.find(DOCKED)->second, x, y)
  132. && isControlClicked(GLOBAL, mGroupControls.find(GLOBAL)->second, x, y);
  133. if (hide)
  134. {
  135. hideTransientFloaters(x, y);
  136. }
  137. }
  138. void LLTransientFloater::init(LLFloater* thiz)
  139. {
  140. // used since LLTransientFloater(this) can't be used in descendant constructor parameter initialization.
  141. mFloater = thiz;
  142. }