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