ROOT logo
// @(#)root/gui:$Id: TRootControlBar.cxx 23115 2008-04-10 13:35:37Z rdm $
// Author: Fons Rademakers   22/02/98

/*************************************************************************
 * 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.             *
 *************************************************************************/

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TRootControlBar                                                      //
//                                                                      //
// This class provides an interface to the GUI dependent functions of   //
// the TControlBar class. A control bar is a horizontal or vertical bar //
// with a number of buttons (text or picture buttons).                  //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#include "TRootControlBar.h"
#include "TControlBar.h"
#include "TList.h"
#include "TGButton.h"


ClassImp(TRootControlBar)

//______________________________________________________________________________
TRootControlBar::TRootControlBar(TControlBar *c, const char *title, Int_t x, Int_t y)
   : TGMainFrame(gClient->GetRoot(), 10, 10), TControlBarImp(c)
{
   // Create a ROOT native GUI controlbar.

   fWidgets = 0;
   fXpos    = x;
   fYpos    = y;
   fBwidth  = 0;
   fClicked = 0;
   SetCleanup(kDeepCleanup);

   // if controlbar orientation is horizontal change layout manager
   if (c && c->GetOrientation() == TControlBar::kHorizontal) {
      ChangeOptions(kHorizontalFrame);
      fL1 = new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1);
   } else
      fL1 = new TGLayoutHints(kLHintsCenterY | kLHintsExpandX, 1, 1, 1, 1);

   SetWindowName(title);
   SetIconName(title);
}

//______________________________________________________________________________
TRootControlBar::~TRootControlBar()
{
   // Delete the control bar implementation.

   delete fWidgets;
   fWidgets = 0;
}

//______________________________________________________________________________
void TRootControlBar::Create()
{
   // Create the control bar. Loop over all buttons defined in the
   // TControlBar and create the buttons.

   fWidgets = new TList;
   TGButton *b = 0;

   TControlBarButton *button;
   TIter next(fControlBar->GetListOfButtons());

   while ((button = (TControlBarButton *) next())) {

      switch (button->GetType()) {

         case TControlBarButton::kSeparator:
            Warning("Create", "separators not yet supported");
            break;

         case TControlBarButton::kDrawnButton:
            Warning("Create", "picture buttons not yet supported");
            break;

         case TControlBarButton::kButton:
            {
               b = new TGTextButton(this, button->GetName());
               b->SetToolTipText(button->GetTitle());
               b->SetUserData(button);
               AddFrame(b, fL1);
               fWidgets->Add(b);
               if (fBwidth < b->GetDefaultWidth())
                  fBwidth = b->GetDefaultWidth();  //do not cut the label
            }
            break;
      }
   }

   MapSubwindows();
   Resize(GetDefaultSize());

   SetMWMHints(kMWMDecorAll | kMWMDecorResizeH,
               kMWMFuncAll  | kMWMFuncResize    | kMWMFuncMaximize,
               kMWMInputModeless);

   if (fXpos != -999) {
      Move(fXpos, fYpos);
      SetWMPosition(fXpos, fYpos);
   }
   if (GetOptions() & kHorizontalFrame)
      SetWMSize(fBwidth*fWidgets->GetSize(), GetHeight());
   else
      SetWMSize(fBwidth, GetHeight());
}

//______________________________________________________________________________
void TRootControlBar::Show()
{
   // Show controlbar. If not yet created create it first.

   if (!fWidgets) Create();

   MapRaised();
}

//______________________________________________________________________________
void TRootControlBar::Hide()
{
   // Hide controlbar.

   UnmapWindow();
}

//______________________________________________________________________________
Bool_t TRootControlBar::ProcessMessage(Long_t, Long_t, Long_t parm2)
{
   // Handle controlbar button messages.

   TControlBarButton *button = (TControlBarButton *) parm2;

   if (button) {
      fClicked = button;
      button->Action();
   }
   return kTRUE;
}

//______________________________________________________________________________
void TRootControlBar::ReallyDelete()
{
   // Really delete the control bar and the this GUI.

   delete fControlBar;    // will in turn delete this object
}

//______________________________________________________________________________
void TRootControlBar::CloseWindow()
{
   // Called when closed via window manager action.

   DeleteWindow();        // but do it slightly delayed here
}

//______________________________________________________________________________
void TRootControlBar::SetFont(const char *fontName)
{
   // sets new font for control bar buttons

   TIter next(fWidgets);

   TObject *obj;
   
   while ((obj=next())) {
      if (!obj->InheritsFrom(TGTextButton::Class())) continue;

      ((TGTextButton *)obj)->SetFont(fontName);
   }
   Resize();
}

//______________________________________________________________________________
void TRootControlBar::SetButtonState(const char *label, Int_t state)
{
   // sets new font for control bar buttons

   TIter next(fWidgets);

   TObject *obj;
   
   while ((obj=next())) {
      if (!obj->InheritsFrom(TGTextButton::Class())) continue;

      if (!strcmp(((TGTextButton *)obj)->GetTitle(), label)) {
         switch (state) {
            case 0: {
               ((TGTextButton *)obj)->SetState(kButtonUp);
               break;
            }
            case 1: {
               ((TGTextButton *)obj)->SetState(kButtonDown);
               break;
            }
            case 2: {
               ((TGTextButton *)obj)->SetState(kButtonEngaged);
               break;
            }
            case 3: {
               ((TGTextButton *)obj)->SetState(kButtonDisabled);
               break;
            }
            default: {
               Error("SetButtonState", "not valid button state (expecting 0, 1, 2 or 3)");
               break;
            }
         }
      }
   }
   Resize();
}

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

   Pixel_t color;
   gClient->GetColorByName(colorName, color);
   
   if (!fWidgets) Create();
   
   TIter next(fWidgets);

   TObject *obj;
   
   while ((obj=next())) {
      if (!obj->InheritsFrom(TGTextButton::Class())) continue;

      ((TGTextButton *)obj)->SetTextColor(color);
   }
   Resize();
}

//______________________________________________________________________________
void TRootControlBar::SetButtonWidth(UInt_t width)
{
   // Set button width in pixels.
   
   fBwidth = width;
}
 TRootControlBar.cxx:1
 TRootControlBar.cxx:2
 TRootControlBar.cxx:3
 TRootControlBar.cxx:4
 TRootControlBar.cxx:5
 TRootControlBar.cxx:6
 TRootControlBar.cxx:7
 TRootControlBar.cxx:8
 TRootControlBar.cxx:9
 TRootControlBar.cxx:10
 TRootControlBar.cxx:11
 TRootControlBar.cxx:12
 TRootControlBar.cxx:13
 TRootControlBar.cxx:14
 TRootControlBar.cxx:15
 TRootControlBar.cxx:16
 TRootControlBar.cxx:17
 TRootControlBar.cxx:18
 TRootControlBar.cxx:19
 TRootControlBar.cxx:20
 TRootControlBar.cxx:21
 TRootControlBar.cxx:22
 TRootControlBar.cxx:23
 TRootControlBar.cxx:24
 TRootControlBar.cxx:25
 TRootControlBar.cxx:26
 TRootControlBar.cxx:27
 TRootControlBar.cxx:28
 TRootControlBar.cxx:29
 TRootControlBar.cxx:30
 TRootControlBar.cxx:31
 TRootControlBar.cxx:32
 TRootControlBar.cxx:33
 TRootControlBar.cxx:34
 TRootControlBar.cxx:35
 TRootControlBar.cxx:36
 TRootControlBar.cxx:37
 TRootControlBar.cxx:38
 TRootControlBar.cxx:39
 TRootControlBar.cxx:40
 TRootControlBar.cxx:41
 TRootControlBar.cxx:42
 TRootControlBar.cxx:43
 TRootControlBar.cxx:44
 TRootControlBar.cxx:45
 TRootControlBar.cxx:46
 TRootControlBar.cxx:47
 TRootControlBar.cxx:48
 TRootControlBar.cxx:49
 TRootControlBar.cxx:50
 TRootControlBar.cxx:51
 TRootControlBar.cxx:52
 TRootControlBar.cxx:53
 TRootControlBar.cxx:54
 TRootControlBar.cxx:55
 TRootControlBar.cxx:56
 TRootControlBar.cxx:57
 TRootControlBar.cxx:58
 TRootControlBar.cxx:59
 TRootControlBar.cxx:60
 TRootControlBar.cxx:61
 TRootControlBar.cxx:62
 TRootControlBar.cxx:63
 TRootControlBar.cxx:64
 TRootControlBar.cxx:65
 TRootControlBar.cxx:66
 TRootControlBar.cxx:67
 TRootControlBar.cxx:68
 TRootControlBar.cxx:69
 TRootControlBar.cxx:70
 TRootControlBar.cxx:71
 TRootControlBar.cxx:72
 TRootControlBar.cxx:73
 TRootControlBar.cxx:74
 TRootControlBar.cxx:75
 TRootControlBar.cxx:76
 TRootControlBar.cxx:77
 TRootControlBar.cxx:78
 TRootControlBar.cxx:79
 TRootControlBar.cxx:80
 TRootControlBar.cxx:81
 TRootControlBar.cxx:82
 TRootControlBar.cxx:83
 TRootControlBar.cxx:84
 TRootControlBar.cxx:85
 TRootControlBar.cxx:86
 TRootControlBar.cxx:87
 TRootControlBar.cxx:88
 TRootControlBar.cxx:89
 TRootControlBar.cxx:90
 TRootControlBar.cxx:91
 TRootControlBar.cxx:92
 TRootControlBar.cxx:93
 TRootControlBar.cxx:94
 TRootControlBar.cxx:95
 TRootControlBar.cxx:96
 TRootControlBar.cxx:97
 TRootControlBar.cxx:98
 TRootControlBar.cxx:99
 TRootControlBar.cxx:100
 TRootControlBar.cxx:101
 TRootControlBar.cxx:102
 TRootControlBar.cxx:103
 TRootControlBar.cxx:104
 TRootControlBar.cxx:105
 TRootControlBar.cxx:106
 TRootControlBar.cxx:107
 TRootControlBar.cxx:108
 TRootControlBar.cxx:109
 TRootControlBar.cxx:110
 TRootControlBar.cxx:111
 TRootControlBar.cxx:112
 TRootControlBar.cxx:113
 TRootControlBar.cxx:114
 TRootControlBar.cxx:115
 TRootControlBar.cxx:116
 TRootControlBar.cxx:117
 TRootControlBar.cxx:118
 TRootControlBar.cxx:119
 TRootControlBar.cxx:120
 TRootControlBar.cxx:121
 TRootControlBar.cxx:122
 TRootControlBar.cxx:123
 TRootControlBar.cxx:124
 TRootControlBar.cxx:125
 TRootControlBar.cxx:126
 TRootControlBar.cxx:127
 TRootControlBar.cxx:128
 TRootControlBar.cxx:129
 TRootControlBar.cxx:130
 TRootControlBar.cxx:131
 TRootControlBar.cxx:132
 TRootControlBar.cxx:133
 TRootControlBar.cxx:134
 TRootControlBar.cxx:135
 TRootControlBar.cxx:136
 TRootControlBar.cxx:137
 TRootControlBar.cxx:138
 TRootControlBar.cxx:139
 TRootControlBar.cxx:140
 TRootControlBar.cxx:141
 TRootControlBar.cxx:142
 TRootControlBar.cxx:143
 TRootControlBar.cxx:144
 TRootControlBar.cxx:145
 TRootControlBar.cxx:146
 TRootControlBar.cxx:147
 TRootControlBar.cxx:148
 TRootControlBar.cxx:149
 TRootControlBar.cxx:150
 TRootControlBar.cxx:151
 TRootControlBar.cxx:152
 TRootControlBar.cxx:153
 TRootControlBar.cxx:154
 TRootControlBar.cxx:155
 TRootControlBar.cxx:156
 TRootControlBar.cxx:157
 TRootControlBar.cxx:158
 TRootControlBar.cxx:159
 TRootControlBar.cxx:160
 TRootControlBar.cxx:161
 TRootControlBar.cxx:162
 TRootControlBar.cxx:163
 TRootControlBar.cxx:164
 TRootControlBar.cxx:165
 TRootControlBar.cxx:166
 TRootControlBar.cxx:167
 TRootControlBar.cxx:168
 TRootControlBar.cxx:169
 TRootControlBar.cxx:170
 TRootControlBar.cxx:171
 TRootControlBar.cxx:172
 TRootControlBar.cxx:173
 TRootControlBar.cxx:174
 TRootControlBar.cxx:175
 TRootControlBar.cxx:176
 TRootControlBar.cxx:177
 TRootControlBar.cxx:178
 TRootControlBar.cxx:179
 TRootControlBar.cxx:180
 TRootControlBar.cxx:181
 TRootControlBar.cxx:182
 TRootControlBar.cxx:183
 TRootControlBar.cxx:184
 TRootControlBar.cxx:185
 TRootControlBar.cxx:186
 TRootControlBar.cxx:187
 TRootControlBar.cxx:188
 TRootControlBar.cxx:189
 TRootControlBar.cxx:190
 TRootControlBar.cxx:191
 TRootControlBar.cxx:192
 TRootControlBar.cxx:193
 TRootControlBar.cxx:194
 TRootControlBar.cxx:195
 TRootControlBar.cxx:196
 TRootControlBar.cxx:197
 TRootControlBar.cxx:198
 TRootControlBar.cxx:199
 TRootControlBar.cxx:200
 TRootControlBar.cxx:201
 TRootControlBar.cxx:202
 TRootControlBar.cxx:203
 TRootControlBar.cxx:204
 TRootControlBar.cxx:205
 TRootControlBar.cxx:206
 TRootControlBar.cxx:207
 TRootControlBar.cxx:208
 TRootControlBar.cxx:209
 TRootControlBar.cxx:210
 TRootControlBar.cxx:211
 TRootControlBar.cxx:212
 TRootControlBar.cxx:213
 TRootControlBar.cxx:214
 TRootControlBar.cxx:215
 TRootControlBar.cxx:216
 TRootControlBar.cxx:217
 TRootControlBar.cxx:218
 TRootControlBar.cxx:219
 TRootControlBar.cxx:220
 TRootControlBar.cxx:221
 TRootControlBar.cxx:222
 TRootControlBar.cxx:223
 TRootControlBar.cxx:224
 TRootControlBar.cxx:225
 TRootControlBar.cxx:226
 TRootControlBar.cxx:227
 TRootControlBar.cxx:228
 TRootControlBar.cxx:229
 TRootControlBar.cxx:230
 TRootControlBar.cxx:231
 TRootControlBar.cxx:232
 TRootControlBar.cxx:233
 TRootControlBar.cxx:234
 TRootControlBar.cxx:235
 TRootControlBar.cxx:236
 TRootControlBar.cxx:237
 TRootControlBar.cxx:238
 TRootControlBar.cxx:239
 TRootControlBar.cxx:240
 TRootControlBar.cxx:241
 TRootControlBar.cxx:242
 TRootControlBar.cxx:243
 TRootControlBar.cxx:244
 TRootControlBar.cxx:245
 TRootControlBar.cxx:246
 TRootControlBar.cxx:247
 TRootControlBar.cxx:248
 TRootControlBar.cxx:249
 TRootControlBar.cxx:250
 TRootControlBar.cxx:251
 TRootControlBar.cxx:252
 TRootControlBar.cxx:253