]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/menu.h
remove SetBackgroundStyle call from OnInternalIdle, it should be done from realize...
[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
96049305
VZ
64 // MSW-only methods
65 // ----------------
66
67 // Create a new menu from the given native HMENU. Takes ownership of the
68 // menu handle and will delete it when this object is destroyed.
69 static wxMenu *MSWNewFromHMENU(WXHMENU hMenu) { return new wxMenu(hMenu); }
70
71
717a57c2
VZ
72 // implementation only from now on
73 // -------------------------------
c626a8b7 74
717a57c2 75 bool MSWCommand(WXUINT param, WXWORD id);
c626a8b7 76
7118e711 77 // get the native menu handle
717a57c2 78 WXHMENU GetHMenu() const { return m_hMenu; }
2bda0e17 79
89511b42
VZ
80 // Return the start and end position of the radio group to which the item
81 // at the given position belongs. Returns false if there is no radio group
82 // containing this position.
83 bool MSWGetRadioGroupRange(int pos, int *start, int *end) const;
84
d427503c 85#if wxUSE_ACCEL
717a57c2 86 // called by wxMenuBar to build its accel table from the accels of all menus
67fdb6f9
VZ
87 bool HasAccels() const { return !m_accels.empty(); }
88 size_t GetAccelCount() const { return m_accels.size(); }
42e69d6b
VZ
89 size_t CopyAccels(wxAcceleratorEntry *accels) const;
90
717a57c2
VZ
91 // called by wxMenuItem when its accels changes
92 void UpdateAccel(wxMenuItem *item);
42e69d6b 93
717a57c2
VZ
94 // helper used by wxMenu itself (returns the index in m_accels)
95 int FindAccel(int id) const;
67fdb6f9
VZ
96
97 // used only by wxMDIParentFrame currently but could be useful elsewhere:
98 // returns a new accelerator table with accelerators for just this menu
99 // (shouldn't be called if we don't have any accelerators)
100 wxAcceleratorTable *CreateAccelTable() const;
717a57c2 101#endif // wxUSE_ACCEL
42e69d6b 102
9c32ed26
VZ
103#if wxUSE_OWNER_DRAWN
104
105 int GetMaxAccelWidth()
106 {
107 if (m_maxAccelWidth == -1)
108 CalculateMaxAccelWidth();
109 return m_maxAccelWidth;
110 }
111
112 void ResetMaxAccelWidth()
113 {
114 m_maxAccelWidth = -1;
115 }
116
a99a3029
VZ
117 // get the menu with given handle (recursively)
118 wxMenu* MSWGetMenu(WXHMENU hMenu);
119
9c32ed26
VZ
120private:
121 void CalculateMaxAccelWidth();
122
123#endif // wxUSE_OWNER_DRAWN
124
6f02a879
VZ
125protected:
126 virtual wxMenuItem* DoAppend(wxMenuItem *item);
127 virtual wxMenuItem* DoInsert(size_t pos, wxMenuItem *item);
128 virtual wxMenuItem* DoRemove(wxMenuItem *item);
129
2bda0e17 130private:
96049305
VZ
131 // This constructor is private, use MSWNewFromHMENU() to use it.
132 wxMenu(WXHMENU hMenu);
133
134 // Common part of all ctors, it doesn't create a new HMENU.
135 void InitNoCreate();
136
137 // Common part of all ctors except of the one above taking a native menu
138 // handler: calls InitNoCreate() and also creates a new menu.
717a57c2
VZ
139 void Init();
140
141 // common part of Append/Insert (behaves as Append is pos == (size_t)-1)
142 bool DoInsertOrAppend(wxMenuItem *item, size_t pos = (size_t)-1);
143
89511b42
VZ
144
145 // This variable contains the description of the radio item groups and
146 // allows to find whether an item at the given position is part of the
147 // group and also where its group starts and ends.
148 //
149 // It is initially NULL and only allocated if we have any radio items.
150 wxMenuRadioItemsData *m_radioData;
0472ece7 151
598ddd96 152 // if true, insert a breal before appending the next item
717a57c2
VZ
153 bool m_doBreak;
154
155 // the menu handle of this menu
156 WXHMENU m_hMenu;
42e69d6b 157
d427503c 158#if wxUSE_ACCEL
974e8d94
VZ
159 // the accelerators for our menu items
160 wxAcceleratorArray m_accels;
d427503c 161#endif // wxUSE_ACCEL
717a57c2 162
d08504df
VZ
163#if wxUSE_OWNER_DRAWN
164 // true if the menu has any ownerdrawn items
165 bool m_ownerDrawn;
166
167 // the max width of menu items bitmaps
168 int m_maxBitmapWidth;
9c32ed26
VZ
169
170 // the max width of menu items accels
171 int m_maxAccelWidth;
d08504df
VZ
172#endif // wxUSE_OWNER_DRAWN
173
fc7a2a60 174 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenu)
2bda0e17
KB
175};
176
177// ----------------------------------------------------------------------------
178// Menu Bar (a la Windows)
179// ----------------------------------------------------------------------------
c626a8b7 180
53a2db12 181class WXDLLIMPEXP_CORE wxMenuBar : public wxMenuBarBase
2bda0e17 182{
c626a8b7 183public:
598ddd96 184 // ctors & dtor
c2dcfdef 185 // default constructor
c626a8b7 186 wxMenuBar();
c2dcfdef 187 // unused under MSW
c626a8b7 188 wxMenuBar(long style);
c2dcfdef 189 // menubar takes ownership of the menus arrays but copies the titles
294ea16d 190 wxMenuBar(size_t n, wxMenu *menus[], const wxString titles[], long style = 0);
c626a8b7
VZ
191 virtual ~wxMenuBar();
192
193 // menubar construction
a8cfd0cb
VZ
194 virtual bool Append( wxMenu *menu, const wxString &title );
195 virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title);
196 virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
197 virtual wxMenu *Remove(size_t pos);
c626a8b7 198
a8cfd0cb 199 virtual void EnableTop( size_t pos, bool flag );
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_