llcontainerview.cpp

Go to the documentation of this file.
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 #include "llscrollcontainer.h"
00043 
00044 LLContainerView::LLContainerView(const std::string& name, const LLRect& rect)
00045 :       LLView(name, rect, FALSE)
00046 {
00047         mShowLabel = TRUE;
00048         mCollapsible = TRUE;
00049         mDisplayChildren = TRUE;
00050         mScrollContainer = NULL;
00051 }
00052 
00053 LLContainerView::~LLContainerView()
00054 {
00055         // Children all cleaned up by default view destructor.
00056 }
00057 
00058 BOOL LLContainerView::handleMouseDown(S32 x, S32 y, MASK mask)
00059 {
00060         BOOL handled = FALSE;
00061         if (mDisplayChildren)
00062         {
00063                 handled = (LLView::childrenHandleMouseDown(x, y, mask) != NULL);
00064         }
00065         if (!handled)
00066         {
00067                 if( mCollapsible && mShowLabel && (y >= getRect().getHeight() - 10) )
00068                 {
00069                         setDisplayChildren(!mDisplayChildren);
00070                         reshape(getRect().getWidth(), getRect().getHeight(), FALSE);
00071                         handled = TRUE;
00072                 }
00073         }
00074         return handled;
00075 }
00076 
00077 BOOL LLContainerView::handleMouseUp(S32 x, S32 y, MASK mask)
00078 {
00079         BOOL handled = FALSE;
00080         if (mDisplayChildren)
00081         {
00082                 handled = (LLView::childrenHandleMouseUp(x, y, mask) != NULL);
00083         }
00084         return handled;
00085 }
00086 
00087 
00088 void LLContainerView::draw()
00089 {
00090         {
00091                 LLGLSNoTexture gls_no_texture;
00092 
00093                 gl_rect_2d(0, getRect().getHeight(), getRect().getWidth(), 0, LLColor4(0.f, 0.f, 0.f, 0.25f));
00094         }
00095                 
00096         // Draw the label
00097         if (mShowLabel)
00098         {
00099                 LLResMgr::getInstance()->getRes( LLFONT_OCRA )->renderUTF8(mLabel, 0, 2, getRect().getHeight() - 2, LLColor4(1,1,1,1), LLFontGL::LEFT, LLFontGL::TOP);
00100         }
00101 
00102         LLView::draw();
00103 }
00104 
00105 
00106 void LLContainerView::reshape(S32 width, S32 height, BOOL called_from_parent)
00107 {
00108         S32 desired_width = width;
00109         S32 desired_height = height;
00110 
00111         if (mScrollContainer)
00112         {
00113                 BOOL dum_bool;
00114                 mScrollContainer->calcVisibleSize(&desired_width, &desired_height, &dum_bool, &dum_bool);
00115         }
00116         else
00117         {
00118                 // if we're uncontained - make height as small as possible
00119                 desired_height = 0;
00120         }
00121 
00122         arrange(desired_width, desired_height, called_from_parent);
00123 
00124         // sometimes, after layout, our container will change size (scrollbars popping in and out)
00125         // if so, attempt another layout
00126         if (mScrollContainer)
00127         {
00128                 S32 new_container_width;
00129                 S32 new_container_height;
00130                 BOOL dum_bool;
00131                 mScrollContainer->calcVisibleSize(&new_container_width, &new_container_height, &dum_bool, &dum_bool);
00132 
00133                 if ((new_container_width != desired_width) ||
00134                         (new_container_height != desired_height))  // the container size has changed, attempt to arrange again
00135                 {
00136                         arrange(new_container_width, new_container_height, called_from_parent);
00137                 }
00138         }
00139 }
00140 
00141 void LLContainerView::arrange(S32 width, S32 height, BOOL called_from_parent)
00142 {
00143         // Determine the sizes and locations of all contained views
00144         S32 total_height = 0;
00145         S32 top, left, right, bottom;
00146         //LLView *childp;
00147 
00148         // These will be used for the children
00149         left = 4;
00150         top = getRect().getHeight() - 4;
00151         right = width - 2;
00152         bottom = top;
00153         
00154         // Leave some space for the top label/grab handle
00155         if (mShowLabel)
00156         {
00157                 total_height += 20;
00158         }
00159 
00160         if (mDisplayChildren)
00161         {
00162                 // Determine total height
00163                 U32 child_height = 0;
00164                 for (child_list_const_iter_t child_iter = getChildList()->begin();
00165                          child_iter != getChildList()->end(); ++child_iter)
00166                 {
00167                         LLView *childp = *child_iter;
00168                         if (!childp->getVisible())
00169                         {
00170                                 llwarns << "Incorrect visibility!" << llendl;
00171                         }
00172                         LLRect child_rect = childp->getRequiredRect();
00173                         child_height += child_rect.getHeight();
00174                         child_height += 2;
00175                 }
00176                 total_height += child_height;
00177         }
00178 
00179         if (total_height < height)
00180                 total_height = height;
00181         
00182         if (followsTop())
00183         {
00184                 // HACK: casting away const. Should use setRect or some helper function instead.
00185                 const_cast<LLRect&>(getRect()).mBottom = getRect().mTop - total_height;
00186         }
00187         else
00188         {
00189                 // HACK: casting away const. Should use setRect or some helper function instead.
00190                 const_cast<LLRect&>(getRect()).mTop = getRect().mBottom + total_height;
00191         }
00192         // HACK: casting away const. Should use setRect or some helper function instead.
00193                 const_cast<LLRect&>(getRect()).mRight = getRect().mLeft + width;
00194 
00195         top = total_height;
00196         if (mShowLabel)
00197                 {
00198                         top -= 20;
00199                 }
00200         
00201         bottom = top;
00202 
00203         if (mDisplayChildren)
00204         {
00205                 // Iterate through all children, and put in container from top down.
00206                 for (child_list_const_iter_t child_iter = getChildList()->begin();
00207                          child_iter != getChildList()->end(); ++child_iter)
00208                 {
00209                         LLView *childp = *child_iter;
00210                         LLRect child_rect = childp->getRequiredRect();
00211                         bottom -= child_rect.getHeight();
00212                         LLRect r(left, bottom + child_rect.getHeight(), right, bottom);
00213                         childp->setRect(r);
00214                         childp->reshape(right - left, top - bottom);
00215                         top = bottom - 2;
00216                         bottom = top;
00217                 }
00218         }
00219         
00220         if (!called_from_parent)
00221         {
00222                 if (getParent())
00223                 {
00224                         getParent()->reshape(getParent()->getRect().getWidth(), getParent()->getRect().getHeight(), FALSE);
00225                 }
00226         }
00227 
00228 }
00229 
00230 LLRect LLContainerView::getRequiredRect()
00231 {
00232         LLRect req_rect;
00233         //LLView *childp;
00234         U32 total_height = 0;
00235         
00236         // Determine the sizes and locations of all contained views
00237 
00238         // Leave some space for the top label/grab handle
00239 
00240         if (mShowLabel)
00241         {
00242                 total_height = 20;
00243         }
00244                 
00245 
00246         if (mDisplayChildren)
00247         {
00248                 // Determine total height
00249                 U32 child_height = 0;
00250                 for (child_list_const_iter_t child_iter = getChildList()->begin();
00251                          child_iter != getChildList()->end(); ++child_iter)
00252                 {
00253                         LLView *childp = *child_iter;
00254                         LLRect child_rect = childp->getRequiredRect();
00255                         child_height += child_rect.getHeight();
00256                         child_height += 2;
00257                 }
00258 
00259                 total_height += child_height;
00260         }
00261         req_rect.mTop = total_height;
00262         return req_rect;
00263 }
00264 
00265 void LLContainerView::setLabel(const LLString& label)
00266 {
00267         mLabel = label;
00268 }
00269 
00270 void LLContainerView::setDisplayChildren(const BOOL displayChildren)
00271 {
00272         mDisplayChildren = displayChildren;
00273         for (child_list_const_iter_t child_iter = getChildList()->begin();
00274                  child_iter != getChildList()->end(); ++child_iter)
00275         {
00276                 LLView *childp = *child_iter;
00277                 childp->setVisible(mDisplayChildren);
00278         }
00279 }

Generated on Fri May 16 08:33:16 2008 for SecondLife by  doxygen 1.5.5