00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "TGWindow.h"
00032 #include "Riostream.h"
00033 #include "TApplication.h"
00034
00035 ClassImp(TGWindow)
00036 ClassImp(TGUnknownWindowHandler)
00037
00038 Int_t TGWindow::fgCounter = 0;
00039
00040
00041 TGWindow::TGWindow(const TGWindow *p, Int_t x, Int_t y, UInt_t w, UInt_t h,
00042 UInt_t border, Int_t depth, UInt_t clss, void *visual,
00043 SetWindowAttributes_t *attr, UInt_t wtype)
00044 {
00045
00046
00047
00048
00049 UInt_t type = wtype;
00050 fId = 0;
00051 fParent = 0;
00052
00053 if (!p && gClient) {
00054 p = gClient->GetRoot();
00055 }
00056
00057 if (p) {
00058 fClient = p->fClient;
00059 if (fClient->IsEditable()) type = wtype & ~1;
00060
00061 fParent = p;
00062 if (fParent && fParent->IsMapSubwindows()) {
00063 fId = gVirtualX->CreateWindow(fParent->fId, x, y,
00064 TMath::Max(w, (UInt_t) 1),
00065 TMath::Max(h, (UInt_t) 1), border,
00066 depth, clss, visual, attr, type);
00067 fClient->RegisterWindow(this);
00068 }
00069 fNeedRedraw = kFALSE;
00070
00071
00072 fgCounter++;
00073 fName = "frame";
00074 fName += fgCounter;
00075 }
00076 fEditDisabled = (fId != gVirtualX->GetDefaultRootWindow()) && fParent ?
00077 (fParent->fEditDisabled == kEditDisable) : 0;
00078
00079 SetWindowName();
00080 }
00081
00082
00083 TGWindow::TGWindow(TGClient *c, Window_t id, const TGWindow *parent)
00084 {
00085
00086
00087 fClient = c;
00088 fId = id;
00089 fParent = parent;
00090 fClient->RegisterWindow(this);
00091 fNeedRedraw = kFALSE;
00092 fEditDisabled = (fId != gVirtualX->GetDefaultRootWindow()) && fParent ?
00093 fParent->fEditDisabled : kFALSE;
00094
00095
00096 fgCounter++;
00097 fName = "frame";
00098 fName += fgCounter;
00099 }
00100
00101
00102 TGWindow::~TGWindow()
00103 {
00104
00105
00106 if (fClient) {
00107 if (fParent == fClient->GetDefaultRoot())
00108 DestroyWindow();
00109 fClient->UnregisterWindow(this);
00110 }
00111 }
00112
00113
00114 void TGWindow::SetWindowName(const char *name)
00115 {
00116
00117
00118 if (!name && gDebug > 0) {
00119
00120 TString wname = ClassName();
00121 wname += "::" + fName;
00122 gVirtualX->SetWindowName(fId, (char *)wname.Data());
00123 } else {
00124 gVirtualX->SetWindowName(fId, (char *)name);
00125 }
00126 }
00127
00128
00129 const TGWindow *TGWindow::GetMainFrame() const
00130 {
00131
00132
00133 return ((fParent == 0) || (fParent == fClient->GetDefaultRoot())) ? this : fParent->GetMainFrame();
00134 }
00135
00136
00137 void TGWindow::ReparentWindow(const TGWindow *p, Int_t x, Int_t y)
00138 {
00139
00140
00141
00142 if (p == fParent) return;
00143
00144 if (p) {
00145 gVirtualX->ReparentWindow(fId, p->GetId(), x, y);
00146 gVirtualX->Update(1);
00147 }
00148 fParent = p;
00149 }
00150
00151
00152 void TGWindow::Move(Int_t x, Int_t y)
00153 {
00154
00155
00156 gVirtualX->MoveWindow(fId, x, y);
00157 }
00158
00159
00160 void TGWindow::Resize(UInt_t w, UInt_t h)
00161 {
00162
00163
00164 gVirtualX->ResizeWindow(fId, TMath::Max(w, (UInt_t)1), TMath::Max(h, (UInt_t)1));
00165 }
00166
00167
00168 void TGWindow::MoveResize(Int_t x, Int_t y, UInt_t w, UInt_t h)
00169 {
00170
00171
00172 gVirtualX->MoveResizeWindow(fId, x, y, TMath::Max(w, (UInt_t)1), TMath::Max(h, (UInt_t)1));
00173 }
00174
00175
00176 Bool_t TGWindow::IsMapped()
00177 {
00178
00179
00180 WindowAttributes_t attr;
00181
00182 gVirtualX->GetWindowAttributes(fId, attr);
00183 return (attr.fMapState != kIsUnmapped);
00184 }
00185
00186
00187 void TGWindow::Print(Option_t *option) const
00188 {
00189
00190
00191
00192 TString opt = option;
00193
00194 if (opt.Contains("tree")) {
00195
00196 const TGWindow *parent = fParent;
00197 cout << ClassName() << ":\t" << fId << endl;
00198
00199 while (parent && (parent != fClient->GetDefaultRoot())) {
00200 cout << "\t" << parent->ClassName() << ":\t" << parent->GetId() << endl;
00201 parent = parent->GetParent();
00202 }
00203 } else {
00204 cout << ClassName() << ":\t" << fId << endl;
00205 }
00206 }
00207
00208
00209 Int_t TGWindow::GetCounter()
00210 {
00211
00212
00213 return fgCounter;
00214 }
00215
00216
00217 const char *TGWindow::GetName()const
00218 {
00219
00220
00221 TGWindow *w = (TGWindow*)this;
00222
00223 if (fName.BeginsWith("frame")) {
00224 TString cname = ClassName();
00225 if (cname.BeginsWith("TGed"))
00226 cname.Replace(0, 1, 'f');
00227 else if (cname.BeginsWith("TG"))
00228 cname.Replace(0,2,'f');
00229 else
00230 cname.Replace(0, 1, 'f');
00231 w->fName.Remove(0,5);
00232 w->fName = cname + w->fName;
00233 }
00234
00235 if (w->fName.Contains(" "))
00236 w->fName.ReplaceAll(" ", "");
00237 if (w->fName.Contains(":"))
00238 w->fName.ReplaceAll(":", "");
00239
00240 return fName.Data();
00241 }