00001
00032 #include "llviewerprecompiledheaders.h"
00033
00034 #include "llcontainerview.h"
00035
00036 #include "llerror.h"
00037 #include "llfontgl.h"
00038 #include "llgl.h"
00039 #include "llui.h"
00040 #include "llresmgr.h"
00041 #include "llstring.h"
00042
00043 LLContainerView::LLContainerView(const std::string& name, const LLRect& rect)
00044 : LLView(name, rect, FALSE)
00045 {
00046 mCollapsible = TRUE;
00047 mDisplayChildren = TRUE;
00048 }
00049
00050 LLContainerView::~LLContainerView()
00051 {
00052
00053 }
00054
00055 EWidgetType LLContainerView::getWidgetType() const
00056 {
00057 return WIDGET_TYPE_CONTAINER_VIEW;
00058 }
00059
00060 LLString LLContainerView::getWidgetTag() const
00061 {
00062 return LL_CONTAINER_VIEW_TAG;
00063 }
00064
00065 BOOL LLContainerView::handleMouseDown(S32 x, S32 y, MASK mask)
00066 {
00067 BOOL handled = FALSE;
00068 if (mDisplayChildren)
00069 {
00070 handled = LLView::childrenHandleMouseDown(x, y, mask) != NULL;
00071 }
00072 if (!handled)
00073 {
00074 if( mCollapsible && (y >= mRect.getHeight() - 10) )
00075 {
00076 setDisplayChildren(!mDisplayChildren);
00077 reshape(mRect.getWidth(), mRect.getHeight(), FALSE);
00078 }
00079 }
00080 return TRUE;
00081 }
00082
00083 BOOL LLContainerView::handleMouseUp(S32 x, S32 y, MASK mask)
00084 {
00085 if (mDisplayChildren)
00086 {
00087 LLView::childrenHandleMouseUp(x, y, mask);
00088 }
00089 return TRUE;
00090 }
00091
00092 void LLContainerView::draw()
00093 {
00094 if (!getVisible())
00095 {
00096 return;
00097 }
00098
00099 {
00100 LLGLSNoTexture gls_no_texture;
00101
00102 gl_rect_2d(0, mRect.getHeight(), mRect.getWidth(), 0, LLColor4(0.f, 0.f, 0.f, 0.25f));
00103 }
00104
00105
00106 gResMgr->getRes( LLFONT_OCRA )->renderUTF8(mLabel, 0, 2, mRect.getHeight() - 2, LLColor4(1,1,1,1), LLFontGL::LEFT, LLFontGL::TOP);
00107
00108 LLView::draw();
00109 }
00110
00111 void LLContainerView::reshape(S32 width, S32 height, BOOL called_from_parent)
00112 {
00113
00114 U32 total_height = 0;
00115 U32 top, left, right, bottom;
00116
00117
00118
00119 left = 4;
00120 top = mRect.getHeight() - 4;
00121 right = mRect.getWidth() - 2;
00122 bottom = top;
00123
00124
00125 total_height += 20;
00126
00127 if (mDisplayChildren)
00128 {
00129
00130 U32 child_height = 0;
00131 for (child_list_const_iter_t child_iter = getChildList()->begin();
00132 child_iter != getChildList()->end(); ++child_iter)
00133 {
00134 LLView *childp = *child_iter;
00135 if (!childp->getVisible())
00136 {
00137 llwarns << "Incorrect visibility!" << llendl;
00138 }
00139 LLRect child_rect = childp->getRequiredRect();
00140 child_height += child_rect.getHeight();
00141 child_height += 2;
00142 }
00143 total_height += child_height;
00144 }
00145
00146
00147 if (followsTop())
00148 {
00149 mRect.mBottom = mRect.mTop - total_height;
00150 }
00151 else
00152 {
00153 mRect.mTop = mRect.mBottom + total_height;
00154 }
00155 mRect.mRight = mRect.mLeft + width;
00156
00157 top = total_height - 20;
00158 bottom = top;
00159
00160 if (mDisplayChildren)
00161 {
00162
00163 for (child_list_const_iter_t child_iter = getChildList()->begin();
00164 child_iter != getChildList()->end(); ++child_iter)
00165 {
00166 LLView *childp = *child_iter;
00167 LLRect child_rect = childp->getRequiredRect();
00168 bottom -= child_rect.getHeight();
00169 LLRect r(left, bottom + child_rect.getHeight(), right, bottom);
00170 childp->setRect(r);
00171 childp->reshape(right - left, top - bottom);
00172 top = bottom - 2;
00173 bottom = top;
00174 }
00175 }
00176
00177 if (!called_from_parent)
00178 {
00179 if (getParent())
00180 {
00181 getParent()->reshape(getParent()->getRect().getWidth(), getParent()->getRect().getHeight(), FALSE);
00182 }
00183 }
00184 }
00185
00186 LLRect LLContainerView::getRequiredRect()
00187 {
00188 LLRect req_rect;
00189
00190 U32 total_height = 0;
00191
00192
00193
00194
00195
00196 if (mDisplayChildren)
00197 {
00198 total_height = 20;
00199
00200
00201 U32 child_height = 0;
00202 for (child_list_const_iter_t child_iter = getChildList()->begin();
00203 child_iter != getChildList()->end(); ++child_iter)
00204 {
00205 LLView *childp = *child_iter;
00206 LLRect child_rect = childp->getRequiredRect();
00207 child_height += child_rect.getHeight();
00208 child_height += 2;
00209 }
00210
00211 total_height += child_height;
00212 }
00213 else
00214 {
00215 total_height = 20;
00216 }
00217
00218 req_rect.mTop = total_height;
00219 return req_rect;
00220 }
00221
00222 void LLContainerView::setLabel(const LLString& label)
00223 {
00224 mLabel = label;
00225 }
00226
00227 void LLContainerView::setDisplayChildren(const BOOL displayChildren)
00228 {
00229 mDisplayChildren = displayChildren;
00230 for (child_list_const_iter_t child_iter = getChildList()->begin();
00231 child_iter != getChildList()->end(); ++child_iter)
00232 {
00233 LLView *childp = *child_iter;
00234 childp->setVisible(mDisplayChildren);
00235 }
00236 }