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