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