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