CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FWCompactVerticalLayout.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : FWCompactVerticalLayout
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Chris Jones
10 // Created: Tue Mar 17 12:10:42 CDT 2009
11 //
12 
13 // system include files
14 #include <algorithm>
15 #include <iostream>
16 #include "TGFrame.h"
17 
18 // user include files
20 
21 //
22 // constants, enums and typedefs
23 //
24 
25 //
26 // static data member definitions
27 //
28 
29 //
30 // constructors and destructor
31 //
33 TGVerticalLayout(iMain)
34 {
35 }
36 
37 // FWCompactVerticalLayout::FWCompactVerticalLayout(const FWCompactVerticalLayout& rhs)
38 // {
39 // // do actual copying here;
40 // }
41 
43 {
44 }
45 
46 //
47 // assignment operators
48 //
49 // const FWCompactVerticalLayout& FWCompactVerticalLayout::operator=(const FWCompactVerticalLayout& rhs)
50 // {
51 // //An exception safe implementation is
52 // FWCompactVerticalLayout temp(rhs);
53 // swap(rhs);
54 //
55 // return *this;
56 // }
57 
58 //
59 // member functions
60 //
61 //______________________________________________________________________________
63 {
64  // Make a vertical layout of all frames in the list.
65 
66  TGFrameElement *ptr;
67  TGLayoutHints *layout;
68  Int_t nb_expand = 0;
69  Int_t top, bottom;
70  ULong_t hints;
71  UInt_t extra_space = 0;
72  Int_t exp = 0;
73  Int_t exp_max = 0;
74  Int_t remain;
75  Int_t x = 0, y = 0;
76  Int_t bw = fMain->GetBorderWidth();
77  TGDimension size(0,0), csize(0,0);
78  TGDimension msize = fMain->GetSize();
79  UInt_t pad_left, pad_top, pad_right, pad_bottom;
80  Int_t size_expand=0, esize_expand=0, rem_expand=0, tmp_expand = 0;
81 
82  if (!fList) return;
83 
84  fModified = kFALSE;
85 
86  bottom = msize.fHeight - (top = bw);
87  remain = msize.fHeight - (bw << 1);
88 
89  std::vector<int> expandSizes;
90  expandSizes.reserve(fList->GetSize());
91  TIter next(fList);
92  while ((ptr = (TGFrameElement *) next())) {
93  if (ptr->fState & kIsVisible) {
94  layout = ptr->fLayout;
95  size = ptr->fFrame->GetDefaultSize();
96  size.fHeight += layout->GetPadTop() + layout->GetPadBottom();
97  hints = layout->GetLayoutHints();
98  if ((hints & kLHintsExpandY) || (hints & kLHintsCenterY)) {
99  nb_expand++;
100  exp += size.fHeight;
101  if (hints & kLHintsExpandY) {
102  exp_max = 0;
103  expandSizes.push_back(size.fHeight);
104  }
105  else exp_max = TMath::Max(exp_max, (Int_t)size.fHeight);
106  } else {
107  remain -= size.fHeight;
108  if (remain < 0)
109  remain = 0;
110  }
111  }
112  }
113 
114  if (nb_expand) {
115  size_expand = remain/nb_expand;
116 
117  if (size_expand < exp_max)
118  esize_expand = (remain - exp)/nb_expand;
119  rem_expand = remain % nb_expand;
120  }
121 
122  std::sort(expandSizes.begin(), expandSizes.end(),std::less<int>());
123  //Now see if expanded widgets exceed their max sizes
124  for(std::vector<int>::iterator it = expandSizes.begin(), itEnd = expandSizes.end();
125  it != itEnd;
126  ++it) {
127  if(*it > size_expand) {
128  break;
129  }
130  remain -= *it;
131  --nb_expand;
132  if(remain<0) {remain=0;}
133  if(nb_expand>0) {
134  size_expand = remain/nb_expand;
135  } else {
136  size_expand=msize.fHeight - (bw << 1);
137  }
138  }
139 
140  next.Reset();
141  while ((ptr = (TGFrameElement *) next())) {
142  if (ptr->fState & kIsVisible) {
143  hints = (layout = ptr->fLayout)->GetLayoutHints();
144  csize = ptr->fFrame->GetDefaultSize();
145  pad_left = layout->GetPadLeft();
146  pad_top = layout->GetPadTop();
147  pad_right = layout->GetPadRight();
148  pad_bottom = layout->GetPadBottom();
149 
150  if (hints & kLHintsRight) {
151  x = msize.fWidth - bw - csize.fWidth - pad_right;
152  } else if (hints & kLHintsCenterX) {
153  x = (msize.fWidth - (bw << 1) - csize.fWidth) >> 1;
154  } else { // defaults to kLHintsLeft
155  x = pad_left + bw;
156  }
157 
158  if (hints & kLHintsExpandX) {
159  size.fWidth = msize.fWidth - (bw << 1) - pad_left - pad_right;
160  x = pad_left + bw;
161  } else {
162  size.fWidth = csize.fWidth;
163  }
164 
165  if (hints & kLHintsExpandY) {
166  if (size_expand >= exp_max)
167  if(static_cast<int>(csize.fHeight) > size_expand) {
168  size.fHeight = size_expand - pad_top - pad_bottom;
169  } else {
170  size.fHeight = csize.fHeight;
171  }
172  else
173  size.fHeight = csize.fHeight + esize_expand;
174 
175  tmp_expand += rem_expand;
176  if (tmp_expand >= nb_expand) {
177  size.fHeight++;
178  tmp_expand -= nb_expand;
179  }
180  } else {
181  size.fHeight = csize.fHeight;
182  if (hints & kLHintsCenterY) {
183  if (size_expand >= exp_max) {
184  extra_space = (size_expand - pad_top - pad_bottom - size.fHeight) >> 1;
185  } else {
186  extra_space = esize_expand >> 1;
187  }
188  top += extra_space;
189  }
190  }
191 
192  if (hints & kLHintsBottom) {
193  y = bottom - size.fHeight - pad_bottom;
194  bottom -= size.fHeight + pad_top + pad_bottom;
195  } else { // kLHintsTop by default
196  y = top + pad_top;
197  top += size.fHeight + pad_top + pad_bottom;
198  }
199 
200  if (hints & kLHintsCenterY)
201  top += extra_space;
202 
203  if (size.fWidth > 32768)
204  size.fWidth = 1;
205  if (size.fHeight > 32768)
206  size.fHeight = 1;
207  ptr->fFrame->MoveResize(x, y, size.fWidth, size.fHeight);
208 
209  fModified = fModified || (ptr->fFrame->GetX() != x) ||
210  (ptr->fFrame->GetY() != y) ||
211  (ptr->fFrame->GetWidth() != size.fWidth) ||
212  (ptr->fFrame->GetHeight() != size.fHeight);
213  }
214  }
215 
216 }
217 
218 //______________________________________________________________________________
220 {
221  // Return default dimension of the vertical layout.
222 
223  TGFrameElement *ptr;
224  TGDimension size(0,0), msize = fMain->GetSize(), csize;
225  UInt_t options = fMain->GetOptions();
226 
227  if ((options & kFixedWidth) && (options & kFixedHeight))
228  return msize;
229 
230  TIter next(fList);
231  while ((ptr = (TGFrameElement *) next())) {
232  if (ptr->fState & kIsVisible) {
233  csize = ptr->fFrame->GetDefaultSize();
234  size.fWidth = TMath::Max(size.fWidth, csize.fWidth + ptr->fLayout->GetPadLeft() +
235  ptr->fLayout->GetPadRight());
236  size.fHeight += csize.fHeight + ptr->fLayout->GetPadTop() +
237  ptr->fLayout->GetPadBottom();
238  }
239  }
240 
241  size.fWidth += fMain->GetBorderWidth() << 1;
242  size.fHeight += fMain->GetBorderWidth() << 1;
243 
244  if (options & kFixedWidth) size.fWidth = msize.fWidth;
245  if (options & kFixedHeight) size.fHeight = msize.fHeight;
246 
247  return size;
248 }
249 
250 //
251 // const member functions
252 //
253 
254 //
255 // static member functions
256 //
virtual TGDimension GetDefaultSize() const
T Max(T a, T b)
Definition: MathUtil.h:44
static const std::string kIsVisible("isVisible")
FWCompactVerticalLayout(TGCompositeFrame *iMain)
tuple size
Write out results.