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