]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/menu.h
Don't duplicate INVALID_FILE_ATTRIBUTES definition.
[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 #if wxUSE_ACCEL
16 #include "wx/accel.h"
17 #include "wx/dynarray.h"
18
19 WX_DEFINE_EXPORTED_ARRAY_PTR(wxAcceleratorEntry *, wxAcceleratorArray);
20 #endif // wxUSE_ACCEL
21
22 class WXDLLIMPEXP_FWD_CORE wxFrame;
23
24 #if defined(__WXWINCE__) && wxUSE_TOOLBAR
25 class WXDLLIMPEXP_FWD_CORE wxToolBar;
26 #endif
27
28
29 // Not using a combined wxToolBar/wxMenuBar? then use
30 // a commandbar in WinCE .NET to implement the
31 // menubar, since there is no ::SetMenu function.
32 #if defined(__WXWINCE__)
33 # if ((_WIN32_WCE >= 400) && !defined(__POCKETPC__) && !defined(__SMARTPHONE__)) || \
34 defined(__HANDHELDPC__)
35 # define WINCE_WITH_COMMANDBAR
36 # else
37 # define WINCE_WITHOUT_COMMANDBAR
38 # endif
39 #endif
40
41
42 #include "wx/arrstr.h"
43
44 // ----------------------------------------------------------------------------
45 // Menu
46 // ----------------------------------------------------------------------------
47
48 class WXDLLIMPEXP_CORE wxMenu : public wxMenuBase
49 {
50 public:
51 // ctors & dtor
52 wxMenu(const wxString& title, long style = 0)
53 : wxMenuBase(title, style) { Init(); }
54
55 wxMenu(long style = 0) : wxMenuBase(style) { Init(); }
56
57 virtual ~wxMenu();
58
59 virtual void Break();
60
61 virtual void SetTitle(const wxString& title);
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 // get the native menu handle
71 WXHMENU GetHMenu() const { return m_hMenu; }
72
73 #if wxUSE_ACCEL
74 // called by wxMenuBar to build its accel table from the accels of all menus
75 bool HasAccels() const { return !m_accels.empty(); }
76 size_t GetAccelCount() const { return m_accels.size(); }
77 size_t CopyAccels(wxAcceleratorEntry *accels) const;
78
79 // called by wxMenuItem when its accels changes
80 void UpdateAccel(wxMenuItem *item);
81
82 // helper used by wxMenu itself (returns the index in m_accels)
83 int FindAccel(int id) const;
84
85 // used only by wxMDIParentFrame currently but could be useful elsewhere:
86 // returns a new accelerator table with accelerators for just this menu
87 // (shouldn't be called if we don't have any accelerators)
88 wxAcceleratorTable *CreateAccelTable() const;
89 #endif // wxUSE_ACCEL
90
91 #if wxUSE_OWNER_DRAWN
92
93 int GetMaxAccelWidth()
94 {
95 if (m_maxAccelWidth == -1)
96 CalculateMaxAccelWidth();
97 return m_maxAccelWidth;
98 }
99
100 void ResetMaxAccelWidth()
101 {
102 m_maxAccelWidth = -1;
103 }
104
105 private:
106 void CalculateMaxAccelWidth();
107
108 #endif // wxUSE_OWNER_DRAWN
109
110 protected:
111 virtual wxMenuItem* DoAppend(wxMenuItem *item);
112 virtual wxMenuItem* DoInsert(size_t pos, wxMenuItem *item);
113 virtual wxMenuItem* DoRemove(wxMenuItem *item);
114
115 private:
116 // common part of all ctors
117 void Init();
118
119 // common part of Append/Insert (behaves as Append is pos == (size_t)-1)
120 bool DoInsertOrAppend(wxMenuItem *item, size_t pos = (size_t)-1);
121
122 // terminate the current radio group, if any
123 void EndRadioGroup();
124
125 // if true, insert a breal before appending the next item
126 bool m_doBreak;
127
128 // the position of the first item in the current radio group or -1
129 int m_startRadioGroup;
130
131 // the menu handle of this menu
132 WXHMENU m_hMenu;
133
134 #if wxUSE_ACCEL
135 // the accelerators for our menu items
136 wxAcceleratorArray m_accels;
137 #endif // wxUSE_ACCEL
138
139 #if wxUSE_OWNER_DRAWN
140 // true if the menu has any ownerdrawn items
141 bool m_ownerDrawn;
142
143 // the max width of menu items bitmaps
144 int m_maxBitmapWidth;
145
146 // the max width of menu items accels
147 int m_maxAccelWidth;
148 #endif // wxUSE_OWNER_DRAWN
149
150 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenu)
151 };
152
153 // ----------------------------------------------------------------------------
154 // Menu Bar (a la Windows)
155 // ----------------------------------------------------------------------------
156
157 class WXDLLIMPEXP_CORE wxMenuBar : public wxMenuBarBase
158 {
159 public:
160 // ctors & dtor
161 // default constructor
162 wxMenuBar();
163 // unused under MSW
164 wxMenuBar(long style);
165 // menubar takes ownership of the menus arrays but copies the titles
166 wxMenuBar(size_t n, wxMenu *menus[], const wxString titles[], long style = 0);
167 virtual ~wxMenuBar();
168
169 // menubar construction
170 virtual bool Append( wxMenu *menu, const wxString &title );
171 virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title);
172 virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
173 virtual wxMenu *Remove(size_t pos);
174
175 virtual void EnableTop( size_t pos, bool flag );
176 virtual void SetMenuLabel( size_t pos, const wxString& label );
177 virtual wxString GetMenuLabel( size_t pos ) const;
178
179 // implementation from now on
180 WXHMENU Create();
181 virtual void Detach();
182 virtual void Attach(wxFrame *frame);
183
184 #if defined(__WXWINCE__) && wxUSE_TOOLBAR
185 // Under WinCE, a menubar is owned by the frame's toolbar
186 void SetToolBar(wxToolBar* toolBar) { m_toolBar = toolBar; }
187 wxToolBar* GetToolBar() const { return m_toolBar; }
188 #endif
189
190 #ifdef WINCE_WITH_COMMANDBAR
191 WXHWND GetCommandBar() const { return m_commandBar; }
192 bool AddAdornments(long style);
193 #endif
194
195 #if wxUSE_ACCEL
196 // update the accel table (must be called after adding/deleting a menu)
197 void RebuildAccelTable();
198 #endif // wxUSE_ACCEL
199
200 // get the menu handle
201 WXHMENU GetHMenu() const { return m_hMenu; }
202
203 // if the menubar is modified, the display is not updated automatically,
204 // call this function to update it (m_menuBarFrame should be !NULL)
205 void Refresh();
206
207 // To avoid compile warning
208 void Refresh( bool eraseBackground,
209 const wxRect *rect = (const wxRect *) NULL ) { wxWindow::Refresh(eraseBackground, rect); }
210
211 protected:
212 // common part of all ctors
213 void Init();
214
215 WXHMENU m_hMenu;
216
217 // Return the MSW position for a wxMenu which is sometimes different from
218 // the wxWidgets position.
219 int MSWPositionForWxMenu(wxMenu *menu, int wxpos);
220
221 #if defined(__WXWINCE__) && wxUSE_TOOLBAR
222 wxToolBar* m_toolBar;
223 #endif
224
225 #ifdef WINCE_WITH_COMMANDBAR
226 WXHWND m_commandBar;
227 bool m_adornmentsAdded;
228 #endif
229
230 private:
231 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenuBar)
232 };
233
234 #endif // _WX_MENU_H_