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