]> git.saurik.com Git - wxWidgets.git/blame - include/wx/univ/menu.h
Initial work on virtual file system support for the WebKitGTK+ backend. It now suppor...
[wxWidgets.git] / include / wx / univ / menu.h
CommitLineData
1e6feb95
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: wx/univ/menu.h
3// Purpose: wxMenu and wxMenuBar classes for wxUniversal
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 05.05.01
7// RCS-ID: $Id$
442b35b5 8// Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
65571936 9// Licence: wxWindows licence
1e6feb95
VZ
10///////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_UNIV_MENU_H_
13#define _WX_UNIV_MENU_H_
14
1e6feb95
VZ
15#if wxUSE_ACCEL
16 #include "wx/accel.h"
17#endif // wxUSE_ACCEL
18
19#include "wx/dynarray.h"
20
21// fwd declarations
b5dbe15d 22class WXDLLIMPEXP_FWD_CORE wxMenuInfo;
61fef19b 23WX_DECLARE_EXPORTED_OBJARRAY(wxMenuInfo, wxMenuInfoArray);
1e6feb95 24
b5dbe15d
VS
25class WXDLLIMPEXP_FWD_CORE wxMenuGeometryInfo;
26class WXDLLIMPEXP_FWD_CORE wxPopupMenuWindow;
27class WXDLLIMPEXP_FWD_CORE wxRenderer;
1e6feb95 28
1e6feb95
VZ
29// ----------------------------------------------------------------------------
30// wxMenu
31// ----------------------------------------------------------------------------
32
53a2db12 33class WXDLLIMPEXP_CORE wxMenu : public wxMenuBase
1e6feb95
VZ
34{
35public:
36 // ctors and dtor
37 wxMenu(const wxString& title, long style = 0)
38 : wxMenuBase(title, style) { Init(); }
39
40 wxMenu(long style = 0) : wxMenuBase(style) { Init(); }
41
42 virtual ~wxMenu();
43
44 // called by wxMenuItem when an item of this menu changes
45 void RefreshItem(wxMenuItem *item);
46
47 // does the menu have any items?
48 bool IsEmpty() const { return !GetMenuItems().GetFirst(); }
49
50 // show this menu at the given position (in screen coords) and optionally
51 // select its first item
52 void Popup(const wxPoint& pos, const wxSize& size,
a290fa5a 53 bool selectFirst = true);
1e6feb95
VZ
54
55 // dismiss the menu
56 void Dismiss();
57
58 // override the base class methods to connect/disconnect event handlers
59 virtual void Attach(wxMenuBarBase *menubar);
60 virtual void Detach();
61
62 // implementation only from here
63
a290fa5a
WS
64 // do as if this item were clicked, return true if the resulting event was
65 // processed, false otherwise
1e6feb95
VZ
66 bool ClickItem(wxMenuItem *item);
67
a290fa5a 68 // process the key event, return true if done
1e6feb95
VZ
69 bool ProcessKeyDown(int key);
70
71#if wxUSE_ACCEL
72 // find the item for the given accel and generate an event if found
73 bool ProcessAccelEvent(const wxKeyEvent& event);
74#endif // wxUSE_ACCEL
75
76protected:
77 // implement base class virtuals
9add9367
RD
78 virtual wxMenuItem* DoAppend(wxMenuItem *item);
79 virtual wxMenuItem* DoInsert(size_t pos, wxMenuItem *item);
80 virtual wxMenuItem* DoRemove(wxMenuItem *item);
1e6feb95
VZ
81
82 // common part of DoAppend and DoInsert
83 void OnItemAdded(wxMenuItem *item);
84
85 // called by wxPopupMenuWindow when the window is hidden
86 void OnDismiss(bool dismissParent);
87
88 // return true if the menu is currently shown on screen
89 bool IsShown() const;
90
91 // get the menu geometry info
92 const wxMenuGeometryInfo& GetGeometryInfo() const;
93
94 // forget old menu geometry info
95 void InvalidateGeometryInfo();
96
97 // return either the menubar or the invoking window, normally never NULL
98 wxWindow *GetRootWindow() const;
99
100 // get the renderer we use for drawing: either the one of the menu bar or
101 // the one of the window if we're a popup menu
102 wxRenderer *GetRenderer() const;
103
104#if wxUSE_ACCEL
105 // add/remove accel for the given menu item
106 void AddAccelFor(wxMenuItem *item);
107 void RemoveAccelFor(wxMenuItem *item);
108#endif // wxUSE_ACCEL
109
110private:
111 // common part of all ctors
112 void Init();
113
6f7c5199
JS
114 // terminate the current radio group, if any
115 void EndRadioGroup();
116
1e6feb95
VZ
117 // the exact menu geometry is defined by a struct derived from this one
118 // which is opaque and defined by the renderer
119 wxMenuGeometryInfo *m_geometry;
120
121 // the menu shown on screen or NULL if not currently shown
122 wxPopupMenuWindow *m_popupMenu;
123
124#if wxUSE_ACCEL
125 // the accel table for this menu
126 wxAcceleratorTable m_accelTable;
127#endif // wxUSE_ACCEL
128
6f7c5199
JS
129 // the position of the first item in the current radio group or -1
130 int m_startRadioGroup;
131
1e6feb95 132 // it calls out OnDismiss()
e766c8a9 133 friend class wxPopupMenuWindow;
1e6feb95
VZ
134 DECLARE_DYNAMIC_CLASS(wxMenu)
135};
136
137// ----------------------------------------------------------------------------
138// wxMenuBar
139// ----------------------------------------------------------------------------
140
53a2db12 141class WXDLLIMPEXP_CORE wxMenuBar : public wxMenuBarBase
1e6feb95
VZ
142{
143public:
144 // ctors and dtor
145 wxMenuBar(long WXUNUSED(style) = 0) { Init(); }
87a39e3b 146 wxMenuBar(size_t n, wxMenu *menus[], const wxString titles[], long style = 0);
1e6feb95
VZ
147 virtual ~wxMenuBar();
148
149 // implement base class virtuals
150 virtual bool Append( wxMenu *menu, const wxString &title );
151 virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title);
152 virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
153 virtual wxMenu *Remove(size_t pos);
154
155 virtual void EnableTop(size_t pos, bool enable);
156 virtual bool IsEnabledTop(size_t pos) const;
157
52af3158
JS
158 virtual void SetMenuLabel(size_t pos, const wxString& label);
159 virtual wxString GetMenuLabel(size_t pos) const;
1e6feb95
VZ
160
161 virtual void Attach(wxFrame *frame);
162 virtual void Detach();
163
164 // get the next item for the givan accel letter (used by wxFrame), return
165 // -1 if none
166 //
a290fa5a
WS
167 // if unique is not NULL, filled with true if there is only one item with
168 // this accel, false if two or more
1e6feb95
VZ
169 int FindNextItemForAccel(int idxStart,
170 int keycode,
171 bool *unique = NULL) const;
172
173 // called by wxFrame to set focus to or open the given menu
174 void SelectMenu(size_t pos);
175 void PopupMenu(size_t pos);
176
177#if wxUSE_ACCEL
178 // find the item for the given accel and generate an event if found
179 bool ProcessAccelEvent(const wxKeyEvent& event);
180#endif // wxUSE_ACCEL
181
182 // called by wxMenu when it is dismissed
a290fa5a 183 void OnDismissMenu(bool dismissMenuBar = false);
1e6feb95
VZ
184
185protected:
186 // common part of all ctors
187 void Init();
188
189 // event handlers
190 void OnLeftDown(wxMouseEvent& event);
191 void OnMouseMove(wxMouseEvent& event);
192 void OnKeyDown(wxKeyEvent& event);
193 void OnKillFocus(wxFocusEvent& event);
194
a290fa5a 195 // process the mouse move event, return true if we did, false to continue
1e6feb95
VZ
196 // processing as usual
197 //
198 // the coordinates are client coordinates of menubar, convert if necessary
199 bool ProcessMouseEvent(const wxPoint& pt);
200
201 // called when the menu bar loses mouse capture - it is not hidden unlike
202 // menus, but it doesn't have modal status any longer
203 void OnDismiss();
204
205 // draw the menubar
206 virtual void DoDraw(wxControlRenderer *renderer);
207
208 // menubar geometry
209 virtual wxSize DoGetBestClientSize() const;
210
211 // has the menubar been created already?
212 bool IsCreated() const { return m_frameLast != NULL; }
213
214 // "fast" version of GetMenuCount()
215 size_t GetCount() const { return m_menuInfos.GetCount(); }
216
217 // get the (total) width of the specified menu
218 wxCoord GetItemWidth(size_t pos) const;
219
220 // get the rect of the item
221 wxRect GetItemRect(size_t pos) const;
222
223 // get the menu from the given point or -1 if none
224 int GetMenuFromPoint(const wxPoint& pos) const;
225
226 // refresh the given item
227 void RefreshItem(size_t pos);
228
229 // refresh all items after this one (including it)
230 void RefreshAllItemsAfter(size_t pos);
231
232 // hide the currently shown menu and show this one
233 void DoSelectMenu(size_t pos);
234
235 // popup the currently selected menu
a290fa5a 236 void PopupCurrentMenu(bool selectFirst = true);
1e6feb95
VZ
237
238 // hide the currently selected menu
239 void DismissMenu();
240
241 // do we show a menu currently?
242 bool IsShowingMenu() const { return m_menuShown != 0; }
243
244 // we don't want to have focus except while selecting from menu
245 void GiveAwayFocus();
246
5b3166fd
MW
247 // Release the mouse capture if we have it
248 bool ReleaseMouseCapture();
249
1e6feb95
VZ
250 // the array containing extra menu info we need
251 wxMenuInfoArray m_menuInfos;
252
253 // the current item (only used when menubar has focus)
254 int m_current;
255
256private:
257 // the last frame to which we were attached, NULL initially
258 wxFrame *m_frameLast;
259
260 // the currently shown menu or NULL
261 wxMenu *m_menuShown;
262
263 // should be showing the menu? this is subtly different from m_menuShown !=
264 // NULL as the menu which should be shown may be disabled in which case we
265 // don't show it - but will do as soon as the focus shifts to another menu
266 bool m_shouldShowMenu;
267
268 // it calls out ProcessMouseEvent()
e766c8a9 269 friend class wxPopupMenuWindow;
1e6feb95
VZ
270
271 DECLARE_EVENT_TABLE()
272 DECLARE_DYNAMIC_CLASS(wxMenuBar)
273};
274
275#endif // _WX_UNIV_MENU_H_