Logo ROOT   6.12/07
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 "Riostream.h"
33 #include "TApplication.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 /// Reparent window, make p the new parent and position the window at
140 /// position (x,y) in new parent.
141 
143 {
144  if (p == fParent) return;
145 
146  if (p) {
147  gVirtualX->ReparentWindow(fId, p->GetId(), x, y);
148  gVirtualX->Update(1);
149  }
150  fParent = p;
151 }
152 
153 ////////////////////////////////////////////////////////////////////////////////
154 /// Move the window.
155 
157 {
158  gVirtualX->MoveWindow(fId, x, y);
159 }
160 
161 ////////////////////////////////////////////////////////////////////////////////
162 /// Resize the window.
163 
165 {
166  gVirtualX->ResizeWindow(fId, TMath::Max(w, (UInt_t)1), TMath::Max(h, (UInt_t)1));
167 }
168 
169 ////////////////////////////////////////////////////////////////////////////////
170 /// Move and resize the window.
171 
173 {
174  gVirtualX->MoveResizeWindow(fId, x, y, TMath::Max(w, (UInt_t)1), TMath::Max(h, (UInt_t)1));
175 }
176 
177 ////////////////////////////////////////////////////////////////////////////////
178 /// Returns kTRUE if window is mapped on screen, kFALSE otherwise.
179 
181 {
182  WindowAttributes_t attr;
183 
184  gVirtualX->GetWindowAttributes(fId, attr);
185  return (attr.fMapState != kIsUnmapped);
186 }
187 
188 ////////////////////////////////////////////////////////////////////////////////
189 /// Print window id.
190 /// If option is "tree" - print all parent windows tree
191 
192 void TGWindow::Print(Option_t *option) const
193 {
194  TString opt = option;
195 
196  if (opt.Contains("tree")) {
197 
198  const TGWindow *parent = fParent;
199  std::cout << ClassName() << ":\t" << fId << std::endl;
200 
201  while (parent && (parent != fClient->GetDefaultRoot())) {
202  std::cout << "\t" << parent->ClassName() << ":\t" << parent->GetId() << std::endl;
203  parent = parent->GetParent();
204  }
205  } else {
206  std::cout << ClassName() << ":\t" << fId << std::endl;
207  }
208 }
209 
210 ////////////////////////////////////////////////////////////////////////////////
211 /// Return global window counter (total number of created windows).
212 
214 {
215  return fgCounter;
216 }
217 
218 ////////////////////////////////////////////////////////////////////////////////
219 /// Return unique name, used in SavePrimitive methods.
220 
221 const char *TGWindow::GetName()const
222 {
223  TGWindow *w = (TGWindow*)this;
224 
225  if (fName.BeginsWith("frame")) {
226  TString cname = ClassName();
227  if (cname.BeginsWith("TGed"))
228  cname.Replace(0, 1, 'f');
229  else if (cname.BeginsWith("TG"))
230  cname.Replace(0,2,'f');
231  else
232  cname.Replace(0, 1, 'f');
233  w->fName.Remove(0,5);
234  w->fName = cname + w->fName;
235  }
236 
237  if (w->fName.Contains(" "))
238  w->fName.ReplaceAll(" ", "");
239  if (w->fName.Contains(":"))
240  w->fName.ReplaceAll(":", "");
241 
242  return fName.Data();
243 }
const TGWindow * fParent
Definition: TGWindow.h:37
virtual ~TGWindow()
Window destructor. Unregisters the window.
Definition: TGWindow.cxx:106
const char Option_t
Definition: RtypesCore.h:62
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:638
TH1 * h
Definition: legend2.C:5
static Int_t fgCounter
Definition: TGWindow.h:40
Bool_t fNeedRedraw
Definition: TGWindow.h:38
Basic string class.
Definition: TString.h:125
#define gClient
Definition: TGClient.h:166
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual Bool_t IsMapSubwindows() const
Definition: TGWindow.h:128
Handle_t GetId() const
Definition: TGObject.h:47
void UnregisterWindow(TGWindow *w)
Remove a TGWindow from the list of windows.
Definition: TGClient.cxx:520
TString & Replace(Ssiz_t pos, Ssiz_t n, const char *s)
Definition: TString.h:628
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:128
TGWindow(Window_t id)
Definition: TGWindow.h:43
Double_t x[n]
Definition: legend1.C:17
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:142
void RegisterWindow(TGWindow *w)
Add a TGWindow to the clients list of windows.
Definition: TGClient.cxx:509
virtual const TGWindow * GetMainFrame() const
Returns top level main frame.
Definition: TGWindow.cxx:133
XFontStruct * id
Definition: TGX11.cxx:108
virtual void Print(Option_t *option="") const
Print window id.
Definition: TGWindow.cxx:192
virtual void Resize(UInt_t w, UInt_t h)
Resize the window.
Definition: TGWindow.cxx:164
Bool_t IsEditable() const
Definition: TGClient.h:98
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition: TString.h:561
virtual const char * GetName() const
Return unique name, used in SavePrimitive methods.
Definition: TGWindow.cxx:221
unsigned int UInt_t
Definition: RtypesCore.h:42
TString fName
Definition: TGWindow.h:39
#define gVirtualX
Definition: TVirtualX.h:350
const Bool_t kFALSE
Definition: RtypesCore.h:88
virtual void Move(Int_t x, Int_t y)
Move the window.
Definition: TGWindow.cxx:156
TString & Remove(Ssiz_t pos)
Definition: TString.h:619
#define ClassImp(name)
Definition: Rtypes.h:359
int type
Definition: TGX11.cxx:120
Double_t y[n]
Definition: legend1.C:17
virtual Bool_t IsMapped()
Returns kTRUE if window is mapped on screen, kFALSE otherwise.
Definition: TGWindow.cxx:180
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:570
const TGWindow * GetParent() const
Definition: TGWindow.h:85
Handle_t fId
Definition: TGObject.h:36
virtual void MoveResize(Int_t x, Int_t y, UInt_t w, UInt_t h)
Move and resize the window.
Definition: TGWindow.cxx:172
Handle_t Window_t
Definition: GuiTypes.h:28
TGClient * fClient
Definition: TGObject.h:37
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:200
static Int_t GetCounter()
Return global window counter (total number of created windows).
Definition: TGWindow.cxx:213
const TGWindow * GetDefaultRoot() const
Returns the root (i.e.
Definition: TGClient.cxx:232
UInt_t fEditDisabled
Definition: TGWindow.h:41
R__EXTERN Int_t gDebug
Definition: Rtypes.h:86
char name[80]
Definition: TGX11.cxx:109
virtual void DestroyWindow()
Definition: TGWindow.h:92
virtual void SetWindowName(const char *name=0)
Set window name.
Definition: TGWindow.cxx:118
const char * Data() const
Definition: TString.h:345