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