]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/menu.h
MinGW compilation fixes.
[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
717a57c2
VZ
52 // implementation only from now on
53 // -------------------------------
c626a8b7 54
0472ece7
VZ
55 virtual void Attach(wxMenuBarBase *menubar);
56
717a57c2 57 bool MSWCommand(WXUINT param, WXWORD id);
c626a8b7
VZ
58
59 // semi-private accessors
60 // get the window which contains this menu
61 wxWindow *GetWindow() const;
62 // get the menu handle
717a57c2 63 WXHMENU GetHMenu() const { return m_hMenu; }
2bda0e17 64
d427503c 65#if wxUSE_ACCEL
717a57c2
VZ
66 // called by wxMenuBar to build its accel table from the accels of all menus
67 bool HasAccels() const { return !m_accels.IsEmpty(); }
974e8d94 68 size_t GetAccelCount() const { return m_accels.GetCount(); }
42e69d6b
VZ
69 size_t CopyAccels(wxAcceleratorEntry *accels) const;
70
717a57c2
VZ
71 // called by wxMenuItem when its accels changes
72 void UpdateAccel(wxMenuItem *item);
42e69d6b 73
717a57c2
VZ
74 // helper used by wxMenu itself (returns the index in m_accels)
75 int FindAccel(int id) const;
76#endif // wxUSE_ACCEL
42e69d6b 77
2bda0e17 78private:
b908d224 79 // common part of all ctors
717a57c2
VZ
80 void Init();
81
82 // common part of Append/Insert (behaves as Append is pos == (size_t)-1)
83 bool DoInsertOrAppend(wxMenuItem *item, size_t pos = (size_t)-1);
84
0472ece7
VZ
85 // terminate the current radio group, if any
86 void EndRadioGroup();
87
717a57c2
VZ
88 // if TRUE, insert a breal before appending the next item
89 bool m_doBreak;
90
0472ece7
VZ
91 // the position of the first item in the current radio group or -1
92 int m_startRadioGroup;
93
717a57c2
VZ
94 // the menu handle of this menu
95 WXHMENU m_hMenu;
42e69d6b 96
d427503c 97#if wxUSE_ACCEL
974e8d94
VZ
98 // the accelerators for our menu items
99 wxAcceleratorArray m_accels;
d427503c 100#endif // wxUSE_ACCEL
717a57c2
VZ
101
102 DECLARE_DYNAMIC_CLASS(wxMenu)
2bda0e17
KB
103};
104
105// ----------------------------------------------------------------------------
106// Menu Bar (a la Windows)
107// ----------------------------------------------------------------------------
c626a8b7 108
a8cfd0cb 109class WXDLLEXPORT wxMenuBar : public wxMenuBarBase
2bda0e17 110{
c626a8b7
VZ
111public:
112 // ctors & dtor
c2dcfdef 113 // default constructor
c626a8b7 114 wxMenuBar();
c2dcfdef 115 // unused under MSW
c626a8b7 116 wxMenuBar(long style);
c2dcfdef 117 // menubar takes ownership of the menus arrays but copies the titles
c626a8b7
VZ
118 wxMenuBar(int n, wxMenu *menus[], const wxString titles[]);
119 virtual ~wxMenuBar();
120
121 // menubar construction
a8cfd0cb
VZ
122 virtual bool Append( wxMenu *menu, const wxString &title );
123 virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title);
124 virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
125 virtual wxMenu *Remove(size_t pos);
c626a8b7 126
a8cfd0cb
VZ
127 virtual void EnableTop( size_t pos, bool flag );
128 virtual void SetLabelTop( size_t pos, const wxString& label );
129 virtual wxString GetLabelTop( size_t pos ) const;
c626a8b7 130
a8cfd0cb 131 // compatibility: these functions are deprecated
600ea9da 132#if WXWIN_COMPATIBILITY
c626a8b7
VZ
133 void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
134 wxEvtHandler *GetEventHandler() { return m_eventHandler; }
135
c626a8b7
VZ
136 bool Enabled(int id) const { return IsEnabled(id); }
137 bool Checked(int id) const { return IsChecked(id); }
138#endif // WXWIN_COMPATIBILITY
2bda0e17 139
a8cfd0cb
VZ
140 // implementation from now on
141 WXHMENU Create();
1e6feb95
VZ
142 virtual void Detach();
143 virtual void Attach(wxFrame *frame);
c2dcfdef 144
d427503c 145#if wxUSE_ACCEL
717a57c2 146 // get the accel table for all the menus
42e69d6b 147 const wxAcceleratorTable& GetAccelTable() const { return m_accelTable; }
717a57c2
VZ
148
149 // update the accel table (must be called after adding/deletign a menu)
150 void RebuildAccelTable();
d427503c
VZ
151#endif // wxUSE_ACCEL
152
c2dcfdef
VZ
153 // get the menu handle
154 WXHMENU GetHMenu() const { return m_hMenu; }
155
c2dcfdef
VZ
156 // if the menubar is modified, the display is not updated automatically,
157 // call this function to update it (m_menuBarFrame should be !NULL)
158 void Refresh();
159
fbb90f7f
PA
160protected:
161 // common part of all ctors
162 void Init();
163
600ea9da 164#if WXWIN_COMPATIBILITY
c2dcfdef 165 wxEvtHandler *m_eventHandler;
a8cfd0cb
VZ
166#endif // WXWIN_COMPATIBILITY
167
168 wxArrayString m_titles;
169
c2dcfdef 170 WXHMENU m_hMenu;
42e69d6b 171
d427503c 172#if wxUSE_ACCEL
42e69d6b
VZ
173 // the accelerator table for all accelerators in all our menus
174 wxAcceleratorTable m_accelTable;
d427503c 175#endif // wxUSE_ACCEL
a8cfd0cb
VZ
176
177private:
178 DECLARE_DYNAMIC_CLASS(wxMenuBar)
2bda0e17
KB
179};
180
bbcdf8bc 181#endif // _WX_MENU_H_