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