]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/menu.h
added wxFrame::Command()
[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
KB
26
27WXDLLEXPORT_DATA(extern const char*) wxEmptyString;
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
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;
2bda0e17
KB
131
132private:
c626a8b7 133 bool m_doBreak ;
2bda0e17
KB
134
135public:
c626a8b7
VZ
136 // This is used when m_hMenu is NULL because we don't want to
137 // delete it in ~wxMenu (it's been added to a parent menu).
138 // But we'll still need the handle for other purposes.
139 // Might be better to have a flag saying whether it's deleteable or not.
140 WXHMENU m_savehMenu ; // Used for Enable() on popup
141 WXHMENU m_hMenu;
142 wxFunction m_callback;
143
144 int m_noItems;
145 wxString m_title;
146 wxMenu * m_topLevelMenu;
147 wxMenuBar * m_menuBar;
148 wxList m_menuItems;
149 wxEvtHandler * m_parent;
150 wxEvtHandler * m_eventHandler;
151 wxWindow *m_pInvokingWindow;
152 void* m_clientData;
2bda0e17
KB
153};
154
155// ----------------------------------------------------------------------------
156// Menu Bar (a la Windows)
157// ----------------------------------------------------------------------------
c626a8b7
VZ
158
159class WXDLLEXPORT wxMenuBar : public wxEvtHandler
2bda0e17 160{
c626a8b7
VZ
161 DECLARE_DYNAMIC_CLASS(wxMenuBar)
162
163public:
164 // ctors & dtor
165 wxMenuBar();
166 wxMenuBar(long style);
167 wxMenuBar(int n, wxMenu *menus[], const wxString titles[]);
168 virtual ~wxMenuBar();
169
170 // menubar construction
171 void Append(wxMenu *menu, const wxString& title);
172 virtual void Delete(wxMenu *menu, int index = 0); /* Menu not destroyed */
173
174 // state control
175 // NB: must only be used AFTER menu has been attached to frame,
176 // otherwise use individual menus to enable/disable items
177 // enable the item
178 void Enable(int id, bool enable);
179 // TRUE if item enabled
180 bool IsEnabled(int id) const;
181 //
182 void EnableTop(int pos, bool enable);
183
184 // works only with checkable items
185 void Check(int id, bool check);
186 // TRUE if checked
187 bool IsChecked(int id) const;
188
189 void SetLabel(int id, const wxString& label) ;
190 wxString GetLabel(int id) const ;
191
192 virtual void SetHelpString(int id, const wxString& helpString);
193 virtual wxString GetHelpString(int id) const ;
194
195 void SetLabelTop(int pos, const wxString& label) ;
196 wxString GetLabelTop(int pos) const ;
197
198 // notifications
199 virtual bool OnAppend(wxMenu *menu, const char *title);
200 virtual bool OnDelete(wxMenu *menu, int index);
201
202 // item search
203 // by menu and item names, returns wxNOT_FOUND if not found
204 virtual int FindMenuItem(const wxString& menuString,
205 const wxString& itemString) const;
206 // returns NULL if not found
207 wxMenuItem* FindItem(int id) const { return FindItemForId(id); }
208 // returns NULL if not found, fills menuForItem if !NULL
209 wxMenuItem *FindItemForId(int itemId, wxMenu **menuForItem = NULL) const;
210
211 // submenus access
212 int GetMenuCount() const { return m_menuCount; }
213 wxMenu *GetMenu(int i) const { return m_menus[i]; }
214
215 void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
216 wxEvtHandler *GetEventHandler() { return m_eventHandler; }
217
218#ifdef WXWIN_COMPATIBILITY
219 // compatibility: these functions are deprecated
220 bool Enabled(int id) const { return IsEnabled(id); }
221 bool Checked(int id) const { return IsChecked(id); }
222#endif // WXWIN_COMPATIBILITY
2bda0e17 223
a3622daa 224public:
c626a8b7
VZ
225 wxEvtHandler * m_eventHandler;
226 int m_menuCount;
227 wxMenu ** m_menus;
228 wxString * m_titles;
229 wxFrame * m_menuBarFrame;
230 WXHMENU m_hMenu;
2bda0e17
KB
231};
232
bbcdf8bc 233#endif // _WX_MENU_H_