Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:36

0001 // -*- C++ -*-
0002 //
0003 // Package:     Core
0004 // Class  :     FWCompactVerticalLayout
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:  Chris Jones
0010 //         Created:  Tue Mar 17 12:10:42 CDT 2009
0011 //
0012 
0013 // system include files
0014 #include <algorithm>
0015 #include <iostream>
0016 #include "TGFrame.h"
0017 
0018 // user include files
0019 #include "Fireworks/Core/src/FWCompactVerticalLayout.h"
0020 
0021 //
0022 // constants, enums and typedefs
0023 //
0024 
0025 //
0026 // static data member definitions
0027 //
0028 
0029 //
0030 // constructors and destructor
0031 //
0032 FWCompactVerticalLayout::FWCompactVerticalLayout(TGCompositeFrame *iMain) : TGVerticalLayout(iMain) {}
0033 
0034 // FWCompactVerticalLayout::FWCompactVerticalLayout(const FWCompactVerticalLayout& rhs)
0035 // {
0036 //    // do actual copying here;
0037 // }
0038 
0039 FWCompactVerticalLayout::~FWCompactVerticalLayout() {}
0040 
0041 //
0042 // assignment operators
0043 //
0044 // const FWCompactVerticalLayout& FWCompactVerticalLayout::operator=(const FWCompactVerticalLayout& rhs)
0045 // {
0046 //   //An exception safe implementation is
0047 //   FWCompactVerticalLayout temp(rhs);
0048 //   swap(rhs);
0049 //
0050 //   return *this;
0051 // }
0052 
0053 //
0054 // member functions
0055 //
0056 //______________________________________________________________________________
0057 void FWCompactVerticalLayout::Layout() {
0058   // Make a vertical layout of all frames in the list.
0059 
0060   TGFrameElement *ptr;
0061   TGLayoutHints *layout;
0062   Int_t nb_expand = 0;
0063   Int_t top, bottom;
0064   ULong_t hints;
0065   UInt_t extra_space = 0;
0066   Int_t exp = 0;
0067   Int_t exp_max = 0;
0068   Int_t remain;
0069   Int_t x = 0, y = 0;
0070   Int_t bw = fMain->GetBorderWidth();
0071   TGDimension size(0, 0), csize(0, 0);
0072   TGDimension msize = fMain->GetSize();
0073   UInt_t pad_left, pad_top, pad_right, pad_bottom;
0074   Int_t size_expand = 0, esize_expand = 0, rem_expand = 0, tmp_expand = 0;
0075 
0076   if (!fList)
0077     return;
0078 
0079   fModified = kFALSE;
0080 
0081   bottom = msize.fHeight - (top = bw);
0082   remain = msize.fHeight - (bw << 1);
0083 
0084   std::vector<int> expandSizes;
0085   expandSizes.reserve(fList->GetSize());
0086   TIter next(fList);
0087   while ((ptr = (TGFrameElement *)next())) {
0088     if (ptr->fState & kIsVisible) {
0089       layout = ptr->fLayout;
0090       size = ptr->fFrame->GetDefaultSize();
0091       size.fHeight += layout->GetPadTop() + layout->GetPadBottom();
0092       hints = layout->GetLayoutHints();
0093       if ((hints & kLHintsExpandY) || (hints & kLHintsCenterY)) {
0094         nb_expand++;
0095         exp += size.fHeight;
0096         if (hints & kLHintsExpandY) {
0097           exp_max = 0;
0098           expandSizes.push_back(size.fHeight);
0099         } else
0100           exp_max = TMath::Max(exp_max, (Int_t)size.fHeight);
0101       } else {
0102         remain -= size.fHeight;
0103         if (remain < 0)
0104           remain = 0;
0105       }
0106     }
0107   }
0108 
0109   if (nb_expand) {
0110     size_expand = remain / nb_expand;
0111 
0112     if (size_expand < exp_max)
0113       esize_expand = (remain - exp) / nb_expand;
0114     rem_expand = remain % nb_expand;
0115   }
0116 
0117   std::sort(expandSizes.begin(), expandSizes.end(), std::less<int>());
0118   //Now see if expanded widgets exceed their max sizes
0119   for (std::vector<int>::iterator it = expandSizes.begin(), itEnd = expandSizes.end(); it != itEnd; ++it) {
0120     if (*it > size_expand) {
0121       break;
0122     }
0123     remain -= *it;
0124     --nb_expand;
0125     if (remain < 0) {
0126       remain = 0;
0127     }
0128     if (nb_expand > 0) {
0129       size_expand = remain / nb_expand;
0130     } else {
0131       size_expand = msize.fHeight - (bw << 1);
0132     }
0133   }
0134 
0135   next.Reset();
0136   while ((ptr = (TGFrameElement *)next())) {
0137     if (ptr->fState & kIsVisible) {
0138       hints = (layout = ptr->fLayout)->GetLayoutHints();
0139       csize = ptr->fFrame->GetDefaultSize();
0140       pad_left = layout->GetPadLeft();
0141       pad_top = layout->GetPadTop();
0142       pad_right = layout->GetPadRight();
0143       pad_bottom = layout->GetPadBottom();
0144 
0145       if (hints & kLHintsRight) {
0146         x = msize.fWidth - bw - csize.fWidth - pad_right;
0147       } else if (hints & kLHintsCenterX) {
0148         x = (msize.fWidth - (bw << 1) - csize.fWidth) >> 1;
0149       } else {  // defaults to kLHintsLeft
0150         x = pad_left + bw;
0151       }
0152 
0153       if (hints & kLHintsExpandX) {
0154         size.fWidth = msize.fWidth - (bw << 1) - pad_left - pad_right;
0155         x = pad_left + bw;
0156       } else {
0157         size.fWidth = csize.fWidth;
0158       }
0159 
0160       if (hints & kLHintsExpandY) {
0161         if (size_expand >= exp_max)
0162           if (static_cast<int>(csize.fHeight) > size_expand) {
0163             size.fHeight = size_expand - pad_top - pad_bottom;
0164           } else {
0165             size.fHeight = csize.fHeight;
0166           }
0167         else
0168           size.fHeight = csize.fHeight + esize_expand;
0169 
0170         tmp_expand += rem_expand;
0171         if (tmp_expand >= nb_expand) {
0172           size.fHeight++;
0173           tmp_expand -= nb_expand;
0174         }
0175       } else {
0176         size.fHeight = csize.fHeight;
0177         if (hints & kLHintsCenterY) {
0178           if (size_expand >= exp_max) {
0179             extra_space = (size_expand - pad_top - pad_bottom - size.fHeight) >> 1;
0180           } else {
0181             extra_space = esize_expand >> 1;
0182           }
0183           top += extra_space;
0184         }
0185       }
0186 
0187       if (hints & kLHintsBottom) {
0188         y = bottom - size.fHeight - pad_bottom;
0189         bottom -= size.fHeight + pad_top + pad_bottom;
0190       } else {  // kLHintsTop by default
0191         y = top + pad_top;
0192         top += size.fHeight + pad_top + pad_bottom;
0193       }
0194 
0195       if (hints & kLHintsCenterY)
0196         top += extra_space;
0197 
0198       if (size.fWidth > 32768)
0199         size.fWidth = 1;
0200       if (size.fHeight > 32768)
0201         size.fHeight = 1;
0202       ptr->fFrame->MoveResize(x, y, size.fWidth, size.fHeight);
0203 
0204       fModified = fModified || (ptr->fFrame->GetX() != x) || (ptr->fFrame->GetY() != y) ||
0205                   (ptr->fFrame->GetWidth() != size.fWidth) || (ptr->fFrame->GetHeight() != size.fHeight);
0206     }
0207   }
0208 }
0209 
0210 //______________________________________________________________________________
0211 TGDimension FWCompactVerticalLayout::GetDefaultSize() const {
0212   // Return default dimension of the vertical layout.
0213 
0214   TGFrameElement *ptr;
0215   TGDimension size(0, 0), msize = fMain->GetSize(), csize;
0216   UInt_t options = fMain->GetOptions();
0217 
0218   if ((options & kFixedWidth) && (options & kFixedHeight))
0219     return msize;
0220 
0221   TIter next(fList);
0222   while ((ptr = (TGFrameElement *)next())) {
0223     if (ptr->fState & kIsVisible) {
0224       csize = ptr->fFrame->GetDefaultSize();
0225       size.fWidth = TMath::Max(size.fWidth, csize.fWidth + ptr->fLayout->GetPadLeft() + ptr->fLayout->GetPadRight());
0226       size.fHeight += csize.fHeight + ptr->fLayout->GetPadTop() + ptr->fLayout->GetPadBottom();
0227     }
0228   }
0229 
0230   size.fWidth += fMain->GetBorderWidth() << 1;
0231   size.fHeight += fMain->GetBorderWidth() << 1;
0232 
0233   if (options & kFixedWidth)
0234     size.fWidth = msize.fWidth;
0235   if (options & kFixedHeight)
0236     size.fHeight = msize.fHeight;
0237 
0238   return size;
0239 }
0240 
0241 //
0242 // const member functions
0243 //
0244 
0245 //
0246 // static member functions
0247 //