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