TGMenu.h

Go to the documentation of this file.
00001 // @(#)root/gui:$Id: TGMenu.h 31295 2009-11-18 20:29:26Z rdm $
00002 // Author: Fons Rademakers   09/01/98
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #ifndef ROOT_TGMenu
00013 #define ROOT_TGMenu
00014 
00015 
00016 //////////////////////////////////////////////////////////////////////////
00017 //                                                                      //
00018 // TGMenuBar, TGPopupMenu, TGMenuTitle and TGMenuEntry                  //
00019 //                                                                      //
00020 // This header contains all different menu classes.                     //
00021 //                                                                      //
00022 // Selecting a menu item will generate the event:                       //
00023 // kC_COMMAND, kCM_MENU, menu id, user data.                            //
00024 //                                                                      //
00025 //////////////////////////////////////////////////////////////////////////
00026 
00027 #ifndef ROOT_TGFrame
00028 #include "TGFrame.h"
00029 #endif
00030 #ifndef ROOT_TGString
00031 #include "TGString.h"
00032 #endif
00033 #ifndef ROOT_TGPicture
00034 #include "TGPicture.h"
00035 #endif
00036 #ifndef ROOT_TGWidget
00037 #include "TGWidget.h"
00038 #endif
00039 
00040 //--- Menu entry status mask
00041 
00042 enum EMenuEntryState {
00043    kMenuActiveMask     = BIT(0),
00044    kMenuEnableMask     = BIT(1),
00045    kMenuDefaultMask    = BIT(2),
00046    kMenuCheckedMask    = BIT(3),
00047    kMenuRadioMask      = BIT(4),
00048    kMenuHideMask       = BIT(5),
00049    kMenuRadioEntryMask = BIT(6)
00050 };
00051 
00052 //--- Menu entry types
00053 
00054 enum EMenuEntryType {
00055    kMenuSeparator,
00056    kMenuLabel,
00057    kMenuEntry,
00058    kMenuPopup
00059 };
00060 
00061 
00062 class TGPopupMenu;
00063 class TGMenuBar;
00064 class TGMenuTitle;
00065 class TTimer;
00066 class TGSplitButton;
00067 
00068 //////////////////////////////////////////////////////////////////////////
00069 //                                                                      //
00070 // TGMenuEntry                                                          //
00071 //                                                                      //
00072 // This class contains all information about a menu entry.              //
00073 // It is a fully protected class used internally by TGPopupMenu.        //
00074 //                                                                      //
00075 //////////////////////////////////////////////////////////////////////////
00076 
00077 class TGMenuEntry : public TObject {
00078 
00079 friend class TGPopupMenu;
00080 friend class TGMenuBar;
00081 
00082 protected:
00083    Int_t             fEntryId;   // the entry id (used for event processing)
00084    void             *fUserData;  // pointer to user data structure
00085    EMenuEntryType    fType;      // type of entry
00086    Int_t             fStatus;    // entry status (OR of EMenuEntryState)
00087    Int_t             fEx, fEy;   // position of entry
00088    UInt_t            fEw, fEh;   // width and height of entry
00089    TGHotString      *fLabel;     // menu entry label
00090    TGString         *fShortcut;  // menu entry shortcut
00091    const TGPicture  *fPic;       // menu entry icon
00092    TGPopupMenu      *fPopup;     // pointer to popup menu (in case of cascading menus)
00093 
00094 private:
00095    TGMenuEntry(const TGMenuEntry&);             // not implemented
00096    TGMenuEntry& operator=(const TGMenuEntry&);  // not implemented
00097 
00098 public:
00099    TGMenuEntry(): fEntryId(0), fUserData(0), fType(), fStatus(0),
00100       fEx(0), fEy(0), fEw(0), fEh(0), fLabel(0), fShortcut(0), fPic(0), fPopup(0) { }
00101    virtual ~TGMenuEntry() { if (fLabel) delete fLabel; if (fShortcut) delete fShortcut; }
00102 
00103    Int_t          GetEntryId() const { return fEntryId; }
00104    const char    *GetName() const { return fLabel ? fLabel->GetString() : 0; }
00105    const char    *GetShortcutText() const { return fShortcut ? fShortcut->GetString() : 0; }
00106    virtual Int_t  GetStatus() const { return fStatus; }
00107    EMenuEntryType GetType() const { return fType; }
00108    TGPopupMenu   *GetPopup() const { return fPopup; }
00109    TGHotString   *GetLabel() const  { return fLabel; }
00110    TGString      *GetShortcut() const { return fShortcut; }
00111    Int_t          GetEx() const { return fEx; }
00112    Int_t          GetEy() const { return fEy; }
00113    UInt_t         GetEw() const { return fEw; }
00114    UInt_t         GetEh() const { return fEh; }
00115    const TGPicture *GetPic() const { return fPic; }
00116    void          *GetUserData() const { return fUserData; }
00117 
00118    ClassDef(TGMenuEntry,0);  // Menu entry class
00119 };
00120 
00121 
00122 //////////////////////////////////////////////////////////////////////////
00123 //                                                                      //
00124 // TGPopupMenu                                                          //
00125 //                                                                      //
00126 // This class creates a popup menu object. Popup menu's are attached    //
00127 // to TGMenuBar objects.                                                //
00128 //                                                                      //
00129 //////////////////////////////////////////////////////////////////////////
00130 
00131 class TGPopupMenu : public TGFrame {
00132 
00133 friend class TGMenuTitle;
00134 friend class TGMenuBar;
00135 friend class TGSplitButton;
00136 
00137 protected:
00138    TList             *fEntryList;     // list of menu entries
00139    TGMenuEntry       *fCurrent;       // currently selected menu entry
00140    Bool_t             fStick;         // stick mode (popup menu stays sticked on screen)
00141    Bool_t             fHasGrab;       // true if menu has grabbed pointer
00142    Bool_t             fPoppedUp;      // true if menu is currently popped up
00143    UInt_t             fXl;            // Max width of all menu entries
00144    UInt_t             fMenuWidth;     // width of popup menu
00145    UInt_t             fMenuHeight;    // height of popup menu
00146    TTimer            *fDelay;         // delay before poping up cascading menu
00147    GContext_t         fNormGC;        // normal drawing graphics context
00148    GContext_t         fSelGC;         // graphics context for drawing selections
00149    GContext_t         fSelbackGC;     // graphics context for drawing selection background
00150    FontStruct_t       fFontStruct;    // font to draw menu entries
00151    FontStruct_t       fHifontStruct;  // font to draw highlighted entries
00152    Cursor_t           fDefaultCursor; // right pointing cursor
00153    const TGWindow    *fMsgWindow;     // window which handles menu events
00154    TGMenuBar         *fMenuBar;       // menu bar (if any)
00155    TGSplitButton     *fSplitButton;   // split button (if any)
00156    UInt_t             fEntrySep;      // separation distance between ebtris
00157 
00158    static const TGFont *fgDefaultFont;
00159    static const TGFont *fgHilightFont;
00160    static const TGGC   *fgDefaultGC;
00161    static const TGGC   *fgDefaultSelectedGC;
00162    static const TGGC   *fgDefaultSelectedBackgroundGC;
00163 
00164    void DrawTrianglePattern(GContext_t gc, Int_t l, Int_t t, Int_t r, Int_t b);
00165    void DrawCheckMark(GContext_t gc, Int_t l, Int_t t, Int_t r, Int_t b);
00166    void DrawRCheckMark(GContext_t gc, Int_t l, Int_t t, Int_t r, Int_t b);
00167    virtual void DoRedraw();
00168    virtual void DrawEntry(TGMenuEntry *entry);
00169    virtual void Reposition();
00170 
00171    static FontStruct_t  GetDefaultFontStruct();
00172    static FontStruct_t  GetHilightFontStruct();
00173    static const TGGC   &GetDefaultGC();
00174    static const TGGC   &GetDefaultSelectedGC();
00175    static const TGGC   &GetDefaultSelectedBackgroundGC();
00176 
00177 private:
00178    TGPopupMenu(const TGPopupMenu&);             // not implemented
00179    TGPopupMenu& operator=(const TGPopupMenu&);  // not implemented
00180 
00181 public:
00182    TGPopupMenu(const TGWindow *p = 0, UInt_t w = 10, UInt_t h = 10,
00183                UInt_t options = 0);
00184    virtual ~TGPopupMenu();
00185 
00186    virtual void AddEntry(TGHotString *s, Int_t id, void *ud = 0,
00187                          const TGPicture *p = 0, TGMenuEntry *before = 0);
00188    virtual void AddEntry(const char *s, Int_t id, void *ud = 0,
00189                          const TGPicture *p = 0, TGMenuEntry *before = 0);
00190    virtual void AddSeparator(TGMenuEntry *before = 0);
00191    virtual void AddLabel(TGHotString *s, const TGPicture *p = 0,
00192                          TGMenuEntry *before = 0);
00193    virtual void AddLabel(const char *s, const TGPicture *p = 0,
00194                          TGMenuEntry *before = 0);
00195    virtual void AddPopup(TGHotString *s, TGPopupMenu *popup,
00196                          TGMenuEntry *before = 0, const TGPicture *p = 0);
00197    virtual void AddPopup(const char *s, TGPopupMenu *popup,
00198                          TGMenuEntry *before = 0, const TGPicture *p = 0);
00199    virtual void   EnableEntry(Int_t id);
00200    virtual void   DisableEntry(Int_t id);
00201    virtual Bool_t IsEntryEnabled(Int_t id);
00202    virtual void   HideEntry(Int_t id);
00203    virtual Bool_t IsEntryHidden(Int_t id);
00204    virtual void   DefaultEntry(Int_t id);
00205    virtual void   CheckEntry(Int_t id);
00206    virtual void   CheckEntryByData(void *user_data);
00207    virtual void   UnCheckEntry(Int_t id);
00208    virtual void   UnCheckEntryByData(void *user_data);
00209    virtual void   UnCheckEntries();
00210    virtual Bool_t IsEntryChecked(Int_t id);
00211    virtual void   RCheckEntry(Int_t id, Int_t IDfirst, Int_t IDlast);
00212    virtual Bool_t IsEntryRChecked(Int_t id);
00213    virtual void   PlaceMenu(Int_t x, Int_t y, Bool_t stick_mode,
00214                             Bool_t grab_pointer);
00215    virtual Int_t  EndMenu(void *&userData);
00216    virtual void   DeleteEntry(Int_t id);
00217    virtual void   DeleteEntry(TGMenuEntry *entry);
00218    virtual TGMenuEntry *GetEntry(Int_t id);
00219    virtual TGMenuEntry *GetCurrent() const { return fCurrent; }
00220    virtual TGMenuEntry *GetEntry(const char *s);
00221    const TList    *GetListOfEntries() const { return fEntryList; }
00222    virtual void    DrawBorder();
00223    virtual Bool_t  HandleButton(Event_t *event);
00224    virtual Bool_t  HandleMotion(Event_t *event);
00225    virtual Bool_t  HandleCrossing(Event_t *event);
00226    virtual Bool_t  HandleTimer(TTimer *t);
00227    virtual void    Associate(const TGWindow *w) { fMsgWindow = w; }
00228    virtual void    SetMenuBar(TGMenuBar *bar) { fMenuBar = bar; }
00229    TGMenuBar      *GetMenuBar() const { return fMenuBar; }
00230    virtual void    Activate(Bool_t) { }
00231    virtual void    Activate(TGMenuEntry *entry);
00232    virtual void    SavePrimitive(ostream &out, Option_t *option = "");
00233 
00234    UInt_t GetEntrySep()  const { return fEntrySep; }
00235    virtual void SetEntrySep(UInt_t sep)  { fEntrySep = sep; }
00236 
00237    virtual void PoppedUp() { Emit("PoppedUp()"); }                        // *SIGNAL*
00238    virtual void PoppedDown() { Emit("PoppedDown()"); }                    // *SIGNAL*
00239    virtual void Highlighted(Int_t id) { Emit("Highlighted(Int_t)", id); } // *SIGNAL*
00240    virtual void Activated(Int_t id) { Emit("Activated(Int_t)", id); }     // *SIGNAL*
00241 
00242    ClassDef(TGPopupMenu,0)  // Popup menu
00243 };
00244 
00245 
00246 //////////////////////////////////////////////////////////////////////////
00247 //                                                                      //
00248 // TGMenuTitle                                                          //
00249 //                                                                      //
00250 // This class creates a menu title. A menu title is a frame             //
00251 // to which a popup menu can be attached. Menu titles are automatically //
00252 // created when adding a popup menu to a menubar.                       //
00253 //                                                                      //
00254 //////////////////////////////////////////////////////////////////////////
00255 
00256 class TGMenuTitle : public TGFrame {
00257 
00258 protected:
00259    TGPopupMenu    *fMenu;             // attached popup menu
00260    TGHotString    *fLabel;            // menu title
00261    Int_t           fTitleId;          // id of selected menu item
00262    void           *fTitleData;        // user data associated with selected item
00263    Bool_t          fState;            // menu title state (active/not active)
00264    Int_t           fHkeycode;         // hot key code
00265    FontStruct_t    fFontStruct;       // font
00266    Pixel_t         fTextColor;        // text color
00267    GContext_t      fNormGC, fSelGC;   // normal and selection graphics contexts
00268 
00269    virtual void DoRedraw();
00270 
00271    static const TGFont *fgDefaultFont;
00272    static const TGGC   *fgDefaultSelectedGC;
00273    static const TGGC   *fgDefaultGC;
00274 
00275 private:
00276    TGMenuTitle(const TGMenuTitle&);             // not implemented
00277    TGMenuTitle& operator=(const TGMenuTitle&);  // not implemented
00278 
00279 public:
00280    static FontStruct_t  GetDefaultFontStruct();
00281    static const TGGC   &GetDefaultSelectedGC();
00282    static const TGGC   &GetDefaultGC();
00283 
00284    TGMenuTitle(const TGWindow *p = 0, TGHotString *s = 0, TGPopupMenu *menu = 0,
00285                GContext_t norm = GetDefaultGC()(),
00286                FontStruct_t font = GetDefaultFontStruct(),
00287                UInt_t options = 0);
00288    virtual ~TGMenuTitle() { if (fLabel) delete fLabel; }
00289 
00290    Pixel_t      GetTextColor() const { return fTextColor; }
00291    void         SetTextColor(Pixel_t col) { fTextColor = col; }
00292    virtual void SetState(Bool_t state);
00293    Bool_t       GetState() const { return fState; }
00294    Int_t        GetHotKeyCode() const { return fHkeycode; }
00295    TGPopupMenu *GetMenu() const { return fMenu; }
00296    const char  *GetName() const { return fLabel ? fLabel->GetString() : 0; }
00297    virtual void DoSendMessage();
00298    virtual void SavePrimitive(ostream &out, Option_t *option = "");
00299 
00300    ClassDef(TGMenuTitle,0)  // Menu title class
00301 };
00302 
00303 
00304 //////////////////////////////////////////////////////////////////////////
00305 //                                                                      //
00306 // TGMenuBar                                                            //
00307 //                                                                      //
00308 // This class creates a menu bar.                                       //
00309 //                                                                      //
00310 //////////////////////////////////////////////////////////////////////////
00311 
00312 class TGMenuBar : public TGHorizontalFrame {
00313 
00314 friend class TGPopupMenu;
00315 
00316 protected:
00317    TGMenuTitle   *fCurrent;            // current menu title
00318    TList         *fTitles;             // list of menu titles
00319    Cursor_t       fDefaultCursor;      // right pointing cursor
00320    Bool_t         fStick;              // stick mode (popup menu stays sticked on screen)
00321    TList         *fTrash;              // garbage
00322    Bool_t         fKeyNavigate;        // kTRUE if arrow key navigation is on
00323    TGPopupMenu   *fMenuMore;           // extra >> menu
00324    TGLayoutHints *fMenuBarMoreLayout;  // layout of the extra menu
00325    Bool_t         fWithExt;            // indicates whether the >> menu is shown or not
00326    TList         *fOutLayouts;         // keeps trace of layouts of hidden menus
00327    TList         *fNeededSpace;        // keeps trace of space needed for hidden menus
00328 
00329    virtual void AddFrameBefore(TGFrame *f, TGLayoutHints *l = 0,
00330                                TGPopupMenu *before = 0);
00331 
00332    virtual void BindHotKey(Int_t keycode, Bool_t on = kTRUE);
00333    virtual void BindKeys(Bool_t on = kTRUE);
00334            void BindMenu(TGPopupMenu* subMenu, Bool_t on);
00335 
00336 private:
00337    TGMenuBar(const TGMenuBar&);             // not implemented
00338    TGMenuBar& operator=(const TGMenuBar&);  // not implemented
00339 
00340 public:
00341    TGMenuBar(const TGWindow *p = 0, UInt_t w = 60, UInt_t h = 20,
00342              UInt_t options = kHorizontalFrame | kRaisedFrame);
00343    virtual ~TGMenuBar();
00344 
00345    virtual void AddPopup(TGHotString *s, TGPopupMenu *menu, TGLayoutHints *l,
00346                          TGPopupMenu *before = 0);
00347    virtual void AddPopup(const char *s, TGPopupMenu *menu, TGLayoutHints *l,
00348                          TGPopupMenu *before = 0);
00349    virtual TGPopupMenu *AddPopup(const TString &s, Int_t padleft = 4, Int_t padright = 0,
00350                                  Int_t padtop = 0, Int_t padbottom = 0);
00351    virtual void AddTitle(TGMenuTitle *title, TGLayoutHints *l, TGPopupMenu *before = 0);
00352 
00353    virtual TGPopupMenu *GetPopup(const char *s);
00354    virtual TGPopupMenu *RemovePopup(const char *s);
00355 
00356    virtual TGMenuTitle *GetCurrent() const { return fCurrent; }
00357    virtual TList  *GetTitles() const { return fTitles; }
00358    virtual Bool_t  HandleButton(Event_t *event);
00359    virtual Bool_t  HandleMotion(Event_t *event);
00360    virtual Bool_t  HandleKey(Event_t *event);
00361    virtual void    SavePrimitive(ostream &out, Option_t *option = "");
00362    virtual void    Layout();
00363            void    PopupConnection();
00364    TGFrameElement* GetLastOnLeft();
00365 
00366    ClassDef(TGMenuBar,0)  // Menu bar class
00367 };
00368 
00369 #endif

Generated on Tue Jul 5 14:20:06 2011 for ROOT_528-00b_version by  doxygen 1.5.1