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 //---------------------------------------------------------------------------
 
  22 class wxMenu : public wxEvtHandler
 
  25     %pythonAppend wxMenu         "self._setOORInfo(self)"
 
  26     %typemap(out) wxMenu*;    // turn off this typemap
 
  28     wxMenu(const wxString& title = wxPyEmptyString, long style = 0);
 
  30     // Turn it back on again
 
  31     %typemap(out) wxMenu* { $result = wxPyMake_wxObject($1, $owner); }
 
  34     // append any kind of item (normal/check/radio/separator)
 
  35     wxMenuItem* Append(int id,
 
  36                        const wxString& text = wxPyEmptyString,
 
  37                        const wxString& help = wxPyEmptyString,
 
  38                        wxItemKind kind = wxITEM_NORMAL);
 
  40     // append a separator to the menu
 
  41     wxMenuItem* AppendSeparator();
 
  43     // append a check item
 
  44     wxMenuItem* AppendCheckItem(int id,
 
  46                                 const wxString& help = wxPyEmptyString);
 
  48     // append a radio item
 
  49     wxMenuItem* AppendRadioItem(int id,
 
  51                                 const wxString& help = wxPyEmptyString);
 
  53     %Rename(AppendMenu, wxMenuItem*, Append(int id,
 
  56                                            const wxString& help = wxPyEmptyString));
 
  58     wxMenuItem* AppendSubMenu(wxMenu *submenu,
 
  60                               const wxString& help = wxPyEmptyString);
 
  62     %disownarg(wxMenuItem*);
 
  63     // the most generic form of Append() - append anything
 
  64     %Rename(AppendItem, wxMenuItem*, Append(wxMenuItem *item));
 
  65     // insert an item before given position
 
  66     %Rename(InsertItem, wxMenuItem*, Insert(size_t pos, wxMenuItem *item));
 
  67     // prepend an item to the menu
 
  68     %Rename(PrependItem,  wxMenuItem*, Prepend(wxMenuItem *item));
 
  69     %cleardisown(wxMenuItem*);
 
  72     // insert a break in the menu (only works when appending the items, not
 
  76     // insert an item before given position
 
  77     wxMenuItem* Insert(size_t pos,
 
  79                        const wxString& text = wxPyEmptyString,
 
  80                        const wxString& help = wxPyEmptyString,
 
  81                        wxItemKind kind = wxITEM_NORMAL);
 
  84     wxMenuItem* InsertSeparator(size_t pos);
 
  86     // insert a check item
 
  87     wxMenuItem* InsertCheckItem(size_t pos,
 
  90                                 const wxString& help = wxPyEmptyString);
 
  92     // insert a radio item
 
  93     wxMenuItem* InsertRadioItem(size_t pos,
 
  96                                 const wxString& help = wxPyEmptyString);
 
  99     %Rename(InsertMenu, wxMenuItem*, Insert(size_t pos,
 
 101                                          const wxString& text,
 
 103                                          const wxString& help = wxPyEmptyString));
 
 105     // prepend any item to the menu
 
 106     wxMenuItem* Prepend(int id,
 
 107                         const wxString& text = wxPyEmptyString,
 
 108                         const wxString& help = wxPyEmptyString,
 
 109                         wxItemKind kind = wxITEM_NORMAL);
 
 111     // prepend a separator
 
 112     wxMenuItem*  PrependSeparator();
 
 114     // prepend a check item
 
 115     wxMenuItem* PrependCheckItem(int id,
 
 116                                  const wxString& text,
 
 117                                  const wxString& help = wxPyEmptyString);
 
 119     // prepend a radio item
 
 120     wxMenuItem*  PrependRadioItem(int id,
 
 121                                   const wxString& text,
 
 122                                   const wxString& help = wxPyEmptyString);
 
 125     %Rename(PrependMenu,  wxMenuItem*, Prepend(int id,
 
 126                                            const wxString& text,
 
 128                                            const wxString& help = wxPyEmptyString));
 
 131     // detach an item from the menu, but don't delete it so that it can be
 
 132     // added back later (but if it's not, the caller is responsible for
 
 135     wxMenuItem *Remove(int id);
 
 137     %feature("shadow") Remove(wxMenuItem *item) %{
 
 138         def RemoveItem(self, item):
 
 139             """RemoveItem(self, MenuItem item) -> MenuItem"""
 
 140             #// The return object is always the parameter, so return that 
 
 141             #// proxy instead of the new one
 
 142             val = _core_.Menu_RemoveItem(self, item)
 
 143             item.this.own(val.this.own())
 
 147     %Rename(RemoveItem,  wxMenuItem*, Remove(wxMenuItem *item));
 
 149     // delete an item from the menu (submenus are not destroyed by this
 
 150     // function, see Destroy)
 
 152     %Rename(DeleteItem,  bool, Delete(wxMenuItem *item));
 
 154     %pythonPrepend Destroy "args[0].this.own(False)"
 
 155     %extend { void Destroy() { delete self; } }
 
 157     // delete the item from menu and destroy it (if it's a submenu)
 
 158     %pythonPrepend Destroy "";
 
 160         bool , Destroy(int id),
 
 165         bool , Destroy(wxMenuItem *item),
 
 171     size_t GetMenuItemCount() const;
 
 173         PyObject* GetMenuItems() {
 
 174             wxMenuItemList& list = self->GetMenuItems();
 
 175             return wxPy_ConvertList(&list);
 
 180     int FindItem(const wxString& item) const;
 
 181     %Rename(FindItemById, wxMenuItem*, FindItem(int id /*, wxMenu **menu = NULL*/) const);
 
 184     wxMenuItem* FindItemByPosition(size_t position) const;
 
 186     // get/set items attributes
 
 187     void Enable(int id, bool enable);
 
 188     bool IsEnabled(int id) const;
 
 190     void Check(int id, bool check);
 
 191     bool IsChecked(int id) const;
 
 193     void SetLabel(int id, const wxString& label);
 
 194     wxString GetLabel(int id) const;
 
 196     virtual void SetHelpString(int id, const wxString& helpString);
 
 197     virtual wxString GetHelpString(int id) const;
 
 201     virtual void SetTitle(const wxString& title);
 
 202     const wxString GetTitle() const;
 
 205     void SetEventHandler(wxEvtHandler *handler);
 
 206     wxEvtHandler *GetEventHandler() const;
 
 209     void SetInvokingWindow(wxWindow *win);
 
 210     wxWindow *GetInvokingWindow() const;
 
 213     long GetStyle() const { return m_style; }
 
 216     // Updates the UI for a menu and all submenus recursively. source is the
 
 217     // object that has the update event handlers defined for it. If NULL, the
 
 218     // menu or associated window will be used.
 
 219     void UpdateUI(wxEvtHandler* source = NULL);
 
 221     // get the menu bar this menu is attached to (may be NULL, always NULL for
 
 223     wxMenuBar *GetMenuBar() const;
 
 225 // TODO:  Should these be exposed?
 
 226     // called when the menu is attached/detached to/from a menu bar
 
 227     virtual void Attach(wxMenuBarBase *menubar);
 
 228     virtual void Detach();
 
 230     // is the menu attached to a menu bar (or is it a popup one)?
 
 231     bool IsAttached() const;
 
 233     // set/get the parent of this menu
 
 234     void SetParent(wxMenu *parent);
 
 235     wxMenu *GetParent() const;
 
 237     %property(EventHandler, GetEventHandler, SetEventHandler, doc="See `GetEventHandler` and `SetEventHandler`");
 
 238     %property(HelpString, GetHelpString, SetHelpString, doc="See `GetHelpString` and `SetHelpString`");
 
 239     %property(InvokingWindow, GetInvokingWindow, SetInvokingWindow, doc="See `GetInvokingWindow` and `SetInvokingWindow`");
 
 240     %property(MenuBar, GetMenuBar, doc="See `GetMenuBar`");
 
 241     %property(MenuItemCount, GetMenuItemCount, doc="See `GetMenuItemCount`");
 
 242     %property(MenuItems, GetMenuItems, doc="See `GetMenuItems`");
 
 243     %property(Parent, GetParent, SetParent, doc="See `GetParent` and `SetParent`");
 
 244     %property(Style, GetStyle, doc="See `GetStyle`");
 
 245     %property(Title, GetTitle, SetTitle, doc="See `GetTitle` and `SetTitle`");
 
 249 //---------------------------------------------------------------------------
 
 252 MustHaveApp(wxMenuBar);
 
 254 class wxMenuBar : public wxWindow
 
 257     %pythonAppend wxMenuBar         "self._setOORInfo(self)"
 
 258     %typemap(out) wxMenuBar*;    // turn off this typemap
 
 260     wxMenuBar(long style = 0);
 
 262     // Turn it back on again
 
 263     %typemap(out) wxMenuBar* { $result = wxPyMake_wxObject($1, $owner); }
 
 265     // append a menu to the end of menubar, return True if ok
 
 266     virtual bool Append(wxMenu *menu, const wxString& title);
 
 268     // insert a menu before the given position into the menubar, return True
 
 270     virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title);
 
 273     // get the number of menus in the menu bar
 
 274     size_t GetMenuCount() const;
 
 276     // get the menu at given position
 
 277     wxMenu *GetMenu(size_t pos) const;
 
 279     // replace the menu at given position with another one, returns the
 
 280     // previous menu (which should be deleted by the caller)
 
 281     virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
 
 283     // delete the menu at given position from the menu bar, return the pointer
 
 284     // to the menu (which should be  deleted by the caller)
 
 285     virtual wxMenu *Remove(size_t pos);
 
 287     // enable or disable a submenu
 
 288     virtual void EnableTop(size_t pos, bool enable);
 
 290     // is the menu enabled?
 
 291     virtual bool IsEnabledTop(size_t pos) const;
 
 293     // get or change the label of the menu at given position
 
 294     virtual void SetLabelTop(size_t pos, const wxString& label);
 
 295     virtual wxString GetLabelTop(size_t pos) const;
 
 298     // by menu and item names, returns wxNOT_FOUND if not found or id of the
 
 300     virtual int FindMenuItem(const wxString& menu, const wxString& item) const;
 
 302     // find item by id (in any menu), returns NULL if not found
 
 304     // if menu is !NULL, it will be filled with wxMenu this item belongs to
 
 305     %Rename(FindItemById, virtual wxMenuItem*, FindItem(int id /*, wxMenu **menu = NULL*/) const);
 
 307     // find menu by its caption, return wxNOT_FOUND on failure
 
 308     int FindMenu(const wxString& title);
 
 311     // all these functions just use FindItem() and then call an appropriate
 
 314     // NB: under MSW, these methods can only be used after the menubar had
 
 315     //     been attached to the frame
 
 317     void Enable(int id, bool enable);
 
 318     void Check(int id, bool check);
 
 319     bool IsChecked(int id) const;
 
 320     bool IsEnabled(int id) const;
 
 321     // TODO: bool IsEnabled() const;
 
 323     void SetLabel(int id, const wxString &label);
 
 324     wxString GetLabel(int id) const;
 
 326     void SetHelpString(int id, const wxString& helpString);
 
 327     wxString GetHelpString(int id) const;
 
 330     // get the frame we are attached to (may return NULL)
 
 331     wxFrame *GetFrame() const;
 
 333     // returns True if we're attached to a frame
 
 334     bool IsAttached() const;
 
 336     // associate the menubar with the frame
 
 337     virtual void Attach(wxFrame *frame);
 
 339     // called before deleting the menubar normally
 
 340     virtual void Detach();
 
 342     // update all menu item states in all menus
 
 343     virtual void UpdateMenus();
 
 346     static void SetAutoWindowMenu( bool enable );
 
 347     static bool GetAutoWindowMenu();
 
 350         static void SetAutoWindowMenu( bool enable ) {}
 
 351         static bool GetAutoWindowMenu() { return false; }
 
 357             """Return a list of (menu, label) items for the menus in the MenuBar. """
 
 358             return [(self.GetMenu(i), self.GetLabelTop(i)) 
 
 359                     for i in range(self.GetMenuCount())]
 
 361         def SetMenus(self, items):
 
 362             """Clear and add new menus to the MenuBar from a list of (menu, label) items. """
 
 363             for i in range(self.GetMenuCount()-1, -1, -1):
 
 369     %property(Frame, GetFrame, doc="See `GetFrame`");
 
 370     %property(MenuCount, GetMenuCount, doc="See `GetMenuCount`");
 
 371     %property(Menus, GetMenus, SetMenus, doc="See `GetMenus` and `SetMenus`");
 
 374 //---------------------------------------------------------------------------
 
 377 class wxMenuItem : public wxObject {
 
 379     // turn off this typemap
 
 380     %typemap(out) wxMenuItem*;    
 
 382     wxMenuItem(wxMenu* parentMenu=NULL, int id=wxID_SEPARATOR,
 
 383                const wxString& text = wxPyEmptyString,
 
 384                const wxString& help = wxPyEmptyString,
 
 385                wxItemKind kind = wxITEM_NORMAL,
 
 386                wxMenu* subMenu = NULL);
 
 389     // Turn it back on again
 
 390     %typemap(out) wxMenuItem* { $result = wxPyMake_wxObject($1, $owner); }
 
 392     // Make Destroy a NOP.  The destruction will be handled by SWIG.
 
 393     %pythoncode { def Destroy(self): pass }
 
 397     wxMenu *GetMenu() const;
 
 398     void SetMenu(wxMenu* menu);
 
 403     bool IsSeparator() const;
 
 405     // the item's text (or name)
 
 407     // NB: the item's text includes the accelerators and mnemonics info (if
 
 408     //     any), i.e. it may contain '&' or '_' or "\t..." and thus is
 
 409     //     different from the item's label which only contains the text shown
 
 411     virtual void SetText(const wxString& str);
 
 412     wxString GetLabel() const;
 
 413     const wxString& GetText() const;
 
 415     // get the label from text 
 
 416     static wxString GetLabelFromText(const wxString& text);
 
 418     // what kind of menu item we are
 
 419     wxItemKind GetKind() const;
 
 420     void SetKind(wxItemKind kind);
 
 422     virtual void SetCheckable(bool checkable);
 
 423     bool IsCheckable() const;
 
 425     bool IsSubMenu() const;
 
 426     void SetSubMenu(wxMenu *menu);
 
 427     wxMenu *GetSubMenu() const;
 
 430     virtual void Enable(bool enable = true);
 
 431     virtual bool IsEnabled() const;
 
 433     virtual void Check(bool check = true);
 
 434     virtual bool IsChecked() const;
 
 437     // help string (displayed in the status bar by default)
 
 438     void SetHelp(const wxString& str);
 
 439     const wxString& GetHelp() const;
 
 441     // get our accelerator or NULL (caller must delete the pointer)
 
 442     virtual wxAcceleratorEntry *GetAccel() const;
 
 444     // set the accel for this item - this may also be done indirectly with
 
 446     virtual void SetAccel(wxAcceleratorEntry *accel);
 
 448     void SetBitmap(const wxBitmap& bitmap);
 
 449     const wxBitmap& GetBitmap();
 
 451     // wxOwnerDrawn methods
 
 453     void SetFont(const wxFont& font);
 
 455     void SetTextColour(const wxColour& colText);
 
 456     wxColour GetTextColour();
 
 457     void SetBackgroundColour(const wxColour& colBack);
 
 458     wxColour GetBackgroundColour();
 
 459     void SetBitmaps(const wxBitmap& bmpChecked,
 
 460                     const wxBitmap& bmpUnchecked = wxNullBitmap);
 
 462     void SetDisabledBitmap( const wxBitmap& bmpDisabled );
 
 463     const wxBitmap& GetDisabledBitmap() const;
 
 465     void SetMarginWidth(int nWidth);
 
 466     int GetMarginWidth();
 
 467     static int GetDefaultMarginWidth();
 
 470     // switch on/off owner-drawing the item
 
 471     void SetOwnerDrawn(bool ownerDrawn = true);
 
 472     void ResetOwnerDrawn();
 
 475         void SetFont(const wxFont& font) {}
 
 476         wxFont GetFont() { return wxNullFont; }
 
 477         void SetTextColour(const wxColour& colText) {}
 
 478         wxColour GetTextColour() { return wxNullColour; }
 
 479         void SetBackgroundColour(const wxColour& colBack) {}
 
 480         wxColour GetBackgroundColour() { return wxNullColour; }
 
 482         void SetBitmaps(const wxBitmap& bmpChecked,
 
 483                         const wxBitmap& bmpUnchecked = wxNullBitmap)
 
 484             { self->SetBitmap( bmpChecked ); }
 
 486         void SetDisabledBitmap( const wxBitmap& bmpDisabled ) {}
 
 487         const wxBitmap& GetDisabledBitmap() const { return wxNullBitmap; }
 
 489         void SetMarginWidth(int nWidth) {}
 
 490         int GetMarginWidth() { return 0; }
 
 491         static int GetDefaultMarginWidth() { return 0; }
 
 492         bool IsOwnerDrawn() { return false; }
 
 493         void SetOwnerDrawn(bool ownerDrawn = true) {}
 
 494         void ResetOwnerDrawn() {}
 
 498     %property(Accel, GetAccel, SetAccel, doc="See `GetAccel` and `SetAccel`");
 
 499     %property(BackgroundColour, GetBackgroundColour, SetBackgroundColour, doc="See `GetBackgroundColour` and `SetBackgroundColour`");
 
 500     %property(Bitmap, GetBitmap, SetBitmap, doc="See `GetBitmap` and `SetBitmap`");
 
 501     %property(DisabledBitmap, GetDisabledBitmap, SetDisabledBitmap, doc="See `GetDisabledBitmap` and `SetDisabledBitmap`");
 
 502     %property(Font, GetFont, SetFont, doc="See `GetFont` and `SetFont`");
 
 503     %property(Help, GetHelp, SetHelp, doc="See `GetHelp` and `SetHelp`");
 
 504     %property(Id, GetId, SetId, doc="See `GetId` and `SetId`");
 
 505     %property(Kind, GetKind, SetKind, doc="See `GetKind` and `SetKind`");
 
 506     %property(Label, GetLabel, doc="See `GetLabel`");
 
 507     %property(MarginWidth, GetMarginWidth, SetMarginWidth, doc="See `GetMarginWidth` and `SetMarginWidth`");
 
 508     %property(Menu, GetMenu, SetMenu, doc="See `GetMenu` and `SetMenu`");
 
 509     %property(SubMenu, GetSubMenu, SetSubMenu, doc="See `GetSubMenu` and `SetSubMenu`");
 
 510     %property(Text, GetText, SetText, doc="See `GetText` and `SetText`");
 
 511     %property(TextColour, GetTextColour, SetTextColour, doc="See `GetTextColour` and `SetTextColour`");
 
 515 //---------------------------------------------------------------------------
 
 516 //---------------------------------------------------------------------------