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