]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/menu.h
added assert to check that notebook page does have notebook as parent; removed duplic...
[wxWidgets.git] / include / wx / msw / menu.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msw/menu.h
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$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_MENU_H_
13 #define _WX_MENU_H_
14
15 #ifdef __GNUG__
16 #pragma interface "menu.h"
17 #endif
18
19 #if wxUSE_ACCEL
20 #include "wx/accel.h"
21 #include "wx/dynarray.h"
22
23 WX_DEFINE_EXPORTED_ARRAY(wxAcceleratorEntry *, wxAcceleratorArray);
24 #endif // wxUSE_ACCEL
25
26 class WXDLLEXPORT wxFrame;
27
28 // ----------------------------------------------------------------------------
29 // Menu
30 // ----------------------------------------------------------------------------
31
32 class WXDLLEXPORT wxMenu : public wxMenuBase
33 {
34 public:
35 // ctors & dtor
36 wxMenu(const wxString& title, long style = 0)
37 : wxMenuBase(title, style) { Init(); }
38
39 wxMenu(long style = 0) : wxMenuBase(style) { Init(); }
40
41 virtual ~wxMenu();
42
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);
51
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
63 // implementation only from now on
64 // -------------------------------
65
66 virtual void Attach(wxMenuBarBase *menubar);
67
68 bool MSWCommand(WXUINT param, WXWORD id);
69
70 // semi-private accessors
71 // get the window which contains this menu
72 wxWindow *GetWindow() const;
73 // get the menu handle
74 WXHMENU GetHMenu() const { return m_hMenu; }
75
76 #if wxUSE_ACCEL
77 // called by wxMenuBar to build its accel table from the accels of all menus
78 bool HasAccels() const { return !m_accels.IsEmpty(); }
79 size_t GetAccelCount() const { return m_accels.GetCount(); }
80 size_t CopyAccels(wxAcceleratorEntry *accels) const;
81
82 // called by wxMenuItem when its accels changes
83 void UpdateAccel(wxMenuItem *item);
84
85 // helper used by wxMenu itself (returns the index in m_accels)
86 int FindAccel(int id) const;
87 #endif // wxUSE_ACCEL
88
89 private:
90 // common part of all ctors
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
96 // terminate the current radio group, if any
97 void EndRadioGroup();
98
99 // if TRUE, insert a breal before appending the next item
100 bool m_doBreak;
101
102 // the position of the first item in the current radio group or -1
103 int m_startRadioGroup;
104
105 // the menu handle of this menu
106 WXHMENU m_hMenu;
107
108 #if wxUSE_ACCEL
109 // the accelerators for our menu items
110 wxAcceleratorArray m_accels;
111 #endif // wxUSE_ACCEL
112
113 DECLARE_DYNAMIC_CLASS(wxMenu)
114 };
115
116 // ----------------------------------------------------------------------------
117 // Menu Bar (a la Windows)
118 // ----------------------------------------------------------------------------
119
120 class WXDLLEXPORT wxMenuBar : public wxMenuBarBase
121 {
122 public:
123 // ctors & dtor
124 // default constructor
125 wxMenuBar();
126 // unused under MSW
127 wxMenuBar(long style);
128 // menubar takes ownership of the menus arrays but copies the titles
129 wxMenuBar(int n, wxMenu *menus[], const wxString titles[]);
130 virtual ~wxMenuBar();
131
132 // menubar construction
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);
137
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;
141
142 // compatibility: these functions are deprecated
143 #if WXWIN_COMPATIBILITY
144 void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
145 wxEvtHandler *GetEventHandler() { return m_eventHandler; }
146
147 bool Enabled(int id) const { return IsEnabled(id); }
148 bool Checked(int id) const { return IsChecked(id); }
149 #endif // WXWIN_COMPATIBILITY
150
151 // implementation from now on
152 WXHMENU Create();
153 virtual void Detach();
154 virtual void Attach(wxFrame *frame);
155
156 #if wxUSE_ACCEL
157 // get the accel table for all the menus
158 const wxAcceleratorTable& GetAccelTable() const { return m_accelTable; }
159
160 // update the accel table (must be called after adding/deletign a menu)
161 void RebuildAccelTable();
162 #endif // wxUSE_ACCEL
163
164 // get the menu handle
165 WXHMENU GetHMenu() const { return m_hMenu; }
166
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
171 protected:
172 // common part of all ctors
173 void Init();
174
175 #if WXWIN_COMPATIBILITY
176 wxEvtHandler *m_eventHandler;
177 #endif // WXWIN_COMPATIBILITY
178
179 wxArrayString m_titles;
180
181 WXHMENU m_hMenu;
182
183 #if wxUSE_ACCEL
184 // the accelerator table for all accelerators in all our menus
185 wxAcceleratorTable m_accelTable;
186 #endif // wxUSE_ACCEL
187
188 private:
189 DECLARE_DYNAMIC_CLASS(wxMenuBar)
190 };
191
192 #endif // _WX_MENU_H_