]> git.saurik.com Git - wxWidgets.git/blob - include/wx/cocoa/menu.h
Add wxActivateEvent::GetActivationReason().
[wxWidgets.git] / include / wx / cocoa / menu.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/cocoa/menu.h
3 // Purpose: wxMenu and wxMenuBar classes
4 // Author: David Elliott
5 // Modified by:
6 // Created: 2002/12/09
7 // Copyright: (c) 2002 David Elliott
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 #ifndef __WX_COCOA_MENU_H__
12 #define __WX_COCOA_MENU_H__
13
14 #include "wx/cocoa/NSMenu.h"
15
16 #if wxUSE_ACCEL
17 #include "wx/accel.h"
18 #endif // wxUSE_ACCEL
19
20 // ========================================================================
21 // wxMenu
22 // ========================================================================
23
24 class WXDLLIMPEXP_CORE wxMenu : public wxMenuBase, public wxCocoaNSMenu
25 {
26 public:
27 // ctors and dtor
28 wxMenu(const wxString& title, long style = 0)
29 : wxMenuBase(title, style)
30 , m_cocoaDeletes(false)
31 { Create(title,style); }
32 bool Create(const wxString& title, long style = 0);
33
34 wxMenu(long style = 0) : wxMenuBase(style) { Create(wxEmptyString, style); }
35
36 virtual ~wxMenu();
37
38 // ------------------------------------------------------------------------
39 // Cocoa specifics
40 // ------------------------------------------------------------------------
41 public:
42 inline WX_NSMenu GetNSMenu() { return m_cocoaNSMenu; }
43 void SetCocoaDeletes(bool cocoaDeletes);
44 virtual void Cocoa_dealloc();
45 protected:
46 WX_NSMenu m_cocoaNSMenu;
47 bool m_cocoaDeletes;
48 // ------------------------------------------------------------------------
49 // Implementation
50 // ------------------------------------------------------------------------
51 protected:
52 // implement base class virtuals
53 virtual wxMenuItem* DoAppend(wxMenuItem *item);
54 virtual wxMenuItem* DoInsert(size_t pos, wxMenuItem *item);
55 virtual wxMenuItem* DoRemove(wxMenuItem *item);
56
57 #if wxUSE_ACCEL
58 // add/remove accel for the given menu item
59 void AddAccelFor(wxMenuItem *item);
60 void RemoveAccelFor(wxMenuItem *item);
61 #endif // wxUSE_ACCEL
62
63 private:
64 #if wxUSE_ACCEL
65 // the accel table for this menu
66 wxAcceleratorTable m_accelTable;
67 #endif // wxUSE_ACCEL
68
69 DECLARE_DYNAMIC_CLASS(wxMenu)
70 };
71
72 // ========================================================================
73 // wxMenuBar
74 // ========================================================================
75 class WXDLLIMPEXP_CORE wxMenuBar : public wxMenuBarBase
76 {
77 public:
78 // ctors and dtor
79 wxMenuBar(long style = 0) { Create(style); }
80 wxMenuBar(size_t n, wxMenu *menus[], const wxString titles[], long style = 0);
81 bool Create(long style = 0);
82 virtual ~wxMenuBar();
83
84 // ------------------------------------------------------------------------
85 // Cocoa specifics
86 // ------------------------------------------------------------------------
87 public:
88 inline WX_NSMenu GetNSMenu() { return m_cocoaNSMenu; }
89 protected:
90 WX_NSMenu m_cocoaNSMenu;
91 // ------------------------------------------------------------------------
92 // Implementation
93 // ------------------------------------------------------------------------
94 public:
95 // implement base class virtuals
96 virtual bool Append(wxMenu *menu, const wxString &title);
97 virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title);
98 virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
99 virtual wxMenu *Remove(size_t pos);
100
101 virtual void EnableTop(size_t pos, bool enable);
102 virtual bool IsEnabledTop(size_t pos) const;
103
104 virtual void SetMenuLabel(size_t pos, const wxString& label);
105 virtual wxString GetMenuLabel(size_t pos) const;
106
107 virtual void Attach(wxFrame *frame);
108 virtual void Detach();
109
110 // get the next item for the givan accel letter (used by wxFrame), return
111 // -1 if none
112 //
113 // if unique is not NULL, filled with TRUE if there is only one item with
114 // this accel, FALSE if two or more
115 int FindNextItemForAccel(int idxStart,
116 int keycode,
117 bool *unique = NULL) const;
118
119 // called by wxFrame to set focus to or open the given menu
120 void SelectMenu(size_t pos);
121
122 #if wxUSE_ACCEL
123 // find the item for the given accel and generate an event if found
124 bool ProcessAccelEvent(const wxKeyEvent& event);
125 #endif // wxUSE_ACCEL
126
127 protected:
128 // event handlers
129 void OnLeftDown(wxMouseEvent& event);
130 void OnMouseMove(wxMouseEvent& event);
131 void OnKeyDown(wxKeyEvent& event);
132 void OnKillFocus(wxFocusEvent& event);
133
134 // process the mouse move event, return TRUE if we did, FALSE to continue
135 // processing as usual
136 //
137 // the coordinates are client coordinates of menubar, convert if necessary
138 bool ProcessMouseEvent(const wxPoint& pt);
139
140 // menubar geometry
141 virtual wxSize DoGetBestClientSize() const;
142
143 // has the menubar been created already?
144 bool IsCreated() const { return m_frameLast != NULL; }
145
146 // get the (total) width of the specified menu
147 wxCoord GetItemWidth(size_t pos) const;
148
149 // get the rect of the item
150 wxRect GetItemRect(size_t pos) const;
151
152 // get the menu from the given point or -1 if none
153 int GetMenuFromPoint(const wxPoint& pos) const;
154
155 // refresh the given item
156 void RefreshItem(size_t pos);
157
158 // refresh all items after this one (including it)
159 void RefreshAllItemsAfter(size_t pos);
160
161 // do we show a menu currently?
162 bool IsShowingMenu() const { return m_menuShown != 0; }
163
164 // we don't want to have focus except while selecting from menu
165 void GiveAwayFocus();
166
167 // the current item (only used when menubar has focus)
168 int m_current;
169
170 private:
171 // the last frame to which we were attached, NULL initially
172 wxFrame *m_frameLast;
173
174 // the currently shown menu or NULL
175 wxMenu *m_menuShown;
176
177 // should be showing the menu? this is subtly different from m_menuShown !=
178 // NULL as the menu which should be shown may be disabled in which case we
179 // don't show it - but will do as soon as the focus shifts to another menu
180 bool m_shouldShowMenu;
181
182 DECLARE_DYNAMIC_CLASS(wxMenuBar)
183 };
184
185 #endif // _WX_COCOA_MENU_H_