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 class wxMenuRadioItemsData;
19 
20 // ----------------------------------------------------------------------------
21 // Menu
22 // ----------------------------------------------------------------------------
23 
24 class WXDLLIMPEXP_FWD_CORE wxMenuImpl ;
25 
26 class WXDLLIMPEXP_CORE wxMenu : public wxMenuBase
27 {
28 public:
29     // ctors & dtor
30     wxMenu(const wxString& title, long style = 0)
wxMenuBase(title,style)31         : wxMenuBase(title, style) { Init(); }
32 
wxMenuBase(style)33     wxMenu(long style = 0) : wxMenuBase(style) { Init(); }
34 
35     virtual ~wxMenu();
36 
37     virtual void SetTitle(const wxString& title) wxOVERRIDE;
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 );
48     bool HandleCommandProcess( wxMenuItem* menuItem );
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 
64     // Returns the start and end position of the radio group to which the item
65     // at given position belongs. Return false if there is no radio group
66     // containing this position.
67     bool OSXGetRadioGroupRange(int pos, int *start, int *end) const;
68 
69 protected:
70     // hide special menu items like exit, preferences etc
71     // that are expected in the app menu
72     void DoRearrange() ;
73 
74     virtual wxMenuItem* DoAppend(wxMenuItem *item) wxOVERRIDE;
75     virtual wxMenuItem* DoInsert(size_t pos, wxMenuItem *item) wxOVERRIDE;
76     virtual wxMenuItem* DoRemove(wxMenuItem *item) wxOVERRIDE;
77 
78 private:
79     // common part of all ctors
80     void Init();
81 
82     // common part of Do{Append,Insert}(): behaves as Append if pos == -1
83     bool DoInsertOrAppend(wxMenuItem *item, size_t pos = (size_t)-1);
84 
85     // Common part of HandleMenu{Opened,Closed}().
86     void DoHandleMenuOpenedOrClosed(wxEventType evtType);
87 
88 
89     // if TRUE, insert a break before appending the next item
90     bool m_doBreak;
91 
92     // in this menu rearranging of menu items (esp hiding) is allowed
93     bool m_allowRearrange;
94 
95     // don't trigger native events
96     bool m_noEventsMode;
97 
98     wxMenuRadioItemsData* m_radioData;
99 
100     wxMenuImpl* m_peer;
101 
102     wxDECLARE_DYNAMIC_CLASS(wxMenu);
103 };
104 
105 #if wxUSE_MENUBAR
106 
107 // the iphone only has popup-menus
108 
109 // ----------------------------------------------------------------------------
110 // Menu Bar (a la Windows)
111 // ----------------------------------------------------------------------------
112 
113 class WXDLLIMPEXP_CORE wxMenuBar : public wxMenuBarBase
114 {
115 public:
116     // ctors & dtor
117         // default constructor
118     wxMenuBar();
119         // unused under MSW
120     wxMenuBar(long style);
121         // menubar takes ownership of the menus arrays but copies the titles
122     wxMenuBar(size_t n, wxMenu *menus[], const wxString titles[], long style = 0);
123     virtual ~wxMenuBar();
124 
125     // menubar construction
126     virtual bool Append( wxMenu *menu, const wxString &title ) wxOVERRIDE;
127     virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title) wxOVERRIDE;
128     virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title) wxOVERRIDE;
129     virtual wxMenu *Remove(size_t pos) wxOVERRIDE;
130 
131     virtual void EnableTop( size_t pos, bool flag ) wxOVERRIDE;
132     virtual bool IsEnabledTop(size_t pos) const wxOVERRIDE;
133     virtual void SetMenuLabel( size_t pos, const wxString& label ) wxOVERRIDE;
134     virtual wxString GetMenuLabel( size_t pos ) const wxOVERRIDE;
135     virtual bool Enable( bool enable = true ) wxOVERRIDE;
136     // for virtual function hiding
Enable(int itemid,bool enable)137     virtual void Enable( int itemid, bool enable )
138     {
139         wxMenuBarBase::Enable( itemid, enable );
140     }
141 
142     // implementation from now on
143 
144         // returns TRUE if we're attached to a frame
IsAttached()145     bool IsAttached() const { return m_menuBarFrame != NULL; }
146         // get the frame we live in
GetFrame()147     wxFrame *GetFrame() const { return m_menuBarFrame; }
148 
149     // if the menubar is modified, the display is not updated automatically,
150     // call this function to update it (m_menuBarFrame should be !NULL)
151     void Refresh(bool eraseBackground = true, const wxRect *rect = NULL) wxOVERRIDE;
152 
153 #if wxABI_VERSION >= 30001
OSXGetAppleMenu()154     wxMenu *OSXGetAppleMenu() const { return m_appleMenu; }
155 #endif
156 
SetAutoWindowMenu(bool enable)157     static void SetAutoWindowMenu( bool enable ) { s_macAutoWindowMenu = enable ; }
GetAutoWindowMenu()158     static bool GetAutoWindowMenu() { return s_macAutoWindowMenu ; }
159 
160     void MacUninstallMenuBar() ;
161     void MacInstallMenuBar() ;
MacGetInstalledMenuBar()162     static wxMenuBar* MacGetInstalledMenuBar() { return s_macInstalledMenuBar ; }
MacSetCommonMenuBar(wxMenuBar * menubar)163     static void MacSetCommonMenuBar(wxMenuBar* menubar) { s_macCommonMenuBar=menubar; }
MacGetCommonMenuBar()164     static wxMenuBar* MacGetCommonMenuBar() { return s_macCommonMenuBar; }
165 
166 
MacGetWindowMenuHMenu()167     static WXHMENU MacGetWindowMenuHMenu() { return s_macWindowMenuHandle ; }
168 
169     virtual void DoGetPosition(int *x, int *y) const wxOVERRIDE;
170     virtual void DoGetSize(int *width, int *height) const wxOVERRIDE;
171     virtual void DoGetClientSize(int *width, int *height) const wxOVERRIDE;
172 
173 protected:
174     // common part of all ctors
175     void Init();
176 
177     static bool     s_macAutoWindowMenu ;
178     static WXHMENU  s_macWindowMenuHandle ;
179 
180 private:
181     static wxMenuBar*            s_macInstalledMenuBar ;
182     static wxMenuBar*            s_macCommonMenuBar ;
183 
184     wxMenu* m_rootMenu;
185     wxMenu* m_appleMenu;
186 
187     wxDECLARE_DYNAMIC_CLASS(wxMenuBar);
188 };
189 
190 #endif
191 
192 #endif // _WX_MENU_H_
193