Logo ROOT   6.12/07
Reference Guide
TGLayout.cxx
Go to the documentation of this file.
1 // @(#)root/gui:$Id$
2 // Author: Fons Rademakers 02/01/98
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, 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 
13  This source is based on Xclass95, a Win95-looking GUI toolkit.
14  Copyright (C) 1996, 1997 David Barth, Ricky Ralston, Hector Peraza.
15 
16  Xclass95 is free software; you can redistribute it and/or
17  modify it under the terms of the GNU Library General Public
18  License as published by the Free Software Foundation; either
19  version 2 of the License, or (at your option) any later version.
20 
21 **************************************************************************/
22 
23 //////////////////////////////////////////////////////////////////////////
24 // //
25 // A number of different layout classes (TGLayoutManager, //
26 // TGVerticalLayout, TGHorizontalLayout, TGLayoutHints, etc.). //
27 // //
28 // //
29 // Concerning the TGMatrixLayout class: //
30 // //
31 // It arranges frames in a matrix-like way. //
32 // This manager provides : //
33 // - a column number (0 means unlimited) //
34 // - a row number (0 means unlimited) //
35 // - horizontal & vertical separators //
36 // //
37 // Notes : If both column and row are fixed values, any remaining //
38 // frames outside the count won't be managed. //
39 // Unlimited rows means the frame can expand downward //
40 // (the default behaviour in most UI). //
41 // Both unlimited rows and columns is undefined (read: will //
42 // crash the algorithm ;-). //
43 // With fixed dimensions, frames are always arranged in rows. //
44 // That is: 1st frame is at position (0,0), next one is at //
45 // row(0), column(1) and so on... //
46 // When specifying one dimension as unlimited (i.e. row=0 or //
47 // column=0) the frames are arranged according to the direction //
48 // of the fixed dimension. This layout manager does not make //
49 // use of TGLayoutHints. //
50 // //
51 //////////////////////////////////////////////////////////////////////////
52 
53 #include "TGLayout.h"
54 #include "TGFrame.h"
55 #include "TList.h"
56 #include "Riostream.h"
57 
58 
69 
70 
71 ////////////////////////////////////////////////////////////////////////////////
72 /// Constructor.
73 
75 {
76  fLayout = 0;
77  fFrame = f;
78  if (f) f->SetFrameElement(this);
79 
80  if (l) {
81  l->AddReference();
82  fLayout = l;
83  l->fPrev = l->fFE;
84  l->fFE = this;
85  }
86  fState = 1;
87 }
88 
89 ////////////////////////////////////////////////////////////////////////////////
90 /// Destructor. Decrease ref. count of fLayout.
91 
93 {
94 }
95 
96 ////////////////////////////////////////////////////////////////////////////////
97 /// Print this frame element.
98 
99 void TGFrameElement::Print(Option_t *option) const
100 {
101  TObject::Print(option);
102 
103  std::cout << "\t";
104  if (fFrame) {
105  std::cout << fFrame->ClassName() << "::" << fFrame->GetName();
106  }
107  if (fLayout) {
108  fLayout->Print(option);
109  }
110  std::cout << std::endl;
111 }
112 
113 ////////////////////////////////////////////////////////////////////////////////
114 /// Constructor.
115 
117 {
121  SetRefCount(0);
122  fFE = lh.fFE; fPrev = lh.fPrev;
123 }
124 
125 ////////////////////////////////////////////////////////////////////////////////
126 /// Destructor.
127 
129 {
130 }
131 
132 ////////////////////////////////////////////////////////////////////////////////
133 /// Update layout hints of frame elements.
134 
136 {
137  if (fFE) fFE->fLayout = l;
138  else return;
139 
140  TGFrameElement *p = fPrev;
141 
142  while (p && p->fLayout) {
143  p->fLayout = l;
144  p = p->fLayout->fPrev;
145  }
146 }
147 
148 ////////////////////////////////////////////////////////////////////////////////
149 /// Printing.
150 
152 {
153  Bool_t bor = kFALSE;
154 
155  if (fLayoutHints & kLHintsLeft) {
156  std::cout << "kLHintsLeft";
157  bor = kTRUE;
158  }
160  if (bor) std::cout << " | ";
161  std::cout << "kLHintsCenterX";
162  bor = kTRUE;
163  }
164  if (fLayoutHints & kLHintsRight) {
165  if (bor) std::cout << " | ";
166  std::cout << "kLHintsRight";
167  bor = kTRUE;
168  }
169  if (fLayoutHints & kLHintsTop) {
170  if (bor) std::cout << " | ";
171  std::cout << "kLHintsTop";
172  bor = kTRUE;
173  }
175  if (bor) std::cout << " | ";
176  std::cout << "kLHintsCenterY";
177  bor = kTRUE;
178  }
179  if (fLayoutHints & kLHintsBottom) {
180  if (bor) std::cout << " | ";
181  std::cout << "kLHintsBottom";
182  bor = kTRUE;
183  }
185  if (bor) std::cout << " | ";
186  std::cout << "kLHintsExpandX";
187  bor = kTRUE;
188  }
190  if (bor) std::cout << " | ";
191  std::cout << "kLHintsExpandY";
192  bor = kTRUE;
193  }
194  if (fLayoutHints == kLHintsNoHints) {
195  if (bor) std::cout << " | ";
196  std::cout << "kLHintsNoHints";
197  }
198  std::cout << ", fPadtop=" << fPadtop;
199  std::cout << ", fPadbottom=" << fPadbottom;
200  std::cout << ", fPadleft=" << fPadleft;
201  std::cout << ", fPadright=" << fPadright;
202  std::cout << std::endl;
203 }
204 
205 ////////////////////////////////////////////////////////////////////////////////
206 /// Create vertical layout manager.
207 
209 {
210  fMain = main;
211  fList = fMain->GetList();
212 }
213 
214 ////////////////////////////////////////////////////////////////////////////////
215 /// Make a vertical layout of all frames in the list.
216 
218 {
219  TGFrameElement *ptr;
220  TGLayoutHints *layout;
221  Int_t nb_expand = 0;
222  Int_t top, bottom;
223  ULong_t hints;
224  UInt_t extra_space = 0;
225  Int_t exp = 0;
226  Int_t exp_max = 0;
227  Int_t remain;
228  Int_t x = 0, y = 0;
229  Int_t bw = fMain->GetBorderWidth();
230  TGDimension size(0,0), csize(0,0);
231  TGDimension msize = fMain->GetSize();
232  UInt_t pad_left, pad_top, pad_right, pad_bottom;
233  Int_t size_expand=0, esize_expand=0, rem_expand=0, tmp_expand = 0;
234 
235  if (!fList) return;
236 
237  fModified = kFALSE;
238 
239  bottom = msize.fHeight - (top = bw);
240  remain = msize.fHeight - (bw << 1);
241 
242  TIter next(fList);
243  while ((ptr = (TGFrameElement *) next())) {
244  if (ptr->fState & kIsVisible) {
245  layout = ptr->fLayout;
246  size = ptr->fFrame->GetDefaultSize();
247  size.fHeight += layout->GetPadTop() + layout->GetPadBottom();
248  hints = layout->GetLayoutHints();
249  if ((hints & kLHintsExpandY) || (hints & kLHintsCenterY)) {
250  nb_expand++;
251  exp += size.fHeight;
252  if (hints & kLHintsExpandY) exp_max = 0;
253  else exp_max = TMath::Max(exp_max, (Int_t)size.fHeight);
254  } else {
255  remain -= size.fHeight;
256  if (remain < 0)
257  remain = 0;
258  }
259  }
260  }
261 
262  if (nb_expand) {
263  size_expand = remain/nb_expand;
264 
265  if (size_expand < exp_max)
266  esize_expand = (remain - exp)/nb_expand;
267  rem_expand = remain % nb_expand;
268  }
269 
270  next.Reset();
271  while ((ptr = (TGFrameElement *) next())) {
272  if (ptr->fState & kIsVisible) {
273  hints = (layout = ptr->fLayout)->GetLayoutHints();
274  csize = ptr->fFrame->GetDefaultSize();
275  pad_left = layout->GetPadLeft();
276  pad_top = layout->GetPadTop();
277  pad_right = layout->GetPadRight();
278  pad_bottom = layout->GetPadBottom();
279 
280  if (hints & kLHintsRight) {
281  x = msize.fWidth - bw - csize.fWidth - pad_right;
282  } else if (hints & kLHintsCenterX) {
283  x = (msize.fWidth - (bw << 1) - csize.fWidth) >> 1;
284  } else { // defaults to kLHintsLeft
285  x = pad_left + bw;
286  }
287 
288  if (hints & kLHintsExpandX) {
289  size.fWidth = msize.fWidth - (bw << 1) - pad_left - pad_right;
290  x = pad_left + bw;
291  } else {
292  size.fWidth = csize.fWidth;
293  }
294 
295  if (hints & kLHintsExpandY) {
296  if (size_expand >= exp_max)
297  size.fHeight = size_expand - pad_top - pad_bottom;
298  else
299  size.fHeight = csize.fHeight + esize_expand;
300 
301  tmp_expand += rem_expand;
302  if (tmp_expand >= nb_expand) {
303  size.fHeight++;
304  tmp_expand -= nb_expand;
305  }
306  } else {
307  size.fHeight = csize.fHeight;
308  if (hints & kLHintsCenterY) {
309  if (size_expand >= exp_max) {
310  extra_space = (size_expand - pad_top - pad_bottom - size.fHeight) >> 1;
311  } else {
312  extra_space = esize_expand >> 1;
313  }
314  y += extra_space;
315  top += extra_space;
316  }
317  }
318 
319  if (hints & kLHintsBottom) {
320  y = bottom - size.fHeight - pad_bottom;
321  bottom -= size.fHeight + pad_top + pad_bottom;
322  } else { // kLHintsTop by default
323  y = top + pad_top;
324  top += size.fHeight + pad_top + pad_bottom;
325  }
326 
327  if (hints & kLHintsCenterY)
328  top += extra_space;
329 
330  if (x > 32768) x = bw + 1;
331  //if (y > 32768) y = bw + 1;
332  if (size.fWidth > 32768)
333  size.fWidth = 1;
334  if (size.fHeight > 32768)
335  size.fHeight = 1;
336  ptr->fFrame->MoveResize(x, y, size.fWidth, size.fHeight);
337 
338  fModified = fModified || (ptr->fFrame->GetX() != x) ||
339  (ptr->fFrame->GetY() != y) ||
340  (ptr->fFrame->GetWidth() != size.fWidth) ||
341  (ptr->fFrame->GetHeight() != size.fHeight);
342  }
343  }
344 }
345 
346 ////////////////////////////////////////////////////////////////////////////////
347 /// Return default dimension of the vertical layout.
348 
350 {
351  TGFrameElement *ptr;
352  TGDimension size(0,0), msize = fMain->GetSize(), csize;
353  UInt_t options = fMain->GetOptions();
354 
355  if ((options & kFixedWidth) && (options & kFixedHeight))
356  return msize;
357 
358  TIter next(fList);
359  while ((ptr = (TGFrameElement *) next())) {
360  if (ptr->fState & kIsVisible) {
361  csize = ptr->fFrame->GetDefaultSize();
362  size.fWidth = TMath::Max(size.fWidth, csize.fWidth + ptr->fLayout->GetPadLeft() +
363  ptr->fLayout->GetPadRight());
364  size.fHeight += csize.fHeight + ptr->fLayout->GetPadTop() +
365  ptr->fLayout->GetPadBottom();
366  }
367  }
368 
369  size.fWidth += fMain->GetBorderWidth() << 1;
370  size.fHeight += fMain->GetBorderWidth() << 1;
371 
372  if (options & kFixedWidth) size.fWidth = msize.fWidth;
373  if (options & kFixedHeight) size.fHeight = msize.fHeight;
374 
375  return size;
376 }
377 
378 ////////////////////////////////////////////////////////////////////////////////
379 /// Make a horizontal layout of all frames in the list.
380 
382 {
383  TGFrameElement *ptr;
384  TGLayoutHints *layout;
385  Int_t nb_expand = 0;
386  Int_t left, right;
387  ULong_t hints;
388  UInt_t extra_space = 0;
389  Int_t exp = 0;
390  Int_t exp_max = 0;
391  Int_t remain;
392  Int_t x = 0, y = 0;
393  Int_t bw = fMain->GetBorderWidth();
394  TGDimension size, csize;
395  TGDimension msize = fMain->GetSize();
396  UInt_t pad_left, pad_top, pad_right, pad_bottom;
397  Int_t size_expand=0, esize_expand=0, rem_expand=0, tmp_expand = 0;
398 
399  if (!fList) return;
400 
401  fModified = kFALSE;
402  right = msize.fWidth - (left = bw);
403  remain = msize.fWidth - (bw << 1);
404 
405  TIter next(fList);
406  while ((ptr = (TGFrameElement *) next())) {
407  if (ptr->fState & kIsVisible) {
408  layout = ptr->fLayout;
409  size = ptr->fFrame->GetDefaultSize();
410  size.fWidth += layout->GetPadLeft() + layout->GetPadRight();
411  hints = layout->GetLayoutHints();
412  if ((hints & kLHintsExpandX) || (hints & kLHintsCenterX)) {
413  nb_expand++;
414  exp += size.fWidth;
415  if (hints & kLHintsExpandX) exp_max = 0;
416  else exp_max = TMath::Max(exp_max, (Int_t)size.fWidth);
417  } else {
418  remain -= size.fWidth;
419  if (remain < 0)
420  remain = 0;
421  }
422  }
423  }
424  if (nb_expand) {
425  size_expand = remain/nb_expand;
426 
427  if (size_expand < exp_max) {
428  esize_expand = (remain - exp)/nb_expand;
429  }
430  rem_expand = remain % nb_expand;
431  }
432 
433  next.Reset();
434  while ((ptr = (TGFrameElement *) next())) {
435  if (ptr->fState & kIsVisible) {
436  hints = (layout = ptr->fLayout)->GetLayoutHints();
437  csize = ptr->fFrame->GetDefaultSize();
438  pad_left = layout->GetPadLeft();
439  pad_top = layout->GetPadTop();
440  pad_right = layout->GetPadRight();
441  pad_bottom = layout->GetPadBottom();
442 
443  if (hints & kLHintsBottom) {
444  y = msize.fHeight - bw - csize.fHeight - pad_bottom;
445  } else if (hints & kLHintsCenterY) {
446  y = (msize.fHeight - (bw << 1) - csize.fHeight) >> 1;
447  } else { // kLHintsTop by default
448  y = pad_top + bw;
449  }
450 
451  if (hints & kLHintsExpandY) {
452  size.fHeight = msize.fHeight - (bw << 1) - pad_top - pad_bottom;
453  y = pad_top + bw;
454  } else {
455  size.fHeight = csize.fHeight;
456  }
457 
458  if (hints & kLHintsExpandX) {
459  if (size_expand >= exp_max)
460  size.fWidth = size_expand - pad_left - pad_right;
461  else
462  size.fWidth = csize.fWidth + esize_expand;
463 
464  tmp_expand += rem_expand;
465 
466  if (tmp_expand >= nb_expand) {
467  size.fWidth++;
468  tmp_expand -= nb_expand;
469  }
470  } else {
471  size.fWidth = csize.fWidth;
472  if (hints & kLHintsCenterX) {
473  if (size_expand >= exp_max) {
474  extra_space = (size_expand - pad_left - pad_right - size.fWidth)>> 1;
475  } else {
476  extra_space = esize_expand >> 1;
477  }
478  x += extra_space;
479  left += extra_space;
480  }
481  }
482 
483  if (hints & kLHintsRight) {
484  x = right - size.fWidth - pad_right;
485  right -= size.fWidth + pad_left + pad_right;
486  } else { // defaults to kLHintsLeft
487  x = left + pad_left;
488  left += size.fWidth + pad_left + pad_right;
489  }
490 
491  if (hints & kLHintsCenterX)
492  left += extra_space;
493 
494  ptr->fFrame->MoveResize(x, y, size.fWidth, size.fHeight);
495 
496  fModified = fModified || (ptr->fFrame->GetX() != x) ||
497  (ptr->fFrame->GetY() != y) ||
498  (ptr->fFrame->GetWidth() != size.fWidth) ||
499  (ptr->fFrame->GetHeight() != size.fHeight);
500  }
501  }
502 }
503 
504 ////////////////////////////////////////////////////////////////////////////////
505 /// Return default dimension of the horizontal layout.
506 
508 {
509  TGFrameElement *ptr;
510  TGDimension size(0,0), msize = fMain->GetSize(), csize;
511  UInt_t options = fMain->GetOptions();
512 
513  if ((options & kFixedWidth) && (options & kFixedHeight))
514  return msize;
515 
516  TIter next(fList);
517  while ((ptr = (TGFrameElement *) next())) {
518  if (ptr->fState & kIsVisible) {
519  csize = ptr->fFrame->GetDefaultSize();
520  size.fWidth += csize.fWidth + ptr->fLayout->GetPadLeft() +
521  ptr->fLayout->GetPadRight();
522 
523  size.fHeight = TMath::Max(size.fHeight, csize.fHeight + ptr->fLayout->GetPadTop() +
524  ptr->fLayout->GetPadBottom());
525  }
526  }
527  size.fWidth += fMain->GetBorderWidth() << 1;
528  size.fHeight += fMain->GetBorderWidth() << 1;
529 
530  if (options & kFixedWidth) size.fWidth = msize.fWidth;
531  if (options & kFixedHeight) size.fHeight = msize.fHeight;
532 
533  return size;
534 }
535 
536 ////////////////////////////////////////////////////////////////////////////////
537 /// Make a row layout of all frames in the list.
538 
540 {
541  TGFrameElement *ptr;
542  TGDimension size;
543  Int_t bw = fMain->GetBorderWidth();
544  Int_t x = bw, y = bw;
545  fModified = kFALSE;
546 
547  TIter next(fList);
548  while ((ptr = (TGFrameElement *) next())) {
549  if (ptr->fState & kIsVisible) {
550  size = ptr->fFrame->GetDefaultSize();
551  ptr->fFrame->Move(x, y);
552 
553  fModified = fModified || (ptr->fFrame->GetX() != x) ||
554  (ptr->fFrame->GetY() != y);
555 
556  ptr->fFrame->Layout();
557  x += size.fWidth + fSep;
558  }
559  }
560 }
561 
562 ////////////////////////////////////////////////////////////////////////////////
563 /// Return default dimension of the row layout.
564 
566 {
567  TGFrameElement *ptr;
568  TGDimension size(0,0), dsize, msize = fMain->GetSize();
569  UInt_t options = fMain->GetOptions();
570 
571  if ((options & kFixedHeight) && (options & kFixedWidth))
572  return msize;
573 
574  TIter next(fList);
575  while ((ptr = (TGFrameElement *) next())) {
576  if (ptr->fState & kIsVisible) {
577  dsize = ptr->fFrame->GetDefaultSize();
578  size.fHeight = TMath::Max(size.fHeight, dsize.fHeight);
579  size.fWidth += dsize.fWidth + fSep;
580  }
581  }
582 
583  size.fHeight += fMain->GetBorderWidth() << 1;
584  size.fWidth += fMain->GetBorderWidth() << 1;
585  size.fWidth -= fSep;
586 
587  if (options & kFixedHeight) size.fHeight = msize.fHeight;
588  if (options & kFixedWidth) size.fWidth = msize.fWidth;
589 
590  return size;
591 }
592 
593 ////////////////////////////////////////////////////////////////////////////////
594 /// Make a column layout of all frames in the list.
595 
597 {
598  TGFrameElement *ptr;
599  TGDimension size;
600  Int_t bw = fMain->GetBorderWidth();
601  Int_t x = bw, y = bw;
602  fModified = kFALSE;
603 
604  TIter next(fList);
605  while ((ptr = (TGFrameElement *) next())) {
606  if (ptr->fState & kIsVisible) {
607  size = ptr->fFrame->GetDefaultSize();
608  ptr->fFrame->Move(x, y);
609  fModified = fModified || (ptr->fFrame->GetX() != x) ||
610  (ptr->fFrame->GetY() != y);
611  ptr->fFrame->Layout();
612  y += size.fHeight + fSep;
613  }
614  }
615 }
616 
617 ////////////////////////////////////////////////////////////////////////////////
618 /// Return default dimension of the column layout.
619 
621 {
622  TGFrameElement *ptr;
623  TGDimension size(0,0), dsize, msize = fMain->GetSize();
624  UInt_t options = fMain->GetOptions();
625 
626  if (options & kFixedHeight && options & kFixedWidth)
627  return msize;
628 
629  TIter next(fList);
630  while ((ptr = (TGFrameElement *) next())) {
631  if (ptr->fState & kIsVisible) {
632  dsize = ptr->fFrame->GetDefaultSize();
633  size.fHeight += dsize.fHeight + fSep;
634  size.fWidth = TMath::Max(size.fWidth, dsize.fWidth);
635  }
636  }
637 
638  size.fHeight += fMain->GetBorderWidth() << 1;
639  size.fHeight -= fSep;
640  size.fWidth += fMain->GetBorderWidth() << 1;
641 
642  if (options & kFixedHeight) size.fHeight = msize.fHeight;
643  if (options & kFixedWidth) size.fWidth = msize.fWidth;
644 
645  return size;
646 }
647 
648 ////////////////////////////////////////////////////////////////////////////////
649 /// TGMatrixLayout constructor.
650 
652  Int_t s, Int_t h)
653 {
654  fMain = main;
655  fList = fMain->GetList();
656  fSep = s;
657  fHints = h;
658  fRows = r;
659  fColumns = c;
660 }
661 
662 ////////////////////////////////////////////////////////////////////////////////
663 /// Make a matrix layout of all frames in the list.
664 
666 {
667  TGFrameElement *ptr;
668  TGDimension csize, maxsize(0,0);
669  Int_t bw = fMain->GetBorderWidth();
670  Int_t x = fSep, y = fSep + bw;
671  UInt_t rowcount = fRows, colcount = fColumns;
672  fModified = kFALSE;
673 
674  TIter next(fList);
675  while ((ptr = (TGFrameElement *) next())) {
676  csize = ptr->fFrame->GetDefaultSize();
677  maxsize.fWidth = TMath::Max(maxsize.fWidth, csize.fWidth);
678  maxsize.fHeight = TMath::Max(maxsize.fHeight, csize.fHeight);
679  }
680 
681  next.Reset();
682  while ((ptr = (TGFrameElement *) next())) {
683  ptr->fFrame->Move(x, y);
684  fModified = fModified || (ptr->fFrame->GetX() != x) ||
685  (ptr->fFrame->GetY() != y);
686 
687  ptr->fFrame->Layout();
688 
689  if (fColumns == 0) {
690  y += maxsize.fHeight + fSep;
691  rowcount--;
692  if (rowcount <= 0) {
693  rowcount = fRows;
694  y = fSep + bw; x += maxsize.fWidth + fSep;
695  }
696  } else if (fRows == 0) {
697  x += maxsize.fWidth + fSep;
698  colcount--;
699  if (colcount <= 0) {
700  colcount = fColumns;
701  x = fSep; y += maxsize.fHeight + fSep;
702  }
703  } else {
704  x += maxsize.fWidth + fSep;
705  colcount--;
706  if (colcount <= 0) {
707  rowcount--;
708  if (rowcount <= 0) return;
709  else {
710  colcount = fColumns;
711  x = fSep; y += maxsize.fHeight + fSep;
712  }
713  }
714  }
715  }
716 }
717 
718 ////////////////////////////////////////////////////////////////////////////////
719 /// Return default dimension of the matrix layout.
720 
722 {
723  TGFrameElement *ptr;
724  TGDimension size, csize, maxsize(0,0);
725  Int_t count = 0;
726  Int_t bw = fMain->GetBorderWidth();
727 
728  TIter next(fList);
729  while ((ptr = (TGFrameElement *) next())) {
730  count++;
731  csize = ptr->fFrame->GetDefaultSize();
732  maxsize.fWidth = TMath::Max(maxsize.fWidth, csize.fWidth);
733  maxsize.fHeight = TMath::Max(maxsize.fHeight, csize.fHeight);
734  }
735 
736  if (fRows == 0) {
737  Int_t rows = (count % fColumns) ? (count / fColumns + 1) : (count / fColumns);
738  size.fWidth = fColumns * (maxsize.fWidth + fSep) + fSep;
739  size.fHeight = rows * (maxsize.fHeight + fSep) + fSep + bw;
740  } else if (fColumns == 0) {
741  Int_t cols = (count % fRows) ? (count / fRows + 1) : (count / fRows);
742  size.fWidth = cols * (maxsize.fWidth + fSep) + fSep;
743  size.fHeight = fRows * (maxsize.fHeight + fSep) + fSep + bw;
744  } else {
745  size.fWidth = fColumns * (maxsize.fWidth + fSep) + fSep;
746  size.fHeight = fRows * (maxsize.fHeight + fSep) + fSep + bw;
747  }
748  return size;
749 }
750 
751 ////////////////////////////////////////////////////////////////////////////////
752 /// Create a tile layout manager.
753 
755 {
756  fMain = main;
757  fSep = sep;
758  fList = fMain->GetList();
759  fModified = kTRUE;
760 }
761 
762 ////////////////////////////////////////////////////////////////////////////////
763 /// Make a tile layout of all frames in the list.
764 
766 {
767  TGFrameElement *ptr;
768  Int_t x, y, xw, yw;
769  UInt_t max_width;
770  ULong_t hints;
771  TGDimension csize, max_osize(0,0), msize = fMain->GetSize();
772  fModified = kFALSE;
773 
774  TIter next(fList);
775  while ((ptr = (TGFrameElement *) next())) {
776  csize = ptr->fFrame->GetDefaultSize();
777  max_osize.fWidth = TMath::Max(max_osize.fWidth, csize.fWidth);
778  max_osize.fHeight = TMath::Max(max_osize.fHeight, csize.fHeight);
779  }
780 
781  max_width = TMath::Max(msize.fWidth, max_osize.fWidth + (fSep << 1));
782  x = fSep; y = fSep << 1;
783 
784  next.Reset();
785  while ((ptr = (TGFrameElement *) next())) {
786  hints = ptr->fLayout->GetLayoutHints();
787  csize = ptr->fFrame->GetDefaultSize();
788 
789  if (hints & kLHintsCenterX)
790  xw = x + (Int_t)((max_osize.fWidth - csize.fWidth) >> 1);
791  else if (hints & kLHintsRight)
792  xw = x + (Int_t)max_osize.fWidth - (Int_t)csize.fWidth;
793  else // defaults to kLHintsLeft
794  xw = x;
795 
796  if (hints & kLHintsCenterY)
797  yw = y + (Int_t)((max_osize.fHeight - csize.fHeight) >> 1);
798  else if (hints & kLHintsBottom)
799  yw = y + (Int_t)max_osize.fHeight - (Int_t)csize.fHeight;
800  else // defaults to kLHintsTop
801  yw = y;
802 
803  fModified = fModified || (ptr->fFrame->GetX() != xw) ||
804  (ptr->fFrame->GetY() != yw);
805  ptr->fFrame->Move(xw, yw);
806  if (hints & kLHintsExpandX)
807  ptr->fFrame->Resize(max_osize.fWidth, ptr->fFrame->GetDefaultHeight());
808  x += (Int_t)max_osize.fWidth + fSep;
809 
810  if (x + max_osize.fWidth > max_width) {
811  x = fSep;
812  y += (Int_t)max_osize.fHeight + fSep + (fSep >> 1);
813  }
814  }
815 }
816 
817 ////////////////////////////////////////////////////////////////////////////////
818 /// Return default dimension of the tile layout.
819 
821 {
822  TGFrameElement *ptr;
823  Int_t x, y;
824  TGDimension max_size, max_osize(0,0), msize = fMain->GetSize();
825 
826  TIter next(fList);
827  while ((ptr = (TGFrameElement *) next())) {
828  max_size = ptr->fFrame->GetDefaultSize();
829  max_osize.fWidth = TMath::Max(max_osize.fWidth, max_size.fWidth);
830  max_osize.fHeight = TMath::Max(max_osize.fHeight, max_size.fHeight);
831  }
832 
833  max_size.fWidth = TMath::Max(msize.fWidth, max_osize.fWidth + (fSep << 1));
834 
835  x = fSep; y = fSep << 1;
836 
837  next.Reset();
838  // coverity[returned_pointer]
839  while ((ptr = (TGFrameElement *) next())) {
840  x += max_osize.fWidth + fSep;
841  if (x + max_osize.fWidth > max_size.fWidth) {
842  x = fSep;
843  y += (Int_t)max_osize.fHeight + fSep + (fSep >> 1); // 3/2
844  }
845  }
846  if (x != fSep) y += max_osize.fHeight + fSep;
847  max_size.fHeight = TMath::Max(y, (Int_t)msize.fHeight);
848 
849  return max_size;
850 }
851 
852 ////////////////////////////////////////////////////////////////////////////////
853 /// Make a tile layout of all frames in the list.
854 
856 {
857  TGFrameElement *ptr;
858  Int_t x, y, xw, yw;
859  UInt_t max_height;
860  ULong_t hints;
861  TGDimension csize, max_osize(0,0), msize = fMain->GetSize();
862  fModified = kFALSE;
863 
864  TIter next(fList);
865  // coverity[returned_pointer]
866  while ((ptr = (TGFrameElement *) next())) {
867  csize = ptr->fFrame->GetDefaultSize();
868  max_osize.fWidth = TMath::Max(max_osize.fWidth, csize.fWidth);
869  max_osize.fHeight = TMath::Max(max_osize.fHeight, csize.fHeight);
870  }
871 
872  max_height = TMath::Max(msize.fHeight, max_osize.fHeight + (fSep << 1));
873 
874  x = fSep; y = fSep << 1;
875 
876  next.Reset();
877  while ((ptr = (TGFrameElement *) next())) {
878 
879  hints = ptr->fLayout->GetLayoutHints();
880  csize = ptr->fFrame->GetDefaultSize();
881 
882  if (hints & kLHintsCenterX)
883  xw = x + (Int_t)((max_osize.fWidth - csize.fWidth) >> 1);
884  else if (hints & kLHintsRight)
885  xw = x + (Int_t)max_osize.fWidth - (Int_t)csize.fWidth;
886  else // defaults to kLHintsLeft
887  xw = x;
888 
889  if (hints & kLHintsCenterY)
890  yw = y + (Int_t)((max_osize.fHeight - csize.fHeight) >> 1);
891  else if (hints & kLHintsBottom)
892  yw = y + (Int_t)max_osize.fHeight - (Int_t)csize.fHeight;
893  else // defaults to kLHintsTop
894  yw = y;
895 
896  fModified = fModified || (ptr->fFrame->GetX() != xw) ||
897  (ptr->fFrame->GetY() != yw);
898  ptr->fFrame->Move(xw, yw);
899  if (hints & kLHintsExpandX)
900  ptr->fFrame->Resize(max_osize.fWidth, ptr->fFrame->GetDefaultHeight());
901  y += (Int_t)max_osize.fHeight + fSep + (fSep >> 1);
902 
903  if (y + max_osize.fHeight > max_height) {
904  y = fSep << 1;
905  x += (Int_t)max_osize.fWidth + fSep;
906  }
907  }
908 }
909 
910 ////////////////////////////////////////////////////////////////////////////////
911 /// Return default dimension of the list layout.
912 
914 {
915  TGFrameElement *ptr;
916  Int_t x, y;
917  TGDimension max_size, max_osize(0,0), msize = fMain->GetSize();
918 
919  TIter next(fList);
920  while ((ptr = (TGFrameElement *) next())) {
921  max_size = ptr->fFrame->GetDefaultSize();
922  max_osize.fWidth = TMath::Max(max_osize.fWidth, max_size.fWidth);
923  max_osize.fHeight = TMath::Max(max_osize.fHeight, max_size.fHeight);
924  }
925 
926  max_size.fHeight = TMath::Max(msize.fHeight, max_osize.fHeight + (fSep << 1));
927 
928  x = fSep; y = fSep << 1;
929 
930  next.Reset();
931  while ((ptr = (TGFrameElement *) next())) {
932  y += (Int_t)max_osize.fHeight + fSep + (fSep >> 1);
933  if (y + max_osize.fHeight > max_size.fHeight) {
934  y = fSep << 1;
935  x += (Int_t)max_osize.fWidth + fSep;
936  }
937  }
938  if (y != (fSep << 1)) x += (Int_t)max_osize.fWidth + fSep;
939  max_size.fWidth = TMath::Max(x, (Int_t)msize.fWidth);
940 
941  return max_size;
942 }
943 
944 ////////////////////////////////////////////////////////////////////////////////
945 /// Make a list details layout of all frames in the list.
946 
948 {
949  TGFrameElement *ptr;
950  TGDimension csize, msize = fMain->GetSize();
951  Int_t max_oh = 0, x = fSep, y = fSep << 1;
952  fModified = kFALSE;
953 
954  TIter next(fList);
955  while ((ptr = (TGFrameElement *) next())) {
956  csize = ptr->fFrame->GetDefaultSize();
957  max_oh = TMath::Max(max_oh, (Int_t)csize.fHeight);
958  }
959 
960  next.Reset();
961 
962  while ((ptr = (TGFrameElement *) next())) {
963  if (ptr->fState & kIsVisible) {
964  csize = ptr->fFrame->GetDefaultSize();
965 
966  fModified = fModified || (ptr->fFrame->GetX() != x) ||
967  (ptr->fFrame->GetY() != y);
968 
969  ptr->fFrame->MoveResize(x, y, msize.fWidth, csize.fHeight);
970  ptr->fFrame->Layout();
971  y += max_oh + fSep + (fSep >> 1);
972  }
973  }
974 }
975 
976 ////////////////////////////////////////////////////////////////////////////////
977 /// Return default dimension of the list details layout.
978 
980 {
981  TGFrameElement *ptr;
982  TGDimension csize, max_osize(0,0);
983  Int_t y = fSep << 1;
984 
985  TIter next(fList);
986  while ((ptr = (TGFrameElement *) next())) {
987  csize = ptr->fFrame->GetDefaultSize();
988  max_osize.fWidth = TMath::Max(max_osize.fWidth, csize.fWidth);
989  max_osize.fHeight = TMath::Max(max_osize.fHeight, csize.fHeight);
990  }
991 
992  next.Reset();
993  while ((ptr = (TGFrameElement *) next())) {
994  if (ptr->fState & kIsVisible) {
995  y += max_osize.fHeight + fSep + (fSep >> 1);
996  }
997  }
998 
999  return TGDimension( fWidth ? fWidth : max_osize.fWidth, y);
1000 }
1001 
1002 // ________________________________________________________________________
1003 void TGLayoutHints::SavePrimitive(std::ostream &out, Option_t * option/*= ""*/)
1004 {
1005 
1006  // Save layout hints as a C++ statement(s) on output stream out
1007 
1008  TString hints;
1010 
1011  if (!GetLayoutHints()) return;
1012 
1013  if ((option == 0) || strcmp(option, "nocoma"))
1014  out << ", ";
1015 
1016  if ((fLayoutHints == kLHintsNormal) && (pad == 0)) {
1017  out << "new TGLayoutHints(kLHintsNormal)";
1018  return;
1019  }
1020  if (fLayoutHints & kLHintsLeft) {
1021  if (hints.Length() == 0) hints = "kLHintsLeft";
1022  else hints += " | kLHintsLeft";
1023  }
1024  if (fLayoutHints & kLHintsCenterX) {
1025  if (hints.Length() == 0) hints = "kLHintsCenterX";
1026  else hints += " | kLHintsCenterX";
1027  }
1028  if (fLayoutHints & kLHintsRight) {
1029  if (hints.Length() == 0) hints = "kLHintsRight";
1030  else hints += " | kLHintsRight";
1031  }
1032  if (fLayoutHints & kLHintsTop) {
1033  if (hints.Length() == 0) hints = "kLHintsTop";
1034  else hints += " | kLHintsTop";
1035  }
1036  if (fLayoutHints & kLHintsCenterY) {
1037  if (hints.Length() == 0) hints = "kLHintsCenterY";
1038  else hints += " | kLHintsCenterY";
1039  }
1040  if (fLayoutHints & kLHintsBottom) {
1041  if (hints.Length() == 0) hints = "kLHintsBottom";
1042  else hints += " | kLHintsBottom";
1043  }
1044  if (fLayoutHints & kLHintsExpandX) {
1045  if (hints.Length() == 0) hints = "kLHintsExpandX";
1046  else hints += " | kLHintsExpandX";
1047  }
1048  if (fLayoutHints & kLHintsExpandY) {
1049  if (hints.Length() == 0) hints = "kLHintsExpandY";
1050  else hints += " | kLHintsExpandY";
1051  }
1052 
1053  out << "new TGLayoutHints(" << hints;
1054 
1055  if (pad) {
1056  out << "," << GetPadLeft() << "," << GetPadRight()
1057  << "," << GetPadTop() << "," << GetPadBottom();
1058  }
1059  out<< ")";
1060 }
1061 
1062 // __________________________________________________________________________
1063 void TGVerticalLayout::SavePrimitive(std::ostream &out, Option_t * /*= ""*/)
1064 {
1065 
1066  // Save vertical layout manager as a C++ statement(s) on output stream
1067 
1068  out << "new TGVerticalLayout(" << fMain->GetName() << ")";
1069 
1070 }
1071 
1072 // __________________________________________________________________________
1073 void TGHorizontalLayout::SavePrimitive(std::ostream &out, Option_t * /*= ""*/)
1074 {
1075 
1076  // Save horizontal layout manager as a C++ statement(s) on output stream
1077 
1078  out << "new TGHorizontalLayout(" << fMain->GetName() << ")";
1079 }
1080 
1081 // __________________________________________________________________________
1082 void TGRowLayout::SavePrimitive(std::ostream &out, Option_t * /*= ""*/)
1083 {
1084 
1085  // Save row layout manager as a C++ statement(s) on output stream
1086 
1087  out << "new TGRowLayout(" << fMain->GetName() << ","
1088  << fSep << ")";
1089 }
1090 
1091 // __________________________________________________________________________
1092 void TGColumnLayout::SavePrimitive(std::ostream &out, Option_t * /*= ""*/)
1093 {
1094 
1095  // Save column layout manager as a C++ statement(s) on output stream
1096 
1097  out << "new TGColumnLayout(" << fMain->GetName() << ","
1098  << fSep << ")";
1099 
1100 }
1101 
1102 // __________________________________________________________________________
1103 void TGMatrixLayout::SavePrimitive(std::ostream &out, Option_t * /*= ""*/)
1104 {
1105 
1106  // Save matrix layout manager as a C++ statement(s) on output stream
1107 
1108  out << "new TGMatrixLayout(" << fMain->GetName() << ","
1109  << fRows << ","
1110  << fColumns << ","
1111  << fSep << ","
1112  << fHints <<")";
1113 
1114 }
1115 
1116 // __________________________________________________________________________
1117 void TGTileLayout::SavePrimitive(std::ostream &out, Option_t * /*= ""*/)
1118 {
1119 
1120  // Save tile layout manager as a C++ statement(s) on output stream
1121 
1122  out << "new TGTileLayout(" << fMain->GetName() << ","
1123  << fSep << ")";
1124 
1125 }
1126 
1127 // __________________________________________________________________________
1128 void TGListLayout::SavePrimitive(std::ostream &out, Option_t * /*= ""*/)
1129 {
1130 
1131  // Save list layout manager as a C++ statement(s) on output stream
1132 
1133  out << "new TGListLayout(" << fMain->GetName() << ","
1134  << fSep << ")";
1135 
1136 }
1137 
1138 // __________________________________________________________________________
1139 void TGListDetailsLayout::SavePrimitive(std::ostream &out, Option_t * /*= ""*/)
1140 {
1141 
1142  // Save list details layout manager as a C++ statement(s) on out stream
1143 
1144  out << "new TGListDetailsLayout(" << fMain->GetName() << ","
1145  << fSep << "," << fWidth << ")";
1146 
1147 }
virtual TGDimension GetDefaultSize() const
std::cout << fWidth << "x" << fHeight << std::endl;
Definition: TGFrame.cxx:566
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:587
virtual TGDimension GetDefaultSize() const
Return default dimension of the list layout.
Definition: TGLayout.cxx:913
Int_t fPadleft
Definition: TGLayout.h:72
virtual void SavePrimitive(std::ostream &out, Option_t *="")
Save a primitive as a C++ statement(s) on output stream "out".
Definition: TGLayout.cxx:1103
virtual void MoveResize(Int_t x, Int_t y, UInt_t w=0, UInt_t h=0)
Move and/or resize the frame.
Definition: TGFrame.cxx:611
ULong_t GetLayoutHints() const
Definition: TGLayout.h:89
const char Option_t
Definition: RtypesCore.h:62
Int_t GetY() const
Definition: TGFrame.h:279
UInt_t GetHeight() const
Definition: TGFrame.h:272
TH1 * h
Definition: legend2.C:5
Definitions for TRefCnt, base class for reference counted objects.
Definition: TRefCnt.h:27
TGMatrixLayout(const TGMatrixLayout &)
virtual void SavePrimitive(std::ostream &out, Option_t *="")
Save a primitive as a C++ statement(s) on output stream "out".
Definition: TGLayout.cxx:1092
virtual TGDimension GetDefaultSize() const
Return default dimension of the tile layout.
Definition: TGLayout.cxx:820
Basic string class.
Definition: TString.h:125
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual void Print(Option_t *option="") const
This method must be overridden when a class wants to print itself.
Definition: TObject.cxx:550
UInt_t GetWidth() const
Definition: TGFrame.h:271
Int_t fState
Definition: TGLayout.h:120
void Reset()
Definition: TCollection.h:250
virtual TGDimension GetDefaultSize() const
Return default dimension of the row layout.
Definition: TGLayout.cxx:565
ULong_t fLayoutHints
Definition: TGLayout.h:69
TGLayoutHints * fLayout
Definition: TGLayout.h:121
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:128
Double_t x[n]
Definition: legend1.C:17
virtual void SavePrimitive(std::ostream &out, Option_t *="")
Save a primitive as a C++ statement(s) on output stream "out".
Definition: TGLayout.cxx:1139
virtual void Layout()
Make a vertical layout of all frames in the list.
Definition: TGLayout.cxx:217
TGVerticalLayout(const TGVerticalLayout &gvl)
Definition: TGLayout.h:172
virtual void Layout()
Definition: TGFrame.h:246
int main(int argc, char **argv)
UInt_t fHeight
Definition: TGDimension.h:30
virtual void Layout()
Make a horizontal layout of all frames in the list.
Definition: TGLayout.cxx:381
virtual void Layout()
Make a row layout of all frames in the list.
Definition: TGLayout.cxx:539
virtual void SavePrimitive(std::ostream &out, Option_t *="")
Save a primitive as a C++ statement(s) on output stream "out".
Definition: TGLayout.cxx:1128
virtual TGDimension GetDefaultSize() const
Return default dimension of the vertical layout.
Definition: TGLayout.cxx:349
virtual void Layout()
Make a column layout of all frames in the list.
Definition: TGLayout.cxx:596
virtual void Layout()
Make a tile layout of all frames in the list.
Definition: TGLayout.cxx:855
Int_t GetX() const
Definition: TGFrame.h:278
UInt_t fWidth
Definition: TGDimension.h:29
virtual void SavePrimitive(std::ostream &out, Option_t *="")
Save a primitive as a C++ statement(s) on output stream "out".
Definition: TGLayout.cxx:1082
virtual void SavePrimitive(std::ostream &out, Option_t *="")
Save a primitive as a C++ statement(s) on output stream "out".
Definition: TGLayout.cxx:1073
void SetRefCount(UInt_t r)
Definition: TRefCnt.h:39
void Print(Option_t *option="") const
Printing.
Definition: TGLayout.cxx:151
ROOT::R::TRInterface & r
Definition: Object.C:4
TGLayoutHints(ULong_t hints=kLHintsNormal, Int_t padleft=0, Int_t padright=0, Int_t padtop=0, Int_t padbottom=0)
Definition: TGLayout.h:78
Int_t fPadbottom
Definition: TGLayout.h:71
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a primitive as a C++ statement(s) on output stream "out".
Definition: TGLayout.cxx:1003
virtual const char * GetName() const
Return unique name, used in SavePrimitive methods.
Definition: TGWindow.cxx:221
Int_t GetPadLeft() const
Definition: TGLayout.h:92
void UpdateFrameElements(TGLayoutHints *l)
Update layout hints of frame elements.
Definition: TGLayout.cxx:135
unsigned int UInt_t
Definition: RtypesCore.h:42
Ssiz_t Length() const
Definition: TString.h:386
TGFrame * fFrame
Definition: TGLayout.h:119
virtual TGDimension GetDefaultSize() const
Return default dimension of the horizontal layout.
Definition: TGLayout.cxx:507
virtual void SavePrimitive(std::ostream &out, Option_t *="")
Save a primitive as a C++ statement(s) on output stream "out".
Definition: TGLayout.cxx:1063
virtual TGDimension GetDefaultSize() const
Return default dimension of the list details layout.
Definition: TGLayout.cxx:979
TGFrameElement * fFE
Definition: TGLayout.h:63
virtual void Move(Int_t x, Int_t y)
Move frame.
Definition: TGFrame.cxx:575
const Bool_t kFALSE
Definition: RtypesCore.h:88
virtual UInt_t GetDefaultHeight() const
Definition: TGFrame.h:238
virtual TGDimension GetDefaultSize() const
Return default dimension of the matrix layout.
Definition: TGLayout.cxx:721
virtual void Layout()
Make a tile layout of all frames in the list.
Definition: TGLayout.cxx:765
#define ClassImp(name)
Definition: Rtypes.h:359
Int_t GetPadRight() const
Definition: TGLayout.h:93
unsigned long ULong_t
Definition: RtypesCore.h:51
Double_t y[n]
Definition: legend1.C:17
static constexpr double s
virtual ~TGLayoutHints()
Destructor.
Definition: TGLayout.cxx:128
TGTileLayout(const TGTileLayout &)
Mother of all ROOT objects.
Definition: TObject.h:37
~TGFrameElement()
Destructor. Decrease ref. count of fLayout.
Definition: TGLayout.cxx:92
void SetFrameElement(TGFrameElement *fe)
Definition: TGFrame.h:283
void Print(Option_t *option="") const
Print this frame element.
Definition: TGLayout.cxx:99
auto * l
Definition: textangle.C:4
void AddReference()
Definition: TRefCnt.h:40
virtual void Layout()
Make a matrix layout of all frames in the list.
Definition: TGLayout.cxx:665
virtual TGDimension GetDefaultSize() const
Return default dimension of the column layout.
Definition: TGLayout.cxx:620
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:200
TGFrameElement * fPrev
Definition: TGLayout.h:64
Int_t fPadright
Definition: TGLayout.h:73
Int_t GetPadTop() const
Definition: TGLayout.h:90
double exp(double)
virtual void SavePrimitive(std::ostream &out, Option_t *="")
Save a primitive as a C++ statement(s) on output stream "out".
Definition: TGLayout.cxx:1117
const Bool_t kTRUE
Definition: RtypesCore.h:87
Int_t fPadtop
Definition: TGLayout.h:70
Int_t GetPadBottom() const
Definition: TGLayout.h:91
virtual void Layout()
Make a list details layout of all frames in the list.
Definition: TGLayout.cxx:947