ROOT logo
// @(#)root/gpad:$Id$
// Author: Nenad Buncic   20/02/96

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

/////////////////////////////////////////////////////////////////////////
//                                                                     //
//   ControlBar is fully user configurable tool which provides fast    //
// access to frequently used operations. User can choose between       //
// buttons and drawnbuttons (let's say icons) and assign to them his   //
// own actions (let's say ROOT or C++ commands).                       //
//
// The macro belows shows an example of controlbar.
// To execute an item, click with the left mouse button.
// To see the HELP of a button, click on the right mouse button.
// 
// You have access to the last clicked button via the method
// GetClicked(). For example, bar->GetClicked()->GetName() 
// will return the name of the last clicked button. 
// 
//
//{
//   gROOT.Reset("a");
//   TControlBar bar("vertical");
//   bar.AddButton("Help to run demos",".x demoshelp.C",
//                 "Explains how to run the demos");
//   bar.AddButton("framework",        ".x framework.C",
//                 "An Example of Object Oriented User Interface");
//   bar.AddButton("hsimple",          ".x hsimple.C",
//                 "An Example Creating Histograms/Ntuples on File");
//   bar.AddButton("hsum",             ".x hsum.C",
//                 "Filling histograms and some graphics options");
//   bar.AddButton("canvas",           ".x canvas.C",
//                 "Canvas and Pad Management");
//   bar.AddButton("formula1",         ".x formula1.C",
//                 "Simple Formula and Functions");
//   bar.AddButton("fillrandom",       ".x fillrandom.C",
//                 "Histograms with Random Numbers from a Function");
//   bar.AddButton("fit1",             ".x fit1.C",
//                 "A Simple Fitting Example");
//   bar.AddButton("h1draw",           ".x h1draw.C",
//                 "Drawing Options for 1D Histograms");
//   bar.AddButton("graph",            ".x graph.C",
//                 "Examples of a simple graph");
//   bar.AddButton("tornado",          ".x tornado.C",
//                 "Examples of 3-D PolyMarkers");
//   bar.AddButton("shapes",           ".x shapes.C",
//                 "The Geometry Shapes");
//   bar.AddButton("atlasna49",        ".x atlasna49.C",
//                 "Creating and Viewing Geometries");
//   bar.AddButton("file_layout",      ".x file.C",
//                 "The ROOT file format");
//   bar.AddButton("tree_layout",      ".x tree.C",
//                 "The Tree Data Structure");
//   bar.AddButton("ntuple1",          ".x ntuple1.C",
//                 "Ntuples and Selections");
//   bar.AddButton("run benchmarks",   ".x benchmarks.C",
//                 "Runs all the ROOT benchmarks");
//   bar.AddButton("rootmarks",        ".x rootmarks.C",
//                 "Prints an estimated ROOTMARKS for your machine");
//   bar.AddButton("edit_hsimple",     ".!ved hsimple.C &",
//                 "Invokes the text editor on file hsimple.C");
//   bar.AddButton("Close Bar",        "gROOT.Reset(\"a\")",
//                 "Close ControlBar");
//   bar.Show();
//   gROOT.SaveContext();
//}
//
//Begin_Html
/*
<img src="gif/controlbar.gif">
*/
//End_Html
//
//                                                                     //
/////////////////////////////////////////////////////////////////////////

#include "TControlBar.h"
#include "TGuiFactory.h"
#include "TList.h"
#include "TStyle.h"


ClassImp(TControlBar)


//_______________________________________________________________________
TControlBar::TControlBar() : TControlBarButton()
{
   // Default constructor.

   fControlBarImp = 0;
   fOrientation   = 0;
   fButtons       = 0;
   fNoroc         = 1;
}


//_______________________________________________________________________
TControlBar::TControlBar(const char *orientation, const char *title)
            : TControlBarButton(title, "", "", "button")

{
   // Normal constructor.

   SetOrientation( orientation );
   Initialize(-999, -999);
}


//_______________________________________________________________________
TControlBar::TControlBar(const char *orientation, const char *title, Int_t x, Int_t y)
            : TControlBarButton(title, "", "", "button")

{
   // Normal constructor.

   Int_t xs = (Int_t)(x*gStyle->GetScreenFactor());
   Int_t ys = (Int_t)(y*gStyle->GetScreenFactor());
   SetOrientation( orientation );
   Initialize(xs, ys);
}


//_______________________________________________________________________
TControlBar::~TControlBar()
{
   // Destructor.

   delete fControlBarImp;

   if( fButtons )
      fButtons->Delete();

   fButtons       = 0;
   fControlBarImp = 0;
}


//_______________________________________________________________________
void TControlBar::AddButton(TControlBarButton &button)
{
   // Add button.

   AddButton( &button );
}


//_______________________________________________________________________
void TControlBar::AddButton(TControlBarButton *button)
{
   // Add button.

   if( fButtons && button )
      fButtons->Add( button );
}


//_______________________________________________________________________
void TControlBar::AddButton(const char *label, const char *action, const char *hint, const char *type)
{
   // Add button.

   TControlBarButton *button = new TControlBarButton( label, action, hint, type );
   AddButton( button );
}


//_______________________________________________________________________
void TControlBar::AddControlBar(TControlBar &controlBar)
{
   // Add controlbar.

   AddControlBar( &controlBar );
}


//_______________________________________________________________________
void TControlBar::AddControlBar(TControlBar *controlBar)
{
   // Add controlbar.

   if( fButtons && controlBar )
      fButtons->Add( controlBar );
}


//_______________________________________________________________________
void TControlBar::AddSeparator()
{
   // Add separator.
}


//_______________________________________________________________________
void TControlBar::Create()
{
   // Create controlbar.
  
   if( fControlBarImp ) {
      fControlBarImp->Create();
   }
}


//_______________________________________________________________________
void TControlBar::Hide()
{
   // Hide controlbar.

   if( fControlBarImp ) {
      fControlBarImp->Hide();
   }
}


//_______________________________________________________________________
void TControlBar::Initialize(Int_t x, Int_t y)
{
   // Initialize controlbar.

   if (x == -999) {
      fControlBarImp = gGuiFactory->CreateControlBarImp( this, GetName() );
   } else {
      fControlBarImp = gGuiFactory->CreateControlBarImp( this, GetName(), x, y );
   }
  
   fButtons       = new TList();
   fNoroc         = 1;
}


//_______________________________________________________________________
void TControlBar::SetFont(const char *fontName)
{
   // Sets new font for control bar buttons, e.g.:
   // root > .x tutorials/demos.C
   // root > bar->SetFont("-adobe-helvetica-bold-r-*-*-24-*-*-*-*-*-iso8859-1")

   fControlBarImp->SetFont(fontName);
}


//_______________________________________________________________________
void TControlBar::SetTextColor(const char *colorName)
{
   // Sets text color for control bar buttons, e.g.:
   // root > .x tutorials/demos.C
   // root > bar->SetTextColor("red")

   fControlBarImp->SetTextColor(colorName);
}


//_______________________________________________________________________
void TControlBar::SetButtonState(const char *label, Int_t state)
{
   // Sets a state for control bar button 'label'; possible states are
   // 0-kButtonUp, 1-kButtonDown, 2-kButtonEngaged, 3-kButtonDisabled,
   // e.g.:
   // root > .x tutorials/demos.C
   // to disable the button 'first' do:
   // root > bar->SetButtonState("first", 3)
   // to enable the button 'first' do:
   // root > bar->SetButtonState("first", 0)

   if (state > 3) {
      Error("SetButtonState", "not valid button state (expecting 0, 1, 2 or 3)");
      return;
   }
   fControlBarImp->SetButtonState(label, state);
}


 //_______________________________________________________________________
void TControlBar::SetButtonWidth(UInt_t width)
{
   // Sets the width in pixels for control bar button.

   fControlBarImp->SetButtonWidth(width);
}


//_______________________________________________________________________
void TControlBar::SetOrientation(const char *o)
{
   // Set controlbar orientation.

   fOrientation = kVertical;

   if( *o ) {
      if( !strcasecmp( o, "vertical" ) )
         fOrientation = kVertical;
      else if( !strcasecmp( o, "horizontal" ) )
         fOrientation = kHorizontal;
      else
         Error( "SetOrientation", "Unknown orientation: '%s' !\n\t\t(choice of: %s, %s)",
                 o, "vertical", "horizontal" );
   }
}


//_______________________________________________________________________
void TControlBar::SetOrientation(Int_t o)
{
   // Set controlbar orientation.

   fOrientation = kVertical;

   if( ( o == kVertical ) || ( o == kHorizontal ) )
      fOrientation = o;
   else
      Error( "SetOrientation", "Unknown orientation: %d !\n\t\t(choice of: %d, %d)",
              o, kVertical, kHorizontal );
}



//_______________________________________________________________________
void TControlBar::Show()
{
   // Show controlbar.

   if( fControlBarImp )
      fControlBarImp->Show();
}


//_______________________________________________________________________
TControlBarButton *TControlBar::GetClicked() const
{
   // Returns a pointer to the last clicked controlbar button;    
   // null if no button was clicked yet
   
   if (!fControlBarImp->GetClicked()) 
      Printf("None of the controlbar buttons is clicked yet");
   return fControlBarImp->GetClicked();
}
 TControlBar.cxx:1
 TControlBar.cxx:2
 TControlBar.cxx:3
 TControlBar.cxx:4
 TControlBar.cxx:5
 TControlBar.cxx:6
 TControlBar.cxx:7
 TControlBar.cxx:8
 TControlBar.cxx:9
 TControlBar.cxx:10
 TControlBar.cxx:11
 TControlBar.cxx:12
 TControlBar.cxx:13
 TControlBar.cxx:14
 TControlBar.cxx:15
 TControlBar.cxx:16
 TControlBar.cxx:17
 TControlBar.cxx:18
 TControlBar.cxx:19
 TControlBar.cxx:20
 TControlBar.cxx:21
 TControlBar.cxx:22
 TControlBar.cxx:23
 TControlBar.cxx:24
 TControlBar.cxx:25
 TControlBar.cxx:26
 TControlBar.cxx:27
 TControlBar.cxx:28
 TControlBar.cxx:29
 TControlBar.cxx:30
 TControlBar.cxx:31
 TControlBar.cxx:32
 TControlBar.cxx:33
 TControlBar.cxx:34
 TControlBar.cxx:35
 TControlBar.cxx:36
 TControlBar.cxx:37
 TControlBar.cxx:38
 TControlBar.cxx:39
 TControlBar.cxx:40
 TControlBar.cxx:41
 TControlBar.cxx:42
 TControlBar.cxx:43
 TControlBar.cxx:44
 TControlBar.cxx:45
 TControlBar.cxx:46
 TControlBar.cxx:47
 TControlBar.cxx:48
 TControlBar.cxx:49
 TControlBar.cxx:50
 TControlBar.cxx:51
 TControlBar.cxx:52
 TControlBar.cxx:53
 TControlBar.cxx:54
 TControlBar.cxx:55
 TControlBar.cxx:56
 TControlBar.cxx:57
 TControlBar.cxx:58
 TControlBar.cxx:59
 TControlBar.cxx:60
 TControlBar.cxx:61
 TControlBar.cxx:62
 TControlBar.cxx:63
 TControlBar.cxx:64
 TControlBar.cxx:65
 TControlBar.cxx:66
 TControlBar.cxx:67
 TControlBar.cxx:68
 TControlBar.cxx:69
 TControlBar.cxx:70
 TControlBar.cxx:71
 TControlBar.cxx:72
 TControlBar.cxx:73
 TControlBar.cxx:74
 TControlBar.cxx:75
 TControlBar.cxx:76
 TControlBar.cxx:77
 TControlBar.cxx:78
 TControlBar.cxx:79
 TControlBar.cxx:80
 TControlBar.cxx:81
 TControlBar.cxx:82
 TControlBar.cxx:83
 TControlBar.cxx:84
 TControlBar.cxx:85
 TControlBar.cxx:86
 TControlBar.cxx:87
 TControlBar.cxx:88
 TControlBar.cxx:89
 TControlBar.cxx:90
 TControlBar.cxx:91
 TControlBar.cxx:92
 TControlBar.cxx:93
 TControlBar.cxx:94
 TControlBar.cxx:95
 TControlBar.cxx:96
 TControlBar.cxx:97
 TControlBar.cxx:98
 TControlBar.cxx:99
 TControlBar.cxx:100
 TControlBar.cxx:101
 TControlBar.cxx:102
 TControlBar.cxx:103
 TControlBar.cxx:104
 TControlBar.cxx:105
 TControlBar.cxx:106
 TControlBar.cxx:107
 TControlBar.cxx:108
 TControlBar.cxx:109
 TControlBar.cxx:110
 TControlBar.cxx:111
 TControlBar.cxx:112
 TControlBar.cxx:113
 TControlBar.cxx:114
 TControlBar.cxx:115
 TControlBar.cxx:116
 TControlBar.cxx:117
 TControlBar.cxx:118
 TControlBar.cxx:119
 TControlBar.cxx:120
 TControlBar.cxx:121
 TControlBar.cxx:122
 TControlBar.cxx:123
 TControlBar.cxx:124
 TControlBar.cxx:125
 TControlBar.cxx:126
 TControlBar.cxx:127
 TControlBar.cxx:128
 TControlBar.cxx:129
 TControlBar.cxx:130
 TControlBar.cxx:131
 TControlBar.cxx:132
 TControlBar.cxx:133
 TControlBar.cxx:134
 TControlBar.cxx:135
 TControlBar.cxx:136
 TControlBar.cxx:137
 TControlBar.cxx:138
 TControlBar.cxx:139
 TControlBar.cxx:140
 TControlBar.cxx:141
 TControlBar.cxx:142
 TControlBar.cxx:143
 TControlBar.cxx:144
 TControlBar.cxx:145
 TControlBar.cxx:146
 TControlBar.cxx:147
 TControlBar.cxx:148
 TControlBar.cxx:149
 TControlBar.cxx:150
 TControlBar.cxx:151
 TControlBar.cxx:152
 TControlBar.cxx:153
 TControlBar.cxx:154
 TControlBar.cxx:155
 TControlBar.cxx:156
 TControlBar.cxx:157
 TControlBar.cxx:158
 TControlBar.cxx:159
 TControlBar.cxx:160
 TControlBar.cxx:161
 TControlBar.cxx:162
 TControlBar.cxx:163
 TControlBar.cxx:164
 TControlBar.cxx:165
 TControlBar.cxx:166
 TControlBar.cxx:167
 TControlBar.cxx:168
 TControlBar.cxx:169
 TControlBar.cxx:170
 TControlBar.cxx:171
 TControlBar.cxx:172
 TControlBar.cxx:173
 TControlBar.cxx:174
 TControlBar.cxx:175
 TControlBar.cxx:176
 TControlBar.cxx:177
 TControlBar.cxx:178
 TControlBar.cxx:179
 TControlBar.cxx:180
 TControlBar.cxx:181
 TControlBar.cxx:182
 TControlBar.cxx:183
 TControlBar.cxx:184
 TControlBar.cxx:185
 TControlBar.cxx:186
 TControlBar.cxx:187
 TControlBar.cxx:188
 TControlBar.cxx:189
 TControlBar.cxx:190
 TControlBar.cxx:191
 TControlBar.cxx:192
 TControlBar.cxx:193
 TControlBar.cxx:194
 TControlBar.cxx:195
 TControlBar.cxx:196
 TControlBar.cxx:197
 TControlBar.cxx:198
 TControlBar.cxx:199
 TControlBar.cxx:200
 TControlBar.cxx:201
 TControlBar.cxx:202
 TControlBar.cxx:203
 TControlBar.cxx:204
 TControlBar.cxx:205
 TControlBar.cxx:206
 TControlBar.cxx:207
 TControlBar.cxx:208
 TControlBar.cxx:209
 TControlBar.cxx:210
 TControlBar.cxx:211
 TControlBar.cxx:212
 TControlBar.cxx:213
 TControlBar.cxx:214
 TControlBar.cxx:215
 TControlBar.cxx:216
 TControlBar.cxx:217
 TControlBar.cxx:218
 TControlBar.cxx:219
 TControlBar.cxx:220
 TControlBar.cxx:221
 TControlBar.cxx:222
 TControlBar.cxx:223
 TControlBar.cxx:224
 TControlBar.cxx:225
 TControlBar.cxx:226
 TControlBar.cxx:227
 TControlBar.cxx:228
 TControlBar.cxx:229
 TControlBar.cxx:230
 TControlBar.cxx:231
 TControlBar.cxx:232
 TControlBar.cxx:233
 TControlBar.cxx:234
 TControlBar.cxx:235
 TControlBar.cxx:236
 TControlBar.cxx:237
 TControlBar.cxx:238
 TControlBar.cxx:239
 TControlBar.cxx:240
 TControlBar.cxx:241
 TControlBar.cxx:242
 TControlBar.cxx:243
 TControlBar.cxx:244
 TControlBar.cxx:245
 TControlBar.cxx:246
 TControlBar.cxx:247
 TControlBar.cxx:248
 TControlBar.cxx:249
 TControlBar.cxx:250
 TControlBar.cxx:251
 TControlBar.cxx:252
 TControlBar.cxx:253
 TControlBar.cxx:254
 TControlBar.cxx:255
 TControlBar.cxx:256
 TControlBar.cxx:257
 TControlBar.cxx:258
 TControlBar.cxx:259
 TControlBar.cxx:260
 TControlBar.cxx:261
 TControlBar.cxx:262
 TControlBar.cxx:263
 TControlBar.cxx:264
 TControlBar.cxx:265
 TControlBar.cxx:266
 TControlBar.cxx:267
 TControlBar.cxx:268
 TControlBar.cxx:269
 TControlBar.cxx:270
 TControlBar.cxx:271
 TControlBar.cxx:272
 TControlBar.cxx:273
 TControlBar.cxx:274
 TControlBar.cxx:275
 TControlBar.cxx:276
 TControlBar.cxx:277
 TControlBar.cxx:278
 TControlBar.cxx:279
 TControlBar.cxx:280
 TControlBar.cxx:281
 TControlBar.cxx:282
 TControlBar.cxx:283
 TControlBar.cxx:284
 TControlBar.cxx:285
 TControlBar.cxx:286
 TControlBar.cxx:287
 TControlBar.cxx:288
 TControlBar.cxx:289
 TControlBar.cxx:290
 TControlBar.cxx:291
 TControlBar.cxx:292
 TControlBar.cxx:293
 TControlBar.cxx:294
 TControlBar.cxx:295
 TControlBar.cxx:296
 TControlBar.cxx:297
 TControlBar.cxx:298
 TControlBar.cxx:299
 TControlBar.cxx:300
 TControlBar.cxx:301
 TControlBar.cxx:302
 TControlBar.cxx:303
 TControlBar.cxx:304
 TControlBar.cxx:305
 TControlBar.cxx:306
 TControlBar.cxx:307
 TControlBar.cxx:308
 TControlBar.cxx:309
 TControlBar.cxx:310
 TControlBar.cxx:311
 TControlBar.cxx:312
 TControlBar.cxx:313
 TControlBar.cxx:314
 TControlBar.cxx:315
 TControlBar.cxx:316
 TControlBar.cxx:317
 TControlBar.cxx:318
 TControlBar.cxx:319
 TControlBar.cxx:320
 TControlBar.cxx:321
 TControlBar.cxx:322
 TControlBar.cxx:323
 TControlBar.cxx:324
 TControlBar.cxx:325
 TControlBar.cxx:326
 TControlBar.cxx:327
 TControlBar.cxx:328
 TControlBar.cxx:329
 TControlBar.cxx:330
 TControlBar.cxx:331
 TControlBar.cxx:332
 TControlBar.cxx:333
 TControlBar.cxx:334
 TControlBar.cxx:335
 TControlBar.cxx:336
 TControlBar.cxx:337
 TControlBar.cxx:338
 TControlBar.cxx:339
 TControlBar.cxx:340
 TControlBar.cxx:341
 TControlBar.cxx:342
 TControlBar.cxx:343
 TControlBar.cxx:344