llcontainerview.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /**
  2. * @file llcontainerview.cpp
  3. * @brief Container for all statistics info
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #include "linden_common.h"
  33. #include "llcontainerview.h"
  34. #include "llgl.h"
  35. #include "llscrollcontainer.h"
  36. LLContainerView::LLContainerView(const std::string& name, const LLRect& rect)
  37. : LLView(name, rect, false),
  38. mShowLabel(true),
  39. mCanCollapse(true),
  40. mDisplayChildren(true),
  41. mScrollContainer(NULL)
  42. {
  43. setDisplayChildren(true);
  44. #if 0 // Do not do that: this prevents auto-sizing (e.g. in
  45. // llfloaterjoystick.cpp) and breaks the layout... HB
  46. reshape(rect.getWidth(), rect.getHeight(), false);
  47. #endif
  48. }
  49. bool LLContainerView::handleMouseDown(S32 x, S32 y, MASK mask)
  50. {
  51. if (mDisplayChildren && LLView::childrenHandleMouseDown(x, y, mask))
  52. {
  53. return true;
  54. }
  55. if (mCanCollapse && mShowLabel && y >= getRect().getHeight() - 10)
  56. {
  57. setDisplayChildren(!mDisplayChildren);
  58. reshape(getRect().getWidth(), getRect().getHeight(), false);
  59. return true;
  60. }
  61. return false;
  62. }
  63. bool LLContainerView::handleMouseUp(S32 x, S32 y, MASK mask)
  64. {
  65. if (mDisplayChildren)
  66. {
  67. return LLView::childrenHandleMouseUp(x, y, mask) != NULL;
  68. }
  69. return false;
  70. }
  71. void LLContainerView::draw()
  72. {
  73. gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
  74. static const LLColor4 bg_color(0.f, 0.f, 0.f, 0.25f);
  75. S32 height = getRect().getHeight();
  76. gl_rect_2d(0, height, getRect().getWidth(), 0, bg_color);
  77. // Draw the label
  78. if (mShowLabel)
  79. {
  80. static const LLFontGL* fontp = LLFontGL::getFontMonospace();
  81. fontp->renderUTF8(mLabel, 0, 2, height - 2, LLColor4::white,
  82. LLFontGL::LEFT, LLFontGL::TOP);
  83. }
  84. LLView::draw();
  85. }
  86. void LLContainerView::reshape(S32 width, S32 height, bool called_from_parent)
  87. {
  88. LLRect scroller_rect;
  89. if (mScrollContainer)
  90. {
  91. scroller_rect = mScrollContainer->getContentWindowRect();
  92. }
  93. else
  94. {
  95. // If we are uncontained, make height as small as possible
  96. scroller_rect.setOriginAndSize(0, 0, width, height);
  97. scroller_rect.mTop = 0;
  98. }
  99. arrange(scroller_rect.getWidth(), scroller_rect.getHeight(),
  100. called_from_parent);
  101. if (!mScrollContainer)
  102. {
  103. return;
  104. }
  105. // Sometimes, after layout, our container will change size (scrollbars
  106. // popping in and out). If so, attempt another layout.
  107. LLRect new_container_rect = mScrollContainer->getContentWindowRect();
  108. if (new_container_rect.getWidth() != scroller_rect.getWidth() ||
  109. new_container_rect.getHeight() != scroller_rect.getHeight())
  110. {
  111. // The container size has changed, attempt to arrange again
  112. arrange(new_container_rect.getWidth(), new_container_rect.getHeight(),
  113. called_from_parent);
  114. }
  115. }
  116. // Determines the sizes and locations of all contained views
  117. void LLContainerView::arrange(S32 width, S32 height, bool called_from_parent)
  118. {
  119. // These will be used for the children
  120. S32 left = 4;
  121. S32 top = getRect().getHeight() - 4;
  122. S32 right = width - 2;
  123. S32 bottom = top;
  124. // Leave some space for the top label/grab handle
  125. S32 total_height = 0;
  126. if (mShowLabel)
  127. {
  128. total_height += 20;
  129. }
  130. if (mDisplayChildren)
  131. {
  132. // Determine total height
  133. U32 child_height = 0;
  134. for (child_list_const_iter_t it = getChildList()->begin(),
  135. end = getChildList()->end();
  136. it != end; ++it)
  137. {
  138. LLView* childp = *it;
  139. if (!childp->getVisible())
  140. {
  141. llwarns << "Incorrect visibility !" << llendl;
  142. }
  143. child_height += childp->getRequiredRect().getHeight();
  144. child_height += 2;
  145. }
  146. total_height += child_height;
  147. }
  148. if (total_height < height)
  149. {
  150. total_height = height;
  151. }
  152. LLRect my_rect = getRect();
  153. if (followsTop())
  154. {
  155. my_rect.mBottom = my_rect.mTop - total_height;
  156. }
  157. else
  158. {
  159. my_rect.mTop = my_rect.mBottom + total_height;
  160. }
  161. my_rect.mRight = my_rect.mLeft + width;
  162. setRect(my_rect);
  163. top = total_height;
  164. if (mShowLabel)
  165. {
  166. top -= 20;
  167. }
  168. bottom = top;
  169. if (mDisplayChildren)
  170. {
  171. LLRect new_rect;
  172. // Iterate through all children, and put in container from top down.
  173. for (child_list_const_iter_t it = getChildList()->begin(),
  174. end = getChildList()->end();
  175. it != end; ++it)
  176. {
  177. LLView* childp = *it;
  178. S32 height = childp->getRequiredRect().getHeight();
  179. bottom -= height;
  180. new_rect.set(left, bottom + height, right, bottom);
  181. childp->setRect(new_rect);
  182. childp->reshape(right - left, top - bottom);
  183. top = bottom - 2;
  184. bottom = top;
  185. }
  186. }
  187. if (!called_from_parent)
  188. {
  189. LLView* parentp = getParent();
  190. if (parentp)
  191. {
  192. const LLRect& rect = parentp->getRect();
  193. parentp->reshape(rect.getWidth(), rect.getHeight(), false);
  194. }
  195. }
  196. }
  197. LLRect LLContainerView::getRequiredRect()
  198. {
  199. LLRect req_rect;
  200. U32 total_height = 0;
  201. // Determine the sizes and locations of all contained views
  202. // Leave some space for the top label/grab handle
  203. if (mShowLabel)
  204. {
  205. total_height = 20;
  206. }
  207. if (mDisplayChildren)
  208. {
  209. // Determine total height
  210. for (child_list_const_iter_t it = getChildList()->begin(),
  211. end = getChildList()->end();
  212. it != end; ++it)
  213. {
  214. LLView* childp = *it;
  215. total_height += childp->getRequiredRect().getHeight() + 2;
  216. }
  217. }
  218. req_rect.mTop = total_height;
  219. return req_rect;
  220. }
  221. void LLContainerView::setDisplayChildren(bool display)
  222. {
  223. mDisplayChildren = display;
  224. for (child_list_const_iter_t it = getChildList()->begin(),
  225. end = getChildList()->end();
  226. it != end; ++it)
  227. {
  228. LLView* childp = *it;
  229. childp->setVisible(display);
  230. }
  231. }