]> git.saurik.com Git - wxWidgets.git/blob - include/wx/osx/menu.h
Destroy the wxDialog::ShowWindowModalThenDo() functor a.s.a.p.
[wxWidgets.git] / include / wx / osx / menu.h
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)
29 : wxMenuBase(title, style) { Init(); }
30
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
53 wxMenuImpl* GetPeer() { return m_peer; }
54
55 // make sure we can veto
56 void SetAllowRearrange( bool allow );
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 );
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
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
139 bool IsAttached() const { return m_menuBarFrame != NULL; }
140 // get the frame we live in
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 static void SetAutoWindowMenu( bool enable ) { s_macAutoWindowMenu = enable ; }
150 static bool GetAutoWindowMenu() { return s_macAutoWindowMenu ; }
151
152 void MacInstallMenuBar() ;
153 static wxMenuBar* MacGetInstalledMenuBar() { return s_macInstalledMenuBar ; }
154 static void MacSetCommonMenuBar(wxMenuBar* menubar) { s_macCommonMenuBar=menubar; }
155 static wxMenuBar* MacGetCommonMenuBar() { return s_macCommonMenuBar; }
156
157
158 static WXHMENU MacGetWindowMenuHMenu() { return s_macWindowMenuHandle ; }
159 protected:
160 // common part of all ctors
161 void Init();
162
163 static bool s_macAutoWindowMenu ;
164 static WXHMENU s_macWindowMenuHandle ;
165
166 private:
167 static wxMenuBar* s_macInstalledMenuBar ;
168 static wxMenuBar* s_macCommonMenuBar ;
169
170 wxMenu* m_rootMenu;
171 wxMenu* m_appleMenu;
172
173 DECLARE_DYNAMIC_CLASS(wxMenuBar)
174 };
175
176 #endif
177
178 #endif // _WX_MENU_H_