1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/cocoa/menu.h
3 // Purpose: wxMenu and wxMenuBar classes
4 // Author: David Elliott
8 // Copyright: (c) 2002 David Elliott
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef __WX_COCOA_MENU_H__
13 #define __WX_COCOA_MENU_H__
15 #include "wx/cocoa/NSMenu.h"
21 // ========================================================================
23 // ========================================================================
25 class WXDLLEXPORT wxMenu
: public wxMenuBase
, public wxCocoaNSMenu
29 wxMenu(const wxString
& title
, long style
= 0)
30 : wxMenuBase(title
, style
) { Create(title
,style
); }
31 bool Create(const wxString
& title
, long style
= 0);
33 wxMenu(long style
= 0) : wxMenuBase(style
) { Create(wxEmptyString
, style
); }
37 // ------------------------------------------------------------------------
39 // ------------------------------------------------------------------------
41 inline WX_NSMenu
GetNSMenu() { return m_cocoaNSMenu
; }
43 WX_NSMenu m_cocoaNSMenu
;
44 // ------------------------------------------------------------------------
46 // ------------------------------------------------------------------------
48 // implement base class virtuals
49 virtual wxMenuItem
* DoAppend(wxMenuItem
*item
);
50 virtual wxMenuItem
* DoInsert(size_t pos
, wxMenuItem
*item
);
51 virtual wxMenuItem
* DoRemove(wxMenuItem
*item
);
54 // add/remove accel for the given menu item
55 void AddAccelFor(wxMenuItem
*item
);
56 void RemoveAccelFor(wxMenuItem
*item
);
61 // the accel table for this menu
62 wxAcceleratorTable m_accelTable
;
65 DECLARE_DYNAMIC_CLASS(wxMenu
)
68 // ========================================================================
70 // ========================================================================
71 class WXDLLEXPORT wxMenuBar
: public wxMenuBarBase
, public wxCocoaNSMenu
75 wxMenuBar(long style
= 0) { Create(style
); }
76 bool Create(long style
= 0);
79 // ------------------------------------------------------------------------
81 // ------------------------------------------------------------------------
83 inline WX_NSMenu
GetNSMenu() { return m_cocoaNSMenu
; }
85 WX_NSMenu m_cocoaNSMenu
;
86 // ------------------------------------------------------------------------
88 // ------------------------------------------------------------------------
90 // implement base class virtuals
91 virtual bool Append(wxMenu
*menu
, const wxString
&title
);
92 virtual bool Insert(size_t pos
, wxMenu
*menu
, const wxString
& title
);
93 virtual wxMenu
*Replace(size_t pos
, wxMenu
*menu
, const wxString
& title
);
94 virtual wxMenu
*Remove(size_t pos
);
96 virtual void EnableTop(size_t pos
, bool enable
);
97 virtual bool IsEnabledTop(size_t pos
) const;
99 virtual void SetLabelTop(size_t pos
, const wxString
& label
);
100 virtual wxString
GetLabelTop(size_t pos
) const;
102 virtual void Attach(wxFrame
*frame
);
103 virtual void Detach();
105 // get the next item for the givan accel letter (used by wxFrame), return
108 // if unique is not NULL, filled with TRUE if there is only one item with
109 // this accel, FALSE if two or more
110 int FindNextItemForAccel(int idxStart
,
112 bool *unique
= NULL
) const;
114 // called by wxFrame to set focus to or open the given menu
115 void SelectMenu(size_t pos
);
118 // find the item for the given accel and generate an event if found
119 bool ProcessAccelEvent(const wxKeyEvent
& event
);
120 #endif // wxUSE_ACCEL
124 void OnLeftDown(wxMouseEvent
& event
);
125 void OnMouseMove(wxMouseEvent
& event
);
126 void OnKeyDown(wxKeyEvent
& event
);
127 void OnKillFocus(wxFocusEvent
& event
);
129 // process the mouse move event, return TRUE if we did, FALSE to continue
130 // processing as usual
132 // the coordinates are client coordinates of menubar, convert if necessary
133 bool ProcessMouseEvent(const wxPoint
& pt
);
136 virtual wxSize
DoGetBestClientSize() const;
138 // has the menubar been created already?
139 bool IsCreated() const { return m_frameLast
!= NULL
; }
141 // get the (total) width of the specified menu
142 wxCoord
GetItemWidth(size_t pos
) const;
144 // get the rect of the item
145 wxRect
GetItemRect(size_t pos
) const;
147 // get the menu from the given point or -1 if none
148 int GetMenuFromPoint(const wxPoint
& pos
) const;
150 // refresh the given item
151 void RefreshItem(size_t pos
);
153 // refresh all items after this one (including it)
154 void RefreshAllItemsAfter(size_t pos
);
156 // do we show a menu currently?
157 bool IsShowingMenu() const { return m_menuShown
!= 0; }
159 // we don't want to have focus except while selecting from menu
160 void GiveAwayFocus();
162 // the current item (only used when menubar has focus)
166 // the last frame to which we were attached, NULL initially
167 wxFrame
*m_frameLast
;
169 // the currently shown menu or NULL
172 // should be showing the menu? this is subtly different from m_menuShown !=
173 // NULL as the menu which should be shown may be disabled in which case we
174 // don't show it - but will do as soon as the focus shifts to another menu
175 bool m_shouldShowMenu
;
177 DECLARE_DYNAMIC_CLASS(wxMenuBar
)
180 #endif // _WX_COCOA_MENU_H_