00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00035
00036 fWidgets = 0;
00037 fXpos = x;
00038 fYpos = y;
00039 fBwidth = 0;
00040 fClicked = 0;
00041 SetCleanup(kDeepCleanup);
00042
00043
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
00058
00059 delete fWidgets;
00060 fWidgets = 0;
00061 }
00062
00063
00064 void TRootControlBar::Create()
00065 {
00066
00067
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();
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
00122
00123 if (!fWidgets) Create();
00124
00125 MapRaised();
00126 }
00127
00128
00129 void TRootControlBar::Hide()
00130 {
00131
00132
00133 UnmapWindow();
00134 }
00135
00136
00137 Bool_t TRootControlBar::ProcessMessage(Long_t, Long_t, Long_t parm2)
00138 {
00139
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
00154
00155 delete fControlBar;
00156 }
00157
00158
00159 void TRootControlBar::CloseWindow()
00160 {
00161
00162
00163 DeleteWindow();
00164 }
00165
00166
00167 void TRootControlBar::SetFont(const char *fontName)
00168 {
00169
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
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
00227
00228
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
00251
00252 fBwidth = width;
00253 }