CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_2_9_HLT1_bphpatch4/src/Fireworks/Core/src/FWCompactVerticalLayout.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Core
00004 // Class  :     FWCompactVerticalLayout
00005 // 
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  Chris Jones
00010 //         Created:  Tue Mar 17 12:10:42 CDT 2009
00011 // $Id: FWCompactVerticalLayout.cc,v 1.2 2010/06/18 10:17:15 yana Exp $
00012 //
00013 
00014 // system include files
00015 #include <algorithm>
00016 #include <iostream>
00017 #include "TGFrame.h"
00018 
00019 // user include files
00020 #include "Fireworks/Core/src/FWCompactVerticalLayout.h"
00021 
00022 //
00023 // constants, enums and typedefs
00024 //
00025 
00026 //
00027 // static data member definitions
00028 //
00029 
00030 //
00031 // constructors and destructor
00032 //
00033 FWCompactVerticalLayout::FWCompactVerticalLayout(TGCompositeFrame* iMain):
00034 TGVerticalLayout(iMain)
00035 {
00036 }
00037 
00038 // FWCompactVerticalLayout::FWCompactVerticalLayout(const FWCompactVerticalLayout& rhs)
00039 // {
00040 //    // do actual copying here;
00041 // }
00042 
00043 FWCompactVerticalLayout::~FWCompactVerticalLayout()
00044 {
00045 }
00046 
00047 //
00048 // assignment operators
00049 //
00050 // const FWCompactVerticalLayout& FWCompactVerticalLayout::operator=(const FWCompactVerticalLayout& rhs)
00051 // {
00052 //   //An exception safe implementation is
00053 //   FWCompactVerticalLayout temp(rhs);
00054 //   swap(rhs);
00055 //
00056 //   return *this;
00057 // }
00058 
00059 //
00060 // member functions
00061 //
00062 //______________________________________________________________________________
00063 void FWCompactVerticalLayout::Layout()
00064 {
00065    // Make a vertical layout of all frames in the list.
00066    
00067    TGFrameElement *ptr;
00068    TGLayoutHints  *layout;
00069    Int_t    nb_expand = 0;
00070    Int_t    top, bottom;
00071    ULong_t  hints;
00072    UInt_t   extra_space = 0;
00073    Int_t    exp = 0;
00074    Int_t    exp_max = 0;
00075    Int_t    remain;
00076    Int_t    x = 0, y = 0;
00077    Int_t    bw = fMain->GetBorderWidth();
00078    TGDimension size(0,0), csize(0,0);
00079    TGDimension msize = fMain->GetSize();
00080    UInt_t pad_left, pad_top, pad_right, pad_bottom;
00081    Int_t size_expand=0, esize_expand=0, rem_expand=0, tmp_expand = 0;
00082    
00083    if (!fList) return;
00084    
00085    fModified = kFALSE;
00086    
00087    bottom = msize.fHeight - (top = bw);
00088    remain = msize.fHeight - (bw << 1);
00089    
00090    std::vector<int> expandSizes;
00091    expandSizes.reserve(fList->GetSize());
00092    TIter next(fList);
00093    while ((ptr = (TGFrameElement *) next())) {
00094       if (ptr->fState & kIsVisible) {
00095          layout = ptr->fLayout;
00096          size = ptr->fFrame->GetDefaultSize();
00097          size.fHeight += layout->GetPadTop() + layout->GetPadBottom();
00098          hints = layout->GetLayoutHints();
00099          if ((hints & kLHintsExpandY) || (hints & kLHintsCenterY)) {
00100             nb_expand++;
00101             exp += size.fHeight;
00102             if (hints & kLHintsExpandY) { 
00103                exp_max = 0;
00104                expandSizes.push_back(size.fHeight);
00105             }
00106             else exp_max = TMath::Max(exp_max, (Int_t)size.fHeight);
00107          } else {
00108             remain -= size.fHeight;
00109             if (remain < 0)
00110                remain = 0;
00111          }
00112       }
00113    }
00114    
00115    if (nb_expand) {
00116       size_expand = remain/nb_expand;
00117       
00118       if (size_expand < exp_max)
00119          esize_expand = (remain - exp)/nb_expand;
00120       rem_expand = remain % nb_expand;
00121    }
00122    
00123    std::sort(expandSizes.begin(), expandSizes.end(),std::less<int>());
00124    //Now see if expanded widgets exceed their max sizes
00125    for(std::vector<int>::iterator it = expandSizes.begin(), itEnd = expandSizes.end();
00126        it != itEnd;
00127        ++it) {
00128       if(*it > size_expand) {
00129          break;
00130       }
00131       remain -= *it;
00132       --nb_expand;
00133       if(remain<0) {remain=0;}
00134       if(nb_expand>0) {
00135          size_expand = remain/nb_expand;
00136       } else {
00137          size_expand=msize.fHeight - (bw << 1);
00138       }
00139    }
00140    
00141    next.Reset();
00142    while ((ptr = (TGFrameElement *) next())) {
00143       if (ptr->fState & kIsVisible) {
00144          hints = (layout = ptr->fLayout)->GetLayoutHints();
00145          csize      = ptr->fFrame->GetDefaultSize();
00146          pad_left   = layout->GetPadLeft();
00147          pad_top    = layout->GetPadTop();
00148          pad_right  = layout->GetPadRight();
00149          pad_bottom = layout->GetPadBottom();
00150          
00151          if (hints & kLHintsRight) {
00152             x = msize.fWidth - bw - csize.fWidth - pad_right;
00153          } else if (hints & kLHintsCenterX) {
00154             x = (msize.fWidth - (bw << 1) - csize.fWidth) >> 1;
00155          } else { // defaults to kLHintsLeft
00156             x = pad_left + bw;
00157          }
00158          
00159          if (hints & kLHintsExpandX) {
00160             size.fWidth = msize.fWidth - (bw << 1) - pad_left - pad_right;
00161             x = pad_left + bw;
00162          } else {
00163             size.fWidth = csize.fWidth;
00164          }
00165          
00166          if (hints & kLHintsExpandY) {
00167             if (size_expand >= exp_max)
00168                if(static_cast<int>(csize.fHeight) > size_expand) {
00169                   size.fHeight = size_expand - pad_top - pad_bottom;
00170                } else {
00171                   size.fHeight = csize.fHeight;
00172                }
00173             else
00174                size.fHeight = csize.fHeight + esize_expand;
00175             
00176             tmp_expand += rem_expand;
00177             if (tmp_expand >= nb_expand) {
00178                size.fHeight++;
00179                tmp_expand -= nb_expand;
00180             }
00181          } else {
00182             size.fHeight = csize.fHeight;
00183             if (hints & kLHintsCenterY) {
00184                if (size_expand >= exp_max) {
00185                   extra_space = (size_expand - pad_top - pad_bottom - size.fHeight) >> 1;
00186                } else {
00187                   extra_space = esize_expand >> 1;
00188                }
00189                y += extra_space;
00190                top += extra_space;
00191             }
00192          }
00193          
00194          if (hints & kLHintsBottom) {
00195             y = bottom - size.fHeight - pad_bottom;
00196             bottom -= size.fHeight + pad_top + pad_bottom;
00197          } else { // kLHintsTop by default
00198             y = top + pad_top;
00199             top += size.fHeight + pad_top + pad_bottom;
00200          }
00201          
00202          if (hints & kLHintsCenterY)
00203             top += extra_space;
00204          
00205          if (size.fWidth > 32768)
00206             size.fWidth = 1;
00207          if (size.fHeight > 32768)
00208             size.fHeight = 1;
00209          ptr->fFrame->MoveResize(x, y, size.fWidth, size.fHeight);
00210          
00211          fModified = fModified || (ptr->fFrame->GetX() != x) || 
00212          (ptr->fFrame->GetY() != y) ||
00213          (ptr->fFrame->GetWidth() != size.fWidth) ||
00214          (ptr->fFrame->GetHeight() != size.fHeight);
00215       }
00216    }
00217 
00218 }
00219 
00220 //______________________________________________________________________________
00221 TGDimension FWCompactVerticalLayout::GetDefaultSize() const
00222 {
00223    // Return default dimension of the vertical layout.
00224    
00225    TGFrameElement *ptr;
00226    TGDimension     size(0,0), msize = fMain->GetSize(), csize;
00227    UInt_t options = fMain->GetOptions();
00228    
00229    if ((options & kFixedWidth) && (options & kFixedHeight))
00230       return msize;
00231    
00232    TIter next(fList);
00233    while ((ptr = (TGFrameElement *) next())) {
00234       if (ptr->fState & kIsVisible) {
00235          csize = ptr->fFrame->GetDefaultSize();
00236          size.fWidth = TMath::Max(size.fWidth, csize.fWidth + ptr->fLayout->GetPadLeft() +
00237                                   ptr->fLayout->GetPadRight());
00238          size.fHeight += csize.fHeight + ptr->fLayout->GetPadTop() +
00239          ptr->fLayout->GetPadBottom();
00240       }
00241    }
00242    
00243    size.fWidth  += fMain->GetBorderWidth() << 1;
00244    size.fHeight += fMain->GetBorderWidth() << 1;
00245    
00246    if (options & kFixedWidth)  size.fWidth  = msize.fWidth;
00247    if (options & kFixedHeight) size.fHeight = msize.fHeight;
00248    
00249    return size;
00250 }
00251 
00252 //
00253 // const member functions
00254 //
00255 
00256 //
00257 // static member functions
00258 //