#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)
{
   
   fWidgets = 0;
   fXpos    = x;
   fYpos    = y;
   fClicked = 0;
   SetCleanup(kDeepCleanup);
   
   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 fWidgets;
   fWidgets = 0;
}
void TRootControlBar::Create()
{
   
   
   fWidgets = new TList;
   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:
            {
               TGButton *b = new TGTextButton(this, button->GetName());
               b->SetToolTipText(button->GetTitle());
               b->SetUserData(button);
               AddFrame(b, fL1);
               fWidgets->Add(b);
            }
            break;
      }
   }
   MapSubwindows();
   Resize(GetDefaultSize());
   SetMWMHints(kMWMDecorAll | kMWMDecorResizeH,
               kMWMFuncAll  | kMWMFuncResize    | kMWMFuncMaximize,
               kMWMInputModeless);
   if (fXpos != -999) {
      Move(fXpos, fYpos);
      SetWMPosition(fXpos, fYpos);
   }
}
void TRootControlBar::Show()
{
   
   if (!fWidgets) Create();
   MapRaised();
}
void TRootControlBar::Hide()
{
   
   UnmapWindow();
}
Bool_t TRootControlBar::ProcessMessage(Long_t, Long_t, Long_t parm2)
{
   
   TControlBarButton *button = (TControlBarButton *) parm2;
   if (button) {
      fClicked = button;
      button->Action();
   }
   return kTRUE;
}
void TRootControlBar::ReallyDelete()
{
   
   delete fControlBar;    
}
void TRootControlBar::CloseWindow()
{
   
   DeleteWindow();        
}
void TRootControlBar::SetFont(const char *fontName)
{
   
   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)
{
   
   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)
{
   
   
   
   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();
}
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.