PageRenderTime 43ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llui/llcontainerview.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 296 lines | 211 code | 42 blank | 43 comment | 34 complexity | dda0cc2c28d186c00ef9eb3c637e2230 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llcontainerview.cpp
  3. * @brief Container for all statistics info
  4. *
  5. * $LicenseInfo:firstyear=2001&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 "llcontainerview.h"
  28. #include "llerror.h"
  29. #include "llfontgl.h"
  30. #include "llgl.h"
  31. #include "llui.h"
  32. #include "llstring.h"
  33. #include "llscrollcontainer.h"
  34. #include "lluictrlfactory.h"
  35. static LLDefaultChildRegistry::Register<LLContainerView> r1("container_view");
  36. #include "llpanel.h"
  37. #include "llstatview.h"
  38. static ContainerViewRegistry::Register<LLStatView> r2("stat_view");
  39. static ContainerViewRegistry::Register<LLPanel> r3("panel", &LLPanel::fromXML);
  40. LLContainerView::LLContainerView(const LLContainerView::Params& p)
  41. : LLView(p),
  42. mShowLabel(p.show_label),
  43. mLabel(p.label),
  44. mDisplayChildren(p.display_children)
  45. {
  46. mCollapsible = TRUE;
  47. mScrollContainer = NULL;
  48. }
  49. LLContainerView::~LLContainerView()
  50. {
  51. // Children all cleaned up by default view destructor.
  52. }
  53. BOOL LLContainerView::postBuild()
  54. {
  55. setDisplayChildren(mDisplayChildren);
  56. reshape(getRect().getWidth(), getRect().getHeight(), FALSE);
  57. return TRUE;
  58. }
  59. bool LLContainerView::addChild(LLView* child, S32 tab_group)
  60. {
  61. bool res = LLView::addChild(child, tab_group);
  62. if (res)
  63. {
  64. sendChildToBack(child);
  65. }
  66. return res;
  67. }
  68. BOOL LLContainerView::handleMouseDown(S32 x, S32 y, MASK mask)
  69. {
  70. BOOL handled = FALSE;
  71. if (mDisplayChildren)
  72. {
  73. handled = (LLView::childrenHandleMouseDown(x, y, mask) != NULL);
  74. }
  75. if (!handled)
  76. {
  77. if( mCollapsible && mShowLabel && (y >= getRect().getHeight() - 10) )
  78. {
  79. setDisplayChildren(!mDisplayChildren);
  80. reshape(getRect().getWidth(), getRect().getHeight(), FALSE);
  81. handled = TRUE;
  82. }
  83. }
  84. return handled;
  85. }
  86. BOOL LLContainerView::handleMouseUp(S32 x, S32 y, MASK mask)
  87. {
  88. BOOL handled = FALSE;
  89. if (mDisplayChildren)
  90. {
  91. handled = (LLView::childrenHandleMouseUp(x, y, mask) != NULL);
  92. }
  93. return handled;
  94. }
  95. void LLContainerView::draw()
  96. {
  97. {
  98. gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
  99. gl_rect_2d(0, getRect().getHeight(), getRect().getWidth(), 0, LLColor4(0.f, 0.f, 0.f, 0.25f));
  100. }
  101. // Draw the label
  102. if (mShowLabel)
  103. {
  104. LLFontGL::getFontMonospace()->renderUTF8(
  105. mLabel, 0, 2, getRect().getHeight() - 2, LLColor4(1,1,1,1), LLFontGL::LEFT, LLFontGL::TOP);
  106. }
  107. LLView::draw();
  108. }
  109. void LLContainerView::reshape(S32 width, S32 height, BOOL called_from_parent)
  110. {
  111. LLRect scroller_rect;
  112. scroller_rect.setOriginAndSize(0, 0, width, height);
  113. if (mScrollContainer)
  114. {
  115. scroller_rect = mScrollContainer->getContentWindowRect();
  116. }
  117. else
  118. {
  119. // if we're uncontained - make height as small as possible
  120. scroller_rect.mTop = 0;
  121. }
  122. arrange(scroller_rect.getWidth(), scroller_rect.getHeight(), called_from_parent);
  123. // sometimes, after layout, our container will change size (scrollbars popping in and out)
  124. // if so, attempt another layout
  125. if (mScrollContainer)
  126. {
  127. LLRect new_container_rect = mScrollContainer->getContentWindowRect();
  128. if ((new_container_rect.getWidth() != scroller_rect.getWidth()) ||
  129. (new_container_rect.getHeight() != scroller_rect.getHeight())) // the container size has changed, attempt to arrange again
  130. {
  131. arrange(new_container_rect.getWidth(), new_container_rect.getHeight(), called_from_parent);
  132. }
  133. }
  134. }
  135. void LLContainerView::arrange(S32 width, S32 height, BOOL called_from_parent)
  136. {
  137. // Determine the sizes and locations of all contained views
  138. S32 total_height = 0;
  139. S32 top, left, right, bottom;
  140. //LLView *childp;
  141. // These will be used for the children
  142. left = 4;
  143. top = getRect().getHeight() - 4;
  144. right = width - 2;
  145. bottom = top;
  146. // Leave some space for the top label/grab handle
  147. if (mShowLabel)
  148. {
  149. total_height += 20;
  150. }
  151. if (mDisplayChildren)
  152. {
  153. // Determine total height
  154. U32 child_height = 0;
  155. for (child_list_const_iter_t child_iter = getChildList()->begin();
  156. child_iter != getChildList()->end(); ++child_iter)
  157. {
  158. LLView *childp = *child_iter;
  159. if (!childp->getVisible())
  160. {
  161. llwarns << "Incorrect visibility!" << llendl;
  162. }
  163. LLRect child_rect = childp->getRequiredRect();
  164. child_height += child_rect.getHeight();
  165. child_height += 2;
  166. }
  167. total_height += child_height;
  168. }
  169. if (total_height < height)
  170. total_height = height;
  171. if (followsTop())
  172. {
  173. // HACK: casting away const. Should use setRect or some helper function instead.
  174. const_cast<LLRect&>(getRect()).mBottom = getRect().mTop - total_height;
  175. }
  176. else
  177. {
  178. // HACK: casting away const. Should use setRect or some helper function instead.
  179. const_cast<LLRect&>(getRect()).mTop = getRect().mBottom + total_height;
  180. }
  181. // HACK: casting away const. Should use setRect or some helper function instead.
  182. const_cast<LLRect&>(getRect()).mRight = getRect().mLeft + width;
  183. top = total_height;
  184. if (mShowLabel)
  185. {
  186. top -= 20;
  187. }
  188. bottom = top;
  189. if (mDisplayChildren)
  190. {
  191. // Iterate through all children, and put in container from top down.
  192. for (child_list_const_iter_t child_iter = getChildList()->begin();
  193. child_iter != getChildList()->end(); ++child_iter)
  194. {
  195. LLView *childp = *child_iter;
  196. LLRect child_rect = childp->getRequiredRect();
  197. bottom -= child_rect.getHeight();
  198. LLRect r(left, bottom + child_rect.getHeight(), right, bottom);
  199. childp->setRect(r);
  200. childp->reshape(right - left, top - bottom);
  201. top = bottom - 2;
  202. bottom = top;
  203. }
  204. }
  205. if (!called_from_parent)
  206. {
  207. if (getParent())
  208. {
  209. getParent()->reshape(getParent()->getRect().getWidth(), getParent()->getRect().getHeight(), FALSE);
  210. }
  211. }
  212. }
  213. LLRect LLContainerView::getRequiredRect()
  214. {
  215. LLRect req_rect;
  216. //LLView *childp;
  217. U32 total_height = 0;
  218. // Determine the sizes and locations of all contained views
  219. // Leave some space for the top label/grab handle
  220. if (mShowLabel)
  221. {
  222. total_height = 20;
  223. }
  224. if (mDisplayChildren)
  225. {
  226. // Determine total height
  227. U32 child_height = 0;
  228. for (child_list_const_iter_t child_iter = getChildList()->begin();
  229. child_iter != getChildList()->end(); ++child_iter)
  230. {
  231. LLView *childp = *child_iter;
  232. LLRect child_rect = childp->getRequiredRect();
  233. child_height += child_rect.getHeight();
  234. child_height += 2;
  235. }
  236. total_height += child_height;
  237. }
  238. req_rect.mTop = total_height;
  239. return req_rect;
  240. }
  241. void LLContainerView::setLabel(const std::string& label)
  242. {
  243. mLabel = label;
  244. }
  245. void LLContainerView::setDisplayChildren(const BOOL displayChildren)
  246. {
  247. mDisplayChildren = displayChildren;
  248. for (child_list_const_iter_t child_iter = getChildList()->begin();
  249. child_iter != getChildList()->end(); ++child_iter)
  250. {
  251. LLView *childp = *child_iter;
  252. childp->setVisible(mDisplayChildren);
  253. }
  254. }