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