File indexing completed on 2024-04-06 12:11:36
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include <algorithm>
0015 #include <iostream>
0016 #include "TGFrame.h"
0017
0018
0019 #include "Fireworks/Core/src/FWCompactVerticalLayout.h"
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032 FWCompactVerticalLayout::FWCompactVerticalLayout(TGCompositeFrame *iMain) : TGVerticalLayout(iMain) {}
0033
0034
0035
0036
0037
0038
0039 FWCompactVerticalLayout::~FWCompactVerticalLayout() {}
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057 void FWCompactVerticalLayout::Layout() {
0058
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
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 {
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 {
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
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
0243
0244
0245
0246
0247