]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/menu.h
XRC: make wxSplitterWindow's sashpos and minpanesize dimensions.
[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 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_MENU_H_
12 #define _WX_MENU_H_
13
14 #if wxUSE_ACCEL
15 #include "wx/accel.h"
16 #include "wx/dynarray.h"
17
18 WX_DEFINE_EXPORTED_ARRAY_PTR(wxAcceleratorEntry *, wxAcceleratorArray);
19 #endif // wxUSE_ACCEL
20
21 class WXDLLIMPEXP_FWD_CORE wxFrame;
22
23 #if defined(__WXWINCE__) && wxUSE_TOOLBAR
24 class WXDLLIMPEXP_FWD_CORE wxToolBar;
25 #endif
26
27 class wxMenuRadioItemsData;
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 // MSW-only methods
64 // ----------------
65
66 // Create a new menu from the given native HMENU. Takes ownership of the
67 // menu handle and will delete it when this object is destroyed.
68 static wxMenu *MSWNewFromHMENU(WXHMENU hMenu) { return new wxMenu(hMenu); }
69
70
71 // implementation only from now on
72 // -------------------------------
73
74 bool MSWCommand(WXUINT param, WXWORD id);
75
76 // get the native menu handle
77 WXHMENU GetHMenu() const { return m_hMenu; }
78
79 // Return the start and end position of the radio group to which the item
80 // at the given position belongs. Returns false if there is no radio group
81 // containing this position.
82 bool MSWGetRadioGroupRange(int pos, int *start, int *end) const;
83
84 #if wxUSE_ACCEL
85 // called by wxMenuBar to build its accel table from the accels of all menus
86 bool HasAccels() const { return !m_accels.empty(); }
87 size_t GetAccelCount() const { return m_accels.size(); }
88 size_t CopyAccels(wxAcceleratorEntry *accels) const;
89
90 // called by wxMenuItem when its accels changes
91 void UpdateAccel(wxMenuItem *item);
92
93 // helper used by wxMenu itself (returns the index in m_accels)
94 int FindAccel(int id) const;
95
96 // used only by wxMDIParentFrame currently but could be useful elsewhere:
97 // returns a new accelerator table with accelerators for just this menu
98 // (shouldn't be called if we don't have any accelerators)
99 wxAcceleratorTable *CreateAccelTable() const;
100 #endif // wxUSE_ACCEL
101
102 #if wxUSE_OWNER_DRAWN
103
104 int GetMaxAccelWidth()
105 {
106 if (m_maxAccelWidth == -1)
107 CalculateMaxAccelWidth();
108 return m_maxAccelWidth;
109 }
110
111 void ResetMaxAccelWidth()
112 {
113 m_maxAccelWidth = -1;
114 }
115
116 // get the menu with given handle (recursively)
117 wxMenu* MSWGetMenu(WXHMENU hMenu);
118
119 private:
120 void CalculateMaxAccelWidth();
121
122 #endif // wxUSE_OWNER_DRAWN
123
124 protected:
125 virtual wxMenuItem* DoAppend(wxMenuItem *item);
126 virtual wxMenuItem* DoInsert(size_t pos, wxMenuItem *item);
127 virtual wxMenuItem* DoRemove(wxMenuItem *item);
128
129 private:
130 // This constructor is private, use MSWNewFromHMENU() to use it.
131 wxMenu(WXHMENU hMenu);
132
133 // Common part of all ctors, it doesn't create a new HMENU.
134 void InitNoCreate();
135
136 // Common part of all ctors except of the one above taking a native menu
137 // handler: calls InitNoCreate() and also creates a new menu.
138 void Init();
139
140 // common part of Append/Insert (behaves as Append is pos == (size_t)-1)
141 bool DoInsertOrAppend(wxMenuItem *item, size_t pos = (size_t)-1);
142
143
144 // This variable contains the description of the radio item groups and
145 // allows to find whether an item at the given position is part of the
146 // group and also where its group starts and ends.
147 //
148 // It is initially NULL and only allocated if we have any radio items.
149 wxMenuRadioItemsData *m_radioData;
150
151 // if true, insert a breal before appending the next item
152 bool m_doBreak;
153
154 // the menu handle of this menu
155 WXHMENU m_hMenu;
156
157 #if wxUSE_ACCEL
158 // the accelerators for our menu items
159 wxAcceleratorArray m_accels;
160 #endif // wxUSE_ACCEL
161
162 #if wxUSE_OWNER_DRAWN
163 // true if the menu has any ownerdrawn items
164 bool m_ownerDrawn;
165
166 // the max width of menu items bitmaps
167 int m_maxBitmapWidth;
168
169 // the max width of menu items accels
170 int m_maxAccelWidth;
171 #endif // wxUSE_OWNER_DRAWN
172
173 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenu)
174 };
175
176 // ----------------------------------------------------------------------------
177 // Menu Bar (a la Windows)
178 // ----------------------------------------------------------------------------
179
180 class WXDLLIMPEXP_CORE wxMenuBar : public wxMenuBarBase
181 {
182 public:
183 // ctors & dtor
184 // default constructor
185 wxMenuBar();
186 // unused under MSW
187 wxMenuBar(long style);
188 // menubar takes ownership of the menus arrays but copies the titles
189 wxMenuBar(size_t n, wxMenu *menus[], const wxString titles[], long style = 0);
190 virtual ~wxMenuBar();
191
192 // menubar construction
193 virtual bool Append( wxMenu *menu, const wxString &title );
194 virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title);
195 virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
196 virtual wxMenu *Remove(size_t pos);
197
198 virtual void EnableTop( size_t pos, bool flag );
199 virtual bool IsEnabledTop(size_t pos) const;
200 virtual void SetMenuLabel( size_t pos, const wxString& label );
201 virtual wxString GetMenuLabel( size_t pos ) const;
202
203 // implementation from now on
204 WXHMENU Create();
205 virtual void Detach();
206 virtual void Attach(wxFrame *frame);
207
208 #if defined(__WXWINCE__) && wxUSE_TOOLBAR
209 // Under WinCE, a menubar is owned by the frame's toolbar
210 void SetToolBar(wxToolBar* toolBar) { m_toolBar = toolBar; }
211 wxToolBar* GetToolBar() const { return m_toolBar; }
212 #endif
213
214 #ifdef WINCE_WITH_COMMANDBAR
215 WXHWND GetCommandBar() const { return m_commandBar; }
216 bool AddAdornments(long style);
217 #endif
218
219 #if wxUSE_ACCEL
220 // update the accel table (must be called after adding/deleting a menu)
221 void RebuildAccelTable();
222 #endif // wxUSE_ACCEL
223
224 // get the menu handle
225 WXHMENU GetHMenu() const { return m_hMenu; }
226
227 // if the menubar is modified, the display is not updated automatically,
228 // call this function to update it (m_menuBarFrame should be !NULL)
229 void Refresh();
230
231 // To avoid compile warning
232 void Refresh( bool eraseBackground,
233 const wxRect *rect = (const wxRect *) NULL ) { wxWindow::Refresh(eraseBackground, rect); }
234
235 // get the menu with given handle (recursively)
236 wxMenu* MSWGetMenu(WXHMENU hMenu);
237
238 protected:
239 // common part of all ctors
240 void Init();
241
242 WXHMENU m_hMenu;
243
244 // Return the MSW position for a wxMenu which is sometimes different from
245 // the wxWidgets position.
246 int MSWPositionForWxMenu(wxMenu *menu, int wxpos);
247
248 #if defined(__WXWINCE__) && wxUSE_TOOLBAR
249 wxToolBar* m_toolBar;
250 #endif
251
252 #ifdef WINCE_WITH_COMMANDBAR
253 WXHWND m_commandBar;
254 bool m_adornmentsAdded;
255 #endif
256
257 private:
258 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenuBar)
259 };
260
261 #endif // _WX_MENU_H_