Logo ROOT   master
Reference Guide
TGWindow.cxx
Go to the documentation of this file.
1 // @(#)root/gui:$Id$
2 // Author: Fons Rademakers 28/12/97
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 
13  This source is based on Xclass95, a Win95-looking GUI toolkit.
14  Copyright (C) 1996, 1997 David Barth, Ricky Ralston, Hector Peraza.
15 
16  Xclass95 is free software; you can redistribute it and/or
17  modify it under the terms of the GNU Library General Public
18  License as published by the Free Software Foundation; either
19  version 2 of the License, or (at your option) any later version.
20 
21 **************************************************************************/
22 
23 //////////////////////////////////////////////////////////////////////////
24 // //
25 // TGWindow //
26 // //
27 // ROOT GUI Window base class. //
28 // //
29 //////////////////////////////////////////////////////////////////////////
30 
31 #include "TGWindow.h"
32 #include "Riostream.h"
33 #include "TApplication.h"
34 #include "TVirtualX.h"
35 
38 
40 
41 ////////////////////////////////////////////////////////////////////////////////
42 /// Create a new window. Parent p must exist otherwise the root window
43 /// is taken as parent. No arguments specified results in values from
44 /// parent to be taken (or defaults).
45 
47  UInt_t border, Int_t depth, UInt_t clss, void *visual,
48  SetWindowAttributes_t *attr, UInt_t wtype)
49 {
50  UInt_t type = wtype;
51  fId = 0;
52  fParent = 0;
54 
55  if (!p && gClient) {
56  p = gClient->GetRoot();
57  }
58 
59  if (p) {
60  fClient = p->fClient;
61  if (fClient->IsEditable()) type = wtype & ~1;
62 
63  fParent = p;
64  if (fParent && fParent->IsMapSubwindows()) {
65  fId = gVirtualX->CreateWindow(fParent->fId, x, y,
66  TMath::Max(w, (UInt_t) 1),
67  TMath::Max(h, (UInt_t) 1), border,
68  depth, clss, visual, attr, type);
69  fClient->RegisterWindow(this);
70  }
71 
72  // name will be used in SavePrimitive methods
73  fgCounter++;
74  fName = "frame";
75  fName += fgCounter;
76  }
77  fEditDisabled = (fId != gVirtualX->GetDefaultRootWindow()) && fParent ?
79 
80  // add protection for the root window on Cocoa (MacOS X)
81  if (fClient && fClient->GetDefaultRoot())
82  SetWindowName();
83 }
84 
85 ////////////////////////////////////////////////////////////////////////////////
86 /// Create a copy of a window.
87 
89 {
90  fClient = c;
91  fId = id;
92  fParent = parent;
93  fClient->RegisterWindow(this);
95  fEditDisabled = (fId != gVirtualX->GetDefaultRootWindow()) && fParent ?
97 
98  // name used in SavePrimitive methods
99  fgCounter++;
100  fName = "frame";
101  fName += fgCounter;
102 }
103 
104 ////////////////////////////////////////////////////////////////////////////////
105 /// Window destructor. Unregisters the window.
106 
108 {
109  if (fClient) {
110  if (fParent == fClient->GetDefaultRoot())
111  DestroyWindow();
112  fClient->UnregisterWindow(this);
113  }
114 }
115 
116 ////////////////////////////////////////////////////////////////////////////////
117 /// Set window name.
118 
119 void TGWindow::SetWindowName(const char *name)
120 {
121  if (!name && gDebug > 0) {
122  // set default frame names only when in debug mode
123  TString wname = ClassName();
124  wname += "::" + fName;
125  gVirtualX->SetWindowName(fId, (char *)wname.Data());
126  } else {
127  gVirtualX->SetWindowName(fId, (char *)name);
128  }
129 }
130 
131 ////////////////////////////////////////////////////////////////////////////////
132 /// Returns top level main frame.
133 
135 {
136  return ((fParent == 0) || (fParent == fClient->GetDefaultRoot())) ? this : fParent->GetMainFrame();
137 }
138 
139 ////////////////////////////////////////////////////////////////////////////////
140 /// map window
141 
143 {
144  gVirtualX->MapWindow(fId);
145 }
146 
147 ////////////////////////////////////////////////////////////////////////////////
148 /// map sub windows
149 
151 {
152  gVirtualX->MapSubwindows(fId);
153 }
154 
155 ////////////////////////////////////////////////////////////////////////////////
156 /// map raised
157 
159 {
160  gVirtualX->MapRaised(fId);
161 }
162 
163 ////////////////////////////////////////////////////////////////////////////////
164 /// unmap window
165 
167 {
168  gVirtualX->UnmapWindow(fId);
169 }
170 
171 ////////////////////////////////////////////////////////////////////////////////
172 /// destroy window
173 
175 {
176  gVirtualX->DestroyWindow(fId);
177 }
178 
179 ////////////////////////////////////////////////////////////////////////////////
180 /// destroy sub windows
181 
183 {
184  gVirtualX->DestroySubwindows(fId);
185 }
186 
187 ////////////////////////////////////////////////////////////////////////////////
188 /// raise window
189 
191 {
192  gVirtualX->RaiseWindow(fId);
193 }
194 
195 ////////////////////////////////////////////////////////////////////////////////
196 /// lower window
197 
199 {
200  gVirtualX->LowerWindow(fId);
201 }
202 
203 ////////////////////////////////////////////////////////////////////////////////
204 /// iconify window
205 
207 {
208  gVirtualX->IconifyWindow(fId);
209 }
210 
211 ////////////////////////////////////////////////////////////////////////////////
212 /// request focus
213 
215 {
216  gVirtualX->SetInputFocus(fId);
217 }
218 
219 ////////////////////////////////////////////////////////////////////////////////
220 /// set background color
221 
223 {
224  gVirtualX->SetWindowBackground(fId, color);
225 }
226 
227 ////////////////////////////////////////////////////////////////////////////////
228 /// set background pixmap
229 
231 {
232  gVirtualX->SetWindowBackgroundPixmap(fId, pixmap);
233 }
234 
235 ////////////////////////////////////////////////////////////////////////////////
236 /// Reparent window, make p the new parent and position the window at
237 /// position (x,y) in new parent.
238 
240 {
241  if (p == fParent) return;
242 
243  if (p) {
244  gVirtualX->ReparentWindow(fId, p->GetId(), x, y);
245  gVirtualX->Update(1);
246  }
247  fParent = p;
248 }
249 
250 ////////////////////////////////////////////////////////////////////////////////
251 /// Move the window.
252 
254 {
255  gVirtualX->MoveWindow(fId, x, y);
256 }
257 
258 ////////////////////////////////////////////////////////////////////////////////
259 /// Resize the window.
260 
262 {
263  gVirtualX->ResizeWindow(fId, TMath::Max(w, (UInt_t)1), TMath::Max(h, (UInt_t)1));
264 }
265 
266 ////////////////////////////////////////////////////////////////////////////////
267 /// Move and resize the window.
268 
270 {
271  gVirtualX->MoveResizeWindow(fId, x, y, TMath::Max(w, (UInt_t)1), TMath::Max(h, (UInt_t)1));
272 }
273 
274 ////////////////////////////////////////////////////////////////////////////////
275 /// Returns kTRUE if window is mapped on screen, kFALSE otherwise.
276 
278 {
279  WindowAttributes_t attr;
280 
281  gVirtualX->GetWindowAttributes(fId, attr);
282  return (attr.fMapState != kIsUnmapped);
283 }
284 
285 ////////////////////////////////////////////////////////////////////////////////
286 /// Print window id.
287 /// If option is "tree" - print all parent windows tree
288 
289 void TGWindow::Print(Option_t *option) const
290 {
291  TString opt = option;
292 
293  if (opt.Contains("tree")) {
294 
295  const TGWindow *parent = fParent;
296  std::cout << ClassName() << ":\t" << fId << std::endl;
297 
298  while (parent && (parent != fClient->GetDefaultRoot())) {
299  std::cout << "\t" << parent->ClassName() << ":\t" << parent->GetId() << std::endl;
300  parent = parent->GetParent();
301  }
302  } else {
303  std::cout << ClassName() << ":\t" << fId << std::endl;
304  }
305 }
306 
307 ////////////////////////////////////////////////////////////////////////////////
308 /// Return global window counter (total number of created windows).
309 
311 {
312  return fgCounter;
313 }
314 
315 ////////////////////////////////////////////////////////////////////////////////
316 /// Return unique name, used in SavePrimitive methods.
317 
318 const char *TGWindow::GetName()const
319 {
320  TGWindow *w = (TGWindow*)this;
321 
322  if (fName.BeginsWith("frame")) {
323  TString cname = ClassName();
324  if (cname.BeginsWith("TGed"))
325  cname.Replace(0, 1, 'f');
326  else if (cname.BeginsWith("TG"))
327  cname.Replace(0,2,'f');
328  else
329  cname.Replace(0, 1, 'f');
330  w->fName.Remove(0,5);
331  w->fName = cname + w->fName;
332  }
333 
334  if (w->fName.Contains(" "))
335  w->fName.ReplaceAll(" ", "");
336  if (w->fName.Contains(":"))
337  w->fName.ReplaceAll(":", "");
338 
339  return fName.Data();
340 }
const TGWindow * fParent
Definition: TGWindow.h:36
virtual ~TGWindow()
Window destructor. Unregisters the window.
Definition: TGWindow.cxx:107
const char Option_t
Definition: RtypesCore.h:62
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:687
static Int_t fgCounter
Definition: TGWindow.h:39
Bool_t fNeedRedraw
Definition: TGWindow.h:37
virtual void DestroySubwindows()
destroy sub windows
Definition: TGWindow.cxx:182
virtual void DestroyWindow()
destroy window
Definition: TGWindow.cxx:174
Basic string class.
Definition: TString.h:131
#define gClient
Definition: TGClient.h:166
int Int_t
Definition: RtypesCore.h:41
virtual Bool_t IsMapSubwindows() const
Definition: TGWindow.h:125
Handle_t GetId() const
Definition: TGObject.h:47
void UnregisterWindow(TGWindow *w)
Remove a TGWindow from the list of windows.
Definition: TGClient.cxx:522
TString & Replace(Ssiz_t pos, Ssiz_t n, const char *s)
Definition: TString.h:677
virtual void SetBackgroundPixmap(Pixmap_t pixmap)
set background pixmap
Definition: TGWindow.cxx:230
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:127
TGWindow(Window_t id)
Definition: TGWindow.h:42
virtual void MapWindow()
map window
Definition: TGWindow.cxx:142
Double_t x[n]
Definition: legend1.C:17
ULong_t Pixel_t
Definition: GuiTypes.h:39
virtual void MapSubwindows()
map sub windows
Definition: TGWindow.cxx:150
virtual void ReparentWindow(const TGWindow *p, Int_t x=0, Int_t y=0)
Reparent window, make p the new parent and position the window at position (x,y) in new parent...
Definition: TGWindow.cxx:239
void RegisterWindow(TGWindow *w)
Add a TGWindow to the clients list of windows.
Definition: TGClient.cxx:511
virtual const TGWindow * GetMainFrame() const
Returns top level main frame.
Definition: TGWindow.cxx:134
XFontStruct * id
Definition: TGX11.cxx:108
virtual void Print(Option_t *option="") const
Print window id.
Definition: TGWindow.cxx:289
virtual void MapRaised()
map raised
Definition: TGWindow.cxx:158
virtual void Resize(UInt_t w, UInt_t h)
Resize the window.
Definition: TGWindow.cxx:261
Bool_t IsEditable() const
Definition: TGClient.h:98
virtual void UnmapWindow()
unmap window
Definition: TGWindow.cxx:166
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition: TString.h:610
virtual const char * GetName() const
Return unique name, used in SavePrimitive methods.
Definition: TGWindow.cxx:318
unsigned int UInt_t
Definition: RtypesCore.h:42
TString fName
Definition: TGWindow.h:38
virtual void SetBackgroundColor(Pixel_t color)
set background color
Definition: TGWindow.cxx:222
#define gVirtualX
Definition: TVirtualX.h:338
#define h(i)
Definition: RSha256.hxx:106
const Bool_t kFALSE
Definition: RtypesCore.h:88
virtual void Move(Int_t x, Int_t y)
Move the window.
Definition: TGWindow.cxx:253
TString & Remove(Ssiz_t pos)
Definition: TString.h:668
#define ClassImp(name)
Definition: Rtypes.h:365
int type
Definition: TGX11.cxx:120
Double_t y[n]
Definition: legend1.C:17
virtual Bool_t IsMapped()
Returns kTRUE if window is mapped on screen, kFALSE otherwise.
Definition: TGWindow.cxx:277
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:619
const TGWindow * GetParent() const
Definition: TGWindow.h:84
Handle_t fId
Definition: TGObject.h:36
virtual void MoveResize(Int_t x, Int_t y, UInt_t w, UInt_t h)
Move and resize the window.
Definition: TGWindow.cxx:269
Handle_t Window_t
Definition: GuiTypes.h:28
TGClient * fClient
Definition: TGObject.h:37
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:212
static Int_t GetCounter()
Return global window counter (total number of created windows).
Definition: TGWindow.cxx:310
Handle_t Pixmap_t
Definition: GuiTypes.h:29
const TGWindow * GetDefaultRoot() const
Returns the root (i.e.
Definition: TGClient.cxx:234
virtual void RequestFocus()
request focus
Definition: TGWindow.cxx:214
UInt_t fEditDisabled
Definition: TGWindow.h:40
R__EXTERN Int_t gDebug
Definition: Rtypes.h:91
#define c(i)
Definition: RSha256.hxx:101
virtual void LowerWindow()
lower window
Definition: TGWindow.cxx:198
virtual void IconifyWindow()
iconify window
Definition: TGWindow.cxx:206
char name[80]
Definition: TGX11.cxx:109
virtual void RaiseWindow()
raise window
Definition: TGWindow.cxx:190
virtual void SetWindowName(const char *name=0)
Set window name.
Definition: TGWindow.cxx:119
const char * Data() const
Definition: TString.h:364