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