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