1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/univ/menu.h
3 // Purpose: wxMenu and wxMenuBar classes for wxUniversal
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_UNIV_MENU_H_
13 #define _WX_UNIV_MENU_H_
16 #pragma interface "univmenu.h"
23 #include "wx/dynarray.h"
26 class WXDLLEXPORT wxMenuInfo
;
27 WX_DECLARE_EXPORTED_OBJARRAY(wxMenuInfo
, wxMenuInfoArray
);
29 class WXDLLEXPORT wxMenuGeometryInfo
;
30 class WXDLLEXPORT wxPopupMenuWindow
;
31 class WXDLLEXPORT wxRenderer
;
33 // ----------------------------------------------------------------------------
35 // ----------------------------------------------------------------------------
37 class WXDLLEXPORT wxMenu
: public wxMenuBase
41 wxMenu(const wxString
& title
, long style
= 0)
42 : wxMenuBase(title
, style
) { Init(); }
44 wxMenu(long style
= 0) : wxMenuBase(style
) { Init(); }
48 // called by wxMenuItem when an item of this menu changes
49 void RefreshItem(wxMenuItem
*item
);
51 // does the menu have any items?
52 bool IsEmpty() const { return !GetMenuItems().GetFirst(); }
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
,
57 bool selectFirst
= TRUE
);
62 // override the base class methods to connect/disconnect event handlers
63 virtual void Attach(wxMenuBarBase
*menubar
);
64 virtual void Detach();
66 // implementation only from here
68 // do as if this item were clicked, return TRUE if the resulting event was
69 // processed, FALSE otherwise
70 bool ClickItem(wxMenuItem
*item
);
72 // process the key event, return TRUE if done
73 bool ProcessKeyDown(int key
);
76 // find the item for the given accel and generate an event if found
77 bool ProcessAccelEvent(const wxKeyEvent
& event
);
81 // implement base class virtuals
82 virtual bool DoAppend(wxMenuItem
*item
);
83 virtual bool DoInsert(size_t pos
, wxMenuItem
*item
);
84 virtual wxMenuItem
*DoRemove(wxMenuItem
*item
);
86 // common part of DoAppend and DoInsert
87 void OnItemAdded(wxMenuItem
*item
);
89 // called by wxPopupMenuWindow when the window is hidden
90 void OnDismiss(bool dismissParent
);
92 // return true if the menu is currently shown on screen
95 // get the menu geometry info
96 const wxMenuGeometryInfo
& GetGeometryInfo() const;
98 // forget old menu geometry info
99 void InvalidateGeometryInfo();
101 // return either the menubar or the invoking window, normally never NULL
102 wxWindow
*GetRootWindow() const;
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;
109 // add/remove accel for the given menu item
110 void AddAccelFor(wxMenuItem
*item
);
111 void RemoveAccelFor(wxMenuItem
*item
);
112 #endif // wxUSE_ACCEL
115 // common part of all ctors
118 // terminate the current radio group, if any
119 void EndRadioGroup();
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
;
125 // the menu shown on screen or NULL if not currently shown
126 wxPopupMenuWindow
*m_popupMenu
;
129 // the accel table for this menu
130 wxAcceleratorTable m_accelTable
;
131 #endif // wxUSE_ACCEL
133 // the position of the first item in the current radio group or -1
134 int m_startRadioGroup
;
136 // it calls out OnDismiss()
137 friend class wxPopupMenuWindow
;
138 DECLARE_DYNAMIC_CLASS(wxMenu
)
141 // ----------------------------------------------------------------------------
143 // ----------------------------------------------------------------------------
145 class WXDLLEXPORT wxMenuBar
: public wxMenuBarBase
149 wxMenuBar(long WXUNUSED(style
) = 0) { Init(); }
150 virtual ~wxMenuBar();
152 // implement base class virtuals
153 virtual bool Append( wxMenu
*menu
, const wxString
&title
);
154 virtual bool Insert(size_t pos
, wxMenu
*menu
, const wxString
& title
);
155 virtual wxMenu
*Replace(size_t pos
, wxMenu
*menu
, const wxString
& title
);
156 virtual wxMenu
*Remove(size_t pos
);
158 virtual void EnableTop(size_t pos
, bool enable
);
159 virtual bool IsEnabledTop(size_t pos
) const;
161 virtual void SetLabelTop(size_t pos
, const wxString
& label
);
162 virtual wxString
GetLabelTop(size_t pos
) const;
164 virtual void Attach(wxFrame
*frame
);
165 virtual void Detach();
167 // get the next item for the givan accel letter (used by wxFrame), return
170 // if unique is not NULL, filled with TRUE if there is only one item with
171 // this accel, FALSE if two or more
172 int FindNextItemForAccel(int idxStart
,
174 bool *unique
= NULL
) const;
176 // called by wxFrame to set focus to or open the given menu
177 void SelectMenu(size_t pos
);
178 void PopupMenu(size_t pos
);
181 // find the item for the given accel and generate an event if found
182 bool ProcessAccelEvent(const wxKeyEvent
& event
);
183 #endif // wxUSE_ACCEL
185 // called by wxMenu when it is dismissed
186 void OnDismissMenu(bool dismissMenuBar
= FALSE
);
189 // common part of all ctors
193 void OnLeftDown(wxMouseEvent
& event
);
194 void OnMouseMove(wxMouseEvent
& event
);
195 void OnKeyDown(wxKeyEvent
& event
);
196 void OnKillFocus(wxFocusEvent
& event
);
198 // process the mouse move event, return TRUE if we did, FALSE to continue
199 // processing as usual
201 // the coordinates are client coordinates of menubar, convert if necessary
202 bool ProcessMouseEvent(const wxPoint
& pt
);
204 // called when the menu bar loses mouse capture - it is not hidden unlike
205 // menus, but it doesn't have modal status any longer
209 virtual void DoDraw(wxControlRenderer
*renderer
);
212 virtual wxSize
DoGetBestClientSize() const;
214 // has the menubar been created already?
215 bool IsCreated() const { return m_frameLast
!= NULL
; }
217 // "fast" version of GetMenuCount()
218 size_t GetCount() const { return m_menuInfos
.GetCount(); }
220 // get the (total) width of the specified menu
221 wxCoord
GetItemWidth(size_t pos
) const;
223 // get the rect of the item
224 wxRect
GetItemRect(size_t pos
) const;
226 // get the menu from the given point or -1 if none
227 int GetMenuFromPoint(const wxPoint
& pos
) const;
229 // refresh the given item
230 void RefreshItem(size_t pos
);
232 // refresh all items after this one (including it)
233 void RefreshAllItemsAfter(size_t pos
);
235 // hide the currently shown menu and show this one
236 void DoSelectMenu(size_t pos
);
238 // popup the currently selected menu
239 void PopupCurrentMenu(bool selectFirst
= TRUE
);
241 // hide the currently selected menu
244 // do we show a menu currently?
245 bool IsShowingMenu() const { return m_menuShown
!= 0; }
247 // we don't want to have focus except while selecting from menu
248 void GiveAwayFocus();
250 // the array containing extra menu info we need
251 wxMenuInfoArray m_menuInfos
;
253 // the current item (only used when menubar has focus)
257 // the last frame to which we were attached, NULL initially
258 wxFrame
*m_frameLast
;
260 // the currently shown menu or NULL
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
;
268 // it calls out ProcessMouseEvent()
269 friend class wxPopupMenuWindow
;
271 DECLARE_EVENT_TABLE()
272 DECLARE_DYNAMIC_CLASS(wxMenuBar
)
275 #endif // _WX_UNIV_MENU_H_