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