]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/menu.h
Replace wxControlContainer-related macros with wxNavigationEnabled<>.
[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
3f3cec48 15#if wxUSE_ACCEL
974e8d94 16 #include "wx/accel.h"
717a57c2
VZ
17 #include "wx/dynarray.h"
18
d5d29b8a 19 WX_DEFINE_EXPORTED_ARRAY_PTR(wxAcceleratorEntry *, wxAcceleratorArray);
3f3cec48 20#endif // wxUSE_ACCEL
2bda0e17 21
b5dbe15d 22class WXDLLIMPEXP_FWD_CORE wxFrame;
2bda0e17 23
39d2f9a7 24#if defined(__WXWINCE__) && wxUSE_TOOLBAR
b5dbe15d 25class WXDLLIMPEXP_FWD_CORE wxToolBar;
39d2f9a7
JS
26#endif
27
89511b42 28class wxMenuRadioItemsData;
b3900fb5
RR
29
30// Not using a combined wxToolBar/wxMenuBar? then use
31// a commandbar in WinCE .NET to implement the
32// menubar, since there is no ::SetMenu function.
33#if defined(__WXWINCE__)
34# if ((_WIN32_WCE >= 400) && !defined(__POCKETPC__) && !defined(__SMARTPHONE__)) || \
35 defined(__HANDHELDPC__)
36# define WINCE_WITH_COMMANDBAR
37# else
38# define WINCE_WITHOUT_COMMANDBAR
39# endif
40#endif
41
42
a381fd1c
MB
43#include "wx/arrstr.h"
44
2bda0e17
KB
45// ----------------------------------------------------------------------------
46// Menu
47// ----------------------------------------------------------------------------
c626a8b7 48
53a2db12 49class WXDLLIMPEXP_CORE wxMenu : public wxMenuBase
2bda0e17 50{
2bda0e17 51public:
b908d224 52 // ctors & dtor
717a57c2
VZ
53 wxMenu(const wxString& title, long style = 0)
54 : wxMenuBase(title, style) { Init(); }
33961d59 55
717a57c2 56 wxMenu(long style = 0) : wxMenuBase(style) { Init(); }
b908d224 57
c626a8b7
VZ
58 virtual ~wxMenu();
59
717a57c2
VZ
60 virtual void Break();
61
62 virtual void SetTitle(const wxString& title);
c626a8b7 63
717a57c2
VZ
64 // implementation only from now on
65 // -------------------------------
c626a8b7 66
717a57c2 67 bool MSWCommand(WXUINT param, WXWORD id);
c626a8b7 68
7118e711 69 // get the native menu handle
717a57c2 70 WXHMENU GetHMenu() const { return m_hMenu; }
2bda0e17 71
89511b42
VZ
72 // Return the start and end position of the radio group to which the item
73 // at the given position belongs. Returns false if there is no radio group
74 // containing this position.
75 bool MSWGetRadioGroupRange(int pos, int *start, int *end) const;
76
d427503c 77#if wxUSE_ACCEL
717a57c2 78 // called by wxMenuBar to build its accel table from the accels of all menus
67fdb6f9
VZ
79 bool HasAccels() const { return !m_accels.empty(); }
80 size_t GetAccelCount() const { return m_accels.size(); }
42e69d6b
VZ
81 size_t CopyAccels(wxAcceleratorEntry *accels) const;
82
717a57c2
VZ
83 // called by wxMenuItem when its accels changes
84 void UpdateAccel(wxMenuItem *item);
42e69d6b 85
717a57c2
VZ
86 // helper used by wxMenu itself (returns the index in m_accels)
87 int FindAccel(int id) const;
67fdb6f9
VZ
88
89 // used only by wxMDIParentFrame currently but could be useful elsewhere:
90 // returns a new accelerator table with accelerators for just this menu
91 // (shouldn't be called if we don't have any accelerators)
92 wxAcceleratorTable *CreateAccelTable() const;
717a57c2 93#endif // wxUSE_ACCEL
42e69d6b 94
9c32ed26
VZ
95#if wxUSE_OWNER_DRAWN
96
97 int GetMaxAccelWidth()
98 {
99 if (m_maxAccelWidth == -1)
100 CalculateMaxAccelWidth();
101 return m_maxAccelWidth;
102 }
103
104 void ResetMaxAccelWidth()
105 {
106 m_maxAccelWidth = -1;
107 }
108
a99a3029
VZ
109 // get the menu with given handle (recursively)
110 wxMenu* MSWGetMenu(WXHMENU hMenu);
111
9c32ed26
VZ
112private:
113 void CalculateMaxAccelWidth();
114
115#endif // wxUSE_OWNER_DRAWN
116
6f02a879
VZ
117protected:
118 virtual wxMenuItem* DoAppend(wxMenuItem *item);
119 virtual wxMenuItem* DoInsert(size_t pos, wxMenuItem *item);
120 virtual wxMenuItem* DoRemove(wxMenuItem *item);
121
2bda0e17 122private:
b908d224 123 // common part of all ctors
717a57c2
VZ
124 void Init();
125
126 // common part of Append/Insert (behaves as Append is pos == (size_t)-1)
127 bool DoInsertOrAppend(wxMenuItem *item, size_t pos = (size_t)-1);
128
89511b42
VZ
129
130 // This variable contains the description of the radio item groups and
131 // allows to find whether an item at the given position is part of the
132 // group and also where its group starts and ends.
133 //
134 // It is initially NULL and only allocated if we have any radio items.
135 wxMenuRadioItemsData *m_radioData;
0472ece7 136
598ddd96 137 // if true, insert a breal before appending the next item
717a57c2
VZ
138 bool m_doBreak;
139
140 // the menu handle of this menu
141 WXHMENU m_hMenu;
42e69d6b 142
d427503c 143#if wxUSE_ACCEL
974e8d94
VZ
144 // the accelerators for our menu items
145 wxAcceleratorArray m_accels;
d427503c 146#endif // wxUSE_ACCEL
717a57c2 147
d08504df
VZ
148#if wxUSE_OWNER_DRAWN
149 // true if the menu has any ownerdrawn items
150 bool m_ownerDrawn;
151
152 // the max width of menu items bitmaps
153 int m_maxBitmapWidth;
9c32ed26
VZ
154
155 // the max width of menu items accels
156 int m_maxAccelWidth;
d08504df
VZ
157#endif // wxUSE_OWNER_DRAWN
158
fc7a2a60 159 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenu)
2bda0e17
KB
160};
161
162// ----------------------------------------------------------------------------
163// Menu Bar (a la Windows)
164// ----------------------------------------------------------------------------
c626a8b7 165
53a2db12 166class WXDLLIMPEXP_CORE wxMenuBar : public wxMenuBarBase
2bda0e17 167{
c626a8b7 168public:
598ddd96 169 // ctors & dtor
c2dcfdef 170 // default constructor
c626a8b7 171 wxMenuBar();
c2dcfdef 172 // unused under MSW
c626a8b7 173 wxMenuBar(long style);
c2dcfdef 174 // menubar takes ownership of the menus arrays but copies the titles
294ea16d 175 wxMenuBar(size_t n, wxMenu *menus[], const wxString titles[], long style = 0);
c626a8b7
VZ
176 virtual ~wxMenuBar();
177
178 // menubar construction
a8cfd0cb
VZ
179 virtual bool Append( wxMenu *menu, const wxString &title );
180 virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title);
181 virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
182 virtual wxMenu *Remove(size_t pos);
c626a8b7 183
a8cfd0cb 184 virtual void EnableTop( size_t pos, bool flag );
52af3158
JS
185 virtual void SetMenuLabel( size_t pos, const wxString& label );
186 virtual wxString GetMenuLabel( size_t pos ) const;
c626a8b7 187
a8cfd0cb
VZ
188 // implementation from now on
189 WXHMENU Create();
1e6feb95
VZ
190 virtual void Detach();
191 virtual void Attach(wxFrame *frame);
c2dcfdef 192
b3900fb5 193#if defined(__WXWINCE__) && wxUSE_TOOLBAR
39d2f9a7
JS
194 // Under WinCE, a menubar is owned by the frame's toolbar
195 void SetToolBar(wxToolBar* toolBar) { m_toolBar = toolBar; }
196 wxToolBar* GetToolBar() const { return m_toolBar; }
197#endif
198
b3900fb5 199#ifdef WINCE_WITH_COMMANDBAR
45f27284 200 WXHWND GetCommandBar() const { return m_commandBar; }
a9928e9d 201 bool AddAdornments(long style);
45f27284
JS
202#endif
203
d427503c 204#if wxUSE_ACCEL
3103e8a9 205 // update the accel table (must be called after adding/deleting a menu)
717a57c2 206 void RebuildAccelTable();
d427503c
VZ
207#endif // wxUSE_ACCEL
208
c2dcfdef
VZ
209 // get the menu handle
210 WXHMENU GetHMenu() const { return m_hMenu; }
211
c2dcfdef
VZ
212 // if the menubar is modified, the display is not updated automatically,
213 // call this function to update it (m_menuBarFrame should be !NULL)
214 void Refresh();
215
b85b77ae 216 // To avoid compile warning
39428534 217 void Refresh( bool eraseBackground,
b85b77ae
JS
218 const wxRect *rect = (const wxRect *) NULL ) { wxWindow::Refresh(eraseBackground, rect); }
219
a99a3029
VZ
220 // get the menu with given handle (recursively)
221 wxMenu* MSWGetMenu(WXHMENU hMenu);
222
fbb90f7f
PA
223protected:
224 // common part of all ctors
225 void Init();
226
c2dcfdef 227 WXHMENU m_hMenu;
42e69d6b 228
b2c5f143 229 // Return the MSW position for a wxMenu which is sometimes different from
77ffb593 230 // the wxWidgets position.
b2c5f143 231 int MSWPositionForWxMenu(wxMenu *menu, int wxpos);
a8cfd0cb 232
39d2f9a7
JS
233#if defined(__WXWINCE__) && wxUSE_TOOLBAR
234 wxToolBar* m_toolBar;
235#endif
b3900fb5
RR
236
237#ifdef WINCE_WITH_COMMANDBAR
a96b4743 238 WXHWND m_commandBar;
a9928e9d 239 bool m_adornmentsAdded;
a96b4743 240#endif
39d2f9a7 241
a8cfd0cb 242private:
fc7a2a60 243 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenuBar)
2bda0e17
KB
244};
245
bbcdf8bc 246#endif // _WX_MENU_H_