Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGPack.cxx
Go to the documentation of this file.
1// @(#)root/eve:$Id$
2// Author: Matevz Tadel 2007
3
4/*************************************************************************
5 * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#include "TGPack.h"
13#include "TGSplitter.h"
14#include "TMath.h"
15
16
17/** \class TGPack
18 \ingroup guiwidgets
19
20Stack of frames in horizontal (default) or vertical stack.
21The splitters are placed between the neighbouring frames so that
22they can be resized by the user.
23When the whole pack is resized, frames are scaled proportionally to
24their previous size.
25
26When frames are left in pack at destruction time, they will be
27deleted via local-cleanup.
28
29*/
30
31
32
33////////////////////////////////////////////////////////////////////////////////
34/// Constructor.
35
37 TGCompositeFrame(p, w, h, options, back),
38 fVertical (kTRUE),
39 fUseSplitters (kTRUE),
40 fSplitterLen (4),
41 fDragOverflow (0),
42 fWeightSum(0),
43 fNVisible(0)
44{
46}
47
48////////////////////////////////////////////////////////////////////////////////
49/// Constructor.
50
52 TGCompositeFrame(c, id, parent),
53 fVertical (kTRUE),
54 fUseSplitters (kTRUE),
55 fSplitterLen (4),
56 fDragOverflow (0),
57 fWeightSum (0.0),
58 fNVisible (0)
59{
61}
62
63////////////////////////////////////////////////////////////////////////////////
64/// Destructor.
65
69
70//------------------------------------------------------------------------------
71
72////////////////////////////////////////////////////////////////////////////////
73/// Return length of entire frame without splitters.
74
76{
78 len -= fSplitterLen * (fNVisible - 1);
79
80 return len;
81}
82
83////////////////////////////////////////////////////////////////////////////////
84/// Set pack-wise length of frame f.
85
87{
88 if (fVertical)
89 f->Resize(GetWidth(), len);
90 else
91 f->Resize(len, GetHeight());
92}
93
94////////////////////////////////////////////////////////////////////////////////
95/// Set pack-wise position of frame f.
96
98{
99 if (fVertical)
100 f->Move(0, pos);
101 else
102 f->Move(pos, 0);
103}
104
105////////////////////////////////////////////////////////////////////////////////
106/// Check if splitter of first visible frame is hidden.
107/// Check if the next following visible splitter is visible.
108
110{
112 TIter next(fList);
113 Int_t rvf = 0;
114 while ((el = (TGFrameElementPack*) next())) {
115 if (el->fState && el->fSplitFE) {
116 if (rvf) {
117 // unmap first slider if necessary
118 if ( el->fSplitFE->fState == 0 ) {
119 el->fSplitFE->fState = 1;
120 el->fSplitFE->fFrame->MapWindow();
121 }
122 } else {
123 // show slider in next visible frame
124 if (el->fSplitFE->fState) {
125 el->fSplitFE->fState = 0;
126 el->fSplitFE->fFrame->UnmapWindow();
127 }
128 }
129 ++rvf;
130 }
131 }
132}
133
134////////////////////////////////////////////////////////////////////////////////
135/// Resize (shrink or expand) existing frames by amount in total.
136
138{
139 if (fList->IsEmpty())
140 return;
141
142 // get unitsize
145
146 // set frame sizes
147 Int_t sumFrames = 0;
148 Int_t frameLength = 0;
149 {
151 TIter next(fList);
152 while ((el = (TGFrameElementPack*) next())) {
153 if (el->fState) {
154 frameLength = TMath::Nint( unit*(el->fWeight));
155 SetFrameLength(el->fFrame, frameLength);
157 }
158 }
159 }
160
161 // redistribute the remain
162 {
163 // printf("available %d total %d \n", nflen, sumFrames);
165 Int_t step = TMath::Sign(1, remain);
167 TIter next(fList);
168 while ((el = (TGFrameElementPack*) next()) && remain) {
169 if (el->fState) {
170 Int_t l = GetFrameLength(el->fFrame) + step;
171 if (l > 0) {
172 SetFrameLength(el->fFrame, l);
173 remain -= step;
174 }
175 }
176 }
177 }
179}
180
181////////////////////////////////////////////////////////////////////////////////
182/// Refit existing frames to pack size.
183
185{
187 TIter next(fList);
188
189 while ((el = (TGFrameElement *) next())) {
190 if (fVertical)
191 el->fFrame->Resize(GetWidth(), el->fFrame->GetHeight());
192 else
193 el->fFrame->Resize(el->fFrame->GetWidth(), GetHeight());
194 }
195}
196
197////////////////////////////////////////////////////////////////////////////////
198/// Find frames around splitter and return them f0 (previous) and f1 (next).
199
201{
203 TIter next(fList);
204
205 while ((el = (TGFrameElementPack *) next())) {
206 if ( ! (el->fState & kIsVisible) )
207 continue;
208
209 if (el->fFrame == splitter)
210 break;
211 f0 = el;
212 }
213 f1 = (TGFrameElementPack *) next();
214}
215
216////////////////////////////////////////////////////////////////////////////////
217/// Add frame f at the end.
218/// LayoutHints are ignored in TGPack.
219
221{
222 // add splitter
224 if (fUseSplitters) {
225 TGSplitter* s = 0;
226 if (fVertical)
227 s = new TGHSplitter(this, GetWidth(), fSplitterLen, kTRUE);
228 else
229 s = new TGVSplitter(this, fSplitterLen, GetHeight(), kTRUE);
230 s->Connect("Moved(Int_t)", "TGPack", this, "HandleSplitterResize(Int_t)");
231 s->Connect("DragStarted()", "TGPack", this, "HandleSplitterStart()");
232
233 sf = new TGFrameElementPack(s, l ? l : fgDefaultHints, 0);
234 fList->Add(sf);
235 // in case of recursive cleanup, propagate cleanup setting to all
236 // child composite frames
239 s->MapWindow();
240 }
241
242 // instead TGCopositeFrame::AddFrame
244 el->fSplitFE = sf;
245 fList->Add(el);
246
247 // in case of recursive cleanup, propagate cleanup setting to all
248 // child composite frames
250 f->SetCleanup(kDeepCleanup);
251 f->MapWindow();
252
253 fNVisible ++;
254 fWeightSum += weight;
255
258}
259
260////////////////////////////////////////////////////////////////////////////////
261/// Add frame f at the end with given weight.
262/// LayoutHints are ignored in TGPack.
263
265{
266 AddFrameInternal(f, l, weight);
267 Layout();
268}
269
270////////////////////////////////////////////////////////////////////////////////
271/// Add frame f at the end with default weight.
272/// LayoutHints are ignored in TGPack.
273
275{
276 AddFrameInternal(f, l, 1);
277 Layout();
278}
279
280////////////////////////////////////////////////////////////////////////////////
281/// Remove frame f.
282
284{
286
287 if (!el) return;
288
289 if (fUseSplitters) {
290 TGFrame* splitter = el->fSplitFE->fFrame;
291 splitter->UnmapWindow();
293 // This is needed so that splitter window gets destroyed on server.
294 splitter->ReparentWindow(fClient->GetDefaultRoot());
295 delete splitter;
296 }
297 if (el->fState & kIsVisible) {
298 f->UnmapWindow();
299 fWeightSum -= el->fWeight;
300 --fNVisible;
301 }
303
306}
307
308////////////////////////////////////////////////////////////////////////////////
309/// Remove frame f and refit existing frames to pack size.
310/// Frame is deleted.
311
313{
315 delete f;
316 Layout();
317}
318
319////////////////////////////////////////////////////////////////////////////////
320/// Remove frame f and refit existing frames to pack size.
321/// Frame is not deleted.
322
328
329////////////////////////////////////////////////////////////////////////////////
330/// Print sub frame info.
331
332void TGPack::Dump() const
333{
334 printf("--------------------------------------------------------------\n");
335 Int_t cnt = 0;
337 TIter next(fList);
338 while ((el = (TGFrameElementPack *) next())) {
339 printf("idx[%d] visible(%d) %s \n",cnt, el->fState, el->fFrame->GetName());
340 cnt++;
341 }
342 printf("--------------------------------------------------------------\n");
343}
344
345////////////////////////////////////////////////////////////////////////////////
346/// Show sub frame.
347/// Virtual from TGCompositeFrame.
348
350{
352 if (el) {
353 //show
354 el->fState = 1;
355 el->fFrame->MapWindow();
356
357 // show splitter
358 if (fUseSplitters) {
359 el->fSplitFE->fFrame->MapWindow();
360 el->fSplitFE->fState = 1;
361 }
362
363 // Dump();
364 fNVisible++;
365 fWeightSum += el->fWeight;
366
369 Layout();
370 }
371}
372
373////////////////////////////////////////////////////////////////////////////////
374/// Hide sub frame.
375/// Virtual from TGCompositeFrame.
376
378{
380 if (el) {
381 // hide real frame
382 el->fState = 0;
383 el->fFrame->UnmapWindow();
384
385 // hide splitter
386 if (fUseSplitters) {
387 el->fSplitFE->fFrame->UnmapWindow();
388 el->fSplitFE->fState = 0;
389 }
390
391 // Dump();
392 fNVisible--;
393 fWeightSum -= el->fWeight;
394
397 Layout();
398 }
399}
400
401
402////////////////////////////////////////////////////////////////////////////////
403/// Virtual method of TGcompositeFrame.
404/// Map all sub windows that are part of the composite frame.
405
407{
408 if (!fMapSubwindows) {
409 return;
410 }
411
412 if (!fList) return;
413
415 TIter next(fList);
416
417 while ((el = (TGFrameElement *) next())) {
418 if (el->fFrame && el->fState) {
419 el->fFrame->MapWindow();
420 el->fFrame->MapSubwindows();
421 TGFrameElement *fe = el->fFrame->GetFrameElement();
422 if (fe) fe->fState |= kIsVisible;
423 }
424 }
425}
426
427////////////////////////////////////////////////////////////////////////////////
428/// Resize the pack.
429/// Contents is resized proportionally.
430
432{
433 if (w == fWidth && h == fHeight) return;
434
435 fWidth = w;
436 fHeight = h;
438
440
441 Layout();
442}
443
444////////////////////////////////////////////////////////////////////////////////
445/// Move and resize the pack.
446
452
453////////////////////////////////////////////////////////////////////////////////
454/// Reposition the frames so that they fit correctly.
455/// LayoutHints are ignored.
456
458{
459 Int_t pos = 0;
460
462 TIter next(fList);
463
464 while ((el = (TGFrameElement *) next())) {
465 if (el->fState) {
466 SetFramePosition(el->fFrame, pos);
467 pos += GetFrameLength(el->fFrame);
468 el->fFrame->Layout();
469 }
470 }
471}
472
473////////////////////////////////////////////////////////////////////////////////
474/// Refit existing frames so that their lengths are equal.
475
477{
478 if (fList->IsEmpty())
479 return;
480
481 fWeightSum = 0;
483 TIter next(fList);
484 while ((el = (TGFrameElementPack *) next())) {
485 el->fWeight = 1;
486 if (el->fState)
487 fWeightSum ++;
488 }
489
491 Layout();
492}
493
494////////////////////////////////////////////////////////////////////////////////
495/// Called when splitter drag starts.
496
501
502////////////////////////////////////////////////////////////////////////////////
503/// Handle resize events from splitters.
504
506{
508 Int_t min_dec = - (available + fNVisible*2 -1);
509 if (delta < min_dec)
510 delta = min_dec;
511
512 TGSplitter *s = dynamic_cast<TGSplitter*>((TGFrame*) gTQSender);
513
514 TGFrameElementPack *f0 = nullptr, *f1 = nullptr;
515 FindFrames(s, f0, f1);
516 if (!f0 || !f1)
517 return;
518
519 if (fDragOverflow < 0) {
520 fDragOverflow += delta;
521 if (fDragOverflow > 0) {
522 delta = fDragOverflow;
523 fDragOverflow = 0;
524 } else {
525 return;
526 }
527 } else if (fDragOverflow > 0) {
528 fDragOverflow += delta;
529 if (fDragOverflow < 0) {
530 delta = fDragOverflow;
531 fDragOverflow = 0;
532 } else {
533 return;
534 }
535 }
536
537 Int_t l0 = GetFrameLength(f0->fFrame);
538 Int_t l1 = GetFrameLength(f1->fFrame);
539 if (delta < 0) {
540 if (l0 - 1 < -delta) {
541 fDragOverflow += delta + l0 - 1;
542 delta = -l0 + 1;
543 }
544 } else {
545 if (l1 - 1 < delta) {
546 fDragOverflow += delta - l1 + 1;
547 delta = l1 - 1;
548 }
549 }
550 l0 += delta;
551 l1 -= delta;
552 SetFrameLength(f0->fFrame, l0);
553 SetFrameLength(f1->fFrame, l1);
556 f0->fWeight += weightDelta;
557 f1->fWeight -= weightDelta;
558
560 Layout();
561}
562
563
564////////////////////////////////////////////////////////////////////////////////
565/// Sets the vertical flag and reformats the back to new stacking
566/// direction.
567
569{
570 if (x == fVertical)
571 return;
572
573 TList list;
574 while ( ! fList->IsEmpty()) {
576 TGFrame *f = el->fFrame;
577 if ( ! (el->fState & kIsVisible) )
578 f->SetBit(kTempFrame);
580 list.Add(f);
581 }
582 fVertical = x;
583 while ( ! list.IsEmpty()) {
584 TGFrame* f = (TGFrame*) list.First();
586 if (f->TestBit(kTempFrame)) {
587 f->ResetBit(kTempFrame);
588 HideFrame(f);
589 }
590 list.RemoveFirst();
591 }
592 Layout();
593}
Handle_t Window_t
Window handle.
Definition GuiTypes.h:29
@ kTempFrame
Definition GuiTypes.h:393
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:40
#define f(i)
Definition RSha256.hxx:104
#define c(i)
Definition RSha256.hxx:101
#define h(i)
Definition RSha256.hxx:106
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
@ kLocalCleanup
Definition TGFrame.h:41
@ kDeepCleanup
Definition TGFrame.h:42
@ kIsVisible
Definition TGFrame.h:33
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
R__EXTERN void * gTQSender
Definition TQObject.h:46
virtual Bool_t IsEmpty() const
Window client.
Definition TGClient.h:37
const TGWindow * GetDefaultRoot() const
Returns the root (i.e.
Definition TGClient.cxx:233
The base class for composite widgets (menu bars, list boxes, etc.).
Definition TGFrame.h:289
virtual TGFrameElement * FindFrameElement(TGFrame *f) const
Find frame-element holding frame f.
Definition TGFrame.cxx:1086
Int_t fMustCleanup
cleanup mode (see EFrameCleanup)
Definition TGFrame.h:296
Bool_t fMapSubwindows
kTRUE - map subwindows
Definition TGFrame.h:297
TList * fList
container of frame elements
Definition TGFrame.h:294
void SetCleanup(Int_t mode=kLocalCleanup) override
Turn on automatic cleanup of child frames in dtor.
Definition TGFrame.cxx:1064
virtual void RemoveFrame(TGFrame *f)
Remove frame from composite frame.
Definition TGFrame.cxx:1141
static TGLayoutHints * fgDefaultHints
Definition TGFrame.h:299
A subclasses of TGWindow, and is used as base class for some simple widgets (buttons,...
Definition TGFrame.h:80
UInt_t fHeight
frame height
Definition TGFrame.h:88
void MapWindow() override
map window
Definition TGFrame.h:206
void Move(Int_t x, Int_t y) override
Move frame.
Definition TGFrame.cxx:585
UInt_t fWidth
frame width
Definition TGFrame.h:87
UInt_t GetHeight() const
Definition TGFrame.h:227
virtual void SetCleanup(Int_t=kLocalCleanup)
Definition TGFrame.h:219
UInt_t GetWidth() const
Definition TGFrame.h:226
This class describes layout hints used by the layout classes.
Definition TGLayout.h:50
TGClient * fClient
Connection to display server.
Definition TGObject.h:25
Bool_t fVertical
Definition TGPack.h:46
void MapSubwindows() override
Virtual method of TGcompositeFrame.
Definition TGPack.cxx:406
void RemoveFrameInternal(TGFrame *f)
Remove frame f.
Definition TGPack.cxx:283
void ResizeExistingFrames()
Resize (shrink or expand) existing frames by amount in total.
Definition TGPack.cxx:137
void MoveResize(Int_t x, Int_t y, UInt_t w=0, UInt_t h=0) override
Move and resize the pack.
Definition TGPack.cxx:447
Int_t GetAvailableLength() const
Return length of entire frame without splitters.
Definition TGPack.cxx:75
void Dump() const override
Print sub frame info.
Definition TGPack.cxx:332
Int_t fSplitterLen
Definition TGPack.h:48
virtual void DeleteFrame(TGFrame *f)
Remove frame f and refit existing frames to pack size.
Definition TGPack.cxx:312
Int_t GetFrameLength(const TGFrame *f) const
Definition TGPack.h:55
virtual void AddFrameWithWeight(TGFrame *f, TGLayoutHints *l, Float_t w)
Add frame f at the end with given weight.
Definition TGPack.cxx:264
void RefitFramesToPack()
Refit existing frames to pack size.
Definition TGPack.cxx:184
void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr) override
Add frame f at the end with default weight.
Definition TGPack.cxx:274
~TGPack() override
Destructor.
Definition TGPack.cxx:66
void EqualizeFrames()
Refit existing frames so that their lengths are equal.
Definition TGPack.cxx:476
void HandleSplitterStart()
Called when splitter drag starts.
Definition TGPack.cxx:497
Float_t fWeightSum
total sum of sub frame weights
Definition TGPack.h:52
void RemoveFrame(TGFrame *f) override
Remove frame f and refit existing frames to pack size.
Definition TGPack.cxx:323
TGPack(const TGPack &)=delete
void AddFrameInternal(TGFrame *f, TGLayoutHints *l=nullptr, Float_t weight=1)
Add frame f at the end.
Definition TGPack.cxx:220
Bool_t fUseSplitters
Definition TGPack.h:47
void SetVertical(Bool_t x)
Sets the vertical flag and reformats the back to new stacking direction.
Definition TGPack.cxx:568
void HandleSplitterResize(Int_t delta)
Handle resize events from splitters.
Definition TGPack.cxx:505
void SetFrameLength(TGFrame *f, Int_t len)
Set pack-wise length of frame f.
Definition TGPack.cxx:86
void Resize(UInt_t w=0, UInt_t h=0) override
Resize the pack.
Definition TGPack.cxx:431
void SetFramePosition(TGFrame *f, Int_t pos)
Set pack-wise position of frame f.
Definition TGPack.cxx:97
void CheckSplitterVisibility()
Check if splitter of first visible frame is hidden.
Definition TGPack.cxx:109
Int_t fNVisible
number of visible frames
Definition TGPack.h:53
void Layout() override
Reposition the frames so that they fit correctly.
Definition TGPack.cxx:457
Int_t fDragOverflow
!
Definition TGPack.h:50
void ShowFrame(TGFrame *f) override
Show sub frame.
Definition TGPack.cxx:349
void HideFrame(TGFrame *f) override
Hide sub frame.
Definition TGPack.cxx:377
void FindFrames(TGFrame *splitter, TGFrameElementPack *&f0, TGFrameElementPack *&f1) const
Find frames around splitter and return them f0 (previous) and f1 (next).
Definition TGPack.cxx:200
A splitter allows the frames left and right or above and below of it to be resized.
Definition TGSplitter.h:19
ROOT GUI Window base class.
Definition TGWindow.h:23
virtual void Resize(UInt_t w, UInt_t h)
Resize the window.
Definition TGWindow.cxx:277
A doubly linked list.
Definition TList.h:38
void Add(TObject *obj) override
Definition TList.h:81
TObject * At(Int_t idx) const override
Returns the object at position idx. Returns 0 if idx is out of range.
Definition TList.cxx:354
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot.
Definition TQObject.cxx:865
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
TF1 * f1
Definition legend1.C:11
Int_t Nint(T x)
Round to nearest integer. Rounds half integers to the nearest even integer.
Definition TMath.h:704
T1 Sign(T1 a, T2 b)
Returns a value with the magnitude of a and the sign of b.
Definition TMathBase.h:176
TLine l
Definition textangle.C:4