Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 <iostream>
33#include "TVirtualX.h"
34#include "TApplication.h"
35#include "TError.h"
36#include "TSystem.h"
37
40
42
43////////////////////////////////////////////////////////////////////////////////
44/// Create a new window. Parent p must exist otherwise the root window
45/// is taken as parent. No arguments specified results in values from
46/// parent to be taken (or defaults).
47
49 UInt_t border, Int_t depth, UInt_t clss, void *visual,
50 SetWindowAttributes_t *attr, UInt_t wtype)
51{
52 UInt_t type = wtype;
53 fId = 0;
54 fParent = 0;
56
57 if (!p && !gClient && !gApplication) {
58 ::Error("TGWindow::TGWindow",
59 "gClient and gApplication are nullptr!\n"
60 "Please add a TApplication instance in the main() function of your application\n");
61 gSystem->Exit(1);
62 }
63
64 if (!p && gClient) {
65 p = gClient->GetRoot();
66 }
67
68 if (p) {
69 fClient = p->fClient;
70 if (fClient->IsEditable()) type = wtype & ~1;
71
72 fParent = p;
74 fId = gVirtualX->CreateWindow(fParent->fId, x, y,
75 TMath::Max(w, (UInt_t) 1),
76 TMath::Max(h, (UInt_t) 1), border,
77 depth, clss, visual, attr, type);
79 }
80
81 // name will be used in SavePrimitive methods
82 fgCounter++;
83 fName = "frame";
85 }
86 fEditDisabled = (fId != gVirtualX->GetDefaultRootWindow()) && fParent ?
88
89 // add protection for the root window on Cocoa (MacOS X)
92}
93
94////////////////////////////////////////////////////////////////////////////////
95/// Create a copy of a window.
96
98{
99 fClient = c;
100 fId = id;
101 fParent = parent;
102 fClient->RegisterWindow(this);
104 fEditDisabled = (fId != gVirtualX->GetDefaultRootWindow()) && fParent ?
106
107 // name used in SavePrimitive methods
108 fgCounter++;
109 fName = "frame";
110 fName += fgCounter;
111}
112
113////////////////////////////////////////////////////////////////////////////////
114/// Window destructor. Unregisters the window.
115
117{
118 if (fClient) {
122 }
123}
124
125////////////////////////////////////////////////////////////////////////////////
126/// Set window name.
127
129{
130#ifdef R__MACOSX
131 // MacOS fails to find the drawable of GetDefaultRootWindow(), only subsequent
132 // windows ids can be found. See discussion here:
133 // https://github.com/root-project/root/pull/6757#discussion_r518776154
134 if (fId == gVirtualX->GetDefaultRootWindow())
135 return;
136#endif
137
138 if (!name && gDebug > 0) {
139 // set default frame names only when in debug mode
140 TString wname = ClassName();
141 wname += "::" + fName;
142 gVirtualX->SetWindowName(fId, (char *)wname.Data());
143 } else {
144 gVirtualX->SetWindowName(fId, (char *)name);
145 }
146}
147
148////////////////////////////////////////////////////////////////////////////////
149/// Returns top level main frame.
150
152{
153 return ((fParent == 0) || (fParent == fClient->GetDefaultRoot())) ? this : fParent->GetMainFrame();
154}
155
156////////////////////////////////////////////////////////////////////////////////
157/// map window
158
160{
162}
163
164////////////////////////////////////////////////////////////////////////////////
165/// map sub windows
166
168{
169 gVirtualX->MapSubwindows(fId);
170}
171
172////////////////////////////////////////////////////////////////////////////////
173/// map raised
174
176{
177 gVirtualX->MapRaised(fId);
178}
179
180////////////////////////////////////////////////////////////////////////////////
181/// unmap window
182
184{
185 gVirtualX->UnmapWindow(fId);
186}
187
188////////////////////////////////////////////////////////////////////////////////
189/// destroy window
190
192{
193 gVirtualX->DestroyWindow(fId);
194}
195
196////////////////////////////////////////////////////////////////////////////////
197/// destroy sub windows
198
200{
201 gVirtualX->DestroySubwindows(fId);
202}
203
204////////////////////////////////////////////////////////////////////////////////
205/// raise window
206
208{
209 gVirtualX->RaiseWindow(fId);
210}
211
212////////////////////////////////////////////////////////////////////////////////
213/// lower window
214
216{
217 gVirtualX->LowerWindow(fId);
218}
219
220////////////////////////////////////////////////////////////////////////////////
221/// iconify window
222
224{
225 gVirtualX->IconifyWindow(fId);
226}
227
228////////////////////////////////////////////////////////////////////////////////
229/// request focus
230
232{
233 gVirtualX->SetInputFocus(fId);
234}
235
236////////////////////////////////////////////////////////////////////////////////
237/// set background color
238
240{
241 gVirtualX->SetWindowBackground(fId, color);
242}
243
244////////////////////////////////////////////////////////////////////////////////
245/// set background pixmap
246
248{
249 gVirtualX->SetWindowBackgroundPixmap(fId, pixmap);
250}
251
252////////////////////////////////////////////////////////////////////////////////
253/// Reparent window, make p the new parent and position the window at
254/// position (x,y) in new parent.
255
257{
258 if (p == fParent) return;
259
260 if (p) {
261 gVirtualX->ReparentWindow(fId, p->GetId(), x, y);
262 gVirtualX->Update(1);
263 }
264 fParent = p;
265}
266
267////////////////////////////////////////////////////////////////////////////////
268/// Move the window.
269
271{
272 gVirtualX->MoveWindow(fId, x, y);
273}
274
275////////////////////////////////////////////////////////////////////////////////
276/// Resize the window.
277
279{
280 gVirtualX->ResizeWindow(fId, TMath::Max(w, (UInt_t)1), TMath::Max(h, (UInt_t)1));
281}
282
283////////////////////////////////////////////////////////////////////////////////
284/// Move and resize the window.
285
287{
288 gVirtualX->MoveResizeWindow(fId, x, y, TMath::Max(w, (UInt_t)1), TMath::Max(h, (UInt_t)1));
289}
290
291////////////////////////////////////////////////////////////////////////////////
292/// Returns kTRUE if window is mapped on screen, kFALSE otherwise.
293
295{
297
298 gVirtualX->GetWindowAttributes(fId, attr);
299 return (attr.fMapState != kIsUnmapped);
300}
301
302////////////////////////////////////////////////////////////////////////////////
303/// Print window id.
304/// If option is "tree" - print all parent windows tree
305
306void TGWindow::Print(Option_t *option) const
307{
308 TString opt = option;
309
310 if (opt.Contains("tree")) {
311
312 const TGWindow *parent = fParent;
313 std::cout << ClassName() << ":\t" << fId << std::endl;
314
315 while (parent && (parent != fClient->GetDefaultRoot())) {
316 std::cout << "\t" << parent->ClassName() << ":\t" << parent->GetId() << std::endl;
317 parent = parent->GetParent();
318 }
319 } else {
320 std::cout << ClassName() << ":\t" << fId << std::endl;
321 }
322}
323
324////////////////////////////////////////////////////////////////////////////////
325/// Return global window counter (total number of created windows).
326
328{
329 return fgCounter;
330}
331
332////////////////////////////////////////////////////////////////////////////////
333/// Return unique name, used in SavePrimitive methods.
334
335const char *TGWindow::GetName()const
336{
337 TGWindow *w = (TGWindow*)this;
338
339 if (fName.BeginsWith("frame")) {
340 TString cname = ClassName();
341 if (cname.BeginsWith("TGed"))
342 cname.Replace(0, 1, 'f');
343 else if (cname.BeginsWith("TG"))
344 cname.Replace(0,2,'f');
345 else
346 cname.Replace(0, 1, 'f');
347 w->fName.Remove(0,5);
348 w->fName = cname + w->fName;
349 }
350
351 if (w->fName.Contains(" "))
352 w->fName.ReplaceAll(" ", "");
353 if (w->fName.Contains(":"))
354 w->fName.ReplaceAll(":", "");
355
356 return fName.Data();
357}
Handle_t Pixmap_t
Pixmap handle.
Definition GuiTypes.h:30
@ kIsUnmapped
Definition GuiTypes.h:46
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:40
Handle_t Window_t
Window handle.
Definition GuiTypes.h:29
#define c(i)
Definition RSha256.hxx:101
#define h(i)
Definition RSha256.hxx:106
int Int_t
Definition RtypesCore.h:45
const Bool_t kFALSE
Definition RtypesCore.h:92
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:364
R__EXTERN TApplication * gApplication
#define gClient
Definition TGClient.h:166
XFontStruct * id
Definition TGX11.cxx:109
char name[80]
Definition TGX11.cxx:110
int type
Definition TGX11.cxx:121
Int_t gDebug
Definition TROOT.cxx:590
R__EXTERN TSystem * gSystem
Definition TSystem.h:559
#define gVirtualX
Definition TVirtualX.h:338
const TGWindow * GetDefaultRoot() const
Returns the root (i.e.
Definition TGClient.cxx:233
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:128
virtual const TGWindow * GetMainFrame() const
Returns top level main frame.
Definition TGWindow.cxx:151
virtual void Move(Int_t x, Int_t y)
Move the window.
Definition TGWindow.cxx:270
virtual const char * GetName() const
Return unique name, used in SavePrimitive methods.
Definition TGWindow.cxx:335
virtual ~TGWindow()
Window destructor. Unregisters the window.
Definition TGWindow.cxx:116
virtual void Print(Option_t *option="") const
Print window id.
Definition TGWindow.cxx:306
virtual void MapRaised()
map raised
Definition TGWindow.cxx:175
static Int_t fgCounter
Definition TGWindow.h:39
virtual void SetBackgroundPixmap(Pixmap_t pixmap)
set background pixmap
Definition TGWindow.cxx:247
virtual void RequestFocus()
request focus
Definition TGWindow.cxx:231
const TGWindow * fParent
Definition TGWindow.h:36
virtual void DestroySubwindows()
destroy sub windows
Definition TGWindow.cxx:199
@ kEditDisable
Definition TGWindow.h:58
virtual void IconifyWindow()
iconify window
Definition TGWindow.cxx:223
virtual void MoveResize(Int_t x, Int_t y, UInt_t w, UInt_t h)
Move and resize the window.
Definition TGWindow.cxx:286
virtual void MapWindow()
map window
Definition TGWindow.cxx:159
virtual void UnmapWindow()
unmap window
Definition TGWindow.cxx:183
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:215
virtual void DestroyWindow()
destroy window
Definition TGWindow.cxx:191
static Int_t GetCounter()
Return global window counter (total number of created windows).
Definition TGWindow.cxx:327
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:294
virtual void Resize(UInt_t w, UInt_t h)
Resize the window.
Definition TGWindow.cxx:278
virtual void SetBackgroundColor(Pixel_t color)
set background color
Definition TGWindow.cxx:239
TString fName
Definition TGWindow.h:38
virtual void RaiseWindow()
raise window
Definition TGWindow.cxx:207
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:256
Bool_t fNeedRedraw
Definition TGWindow.h:37
virtual void MapSubwindows()
map sub windows
Definition TGWindow.cxx:167
UInt_t fEditDisabled
Definition TGWindow.h:40
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition TObject.cxx:130
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:893
Basic string class.
Definition TString.h:136
TString & Replace(Ssiz_t pos, Ssiz_t n, const char *s)
Definition TString.h:682
const char * Data() const
Definition TString.h:369
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition TString.h:692
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition TString.h:615
TString & Remove(Ssiz_t pos)
Definition TString.h:673
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:624
virtual void Exit(int code, Bool_t mode=kTRUE)
Exit the application.
Definition TSystem.cxx:717
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
Attributes that can be used when creating or changing a window.
Definition GuiTypes.h:93
Window attributes that can be inquired.
Definition GuiTypes.h:114
Int_t fMapState
kIsUnmapped, kIsUnviewable, kIsViewable
Definition GuiTypes.h:130