]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/menu.h
work around (harmless) warnings in VC7 release build
[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
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
717a57c2
VZ
63 // implementation only from now on
64 // -------------------------------
c626a8b7 65
0472ece7
VZ
66 virtual void Attach(wxMenuBarBase *menubar);
67
717a57c2 68 bool MSWCommand(WXUINT param, WXWORD id);
c626a8b7
VZ
69
70 // semi-private accessors
71 // get the window which contains this menu
72 wxWindow *GetWindow() const;
73 // get the menu handle
717a57c2 74 WXHMENU GetHMenu() const { return m_hMenu; }
2bda0e17 75
d427503c 76#if wxUSE_ACCEL
717a57c2 77 // called by wxMenuBar to build its accel table from the accels of all menus
67fdb6f9
VZ
78 bool HasAccels() const { return !m_accels.empty(); }
79 size_t GetAccelCount() const { return m_accels.size(); }
42e69d6b
VZ
80 size_t CopyAccels(wxAcceleratorEntry *accels) const;
81
717a57c2
VZ
82 // called by wxMenuItem when its accels changes
83 void UpdateAccel(wxMenuItem *item);
42e69d6b 84
717a57c2
VZ
85 // helper used by wxMenu itself (returns the index in m_accels)
86 int FindAccel(int id) const;
67fdb6f9
VZ
87
88 // used only by wxMDIParentFrame currently but could be useful elsewhere:
89 // returns a new accelerator table with accelerators for just this menu
90 // (shouldn't be called if we don't have any accelerators)
91 wxAcceleratorTable *CreateAccelTable() const;
717a57c2 92#endif // wxUSE_ACCEL
42e69d6b 93
6f02a879
VZ
94protected:
95 virtual wxMenuItem* DoAppend(wxMenuItem *item);
96 virtual wxMenuItem* DoInsert(size_t pos, wxMenuItem *item);
97 virtual wxMenuItem* DoRemove(wxMenuItem *item);
98
2bda0e17 99private:
b908d224 100 // common part of all ctors
717a57c2
VZ
101 void Init();
102
103 // common part of Append/Insert (behaves as Append is pos == (size_t)-1)
104 bool DoInsertOrAppend(wxMenuItem *item, size_t pos = (size_t)-1);
105
0472ece7
VZ
106 // terminate the current radio group, if any
107 void EndRadioGroup();
108
598ddd96 109 // if true, insert a breal before appending the next item
717a57c2
VZ
110 bool m_doBreak;
111
0472ece7
VZ
112 // the position of the first item in the current radio group or -1
113 int m_startRadioGroup;
114
717a57c2
VZ
115 // the menu handle of this menu
116 WXHMENU m_hMenu;
42e69d6b 117
d427503c 118#if wxUSE_ACCEL
974e8d94
VZ
119 // the accelerators for our menu items
120 wxAcceleratorArray m_accels;
d427503c 121#endif // wxUSE_ACCEL
717a57c2 122
fc7a2a60 123 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenu)
2bda0e17
KB
124};
125
126// ----------------------------------------------------------------------------
127// Menu Bar (a la Windows)
128// ----------------------------------------------------------------------------
c626a8b7 129
53a2db12 130class WXDLLIMPEXP_CORE wxMenuInfo : public wxObject
6c7a1f82
SC
131{
132public :
3839f37e 133 wxMenuInfo() { m_menu = NULL; }
6c7a1f82
SC
134 virtual ~wxMenuInfo() { }
135
598ddd96 136 void Create( wxMenu *menu , const wxString &title )
3839f37e
VZ
137 { m_menu = menu; m_title = title; }
138 wxMenu* GetMenu() const { return m_menu; }
139 wxString GetTitle() const { return m_title; }
6c7a1f82 140private :
3839f37e
VZ
141 wxMenu *m_menu;
142 wxString m_title;
6c7a1f82 143
3839f37e
VZ
144 DECLARE_DYNAMIC_CLASS(wxMenuInfo)
145};
6c7a1f82
SC
146
147WX_DECLARE_EXPORTED_LIST(wxMenuInfo, wxMenuInfoList );
148
53a2db12 149class WXDLLIMPEXP_CORE wxMenuBar : public wxMenuBarBase
2bda0e17 150{
c626a8b7 151public:
598ddd96 152 // ctors & dtor
c2dcfdef 153 // default constructor
c626a8b7 154 wxMenuBar();
c2dcfdef 155 // unused under MSW
c626a8b7 156 wxMenuBar(long style);
c2dcfdef 157 // menubar takes ownership of the menus arrays but copies the titles
294ea16d 158 wxMenuBar(size_t n, wxMenu *menus[], const wxString titles[], long style = 0);
c626a8b7
VZ
159 virtual ~wxMenuBar();
160
161 // menubar construction
3839f37e
VZ
162 bool Append( wxMenuInfo *info ) { return Append( info->GetMenu() , info->GetTitle() ); }
163 const wxMenuInfoList& GetMenuInfos() const;
6c7a1f82 164
a8cfd0cb
VZ
165 virtual bool Append( wxMenu *menu, const wxString &title );
166 virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title);
167 virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
168 virtual wxMenu *Remove(size_t pos);
c626a8b7 169
a8cfd0cb 170 virtual void EnableTop( size_t pos, bool flag );
52af3158
JS
171 virtual void SetMenuLabel( size_t pos, const wxString& label );
172 virtual wxString GetMenuLabel( size_t pos ) const;
c626a8b7 173
a8cfd0cb
VZ
174 // implementation from now on
175 WXHMENU Create();
1e6feb95
VZ
176 virtual void Detach();
177 virtual void Attach(wxFrame *frame);
c2dcfdef 178
b3900fb5 179#if defined(__WXWINCE__) && wxUSE_TOOLBAR
39d2f9a7
JS
180 // Under WinCE, a menubar is owned by the frame's toolbar
181 void SetToolBar(wxToolBar* toolBar) { m_toolBar = toolBar; }
182 wxToolBar* GetToolBar() const { return m_toolBar; }
183#endif
184
b3900fb5 185#ifdef WINCE_WITH_COMMANDBAR
45f27284 186 WXHWND GetCommandBar() const { return m_commandBar; }
a9928e9d 187 bool AddAdornments(long style);
45f27284
JS
188#endif
189
d427503c 190#if wxUSE_ACCEL
3103e8a9 191 // update the accel table (must be called after adding/deleting a menu)
717a57c2 192 void RebuildAccelTable();
d427503c
VZ
193#endif // wxUSE_ACCEL
194
c2dcfdef
VZ
195 // get the menu handle
196 WXHMENU GetHMenu() const { return m_hMenu; }
197
c2dcfdef
VZ
198 // if the menubar is modified, the display is not updated automatically,
199 // call this function to update it (m_menuBarFrame should be !NULL)
200 void Refresh();
201
b85b77ae 202 // To avoid compile warning
39428534 203 void Refresh( bool eraseBackground,
b85b77ae
JS
204 const wxRect *rect = (const wxRect *) NULL ) { wxWindow::Refresh(eraseBackground, rect); }
205
fbb90f7f
PA
206protected:
207 // common part of all ctors
208 void Init();
209
3839f37e 210 wxArrayString m_titles;
6c7a1f82 211 wxMenuInfoList m_menuInfos;
a8cfd0cb 212
c2dcfdef 213 WXHMENU m_hMenu;
42e69d6b 214
b2c5f143 215 // Return the MSW position for a wxMenu which is sometimes different from
77ffb593 216 // the wxWidgets position.
b2c5f143 217 int MSWPositionForWxMenu(wxMenu *menu, int wxpos);
a8cfd0cb 218
39d2f9a7
JS
219#if defined(__WXWINCE__) && wxUSE_TOOLBAR
220 wxToolBar* m_toolBar;
221#endif
b3900fb5
RR
222
223#ifdef WINCE_WITH_COMMANDBAR
a96b4743 224 WXHWND m_commandBar;
a9928e9d 225 bool m_adornmentsAdded;
a96b4743 226#endif
39d2f9a7 227
a8cfd0cb 228private:
fc7a2a60 229 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenuBar)
2bda0e17
KB
230};
231
bbcdf8bc 232#endif // _WX_MENU_H_