TRootControlBar.cxx

Go to the documentation of this file.
00001 // @(#)root/gui:$Id: TRootControlBar.cxx 23115 2008-04-10 13:35:37Z rdm $
00002 // Author: Fons Rademakers   22/02/98
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 //////////////////////////////////////////////////////////////////////////
00013 //                                                                      //
00014 // TRootControlBar                                                      //
00015 //                                                                      //
00016 // This class provides an interface to the GUI dependent functions of   //
00017 // the TControlBar class. A control bar is a horizontal or vertical bar //
00018 // with a number of buttons (text or picture buttons).                  //
00019 //                                                                      //
00020 //////////////////////////////////////////////////////////////////////////
00021 
00022 #include "TRootControlBar.h"
00023 #include "TControlBar.h"
00024 #include "TList.h"
00025 #include "TGButton.h"
00026 
00027 
00028 ClassImp(TRootControlBar)
00029 
00030 //______________________________________________________________________________
00031 TRootControlBar::TRootControlBar(TControlBar *c, const char *title, Int_t x, Int_t y)
00032    : TGMainFrame(gClient->GetRoot(), 10, 10), TControlBarImp(c)
00033 {
00034    // Create a ROOT native GUI controlbar.
00035 
00036    fWidgets = 0;
00037    fXpos    = x;
00038    fYpos    = y;
00039    fBwidth  = 0;
00040    fClicked = 0;
00041    SetCleanup(kDeepCleanup);
00042 
00043    // if controlbar orientation is horizontal change layout manager
00044    if (c && c->GetOrientation() == TControlBar::kHorizontal) {
00045       ChangeOptions(kHorizontalFrame);
00046       fL1 = new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1);
00047    } else
00048       fL1 = new TGLayoutHints(kLHintsCenterY | kLHintsExpandX, 1, 1, 1, 1);
00049 
00050    SetWindowName(title);
00051    SetIconName(title);
00052 }
00053 
00054 //______________________________________________________________________________
00055 TRootControlBar::~TRootControlBar()
00056 {
00057    // Delete the control bar implementation.
00058 
00059    delete fWidgets;
00060    fWidgets = 0;
00061 }
00062 
00063 //______________________________________________________________________________
00064 void TRootControlBar::Create()
00065 {
00066    // Create the control bar. Loop over all buttons defined in the
00067    // TControlBar and create the buttons.
00068 
00069    fWidgets = new TList;
00070    TGButton *b = 0;
00071 
00072    TControlBarButton *button;
00073    TIter next(fControlBar->GetListOfButtons());
00074 
00075    while ((button = (TControlBarButton *) next())) {
00076 
00077       switch (button->GetType()) {
00078 
00079          case TControlBarButton::kSeparator:
00080             Warning("Create", "separators not yet supported");
00081             break;
00082 
00083          case TControlBarButton::kDrawnButton:
00084             Warning("Create", "picture buttons not yet supported");
00085             break;
00086 
00087          case TControlBarButton::kButton:
00088             {
00089                b = new TGTextButton(this, button->GetName());
00090                b->SetToolTipText(button->GetTitle());
00091                b->SetUserData(button);
00092                AddFrame(b, fL1);
00093                fWidgets->Add(b);
00094                if (fBwidth < b->GetDefaultWidth())
00095                   fBwidth = b->GetDefaultWidth();  //do not cut the label
00096             }
00097             break;
00098       }
00099    }
00100 
00101    MapSubwindows();
00102    Resize(GetDefaultSize());
00103 
00104    SetMWMHints(kMWMDecorAll | kMWMDecorResizeH,
00105                kMWMFuncAll  | kMWMFuncResize    | kMWMFuncMaximize,
00106                kMWMInputModeless);
00107 
00108    if (fXpos != -999) {
00109       Move(fXpos, fYpos);
00110       SetWMPosition(fXpos, fYpos);
00111    }
00112    if (GetOptions() & kHorizontalFrame)
00113       SetWMSize(fBwidth*fWidgets->GetSize(), GetHeight());
00114    else
00115       SetWMSize(fBwidth, GetHeight());
00116 }
00117 
00118 //______________________________________________________________________________
00119 void TRootControlBar::Show()
00120 {
00121    // Show controlbar. If not yet created create it first.
00122 
00123    if (!fWidgets) Create();
00124 
00125    MapRaised();
00126 }
00127 
00128 //______________________________________________________________________________
00129 void TRootControlBar::Hide()
00130 {
00131    // Hide controlbar.
00132 
00133    UnmapWindow();
00134 }
00135 
00136 //______________________________________________________________________________
00137 Bool_t TRootControlBar::ProcessMessage(Long_t, Long_t, Long_t parm2)
00138 {
00139    // Handle controlbar button messages.
00140 
00141    TControlBarButton *button = (TControlBarButton *) parm2;
00142 
00143    if (button) {
00144       fClicked = button;
00145       button->Action();
00146    }
00147    return kTRUE;
00148 }
00149 
00150 //______________________________________________________________________________
00151 void TRootControlBar::ReallyDelete()
00152 {
00153    // Really delete the control bar and the this GUI.
00154 
00155    delete fControlBar;    // will in turn delete this object
00156 }
00157 
00158 //______________________________________________________________________________
00159 void TRootControlBar::CloseWindow()
00160 {
00161    // Called when closed via window manager action.
00162 
00163    DeleteWindow();        // but do it slightly delayed here
00164 }
00165 
00166 //______________________________________________________________________________
00167 void TRootControlBar::SetFont(const char *fontName)
00168 {
00169    // sets new font for control bar buttons
00170 
00171    TIter next(fWidgets);
00172 
00173    TObject *obj;
00174    
00175    while ((obj=next())) {
00176       if (!obj->InheritsFrom(TGTextButton::Class())) continue;
00177 
00178       ((TGTextButton *)obj)->SetFont(fontName);
00179    }
00180    Resize();
00181 }
00182 
00183 //______________________________________________________________________________
00184 void TRootControlBar::SetButtonState(const char *label, Int_t state)
00185 {
00186    // sets new font for control bar buttons
00187 
00188    TIter next(fWidgets);
00189 
00190    TObject *obj;
00191    
00192    while ((obj=next())) {
00193       if (!obj->InheritsFrom(TGTextButton::Class())) continue;
00194 
00195       if (!strcmp(((TGTextButton *)obj)->GetTitle(), label)) {
00196          switch (state) {
00197             case 0: {
00198                ((TGTextButton *)obj)->SetState(kButtonUp);
00199                break;
00200             }
00201             case 1: {
00202                ((TGTextButton *)obj)->SetState(kButtonDown);
00203                break;
00204             }
00205             case 2: {
00206                ((TGTextButton *)obj)->SetState(kButtonEngaged);
00207                break;
00208             }
00209             case 3: {
00210                ((TGTextButton *)obj)->SetState(kButtonDisabled);
00211                break;
00212             }
00213             default: {
00214                Error("SetButtonState", "not valid button state (expecting 0, 1, 2 or 3)");
00215                break;
00216             }
00217          }
00218       }
00219    }
00220    Resize();
00221 }
00222 
00223 //______________________________________________________________________________
00224 void TRootControlBar::SetTextColor(const char *colorName)
00225 {
00226    // sets text color for control bar buttons, e.g.:
00227    // root > .x tutorials/demos.C
00228    // root > bar->SetTextColor("red")
00229 
00230    Pixel_t color;
00231    gClient->GetColorByName(colorName, color);
00232    
00233    if (!fWidgets) Create();
00234    
00235    TIter next(fWidgets);
00236 
00237    TObject *obj;
00238    
00239    while ((obj=next())) {
00240       if (!obj->InheritsFrom(TGTextButton::Class())) continue;
00241 
00242       ((TGTextButton *)obj)->SetTextColor(color);
00243    }
00244    Resize();
00245 }
00246 
00247 //______________________________________________________________________________
00248 void TRootControlBar::SetButtonWidth(UInt_t width)
00249 {
00250    // Set button width in pixels.
00251    
00252    fBwidth = width;
00253 }

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