1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG interface defs for wxMenuBar, wxMenu and wxMenuItem
7 // Created: 24-June-1997
9 // Copyright: (c) 2003 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
16 //---------------------------------------------------------------------------
19 wxLIST_WRAPPER(wxMenuItemList, wxMenuItem);
25 class wxMenu : public wxEvtHandler
28 %pythonAppend wxMenu "self._setOORInfo(self)"
29 %typemap(out) wxMenu*; // turn off this typemap
31 wxMenu(const wxString& title = wxPyEmptyString, long style = 0);
33 // Turn it back on again
34 %typemap(out) wxMenu* { $result = wxPyMake_wxObject($1, $owner); }
37 // append any kind of item (normal/check/radio/separator)
38 wxMenuItem* Append(int id,
39 const wxString& text = wxPyEmptyString,
40 const wxString& help = wxPyEmptyString,
41 wxItemKind kind = wxITEM_NORMAL);
43 // append a separator to the menu
44 wxMenuItem* AppendSeparator();
46 // append a check item
47 wxMenuItem* AppendCheckItem(int id,
49 const wxString& help = wxPyEmptyString);
51 // append a radio item
52 wxMenuItem* AppendRadioItem(int id,
54 const wxString& help = wxPyEmptyString);
56 %Rename(AppendMenu, wxMenuItem*, Append(int id,
59 const wxString& help = wxPyEmptyString));
61 wxMenuItem* AppendSubMenu(wxMenu *submenu,
63 const wxString& help = wxPyEmptyString);
65 %disownarg(wxMenuItem*);
66 // the most generic form of Append() - append anything
67 %Rename(AppendItem, wxMenuItem*, Append(wxMenuItem *item));
68 // insert an item before given position
69 %Rename(InsertItem, wxMenuItem*, Insert(size_t pos, wxMenuItem *item));
70 // prepend an item to the menu
71 %Rename(PrependItem, wxMenuItem*, Prepend(wxMenuItem *item));
72 %cleardisown(wxMenuItem*);
75 // insert a break in the menu (only works when appending the items, not
79 // insert an item before given position
80 wxMenuItem* Insert(size_t pos,
82 const wxString& text = wxPyEmptyString,
83 const wxString& help = wxPyEmptyString,
84 wxItemKind kind = wxITEM_NORMAL);
87 wxMenuItem* InsertSeparator(size_t pos);
89 // insert a check item
90 wxMenuItem* InsertCheckItem(size_t pos,
93 const wxString& help = wxPyEmptyString);
95 // insert a radio item
96 wxMenuItem* InsertRadioItem(size_t pos,
99 const wxString& help = wxPyEmptyString);
102 %Rename(InsertMenu, wxMenuItem*, Insert(size_t pos,
104 const wxString& text,
106 const wxString& help = wxPyEmptyString));
108 // prepend any item to the menu
109 wxMenuItem* Prepend(int id,
110 const wxString& text = wxPyEmptyString,
111 const wxString& help = wxPyEmptyString,
112 wxItemKind kind = wxITEM_NORMAL);
114 // prepend a separator
115 wxMenuItem* PrependSeparator();
117 // prepend a check item
118 wxMenuItem* PrependCheckItem(int id,
119 const wxString& text,
120 const wxString& help = wxPyEmptyString);
122 // prepend a radio item
123 wxMenuItem* PrependRadioItem(int id,
124 const wxString& text,
125 const wxString& help = wxPyEmptyString);
128 %Rename(PrependMenu, wxMenuItem*, Prepend(int id,
129 const wxString& text,
131 const wxString& help = wxPyEmptyString));
134 // detach an item from the menu, but don't delete it so that it can be
135 // added back later (but if it's not, the caller is responsible for
138 wxMenuItem *Remove(int id);
140 %feature("shadow") Remove(wxMenuItem *item) %{
141 def RemoveItem(self, item):
142 """RemoveItem(self, MenuItem item) -> MenuItem"""
143 #// The return object is always the parameter, so return that
144 #// proxy instead of the new one
145 val = _core_.Menu_RemoveItem(self, item)
146 item.this.own(val.this.own())
150 %Rename(RemoveItem, wxMenuItem*, Remove(wxMenuItem *item));
152 // delete an item from the menu (submenus are not destroyed by this
153 // function, see Destroy)
155 %Rename(DeleteItem, bool, Delete(wxMenuItem *item));
157 %pythonPrepend Destroy "args[0].this.own(False)"
158 %extend { void Destroy() { delete self; } }
160 // delete the item from menu and destroy it (if it's a submenu)
161 %pythonPrepend Destroy "";
163 bool , Destroy(int id),
168 bool , Destroy(wxMenuItem *item),
174 size_t GetMenuItemCount() const;
175 wxMenuItemList& GetMenuItems();
178 int FindItem(const wxString& item) const;
179 %Rename(FindItemById, wxMenuItem*, FindItem(int id /*, wxMenu **menu = NULL*/) const);
182 wxMenuItem* FindItemByPosition(size_t position) const;
184 // get/set items attributes
185 void Enable(int id, bool enable);
186 bool IsEnabled(int id) const;
188 void Check(int id, bool check);
189 bool IsChecked(int id) const;
191 void SetLabel(int id, const wxString& label);
192 wxString GetLabel(int id) const;
194 virtual void SetHelpString(int id, const wxString& helpString);
195 virtual wxString GetHelpString(int id) const;
199 virtual void SetTitle(const wxString& title);
200 const wxString GetTitle() const;
203 void SetEventHandler(wxEvtHandler *handler);
204 wxEvtHandler *GetEventHandler() const;
207 void SetInvokingWindow(wxWindow *win);
208 wxWindow *GetInvokingWindow() const;
211 long GetStyle() const { return m_style; }
214 // Updates the UI for a menu and all submenus recursively. source is the
215 // object that has the update event handlers defined for it. If NULL, the
216 // menu or associated window will be used.
217 void UpdateUI(wxEvtHandler* source = NULL);
219 // get the menu bar this menu is attached to (may be NULL, always NULL for
221 wxMenuBar *GetMenuBar() const;
223 // TODO: Should these be exposed?
224 // called when the menu is attached/detached to/from a menu bar
225 virtual void Attach(wxMenuBarBase *menubar);
226 virtual void Detach();
228 // is the menu attached to a menu bar (or is it a popup one)?
229 bool IsAttached() const;
231 // set/get the parent of this menu
232 void SetParent(wxMenu *parent);
233 wxMenu *GetParent() const;
235 %property(EventHandler, GetEventHandler, SetEventHandler, doc="See `GetEventHandler` and `SetEventHandler`");
236 %property(HelpString, GetHelpString, SetHelpString, doc="See `GetHelpString` and `SetHelpString`");
237 %property(InvokingWindow, GetInvokingWindow, SetInvokingWindow, doc="See `GetInvokingWindow` and `SetInvokingWindow`");
238 %property(MenuBar, GetMenuBar, doc="See `GetMenuBar`");
239 %property(MenuItemCount, GetMenuItemCount, doc="See `GetMenuItemCount`");
240 %property(MenuItems, GetMenuItems, doc="See `GetMenuItems`");
241 %property(Parent, GetParent, SetParent, doc="See `GetParent` and `SetParent`");
242 %property(Style, GetStyle, doc="See `GetStyle`");
243 %property(Title, GetTitle, SetTitle, doc="See `GetTitle` and `SetTitle`");
247 //---------------------------------------------------------------------------
250 MustHaveApp(wxMenuBar);
252 class wxMenuBar : public wxWindow
255 %pythonAppend wxMenuBar "self._setOORInfo(self)"
256 %typemap(out) wxMenuBar*; // turn off this typemap
258 wxMenuBar(long style = 0);
260 // Turn it back on again
261 %typemap(out) wxMenuBar* { $result = wxPyMake_wxObject($1, $owner); }
263 // append a menu to the end of menubar, return True if ok
264 virtual bool Append(wxMenu *menu, const wxString& title);
266 // insert a menu before the given position into the menubar, return True
268 virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title);
271 // get the number of menus in the menu bar
272 size_t GetMenuCount() const;
274 // get the menu at given position
275 wxMenu *GetMenu(size_t pos) const;
277 // replace the menu at given position with another one, returns the
278 // previous menu (which should be deleted by the caller)
279 virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
281 // delete the menu at given position from the menu bar, return the pointer
282 // to the menu (which should be deleted by the caller)
283 virtual wxMenu *Remove(size_t pos);
285 // enable or disable a submenu
286 virtual void EnableTop(size_t pos, bool enable);
288 // is the menu enabled?
289 virtual bool IsEnabledTop(size_t pos) const;
291 // get or change the label of the menu at given position
292 virtual void SetLabelTop(size_t pos, const wxString& label);
293 virtual wxString GetLabelTop(size_t pos) const;
296 // by menu and item names, returns wxNOT_FOUND if not found or id of the
298 virtual int FindMenuItem(const wxString& menu, const wxString& item) const;
300 // find item by id (in any menu), returns NULL if not found
302 // if menu is !NULL, it will be filled with wxMenu this item belongs to
303 %Rename(FindItemById, virtual wxMenuItem*, FindItem(int id /*, wxMenu **menu = NULL*/) const);
305 // find menu by its caption, return wxNOT_FOUND on failure
306 int FindMenu(const wxString& title);
309 // all these functions just use FindItem() and then call an appropriate
312 // NB: under MSW, these methods can only be used after the menubar had
313 // been attached to the frame
315 void Enable(int id, bool enable);
316 void Check(int id, bool check);
317 bool IsChecked(int id) const;
318 bool IsEnabled(int id) const;
319 // TODO: bool IsEnabled() const;
321 void SetLabel(int id, const wxString &label);
322 wxString GetLabel(int id) const;
324 void SetHelpString(int id, const wxString& helpString);
325 wxString GetHelpString(int id) const;
328 // get the frame we are attached to (may return NULL)
329 wxFrame *GetFrame() const;
331 // returns True if we're attached to a frame
332 bool IsAttached() const;
334 // associate the menubar with the frame
335 virtual void Attach(wxFrame *frame);
337 // called before deleting the menubar normally
338 virtual void Detach();
340 // update all menu item states in all menus
341 virtual void UpdateMenus();
344 static void SetAutoWindowMenu( bool enable );
345 static bool GetAutoWindowMenu();
348 static void SetAutoWindowMenu( bool enable ) {}
349 static bool GetAutoWindowMenu() { return false; }
355 """Return a list of (menu, label) items for the menus in the MenuBar. """
356 return [(self.GetMenu(i), self.GetLabelTop(i))
357 for i in range(self.GetMenuCount())]
359 def SetMenus(self, items):
360 """Clear and add new menus to the MenuBar from a list of (menu, label) items. """
361 for i in range(self.GetMenuCount()-1, -1, -1):
367 %property(Frame, GetFrame, doc="See `GetFrame`");
368 %property(MenuCount, GetMenuCount, doc="See `GetMenuCount`");
369 %property(Menus, GetMenus, SetMenus, doc="See `GetMenus` and `SetMenus`");
372 //---------------------------------------------------------------------------
375 class wxMenuItem : public wxObject {
377 // turn off this typemap
378 %typemap(out) wxMenuItem*;
380 wxMenuItem(wxMenu* parentMenu=NULL, int id=wxID_SEPARATOR,
381 const wxString& text = wxPyEmptyString,
382 const wxString& help = wxPyEmptyString,
383 wxItemKind kind = wxITEM_NORMAL,
384 wxMenu* subMenu = NULL);
387 // Turn it back on again
388 %typemap(out) wxMenuItem* { $result = wxPyMake_wxObject($1, $owner); }
390 // Make Destroy a NOP. The destruction will be handled by SWIG.
391 %pythoncode { def Destroy(self): pass }
395 wxMenu *GetMenu() const;
396 void SetMenu(wxMenu* menu);
401 bool IsSeparator() const;
403 // the item's text (or name)
405 // NB: the item's text includes the accelerators and mnemonics info (if
406 // any), i.e. it may contain '&' or '_' or "\t..." and thus is
407 // different from the item's label which only contains the text shown
409 virtual void SetText(const wxString& str);
410 wxString GetLabel() const;
411 const wxString& GetText() const;
413 // get the label from text
414 static wxString GetLabelFromText(const wxString& text);
416 // what kind of menu item we are
417 wxItemKind GetKind() const;
418 void SetKind(wxItemKind kind);
420 virtual void SetCheckable(bool checkable);
421 bool IsCheckable() const;
423 bool IsSubMenu() const;
424 void SetSubMenu(wxMenu *menu);
425 wxMenu *GetSubMenu() const;
428 virtual void Enable(bool enable = true);
429 virtual bool IsEnabled() const;
431 virtual void Check(bool check = true);
432 virtual bool IsChecked() const;
435 // help string (displayed in the status bar by default)
436 void SetHelp(const wxString& str);
437 const wxString& GetHelp() const;
439 // get our accelerator or NULL (caller must delete the pointer)
440 virtual wxAcceleratorEntry *GetAccel() const;
442 // set the accel for this item - this may also be done indirectly with
444 virtual void SetAccel(wxAcceleratorEntry *accel);
446 void SetBitmap(const wxBitmap& bitmap);
447 const wxBitmap& GetBitmap();
449 // wxOwnerDrawn methods
451 void SetFont(const wxFont& font);
453 void SetTextColour(const wxColour& colText);
454 wxColour GetTextColour();
455 void SetBackgroundColour(const wxColour& colBack);
456 wxColour GetBackgroundColour();
457 void SetBitmaps(const wxBitmap& bmpChecked,
458 const wxBitmap& bmpUnchecked = wxNullBitmap);
460 void SetDisabledBitmap( const wxBitmap& bmpDisabled );
461 const wxBitmap& GetDisabledBitmap() const;
463 void SetMarginWidth(int nWidth);
464 int GetMarginWidth();
465 static int GetDefaultMarginWidth();
468 // switch on/off owner-drawing the item
469 void SetOwnerDrawn(bool ownerDrawn = true);
470 void ResetOwnerDrawn();
473 void SetFont(const wxFont& font) {}
474 wxFont GetFont() { return wxNullFont; }
475 void SetTextColour(const wxColour& colText) {}
476 wxColour GetTextColour() { return wxNullColour; }
477 void SetBackgroundColour(const wxColour& colBack) {}
478 wxColour GetBackgroundColour() { return wxNullColour; }
480 void SetBitmaps(const wxBitmap& bmpChecked,
481 const wxBitmap& bmpUnchecked = wxNullBitmap)
482 { self->SetBitmap( bmpChecked ); }
484 void SetDisabledBitmap( const wxBitmap& bmpDisabled ) {}
485 const wxBitmap& GetDisabledBitmap() const { return wxNullBitmap; }
487 void SetMarginWidth(int nWidth) {}
488 int GetMarginWidth() { return 0; }
489 static int GetDefaultMarginWidth() { return 0; }
490 bool IsOwnerDrawn() { return false; }
491 void SetOwnerDrawn(bool ownerDrawn = true) {}
492 void ResetOwnerDrawn() {}
496 %property(Accel, GetAccel, SetAccel, doc="See `GetAccel` and `SetAccel`");
497 %property(BackgroundColour, GetBackgroundColour, SetBackgroundColour, doc="See `GetBackgroundColour` and `SetBackgroundColour`");
498 %property(Bitmap, GetBitmap, SetBitmap, doc="See `GetBitmap` and `SetBitmap`");
499 %property(DisabledBitmap, GetDisabledBitmap, SetDisabledBitmap, doc="See `GetDisabledBitmap` and `SetDisabledBitmap`");
500 %property(Font, GetFont, SetFont, doc="See `GetFont` and `SetFont`");
501 %property(Help, GetHelp, SetHelp, doc="See `GetHelp` and `SetHelp`");
502 %property(Id, GetId, SetId, doc="See `GetId` and `SetId`");
503 %property(Kind, GetKind, SetKind, doc="See `GetKind` and `SetKind`");
504 %property(Label, GetLabel, doc="See `GetLabel`");
505 %property(MarginWidth, GetMarginWidth, SetMarginWidth, doc="See `GetMarginWidth` and `SetMarginWidth`");
506 %property(Menu, GetMenu, SetMenu, doc="See `GetMenu` and `SetMenu`");
507 %property(SubMenu, GetSubMenu, SetSubMenu, doc="See `GetSubMenu` and `SetSubMenu`");
508 %property(Text, GetText, SetText, doc="See `GetText` and `SetText`");
509 %property(TextColour, GetTextColour, SetTextColour, doc="See `GetTextColour` and `SetTextColour`");
513 //---------------------------------------------------------------------------
514 //---------------------------------------------------------------------------