TGWindow.cxx

Go to the documentation of this file.
00001 // @(#)root/gui:$Id: TGWindow.cxx 38151 2011-02-18 17:08:48Z ganis $
00002 // Author: Fons Rademakers   28/12/97
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 /**************************************************************************
00012 
00013     This source is based on Xclass95, a Win95-looking GUI toolkit.
00014     Copyright (C) 1996, 1997 David Barth, Ricky Ralston, Hector Peraza.
00015 
00016     Xclass95 is free software; you can redistribute it and/or
00017     modify it under the terms of the GNU Library General Public
00018     License as published by the Free Software Foundation; either
00019     version 2 of the License, or (at your option) any later version.
00020 
00021 **************************************************************************/
00022 
00023 //////////////////////////////////////////////////////////////////////////
00024 //                                                                      //
00025 // TGWindow                                                             //
00026 //                                                                      //
00027 // ROOT GUI Window base class.                                          //
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    // Create a new window. Parent p must exist otherwise the root window
00046    // is taken as parent. No arguments specified results in values from
00047    // parent to be taken (or defaults).
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       // name will be used in SavePrimitive methods
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    // Create a copy of a window.
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    // name used in SavePrimitive methods
00096    fgCounter++;
00097    fName = "frame";
00098    fName += fgCounter;
00099 }
00100 
00101 //______________________________________________________________________________
00102 TGWindow::~TGWindow()
00103 {
00104    // Window destructor. Unregisters the window.
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    // Set window name.
00117 
00118    if (!name && gDebug > 0) {
00119       // set default frame names only when in debug mode
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    // Returns top level main frame.
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    // Reparent window, make p the new parent and position the window at
00140    // position (x,y) in new parent.
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    // Move the window.
00155 
00156    gVirtualX->MoveWindow(fId, x, y);
00157 }
00158 
00159 //______________________________________________________________________________
00160 void TGWindow::Resize(UInt_t w, UInt_t h)
00161 {
00162    // Resize the window.
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    // Move and resize the window.
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    // Returns kTRUE if window is mapped on screen, kFALSE otherwise.
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    // Print window id.
00190    // If option is "tree" - print all parent windows tree
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    // Return global window counter (total number of created windows).
00212 
00213    return fgCounter;
00214 }
00215 
00216 //______________________________________________________________________________
00217 const char *TGWindow::GetName()const
00218 {
00219    // Return unique name, used in SavePrimitive methods.
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 }

Generated on Tue Jul 5 14:22:06 2011 for ROOT_528-00b_version by  doxygen 1.5.1