]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/menu.h
Rewrote wxNotebook, incl. PAGE_CHANGING event
[wxWidgets.git] / include / wx / msw / menu.h
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
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_MENU_H_
13 #define _WX_MENU_H_
14
15 #ifdef __GNUG__
16 #pragma interface "menu.h"
17 #endif
18
19 #include "wx/defs.h"
20 #include "wx/event.h"
21
22 class WXDLLEXPORT wxMenuItem;
23 class WXDLLEXPORT wxMenuBar;
24 class WXDLLEXPORT wxMenu;
25 class WXDLLEXPORT wxFrame;
26
27 WXDLLEXPORT_DATA(extern const wxChar*) wxEmptyString;
28
29 // ----------------------------------------------------------------------------
30 // Menu
31 // ----------------------------------------------------------------------------
32
33 class WXDLLEXPORT wxMenu : public wxEvtHandler
34 {
35 DECLARE_DYNAMIC_CLASS(wxMenu)
36
37 public:
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
106 bool ProcessCommand(wxCommandEvent& event);
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
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;
123
124 // only for wxMenuBar
125 void Attach(wxMenuBar *menubar);
126 void Detach();
127
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
138 private:
139 wxFunction m_callback;
140 #endif // WXWIN_COMPATIBILITY
141
142 private:
143 bool m_doBreak;
144
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;
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;
161
162 // the accelerators data
163 wxArrayInt m_accelKeyCodes, m_accelFlags, m_accelIds;
164 };
165
166 // ----------------------------------------------------------------------------
167 // Menu Bar (a la Windows)
168 // ----------------------------------------------------------------------------
169
170 class WXDLLEXPORT wxMenuBar : public wxEvtHandler
171 {
172 DECLARE_DYNAMIC_CLASS(wxMenuBar)
173
174 public:
175 // ctors & dtor
176 // default constructor
177 wxMenuBar();
178 // unused under MSW
179 wxMenuBar(long style);
180 // menubar takes ownership of the menus arrays but copies the titles
181 wxMenuBar(int n, wxMenu *menus[], const wxString titles[]);
182 virtual ~wxMenuBar();
183
184 // menubar construction
185 WXHMENU Create();
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
213 // notifications: return FALSE to prevent the menu from being
214 // appended/deleted
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
239
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
246 void Attach(wxFrame *frame);
247
248 // get the accel table for the menus
249 const wxAcceleratorTable& GetAccelTable() const { return m_accelTable; }
250 // get the menu handle
251 WXHMENU GetHMenu() const { return m_hMenu; }
252
253 protected:
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;
267
268 // the accelerator table for all accelerators in all our menus
269 wxAcceleratorTable m_accelTable;
270 };
271
272 #endif // _WX_MENU_H_