]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/menu.h
replaced untyped hash with a typed one; 64 bit fixes (don't cast pointers to long...)
[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_NO_PTR(wxAcceleratorEntry *, wxAcceleratorArray);
24 #endif // wxUSE_ACCEL
25
26 class WXDLLEXPORT wxFrame;
27
28 #if defined(__WXWINCE__) && wxUSE_TOOLBAR
29 class WXDLLEXPORT wxToolBar;
30 #endif
31
32 // ----------------------------------------------------------------------------
33 // Menu
34 // ----------------------------------------------------------------------------
35
36 class WXDLLEXPORT wxMenu : public wxMenuBase
37 {
38 public:
39 // ctors & dtor
40 wxMenu(const wxString& title, long style = 0)
41 : wxMenuBase(title, style) { Init(); }
42
43 wxMenu(long style = 0) : wxMenuBase(style) { Init(); }
44
45 virtual ~wxMenu();
46
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);
55
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
67 // implementation only from now on
68 // -------------------------------
69
70 virtual void Attach(wxMenuBarBase *menubar);
71
72 bool MSWCommand(WXUINT param, WXWORD id);
73
74 // semi-private accessors
75 // get the window which contains this menu
76 wxWindow *GetWindow() const;
77 // get the menu handle
78 WXHMENU GetHMenu() const { return m_hMenu; }
79
80 #if wxUSE_ACCEL
81 // called by wxMenuBar to build its accel table from the accels of all menus
82 bool HasAccels() const { return !m_accels.IsEmpty(); }
83 size_t GetAccelCount() const { return m_accels.GetCount(); }
84 size_t CopyAccels(wxAcceleratorEntry *accels) const;
85
86 // called by wxMenuItem when its accels changes
87 void UpdateAccel(wxMenuItem *item);
88
89 // helper used by wxMenu itself (returns the index in m_accels)
90 int FindAccel(int id) const;
91 #endif // wxUSE_ACCEL
92
93 private:
94 // common part of all ctors
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
100 // terminate the current radio group, if any
101 void EndRadioGroup();
102
103 // if TRUE, insert a breal before appending the next item
104 bool m_doBreak;
105
106 // the position of the first item in the current radio group or -1
107 int m_startRadioGroup;
108
109 // the menu handle of this menu
110 WXHMENU m_hMenu;
111
112 #if wxUSE_ACCEL
113 // the accelerators for our menu items
114 wxAcceleratorArray m_accels;
115 #endif // wxUSE_ACCEL
116
117 DECLARE_DYNAMIC_CLASS(wxMenu)
118 };
119
120 // ----------------------------------------------------------------------------
121 // Menu Bar (a la Windows)
122 // ----------------------------------------------------------------------------
123
124 class WXDLLEXPORT wxMenuBar : public wxMenuBarBase
125 {
126 public:
127 // ctors & dtor
128 // default constructor
129 wxMenuBar();
130 // unused under MSW
131 wxMenuBar(long style);
132 // menubar takes ownership of the menus arrays but copies the titles
133 wxMenuBar(int n, wxMenu *menus[], const wxString titles[]);
134 virtual ~wxMenuBar();
135
136 // menubar construction
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);
141
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;
145
146 // compatibility: these functions are deprecated
147 #if WXWIN_COMPATIBILITY
148 void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
149 wxEvtHandler *GetEventHandler() { return m_eventHandler; }
150
151 bool Enabled(int id) const { return IsEnabled(id); }
152 bool Checked(int id) const { return IsChecked(id); }
153 #endif // WXWIN_COMPATIBILITY
154
155 // implementation from now on
156 WXHMENU Create();
157 virtual void Detach();
158 virtual void Attach(wxFrame *frame);
159
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
166 #if wxUSE_ACCEL
167 // get the accel table for all the menus
168 const wxAcceleratorTable& GetAccelTable() const { return m_accelTable; }
169
170 // update the accel table (must be called after adding/deletign a menu)
171 void RebuildAccelTable();
172 #endif // wxUSE_ACCEL
173
174 // get the menu handle
175 WXHMENU GetHMenu() const { return m_hMenu; }
176
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
181 // To avoid compile warning
182 void Refresh( bool eraseBackground,
183 const wxRect *rect = (const wxRect *) NULL ) { wxWindow::Refresh(eraseBackground, rect); }
184
185 protected:
186 // common part of all ctors
187 void Init();
188
189 #if WXWIN_COMPATIBILITY
190 wxEvtHandler *m_eventHandler;
191 #endif // WXWIN_COMPATIBILITY
192
193 wxArrayString m_titles;
194
195 WXHMENU m_hMenu;
196
197 #if wxUSE_ACCEL
198 // the accelerator table for all accelerators in all our menus
199 wxAcceleratorTable m_accelTable;
200 #endif // wxUSE_ACCEL
201
202 #if defined(__WXWINCE__) && wxUSE_TOOLBAR
203 wxToolBar* m_toolBar;
204 #endif
205
206 private:
207 DECLARE_DYNAMIC_CLASS(wxMenuBar)
208 };
209
210 #endif // _WX_MENU_H_