1 ///////////////////////////////////////////////////////////////////////////// 2 // Name: wx/motif/menu.h 3 // Purpose: wxMenu, wxMenuBar classes 4 // Author: Julian Smart 5 // Modified by: 6 // Created: 17/09/98 7 // Copyright: (c) Julian Smart 8 // Licence: wxWindows licence 9 ///////////////////////////////////////////////////////////////////////////// 10 11 #ifndef _WX_MOTIF_MENU_H_ 12 #define _WX_MOTIF_MENU_H_ 13 14 #include "wx/colour.h" 15 #include "wx/font.h" 16 #include "wx/arrstr.h" 17 18 class WXDLLIMPEXP_FWD_CORE wxFrame; 19 20 // ---------------------------------------------------------------------------- 21 // Menu 22 // ---------------------------------------------------------------------------- 23 24 class WXDLLIMPEXP_CORE wxMenu : public wxMenuBase 25 { 26 public: 27 // ctors & dtor 28 wxMenu(const wxString& title, long style = 0) wxMenuBase(title,style)29 : wxMenuBase(title, style) { Init(); } 30 wxMenuBase(style)31 wxMenu(long style = 0) : wxMenuBase(style) { Init(); } 32 33 virtual ~wxMenu(); 34 35 // implement base class virtuals 36 virtual wxMenuItem* DoAppend(wxMenuItem *item); 37 virtual wxMenuItem* DoInsert(size_t pos, wxMenuItem *item); 38 virtual wxMenuItem* DoRemove(wxMenuItem *item); 39 40 virtual void Break(); 41 42 virtual void SetTitle(const wxString& title); 43 44 bool ProcessCommand(wxCommandEvent& event); 45 46 //// Motif-specific GetButtonWidget()47 WXWidget GetButtonWidget() const { return m_buttonWidget; } SetButtonWidget(WXWidget buttonWidget)48 void SetButtonWidget(WXWidget buttonWidget) { m_buttonWidget = buttonWidget; } 49 GetMainWidget()50 WXWidget GetMainWidget() const { return m_menuWidget; } 51 GetId()52 int GetId() const { return m_menuId; } SetId(int id)53 void SetId(int id) { m_menuId = id; } 54 SetMenuBar(wxMenuBar * menuBar)55 void SetMenuBar(wxMenuBar* menuBar) { m_menuBar = menuBar; } GetMenuBar()56 wxMenuBar* GetMenuBar() const { return m_menuBar; } 57 58 void CreatePopup(WXWidget logicalParent, int x, int y); 59 void DestroyPopup(); 60 void ShowPopup(int x, int y); 61 void HidePopup(); 62 63 WXWidget CreateMenu(wxMenuBar *menuBar, WXWidget parent, wxMenu *topMenu, 64 size_t index, const wxString& title = wxEmptyString, 65 bool isPulldown = false); 66 67 // For popups, need to destroy, then recreate menu for a different (or 68 // possibly same) window, since the parent may change. 69 void DestroyMenu(bool full); 70 WXWidget FindMenuItem(int id, wxMenuItem **it = NULL) const; 71 GetBackgroundColour()72 const wxColour& GetBackgroundColour() const { return m_backgroundColour; } GetForegroundColour()73 const wxColour& GetForegroundColour() const { return m_foregroundColour; } GetFont()74 const wxFont& GetFont() const { return m_font; } 75 76 void SetBackgroundColour(const wxColour& colour); 77 void SetForegroundColour(const wxColour& colour); 78 void SetFont(const wxFont& colour); 79 void ChangeFont(bool keepOriginalSize = false); 80 GetHandle()81 WXWidget GetHandle() const { return m_menuWidget; } 82 IsTearOff()83 bool IsTearOff() const { return (m_style & wxMENU_TEAROFF) != 0; } 84 85 void DestroyWidgetAndDetach(); 86 public: 87 // Motif-specific data 88 int m_numColumns; 89 WXWidget m_menuWidget; 90 WXWidget m_popupShell; // For holding the popup shell widget 91 WXWidget m_buttonWidget; // The actual string, so we can grey it etc. 92 int m_menuId; 93 wxMenu* m_topLevelMenu ; 94 bool m_ownedByMenuBar; 95 wxColour m_foregroundColour; 96 wxColour m_backgroundColour; 97 wxFont m_font; 98 99 private: 100 // common code for both constructors: 101 void Init(); 102 103 DECLARE_DYNAMIC_CLASS(wxMenu) 104 }; 105 106 // ---------------------------------------------------------------------------- 107 // Menu Bar 108 // ---------------------------------------------------------------------------- 109 110 class WXDLLIMPEXP_CORE wxMenuBar : public wxMenuBarBase 111 { 112 public: wxMenuBar()113 wxMenuBar() { Init(); } wxMenuBar(long WXUNUSED (style))114 wxMenuBar(long WXUNUSED(style)) { Init(); } 115 wxMenuBar(size_t n, wxMenu *menus[], const wxString titles[], long style = 0); 116 wxMenuBar(size_t n, wxMenu *menus[], const wxArrayString& titles, long style = 0); 117 virtual ~wxMenuBar(); 118 119 // implement base class (pure) virtuals 120 // ------------------------------------ 121 122 virtual bool Append( wxMenu *menu, const wxString &title ); 123 virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title); 124 virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title); 125 virtual wxMenu *Remove(size_t pos); 126 127 virtual int FindMenuItem(const wxString& menuString, 128 const wxString& itemString) const; 129 virtual wxMenuItem* FindItem( int id, wxMenu **menu = NULL ) const; 130 131 virtual void EnableTop( size_t pos, bool flag ); 132 virtual void SetMenuLabel( size_t pos, const wxString& label ); 133 virtual wxString GetMenuLabel( size_t pos ) const; 134 135 // implementation only from now on 136 // ------------------------------- 137 GetMenuBarFrame()138 wxFrame* GetMenuBarFrame() const { return m_menuBarFrame; } SetMenuBarFrame(wxFrame * frame)139 void SetMenuBarFrame(wxFrame* frame) { m_menuBarFrame = frame; } GetMainWidget()140 WXWidget GetMainWidget() const { return m_mainWidget; } SetMainWidget(WXWidget widget)141 void SetMainWidget(WXWidget widget) { m_mainWidget = widget; } 142 143 // Create menubar 144 bool CreateMenuBar(wxFrame* frame); 145 146 // Destroy menubar, but keep data structures intact so we can recreate it. 147 bool DestroyMenuBar(); 148 GetBackgroundColour()149 const wxColour& GetBackgroundColour() const { return m_backgroundColour; } GetForegroundColour()150 const wxColour& GetForegroundColour() const { return m_foregroundColour; } GetFont()151 const wxFont& GetFont() const { return m_font; } 152 153 virtual bool SetBackgroundColour(const wxColour& colour); 154 virtual bool SetForegroundColour(const wxColour& colour); 155 virtual bool SetFont(const wxFont& colour); 156 void ChangeFont(bool keepOriginalSize = false); 157 158 public: 159 // common part of all ctors 160 void Init(); 161 162 wxArrayString m_titles; 163 wxFrame *m_menuBarFrame; 164 165 WXWidget m_mainWidget; 166 167 wxColour m_foregroundColour; 168 wxColour m_backgroundColour; 169 wxFont m_font; 170 171 DECLARE_DYNAMIC_CLASS(wxMenuBar) 172 }; 173 174 #endif // _WX_MOTIF_MENU_H_ 175