]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/menu.h
gave default parameters for wxPen() ctor from wxColour (this is what is used in 99...
[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
JS
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
bbcdf8bc
JS
12#ifndef _WX_MENU_H_
13#define _WX_MENU_H_
2bda0e17
KB
14
15#ifdef __GNUG__
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
6108e3fd 23 WX_DEFINE_EXPORTED_ARRAY_NO_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
2bda0e17
KB
32// ----------------------------------------------------------------------------
33// Menu
34// ----------------------------------------------------------------------------
c626a8b7 35
717a57c2 36class WXDLLEXPORT wxMenu : public wxMenuBase
2bda0e17 37{
2bda0e17 38public:
b908d224 39 // ctors & dtor
717a57c2
VZ
40 wxMenu(const wxString& title, long style = 0)
41 : wxMenuBase(title, style) { Init(); }
33961d59 42
717a57c2 43 wxMenu(long style = 0) : wxMenuBase(style) { Init(); }
b908d224 44
c626a8b7
VZ
45 virtual ~wxMenu();
46
717a57c2
VZ
47 // implement base class virtuals
48 virtual bool DoAppend(wxMenuItem *item);
49 virtual bool DoInsert(size_t pos, wxMenuItem *item);
50 virtual wxMenuItem *DoRemove(wxMenuItem *item);
51
52 virtual void Break();
53
54 virtual void SetTitle(const wxString& title);
c626a8b7 55
39428534
JS
56 // deprecated functions
57#if wxUSE_MENU_CALLBACK
58 wxMenu(const wxString& title, const wxFunction func)
59 : wxMenuBase(title)
60 {
61 Init();
62
63 Callback(func);
64 }
65#endif // wxUSE_MENU_CALLBACK
66
717a57c2
VZ
67 // implementation only from now on
68 // -------------------------------
c626a8b7 69
0472ece7
VZ
70 virtual void Attach(wxMenuBarBase *menubar);
71
717a57c2 72 bool MSWCommand(WXUINT param, WXWORD id);
c626a8b7
VZ
73
74 // semi-private accessors
75 // get the window which contains this menu
76 wxWindow *GetWindow() const;
77 // get the menu handle
717a57c2 78 WXHMENU GetHMenu() const { return m_hMenu; }
2bda0e17 79
d427503c 80#if wxUSE_ACCEL
717a57c2
VZ
81 // called by wxMenuBar to build its accel table from the accels of all menus
82 bool HasAccels() const { return !m_accels.IsEmpty(); }
974e8d94 83 size_t GetAccelCount() const { return m_accels.GetCount(); }
42e69d6b
VZ
84 size_t CopyAccels(wxAcceleratorEntry *accels) const;
85
717a57c2
VZ
86 // called by wxMenuItem when its accels changes
87 void UpdateAccel(wxMenuItem *item);
42e69d6b 88
717a57c2
VZ
89 // helper used by wxMenu itself (returns the index in m_accels)
90 int FindAccel(int id) const;
91#endif // wxUSE_ACCEL
42e69d6b 92
2bda0e17 93private:
b908d224 94 // common part of all ctors
717a57c2
VZ
95 void Init();
96
97 // common part of Append/Insert (behaves as Append is pos == (size_t)-1)
98 bool DoInsertOrAppend(wxMenuItem *item, size_t pos = (size_t)-1);
99
0472ece7
VZ
100 // terminate the current radio group, if any
101 void EndRadioGroup();
102
717a57c2
VZ
103 // if TRUE, insert a breal before appending the next item
104 bool m_doBreak;
105
0472ece7
VZ
106 // the position of the first item in the current radio group or -1
107 int m_startRadioGroup;
108
717a57c2
VZ
109 // the menu handle of this menu
110 WXHMENU m_hMenu;
42e69d6b 111
d427503c 112#if wxUSE_ACCEL
974e8d94
VZ
113 // the accelerators for our menu items
114 wxAcceleratorArray m_accels;
d427503c 115#endif // wxUSE_ACCEL
717a57c2
VZ
116
117 DECLARE_DYNAMIC_CLASS(wxMenu)
2bda0e17
KB
118};
119
120// ----------------------------------------------------------------------------
121// Menu Bar (a la Windows)
122// ----------------------------------------------------------------------------
c626a8b7 123
a8cfd0cb 124class WXDLLEXPORT wxMenuBar : public wxMenuBarBase
2bda0e17 125{
c626a8b7
VZ
126public:
127 // ctors & dtor
c2dcfdef 128 // default constructor
c626a8b7 129 wxMenuBar();
c2dcfdef 130 // unused under MSW
c626a8b7 131 wxMenuBar(long style);
c2dcfdef 132 // menubar takes ownership of the menus arrays but copies the titles
c626a8b7
VZ
133 wxMenuBar(int n, wxMenu *menus[], const wxString titles[]);
134 virtual ~wxMenuBar();
135
136 // menubar construction
a8cfd0cb
VZ
137 virtual bool Append( wxMenu *menu, const wxString &title );
138 virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title);
139 virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
140 virtual wxMenu *Remove(size_t pos);
c626a8b7 141
a8cfd0cb
VZ
142 virtual void EnableTop( size_t pos, bool flag );
143 virtual void SetLabelTop( size_t pos, const wxString& label );
144 virtual wxString GetLabelTop( size_t pos ) const;
c626a8b7 145
a8cfd0cb 146 // compatibility: these functions are deprecated
600ea9da 147#if WXWIN_COMPATIBILITY
c626a8b7
VZ
148 void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
149 wxEvtHandler *GetEventHandler() { return m_eventHandler; }
150
c626a8b7
VZ
151 bool Enabled(int id) const { return IsEnabled(id); }
152 bool Checked(int id) const { return IsChecked(id); }
153#endif // WXWIN_COMPATIBILITY
2bda0e17 154
a8cfd0cb
VZ
155 // implementation from now on
156 WXHMENU Create();
1e6feb95
VZ
157 virtual void Detach();
158 virtual void Attach(wxFrame *frame);
c2dcfdef 159
39d2f9a7
JS
160#if defined(__WXWINCE__) && wxUSE_TOOLBAR
161 // Under WinCE, a menubar is owned by the frame's toolbar
162 void SetToolBar(wxToolBar* toolBar) { m_toolBar = toolBar; }
163 wxToolBar* GetToolBar() const { return m_toolBar; }
164#endif
165
d427503c 166#if wxUSE_ACCEL
717a57c2 167 // get the accel table for all the menus
42e69d6b 168 const wxAcceleratorTable& GetAccelTable() const { return m_accelTable; }
717a57c2
VZ
169
170 // update the accel table (must be called after adding/deletign a menu)
171 void RebuildAccelTable();
d427503c
VZ
172#endif // wxUSE_ACCEL
173
c2dcfdef
VZ
174 // get the menu handle
175 WXHMENU GetHMenu() const { return m_hMenu; }
176
c2dcfdef
VZ
177 // if the menubar is modified, the display is not updated automatically,
178 // call this function to update it (m_menuBarFrame should be !NULL)
179 void Refresh();
180
b85b77ae 181 // To avoid compile warning
39428534 182 void Refresh( bool eraseBackground,
b85b77ae
JS
183 const wxRect *rect = (const wxRect *) NULL ) { wxWindow::Refresh(eraseBackground, rect); }
184
fbb90f7f
PA
185protected:
186 // common part of all ctors
187 void Init();
188
600ea9da 189#if WXWIN_COMPATIBILITY
c2dcfdef 190 wxEvtHandler *m_eventHandler;
a8cfd0cb
VZ
191#endif // WXWIN_COMPATIBILITY
192
193 wxArrayString m_titles;
194
c2dcfdef 195 WXHMENU m_hMenu;
42e69d6b 196
d427503c 197#if wxUSE_ACCEL
42e69d6b
VZ
198 // the accelerator table for all accelerators in all our menus
199 wxAcceleratorTable m_accelTable;
d427503c 200#endif // wxUSE_ACCEL
a8cfd0cb 201
39d2f9a7
JS
202#if defined(__WXWINCE__) && wxUSE_TOOLBAR
203 wxToolBar* m_toolBar;
204#endif
205
a8cfd0cb
VZ
206private:
207 DECLARE_DYNAMIC_CLASS(wxMenuBar)
2bda0e17
KB
208};
209
bbcdf8bc 210#endif // _WX_MENU_H_