]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/msw/menu.h
* add documentation for wxMemoryBuffer
[wxWidgets.git] / include / wx / msw / menu.h
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/msw/menu.h
3// Purpose: wxMenu, wxMenuBar classes
4// Author: Julian Smart
5// Modified by: Vadim Zeitlin (wxMenuItem is now in separate file)
6// Created: 01/02/97
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_MENU_H_
13#define _WX_MENU_H_
14
15#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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_PTR(wxAcceleratorEntry *, wxAcceleratorArray);
24#endif // wxUSE_ACCEL
25
26class WXDLLEXPORT wxFrame;
27
28#if defined(__WXWINCE__) && wxUSE_TOOLBAR
29class WXDLLEXPORT wxToolBar;
30#endif
31
32
33// Not using a combined wxToolBar/wxMenuBar? then use
34// a commandbar in WinCE .NET to implement the
35// menubar, since there is no ::SetMenu function.
36#if defined(__WXWINCE__)
37# if ((_WIN32_WCE >= 400) && !defined(__POCKETPC__) && !defined(__SMARTPHONE__)) || \
38 defined(__HANDHELDPC__)
39# define WINCE_WITH_COMMANDBAR
40# else
41# define WINCE_WITHOUT_COMMANDBAR
42# endif
43#endif
44
45
46#include "wx/arrstr.h"
47
48// ----------------------------------------------------------------------------
49// Menu
50// ----------------------------------------------------------------------------
51
52class WXDLLEXPORT wxMenu : public wxMenuBase
53{
54public:
55 // ctors & dtor
56 wxMenu(const wxString& title, long style = 0)
57 : wxMenuBase(title, style) { Init(); }
58
59 wxMenu(long style = 0) : wxMenuBase(style) { Init(); }
60
61 virtual ~wxMenu();
62
63 // implement base class virtuals
64 virtual wxMenuItem* DoAppend(wxMenuItem *item);
65 virtual wxMenuItem* DoInsert(size_t pos, wxMenuItem *item);
66 virtual wxMenuItem* DoRemove(wxMenuItem *item);
67
68 virtual void Break();
69
70 virtual void SetTitle(const wxString& title);
71
72 // deprecated functions
73#if wxUSE_MENU_CALLBACK
74 wxMenu(const wxString& title, const wxFunction func)
75 : wxMenuBase(title)
76 {
77 Init();
78
79 Callback(func);
80 }
81#endif // wxUSE_MENU_CALLBACK
82
83 // implementation only from now on
84 // -------------------------------
85
86 virtual void Attach(wxMenuBarBase *menubar);
87
88 bool MSWCommand(WXUINT param, WXWORD id);
89
90 // semi-private accessors
91 // get the window which contains this menu
92 wxWindow *GetWindow() const;
93 // get the menu handle
94 WXHMENU GetHMenu() const { return m_hMenu; }
95
96#if wxUSE_ACCEL
97 // called by wxMenuBar to build its accel table from the accels of all menus
98 bool HasAccels() const { return !m_accels.IsEmpty(); }
99 size_t GetAccelCount() const { return m_accels.GetCount(); }
100 size_t CopyAccels(wxAcceleratorEntry *accels) const;
101
102 // called by wxMenuItem when its accels changes
103 void UpdateAccel(wxMenuItem *item);
104
105 // helper used by wxMenu itself (returns the index in m_accels)
106 int FindAccel(int id) const;
107#endif // wxUSE_ACCEL
108
109private:
110 // common part of all ctors
111 void Init();
112
113 // common part of Append/Insert (behaves as Append is pos == (size_t)-1)
114 bool DoInsertOrAppend(wxMenuItem *item, size_t pos = (size_t)-1);
115
116 // terminate the current radio group, if any
117 void EndRadioGroup();
118
119 // if TRUE, insert a breal before appending the next item
120 bool m_doBreak;
121
122 // the position of the first item in the current radio group or -1
123 int m_startRadioGroup;
124
125 // the menu handle of this menu
126 WXHMENU m_hMenu;
127
128#if wxUSE_ACCEL
129 // the accelerators for our menu items
130 wxAcceleratorArray m_accels;
131#endif // wxUSE_ACCEL
132
133 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenu)
134};
135
136// ----------------------------------------------------------------------------
137// Menu Bar (a la Windows)
138// ----------------------------------------------------------------------------
139
140class WXDLLEXPORT wxMenuInfo : public wxObject
141{
142public :
143 wxMenuInfo() { m_menu = NULL ; }
144 virtual ~wxMenuInfo() { }
145
146 void Create( wxMenu *menu , const wxString &title )
147 { m_menu = menu ; m_title = title ; }
148 wxMenu* GetMenu() const { return m_menu ; }
149 wxString GetTitle() const { return m_title ; }
150private :
151 wxMenu *m_menu ;
152 wxString m_title ;
153
154 DECLARE_DYNAMIC_CLASS(wxMenuInfo) ;
155} ;
156
157WX_DECLARE_EXPORTED_LIST(wxMenuInfo, wxMenuInfoList );
158
159class WXDLLEXPORT wxMenuBar : public wxMenuBarBase
160{
161public:
162 // ctors & dtor
163 // default constructor
164 wxMenuBar();
165 // unused under MSW
166 wxMenuBar(long style);
167 // menubar takes ownership of the menus arrays but copies the titles
168 wxMenuBar(int n, wxMenu *menus[], const wxString titles[]);
169 virtual ~wxMenuBar();
170
171 // menubar construction
172 bool Append( wxMenuInfo *info ) { return Append( info->GetMenu() , info->GetTitle() ) ; }
173 const wxMenuInfoList& GetMenuInfos() const ;
174
175 virtual bool Append( wxMenu *menu, const wxString &title );
176 virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title);
177 virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
178 virtual wxMenu *Remove(size_t pos);
179
180 virtual void EnableTop( size_t pos, bool flag );
181 virtual void SetLabelTop( size_t pos, const wxString& label );
182 virtual wxString GetLabelTop( size_t pos ) const;
183
184 // implementation from now on
185 WXHMENU Create();
186 virtual void Detach();
187 virtual void Attach(wxFrame *frame);
188
189#if defined(__WXWINCE__) && wxUSE_TOOLBAR
190 // Under WinCE, a menubar is owned by the frame's toolbar
191 void SetToolBar(wxToolBar* toolBar) { m_toolBar = toolBar; }
192 wxToolBar* GetToolBar() const { return m_toolBar; }
193#endif
194
195#ifdef WINCE_WITH_COMMANDBAR
196 WXHWND GetCommandBar() const { return m_commandBar; }
197 bool AddAdornments(long style);
198#endif
199
200#if wxUSE_ACCEL
201 // get the accel table for all the menus
202 const wxAcceleratorTable& GetAccelTable() const { return m_accelTable; }
203
204 // update the accel table (must be called after adding/deletign a menu)
205 void RebuildAccelTable();
206#endif // wxUSE_ACCEL
207
208 // get the menu handle
209 WXHMENU GetHMenu() const { return m_hMenu; }
210
211 // if the menubar is modified, the display is not updated automatically,
212 // call this function to update it (m_menuBarFrame should be !NULL)
213 void Refresh();
214
215 // To avoid compile warning
216 void Refresh( bool eraseBackground,
217 const wxRect *rect = (const wxRect *) NULL ) { wxWindow::Refresh(eraseBackground, rect); }
218
219protected:
220 // common part of all ctors
221 void Init();
222
223 wxArrayString m_titles ;
224 wxMenuInfoList m_menuInfos;
225
226 WXHMENU m_hMenu;
227
228 // Return the MSW position for a wxMenu which is sometimes different from
229 // the wxWidgets position.
230 int MSWPositionForWxMenu(wxMenu *menu, int wxpos);
231#if wxUSE_ACCEL
232 // the accelerator table for all accelerators in all our menus
233 wxAcceleratorTable m_accelTable;
234#endif // wxUSE_ACCEL
235
236#if defined(__WXWINCE__) && wxUSE_TOOLBAR
237 wxToolBar* m_toolBar;
238#endif
239
240#ifdef WINCE_WITH_COMMANDBAR
241 WXHWND m_commandBar;
242 bool m_adornmentsAdded;
243#endif
244
245private:
246 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenuBar)
247};
248
249#endif // _WX_MENU_H_