Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TGLayout.h
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 #ifndef ROOT_TGLayout
13 #define ROOT_TGLayout
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // A number of different layout classes (TGLayoutManager, //
19 // TGVerticalLayout, TGHorizontalLayout, TGLayoutHints, etc.). //
20 // //
21 //////////////////////////////////////////////////////////////////////////
22 
23 #include "TObject.h"
24 #include "TGDimension.h"
25 #include "TRefCnt.h"
26 
27 //---- layout hints
28 
29 enum ELayoutHints {
30  kLHintsNoHints = 0,
31  kLHintsLeft = BIT(0),
32  kLHintsCenterX = BIT(1),
33  kLHintsRight = BIT(2),
34  kLHintsTop = BIT(3),
35  kLHintsCenterY = BIT(4),
36  kLHintsBottom = BIT(5),
37  kLHintsExpandX = BIT(6),
38  kLHintsExpandY = BIT(7),
39  kLHintsNormal = (kLHintsLeft | kLHintsTop)
40  // bits 8-11 used by ETableLayoutHints
41 };
42 
43 class TGFrame;
44 class TGCompositeFrame;
45 class TGLayoutHints;
46 class TList;
47 class TGFrameElement;
48 
49 //////////////////////////////////////////////////////////////////////////
50 // //
51 // TGLayoutHints //
52 // //
53 // This class describes layout hints used by the layout classes. //
54 // //
55 //////////////////////////////////////////////////////////////////////////
56 
57 class TGLayoutHints : public TObject, public TRefCnt {
58 
59 friend class TGFrameElement;
60 friend class TGCompositeFrame;
61 
62 private:
63  TGFrameElement *fFE; // back pointer to the last frame element
64  TGFrameElement *fPrev; // previous element sharing this layout_hints
65 
66  TGLayoutHints& operator=(const TGLayoutHints&);
67 
68 protected:
69  ULong_t fLayoutHints; // layout hints (combination of ELayoutHints)
70  Int_t fPadtop; // amount of top padding
71  Int_t fPadbottom; // amount of bottom padding
72  Int_t fPadleft; // amount of left padding
73  Int_t fPadright; // amount of right padding
74 
75  void UpdateFrameElements(TGLayoutHints *l);
76 
77 public:
78  TGLayoutHints(ULong_t hints = kLHintsNormal,
79  Int_t padleft = 0, Int_t padright = 0,
80  Int_t padtop = 0, Int_t padbottom = 0):
81  fFE(0), fPrev(0), fLayoutHints(hints), fPadtop(padtop), fPadbottom(padbottom),
82  fPadleft(padleft), fPadright(padright)
83  { SetRefCount(0); }
84 
85  TGLayoutHints(const TGLayoutHints &lh);
86 
87  virtual ~TGLayoutHints();
88 
89  ULong_t GetLayoutHints() const { return fLayoutHints; }
90  Int_t GetPadTop() const { return fPadtop; }
91  Int_t GetPadBottom() const { return fPadbottom; }
92  Int_t GetPadLeft() const { return fPadleft; }
93  Int_t GetPadRight() const { return fPadright; }
94 
95  virtual void SetLayoutHints(ULong_t lh) { fLayoutHints = lh; }
96  virtual void SetPadTop(Int_t v) { fPadtop = v; }
97  virtual void SetPadBottom(Int_t v) { fPadbottom = v; }
98  virtual void SetPadLeft(Int_t v) { fPadleft = v; }
99  virtual void SetPadRight(Int_t v) { fPadright = v; }
100 
101  void Print(Option_t* option = "") const;
102  void ls(Option_t* option = "") const { Print(option); }
103 
104  virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
105 
106  ClassDef(TGLayoutHints,0) // Class describing GUI layout hints
107 };
108 
109 // Temporarily public as we need to share this class definition
110 // with the frame manager class
111 
112 class TGFrameElement : public TObject {
113 
114 private:
115  TGFrameElement(const TGFrameElement&);
116  TGFrameElement& operator=(const TGFrameElement&);
117 
118 public:
119  TGFrame *fFrame; // frame used in layout
120  Int_t fState; // EFrameState defined in TGFrame.h
121  TGLayoutHints *fLayout; // layout hints used in layout
122 
123  TGFrameElement() : fFrame(0), fState(0), fLayout(0) { }
124  TGFrameElement(TGFrame *f, TGLayoutHints *l);
125  ~TGFrameElement();
126 
127  void Print(Option_t* option = "") const;
128  void ls(Option_t* option = "") const { Print(option); }
129 
130  ClassDef(TGFrameElement, 0); // Base class used in GUI containers
131 };
132 
133 
134 //////////////////////////////////////////////////////////////////////////
135 // //
136 // TGLayoutManager //
137 // //
138 // Frame layout manager. This is an abstract class. //
139 // //
140 //////////////////////////////////////////////////////////////////////////
141 
142 class TGLayoutManager : public TObject {
143 protected:
144  Bool_t fModified;// kTRUE if positions of subframes changed after layout
145 
146 public:
147  TGLayoutManager() : fModified(kTRUE) {}
148 
149  virtual void Layout() = 0;
150  virtual TGDimension GetDefaultSize() const = 0;
151  virtual void SetDefaultWidth(UInt_t /* w */) {}
152  virtual void SetDefaultHeight(UInt_t /* h */) {}
153  virtual Bool_t IsModified() const { return fModified; }
154  virtual void SetModified(Bool_t flag = kTRUE) { fModified = flag; }
155 
156  ClassDef(TGLayoutManager,0) // Layout manager abstract base class
157 };
158 
159 
160 //////////////////////////////////////////////////////////////////////////
161 // //
162 // TGVerticalLayout and TGHorizontalLayout managers. //
163 // //
164 //////////////////////////////////////////////////////////////////////////
165 
166 class TGVerticalLayout : public TGLayoutManager {
167 
168 protected:
169  TGCompositeFrame *fMain; // container frame
170  TList *fList; // list of frames to arrange
171 
172  TGVerticalLayout(const TGVerticalLayout& gvl) :
173  TGLayoutManager(gvl), fMain(gvl.fMain), fList(gvl.fList) { }
174  TGVerticalLayout& operator=(const TGVerticalLayout& gvl)
175  {if(this!=&gvl) { TGLayoutManager::operator=(gvl);
176  fMain=gvl.fMain; fList=gvl.fList;} return *this;}
177 
178 public:
179  TGVerticalLayout(TGCompositeFrame *main);
180 
181  virtual void Layout();
182  virtual TGDimension GetDefaultSize() const;
183  virtual void SavePrimitive(std::ostream &out, Option_t * = "");
184 
185  ClassDef(TGVerticalLayout,0) // Vertical layout manager
186 };
187 
188 class TGHorizontalLayout : public TGVerticalLayout {
189 public:
190  TGHorizontalLayout(TGCompositeFrame *main) : TGVerticalLayout(main) { }
191 
192  virtual void Layout();
193  virtual TGDimension GetDefaultSize() const;
194  virtual void SavePrimitive(std::ostream &out, Option_t * = "");
195 
196  ClassDef(TGHorizontalLayout,0) // Horizontal layout manager
197 };
198 
199 
200 //////////////////////////////////////////////////////////////////////////
201 // //
202 // TGRowLayout and TGColumnLayout managers. //
203 // //
204 // The follwing two layout managers do not make use of TGLayoutHints. //
205 // //
206 //////////////////////////////////////////////////////////////////////////
207 
208 class TGRowLayout : public TGVerticalLayout {
209 public:
210  Int_t fSep; // interval between frames
211 
212  TGRowLayout(TGCompositeFrame *main, Int_t s = 0) :
213  TGVerticalLayout(main), fSep(s) { }
214 
215  virtual void Layout();
216  virtual TGDimension GetDefaultSize() const;
217  virtual void SavePrimitive(std::ostream &out, Option_t * = "");
218 
219  ClassDef(TGRowLayout,0) // Row layout manager
220 };
221 
222 class TGColumnLayout : public TGRowLayout {
223 public:
224  TGColumnLayout(TGCompositeFrame *main, Int_t s = 0) : TGRowLayout(main, s) { }
225 
226  virtual void Layout();
227  virtual TGDimension GetDefaultSize() const;
228  virtual void SavePrimitive(std::ostream &out, Option_t * = "");
229 
230  ClassDef(TGColumnLayout,0) // Column layout manager
231 };
232 
233 
234 //////////////////////////////////////////////////////////////////////////
235 // //
236 // TGMatrixLayout manager. //
237 // //
238 // This layout managers does not make use of TGLayoutHints. //
239 // //
240 //////////////////////////////////////////////////////////////////////////
241 
242 class TGMatrixLayout : public TGLayoutManager {
243 
244 private:
245  TGMatrixLayout(const TGMatrixLayout&);
246  TGMatrixLayout& operator=(const TGMatrixLayout&);
247 
248 protected:
249  TGCompositeFrame *fMain; // container frame
250  TList *fList; // list of frames to arrange
251 
252 public:
253  Int_t fSep; // interval between frames
254  Int_t fHints; // layout hints (currently not used)
255  UInt_t fRows; // number of rows
256  UInt_t fColumns; // number of columns
257 
258  TGMatrixLayout(TGCompositeFrame *main, UInt_t r, UInt_t c, Int_t s=0, Int_t h=0);
259 
260  virtual void Layout();
261  virtual TGDimension GetDefaultSize() const;
262  virtual void SavePrimitive(std::ostream &out, Option_t * = "");
263 
264  ClassDef(TGMatrixLayout,0) // Matrix layout manager
265 };
266 
267 
268 //////////////////////////////////////////////////////////////////////////
269 // //
270 // TGTileLayout, TGListLayout and TGListDetailsLayout managers. //
271 // //
272 // This are layout managers for the TGListView widget. //
273 // //
274 //////////////////////////////////////////////////////////////////////////
275 
276 class TGTileLayout : public TGLayoutManager {
277 
278 private:
279  TGTileLayout(const TGTileLayout&);
280  TGTileLayout& operator=(const TGTileLayout&);
281 
282 protected:
283  Int_t fSep; // separation between tiles
284  TGCompositeFrame *fMain; // container frame
285  TList *fList; // list of frames to arrange
286  Bool_t fModified;// layout changed
287 
288 
289 public:
290  TGTileLayout(TGCompositeFrame *main, Int_t sep = 0);
291 
292  virtual void Layout();
293  virtual TGDimension GetDefaultSize() const;
294  virtual Bool_t IsModified() const { return fModified; }
295  virtual void SavePrimitive(std::ostream &out, Option_t * = "");
296 
297  ClassDef(TGTileLayout,0) // Tile layout manager
298 };
299 
300 class TGListLayout : public TGTileLayout {
301 public:
302  TGListLayout(TGCompositeFrame *main, Int_t sep = 0) :
303  TGTileLayout(main, sep) { }
304 
305  virtual void Layout();
306  virtual TGDimension GetDefaultSize() const;
307  virtual void SavePrimitive(std::ostream &out, Option_t * = "");
308 
309  ClassDef(TGListLayout,0) // Layout manager for TGListView widget
310 };
311 
312 class TGListDetailsLayout : public TGTileLayout {
313 private:
314  UInt_t fWidth; // width of listview container
315 
316 public:
317  TGListDetailsLayout(TGCompositeFrame *main, Int_t sep = 0, UInt_t w = 0) :
318  TGTileLayout(main, sep), fWidth(w) { }
319 
320  virtual void Layout();
321  virtual TGDimension GetDefaultSize() const;
322  virtual void SetDefaultWidth(UInt_t w) { fWidth = w; }
323  virtual void SavePrimitive(std::ostream &out, Option_t * = "");
324 
325  ClassDef(TGListDetailsLayout,0) // Layout manager for TGListView details
326 };
327 
328 #endif