Logo ROOT  
Reference Guide
TGXYLayout.cxx
Go to the documentation of this file.
1// @(#)root/gui:$Id$
2// Author: Reiner Rohlfs 24/03/2002
3
4/*************************************************************************
5 * Copyright (C) 1995-2001, Rene Brun, Fons Rademakers and Reiner Rohlfs *
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/** \class TGXYLayout
14 \ingroup guiwidgets
15
16Is a layout manager where the position and the size of each widget
17in the frame are defined by X / Y - coordinates. The coordinates
18for each widget are defined by the TGXYLayoutHints. Therefore it
19is not possible to share a layout hint for several widgets.
20
21The coordinates (X, Y) and the size (W, H) are defined in units
22of the size of a typical character. Also the size of the
23TGCompositeFrame for which a TGXYLayout manager is used has to be
24defined in its constructor in units of the size of a character!
25
26It is not possible to use any other layout hint than the
27TGXYLayoutHints for this layout manager!
28
29The rubberFlag in the constructor of the TGLXYLayoutHins defines
30how the position and the size of a widget is recalculated if the
31size of the frame is increased:
32
33 - kLRubberX: The X - position (left edge) is increased by the same
34 factor as the width of the frame increases.
35 - kLRubberY: The Y - position (upper edge) is increased by the same
36 factor as the height of the frame increases.
37 - kLRubberW: The width of the widget is increased by the same
38 factor as the width of the frame increases.
39 - kLRubberH: The height of the widget is increased by the same
40 factor as the height of the frame increases.
41
42But the size never becomes smaller than defined by the
43TGXYLayoutHints and the X and Y coordinates becomes never smaller
44than defined by the layout hints.
45
46
47\class TGXYLayoutHints
48\ingroup guiwidgets
49
50This layout hint must be used for the TGXYLayout manager!
51
52Example how to use this layout manager:
53
54```
55TGMyFrame::TGMyFrame()
56 : TGMainFrame(gClient->GetRoot(), 30, 12)
57 // frame is 30 character long and 12 character heigh
58{
59 SetLayoutManager(new TGXYLayout(this));
60
61 // create a button of size 8 X 1.8 at position 20 / 1
62 TGTextButton * button;
63 button = new TGTextButton(this, "&Apply", 1);
64 AddFrame(button, new TGXYLayoutHints(20, 1, 8, 1.8));
65
66 // create a listbox of size 18 X 10 at position 1 / 1.
67 // The height will increase if the frame height increases
68 TGListBox * listBox;
69 listBox = new TGListBox(this, 2);
70 AddFrame(listBox, new TGXYLayoutHints(1, 1, 18, 10,
71 TGXYLayoutHints::kLRubberX |
72 TGXYLayoutHints::kLRubberY |
73 TGXYLayoutHints::kLRubberH ));
74 .
75 .
76 .
77}
78```
79
80Normally there is one layout hint per widget. Therefore these
81can be deleted like in the following example in the destructor
82of the frame:
83
84```
85TGMyFrame::~TGMyFrame()
86{
87 // Destructor, deletes all frames and their layout hints.
88
89 TGFrameElement *ptr;
90
91 // delete all frames and layout hints
92 if (fList) {
93 TIter next(fList);
94 while ((ptr = (TGFrameElement *) next())) {
95 if (ptr->fLayout)
96 delete ptr->fLayout;
97 if (ptr->fFrame)
98 delete ptr->fFrame;
99 }
100 }
101}
102```
103
104*/
105
106
107#include "TGXYLayout.h"
108#include "TGFrame.h"
109#include "TGLabel.h"
110#include "TVirtualX.h"
111
112#include <iostream>
113
114
117
118////////////////////////////////////////////////////////////////////////////////
119/// Constructor. The x, y, w and h define the position of the widget in
120/// its frame and the size of the widget. The unit is the size of a
121/// character. The rubberFlag defines how to move and to resize the
122/// widget when the frame is resized. Default is moving the X and Y
123/// position but keep the size of the widget.
124
126 UInt_t rubberFlag)
127 : TGLayoutHints(kLHintsNormal, 0,0,0,0)
128{
129 fX = x;
130 fY = y;
131 fW = w;
132 fH = h;
133 fFlag = rubberFlag;
134}
135
136////////////////////////////////////////////////////////////////////////////////
137/// Save XY layout hints as a C++ statement(s) on output stream.
138
139void TGXYLayoutHints::SavePrimitive(std::ostream &out, Option_t * /*option = ""*/)
140{
141 TString flag = "";
142 if (fFlag & kLRubberX) {
143 if (flag.Length() == 0) flag = "TGXYLayoutHints::kLRubberX";
144 else flag += " | TGXYLayoutHints::kLRubberX";
145 }
146 if (fFlag & kLRubberY) {
147 if (flag.Length() == 0) flag = "TGXYLayoutHints::kLRubberY";
148 else flag += " | TGXYLayoutHints::kLRubberY";
149 }
150 if (fFlag & kLRubberW) {
151 if (flag.Length() == 0) flag = "TGXYLayoutHints::kLRubberW";
152 else flag += " | TGXYLayoutHints::kLRubberW";
153 }
154 if (fFlag & kLRubberH) {
155 if (flag.Length() == 0) flag = "TGXYLayoutHints::kLRubberH";
156 else flag += " | TGXYLayoutHints::kLRubberH";
157 }
158
159 out << ", new TGXYLayoutHints(" << GetX() << ", " << GetY() << ", "
160 << GetW() << ", " << GetH();
161
162 if (!flag.Length())
163 out << ")";
164 else
165 out << ", " << flag << ")";
166
167}
168
169////////////////////////////////////////////////////////////////////////////////
170/// Constructor. The main is the frame for which this layout manager works.
171
173{
174 UInt_t width, height;
175 Int_t dummy;
176
177 fMain = main;
178 fList = main->GetList();
179 fFirst = kTRUE;
181
183
184 // get standard width an height of a character
185 fTWidth = gVirtualX->TextWidth(fs, "1234567890", 10) / 10;
186 gVirtualX->GetFontProperties(fs, fTHeight, dummy);
187
188 // the size of the main window are defined in units of a character
189 // but the system does not understand this. We have to recalculate
190 // the size into pixels.
191 width = main->GetWidth() * fTWidth;
192 height = main->GetHeight() * fTHeight;
193
194 main->Resize(width, height);
195}
196
197////////////////////////////////////////////////////////////////////////////////
198///copy constructor
199
201 TGLayoutManager(xyl),
202 fList(xyl.fList),
203 fMain(xyl.fMain),
204 fFirst(xyl.fFirst),
205 fFirstWidth(xyl.fFirstWidth),
206 fFirstHeight(xyl.fFirstHeight),
207 fTWidth(xyl.fTWidth),
208 fTHeight(xyl.fTHeight)
209{
210}
211
212////////////////////////////////////////////////////////////////////////////////
213///assignment operator
214
216{
217 if(this!=&xyl) {
219 fList=xyl.fList;
220 fMain=xyl.fMain;
221 fFirst=xyl.fFirst;
224 fTWidth=xyl.fTWidth;
225 fTHeight=xyl.fTHeight;
226 }
227 return *this;
228}
229
230////////////////////////////////////////////////////////////////////////////////
231/// Recalculates the postion and the size of all widgets.
232
234{
235 TGFrameElement *ptr;
236 TGXYLayoutHints *layout;
237 Double_t xFactor;
238 Double_t yFactor;
239 Int_t newX, newY;
240 UInt_t newW, newH;
241 Double_t temp;
242
243 if (!fList) return;
244
245 if (fFirst) {
246 // save the original size of the frame. It is used to determin
247 // if the user has changed the window
250 fFirst = kFALSE;
251 }
252
253 // get the factor to increase of window size
254 xFactor = (Double_t)fMain->GetWidth() / (Double_t)fFirstWidth;
255 if (xFactor < 1.0) xFactor = 1.0;
257 if (yFactor < 1.0) yFactor = 1.0;
258
259 // set the position an size for each widget and call the layout
260 // function for each widget
261 TIter next(fList);
262 while ((ptr = (TGFrameElement *) next())) {
263 if (ptr->fState & kIsVisible) {
264 layout = (TGXYLayoutHints*)ptr->fLayout;
265 if (layout == 0)
266 continue;
267
268 temp = layout->GetX() * fTWidth ;
269 if (layout->GetFlag() & TGXYLayoutHints::kLRubberX)
270 temp *= xFactor;
271 newX = (Int_t)(temp + 0.5);
272
273 temp = layout->GetY() * fTHeight;
274 if (layout->GetFlag() & TGXYLayoutHints::kLRubberY)
275 temp *= yFactor;
276 newY = (Int_t)(temp + 0.5);
277
278 temp = layout->GetW() * fTWidth;
279 if (layout->GetFlag() & TGXYLayoutHints::kLRubberW)
280 temp *= xFactor;
281 newW = (UInt_t)(temp + 0.5);
282
283 temp = layout->GetH() * fTHeight;
284 if (layout->GetFlag() & TGXYLayoutHints::kLRubberH)
285 temp *= yFactor;
286 newH = (UInt_t)(temp + 0.5);
287 ptr->fFrame->MoveResize(newX, newY, newW, newH);
288 ptr->fFrame->Layout();
289 }
290 }
291}
292
293////////////////////////////////////////////////////////////////////////////////
294/// Returns the original size of the frame.
295
297{
299
300 return size;
301}
302
303////////////////////////////////////////////////////////////////////////////////
304/// Save XY layout manager as a C++ statement(s) on output stream.
305
306void TGXYLayout::SavePrimitive(std::ostream &out, Option_t * /*option = ""*/)
307{
308 out << "new TGXYLayout(" << fMain->GetName() << ")";
309
310}
Handle_t FontStruct_t
Pointer to font structure.
Definition: GuiTypes.h:39
#define h(i)
Definition: RSha256.hxx:106
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Definition: RtypesCore.h:45
unsigned int UInt_t
Definition: RtypesCore.h:46
const Bool_t kFALSE
Definition: RtypesCore.h:101
double Double_t
Definition: RtypesCore.h:59
const Bool_t kTRUE
Definition: RtypesCore.h:100
const char Option_t
Definition: RtypesCore.h:66
#define ClassImp(name)
Definition: Rtypes.h:364
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:121
@ kIsVisible
Definition: TGFrame.h:33
@ kLHintsNormal
Definition: TGLayout.h:32
#define gVirtualX
Definition: TVirtualX.h:338
T1 fFirst
Definition: X11Events.mm:86
int main(int argc, char *argv[])
Definition: cef_main.cxx:54
The base class for composite widgets (menu bars, list boxes, etc.).
Definition: TGFrame.h:287
TGLayoutHints * fLayout
Definition: TGLayout.h:114
Int_t fState
Definition: TGLayout.h:113
TGFrame * fFrame
Definition: TGLayout.h:112
UInt_t GetHeight() const
Definition: TGFrame.h:225
virtual void Layout()
Definition: TGFrame.h:199
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:629
UInt_t GetWidth() const
Definition: TGFrame.h:224
static FontStruct_t GetDefaultFontStruct()
Static returning label default font struct.
Definition: TGLabel.cxx:525
This class describes layout hints used by the layout classes.
Definition: TGLayout.h:50
Frame layout manager.
Definition: TGLayout.h:135
virtual const char * GetName() const
Return unique name, used in SavePrimitive methods.
Definition: TGWindow.cxx:336
This layout hint must be used for the TGXYLayout manager!
Definition: TGXYLayout.h:19
Double_t GetX() const
Definition: TGXYLayout.h:40
virtual void SavePrimitive(std::ostream &out, Option_t *="")
Save XY layout hints as a C++ statement(s) on output stream.
Definition: TGXYLayout.cxx:139
TGXYLayoutHints(Double_t x, Double_t y, Double_t w, Double_t h, UInt_t rubberFlag=kLRubberX|kLRubberY)
Constructor.
Definition: TGXYLayout.cxx:125
Double_t fY
y - position of widget
Definition: TGXYLayout.h:23
Double_t fW
width of widget
Definition: TGXYLayout.h:24
Double_t fH
height of widget
Definition: TGXYLayout.h:25
Double_t GetH() const
Definition: TGXYLayout.h:43
Double_t GetW() const
Definition: TGXYLayout.h:42
UInt_t fFlag
rubber flag
Definition: TGXYLayout.h:26
Double_t fX
x - position of widget
Definition: TGXYLayout.h:22
Double_t GetY() const
Definition: TGXYLayout.h:41
UInt_t GetFlag() const
Definition: TGXYLayout.h:44
Is a layout manager where the position and the size of each widget in the frame are defined by X / Y ...
Definition: TGXYLayout.h:58
Int_t fTWidth
text width of a default character "1234567890" / 10
Definition: TGXYLayout.h:68
TList * fList
list of frames to arrange
Definition: TGXYLayout.h:61
TGXYLayout(const TGXYLayout &)
copy constructor
Definition: TGXYLayout.cxx:200
UInt_t fFirstWidth
original width of the frame fMain
Definition: TGXYLayout.h:65
UInt_t fFirstHeight
original height of the fram fMain
Definition: TGXYLayout.h:66
TGCompositeFrame * fMain
container frame
Definition: TGXYLayout.h:62
TGXYLayout & operator=(const TGXYLayout &)
assignment operator
Definition: TGXYLayout.cxx:215
virtual TGDimension GetDefaultSize() const
Returns the original size of the frame.
Definition: TGXYLayout.cxx:296
Int_t fTHeight
text height
Definition: TGXYLayout.h:69
virtual void Layout()
Recalculates the postion and the size of all widgets.
Definition: TGXYLayout.cxx:233
Bool_t fFirst
flag to determine the first call of Layout()
Definition: TGXYLayout.h:64
virtual void SavePrimitive(std::ostream &out, Option_t *="")
Save XY layout manager as a C++ statement(s) on output stream.
Definition: TGXYLayout.cxx:306
TObject & operator=(const TObject &rhs)
TObject assignment operator.
Definition: TObject.h:283
Basic string class.
Definition: TString.h:136
Ssiz_t Length() const
Definition: TString.h:410
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17