TRootGuiBuilder.cxx

Go to the documentation of this file.
00001 // @(#)root/guibuilder:$Id: TRootGuiBuilder.cxx 35582 2010-09-22 13:38:27Z bellenot $
00002 // Author: Valeriy Onuchin   12/09/04
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2004, 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 #include "TRootGuiBuilder.h"
00014 #include "TGuiBldDragManager.h"
00015 #include "TGuiBldEditor.h"
00016 
00017 #include "TGShutter.h"
00018 #include "TGSplitter.h"
00019 #include "TGLayout.h"
00020 #include "TGResourcePool.h"
00021 #include "TGButton.h"
00022 #include "TROOT.h"
00023 #include "TGDockableFrame.h"
00024 #include "TGMdi.h"
00025 #include "TGStatusBar.h"
00026 #include "TG3DLine.h"
00027 #include "TGLabel.h"
00028 #include "TColor.h"
00029 #include "TGToolBar.h"
00030 #include "TGToolTip.h"
00031 #include "KeySymbols.h"
00032 #include "TGFileDialog.h"
00033 #include "TGMsgBox.h"
00034 #include "TSystem.h"
00035 #include "TApplication.h"
00036 #include "TRootHelpDialog.h"
00037 #include "TGListTree.h"
00038 #include "TImage.h"
00039 #include "TTimer.h"
00040 #include "TGTextEdit.h"
00041 #include "TGTab.h"
00042 #include "TGListBox.h"
00043 #include "TGComboBox.h"
00044 #include "TGProgressBar.h"
00045 
00046 
00047 //////////////////////////////////////////////////////////////////////////
00048 //
00049 // TRootGuiBuilder
00050 //
00051 //
00052 //  ************************************************
00053 //                ROOT GUI Builder principles
00054 //  ************************************************
00055 //
00056 //  With the GUI builder, we try to make the next step from WYSIWYG
00057 //  to embedded editing concept - WYSIWYE ("what you see is what you edit").
00058 //  The ROOT GUI Builder allows modifying real GUI objects.
00059 //  For example, one can edit the existing GUI application created by
00060 //  $ROOTSYS/tutorials/gui/guitest.C.
00061 //  GUI components can be added to a design area from a widget palette,
00062 //  or can be borrowed from another application.
00063 //  One can drag and and drop TCanvas's menu bar into the application.
00064 //  GUI objects can be resized and dragged, copied and pasted.
00065 //  ROOT GUI Builder allows changing the layout, snap to grid, change object's
00066 //  layout order via the GUI Builder toolbar, or by options in the right-click
00067 //  context menus.
00068 //  A final design can be immediatly tested and used, or saved as a C++ macro.
00069 //  For example, it's possible to rearrange buttons in control bar,
00070 //  add separators etc. and continue to use a new fancy control bar in the
00071 //  application.
00072 //
00073 //  ************************************************
00074 //
00075 //  The following is a short description of the GUI Builder actions and key shortcuts:
00076 //
00077 //   o Press Ctrl-Double-Click to start/stop edit mode
00078 //   o Press Double-Click to activate quick edit action (defined in root.mimes)
00079 //
00080 //                 Selection, grabbing, dropping
00081 //       ************************************************
00082 //    It is possible to select, drag any frame and drop it to any frame
00083 //
00084 //   o Click left mouse button or Ctrl-Click to select an object to edit.
00085 //   o Press right mouse button to activate context menu
00086 //   o Mutiple selection (grabbing):
00087 //      - draw lasso and press Return key
00088 //      - press Shift key and draw lasso
00089 //   o Dropping:
00090 //      - select frame and press Ctrl-Return key
00091 //   o Changing layout order:
00092 //      - select frame and use arrow keys to change layout order
00093 //   o Alignment:
00094 //      - draw lasso and press arrow keys (or Shift-Arrow key) to align frames
00095 //
00096 //                    Key shortcuts
00097 //       ************************************************
00098 //   o Return    - grab selected frames
00099 //   o Ctrl-Return - drop frames
00100 //   o Del       - delete selected frame
00101 //   o Shift-Del - crop action
00102 //   o Ctrl-X    - cut action
00103 //   o Ctrl-C    - copy action
00104 //   o Ctrl-V    - paste frame into the last clicked position
00105 //   o Ctrl-L    - compact
00106 //   o Ctrl-B    - enable/disable layout
00107 //   o Ctrl-H    - switch horizontal-vertical layout
00108 //   o Ctrl-G    - switch on/off grid
00109 //   o Ctrl-S    - save action
00110 //   o Ctrl-O    - open and execute a ROOT macro file.  GUI components created
00111 //                 after macro execution will be emebedded to currently edited
00112 //                 design area.
00113 //   o Ctrl-N    - create new main frame
00114 //
00115 //Begin_Html
00116 /*
00117 <img src="gif/RootGuiBuilder.gif">
00118 */
00119 //End_Html
00120 
00121 
00122 const char gHelpBuilder[] = "\
00123                Start/Stop Edit Mode\n\
00124      ************************************************\n\
00125  o Select File menu / Edit\n\
00126  o Select Start Edit button on the toolbar\n\
00127  o Ctrl-Double-Click on the project frame\n\
00128  o Double-Click to activate quick edit action (defined in root.mimes)\n\
00129 \n\
00130                Select, Grab, Drop\n\
00131      ************************************************\n\
00132   It is possible to select & drag any frame and drop it to another frame\n\
00133 \n\
00134  o Press left mouse button Click or Ctrl-Click to select an object.\n\
00135  o Press right mouse button to activate context menu\n\
00136  o Mutiple selection can be done in two ways (grabbing):\n\
00137       - draw lasso and press Return key\n\
00138       - press Shift key and draw lasso\n\
00139  o Dropping:\n\
00140       - select frame and press Ctrl-Return key\n\
00141  o Changing layout order of widgets:\n\
00142       - set broken layout mode via toolbar button or check button\n\
00143         \'Layout subframes\' in tab \'Layout\'\n\
00144       - select a widget and use arrow keys to change the layout order\n\
00145  o Alignment:\n\
00146       - remove the selection (if any) by using the space bar\n\
00147       - draw lasso and use the four toolbar buttons for widget alignment\n\
00148       - arrow keys align the frames too, if you prefer the keyboard\n\
00149 \n\
00150                     Key shortcuts\n\
00151      ************************************************\n\
00152  o Return    - grab selected frames\n\
00153  o Ctrl-Return - drop frames\n\
00154  o Del       - delete selected frame\n\
00155  o Shift-Del - crop\n\
00156  o Ctrl-X    - cut\n\
00157  o Ctrl-C    - copy\n\
00158  o Ctrl-V    - paste frame into the last clicked position\n\
00159  o Ctrl-L    - compact frame\n\
00160  o Ctrl-B    - enable/disable layout\n\
00161  o Ctrl-H    - switch Horizontal-Vertical layout\n\
00162  o Ctrl-G    - switch ON/OFF grid\n\
00163  o Ctrl-S    - save\n\
00164  o Ctrl-O    - open and execute ROOT macro file\n\
00165  o Ctrl-N    - create new main frame\n\
00166  o Ctrl-Z    - undo last action (not implemented)\n\
00167  o Shift-Ctrl-Z - redo (not implemented)\n\
00168 \n\
00169                     More informations\n\
00170      ************************************************\n\
00171 \n\
00172 For more information, please see the GuiBuilder Howto page at:\n\
00173 \n\
00174    http://root.cern.ch/root/HowtoGuiBuilder.html\n\
00175 \n\
00176 ";
00177 
00178 const char gHelpAboutBuilder[] = "\
00179                   ROOT Gui Builder\n\
00180 \n\
00181 ************************************************************\n\
00182 * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers.  *\n\
00183 * All rights reserved.                                     *\n\
00184 *                                                          *\n\
00185 * For the licensing terms see $ROOTSYS/LICENSE.            *\n\
00186 * For the list of contributors see $ROOTSYS/README/CREDITS.*\n\
00187 ************************************************************\n\
00188 ";
00189 
00190 //----- Toolbar stuff...
00191 
00192 static ToolBarData_t gToolBarData[] = {
00193    { "bld_edit.png",   "Start Edit (Ctrl-Dbl-Click)",   kFALSE, kEditableAct, 0 },
00194    { "",                 "",               kFALSE, -1, 0 },
00195    { "bld_new.png",   "New (Ctrl-N)",   kFALSE, kNewAct, 0 },
00196    { "bld_open.png",   "Open (Ctrl-O)",   kFALSE, kOpenAct, 0 },
00197    { "bld_save.png",   "Save As (Ctrl-S)",   kFALSE, kSaveAct, 0 },
00198    { "",                 "",               kFALSE, -1, 0 },
00199 //   { "bld_pointer.xpm",   "Selector (Ctrl-Click)",   kTRUE, kSelectAct, 0 },
00200 //   { "bld_grab.xpm",   "Grab Selected Frames (Return)",   kTRUE, kGrabAct, 0 },
00201    { "",                 "",               kFALSE, -1, 0 },
00202    { "bld_compact.png",   "Compact selected frame (Ctrl-L)",        kFALSE,  kCompactAct, 0 },
00203    { "bld_break.png",   "Disable/Enable layout (Ctrl-B)",        kFALSE,  kBreakLayoutAct, 0 },
00204    { "bld_hbox.png",  "Layout selected frame horizontally (Ctrl-H)",    kFALSE,  kLayoutHAct, 0 },
00205    { "bld_vbox.png",   "Layout selected frame vertically (Ctrl-H)",    kFALSE,  kLayoutVAct, 0 },
00206    { "bld_grid.png",   "On/Off grid (Ctrl+G)",     kFALSE,  kGridAct, 0 },
00207    { "",                 "",               kFALSE, -1, 0 },
00208    { "bld_AlignTop.png",   "Align selected frames to the top line of lasso (Up  Arrow)",        kFALSE,  kUpAct, 0 },
00209    { "bld_AlignBtm.png",   "Align selected frames to the down line of lasso (Down Arrow)",        kFALSE,  kDownAct, 0 },
00210    { "bld_AlignLeft.png",   "Align selected frames to the left line of lasso (Left  Arrow)",        kFALSE,  kLeftAct, 0 },
00211    { "bld_AlignRight.png",   "Align selected frames to the right line of lasso (Right  Arrow)",        kFALSE,  kRightAct, 0 },
00212    { "",                 "",               kFALSE, -1, 0 },
00213    { "bld_cut.png",   "Cut (Ctrl-X)",        kFALSE,  kCutAct, 0 },
00214    { "bld_copy.png",   "Copy (Ctrl-C)",        kFALSE,  kCopyAct, 0 },
00215    { "bld_paste.png",   "Paste frame into the last clicked position (Ctrl-V)",        kFALSE,  kPasteAct, 0 },
00216 //   { "bld_paste_into.png",   "Paste with replacing of selected frame (Ctrl-R)",        kFALSE,  kReplaceAct, 0 },
00217    { "bld_delete.png",   "Delete (Del/Backspace)",        kFALSE,  kDeleteAct, 0 },
00218    { "bld_crop.png",   "Crop (Shift-Del)",        kFALSE,  kCropAct, 0 },
00219 //   { "",                 "",               kFALSE, -1, 0 },
00220 //   { "bld_undo.png",   "Undo (Ctrl-Z)",        kFALSE,  kUndoAct, 0 },
00221 //   { "bld_redo.png",   "Redo (Shift-Ctrl-Z)",        kFALSE,  kRedoAct, 0 },
00222    { 0,                  0,                kFALSE, 0, 0 }
00223 };
00224 
00225 
00226 ClassImp(TRootGuiBuilder)
00227 
00228 
00229 TGGC *TRootGuiBuilder::fgBgnd = 0;
00230 TGGC *TRootGuiBuilder::fgBgndPopup = 0;
00231 TGGC *TRootGuiBuilder::fgBgndPopupHlght = 0;
00232 
00233 
00234 ////////////////////////////////////////////////////////////////////////////////
00235 //
00236 // Here are few experimental GUI classes which give a nice&fancy appearence
00237 // to GuiBuilder.
00238 //
00239 ////////////////////////////////////////////////////////////////////////////////
00240 
00241 ////////////////////////////////////////////////////////////////////////////////
00242 class TGuiBldMenuTitle : public TGMenuTitle {
00243 
00244 private:
00245    Pixel_t fBgndColor;
00246 
00247 protected:
00248    void DoRedraw();
00249 
00250 public:
00251    virtual ~TGuiBldMenuTitle() {}
00252    TGuiBldMenuTitle(const TGWindow *p, TGHotString *s, TGPopupMenu *menu) :
00253       TGMenuTitle(p, s, menu) {
00254          fEditDisabled = kEditDisable;
00255          fBgndColor = TRootGuiBuilder::GetBgnd();
00256          SetBackgroundColor(fBgndColor);
00257          AddInput(kEnterWindowMask | kLeaveWindowMask);
00258    }
00259 
00260    Bool_t HandleCrossing(Event_t *event);
00261 };
00262 
00263 //______________________________________________________________________________
00264 Bool_t TGuiBldMenuTitle::HandleCrossing(Event_t *event)
00265 {
00266    // Handle  crossing events.
00267 
00268    if (event->fType == kEnterNotify) {
00269       fBgndColor = TRootGuiBuilder::GetPopupHlght();
00270    } else {
00271       fBgndColor = TRootGuiBuilder::GetBgnd();
00272    }
00273    DoRedraw();
00274    return kTRUE;
00275 }
00276 
00277 //______________________________________________________________________________
00278 void TGuiBldMenuTitle::DoRedraw()
00279 {
00280    // Redraw builder menu title.
00281 
00282    TGFrame::DoRedraw();
00283 
00284    int x, y, max_ascent, max_descent;
00285    x = y = 4;
00286 
00287    gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
00288 
00289    if (fState) {
00290       gVirtualX->SetForeground(fNormGC, GetDefaultSelectedBackground());
00291       gVirtualX->FillRectangle(fId,fNormGC, 0, 0, fWidth, fHeight);
00292       gVirtualX->SetForeground(fNormGC, GetForeground());
00293       fLabel->Draw(fId, fSelGC, x, y + max_ascent);
00294    } else {
00295       gVirtualX->SetForeground(fNormGC, fBgndColor);
00296       gVirtualX->FillRectangle(fId,fNormGC, 0, 0, fWidth, fHeight);
00297       gVirtualX->SetForeground(fNormGC, GetForeground());
00298       fLabel->Draw(fId, fNormGC, x, y + max_ascent);
00299    }
00300    if (fBgndColor == TRootGuiBuilder::GetPopupHlght()) {
00301       gVirtualX->DrawRectangle(fId, TGFrame::GetBlackGC()(),
00302                                0, 0, GetWidth()-1, GetHeight()-1);
00303    }
00304 }
00305 
00306 
00307 ////////////////////////////////////////////////////////////////////////////////
00308 class TGuiBldPopupMenu : public TGPopupMenu {
00309 
00310 public:
00311    virtual ~TGuiBldPopupMenu() { }
00312    TGuiBldPopupMenu() :
00313       TGPopupMenu(gClient->GetDefaultRoot()) {
00314       fEditDisabled = kEditDisable;
00315       SetBackgroundColor(TRootGuiBuilder::GetPopupBgnd());
00316       fEntrySep = 8;
00317    }
00318    void DrawEntry(TGMenuEntry *entry);
00319 };
00320 
00321 //______________________________________________________________________________
00322 void TGuiBldPopupMenu::DrawEntry(TGMenuEntry *entry)
00323 {
00324    // Draw popup menu entry.
00325 
00326    FontStruct_t  font;
00327    GCValues_t    gcval;
00328 
00329    if (entry->GetStatus() & kMenuHideMask)
00330       return;
00331 
00332    if (entry->GetStatus() & kMenuDefaultMask) {
00333       font = fHifontStruct;
00334       gcval.fMask = kGCFont;
00335       gcval.fFont = gVirtualX->GetFontHandle(font);
00336       gVirtualX->ChangeGC(fNormGC, &gcval);
00337       gVirtualX->ChangeGC(fSelGC, &gcval);
00338    } else {
00339       font = fFontStruct;
00340    }
00341 
00342    UInt_t tw = 0;
00343    UInt_t sep = fEntrySep;
00344    Int_t max_ascent, max_descent;
00345    gVirtualX->GetFontProperties(font, max_ascent, max_descent);
00346    if (entry->GetShortcut())
00347       tw = 7 + gVirtualX->TextWidth(fFontStruct, entry->GetShortcutText(),
00348                                     entry->GetShortcut()->Length());
00349 
00350    Int_t tx = entry->GetEx() + fXl;
00351    Int_t ty = entry->GetEy() + max_ascent + 2;
00352    UInt_t h = max_ascent + max_descent + sep;
00353    Int_t picposy = 0;
00354    if (entry->GetPic() != 0) {
00355       picposy = entry->GetEy() + h / 2;
00356       picposy -= entry->GetPic()->GetHeight() / 2;
00357    }
00358 
00359    switch (entry->GetType()) {
00360       case kMenuPopup:
00361       case kMenuLabel:
00362       case kMenuEntry:
00363          if ((entry->GetStatus() & kMenuActiveMask) && 
00364              entry->GetType() != kMenuLabel) {
00365             if (entry->GetStatus() & kMenuEnableMask) {
00366                gVirtualX->FillRectangle(fId, 
00367                               TRootGuiBuilder::GetPopupHlghtGC()->GetGC(),
00368                               entry->GetEx()+1, entry->GetEy(),
00369                               fMenuWidth-6, h - 1);
00370                gVirtualX->DrawRectangle(fId,  TGFrame::GetBlackGC()(),
00371                                         entry->GetEx()+ 1, entry->GetEy()-1,
00372                                         fMenuWidth - entry->GetEx()- 6, h - 1);
00373             }
00374 
00375             if (entry->GetType() == kMenuPopup) {
00376                DrawTrianglePattern(fSelGC, fMenuWidth-10, entry->GetEy() + 3,
00377                                    fMenuWidth-6, entry->GetEy() + 11);
00378             }
00379 
00380             if (entry->GetStatus() & kMenuCheckedMask) {
00381                DrawCheckMark(fSelGC, 6, entry->GetEy()+sep, 14,
00382                              entry->GetEy()+11);
00383             }
00384 
00385             if (entry->GetStatus() & kMenuRadioMask) {
00386                DrawRCheckMark(fSelGC, 6, entry->GetEy()+sep, 14,
00387                               entry->GetEy()+11);
00388             }
00389 
00390             if (entry->GetPic() != 0) {
00391                entry->GetPic()->Draw(fId, fSelGC, 8, picposy);
00392             }
00393 
00394             entry->GetLabel()->Draw(fId,
00395                            (entry->GetStatus() & kMenuEnableMask) ? fSelGC : 
00396                             GetShadowGC()(), tx, ty);
00397             if (entry->GetShortcut())
00398                entry->GetShortcut()->Draw(fId,
00399                            (entry->GetStatus() & kMenuEnableMask) ? fSelGC : 
00400                            GetShadowGC()(), fMenuWidth - tw, ty);
00401          } else {
00402             if ( entry->GetType() != kMenuLabel) {
00403                gVirtualX->FillRectangle(fId, 
00404                            TRootGuiBuilder::GetBgndGC()->GetGC(),
00405                            entry->GetEx()+1, entry->GetEy()-1, tx-4, h);
00406 
00407                gVirtualX->FillRectangle(fId, 
00408                            TRootGuiBuilder::GetPopupBgndGC()->GetGC(),
00409                            tx-1, entry->GetEy()-1, fMenuWidth-tx-1, h);
00410             } else { // we need some special background for labels
00411                gVirtualX->FillRectangle(fId, TGFrame::GetBckgndGC()(),
00412                                        entry->GetEx()+1, entry->GetEy()-1,
00413                                        fMenuWidth - entry->GetEx()- 3, h);
00414             }
00415 
00416             if (entry->GetType() == kMenuPopup) {
00417                DrawTrianglePattern(fNormGC, fMenuWidth-10, entry->GetEy() + 3,
00418                                    fMenuWidth-6, entry->GetEy() + 11);
00419             }
00420 
00421             if (entry->GetStatus() & kMenuCheckedMask) {
00422                DrawCheckMark(fNormGC, 6, entry->GetEy()+sep, 14,
00423                              entry->GetEy()+11);
00424             }
00425 
00426             if (entry->GetStatus() & kMenuRadioMask) {
00427                DrawRCheckMark(fNormGC, 6, entry->GetEy()+sep, 14,
00428                               entry->GetEy()+11);
00429             }
00430 
00431             if (entry->GetPic() != 0) {
00432                entry->GetPic()->Draw(fId, fNormGC, 8, picposy);
00433             }
00434 
00435             if (entry->GetStatus() & kMenuEnableMask) {
00436                entry->GetLabel()->Draw(fId, fNormGC, tx, ty);
00437                if (entry->GetShortcut())
00438                   entry->GetShortcut()->Draw(fId, fNormGC, fMenuWidth - tw, ty);
00439             } else {
00440                entry->GetLabel()->Draw(fId, GetHilightGC()(), tx+1, ty+1);
00441                entry->GetLabel()->Draw(fId, GetShadowGC()(), tx, ty);
00442                if (entry->GetShortcut()) {
00443                   entry->GetShortcut()->Draw(fId, GetHilightGC()(),
00444                                              fMenuWidth - tw+1, ty+1);
00445                   entry->GetShortcut()->Draw(fId, GetShadowGC()(),
00446                                              fMenuWidth - tw, ty);
00447                }
00448             }
00449          }
00450          break;
00451 
00452       case kMenuSeparator:
00453          gVirtualX->FillRectangle(fId, TRootGuiBuilder::GetBgndGC()->GetGC(),
00454                                      entry->GetEx()+1, entry->GetEy()-1,
00455                                      tx-4, 4);
00456          gVirtualX->DrawLine(fId, TGFrame::GetBlackGC()(), tx+1,
00457                              entry->GetEy()+1, fMenuWidth-sep,
00458                              entry->GetEy()+1);
00459          break;
00460    }
00461 
00462    // restore font
00463    if (entry->GetStatus() & kMenuDefaultMask) {
00464       gcval.fFont = gVirtualX->GetFontHandle(fFontStruct);
00465       gVirtualX->ChangeGC(fNormGC, &gcval);
00466       gVirtualX->ChangeGC(fSelGC, &gcval);
00467    }
00468 }
00469 
00470 ////////////////////////////////////////////////////////////////////////////////
00471 class TGuiBldToolButton : public TGPictureButton {
00472 
00473 private:
00474    Pixel_t fBgndColor;
00475 
00476 protected:
00477    void  DoRedraw();
00478 
00479 public:
00480    virtual ~TGuiBldToolButton() { }
00481    TGuiBldToolButton(const TGWindow *p, const TGPicture *pic, Int_t id = -1) :
00482          TGPictureButton(p, pic, id) {
00483       fBgndColor = TRootGuiBuilder::GetBgnd();
00484       ChangeOptions(GetOptions() & ~kRaisedFrame);
00485    }
00486 
00487    Bool_t IsDown() const { return (fOptions & kSunkenFrame); }
00488    void SetState(EButtonState state, Bool_t emit = kTRUE);
00489    Bool_t HandleCrossing(Event_t *event);
00490    void SetBackgroundColor(Pixel_t bgnd) { fBgndColor = bgnd; TGFrame::SetBackgroundColor(bgnd); }
00491 };
00492 
00493 //______________________________________________________________________________
00494 void TGuiBldToolButton::DoRedraw()
00495 {
00496    // Redraw tool button.
00497 
00498    int x = (fWidth - fTWidth) >> 1;
00499    int y = (fHeight - fTHeight) >> 1;
00500    UInt_t w = GetWidth() - 1;
00501    UInt_t h = GetHeight()- 1;
00502 
00503    TGFrame::SetBackgroundColor(fBgndColor);
00504 
00505    TGFrame::DoRedraw();
00506    if (fState == kButtonDown || fState == kButtonEngaged) {
00507       ++x; ++y;
00508       w--; h--;
00509    }
00510 
00511    const TGPicture *pic = fPic;
00512    if (fState == kButtonDisabled) {
00513       if (!fPicD) CreateDisabledPicture();
00514       pic = fPicD ? fPicD : fPic;
00515    }
00516    if (fBgndColor == TRootGuiBuilder::GetPopupHlght()) {
00517       x--; y--;
00518       gVirtualX->DrawRectangle(fId, TGFrame::GetBlackGC()(), 0, 0, w, h);
00519    }
00520    pic->Draw(fId, fNormGC, x, y);
00521 }
00522 
00523 //______________________________________________________________________________
00524 Bool_t TGuiBldToolButton::HandleCrossing(Event_t *event)
00525 {
00526    // Handle crossing events.
00527 
00528    if (fTip) {
00529       if (event->fType == kEnterNotify) {
00530          fTip->Reset();
00531       } else {
00532          fTip->Hide();
00533       }
00534    }
00535 
00536    if ((event->fType == kEnterNotify) && (fState != kButtonDisabled)) {
00537       fBgndColor = TRootGuiBuilder::GetPopupHlght();
00538    } else {
00539       fBgndColor = TRootGuiBuilder::GetBgnd();
00540    }
00541    if (event->fType == kLeaveNotify) {
00542       fBgndColor = TRootGuiBuilder::GetBgnd();
00543       if (fState != kButtonDisabled && fState != kButtonEngaged)
00544          SetState(kButtonUp, kFALSE);
00545    }
00546    DoRedraw();
00547 
00548    return kTRUE;
00549 }
00550 
00551 //______________________________________________________________________________
00552 void TGuiBldToolButton::SetState(EButtonState state, Bool_t emit)
00553 {
00554    // Set state of tool bar button and emit a signal according
00555    // to passed arguments.
00556 
00557    Bool_t was = !IsDown();
00558 
00559    if (state != fState) {
00560       switch (state) {
00561          case kButtonEngaged:
00562          case kButtonDown:
00563             fOptions &= ~kRaisedFrame;
00564             fOptions |= kSunkenFrame;
00565             break;
00566          case kButtonDisabled:
00567          case kButtonUp:
00568             fOptions &= ~kRaisedFrame;
00569             fOptions &= ~kSunkenFrame;
00570             break;
00571       }
00572       fState = state;
00573       DoRedraw();
00574       if (emit) EmitSignals(was);
00575    }
00576 }
00577 
00578 ////////////////////////////////////////////////////////////////////////////////
00579 //______________________________________________________________________________
00580 TRootGuiBuilder::TRootGuiBuilder(const TGWindow *p) : TGuiBuilder(),
00581    TGMainFrame(p ? p : gClient->GetDefaultRoot(), 1, 1)
00582 {
00583    // Create GUI builder application.
00584 
00585    SetCleanup(kDeepCleanup);
00586    gGuiBuilder  = this;
00587    fManager = 0;
00588    fEditor = 0;
00589    fActionButton = 0;
00590    fClosing = 0;
00591 
00592    if (gDragManager) {
00593       fManager = (TGuiBldDragManager *)gDragManager;
00594    } else {
00595       gDragManager = fManager = new TGuiBldDragManager();
00596    }
00597    fManager->SetBuilder(this);
00598 
00599    fMenuBar = new TGMdiMenuBar(this, 10, 10);
00600    AddFrame(fMenuBar, new TGLayoutHints(kLHintsTop | kLHintsExpandX));
00601    InitMenu();
00602 
00603    AddFrame(new TGHorizontal3DLine(this), new TGLayoutHints(kLHintsTop |
00604             kLHintsExpandX, 0,0,2,2));
00605 
00606    fToolDock = new TGDockableFrame(this);
00607    AddFrame(fToolDock, new TGLayoutHints(kLHintsExpandX, 0, 0, 1, 0));
00608    fToolDock->SetWindowName("GuiBuilder ToolBar");
00609 
00610    fToolBar = new TGToolBar(fToolDock);
00611    fToolDock->AddFrame(fToolBar, new TGLayoutHints(kLHintsTop |
00612                        kLHintsExpandX));
00613 
00614    int spacing = 8;
00615 
00616    for (int i = 0; gToolBarData[i].fPixmap; i++) {
00617       if (strlen(gToolBarData[i].fPixmap) == 0) {
00618          spacing = 8;
00619          continue;
00620       }
00621 
00622       const TGPicture *pic = fClient->GetPicture(gToolBarData[i].fPixmap);
00623       TGuiBldToolButton *pb = new TGuiBldToolButton(fToolBar, pic,
00624                                                     gToolBarData[i].fId);
00625 
00626       pb->SetToolTipText(gToolBarData[i].fTipText);
00627 
00628       TGToolTip *tip = pb->GetToolTip();
00629       tip->SetDelay(200);
00630 
00631       tip->Connect("Reset()", "TRootGuiBuilder", this, "UpdateStatusBar(=0)");
00632       tip->Connect("Hide()", "TRootGuiBuilder", this, "EraseStatusBar()");
00633 
00634       fToolBar->AddButton(this, pb, spacing);
00635       spacing = 0;
00636 
00637       if (gToolBarData[i].fId == kEditableAct) {
00638          fStartButton = pb;
00639          continue;
00640       }
00641 
00642       if ((gToolBarData[i].fId == kUndoAct) ||
00643           (gToolBarData[i].fId == kRedoAct)) {
00644          pb->SetState(kButtonDisabled);
00645       }
00646    }
00647 
00648    fToolBar->Connect("Clicked(Int_t)", "TGuiBldDragManager", fManager,
00649                      "HandleAction(Int_t)");
00650 
00651    AddFrame(new TGHorizontal3DLine(this), new TGLayoutHints(kLHintsTop |
00652             kLHintsExpandX, 0,0,2,5));
00653 
00654    TGCompositeFrame *cf = new TGHorizontalFrame(this, 1, 1);
00655    AddFrame(cf, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
00656 
00657    //fShutterDock = new TGDockableFrame(cf);
00658    //cf->AddFrame(fShutterDock, new TGLayoutHints(kLHintsNormal ));
00659    //fShutterDock->SetWindowName("Widget Factory");
00660    //fShutterDock->EnableUndock(kTRUE);
00661    //fShutterDock->EnableHide(kTRUE);
00662    //fShutterDock->DockContainer();
00663 
00664    fShutter = new TGShutter(cf, kSunkenFrame);
00665    cf->AddFrame(fShutter, new TGLayoutHints(kLHintsNormal | kLHintsExpandY));
00666    fShutter->ChangeOptions(fShutter->GetOptions() | kFixedWidth);
00667 
00668    TGVSplitter *splitter = new TGVSplitter(cf);
00669    splitter->SetFrame(fShutter, kTRUE);
00670    cf->AddFrame(splitter, new TGLayoutHints(kLHintsLeft | kLHintsExpandY));
00671 
00672    fMain = new TGMdiMainFrame(cf, fMenuBar, 1, 1);
00673    fMain->Connect("FrameClosed(Int_t)", "TRootGuiBuilder", this,
00674                   "HandleWindowClosed(Int_t)");
00675 
00676    TQObject::Connect("TGMdiFrame", "CloseWindow()", "TRootGuiBuilder", this,
00677                      "MaybeCloseWindow()");
00678 
00679    cf->AddFrame(fMain, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
00680 
00681    fMain->GetContainer()->SetEditDisabled(kEditDisable);
00682 
00683    const TGPicture *pbg = fClient->GetPicture("bld_bg.png");
00684    if (pbg) {
00685       fMain->GetContainer()->SetBackgroundPixmap(pbg->GetPicture());
00686    }
00687 
00688    if (fManager) {
00689       fEditor = new TGuiBldEditor(cf);
00690       cf->AddFrame(fEditor, new TGLayoutHints(kLHintsNormal | kLHintsExpandY));
00691       fManager->SetPropertyEditor(fEditor);
00692       fEditor->SetEmbedded();
00693    }
00694 
00695    AddSection("Projects");
00696    AddSection("Buttons");
00697    AddSection("Containers");
00698    AddSection("Bars");
00699    AddSection("Input");
00700    AddSection("Complex Input");
00701    AddSection("Display");
00702    AddSection("Dialogs");
00703 
00704    // create an empty section
00705    AddSection("User's Macros");
00706    TGShutterItem *item = fShutter->GetItem("User's Macros");
00707    TGCompositeFrame *cont = (TGCompositeFrame *)item->GetContainer();
00708    cont->SetBackgroundColor(TColor::Number2Pixel(18));
00709 
00710    TGuiBldAction *act = new TGuiBldAction("TGMainFrame", "Empty Frame",
00711                                           kGuiBldProj);
00712    act->fAct = "empty";
00713    act->fPic = "bld_mainframe.xpm";
00714    AddAction(act, "Projects");
00715 
00716    act = new TGuiBldAction("TGMainFrame", "Horizontal Frame", kGuiBldProj);
00717    act->fAct = "horizontal";
00718    act->fPic = "bld_mainframe.xpm";
00719    AddAction(act, "Projects");
00720 
00721    act = new TGuiBldAction("TGMainFrame", "Vertical Frame", kGuiBldProj);
00722    act->fAct = "vertical";
00723    act->fPic = "bld_mainframe.xpm";
00724    AddAction(act, "Projects");
00725 
00726    // Standard
00727    act = new TGuiBldAction("TGTextButton", "Text Button", kGuiBldCtor);
00728    act->fAct = "new TGTextButton()";
00729    act->fPic = "bld_textbutton.xpm";
00730    AddAction(act, "Buttons");
00731 
00732    act = new TGuiBldAction("TGCheckButton", "Check Button", kGuiBldCtor);
00733    act->fAct = "new TGCheckButton()";
00734    act->fPic = "bld_checkbutton.xpm";
00735    AddAction(act, "Buttons");
00736 
00737    act = new TGuiBldAction("TGRadioButton", "Radio Button", kGuiBldCtor);
00738    act->fAct = "new TGRadioButton()";
00739    act->fPic = "bld_radiobutton.xpm";
00740    AddAction(act, "Buttons");
00741 
00742    act = new TGuiBldAction("TGPictureButton", "Picture Button", kGuiBldCtor);
00743    act->fAct = "new TGPictureButton()";
00744    act->fPic = "bld_image.xpm";
00745    AddAction(act, "Buttons");
00746 
00747    act = new TGuiBldAction("TGTextEntry", "Text Entry", kGuiBldCtor);
00748    act->fAct = "new TGTextEntry()";
00749    act->fPic = "bld_entry.xpm";
00750    AddAction(act, "Input");
00751 
00752    act = new TGuiBldAction("TGTextEdit", "Text Edit", kGuiBldCtor);
00753    act->fAct = "TRootGuiBuilder::BuildTextEdit()";
00754    act->fPic = "bld_text.xpm";
00755    AddAction(act, "Input");
00756 
00757    act = new TGuiBldAction("TGNumberEntry", "Number Entry", kGuiBldCtor);
00758    act->fAct = "new TGNumberEntry()";
00759    act->fPic = "bld_numberentry.xpm";
00760    AddAction(act, "Input");
00761 
00762    act = new TGuiBldAction("TGComboBox", "Combo Box", kGuiBldCtor);
00763    act->fAct = "TRootGuiBuilder::BuildComboBox()";
00764    act->fPic = "bld_combobox.xpm";
00765    AddAction(act, "Input");
00766 
00767    act = new TGuiBldAction("TGListBox", "List Box", kGuiBldCtor);
00768    act->fAct = "TRootGuiBuilder::BuildListBox()";
00769    act->fPic = "bld_listbox.xpm";
00770    AddAction(act, "Input");
00771 
00772    act = new TGuiBldAction("TGHSlider", "Horizontal Slider", kGuiBldCtor);
00773    act->fAct = "new TGHSlider()";
00774    act->fPic = "bld_hslider.xpm";
00775    AddAction(act, "Input");
00776 
00777    act = new TGuiBldAction("TGVSlider", "Vertical Slider", kGuiBldCtor);
00778    act->fAct = "new TGVSlider()";
00779    act->fPic = "bld_vslider.xpm";
00780    AddAction(act, "Input");
00781 
00782    act = new TGuiBldAction("TGHScrollBar", "HScrollbar", kGuiBldCtor);
00783    act->fAct = "TRootGuiBuilder::BuildHScrollBar()";
00784    act->fPic = "bld_hscrollbar.xpm";
00785    AddAction(act, "Input");
00786 
00787    act = new TGuiBldAction("TGVScrollBar", "VScrollbar", kGuiBldCtor);
00788    act->fAct = "TRootGuiBuilder::BuildVScrollBar()";
00789    act->fPic = "bld_vscrollbar.xpm";
00790    AddAction(act, "Input");
00791 
00792    act = new TGuiBldAction("TGListTree", "List Tree", kGuiBldCtor);
00793    act->fAct = "TRootGuiBuilder::BuildListTree()";
00794    act->fPic = "bld_listtree.xpm";
00795    AddAction(act, "Complex Input");
00796 
00797    act = new TGuiBldAction("TGLabel", "Text Label", kGuiBldCtor);
00798    act->fAct = "new TGLabel()";
00799    act->fPic = "bld_label.xpm";
00800    AddAction(act, "Display");
00801 
00802    act = new TGuiBldAction("TGIcon", "Icon", kGuiBldCtor);
00803    act->fAct = "new TGIcon()";
00804    act->fPic = "bld_image.xpm";
00805    AddAction(act, "Display");
00806 
00807    act = new TGuiBldAction("TGHorizontal3DLine", "Horizontal Line",
00808                            kGuiBldCtor);
00809    act->fAct = "TRootGuiBuilder::BuildH3DLine()";
00810    act->fPic = "bld_hseparator.xpm";
00811    AddAction(act, "Display");
00812 
00813    act = new TGuiBldAction("TGVertical3DLine", "Vertical Line", kGuiBldCtor);
00814    act->fAct = "TRootGuiBuilder::BuildV3DLine()";
00815    act->fPic = "bld_vseparator.xpm";
00816    AddAction(act, "Display");
00817 
00818    act = new TGuiBldAction("TGStatusBar", "Status Bar", kGuiBldCtor);
00819    act->fAct = "new TGStatusBar()";
00820    act->fPic = "bld_statusbar.xpm";
00821    act->fHints = new TGLayoutHints(kLHintsBottom | kLHintsExpandX);
00822    AddAction(act, "Bars");
00823 
00824    act = new TGuiBldAction("TGHProgressBar", "HProgress Bar", kGuiBldCtor);
00825    act->fAct = "TRootGuiBuilder::BuildHProgressBar()";
00826    act->fPic = "bld_hprogressbar.xpm";
00827    AddAction(act, "Display");
00828 
00829    act = new TGuiBldAction("TGVProgressBar", "VProgress Bar", kGuiBldCtor);
00830    act->fAct = "TRootGuiBuilder::BuildVProgressBar()";
00831    act->fPic = "bld_vprogressbar.xpm";
00832    AddAction(act, "Display");
00833 
00834    act = new TGuiBldAction("TRootEmbeddedCanvas", "Embed Canvas", kGuiBldCtor);
00835    act->fAct = "new TRootEmbeddedCanvas()";
00836    act->fPic = "bld_embedcanvas.xpm";
00837    AddAction(act, "Display");
00838 
00839    // Containers
00840    act = new TGuiBldAction("TGHorizontalFrame", "Horizontal Frame",
00841                            kGuiBldCtor);
00842    act->fAct = "new TGHorizontalFrame(0,200,100)";
00843    act->fPic = "bld_hbox.xpm";
00844    AddAction(act, "Containers");
00845 
00846    act = new TGuiBldAction("TGVerticalFrame", "Vertical Frame", kGuiBldCtor);
00847    act->fAct = "new TGVerticalFrame(0,100,200)";
00848    act->fPic = "bld_vbox.xpm";
00849    AddAction(act, "Containers");
00850 
00851    act = new TGuiBldAction("TGGroupFrame", "Group Frame", kGuiBldCtor);
00852    act->fAct = "new TGGroupFrame()";
00853    act->fPic = "bld_groupframe.xpm";
00854    AddAction(act, "Containers");
00855 
00856    act = new TGuiBldAction("TGTab", "Tabbed Frame", kGuiBldCtor);
00857    act->fAct = "TRootGuiBuilder::BuildTab()";
00858    act->fPic = "bld_tab.xpm";
00859    AddAction(act, "Containers");
00860 
00861    act = new TGuiBldAction("TGShutter", "Shutter", kGuiBldCtor);
00862    act->fAct = "TRootGuiBuilder::BuildShutter()";
00863    act->fPic = "bld_shutter.png";
00864    AddAction(act, "Containers");
00865 
00866 
00867    act = new TGuiBldAction("TGCanvas", "Scrolled Canvas", kGuiBldCtor);
00868    act->fAct = "TRootGuiBuilder::BuildCanvas()";
00869    act->fPic = "bld_canvas.xpm";
00870    AddAction(act, "Containers");
00871 /*
00872    act = new TGuiBldAction("TGVSplitter", "Horizontal Panes", kGuiBldFunc);
00873    act->fAct = "TRootGuiBuilder::VSplitter()";
00874    act->fPic = "bld_hpaned.xpm";
00875    AddAction(act, "Containers");
00876 
00877    act = new TGuiBldAction("TGHSplitter", "Vertical Panes", kGuiBldFunc);
00878    act->fAct = "TRootGuiBuilder::HSplitter()";
00879    act->fPic = "bld_vpaned.xpm";
00880    AddAction(act, "Containers");
00881 */
00882    act = new TGuiBldAction("TGColorSelect", "Color Selector", kGuiBldFunc);
00883    act->fAct = "new TGColorSelect()";
00884    act->fPic = "bld_colorselect.xpm";
00885    AddAction(act, "Dialogs");
00886 
00887    fShutter->Resize(140, fShutter->GetHeight());
00888 
00889    fStatusBar = new TGStatusBar(this, 40, 10);
00890    AddFrame(fStatusBar, new TGLayoutHints(kLHintsBottom | kLHintsExpandX,
00891             0, 0, 3, 0));
00892 
00893    PropagateBgndColor(this, GetBgnd());
00894    SetEditDisabled(kEditDisable);   // disable editting to all subframes
00895 
00896    MapSubwindows();
00897 
00898    Int_t qq;
00899    UInt_t ww;
00900    UInt_t hh;
00901    gVirtualX->GetWindowSize(gVirtualX->GetDefaultRootWindow(), qq, qq, ww, hh);
00902    MoveResize(100, 100, ww - 200, hh - 200);
00903    SetWMPosition(100, 100);
00904 
00905    SetWindowName("ROOT GuiBuilder");
00906    SetIconName("ROOT GuiBuilder");
00907    fIconPic = SetIconPixmap("bld_rgb.xpm");
00908    SetClassHints("GuiBuilder", "GuiBuilder");
00909 
00910    fSelected = 0;
00911    Update();
00912 
00913    fMenuFile->Connect("Activated(Int_t)", "TRootGuiBuilder", this,
00914                       "HandleMenu(Int_t)");
00915    fMenuWindow->Connect("Activated(Int_t)", "TRootGuiBuilder", this,
00916                         "HandleMenu(Int_t)");
00917    fMenuHelp->Connect("Activated(Int_t)", "TRootGuiBuilder", this,
00918                       "HandleMenu(Int_t)");
00919 
00920    // doesn't work properly on Windows...
00921    if (gVirtualX->InheritsFrom("TGX11"))
00922       BindKeys();
00923    UpdateStatusBar("Ready");
00924    MapRaised();
00925 
00926    fEditor->SwitchLayout();
00927 }
00928 
00929 //______________________________________________________________________________
00930 TRootGuiBuilder::~TRootGuiBuilder()
00931 {
00932    // Destructor.
00933 
00934    if (fIconPic) gClient->FreePicture(fIconPic);
00935    delete fMenuFile;
00936    delete fMenuWindow;
00937    delete fMenuHelp;
00938    gGuiBuilder = 0;
00939 }
00940 
00941 //______________________________________________________________________________
00942 void TRootGuiBuilder::CloseWindow()
00943 {
00944    // Close GUI builder via window manager "Close" button.
00945 
00946    TGWindow *root = (TGWindow*)fClient->GetRoot();
00947    if (root) root->SetEditable(kFALSE);
00948 
00949    fEditor->Reset();
00950 
00951    if (fMain->GetNumberOfFrames() == 0) {
00952       fMenuFile->DisableEntry(kGUIBLD_FILE_CLOSE);
00953       fMenuFile->DisableEntry(kGUIBLD_FILE_STOP);
00954       fMenuFile->DisableEntry(kGUIBLD_FILE_START);
00955    } else {
00956       fMenuFile->DisableEntry(kGUIBLD_FILE_STOP);
00957       fMenuFile->EnableEntry(kGUIBLD_FILE_START);
00958       fMenuFile->EnableEntry(kGUIBLD_FILE_CLOSE);
00959    }
00960 
00961    TGButton *btn = fToolBar->GetButton(kGridAct);
00962    if (btn) {
00963       btn->SetState(!fClient->IsEditable() ? kButtonDisabled : kButtonUp);
00964    }
00965    fClosing = 1;
00966    fMain->CloseAll();
00967    if (fClosing == -1) {
00968       fClosing = 0;
00969       return;
00970    }
00971    SwitchToolbarButton();
00972    Hide();
00973 }
00974 
00975 //______________________________________________________________________________
00976 TGButton *TRootGuiBuilder::FindActionButton(const char *name, const char *sect)
00977 {
00978    // Find action by name
00979 
00980    if (!name || !sect) return 0;
00981 
00982    TGShutterItem *item = fShutter->GetItem(sect);
00983    if (!item) return 0;
00984 
00985    TGCompositeFrame *cont = (TGCompositeFrame *)item->GetContainer();
00986    TGHorizontalFrame *hf;
00987    TGFrameElement *fe;
00988 
00989    TIter next(cont->GetList());
00990    TGLabel *lb;
00991    TGButton *btn;
00992 
00993    while ((fe = (TGFrameElement*)next())) {
00994       hf = (TGHorizontalFrame*)fe->fFrame;
00995       btn = (TGButton*)((TGFrameElement*)hf->GetList()->First())->fFrame;
00996       lb = (TGLabel*)((TGFrameElement*)hf->GetList()->Last())->fFrame;
00997       if (*(lb->GetText()) == name) {
00998          return (TGButton*)btn;
00999       }
01000    }
01001    return 0;
01002 }
01003 
01004 //______________________________________________________________________________
01005 void TRootGuiBuilder::AddAction(TGuiBldAction *act, const char *sect)
01006 {
01007    // Add new action to widget palette.
01008 
01009    if (!act || !sect) return;
01010 
01011    TGShutterItem *item = fShutter->GetItem(sect);
01012    TGButton *btn = 0;
01013 
01014    if (!item) return;
01015    TGCompositeFrame *cont = (TGCompositeFrame *)item->GetContainer();
01016    cont->SetBackgroundColor(TColor::Number2Pixel(18));
01017 
01018    const TGPicture *pic = 0;
01019    if (!act->fPicture) {
01020       act->fPicture = fClient->GetPicture(act->fPic);
01021    }
01022    pic = act->fPicture;
01023 
01024    TGHorizontalFrame *hf = new TGHorizontalFrame(cont);
01025 
01026    if (pic) {
01027       btn = new TGPictureButton(hf, pic);
01028    } else {
01029       btn = new TGTextButton(hf, act->GetName());
01030    }
01031 
01032    btn->SetToolTipText(act->GetTitle(), 200);
01033    btn->SetUserData((void*)act);
01034    btn->Connect("Clicked()", "TRootGuiBuilder", this, "HandleButtons()");
01035 
01036    hf->AddFrame(btn, new TGLayoutHints(kLHintsTop | kLHintsCenterY,1,1,1,1));
01037 
01038    TGLabel *lb = new TGLabel(hf, act->fType != kGuiBldMacro ? act->GetTitle() :
01039                              act->GetName());
01040    lb->SetBackgroundColor(cont->GetBackground());
01041    hf->AddFrame(lb, new TGLayoutHints(kLHintsTop | kLHintsCenterY,1,1,1,1));
01042    hf->SetBackgroundColor(cont->GetBackground());
01043 
01044    // disable edit
01045    cont->SetEditDisabled(kEditDisable);
01046    hf->SetEditDisabled(kEditDisable);
01047 
01048    cont->AddFrame(hf, new TGLayoutHints(kLHintsTop, 5, 5, 5, 0));
01049    cont->MapSubwindows();
01050    cont->Resize();  // invoke Layout()
01051 }
01052 
01053 //______________________________________________________________________________
01054 void TRootGuiBuilder::AddSection(const char *sect)
01055 {
01056    // Add new shutter item.
01057 
01058    static int id = 10000;
01059    TGShutterItem *item = new TGShutterItem(fShutter, new TGHotString(sect),
01060                                            id++);
01061    fShutter->AddItem(item);
01062    item->Connect("Selected()", "TRootGuiBuilder", this, "HandleMenu(=3)");
01063 }
01064 
01065 //______________________________________________________________________________
01066 void TRootGuiBuilder::HandleButtons()
01067 {
01068    // Handle buttons in the GUI builder's widget palette.
01069 
01070    TGFrame *parent;
01071 
01072    if (fActionButton) {
01073       parent = (TGFrame*)fActionButton->GetParent();
01074       parent->ChangeOptions(parent->GetOptions() & ~kSunkenFrame);
01075       fClient->NeedRedraw(parent, kTRUE);
01076    }
01077 
01078    if (!fClient->IsEditable()) {
01079       HandleMenu(kGUIBLD_FILE_START);
01080    }
01081 
01082    fActionButton = (TGButton *)gTQSender;
01083    TGuiBldAction *act  = (TGuiBldAction *)fActionButton->GetUserData();
01084    parent = (TGFrame*)fActionButton->GetParent();
01085 
01086    parent->ChangeOptions(parent->GetOptions() | kSunkenFrame);
01087    fClient->NeedRedraw(parent, kTRUE);
01088 
01089    if (act) {
01090       fAction = act;
01091       fManager->UngrabFrame();
01092       if (fAction->fType != kGuiBldCtor) ExecuteAction();
01093    }
01094 }
01095 
01096 //______________________________________________________________________________
01097 TGFrame *TRootGuiBuilder::ExecuteAction()
01098 {
01099    // Execute an action.
01100 
01101    if (!fAction || fAction->fAct.IsNull()) return 0;
01102 
01103    TGFrame *ret = 0;
01104 
01105    if (!fClient->IsEditable() && (fAction->fType != kGuiBldMacro)) {
01106       TGMdiFrame *current = fMain->GetCurrent();
01107       if (current) current->SetEditable(kTRUE);
01108    }
01109 
01110    TString s = "";
01111 
01112    switch (fAction->fType) {
01113       case kGuiBldProj:
01114          s = fAction->fAct.Data();
01115          NewProject(s);
01116          fAction = 0;
01117          break;
01118       case kGuiBldMacro:
01119          {
01120          TGWindow *root = (TGWindow*)fClient->GetRoot();
01121          if (root) root->SetEditable(kFALSE);
01122          gROOT->Macro(fAction->fAct.Data());
01123          if (root) root->SetEditable(kTRUE);
01124          fAction = 0;
01125          break;
01126          }
01127       default:
01128          ret = (TGFrame *)gROOT->ProcessLineFast(fAction->fAct.Data());
01129          break;
01130    }
01131 
01132    Update();
01133 
01134    return ret;
01135 }
01136 
01137 //______________________________________________________________________________
01138 void TRootGuiBuilder::InitMenu()
01139 {
01140    // Inititiate GUI Builder menus.
01141 
01142    fMenuFile = new TGuiBldPopupMenu();
01143    fMenuFile->AddEntry(new TGHotString("&Edit (Ctrl+double-click)"),
01144                        kGUIBLD_FILE_START, 0,
01145                        fClient->GetPicture("bld_edit.png"));
01146    fMenuFile->AddEntry(new TGHotString("&Stop (Ctrl+double-click)"),
01147                        kGUIBLD_FILE_STOP, 0,
01148                        fClient->GetPicture("bld_stop.png"));
01149    fMenuFile->DisableEntry(kGUIBLD_FILE_STOP);
01150    fMenuFile->DisableEntry(kGUIBLD_FILE_START);
01151    fMenuFile->AddSeparator();
01152    fMenuFile->AddEntry(new TGHotString("&New Project"), kGUIBLD_FILE_NEW,
01153                        0, fClient->GetPicture("bld_new.png"));
01154    fMenuFile->AddEntry(new TGHotString("&Open"), kGUIBLD_FILE_OPEN,
01155                        0, fClient->GetPicture("bld_open.png"));
01156    fMenuFile->AddEntry(new TGHotString("&Close"), kGUIBLD_FILE_CLOSE,
01157                         0, fClient->GetPicture("bld_delete.png"));
01158    fMenuFile->AddEntry(new TGHotString("&Save project as"), kGUIBLD_FILE_SAVE,
01159                        0, fClient->GetPicture("bld_save.png"));
01160    fMenuFile->DisableEntry(kGUIBLD_FILE_CLOSE);
01161    fMenuFile->AddSeparator();
01162    fMenuFile->AddEntry(new TGHotString("E&xit"), kGUIBLD_FILE_EXIT,
01163                         0, fClient->GetPicture("bld_exit.png"));
01164 /*
01165    fMenuEdit = new TGuiBldPopupMenu();
01166    fMenuEdit->AddSeparator();
01167    fMenuEdit->AddEntry(new TGHotString("&Preferences ..."), kGUIBLD_EDIT_PREF);
01168 */
01169    fMenuWindow = new TGuiBldPopupMenu();
01170    fMenuWindow->AddEntry(new TGHotString("Tile &Horizontally"),
01171                          kGUIBLD_WINDOW_HOR);
01172    fMenuWindow->AddEntry(new TGHotString("Tile &Vertically"),
01173                          kGUIBLD_WINDOW_VERT);
01174    fMenuWindow->AddEntry(new TGHotString("&Cascade"),
01175                          kGUIBLD_WINDOW_CASCADE);
01176    fMenuWindow->AddSeparator();
01177    //fMenuWindow->AddPopup(new TGHotString("&Windows"), fMain->GetWinListMenu());
01178    fMenuWindow->AddEntry(new TGHotString("&Arrange icons"),
01179                          kGUIBLD_WINDOW_ARRANGE);
01180    fMenuWindow->AddSeparator();
01181    fMenuWindow->AddEntry(new TGHotString("&Opaque resize"),
01182                          kGUIBLD_WINDOW_OPAQUE);
01183    fMenuWindow->CheckEntry(kGUIBLD_WINDOW_OPAQUE);
01184 
01185    fMenuHelp = new TGuiBldPopupMenu();
01186    fMenuHelp->AddEntry(new TGHotString("&Contents"), kGUIBLD_HELP_CONTENTS);
01187    fMenuHelp->AddSeparator();
01188    fMenuHelp->AddEntry(new TGHotString("&About"), kGUIBLD_HELP_ABOUT);
01189    //fMenuHelp->AddSeparator();
01190    //fMenuHelp->AddEntry(new TGHotString("&Send Bug Report"),kGUIBLD_HELP_BUG);
01191 
01192    TGMenuBar *bar = fMenuBar->GetMenuBar();
01193 
01194    TGuiBldMenuTitle *title;
01195    title = new TGuiBldMenuTitle(bar, new TGHotString("&File"), fMenuFile);
01196    bar->AddTitle(title, new TGLayoutHints(kLHintsTop | kLHintsLeft,0,4,0,0));
01197 
01198    //title = new TGuiBldMenuTitle(bar, new TGHotString("&Edit"), fMenuEdit);
01199    //bar->AddTitle(title, new TGLayoutHints(kLHintsTop | kLHintsLeft,0,4,0,0));
01200 
01201    title = new TGuiBldMenuTitle(bar, new TGHotString("&Windows"), fMenuWindow);
01202    bar->AddTitle(title, new TGLayoutHints(kLHintsTop | kLHintsLeft,0,4,0,0));
01203 
01204    title = new TGuiBldMenuTitle(bar, new TGHotString("&Help"), fMenuHelp);
01205    bar->AddTitle(title, new TGLayoutHints(kLHintsTop | kLHintsRight,4,4,0,0));
01206 
01207    fMenuBar->SetEditDisabled(kEditDisable);
01208    PropagateBgndColor(fMenuBar, GetBgnd());
01209 }
01210 
01211 //______________________________________________________________________________
01212 void TRootGuiBuilder::ChangeSelected(TGFrame *f)
01213 {
01214    // Set selected frame.
01215 
01216    fSelected = f;
01217    Update();
01218 }
01219 
01220 //______________________________________________________________________________
01221 void TRootGuiBuilder::EnableLassoButtons(Bool_t on)
01222 {
01223    // Enable toolbar buttons for alignment.
01224 
01225    TGButton *btn = 0;
01226 
01227    btn = fToolBar->GetButton(kUpAct);
01228    if (btn) {
01229       btn->SetState(!on ? kButtonDisabled : kButtonUp);
01230    }
01231 
01232    btn = fToolBar->GetButton(kDownAct);
01233    if (btn) {
01234       btn->SetState(!on ? kButtonDisabled : kButtonUp);
01235    }
01236 
01237    btn = fToolBar->GetButton(kRightAct);
01238    if (btn) {
01239       btn->SetState(!on ? kButtonDisabled : kButtonUp);
01240    }
01241 
01242    btn = fToolBar->GetButton(kLeftAct);
01243    if (btn) {
01244       btn->SetState(!on ? kButtonDisabled : kButtonUp);
01245    }
01246 
01247    btn = fToolBar->GetButton(kDeleteAct);
01248    if (btn) {
01249       btn->SetState(!on ? kButtonDisabled : kButtonUp);
01250    }
01251 
01252    btn = fToolBar->GetButton(kGrabAct);
01253    if (btn) {
01254       btn->SetState(kButtonUp);
01255    }
01256 
01257    btn = fToolBar->GetButton(kCropAct);
01258    if (btn) {
01259       btn->SetState(!on ? kButtonDisabled : kButtonUp);
01260    }
01261 
01262 }
01263 
01264 //______________________________________________________________________________
01265 void TRootGuiBuilder::EnableSelectedButtons(Bool_t on)
01266 {
01267    // Enable/disable toolbar buttons according to the selected frame.
01268 
01269    fSelected = fManager->GetSelected();
01270 
01271    TGButton *btn = 0;
01272 
01273    if (!fSelected) {
01274       btn = fToolBar->GetButton(kCompactAct);
01275       if (btn) btn->SetState(kButtonDisabled);
01276 
01277       btn = fToolBar->GetButton(kLayoutVAct);
01278       if (btn) btn->SetState(kButtonDisabled);
01279 
01280       btn = fToolBar->GetButton(kLayoutHAct);
01281       if (btn) btn->SetState(kButtonDisabled);
01282 
01283       btn = fToolBar->GetButton(kBreakLayoutAct);
01284       if (btn) btn->SetState(kButtonDisabled);
01285       return;
01286    }
01287 
01288    Bool_t comp = kFALSE;
01289    TGLayoutManager *lm = 0;
01290    Bool_t hor = kFALSE;
01291    Bool_t fixed = kFALSE;
01292    Bool_t enable = on;
01293    Bool_t compact_disable = kTRUE;
01294 
01295    if (fSelected->InheritsFrom(TGCompositeFrame::Class())) {
01296       lm = ((TGCompositeFrame*)fSelected)->GetLayoutManager();
01297       comp = kTRUE;
01298       hor = lm && lm->InheritsFrom(TGHorizontalLayout::Class());
01299       fixed = !fManager->CanChangeLayout(fSelected);
01300       compact_disable = !fManager->CanCompact(fSelected);
01301    } else {
01302       enable = kFALSE;
01303    }
01304 
01305    btn = fToolBar->GetButton(kCompactAct);
01306    if (btn) btn->SetState(enable && comp && !fixed && !compact_disable ?
01307                           kButtonUp : kButtonDisabled);
01308 
01309    btn = fToolBar->GetButton(kLayoutHAct);
01310    if (btn) {
01311       btn->SetState(enable && comp && !hor && !fixed ? kButtonUp :
01312                     kButtonDisabled);
01313    }
01314 
01315    btn = fToolBar->GetButton(kLayoutVAct);
01316    if (btn) {
01317       btn->SetState(enable && comp && hor && !fixed ? kButtonUp :
01318                     kButtonDisabled);
01319    }
01320 
01321    btn = fToolBar->GetButton(kBreakLayoutAct);
01322    if (btn) {
01323       btn->SetState(enable && comp && !fixed ? kButtonUp : kButtonDisabled);
01324    }
01325 /*
01326    btn = fToolBar->GetButton(kGrabAct);
01327    if (btn) {
01328       btn->SetState(enable && comp ? kButtonDown : kButtonUp);
01329       TGToolTip *tt = btn->GetToolTip();
01330       tt->SetText(btn->IsDown() ? "Drop Frames (Ctrl-Return)" :
01331                                   "Grab Selected Frames (Return)");
01332    }
01333 */
01334 }
01335 
01336 //______________________________________________________________________________
01337 void TRootGuiBuilder::EnableEditButtons(Bool_t on)
01338 {
01339    // Enable/disable toolbar buttons according to the selected frame.
01340 
01341    TGButton *btn = 0;
01342 
01343    Bool_t lasso = fManager->IsLassoDrawn() && on;
01344 
01345    btn = fToolBar->GetButton(kReplaceAct);
01346    if (btn) {
01347       btn->SetState(!on ? kButtonDisabled : kButtonUp);
01348    }
01349 
01350    btn = fToolBar->GetButton(kCutAct);
01351    if (btn) {
01352       btn->SetState(!on || lasso ? kButtonDisabled : kButtonUp);
01353    }
01354 
01355    btn = fToolBar->GetButton(kDropAct);
01356    if (btn) {
01357       btn->SetState(!on || lasso ? kButtonDisabled : kButtonUp);
01358    }
01359 
01360    btn = fToolBar->GetButton(kCopyAct);
01361    if (btn) {
01362       btn->SetState(!on || lasso ? kButtonDisabled : kButtonUp);
01363    }
01364 
01365    btn = fToolBar->GetButton(kPasteAct);
01366    if (btn) {
01367       btn->SetState(!on || !fManager->IsPasteFrameExist() ?
01368                     kButtonDisabled : kButtonUp);
01369    }
01370 
01371    btn = fToolBar->GetButton(kCropAct);
01372    if (btn) {
01373       btn->SetState(!on && !lasso ? kButtonDisabled : kButtonUp);
01374    }
01375 
01376    btn = fToolBar->GetButton(kDeleteAct);
01377    if (btn) {
01378       btn->SetState(!on && !lasso ? kButtonDisabled : kButtonUp);
01379    }
01380 }
01381 
01382 //______________________________________________________________________________
01383 void TRootGuiBuilder::Update()
01384 {
01385    // Update gui builder.
01386 
01387    if (!fManager) {
01388       return;
01389    }
01390 
01391    EnableLassoButtons(fManager->IsLassoDrawn());
01392    fSelected = fManager->GetSelected();
01393    EnableSelectedButtons(fSelected);
01394    EnableEditButtons(fClient->IsEditable() && (fManager->IsLassoDrawn() ||
01395                      fManager->GetSelected() ||
01396                      fManager->IsPasteFrameExist()));
01397 
01398    if (fActionButton) {
01399       TGFrame *parent = (TGFrame*)fActionButton->GetParent();
01400       parent->ChangeOptions(parent->GetOptions() & ~kSunkenFrame);
01401       fClient->NeedRedraw(parent, kTRUE);
01402    }
01403 
01404    if (!fClient->IsEditable()) {
01405       UpdateStatusBar("");
01406       fMenuFile->EnableEntry(kGUIBLD_FILE_START);
01407       fMenuFile->DisableEntry(kGUIBLD_FILE_STOP);
01408       fEditable = 0;
01409       //fShutter->SetSelectedItem(fShutter->GetItem("Projects"));
01410    } else {
01411       fMenuFile->DisableEntry(kGUIBLD_FILE_START);
01412       fMenuFile->EnableEntry(kGUIBLD_FILE_STOP);
01413    }
01414 
01415    SwitchToolbarButton();
01416    fActionButton = 0;
01417 }
01418 
01419 //______________________________________________________________________________
01420 Bool_t TRootGuiBuilder::IsSelectMode() const
01421 {
01422    // Return the status of the selected mode.
01423 
01424    TGButton *btn = 0;
01425    btn = fToolBar->GetButton(kSelectAct);
01426 
01427    if (!btn) return kFALSE;
01428 
01429    return btn->IsDown();
01430 }
01431 
01432 //______________________________________________________________________________
01433 Bool_t TRootGuiBuilder::IsGrabButtonDown() const
01434 {
01435    // Return the status of the grab mode.
01436 
01437    TGButton *btn = fToolBar->GetButton(kGrabAct);
01438 
01439    if (!btn) return kFALSE;
01440 
01441    return btn->IsDown();
01442 }
01443 
01444 ////////////////////////////////////////////////////////////////////////////////
01445 class TGuiBldSaveFrame : public TGMainFrame {
01446 
01447 public:
01448    TGuiBldSaveFrame(const TGWindow *p, UInt_t w , UInt_t h) :
01449       TGMainFrame(p, w, h) {}
01450    void SetList(TList *li) { fList = li; }
01451 };
01452 
01453 static const char *gSaveMacroTypes[] = {
01454    "Macro files", "*.[C|c]*",
01455    "All files",   "*",
01456    0,             0
01457 };
01458 
01459 //______________________________________________________________________________
01460 Bool_t TRootGuiBuilder::HandleKey(Event_t *event)
01461 {
01462    // Handle keys.
01463 
01464    if (event->fType == kGKeyPress) {
01465       UInt_t keysym;
01466       char str[2];
01467       gVirtualX->LookupString(event, str, sizeof(str), keysym);
01468 
01469       if (event->fState & kKeyControlMask) {
01470          if (str[0] == 19) {  // ctrl-s
01471             if (fMain->GetCurrent()) {
01472                return SaveProject(event);
01473             } else {
01474                return kFALSE; //TGMainFrame::HandleKey(event);
01475             }
01476          } else if (str[0] == 14) { //ctrl-n
01477             return NewProject();  //event not needed
01478          } else if (str[0] == 15) { // ctrl-o
01479             return OpenProject(event);
01480          }
01481       }
01482       fManager->HandleKey(event);
01483       return TGMainFrame::HandleKey(event);
01484    }
01485    return kTRUE;
01486 }
01487 
01488 //______________________________________________________________________________
01489 Bool_t TRootGuiBuilder::NewProject(TString type)
01490 {
01491    // Create a new project.
01492 
01493    TGWindow *root = (TGWindow*)fClient->GetRoot();
01494 
01495    if (root) root->SetEditable(kFALSE);
01496    fEditable = new TGMdiFrame(fMain, 500, 400, kOwnBackground);
01497    fEditable->DontCallClose();
01498    fEditable->SetMdiHints(kMdiDefaultHints);
01499    fEditable->SetWindowName(fEditable->GetName());
01500    fEditable->SetEditDisabled(0);   // enable editting
01501    fEditable->MapRaised();
01502    fEditable->AddInput(kKeyPressMask | kButtonPressMask);
01503    fEditable->SetEditable(kTRUE);
01504 
01505    if (type == "horizontal") {
01506       TGHorizontalFrame *hor = new TGHorizontalFrame(fEditable, 100, 100);
01507       fEditable->AddFrame(hor, new TGLayoutHints( kLHintsExpandX |
01508                           kLHintsExpandY, 1, 1, 1, 1));
01509       hor->SetEditable(kTRUE);
01510       fClient->NeedRedraw(hor, kTRUE);
01511       fEditable->MapSubwindows();
01512       fEditable->MapWindow();
01513       fClient->NeedRedraw(fEditable, kTRUE);
01514       fEditable->SetLayoutBroken(kFALSE);
01515       fEditable->Layout();
01516    }
01517    else if (type == "vertical") {
01518       TGVerticalFrame *vert = new TGVerticalFrame(fEditable, 100, 100);
01519       fEditable->AddFrame(vert, new TGLayoutHints( kLHintsExpandX |
01520                           kLHintsExpandY,1,1,1,1));
01521       vert->SetEditable(kTRUE);
01522       fClient->NeedRedraw(vert, kTRUE);
01523       fEditable->MapSubwindows();
01524       fEditable->MapWindow();
01525       fClient->NeedRedraw(fEditable, kTRUE);
01526       fEditable->SetLayoutBroken(kFALSE);
01527       fEditable->Layout();
01528 
01529    } else {
01530       fEditable->SetLayoutBroken(kTRUE);
01531    }
01532    fManager->SetEditable(kTRUE);
01533    fMenuFile->EnableEntry(kGUIBLD_FILE_CLOSE);
01534    fMenuFile->EnableEntry(kGUIBLD_FILE_STOP);
01535    fEditable->SetCleanup(kDeepCleanup);
01536 
01537 
01538    SwitchToolbarButton();
01539    return kTRUE;
01540 }
01541 
01542 //______________________________________________________________________________
01543 Bool_t TRootGuiBuilder::OpenProject(Event_t *event)
01544 {
01545    // Open new gui builder project.
01546 
01547 
01548    TGButton *btn = fToolBar->GetButton(kOpenAct);
01549    if (btn) {
01550       btn->SetBackgroundColor(GetBgnd());
01551       fClient->NeedRedraw(btn, kTRUE);
01552    }
01553 
01554    TGFileInfo fi;
01555    static TString dir(".");
01556    static Bool_t overwr = kFALSE;
01557    TString fname;
01558 
01559    fi.fFileTypes = gSaveMacroTypes;
01560    fi.fIniDir    = StrDup(dir);
01561    fi.fOverwrite = overwr;
01562    TGWindow *root = (TGWindow*)fClient->GetRoot();
01563    root->SetEditable(kFALSE);
01564 
01565    new TGFileDialog(fClient->GetDefaultRoot(), this, kFDOpen, &fi);
01566 
01567    if (!fi.fFilename) {
01568       root->SetEditable(kTRUE);
01569       return kFALSE;
01570    }
01571 
01572    dir    = fi.fIniDir;
01573    overwr = fi.fOverwrite;
01574    fname  = fi.fFilename;
01575 
01576    if (fname.EndsWith(".C", TString::kIgnoreCase) || fname.EndsWith(".cxx") ||
01577        fname.EndsWith(".cpp") || fname.EndsWith(".cc")) {
01578       NewProject();        // create new project
01579       gROOT->Macro(fname.Data()); // put content of the macro as child frame
01580    } else {
01581       Int_t retval;
01582       new TGMsgBox(fClient->GetDefaultRoot(), this, "Error...",
01583                    TString::Format("file (%s) must have source extension (.C, .c, .cxx, .cpp, .cc)",
01584                    fname.Data()), kMBIconExclamation, kMBRetry | kMBCancel,
01585                    &retval);
01586 
01587       if (retval == kMBRetry) {
01588          OpenProject(event);
01589       }
01590    }
01591 
01592    fMenuFile->EnableEntry(kGUIBLD_FILE_CLOSE);
01593    fMenuFile->EnableEntry(kGUIBLD_FILE_STOP);
01594    SwitchToolbarButton();
01595 
01596    return kTRUE;
01597 }
01598 
01599 //______________________________________________________________________________
01600 Bool_t TRootGuiBuilder::SaveProject(Event_t *event)
01601 {
01602    // Save selected project.
01603 
01604    TGButton *btn = fToolBar->GetButton(kSaveAct);
01605    if (btn) {
01606       btn->SetBackgroundColor(GetBgnd());
01607       fClient->NeedRedraw(btn, kTRUE);
01608    }
01609 
01610    TGMdiFrame *savfr = fMain->GetCurrent();
01611    if (!savfr) return kFALSE;
01612 
01613    static TImage *img = 0;
01614 
01615    if (!img) {
01616       img = TImage::Create();
01617    }
01618    img->FromWindow(savfr->GetParent()->GetId());
01619 
01620    TGWindow *root = (TGWindow*)fClient->GetRoot();
01621    TGFileInfo fi;
01622    static TString dir(".");
01623    static Bool_t overwr = kFALSE;
01624    TString fname;
01625    root->SetEditable(kFALSE);
01626 
01627    fi.fFileTypes = gSaveMacroTypes;
01628    fi.fIniDir    = StrDup(dir);
01629    fi.fOverwrite = overwr;
01630 
01631    new TGFileDialog(fClient->GetDefaultRoot(), this, kFDSave, &fi);
01632 
01633    if (!fi.fFilename) {
01634       root->SetEditable(kTRUE);
01635       SetEditable(kTRUE);
01636       return kFALSE;
01637    }
01638 
01639    dir = fi.fIniDir;
01640    overwr = fi.fOverwrite;
01641    fname = gSystem->UnixPathName(fi.fFilename);
01642 
01643    if (fname.EndsWith(".C", TString::kIgnoreCase) || fname.EndsWith(".cxx") ||
01644        fname.EndsWith(".cpp") || fname.EndsWith(".cc")) {
01645       TGuiBldSaveFrame *main = new TGuiBldSaveFrame(fClient->GetDefaultRoot(),
01646                                                     savfr->GetWidth(),
01647                                                     savfr->GetHeight());
01648       TList *list = main->GetList();
01649       TString name = savfr->GetName();
01650       savfr->SetName(main->GetName());
01651       main->SetList(savfr->GetList());
01652       main->SetLayoutBroken(savfr->IsLayoutBroken());
01653       main->SaveSource(fname.Data(), "keep_names");
01654       savfr->SetWindowName(fname.Data());
01655       main->SetList(list);
01656 
01657       main->SetMWMHints(kMWMDecorAll, kMWMFuncAll,
01658                         kMWMInputFullApplicationModal);
01659       main->SetWMSize(main->GetWidth(), main->GetHeight());
01660       main->SetWMSizeHints(main->GetDefaultWidth(), main->GetDefaultHeight(),
01661                            10000, 10000, 0, 0);
01662       main->SetWindowName(fname.Data());
01663       main->SetIconName(fname.Data());
01664       main->SetClassHints(fname.Data(), fname.Data());
01665       // some problems here under win32
01666       if (gVirtualX->InheritsFrom("TGX11")) main->SetIconPixmap("bld_rgb.xpm");
01667 
01668       savfr->SetName(name.Data());
01669 
01670       AddMacro(fname.Data(), img);
01671       delete main;
01672    } else {
01673       Int_t retval;
01674       new TGMsgBox(fClient->GetDefaultRoot(), this, "Error...",
01675                    TString::Format("file (%s) must have source extension (.C, .c, .cxx, .cpp, .cc)",
01676                    fname.Data()), kMBIconExclamation, kMBRetry | kMBCancel,
01677                    &retval);
01678       if (retval == kMBRetry) {
01679          SaveProject(event);
01680       }
01681       SwitchToolbarButton();
01682    }
01683    SwitchToolbarButton();
01684    return kTRUE;
01685 }
01686 
01687 //______________________________________________________________________________
01688 void TRootGuiBuilder::AddMacro(const char *macro, TImage *img)
01689 {
01690    // Add macro to "User's Macros" section
01691    // Input img must be static - do not delete it.
01692 
01693    if (!img || !img->GetWidth() || !img->GetHeight()) {
01694       return;
01695    }
01696 
01697    UInt_t w = 100;
01698    Float_t ratio = Float_t(w)/img->GetWidth();
01699    Float_t rh = img->GetHeight()*ratio;
01700    UInt_t h = UInt_t(rh);
01701    img->Scale(w, h);
01702    img->Merge(img, "overlay");
01703 
01704    static int i = 0;
01705    const TGPicture *pic = fClient->GetPicturePool()->GetPicture(
01706                                        TString::Format("%s;%d", macro, i++),
01707                                        img->GetPixmap(),img->GetMask());
01708    const char *name = gSystem->BaseName(macro);
01709 
01710    TGButton *btn = FindActionButton(name, "User's Macros");
01711    TGuiBldAction *act = 0;
01712 
01713    if (!btn) {
01714       act = new TGuiBldAction(name, macro, kGuiBldMacro);
01715       act->fAct = macro;
01716       act->fPic = macro;
01717       act->fPicture = pic;
01718 
01719       AddAction(act, "User's Macros");
01720    } else {
01721       act = (TGuiBldAction*)btn->GetUserData();
01722       act->fAct = macro;
01723       act->fPic = macro;
01724       act->fPicture = pic;
01725 
01726       if (btn->InheritsFrom(TGPictureButton::Class())) {
01727          btn->Resize(w, h);
01728          fClient->FreePicture(((TGPictureButton*)btn)->GetPicture());
01729          ((TGPictureButton*)btn)->SetPicture(pic);
01730       }
01731    }
01732    fClient->NeedRedraw(fShutter);
01733 }
01734 
01735 //______________________________________________________________________________
01736 TGMdiFrame *TRootGuiBuilder::FindEditableMdiFrame(const TGWindow *win)
01737 {
01738    // Find the editable frame.
01739 
01740    const TGWindow *parent = win;
01741    TGMdiFrame *ret = 0;
01742 
01743    while (parent && (parent != fClient->GetDefaultRoot())) {
01744       if (parent->InheritsFrom(TGMdiFrame::Class())) {
01745          ret = (TGMdiFrame*)parent;
01746          return ret;
01747       }
01748       parent = parent->GetParent();
01749    }
01750    return 0;
01751 }
01752 
01753 //______________________________________________________________________________
01754 void TRootGuiBuilder::SwitchToolbarButton()
01755 {
01756    // Switch image of toolbar edit button according to the current state.
01757 
01758    static const TGPicture *start = fClient->GetPicture("bld_edit.png");
01759    static const TGPicture *stop = fClient->GetPicture("bld_stop.png");
01760 
01761    if (fClient->IsEditable()) {
01762       fStartButton->SetEnabled(kTRUE);
01763       fStartButton->SetPicture(stop);
01764       fToolBar->SetId(fStartButton, kEndEditAct);
01765       fStartButton->SetToolTipText("Stop Edit (Ctrl-Dbl-Click)");
01766    } else {
01767       if (fMain->GetNumberOfFrames() < 1) {
01768          fStartButton->SetEnabled(kFALSE);
01769       } else {
01770          fStartButton->SetEnabled(kTRUE);
01771          fStartButton->SetPicture(start);
01772          fToolBar->SetId(fStartButton, kEditableAct);
01773          fStartButton->SetToolTipText("Start Edit (Ctrl-Dbl-Click)");
01774       }
01775    }
01776 
01777    fClient->NeedRedraw(fStartButton, kTRUE);
01778 }
01779 
01780 //______________________________________________________________________________
01781 void TRootGuiBuilder::HandleMenu(Int_t id)
01782 {
01783    // Handle menu items.
01784 
01785    TGWindow *root = (TGWindow*)fClient->GetRoot();
01786    TRootHelpDialog *hd;
01787 
01788    switch (id) {
01789       case kGUIBLD_FILE_START:
01790          if (fClient->IsEditable()) {
01791             break;
01792          }
01793          fEditable = fMain->GetCurrent();
01794          if (fEditable) {
01795             fEditable->SetEditable(kTRUE);
01796          } //else if (!fMain->GetCurrent()) {
01797             //NewProject();
01798          //}
01799          UpdateStatusBar("Start edit");
01800          fMenuFile->EnableEntry(kGUIBLD_FILE_STOP);
01801          fMenuFile->DisableEntry(kGUIBLD_FILE_START);
01802          SwitchToolbarButton();
01803          break;
01804 
01805       case kGUIBLD_FILE_STOP:
01806          if (!fClient->IsEditable()) {
01807             break;
01808          }
01809          fEditable = FindEditableMdiFrame(root);
01810 
01811          if (fEditable) {
01812             root->SetEditable(kFALSE);
01813 
01814             UpdateStatusBar("Stop edit");
01815             fMenuFile->EnableEntry(kGUIBLD_FILE_START);
01816             fMenuFile->DisableEntry(kGUIBLD_FILE_STOP);
01817             fEditable = 0;
01818             SwitchToolbarButton();
01819          }
01820          fEditor->Reset();
01821          break;
01822 
01823       case kGUIBLD_FILE_NEW:
01824          NewProject();
01825          SwitchToolbarButton();
01826          break;
01827 
01828       case kGUIBLD_FILE_CLOSE:
01829          fEditable = FindEditableMdiFrame(root);
01830          if (fEditable && (fEditable == fMain->GetCurrent())) {
01831             root->SetEditable(kFALSE);
01832          }
01833          fEditor->Reset();
01834          UpdateStatusBar("");
01835          fMain->Close(fMain->GetCurrent());
01836 
01837          if (fMain->GetNumberOfFrames() <= 1) {
01838             fMenuFile->DisableEntry(kGUIBLD_FILE_CLOSE);
01839             fMenuFile->DisableEntry(kGUIBLD_FILE_STOP);
01840             fMenuFile->DisableEntry(kGUIBLD_FILE_START);
01841          }
01842 
01843          if (fClient->IsEditable()) {
01844             fMenuFile->DisableEntry(kGUIBLD_FILE_START);
01845             fMenuFile->EnableEntry(kGUIBLD_FILE_STOP);
01846          } else {
01847             fMenuFile->EnableEntry(kGUIBLD_FILE_START);
01848             fMenuFile->DisableEntry(kGUIBLD_FILE_STOP);
01849          }
01850          SwitchToolbarButton();
01851          break;
01852 
01853       case kGUIBLD_FILE_EXIT:
01854          CloseWindow();
01855          break;
01856 
01857       case kGUIBLD_FILE_OPEN:
01858          OpenProject();
01859          SwitchToolbarButton();
01860          break;
01861 
01862       case kGUIBLD_FILE_SAVE:
01863          SaveProject();
01864          SwitchToolbarButton();
01865          break;
01866 
01867       case kGUIBLD_WINDOW_HOR:
01868          fMain->TileHorizontal();
01869          break;
01870 
01871       case kGUIBLD_WINDOW_VERT:
01872          fMain->TileVertical();
01873          break;
01874 
01875       case kGUIBLD_WINDOW_CASCADE:
01876          fMain->Cascade();
01877          break;
01878 
01879       case kGUIBLD_WINDOW_ARRANGE:
01880          fMain->ArrangeMinimized();
01881          break;
01882 
01883       case kGUIBLD_WINDOW_OPAQUE:
01884          if (fMenuWindow->IsEntryChecked(kGUIBLD_WINDOW_OPAQUE)) {
01885             fMenuWindow->UnCheckEntry(kGUIBLD_WINDOW_OPAQUE);
01886             fMain->SetResizeMode(kMdiNonOpaque);
01887          } else {
01888             fMenuWindow->CheckEntry(kGUIBLD_WINDOW_OPAQUE);
01889             fMain->SetResizeMode(kMdiOpaque);
01890          }
01891          break;
01892       case  kGUIBLD_HELP_CONTENTS:
01893          root->SetEditable(kFALSE);
01894          hd = new TRootHelpDialog(this, "Help on Gui Builder...", 600, 400);
01895          hd->SetText(gHelpBuilder);
01896          hd->SetEditDisabled();
01897          hd->Popup();
01898          root->SetEditable(kTRUE);
01899          break;
01900 
01901       case  kGUIBLD_HELP_ABOUT:
01902          root->SetEditable(kFALSE);
01903          hd = new TRootHelpDialog(this, "About Gui Builder...", 520, 160);
01904          hd->SetEditDisabled();
01905          hd->SetText(gHelpAboutBuilder);
01906          hd->Popup();
01907          root->SetEditable(kTRUE);
01908          break;
01909 
01910       default:
01911          fMain->SetCurrent(id);
01912          break;
01913    }
01914 }
01915 
01916 //______________________________________________________________________________
01917 void TRootGuiBuilder::MaybeCloseWindow()
01918 {
01919    // Handler before closing MDI frame.
01920 
01921    int retval;
01922    if (fClosing == -1)
01923       return;
01924    TGMdiFrame *mdiframe = (TGMdiFrame *)gTQSender;
01925    fManager->SetEditable(kFALSE);
01926    new TGMsgBox(gClient->GetDefaultRoot(), this,
01927                 "Closing project", "Do you want to save the project before closing?",
01928                 kMBIconExclamation, kMBYes | kMBNo | kMBCancel, &retval);
01929 
01930    fManager->SetEditable(kTRUE);
01931    if (retval == kMBYes) {
01932       SaveProject();
01933    }
01934    if (retval == kMBCancel) {
01935       fClosing = -1;
01936       if (!fClient->IsEditable())
01937          HandleMenu(kGUIBLD_FILE_START);
01938       return;
01939    }
01940    fEditor->RemoveFrame(mdiframe);
01941    mdiframe->CloseWindow();
01942 }
01943 
01944 //______________________________________________________________________________
01945 void TRootGuiBuilder::HandleWindowClosed(Int_t )
01946 {
01947    // Handler for closed MDI frame.
01948 
01949    fEditable = 0;
01950 
01951    if (fClient->IsEditable()) {
01952       fManager->SetEditable(kFALSE);
01953       fMenuFile->DisableEntry(kGUIBLD_FILE_START);
01954       fMenuFile->EnableEntry(kGUIBLD_FILE_STOP);
01955    } else {
01956       fMenuFile->EnableEntry(kGUIBLD_FILE_START);
01957       fMenuFile->DisableEntry(kGUIBLD_FILE_STOP);
01958    }
01959    fEditor->Reset();
01960    UpdateStatusBar("");
01961 
01962    if (fMain->GetNumberOfFrames() == 0) {
01963       fMenuFile->DisableEntry(kGUIBLD_FILE_CLOSE);
01964       fMenuFile->DisableEntry(kGUIBLD_FILE_STOP);
01965       fMenuFile->DisableEntry(kGUIBLD_FILE_START);
01966       SwitchToolbarButton();
01967       return;
01968    }
01969 }
01970 
01971 //______________________________________________________________________________
01972 void TRootGuiBuilder::UpdateStatusBar(const char *txt)
01973 {
01974    // Update information shown on the status bar.
01975 
01976    if (!fStatusBar) return;
01977 
01978    const char *text = 0;
01979 
01980    if (!txt) {
01981       TObject *o = (TObject *)gTQSender;
01982 
01983       if (o && o->InheritsFrom(TGToolTip::Class())) {
01984          TGToolTip *tip = (TGToolTip*)o;
01985          text = tip->GetText()->Data();
01986       }
01987    } else {
01988       text = txt;
01989    }
01990    fStatusBar->SetText(text);
01991 }
01992 
01993 //______________________________________________________________________________
01994 void TRootGuiBuilder::EraseStatusBar()
01995 {
01996    // Clear information shown in the status bar.
01997 
01998    if (!fStatusBar) return;
01999 
02000    fStatusBar->SetText("");
02001 }
02002 
02003 //______________________________________________________________________________
02004 void TRootGuiBuilder::BindKeys()
02005 {
02006    // Keyborad key binding.
02007 
02008    gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_a),
02009                       kKeyControlMask, kTRUE);
02010 
02011    gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_n),
02012                       kKeyControlMask, kTRUE);
02013 
02014    gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_o),
02015                       kKeyControlMask, kTRUE);
02016 
02017    gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Return),
02018                       kKeyControlMask, kTRUE);
02019 
02020    gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Return),
02021                       0, kTRUE);
02022 
02023    gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Enter),
02024                       kKeyControlMask, kTRUE);
02025 
02026    gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Enter),
02027                       0, kTRUE);
02028 
02029    gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_x),
02030                       kKeyControlMask, kTRUE);
02031 
02032    gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_c),
02033                       kKeyControlMask, kTRUE);
02034 
02035    gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_v),
02036                       kKeyControlMask, kTRUE);
02037 
02038    gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_r),
02039                       kKeyControlMask, kTRUE);
02040 
02041    gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_z),
02042                       kKeyControlMask, kTRUE);
02043 
02044    gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_z),
02045                       kKeyControlMask | kKeyShiftMask, kTRUE);
02046 
02047    gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_b),
02048                       kKeyControlMask, kTRUE);
02049 
02050    gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_l),
02051                       kKeyControlMask, kTRUE);
02052 
02053    gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_g),
02054                       kKeyControlMask, kTRUE);
02055 
02056    gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_h),
02057                       kKeyControlMask, kTRUE);
02058 
02059    gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Delete),
02060                       0, kTRUE);
02061 
02062    gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Backspace),
02063                       0, kTRUE);
02064 
02065    gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Space),
02066                       0, kTRUE);
02067 
02068    gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Left),
02069                       0, kTRUE);
02070 
02071    gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Right),
02072                       0, kTRUE);
02073 
02074    gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Up),
02075                       0, kTRUE);
02076 
02077    gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Down),
02078                       0, kTRUE);
02079 
02080    gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Left),
02081                       kKeyShiftMask, kTRUE);
02082 
02083    gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Right),
02084                       kKeyShiftMask, kTRUE);
02085 
02086    gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Up),
02087                       kKeyShiftMask, kTRUE);
02088 
02089    gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Down),
02090                       kKeyShiftMask, kTRUE);
02091 
02092    gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Delete),
02093                       kKeyShiftMask, kTRUE);
02094 
02095    gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Backspace),
02096                       kKeyShiftMask, kTRUE);
02097 }
02098 
02099 //______________________________________________________________________________
02100 TGFrame *TRootGuiBuilder::VSplitter()
02101 {
02102    // Create new vertical splitter (TGVSplitter).
02103 
02104    TGHorizontalFrame *ret = new TGHorizontalFrame();
02105    ret->SetCleanup(kDeepCleanup);
02106    TGVerticalFrame *v1 = new TGVerticalFrame(ret, 40, 10, kSunkenFrame |
02107                                              kFixedWidth);
02108    ret->AddFrame(v1, new TGLayoutHints(kLHintsLeft | kLHintsExpandY));
02109    //v1->SetEditDisabled(kEditDisableGrab);
02110 
02111    TGVSplitter *splitter = new TGVSplitter(ret);
02112    splitter->SetFrame(v1, kTRUE);
02113    ret->AddFrame(splitter, new TGLayoutHints(kLHintsLeft | kLHintsExpandY));
02114    splitter->SetEditDisabled(kEditDisableBtnEnable);
02115 
02116    TGVerticalFrame *v2 = new TGVerticalFrame(ret, 10, 10, kSunkenFrame);
02117    v2->ChangeOptions(kSunkenFrame);
02118    ret->AddFrame(v2, new TGLayoutHints(kLHintsRight | kLHintsExpandX |
02119                  kLHintsExpandY));
02120    //v2->SetEditDisabled(kEditDisableGrab);
02121    ret->SetEditDisabled(kEditDisableLayout);
02122 
02123    ret->MapSubwindows();
02124    ret->SetLayoutBroken(kFALSE);
02125    return ret;
02126 }
02127 
02128 //______________________________________________________________________________
02129 TGFrame *TRootGuiBuilder::HSplitter()
02130 {
02131    //  Creates new horizontal splitter (TGHSplitter).
02132 
02133    TGVerticalFrame *ret = new TGVerticalFrame();
02134    ret->SetCleanup(kDeepCleanup);
02135    TGHorizontalFrame *v1 = new TGHorizontalFrame(ret, 10, 40, kSunkenFrame |
02136                                                  kFixedHeight);
02137    ret->AddFrame(v1, new TGLayoutHints(kLHintsTop | kLHintsExpandX));
02138    //v1->SetEditDisabled(kEditDisableGrab);
02139 
02140    TGHSplitter *splitter = new TGHSplitter(ret);
02141    splitter->SetFrame(v1, kTRUE);
02142    ret->AddFrame(splitter, new TGLayoutHints(kLHintsTop | kLHintsExpandX));
02143    splitter->SetEditDisabled(kEditDisable);
02144 
02145    TGHorizontalFrame *v2 = new TGHorizontalFrame(ret, 10, 10);
02146    v2->ChangeOptions(kSunkenFrame);
02147    ret->AddFrame(v2, new TGLayoutHints(kLHintsBottom | kLHintsExpandX |
02148                  kLHintsExpandY));
02149    //v2->SetEditDisabled(kEditDisableGrab);
02150    ret->SetEditDisabled(kEditDisableLayout);
02151 
02152    ret->MapSubwindows();
02153    ret->SetLayoutBroken(kFALSE);
02154    return ret;
02155 }
02156 
02157 //______________________________________________________________________________
02158 void TRootGuiBuilder::Hide()
02159 {
02160    // Hide builder.
02161 
02162    //fMain->CloseAll();
02163    UnmapWindow();
02164 }
02165 
02166 //______________________________________________________________________________
02167 ULong_t TRootGuiBuilder::GetBgnd()
02168 {
02169    // Return default background color.
02170 
02171    static ULong_t gPixel = 0;
02172 
02173    if (gPixel) return gPixel;
02174 
02175    Float_t r, g, b;
02176 
02177    r = 232./255;
02178    g = 232./255;
02179    b = 222./255;
02180 
02181    gPixel = TColor::RGB2Pixel(r, g, b);
02182    return gPixel;
02183 }
02184 
02185 //______________________________________________________________________________
02186 TGGC *TRootGuiBuilder::GetBgndGC()
02187 {
02188    // Return background GC.
02189 
02190    if (fgBgnd) return fgBgnd;
02191 
02192    fgBgnd = new TGGC(TGFrame::GetBckgndGC());
02193 
02194    Pixel_t back = GetBgnd();
02195    fgBgnd->SetBackground(back);
02196    fgBgnd->SetForeground(back);
02197 
02198    return fgBgnd;
02199 }
02200 
02201 //______________________________________________________________________________
02202 void TRootGuiBuilder::PropagateBgndColor(TGFrame *frame, Pixel_t color)
02203 {
02204    // Set a background color to frame and all its subframes.
02205 
02206    if (!frame) return;
02207 
02208    frame->SetBackgroundColor(color);
02209    if (!frame->InheritsFrom(TGCompositeFrame::Class())) return;
02210 
02211    TIter next(((TGCompositeFrame*)frame)->GetList());
02212    TGFrameElement *fe;
02213 
02214    while ((fe = (TGFrameElement*)next())) {
02215       if (fe->fFrame->GetBackground() == TGFrame::GetWhitePixel()) {
02216          continue;
02217       }
02218       PropagateBgndColor(fe->fFrame, color);
02219    }
02220 }
02221 
02222 //______________________________________________________________________________
02223 ULong_t TRootGuiBuilder::GetPopupBgnd()
02224 {
02225    // Return background color for popup menus.
02226 
02227    static ULong_t gPixel = 0;
02228 
02229    if (gPixel) return gPixel;
02230 
02231    Float_t r, g, b;
02232 
02233    r = 250./255;
02234    g = 250./255;
02235    b = 250./255;
02236 
02237    gPixel = TColor::RGB2Pixel(r, g, b);
02238 
02239    return gPixel;
02240 }
02241 
02242 //______________________________________________________________________________
02243 TGGC *TRootGuiBuilder::GetPopupBgndGC()
02244 {
02245    // Return background GC for popup menus.
02246 
02247    if (fgBgndPopup) return fgBgndPopup;
02248 
02249    fgBgndPopup = new TGGC(TGFrame::GetBckgndGC());
02250 
02251    Pixel_t back = GetPopupBgnd();
02252    fgBgndPopup->SetBackground(back);
02253    fgBgndPopup->SetForeground(back);
02254 
02255    return fgBgndPopup;
02256 }
02257 
02258 //______________________________________________________________________________
02259 ULong_t TRootGuiBuilder::GetPopupHlght()
02260 {
02261    // Return highlighted color for popup menu entry.
02262 
02263    static ULong_t gPixel = 0;
02264 
02265    if (gPixel) return gPixel;
02266 
02267    Float_t r, g, b;
02268 
02269    r = 120./255;
02270    g = 120./255;
02271    b = 222./255;
02272 
02273    gPixel = TColor::RGB2Pixel(r, g, b);
02274 
02275    return gPixel;
02276 }
02277 
02278 //______________________________________________________________________________
02279 TGGC *TRootGuiBuilder::GetPopupHlghtGC()
02280 {
02281    // Return background GC for highlighted popup menu entry.
02282 
02283    if (fgBgndPopupHlght) return fgBgndPopupHlght;
02284 
02285    fgBgndPopupHlght = new TGGC(TGFrame::GetHilightGC());
02286 
02287    Pixel_t back = GetPopupHlght();
02288    fgBgndPopupHlght->SetBackground(back);
02289    fgBgndPopupHlght->SetForeground(back);
02290 
02291    return fgBgndPopupHlght;
02292 }
02293 
02294 //______________________________________________________________________________
02295 TGPopupMenu *TRootGuiBuilder::CreatePopup()
02296 {
02297    // Return style popup menu.
02298 
02299    return new TGuiBldPopupMenu();
02300 }
02301 
02302 //______________________________________________________________________________
02303 TGFrame *TRootGuiBuilder::BuildListTree()
02304 {
02305    // Helper method used in guibuilding
02306 
02307    TGCanvas *canvas = new TGCanvas(gClient->GetRoot(), 100, 100);
02308    TGListTree *lt = new TGListTree(canvas, kHorizontalFrame);
02309    lt->AddItem(0, "Entry 1");
02310    lt->AddItem(0, "Entry 2");
02311    lt->AddItem(0, "Entry 3");
02312    lt->AddItem(0, "Entry 4");
02313    lt->AddItem(0, "Entry 5");
02314    canvas->Resize(100, 60);
02315    canvas->MapSubwindows();
02316 
02317    return canvas;
02318 }
02319 
02320 //______________________________________________________________________________
02321 TGFrame *TRootGuiBuilder::BuildCanvas()
02322 {
02323    // Helper method used in guibuilding to create TGCanvas widget
02324 
02325    TGCanvas *canvas = new TGCanvas(gClient->GetRoot(), 100, 100);
02326    TGCompositeFrame *cont = new TGCompositeFrame(canvas->GetViewPort(),
02327                                                  200, 200, kHorizontalFrame |
02328                                                  kOwnBackground);
02329 
02330    cont->SetCleanup(kDeepCleanup);
02331    cont->SetLayoutManager(new TGTileLayout(cont, 8));
02332    cont->AddFrame(new TGTextButton(cont, "Button1"));
02333    cont->AddFrame(new TGTextButton(cont, "Button2"));
02334    cont->AddFrame(new TGTextButton(cont, "Button3"));
02335    cont->AddFrame(new TGTextButton(cont, "Button4"));
02336 
02337    canvas->SetContainer(cont);
02338    return canvas;
02339 }
02340 
02341 //______________________________________________________________________________
02342 TGFrame *TRootGuiBuilder::BuildShutter()
02343 {
02344    // Helper method used in guibuilding to create TGShutter widget
02345 
02346    TGShutterItem *item;
02347    TGCompositeFrame *container;
02348    const TGPicture  *buttonpic;
02349    TGPictureButton  *button;
02350 
02351    TGLayoutHints *l = new TGLayoutHints(kLHintsTop | kLHintsCenterX,5,5,5,0);
02352    TGShutter *shut = new TGShutter();
02353 
02354    item = shut->AddPage("Histograms");
02355    container = (TGCompositeFrame *)item->GetContainer();
02356    buttonpic = gClient->GetPicture("h1_s.xpm");
02357 
02358    if (buttonpic) {
02359       button = new TGPictureButton(container, buttonpic);
02360       button->SetToolTipText("TH1");
02361       container->AddFrame(button, l);
02362    }
02363    buttonpic = gClient->GetPicture("h2_s.xpm");
02364 
02365    if (buttonpic) {
02366       button = new TGPictureButton(container, buttonpic);
02367       button->SetToolTipText("TH2");
02368       container->AddFrame(button, l);
02369    }
02370    buttonpic = gClient->GetPicture("h3_s.xpm");
02371 
02372    if (buttonpic) {
02373       button = new TGPictureButton(container, buttonpic);
02374       button->SetToolTipText("TH3");
02375       container->AddFrame(button, l);
02376    }
02377    buttonpic = gClient->GetPicture("profile_s.xpm");
02378 
02379    if (buttonpic) {
02380       button = new TGPictureButton(container, buttonpic);
02381       button->SetToolTipText("TProfile");
02382       container->AddFrame(button, l);
02383    }
02384 
02385    // new page
02386    item = shut->AddPage("Functions");
02387    container = (TGCompositeFrame *)item->GetContainer();
02388    buttonpic = gClient->GetPicture("f1_s.xpm");
02389 
02390    if (buttonpic) {
02391       button = new TGPictureButton(container, buttonpic);
02392       button->SetToolTipText("TF1");
02393       container->AddFrame(button, l);
02394    }
02395    buttonpic = gClient->GetPicture("f2_s.xpm");
02396 
02397    if (buttonpic) {
02398       button = new TGPictureButton(container, buttonpic);
02399       button->SetToolTipText("TF2");
02400       container->AddFrame(button, l);
02401    }
02402 
02403    // new page
02404    item = shut->AddPage("Trees");
02405    container = (TGCompositeFrame *)item->GetContainer();
02406    buttonpic = gClient->GetPicture("ntuple_s.xpm");
02407 
02408    if (buttonpic) {
02409       button = new TGPictureButton(container, buttonpic);
02410       button->SetToolTipText("TNtuple");
02411       container->AddFrame(button, l);
02412    }
02413    buttonpic = gClient->GetPicture("tree_s.xpm");
02414 
02415    if (buttonpic) {
02416       button = new TGPictureButton(container, buttonpic);
02417       button->SetToolTipText("TTree");
02418       container->AddFrame(button, l);
02419    }
02420    buttonpic = gClient->GetPicture("chain_s.xpm");
02421 
02422    if (buttonpic) {
02423       button = new TGPictureButton(container, buttonpic);
02424       button->SetToolTipText("TChain");
02425       container->AddFrame(button, l);
02426    }
02427 
02428    shut->MapSubwindows();
02429    return shut;
02430 }
02431 
02432 //______________________________________________________________________________
02433 TGFrame *TRootGuiBuilder::BuildTextEdit()
02434 {
02435    // Helper method to create TGTextEdit widget
02436 
02437    TGTextEdit *te = new TGTextEdit();
02438 
02439    te->AddLine("all work and no play makes jack a pretty");
02440    te->AddLine("dull boy. all work and no play makes jack");
02441    te->AddLine("a pretty dull boy. all work and no play ");
02442    te->AddLine("makes jack a pretty dull boy. all work");
02443    te->AddLine("and no play makes jack a pretty dull boy.");
02444 
02445    te->MapSubwindows();
02446    te->Layout();
02447    te->Resize(100, 60);
02448 
02449    return te;
02450 }
02451 
02452 //______________________________________________________________________________
02453 TGFrame *TRootGuiBuilder::BuildTab()
02454 {
02455    // Helper method to create TGTab widget
02456 
02457    TGTab *tab = new TGTab();
02458 
02459    tab->AddTab("Tab1");
02460    tab->AddTab("Tab2");
02461    tab->MapSubwindows();
02462 
02463    return tab;
02464 }
02465 
02466 //______________________________________________________________________________
02467 TGFrame *TRootGuiBuilder::BuildListBox()
02468 {
02469    // Helper method to create TGListBox widget
02470 
02471    TGListBox *lb = new TGListBox();
02472 
02473    lb->AddEntry("Entry 1", 0);
02474    lb->AddEntry("Entry 2", 1);
02475    lb->AddEntry("Entry 3", 2);
02476    lb->AddEntry("Entry 4", 3);
02477    lb->AddEntry("Entry 5", 4);
02478    lb->AddEntry("Entry 6", 5);
02479    lb->AddEntry("Entry 7", 6);
02480    lb->MapSubwindows();
02481 
02482    lb->Resize(100,100);
02483 
02484    return lb;
02485 }
02486 
02487 //______________________________________________________________________________
02488 TGFrame *TRootGuiBuilder::BuildComboBox()
02489 {
02490    // Helper method to create TGComboBox widget
02491 
02492    TGComboBox *cb = new TGComboBox();
02493 
02494    cb->AddEntry("Entry 1 ", 0);
02495    cb->AddEntry("Entry 2 ", 1);
02496    cb->AddEntry("Entry 3 ", 2);
02497    cb->AddEntry("Entry 4 ", 3);
02498    cb->AddEntry("Entry 5 ", 4);
02499    cb->AddEntry("Entry 6 ", 5);
02500    cb->AddEntry("Entry 7 ", 6);
02501    cb->MapSubwindows();
02502 
02503    FontStruct_t fs = TGTextLBEntry::GetDefaultFontStruct();
02504    int max_ascent, max_descent;
02505    gVirtualX->GetFontProperties(fs, max_ascent, max_descent);
02506 
02507    cb->Resize(cb->GetListBox()->GetDefaultWidth(), max_ascent+max_descent+7);
02508    return cb;
02509 }
02510 
02511 //______________________________________________________________________________
02512 TGFrame *TRootGuiBuilder::BuildH3DLine()
02513 {
02514    // Helper method to create TGHorizontal3DLine widget.
02515 
02516    TGHorizontal3DLine *l = new TGHorizontal3DLine(0, 100, 2);
02517    l->Resize(100, 2);
02518 
02519    return l;
02520 }
02521 
02522 //______________________________________________________________________________
02523 TGFrame *TRootGuiBuilder::BuildV3DLine()
02524 {
02525    // Helper method to create TGVertical3DLine widget.
02526 
02527    TGVertical3DLine *l = new TGVertical3DLine();
02528    l->Resize(2, 100);
02529 
02530    return l;
02531 }
02532 
02533 //______________________________________________________________________________
02534 TGFrame *TRootGuiBuilder::BuildHScrollBar()
02535 {
02536    // Helper method to create TGHScrollBar
02537 
02538    TGHScrollBar *b = new TGHScrollBar();
02539 
02540    b->Resize(100, b->GetDefaultHeight());
02541    b->SetRange(100, 20);
02542    b->MapSubwindows();
02543 
02544    return b;
02545 }
02546 
02547 //______________________________________________________________________________
02548 TGFrame *TRootGuiBuilder::BuildVScrollBar()
02549 {
02550    // Helper method to create TGVScrollBar
02551 
02552    TGVScrollBar *b = new TGVScrollBar();
02553 
02554    b->Resize(b->GetDefaultWidth(), 100);
02555    b->MapSubwindows();
02556    b->SetRange(100, 20);
02557 
02558    return b;
02559 }
02560 
02561 //______________________________________________________________________________
02562 TGFrame *TRootGuiBuilder::BuildHProgressBar()
02563 {
02564    // Helper method to create TGHProgressBar
02565 
02566    TGHProgressBar *b = new TGHProgressBar();
02567 
02568    b->Resize(100, b->GetDefaultHeight());
02569    b->SetPosition(25);
02570    b->Format("%.2f");
02571    b->SetFillType(TGProgressBar::kBlockFill);
02572 
02573    return b;
02574 }
02575 
02576 //______________________________________________________________________________
02577 TGFrame *TRootGuiBuilder::BuildVProgressBar()
02578 {
02579    // Helper method to create TGVProgressBar
02580 
02581    TGVProgressBar *b = new TGVProgressBar();
02582 
02583    b->Resize(b->GetDefaultWidth(), 100);
02584    b->SetPosition(25);
02585    b->SetFillType(TGProgressBar::kBlockFill);
02586 
02587    return b;
02588 }
02589 
02590 

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