]> git.saurik.com Git - wxWidgets.git/blob - include/wx/cocoa/menu.h
wxZlibStreams fixes; allow them to be used as deflate [de]compressor in gz/zip files...
[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 // ------------------------------------------------------------------------
38 // Cocoa specifics
39 // ------------------------------------------------------------------------
40 public:
41 inline WX_NSMenu GetNSMenu() { return m_cocoaNSMenu; }
42 protected:
43 WX_NSMenu m_cocoaNSMenu;
44 // ------------------------------------------------------------------------
45 // Implementation
46 // ------------------------------------------------------------------------
47 protected:
48 // implement base class virtuals
49 virtual bool DoAppend(wxMenuItem *item);
50 virtual bool DoInsert(size_t pos, wxMenuItem *item);
51 virtual wxMenuItem *DoRemove(wxMenuItem *item);
52
53 #if wxUSE_ACCEL
54 // add/remove accel for the given menu item
55 void AddAccelFor(wxMenuItem *item);
56 void RemoveAccelFor(wxMenuItem *item);
57 #endif // wxUSE_ACCEL
58
59 private:
60 #if wxUSE_ACCEL
61 // the accel table for this menu
62 wxAcceleratorTable m_accelTable;
63 #endif // wxUSE_ACCEL
64
65 DECLARE_DYNAMIC_CLASS(wxMenu)
66 };
67
68 // ========================================================================
69 // wxMenuBar
70 // ========================================================================
71 class WXDLLEXPORT wxMenuBar : public wxMenuBarBase, public wxCocoaNSMenu
72 {
73 public:
74 // ctors and dtor
75 wxMenuBar(long style = 0) { Create(style); }
76 bool Create(long style = 0);
77 virtual ~wxMenuBar();
78
79 // ------------------------------------------------------------------------
80 // Cocoa specifics
81 // ------------------------------------------------------------------------
82 public:
83 inline WX_NSMenu GetNSMenu() { return m_cocoaNSMenu; }
84 protected:
85 WX_NSMenu m_cocoaNSMenu;
86 // ------------------------------------------------------------------------
87 // Implementation
88 // ------------------------------------------------------------------------
89 public:
90 wxMenuItemList m_items; // the list of menu items
91
92 // implement base class virtuals
93 virtual bool Append(wxMenu *menu, const wxString &title);
94 virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title);
95 virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
96 virtual wxMenu *Remove(size_t pos);
97
98 virtual void EnableTop(size_t pos, bool enable);
99 virtual bool IsEnabledTop(size_t pos) const;
100
101 virtual void SetLabelTop(size_t pos, const wxString& label);
102 virtual wxString GetLabelTop(size_t pos) const;
103
104 virtual void Attach(wxFrame *frame);
105 virtual void Detach();
106
107 // get the next item for the givan accel letter (used by wxFrame), return
108 // -1 if none
109 //
110 // if unique is not NULL, filled with TRUE if there is only one item with
111 // this accel, FALSE if two or more
112 int FindNextItemForAccel(int idxStart,
113 int keycode,
114 bool *unique = NULL) const;
115
116 // called by wxFrame to set focus to or open the given menu
117 void SelectMenu(size_t pos);
118
119 #if wxUSE_ACCEL
120 // find the item for the given accel and generate an event if found
121 bool ProcessAccelEvent(const wxKeyEvent& event);
122 #endif // wxUSE_ACCEL
123
124 protected:
125 // event handlers
126 void OnLeftDown(wxMouseEvent& event);
127 void OnMouseMove(wxMouseEvent& event);
128 void OnKeyDown(wxKeyEvent& event);
129 void OnKillFocus(wxFocusEvent& event);
130
131 // process the mouse move event, return TRUE if we did, FALSE to continue
132 // processing as usual
133 //
134 // the coordinates are client coordinates of menubar, convert if necessary
135 bool ProcessMouseEvent(const wxPoint& pt);
136
137 // menubar geometry
138 virtual wxSize DoGetBestClientSize() const;
139
140 // has the menubar been created already?
141 bool IsCreated() const { return m_frameLast != NULL; }
142
143 // get the (total) width of the specified menu
144 wxCoord GetItemWidth(size_t pos) const;
145
146 // get the rect of the item
147 wxRect GetItemRect(size_t pos) const;
148
149 // get the menu from the given point or -1 if none
150 int GetMenuFromPoint(const wxPoint& pos) const;
151
152 // refresh the given item
153 void RefreshItem(size_t pos);
154
155 // refresh all items after this one (including it)
156 void RefreshAllItemsAfter(size_t pos);
157
158 // do we show a menu currently?
159 bool IsShowingMenu() const { return m_menuShown != 0; }
160
161 // we don't want to have focus except while selecting from menu
162 void GiveAwayFocus();
163
164 // the current item (only used when menubar has focus)
165 int m_current;
166
167 private:
168 // the last frame to which we were attached, NULL initially
169 wxFrame *m_frameLast;
170
171 // the currently shown menu or NULL
172 wxMenu *m_menuShown;
173
174 // should be showing the menu? this is subtly different from m_menuShown !=
175 // NULL as the menu which should be shown may be disabled in which case we
176 // don't show it - but will do as soon as the focus shifts to another menu
177 bool m_shouldShowMenu;
178
179 DECLARE_DYNAMIC_CLASS(wxMenuBar)
180 };
181
182 #endif // _WX_COCOA_MENU_H_