]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/menu.h
Fix for MinGW macros not available due to include order (http://www.solidsteel.nl...
[wxWidgets.git] / include / wx / msw / menu.h
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
0472ece7 2// Name: wx/msw/menu.h
2bda0e17
KB
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$
371a5b4e 8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
bbcdf8bc
JS
12#ifndef _WX_MENU_H_
13#define _WX_MENU_H_
2bda0e17 14
12028905 15#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
c626a8b7 16 #pragma interface "menu.h"
2bda0e17
KB
17#endif
18
3f3cec48 19#if wxUSE_ACCEL
974e8d94 20 #include "wx/accel.h"
717a57c2
VZ
21 #include "wx/dynarray.h"
22
d5d29b8a 23 WX_DEFINE_EXPORTED_ARRAY_PTR(wxAcceleratorEntry *, wxAcceleratorArray);
3f3cec48 24#endif // wxUSE_ACCEL
2bda0e17 25
c626a8b7 26class WXDLLEXPORT wxFrame;
2bda0e17 27
39d2f9a7
JS
28#if defined(__WXWINCE__) && wxUSE_TOOLBAR
29class WXDLLEXPORT wxToolBar;
30#endif
31
b3900fb5
RR
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
a381fd1c
MB
46#include "wx/arrstr.h"
47
2bda0e17
KB
48// ----------------------------------------------------------------------------
49// Menu
50// ----------------------------------------------------------------------------
c626a8b7 51
717a57c2 52class WXDLLEXPORT wxMenu : public wxMenuBase
2bda0e17 53{
2bda0e17 54public:
b908d224 55 // ctors & dtor
717a57c2
VZ
56 wxMenu(const wxString& title, long style = 0)
57 : wxMenuBase(title, style) { Init(); }
33961d59 58
717a57c2 59 wxMenu(long style = 0) : wxMenuBase(style) { Init(); }
b908d224 60
c626a8b7
VZ
61 virtual ~wxMenu();
62
717a57c2 63 // implement base class virtuals
9add9367
RD
64 virtual wxMenuItem* DoAppend(wxMenuItem *item);
65 virtual wxMenuItem* DoInsert(size_t pos, wxMenuItem *item);
66 virtual wxMenuItem* DoRemove(wxMenuItem *item);
717a57c2
VZ
67
68 virtual void Break();
69
70 virtual void SetTitle(const wxString& title);
c626a8b7 71
39428534
JS
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
717a57c2
VZ
83 // implementation only from now on
84 // -------------------------------
c626a8b7 85
0472ece7
VZ
86 virtual void Attach(wxMenuBarBase *menubar);
87
717a57c2 88 bool MSWCommand(WXUINT param, WXWORD id);
c626a8b7
VZ
89
90 // semi-private accessors
91 // get the window which contains this menu
92 wxWindow *GetWindow() const;
93 // get the menu handle
717a57c2 94 WXHMENU GetHMenu() const { return m_hMenu; }
2bda0e17 95
d427503c 96#if wxUSE_ACCEL
717a57c2
VZ
97 // called by wxMenuBar to build its accel table from the accels of all menus
98 bool HasAccels() const { return !m_accels.IsEmpty(); }
974e8d94 99 size_t GetAccelCount() const { return m_accels.GetCount(); }
42e69d6b
VZ
100 size_t CopyAccels(wxAcceleratorEntry *accels) const;
101
717a57c2
VZ
102 // called by wxMenuItem when its accels changes
103 void UpdateAccel(wxMenuItem *item);
42e69d6b 104
717a57c2
VZ
105 // helper used by wxMenu itself (returns the index in m_accels)
106 int FindAccel(int id) const;
107#endif // wxUSE_ACCEL
42e69d6b 108
2bda0e17 109private:
b908d224 110 // common part of all ctors
717a57c2
VZ
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
0472ece7
VZ
116 // terminate the current radio group, if any
117 void EndRadioGroup();
118
598ddd96 119 // if true, insert a breal before appending the next item
717a57c2
VZ
120 bool m_doBreak;
121
0472ece7
VZ
122 // the position of the first item in the current radio group or -1
123 int m_startRadioGroup;
124
717a57c2
VZ
125 // the menu handle of this menu
126 WXHMENU m_hMenu;
42e69d6b 127
d427503c 128#if wxUSE_ACCEL
974e8d94
VZ
129 // the accelerators for our menu items
130 wxAcceleratorArray m_accels;
d427503c 131#endif // wxUSE_ACCEL
717a57c2 132
fc7a2a60 133 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenu)
2bda0e17
KB
134};
135
136// ----------------------------------------------------------------------------
137// Menu Bar (a la Windows)
138// ----------------------------------------------------------------------------
c626a8b7 139
6c7a1f82
SC
140class WXDLLEXPORT wxMenuInfo : public wxObject
141{
142public :
3839f37e 143 wxMenuInfo() { m_menu = NULL; }
6c7a1f82
SC
144 virtual ~wxMenuInfo() { }
145
598ddd96 146 void Create( wxMenu *menu , const wxString &title )
3839f37e
VZ
147 { m_menu = menu; m_title = title; }
148 wxMenu* GetMenu() const { return m_menu; }
149 wxString GetTitle() const { return m_title; }
6c7a1f82 150private :
3839f37e
VZ
151 wxMenu *m_menu;
152 wxString m_title;
6c7a1f82 153
3839f37e
VZ
154 DECLARE_DYNAMIC_CLASS(wxMenuInfo)
155};
6c7a1f82
SC
156
157WX_DECLARE_EXPORTED_LIST(wxMenuInfo, wxMenuInfoList );
158
a8cfd0cb 159class WXDLLEXPORT wxMenuBar : public wxMenuBarBase
2bda0e17 160{
c626a8b7 161public:
598ddd96 162 // ctors & dtor
c2dcfdef 163 // default constructor
c626a8b7 164 wxMenuBar();
c2dcfdef 165 // unused under MSW
c626a8b7 166 wxMenuBar(long style);
c2dcfdef 167 // menubar takes ownership of the menus arrays but copies the titles
294ea16d 168 wxMenuBar(size_t n, wxMenu *menus[], const wxString titles[], long style = 0);
c626a8b7
VZ
169 virtual ~wxMenuBar();
170
171 // menubar construction
3839f37e
VZ
172 bool Append( wxMenuInfo *info ) { return Append( info->GetMenu() , info->GetTitle() ); }
173 const wxMenuInfoList& GetMenuInfos() const;
6c7a1f82 174
a8cfd0cb
VZ
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);
c626a8b7 179
a8cfd0cb
VZ
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;
c626a8b7 183
a8cfd0cb
VZ
184 // implementation from now on
185 WXHMENU Create();
1e6feb95
VZ
186 virtual void Detach();
187 virtual void Attach(wxFrame *frame);
c2dcfdef 188
b3900fb5 189#if defined(__WXWINCE__) && wxUSE_TOOLBAR
39d2f9a7
JS
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
b3900fb5 195#ifdef WINCE_WITH_COMMANDBAR
45f27284 196 WXHWND GetCommandBar() const { return m_commandBar; }
a9928e9d 197 bool AddAdornments(long style);
45f27284
JS
198#endif
199
d427503c 200#if wxUSE_ACCEL
717a57c2 201 // get the accel table for all the menus
42e69d6b 202 const wxAcceleratorTable& GetAccelTable() const { return m_accelTable; }
717a57c2
VZ
203
204 // update the accel table (must be called after adding/deletign a menu)
205 void RebuildAccelTable();
d427503c
VZ
206#endif // wxUSE_ACCEL
207
c2dcfdef
VZ
208 // get the menu handle
209 WXHMENU GetHMenu() const { return m_hMenu; }
210
c2dcfdef
VZ
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
b85b77ae 215 // To avoid compile warning
39428534 216 void Refresh( bool eraseBackground,
b85b77ae
JS
217 const wxRect *rect = (const wxRect *) NULL ) { wxWindow::Refresh(eraseBackground, rect); }
218
fbb90f7f
PA
219protected:
220 // common part of all ctors
221 void Init();
222
3839f37e 223 wxArrayString m_titles;
6c7a1f82 224 wxMenuInfoList m_menuInfos;
a8cfd0cb 225
c2dcfdef 226 WXHMENU m_hMenu;
42e69d6b 227
b2c5f143 228 // Return the MSW position for a wxMenu which is sometimes different from
77ffb593 229 // the wxWidgets position.
b2c5f143 230 int MSWPositionForWxMenu(wxMenu *menu, int wxpos);
d427503c 231#if wxUSE_ACCEL
42e69d6b
VZ
232 // the accelerator table for all accelerators in all our menus
233 wxAcceleratorTable m_accelTable;
d427503c 234#endif // wxUSE_ACCEL
a8cfd0cb 235
39d2f9a7
JS
236#if defined(__WXWINCE__) && wxUSE_TOOLBAR
237 wxToolBar* m_toolBar;
238#endif
b3900fb5
RR
239
240#ifdef WINCE_WITH_COMMANDBAR
a96b4743 241 WXHWND m_commandBar;
a9928e9d 242 bool m_adornmentsAdded;
a96b4743 243#endif
39d2f9a7 244
a8cfd0cb 245private:
fc7a2a60 246 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenuBar)
2bda0e17
KB
247};
248
bbcdf8bc 249#endif // _WX_MENU_H_