Warning, file /include/root/TGMenu.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_TGMenu
0013 #define ROOT_TGMenu
0014
0015
0016 #include "TGFrame.h"
0017 #include "TGString.h"
0018 #include "TGPicture.h"
0019 #include "TGWidget.h"
0020
0021
0022
0023 enum EMenuEntryState {
0024 kMenuActiveMask = BIT(0),
0025 kMenuEnableMask = BIT(1),
0026 kMenuDefaultMask = BIT(2),
0027 kMenuCheckedMask = BIT(3),
0028 kMenuRadioMask = BIT(4),
0029 kMenuHideMask = BIT(5),
0030 kMenuRadioEntryMask = BIT(6)
0031 };
0032
0033
0034
0035 enum EMenuEntryType {
0036 kMenuSeparator,
0037 kMenuLabel,
0038 kMenuEntry,
0039 kMenuPopup
0040 };
0041
0042
0043 class TGPopupMenu;
0044 class TGMenuBar;
0045 class TGMenuTitle;
0046 class TTimer;
0047 class TGSplitButton;
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057 class TGMenuEntry : public TObject {
0058
0059 friend class TGPopupMenu;
0060 friend class TGMenuBar;
0061
0062 protected:
0063 Int_t fEntryId;
0064 void *fUserData;
0065 EMenuEntryType fType;
0066 Int_t fStatus;
0067 Int_t fEx, fEy;
0068 UInt_t fEw, fEh;
0069 TGHotString *fLabel;
0070 TGString *fShortcut;
0071 const TGPicture *fPic;
0072 TGPopupMenu *fPopup;
0073
0074 private:
0075 TGMenuEntry(const TGMenuEntry&) = delete;
0076 TGMenuEntry& operator=(const TGMenuEntry&) = delete;
0077
0078 public:
0079 TGMenuEntry(): fEntryId(0), fUserData(nullptr), fType(), fStatus(0),
0080 fEx(0), fEy(0), fEw(0), fEh(0), fLabel(nullptr), fShortcut(nullptr), fPic(nullptr), fPopup(nullptr) { }
0081 ~TGMenuEntry() override { if (fLabel) delete fLabel; if (fShortcut) delete fShortcut; }
0082
0083 Int_t GetEntryId() const { return fEntryId; }
0084 const char *GetName() const override { return fLabel ? fLabel->GetString() : nullptr; }
0085 const char *GetShortcutText() const { return fShortcut ? fShortcut->GetString() : nullptr; }
0086 virtual Int_t GetStatus() const { return fStatus; }
0087 EMenuEntryType GetType() const { return fType; }
0088 TGPopupMenu *GetPopup() const { return fPopup; }
0089 TGHotString *GetLabel() const { return fLabel; }
0090 TGString *GetShortcut() const { return fShortcut; }
0091 Int_t GetEx() const { return fEx; }
0092 Int_t GetEy() const { return fEy; }
0093 UInt_t GetEw() const { return fEw; }
0094 UInt_t GetEh() const { return fEh; }
0095 const TGPicture *GetPic() const { return fPic; }
0096 void *GetUserData() const { return fUserData; }
0097
0098 ClassDefOverride(TGMenuEntry,0);
0099 };
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110 class TGPopupMenu : public TGFrame {
0111
0112 friend class TGMenuTitle;
0113 friend class TGMenuBar;
0114 friend class TGSplitButton;
0115
0116 protected:
0117 TList *fEntryList;
0118 TGMenuEntry *fCurrent;
0119 Bool_t fStick;
0120 Bool_t fHasGrab;
0121 Bool_t fPoppedUp;
0122 UInt_t fXl;
0123 UInt_t fMenuWidth;
0124 UInt_t fMenuHeight;
0125 TTimer *fDelay;
0126 GContext_t fNormGC;
0127 GContext_t fSelGC;
0128 GContext_t fSelbackGC;
0129 FontStruct_t fFontStruct;
0130 FontStruct_t fHifontStruct;
0131 Cursor_t fDefaultCursor;
0132 const TGWindow *fMsgWindow;
0133 TGMenuBar *fMenuBar;
0134 TGSplitButton *fSplitButton;
0135 UInt_t fEntrySep;
0136
0137 static const TGFont *fgDefaultFont;
0138 static const TGFont *fgHilightFont;
0139 static const TGGC *fgDefaultGC;
0140 static const TGGC *fgDefaultSelectedGC;
0141 static const TGGC *fgDefaultSelectedBackgroundGC;
0142
0143 void DrawTrianglePattern(GContext_t gc, Int_t l, Int_t t, Int_t r, Int_t b);
0144 void DrawCheckMark(GContext_t gc, Int_t l, Int_t t, Int_t r, Int_t b);
0145 void DrawRCheckMark(GContext_t gc, Int_t l, Int_t t, Int_t r, Int_t b);
0146 void DoRedraw() override;
0147 virtual void DrawEntry(TGMenuEntry *entry);
0148 virtual void Reposition();
0149
0150 static FontStruct_t GetDefaultFontStruct();
0151 static FontStruct_t GetHilightFontStruct();
0152 static const TGGC &GetDefaultGC();
0153 static const TGGC &GetDefaultSelectedGC();
0154 static const TGGC &GetDefaultSelectedBackgroundGC();
0155
0156 private:
0157 TGPopupMenu(const TGPopupMenu&) = delete;
0158 TGPopupMenu& operator=(const TGPopupMenu&) = delete;
0159
0160 public:
0161 TGPopupMenu(const TGWindow *p = nullptr, UInt_t w = 10, UInt_t h = 10,
0162 UInt_t options = 0);
0163 ~TGPopupMenu() override;
0164
0165 virtual void AddEntry(TGHotString *s, Int_t id, void *ud = nullptr,
0166 const TGPicture *p = nullptr, TGMenuEntry *before = nullptr);
0167 virtual void AddEntry(const char *s, Int_t id, void *ud = nullptr,
0168 const TGPicture *p = nullptr, TGMenuEntry *before = nullptr);
0169 virtual void AddSeparator(TGMenuEntry *before = nullptr);
0170 virtual void AddLabel(TGHotString *s, const TGPicture *p = nullptr,
0171 TGMenuEntry *before = nullptr);
0172 virtual void AddLabel(const char *s, const TGPicture *p = nullptr,
0173 TGMenuEntry *before = nullptr);
0174 virtual void AddPopup(TGHotString *s, TGPopupMenu *popup,
0175 TGMenuEntry *before = nullptr, const TGPicture *p = nullptr);
0176 virtual void AddPopup(const char *s, TGPopupMenu *popup,
0177 TGMenuEntry *before = nullptr, const TGPicture *p = nullptr);
0178 virtual void EnableEntry(Int_t id);
0179 virtual void DisableEntry(Int_t id);
0180 virtual Bool_t IsEntryEnabled(Int_t id);
0181 virtual void HideEntry(Int_t id);
0182 virtual Bool_t IsEntryHidden(Int_t id);
0183 virtual void DefaultEntry(Int_t id);
0184 virtual void CheckEntry(Int_t id);
0185 virtual void CheckEntryByData(void *user_data);
0186 virtual void UnCheckEntry(Int_t id);
0187 virtual void UnCheckEntryByData(void *user_data);
0188 virtual void UnCheckEntries();
0189 virtual Bool_t IsEntryChecked(Int_t id);
0190 virtual void RCheckEntry(Int_t id, Int_t IDfirst, Int_t IDlast);
0191 virtual Bool_t IsEntryRChecked(Int_t id);
0192 virtual void PlaceMenu(Int_t x, Int_t y, Bool_t stick_mode,
0193 Bool_t grab_pointer);
0194 virtual Int_t EndMenu(void *&userData);
0195 virtual void DeleteEntry(Int_t id);
0196 virtual void DeleteEntry(TGMenuEntry *entry);
0197 virtual TGMenuEntry *GetEntry(Int_t id);
0198 virtual TGMenuEntry *GetCurrent() const { return fCurrent; }
0199 virtual TGMenuEntry *GetEntry(const char *s);
0200 const TList *GetListOfEntries() const { return fEntryList; }
0201 void DrawBorder() override;
0202 Bool_t HandleButton(Event_t *event) override;
0203 Bool_t HandleMotion(Event_t *event) override;
0204 Bool_t HandleCrossing(Event_t *event) override;
0205 Bool_t HandleTimer(TTimer *t) override;
0206 virtual void Associate(const TGWindow *w) { fMsgWindow = w; }
0207 virtual void SetMenuBar(TGMenuBar *bar) { fMenuBar = bar; }
0208 TGMenuBar *GetMenuBar() const { return fMenuBar; }
0209 void Activate(Bool_t) override {}
0210 virtual void Activate(TGMenuEntry *entry);
0211 void SavePrimitive(std::ostream &out, Option_t *option = "") override;
0212
0213 UInt_t GetEntrySep() const { return fEntrySep; }
0214 virtual void SetEntrySep(UInt_t sep) { fEntrySep = sep; }
0215
0216 virtual void PoppedUp() { Emit("PoppedUp()"); }
0217 virtual void PoppedDown() { Emit("PoppedDown()"); }
0218 virtual void Highlighted(Int_t id) { Emit("Highlighted(Int_t)", id); }
0219 virtual void Activated(Int_t id) { Emit("Activated(Int_t)", id); }
0220
0221 ClassDefOverride(TGPopupMenu,0)
0222 };
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234 class TGMenuTitle : public TGFrame {
0235
0236 protected:
0237 TGPopupMenu *fMenu;
0238 TGHotString *fLabel;
0239 Int_t fTitleId;
0240 void *fTitleData;
0241 Bool_t fState;
0242 Int_t fHkeycode;
0243 FontStruct_t fFontStruct;
0244 Pixel_t fTextColor;
0245 GContext_t fNormGC, fSelGC;
0246
0247 void DoRedraw() override;
0248
0249 static const TGFont *fgDefaultFont;
0250 static const TGGC *fgDefaultSelectedGC;
0251 static const TGGC *fgDefaultGC;
0252
0253 private:
0254 TGMenuTitle(const TGMenuTitle&) = delete;
0255 TGMenuTitle& operator=(const TGMenuTitle&) = delete;
0256
0257 public:
0258 static FontStruct_t GetDefaultFontStruct();
0259 static const TGGC &GetDefaultSelectedGC();
0260 static const TGGC &GetDefaultGC();
0261
0262 TGMenuTitle(const TGWindow *p = nullptr, TGHotString *s = nullptr, TGPopupMenu *menu = nullptr,
0263 GContext_t norm = GetDefaultGC()(),
0264 FontStruct_t font = GetDefaultFontStruct(),
0265 UInt_t options = 0);
0266 ~TGMenuTitle() override { if (fLabel) delete fLabel; }
0267
0268 Pixel_t GetTextColor() const { return fTextColor; }
0269 void SetTextColor(Pixel_t col) { fTextColor = col; }
0270 virtual void SetState(Bool_t state);
0271 Bool_t GetState() const { return fState; }
0272 Int_t GetHotKeyCode() const { return fHkeycode; }
0273 TGPopupMenu *GetMenu() const { return fMenu; }
0274 const char *GetName() const override { return fLabel ? fLabel->GetString() : nullptr; }
0275 virtual void DoSendMessage();
0276 void SavePrimitive(std::ostream &out, Option_t *option = "") override;
0277
0278 ClassDefOverride(TGMenuTitle,0)
0279 };
0280
0281
0282 class TGMenuBar : public TGHorizontalFrame {
0283
0284 friend class TGPopupMenu;
0285
0286 protected:
0287 TGMenuTitle *fCurrent;
0288 TList *fTitles;
0289 Cursor_t fDefaultCursor;
0290 Bool_t fStick;
0291 TList *fTrash;
0292 Bool_t fKeyNavigate;
0293 TGPopupMenu *fMenuMore;
0294 TGLayoutHints *fMenuBarMoreLayout;
0295 Bool_t fWithExt;
0296 TList *fOutLayouts;
0297 TList *fNeededSpace;
0298
0299 virtual void AddFrameBefore(TGFrame *f, TGLayoutHints *l = nullptr,
0300 TGPopupMenu *before = nullptr);
0301
0302 virtual void BindHotKey(Int_t keycode, Bool_t on = kTRUE);
0303 virtual void BindKeys(Bool_t on = kTRUE);
0304 void BindMenu(TGPopupMenu* subMenu, Bool_t on);
0305
0306 private:
0307 TGMenuBar(const TGMenuBar&) = delete;
0308 TGMenuBar& operator=(const TGMenuBar&) = delete;
0309
0310 public:
0311 TGMenuBar(const TGWindow *p = nullptr, UInt_t w = 60, UInt_t h = 20,
0312 UInt_t options = kHorizontalFrame | kRaisedFrame);
0313 ~TGMenuBar() override;
0314
0315 virtual void AddPopup(TGHotString *s, TGPopupMenu *menu, TGLayoutHints *l,
0316 TGPopupMenu *before = nullptr);
0317 virtual void AddPopup(const char *s, TGPopupMenu *menu, TGLayoutHints *l,
0318 TGPopupMenu *before = nullptr);
0319 virtual TGPopupMenu *AddPopup(const TString &s, Int_t padleft = 4, Int_t padright = 0,
0320 Int_t padtop = 0, Int_t padbottom = 0);
0321 virtual void AddTitle(TGMenuTitle *title, TGLayoutHints *l, TGPopupMenu *before = nullptr);
0322
0323 virtual TGPopupMenu *GetPopup(const char *s);
0324 virtual TGPopupMenu *RemovePopup(const char *s);
0325
0326 virtual TGMenuTitle *GetCurrent() const { return fCurrent; }
0327 virtual TList *GetTitles() const { return fTitles; }
0328 Bool_t HandleButton(Event_t *event) override;
0329 Bool_t HandleMotion(Event_t *event) override;
0330 Bool_t HandleKey(Event_t *event) override;
0331 void SavePrimitive(std::ostream &out, Option_t *option = "") override;
0332 void Layout() override;
0333 void PopupConnection();
0334 TGFrameElement* GetLastOnLeft();
0335
0336 ClassDefOverride(TGMenuBar,0)
0337 };
0338
0339 #endif