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