Warning, file /include/root/TGButton.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef ROOT_TGButton
0013 #define ROOT_TGButton
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047 #include "TGFrame.h"
0048 #include "TGWidget.h"
0049
0050
0051
0052 enum EButtonState {
0053 kButtonUp,
0054 kButtonDown,
0055 kButtonEngaged,
0056 kButtonDisabled
0057 };
0058
0059
0060 class TGWidget;
0061 class TGHotString;
0062 class TGPicture;
0063 class TGToolTip;
0064 class TGButtonGroup;
0065 class TGPopupMenu;
0066 class TGTextLayout;
0067
0068 class TGButton : public TGFrame, public TGWidget {
0069
0070 friend class TGButtonGroup;
0071
0072 protected:
0073 UInt_t fTWidth;
0074 UInt_t fTHeight;
0075 EButtonState fState;
0076 Bool_t fStayDown;
0077 GContext_t fNormGC;
0078 void *fUserData;
0079 TGToolTip *fTip;
0080 TGButtonGroup *fGroup;
0081 Pixel_t fBgndColor;
0082 Pixel_t fHighColor;
0083 UInt_t fStyle;
0084
0085 virtual void SetToggleButton(Bool_t) {}
0086 virtual void EmitSignals(Bool_t wasUp);
0087
0088 static const TGGC *fgDefaultGC;
0089 static const TGGC *fgHibckgndGC;
0090
0091 static Window_t fgReleaseBtn;
0092
0093 private:
0094 TGButton(const TGButton&) = delete;
0095 TGButton& operator=(const TGButton&) = delete;
0096
0097 public:
0098 static const TGGC &GetDefaultGC();
0099 static const TGGC &GetHibckgndGC();
0100
0101 TGButton(const TGWindow *p = nullptr, Int_t id = -1, GContext_t norm = GetDefaultGC()(),
0102 UInt_t option = kRaisedFrame | kDoubleBorder);
0103 ~TGButton() override;
0104
0105 Bool_t HandleButton(Event_t *event) override;
0106 Bool_t HandleCrossing(Event_t *event) override;
0107 virtual void SetUserData(void *userData) { fUserData = userData; }
0108 virtual void *GetUserData() const { return fUserData; }
0109 virtual void SetToolTipText(const char *text, Long_t delayms = 400);
0110 virtual TGToolTip *GetToolTip() const { return fTip; }
0111 virtual void SetState(EButtonState state, Bool_t emit = kFALSE);
0112 virtual EButtonState GetState() const { return fState; }
0113 virtual void AllowStayDown(Bool_t a) { fStayDown = a; }
0114 virtual void SetGroup(TGButtonGroup *gr);
0115 TGButtonGroup *GetGroup() const { return fGroup; }
0116
0117 virtual Bool_t IsDown() const;
0118 virtual void SetDown(Bool_t on = kTRUE, Bool_t emit = kFALSE);
0119 virtual Bool_t IsOn() const { return IsDown(); }
0120 virtual void SetOn(Bool_t on = kTRUE, Bool_t emit = kFALSE) { SetDown(on, emit); }
0121 virtual Bool_t IsToggleButton() const { return kFALSE; }
0122 virtual Bool_t IsExclusiveToggle() const { return kFALSE; }
0123 virtual void Toggle(Bool_t emit = kFALSE) { SetDown(IsDown() ? kFALSE : kTRUE, emit); }
0124 virtual void SetEnabled(Bool_t e = kTRUE);
0125 virtual UInt_t GetStyle() const { return fStyle; }
0126 virtual void SetStyle(UInt_t newstyle);
0127 virtual void SetStyle(const char *style);
0128
0129 void SavePrimitive(std::ostream &out, Option_t *option = "") override;
0130
0131 GContext_t GetNormGC() const { return fNormGC; }
0132
0133 virtual void Pressed() { Emit("Pressed()"); }
0134 virtual void Released() { Emit("Released()"); }
0135 virtual void Clicked() { Emit("Clicked()"); }
0136 virtual void Toggled(Bool_t on) { Emit("Toggled(Bool_t)", on); }
0137
0138 ClassDefOverride(TGButton,0)
0139 };
0140
0141
0142 class TGTextButton : public TGButton {
0143
0144 protected:
0145 TGHotString *fLabel;
0146 Int_t fMLeft;
0147 Int_t fMRight;
0148 Int_t fMTop;
0149 Int_t fMBottom;
0150 Int_t fTMode;
0151 Int_t fWrapLength;
0152 Int_t fHKeycode;
0153 TGTextLayout *fTLayout;
0154 FontStruct_t fFontStruct;
0155 Bool_t fHasOwnFont;
0156 Bool_t fStateOn;
0157 Bool_t fPrevStateOn;
0158
0159 static const TGFont *fgDefaultFont;
0160
0161 void Init();
0162 void DoRedraw() override;
0163
0164 private:
0165 TGTextButton(const TGTextButton&) = delete;
0166 TGTextButton& operator=(const TGTextButton&) = delete;
0167
0168 public:
0169 static FontStruct_t GetDefaultFontStruct();
0170
0171 TGTextButton(const TGWindow *p, TGHotString *s, Int_t id = -1,
0172 GContext_t norm = GetDefaultGC()(),
0173 FontStruct_t font = GetDefaultFontStruct(),
0174 UInt_t option = kRaisedFrame | kDoubleBorder);
0175 TGTextButton(const TGWindow *p = nullptr, const char *s = nullptr, Int_t id = -1,
0176 GContext_t norm = GetDefaultGC()(),
0177 FontStruct_t font = GetDefaultFontStruct(),
0178 UInt_t option = kRaisedFrame | kDoubleBorder);
0179 TGTextButton(const TGWindow *p, const char *s, const char *cmd,
0180 Int_t id = -1, GContext_t norm = GetDefaultGC()(),
0181 FontStruct_t font = GetDefaultFontStruct(),
0182 UInt_t option = kRaisedFrame | kDoubleBorder);
0183
0184 ~TGTextButton() override;
0185
0186 TGDimension GetDefaultSize() const override;
0187
0188 Bool_t HandleKey(Event_t *event) override;
0189 const TGHotString *GetText() const { return fLabel; }
0190 const char *GetTitle() const override { return fLabel->Data(); }
0191 TString GetString() const { return TString(fLabel->GetString()); }
0192 virtual void SetTextJustify(Int_t tmode);
0193 Int_t GetTextJustify() const { return fTMode; }
0194 virtual void SetText(TGHotString *new_label);
0195 virtual void SetText(const TString &new_label);
0196 virtual void SetTitle(const char *label) { SetText(label); }
0197 virtual void SetFont(FontStruct_t font, Bool_t global = kFALSE);
0198 virtual void SetFont(const char *fontName, Bool_t global = kFALSE);
0199 virtual void SetTextColor(Pixel_t color, Bool_t global = kFALSE);
0200 void SetForegroundColor(Pixel_t fore) override { SetTextColor(fore); }
0201 Bool_t HasOwnFont() const;
0202 void SetWrapLength(Int_t wl) { fWrapLength = wl; Layout(); }
0203 Int_t GetWrapLength() const { return fWrapLength; }
0204 void SetMargins(Int_t left=0, Int_t right=0, Int_t top=0, Int_t bottom=0)
0205 { fMLeft = left; fMRight = right; fMTop = top; fMBottom = bottom; }
0206
0207 virtual void SetLeftMargin(Int_t val) { fMLeft = val; }
0208 virtual void SetRightMargin(Int_t val) { fMRight = val; }
0209 virtual void SetTopMargin(Int_t val) { fMTop = val; }
0210 virtual void SetBottomMargin(Int_t val) { fMBottom = val; }
0211
0212 Int_t GetLeftMargin() const { return fMLeft; }
0213 Int_t GetRightMargin() const { return fMRight; }
0214 Int_t GetTopMargin() const { return fMTop; }
0215 Int_t GetBottomMargin() const { return fMBottom; }
0216
0217 void ChangeText(const char *title) { SetTitle(title); }
0218
0219 FontStruct_t GetFontStruct() const { return fFontStruct; }
0220
0221 void Layout() override;
0222 void SavePrimitive(std::ostream &out, Option_t *option = "") override;
0223
0224 ClassDefOverride(TGTextButton,0)
0225 };
0226
0227
0228 class TGPictureButton : public TGButton {
0229
0230 protected:
0231 const TGPicture *fPic;
0232 const TGPicture *fPicD;
0233 Bool_t fOwnDisabledPic;
0234
0235 void DoRedraw() override;
0236 virtual void CreateDisabledPicture();
0237
0238 private:
0239 TGPictureButton(const TGPictureButton&) = delete;
0240 TGPictureButton& operator=(const TGPictureButton&) = delete;
0241
0242 public:
0243 TGPictureButton(const TGWindow *p, const TGPicture *pic, Int_t id = -1,
0244 GContext_t norm = GetDefaultGC()(),
0245 UInt_t option = kRaisedFrame | kDoubleBorder);
0246 TGPictureButton(const TGWindow *p, const TGPicture *pic, const char *cmd,
0247 Int_t id = -1, GContext_t norm = GetDefaultGC()(),
0248 UInt_t option = kRaisedFrame | kDoubleBorder);
0249 TGPictureButton(const TGWindow *p = nullptr, const char* pic = nullptr, Int_t id = -1,
0250 GContext_t norm = GetDefaultGC()(),
0251 UInt_t option = kRaisedFrame | kDoubleBorder);
0252 ~TGPictureButton() override;
0253
0254 virtual void SetPicture(const TGPicture *new_pic);
0255 virtual void SetDisabledPicture(const TGPicture *pic);
0256 const TGPicture *GetPicture() const { return fPic; };
0257 const TGPicture *GetDisabledPicture() const { return fPicD; };
0258 void SavePrimitive(std::ostream &out, Option_t *option = "") override;
0259
0260 ClassDefOverride(TGPictureButton,0)
0261 };
0262
0263
0264 class TGCheckButton : public TGTextButton {
0265
0266 private:
0267
0268 TGCheckButton(const TGCheckButton&) = delete;
0269 TGCheckButton& operator=(const TGCheckButton&) = delete;
0270
0271 protected:
0272 EButtonState fPrevState;
0273 const TGPicture *fOn;
0274 const TGPicture *fOff;
0275 const TGPicture *fDisOn;
0276 const TGPicture *fDisOff;
0277
0278 void Init();
0279 void PSetState(EButtonState state, Bool_t emit);
0280 void DoRedraw() override;
0281 void EmitSignals(Bool_t wasUp = kTRUE) override;
0282
0283 static const TGFont *fgDefaultFont;
0284 static const TGGC *fgDefaultGC;
0285
0286 public:
0287 static FontStruct_t GetDefaultFontStruct();
0288 static const TGGC &GetDefaultGC();
0289
0290 TGCheckButton(const TGWindow *p, TGHotString *s, Int_t id = -1,
0291 GContext_t norm = GetDefaultGC()(),
0292 FontStruct_t font = GetDefaultFontStruct(),
0293 UInt_t option = 0);
0294 TGCheckButton(const TGWindow *p = nullptr, const char *s = nullptr, Int_t id = -1,
0295 GContext_t norm = GetDefaultGC()(),
0296 FontStruct_t font = GetDefaultFontStruct(),
0297 UInt_t option = 0);
0298 TGCheckButton(const TGWindow *p, const char *s, const char *cmd, Int_t id = -1,
0299 GContext_t norm = GetDefaultGC()(),
0300 FontStruct_t font = GetDefaultFontStruct(),
0301 UInt_t option = 0);
0302 ~TGCheckButton() override;
0303
0304 TGDimension GetDefaultSize() const override;
0305
0306 Bool_t HandleButton(Event_t *event) override;
0307 Bool_t HandleKey(Event_t *event) override;
0308 Bool_t HandleCrossing(Event_t *event) override;
0309 Bool_t IsToggleButton() const override { return kTRUE; }
0310 Bool_t IsOn() const override { return fState == kButtonDown; }
0311 Bool_t IsDown() const override { return fState == kButtonDown; }
0312 virtual Bool_t IsDisabledAndSelected() const { return ((fState == kButtonDisabled) && fStateOn); }
0313 virtual void SetDisabledAndSelected(Bool_t);
0314 void SetState(EButtonState state, Bool_t emit = kFALSE) override;
0315 void SavePrimitive(std::ostream &out, Option_t *option = "") override;
0316
0317 ClassDefOverride(TGCheckButton,0)
0318 };
0319
0320
0321 class TGRadioButton : public TGTextButton {
0322
0323 private:
0324 TGRadioButton(const TGRadioButton&) = delete;
0325 TGRadioButton& operator=(const TGRadioButton&) = delete;
0326
0327 protected:
0328 EButtonState fPrevState;
0329 const TGPicture *fOn;
0330 const TGPicture *fOff;
0331 const TGPicture *fDisOn;
0332 const TGPicture *fDisOff;
0333
0334 void Init();
0335 void PSetState(EButtonState state, Bool_t emit);
0336 void DoRedraw() override;
0337 void EmitSignals(Bool_t wasUp = kTRUE) override;
0338
0339 static const TGFont *fgDefaultFont;
0340 static const TGGC *fgDefaultGC;
0341
0342 public:
0343 static FontStruct_t GetDefaultFontStruct();
0344 static const TGGC &GetDefaultGC();
0345
0346 TGRadioButton(const TGWindow *p, TGHotString *s, Int_t id = -1,
0347 GContext_t norm = GetDefaultGC()(),
0348 FontStruct_t font = GetDefaultFontStruct(),
0349 UInt_t option = 0);
0350 TGRadioButton(const TGWindow *p = nullptr, const char *s = nullptr, Int_t id = -1,
0351 GContext_t norm = GetDefaultGC()(),
0352 FontStruct_t font = GetDefaultFontStruct(),
0353 UInt_t option = 0);
0354 TGRadioButton(const TGWindow *p, const char *s, const char *cmd, Int_t id = -1,
0355 GContext_t norm = GetDefaultGC()(),
0356 FontStruct_t font = GetDefaultFontStruct(),
0357 UInt_t option = 0);
0358 ~TGRadioButton() override;
0359
0360 TGDimension GetDefaultSize() const override;
0361
0362 Bool_t HandleButton(Event_t *event) override;
0363 Bool_t HandleKey(Event_t *event) override;
0364 Bool_t HandleCrossing(Event_t *event) override;
0365 void SetState(EButtonState state, Bool_t emit = kFALSE) override;
0366 virtual void SetDisabledAndSelected(Bool_t);
0367 Bool_t IsToggleButton() const override { return kTRUE; }
0368 Bool_t IsExclusiveToggle() const override { return kTRUE; }
0369 Bool_t IsOn() const override { return fStateOn; }
0370 Bool_t IsDown() const override { return fStateOn; }
0371 virtual Bool_t IsDisabledAndSelected() const { return ((fState == kButtonDisabled) && fStateOn); }
0372 void SavePrimitive(std::ostream &out, Option_t *option = "") override;
0373
0374 ClassDefOverride(TGRadioButton,0)
0375 };
0376
0377
0378 class TGSplitButton : public TGTextButton {
0379
0380 friend class TGPopupMenu;
0381
0382 private:
0383 TGSplitButton(const TGSplitButton&) = delete;
0384 TGSplitButton& operator=(const TGSplitButton&) = delete;
0385
0386 void CalcSize();
0387 void DrawTriangle(const GContext_t gc, Int_t x, Int_t y);
0388 Bool_t HandleSButton(Event_t *event);
0389 Bool_t HandleSCrossing(Event_t *event);
0390 Bool_t HandleSKey(Event_t *event);
0391 void SetMenuState(Bool_t state) ;
0392
0393 protected:
0394
0395
0396 Bool_t fSplit;
0397 EButtonState fMBState;
0398 UInt_t fTBWidth;
0399 UInt_t fMBWidth;
0400 TGPopupMenu *fPopMenu;
0401 Int_t fEntryId;
0402 TGHotString *fMenuLabel;
0403 Cursor_t fDefaultCursor;
0404 Bool_t fKeyNavigate;
0405 TGString fWidestLabel;
0406 TGString fHeighestLabel;
0407
0408
0409 void DoRedraw() override;
0410 void Init();
0411 void BindKeys(Bool_t on = kTRUE);
0412 void BindMenuKeys(Bool_t on = kTRUE);
0413
0414 public:
0415 TGSplitButton(const TGWindow *p, TGHotString *menulabel,
0416 TGPopupMenu *popmenu, Bool_t split = kTRUE,
0417 Int_t id = -1, GContext_t norm = GetDefaultGC()(),
0418 FontStruct_t fontstruct = GetDefaultFontStruct(),
0419 UInt_t option = kRaisedFrame | kDoubleBorder);
0420
0421 ~TGSplitButton() override;
0422
0423 TGDimension GetDefaultSize() const override;
0424
0425 void SetText(TGHotString *new_label) override;
0426 void SetText(const TString &new_label) override;
0427 void SetFont(FontStruct_t font, Bool_t global = kFALSE) override;
0428 void SetFont(const char *fontName, Bool_t global = kFALSE) override;
0429 virtual void SetMBState(EButtonState state);
0430 virtual void SetSplit(Bool_t split);
0431 Bool_t IsSplit() { return fSplit; }
0432 Bool_t HandleButton(Event_t *event) override;
0433 Bool_t HandleCrossing(Event_t *event) override;
0434 Bool_t HandleKey(Event_t *event) override;
0435 Bool_t HandleMotion(Event_t *event) override;
0436 void Layout() override;
0437
0438 virtual void MBPressed() { Emit("MBPressed()"); }
0439 virtual void MBReleased() { Emit("MBReleased()"); }
0440 virtual void MBClicked() { Emit("MBClicked()"); }
0441 virtual void ItemClicked(Int_t id) { Emit("ItemClicked(Int_t)", id); }
0442
0443
0444 void HandleMenu(Int_t id);
0445
0446 ClassDefOverride(TGSplitButton,0)
0447 };
0448
0449 #endif