32 TGPack::TGPack(
const TGWindow *p, UInt_t w, UInt_t h, UInt_t options, Pixel_t back) :
33 TGCompositeFrame(p, w, h, options, back),
35 fUseSplitters (kTRUE),
41 SetCleanup(kLocalCleanup);
47 TGPack::TGPack(TGClient *c, Window_t
id,
const TGWindow *parent) :
48 TGCompositeFrame(c, id, parent),
50 fUseSplitters (kTRUE),
56 SetCleanup(kLocalCleanup);
71 Int_t TGPack::GetAvailableLength()
const
73 Int_t len = fVertical ? GetHeight() : GetWidth();
74 len -= fSplitterLen * (fNVisible - 1);
82 void TGPack::SetFrameLength(TGFrame* f, Int_t len)
85 f->Resize(GetWidth(), len);
87 f->Resize(len, GetHeight());
93 void TGPack::SetFramePosition(TGFrame* f, Int_t pos)
105 void TGPack::CheckSplitterVisibility()
107 TGFrameElementPack *el;
110 while ((el = (TGFrameElementPack*) next()))
112 if (el->fState && el->fSplitFE)
117 if ( el->fSplitFE->fState == 0 ) {
118 el->fSplitFE->fState = 1;
119 el->fSplitFE->fFrame->MapWindow();
125 if (el->fSplitFE->fState) {
126 el->fSplitFE->fState = 0;
127 el->fSplitFE->fFrame->UnmapWindow();
138 void TGPack::ResizeExistingFrames()
140 if (fList->IsEmpty())
144 Int_t nflen = GetAvailableLength();
145 Float_t unit = Float_t(nflen)/fWeightSum;
149 Int_t frameLength = 0;
151 TGFrameElementPack *el;
153 while ((el = (TGFrameElementPack*) next()))
155 if (el->fState && el->fWeight)
157 frameLength = TMath::Nint( unit*(el->fWeight));
158 SetFrameLength(el->fFrame, frameLength);
159 sumFrames += frameLength;
167 Int_t remain = nflen-sumFrames;
168 Int_t step = TMath::Sign(1, remain);
169 TGFrameElementPack *el;
171 while ((el = (TGFrameElementPack*) next()) && remain)
173 if (el->fState && el->fWeight)
175 Int_t l = GetFrameLength(el->fFrame) + step;
178 SetFrameLength(el->fFrame, l);
190 void TGPack::RefitFramesToPack()
195 while ((el = (TGFrameElement *) next()))
198 el->fFrame->Resize(GetWidth(), el->fFrame->GetHeight());
200 el->fFrame->Resize(el->fFrame->GetWidth(), GetHeight());
207 void TGPack::FindFrames(TGFrame* splitter, TGFrameElementPack*& f0, TGFrameElementPack*& f1)
const
209 TGFrameElementPack *el;
212 while ((el = (TGFrameElementPack *) next()))
214 if ( ! (el->fState & kIsVisible) )
217 if (el->fFrame == splitter)
221 f1 = (TGFrameElementPack *) next();
231 void TGPack::AddFrameInternal(TGFrame* f, TGLayoutHints* l, Float_t weight)
234 TGFrameElementPack *sf = 0;
238 s =
new TGHSplitter(
this, GetWidth(), fSplitterLen, kTRUE);
240 s =
new TGVSplitter(
this, fSplitterLen, GetHeight(), kTRUE);
241 s->Connect(
"Moved(Int_t)",
"TGPack",
this,
"HandleSplitterResize(Int_t)");
242 s->Connect(
"DragStarted()",
"TGPack",
this,
"HandleSplitterStart()");
244 sf =
new TGFrameElementPack(s, l ? l : fgDefaultHints, 0);
248 if (fMustCleanup == kDeepCleanup)
249 s->SetCleanup(kDeepCleanup);
254 TGFrameElementPack *el =
new TGFrameElementPack(f, l ? l : fgDefaultHints, weight);
260 if (fMustCleanup == kDeepCleanup)
261 f->SetCleanup(kDeepCleanup);
265 fWeightSum += weight;
267 CheckSplitterVisibility();
268 ResizeExistingFrames();
275 void TGPack::AddFrameWithWeight(TGFrame* f, TGLayoutHints *l, Float_t weight)
277 AddFrameInternal(f, l, weight);
285 void TGPack::AddFrame(TGFrame* f, TGLayoutHints *l)
287 AddFrameInternal(f, l, 1);
294 void TGPack::RemoveFrameInternal(TGFrame* f)
296 TGFrameElementPack *el = (TGFrameElementPack*)FindFrameElement(f);
302 TGFrame* splitter = el->fSplitFE->fFrame;
303 splitter->UnmapWindow();
304 TGCompositeFrame::RemoveFrame(splitter);
306 splitter->ReparentWindow(fClient->GetDefaultRoot());
309 if (el->fState & kIsVisible)
312 fWeightSum -= el->fWeight;
315 TGCompositeFrame::RemoveFrame(f);
317 CheckSplitterVisibility();
318 ResizeExistingFrames();
325 void TGPack::DeleteFrame(TGFrame* f)
327 RemoveFrameInternal(f);
336 void TGPack::RemoveFrame(TGFrame* f)
338 RemoveFrameInternal(f);
345 void TGPack::Dump()
const
347 printf(
"--------------------------------------------------------------\n");
349 TGFrameElementPack *el;
351 while ((el = (TGFrameElementPack *) next()))
353 printf(
"idx[%d] visible(%d) %s \n",cnt, el->fState, el->fFrame->GetName());
356 printf(
"--------------------------------------------------------------\n");
363 void TGPack::ShowFrame(TGFrame* f)
365 TGFrameElementPack *el = (TGFrameElementPack*)FindFrameElement(f);
370 el->fFrame->MapWindow();
375 el->fSplitFE->fFrame->MapWindow();
376 el->fSplitFE->fState = 1;
381 fWeightSum += el->fWeight;
383 CheckSplitterVisibility();
384 ResizeExistingFrames();
393 void TGPack::HideFrame(TGFrame* f)
395 TGFrameElementPack *el = (TGFrameElementPack*) FindFrameElement(f);
400 el->fFrame->UnmapWindow();
405 el->fSplitFE->fFrame->UnmapWindow();
406 el->fSplitFE->fState = 0;
411 fWeightSum -= el->fWeight;
413 CheckSplitterVisibility();
414 ResizeExistingFrames();
425 void TGPack::MapSubwindows()
427 if (!fMapSubwindows) {
436 while ((el = (TGFrameElement *) next())) {
437 if (el->fFrame && el->fState) {
438 el->fFrame->MapWindow();
439 el->fFrame->MapSubwindows();
440 TGFrameElement *fe = el->fFrame->GetFrameElement();
441 if (fe) fe->fState |= kIsVisible;
450 void TGPack::Resize(UInt_t w, UInt_t h)
452 if (w == fWidth && h == fHeight)
return;
456 TGWindow::Resize(fWidth, fHeight);
458 ResizeExistingFrames();
466 void TGPack::MoveResize(Int_t x, Int_t y, UInt_t w, UInt_t h)
468 TGCompositeFrame::Move(x, y);
476 void TGPack::Layout()
483 while ((el = (TGFrameElement *) next()))
487 SetFramePosition(el->fFrame, pos);
488 pos += GetFrameLength(el->fFrame);
489 el->fFrame->Layout();
497 void TGPack::EqualizeFrames()
499 if (fList->IsEmpty())
503 TGFrameElementPack *el;
505 while ((el = (TGFrameElementPack *) next()))
512 ResizeExistingFrames();
519 void TGPack::HandleSplitterStart()
527 void TGPack::HandleSplitterResize(Int_t delta)
529 Int_t available = GetAvailableLength();
530 Int_t min_dec = - (available + fNVisible*2 -1);
534 TGSplitter *s =
dynamic_cast<TGSplitter*
>((TGFrame*) gTQSender);
536 TGFrameElementPack *f0=0, *f1=0;
537 FindFrames(s, f0, f1);
539 if (fDragOverflow < 0)
541 fDragOverflow += delta;
542 if (fDragOverflow > 0) {
543 delta = fDragOverflow;
549 else if (fDragOverflow > 0)
551 fDragOverflow += delta;
552 if (fDragOverflow < 0) {
553 delta = fDragOverflow;
560 Int_t l0 = GetFrameLength(f0->fFrame);
561 Int_t l1 = GetFrameLength(f1->fFrame);
566 fDragOverflow += delta + l0 - 1;
574 fDragOverflow += delta - l1 + 1;
580 SetFrameLength(f0->fFrame, l0);
581 SetFrameLength(f1->fFrame, l1);
582 Float_t weightDelta = Float_t(delta)/available;
583 weightDelta *= fWeightSum;
584 f0->fWeight += weightDelta;
585 f1->fWeight -= weightDelta;
587 ResizeExistingFrames();
597 void TGPack::SetVertical(Bool_t x)
603 while ( ! fList->IsEmpty())
605 TGFrameElement *el = (TGFrameElement*) fList->At(1);
606 TGFrame *f = el->fFrame;
607 if ( ! (el->fState & kIsVisible) )
608 f->SetBit(kTempFrame);
609 RemoveFrameInternal(f);
613 while ( ! list.IsEmpty())
615 TGFrame* f = (TGFrame*) list.First();
617 if (f->TestBit(kTempFrame)) {
618 f->ResetBit(kTempFrame);