]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_menu.i
doc tweaks
[wxWidgets.git] / wxPython / src / _menu.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: _menu.i
3 // Purpose: SWIG interface defs for wxMenuBar, wxMenu and wxMenuItem
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 24-June-1997
8 // RCS-ID: $Id$
9 // Copyright: (c) 2003 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13 // Not a %module
14
15
16 //---------------------------------------------------------------------------
17 %newgroup
18
19
20 MustHaveApp(wxMenu);
21
22 class wxMenu : public wxEvtHandler
23 {
24 public:
25 %pythonAppend wxMenu "self._setOORInfo(self)"
26 wxMenu(const wxString& title = wxPyEmptyString, long style = 0);
27
28
29 // append any kind of item (normal/check/radio/separator)
30 wxMenuItem* Append(int id,
31 const wxString& text,
32 const wxString& help = wxPyEmptyString,
33 wxItemKind kind = wxITEM_NORMAL);
34
35 // append a separator to the menu
36 wxMenuItem* AppendSeparator();
37
38 // append a check item
39 wxMenuItem* AppendCheckItem(int id,
40 const wxString& text,
41 const wxString& help = wxPyEmptyString);
42
43 // append a radio item
44 wxMenuItem* AppendRadioItem(int id,
45 const wxString& text,
46 const wxString& help = wxPyEmptyString);
47 // append a submenu
48 %name(AppendMenu) wxMenuItem* Append(int id,
49 const wxString& text,
50 wxMenu *submenu,
51 const wxString& help = wxPyEmptyString);
52
53 // the most generic form of Append() - append anything
54 %name(AppendItem) wxMenuItem* Append(wxMenuItem *item);
55
56 // insert a break in the menu (only works when appending the items, not
57 // inserting them)
58 virtual void Break();
59
60 // insert an item before given position
61 %name(InsertItem) wxMenuItem* Insert(size_t pos, wxMenuItem *item);
62
63 // insert an item before given position
64 wxMenuItem* Insert(size_t pos,
65 int id,
66 const wxString& text,
67 const wxString& help = wxPyEmptyString,
68 wxItemKind kind = wxITEM_NORMAL);
69
70 // insert a separator
71 wxMenuItem* InsertSeparator(size_t pos);
72
73 // insert a check item
74 wxMenuItem* InsertCheckItem(size_t pos,
75 int id,
76 const wxString& text,
77 const wxString& help = wxPyEmptyString);
78
79 // insert a radio item
80 wxMenuItem* InsertRadioItem(size_t pos,
81 int id,
82 const wxString& text,
83 const wxString& help = wxPyEmptyString);
84
85 // insert a submenu
86 %name(InsertMenu) wxMenuItem* Insert(size_t pos,
87 int id,
88 const wxString& text,
89 wxMenu *submenu,
90 const wxString& help = wxPyEmptyString);
91
92 // prepend an item to the menu
93 %name(PrependItem) wxMenuItem* Prepend(wxMenuItem *item);
94
95 // prepend any item to the menu
96 wxMenuItem* Prepend(int id,
97 const wxString& text,
98 const wxString& help = wxPyEmptyString,
99 wxItemKind kind = wxITEM_NORMAL);
100
101 // prepend a separator
102 wxMenuItem* PrependSeparator();
103
104 // prepend a check item
105 wxMenuItem* PrependCheckItem(int id,
106 const wxString& text,
107 const wxString& help = wxPyEmptyString);
108
109 // prepend a radio item
110 wxMenuItem* PrependRadioItem(int id,
111 const wxString& text,
112 const wxString& help = wxPyEmptyString);
113
114 // prepend a submenu
115 %name(PrependMenu) wxMenuItem* Prepend(int id,
116 const wxString& text,
117 wxMenu *submenu,
118 const wxString& help = wxPyEmptyString);
119
120 // detach an item from the menu, but don't delete it so that it can be
121 // added back later (but if it's not, the caller is responsible for
122 // deleting it!)
123 wxMenuItem *Remove(int id);
124 %name(RemoveItem) wxMenuItem *Remove(wxMenuItem *item);
125
126 // delete an item from the menu (submenus are not destroyed by this
127 // function, see Destroy)
128 bool Delete(int id);
129 %name(DeleteItem) bool Delete(wxMenuItem *item);
130
131 // delete the item from menu and destroy it (if it's a submenu)
132 %extend { void Destroy() { delete self; } }
133 %name(DestroyId) bool Destroy(int id);
134 %name(DestroyItem) bool Destroy(wxMenuItem *item);
135
136
137 // get the items
138 size_t GetMenuItemCount() const;
139 %extend {
140 PyObject* GetMenuItems() {
141 wxMenuItemList& list = self->GetMenuItems();
142 return wxPy_ConvertList(&list);
143 }
144 }
145
146 // search
147 int FindItem(const wxString& item) const;
148 %name(FindItemById) wxMenuItem* FindItem(int id /*, wxMenu **menu = NULL*/) const;
149
150 // find by position
151 wxMenuItem* FindItemByPosition(size_t position) const;
152
153 // get/set items attributes
154 void Enable(int id, bool enable);
155 bool IsEnabled(int id) const;
156
157 void Check(int id, bool check);
158 bool IsChecked(int id) const;
159
160 void SetLabel(int id, const wxString& label);
161 wxString GetLabel(int id) const;
162
163 virtual void SetHelpString(int id, const wxString& helpString);
164 virtual wxString GetHelpString(int id) const;
165
166
167 // the title
168 virtual void SetTitle(const wxString& title);
169 const wxString GetTitle() const;
170
171 // event handler
172 void SetEventHandler(wxEvtHandler *handler);
173 wxEvtHandler *GetEventHandler() const;
174
175 // invoking window
176 void SetInvokingWindow(wxWindow *win);
177 wxWindow *GetInvokingWindow() const;
178
179 // style
180 long GetStyle() const { return m_style; }
181
182
183 // Updates the UI for a menu and all submenus recursively. source is the
184 // object that has the update event handlers defined for it. If NULL, the
185 // menu or associated window will be used.
186 void UpdateUI(wxEvtHandler* source = NULL);
187
188 // get the menu bar this menu is attached to (may be NULL, always NULL for
189 // popup menus)
190 wxMenuBar *GetMenuBar() const;
191
192 // TODO: Should these be exposed?
193 // called when the menu is attached/detached to/from a menu bar
194 virtual void Attach(wxMenuBarBase *menubar);
195 virtual void Detach();
196
197 // is the menu attached to a menu bar (or is it a popup one)?
198 bool IsAttached() const;
199
200 // set/get the parent of this menu
201 void SetParent(wxMenu *parent);
202 wxMenu *GetParent() const;
203 };
204
205 //---------------------------------------------------------------------------
206 %newgroup
207
208 MustHaveApp(wxMenuBar);
209
210 class wxMenuBar : public wxWindow
211 {
212 public:
213 %pythonAppend wxMenuBar "self._setOORInfo(self)"
214 wxMenuBar(long style = 0);
215
216
217 // append a menu to the end of menubar, return True if ok
218 virtual bool Append(wxMenu *menu, const wxString& title);
219
220 // insert a menu before the given position into the menubar, return True
221 // if inserted ok
222 virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title);
223
224
225 // get the number of menus in the menu bar
226 size_t GetMenuCount() const;
227
228 // get the menu at given position
229 wxMenu *GetMenu(size_t pos) const;
230
231 // replace the menu at given position with another one, returns the
232 // previous menu (which should be deleted by the caller)
233 virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
234
235 // delete the menu at given position from the menu bar, return the pointer
236 // to the menu (which should be deleted by the caller)
237 virtual wxMenu *Remove(size_t pos);
238
239 // enable or disable a submenu
240 virtual void EnableTop(size_t pos, bool enable);
241
242 // is the menu enabled?
243 virtual bool IsEnabledTop(size_t WXUNUSED(pos)) const { return True; }
244
245 // get or change the label of the menu at given position
246 virtual void SetLabelTop(size_t pos, const wxString& label);
247 virtual wxString GetLabelTop(size_t pos) const;
248
249
250 // by menu and item names, returns wxNOT_FOUND if not found or id of the
251 // found item
252 virtual int FindMenuItem(const wxString& menu, const wxString& item) const;
253
254 // find item by id (in any menu), returns NULL if not found
255 //
256 // if menu is !NULL, it will be filled with wxMenu this item belongs to
257 %name(FindItemById) virtual wxMenuItem* FindItem(int id /*, wxMenu **menu = NULL*/) const;
258
259 // find menu by its caption, return wxNOT_FOUND on failure
260 int FindMenu(const wxString& title) const;
261
262
263 // all these functions just use FindItem() and then call an appropriate
264 // method on it
265 //
266 // NB: under MSW, these methods can only be used after the menubar had
267 // been attached to the frame
268
269 void Enable(int id, bool enable);
270 void Check(int id, bool check);
271 bool IsChecked(int id) const;
272 bool IsEnabled(int id) const;
273
274 void SetLabel(int id, const wxString &label);
275 wxString GetLabel(int id) const;
276
277 void SetHelpString(int id, const wxString& helpString);
278 wxString GetHelpString(int id) const;
279
280
281 // get the frame we are attached to (may return NULL)
282 wxFrame *GetFrame() const;
283
284 // returns True if we're attached to a frame
285 bool IsAttached() const;
286
287 // associate the menubar with the frame
288 virtual void Attach(wxFrame *frame);
289
290 // called before deleting the menubar normally
291 virtual void Detach();
292 };
293
294 //---------------------------------------------------------------------------
295 %newgroup
296
297 class wxMenuItem : public wxObject {
298 public:
299 wxMenuItem(wxMenu* parentMenu=NULL, int id=wxID_ANY,
300 const wxString& text = wxPyEmptyString,
301 const wxString& help = wxPyEmptyString,
302 wxItemKind kind = wxITEM_NORMAL,
303 wxMenu* subMenu = NULL);
304
305 // the menu we're in
306 wxMenu *GetMenu() const;
307 void SetMenu(wxMenu* menu);
308
309 // get/set id
310 void SetId(int id);
311 int GetId() const;
312 bool IsSeparator() const;
313
314 // the item's text (or name)
315 //
316 // NB: the item's text includes the accelerators and mnemonics info (if
317 // any), i.e. it may contain '&' or '_' or "\t..." and thus is
318 // different from the item's label which only contains the text shown
319 // in the menu
320 virtual void SetText(const wxString& str);
321 wxString GetLabel() const;
322 const wxString& GetText() const;
323
324 // get the label from text
325 static wxString GetLabelFromText(const wxString& text);
326
327 // what kind of menu item we are
328 wxItemKind GetKind() const;
329 void SetKind(wxItemKind kind);
330
331 virtual void SetCheckable(bool checkable);
332 bool IsCheckable() const;
333
334 bool IsSubMenu() const;
335 void SetSubMenu(wxMenu *menu);
336 wxMenu *GetSubMenu() const;
337
338 // state
339 virtual void Enable(bool enable = True);
340 virtual bool IsEnabled() const;
341
342 virtual void Check(bool check = True);
343 virtual bool IsChecked() const;
344 void Toggle();
345
346 // help string (displayed in the status bar by default)
347 void SetHelp(const wxString& str);
348 const wxString& GetHelp() const;
349
350 // get our accelerator or NULL (caller must delete the pointer)
351 virtual wxAcceleratorEntry *GetAccel() const;
352
353 // set the accel for this item - this may also be done indirectly with
354 // SetText()
355 virtual void SetAccel(wxAcceleratorEntry *accel);
356
357
358 // wxOwnerDrawn methods
359 #ifdef __WXMSW__
360 void SetFont(const wxFont& font);
361 wxFont GetFont();
362 void SetTextColour(const wxColour& colText);
363 wxColour GetTextColour();
364 void SetBackgroundColour(const wxColour& colBack);
365 wxColour GetBackgroundColour();
366 void SetBitmaps(const wxBitmap& bmpChecked,
367 const wxBitmap& bmpUnchecked = wxNullBitmap);
368
369 void SetDisabledBitmap( const wxBitmap& bmpDisabled );
370 const wxBitmap& GetDisabledBitmap() const;
371
372 void SetMarginWidth(int nWidth);
373 int GetMarginWidth();
374 static int GetDefaultMarginWidth();
375 bool IsOwnerDrawn();
376
377 // switch on/off owner-drawing the item
378 void SetOwnerDrawn(bool ownerDrawn = True);
379 void ResetOwnerDrawn();
380 #else
381 // just to keep the global renamers in sync
382 %extend {
383 static int GetDefaultMarginWidth() { return 0; }
384 }
385 #endif
386
387 void SetBitmap(const wxBitmap& bitmap);
388 const wxBitmap& GetBitmap();
389 };
390
391 //---------------------------------------------------------------------------
392 //---------------------------------------------------------------------------