]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mac/menu.h
Added wxUSE_NUMBERDLG to setup.h; added some files to VC++ project files;
[wxWidgets.git] / include / wx / mac / menu.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: menu.h
3 // Purpose: wxMenu, wxMenuBar classes
4 // Author: AUTHOR
5 // Modified by:
6 // Created: ??/??/98
7 // RCS-ID: $Id$
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_MENU_H_
13 #define _WX_MENU_H_
14
15 #ifdef __GNUG__
16 #pragma interface "menu.h"
17 #endif
18
19 #if wxUSE_ACCEL
20 #include "wx/accel.h"
21 #include "wx/dynarray.h"
22
23 WX_DEFINE_EXPORTED_ARRAY(wxAcceleratorEntry *, wxAcceleratorArray);
24 #endif // wxUSE_ACCEL
25
26 class WXDLLEXPORT wxFrame;
27
28 // ----------------------------------------------------------------------------
29 // Menu
30 // ----------------------------------------------------------------------------
31
32 class WXDLLEXPORT wxMenu : public wxMenuBase
33 {
34 public:
35 // ctors & dtor
36 wxMenu(const wxString& title, long style = 0)
37 : wxMenuBase(title, style) { Init(); }
38
39 wxMenu(long style = 0) : wxMenuBase(style) { Init(); }
40
41 virtual ~wxMenu();
42
43 // implement base class virtuals
44 virtual bool DoAppend(wxMenuItem *item);
45 virtual bool DoInsert(size_t pos, wxMenuItem *item);
46 virtual wxMenuItem *DoRemove(wxMenuItem *item);
47
48 virtual void Break();
49
50 virtual void SetTitle(const wxString& title);
51
52 // MSW-specific
53 bool ProcessCommand(wxCommandEvent& event);
54
55 #if WXWIN_COMPATIBILITY
56 wxMenu(const wxString& title, const wxFunction func)
57 : wxMenuBase(title)
58 {
59 Callback(func);
60 }
61 #endif // WXWIN_COMPATIBILITY
62
63 // implementation only from now on
64 // -------------------------------
65
66 bool MacMenuSelect(wxEvtHandler* handler, long when , int macMenuId, int macMenuItemNum) ;
67 int MacGetIndexFromId( int id ) ;
68 int MacGetIndexFromItem( wxMenuItem *pItem ) ;
69 void MacEnableMenu( bool bDoEnable ) ;
70
71 // semi-private accessors
72 // get the window which contains this menu
73 wxWindow *GetWindow() const;
74 // get the menu handle
75 WXHMENU GetHMenu() const { return m_hMenu; }
76
77 // attach/detach menu to/from wxMenuBar
78 void Attach(wxMenuBar *menubar);
79 void Detach();
80 short MacGetMenuId() { return m_macMenuId ; }
81 #if wxUSE_ACCEL
82 // called by wxMenuBar to build its accel table from the accels of all menus
83 bool HasAccels() const { return !m_accels.IsEmpty(); }
84 size_t GetAccelCount() const { return m_accels.GetCount(); }
85 size_t CopyAccels(wxAcceleratorEntry *accels) const;
86
87 // called by wxMenuItem when its accels changes
88 void UpdateAccel(wxMenuItem *item);
89
90 // helper used by wxMenu itself (returns the index in m_accels)
91 int FindAccel(int id) const;
92 #endif // wxUSE_ACCEL
93
94 private:
95 // common part of all ctors
96 void Init();
97
98 // common part of Append/Insert (behaves as Append is pos == (size_t)-1)
99 bool DoInsertOrAppend(wxMenuItem *item, size_t pos = (size_t)-1);
100
101 // if TRUE, insert a breal before appending the next item
102 bool m_doBreak;
103
104 // the menu handle of this menu
105 WXHMENU m_hMenu;
106
107 short m_macMenuId;
108
109 static short s_macNextMenuId ;
110 #if wxUSE_ACCEL
111 // the accelerators for our menu items
112 wxAcceleratorArray m_accels;
113 #endif // wxUSE_ACCEL
114
115 DECLARE_DYNAMIC_CLASS(wxMenu)
116 };
117
118 // ----------------------------------------------------------------------------
119 // Menu Bar (a la Windows)
120 // ----------------------------------------------------------------------------
121
122 class WXDLLEXPORT wxMenuBar : public wxMenuBarBase
123 {
124 public:
125 // ctors & dtor
126 // default constructor
127 wxMenuBar();
128 // unused under MSW
129 wxMenuBar(long style);
130 // menubar takes ownership of the menus arrays but copies the titles
131 wxMenuBar(int n, wxMenu *menus[], const wxString titles[]);
132 virtual ~wxMenuBar();
133
134 // menubar construction
135 virtual bool Append( wxMenu *menu, const wxString &title );
136 virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title);
137 virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
138 virtual wxMenu *Remove(size_t pos);
139
140 virtual int FindMenuItem(const wxString& menuString,
141 const wxString& itemString) const;
142 virtual wxMenuItem* FindItem( int id, wxMenu **menu = NULL ) const;
143
144 virtual void EnableTop( size_t pos, bool flag );
145 virtual void SetLabelTop( size_t pos, const wxString& label );
146 virtual wxString GetLabelTop( size_t pos ) const;
147
148 // compatibility: these functions are deprecated
149 #if WXWIN_COMPATIBILITY
150 void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
151 wxEvtHandler *GetEventHandler() { return m_eventHandler; }
152
153 bool Enabled(int id) const { return IsEnabled(id); }
154 bool Checked(int id) const { return IsChecked(id); }
155 #endif // WXWIN_COMPATIBILITY
156
157 // implementation from now on
158 WXHMENU Create();
159 int FindMenu(const wxString& title);
160 void Detach();
161
162 // returns TRUE if we're attached to a frame
163 bool IsAttached() const { return m_menuBarFrame != NULL; }
164 // get the frame we live in
165 wxFrame *GetFrame() const { return m_menuBarFrame; }
166 // attach to a frame
167 void Attach(wxFrame *frame);
168
169 #if wxUSE_ACCEL
170 // get the accel table for all the menus
171 const wxAcceleratorTable& GetAccelTable() const { return m_accelTable; }
172
173 // update the accel table (must be called after adding/deletign a menu)
174 void RebuildAccelTable();
175 #endif // wxUSE_ACCEL
176
177 // if the menubar is modified, the display is not updated automatically,
178 // call this function to update it (m_menuBarFrame should be !NULL)
179 void Refresh();
180
181 void MacInstallMenuBar() ;
182 void MacMenuSelect(wxEvtHandler* handler, long when , int macMenuId, int macMenuItemNum) ;
183 static wxMenuBar* MacGetInstalledMenuBar() { return s_macInstalledMenuBar ; }
184
185 protected:
186 // common part of all ctors
187 void Init();
188
189 #if WXWIN_COMPATIBILITY
190 wxEvtHandler *m_eventHandler;
191 #endif // WXWIN_COMPATIBILITY
192
193 wxArrayString m_titles;
194
195 wxFrame *m_menuBarFrame;
196
197 #if wxUSE_ACCEL
198 // the accelerator table for all accelerators in all our menus
199 wxAcceleratorTable m_accelTable;
200 #endif // wxUSE_ACCEL
201
202 private:
203 static wxMenuBar* s_macInstalledMenuBar ;
204
205 DECLARE_DYNAMIC_CLASS(wxMenuBar)
206 };
207
208 #endif // _WX_MENU_H_