Back to home page

EIC code displayed by LXR

 
 

    


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 // @(#)root/gui:$Id$
0002 // Author: Fons Rademakers   09/01/98
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2021, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
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 //--- Menu entry status mask
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 //--- Menu entry types
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 /** \class TGMenuEntry
0050 
0051 This class contains all information about a menu entry.
0052 It is a fully protected class used internally by TGPopupMenu.
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;   ///< the entry id (used for event processing)
0064    void             *fUserData;  ///< pointer to user data structure
0065    EMenuEntryType    fType;      ///< type of entry
0066    Int_t             fStatus;    ///< entry status (OR of EMenuEntryState)
0067    Int_t             fEx, fEy;   ///< position of entry
0068    UInt_t            fEw, fEh;   ///< width and height of entry
0069    TGHotString      *fLabel;     ///< menu entry label
0070    TGString         *fShortcut;  ///< menu entry shortcut
0071    const TGPicture  *fPic;       ///< menu entry icon
0072    TGPopupMenu      *fPopup;     ///< pointer to popup menu (in case of cascading menus)
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);  // Menu entry class
0099 };
0100 
0101 
0102 /** \class TGPopupMenu
0103 
0104 This class creates a popup menu object. Popup menu's are attached
0105 to TGMenuBar objects.
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;     ///< list of menu entries
0118    TGMenuEntry       *fCurrent;       ///< currently selected menu entry
0119    Bool_t             fStick;         ///< stick mode (popup menu stays sticked on screen)
0120    Bool_t             fHasGrab;       ///< true if menu has grabbed pointer
0121    Bool_t             fPoppedUp;      ///< true if menu is currently popped up
0122    UInt_t             fXl;            ///< Max width of all menu entries
0123    UInt_t             fMenuWidth;     ///< width of popup menu
0124    UInt_t             fMenuHeight;    ///< height of popup menu
0125    TTimer            *fDelay;         ///< delay before popping up cascading menu
0126    GContext_t         fNormGC;        ///< normal drawing graphics context
0127    GContext_t         fSelGC;         ///< graphics context for drawing selections
0128    GContext_t         fSelbackGC;     ///< graphics context for drawing selection background
0129    FontStruct_t       fFontStruct;    ///< font to draw menu entries
0130    FontStruct_t       fHifontStruct;  ///< font to draw highlighted entries
0131    Cursor_t           fDefaultCursor; ///< right pointing cursor
0132    const TGWindow    *fMsgWindow;     ///< window which handles menu events
0133    TGMenuBar         *fMenuBar;       ///< menu bar (if any)
0134    TGSplitButton     *fSplitButton;   ///< split button (if any)
0135    UInt_t             fEntrySep;      ///< separation distance between entries
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()"); }                        // *SIGNAL*
0217    virtual void PoppedDown() { Emit("PoppedDown()"); }                    // *SIGNAL*
0218    virtual void Highlighted(Int_t id) { Emit("Highlighted(Int_t)", id); } // *SIGNAL*
0219    virtual void Activated(Int_t id) { Emit("Activated(Int_t)", id); }     // *SIGNAL*
0220 
0221    ClassDefOverride(TGPopupMenu,0)  // Popup menu
0222 };
0223 
0224 
0225 /** \class TGMenuTitle
0226 
0227 This class creates a menu title. A menu title is a frame
0228 to which a popup menu can be attached. Menu titles are automatically
0229 created when adding a popup menu to a menubar.
0230 
0231 */
0232 
0233 
0234 class TGMenuTitle : public TGFrame {
0235 
0236 protected:
0237    TGPopupMenu    *fMenu;             ///< attached popup menu
0238    TGHotString    *fLabel;            ///< menu title
0239    Int_t           fTitleId;          ///< id of selected menu item
0240    void           *fTitleData;        ///< user data associated with selected item
0241    Bool_t          fState;            ///< menu title state (active/not active)
0242    Int_t           fHkeycode;         ///< hot key code
0243    FontStruct_t    fFontStruct;       ///< font
0244    Pixel_t         fTextColor;        ///< text color
0245    GContext_t      fNormGC, fSelGC;   ///< normal and selection graphics contexts
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)  // Menu title class
0279 };
0280 
0281 
0282 class TGMenuBar : public TGHorizontalFrame {
0283 
0284 friend class TGPopupMenu;
0285 
0286 protected:
0287    TGMenuTitle   *fCurrent;            ///< current menu title
0288    TList         *fTitles;             ///< list of menu titles
0289    Cursor_t       fDefaultCursor;      ///< right pointing cursor
0290    Bool_t         fStick;              ///< stick mode (popup menu stays sticked on screen)
0291    TList         *fTrash;              ///< garbage
0292    Bool_t         fKeyNavigate;        ///< kTRUE if arrow key navigation is on
0293    TGPopupMenu   *fMenuMore;           ///< extra >> menu
0294    TGLayoutHints *fMenuBarMoreLayout;  ///< layout of the extra menu
0295    Bool_t         fWithExt;            ///< indicates whether the >> menu is shown or not
0296    TList         *fOutLayouts;         ///< keeps trace of layouts of hidden menus
0297    TList         *fNeededSpace;        ///< keeps trace of space needed for hidden menus
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)  // Menu bar class
0337 };
0338 
0339 #endif