00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef ROOT_TGButton
00013 #define ROOT_TGButton
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 #ifndef ROOT_TGFrame
00048 #include "TGFrame.h"
00049 #endif
00050 #ifndef ROOT_TGWidget
00051 #include "TGWidget.h"
00052 #endif
00053
00054
00055
00056 enum EButtonState {
00057 kButtonUp,
00058 kButtonDown,
00059 kButtonEngaged,
00060 kButtonDisabled
00061 };
00062
00063
00064 class TGWidget;
00065 class TGHotString;
00066 class TGPicture;
00067 class TGToolTip;
00068 class TGButtonGroup;
00069 class TGPopupMenu;
00070 class TGTextLayout;
00071
00072 class TGButton : public TGFrame, public TGWidget {
00073
00074 friend class TGButtonGroup;
00075
00076 protected:
00077 UInt_t fTWidth;
00078 UInt_t fTHeight;
00079 EButtonState fState;
00080 Bool_t fStayDown;
00081 GContext_t fNormGC;
00082 void *fUserData;
00083 TGToolTip *fTip;
00084 TGButtonGroup *fGroup;
00085
00086 virtual void SetToggleButton(Bool_t) { }
00087 virtual void EmitSignals(Bool_t wasUp);
00088
00089 static const TGGC *fgDefaultGC;
00090 static const TGGC *fgHibckgndGC;
00091
00092 static Window_t fgReleaseBtn;
00093
00094 private:
00095 TGButton(const TGButton&);
00096 TGButton& operator=(const TGButton&);
00097
00098 public:
00099 static const TGGC &GetDefaultGC();
00100 static const TGGC &GetHibckgndGC();
00101
00102 TGButton(const TGWindow *p = 0, Int_t id = -1, GContext_t norm = GetDefaultGC()(),
00103 UInt_t option = kRaisedFrame | kDoubleBorder);
00104 virtual ~TGButton();
00105
00106 virtual Bool_t HandleButton(Event_t *event);
00107 virtual Bool_t HandleCrossing(Event_t *event);
00108 virtual void SetUserData(void *userData) { fUserData = userData; }
00109 virtual void *GetUserData() const { return fUserData; }
00110 virtual void SetToolTipText(const char *text, Long_t delayms = 400);
00111 virtual TGToolTip *GetToolTip() const { return fTip; }
00112 virtual void SetState(EButtonState state, Bool_t emit = kFALSE);
00113 virtual EButtonState GetState() const { return fState; }
00114 virtual void AllowStayDown(Bool_t a) { fStayDown = a; }
00115 virtual void SetGroup(TGButtonGroup *gr);
00116 TGButtonGroup *GetGroup() const { return fGroup; }
00117
00118 virtual Bool_t IsDown() const { return !(fOptions & kRaisedFrame); }
00119 virtual void SetDown(Bool_t on = kTRUE, Bool_t emit = kFALSE);
00120 virtual Bool_t IsOn() const { return IsDown(); }
00121 virtual void SetOn(Bool_t on = kTRUE, Bool_t emit = kFALSE) { SetDown(on, emit); }
00122 virtual Bool_t IsToggleButton() const { return kFALSE; }
00123 virtual Bool_t IsExclusiveToggle() const { return kFALSE; }
00124 virtual void Toggle(Bool_t emit = kFALSE) { SetDown(IsDown() ? kFALSE : kTRUE, emit); }
00125 virtual void SetEnabled(Bool_t e = kTRUE);
00126
00127 virtual void SavePrimitive(ostream &out, Option_t *option = "");
00128
00129 GContext_t GetNormGC() const { return fNormGC; }
00130
00131 virtual void Pressed() { Emit("Pressed()"); }
00132 virtual void Released() { Emit("Released()"); }
00133 virtual void Clicked() { Emit("Clicked()"); }
00134 virtual void Toggled(Bool_t on) { Emit("Toggled(Bool_t)", on); }
00135
00136 ClassDef(TGButton,0)
00137 };
00138
00139
00140 class TGTextButton : public TGButton {
00141
00142 protected:
00143 TGHotString *fLabel;
00144 Int_t fMLeft;
00145 Int_t fMRight;
00146 Int_t fMTop;
00147 Int_t fMBottom;
00148 Int_t fTMode;
00149 Int_t fWrapLength;
00150 Int_t fHKeycode;
00151 TGTextLayout *fTLayout;
00152 FontStruct_t fFontStruct;
00153 Bool_t fHasOwnFont;
00154 Bool_t fStateOn;
00155 Bool_t fPrevStateOn;
00156
00157 static const TGFont *fgDefaultFont;
00158
00159 void Init();
00160 virtual void DoRedraw();
00161
00162 private:
00163 TGTextButton(const TGTextButton&);
00164 TGTextButton& operator=(const TGTextButton&);
00165
00166 public:
00167 static FontStruct_t GetDefaultFontStruct();
00168
00169 TGTextButton(const TGWindow *p, TGHotString *s, Int_t id = -1,
00170 GContext_t norm = GetDefaultGC()(),
00171 FontStruct_t font = GetDefaultFontStruct(),
00172 UInt_t option = kRaisedFrame | kDoubleBorder);
00173 TGTextButton(const TGWindow *p = 0, const char *s = 0, Int_t id = -1,
00174 GContext_t norm = GetDefaultGC()(),
00175 FontStruct_t font = GetDefaultFontStruct(),
00176 UInt_t option = kRaisedFrame | kDoubleBorder);
00177 TGTextButton(const TGWindow *p, const char *s, const char *cmd,
00178 Int_t id = -1, GContext_t norm = GetDefaultGC()(),
00179 FontStruct_t font = GetDefaultFontStruct(),
00180 UInt_t option = kRaisedFrame | kDoubleBorder);
00181
00182 virtual ~TGTextButton();
00183
00184 virtual TGDimension GetDefaultSize() const;
00185
00186 virtual Bool_t HandleKey(Event_t *event);
00187 const TGHotString *GetText() const { return fLabel; }
00188 virtual const char *GetTitle() const { return fLabel->Data(); }
00189 TString GetString() const { return TString(fLabel->GetString()); }
00190 virtual void SetTextJustify(Int_t tmode);
00191 Int_t GetTextJustify() const { return fTMode; }
00192 virtual void SetText(TGHotString *new_label);
00193 virtual void SetText(const TString &new_label);
00194 virtual void SetTitle(const char *label) { SetText(label); }
00195 virtual void SetFont(FontStruct_t font, Bool_t global = kFALSE);
00196 virtual void SetFont(const char *fontName, Bool_t global = kFALSE);
00197 virtual void SetTextColor(Pixel_t color, Bool_t global = kFALSE);
00198 virtual void SetForegroundColor(Pixel_t fore) { SetTextColor(fore); }
00199 Bool_t HasOwnFont() const;
00200 void SetWrapLength(Int_t wl) { fWrapLength = wl; Layout(); }
00201 Int_t GetWrapLength() const { return fWrapLength; }
00202 void SetMargins(Int_t left=0, Int_t right=0, Int_t top=0, Int_t bottom=0)
00203 { fMLeft = left; fMRight = right; fMTop = top; fMBottom = bottom; }
00204
00205 virtual void SetLeftMargin(Int_t val) { fMLeft = val; }
00206 virtual void SetRightMargin(Int_t val) { fMRight = val; }
00207 virtual void SetTopMargin(Int_t val) { fMTop = val; }
00208 virtual void SetBottomMargin(Int_t val) { fMBottom = val; }
00209
00210 Int_t GetLeftMargin() const { return fMLeft; }
00211 Int_t GetRightMargin() const { return fMRight; }
00212 Int_t GetTopMargin() const { return fMTop; }
00213 Int_t GetBottomMargin() const { return fMBottom; }
00214
00215 void ChangeText(const char *title) { SetTitle(title); }
00216
00217 FontStruct_t GetFontStruct() const { return fFontStruct; }
00218
00219 virtual void Layout();
00220 virtual void SavePrimitive(ostream &out, Option_t *option = "");
00221
00222 ClassDef(TGTextButton,0)
00223 };
00224
00225
00226 class TGPictureButton : public TGButton {
00227
00228 protected:
00229 const TGPicture *fPic;
00230 const TGPicture *fPicD;
00231 Bool_t fOwnDisabledPic;
00232
00233 virtual void DoRedraw();
00234 virtual void CreateDisabledPicture();
00235
00236 private:
00237 TGPictureButton(const TGPictureButton&);
00238 TGPictureButton& operator=(const TGPictureButton&);
00239
00240 public:
00241 TGPictureButton(const TGWindow *p, const TGPicture *pic, Int_t id = -1,
00242 GContext_t norm = GetDefaultGC()(),
00243 UInt_t option = kRaisedFrame | kDoubleBorder);
00244 TGPictureButton(const TGWindow *p, const TGPicture *pic, const char *cmd,
00245 Int_t id = -1, GContext_t norm = GetDefaultGC()(),
00246 UInt_t option = kRaisedFrame | kDoubleBorder);
00247 TGPictureButton(const TGWindow *p = 0, const char* pic = 0, Int_t id = -1,
00248 GContext_t norm = GetDefaultGC()(),
00249 UInt_t option = kRaisedFrame | kDoubleBorder);
00250 virtual ~TGPictureButton();
00251
00252 virtual void SetPicture(const TGPicture *new_pic);
00253 virtual void SetDisabledPicture(const TGPicture *pic);
00254 const TGPicture *GetPicture() const { return fPic; };
00255 const TGPicture *GetDisabledPicture() const { return fPicD; };
00256 virtual void SavePrimitive(ostream &out, Option_t *option = "");
00257
00258 ClassDef(TGPictureButton,0)
00259 };
00260
00261
00262 class TGCheckButton : public TGTextButton {
00263
00264 private:
00265
00266 TGCheckButton(const TGCheckButton&);
00267 TGCheckButton& operator=(const TGCheckButton&);
00268
00269 protected:
00270 EButtonState fPrevState;
00271 const TGPicture *fOn;
00272 const TGPicture *fOff;
00273 const TGPicture *fDisOn;
00274 const TGPicture *fDisOff;
00275
00276
00277 void Init();
00278 void PSetState(EButtonState state, Bool_t emit);
00279 virtual void DoRedraw();
00280 virtual void EmitSignals(Bool_t wasUp = kTRUE);
00281
00282 static const TGFont *fgDefaultFont;
00283 static const TGGC *fgDefaultGC;
00284
00285 public:
00286 static FontStruct_t GetDefaultFontStruct();
00287 static const TGGC &GetDefaultGC();
00288
00289 TGCheckButton(const TGWindow *p, TGHotString *s, Int_t id = -1,
00290 GContext_t norm = GetDefaultGC()(),
00291 FontStruct_t font = GetDefaultFontStruct(),
00292 UInt_t option = 0);
00293 TGCheckButton(const TGWindow *p = 0, const char *s = 0, Int_t id = -1,
00294 GContext_t norm = GetDefaultGC()(),
00295 FontStruct_t font = GetDefaultFontStruct(),
00296 UInt_t option = 0);
00297 TGCheckButton(const TGWindow *p, const char *s, const char *cmd, Int_t id = -1,
00298 GContext_t norm = GetDefaultGC()(),
00299 FontStruct_t font = GetDefaultFontStruct(),
00300 UInt_t option = 0);
00301 virtual ~TGCheckButton();
00302
00303 virtual TGDimension GetDefaultSize() const;
00304
00305 virtual Bool_t HandleButton(Event_t *event);
00306 virtual Bool_t HandleKey(Event_t *event);
00307 virtual Bool_t HandleCrossing(Event_t *event);
00308 virtual Bool_t IsToggleButton() const { return kTRUE; }
00309 virtual Bool_t IsOn() const { return fState == kButtonDown; }
00310 virtual Bool_t IsDown() const { return fState == kButtonDown; }
00311 virtual Bool_t IsDisabledAndSelected() const { return kButtonDisabled && fStateOn; }
00312 virtual void SetDisabledAndSelected(Bool_t);
00313 virtual void SetState(EButtonState state, Bool_t emit = kFALSE);
00314 virtual void SavePrimitive(ostream &out, Option_t *option = "");
00315
00316 ClassDef(TGCheckButton,0)
00317 };
00318
00319
00320 class TGRadioButton : public TGTextButton {
00321
00322 private:
00323 TGRadioButton(const TGRadioButton&);
00324 TGRadioButton& operator=(const TGRadioButton&);
00325
00326 protected:
00327 EButtonState fPrevState;
00328 const TGPicture *fOn;
00329 const TGPicture *fOff;
00330 const TGPicture *fDisOn;
00331 const TGPicture *fDisOff;
00332
00333 void Init();
00334 void PSetState(EButtonState state, Bool_t emit);
00335 virtual void DoRedraw();
00336 virtual void EmitSignals(Bool_t wasUp = kTRUE);
00337
00338 static const TGFont *fgDefaultFont;
00339 static const TGGC *fgDefaultGC;
00340
00341 public:
00342 static FontStruct_t GetDefaultFontStruct();
00343 static const TGGC &GetDefaultGC();
00344
00345 TGRadioButton(const TGWindow *p, TGHotString *s, Int_t id = -1,
00346 GContext_t norm = GetDefaultGC()(),
00347 FontStruct_t font = GetDefaultFontStruct(),
00348 UInt_t option = 0);
00349 TGRadioButton(const TGWindow *p = 0, const char *s = 0, Int_t id = -1,
00350 GContext_t norm = GetDefaultGC()(),
00351 FontStruct_t font = GetDefaultFontStruct(),
00352 UInt_t option = 0);
00353 TGRadioButton(const TGWindow *p, const char *s, const char *cmd, Int_t id = -1,
00354 GContext_t norm = GetDefaultGC()(),
00355 FontStruct_t font = GetDefaultFontStruct(),
00356 UInt_t option = 0);
00357 virtual ~TGRadioButton();
00358
00359 virtual TGDimension GetDefaultSize() const;
00360
00361 virtual Bool_t HandleButton(Event_t *event);
00362 virtual Bool_t HandleKey(Event_t *event);
00363 virtual Bool_t HandleCrossing(Event_t *event);
00364 virtual void SetState(EButtonState state, Bool_t emit = kFALSE);
00365 virtual void SetDisabledAndSelected(Bool_t);
00366 virtual Bool_t IsToggleButton() const { return kTRUE; }
00367 virtual Bool_t IsExclusiveToggle() const { return kTRUE; }
00368 virtual Bool_t IsOn() const { return fStateOn; }
00369 virtual Bool_t IsDown() const { return fStateOn; }
00370 virtual Bool_t IsDisabledAndSelected() const { return kButtonDisabled && fStateOn; }
00371 virtual void SavePrimitive(ostream &out, Option_t *option = "");
00372
00373 ClassDef(TGRadioButton,0)
00374 };
00375
00376
00377 class TGSplitButton : public TGTextButton {
00378
00379 friend class TGPopupMenu;
00380
00381 private:
00382 TGSplitButton(const TGSplitButton&);
00383 TGSplitButton& operator=(const TGSplitButton&);
00384
00385 void CalcSize();
00386 void DrawTriangle(const GContext_t gc, Int_t x, Int_t y);
00387 Bool_t HandleSButton(Event_t *event);
00388 Bool_t HandleSCrossing(Event_t *event);
00389 Bool_t HandleSKey(Event_t *event);
00390 void SetMenuState(Bool_t state) ;
00391
00392 protected:
00393
00394 Bool_t fSplit;
00395 EButtonState fMBState;
00396 UInt_t fTBWidth;
00397 UInt_t fMBWidth;
00398 TGPopupMenu *fPopMenu;
00399 Int_t fEntryId;
00400 TGHotString *fMenuLabel;
00401 Cursor_t fDefaultCursor;
00402 Bool_t fKeyNavigate;
00403 TGString fWidestLabel;
00404 TGString fHeighestLabel;
00405
00406 virtual void DoRedraw();
00407 void Init();
00408 void BindKeys(Bool_t on = kTRUE);
00409 void BindMenuKeys(Bool_t on = kTRUE);
00410
00411 public:
00412 TGSplitButton(const TGWindow *p, TGHotString *menulabel,
00413 TGPopupMenu *popmenu, Bool_t split = kTRUE,
00414 Int_t id = -1, GContext_t norm = GetDefaultGC()(),
00415 FontStruct_t fontstruct = GetDefaultFontStruct(),
00416 UInt_t option = kRaisedFrame | kDoubleBorder);
00417
00418 virtual ~TGSplitButton();
00419
00420 virtual TGDimension GetDefaultSize() const ;
00421
00422 virtual void SetText(TGHotString *new_label);
00423 virtual void SetText(const TString &new_label);
00424 virtual void SetFont(FontStruct_t font, Bool_t global = kFALSE);
00425 virtual void SetFont(const char *fontName, Bool_t global = kFALSE);
00426 virtual void SetMBState(EButtonState state);
00427 virtual void SetSplit(Bool_t split);
00428 Bool_t IsSplit() { return fSplit; }
00429 virtual Bool_t HandleButton(Event_t *event);
00430 virtual Bool_t HandleCrossing(Event_t *event);
00431 virtual Bool_t HandleKey(Event_t *event);
00432 virtual Bool_t HandleMotion(Event_t *event);
00433 virtual void Layout();
00434
00435 virtual void MBPressed() { Emit("MBPressed()"); }
00436 virtual void MBReleased() { Emit("MBReleased()"); }
00437 virtual void MBClicked() { Emit("MBClicked()"); }
00438 virtual void ItemClicked(Int_t id) { Emit("ItemClicked(Int_t)", id); }
00439
00440
00441 void HandleMenu(Int_t id) ;
00442
00443 ClassDef(TGSplitButton, 0)
00444 };
00445
00446 #endif