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