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