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 "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 
131 void 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;
248  yFactor = (Double_t)fMain->GetHeight() / (Double_t)fFirstHeight;
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 
298 void TGXYLayout::SavePrimitive(std::ostream &out, Option_t * /*option = ""*/)
299 {
300  out << "new TGXYLayout(" << fMain->GetName() << ")";
301 
302 }
TGXYLayout::SavePrimitive
virtual void SavePrimitive(std::ostream &out, Option_t *="")
Save XY layout manager as a C++ statement(s) on output stream.
Definition: TGXYLayout.cxx:298
TGXYLayout::fTHeight
Int_t fTHeight
Definition: TGXYLayout.h:145
TGFrame::GetHeight
UInt_t GetHeight() const
Definition: TGFrame.h:250
TGXYLayoutHints::GetH
Double_t GetH() const
Definition: TGXYLayout.h:125
TGFrameElement::fLayout
TGLayoutHints * fLayout
Definition: TGLayout.h:121
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TGXYLayoutHints::fX
Double_t fX
Definition: TGXYLayout.h:104
TGXYLayout::fFirstWidth
UInt_t fFirstWidth
Definition: TGXYLayout.h:141
TGXYLayout::Layout
virtual void Layout()
Recalculates the postion and the size of all widgets.
Definition: TGXYLayout.cxx:225
TGXYLayoutHints::kLRubberH
@ kLRubberH
Definition: TGXYLayout.h:116
TGDimension
Definition: TGDimension.h:27
TGXYLayoutHints::kLRubberW
@ kLRubberW
Definition: TGXYLayout.h:115
gVirtualX
#define gVirtualX
Definition: TVirtualX.h:338
TGXYLayout::operator=
TGXYLayout & operator=(const TGXYLayout &)
assignment operator
Definition: TGXYLayout.cxx:207
TGFrameElement::fState
Int_t fState
Definition: TGLayout.h:120
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
TGXYLayoutHints::fFlag
UInt_t fFlag
Definition: TGXYLayout.h:108
FontStruct_t
Handle_t FontStruct_t
Definition: GuiTypes.h:38
TGXYLayoutHints
Definition: TGXYLayout.h:95
width
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:121
kIsVisible
@ kIsVisible
Definition: TGFrame.h:42
Int_t
int Int_t
Definition: RtypesCore.h:45
x
Double_t x[n]
Definition: legend1.C:17
TString::Length
Ssiz_t Length() const
Definition: TString.h:410
TGXYLayoutHints::kLRubberX
@ kLRubberX
Definition: TGXYLayout.h:113
TGLabel::GetDefaultFontStruct
static FontStruct_t GetDefaultFontStruct()
Static returning label default font struct.
Definition: TGLabel.cxx:524
TVirtualX.h
TGXYLayoutHints::GetW
Double_t GetW() const
Definition: TGXYLayout.h:124
TString
Definition: TString.h:136
TGXYLayout
Definition: TGXYLayout.h:134
TGFrame::GetWidth
UInt_t GetWidth() const
Definition: TGFrame.h:249
TGFrameElement::fFrame
TGFrame * fFrame
Definition: TGLayout.h:119
TGLayoutManager
Definition: TGLayout.h:142
TGXYLayoutHints::fW
Double_t fW
Definition: TGXYLayout.h:106
TGXYLayout::GetDefaultSize
virtual TGDimension GetDefaultSize() const
Returns the original size of the frame.
Definition: TGXYLayout.cxx:288
TGXYLayout::fFirstHeight
UInt_t fFirstHeight
Definition: TGXYLayout.h:142
Option_t
const typedef char Option_t
Definition: RtypesCore.h:66
kLHintsNormal
@ kLHintsNormal
Definition: TGLayout.h:45
TGXYLayoutHints::TGXYLayoutHints
TGXYLayoutHints(Double_t x, Double_t y, Double_t w, Double_t h, UInt_t rubberFlag=kLRubberX|kLRubberY)
Constructor.
Definition: TGXYLayout.cxx:117
h
#define h(i)
Definition: RSha256.hxx:124
TGWindow::GetName
virtual const char * GetName() const
Return unique name, used in SavePrimitive methods.
Definition: TGWindow.cxx:317
TGXYLayout::fTWidth
Int_t fTWidth
Definition: TGXYLayout.h:144
TGXYLayout::fFirst
Bool_t fFirst
Definition: TGXYLayout.h:140
TGXYLayoutHints::GetY
Double_t GetY() const
Definition: TGXYLayout.h:123
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TGFrame.h
main
int main(int argc, char **argv)
Definition: histspeedtest.cxx:751
TGLayoutHints
Definition: TGLayout.h:57
TGXYLayout::fList
TList * fList
Definition: TGXYLayout.h:137
UInt_t
unsigned int UInt_t
Definition: RtypesCore.h:46
TGXYLayoutHints::GetFlag
UInt_t GetFlag() const
Definition: TGXYLayout.h:126
y
Double_t y[n]
Definition: legend1.C:17
TGXYLayoutHints::fH
Double_t fH
Definition: TGXYLayout.h:107
unsigned int
TGXYLayoutHints::kLRubberY
@ kLRubberY
Definition: TGXYLayout.h:114
TGLabel.h
TGXYLayout::fMain
TGCompositeFrame * fMain
Definition: TGXYLayout.h:138
Double_t
double Double_t
Definition: RtypesCore.h:59
TObject::operator=
TObject & operator=(const TObject &rhs)
TObject assignment operator.
Definition: TObject.h:268
TGXYLayout.h
dummy
static RooMathCoreReg dummy
Definition: RooMathCoreReg.cxx:27
TGFrame::MoveResize
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
TGFrameElement
Definition: TGLayout.h:112
TGXYLayoutHints::SavePrimitive
virtual void SavePrimitive(std::ostream &out, Option_t *="")
Save XY layout hints as a C++ statement(s) on output stream.
Definition: TGXYLayout.cxx:131
TIter
Definition: TCollection.h:233
fFirst
T1 fFirst
Definition: X11Events.mm:86
TGXYLayout::TGXYLayout
TGXYLayout(const TGXYLayout &)
copy constructor
Definition: TGXYLayout.cxx:192
TGFrame::Layout
virtual void Layout()
Definition: TGFrame.h:224
TGCompositeFrame
Definition: TGFrame.h:324
TGXYLayoutHints::fY
Double_t fY
Definition: TGXYLayout.h:105
TGXYLayoutHints::GetX
Double_t GetX() const
Definition: TGXYLayout.h:122
int