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