]> git.saurik.com Git - wxWidgets.git/blob - include/wx/osx/menu.h
make more wxFileName methods const (closes #10887)
[wxWidgets.git] / include / wx / osx / menu.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: menu.h
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
44 // semi-private accessors
45
46 // get the window which contains this menu
47 wxWindow *GetWindow() const;
48 // get the menu handle
49 WXHMENU GetHMenu() const ;
50
51 // implementation only from now on
52 // -------------------------------
53
54 bool HandleCommandUpdateStatus( wxMenuItem* menuItem, wxWindow* senderWindow = NULL);
55 bool HandleCommandProcess( wxMenuItem* menuItem, wxWindow* senderWindow = NULL);
56 void HandleMenuItemHighlighted( wxMenuItem* menuItem );
57 void HandleMenuOpened();
58 void HandleMenuClosed();
59
60 wxMenuImpl* GetPeer() { return m_peer; }
61
62 // make sure we can veto
63 void SetAllowRearrange( bool allow );
64 bool AllowRearrange() const { return m_allowRearrange; }
65
66 // if a menu is used purely for internal implementation reasons (eg wxChoice)
67 // we don't want native menu events being triggered
68 void SetNoEventsMode( bool noEvents );
69 bool GetNoEventsMode() const { return m_noEventsMode; }
70 protected:
71 // hide special menu items like exit, preferences etc
72 // that are expected in the app menu
73 void DoRearrange() ;
74
75 bool DoHandleMenuEvent( wxEvent& evt );
76 virtual wxMenuItem* DoAppend(wxMenuItem *item);
77 virtual wxMenuItem* DoInsert(size_t pos, wxMenuItem *item);
78 virtual wxMenuItem* DoRemove(wxMenuItem *item);
79
80 private:
81 // common part of all ctors
82 void Init();
83
84 // common part of Append/Insert (behaves as Append is pos == (size_t)-1)
85 bool DoInsertOrAppend(wxMenuItem *item, size_t pos = (size_t)-1);
86
87 // terminate the current radio group, if any
88 void EndRadioGroup();
89
90 // if TRUE, insert a breal before appending the next item
91 bool m_doBreak;
92
93 // in this menu rearranging of menu items (esp hiding) is allowed
94 bool m_allowRearrange;
95
96 // don't trigger native events
97 bool m_noEventsMode;
98
99 // the position of the first item in the current radio group or -1
100 int m_startRadioGroup;
101
102 wxMenuImpl* m_peer;
103
104 DECLARE_DYNAMIC_CLASS(wxMenu)
105 };
106
107 #if wxOSX_USE_COCOA_OR_CARBON
108
109 // the iphone only has popup-menus
110
111 // ----------------------------------------------------------------------------
112 // Menu Bar (a la Windows)
113 // ----------------------------------------------------------------------------
114
115 class WXDLLIMPEXP_CORE wxMenuBar : public wxMenuBarBase
116 {
117 public:
118 // ctors & dtor
119 // default constructor
120 wxMenuBar();
121 // unused under MSW
122 wxMenuBar(long style);
123 // menubar takes ownership of the menus arrays but copies the titles
124 wxMenuBar(size_t n, wxMenu *menus[], const wxString titles[], long style = 0);
125 virtual ~wxMenuBar();
126
127 // menubar construction
128 virtual bool Append( wxMenu *menu, const wxString &title );
129 virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title);
130 virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
131 virtual wxMenu *Remove(size_t pos);
132
133 virtual int FindMenuItem(const wxString& menuString,
134 const wxString& itemString) const;
135 virtual wxMenuItem* FindItem( int id, wxMenu **menu = NULL ) const;
136
137 virtual void EnableTop( size_t pos, bool flag );
138 virtual void SetMenuLabel( size_t pos, const wxString& label );
139 virtual wxString GetMenuLabel( size_t pos ) const;
140 virtual bool Enable( bool enable = TRUE );
141 // for virtual function hiding
142 virtual void Enable( int itemid, bool enable )
143 {
144 wxMenuBarBase::Enable( itemid, enable );
145 }
146
147 // implementation from now on
148 int FindMenu(const wxString& title);
149 void Detach();
150
151 // returns TRUE if we're attached to a frame
152 bool IsAttached() const { return m_menuBarFrame != NULL; }
153 // get the frame we live in
154 wxFrame *GetFrame() const { return m_menuBarFrame; }
155 // attach to a frame
156 void Attach(wxFrame *frame);
157
158 // clear the invoking window for all menus and submenus
159 void UnsetInvokingWindow() ;
160
161 // set the invoking window for all menus and submenus
162 void SetInvokingWindow( wxFrame* frame ) ;
163
164 // if the menubar is modified, the display is not updated automatically,
165 // call this function to update it (m_menuBarFrame should be !NULL)
166 void Refresh(bool eraseBackground = TRUE, const wxRect *rect = (const wxRect *) NULL);
167
168 static void SetAutoWindowMenu( bool enable ) { s_macAutoWindowMenu = enable ; }
169 static bool GetAutoWindowMenu() { return s_macAutoWindowMenu ; }
170
171 void MacInstallMenuBar() ;
172 static wxMenuBar* MacGetInstalledMenuBar() { return s_macInstalledMenuBar ; }
173 static void MacSetCommonMenuBar(wxMenuBar* menubar) { s_macCommonMenuBar=menubar; }
174 static wxMenuBar* MacGetCommonMenuBar() { return s_macCommonMenuBar; }
175
176
177 static WXHMENU MacGetWindowMenuHMenu() { return s_macWindowMenuHandle ; }
178 protected:
179 // common part of all ctors
180 void Init();
181 wxWindow *m_invokingWindow;
182
183 wxArrayString m_titles;
184 static bool s_macAutoWindowMenu ;
185 static WXHMENU s_macWindowMenuHandle ;
186
187 private:
188 static wxMenuBar* s_macInstalledMenuBar ;
189 static wxMenuBar* s_macCommonMenuBar ;
190
191 wxMenu* m_rootMenu;
192 wxMenu* m_appleMenu;
193
194 DECLARE_DYNAMIC_CLASS(wxMenuBar)
195 };
196
197 #endif
198
199 #endif // _WX_MENU_H_