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