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