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/** \class TGWindow
25 \ingroup guiwidgets
26
27ROOT GUI Window base class.
28
29*/
30
31
32#include "TGWindow.h"
33#include <iostream>
34#include "TVirtualX.h"
35#include "TApplication.h"
36#include "TError.h"
37#include "TSystem.h"
38
39
41
42////////////////////////////////////////////////////////////////////////////////
43/// Create a new window. Parent p must exist otherwise the root window
44/// is taken as parent. No arguments specified results in values from
45/// parent to be taken (or defaults).
46
48 UInt_t border, Int_t depth, UInt_t clss, void *visual,
50{
52 fId = 0;
53 fParent = 0;
55
56 if (!p && !gClient && !gApplication) {
57 ::Error("TGWindow::TGWindow",
58 "gClient and gApplication are nullptr!\n"
59 "Please add a TApplication instance in the main() function of your application\n");
60 gSystem->Exit(1);
61 }
62
63 if (!p && gClient) {
64 p = gClient->GetRoot();
65 }
66
67 if (p) {
68 fClient = p->fClient;
69 if (fClient->IsEditable()) type = wtype & ~1;
70
71 fParent = p;
72 if (fParent && fParent->IsMapSubwindows()) {
73 fId = gVirtualX->CreateWindow(fParent->fId, x, y,
74 std::max(w, (UInt_t) 1),
75 std::max(h, (UInt_t) 1), border,
78 }
79
80 // name will be used in SavePrimitive methods
81 fgCounter++;
82 fName = "frame";
84 }
85 fEditDisabled = (fId != gVirtualX->GetDefaultRootWindow()) && fParent ?
86 (fParent->fEditDisabled == kEditDisable) : 0;
87
88 // add protection for the root window on Cocoa (MacOS X)
91}
92
93////////////////////////////////////////////////////////////////////////////////
94/// Create a copy of a window.
95
97{
98 fClient = c;
99 fId = id;
100 fParent = parent;
101 fClient->RegisterWindow(this);
103 fEditDisabled = (fId != gVirtualX->GetDefaultRootWindow()) && fParent ?
104 fParent->fEditDisabled : kFALSE;
105
106 // name used in SavePrimitive methods
107 fgCounter++;
108 fName = "frame";
109 fName += fgCounter;
110}
111
112////////////////////////////////////////////////////////////////////////////////
113/// Window destructor. Unregisters the window.
114
116{
117 if (fClient) {
121 }
122}
123
124////////////////////////////////////////////////////////////////////////////////
125/// Set window name.
126
128{
129#ifdef R__MACOSX
130 // MacOS fails to find the drawable of GetDefaultRootWindow(), only subsequent
131 // windows ids can be found. See discussion here:
132 // https://github.com/root-project/root/pull/6757#discussion_r518776154
133 if (fId == gVirtualX->GetDefaultRootWindow())
134 return;
135#endif
136
137 if (!name && gDebug > 0) {
138 // set default frame names only when in debug mode
140 wname += "::" + fName;
141 gVirtualX->SetWindowName(fId, (char *)wname.Data());
142 } else {
143 gVirtualX->SetWindowName(fId, (char *)name);
144 }
145}
146
147////////////////////////////////////////////////////////////////////////////////
148/// Returns top level main frame.
149
151{
152 return ((fParent == 0) || (fParent == fClient->GetDefaultRoot())) ? this : fParent->GetMainFrame();
153}
154
155////////////////////////////////////////////////////////////////////////////////
156/// map window
157
159{
160 gVirtualX->MapWindow(fId);
161}
162
163////////////////////////////////////////////////////////////////////////////////
164/// map sub windows
165
167{
168 gVirtualX->MapSubwindows(fId);
169}
170
171////////////////////////////////////////////////////////////////////////////////
172/// map raised
173
175{
176 gVirtualX->MapRaised(fId);
177}
178
179////////////////////////////////////////////////////////////////////////////////
180/// unmap window
181
183{
184 gVirtualX->UnmapWindow(fId);
185}
186
187////////////////////////////////////////////////////////////////////////////////
188/// destroy window
189
191{
192 gVirtualX->DestroyWindow(fId);
193}
194
195////////////////////////////////////////////////////////////////////////////////
196/// destroy sub windows
197
199{
200 gVirtualX->DestroySubwindows(fId);
201}
202
203////////////////////////////////////////////////////////////////////////////////
204/// raise window
205
207{
208 gVirtualX->RaiseWindow(fId);
209}
210
211////////////////////////////////////////////////////////////////////////////////
212/// lower window
213
215{
216 gVirtualX->LowerWindow(fId);
217}
218
219////////////////////////////////////////////////////////////////////////////////
220/// iconify window
221
223{
224 gVirtualX->IconifyWindow(fId);
225}
226
227////////////////////////////////////////////////////////////////////////////////
228/// request focus
229
231{
232 gVirtualX->SetInputFocus(fId);
233}
234
235////////////////////////////////////////////////////////////////////////////////
236/// set background color
237
239{
240 gVirtualX->SetWindowBackground(fId, color);
241}
242
243////////////////////////////////////////////////////////////////////////////////
244/// set background pixmap
245
247{
248 gVirtualX->SetWindowBackgroundPixmap(fId, pixmap);
249}
250
251////////////////////////////////////////////////////////////////////////////////
252/// Reparent window, make p the new parent and position the window at
253/// position (x,y) in new parent.
254
256{
257 if (p == fParent) return;
258
259 if (p) {
260 gVirtualX->ReparentWindow(fId, p->GetId(), x, y);
261 gVirtualX->Update(1);
262 }
263 fParent = p;
264}
265
266////////////////////////////////////////////////////////////////////////////////
267/// Move the window.
268
270{
271 gVirtualX->MoveWindow(fId, x, y);
272}
273
274////////////////////////////////////////////////////////////////////////////////
275/// Resize the window.
276
278{
279 gVirtualX->ResizeWindow(fId, std::max(w, (UInt_t)1), std::max(h, (UInt_t)1));
280}
281
282////////////////////////////////////////////////////////////////////////////////
283/// Move and resize the window.
284
286{
287 gVirtualX->MoveResizeWindow(fId, x, y, std::max(w, (UInt_t)1), std::max(h, (UInt_t)1));
288}
289
290////////////////////////////////////////////////////////////////////////////////
291/// Returns kTRUE if window is mapped on screen, kFALSE otherwise.
292
294{
296
297 gVirtualX->GetWindowAttributes(fId, attr);
298 return (attr.fMapState != kIsUnmapped);
299}
300
301////////////////////////////////////////////////////////////////////////////////
302/// Print window id.
303/// If option is "tree" - print all parent windows tree
304
306{
307 TString opt = option;
308
309 if (opt.Contains("tree")) {
310
311 const TGWindow *parent = fParent;
312 std::cout << ClassName() << ":\t" << fId << std::endl;
313
314 while (parent && (parent != fClient->GetDefaultRoot())) {
315 std::cout << "\t" << parent->ClassName() << ":\t" << parent->GetId() << std::endl;
316 parent = parent->GetParent();
317 }
318 } else {
319 std::cout << ClassName() << ":\t" << fId << std::endl;
320 }
321}
322
323////////////////////////////////////////////////////////////////////////////////
324/// Return global window counter (total number of created windows).
325
327{
328 return fgCounter;
329}
330
331////////////////////////////////////////////////////////////////////////////////
332/// Return unique name, used in SavePrimitive methods.
333
334const char *TGWindow::GetName()const
335{
336 TGWindow *w = (TGWindow*)this;
337
338 if (fName.BeginsWith("frame")) {
340 if (cname.BeginsWith("TGed"))
341 cname.Replace(0, 1, 'f');
342 else if (cname.BeginsWith("TG"))
343 cname.Replace(0,2,'f');
344 else
345 cname.Replace(0, 1, 'f');
346 w->fName.Remove(0,5);
347 w->fName = cname + w->fName;
348 }
349
350 if (w->fName.Contains(" "))
351 w->fName.ReplaceAll(" ", "");
352 if (w->fName.Contains(":"))
353 w->fName.ReplaceAll(":", "");
354
355 return fName.Data();
356}
Handle_t Pixmap_t
Pixmap handle.
Definition GuiTypes.h:30
Handle_t Window_t
Window handle.
Definition GuiTypes.h:29
@ kIsUnmapped
Definition GuiTypes.h:46
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:40
#define c(i)
Definition RSha256.hxx:101
#define h(i)
Definition RSha256.hxx:106
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
R__EXTERN TApplication * gApplication
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define gClient
Definition TGClient.h:157
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char cname
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t attr
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
Definition TGX11.cxx:110
Int_t gDebug
Global variable setting the debug level. Set to 0 to disable, increase it in steps of 1 to increase t...
Definition TROOT.cxx:627
R__EXTERN TSystem * gSystem
Definition TSystem.h:572
#define gVirtualX
Definition TVirtualX.h:337
Window client.
Definition TGClient.h:37
const TGWindow * GetDefaultRoot() const
Returns the root (i.e.
Definition TGClient.cxx:233
Bool_t IsEditable() const
Definition TGClient.h:89
void RegisterWindow(TGWindow *w)
Add a TGWindow to the clients list of windows.
Definition TGClient.cxx:520
void UnregisterWindow(TGWindow *w)
Remove a TGWindow from the list of windows.
Definition TGClient.cxx:531
TGClient * fClient
Connection to display server.
Definition TGObject.h:25
Handle_t GetId() const
Definition TGObject.h:41
Handle_t fId
X11/Win32 Window identifier.
Definition TGObject.h:24
ROOT GUI Window base class.
Definition TGWindow.h:23
virtual const TGWindow * GetMainFrame() const
Returns top level main frame.
Definition TGWindow.cxx:150
virtual void Move(Int_t x, Int_t y)
Move the window.
Definition TGWindow.cxx:269
virtual void MapRaised()
map raised
Definition TGWindow.cxx:174
static Int_t fgCounter
counter of created windows in SavePrimitive
Definition TGWindow.h:31
void Print(Option_t *option="") const override
Print window id.
Definition TGWindow.cxx:305
virtual void SetBackgroundPixmap(Pixmap_t pixmap)
set background pixmap
Definition TGWindow.cxx:246
virtual void RequestFocus()
request focus
Definition TGWindow.cxx:230
const TGWindow * fParent
Parent window.
Definition TGWindow.h:28
virtual void DestroySubwindows()
destroy sub windows
Definition TGWindow.cxx:198
@ kEditDisable
disable edit of this window
Definition TGWindow.h:57
virtual void IconifyWindow()
iconify window
Definition TGWindow.cxx:222
virtual void MoveResize(Int_t x, Int_t y, UInt_t w, UInt_t h)
Move and resize the window.
Definition TGWindow.cxx:285
virtual void MapWindow()
map window
Definition TGWindow.cxx:158
virtual void UnmapWindow()
unmap window
Definition TGWindow.cxx:182
TGWindow(Window_t id)
Definition TGWindow.h:34
virtual void LowerWindow()
lower window
Definition TGWindow.cxx:214
virtual void DestroyWindow()
destroy window
Definition TGWindow.cxx:190
virtual void SetWindowName(const char *name=nullptr)
Set window name.
Definition TGWindow.cxx:127
static Int_t GetCounter()
Return global window counter (total number of created windows).
Definition TGWindow.cxx:326
const TGWindow * GetParent() const
Definition TGWindow.h:83
virtual Bool_t IsMapped()
Returns kTRUE if window is mapped on screen, kFALSE otherwise.
Definition TGWindow.cxx:293
virtual void Resize(UInt_t w, UInt_t h)
Resize the window.
Definition TGWindow.cxx:277
virtual void SetBackgroundColor(Pixel_t color)
set background color
Definition TGWindow.cxx:238
TString fName
name of the window used in SavePrimitive()
Definition TGWindow.h:30
virtual void RaiseWindow()
raise window
Definition TGWindow.cxx:206
~TGWindow() override
Window destructor. Unregisters the window.
Definition TGWindow.cxx:115
const char * GetName() const override
Return unique name, used in SavePrimitive methods.
Definition TGWindow.cxx:334
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:255
Bool_t fNeedRedraw
kTRUE if window needs to be redrawn
Definition TGWindow.h:29
virtual void MapSubwindows()
map sub windows
Definition TGWindow.cxx:166
UInt_t fEditDisabled
flags used for "guibuilding"
Definition TGWindow.h:32
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition TObject.cxx:226
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1071
Basic string class.
Definition TString.h:138
const char * Data() const
Definition TString.h:384
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition TString.h:631
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:640
virtual void Exit(int code, Bool_t mode=kTRUE)
Exit the application.
Definition TSystem.cxx:725
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
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