ROOT logo
// @(#)root/gui:$Id: TGWindow.cxx 27918 2009-03-24 12:47:05Z bellenot $
// Author: Fons Rademakers   28/12/97

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/
/**************************************************************************

    This source is based on Xclass95, a Win95-looking GUI toolkit.
    Copyright (C) 1996, 1997 David Barth, Ricky Ralston, Hector Peraza.

    Xclass95 is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

**************************************************************************/

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TGWindow                                                             //
//                                                                      //
// ROOT GUI Window base class.                                          //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#include "TGWindow.h"
#include "Riostream.h"
#include "TApplication.h"

ClassImp(TGWindow)
ClassImp(TGUnknownWindowHandler)

Int_t TGWindow::fgCounter = 0;

//______________________________________________________________________________
TGWindow::TGWindow(const TGWindow *p, Int_t x, Int_t y, UInt_t w, UInt_t h,
                   UInt_t border, Int_t depth, UInt_t clss, void *visual,
                   SetWindowAttributes_t *attr, UInt_t wtype)
{
   // Create a new window. Parent p must exist otherwise the root window
   // is taken as parent. No arguments specified results in values from
   // parent to be taken (or defaults).

   UInt_t type = wtype;
   fId = 0;

   if (!p && gClient) {
      p = gClient->GetRoot();
   }

   if (p) {
      fClient = p->fClient;
      if (fClient->IsEditable()) type = wtype & ~1;

      fParent = p;
      if (fParent && fParent->IsMapSubwindows()) {
         fId = gVirtualX->CreateWindow(fParent->fId, x, y,
                                     TMath::Max(w, (UInt_t) 1),
                                     TMath::Max(h, (UInt_t) 1), border,
                                     depth, clss, visual, attr, type);
         fClient->RegisterWindow(this);
      }
      fNeedRedraw = kFALSE;

      // name will be used in SavePrimitive methods
      fgCounter++;
      fName = "frame";
      fName += fgCounter;
   }
   fEditDisabled = (fId != gVirtualX->GetDefaultRootWindow()) && fParent ?
                    (fParent->fEditDisabled == kEditDisable) : 0;

   SetWindowName();
}

//______________________________________________________________________________
TGWindow::TGWindow(TGClient *c, Window_t id, const TGWindow *parent)
{
   // Create a copy of a window.

   fClient = c;
   fId     = id;
   fParent = parent;
   fClient->RegisterWindow(this);
   fNeedRedraw = kFALSE;
   fEditDisabled = (fId != gVirtualX->GetDefaultRootWindow()) && fParent ?
                    fParent->fEditDisabled : kFALSE;

   // name used in SavePrimitive methods
   fgCounter++;
   fName = "frame";
   fName += fgCounter;
}

//______________________________________________________________________________
TGWindow::~TGWindow()
{
   // Window destructor. Unregisters the window.

   if (fClient) {
      if (fParent == fClient->GetDefaultRoot())
         DestroyWindow();
      fClient->UnregisterWindow(this);
   }
}

//______________________________________________________________________________
void TGWindow::SetWindowName(const char *name)
{
   // Set window name.

   if (!name && gDebug > 0) {
      // set default frame names only when in debug mode
      TString wname = ClassName();
      wname += "::" + fName;
      gVirtualX->SetWindowName(fId, (char *)wname.Data());
   } else {
      gVirtualX->SetWindowName(fId, (char *)name);
   }
}

//______________________________________________________________________________
const TGWindow *TGWindow::GetMainFrame() const
{
   // Returns top level main frame.

   return (fParent == fClient->GetDefaultRoot()) ? this : fParent->GetMainFrame();
}

//______________________________________________________________________________
void TGWindow::ReparentWindow(const TGWindow *p, Int_t x, Int_t y)
{
   // Reparent window, make p the new parent and position the window at
   // position (x,y) in new parent.

   if (p == fParent) return;

   if (p) {
      gVirtualX->ReparentWindow(fId, p->GetId(), x, y);
      gVirtualX->Update(1);
   }
   fParent = p;
}

//______________________________________________________________________________
void TGWindow::Move(Int_t x, Int_t y)
{
   // Move the window.

   gVirtualX->MoveWindow(fId, x, y);
}

//______________________________________________________________________________
void TGWindow::Resize(UInt_t w, UInt_t h)
{
   // Resize the window.

   gVirtualX->ResizeWindow(fId, TMath::Max(w, (UInt_t)1), TMath::Max(h, (UInt_t)1));
}

//______________________________________________________________________________
void TGWindow::MoveResize(Int_t x, Int_t y, UInt_t w, UInt_t h)
{
   // Move and resize the window.

   gVirtualX->MoveResizeWindow(fId, x, y, TMath::Max(w, (UInt_t)1), TMath::Max(h, (UInt_t)1));
}

//______________________________________________________________________________
Bool_t TGWindow::IsMapped()
{
   // Returns kTRUE if window is mapped on screen, kFALSE otherwise.

   WindowAttributes_t attr;

   gVirtualX->GetWindowAttributes(fId, attr);
   return (attr.fMapState != kIsUnmapped);
}

//______________________________________________________________________________
void TGWindow::Print(Option_t *option) const
{
   // Print window id.
   // If option is "tree" - print all parent windows tree

   TString opt = option;

   if (opt.Contains("tree")) {

      const TGWindow *parent = fParent;
      cout << ClassName() << ":\t" << fId << endl;

      while (parent && (parent != fClient->GetDefaultRoot())) {
         cout << "\t" << parent->ClassName() << ":\t" << parent->GetId() << endl;
         parent = parent->GetParent();
      }
   } else {
      cout << ClassName() << ":\t" << fId << endl;
   }
}

//______________________________________________________________________________
Int_t TGWindow::GetCounter()
{
   // Return global window counter (total number of created windows).

   return fgCounter;
}

//______________________________________________________________________________
const char *TGWindow::GetName()const
{
   // Return unique name, used in SavePrimitive methods.

   TGWindow *w = (TGWindow*)this;

   if (fName.BeginsWith("frame")) {
      TString cname = ClassName();
      if (cname.BeginsWith("TGed"))
         cname.Replace(0, 1, 'f');
      else if (cname.BeginsWith("TG"))
         cname.Replace(0,2,'f');
      else
         cname.Replace(0, 1, 'f');
      w->fName.Remove(0,5);
      w->fName = cname + w->fName;
   }

   if (w->fName.Contains(" "))
      w->fName.ReplaceAll(" ", "");
   if (w->fName.Contains(":"))
      w->fName.ReplaceAll(":", "");
      
   return fName.Data();
}
 TGWindow.cxx:1
 TGWindow.cxx:2
 TGWindow.cxx:3
 TGWindow.cxx:4
 TGWindow.cxx:5
 TGWindow.cxx:6
 TGWindow.cxx:7
 TGWindow.cxx:8
 TGWindow.cxx:9
 TGWindow.cxx:10
 TGWindow.cxx:11
 TGWindow.cxx:12
 TGWindow.cxx:13
 TGWindow.cxx:14
 TGWindow.cxx:15
 TGWindow.cxx:16
 TGWindow.cxx:17
 TGWindow.cxx:18
 TGWindow.cxx:19
 TGWindow.cxx:20
 TGWindow.cxx:21
 TGWindow.cxx:22
 TGWindow.cxx:23
 TGWindow.cxx:24
 TGWindow.cxx:25
 TGWindow.cxx:26
 TGWindow.cxx:27
 TGWindow.cxx:28
 TGWindow.cxx:29
 TGWindow.cxx:30
 TGWindow.cxx:31
 TGWindow.cxx:32
 TGWindow.cxx:33
 TGWindow.cxx:34
 TGWindow.cxx:35
 TGWindow.cxx:36
 TGWindow.cxx:37
 TGWindow.cxx:38
 TGWindow.cxx:39
 TGWindow.cxx:40
 TGWindow.cxx:41
 TGWindow.cxx:42
 TGWindow.cxx:43
 TGWindow.cxx:44
 TGWindow.cxx:45
 TGWindow.cxx:46
 TGWindow.cxx:47
 TGWindow.cxx:48
 TGWindow.cxx:49
 TGWindow.cxx:50
 TGWindow.cxx:51
 TGWindow.cxx:52
 TGWindow.cxx:53
 TGWindow.cxx:54
 TGWindow.cxx:55
 TGWindow.cxx:56
 TGWindow.cxx:57
 TGWindow.cxx:58
 TGWindow.cxx:59
 TGWindow.cxx:60
 TGWindow.cxx:61
 TGWindow.cxx:62
 TGWindow.cxx:63
 TGWindow.cxx:64
 TGWindow.cxx:65
 TGWindow.cxx:66
 TGWindow.cxx:67
 TGWindow.cxx:68
 TGWindow.cxx:69
 TGWindow.cxx:70
 TGWindow.cxx:71
 TGWindow.cxx:72
 TGWindow.cxx:73
 TGWindow.cxx:74
 TGWindow.cxx:75
 TGWindow.cxx:76
 TGWindow.cxx:77
 TGWindow.cxx:78
 TGWindow.cxx:79
 TGWindow.cxx:80
 TGWindow.cxx:81
 TGWindow.cxx:82
 TGWindow.cxx:83
 TGWindow.cxx:84
 TGWindow.cxx:85
 TGWindow.cxx:86
 TGWindow.cxx:87
 TGWindow.cxx:88
 TGWindow.cxx:89
 TGWindow.cxx:90
 TGWindow.cxx:91
 TGWindow.cxx:92
 TGWindow.cxx:93
 TGWindow.cxx:94
 TGWindow.cxx:95
 TGWindow.cxx:96
 TGWindow.cxx:97
 TGWindow.cxx:98
 TGWindow.cxx:99
 TGWindow.cxx:100
 TGWindow.cxx:101
 TGWindow.cxx:102
 TGWindow.cxx:103
 TGWindow.cxx:104
 TGWindow.cxx:105
 TGWindow.cxx:106
 TGWindow.cxx:107
 TGWindow.cxx:108
 TGWindow.cxx:109
 TGWindow.cxx:110
 TGWindow.cxx:111
 TGWindow.cxx:112
 TGWindow.cxx:113
 TGWindow.cxx:114
 TGWindow.cxx:115
 TGWindow.cxx:116
 TGWindow.cxx:117
 TGWindow.cxx:118
 TGWindow.cxx:119
 TGWindow.cxx:120
 TGWindow.cxx:121
 TGWindow.cxx:122
 TGWindow.cxx:123
 TGWindow.cxx:124
 TGWindow.cxx:125
 TGWindow.cxx:126
 TGWindow.cxx:127
 TGWindow.cxx:128
 TGWindow.cxx:129
 TGWindow.cxx:130
 TGWindow.cxx:131
 TGWindow.cxx:132
 TGWindow.cxx:133
 TGWindow.cxx:134
 TGWindow.cxx:135
 TGWindow.cxx:136
 TGWindow.cxx:137
 TGWindow.cxx:138
 TGWindow.cxx:139
 TGWindow.cxx:140
 TGWindow.cxx:141
 TGWindow.cxx:142
 TGWindow.cxx:143
 TGWindow.cxx:144
 TGWindow.cxx:145
 TGWindow.cxx:146
 TGWindow.cxx:147
 TGWindow.cxx:148
 TGWindow.cxx:149
 TGWindow.cxx:150
 TGWindow.cxx:151
 TGWindow.cxx:152
 TGWindow.cxx:153
 TGWindow.cxx:154
 TGWindow.cxx:155
 TGWindow.cxx:156
 TGWindow.cxx:157
 TGWindow.cxx:158
 TGWindow.cxx:159
 TGWindow.cxx:160
 TGWindow.cxx:161
 TGWindow.cxx:162
 TGWindow.cxx:163
 TGWindow.cxx:164
 TGWindow.cxx:165
 TGWindow.cxx:166
 TGWindow.cxx:167
 TGWindow.cxx:168
 TGWindow.cxx:169
 TGWindow.cxx:170
 TGWindow.cxx:171
 TGWindow.cxx:172
 TGWindow.cxx:173
 TGWindow.cxx:174
 TGWindow.cxx:175
 TGWindow.cxx:176
 TGWindow.cxx:177
 TGWindow.cxx:178
 TGWindow.cxx:179
 TGWindow.cxx:180
 TGWindow.cxx:181
 TGWindow.cxx:182
 TGWindow.cxx:183
 TGWindow.cxx:184
 TGWindow.cxx:185
 TGWindow.cxx:186
 TGWindow.cxx:187
 TGWindow.cxx:188
 TGWindow.cxx:189
 TGWindow.cxx:190
 TGWindow.cxx:191
 TGWindow.cxx:192
 TGWindow.cxx:193
 TGWindow.cxx:194
 TGWindow.cxx:195
 TGWindow.cxx:196
 TGWindow.cxx:197
 TGWindow.cxx:198
 TGWindow.cxx:199
 TGWindow.cxx:200
 TGWindow.cxx:201
 TGWindow.cxx:202
 TGWindow.cxx:203
 TGWindow.cxx:204
 TGWindow.cxx:205
 TGWindow.cxx:206
 TGWindow.cxx:207
 TGWindow.cxx:208
 TGWindow.cxx:209
 TGWindow.cxx:210
 TGWindow.cxx:211
 TGWindow.cxx:212
 TGWindow.cxx:213
 TGWindow.cxx:214
 TGWindow.cxx:215
 TGWindow.cxx:216
 TGWindow.cxx:217
 TGWindow.cxx:218
 TGWindow.cxx:219
 TGWindow.cxx:220
 TGWindow.cxx:221
 TGWindow.cxx:222
 TGWindow.cxx:223
 TGWindow.cxx:224
 TGWindow.cxx:225
 TGWindow.cxx:226
 TGWindow.cxx:227
 TGWindow.cxx:228
 TGWindow.cxx:229
 TGWindow.cxx:230
 TGWindow.cxx:231
 TGWindow.cxx:232
 TGWindow.cxx:233
 TGWindow.cxx:234
 TGWindow.cxx:235
 TGWindow.cxx:236
 TGWindow.cxx:237
 TGWindow.cxx:238
 TGWindow.cxx:239
 TGWindow.cxx:240