]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/menu.h
Moved all WXDLLEXPORT's to be before the return type in order to make
[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 void 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 #ifdef WXWIN_COMPATIBILITY
113 void Callback(const wxFunction func) { m_callback = func; }
114
115 // compatibility: these functions are deprecated
116 bool Enabled(int id) const { return IsEnabled(id); }
117 bool Checked(int id) const { return IsChecked(id); }
118 #endif // WXWIN_COMPATIBILITY
119
120 // IMPLEMENTATION
121 bool MSWCommand(WXUINT param, WXWORD id);
122
123 void SetInvokingWindow(wxWindow *pWin) { m_pInvokingWindow = pWin; }
124 wxWindow *GetInvokingWindow() const { return m_pInvokingWindow; }
125
126 // semi-private accessors
127 // get the window which contains this menu
128 wxWindow *GetWindow() const;
129 // get the menu handle
130 WXHMENU GetHMenu() const;
131
132 // only for wxMenuBar
133 void Attach(wxMenuBar *menubar);
134 void Detach();
135
136 private:
137 bool m_doBreak;
138
139 // This is used when m_hMenu is NULL because we don't want to
140 // delete it in ~wxMenu (it's been added to a parent menu).
141 // But we'll still need the handle for other purposes.
142 // Might be better to have a flag saying whether it's deleteable or not.
143 WXHMENU m_savehMenu ; // Used for Enable() on popup
144 WXHMENU m_hMenu;
145 wxFunction m_callback;
146
147 int m_noItems;
148 wxString m_title;
149 wxMenu * m_topLevelMenu;
150 wxMenuBar * m_menuBar;
151 wxList m_menuItems;
152 wxEvtHandler * m_parent;
153 wxEvtHandler * m_eventHandler;
154 wxWindow *m_pInvokingWindow;
155 void* m_clientData;
156 };
157
158 // ----------------------------------------------------------------------------
159 // Menu Bar (a la Windows)
160 // ----------------------------------------------------------------------------
161
162 class WXDLLEXPORT wxMenuBar : public wxEvtHandler
163 {
164 DECLARE_DYNAMIC_CLASS(wxMenuBar)
165
166 public:
167 // ctors & dtor
168 // default constructor
169 wxMenuBar();
170 // unused under MSW
171 wxMenuBar(long style);
172 // menubar takes ownership of the menus arrays but copies the titles
173 wxMenuBar(int n, wxMenu *menus[], const wxString titles[]);
174 virtual ~wxMenuBar();
175
176 // menubar construction
177 WXHMENU Create();
178 void Append(wxMenu *menu, const wxString& title);
179 virtual void Delete(wxMenu *menu, int index = 0); /* Menu not destroyed */
180
181 // state control
182 // NB: must only be used AFTER menu has been attached to frame,
183 // otherwise use individual menus to enable/disable items
184 // enable the item
185 void Enable(int id, bool enable);
186 // TRUE if item enabled
187 bool IsEnabled(int id) const;
188 //
189 void EnableTop(int pos, bool enable);
190
191 // works only with checkable items
192 void Check(int id, bool check);
193 // TRUE if checked
194 bool IsChecked(int id) const;
195
196 void SetLabel(int id, const wxString& label) ;
197 wxString GetLabel(int id) const ;
198
199 virtual void SetHelpString(int id, const wxString& helpString);
200 virtual wxString GetHelpString(int id) const ;
201
202 void SetLabelTop(int pos, const wxString& label) ;
203 wxString GetLabelTop(int pos) const ;
204
205 // notifications: return FALSE to prevent the menu from being
206 // appended/deleted
207 virtual bool OnAppend(wxMenu *menu, const char *title);
208 virtual bool OnDelete(wxMenu *menu, int index);
209
210 // item search
211 // by menu and item names, returns wxNOT_FOUND if not found
212 virtual int FindMenuItem(const wxString& menuString,
213 const wxString& itemString) const;
214 // returns NULL if not found
215 wxMenuItem* FindItem(int id) const { return FindItemForId(id); }
216 // returns NULL if not found, fills menuForItem if !NULL
217 wxMenuItem *FindItemForId(int itemId, wxMenu **menuForItem = NULL) const;
218
219 // submenus access
220 int GetMenuCount() const { return m_menuCount; }
221 wxMenu *GetMenu(int i) const { return m_menus[i]; }
222
223 void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
224 wxEvtHandler *GetEventHandler() { return m_eventHandler; }
225
226 #ifdef WXWIN_COMPATIBILITY
227 // compatibility: these functions are deprecated
228 bool Enabled(int id) const { return IsEnabled(id); }
229 bool Checked(int id) const { return IsChecked(id); }
230 #endif // WXWIN_COMPATIBILITY
231
232 // IMPLEMENTATION
233 // returns TRUE if we're attached to a frame
234 bool IsAttached() const { return m_menuBarFrame != NULL; }
235 // get the frame we live in
236 wxFrame *GetFrame() const { return m_menuBarFrame; }
237 // attach to a frame
238 void Attach(wxFrame *frame)
239 {
240 wxASSERT_MSG( !m_menuBarFrame, _T("menubar already attached!") );
241
242 m_menuBarFrame = frame;
243 }
244 // get the menu handle
245 WXHMENU GetHMenu() const { return m_hMenu; }
246
247 protected:
248 // common part of all ctors
249 void Init();
250
251 // if the menubar is modified, the display is not updated automatically,
252 // call this function to update it (m_menuBarFrame should be !NULL)
253 void Refresh();
254
255 wxEvtHandler *m_eventHandler;
256 int m_menuCount;
257 wxMenu **m_menus;
258 wxString *m_titles;
259 wxFrame *m_menuBarFrame;
260 WXHMENU m_hMenu;
261 };
262
263 #endif // _WX_MENU_H_