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