]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/menu.h
don't try to build shared library on platforms not supporting it
[wxWidgets.git] / include / wx / msw / menu.h
CommitLineData
2bda0e17
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: 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 and Markus Holzem
a3622daa 9// Licence: wxWindows license
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
bbcdf8bc
JS
12#ifndef _WX_MENU_H_
13#define _WX_MENU_H_
2bda0e17
KB
14
15#ifdef __GNUG__
c626a8b7 16 #pragma interface "menu.h"
2bda0e17
KB
17#endif
18
19#include "wx/defs.h"
20#include "wx/event.h"
546db2a8 21#include "wx/dynarray.h"
3f3cec48
RR
22#include "wx/string.h"
23
24#if wxUSE_ACCEL
25#include "wx/accel.h"
26#endif // wxUSE_ACCEL
2bda0e17 27
bbcdf8bc
JS
28class WXDLLEXPORT wxMenuItem;
29class WXDLLEXPORT wxMenuBar;
30class WXDLLEXPORT wxMenu;
c626a8b7 31class WXDLLEXPORT wxFrame;
2bda0e17 32
39ca6d79 33WXDLLEXPORT_DATA(extern const wxChar*) wxEmptyString;
2bda0e17
KB
34
35// ----------------------------------------------------------------------------
36// Menu
37// ----------------------------------------------------------------------------
c626a8b7
VZ
38
39class WXDLLEXPORT wxMenu : public wxEvtHandler
2bda0e17 40{
c626a8b7 41 DECLARE_DYNAMIC_CLASS(wxMenu)
2bda0e17
KB
42
43public:
b908d224 44 // ctors & dtor
b908d224
VZ
45 wxMenu(const wxString& title,
46 const wxFunction func)
47 {
48 Init(title, func);
49 }
33961d59
RR
50
51 wxMenu( long WXUNUSED(style) )
52 {
53 Init( wxEmptyString );
54 }
b908d224
VZ
55
56 wxMenu(const wxString& title = wxEmptyString, long WXUNUSED(style) = 0)
57 {
58 Init(title);
59 }
60
c626a8b7
VZ
61 virtual ~wxMenu();
62
63 // construct menu
64 // append a separator to the menu
65 void AppendSeparator();
66 // append a normal item to the menu
67 void Append(int id, const wxString& label,
68 const wxString& helpString = wxEmptyString,
69 bool checkable = FALSE);
70 // append a submenu
71 void Append(int id, const wxString& label,
72 wxMenu *submenu,
73 const wxString& helpString = wxEmptyString);
74 // append anything (create wxMenuItem first)
75 void Append(wxMenuItem *pItem);
76
77 // insert a break in the menu
78 void Break();
79
80 // delete an item
81 // If it's a submenu, menu is not destroyed.
82 // VZ: why? shouldn't it return "wxMenu *" then?
83 void Delete(int id);
84
85 // client data
86 void SetClientData(void* clientData) { m_clientData = clientData; }
87 void* GetClientData() const { return m_clientData; }
88
89 // menu item control
90 // enable/disable item
91 void Enable(int id, bool enable);
92 // TRUE if enabled
93 bool IsEnabled(int id) const;
94
95 // check/uncheck item - only for checkable items, of course
96 void Check(int id, bool check);
97 // TRUE if checked
98 bool IsChecked(int id) const;
99
100 // other properties
101 // the menu title
102 void SetTitle(const wxString& label);
103 const wxString GetTitle() const;
104 // the item label
105 void SetLabel(int id, const wxString& label);
106 wxString GetLabel(int id) const;
107 // help string
108 virtual void SetHelpString(int id, const wxString& helpString);
109 virtual wxString GetHelpString(int id) const;
110
111 // get the list of items
112 wxList& GetItems() const { return (wxList &)m_menuItems; }
113
114 // find item
115 // returns id of the item matching the given string or wxNOT_FOUND
116 virtual int FindItem(const wxString& itemString) const;
117 // returns NULL if not found
118 wxMenuItem* FindItem(int id) const { return FindItemForId(id); }
119 // find wxMenuItem by ID, and item's menu too if itemMenu is !NULL
120 wxMenuItem *FindItemForId(int itemId, wxMenu **itemMenu = NULL) const;
121
122 // Updates the UI for a menu and all submenus recursively. source is the
123 // object that has the update event handlers defined for it. If NULL, the
124 // menu or associated window will be used.
125 void UpdateUI(wxEvtHandler* source = (wxEvtHandler*)NULL);
126
42e69d6b 127 bool ProcessCommand(wxCommandEvent& event);
c626a8b7
VZ
128
129 virtual void SetParent(wxEvtHandler *parent) { m_parent = parent; }
130 void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
131 wxEvtHandler *GetEventHandler() const { return m_eventHandler; }
132
c626a8b7
VZ
133 // IMPLEMENTATION
134 bool MSWCommand(WXUINT param, WXWORD id);
135
136 void SetInvokingWindow(wxWindow *pWin) { m_pInvokingWindow = pWin; }
137 wxWindow *GetInvokingWindow() const { return m_pInvokingWindow; }
138
139 // semi-private accessors
140 // get the window which contains this menu
141 wxWindow *GetWindow() const;
142 // get the menu handle
143 WXHMENU GetHMenu() const;
2bda0e17 144
c2dcfdef
VZ
145 // only for wxMenuBar
146 void Attach(wxMenuBar *menubar);
147 void Detach();
148
d427503c 149#if wxUSE_ACCEL
42e69d6b
VZ
150 size_t GetAccelCount() const { return m_accelKeyCodes.GetCount(); }
151 size_t CopyAccels(wxAcceleratorEntry *accels) const;
d427503c 152#endif // wxUSE_ACCEL
42e69d6b 153
33961d59 154 wxFunction GetCallback() const { return m_callback; }
42e69d6b 155 void Callback(const wxFunction func) { m_callback = func; }
33961d59 156 wxFunction m_callback;
42e69d6b 157
33961d59 158#ifdef WXWIN_COMPATIBILITY
42e69d6b
VZ
159 // compatibility: these functions are deprecated
160 bool Enabled(int id) const { return IsEnabled(id); }
161 bool Checked(int id) const { return IsChecked(id); }
162
42e69d6b
VZ
163#endif // WXWIN_COMPATIBILITY
164
2bda0e17 165private:
b908d224 166 // common part of all ctors
33961d59 167 void Init(const wxString& title, const wxFunction func = NULL );
b908d224 168
c2dcfdef 169 bool m_doBreak;
2bda0e17 170
c626a8b7
VZ
171 // This is used when m_hMenu is NULL because we don't want to
172 // delete it in ~wxMenu (it's been added to a parent menu).
173 // But we'll still need the handle for other purposes.
174 // Might be better to have a flag saying whether it's deleteable or not.
175 WXHMENU m_savehMenu ; // Used for Enable() on popup
176 WXHMENU m_hMenu;
c626a8b7
VZ
177
178 int m_noItems;
179 wxString m_title;
180 wxMenu * m_topLevelMenu;
181 wxMenuBar * m_menuBar;
182 wxList m_menuItems;
183 wxEvtHandler * m_parent;
184 wxEvtHandler * m_eventHandler;
185 wxWindow *m_pInvokingWindow;
186 void* m_clientData;
42e69d6b 187
d427503c 188#if wxUSE_ACCEL
42e69d6b
VZ
189 // the accelerators data
190 wxArrayInt m_accelKeyCodes, m_accelFlags, m_accelIds;
d427503c 191#endif // wxUSE_ACCEL
2bda0e17
KB
192};
193
194// ----------------------------------------------------------------------------
195// Menu Bar (a la Windows)
196// ----------------------------------------------------------------------------
c626a8b7
VZ
197
198class WXDLLEXPORT wxMenuBar : public wxEvtHandler
2bda0e17 199{
c626a8b7
VZ
200 DECLARE_DYNAMIC_CLASS(wxMenuBar)
201
202public:
203 // ctors & dtor
c2dcfdef 204 // default constructor
c626a8b7 205 wxMenuBar();
c2dcfdef 206 // unused under MSW
c626a8b7 207 wxMenuBar(long style);
c2dcfdef 208 // menubar takes ownership of the menus arrays but copies the titles
c626a8b7
VZ
209 wxMenuBar(int n, wxMenu *menus[], const wxString titles[]);
210 virtual ~wxMenuBar();
211
212 // menubar construction
c2dcfdef 213 WXHMENU Create();
c626a8b7 214 void Append(wxMenu *menu, const wxString& title);
ca8a9e60
UM
215 void Insert(int pos, wxMenu * menu, const wxString& title);
216 void ReplaceMenu(int pos, wxMenu * new_menu, const wxString& title);
217 int FindMenu(const wxString& title);
218 void Detach();
c626a8b7
VZ
219 virtual void Delete(wxMenu *menu, int index = 0); /* Menu not destroyed */
220
221 // state control
222 // NB: must only be used AFTER menu has been attached to frame,
223 // otherwise use individual menus to enable/disable items
224 // enable the item
225 void Enable(int id, bool enable);
226 // TRUE if item enabled
227 bool IsEnabled(int id) const;
228 //
229 void EnableTop(int pos, bool enable);
230
231 // works only with checkable items
232 void Check(int id, bool check);
233 // TRUE if checked
234 bool IsChecked(int id) const;
235
236 void SetLabel(int id, const wxString& label) ;
237 wxString GetLabel(int id) const ;
238
239 virtual void SetHelpString(int id, const wxString& helpString);
240 virtual wxString GetHelpString(int id) const ;
241
242 void SetLabelTop(int pos, const wxString& label) ;
243 wxString GetLabelTop(int pos) const ;
244
c2dcfdef
VZ
245 // notifications: return FALSE to prevent the menu from being
246 // appended/deleted
9df8c2df 247 virtual bool OnAppend(wxMenu *menu, const wxChar *title);
c626a8b7
VZ
248 virtual bool OnDelete(wxMenu *menu, int index);
249
250 // item search
251 // by menu and item names, returns wxNOT_FOUND if not found
252 virtual int FindMenuItem(const wxString& menuString,
253 const wxString& itemString) const;
254 // returns NULL if not found
255 wxMenuItem* FindItem(int id) const { return FindItemForId(id); }
256 // returns NULL if not found, fills menuForItem if !NULL
257 wxMenuItem *FindItemForId(int itemId, wxMenu **menuForItem = NULL) const;
258
259 // submenus access
260 int GetMenuCount() const { return m_menuCount; }
261 wxMenu *GetMenu(int i) const { return m_menus[i]; }
262
263 void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
264 wxEvtHandler *GetEventHandler() { return m_eventHandler; }
265
266#ifdef WXWIN_COMPATIBILITY
267 // compatibility: these functions are deprecated
268 bool Enabled(int id) const { return IsEnabled(id); }
269 bool Checked(int id) const { return IsChecked(id); }
270#endif // WXWIN_COMPATIBILITY
2bda0e17 271
c2dcfdef
VZ
272 // IMPLEMENTATION
273 // returns TRUE if we're attached to a frame
274 bool IsAttached() const { return m_menuBarFrame != NULL; }
275 // get the frame we live in
276 wxFrame *GetFrame() const { return m_menuBarFrame; }
277 // attach to a frame
42e69d6b 278 void Attach(wxFrame *frame);
c2dcfdef 279
d427503c 280#if wxUSE_ACCEL
42e69d6b
VZ
281 // get the accel table for the menus
282 const wxAcceleratorTable& GetAccelTable() const { return m_accelTable; }
d427503c
VZ
283#endif // wxUSE_ACCEL
284
c2dcfdef
VZ
285 // get the menu handle
286 WXHMENU GetHMenu() const { return m_hMenu; }
287
c2dcfdef
VZ
288 // if the menubar is modified, the display is not updated automatically,
289 // call this function to update it (m_menuBarFrame should be !NULL)
290 void Refresh();
291
fbb90f7f
PA
292protected:
293 // common part of all ctors
294 void Init();
295
c2dcfdef
VZ
296 wxEvtHandler *m_eventHandler;
297 int m_menuCount;
298 wxMenu **m_menus;
299 wxString *m_titles;
300 wxFrame *m_menuBarFrame;
301 WXHMENU m_hMenu;
42e69d6b 302
d427503c 303#if wxUSE_ACCEL
42e69d6b
VZ
304 // the accelerator table for all accelerators in all our menus
305 wxAcceleratorTable m_accelTable;
d427503c 306#endif // wxUSE_ACCEL
2bda0e17
KB
307};
308
bbcdf8bc 309#endif // _WX_MENU_H_