]> git.saurik.com Git - wxWidgets.git/blame - include/wx/mac/carbon/menu.h
cleanup
[wxWidgets.git] / include / wx / mac / carbon / menu.h
CommitLineData
8cf73271
SC
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
65571936 9// Licence: wxWindows licence
8cf73271
SC
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_MENU_H_
13#define _WX_MENU_H_
14
b5dbe15d 15class WXDLLIMPEXP_FWD_CORE wxFrame;
8cf73271
SC
16
17#include "wx/arrstr.h"
18
19// ----------------------------------------------------------------------------
20// Menu
21// ----------------------------------------------------------------------------
22
23class WXDLLEXPORT wxMenu : public wxMenuBase
24{
25public:
26 // ctors & dtor
27 wxMenu(const wxString& title, long style = 0)
28 : wxMenuBase(title, style) { Init(); }
29
30 wxMenu(long style = 0) : wxMenuBase(style) { Init(); }
31
32 virtual ~wxMenu();
33
8cf73271
SC
34 virtual void Attach(wxMenuBarBase *menubar) ;
35
36 virtual void Break();
37
38 virtual void SetTitle(const wxString& title);
39
40 // MSW-specific
41 bool ProcessCommand(wxCommandEvent& event);
42
43 // implementation only from now on
44 // -------------------------------
45
52af3158 46 int MacGetIndexFromId( int id ) ;
8cf73271
SC
47 int MacGetIndexFromItem( wxMenuItem *pItem ) ;
48 void MacEnableMenu( bool bDoEnable ) ;
49 // MacOS needs to know about submenus somewhere within this menu
50 // before it can be displayed , also hide special menu items like preferences
51 // that are handled by the OS
52 void MacBeforeDisplay( bool isSubMenu ) ;
53 // undo all changes from the MacBeforeDisplay call
54 void MacAfterDisplay( bool isSubMenu ) ;
55
56 // semi-private accessors
57 // get the window which contains this menu
58 wxWindow *GetWindow() const;
59 // get the menu handle
60 WXHMENU GetHMenu() const { return m_hMenu; }
61
62 short MacGetMenuId() { return m_macMenuId ; }
63
ebf2a1ec
SC
64 wxInt32 MacHandleCommandProcess( wxMenuItem* item, int id, wxWindow* targetWindow = NULL );
65 wxInt32 MacHandleCommandUpdateStatus( wxMenuItem* item, int id, wxWindow* targetWindow = NULL);
66
6f02a879
VZ
67protected:
68 virtual wxMenuItem* DoAppend(wxMenuItem *item);
69 virtual wxMenuItem* DoInsert(size_t pos, wxMenuItem *item);
70 virtual wxMenuItem* DoRemove(wxMenuItem *item);
71
8cf73271
SC
72private:
73 // common part of all ctors
74 void Init();
75
76 // common part of Append/Insert (behaves as Append is pos == (size_t)-1)
77 bool DoInsertOrAppend(wxMenuItem *item, size_t pos = (size_t)-1);
78
79 // terminate the current radio group, if any
80 void EndRadioGroup();
81
82 // if TRUE, insert a breal before appending the next item
83 bool m_doBreak;
84
85 // the position of the first item in the current radio group or -1
86 int m_startRadioGroup;
87
88 // the menu handle of this menu
89 WXHMENU m_hMenu;
90
91 short m_macMenuId;
92
93 static short s_macNextMenuId ;
94
95 DECLARE_DYNAMIC_CLASS(wxMenu)
96};
97
98// ----------------------------------------------------------------------------
99// Menu Bar (a la Windows)
100// ----------------------------------------------------------------------------
101
102class WXDLLEXPORT wxMenuBar : public wxMenuBarBase
103{
104public:
105 // ctors & dtor
106 // default constructor
107 wxMenuBar();
108 // unused under MSW
109 wxMenuBar(long style);
110 // menubar takes ownership of the menus arrays but copies the titles
294ea16d 111 wxMenuBar(size_t n, wxMenu *menus[], const wxString titles[], long style = 0);
8cf73271
SC
112 virtual ~wxMenuBar();
113
114 // menubar construction
115 virtual bool Append( wxMenu *menu, const wxString &title );
116 virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title);
117 virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
118 virtual wxMenu *Remove(size_t pos);
119
120 virtual int FindMenuItem(const wxString& menuString,
121 const wxString& itemString) const;
122 virtual wxMenuItem* FindItem( int id, wxMenu **menu = NULL ) const;
123
124 virtual void EnableTop( size_t pos, bool flag );
52af3158
JS
125 virtual void SetMenuLabel( size_t pos, const wxString& label );
126 virtual wxString GetMenuLabel( size_t pos ) const;
c393c740 127 virtual bool Enable( bool enable = TRUE );
f8ca3d72
MB
128 // for virtual function hiding
129 virtual void Enable( int itemid, bool enable )
130 {
131 wxMenuBarBase::Enable( itemid, enable );
132 }
8cf73271
SC
133
134 // implementation from now on
135 WXHMENU Create();
136 int FindMenu(const wxString& title);
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 // clear the invoking window for all menus and submenus
147 void UnsetInvokingWindow() ;
148
149 // set the invoking window for all menus and submenus
150 void SetInvokingWindow( wxFrame* frame ) ;
151
152 // if the menubar is modified, the display is not updated automatically,
153 // call this function to update it (m_menuBarFrame should be !NULL)
154 void Refresh(bool eraseBackground = TRUE, const wxRect *rect = (const wxRect *) NULL);
155
501db75a
SC
156 static void SetAutoWindowMenu( bool enable ) { s_macAutoWindowMenu = enable ; }
157 static bool GetAutoWindowMenu() { return s_macAutoWindowMenu ; }
8cf73271 158
501db75a
SC
159 void MacInstallMenuBar() ;
160 static wxMenuBar* MacGetInstalledMenuBar() { return s_macInstalledMenuBar ; }
161 static void MacSetCommonMenuBar(wxMenuBar* menubar) { s_macCommonMenuBar=menubar; }
162 static wxMenuBar* MacGetCommonMenuBar() { return s_macCommonMenuBar; }
163
164
165 static WXHMENU MacGetWindowMenuHMenu() { return s_macWindowMenuHandle ; }
8cf73271
SC
166protected:
167 // common part of all ctors
168 void Init();
169 wxWindow *m_invokingWindow;
170
501db75a
SC
171 wxArrayString m_titles;
172 static bool s_macAutoWindowMenu ;
173 static WXHMENU s_macWindowMenuHandle ;
8cf73271
SC
174
175private:
176 static wxMenuBar* s_macInstalledMenuBar ;
177 static wxMenuBar* s_macCommonMenuBar ;
178
179 DECLARE_DYNAMIC_CLASS(wxMenuBar)
180};
181
182#endif // _WX_MENU_H_