]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/menu.h
split win32 makefiles into shared config files and the rest
[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
23 WX_DEFINE_EXPORTED_ARRAY(wxAcceleratorEntry *, wxAcceleratorArray);
3f3cec48 24#endif // wxUSE_ACCEL
2bda0e17 25
c626a8b7 26class WXDLLEXPORT wxFrame;
2bda0e17 27
2bda0e17
KB
28// ----------------------------------------------------------------------------
29// Menu
30// ----------------------------------------------------------------------------
c626a8b7 31
717a57c2 32class WXDLLEXPORT wxMenu : public wxMenuBase
2bda0e17 33{
2bda0e17 34public:
b908d224 35 // ctors & dtor
717a57c2
VZ
36 wxMenu(const wxString& title, long style = 0)
37 : wxMenuBase(title, style) { Init(); }
33961d59 38
717a57c2 39 wxMenu(long style = 0) : wxMenuBase(style) { Init(); }
b908d224 40
c626a8b7
VZ
41 virtual ~wxMenu();
42
717a57c2
VZ
43 // implement base class virtuals
44 virtual bool DoAppend(wxMenuItem *item);
45 virtual bool DoInsert(size_t pos, wxMenuItem *item);
46 virtual wxMenuItem *DoRemove(wxMenuItem *item);
47
48 virtual void Break();
49
50 virtual void SetTitle(const wxString& title);
c626a8b7 51
39428534
JS
52 // deprecated functions
53#if wxUSE_MENU_CALLBACK
54 wxMenu(const wxString& title, const wxFunction func)
55 : wxMenuBase(title)
56 {
57 Init();
58
59 Callback(func);
60 }
61#endif // wxUSE_MENU_CALLBACK
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
VZ
77 // called by wxMenuBar to build its accel table from the accels of all menus
78 bool HasAccels() const { return !m_accels.IsEmpty(); }
974e8d94 79 size_t GetAccelCount() const { return m_accels.GetCount(); }
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;
87#endif // wxUSE_ACCEL
42e69d6b 88
2bda0e17 89private:
b908d224 90 // common part of all ctors
717a57c2
VZ
91 void Init();
92
93 // common part of Append/Insert (behaves as Append is pos == (size_t)-1)
94 bool DoInsertOrAppend(wxMenuItem *item, size_t pos = (size_t)-1);
95
0472ece7
VZ
96 // terminate the current radio group, if any
97 void EndRadioGroup();
98
717a57c2
VZ
99 // if TRUE, insert a breal before appending the next item
100 bool m_doBreak;
101
0472ece7
VZ
102 // the position of the first item in the current radio group or -1
103 int m_startRadioGroup;
104
717a57c2
VZ
105 // the menu handle of this menu
106 WXHMENU m_hMenu;
42e69d6b 107
d427503c 108#if wxUSE_ACCEL
974e8d94
VZ
109 // the accelerators for our menu items
110 wxAcceleratorArray m_accels;
d427503c 111#endif // wxUSE_ACCEL
717a57c2
VZ
112
113 DECLARE_DYNAMIC_CLASS(wxMenu)
2bda0e17
KB
114};
115
116// ----------------------------------------------------------------------------
117// Menu Bar (a la Windows)
118// ----------------------------------------------------------------------------
c626a8b7 119
a8cfd0cb 120class WXDLLEXPORT wxMenuBar : public wxMenuBarBase
2bda0e17 121{
c626a8b7
VZ
122public:
123 // ctors & dtor
c2dcfdef 124 // default constructor
c626a8b7 125 wxMenuBar();
c2dcfdef 126 // unused under MSW
c626a8b7 127 wxMenuBar(long style);
c2dcfdef 128 // menubar takes ownership of the menus arrays but copies the titles
c626a8b7
VZ
129 wxMenuBar(int n, wxMenu *menus[], const wxString titles[]);
130 virtual ~wxMenuBar();
131
132 // menubar construction
a8cfd0cb
VZ
133 virtual bool Append( wxMenu *menu, const wxString &title );
134 virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title);
135 virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
136 virtual wxMenu *Remove(size_t pos);
c626a8b7 137
a8cfd0cb
VZ
138 virtual void EnableTop( size_t pos, bool flag );
139 virtual void SetLabelTop( size_t pos, const wxString& label );
140 virtual wxString GetLabelTop( size_t pos ) const;
c626a8b7 141
a8cfd0cb 142 // compatibility: these functions are deprecated
600ea9da 143#if WXWIN_COMPATIBILITY
c626a8b7
VZ
144 void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
145 wxEvtHandler *GetEventHandler() { return m_eventHandler; }
146
c626a8b7
VZ
147 bool Enabled(int id) const { return IsEnabled(id); }
148 bool Checked(int id) const { return IsChecked(id); }
149#endif // WXWIN_COMPATIBILITY
2bda0e17 150
a8cfd0cb
VZ
151 // implementation from now on
152 WXHMENU Create();
1e6feb95
VZ
153 virtual void Detach();
154 virtual void Attach(wxFrame *frame);
c2dcfdef 155
d427503c 156#if wxUSE_ACCEL
717a57c2 157 // get the accel table for all the menus
42e69d6b 158 const wxAcceleratorTable& GetAccelTable() const { return m_accelTable; }
717a57c2
VZ
159
160 // update the accel table (must be called after adding/deletign a menu)
161 void RebuildAccelTable();
d427503c
VZ
162#endif // wxUSE_ACCEL
163
c2dcfdef
VZ
164 // get the menu handle
165 WXHMENU GetHMenu() const { return m_hMenu; }
166
c2dcfdef
VZ
167 // if the menubar is modified, the display is not updated automatically,
168 // call this function to update it (m_menuBarFrame should be !NULL)
169 void Refresh();
170
b85b77ae 171 // To avoid compile warning
39428534 172 void Refresh( bool eraseBackground,
b85b77ae
JS
173 const wxRect *rect = (const wxRect *) NULL ) { wxWindow::Refresh(eraseBackground, rect); }
174
fbb90f7f
PA
175protected:
176 // common part of all ctors
177 void Init();
178
600ea9da 179#if WXWIN_COMPATIBILITY
c2dcfdef 180 wxEvtHandler *m_eventHandler;
a8cfd0cb
VZ
181#endif // WXWIN_COMPATIBILITY
182
183 wxArrayString m_titles;
184
c2dcfdef 185 WXHMENU m_hMenu;
42e69d6b 186
d427503c 187#if wxUSE_ACCEL
42e69d6b
VZ
188 // the accelerator table for all accelerators in all our menus
189 wxAcceleratorTable m_accelTable;
d427503c 190#endif // wxUSE_ACCEL
a8cfd0cb
VZ
191
192private:
193 DECLARE_DYNAMIC_CLASS(wxMenuBar)
2bda0e17
KB
194};
195
bbcdf8bc 196#endif // _WX_MENU_H_