1 ///////////////////////////////////////////////////////////////////////////// 2 // Name: wx/osx/menu.h 3 // Purpose: wxMenu, wxMenuBar classes 4 // Author: Stefan Csomor 5 // Modified by: 6 // Created: 1998-01-01 7 // Copyright: (c) Stefan Csomor 8 // Licence: wxWindows licence 9 ///////////////////////////////////////////////////////////////////////////// 10 11 #ifndef _WX_MENU_H_ 12 #define _WX_MENU_H_ 13 14 class WXDLLIMPEXP_FWD_CORE wxFrame; 15 16 #include "wx/arrstr.h" 17 18 // ---------------------------------------------------------------------------- 19 // Menu 20 // ---------------------------------------------------------------------------- 21 22 class WXDLLIMPEXP_FWD_CORE wxMenuImpl ; 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 virtual void Break(); 36 37 virtual void SetTitle(const wxString& title); 38 39 bool ProcessCommand(wxCommandEvent& event); 40 41 // get the menu handle 42 WXHMENU GetHMenu() const ; 43 44 // implementation only from now on 45 // ------------------------------- 46 47 bool HandleCommandUpdateStatus( wxMenuItem* menuItem, wxWindow* senderWindow = NULL); 48 bool HandleCommandProcess( wxMenuItem* menuItem, wxWindow* senderWindow = NULL); 49 void HandleMenuItemHighlighted( wxMenuItem* menuItem ); 50 void HandleMenuOpened(); 51 void HandleMenuClosed(); 52 GetPeer()53 wxMenuImpl* GetPeer() { return m_peer; } 54 55 // make sure we can veto 56 void SetAllowRearrange( bool allow ); AllowRearrange()57 bool AllowRearrange() const { return m_allowRearrange; } 58 59 // if a menu is used purely for internal implementation reasons (eg wxChoice) 60 // we don't want native menu events being triggered 61 void SetNoEventsMode( bool noEvents ); GetNoEventsMode()62 bool GetNoEventsMode() const { return m_noEventsMode; } 63 protected: 64 // hide special menu items like exit, preferences etc 65 // that are expected in the app menu 66 void DoRearrange() ; 67 68 bool DoHandleMenuEvent( wxEvent& evt ); 69 virtual wxMenuItem* DoAppend(wxMenuItem *item); 70 virtual wxMenuItem* DoInsert(size_t pos, wxMenuItem *item); 71 virtual wxMenuItem* DoRemove(wxMenuItem *item); 72 73 private: 74 // common part of all ctors 75 void Init(); 76 77 // common part of Do{Append,Insert}(): behaves as Append if pos == -1 78 bool DoInsertOrAppend(wxMenuItem *item, size_t pos = (size_t)-1); 79 80 // Common part of HandleMenu{Opened,Closed}(). 81 void DoHandleMenuOpenedOrClosed(wxEventType evtType); 82 83 84 // if TRUE, insert a break before appending the next item 85 bool m_doBreak; 86 87 // in this menu rearranging of menu items (esp hiding) is allowed 88 bool m_allowRearrange; 89 90 // don't trigger native events 91 bool m_noEventsMode; 92 93 wxMenuImpl* m_peer; 94 95 DECLARE_DYNAMIC_CLASS(wxMenu) 96 }; 97 98 #if wxOSX_USE_COCOA_OR_CARBON 99 100 // the iphone only has popup-menus 101 102 // ---------------------------------------------------------------------------- 103 // Menu Bar (a la Windows) 104 // ---------------------------------------------------------------------------- 105 106 class WXDLLIMPEXP_CORE wxMenuBar : public wxMenuBarBase 107 { 108 public: 109 // ctors & dtor 110 // default constructor 111 wxMenuBar(); 112 // unused under MSW 113 wxMenuBar(long style); 114 // menubar takes ownership of the menus arrays but copies the titles 115 wxMenuBar(size_t n, wxMenu *menus[], const wxString titles[], long style = 0); 116 virtual ~wxMenuBar(); 117 118 // menubar construction 119 virtual bool Append( wxMenu *menu, const wxString &title ); 120 virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title); 121 virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title); 122 virtual wxMenu *Remove(size_t pos); 123 124 virtual void EnableTop( size_t pos, bool flag ); 125 virtual bool IsEnabledTop(size_t pos) const; 126 virtual void SetMenuLabel( size_t pos, const wxString& label ); 127 virtual wxString GetMenuLabel( size_t pos ) const; 128 virtual bool Enable( bool enable = true ); 129 // for virtual function hiding Enable(int itemid,bool enable)130 virtual void Enable( int itemid, bool enable ) 131 { 132 wxMenuBarBase::Enable( itemid, enable ); 133 } 134 135 // implementation from now on 136 void Detach(); 137 138 // returns TRUE if we're attached to a frame IsAttached()139 bool IsAttached() const { return m_menuBarFrame != NULL; } 140 // get the frame we live in GetFrame()141 wxFrame *GetFrame() const { return m_menuBarFrame; } 142 // attach to a frame 143 void Attach(wxFrame *frame); 144 145 // if the menubar is modified, the display is not updated automatically, 146 // call this function to update it (m_menuBarFrame should be !NULL) 147 void Refresh(bool eraseBackground = true, const wxRect *rect = NULL); 148 149 #if wxABI_VERSION >= 30001 OSXGetAppleMenu()150 wxMenu *OSXGetAppleMenu() const { return m_appleMenu; } 151 #endif 152 SetAutoWindowMenu(bool enable)153 static void SetAutoWindowMenu( bool enable ) { s_macAutoWindowMenu = enable ; } GetAutoWindowMenu()154 static bool GetAutoWindowMenu() { return s_macAutoWindowMenu ; } 155 156 void MacInstallMenuBar() ; MacGetInstalledMenuBar()157 static wxMenuBar* MacGetInstalledMenuBar() { return s_macInstalledMenuBar ; } MacSetCommonMenuBar(wxMenuBar * menubar)158 static void MacSetCommonMenuBar(wxMenuBar* menubar) { s_macCommonMenuBar=menubar; } MacGetCommonMenuBar()159 static wxMenuBar* MacGetCommonMenuBar() { return s_macCommonMenuBar; } 160 161 MacGetWindowMenuHMenu()162 static WXHMENU MacGetWindowMenuHMenu() { return s_macWindowMenuHandle ; } 163 protected: 164 // common part of all ctors 165 void Init(); 166 167 static bool s_macAutoWindowMenu ; 168 static WXHMENU s_macWindowMenuHandle ; 169 170 private: 171 static wxMenuBar* s_macInstalledMenuBar ; 172 static wxMenuBar* s_macCommonMenuBar ; 173 174 wxMenu* m_rootMenu; 175 wxMenu* m_appleMenu; 176 177 DECLARE_DYNAMIC_CLASS(wxMenuBar) 178 }; 179 180 #endif 181 182 #endif // _WX_MENU_H_ 183