00001 // @(#)root/gpad:$Id: TControlBar.cxx 20882 2007-11-19 11:31:26Z rdm $ 00002 // Author: Nenad Buncic 20/02/96 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 // ControlBar is fully user configurable tool which provides fast // 00015 // access to frequently used operations. User can choose between // 00016 // buttons and drawnbuttons (let's say icons) and assign to them his // 00017 // own actions (let's say ROOT or C++ commands). // 00018 // 00019 // The macro belows shows an example of controlbar. 00020 // To execute an item, click with the left mouse button. 00021 // To see the HELP of a button, click on the right mouse button. 00022 // 00023 // You have access to the last clicked button via the method 00024 // GetClicked(). For example, bar->GetClicked()->GetName() 00025 // will return the name of the last clicked button. 00026 // 00027 // 00028 //{ 00029 // gROOT.Reset("a"); 00030 // TControlBar bar("vertical"); 00031 // bar.AddButton("Help to run demos",".x demoshelp.C", 00032 // "Explains how to run the demos"); 00033 // bar.AddButton("framework", ".x framework.C", 00034 // "An Example of Object Oriented User Interface"); 00035 // bar.AddButton("hsimple", ".x hsimple.C", 00036 // "An Example Creating Histograms/Ntuples on File"); 00037 // bar.AddButton("hsum", ".x hsum.C", 00038 // "Filling histograms and some graphics options"); 00039 // bar.AddButton("canvas", ".x canvas.C", 00040 // "Canvas and Pad Management"); 00041 // bar.AddButton("formula1", ".x formula1.C", 00042 // "Simple Formula and Functions"); 00043 // bar.AddButton("fillrandom", ".x fillrandom.C", 00044 // "Histograms with Random Numbers from a Function"); 00045 // bar.AddButton("fit1", ".x fit1.C", 00046 // "A Simple Fitting Example"); 00047 // bar.AddButton("h1draw", ".x h1draw.C", 00048 // "Drawing Options for 1D Histograms"); 00049 // bar.AddButton("graph", ".x graph.C", 00050 // "Examples of a simple graph"); 00051 // bar.AddButton("tornado", ".x tornado.C", 00052 // "Examples of 3-D PolyMarkers"); 00053 // bar.AddButton("shapes", ".x shapes.C", 00054 // "The Geometry Shapes"); 00055 // bar.AddButton("atlasna49", ".x atlasna49.C", 00056 // "Creating and Viewing Geometries"); 00057 // bar.AddButton("file_layout", ".x file.C", 00058 // "The ROOT file format"); 00059 // bar.AddButton("tree_layout", ".x tree.C", 00060 // "The Tree Data Structure"); 00061 // bar.AddButton("ntuple1", ".x ntuple1.C", 00062 // "Ntuples and Selections"); 00063 // bar.AddButton("run benchmarks", ".x benchmarks.C", 00064 // "Runs all the ROOT benchmarks"); 00065 // bar.AddButton("rootmarks", ".x rootmarks.C", 00066 // "Prints an estimated ROOTMARKS for your machine"); 00067 // bar.AddButton("edit_hsimple", ".!ved hsimple.C &", 00068 // "Invokes the text editor on file hsimple.C"); 00069 // bar.AddButton("Close Bar", "gROOT.Reset(\"a\")", 00070 // "Close ControlBar"); 00071 // bar.Show(); 00072 // gROOT.SaveContext(); 00073 //} 00074 // 00075 //Begin_Html 00076 /* 00077 <img src="gif/controlbar.gif"> 00078 */ 00079 //End_Html 00080 // 00081 // // 00082 ///////////////////////////////////////////////////////////////////////// 00083 00084 #include "TControlBar.h" 00085 #include "TGuiFactory.h" 00086 #include "TList.h" 00087 #include "TStyle.h" 00088 00089 00090 ClassImp(TControlBar) 00091 00092 00093 //_______________________________________________________________________ 00094 TControlBar::TControlBar() : TControlBarButton() 00095 { 00096 // Default constructor. 00097 00098 fControlBarImp = 0; 00099 fOrientation = 0; 00100 fButtons = 0; 00101 fNoroc = 1; 00102 } 00103 00104 00105 //_______________________________________________________________________ 00106 TControlBar::TControlBar(const char *orientation, const char *title) 00107 : TControlBarButton(title, "", "", "button") 00108 00109 { 00110 // Normal constructor. 00111 00112 SetOrientation( orientation ); 00113 Initialize(-999, -999); 00114 } 00115 00116 00117 //_______________________________________________________________________ 00118 TControlBar::TControlBar(const char *orientation, const char *title, Int_t x, Int_t y) 00119 : TControlBarButton(title, "", "", "button") 00120 00121 { 00122 // Normal constructor. 00123 00124 Int_t xs = (Int_t)(x*gStyle->GetScreenFactor()); 00125 Int_t ys = (Int_t)(y*gStyle->GetScreenFactor()); 00126 SetOrientation( orientation ); 00127 Initialize(xs, ys); 00128 } 00129 00130 00131 //_______________________________________________________________________ 00132 TControlBar::~TControlBar() 00133 { 00134 // Destructor. 00135 00136 delete fControlBarImp; 00137 00138 if( fButtons ) 00139 fButtons->Delete(); 00140 00141 fButtons = 0; 00142 fControlBarImp = 0; 00143 } 00144 00145 00146 //_______________________________________________________________________ 00147 void TControlBar::AddButton(TControlBarButton &button) 00148 { 00149 // Add button. 00150 00151 AddButton( &button ); 00152 } 00153 00154 00155 //_______________________________________________________________________ 00156 void TControlBar::AddButton(TControlBarButton *button) 00157 { 00158 // Add button. 00159 00160 if( fButtons && button ) 00161 fButtons->Add( button ); 00162 } 00163 00164 00165 //_______________________________________________________________________ 00166 void TControlBar::AddButton(const char *label, const char *action, const char *hint, const char *type) 00167 { 00168 // Add button. 00169 00170 TControlBarButton *button = new TControlBarButton( label, action, hint, type ); 00171 AddButton( button ); 00172 } 00173 00174 00175 //_______________________________________________________________________ 00176 void TControlBar::AddControlBar(TControlBar &controlBar) 00177 { 00178 // Add controlbar. 00179 00180 AddControlBar( &controlBar ); 00181 } 00182 00183 00184 //_______________________________________________________________________ 00185 void TControlBar::AddControlBar(TControlBar *controlBar) 00186 { 00187 // Add controlbar. 00188 00189 if( fButtons && controlBar ) 00190 fButtons->Add( controlBar ); 00191 } 00192 00193 00194 //_______________________________________________________________________ 00195 void TControlBar::AddSeparator() 00196 { 00197 // Add separator. 00198 } 00199 00200 00201 //_______________________________________________________________________ 00202 void TControlBar::Create() 00203 { 00204 // Create controlbar. 00205 00206 if( fControlBarImp ) { 00207 fControlBarImp->Create(); 00208 } 00209 } 00210 00211 00212 //_______________________________________________________________________ 00213 void TControlBar::Hide() 00214 { 00215 // Hide controlbar. 00216 00217 if( fControlBarImp ) { 00218 fControlBarImp->Hide(); 00219 } 00220 } 00221 00222 00223 //_______________________________________________________________________ 00224 void TControlBar::Initialize(Int_t x, Int_t y) 00225 { 00226 // Initialize controlbar. 00227 00228 if (x == -999) { 00229 fControlBarImp = gGuiFactory->CreateControlBarImp( this, GetName() ); 00230 } else { 00231 fControlBarImp = gGuiFactory->CreateControlBarImp( this, GetName(), x, y ); 00232 } 00233 00234 fButtons = new TList(); 00235 fNoroc = 1; 00236 } 00237 00238 00239 //_______________________________________________________________________ 00240 void TControlBar::SetFont(const char *fontName) 00241 { 00242 // Sets new font for control bar buttons, e.g.: 00243 // root > .x tutorials/demos.C 00244 // root > bar->SetFont("-adobe-helvetica-bold-r-*-*-24-*-*-*-*-*-iso8859-1") 00245 00246 fControlBarImp->SetFont(fontName); 00247 } 00248 00249 00250 //_______________________________________________________________________ 00251 void TControlBar::SetTextColor(const char *colorName) 00252 { 00253 // Sets text color for control bar buttons, e.g.: 00254 // root > .x tutorials/demos.C 00255 // root > bar->SetTextColor("red") 00256 00257 fControlBarImp->SetTextColor(colorName); 00258 } 00259 00260 00261 //_______________________________________________________________________ 00262 void TControlBar::SetButtonState(const char *label, Int_t state) 00263 { 00264 // Sets a state for control bar button 'label'; possible states are 00265 // 0-kButtonUp, 1-kButtonDown, 2-kButtonEngaged, 3-kButtonDisabled, 00266 // e.g.: 00267 // root > .x tutorials/demos.C 00268 // to disable the button 'first' do: 00269 // root > bar->SetButtonState("first", 3) 00270 // to enable the button 'first' do: 00271 // root > bar->SetButtonState("first", 0) 00272 00273 if (state > 3) { 00274 Error("SetButtonState", "not valid button state (expecting 0, 1, 2 or 3)"); 00275 return; 00276 } 00277 fControlBarImp->SetButtonState(label, state); 00278 } 00279 00280 00281 //_______________________________________________________________________ 00282 void TControlBar::SetButtonWidth(UInt_t width) 00283 { 00284 // Sets the width in pixels for control bar button. 00285 00286 fControlBarImp->SetButtonWidth(width); 00287 } 00288 00289 00290 //_______________________________________________________________________ 00291 void TControlBar::SetOrientation(const char *o) 00292 { 00293 // Set controlbar orientation. 00294 00295 fOrientation = kVertical; 00296 00297 if( *o ) { 00298 if( !strcasecmp( o, "vertical" ) ) 00299 fOrientation = kVertical; 00300 else if( !strcasecmp( o, "horizontal" ) ) 00301 fOrientation = kHorizontal; 00302 else 00303 Error( "SetOrientation", "Unknown orientation: '%s' !\n\t\t(choice of: %s, %s)", 00304 o, "vertical", "horizontal" ); 00305 } 00306 } 00307 00308 00309 //_______________________________________________________________________ 00310 void TControlBar::SetOrientation(Int_t o) 00311 { 00312 // Set controlbar orientation. 00313 00314 fOrientation = kVertical; 00315 00316 if( ( o == kVertical ) || ( o == kHorizontal ) ) 00317 fOrientation = o; 00318 else 00319 Error( "SetOrientation", "Unknown orientation: %d !\n\t\t(choice of: %d, %d)", 00320 o, kVertical, kHorizontal ); 00321 } 00322 00323 00324 00325 //_______________________________________________________________________ 00326 void TControlBar::Show() 00327 { 00328 // Show controlbar. 00329 00330 if( fControlBarImp ) 00331 fControlBarImp->Show(); 00332 } 00333 00334 00335 //_______________________________________________________________________ 00336 TControlBarButton *TControlBar::GetClicked() const 00337 { 00338 // Returns a pointer to the last clicked controlbar button; 00339 // null if no button was clicked yet 00340 00341 if (!fControlBarImp->GetClicked()) 00342 Printf("None of the controlbar buttons is clicked yet"); 00343 return fControlBarImp->GetClicked(); 00344 }