Logo ROOT  
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;
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);
70 }
71
72 // name will be used in SavePrimitive methods
73 fgCounter++;
74 fName = "frame";
76 }
77 fEditDisabled = (fId != gVirtualX->GetDefaultRootWindow()) && fParent ?
79
80 // add protection for the root window on Cocoa (MacOS X)
83}
84
85////////////////////////////////////////////////////////////////////////////////
86/// Create a copy of a window.
87
89{
90 fClient = c;
91 fId = id;
92 fParent = parent;
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) {
113 }
114}
115
116////////////////////////////////////////////////////////////////////////////////
117/// Set window name.
118
120{
121#ifdef R__MACOSX
122 // MacOS fails to find the drawable of GetDefaultRootWindow(), only subsequent
123 // windows ids can be found. See discussion here:
124 // https://github.com/root-project/root/pull/6757#discussion_r518776154
125 if (fId == gVirtualX->GetDefaultRootWindow())
126 return;
127#endif
128
129 if (!name && gDebug > 0) {
130 // set default frame names only when in debug mode
131 TString wname = ClassName();
132 wname += "::" + fName;
133 gVirtualX->SetWindowName(fId, (char *)wname.Data());
134 } else {
135 gVirtualX->SetWindowName(fId, (char *)name);
136 }
137}
138
139////////////////////////////////////////////////////////////////////////////////
140/// Returns top level main frame.
141
143{
144 return ((fParent == 0) || (fParent == fClient->GetDefaultRoot())) ? this : fParent->GetMainFrame();
145}
146
147////////////////////////////////////////////////////////////////////////////////
148/// map window
149
151{
152 gVirtualX->MapWindow(fId);
153}
154
155////////////////////////////////////////////////////////////////////////////////
156/// map sub windows
157
159{
160 gVirtualX->MapSubwindows(fId);
161}
162
163////////////////////////////////////////////////////////////////////////////////
164/// map raised
165
167{
168 gVirtualX->MapRaised(fId);
169}
170
171////////////////////////////////////////////////////////////////////////////////
172/// unmap window
173
175{
176 gVirtualX->UnmapWindow(fId);
177}
178
179////////////////////////////////////////////////////////////////////////////////
180/// destroy window
181
183{
184 gVirtualX->DestroyWindow(fId);
185}
186
187////////////////////////////////////////////////////////////////////////////////
188/// destroy sub windows
189
191{
192 gVirtualX->DestroySubwindows(fId);
193}
194
195////////////////////////////////////////////////////////////////////////////////
196/// raise window
197
199{
200 gVirtualX->RaiseWindow(fId);
201}
202
203////////////////////////////////////////////////////////////////////////////////
204/// lower window
205
207{
208 gVirtualX->LowerWindow(fId);
209}
210
211////////////////////////////////////////////////////////////////////////////////
212/// iconify window
213
215{
216 gVirtualX->IconifyWindow(fId);
217}
218
219////////////////////////////////////////////////////////////////////////////////
220/// request focus
221
223{
224 gVirtualX->SetInputFocus(fId);
225}
226
227////////////////////////////////////////////////////////////////////////////////
228/// set background color
229
231{
232 gVirtualX->SetWindowBackground(fId, color);
233}
234
235////////////////////////////////////////////////////////////////////////////////
236/// set background pixmap
237
239{
240 gVirtualX->SetWindowBackgroundPixmap(fId, pixmap);
241}
242
243////////////////////////////////////////////////////////////////////////////////
244/// Reparent window, make p the new parent and position the window at
245/// position (x,y) in new parent.
246
248{
249 if (p == fParent) return;
250
251 if (p) {
252 gVirtualX->ReparentWindow(fId, p->GetId(), x, y);
253 gVirtualX->Update(1);
254 }
255 fParent = p;
256}
257
258////////////////////////////////////////////////////////////////////////////////
259/// Move the window.
260
262{
263 gVirtualX->MoveWindow(fId, x, y);
264}
265
266////////////////////////////////////////////////////////////////////////////////
267/// Resize the window.
268
270{
271 gVirtualX->ResizeWindow(fId, TMath::Max(w, (UInt_t)1), TMath::Max(h, (UInt_t)1));
272}
273
274////////////////////////////////////////////////////////////////////////////////
275/// Move and resize the window.
276
278{
279 gVirtualX->MoveResizeWindow(fId, x, y, TMath::Max(w, (UInt_t)1), TMath::Max(h, (UInt_t)1));
280}
281
282////////////////////////////////////////////////////////////////////////////////
283/// Returns kTRUE if window is mapped on screen, kFALSE otherwise.
284
286{
288
289 gVirtualX->GetWindowAttributes(fId, attr);
290 return (attr.fMapState != kIsUnmapped);
291}
292
293////////////////////////////////////////////////////////////////////////////////
294/// Print window id.
295/// If option is "tree" - print all parent windows tree
296
297void TGWindow::Print(Option_t *option) const
298{
299 TString opt = option;
300
301 if (opt.Contains("tree")) {
302
303 const TGWindow *parent = fParent;
304 std::cout << ClassName() << ":\t" << fId << std::endl;
305
306 while (parent && (parent != fClient->GetDefaultRoot())) {
307 std::cout << "\t" << parent->ClassName() << ":\t" << parent->GetId() << std::endl;
308 parent = parent->GetParent();
309 }
310 } else {
311 std::cout << ClassName() << ":\t" << fId << std::endl;
312 }
313}
314
315////////////////////////////////////////////////////////////////////////////////
316/// Return global window counter (total number of created windows).
317
319{
320 return fgCounter;
321}
322
323////////////////////////////////////////////////////////////////////////////////
324/// Return unique name, used in SavePrimitive methods.
325
326const char *TGWindow::GetName()const
327{
328 TGWindow *w = (TGWindow*)this;
329
330 if (fName.BeginsWith("frame")) {
331 TString cname = ClassName();
332 if (cname.BeginsWith("TGed"))
333 cname.Replace(0, 1, 'f');
334 else if (cname.BeginsWith("TG"))
335 cname.Replace(0,2,'f');
336 else
337 cname.Replace(0, 1, 'f');
338 w->fName.Remove(0,5);
339 w->fName = cname + w->fName;
340 }
341
342 if (w->fName.Contains(" "))
343 w->fName.ReplaceAll(" ", "");
344 if (w->fName.Contains(":"))
345 w->fName.ReplaceAll(":", "");
346
347 return fName.Data();
348}
Handle_t Pixmap_t
Definition: GuiTypes.h:29
@ kIsUnmapped
Definition: GuiTypes.h:45
ULong_t Pixel_t
Definition: GuiTypes.h:39
Handle_t Window_t
Definition: GuiTypes.h:28
#define c(i)
Definition: RSha256.hxx:101
#define h(i)
Definition: RSha256.hxx:106
int Int_t
Definition: RtypesCore.h:43
const Bool_t kFALSE
Definition: RtypesCore.h:90
R__EXTERN Int_t gDebug
Definition: RtypesCore.h:117
const char Option_t
Definition: RtypesCore.h:64
#define ClassImp(name)
Definition: Rtypes.h:361
#define gClient
Definition: TGClient.h:166
XFontStruct * id
Definition: TGX11.cxx:108
char name[80]
Definition: TGX11.cxx:109
int type
Definition: TGX11.cxx:120
#define gVirtualX
Definition: TVirtualX.h:338
const TGWindow * GetDefaultRoot() const
Returns the root (i.e.
Definition: TGClient.cxx:234
Bool_t IsEditable() const
Definition: TGClient.h:98
void RegisterWindow(TGWindow *w)
Add a TGWindow to the clients list of windows.
Definition: TGClient.cxx:511
void UnregisterWindow(TGWindow *w)
Remove a TGWindow from the list of windows.
Definition: TGClient.cxx:522
TGClient * fClient
Definition: TGObject.h:37
Handle_t GetId() const
Definition: TGObject.h:47
Handle_t fId
Definition: TGObject.h:36
virtual void SetWindowName(const char *name=0)
Set window name.
Definition: TGWindow.cxx:119
virtual const TGWindow * GetMainFrame() const
Returns top level main frame.
Definition: TGWindow.cxx:142
virtual void Move(Int_t x, Int_t y)
Move the window.
Definition: TGWindow.cxx:261
virtual const char * GetName() const
Return unique name, used in SavePrimitive methods.
Definition: TGWindow.cxx:326
virtual ~TGWindow()
Window destructor. Unregisters the window.
Definition: TGWindow.cxx:107
virtual void Print(Option_t *option="") const
Print window id.
Definition: TGWindow.cxx:297
virtual void MapRaised()
map raised
Definition: TGWindow.cxx:166
static Int_t fgCounter
Definition: TGWindow.h:39
virtual void SetBackgroundPixmap(Pixmap_t pixmap)
set background pixmap
Definition: TGWindow.cxx:238
virtual void RequestFocus()
request focus
Definition: TGWindow.cxx:222
const TGWindow * fParent
Definition: TGWindow.h:36
virtual void DestroySubwindows()
destroy sub windows
Definition: TGWindow.cxx:190
@ kEditDisable
Definition: TGWindow.h:58
virtual void IconifyWindow()
iconify window
Definition: TGWindow.cxx:214
virtual void MoveResize(Int_t x, Int_t y, UInt_t w, UInt_t h)
Move and resize the window.
Definition: TGWindow.cxx:277
virtual void MapWindow()
map window
Definition: TGWindow.cxx:150
virtual void UnmapWindow()
unmap window
Definition: TGWindow.cxx:174
virtual Bool_t IsMapSubwindows() const
Definition: TGWindow.h:125
TGWindow(Window_t id)
Definition: TGWindow.h:42
virtual void LowerWindow()
lower window
Definition: TGWindow.cxx:206
virtual void DestroyWindow()
destroy window
Definition: TGWindow.cxx:182
static Int_t GetCounter()
Return global window counter (total number of created windows).
Definition: TGWindow.cxx:318
const TGWindow * GetParent() const
Definition: TGWindow.h:84
virtual Bool_t IsMapped()
Returns kTRUE if window is mapped on screen, kFALSE otherwise.
Definition: TGWindow.cxx:285
virtual void Resize(UInt_t w, UInt_t h)
Resize the window.
Definition: TGWindow.cxx:269
virtual void SetBackgroundColor(Pixel_t color)
set background color
Definition: TGWindow.cxx:230
TString fName
Definition: TGWindow.h:38
virtual void RaiseWindow()
raise window
Definition: TGWindow.cxx:198
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:247
Bool_t fNeedRedraw
Definition: TGWindow.h:37
virtual void MapSubwindows()
map sub windows
Definition: TGWindow.cxx:158
UInt_t fEditDisabled
Definition: TGWindow.h:40
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:128
Basic string class.
Definition: TString.h:131
TString & Replace(Ssiz_t pos, Ssiz_t n, const char *s)
Definition: TString.h:677
const char * Data() const
Definition: TString.h:364
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:687
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition: TString.h:610
TString & Remove(Ssiz_t pos)
Definition: TString.h:668
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:619
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:212