Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 "TVirtualX.h"
103
104#include <iostream>
105
106
109
110////////////////////////////////////////////////////////////////////////////////
111/// Constructor. The x, y, w and h define the position of the widget in
112/// its frame and the size of the widget. The unit is the size of a
113/// character. The rubberFlag defines how to move and to resize the
114/// widget when the frame is resized. Default is moving the X and Y
115/// position but keep the size of the widget.
116
118 UInt_t rubberFlag)
119 : TGLayoutHints(kLHintsNormal, 0,0,0,0)
120{
121 fX = x;
122 fY = y;
123 fW = w;
124 fH = h;
125 fFlag = rubberFlag;
126}
127
128////////////////////////////////////////////////////////////////////////////////
129/// Save XY layout hints as a C++ statement(s) on output stream.
130
131void TGXYLayoutHints::SavePrimitive(std::ostream &out, Option_t * /*option = ""*/)
132{
133 TString flag = "";
134 if (fFlag & kLRubberX) {
135 if (flag.Length() == 0) flag = "TGXYLayoutHints::kLRubberX";
136 else flag += " | TGXYLayoutHints::kLRubberX";
137 }
138 if (fFlag & kLRubberY) {
139 if (flag.Length() == 0) flag = "TGXYLayoutHints::kLRubberY";
140 else flag += " | TGXYLayoutHints::kLRubberY";
141 }
142 if (fFlag & kLRubberW) {
143 if (flag.Length() == 0) flag = "TGXYLayoutHints::kLRubberW";
144 else flag += " | TGXYLayoutHints::kLRubberW";
145 }
146 if (fFlag & kLRubberH) {
147 if (flag.Length() == 0) flag = "TGXYLayoutHints::kLRubberH";
148 else flag += " | TGXYLayoutHints::kLRubberH";
149 }
150
151 out << ", new TGXYLayoutHints(" << GetX() << ", " << GetY() << ", "
152 << GetW() << ", " << GetH();
153
154 if (!flag.Length())
155 out << ")";
156 else
157 out << ", " << flag << ")";
158
159}
160
161////////////////////////////////////////////////////////////////////////////////
162/// Constructor. The main is the frame for which this layout manager works.
163
165{
166 UInt_t width, height;
167 Int_t dummy;
168
169 fMain = main;
170 fList = main->GetList();
171 fFirst = kTRUE;
173
175
176 // get standard width an height of a character
177 fTWidth = gVirtualX->TextWidth(fs, "1234567890", 10) / 10;
178 gVirtualX->GetFontProperties(fs, fTHeight, dummy);
179
180 // the size of the main window are defined in units of a character
181 // but the system does not understand this. We have to recalculate
182 // the size into pixels.
183 width = main->GetWidth() * fTWidth;
184 height = main->GetHeight() * fTHeight;
185
186 main->Resize(width, height);
187}
188
189////////////////////////////////////////////////////////////////////////////////
190///copy constructor
191
193 TGLayoutManager(xyl),
194 fList(xyl.fList),
195 fMain(xyl.fMain),
196 fFirst(xyl.fFirst),
197 fFirstWidth(xyl.fFirstWidth),
198 fFirstHeight(xyl.fFirstHeight),
199 fTWidth(xyl.fTWidth),
200 fTHeight(xyl.fTHeight)
201{
202}
203
204////////////////////////////////////////////////////////////////////////////////
205///assignment operator
206
208{
209 if(this!=&xyl) {
211 fList=xyl.fList;
212 fMain=xyl.fMain;
213 fFirst=xyl.fFirst;
216 fTWidth=xyl.fTWidth;
217 fTHeight=xyl.fTHeight;
218 }
219 return *this;
220}
221
222////////////////////////////////////////////////////////////////////////////////
223/// Recalculates the postion and the size of all widgets.
224
226{
227 TGFrameElement *ptr;
228 TGXYLayoutHints *layout;
229 Double_t xFactor;
230 Double_t yFactor;
231 Int_t newX, newY;
232 UInt_t newW, newH;
233 Double_t temp;
234
235 if (!fList) return;
236
237 if (fFirst) {
238 // save the original size of the frame. It is used to determin
239 // if the user has changed the window
242 fFirst = kFALSE;
243 }
244
245 // get the factor of the increacement of the window
246 xFactor = (Double_t)fMain->GetWidth() / (Double_t)fFirstWidth;
247 if (xFactor < 1.0) xFactor = 1.0;
249 if (yFactor < 1.0) yFactor = 1.0;
250
251 // set the position an size for each widget and call the layout
252 // function for each widget
253 TIter next(fList);
254 while ((ptr = (TGFrameElement *) next())) {
255 if (ptr->fState & kIsVisible) {
256 layout = (TGXYLayoutHints*)ptr->fLayout;
257 if (layout == 0)
258 continue;
259
260 temp = layout->GetX() * fTWidth ;
261 if (layout->GetFlag() & TGXYLayoutHints::kLRubberX)
262 temp *= xFactor;
263 newX = (Int_t)(temp + 0.5);
264
265 temp = layout->GetY() * fTHeight;
266 if (layout->GetFlag() & TGXYLayoutHints::kLRubberY)
267 temp *= yFactor;
268 newY = (Int_t)(temp + 0.5);
269
270 temp = layout->GetW() * fTWidth;
271 if (layout->GetFlag() & TGXYLayoutHints::kLRubberW)
272 temp *= xFactor;
273 newW = (UInt_t)(temp + 0.5);
274
275 temp = layout->GetH() * fTHeight;
276 if (layout->GetFlag() & TGXYLayoutHints::kLRubberH)
277 temp *= yFactor;
278 newH = (UInt_t)(temp + 0.5);
279 ptr->fFrame->MoveResize(newX, newY, newW, newH);
280 ptr->fFrame->Layout();
281 }
282 }
283}
284
285////////////////////////////////////////////////////////////////////////////////
286/// Returns the original size of the frame.
287
289{
291
292 return size;
293}
294
295////////////////////////////////////////////////////////////////////////////////
296/// Save XY layout manager as a C++ statement(s) on output stream.
297
298void TGXYLayout::SavePrimitive(std::ostream &out, Option_t * /*option = ""*/)
299{
300 out << "new TGXYLayout(" << fMain->GetName() << ")";
301
302}
Handle_t FontStruct_t
Pointer to font structure.
Definition GuiTypes.h:39
#define h(i)
Definition RSha256.hxx:106
int Int_t
Definition RtypesCore.h:45
unsigned int UInt_t
Definition RtypesCore.h:46
const Bool_t kFALSE
Definition RtypesCore.h:92
double Double_t
Definition RtypesCore.h:59
const Bool_t kTRUE
Definition RtypesCore.h:91
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
@ kIsVisible
Definition TGFrame.h:41
@ kLHintsNormal
Definition TGLayout.h:39
#define gVirtualX
Definition TVirtualX.h:338
T1 fFirst
Definition X11Events.mm:86
TGLayoutHints * fLayout
Definition TGLayout.h:121
TGFrame * fFrame
Definition TGLayout.h:119
UInt_t GetHeight() const
Definition TGFrame.h:249
virtual void Layout()
Definition TGFrame.h:223
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:614
UInt_t GetWidth() const
Definition TGFrame.h:248
static FontStruct_t GetDefaultFontStruct()
Static returning label default font struct.
Definition TGLabel.cxx:524
virtual const char * GetName() const
Return unique name, used in SavePrimitive methods.
Definition TGWindow.cxx:335
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.
TGXYLayoutHints(Double_t x, Double_t y, Double_t w, Double_t h, UInt_t rubberFlag=kLRubberX|kLRubberY)
Constructor.
Double_t GetH() const
Definition TGXYLayout.h:119
Double_t GetW() const
Definition TGXYLayout.h:118
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
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
virtual TGDimension GetDefaultSize() const
Returns the original size of the frame.
Int_t fTHeight
Definition TGXYLayout.h:145
virtual void Layout()
Recalculates the postion and the size of all widgets.
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.
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
int main()
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17