]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/menu.h
Assert correction.
[wxWidgets.git] / include / wx / msw / menu.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msw/menu.h
3 // Purpose: wxMenu, wxMenuBar classes
4 // Author: Julian Smart
5 // Modified by: Vadim Zeitlin (wxMenuItem is now in separate file)
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_MENU_H_
13 #define _WX_MENU_H_
14
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "menu.h"
17 #endif
18
19 #if wxUSE_ACCEL
20 #include "wx/accel.h"
21 #include "wx/dynarray.h"
22
23 WX_DEFINE_EXPORTED_ARRAY_PTR(wxAcceleratorEntry *, wxAcceleratorArray);
24 #endif // wxUSE_ACCEL
25
26 class WXDLLEXPORT wxFrame;
27
28 #if defined(__WXWINCE__) && wxUSE_TOOLBAR
29 class WXDLLEXPORT wxToolBar;
30 #endif
31
32
33 // Not using a combined wxToolBar/wxMenuBar? then use
34 // a commandbar in WinCE .NET to implement the
35 // menubar, since there is no ::SetMenu function.
36 #if defined(__WXWINCE__)
37 # if ((_WIN32_WCE >= 400) && !defined(__POCKETPC__) && !defined(__SMARTPHONE__)) || \
38 defined(__HANDHELDPC__)
39 # define WINCE_WITH_COMMANDBAR
40 # else
41 # define WINCE_WITHOUT_COMMANDBAR
42 # endif
43 #endif
44
45
46 #include "wx/arrstr.h"
47
48 // ----------------------------------------------------------------------------
49 // Menu
50 // ----------------------------------------------------------------------------
51
52 class WXDLLEXPORT wxMenu : public wxMenuBase
53 {
54 public:
55 // ctors & dtor
56 wxMenu(const wxString& title, long style = 0)
57 : wxMenuBase(title, style) { Init(); }
58
59 wxMenu(long style = 0) : wxMenuBase(style) { Init(); }
60
61 virtual ~wxMenu();
62
63 // implement base class virtuals
64 virtual wxMenuItem* DoAppend(wxMenuItem *item);
65 virtual wxMenuItem* DoInsert(size_t pos, wxMenuItem *item);
66 virtual wxMenuItem* DoRemove(wxMenuItem *item);
67
68 virtual void Break();
69
70 virtual void SetTitle(const wxString& title);
71
72 // implementation only from now on
73 // -------------------------------
74
75 virtual void Attach(wxMenuBarBase *menubar);
76
77 bool MSWCommand(WXUINT param, WXWORD id);
78
79 // semi-private accessors
80 // get the window which contains this menu
81 wxWindow *GetWindow() const;
82 // get the menu handle
83 WXHMENU GetHMenu() const { return m_hMenu; }
84
85 #if wxUSE_ACCEL
86 // called by wxMenuBar to build its accel table from the accels of all menus
87 bool HasAccels() const { return !m_accels.IsEmpty(); }
88 size_t GetAccelCount() const { return m_accels.GetCount(); }
89 size_t CopyAccels(wxAcceleratorEntry *accels) const;
90
91 // called by wxMenuItem when its accels changes
92 void UpdateAccel(wxMenuItem *item);
93
94 // helper used by wxMenu itself (returns the index in m_accels)
95 int FindAccel(int id) const;
96 #endif // wxUSE_ACCEL
97
98 private:
99 // common part of all ctors
100 void Init();
101
102 // common part of Append/Insert (behaves as Append is pos == (size_t)-1)
103 bool DoInsertOrAppend(wxMenuItem *item, size_t pos = (size_t)-1);
104
105 // terminate the current radio group, if any
106 void EndRadioGroup();
107
108 // if true, insert a breal before appending the next item
109 bool m_doBreak;
110
111 // the position of the first item in the current radio group or -1
112 int m_startRadioGroup;
113
114 // the menu handle of this menu
115 WXHMENU m_hMenu;
116
117 #if wxUSE_ACCEL
118 // the accelerators for our menu items
119 wxAcceleratorArray m_accels;
120 #endif // wxUSE_ACCEL
121
122 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenu)
123 };
124
125 // ----------------------------------------------------------------------------
126 // Menu Bar (a la Windows)
127 // ----------------------------------------------------------------------------
128
129 class WXDLLEXPORT wxMenuInfo : public wxObject
130 {
131 public :
132 wxMenuInfo() { m_menu = NULL; }
133 virtual ~wxMenuInfo() { }
134
135 void Create( wxMenu *menu , const wxString &title )
136 { m_menu = menu; m_title = title; }
137 wxMenu* GetMenu() const { return m_menu; }
138 wxString GetTitle() const { return m_title; }
139 private :
140 wxMenu *m_menu;
141 wxString m_title;
142
143 DECLARE_DYNAMIC_CLASS(wxMenuInfo)
144 };
145
146 WX_DECLARE_EXPORTED_LIST(wxMenuInfo, wxMenuInfoList );
147
148 class WXDLLEXPORT wxMenuBar : public wxMenuBarBase
149 {
150 public:
151 // ctors & dtor
152 // default constructor
153 wxMenuBar();
154 // unused under MSW
155 wxMenuBar(long style);
156 // menubar takes ownership of the menus arrays but copies the titles
157 wxMenuBar(size_t n, wxMenu *menus[], const wxString titles[], long style = 0);
158 virtual ~wxMenuBar();
159
160 // menubar construction
161 bool Append( wxMenuInfo *info ) { return Append( info->GetMenu() , info->GetTitle() ); }
162 const wxMenuInfoList& GetMenuInfos() const;
163
164 virtual bool Append( wxMenu *menu, const wxString &title );
165 virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title);
166 virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
167 virtual wxMenu *Remove(size_t pos);
168
169 virtual void EnableTop( size_t pos, bool flag );
170 virtual void SetLabelTop( size_t pos, const wxString& label );
171 virtual wxString GetLabelTop( size_t pos ) const;
172
173 // implementation from now on
174 WXHMENU Create();
175 virtual void Detach();
176 virtual void Attach(wxFrame *frame);
177
178 #if defined(__WXWINCE__) && wxUSE_TOOLBAR
179 // Under WinCE, a menubar is owned by the frame's toolbar
180 void SetToolBar(wxToolBar* toolBar) { m_toolBar = toolBar; }
181 wxToolBar* GetToolBar() const { return m_toolBar; }
182 #endif
183
184 #ifdef WINCE_WITH_COMMANDBAR
185 WXHWND GetCommandBar() const { return m_commandBar; }
186 bool AddAdornments(long style);
187 #endif
188
189 #if wxUSE_ACCEL
190 // get the accel table for all the menus
191 const wxAcceleratorTable& GetAccelTable() const { return m_accelTable; }
192
193 // update the accel table (must be called after adding/deleting a menu)
194 void RebuildAccelTable();
195 #endif // wxUSE_ACCEL
196
197 // get the menu handle
198 WXHMENU GetHMenu() const { return m_hMenu; }
199
200 // if the menubar is modified, the display is not updated automatically,
201 // call this function to update it (m_menuBarFrame should be !NULL)
202 void Refresh();
203
204 // To avoid compile warning
205 void Refresh( bool eraseBackground,
206 const wxRect *rect = (const wxRect *) NULL ) { wxWindow::Refresh(eraseBackground, rect); }
207
208 protected:
209 // common part of all ctors
210 void Init();
211
212 wxArrayString m_titles;
213 wxMenuInfoList m_menuInfos;
214
215 WXHMENU m_hMenu;
216
217 // Return the MSW position for a wxMenu which is sometimes different from
218 // the wxWidgets position.
219 int MSWPositionForWxMenu(wxMenu *menu, int wxpos);
220 #if wxUSE_ACCEL
221 // the accelerator table for all accelerators in all our menus
222 wxAcceleratorTable m_accelTable;
223 #endif // wxUSE_ACCEL
224
225 #if defined(__WXWINCE__) && wxUSE_TOOLBAR
226 wxToolBar* m_toolBar;
227 #endif
228
229 #ifdef WINCE_WITH_COMMANDBAR
230 WXHWND m_commandBar;
231 bool m_adornmentsAdded;
232 #endif
233
234 private:
235 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenuBar)
236 };
237
238 #endif // _WX_MENU_H_