]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/menu.h
0ce964a495684ea566b6a1bf2d254aac832c682a
[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 // 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.empty(); }
79 size_t GetAccelCount() const { return m_accels.size(); }
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
88 // used only by wxMDIParentFrame currently but could be useful elsewhere:
89 // returns a new accelerator table with accelerators for just this menu
90 // (shouldn't be called if we don't have any accelerators)
91 wxAcceleratorTable *CreateAccelTable() const;
92 #endif // wxUSE_ACCEL
93
94 protected:
95 virtual wxMenuItem* DoAppend(wxMenuItem *item);
96 virtual wxMenuItem* DoInsert(size_t pos, wxMenuItem *item);
97 virtual wxMenuItem* DoRemove(wxMenuItem *item);
98
99 private:
100 // common part of all ctors
101 void Init();
102
103 // common part of Append/Insert (behaves as Append is pos == (size_t)-1)
104 bool DoInsertOrAppend(wxMenuItem *item, size_t pos = (size_t)-1);
105
106 // terminate the current radio group, if any
107 void EndRadioGroup();
108
109 // if true, insert a breal before appending the next item
110 bool m_doBreak;
111
112 // the position of the first item in the current radio group or -1
113 int m_startRadioGroup;
114
115 // the menu handle of this menu
116 WXHMENU m_hMenu;
117
118 #if wxUSE_ACCEL
119 // the accelerators for our menu items
120 wxAcceleratorArray m_accels;
121 #endif // wxUSE_ACCEL
122
123 #if wxUSE_OWNER_DRAWN
124 // true if the menu has any ownerdrawn items
125 bool m_ownerDrawn;
126
127 // the max width of menu items bitmaps
128 int m_maxBitmapWidth;
129 #endif // wxUSE_OWNER_DRAWN
130
131 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenu)
132 };
133
134 // ----------------------------------------------------------------------------
135 // Menu Bar (a la Windows)
136 // ----------------------------------------------------------------------------
137
138 class WXDLLIMPEXP_CORE wxMenuInfo : public wxObject
139 {
140 public :
141 wxMenuInfo() { m_menu = NULL; }
142 virtual ~wxMenuInfo() { }
143
144 void Create( wxMenu *menu , const wxString &title )
145 { m_menu = menu; m_title = title; }
146 wxMenu* GetMenu() const { return m_menu; }
147 wxString GetTitle() const { return m_title; }
148 private :
149 wxMenu *m_menu;
150 wxString m_title;
151
152 DECLARE_DYNAMIC_CLASS(wxMenuInfo)
153 };
154
155 WX_DECLARE_EXPORTED_LIST(wxMenuInfo, wxMenuInfoList );
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 bool Append( wxMenuInfo *info ) { return Append( info->GetMenu() , info->GetTitle() ); }
171 const wxMenuInfoList& GetMenuInfos() const;
172
173 virtual bool Append( wxMenu *menu, const wxString &title );
174 virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title);
175 virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
176 virtual wxMenu *Remove(size_t pos);
177
178 virtual void EnableTop( size_t pos, bool flag );
179 virtual void SetMenuLabel( size_t pos, const wxString& label );
180 virtual wxString GetMenuLabel( size_t pos ) const;
181
182 // implementation from now on
183 WXHMENU Create();
184 virtual void Detach();
185 virtual void Attach(wxFrame *frame);
186
187 #if defined(__WXWINCE__) && wxUSE_TOOLBAR
188 // Under WinCE, a menubar is owned by the frame's toolbar
189 void SetToolBar(wxToolBar* toolBar) { m_toolBar = toolBar; }
190 wxToolBar* GetToolBar() const { return m_toolBar; }
191 #endif
192
193 #ifdef WINCE_WITH_COMMANDBAR
194 WXHWND GetCommandBar() const { return m_commandBar; }
195 bool AddAdornments(long style);
196 #endif
197
198 #if wxUSE_ACCEL
199 // update the accel table (must be called after adding/deleting a menu)
200 void RebuildAccelTable();
201 #endif // wxUSE_ACCEL
202
203 // get the menu handle
204 WXHMENU GetHMenu() const { return m_hMenu; }
205
206 // if the menubar is modified, the display is not updated automatically,
207 // call this function to update it (m_menuBarFrame should be !NULL)
208 void Refresh();
209
210 // To avoid compile warning
211 void Refresh( bool eraseBackground,
212 const wxRect *rect = (const wxRect *) NULL ) { wxWindow::Refresh(eraseBackground, rect); }
213
214 protected:
215 // common part of all ctors
216 void Init();
217
218 wxArrayString m_titles;
219 wxMenuInfoList m_menuInfos;
220
221 WXHMENU m_hMenu;
222
223 // Return the MSW position for a wxMenu which is sometimes different from
224 // the wxWidgets position.
225 int MSWPositionForWxMenu(wxMenu *menu, int wxpos);
226
227 #if defined(__WXWINCE__) && wxUSE_TOOLBAR
228 wxToolBar* m_toolBar;
229 #endif
230
231 #ifdef WINCE_WITH_COMMANDBAR
232 WXHWND m_commandBar;
233 bool m_adornmentsAdded;
234 #endif
235
236 private:
237 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenuBar)
238 };
239
240 #endif // _WX_MENU_H_