File: wx140.htm

package info (click to toggle)
wxwin2-doc 2.01-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 6,540 kB
  • ctags: 5,968
  • sloc: cpp: 15,157; makefile: 434; sh: 6
file content (390 lines) | stat: -rw-r--r-- 14,119 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
<HTML>
<head><title>wxMenu</title></head>

<BODY BGCOLOR=#FFFFFF>
<A NAME="wxmenu"></A><CENTER>
<A HREF="wx.htm"><img align=center src="contents.gif" BORDER=0 ALT="Contents"></A> <A HREF="wx22.htm#classref"><img align=center src="up.gif" BORDER=0 ALT="Up"></A> <A HREF="wx139.htm#wxmemoutputstream"><img align=center src="back.gif" BORDER=0 ALT="Previous"></A> <A HREF="wx141.htm#wxmenubar"><img align=center src="forward.gif" BORDER=0 ALT="Next"></A> </CENTER><HR>

<H2>wxMenu</H2>
<P>
A menu is a popup (or pull down) list of items, one of which may be
selected before the menu goes away (clicking elsewhere dismisses the
menu).  Menus may be used to construct either menu bars or popup menus.<P>
A menu item has an integer ID associated with it which can be used to
identify the selection, or to change the menu item in some way.<P>
<B><FONT COLOR="#FF0000">Derived from</FONT></B><P>
<A HREF="wx85.htm#wxevthandler">wxEvtHandler</A><BR>

<A HREF="wx158.htm#wxobject">wxObject</A><P>
<B><FONT COLOR="#FF0000">Include files</FONT></B><P>
&lt;wx/menu.h&gt;<P>
<B><FONT COLOR="#FF0000">Event handling</FONT></B><P>
If the menu is part of a menubar, then <A HREF="wx141.htm#wxmenubar">wxMenuBar</A> event processing is used.<P>
With a popup menu, there is a variety of ways to handle a menu selection event
(wxEVT_COMMAND_MENU_SELECTED).<P>
<OL>

<LI> Define a callback of type wxFunction, which you pass to the wxMenu constructor.
The callback takes a reference to the menu, and a reference to a <A HREF="wx52.htm#wxcommandevent">wxCommandEvent</A>.
<LI> Derive a new class from wxMenu and define event table entries using the EVT_MENU macro.
<LI> Set a new event handler for wxMenu, using an object whose class has EVT_MENU entries.
<LI> Provide EVT_MENU handlers in the window which pops up the menu, or in an ancestor of
this window.
</OL>
<P>
<B><FONT COLOR="#FF0000">See also</FONT></B><P>
<A HREF="wx141.htm#wxmenubar">wxMenuBar</A>, <A HREF="wx260.htm#wxwindowpopupmenu">wxWindow::PopupMenu</A>,
<A HREF="wx299.htm#eventhandlingoverview">Event handling overview</A><P>
<B><FONT COLOR="#FF0000">Members</FONT></B><P>
<A HREF="#wxmenuconstr">wxMenu::wxMenu</A><BR>
<A HREF="#topic559">wxMenu::~wxMenu</A><BR>
<A HREF="#wxmenuappend">wxMenu::Append</A><BR>
<A HREF="#wxmenuappendseparator">wxMenu::AppendSeparator</A><BR>
<A HREF="#wxmenubreak">wxMenu::Break</A><BR>
<A HREF="#wxmenucheck">wxMenu::Check</A><BR>
<A HREF="#wxmenuenable">wxMenu::Enable</A><BR>
<A HREF="#wxmenufinditem">wxMenu::FindItem</A><BR>
<A HREF="#wxmenufinditemforid">wxMenu::FindItemForId</A><BR>
<A HREF="#wxmenugethelpstring">wxMenu::GetHelpString</A><BR>
<A HREF="#wxmenugetlabel">wxMenu::GetLabel</A><BR>
<A HREF="#wxmenugettitle">wxMenu::GetTitle</A><BR>
<A HREF="#wxmenuischecked">wxMenu::IsChecked</A><BR>
<A HREF="#wxmenuisenabled">wxMenu::IsEnabled</A><BR>
<A HREF="#wxmenusethelpstring">wxMenu::SetHelpString</A><BR>
<A HREF="#wxmenusetlabel">wxMenu::SetLabel</A><BR>
<A HREF="#wxmenusettitle">wxMenu::SetTitle</A><BR>
<A HREF="#wxmenuupdateui">wxMenu::UpdateUI</A><BR>
<P>

<HR>
<A NAME="wxmenuconstr"></A>
<H3>wxMenu::wxMenu</H3>
<P>
<B></B> <B>wxMenu</B>(<B>const wxString&amp; </B><I>title = ""</I>, <B>const wxFunction</B><I> func = NULL</I>)<P>
Constructs a wxMenu object.<P>
<B><FONT COLOR="#FF0000">Parameters</FONT></B><P>
<I>title</I><UL><UL>
A title for the popup menu: the empty string denotes no title.</UL></UL>
<P>
<I>func</I><UL><UL>
A callback function if the menu is used as a popup using <A HREF="wx260.htm#wxwindowpopupmenu">wxWindow::PopupMenu</A>.</UL></UL>
<P>
<B><FONT COLOR="#0000C8">wxPython note:</FONT></B><BR>
 The wxPython version of the <TT>wxMenu</TT> constructor
doesn't accept the callback argument because of reference counting
issues.  There is a specialized wxMenu constructor called
<TT>wxPyMenu</TT> which does and can be used for PopupMenus when callbacks
are needed.  You must retain a reference to the menu while useing it
otherwise your callback function will get dereferenced when the menu
does.
<P>

<HR>
<A NAME="topic559"></A>
<H3>wxMenu::~wxMenu</H3>
<P>
<B></B> <B>~wxMenu</B>()<P>
Destructor, destroying the menu.<P>
Note: under Motif, a popup menu must have a valid parent (the window
it was last popped up on) when being destroyed. Therefore, make sure
you delete or re-use the popup menu <I>before</I> destroying the
parent window. Re-use in this context means popping up the menu on
a different window from last time, which causes an implicit destruction
and recreation of internal data structures.<P>

<HR>
<A NAME="wxmenuappend"></A>
<H3>wxMenu::Append</H3>
<P>
<B>void</B> <B>Append</B>(<B>int</B><I> id</I>, <B>const wxString&amp; </B><I> item</I>, <B>const wxString&amp; </B><I>helpString = ""</I>,
<B>const bool</B><I> checkable = FALSE</I>)<P>
Adds a string item to the end of the menu.<P>
<B>void</B> <B>Append</B>(<B>int</B><I> id</I>, <B>const wxString&amp; </B><I> item</I>, <B>wxMenu *</B><I>subMenu</I>,
<B>const wxString&amp; </B><I>helpString = ""</I>)<P>
Adds a pull-right submenu to the end of the menu.<P>
<B>void</B> <B>Append</B>(<B>wxMenuItem*</B><I> menuItem</I>)<P>
Adds a menu item object. You can specify various extra properties of a menu item this way,
such as bitmaps and fonts.<P>
<B><FONT COLOR="#FF0000">Parameters</FONT></B><P>
<I>id</I><UL><UL>
The menu command identifier.</UL></UL>
<P>
<I>item</I><UL><UL>
The string to appear on the menu item.</UL></UL>
<P>
<I>menu</I><UL><UL>
Pull-right submenu.</UL></UL>
<P>
<I>checkable</I><UL><UL>
If TRUE, this item is checkable.</UL></UL>
<P>
<I>helpString</I><UL><UL>
An optional help string associated with the item.
By default, <A HREF="wx104.htm#wxframeonmenuhighlight">wxFrame::OnMenuHighlight</A> displays
this string in the status line.</UL></UL>
<P>
<I>menuItem</I><UL><UL>
A menuitem object. It will be owned by the wxMenu object after this function
is called, so do not delete it yourself.</UL></UL>
<P>
<B><FONT COLOR="#FF0000">Remarks</FONT></B><P>
This command can be used after the menu has been shown, as well as on initial
creation of a menu or menubar.<P>
<B><FONT COLOR="#FF0000">See also</FONT></B><P>
<A HREF="wx140.htm#wxmenuappendseparator">wxMenu::AppendSeparator</A>, <A HREF="wx140.htm#wxmenusetlabel">wxMenu::SetLabel</A>, <A HREF="wx140.htm#wxmenugethelpstring">wxMenu::GetHelpString</A>,
<A HREF="wx140.htm#wxmenusethelpstring">wxMenu::SetHelpString</A>, <A HREF="wx142.htm#wxmenuitem">wxMenuItem</A><P>

<B><FONT COLOR="#0000C8">wxPython note:</FONT></B><BR>
 In place of a single overloaded method name, wxPython
implements the following methods:<P>

<UL><UL>

<TABLE>


<TR><TD VALIGN=TOP>
<B>Append(id, string, helpStr="", checkable=FALSE)</B>
</TD>

<TD VALIGN=TOP>

</TD></TR>


<TR><TD VALIGN=TOP>
<B>AppendMenu(id, string, aMenu, helpStr="")</B>
</TD>

<TD VALIGN=TOP>

</TD></TR>


<TR><TD VALIGN=TOP>
<B>AppendItem(aMenuItem)</B>
</TD>

<TD VALIGN=TOP>

</TD></TR>


</TABLE>
</UL></UL>

<P>


<HR>
<A NAME="wxmenuappendseparator"></A>
<H3>wxMenu::AppendSeparator</H3>
<P>
<B>void</B> <B>AppendSeparator</B>()<P>
Adds a separator to the end of the menu.<P>
<B><FONT COLOR="#FF0000">See also</FONT></B><P>
<A HREF="wx140.htm#wxmenuappend">wxMenu::Append</A><P>

<HR>
<A NAME="wxmenubreak"></A>
<H3>wxMenu::Break</H3>
<P>
<B>void</B> <B>Break</B>()<P>
Inserts a break in a menu, causing the next appended item to appear in a new column.<P>

<HR>
<A NAME="wxmenucheck"></A>
<H3>wxMenu::Check</H3>
<P>
<B>void</B> <B>Check</B>(<B>int</B><I> id</I>, <B>const bool</B><I> check</I>)<P>
Checks or unchecks the menu item.<P>
<B><FONT COLOR="#FF0000">Parameters</FONT></B><P>
<I>id</I><UL><UL>
The menu item identifier.</UL></UL>
<P>
<I>check</I><UL><UL>
If TRUE, the item will be checked, otherwise it will be unchecked.</UL></UL>
<P>
<B><FONT COLOR="#FF0000">See also</FONT></B><P>
<A HREF="wx140.htm#wxmenuischecked">wxMenu::IsChecked</A><P>

<HR>
<A NAME="wxmenuenable"></A>
<H3>wxMenu::Enable</H3>
<P>
<B>void</B> <B>Enable</B>(<B>int</B><I> id</I>, <B>const bool</B><I> enable</I>)<P>
Enables or disables (greys out) a menu item.<P>
<B><FONT COLOR="#FF0000">Parameters</FONT></B><P>
<I>id</I><UL><UL>
The menu item identifier.</UL></UL>
<P>
<I>enable</I><UL><UL>
TRUE to enable the menu item, FALSE to disable it.</UL></UL>
<P>
<B><FONT COLOR="#FF0000">See also</FONT></B><P>
<A HREF="wx140.htm#wxmenuisenabled">wxMenu::IsEnabled</A><P>

<HR>
<A NAME="wxmenufinditem"></A>
<H3>wxMenu::FindItem</H3>
<P>
<B>int</B> <B>FindItem</B>(<B>const wxString&amp; </B><I>itemString</I>) <B>const</B><P>
Finds the menu item id for a menu item string.<P>
<B><FONT COLOR="#FF0000">Parameters</FONT></B><P>
<I>itemString</I><UL><UL>
Menu item string to find.</UL></UL>
<P>
<B><FONT COLOR="#FF0000">Return value</FONT></B><P>
Menu item identifier, or -1 if none is found.<P>
<B><FONT COLOR="#FF0000">Remarks</FONT></B><P>
Any special menu codes are stripped out of source and target strings
before matching.<P>
<B><FONT COLOR="#FF0000">See also</FONT></B><P>
<A HREF="wx140.htm#wxmenufinditemforid">wxMenu::FindItemForId</A><P>

<HR>
<A NAME="wxmenufinditemforid"></A>
<H3>wxMenu::FindItemForId</H3>
<P>
<B>wxMenuItem*</B> <B>FindItemForId</B>(<B>int</B><I> id</I>) <B>const</B><P>
Finds the menu item object associated with the given menu item identifier.<P>
<B><FONT COLOR="#FF0000">Parameters</FONT></B><P>
<I>id</I><UL><UL>
Menu item identifier.</UL></UL>
<P>
<B><FONT COLOR="#FF0000">Return value</FONT></B><P>
Returns the menu item object, or NULL if it is not found.<P>
<B><FONT COLOR="#FF0000">See also</FONT></B><P>
<A HREF="wx140.htm#wxmenufinditem">wxMenu::FindItem</A><P>

<HR>
<A NAME="wxmenugethelpstring"></A>
<H3>wxMenu::GetHelpString</H3>
<P>
<B>wxString</B> <B>GetHelpString</B>(<B>int</B><I> id</I>) <B>const</B><P>
Returns the help string associated with a menu item.<P>
<B><FONT COLOR="#FF0000">Parameters</FONT></B><P>
<I>id</I><UL><UL>
The menu item identifier.</UL></UL>
<P>
<B><FONT COLOR="#FF0000">Return value</FONT></B><P>
The help string, or the empty string if there is no help string or the
item was not found.<P>
<B><FONT COLOR="#FF0000">See also</FONT></B><P>
<A HREF="wx140.htm#wxmenusethelpstring">wxMenu::SetHelpString</A>, <A HREF="wx140.htm#wxmenuappend">wxMenu::Append</A><P>

<HR>
<A NAME="wxmenugetlabel"></A>
<H3>wxMenu::GetLabel</H3>
<P>
<B>wxString</B> <B>GetLabel</B>(<B>int</B><I> id</I>) <B>const</B><P>
Returns a menu item label.<P>
<B><FONT COLOR="#FF0000">Parameters</FONT></B><P>
<I>id</I><UL><UL>
The menu item identifier.</UL></UL>
<P>
<B><FONT COLOR="#FF0000">Return value</FONT></B><P>
The item label, or the empty string if the item was not found.<P>
<B><FONT COLOR="#FF0000">See also</FONT></B><P>
<A HREF="wx140.htm#wxmenusetlabel">wxMenu::SetLabel</A><P>

<HR>
<A NAME="wxmenugettitle"></A>
<H3>wxMenu::GetTitle</H3>
<P>
<B>wxString</B> <B>GetTitle</B>() <B>const</B><P>
Returns the title of the menu.<P>
<B><FONT COLOR="#FF0000">Remarks</FONT></B><P>
This is relevant only to popup menus.<P>
<B><FONT COLOR="#FF0000">See also</FONT></B><P>
<A HREF="wx140.htm#wxmenusettitle">wxMenu::SetTitle</A><P>

<HR>
<A NAME="wxmenuischecked"></A>
<H3>wxMenu::IsChecked</H3>
<P>
<B>bool</B> <B>IsChecked</B>(<B>int</B><I> id</I>) <B>const</B><P>
Determines whether a menu item is checked.<P>
<B><FONT COLOR="#FF0000">Parameters</FONT></B><P>
<I>id</I><UL><UL>
The menu item identifier.</UL></UL>
<P>
<B><FONT COLOR="#FF0000">Return value</FONT></B><P>
TRUE if the menu item is checked, FALSE otherwise.<P>
<B><FONT COLOR="#FF0000">See also</FONT></B><P>
<A HREF="wx140.htm#wxmenucheck">wxMenu::Check</A><P>

<HR>
<A NAME="wxmenuisenabled"></A>
<H3>wxMenu::IsEnabled</H3>
<P>
<B>bool</B> <B>IsEnabled</B>(<B>int</B><I> id</I>) <B>const</B><P>
Determines whether a menu item is enabled.<P>
<B><FONT COLOR="#FF0000">Parameters</FONT></B><P>
<I>id</I><UL><UL>
The menu item identifier.</UL></UL>
<P>
<B><FONT COLOR="#FF0000">Return value</FONT></B><P>
TRUE if the menu item is enabled, FALSE otherwise.<P>
<B><FONT COLOR="#FF0000">See also</FONT></B><P>
<A HREF="wx140.htm#wxmenuenable">wxMenu::Enable</A><P>

<HR>
<A NAME="wxmenusethelpstring"></A>
<H3>wxMenu::SetHelpString</H3>
<P>
<B>void</B> <B>SetHelpString</B>(<B>int</B><I> id</I>, <B>const wxString&amp; </B><I>helpString</I>)<P>
Sets an item's help string.<P>
<B><FONT COLOR="#FF0000">Parameters</FONT></B><P>
<I>id</I><UL><UL>
The menu item identifier.</UL></UL>
<P>
<I>helpString</I><UL><UL>
The help string to set.</UL></UL>
<P>
<B><FONT COLOR="#FF0000">See also</FONT></B><P>
<A HREF="wx140.htm#wxmenugethelpstring">wxMenu::GetHelpString</A><P>

<HR>
<A NAME="wxmenusetlabel"></A>
<H3>wxMenu::SetLabel</H3>
<P>
<B>void</B> <B>SetLabel</B>(<B>int</B><I> id</I>, <B>const wxString&amp; </B><I>label</I>)<P>
Sets the label of a menu item.<P>
<B><FONT COLOR="#FF0000">Parameters</FONT></B><P>
<I>id</I><UL><UL>
The menu item identifier.</UL></UL>
<P>
<I>label</I><UL><UL>
The menu item label to set.</UL></UL>
<P>
<B><FONT COLOR="#FF0000">See also</FONT></B><P>
<A HREF="wx140.htm#wxmenuappend">wxMenu::Append</A>, <A HREF="wx140.htm#wxmenugetlabel">wxMenu::GetLabel</A><P>

<HR>
<A NAME="wxmenusettitle"></A>
<H3>wxMenu::SetTitle</H3>
<P>
<B>void</B> <B>SetTitle</B>(<B>const wxString&amp; </B><I>title</I>)<P>
Sets the title of the menu.<P>
<B><FONT COLOR="#FF0000">Parameters</FONT></B><P>
<I>title</I><UL><UL>
The title to set.</UL></UL>
<P>
<B><FONT COLOR="#FF0000">Remarks</FONT></B><P>
This is relevant only to popup menus.<P>
<B><FONT COLOR="#FF0000">See also</FONT></B><P>
<A HREF="wx140.htm#wxmenusettitle">wxMenu::SetTitle</A><P>

<HR>
<A NAME="wxmenuupdateui"></A>
<H3>wxMenu::UpdateUI</H3>
<P>
<B>void</B> <B>UpdateUI</B>(<B>wxEvtHandler*</B><I> source = NULL</I>) <B>const</B><P>
Sends events to <I>source</I> (or owning window if NULL) to update the
menu UI. This is called just before the menu is popped up with <A HREF="wx260.htm#wxwindowpopupmenu">wxWindow::PopupMenu</A>, but
the application may call it at other times if required.<P>
<B><FONT COLOR="#FF0000">See also</FONT></B><P>
<A HREF="wx253.htm#wxupdateuievent">wxUpdateUIEvent</A><P>

</BODY></HTML>