TGFrame.cxx

Go to the documentation of this file.
00001 // @(#)root/gui:$Id: TGFrame.cxx 38067 2011-02-14 15:40:41Z bellenot $
00002 // Author: Fons Rademakers   03/01/98
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 // TGFrame, TGCompositeFrame, TGVerticalFrame, TGHorizontalFrame,       //
00026 // TGMainFrame, TGTransientFrame and TGGroupFrame                       //
00027 //                                                                      //
00028 // The frame classes describe the different "dressed" GUI windows.      //
00029 //                                                                      //
00030 // The TGFrame class is a subclasses of TGWindow, and is used as base   //
00031 // class for some simple widgets (buttons, labels, etc.).               //
00032 // It provides:                                                         //
00033 //  - position & dimension fields                                       //
00034 //  - an 'options' attribute (see constant above)                       //
00035 //  - a generic event handler                                           //
00036 //  - a generic layout mechanism                                        //
00037 //  - a generic border                                                  //
00038 //                                                                      //
00039 // The TGCompositeFrame class is the base class for composite widgets   //
00040 // (menu bars, list boxes, etc.).                                       //
00041 // It provides:                                                         //
00042 //  - a layout manager                                                  //
00043 //  - a frame container (TList *)                                       //
00044 //                                                                      //
00045 // The TGVerticalFrame and TGHorizontalFrame are composite frame that   //
00046 // layout their children in vertical or horizontal way.                 //
00047 //                                                                      //
00048 // The TGMainFrame class defines top level windows that interact with   //
00049 // the system Window Manager.                                           //
00050 //                                                                      //
00051 // The TGTransientFrame class defines transient windows that typically  //
00052 // are used for dialogs windows.                                        //
00053 //                                                                      //
00054 // The TGGroupFrame is a composite frame with a border and a title.     //
00055 // It is typically used to group a number of logically related widgets  //
00056 // visually together.                                                   //
00057 //                                                                      //
00058 //Begin_Html
00059 /*
00060 <img src="gif/tgcompositeframe_classtree.gif">
00061 */
00062 //End_Html
00063 //////////////////////////////////////////////////////////////////////////
00064 
00065 #include "TError.h"
00066 #include "TGFrame.h"
00067 #include "TGResourcePool.h"
00068 #include "TGPicture.h"
00069 #include "TList.h"
00070 #include "TApplication.h"
00071 #include "TTimer.h"
00072 #include "Riostream.h"
00073 #include "TClass.h"
00074 
00075 #include "TObjString.h"
00076 #include "TObjArray.h"
00077 #include "TBits.h"
00078 #include "TColor.h"
00079 #include "TROOT.h"
00080 #include "KeySymbols.h"
00081 #include "TGFileDialog.h"
00082 #include "TGMsgBox.h"
00083 #include "TSystem.h"
00084 #include "TVirtualDragManager.h"
00085 #include "TGuiBuilder.h"
00086 #include "TQConnection.h"
00087 #include "TGButton.h"
00088 #include "TGSplitter.h"
00089 #include "TGDNDManager.h"
00090 #include "TImage.h"
00091 #include "TObjectSpy.h"
00092 
00093 
00094 Bool_t      TGFrame::fgInit = kFALSE;
00095 Pixel_t     TGFrame::fgDefaultFrameBackground = 0;
00096 Pixel_t     TGFrame::fgDefaultSelectedBackground = 0;
00097 Pixel_t     TGFrame::fgWhitePixel = 0;
00098 Pixel_t     TGFrame::fgBlackPixel = 0;
00099 const TGGC *TGFrame::fgBlackGC = 0;
00100 const TGGC *TGFrame::fgWhiteGC = 0;
00101 const TGGC *TGFrame::fgHilightGC = 0;
00102 const TGGC *TGFrame::fgShadowGC = 0;
00103 const TGGC *TGFrame::fgBckgndGC = 0;
00104 Time_t      TGFrame::fgLastClick = 0;
00105 UInt_t      TGFrame::fgLastButton = 0;
00106 Int_t       TGFrame::fgDbx = 0;
00107 Int_t       TGFrame::fgDby = 0;
00108 Window_t    TGFrame::fgDbw = 0;
00109 UInt_t      TGFrame::fgUserColor = 0;
00110 
00111 const TGFont *TGGroupFrame::fgDefaultFont = 0;
00112 const TGGC   *TGGroupFrame::fgDefaultGC = 0;
00113 
00114 TGLayoutHints *TGCompositeFrame::fgDefaultHints = 0;
00115 
00116 static const char *gSaveMacroTypes[] = {
00117    "ROOT macros", "*.C",
00118    "GIF",         "*.gif",
00119    "PNG",         "*.png",
00120    "JPEG",        "*.jpg",
00121    "TIFF",        "*.tiff",
00122    "XPM",         "*.xpm",
00123    "All files",   "*",
00124    0,             0
00125 };
00126 
00127 TList *gListOfHiddenFrames = new TList();
00128 
00129 ClassImp(TGFrame)
00130 ClassImp(TGCompositeFrame)
00131 ClassImp(TGVerticalFrame)
00132 ClassImp(TGHorizontalFrame)
00133 ClassImp(TGMainFrame)
00134 ClassImp(TGTransientFrame)
00135 ClassImp(TGGroupFrame)
00136 ClassImp(TGHeaderFrame)
00137 
00138 
00139 //______________________________________________________________________________
00140 TGFrame::TGFrame(const TGWindow *p, UInt_t w, UInt_t h,
00141                  UInt_t options, Pixel_t back)
00142    : TGWindow(p, 0, 0, w, h, 0, 0, 0, 0, 0, options)
00143 {
00144    // Create a TGFrame object. Options is an OR of the EFrameTypes.
00145 
00146    if (!fgInit && gClient) {
00147       TGFrame::GetDefaultFrameBackground();
00148       TGFrame::GetDefaultSelectedBackground();
00149       TGFrame::GetWhitePixel();
00150       TGFrame::GetBlackPixel();
00151       TGFrame::GetBlackGC();
00152       TGFrame::GetWhiteGC();
00153       TGFrame::GetHilightGC();
00154       TGFrame::GetShadowGC();
00155       TGFrame::GetBckgndGC();
00156       fgInit = kTRUE;
00157    }
00158 
00159    SetWindowAttributes_t wattr;
00160 
00161    fDNDState   = 0;
00162    fBackground = back;
00163    fOptions    = options;
00164    fWidth = w; fHeight = h; fX = fY = fBorderWidth = 0;
00165    fMinWidth    = 0;
00166    fMinHeight   = 0;
00167    fMaxWidth    = kMaxUInt;
00168    fMaxHeight   = kMaxUInt;
00169    fFE          = 0;
00170 
00171    if (fOptions & (kSunkenFrame | kRaisedFrame))
00172       fBorderWidth = (fOptions & kDoubleBorder) ? 2 : 1;
00173 
00174    wattr.fMask = kWABackPixel | kWAEventMask;
00175    wattr.fBackgroundPixel = back;
00176    wattr.fEventMask = kExposureMask;
00177    if (fOptions & kMainFrame) {
00178       wattr.fEventMask |= kStructureNotifyMask;
00179       gVirtualX->ChangeWindowAttributes(fId, &wattr);
00180       //if (fgDefaultBackgroundPicture)
00181       //   SetBackgroundPixmap(fgDefaultBackgroundPicture->GetPicture());
00182    } else {
00183       gVirtualX->ChangeWindowAttributes(fId, &wattr);
00184       //if (!(fOptions & kOwnBackground))
00185       //   SetBackgroundPixmap(kParentRelative);
00186    }
00187    fEventMask = (UInt_t) wattr.fEventMask;
00188 
00189    SetWindowName();
00190 }
00191 
00192 //______________________________________________________________________________
00193 TGFrame::TGFrame(TGClient *c, Window_t id, const TGWindow *parent)
00194    : TGWindow(c, id, parent)
00195 {
00196    // Create a frame using an externally created window. For example
00197    // to register the root window (called by TGClient), or a window
00198    // created via TVirtualX::InitWindow() (id is obtained with
00199    // TVirtualX::GetWindowID()).
00200 
00201    if (!fgInit && gClient) {
00202       TGFrame::GetDefaultFrameBackground();
00203       TGFrame::GetDefaultSelectedBackground();
00204       TGFrame::GetWhitePixel();
00205       TGFrame::GetBlackPixel();
00206       TGFrame::GetBlackGC();
00207       TGFrame::GetWhiteGC();
00208       TGFrame::GetHilightGC();
00209       TGFrame::GetShadowGC();
00210       TGFrame::GetBckgndGC();
00211       fgInit = kTRUE;
00212    }
00213 
00214    WindowAttributes_t attributes;
00215    // Initialize some values - needed for batch mode!
00216    attributes.fX      = 0;
00217    attributes.fY      = 0;
00218    attributes.fWidth  = 100;
00219    attributes.fHeight = 100;
00220    attributes.fBorderWidth = 4;
00221    attributes.fYourEventMask = 0;
00222    gVirtualX->GetWindowAttributes(id, attributes);
00223 
00224    fDNDState    = 0;
00225    fX           = attributes.fX;
00226    fY           = attributes.fY;
00227    fWidth       = attributes.fWidth;
00228    fHeight      = attributes.fHeight;
00229    fBorderWidth = attributes.fBorderWidth;
00230    fEventMask   = (UInt_t) attributes.fYourEventMask;
00231    fBackground  = 0;
00232    fOptions     = 0;
00233    fMinWidth    = 0;
00234    fMinHeight   = 0;
00235    fMaxWidth    = kMaxUInt;
00236    fMaxHeight   = kMaxUInt;
00237    fFE          = 0;
00238 
00239    SetWindowName();
00240 }
00241 
00242 //______________________________________________________________________________
00243 TGFrame::~TGFrame()
00244 {
00245    // Destructor.
00246 
00247 }
00248 
00249 //______________________________________________________________________________
00250 void TGFrame::DeleteWindow()
00251 {
00252    // Delete window. Use single shot timer to call final delete method.
00253    // We use this indirect way since deleting the window in its own
00254    // execution "thread" can cause side effects because frame methods
00255    // can still be called while the window object has already been deleted.
00256 
00257    if (gDNDManager) {
00258       if (gDNDManager->GetMainFrame() == this)
00259          gDNDManager->SetMainFrame(0);
00260    }
00261    if (!TestBit(kDeleteWindowCalled))
00262       TTimer::SingleShot(150, IsA()->GetName(), this, "ReallyDelete()");
00263    SetBit(kDeleteWindowCalled);
00264 }
00265 
00266 //______________________________________________________________________________
00267 void TGFrame::ChangeBackground(Pixel_t back)
00268 {
00269    // Change frame background color.
00270 
00271    fBackground = back;
00272    gVirtualX->SetWindowBackground(fId, back);
00273    fClient->NeedRedraw(this);
00274 }
00275 
00276 //______________________________________________________________________________
00277 Pixel_t TGFrame::GetForeground() const
00278 {
00279    // Return frame foreground color.
00280 
00281    return fgBlackPixel;
00282 }
00283 
00284 //______________________________________________________________________________
00285 void TGFrame::SetBackgroundColor(Pixel_t back)
00286 {
00287    // Set background color (override from TGWindow base class).
00288    // Same effect as ChangeBackground().
00289 
00290    fBackground = back;
00291    TGWindow::SetBackgroundColor(back);
00292 }
00293 
00294 //______________________________________________________________________________
00295 void TGFrame::ChangeOptions(UInt_t options)
00296 {
00297    // Change frame options. Options is an OR of the EFrameTypes.
00298 
00299    if ((options & (kDoubleBorder | kSunkenFrame | kRaisedFrame)) !=
00300       (fOptions & (kDoubleBorder | kSunkenFrame | kRaisedFrame))) {
00301       if (!InheritsFrom(TGGroupFrame::Class())) {
00302          if (options & (kSunkenFrame | kRaisedFrame))
00303             fBorderWidth = (options & kDoubleBorder) ? 2 : 1;
00304          else
00305             fBorderWidth = 0;
00306       }
00307    }
00308 
00309    fOptions = options;
00310 }
00311 
00312 //______________________________________________________________________________
00313 void TGFrame::AddInput(UInt_t emask)
00314 {
00315    // Add events specified in the emask to the events the frame should handle.
00316 
00317    fEventMask |= emask;
00318    gVirtualX->SelectInput(fId, fEventMask);
00319 }
00320 
00321 //______________________________________________________________________________
00322 void TGFrame::RemoveInput(UInt_t emask)
00323 {
00324    // Remove events specified in emask from the events the frame should handle.
00325 
00326    fEventMask &= ~emask;
00327    gVirtualX->SelectInput(fId, fEventMask);
00328 }
00329 
00330 //________________________________________________________________________________
00331 void TGFrame::Draw3dRectangle(UInt_t type, Int_t x, Int_t y,
00332                               UInt_t w, UInt_t h)
00333 {
00334    // Draw 3D rectangle on the frame border.
00335 
00336    switch (type) {
00337       case kSunkenFrame:
00338          gVirtualX->DrawLine(fId, GetShadowGC()(),  x,     y,     x+w-2, y);
00339          gVirtualX->DrawLine(fId, GetShadowGC()(),  x,     y,     x,     y+h-2);
00340          gVirtualX->DrawLine(fId, GetHilightGC()(), x,     y+h-1, x+w-1, y+h-1);
00341          gVirtualX->DrawLine(fId, GetHilightGC()(), x+w-1, y+h-1, x+w-1, y);
00342          break;
00343 
00344       case kSunkenFrame | kDoubleBorder:
00345          gVirtualX->DrawLine(fId, GetShadowGC()(), x,     y,     x+w-2, y);
00346          gVirtualX->DrawLine(fId, GetShadowGC()(), x,     y,     x,     y+h-2);
00347          gVirtualX->DrawLine(fId, GetBlackGC()(),  x+1,   y+1,   x+w-3, y+1);
00348          gVirtualX->DrawLine(fId, GetBlackGC()(),  x+1,   y+1,   x+1,   y+h-3);
00349 
00350          gVirtualX->DrawLine(fId, GetHilightGC()(), x,     y+h-1, x+w-1, y+h-1);
00351          gVirtualX->DrawLine(fId, GetHilightGC()(), x+w-1, y+h-1, x+w-1, y);
00352          gVirtualX->DrawLine(fId, GetBckgndGC()(),  x+1,   y+h-2, x+w-2, y+h-2);
00353          gVirtualX->DrawLine(fId, GetBckgndGC()(),  x+w-2, y+1,   x+w-2, y+h-2);
00354          break;
00355 
00356       case kRaisedFrame:
00357          gVirtualX->DrawLine(fId, GetHilightGC()(), x,     y,     x+w-2, y);
00358          gVirtualX->DrawLine(fId, GetHilightGC()(), x,     y,     x,     y+h-2);
00359          gVirtualX->DrawLine(fId, GetShadowGC()(),  x,     y+h-1, x+w-1, y+h-1);
00360          gVirtualX->DrawLine(fId, GetShadowGC()(),  x+w-1, y+h-1, x+w-1, y);
00361          break;
00362 
00363       case kRaisedFrame | kDoubleBorder:
00364          gVirtualX->DrawLine(fId, GetHilightGC()(), x,     y,     x+w-2, y);
00365          gVirtualX->DrawLine(fId, GetHilightGC()(), x,     y,     x,     y+h-2);
00366          gVirtualX->DrawLine(fId, GetBckgndGC()(),  x+1,   y+1,   x+w-3, y+1);
00367          gVirtualX->DrawLine(fId, GetBckgndGC()(),  x+1,   y+1,   x+1,   y+h-3);
00368 
00369          gVirtualX->DrawLine(fId, GetShadowGC()(),  x+1,   y+h-2, x+w-2, y+h-2);
00370          gVirtualX->DrawLine(fId, GetShadowGC()(),  x+w-2, y+h-2, x+w-2, y+1);
00371          gVirtualX->DrawLine(fId, GetBlackGC()(),   x,     y+h-1, x+w-1, y+h-1);
00372          gVirtualX->DrawLine(fId, GetBlackGC()(),   x+w-1, y+h-1, x+w-1, y);
00373          break;
00374 
00375       default:
00376          break;
00377    }
00378 }
00379 
00380 //______________________________________________________________________________
00381 void TGFrame::DrawBorder()
00382 {
00383    // Draw frame border.
00384 
00385    Draw3dRectangle(fOptions & (kSunkenFrame | kRaisedFrame | kDoubleBorder),
00386                    0, 0, fWidth, fHeight);
00387 }
00388 
00389 //______________________________________________________________________________
00390 void TGFrame::DoRedraw()
00391 {
00392    // Redraw the frame.
00393 
00394    gVirtualX->ClearArea(fId, fBorderWidth, fBorderWidth,
00395                    fWidth - (fBorderWidth << 1), fHeight - (fBorderWidth << 1));
00396 
00397    // border will only be drawn if we have a 3D option hint
00398    // (kRaisedFrame or kSunkenFrame)
00399    DrawBorder();
00400 }
00401 
00402 //______________________________________________________________________________
00403 Bool_t TGFrame::HandleConfigureNotify(Event_t *event)
00404 {
00405    // This event is generated when the frame is resized.
00406 
00407    if ((event->fWidth != fWidth) || (event->fHeight != fHeight)) {
00408       fWidth  = event->fWidth;
00409       fHeight = event->fHeight;
00410       Layout();
00411    }
00412    return kTRUE;
00413 }
00414 
00415 //______________________________________________________________________________
00416 Bool_t TGFrame::HandleEvent(Event_t *event)
00417 {
00418    // Handle all frame events. Events are dispatched to the specific
00419    // event handlers.
00420 
00421    if (gDragManager && !fClient->IsEditDisabled() &&
00422        gDragManager->HandleEvent(event)) return kTRUE;
00423 
00424    TObjectSpy deleteCheck(this);
00425 
00426    switch (event->fType) {
00427 
00428       case kExpose:
00429          HandleExpose(event);
00430          break;
00431 
00432       case kConfigureNotify:
00433          while (gVirtualX->CheckEvent(fId, kConfigureNotify, *event))
00434             ;
00435          // protection
00436          if ((event->fWidth < 32768) && (event->fHeight  < 32768)){
00437             ProcessedConfigure(event);  // emit signal
00438             HandleConfigureNotify(event);
00439          }
00440          break;
00441 
00442       case kGKeyPress:
00443       case kKeyRelease:
00444          HandleKey(event);
00445          break;
00446 
00447       case kFocusIn:
00448       case kFocusOut:
00449          HandleFocusChange(event);
00450          break;
00451 
00452       case kButtonPress:
00453          {
00454             Int_t dbl_clk = kFALSE;
00455 
00456             if ((event->fTime - fgLastClick < 350) &&
00457                 (event->fCode == fgLastButton) &&
00458                 (TMath::Abs(event->fXRoot - fgDbx) < 6) &&
00459                 (TMath::Abs(event->fYRoot - fgDby) < 6) &&
00460                 (event->fWindow == fgDbw))
00461                dbl_clk = kTRUE;
00462 
00463             fgLastClick  = event->fTime;
00464             fgLastButton = event->fCode;
00465             fgDbx = event->fXRoot;
00466             fgDby = event->fYRoot;
00467             fgDbw = event->fWindow;
00468 
00469             if (dbl_clk) {
00470                if ((event->fState & kKeyControlMask) &&
00471                     !GetEditDisabled() && gGuiBuilder) {
00472                   StartGuiBuilding(!IsEditable());
00473                   return kTRUE;
00474                }
00475 
00476                if (!HandleDoubleClick(event)) {
00477                   HandleButton(event);
00478                }
00479             } else {
00480                HandleButton(event);
00481             }
00482          }
00483          break;
00484 
00485       case kButtonDoubleClick:
00486          {
00487             fgLastClick  = event->fTime;
00488             fgLastButton = event->fCode;
00489             fgDbx = event->fXRoot;
00490             fgDby = event->fYRoot;
00491             fgDbw = event->fWindow;
00492 
00493             HandleDoubleClick(event);
00494          }
00495          break;
00496 
00497       case kButtonRelease:
00498          HandleButton(event);
00499          break;
00500 
00501       case kEnterNotify:
00502       case kLeaveNotify:
00503          HandleCrossing(event);
00504          break;
00505 
00506       case kMotionNotify:
00507          while (gVirtualX->CheckEvent(fId, kMotionNotify, *event))
00508             ;
00509          HandleMotion(event);
00510          break;
00511 
00512       case kClientMessage:
00513          HandleClientMessage(event);
00514          break;
00515 
00516       case kSelectionNotify:
00517          HandleSelection(event);
00518          break;
00519 
00520       case kSelectionRequest:
00521          HandleSelectionRequest(event);
00522          break;
00523 
00524       case kSelectionClear:
00525          HandleSelectionClear(event);
00526          break;
00527 
00528       case kColormapNotify:
00529          HandleColormapChange(event);
00530          break;
00531 
00532       default:
00533          //Warning("HandleEvent", "unknown event (%#x) for (%#x)", event->fType, fId);
00534          break;
00535    }
00536 
00537    if (deleteCheck.GetObject())
00538       ProcessedEvent(event);  // emit signal
00539 
00540    return kTRUE;
00541 }
00542 
00543 //______________________________________________________________________________
00544 TGDimension TGFrame::GetDefaultSize() const
00545 {
00546    //   std::cout << fWidth << "x" << fHeight << std::endl;
00547    return TGDimension(fWidth, fHeight);
00548 }
00549 
00550 
00551 //______________________________________________________________________________
00552 void TGFrame::Move(Int_t x, Int_t y)
00553 {
00554    // Move frame.
00555 
00556    if (x != fX || y != fY) {
00557       TGWindow::Move(x, y);
00558       fX = x; fY = y;
00559    }
00560 }
00561 
00562 //______________________________________________________________________________
00563 void TGFrame::Resize(UInt_t w, UInt_t h)
00564 {
00565    // Resize the frame.
00566    // If w=0 && h=0 - Resize to deafult size
00567 
00568    if (w != fWidth || h != fHeight) {
00569       TGDimension siz(0,0);
00570       siz = GetDefaultSize();
00571       fWidth = w ? w : siz.fWidth;
00572       fHeight = h ? h : siz.fHeight;
00573       TGWindow::Resize(fWidth, fHeight);
00574       Layout();
00575    }
00576 }
00577 
00578 //______________________________________________________________________________
00579 void TGFrame::Resize(TGDimension size)
00580 {
00581    // Resize the frame.
00582 
00583    Resize(size.fWidth, size.fHeight);
00584 }
00585 
00586 //______________________________________________________________________________
00587 void TGFrame::MoveResize(Int_t x, Int_t y, UInt_t w, UInt_t h)
00588 {
00589    // Move and/or resize the frame.
00590    // If w=0 && h=0 - Resize to deafult size
00591 
00592    // we do it anyway as we don't know if it's only a move or only a resize
00593    TGDimension siz(0,0);
00594    siz = GetDefaultSize();
00595    fWidth = w ? w : siz.fWidth;
00596    fHeight = h ? h : siz.fHeight;
00597    fX = x; fY = y;
00598    TGWindow::MoveResize(x, y, fWidth, fHeight);
00599    Layout();
00600 }
00601 
00602 //______________________________________________________________________________
00603 void TGFrame::SendMessage(const TGWindow *w, Long_t msg, Long_t parm1, Long_t parm2)
00604 {
00605    // Send message (i.e. event) to window w. Message is encoded in one long
00606    // as message type and up to two long parameters.
00607 
00608    Event_t event;
00609 
00610    if (w) {
00611       event.fType   = kClientMessage;
00612       event.fFormat = 32;
00613       event.fHandle = gROOT_MESSAGE;
00614 
00615       event.fWindow  = w->GetId();
00616       event.fUser[0] = msg;
00617       event.fUser[1] = parm1;
00618       event.fUser[2] = parm2;
00619       event.fUser[3] = 0;
00620       event.fUser[4] = 0;
00621 
00622       gVirtualX->SendEvent(w->GetId(), &event);
00623    }
00624 }
00625 
00626 //______________________________________________________________________________
00627 Bool_t TGFrame::HandleClientMessage(Event_t *event)
00628 {
00629    // Handle a client message. Client messages are the ones sent via
00630    // TGFrame::SendMessage (typically by widgets).
00631 
00632    if (gDNDManager) {
00633       gDNDManager->HandleClientMessage(event);
00634    }
00635    if (event->fHandle == gROOT_MESSAGE) {
00636       ProcessMessage(event->fUser[0], event->fUser[1], event->fUser[2]);
00637    }
00638    return kTRUE;
00639 }
00640 
00641 //______________________________________________________________________________
00642 ULong_t TGFrame::GetDefaultFrameBackground()
00643 {
00644    // Get default frame background.
00645 
00646    static Bool_t init = kFALSE;
00647    if (!init && gClient) {
00648       fgDefaultFrameBackground = gClient->GetResourcePool()->GetFrameBgndColor();
00649       init = kTRUE;
00650    }
00651    return fgDefaultFrameBackground;
00652 }
00653 
00654 //______________________________________________________________________________
00655 ULong_t TGFrame::GetDefaultSelectedBackground()
00656 {
00657    // Get default selected frame background.
00658 
00659    static Bool_t init = kFALSE;
00660    if (!init && gClient) {
00661       fgDefaultSelectedBackground = gClient->GetResourcePool()->GetSelectedBgndColor();
00662       init = kTRUE;
00663    }
00664    return fgDefaultSelectedBackground;
00665 }
00666 
00667 //______________________________________________________________________________
00668 ULong_t TGFrame::GetWhitePixel()
00669 {
00670    // Get white pixel value.
00671 
00672    static Bool_t init = kFALSE;
00673    if (!init && gClient) {
00674       fgWhitePixel = gClient->GetResourcePool()->GetWhiteColor();
00675       init  = kTRUE;
00676    }
00677    return fgWhitePixel;
00678 }
00679 
00680 //______________________________________________________________________________
00681 ULong_t TGFrame::GetBlackPixel()
00682 {
00683    // Get black pixel value.
00684 
00685    static Bool_t init = kFALSE;
00686    if (!init && gClient) {
00687       fgBlackPixel = gClient->GetResourcePool()->GetBlackColor();
00688       init = kTRUE;
00689    }
00690    return fgBlackPixel;
00691 }
00692 
00693 //______________________________________________________________________________
00694 const TGGC &TGFrame::GetBlackGC()
00695 {
00696    // Get black graphics context.
00697 
00698    if (!fgBlackGC && gClient)
00699       fgBlackGC = gClient->GetResourcePool()->GetBlackGC();
00700    return *fgBlackGC;
00701 }
00702 
00703 //______________________________________________________________________________
00704 const TGGC &TGFrame::GetWhiteGC()
00705 {
00706    // Get white graphics context.
00707 
00708    if (!fgWhiteGC && gClient)
00709       fgWhiteGC = gClient->GetResourcePool()->GetWhiteGC();
00710    return *fgWhiteGC;
00711 }
00712 
00713 //______________________________________________________________________________
00714 const TGGC &TGFrame::GetHilightGC()
00715 {
00716    // Get highlight color graphics context.
00717 
00718    if (!fgHilightGC && gClient)
00719       fgHilightGC = gClient->GetResourcePool()->GetFrameHiliteGC();
00720    return *fgHilightGC;
00721 }
00722 
00723 //______________________________________________________________________________
00724 const TGGC &TGFrame::GetShadowGC()
00725 {
00726    // Get shadow color graphics context.
00727 
00728    if (!fgShadowGC && gClient)
00729       fgShadowGC = gClient->GetResourcePool()->GetFrameShadowGC();
00730    return *fgShadowGC;
00731 }
00732 
00733 //______________________________________________________________________________
00734 const TGGC &TGFrame::GetBckgndGC()
00735 {
00736    // Get background color graphics context.
00737 
00738    if (!fgBckgndGC && gClient)
00739       fgBckgndGC = gClient->GetResourcePool()->GetFrameBckgndGC();
00740    return *fgBckgndGC;
00741 }
00742 
00743 //______________________________________________________________________________
00744 Time_t TGFrame::GetLastClick()
00745 {
00746    // Get time of last mouse click.
00747 
00748    return fgLastClick;
00749 }
00750 
00751 //______________________________________________________________________________
00752 void TGFrame::Print(Option_t *option) const
00753 {
00754    // Print window id.
00755 
00756    TString opt = option;
00757    if (opt.Contains("tree")) {
00758       TGWindow::Print(option);
00759       return;
00760    }
00761 
00762    cout <<  option << ClassName() << ":\tid=" << fId << " parent=" << fParent->GetId();
00763    cout << " x=" << fX << " y=" << fY;
00764    cout << " w=" << fWidth << " h=" << fHeight << endl;
00765 }
00766 
00767 //______________________________________________________________________________
00768 void TGFrame::SetDragType(Int_t)
00769 {
00770    // SetDragType
00771 }
00772 
00773 //______________________________________________________________________________
00774 void TGFrame::SetDropType(Int_t)
00775 {
00776    // SetDropType
00777 }
00778 
00779 //______________________________________________________________________________
00780 Int_t TGFrame::GetDragType() const
00781 {
00782    // Returns drag source type.
00783    // If frame is not "draggable" - return zero
00784 
00785    return fClient->IsEditable();
00786 }
00787 
00788 //______________________________________________________________________________
00789 Int_t TGFrame::GetDropType() const
00790 {
00791    // Returns drop target type.
00792    // If frame cannot accept drop - return zero
00793 
00794    return 0;
00795 }
00796 
00797 //______________________________________________________________________________
00798 void TGFrame::StartGuiBuilding(Bool_t on)
00799 {
00800    // Go into GUI building mode.
00801 
00802    if (GetEditDisabled()) return;
00803    if (!gDragManager) gDragManager = TVirtualDragManager::Instance();
00804    if (!gDragManager) return;
00805 
00806    TGCompositeFrame *comp = 0;
00807 
00808    if (InheritsFrom(TGCompositeFrame::Class())) {
00809       comp = (TGCompositeFrame *)this;
00810    } else if (fParent->InheritsFrom(TGCompositeFrame::Class())) {
00811       comp = (TGCompositeFrame*)fParent;
00812    }
00813    if (comp) comp->SetEditable(on);
00814 }
00815 
00816 //______________________________________________________________________________
00817 TGCompositeFrame::TGCompositeFrame(const TGWindow *p, UInt_t w, UInt_t h,
00818          UInt_t options, Pixel_t back) : TGFrame(p, w, h, options, back)
00819 {
00820    // Create a composite frame. A composite frame has in addition to a TGFrame
00821    // also a layout manager and a list of child frames.
00822 
00823    fLayoutManager = 0;
00824    fList          = new TList;
00825    fLayoutBroken  = kFALSE;
00826    fMustCleanup   = kNoCleanup;
00827    fMapSubwindows = fParent->IsMapSubwindows();
00828    if (!fgDefaultHints)
00829       fgDefaultHints = new TGLayoutHints;
00830 
00831    if (fOptions & kHorizontalFrame)
00832       SetLayoutManager(new TGHorizontalLayout(this));
00833    else
00834       SetLayoutManager(new TGVerticalLayout(this));
00835 
00836    SetWindowName();
00837 }
00838 
00839 //______________________________________________________________________________
00840 TGCompositeFrame::TGCompositeFrame(TGClient *c, Window_t id, const TGWindow *parent)
00841    : TGFrame(c, id, parent)
00842 {
00843    // Create a frame using an externally created window. For example
00844    // to register the root window (called by TGClient), or a window
00845    // created via TVirtualX::InitWindow() (id is obtained with TVirtualX::GetWindowID()).
00846 
00847    fLayoutManager = 0;
00848    fList          = new TList;
00849    fLayoutBroken  = kFALSE;
00850    fMustCleanup   = kNoCleanup;
00851    fMapSubwindows = fParent->IsMapSubwindows();
00852    if (!fgDefaultHints)
00853       fgDefaultHints = new TGLayoutHints;
00854 
00855    SetLayoutManager(new TGVerticalLayout(this));
00856 
00857    SetWindowName();
00858 }
00859 
00860 //______________________________________________________________________________
00861 TGCompositeFrame::~TGCompositeFrame()
00862 {
00863    // Delete a composite frame.
00864 
00865    if (fMustCleanup != kNoCleanup) {
00866       Cleanup();
00867    } else {
00868       TGFrameElement *el = 0;
00869       TIter next(fList);
00870 
00871       while ((el = (TGFrameElement *) next())) {
00872          fList->Remove(el);
00873          delete el;
00874       }
00875    }
00876 
00877    delete fList;
00878    delete fLayoutManager;
00879    fList = 0;
00880    fLayoutManager = 0;
00881 }
00882 
00883 //______________________________________________________________________________
00884 Bool_t TGCompositeFrame::IsEditable() const
00885 {
00886    // Return kTRUE if frame is being edited.
00887 
00888    return (fClient->GetRoot() == (TGWindow*)this);
00889 }
00890 
00891 //______________________________________________________________________________
00892 void TGCompositeFrame::SetEditable(Bool_t on)
00893 {
00894    // Switch ON/OFF edit mode.
00895    // If edit mode is ON it is possible:
00896    //
00897    //  1. embed other ROOT GUI application (a la ActiveX)
00898    //
00899    //  For example:
00900    //    TGMainFrame *m = new TGMainFrame(gClient->GetRoot(), 500, 500);
00901    //    m->SetEditable();
00902    //    gSystem->Load("$ROOTSYS/test/Aclock"); // load Aclock demo
00903    //    Aclock a;
00904    //    gROOT->Macro("$ROOTSYS/tutorials/gui/guitest.C");
00905    //    m->SetEditable(0);
00906    //    m->MapWindow();
00907    //
00908 
00909    if (on && ((fEditDisabled & kEditDisable) ||
00910               (fEditDisabled & kEditDisableLayout))) return;
00911 
00912    if (on) {
00913       fClient->SetRoot(this);
00914    } else {
00915       fClient->SetRoot(0);
00916    }
00917    if (gDragManager) gDragManager->SetEditable(on);
00918 }
00919 
00920 //______________________________________________________________________________
00921 void TGCompositeFrame::Cleanup()
00922 {
00923    // Cleanup and delete all objects contained in this composite frame.
00924    // This will delete all objects added via AddFrame().
00925    // CAUTION: all objects (frames and layout hints) must be unique, i.e.
00926    // cannot be shared.
00927 
00928    if (!fList) return;
00929 
00930    TGFrameElement *el;
00931    TIter next(fList);
00932 
00933    while ((el = (TGFrameElement *) next())) {
00934       if (el->fFrame) {
00935          el->fFrame->SetFrameElement(0);
00936          if (!gVirtualX->InheritsFrom("TGX11"))
00937             el->fFrame->DestroyWindow();
00938          delete el->fFrame;
00939       }
00940 
00941       if (el->fLayout && (el->fLayout != fgDefaultHints) &&
00942           (el->fLayout->References() > 0)) {
00943          el->fLayout->RemoveReference();
00944          if (!el->fLayout->References()) {
00945             el->fLayout->fFE = 0;
00946             delete el->fLayout;
00947          }
00948       }
00949       fList->Remove(el);
00950       delete el;
00951    }
00952 }
00953 
00954 //______________________________________________________________________________
00955 void TGCompositeFrame::SetLayoutManager(TGLayoutManager *l)
00956 {
00957    // Set the layout manager for the composite frame.
00958    // The layout manager is adopted by the frame and will be deleted
00959    // by the frame.
00960 
00961    if (l) {
00962       delete fLayoutManager;
00963       fLayoutManager = l;
00964    } else
00965       Error("SetLayoutManager", "no layout manager specified");
00966 }
00967 
00968 //______________________________________________________________________________
00969 void TGCompositeFrame::SetLayoutBroken(Bool_t on)
00970 {
00971    // Set broken layout. No Layout method is called.
00972 
00973    fLayoutBroken = on;
00974 }
00975 
00976 //______________________________________________________________________________
00977 void TGCompositeFrame::SetEditDisabled(UInt_t on)
00978 {
00979    // Set edit disable flag for this frame and subframes
00980    //
00981    //  - if (on & kEditDisable) - disable edit for this frame and all subframes.
00982 
00983    fEditDisabled = on;
00984    UInt_t set = on & kEditDisable;
00985 
00986    // propagate only kEditDisable
00987    if (set == kEditDisable) {
00988 
00989       TGFrameElement *el;
00990       TIter next(fList);
00991       while ((el = (TGFrameElement *) next())) {
00992          if (el->fFrame) {
00993             el->fFrame->SetEditDisabled(set);
00994          }
00995       }
00996    }
00997 }
00998 
00999 //______________________________________________________________________________
01000 void TGCompositeFrame::ChangeOptions(UInt_t options)
01001 {
01002    // Change composite frame options. Options is an OR of the EFrameTypes.
01003 
01004    TGFrame::ChangeOptions(options);
01005 
01006    if (options & kHorizontalFrame)
01007       SetLayoutManager(new TGHorizontalLayout(this));
01008    else if (options & kVerticalFrame)
01009       SetLayoutManager(new TGVerticalLayout(this));
01010 }
01011 
01012 //______________________________________________________________________________
01013 void TGCompositeFrame::SetCleanup(Int_t mode)
01014 {
01015    // Turn on automatic cleanup of child frames in dtor.
01016    //
01017    // if mode = kNoCleanup    - no automatic cleanup
01018    // if mode = kLocalCleanup - automatic cleanup in this composite frame only
01019    // if mode = kDeepCleanup  - automatic deep cleanup in this composite frame
01020    //                           and all child composite frames (hierarchical)
01021    //
01022    // Attention!
01023    //    Hierarchical cleaning is dangerous and must be used with caution.
01024    //    There are many GUI components (in ROOT and in user code) which do not
01025    //    use Clean method in destructor ("custom deallocation").
01026    //    Adding such component to GUI container which is using hierarchical
01027    //    cleaning will produce seg. violation when container is deleted.
01028    //    The reason is double deletion: first whem Clean method is invoked,
01029    //    then at "custom deallocation".
01030    //    We are going to correct all ROOT code to make it to be
01031    //    consitent with hierarchical cleaning scheeme.
01032 
01033    if (mode == fMustCleanup)
01034       return;
01035 
01036    fMustCleanup = mode;
01037 
01038    if (fMustCleanup == kDeepCleanup) {
01039       TGFrameElement *el;
01040       TIter next(fList);
01041 
01042       while ((el = (TGFrameElement *) next())) {
01043          if (el->fFrame->InheritsFrom(TGCompositeFrame::Class())) {
01044             el->fFrame->SetCleanup(kDeepCleanup);
01045          }
01046       }
01047    }
01048 }
01049 
01050 //______________________________________________________________________________
01051 TGFrameElement* TGCompositeFrame::FindFrameElement(TGFrame *f) const
01052 {
01053    // Find frame-element holding frame f.
01054 
01055    if (!fList) return 0;
01056 
01057    TGFrameElement *el;
01058    TIter next(fList);
01059 
01060    while ((el = (TGFrameElement *) next()))
01061       if (el->fFrame == f)
01062          return el;
01063 
01064    return 0;
01065 }
01066 
01067 //______________________________________________________________________________
01068 void TGCompositeFrame::AddFrame(TGFrame *f, TGLayoutHints *l)
01069 {
01070    // Add frame to the composite frame using the specified layout hints.
01071    // If no hints are specified default hints TGLayoutHints(kLHintsNormal,0,0,0,0)
01072    // will be used. Most of the time, however, you will want to provide
01073    // specific hints. User specified hints can be reused many times
01074    // and need to be destroyed by the user. The added frames cannot not be
01075    // added to different composite frames but still need to be deleted by
01076    // the user.
01077 
01078    TGFrameElement *nw = new TGFrameElement(f, l ? l : fgDefaultHints);
01079    fList->Add(nw);
01080 
01081    // in case of recusive cleanup, propagate cleanup setting to all
01082    // child composite frames
01083    if (fMustCleanup == kDeepCleanup)
01084       f->SetCleanup(kDeepCleanup);
01085 }
01086 
01087 //______________________________________________________________________________
01088 void TGCompositeFrame::RemoveAll()
01089 {
01090    // Remove all frames from composite frame.
01091 
01092    if (!fList) return;
01093 
01094    TGFrameElement *el;
01095    TIter next(fList);
01096 
01097    while ((el = (TGFrameElement *) next())) {
01098       fList->Remove(el);
01099       if (el->fLayout) el->fLayout->RemoveReference();
01100 //       el->fFrame->SetFrameElement(0);
01101       delete el;
01102    }
01103 }
01104 
01105 //______________________________________________________________________________
01106 void TGCompositeFrame::RemoveFrame(TGFrame *f)
01107 {
01108    // Remove frame from composite frame.
01109 
01110    TGFrameElement *el = FindFrameElement(f);
01111 
01112    if (el) {
01113       fList->Remove(el);
01114       if (el->fLayout) el->fLayout->RemoveReference();
01115       f->SetFrameElement(0);
01116       delete el;
01117    }
01118 }
01119 
01120 //______________________________________________________________________________
01121 void TGCompositeFrame::MapSubwindows()
01122 {
01123    // Map all sub windows that are part of the composite frame.
01124 
01125    if (!fMapSubwindows) {
01126       //MapWindow();
01127       return;
01128    }
01129 
01130    TGWindow::MapSubwindows();
01131 
01132    if (!fList) return;
01133 
01134    TGFrameElement *el;
01135    TIter next(fList);
01136 
01137    while ((el = (TGFrameElement *) next())) {
01138       if (el->fFrame) {
01139          el->fFrame->MapSubwindows();
01140          TGFrameElement *fe = el->fFrame->GetFrameElement();
01141          if (fe) fe->fState |= kIsVisible;
01142       }
01143    }
01144 }
01145 
01146 //______________________________________________________________________________
01147 void TGCompositeFrame::HideFrame(TGFrame *f)
01148 {
01149    // Hide sub frame.
01150 
01151    TGFrameElement *el = FindFrameElement(f);
01152 
01153    if (el) {
01154       el->fState = 0;
01155       el->fFrame->UnmapWindow();
01156       Layout();
01157    }
01158 }
01159 
01160 //______________________________________________________________________________
01161 void TGCompositeFrame::ShowFrame(TGFrame *f)
01162 {
01163    // Show sub frame.
01164 
01165    TGFrameElement *el = FindFrameElement(f);
01166 
01167    if (el) {
01168       el->fState = 1;
01169       el->fFrame->MapWindow();
01170       Layout();
01171    }
01172 }
01173 
01174 //______________________________________________________________________________
01175 Int_t TGCompositeFrame::GetState(TGFrame *f) const
01176 {
01177    // Get state of sub frame.
01178 
01179    TGFrameElement *el = FindFrameElement(f);
01180 
01181    if (el)
01182       return el->fState;
01183    else
01184       return 0;
01185 }
01186 
01187 //______________________________________________________________________________
01188 Bool_t TGCompositeFrame::IsVisible(TGFrame *f) const
01189 {
01190    // Get state of sub frame.
01191 
01192    TGFrameElement *el = FindFrameElement(f);
01193 
01194    if (el)
01195       return (el->fState & kIsVisible);
01196    else
01197       return kFALSE;
01198 }
01199 
01200 //______________________________________________________________________________
01201 Bool_t TGCompositeFrame::IsArranged(TGFrame *f) const
01202 {
01203    // Get state of sub frame.
01204 
01205    TGFrameElement *el = FindFrameElement(f);
01206 
01207    if (el)
01208       return (el->fState & kIsArranged);
01209    else
01210       return kFALSE;
01211 }
01212 
01213 //______________________________________________________________________________
01214 void TGCompositeFrame::Layout()
01215 {
01216    // Layout the elements of the composite frame.
01217 
01218    if (IsLayoutBroken()) return;
01219    fLayoutManager->Layout();
01220 }
01221 
01222 //______________________________________________________________________________
01223 void TGCompositeFrame::Print(Option_t *option) const
01224 {
01225    // Print all frames in this composite frame.
01226 
01227    TString opt = option;
01228    if (opt.Contains("tree")) {
01229       TGWindow::Print(option);
01230       return;
01231    }
01232 
01233    TGFrameElement *el;
01234    TIter next(fList);
01235    TString tab = option;
01236 
01237    TGFrame::Print(tab.Data());
01238    tab += "   ";
01239    while ((el = (TGFrameElement*)next())) {
01240       el->fFrame->Print(tab.Data());
01241    }
01242 }
01243 
01244 //______________________________________________________________________________
01245 void TGCompositeFrame::ChangeSubframesBackground(Pixel_t back)
01246 {
01247    // Change background color for this frame and all subframes.
01248 
01249    TGFrame::ChangeBackground(back);
01250    TGFrameElement *el;
01251 
01252    TIter next(fList);
01253 
01254    while ((el = (TGFrameElement*)next())) {
01255       el->fFrame->SetBackgroundColor(back);
01256       if (el->fFrame->InheritsFrom(TGCompositeFrame::Class())) {
01257          ((TGCompositeFrame*)el->fFrame)->ChangeSubframesBackground(back);
01258       }
01259       fClient->NeedRedraw(el->fFrame);
01260    }
01261    fClient->NeedRedraw(this);
01262 }
01263 
01264 //______________________________________________________________________________
01265 TGFrame *TGCompositeFrame::GetFrameFromPoint(Int_t x, Int_t y)
01266 {
01267    // Get frame located at specified point.
01268 
01269    if (!Contains(x, y)) return 0;
01270 
01271    if (!fList) return this;
01272 
01273    TGFrame *f;
01274    TGFrameElement *el;
01275    TIter next(fList);
01276 
01277    while ((el = (TGFrameElement *) next())) {
01278       //if (el->fFrame->IsVisible()) { //for this need to move IsVisible to TGFrame
01279       if (el->fState & kIsVisible) {
01280          f = el->fFrame->GetFrameFromPoint(x - el->fFrame->GetX(),
01281                                            y - el->fFrame->GetY());
01282          if (f) return f;
01283       }
01284    }
01285    return this;
01286 }
01287 
01288 //______________________________________________________________________________
01289 Bool_t TGCompositeFrame::TranslateCoordinates(TGFrame *child, Int_t x, Int_t y,
01290                                               Int_t &fx, Int_t &fy)
01291 {
01292    // Translate coordinates to child frame.
01293 
01294    if (child == this) {
01295       fx = x;
01296       fy = y;
01297       return kTRUE;
01298    }
01299 
01300    if (!Contains(x, y)) return kFALSE;
01301 
01302    if (!fList) return kFALSE;
01303 
01304    TGFrameElement *el;
01305    TIter next(fList);
01306 
01307    while ((el = (TGFrameElement *) next())) {
01308       if (el->fFrame == child) {
01309          fx = x - el->fFrame->GetX();
01310          fy = y - el->fFrame->GetY();
01311          return kTRUE;
01312       } else if (el->fFrame->IsComposite()) {
01313          if (((TGCompositeFrame *)el->fFrame)->TranslateCoordinates(child,
01314               x - el->fFrame->GetX(), y - el->fFrame->GetY(), fx, fy))
01315             return kTRUE;
01316       }
01317    }
01318    return kFALSE;
01319 }
01320 
01321 //______________________________________________________________________________
01322 Bool_t TGCompositeFrame::HandleDragEnter(TGFrame *)
01323 {
01324    // Handle drag enter event.
01325 
01326    if (fClient && fClient->IsEditable() &&
01327        (fId != fClient->GetRoot()->GetId())) {
01328 
01329       // the dragged frame cannot be droppped
01330       if (fEditDisabled & (kEditDisable | kEditDisableLayout)) return kFALSE;
01331 
01332       //
01333       if (IsEditable()) {
01334          return kTRUE;
01335       }
01336 
01337       Float_t r, g, b;
01338       TColor::Pixel2RGB(fBackground, r, g, b);
01339       r *= 1.12;
01340       g *= 1.13;
01341       b *= 1.12;
01342       Pixel_t back = TColor::RGB2Pixel(r, g, b);
01343       gVirtualX->SetWindowBackground(fId, back);
01344       DoRedraw();
01345       return kTRUE;
01346    }
01347 
01348    return kFALSE;
01349 }
01350 
01351 //______________________________________________________________________________
01352 Bool_t TGCompositeFrame::HandleDragLeave(TGFrame *)
01353 {
01354    // Handle drag leave event.
01355 
01356    if (fClient && fClient->IsEditable() &&
01357        (fId != fClient->GetRoot()->GetId())) {
01358 
01359       if (fEditDisabled & (kEditDisable | kEditDisableLayout)) return kFALSE;
01360 
01361       gVirtualX->SetWindowBackground(fId, fBackground);
01362       DoRedraw();
01363       return kTRUE;
01364    }
01365 
01366    return kFALSE;
01367 }
01368 
01369 //______________________________________________________________________________
01370 Bool_t TGCompositeFrame::HandleDragMotion(TGFrame *)
01371 {
01372    // Handle drag motion event.
01373 
01374    return kFALSE;
01375 }
01376 
01377 //______________________________________________________________________________
01378 Bool_t TGCompositeFrame::HandleDragDrop(TGFrame *frame, Int_t x, Int_t y,
01379                                         TGLayoutHints *lo)
01380 {
01381    // Handle drop event.
01382 
01383    if (fClient && fClient->IsEditable() && frame && (x >= 0) && (y >= 0) &&
01384        (x + frame->GetWidth() <= fWidth) && (y + frame->GetHeight() <= fHeight)) {
01385 
01386       if (fEditDisabled & (kEditDisable | kEditDisableLayout)) return kFALSE;
01387 
01388       frame->ReparentWindow(this, x, y);
01389       AddFrame(frame, lo);
01390       frame->MapWindow();
01391       SetEditable(kTRUE);
01392       return kTRUE;
01393    }
01394 
01395    return kFALSE;
01396 }
01397 
01398 
01399 //______________________________________________________________________________
01400 TGMainFrame::TGMainFrame(const TGWindow *p, UInt_t w, UInt_t h,
01401         UInt_t options) : TGCompositeFrame(p, w, h, options | kMainFrame)
01402 {
01403    // Create a top level main frame. A main frame interacts
01404    // with the window manager.
01405 
01406    // WMDeleteNotify causes the system to send a kClientMessage to the
01407    // window with fFormat=32 and fUser[0]=gWM_DELETE_WINDOW when window
01408    // closed via WM
01409 
01410    gVirtualX->WMDeleteNotify(fId);
01411 
01412    fBindList = new TList;
01413 
01414    fMWMValue    = 0;
01415    fMWMFuncs    = 0;
01416    fMWMInput    = 0;
01417    fWMX         = -1;
01418    fWMY         = -1;
01419    fWMWidth     = (UInt_t) -1;
01420    fWMHeight    = (UInt_t) -1;
01421    fWMMinWidth  = (UInt_t) -1;
01422    fWMMinHeight = (UInt_t) -1;
01423    fWMMaxWidth  = (UInt_t) -1;
01424    fWMMaxHeight = (UInt_t) -1;
01425    fWMWidthInc  = (UInt_t) -1;
01426    fWMHeightInc = (UInt_t) -1;
01427    fWMInitState = (EInitialState) 0;
01428 
01429    gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_s),
01430                       kKeyControlMask, kTRUE);
01431    if (p == fClient->GetDefaultRoot()) {
01432       fMWMValue    = kMWMDecorAll;
01433       fMWMFuncs    = kMWMFuncAll;
01434       fMWMInput    = kMWMInputModeless;
01435       gVirtualX->SetMWMHints(fId, fMWMValue, fMWMFuncs, fMWMInput);
01436    }
01437    // if parent is editing/embedable add this frame to the parent
01438    if (fClient->IsEditable() && (p == fClient->GetRoot())) {
01439       TGCompositeFrame *frame;
01440       if (p && p->InheritsFrom(TGCompositeFrame::Class())) {
01441          frame = (TGCompositeFrame*)p;
01442          frame->AddFrame(this, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
01443 
01444          // used during paste operation
01445          if (gDragManager && gDragManager->IsPasting()) {
01446             gDragManager->SetPasteFrame(this);
01447          }
01448       }
01449    }
01450    //AddInput(kButtonPressMask); // to allow Drag and Drop
01451    // Create Drag&Drop Manager and define a few DND types
01452    fDNDTypeList = new Atom_t[3];
01453    fDNDTypeList[0] = gVirtualX->InternAtom("application/root", kFALSE);
01454    fDNDTypeList[1] = gVirtualX->InternAtom("text/uri-list", kFALSE);
01455    fDNDTypeList[2] = 0;
01456    if (!gDNDManager)
01457       new TGDNDManager(this, fDNDTypeList);
01458    SetWindowName();
01459 }
01460 
01461 //______________________________________________________________________________
01462 TGMainFrame::~TGMainFrame()
01463 {
01464    // TGMainFrame destructor.
01465 
01466    delete [] fDNDTypeList;
01467    if (fBindList) {
01468       fBindList->Delete();
01469       delete fBindList;
01470    }
01471 }
01472 
01473 //______________________________________________________________________________
01474 Bool_t TGMainFrame::SaveFrameAsCodeOrImage()
01475 {
01476    // Opens dialog window allowing user to save the frame contents
01477    // as a ROOT macro or as an image.
01478    // Returns kTRUE if something was saved.
01479    //
01480    // This is bound to Ctrl-S by default.
01481 
01482    static TString dir(".");
01483    static Bool_t overwr = kFALSE;
01484 
01485    Bool_t repeat_save;
01486    do {
01487       repeat_save = kFALSE;
01488 
01489       TGFileInfo fi;
01490       TGMainFrame *main = (TGMainFrame*)GetMainFrame();
01491       fi.fFileTypes = gSaveMacroTypes;
01492       fi.fIniDir    = StrDup(dir);
01493       fi.fOverwrite = overwr;
01494       new TGFileDialog(fClient->GetDefaultRoot(), this, kFDSave, &fi);
01495       if (!fi.fFilename) return kFALSE;
01496       dir = fi.fIniDir;
01497       overwr = fi.fOverwrite;
01498       TString fname = gSystem->UnixPathName(fi.fFilename);
01499       if (fname.EndsWith(".C"))
01500          main->SaveSource(fname.Data(), "");
01501       else {
01502          TImage::EImageFileTypes gtype = TImage::kUnknown;
01503          if (fname.EndsWith("gif")) {
01504             gtype = TImage::kGif;
01505          } else if (fname.EndsWith(".png")) {
01506             gtype = TImage::kPng;
01507          } else if (fname.EndsWith(".jpg")) {
01508             gtype = TImage::kJpeg;
01509          } else if (fname.EndsWith(".tiff")) {
01510             gtype = TImage::kTiff;
01511          } else if (fname.EndsWith(".xpm")) {
01512             gtype = TImage::kXpm;
01513          }
01514          if (gtype != TImage::kUnknown) {
01515             Int_t saver = gErrorIgnoreLevel;
01516             gErrorIgnoreLevel = kFatal;
01517             TImage *img = TImage::Create();
01518             RaiseWindow();
01519             img->FromWindow(GetId());
01520             img->WriteImage(fname, gtype);
01521             gErrorIgnoreLevel = saver;
01522             delete img;
01523          }
01524          else {
01525             Int_t retval;
01526             new TGMsgBox(fClient->GetDefaultRoot(), this, "Error...",
01527                          TString::Format("file (%s) cannot be saved with this extension",
01528                                          fname.Data()), kMBIconExclamation,
01529                          kMBRetry | kMBCancel, &retval);
01530             repeat_save = (retval == kMBRetry);
01531          }
01532       }
01533    } while (repeat_save);
01534 
01535    return kTRUE;
01536 }
01537 
01538 //______________________________________________________________________________
01539 Bool_t TGMainFrame::HandleKey(Event_t *event)
01540 {
01541    // Handle keyboard events.
01542 
01543    if (fBindList) {
01544 
01545       TIter next(fBindList);
01546       TGMapKey *m;
01547       TGFrame  *w = 0;
01548 
01549       while ((m = (TGMapKey *) next())) {
01550          if (m->fKeyCode == event->fCode) {
01551             w = (TGFrame *) m->fWindow;
01552             if (w->HandleKey(event)) return kTRUE;
01553          }
01554       }
01555    }
01556 
01557    if ((event->fType == kGKeyPress) && (event->fState & kKeyControlMask)) {
01558       UInt_t keysym;
01559       char str[2];
01560       gVirtualX->LookupString(event, str, sizeof(str), keysym);
01561 
01562       if ((keysym & ~0x20) == kKey_S) { // case insensitive ctrl-s
01563          return SaveFrameAsCodeOrImage();
01564       }
01565    }
01566    return kFALSE;
01567 }
01568 
01569 //______________________________________________________________________________
01570 Bool_t TGMainFrame::BindKey(const TGWindow *w, Int_t keycode, Int_t modifier) const
01571 {
01572    // Bind key to a window.
01573 
01574    TList *list = fBindList;
01575    Handle_t id = fId;
01576 
01577    if (fClient->IsEditable()) {
01578       TGMainFrame *main = (TGMainFrame*)GetMainFrame();
01579       list = main->GetBindList();
01580       id = main->GetId();
01581    }
01582 
01583    if (list) {
01584       TGMapKey *m = new TGMapKey(keycode, (TGWindow *)w);
01585       list->Add(m);
01586       gVirtualX->GrabKey(id, keycode, modifier, kTRUE);
01587       return kTRUE;
01588    }
01589    return kFALSE;
01590 }
01591 
01592 //______________________________________________________________________________
01593 void TGMainFrame::RemoveBind(const TGWindow *, Int_t keycode, Int_t modifier) const
01594 {
01595    // Remove key binding.
01596 
01597    if (fBindList) {
01598       TIter next(fBindList);
01599       TGMapKey *m;
01600       while ((m = (TGMapKey *) next())) {
01601          if (m->fKeyCode == (UInt_t) keycode) {
01602             fBindList->Remove(m);
01603             delete m;
01604             gVirtualX->GrabKey(fId, keycode, modifier, kFALSE);
01605             return;
01606          }
01607       }
01608    }
01609 }
01610 
01611 //______________________________________________________________________________
01612 Bool_t TGMainFrame::HandleButton(Event_t *event)
01613 {
01614    // Handle mouse button events.
01615 
01616    if (event->fType == kButtonRelease) {
01617       if (gDNDManager->IsDragging()) gDNDManager->Drop();
01618    }
01619    return TGCompositeFrame::HandleButton(event);
01620 }
01621 
01622 
01623 //______________________________________________________________________________
01624 Bool_t TGMainFrame::HandleMotion(Event_t *event)
01625 {
01626    // Handle mouse motion events.
01627 
01628    if (gDNDManager && gDNDManager->IsDragging()) {
01629       gDNDManager->Drag(event->fXRoot, event->fYRoot,
01630                         TGDNDManager::GetDNDActionCopy(), event->fTime);
01631    }
01632    return TGCompositeFrame::HandleMotion(event);
01633 }
01634 
01635 //______________________________________________________________________________
01636 Bool_t TGMainFrame::HandleSelection(Event_t *event)
01637 {
01638    // Handle primary selection event.
01639 
01640    if ((Atom_t)event->fUser[1] == TGDNDManager::GetDNDSelection()) {
01641       if (gDNDManager)
01642          return gDNDManager->HandleSelection(event);
01643    }
01644    return TGCompositeFrame::HandleSelection(event);
01645 }
01646 
01647 //______________________________________________________________________________
01648 Bool_t TGMainFrame::HandleSelectionRequest(Event_t *event)
01649 {
01650    // Handle selection request event.
01651 
01652    if ((Atom_t)event->fUser[1] == TGDNDManager::GetDNDSelection()) {
01653       if (gDNDManager)
01654          return gDNDManager->HandleSelectionRequest(event);
01655    }
01656    return TGCompositeFrame::HandleSelectionRequest(event);
01657 }
01658 
01659 //______________________________________________________________________________
01660 Bool_t TGMainFrame::HandleClientMessage(Event_t *event)
01661 {
01662    // Handle client messages sent to this frame.
01663 
01664    TGCompositeFrame::HandleClientMessage(event);
01665 
01666    if ((event->fFormat == 32) && ((Atom_t)event->fUser[0] == gWM_DELETE_WINDOW) &&
01667        (event->fHandle != gROOT_MESSAGE)) {
01668       Emit("CloseWindow()");
01669       if (TestBit(kNotDeleted) && !TestBit(kDontCallClose))
01670          CloseWindow();
01671    }
01672    return kTRUE;
01673 }
01674 
01675 //______________________________________________________________________________
01676 void TGMainFrame::SendCloseMessage()
01677 {
01678    // Send close message to self. This method should be called from
01679    // a button to close this window.
01680 
01681    Event_t event;
01682 
01683    event.fType   = kClientMessage;
01684    event.fFormat = 32;
01685    event.fHandle = gWM_DELETE_WINDOW;
01686 
01687    event.fWindow  = GetId();
01688    event.fUser[0] = (Long_t) gWM_DELETE_WINDOW;
01689    event.fUser[1] = 0;
01690    event.fUser[2] = 0;
01691    event.fUser[3] = 0;
01692    event.fUser[4] = 0;
01693 
01694    gVirtualX->SendEvent(GetId(), &event);
01695 }
01696 
01697 //______________________________________________________________________________
01698 void TGMainFrame::CloseWindow()
01699 {
01700    // Close and delete main frame. We get here in response to ALT+F4 or
01701    // a window manager close command. To terminate the application when this
01702    // happens override this method and call gApplication->Terminate(0) or
01703    // make a connection to this signal (if after the slot this method
01704    // should not be called call DontCallClose() in the slot).
01705    // By default the window will be deleted.
01706 
01707    DeleteWindow();
01708 }
01709 
01710 //______________________________________________________________________________
01711 void TGMainFrame::DontCallClose()
01712 {
01713    // Typically call this method in the slot connected to the CloseWindow()
01714    // signal to prevent the calling of the default or any derived CloseWindow()
01715    // methods to prevent premature or double deletion of this window.
01716 
01717    SetBit(kDontCallClose);
01718 }
01719 
01720 //______________________________________________________________________________
01721 void TGMainFrame::SetWindowName(const char *name)
01722 {
01723    // Set window name. This is typically done via the window manager.
01724 
01725    if (!name) {
01726       TGWindow::SetWindowName();
01727    } else {
01728       fWindowName = name;
01729       gVirtualX->SetWindowName(fId, (char *)name);
01730    }
01731 }
01732 
01733 //______________________________________________________________________________
01734 void TGMainFrame::SetIconName(const char *name)
01735 {
01736    // Set window icon name. This is typically done via the window manager.
01737 
01738    fIconName = name;
01739    gVirtualX->SetIconName(fId, (char *)name);
01740 }
01741 
01742 //______________________________________________________________________________
01743 const TGPicture *TGMainFrame::SetIconPixmap(const char *iconName)
01744 {
01745    // Set window icon pixmap by name. This is typically done via the window
01746    // manager. Icon can be in any image format supported by TImage, e.g.
01747    // GIF, XPM, PNG, JPG .. or even PS, PDF (see EImageFileTypes in TImage.h
01748    // for the full list of supported formats).
01749    //
01750    // For example,
01751    //    main_frame->SetIconPixmap("/home/root/icons/bld_rgb.png");
01752 
01753    fIconPixmap = iconName;
01754    const TGPicture *iconPic = fClient->GetPicture(iconName);
01755    if (iconPic) {
01756       Pixmap_t pic = iconPic->GetPicture();
01757       gVirtualX->SetIconPixmap(fId, pic);
01758       return iconPic;
01759    } else
01760       return 0;
01761 }
01762 
01763 //______________________________________________________________________________
01764 void TGMainFrame::SetIconPixmap(char **xpm_array)
01765 {
01766    // Set window icon by xpm array. That allows to have icons
01767    // builtin to the source code.
01768    //
01769    // For example,
01770    //    #include "/home/root/icons/bld_rgb.xpm"
01771    //    //bld_rgb.xpm contains char *bld_rgb[] array
01772    //    main_frame->SetIconPixmap(bld_rgb);
01773 
01774    TImage *img = TImage::Create();
01775    img->SetImageBuffer(xpm_array, TImage::kXpm);
01776    Pixmap_t pic = img->GetPixmap();
01777    if (pic) {
01778       gVirtualX->SetIconPixmap(fId, pic);
01779    } else {
01780       Warning("SetIconPixmap", "Failed to set window icon from xpm array.");
01781    }
01782    delete img;
01783 }
01784 
01785 //______________________________________________________________________________
01786 void TGMainFrame::SetClassHints(const char *className, const char *resourceName)
01787 {
01788    // Set the windows class and resource name. Used to get the right
01789    // resources from the resource database. However, ROOT applications
01790    // will typically use the .rootrc file for this.
01791 
01792    fClassName    = className;
01793    fResourceName = resourceName;
01794    gVirtualX->SetClassHints(fId, (char *)className, (char *)resourceName);
01795 }
01796 
01797 //______________________________________________________________________________
01798 void TGMainFrame::SetMWMHints(UInt_t value, UInt_t funcs, UInt_t input)
01799 {
01800    // Set decoration style for MWM-compatible wm (mwm, ncdwm, fvwm?).
01801 
01802    if (fClient->IsEditable() && (fParent == fClient->GetRoot())) return;
01803 
01804    fMWMValue = value;
01805    fMWMFuncs = funcs;
01806    fMWMInput = input;
01807    gVirtualX->SetMWMHints(fId, value, funcs, input);
01808 }
01809 
01810 //______________________________________________________________________________
01811 void TGMainFrame::SetWMPosition(Int_t x, Int_t y)
01812 {
01813    // Give the window manager a window position hint.
01814 
01815    if (fClient->IsEditable() && (fParent == fClient->GetRoot())) return;
01816 
01817    fWMX = x;
01818    fWMY = y;
01819    gVirtualX->SetWMPosition(fId, x, y);
01820 }
01821 
01822 //______________________________________________________________________________
01823 void TGMainFrame::SetWMSize(UInt_t w, UInt_t h)
01824 {
01825    // Give the window manager a window size hint.
01826 
01827    if (fClient->IsEditable() && (fParent == fClient->GetRoot())) return;
01828 
01829    fWMWidth  = w;
01830    fWMHeight = h;
01831    gVirtualX->SetWMSize(fId, w, h);
01832 }
01833 
01834 //______________________________________________________________________________
01835 void TGMainFrame::SetWMSizeHints(UInt_t wmin, UInt_t hmin,
01836                                  UInt_t wmax, UInt_t hmax,
01837                                  UInt_t winc, UInt_t hinc)
01838 {
01839    // Give the window manager minimum and maximum size hints. Also
01840    // specify via winc and hinc the resize increments.
01841 
01842    if (fClient->IsEditable() && (fParent == fClient->GetRoot())) return;
01843 
01844    fMinWidth    = fWMMinWidth  = wmin;
01845    fMinHeight   = fWMMinHeight = hmin;
01846    fMaxWidth    = fWMMaxWidth  = wmax;
01847    fMaxHeight   = fWMMaxHeight = hmax;
01848    fWMWidthInc  = winc;
01849    fWMHeightInc = hinc;
01850    gVirtualX->SetWMSizeHints(fId, wmin, hmin, wmax, hmax, winc, hinc);
01851 }
01852 
01853 //______________________________________________________________________________
01854 void TGMainFrame::SetWMState(EInitialState state)
01855 {
01856    // Set the initial state of the window. Either kNormalState or kIconicState.
01857 
01858    if (fClient->IsEditable() && (fParent == fClient->GetRoot())) return;
01859 
01860    fWMInitState = state;
01861    gVirtualX->SetWMState(fId, state);
01862 }
01863 
01864 
01865 //______________________________________________________________________________
01866 TGTransientFrame::TGTransientFrame(const TGWindow *p, const TGWindow *main,
01867                                    UInt_t w, UInt_t h, UInt_t options)
01868    : TGMainFrame(p, w, h, options | kTransientFrame)
01869 {
01870    // Create a transient window. A transient window is typically used for
01871    // dialog boxes.
01872 
01873    fMain = main;
01874    if (!fMain && gClient)
01875       fMain = gClient->GetRoot();
01876 
01877    if (fMain) {
01878       gVirtualX->SetWMTransientHint(fId, fMain->GetId());
01879    }
01880 }
01881 
01882 //______________________________________________________________________________
01883 void TGTransientFrame::CenterOnParent(Bool_t croot, EPlacement pos)
01884 {
01885    // Position transient frame centered relative to the parent frame.
01886    // If fMain is 0 (i.e. TGTransientFrame is acting just like a
01887    // TGMainFrame) and croot is true, the window will be centered on
01888    // the root window, otherwise no action is taken and the default
01889    // wm placement will be used.
01890 
01891    Int_t x=0, y=0, ax, ay;
01892    Window_t wdummy;
01893 
01894    UInt_t dw = fClient->GetDisplayWidth();
01895    UInt_t dh = fClient->GetDisplayHeight();
01896 
01897    if (fMain) {
01898 
01899       switch (pos) {
01900          case kCenter:
01901             x = (Int_t)(((TGFrame *) fMain)->GetWidth() - fWidth) >> 1;
01902             y = (Int_t)(((TGFrame *) fMain)->GetHeight() - fHeight) >> 1;
01903             break;
01904          case kRight:
01905             x = (Int_t)(((TGFrame *) fMain)->GetWidth() - (fWidth >> 1));
01906             y = (Int_t)(((TGFrame *) fMain)->GetHeight() - fHeight) >> 1;
01907             break;
01908          case kLeft:
01909             x = (Int_t)(-1 * (Int_t)(fWidth >> 1));
01910             y = (Int_t)(((TGFrame *) fMain)->GetHeight() - fHeight) >> 1;
01911             break;
01912          case kTop:
01913             x = (Int_t)(((TGFrame *) fMain)->GetWidth() - fWidth) >> 1;
01914             y = (Int_t)(-1 * (Int_t)(fHeight >> 1));
01915             break;
01916          case kBottom:
01917             x = (Int_t)(((TGFrame *) fMain)->GetWidth() - fWidth) >> 1;
01918             y = (Int_t)(((TGFrame *) fMain)->GetHeight() - (fHeight >> 1));
01919             break;
01920          case kTopLeft:
01921             x = (Int_t)(-1 * (Int_t)(fWidth >> 1));
01922             y = (Int_t)(-1 * (Int_t)(fHeight >> 1));
01923             break;
01924          case kTopRight:
01925             x = (Int_t)(((TGFrame *) fMain)->GetWidth() - (fWidth >> 1));
01926             y = (Int_t)(-1 * (Int_t)(fHeight >> 1));
01927             break;
01928          case kBottomLeft:
01929             x = (Int_t)(-1 * (Int_t)(fWidth >> 1));
01930             y = (Int_t)(((TGFrame *) fMain)->GetHeight() - (fHeight >> 1));
01931             break;
01932          case kBottomRight:
01933             x = (Int_t)(((TGFrame *) fMain)->GetWidth() - (fWidth >> 1));
01934             y = (Int_t)(((TGFrame *) fMain)->GetHeight() - (fHeight >> 1));
01935             break;
01936       }
01937 
01938       gVirtualX->TranslateCoordinates(fMain->GetId(), GetParent()->GetId(),
01939                                       x, y, ax, ay, wdummy);
01940       if (ax < 10)
01941          ax = 10;
01942       else if (ax + fWidth + 10 > dw)
01943          ax = dw - fWidth - 10;
01944 
01945       if (ay < 20)
01946          ay = 20;
01947       else if (ay + fHeight + 50 > dh)
01948          ay = dh - fHeight - 50;
01949 
01950    } else if (croot) {
01951 
01952       switch (pos) {
01953          case kCenter:
01954             x = (dw - fWidth) >> 1;
01955             y = (dh - fHeight) >> 1;
01956             break;
01957          case kRight:
01958             x = dw - (fWidth >> 1);
01959             y = (dh - fHeight) >> 1;
01960             break;
01961          case kLeft:
01962             x = -1 * (Int_t)(fWidth >> 1);
01963             y = (dh - fHeight) >> 1;
01964             break;
01965          case kTop:
01966             x = (dw - fWidth) >> 1;
01967             y = -1 * (Int_t)(fHeight >> 1);
01968             break;
01969          case kBottom:
01970             x = (dw - fWidth) >> 1;
01971             y = dh - (fHeight >> 1);
01972             break;
01973          case kTopLeft:
01974             x = -1 * (Int_t)(fWidth >> 1);
01975             y = -1 * (Int_t)(fHeight >> 1);
01976             break;
01977          case kTopRight:
01978             x = dw - (fWidth >> 1);
01979             y = -1 * (Int_t)(fHeight >> 1);
01980             break;
01981          case kBottomLeft:
01982             x = -1 * (Int_t)(fWidth >> 1);
01983             y = dh - (fHeight >> 1);
01984             break;
01985          case kBottomRight:
01986             x = dw - (fWidth >> 1);
01987             y = dh - (fHeight >> 1);
01988             break;
01989       }
01990 
01991       ax = x;
01992       ay = y;
01993 
01994    } else {
01995 
01996       return;
01997 
01998    }
01999 
02000    Move(ax, ay);
02001    SetWMPosition(ax, ay);
02002 }
02003 
02004 //______________________________________________________________________________
02005 TGGroupFrame::TGGroupFrame(const TGWindow *p, TGString *title,
02006                            UInt_t options, GContext_t norm,
02007                            FontStruct_t font, Pixel_t back) :
02008    TGCompositeFrame(p, 1, 1, options, back)
02009 {
02010    // Create a group frame. The title will be adopted and deleted by the
02011    // group frame.
02012 
02013    fText       = title;
02014    fFontStruct = font;
02015    fNormGC     = norm;
02016    fTitlePos   = kLeft;
02017    fHasOwnFont = kFALSE;
02018 
02019    int max_ascent, max_descent;
02020    gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
02021    fBorderWidth = max_ascent + max_descent + 1;
02022 }
02023 
02024 //______________________________________________________________________________
02025 TGGroupFrame::TGGroupFrame(const TGWindow *p, const char *title,
02026                            UInt_t options, GContext_t norm,
02027                            FontStruct_t font, Pixel_t back) :
02028    TGCompositeFrame(p, 1, 1, options, back)
02029 {
02030    // Create a group frame.
02031 
02032    fText       = new TGString(!p && !title ? GetName() : title);
02033    fFontStruct = font;
02034    fNormGC     = norm;
02035    fTitlePos   = kLeft;
02036    fHasOwnFont = kFALSE;
02037 
02038    int max_ascent, max_descent;
02039    gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
02040    fBorderWidth = max_ascent + max_descent + 1;
02041 
02042    SetWindowName();
02043 }
02044 
02045 //______________________________________________________________________________
02046 TGGroupFrame::~TGGroupFrame()
02047 {
02048    // Delete a group frame.
02049 
02050    if (fHasOwnFont) {
02051       TGGCPool *pool = fClient->GetGCPool();
02052       TGGC *gc = pool->FindGC(fNormGC);
02053       pool->FreeGC(gc);
02054    }
02055    delete fText;
02056 }
02057 
02058 //______________________________________________________________________________
02059 TGDimension TGGroupFrame::GetDefaultSize() const
02060 {
02061    // Returns default size.
02062 
02063    UInt_t tw = gVirtualX->TextWidth(fFontStruct, fText->GetString(),
02064                                     fText->GetLength()) + 24;
02065 
02066    TGDimension dim = TGCompositeFrame::GetDefaultSize();
02067 
02068    return  tw>dim.fWidth ? TGDimension(tw, dim.fHeight) : dim;
02069 }
02070 
02071 //______________________________________________________________________________
02072 void TGGroupFrame::DoRedraw()
02073 {
02074    // Redraw the group frame. Need special DoRedraw() since we need to
02075    // redraw with fBorderWidth=0.
02076 
02077    gVirtualX->ClearArea(fId, 0, 0, fWidth, fHeight);
02078 
02079    DrawBorder();
02080 }
02081 
02082 
02083 //______________________________________________________________________________
02084 void TGGroupFrame::SetTextColor(Pixel_t color, Bool_t local)
02085 {
02086    // Changes text color.
02087    // If local is true color is changed locally, otherwise - globally.
02088 
02089    TGGCPool *pool =  fClient->GetResourcePool()->GetGCPool();
02090    TGGC *gc = pool->FindGC(fNormGC);
02091 
02092    if (local) {
02093       gc = pool->GetGC((GCValues_t*)gc->GetAttributes(), kTRUE); // copy
02094       fHasOwnFont = kTRUE;
02095    }
02096 
02097    gc->SetForeground(color);
02098    fNormGC = gc->GetGC();
02099    fClient->NeedRedraw(this);
02100 }
02101 
02102 //______________________________________________________________________________
02103 void TGGroupFrame::SetTextFont(FontStruct_t font, Bool_t local)
02104 {
02105    // Changes text font.
02106    // If local is true font is changed locally - otherwise globally.
02107 
02108    FontH_t v = gVirtualX->GetFontHandle(font);
02109    if (!v) return;
02110 
02111    fFontStruct = font;
02112 
02113    TGGCPool *pool =  fClient->GetResourcePool()->GetGCPool();
02114    TGGC *gc = pool->FindGC(fNormGC);
02115 
02116    if (local) {
02117       gc = pool->GetGC((GCValues_t*)gc->GetAttributes(), kTRUE); // copy
02118       fHasOwnFont = kTRUE;
02119    }
02120 
02121    gc->SetFont(v);
02122    fNormGC = gc->GetGC();
02123 
02124    fClient->NeedRedraw(this);
02125 }
02126 
02127 //______________________________________________________________________________
02128 void TGGroupFrame::SetTextFont(const char *fontName, Bool_t local)
02129 {
02130    // Changes text font specified by name.
02131    // If local is true font is changed locally - otherwise globally.
02132 
02133    TGFont *font = fClient->GetFont(fontName);
02134 
02135    if (font) {
02136       SetTextFont(font->GetFontStruct(), local);
02137    }
02138 }
02139 
02140 //______________________________________________________________________________
02141 Bool_t TGGroupFrame::HasOwnFont() const
02142 {
02143    // Returns kTRUE if text attributes are unique,
02144    // returns kFALSE if text attributes are shared (global).
02145 
02146    return fHasOwnFont;
02147 }
02148 
02149 //______________________________________________________________________________
02150 void TGGroupFrame::DrawBorder()
02151 {
02152    // Draw border of around the group frame.
02153    //
02154    // if frame is kRaisedFrame  - a frame border is of "wall style",
02155    // otherwise of "groove style".
02156 
02157    Int_t x, y, l, t, r, b, gl, gr, sep, max_ascent, max_descent;
02158 
02159    UInt_t tw = gVirtualX->TextWidth(fFontStruct, fText->GetString(), fText->GetLength());
02160    gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
02161 
02162    l = 0;
02163    t = (max_ascent + max_descent + 2) >> 1;
02164    r = fWidth - 1;
02165    // next three lines are for backward compatibility in case of horizontal layout
02166    TGLayoutManager * lm = GetLayoutManager();
02167    if ((lm->InheritsFrom(TGHorizontalLayout::Class())) ||
02168        (lm->InheritsFrom(TGMatrixLayout::Class())))
02169       b = fHeight - 1;
02170    else
02171       b = fHeight - t;
02172 
02173    sep = 3;
02174    UInt_t rr = 5 + (sep << 1) + tw;
02175 
02176    switch (fTitlePos) {
02177       case kRight:
02178          gl = fWidth>rr ? Int_t(fWidth - rr) : 5 + sep;
02179          break;
02180       case kCenter:
02181          gl = fWidth>tw ? Int_t((fWidth - tw)>>1) - sep : 5 + sep;
02182          break;
02183       case kLeft:
02184       default:
02185          gl = 5 + sep;
02186    }
02187    gr = gl + tw + (sep << 1);
02188 
02189    switch (fOptions & (kSunkenFrame | kRaisedFrame)) {
02190       case kRaisedFrame:
02191          gVirtualX->DrawLine(fId, GetHilightGC()(),  l,   t,   gl,  t);
02192          gVirtualX->DrawLine(fId, GetShadowGC()(), l+1, t+1, gl,  t+1);
02193 
02194          gVirtualX->DrawLine(fId, GetHilightGC()(),  gr,  t,   r-1, t);
02195          gVirtualX->DrawLine(fId, GetShadowGC()(), gr,  t+1, r-2, t+1);
02196 
02197          gVirtualX->DrawLine(fId, GetHilightGC()(),  r-1, t,   r-1, b-1);
02198          gVirtualX->DrawLine(fId, GetShadowGC()(), r,   t,   r,   b);
02199 
02200          gVirtualX->DrawLine(fId, GetHilightGC()(),  r-1, b-1, l,   b-1);
02201          gVirtualX->DrawLine(fId, GetShadowGC()(), r,   b,   l,   b);
02202 
02203          gVirtualX->DrawLine(fId, GetHilightGC()(),  l,   b-1, l,   t);
02204          gVirtualX->DrawLine(fId, GetShadowGC()(), l+1, b-2, l+1, t+1);
02205          break;
02206       case kSunkenFrame:
02207       default:
02208          gVirtualX->DrawLine(fId, GetShadowGC()(),  l,   t,   gl,  t);
02209          gVirtualX->DrawLine(fId, GetHilightGC()(), l+1, t+1, gl,  t+1);
02210 
02211          gVirtualX->DrawLine(fId, GetShadowGC()(),  gr,  t,   r-1, t);
02212          gVirtualX->DrawLine(fId, GetHilightGC()(), gr,  t+1, r-2, t+1);
02213 
02214          gVirtualX->DrawLine(fId, GetShadowGC()(),  r-1, t,   r-1, b-1);
02215          gVirtualX->DrawLine(fId, GetHilightGC()(), r,   t,   r,   b);
02216 
02217          gVirtualX->DrawLine(fId, GetShadowGC()(),  r-1, b-1, l,   b-1);
02218          gVirtualX->DrawLine(fId, GetHilightGC()(), r,   b,   l,   b);
02219 
02220          gVirtualX->DrawLine(fId, GetShadowGC()(),  l,   b-1, l,   t);
02221          gVirtualX->DrawLine(fId, GetHilightGC()(), l+1, b-2, l+1, t+1);
02222          break;
02223    }
02224 
02225    x = gl + sep;
02226    y = 1;
02227 
02228    fText->Draw(fId, fNormGC, x, y + max_ascent);
02229 }
02230 
02231 //______________________________________________________________________________
02232 void TGGroupFrame::SetTitle(TGString *title)
02233 {
02234    // Set or change title of the group frame. Titlte TGString is adopted
02235    // by the TGGroupFrame.
02236 
02237    if (!title) {
02238       Warning("SetTitle", "title cannot be 0, try \"\"");
02239       title = new TGString("");
02240    }
02241 
02242    delete fText;
02243 
02244    fText = title;
02245    fClient->NeedRedraw(this);
02246 }
02247 
02248 //______________________________________________________________________________
02249 void TGGroupFrame::SetTitle(const char *title)
02250 {
02251    // Set or change title of the group frame.
02252 
02253    if (!title) {
02254       Error("SetTitle", "title cannot be 0, try \"\"");
02255       return;
02256    }
02257 
02258    SetTitle(new TGString(title));
02259 }
02260 
02261 //______________________________________________________________________________
02262 FontStruct_t TGGroupFrame::GetDefaultFontStruct()
02263 {
02264    // Return default font structure in use.
02265 
02266    if (!fgDefaultFont && gClient)
02267       fgDefaultFont = gClient->GetResourcePool()->GetDefaultFont();
02268    return fgDefaultFont->GetFontStruct();
02269 }
02270 
02271 //______________________________________________________________________________
02272 const TGGC &TGGroupFrame::GetDefaultGC()
02273 {
02274    // Return default graphics context in use.
02275 
02276    if (!fgDefaultGC && gClient)
02277       fgDefaultGC = gClient->GetResourcePool()->GetFrameGC();
02278    return *fgDefaultGC;
02279 }
02280 
02281 //______________________________________________________________________________
02282 TGHeaderFrame::TGHeaderFrame(const TGWindow *p, UInt_t w, UInt_t h,
02283                  UInt_t options, Pixel_t back) :
02284   TGHorizontalFrame(p, w, h, options | kVerticalFrame, back)
02285 {
02286    // Header Frame constructor.
02287 
02288    fSplitCursor = kNone;
02289    fSplitCursor = gVirtualX->CreateCursor(kArrowHor);
02290    fOverSplitter = false;
02291    fOverButton = -1;
02292    fLastButton = -1;
02293    fNColumns   = 1;
02294 
02295    gVirtualX->GrabButton(fId, kAnyButton, kAnyModifier,
02296                          kButtonPressMask | kButtonReleaseMask,
02297                          kNone, kNone);
02298    AddInput(kPointerMotionMask);
02299 }
02300 
02301 //______________________________________________________________________________
02302 void TGHeaderFrame::SetColumnsInfo(Int_t nColumns, TGTextButton  **colHeader,
02303                TGVFileSplitter  **splitHeader)
02304 {
02305    // Set columns informations in the header frame.
02306 
02307    fNColumns = nColumns;
02308    fColHeader = colHeader;
02309    fSplitHeader = splitHeader;
02310 }
02311 
02312 //______________________________________________________________________________
02313 Bool_t TGHeaderFrame::HandleButton(Event_t* event)
02314 {
02315    // Handle mouse button event in header frame.
02316 
02317    if ( event->fY > 0 &&
02318         event->fY <= (Int_t) this->GetHeight() ) {
02319       for (Int_t i = 1; i < fNColumns; ++i ) {
02320          if ( event->fX < fColHeader[i]->GetX() &&
02321             event->fX >= fColHeader[i-1]->GetX() ) {
02322             if ( fOverSplitter ) {
02323                if ( event->fX <= fColHeader[i-1]->GetX() + 5 )
02324                   fSplitHeader[i-2]->HandleButton(event);
02325                else
02326                   fSplitHeader[i-1]->HandleButton(event);
02327             } else {
02328                if ( event->fType == kButtonPress ) {
02329                   fLastButton = i - 1;
02330                } else {
02331                   fLastButton = -1;
02332                }
02333                event->fX -= fColHeader[i-1]->GetX();
02334                fColHeader[i-1]->HandleButton(event);
02335             }
02336             break;
02337          }
02338       }
02339    }
02340 
02341    return kTRUE;
02342 }
02343 
02344 //______________________________________________________________________________
02345 Bool_t TGHeaderFrame::HandleDoubleClick(Event_t *event)
02346 {
02347    // Handle double click mouse event in header frame.
02348 
02349    if ( event->fY > 0 &&
02350         event->fY <= (Int_t) this->GetHeight() ) {
02351       for (Int_t i = 1; i < fNColumns; ++i ) {
02352          if ( event->fX < fColHeader[i]->GetX() &&
02353             event->fX >= fColHeader[i-1]->GetX() ) {
02354             if ( fOverSplitter ) {
02355                if ( event->fX <= fColHeader[i-1]->GetX() + 5 )
02356                   fSplitHeader[i-2]->HandleDoubleClick(event);
02357                else
02358                   fSplitHeader[i-1]->HandleDoubleClick(event);
02359             } else {
02360                event->fX -= fColHeader[i-1]->GetX();
02361                fColHeader[i-1]->HandleDoubleClick(event);
02362             }
02363             break;
02364          }
02365       }
02366    }
02367 
02368    return kTRUE;
02369 }
02370 
02371 //______________________________________________________________________________
02372 Bool_t TGHeaderFrame::HandleMotion(Event_t* event)
02373 {
02374    // Handle mouse motion events in header frame.
02375 
02376    if ( event->fY > 0 &&
02377         event->fY <= (Int_t) this->GetHeight() ) {
02378       Bool_t inMiddle = false;
02379 
02380       for (Int_t i = 1; i < fNColumns; ++i ) {
02381          if ( event->fX > fColHeader[i]->GetX() - 5 &&
02382             event->fX < fColHeader[i]->GetX() + 5 ) {
02383             inMiddle = true;
02384          }
02385          if ( event->fX < fColHeader[i]->GetX() &&
02386             event->fX >= fColHeader[i-1]->GetX() ) {
02387             fOverButton = i - 1;
02388          }
02389       }
02390       fOverSplitter = inMiddle;
02391       if ( fOverSplitter ) {
02392          gVirtualX->SetCursor(fId, fSplitCursor);
02393       }
02394       else {
02395          gVirtualX->SetCursor(fId, kNone);
02396       }
02397    }
02398    return kTRUE;
02399 }
02400 
02401 //______________________________________________________________________________
02402 void TGFrame::SaveUserColor(ostream &out, Option_t *option)
02403 {
02404    // Save a user color in a C++ macro file - used in SavePrimitive().
02405 
02406    char quote = '"';
02407 
02408    if (gROOT->ClassSaved(TGFrame::Class())) {
02409       out << endl;
02410    } else {
02411       //  declare a color variable to reflect required user changes
02412       out << endl;
02413       out << "   ULong_t ucolor;        // will reflect user color changes" << endl;
02414    }
02415    ULong_t ucolor;
02416    if (option && !strcmp(option, "slider"))
02417       ucolor = GetDefaultFrameBackground();
02418    else
02419       ucolor = GetBackground();
02420    if ((ucolor != fgUserColor) || (ucolor == GetWhitePixel())) {
02421       const char *ucolorname = TColor::PixelAsHexString(ucolor);
02422       out << "   gClient->GetColorByName(" << quote << ucolorname << quote
02423           << ",ucolor);" << endl;
02424       fgUserColor = ucolor;
02425    }
02426 }
02427 
02428 //______________________________________________________________________________
02429 TString TGFrame::GetOptionString() const
02430 {
02431    // Returns a frame option string - used in SavePrimitive().
02432 
02433    TString options;
02434 
02435    if (!GetOptions()) {
02436       options = "kChildFrame";
02437    } else {
02438       if (fOptions & kMainFrame) {
02439          if (options.Length() == 0) options  = "kMainFrame";
02440          else                       options += " | kMainFrame";
02441       }
02442       if (fOptions & kVerticalFrame) {
02443          if (options.Length() == 0) options  = "kVerticalFrame";
02444          else                       options += " | kVerticalFrame";
02445       }
02446       if (fOptions & kHorizontalFrame) {
02447          if (options.Length() == 0) options  = "kHorizontalFrame";
02448          else                       options += " | kHorizontalFrame";
02449       }
02450       if (fOptions & kSunkenFrame) {
02451          if (options.Length() == 0) options  = "kSunkenFrame";
02452          else                       options += " | kSunkenFrame";
02453       }
02454       if (fOptions & kRaisedFrame) {
02455          if (options.Length() == 0) options  = "kRaisedFrame";
02456          else                       options += " | kRaisedFrame";
02457       }
02458       if (fOptions & kDoubleBorder) {
02459          if (options.Length() == 0) options  = "kDoubleBorder";
02460          else                       options += " | kDoubleBorder";
02461       }
02462       if (fOptions & kFitWidth) {
02463          if (options.Length() == 0) options  = "kFitWidth";
02464          else                       options += " | kFitWidth";
02465       }
02466       if (fOptions & kFixedWidth) {
02467          if (options.Length() == 0) options  = "kFixedWidth";
02468          else                       options += " | kFixedWidth";
02469       }
02470       if (fOptions & kFitHeight) {
02471          if (options.Length() == 0) options  = "kFitHeight";
02472          else                       options += " | kFitHeight";
02473       }
02474       if (fOptions & kFixedHeight) {
02475          if (options.Length() == 0) options  = "kFixedHeight";
02476          else                       options += " | kFixedHeight";
02477       }
02478       if (fOptions & kOwnBackground) {
02479          if (options.Length() == 0) options  = "kOwnBackground";
02480          else                       options += " | kOwnBackground";
02481       }
02482       if (fOptions & kTransientFrame) {
02483          if (options.Length() == 0) options  = "kTransientFrame";
02484          else                       options += " | kTransientFrame";
02485       }
02486       if (fOptions & kTempFrame) {
02487          if (options.Length() == 0) options  = "kTempFrame";
02488          else                       options += " | kTempFrame";
02489       }
02490    }
02491    return options;
02492 }
02493 
02494 //______________________________________________________________________________
02495 TString TGMainFrame::GetMWMvalueString() const
02496 {
02497    // Returns MWM decoration hints as a string - used in SavePrimitive().
02498 
02499    TString hints;
02500 
02501    if (fMWMValue) {
02502       if (fMWMValue & kMWMDecorAll) {
02503          if (hints.Length() == 0) hints  = "kMWMDecorAll";
02504          else                     hints += " | kMWMDecorAll";
02505       }
02506       if (fMWMValue & kMWMDecorBorder) {
02507          if (hints.Length() == 0) hints  = "kMWMDecorBorder";
02508          else                     hints += " | kMWMDecorBorder";
02509       }
02510       if (fMWMValue & kMWMDecorResizeH) {
02511          if (hints.Length() == 0) hints  = "kMWMDecorResizeH";
02512          else                     hints += " | kMWMDecorResizeH";
02513       }
02514       if (fMWMValue & kMWMDecorTitle) {
02515          if (hints.Length() == 0) hints  = "kMWMDecorTitle";
02516          else                     hints += " | kMWMDecorTitle";
02517       }
02518       if (fMWMValue & kMWMDecorMenu) {
02519          if (hints.Length() == 0) hints  = "kMWMDecorMenu";
02520          else                     hints += " | kMWMDecorMenu";
02521       }
02522       if (fMWMValue & kMWMDecorMinimize) {
02523          if (hints.Length() == 0) hints  = "kMWMDecorMinimize";
02524          else                     hints += " | kMWMDecorMinimize";
02525       }
02526       if (fMWMValue & kMWMDecorMaximize) {
02527          if (hints.Length() == 0) hints  = "kMWMDecorMaximize";
02528          else                     hints += " | kMWMDecorMaximize";
02529       }
02530    }
02531    return hints;
02532 }
02533 
02534 //______________________________________________________________________________
02535 TString TGMainFrame::GetMWMfuncString() const
02536 {
02537    // Returns MWM function hints as a string - used in SavePrimitive().
02538 
02539    TString hints;
02540 
02541    if (fMWMFuncs) {
02542 
02543       if (fMWMFuncs & kMWMFuncAll) {
02544          if (hints.Length() == 0) hints  = "kMWMFuncAll";
02545          else                     hints += " | kMWMFuncAll";
02546       }
02547       if (fMWMFuncs & kMWMFuncResize) {
02548          if (hints.Length() == 0) hints  = "kMWMFuncResize";
02549          else                     hints += " | kMWMFuncResize";
02550       }
02551       if (fMWMFuncs & kMWMFuncMove) {
02552          if (hints.Length() == 0) hints  = "kMWMFuncMove";
02553          else                     hints += " | kMWMFuncMove";
02554       }
02555       if (fMWMFuncs & kMWMFuncMinimize) {
02556          if (hints.Length() == 0) hints  = "kMWMFuncMinimize";
02557          else                     hints += " | kMWMFuncMinimize";
02558       }
02559       if (fMWMFuncs & kMWMFuncMaximize) {
02560          if (hints.Length() == 0) hints  = "kMWMFuncMaximize";
02561          else                     hints += " | kMWMFuncMaximize";
02562       }
02563       if (fMWMFuncs & kMWMFuncClose) {
02564          if (hints.Length() == 0) hints  = "kMWMFuncClose";
02565          else                     hints += " | kMWMFuncClose";
02566       }
02567    }
02568    return hints;
02569 }
02570 
02571 //______________________________________________________________________________
02572 TString TGMainFrame::GetMWMinpString() const
02573 {
02574    // Returns MWM input mode hints as a string - used in SavePrimitive().
02575 
02576    TString hints;
02577 
02578    if (fMWMInput == 0) hints = "kMWMInputModeless";
02579 
02580    if (fMWMInput == 1) hints = "kMWMInputPrimaryApplicationModal";
02581 
02582    if (fMWMInput == 2) hints = "kMWMInputSystemModal";
02583 
02584    if (fMWMInput == 3) hints = "kMWMInputFullApplicationModal";
02585 
02586    return hints;
02587 }
02588 
02589 //______________________________________________________________________________
02590 void TGCompositeFrame::SavePrimitiveSubframes(ostream &out, Option_t *option /*= ""*/)
02591 {
02592    // Auxilary protected method  used to save subframes.
02593 
02594    if (fLayoutBroken)
02595       out << "   " << GetName() << "->SetLayoutBroken(kTRUE);" << endl;
02596 
02597    if (!fList) return;
02598 
02599    char quote = '"';
02600 
02601    TGFrameElement *el;
02602    static TGHSplitter *hsplit = 0;
02603    static TGVSplitter *vsplit = 0;
02604    TList *signalslist;
02605    TList *connlist;
02606    TQConnection *conn;
02607    TString signal_name, slot_name;
02608 
02609    TIter next(fList);
02610 
02611    while ((el = (TGFrameElement *) next())) {
02612 
02613       // Don't save hidden (unmapped) frames having a parent different
02614       // than this frame. Solves a problem with shared frames
02615       // (e.g. shared menus in the new Browser)
02616       if ((!el->fState & kIsVisible) && (el->fFrame->GetParent() != this))
02617          continue;
02618 
02619       // Remember if the frame to be saved is a TG(H,V)Splitter
02620       // See comments below and in TG[H/V]Splitter::SavePrimitive()
02621       if (el->fFrame->InheritsFrom("TGVSplitter")) {
02622          vsplit = (TGVSplitter *)el->fFrame;
02623          if (vsplit->GetLeft())
02624             vsplit = 0;
02625       }
02626       else if (el->fFrame->InheritsFrom("TGHSplitter")) {
02627          hsplit = (TGHSplitter *)el->fFrame;
02628          if (hsplit->GetAbove())
02629             hsplit = 0;
02630       }
02631       el->fFrame->SavePrimitive(out, option);
02632       out << "   " << GetName() << "->AddFrame(" << el->fFrame->GetName();
02633       el->fLayout->SavePrimitive(out, option);
02634       out << ");"<< endl;
02635       if (IsLayoutBroken()) {
02636          out << "   " << el->fFrame->GetName() << "->MoveResize(";
02637          out << el->fFrame->GetX() << "," << el->fFrame->GetY() << ",";
02638          out << el->fFrame->GetWidth() << ","  << el->fFrame->GetHeight();
02639          out << ");" << endl;
02640       }
02641       // TG(H,V)Splitter->SetFrame(theframe) can only be saved _AFTER_
02642       // having saved "theframe", when "theframe" is either at right
02643       // or below the splitter (that means after the splitter in the
02644       // list of frames), otherwise "theframe" would be undefined
02645       // (aka used before to be created)...
02646       if (vsplit && el->fFrame == vsplit->GetFrame()) {
02647          out << "   " << vsplit->GetName() << "->SetFrame(" << vsplit->GetFrame()->GetName();
02648          if (vsplit->GetLeft()) out << ",kTRUE);" << endl;
02649          else                 out << ",kFALSE);"<< endl;
02650          vsplit = 0;
02651       }
02652       if (hsplit && el->fFrame == hsplit->GetFrame()) {
02653          out << "   " << hsplit->GetName() << "->SetFrame(" << hsplit->GetFrame()->GetName();
02654          if (hsplit->GetAbove()) out << ",kTRUE);" << endl;
02655          else                  out << ",kFALSE);"<< endl;
02656          hsplit = 0;
02657       }
02658 
02659       if (!el->fState & kIsVisible) {
02660          gListOfHiddenFrames->Add(el->fFrame);
02661       }
02662 
02663       // saving signals/slots
02664       signalslist = (TList*)el->fFrame->GetListOfSignals();
02665       if (!signalslist)  continue;
02666       connlist = (TList*)signalslist->Last();
02667       if (connlist) {
02668          conn = (TQConnection*)connlist->Last();
02669          signal_name = connlist->GetName();
02670          slot_name = conn->GetName();
02671          Int_t eq = slot_name.First('=');
02672          Int_t rb = slot_name.First(')');
02673          if (eq != -1)
02674             slot_name.Remove(eq, rb-eq);
02675          out << "   " << el->fFrame->GetName() << "->Connect(" << quote << signal_name
02676              << quote << ", 0, 0, " << quote << slot_name << quote << ");" << endl;
02677 
02678          TList *lsl = (TList *)gROOT->GetListOfSpecials()->FindObject("ListOfSlots");
02679          if (lsl) {
02680             TObjString *slotel = (TObjString *)lsl->FindObject(slot_name);
02681             if (!slotel)
02682                lsl->Add(new TObjString(slot_name));
02683          }
02684       }
02685    }
02686    out << endl;
02687 }
02688 
02689 //______________________________________________________________________________
02690 void TGCompositeFrame::SavePrimitive(ostream &out, Option_t *option /*= ""*/)
02691 {
02692    // Save a composite frame widget as a C++ statement(s) on output stream out.
02693 
02694    if (fBackground != GetDefaultFrameBackground()) SaveUserColor(out, option);
02695 
02696    if (!strcmp(GetName(),"")) {
02697       SetName(Form("fCompositeframe%d",fgCounter));
02698       fgCounter++;
02699    }
02700 
02701    out << endl << "   // composite frame" << endl;
02702    out << "   TGCompositeFrame *";
02703    out << GetName() << " = new TGCompositeFrame(" << fParent->GetName()
02704        << "," << GetWidth() << "," << GetHeight();
02705 
02706    if (fBackground == GetDefaultFrameBackground()) {
02707       if (!GetOptions()) {
02708          out << ");" << endl;
02709       } else {
02710          out << "," << GetOptionString() <<");" << endl;
02711       }
02712    } else {
02713       out << "," << GetOptionString() << ",ucolor);" << endl;
02714    }
02715    if (option && strstr(option, "keep_names"))
02716       out << "   " << GetName() << "->SetName(\"" << GetName() << "\");" << endl;
02717 
02718    // setting layout manager if it differs from the composite frame type
02719    TGLayoutManager *lm = GetLayoutManager();
02720    if ((GetOptions() & kHorizontalFrame) &&
02721        (lm->InheritsFrom(TGHorizontalLayout::Class()))) {
02722       ;
02723    } else if ((GetOptions() & kVerticalFrame) &&
02724               (lm->InheritsFrom(TGVerticalLayout::Class()))) {
02725       ;
02726    } else {
02727       out << "   " << GetName() <<"->SetLayoutManager(";
02728       lm->SavePrimitive(out, option);
02729       out << ");"<< endl;
02730    }
02731 
02732    SavePrimitiveSubframes(out, option);
02733 }
02734 
02735 //______________________________________________________________________________
02736 void TGMainFrame::SaveSource(const char *filename, Option_t *option)
02737 {
02738    // Save the GUI main frame widget in a C++ macro file.
02739 
02740    // iteration over all active classes to exclude the base ones
02741    TString opt = option;
02742    TBits *bc = new TBits();
02743    TClass *c1, *c2, *c3;
02744    UInt_t k = 0;      // will mark k-bit of TBits if the class is a base class
02745 
02746    TIter nextc1(gROOT->GetListOfClasses());
02747    //gROOT->GetListOfClasses()->ls();    // valid. test
02748    while((c1 = (TClass *)nextc1())) {
02749 
02750       //   resets bit TClass::kClassSaved for all classes
02751       c1->ResetBit(TClass::kClassSaved);
02752 
02753       TIter nextc2(gROOT->GetListOfClasses());
02754       while ((c2 = (TClass *)nextc2())) {
02755          if (c1==c2) continue;
02756          else {
02757             c3 = c2->GetBaseClass(c1);
02758             if (c3 != 0) {
02759                bc->SetBitNumber(k, kTRUE);
02760                break;
02761             }
02762          }
02763       }
02764       k++;
02765    }
02766 
02767    TList *ilist = new TList();   // will contain include file names without '.h'
02768    ilist->SetName("ListOfIncludes");
02769    gROOT->GetListOfSpecials()->Add(ilist);
02770    k=0;
02771 
02772    //   completes list of include file names
02773    TIter nextdo(gROOT->GetListOfClasses());
02774    while ((c2 = (TClass *)nextdo())) {
02775       // for used GUI header files
02776       if (bc->TestBitNumber(k) == 0 && c2->InheritsFrom(TGObject::Class()) == 1) {
02777          // for any used ROOT header files activate the line below, comment the line above
02778          //if (bc->TestBitNumber(k) == 0) {
02779          const char *iname;
02780          iname = c2->GetDeclFileName();
02781          if (strlen(iname) != 0 && strstr(iname,".h")) {
02782             const char *lastsl = strrchr(iname,'/');
02783             if (lastsl) iname = lastsl + 1;
02784             char *tname = new char[strlen(iname)+1];
02785             Int_t i=0;
02786             while (*iname != '.') {
02787                tname[i] = *iname;
02788                i++; iname++;
02789             }
02790             tname[i] = 0;    //tname = include file name without '.h'
02791 
02792             TObjString *iel = (TObjString *)ilist->FindObject(tname);
02793             if (!iel) {
02794                ilist->Add(new TObjString(tname));
02795             }
02796             // Weird, but when saving a canvas, the following two classes
02797             // may be missing if the toolbar has not been displayed...
02798             if (strstr(tname, "TRootCanvas")) {
02799                if (!ilist->FindObject("TGDockableFrame"))
02800                   ilist->Add(new TObjString("TGDockableFrame"));
02801                if (!ilist->FindObject("TG3DLine"))
02802                   ilist->Add(new TObjString("TG3DLine"));
02803             }
02804             delete [] tname;
02805          }
02806          k++;  continue;
02807       }
02808       k++;
02809    }
02810 
02811    char quote = '"';
02812    ofstream out;
02813 
02814    TString ff = filename && strlen(filename) ? filename : "Rootappl.C";
02815 
02816    // Computes the main method name.
02817    const char *fname = gSystem->BaseName(ff.Data());
02818    Int_t lenfname = strlen(fname);
02819    char *sname = new char[lenfname+1];
02820 
02821    Int_t i = 0;
02822    while ((*fname != '.') && (i < lenfname)) {
02823       sname[i] = *fname;
02824       i++; fname++;
02825    }
02826    if (i == lenfname)
02827       ff += ".C";
02828    sname[i] = 0;
02829 
02830    out.open(ff.Data(), ios::out);
02831    if (!out.good()) {
02832       Error("SaveSource", "cannot open file: %s", ff.Data());
02833       delete [] sname;
02834       return;
02835    }
02836 
02837    // writes include files in C++ macro
02838    TObjString *inc;
02839    ilist = (TList *)gROOT->GetListOfSpecials()->FindObject("ListOfIncludes");
02840 
02841    if (!ilist) {
02842       delete [] sname;
02843       return;
02844    }
02845 
02846    // write macro header, date/time stamp as string, and the used Root version
02847    TDatime t;
02848    out <<"// Mainframe macro generated from application: "<< gApplication->Argv(0) << endl;
02849    out <<"// By ROOT version "<< gROOT->GetVersion() <<" on "<<t.AsSQLString()<< endl;
02850    out << endl;
02851 
02852    TIter nexti(ilist);
02853    while((inc = (TObjString *)nexti())) {
02854          out << "#ifndef ROOT_" << inc->GetString() << endl;
02855          out << "#include " << quote << inc->GetString() << ".h" << quote << endl;
02856          out << "#endif" << endl;
02857          if (strstr(inc->GetString(),"TRootEmbeddedCanvas")) {
02858             out << "#ifndef ROOT_TCanvas" << endl;
02859             out << "#include " << quote << "TCanvas.h" << quote << endl;
02860             out << "#endif" << endl;
02861          }
02862    }
02863    out << endl << "#include " << quote << "Riostream.h" << quote << endl;
02864    // deletes created ListOfIncludes
02865    gROOT->GetListOfSpecials()->Remove(ilist);
02866    ilist->Delete();
02867    delete ilist;
02868    delete bc;
02869 
02870    // writes the macro entry point equal to the fname
02871    out << endl;
02872    out << "void " << sname << "()" << endl;
02873    out <<"{"<< endl;
02874    delete [] sname;
02875 
02876    gListOfHiddenFrames->Clear();
02877 
02878    // saivng slots
02879    TList *lSlots = new TList;
02880    lSlots->SetName("ListOfSlots");
02881    gROOT->GetListOfSpecials()->Add(lSlots);
02882 
02883    TGMainFrame::SavePrimitive(out, option);
02884 
02885    GetClassHints((const char *&)fClassName, (const char *&)fResourceName);
02886    if (strlen(fClassName) || strlen(fResourceName)) {
02887       out << "   " << GetName() << "->SetClassHints(" << quote << fClassName
02888           << quote << "," << quote << fResourceName << quote << ");" << endl;
02889    }
02890 
02891    GetMWMHints(fMWMValue, fMWMFuncs, fMWMInput);
02892    if (fMWMValue || fMWMFuncs || fMWMInput) {
02893       out << "   " << GetName() << "->SetMWMHints(";
02894       out << GetMWMvalueString() << "," << endl;
02895       out << "                        ";
02896       out << GetMWMfuncString() << "," << endl;
02897       out << "                        ";
02898       out << GetMWMinpString() << ");"<< endl;
02899    }
02900 
02901 ///   GetWMPosition(fWMX, fWMY);
02902 ///   if ((fWMX != -1) || (fWMY != -1)) {
02903 ///      out <<"   "<<GetName()<<"->SetWMPosition("<<fWMX<<","<<fWMY<<");"<<endl;
02904 ///   }   // does not work - fixed via Move() below...
02905 
02906    GetWMSize(fWMWidth, fWMHeight);
02907    if (fWMWidth != UInt_t(-1) || fWMHeight != UInt_t(-1)) {
02908       out <<"   "<<GetName()<<"->SetWMSize("<<fWMWidth<<","<<fWMHeight<<");"<<endl;
02909    }
02910 
02911    GetWMSizeHints(fWMMinWidth, fWMMinHeight, fWMMaxWidth, fWMMaxHeight, fWMWidthInc, fWMHeightInc);
02912    if (fWMMinWidth != UInt_t(-1) || fWMMinHeight != UInt_t(-1) ||
02913       fWMMaxWidth != UInt_t(-1) || fWMMaxHeight != UInt_t(-1) ||
02914       fWMWidthInc != UInt_t(-1) || fWMHeightInc != UInt_t(-1)) {
02915       out <<"   "<<GetName()<<"->SetWMSizeHints("<<fWMMinWidth<<","<<fWMMinHeight
02916           <<","<<fWMMaxWidth<<","<<fWMMaxHeight
02917           <<","<<fWMWidthInc<<","<<fWMHeightInc <<");"<<endl;
02918    }
02919 
02920    out << "   " <<GetName()<< "->MapSubwindows();" << endl;
02921 
02922    TIter nexth(gListOfHiddenFrames);
02923    TGFrame *fhidden;
02924    while ((fhidden = (TGFrame*)nexth())) {
02925       out << "   " <<fhidden->GetName()<< "->UnmapWindow();" << endl;
02926    }
02927 
02928    out << endl;
02929    gListOfHiddenFrames->Clear();
02930 
02931    Bool_t usexy = kFALSE;
02932    TGLayoutManager * lm = GetLayoutManager();
02933    if (lm->InheritsFrom("TGXYLayout"))
02934       usexy = kTRUE;
02935 
02936    if (!usexy)
02937       out << "   " <<GetName()<< "->Resize("<< GetName()<< "->GetDefaultSize());" << endl;
02938    else
02939       out << "   " <<GetName()<< "->Resize("<< GetWidth()<<","<<GetHeight()<<");"<<endl;
02940 
02941    out << "   " <<GetName()<< "->MapWindow();" <<endl;
02942 
02943    GetWMPosition(fWMX, fWMY);
02944    if ((fWMX != -1) || (fWMY != -1)) {
02945       out <<"   "<<GetName()<<"->Move("<<fWMX<<","<<fWMY<<");"<<endl;
02946    }
02947 
02948    // needed in case the frame was resized
02949    // otherwhice the frame became bigger showing all hidden widgets (layout algorithm)
02950    if (!usexy) out << "   " <<GetName()<< "->Resize("<< GetWidth()<<","<<GetHeight()<<");"<<endl;
02951    out << "}  " << endl;
02952 
02953    // writing slots
02954    TList *sl = (TList *)gROOT->GetListOfSpecials()->FindObject("ListOfSlots");
02955    if (sl) {
02956       TIter nextsl(sl);
02957       TObjString *slobj;
02958       Int_t pnumber = 1;
02959 
02960       while ((slobj = (TObjString*) nextsl())) {
02961          TString s = slobj->GetString();
02962          TString p = "";
02963          Int_t lb, rb, eq;
02964          lb = s.First('(');
02965          rb = s.First(')');
02966          eq = s.First('=');
02967          out << endl;
02968 
02969          if (rb - lb > 1 && eq == -1) {
02970             p = TString::Format(" par%d", pnumber);
02971             s.Insert(rb, p);
02972             pnumber++;
02973             out << "void " << s << endl;
02974             out << "{" << endl;
02975             s = slobj->GetString();
02976             s[rb] = ' ';
02977             out << "   cout << " << quote << "Slot " << s  << quote
02978                 << " <<" << p << " << " << quote << ")" << quote
02979                 << " << endl; " << endl;
02980             } else {
02981                if (eq != -1) {
02982                   s.Remove(eq, rb-eq);
02983                   out << "void " << s << endl;
02984                   out << "{" << endl;
02985                   out << "   cout << " << quote << "Slot " << s
02986                       << quote << " << endl; " << endl;
02987                } else {
02988                   out << "void " << slobj->GetString() << endl;
02989                   out << "{" << endl;
02990                   out << "   cout << " << quote << "Slot " << slobj->GetString()
02991                       << quote << " << endl; " << endl;
02992                }
02993             }
02994          out << "}" << endl;
02995       }
02996       gROOT->GetListOfSpecials()->Remove(sl);
02997       sl->Delete();
02998       delete sl;
02999    }
03000    out.close();
03001 
03002    if (!opt.Contains("quiet"))
03003       printf(" C++ macro file %s has been generated\n", gSystem->BaseName(ff.Data()));
03004 
03005    // reset bit TClass::kClassSaved for all classes
03006    nextc1.Reset();
03007    while((c1=(TClass*)nextc1())) {
03008       c1->ResetBit(TClass::kClassSaved);
03009    }
03010 }
03011 
03012 //______________________________________________________________________________
03013 void TGMainFrame::SavePrimitive(ostream &out, Option_t *option /*= ""*/)
03014 {
03015    // Save a main frame widget as a C++ statement(s) on output stream out.
03016 
03017    if (fParent != gClient->GetDefaultRoot()) { // frame is embedded
03018       fOptions &= ~kMainFrame;
03019       TGCompositeFrame::SavePrimitive(out, option);
03020       fOptions |= kMainFrame;
03021       return;
03022    }
03023 
03024    char quote = '"';
03025 
03026    out << endl << "   // main frame" << endl;
03027    out << "   TGMainFrame *";
03028    out << GetName() << " = new TGMainFrame(gClient->GetRoot(),10,10,"   // layout alg.
03029        << GetOptionString() << ");" <<endl;
03030    if (option && strstr(option, "keep_names"))
03031       out << "   " << GetName() << "->SetName(\"" << GetName() << "\");" << endl;
03032 
03033    // setting layout manager if it differs from the main frame type
03034    TGLayoutManager * lm = GetLayoutManager();
03035    if ((GetOptions() & kHorizontalFrame) &&
03036        (lm->InheritsFrom(TGHorizontalLayout::Class()))) {
03037       ;
03038    } else if ((GetOptions() & kVerticalFrame) &&
03039               (lm->InheritsFrom(TGVerticalLayout::Class()))) {
03040       ;
03041    } else {
03042       out << "   " << GetName() <<"->SetLayoutManager(";
03043       lm->SavePrimitive(out, option);
03044       out << ");"<< endl;
03045    }
03046 
03047    SavePrimitiveSubframes(out, option);
03048 
03049    if (strlen(fWindowName)) {
03050       out << "   " << GetName() << "->SetWindowName(" << quote << GetWindowName()
03051           << quote << ");" << endl;
03052    }
03053    if (strlen(fIconName)) {
03054       out <<"   "<<GetName()<< "->SetIconName("<<quote<<GetIconName()<<quote<<");"<<endl;
03055    }
03056    if (strlen(fIconPixmap)) {
03057       out << "   " << GetName() << "->SetIconPixmap(" << quote << GetIconPixmap()
03058           << quote << ");" << endl;
03059    }
03060 }
03061 
03062 //______________________________________________________________________________
03063 void TGHorizontalFrame::SavePrimitive(ostream &out, Option_t *option /*= ""*/)
03064 {
03065    // Save a horizontal frame widget as a C++ statement(s) on output stream out.
03066 
03067    if (fBackground != GetDefaultFrameBackground()) SaveUserColor(out, option);
03068 
03069    out << endl << "   // horizontal frame" << endl;
03070    out << "   TGHorizontalFrame *";
03071    out << GetName() << " = new TGHorizontalFrame(" << fParent->GetName()
03072        << "," << GetWidth() << "," << GetHeight();
03073 
03074    if (fBackground == GetDefaultFrameBackground()) {
03075       if (!GetOptions()) {
03076          out << ");" << endl;
03077       } else {
03078          out << "," << GetOptionString() <<");" << endl;
03079       }
03080    } else {
03081       out << "," << GetOptionString() << ",ucolor);" << endl;
03082    }
03083    if (option && strstr(option, "keep_names"))
03084       out << "   " << GetName() << "->SetName(\"" << GetName() << "\");" << endl;
03085 
03086    // setting layout manager if it differs from the main frame type
03087    TGLayoutManager * lm = GetLayoutManager();
03088    if ((GetOptions() & kHorizontalFrame) &&
03089        (lm->InheritsFrom(TGHorizontalLayout::Class()))) {
03090       ;
03091    } else if ((GetOptions() & kVerticalFrame) &&
03092               (lm->InheritsFrom(TGVerticalLayout::Class()))) {
03093       ;
03094    } else {
03095       out << "   " << GetName() <<"->SetLayoutManager(";
03096       lm->SavePrimitive(out, option);
03097       out << ");"<< endl;
03098    }
03099 
03100    SavePrimitiveSubframes(out, option);
03101 }
03102 
03103 //______________________________________________________________________________
03104 void TGVerticalFrame::SavePrimitive(ostream &out, Option_t *option /*= ""*/)
03105 {
03106     // Save a vertical frame widget as a C++ statement(s) on output stream out.
03107 
03108    if (fBackground != GetDefaultFrameBackground()) SaveUserColor(out, option);
03109 
03110    out << endl << "   // vertical frame" << endl;
03111    out << "   TGVerticalFrame *";
03112    out << GetName() << " = new TGVerticalFrame(" << fParent->GetName()
03113        << "," << GetWidth() << "," << GetHeight();
03114 
03115    if (fBackground == GetDefaultFrameBackground()) {
03116       if (!GetOptions()) {
03117          out <<");" << endl;
03118       } else {
03119          out << "," << GetOptionString() <<");" << endl;
03120       }
03121    } else {
03122       out << "," << GetOptionString() << ",ucolor);" << endl;
03123    }
03124    if (option && strstr(option, "keep_names"))
03125       out << "   " << GetName() << "->SetName(\"" << GetName() << "\");" << endl;
03126 
03127    // setting layout manager if it differs from the main frame type
03128    TGLayoutManager * lm = GetLayoutManager();
03129    if ((GetOptions() & kHorizontalFrame) &&
03130        (lm->InheritsFrom(TGHorizontalLayout::Class()))) {
03131       ;
03132    } else if ((GetOptions() & kVerticalFrame) &&
03133               (lm->InheritsFrom(TGVerticalLayout::Class()))) {
03134       ;
03135    } else {
03136       out << "   " << GetName() <<"->SetLayoutManager(";
03137       lm->SavePrimitive(out, option);
03138       out << ");"<< endl;
03139    }
03140 
03141    SavePrimitiveSubframes(out, option);
03142 }
03143 
03144 //______________________________________________________________________________
03145 void TGFrame::SavePrimitive(ostream &out, Option_t *option /*= ""*/)
03146 {
03147    // Save a frame widget as a C++ statement(s) on output stream out.
03148 
03149    if (fBackground != GetDefaultFrameBackground()) SaveUserColor(out, option);
03150 
03151    out << "   TGFrame *";
03152    out << GetName() << " = new TGFrame("<< fParent->GetName()
03153        << "," << GetWidth() << "," << GetHeight();
03154 
03155    if (fBackground == GetDefaultFrameBackground()) {
03156       if (!GetOptions()) {
03157          out <<");" << endl;
03158       } else {
03159          out << "," << GetOptionString() <<");" << endl;
03160       }
03161    } else {
03162       out << "," << GetOptionString() << ",ucolor);" << endl;
03163    }
03164    if (option && strstr(option, "keep_names"))
03165       out << "   " << GetName() << "->SetName(\"" << GetName() << "\");" << endl;
03166 }
03167 
03168 //______________________________________________________________________________
03169 void TGGroupFrame::SavePrimitive(ostream &out, Option_t *option /*= ""*/)
03170 {
03171    // Save a group frame widget as a C++ statement(s) on output stream out.
03172 
03173    char quote = '"';
03174 
03175    // font + GC
03176    option = GetName()+5;         // unique digit id of the name
03177    TString parGC, parFont;
03178    parFont.Form("%s::GetDefaultFontStruct()",IsA()->GetName());
03179    parGC.Form("%s::GetDefaultGC()()",IsA()->GetName());
03180 
03181    if ((GetDefaultFontStruct() != fFontStruct) || (GetDefaultGC()() != fNormGC)) {
03182       TGFont *ufont = gClient->GetResourcePool()->GetFontPool()->FindFont(fFontStruct);
03183       if (ufont) {
03184          ufont->SavePrimitive(out, option);
03185          parFont.Form("ufont->GetFontStruct()");
03186       }
03187 
03188       TGGC *userGC = gClient->GetResourcePool()->GetGCPool()->FindGC(fNormGC);
03189       if (userGC) {
03190          userGC->SavePrimitive(out, option);
03191          parGC.Form("uGC->GetGC()");
03192       }
03193    }
03194 
03195    if (fBackground != GetDefaultFrameBackground()) SaveUserColor(out, option);
03196 
03197    out << endl << "   // " << quote << GetTitle() << quote << " group frame" << endl;
03198    out << "   TGGroupFrame *";
03199    out << GetName() <<" = new TGGroupFrame("<<fParent->GetName()
03200        << "," << quote << GetTitle() << quote;
03201 
03202    if (fBackground == GetDefaultFrameBackground()) {
03203       if (fFontStruct == GetDefaultFontStruct()) {
03204          if (fNormGC == GetDefaultGC()()) {
03205             if (GetOptions() & kVerticalFrame) {
03206                out <<");" << endl;
03207             } else {
03208                out << "," << GetOptionString() <<");" << endl;
03209             }
03210          } else {
03211             out << "," << GetOptionString() << "," << parGC.Data() <<");" << endl;
03212          }
03213       } else {
03214          out << "," << GetOptionString() << "," << parGC.Data() << "," << parFont.Data() << ");" << endl;
03215       }
03216    } else {
03217       out << "," << GetOptionString() << "," << parGC.Data() << "," << parFont.Data() << ",ucolor);"  << endl;
03218    }
03219    if (option && strstr(option, "keep_names"))
03220       out << "   " << GetName() << "->SetName(\"" << GetName() << "\");" << endl;
03221 
03222    if (GetTitlePos() != -1)
03223       out << "   " << GetName() <<"->SetTitlePos(";
03224    if (GetTitlePos() == 0)
03225       out << "TGGroupFrame::kCenter);" << endl;
03226    if (GetTitlePos() == 1)
03227       out << "TGGroupFrame::kRight);" << endl;
03228 
03229    SavePrimitiveSubframes(out, option);
03230 
03231    // setting layout manager
03232    out << "   " << GetName() <<"->SetLayoutManager(";
03233    GetLayoutManager()->SavePrimitive(out, option);
03234    out << ");"<< endl;
03235 
03236    out << "   " << GetName() <<"->Resize(" << GetWidth() << ","
03237        << GetHeight() << ");" << endl;
03238 }
03239 
03240 
03241 //______________________________________________________________________________
03242 void TGTransientFrame::SaveSource(const char *filename, Option_t *option)
03243 {
03244    // Save the GUI tranzient frame widget in a C++ macro file.
03245 
03246    // iterate over all active classes to exclude the base ones
03247 
03248    TString opt = option;
03249    TBits *bc = new TBits();
03250    TClass *c1, *c2, *c3;
03251    UInt_t k = 0;      // will mark k-bit of TBits if the class is a base class
03252 
03253    TIter nextc1(gROOT->GetListOfClasses());
03254    while((c1 = (TClass *)nextc1())) {
03255 
03256       //   resets bit TClass::kClassSaved for all classes
03257       c1->ResetBit(TClass::kClassSaved);
03258 
03259       TIter nextc2(gROOT->GetListOfClasses());
03260       while ((c2 = (TClass *)nextc2())) {
03261          if (c1==c2) continue;
03262          else {
03263             c3 = c2->GetBaseClass(c1);
03264             if (c3 != 0) {
03265                bc->SetBitNumber(k, kTRUE);
03266                break;
03267             }
03268          }
03269       }
03270       k++;
03271    }
03272 
03273    TList *ilist = new TList();   // will contain include file names without '.h'
03274    ilist->SetName("ListOfIncludes");
03275    gROOT->GetListOfSpecials()->Add(ilist);
03276    k=0;
03277 
03278    // completes list of include file names
03279    TIter nextdo(gROOT->GetListOfClasses());
03280    while ((c2 = (TClass *)nextdo())) {
03281       // to have only used GUI header files
03282       if (bc->TestBitNumber(k) == 0 && c2->InheritsFrom(TGObject::Class()) == 1) {
03283          // for any used ROOT header files activate the line below, comment the line above
03284          //if (bc->TestBitNumber(k) == 0) {
03285          const char *iname;
03286          iname = c2->GetDeclFileName();
03287          if (strlen(iname) != 0 && strstr(iname,".h")) {
03288             const char *lastsl = strrchr(iname,'/');
03289             if (lastsl) iname = lastsl + 1;
03290             char *tname = new char[strlen(iname)+1];
03291             Int_t i=0;
03292             while (*iname != '.') {
03293                tname[i] = *iname;
03294                i++; iname++;
03295             }
03296             tname[i] = 0;    //tname = include file name without '.h'
03297 
03298             TObjString *iel = (TObjString *)ilist->FindObject(tname);
03299             if (!iel) {
03300                ilist->Add(new TObjString(tname));
03301             }
03302             delete [] tname;
03303          }
03304          k++;  continue;
03305       }
03306       k++;
03307    }
03308 
03309    char quote = '"';
03310    ofstream out;
03311 
03312    TString ff = filename && strlen(filename) ? filename : "Rootdlog.C";
03313 
03314    // Computes the main method name.
03315    const char *fname = gSystem->BaseName(ff.Data());
03316    Int_t lenfname = strlen(fname);
03317    char *sname = new char[lenfname+1];
03318 
03319    Int_t i = 0;
03320    while ((*fname != '.') && (i < lenfname)) {
03321       sname[i] = *fname;
03322       i++; fname++;
03323    }
03324    if (i == lenfname)
03325       ff += ".C";
03326    sname[i] = 0;
03327 
03328    out.open(ff.Data(), ios::out);
03329    if (!out.good()) {
03330       Error("SaveSource", "cannot open file: %s", ff.Data());
03331       delete [] sname;
03332       return;
03333    }
03334 
03335    // writes include files in C++ macro
03336    TObjString *inc;
03337    ilist = (TList *)gROOT->GetListOfSpecials()->FindObject("ListOfIncludes");
03338 
03339    if (!ilist) {
03340       delete [] sname;
03341       return;
03342    }
03343 
03344    // write macro header, date/time stamp as string, and the used Root version
03345    TDatime t;
03346    out <<"// Dialog macro generated from application: "<< gApplication->Argv(0) << endl;
03347    out <<"// By ROOT version "<< gROOT->GetVersion() <<" on "<<t.AsSQLString()<< endl;
03348    out << endl;
03349 
03350    out << "#if !defined( __CINT__) || defined (__MAKECINT__)" << endl << endl;
03351 
03352    TIter nexti(ilist);
03353    while((inc = (TObjString *)nexti())) {
03354       out <<"#ifndef ROOT_"<< inc->GetString() << endl;
03355       out <<"#include "<< quote << inc->GetString() <<".h"<< quote << endl;
03356       out <<"#endif" << endl;
03357       if (strstr(inc->GetString(),"TRootEmbeddedCanvas")) {
03358          out <<"#ifndef ROOT_TCanvas"<< endl;
03359          out <<"#include "<< quote <<"TCanvas.h"<< quote << endl;
03360          out <<"#endif" << endl;
03361       }
03362    }
03363    out << endl << "#include " << quote << "Riostream.h" << quote << endl;
03364    out << endl << "#endif" << endl;
03365    // deletes created ListOfIncludes
03366    gROOT->GetListOfSpecials()->Remove(ilist);
03367    ilist->Delete();
03368    delete ilist;
03369    delete bc;
03370 
03371    // writes the macro entry point equal to the fname
03372    out << endl;
03373    out << "void " << sname << "()" << endl;
03374    delete [] sname;
03375 
03376    //  Save GUI widgets as a C++ macro in a file
03377    out <<"{"<< endl;
03378 
03379    gListOfHiddenFrames->Clear();
03380 
03381    // saivng slots
03382    TList *lSlots = new TList;
03383    lSlots->SetName("ListOfSlots");
03384    gROOT->GetListOfSpecials()->Add(lSlots);
03385 
03386    TGTransientFrame::SavePrimitive(out, option);
03387 
03388    GetClassHints((const char *&)fClassName, (const char *&)fResourceName);
03389    if (strlen(fClassName) || strlen(fResourceName)) {
03390       out<<"   "<<GetName()<< "->SetClassHints("<<quote<<fClassName<<quote
03391                                             <<"," <<quote<<fResourceName<<quote
03392                                             <<");"<<endl;
03393    }
03394 
03395    GetMWMHints(fMWMValue, fMWMFuncs, fMWMInput);
03396    if (fMWMValue || fMWMFuncs || fMWMInput) {
03397       out << "   " << GetName() << "->SetMWMHints(";
03398       out << GetMWMvalueString() << "," << endl;
03399       out << "                        ";
03400       out << GetMWMfuncString() << "," << endl;
03401       out << "                        ";
03402       out << GetMWMinpString() << ");"<< endl;
03403    }
03404 
03405    GetWMPosition(fWMX, fWMY);
03406    if ((fWMX != -1) || (fWMY != -1)) {
03407       out <<"   "<<GetName()<<"->SetWMPosition("<<fWMX<<","<<fWMY<<");"<<endl;
03408    }
03409 
03410    GetWMSize(fWMWidth, fWMHeight);
03411    if (fWMWidth != UInt_t(-1) || fWMHeight != UInt_t(-1)) {
03412       out <<"   "<<GetName()<<"->SetWMSize("<<fWMWidth<<","<<fWMHeight<<");"<<endl;
03413    }
03414 
03415    GetWMSizeHints(fWMMinWidth,fWMMinHeight,fWMMaxWidth,fWMMaxHeight,fWMWidthInc,fWMHeightInc);
03416    if (fWMMinWidth != UInt_t(-1) || fWMMinHeight != UInt_t(-1) ||
03417        fWMMaxWidth != UInt_t(-1) || fWMMaxHeight != UInt_t(-1) ||
03418        fWMWidthInc != UInt_t(-1) || fWMHeightInc != UInt_t(-1)) {
03419 
03420       out <<"   "<<GetName()<<"->SetWMSizeHints("<<fWMMinWidth<<","<<fWMMinHeight
03421           <<","<<fWMMaxWidth<<","<<fWMMaxHeight <<","<<fWMWidthInc<<","<<fWMHeightInc
03422           <<");"<<endl;
03423    }
03424 
03425    GetWMPosition(fWMX, fWMY);
03426    if ((fWMX != -1) || (fWMY != -1)) {
03427       out <<"   "<<GetName()<<"->Move("<<fWMX<<","<<fWMY<<");"<<endl;
03428    }
03429 
03430    out << "   " <<GetName()<< "->MapSubwindows();" << endl;
03431 
03432    TIter nexth(gListOfHiddenFrames);
03433    TGFrame *fhidden;
03434    while ((fhidden = (TGFrame*)nexth())) {
03435       out << "   " <<fhidden->GetName()<< "->UnmapWindow();" << endl;
03436    }
03437    out << endl;
03438    gListOfHiddenFrames->Clear();
03439 
03440    Bool_t usexy = kFALSE;
03441    TGLayoutManager * lm = GetLayoutManager();
03442    if (lm->InheritsFrom("TGXYLayout"))
03443       usexy = kTRUE;
03444 
03445    if (!usexy)
03446       out << "   " <<GetName()<< "->Resize("<< GetName()<< "->GetDefaultSize());" << endl;
03447    else
03448       out << "   " <<GetName()<< "->Resize("<< GetWidth()<<","<<GetHeight()<<");"<<endl;
03449 
03450    out << "   " <<GetName()<< "->MapWindow();" <<endl;
03451    if (!usexy) out << "   " <<GetName()<< "->Resize();" << endl;
03452    out << "}  " << endl;
03453 
03454    // writing slots
03455    TList *sl = (TList *)gROOT->GetListOfSpecials()->FindObject("ListOfSlots");
03456    if (sl) {
03457       TIter nextsl(sl);
03458       TObjString *slobj;
03459       Int_t pnumber = 1;
03460 
03461       while ((slobj = (TObjString*) nextsl())) {
03462          TString s = slobj->GetString();
03463          TString p = "";
03464          Int_t lb, rb, eq;
03465          lb = s.First('(');
03466          rb = s.First(')');
03467          eq = s.First('=');
03468          out << endl;
03469 
03470          if (rb - lb > 1 && eq == -1) {
03471             p = TString::Format(" par%d", pnumber);
03472             s.Insert(rb, p);
03473             pnumber++;
03474             out << "void " << s << endl;
03475             out << "{" << endl;
03476             s = slobj->GetString();
03477             s[rb] = ' ';
03478             out << "   cout << " << quote << "Slot " << s  << quote
03479                 << " <<" << p << " << " << quote << ")" << quote
03480                 << " << endl; " << endl;
03481             } else {
03482                if (eq != -1) {
03483                   s.Remove(eq, rb-eq);
03484                   out << "void " << s << endl;
03485                   out << "{" << endl;
03486                   out << "   cout << " << quote << "Slot " << s
03487                       << quote << " << endl; " << endl;
03488                } else {
03489                   out << "void " << slobj->GetString() << endl;
03490                   out << "{" << endl;
03491                   out << "   cout << " << quote << "Slot " << slobj->GetString()
03492                       << quote << " << endl; " << endl;
03493                }
03494             }
03495          out << "}" << endl;
03496       }
03497       gROOT->GetListOfSpecials()->Remove(sl);
03498       sl->Delete();
03499       delete sl;
03500    }
03501 
03502    out.close();
03503 
03504    if (!opt.Contains("quiet"))
03505       printf(" C++ macro file %s has been generated\n", gSystem->BaseName(ff.Data()));
03506 
03507    // reset bit TClass::kClassSaved for all classes
03508    nextc1.Reset();
03509    while((c1=(TClass*)nextc1())) {
03510       c1->ResetBit(TClass::kClassSaved);
03511    }
03512 }
03513 
03514 //______________________________________________________________________________
03515 void TGTransientFrame::SavePrimitive(ostream &out, Option_t *option /*= ""*/)
03516 {
03517    // Save a transient frame widget as a C++ statement(s) on output stream out.
03518 
03519    char quote = '"';
03520 
03521    out << endl << "   // transient frame" << endl;
03522    out << "   TGTransientFrame *";
03523    out << GetName()<<" = new TGTransientFrame(gClient->GetRoot(),0"
03524        << "," << GetWidth() << "," << GetHeight() << "," << GetOptionString() <<");" << endl;
03525 
03526    if (option && strstr(option, "keep_names"))
03527       out << "   " << GetName() << "->SetName(\"" << GetName() << "\");" << endl;
03528 
03529    // setting layout manager if it differs from transient frame type
03530    TGLayoutManager * lm = GetLayoutManager();
03531    if ((GetOptions() & kHorizontalFrame) &&
03532        (lm->InheritsFrom(TGHorizontalLayout::Class()))) {
03533       ;
03534    } else if ((GetOptions() & kVerticalFrame) &&
03535               (lm->InheritsFrom(TGVerticalLayout::Class()))) {
03536       ;
03537    } else {
03538       out << "   " << GetName() <<"->SetLayoutManager(";
03539       lm->SavePrimitive(out, option);
03540       out << ");"<< endl;
03541    }
03542 
03543    SavePrimitiveSubframes(out, option);
03544 
03545    if (strlen(fWindowName)) {
03546       out << "   " << GetName() << "->SetWindowName(" << quote << GetWindowName()
03547           << quote << ");" << endl;
03548    }
03549    if (strlen(fIconName)) {
03550       out <<"   "<<GetName()<< "->SetIconName("<<quote<<GetIconName()<<quote<<");"<<endl;
03551    }
03552    if (strlen(fIconPixmap)) {
03553       out << "   " << GetName() << "->SetIconPixmap(" << quote << GetIconPixmap()
03554           << quote << ");" << endl;
03555    }
03556 }

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