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);
 
 136     %Rename(RemoveItem,  wxMenuItem*, Remove(wxMenuItem *item));
 
 138     // delete an item from the menu (submenus are not destroyed by this
 
 139     // function, see Destroy)
 
 141     %Rename(DeleteItem,  bool, Delete(wxMenuItem *item));
 
 143     %pythonPrepend Destroy "args[0].this.own(False)"
 
 144     %extend { void Destroy() { delete self; } }
 
 146     // delete the item from menu and destroy it (if it's a submenu)
 
 147     %pythonPrepend Destroy "";
 
 149         bool , Destroy(int id),
 
 154         bool , Destroy(wxMenuItem *item),
 
 160     size_t GetMenuItemCount() const;
 
 162         PyObject* GetMenuItems() {
 
 163             wxMenuItemList& list = self->GetMenuItems();
 
 164             return wxPy_ConvertList(&list);
 
 169     int FindItem(const wxString& item) const;
 
 170     %Rename(FindItemById, wxMenuItem*, FindItem(int id /*, wxMenu **menu = NULL*/) const);
 
 173     wxMenuItem* FindItemByPosition(size_t position) const;
 
 175     // get/set items attributes
 
 176     void Enable(int id, bool enable);
 
 177     bool IsEnabled(int id) const;
 
 179     void Check(int id, bool check);
 
 180     bool IsChecked(int id) const;
 
 182     void SetLabel(int id, const wxString& label);
 
 183     wxString GetLabel(int id) const;
 
 185     virtual void SetHelpString(int id, const wxString& helpString);
 
 186     virtual wxString GetHelpString(int id) const;
 
 190     virtual void SetTitle(const wxString& title);
 
 191     const wxString GetTitle() const;
 
 194     void SetEventHandler(wxEvtHandler *handler);
 
 195     wxEvtHandler *GetEventHandler() const;
 
 198     void SetInvokingWindow(wxWindow *win);
 
 199     wxWindow *GetInvokingWindow() const;
 
 202     long GetStyle() const { return m_style; }
 
 205     // Updates the UI for a menu and all submenus recursively. source is the
 
 206     // object that has the update event handlers defined for it. If NULL, the
 
 207     // menu or associated window will be used.
 
 208     void UpdateUI(wxEvtHandler* source = NULL);
 
 210     // get the menu bar this menu is attached to (may be NULL, always NULL for
 
 212     wxMenuBar *GetMenuBar() const;
 
 214 // TODO:  Should these be exposed?
 
 215     // called when the menu is attached/detached to/from a menu bar
 
 216     virtual void Attach(wxMenuBarBase *menubar);
 
 217     virtual void Detach();
 
 219     // is the menu attached to a menu bar (or is it a popup one)?
 
 220     bool IsAttached() const;
 
 222     // set/get the parent of this menu
 
 223     void SetParent(wxMenu *parent);
 
 224     wxMenu *GetParent() const;
 
 226     %property(EventHandler, GetEventHandler, SetEventHandler, doc="See `GetEventHandler` and `SetEventHandler`");
 
 227     %property(HelpString, GetHelpString, SetHelpString, doc="See `GetHelpString` and `SetHelpString`");
 
 228     %property(InvokingWindow, GetInvokingWindow, SetInvokingWindow, doc="See `GetInvokingWindow` and `SetInvokingWindow`");
 
 229     %property(MenuBar, GetMenuBar, doc="See `GetMenuBar`");
 
 230     %property(MenuItemCount, GetMenuItemCount, doc="See `GetMenuItemCount`");
 
 231     %property(MenuItems, GetMenuItems, doc="See `GetMenuItems`");
 
 232     %property(Parent, GetParent, SetParent, doc="See `GetParent` and `SetParent`");
 
 233     %property(Style, GetStyle, doc="See `GetStyle`");
 
 234     %property(Title, GetTitle, SetTitle, doc="See `GetTitle` and `SetTitle`");
 
 238 //---------------------------------------------------------------------------
 
 241 MustHaveApp(wxMenuBar);
 
 243 class wxMenuBar : public wxWindow
 
 246     %pythonAppend wxMenuBar         "self._setOORInfo(self)"
 
 247     %typemap(out) wxMenuBar*;    // turn off this typemap
 
 249     wxMenuBar(long style = 0);
 
 251     // Turn it back on again
 
 252     %typemap(out) wxMenuBar* { $result = wxPyMake_wxObject($1, $owner); }
 
 254     // append a menu to the end of menubar, return True if ok
 
 255     virtual bool Append(wxMenu *menu, const wxString& title);
 
 257     // insert a menu before the given position into the menubar, return True
 
 259     virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title);
 
 262     // get the number of menus in the menu bar
 
 263     size_t GetMenuCount() const;
 
 265     // get the menu at given position
 
 266     wxMenu *GetMenu(size_t pos) const;
 
 268     // replace the menu at given position with another one, returns the
 
 269     // previous menu (which should be deleted by the caller)
 
 270     virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
 
 272     // delete the menu at given position from the menu bar, return the pointer
 
 273     // to the menu (which should be  deleted by the caller)
 
 274     virtual wxMenu *Remove(size_t pos);
 
 276     // enable or disable a submenu
 
 277     virtual void EnableTop(size_t pos, bool enable);
 
 279     // is the menu enabled?
 
 280     virtual bool IsEnabledTop(size_t pos) const;
 
 282     // get or change the label of the menu at given position
 
 283     virtual void SetLabelTop(size_t pos, const wxString& label);
 
 284     virtual wxString GetLabelTop(size_t pos) const;
 
 287     // by menu and item names, returns wxNOT_FOUND if not found or id of the
 
 289     virtual int FindMenuItem(const wxString& menu, const wxString& item) const;
 
 291     // find item by id (in any menu), returns NULL if not found
 
 293     // if menu is !NULL, it will be filled with wxMenu this item belongs to
 
 294     %Rename(FindItemById, virtual wxMenuItem*, FindItem(int id /*, wxMenu **menu = NULL*/) const);
 
 296     // find menu by its caption, return wxNOT_FOUND on failure
 
 297     int FindMenu(const wxString& title);
 
 300     // all these functions just use FindItem() and then call an appropriate
 
 303     // NB: under MSW, these methods can only be used after the menubar had
 
 304     //     been attached to the frame
 
 306     void Enable(int id, bool enable);
 
 307     void Check(int id, bool check);
 
 308     bool IsChecked(int id) const;
 
 309     bool IsEnabled(int id) const;
 
 310     // TODO: bool IsEnabled() const;
 
 312     void SetLabel(int id, const wxString &label);
 
 313     wxString GetLabel(int id) const;
 
 315     void SetHelpString(int id, const wxString& helpString);
 
 316     wxString GetHelpString(int id) const;
 
 319     // get the frame we are attached to (may return NULL)
 
 320     wxFrame *GetFrame() const;
 
 322     // returns True if we're attached to a frame
 
 323     bool IsAttached() const;
 
 325     // associate the menubar with the frame
 
 326     virtual void Attach(wxFrame *frame);
 
 328     // called before deleting the menubar normally
 
 329     virtual void Detach();
 
 331     // update all menu item states in all menus
 
 332     virtual void UpdateMenus();
 
 335     static void SetAutoWindowMenu( bool enable );
 
 336     static bool GetAutoWindowMenu();
 
 339         static void SetAutoWindowMenu( bool enable ) {}
 
 340         static bool GetAutoWindowMenu() { return false; }
 
 346             """Return a list of (menu, label) items for the menus in the MenuBar. """
 
 347             return [(self.GetMenu(i), self.GetLabelTop(i)) 
 
 348                     for i in range(self.GetMenuCount())]
 
 350         def SetMenus(self, items):
 
 351             """Clear and add new menus to the MenuBar from a list of (menu, label) items. """
 
 352             for i in range(self.GetMenuCount()-1, -1, -1):
 
 358     %property(Frame, GetFrame, doc="See `GetFrame`");
 
 359     %property(Menu, GetMenu, doc="See `GetMenu`");
 
 360     %property(MenuCount, GetMenuCount, doc="See `GetMenuCount`");
 
 361     %property(Menus, GetMenus, SetMenus, doc="See `GetMenus` and `SetMenus`");
 
 364 //---------------------------------------------------------------------------
 
 367 class wxMenuItem : public wxObject {
 
 369     // turn off this typemap
 
 370     %typemap(out) wxMenuItem*;    
 
 372     wxMenuItem(wxMenu* parentMenu=NULL, int id=wxID_ANY,
 
 373                const wxString& text = wxPyEmptyString,
 
 374                const wxString& help = wxPyEmptyString,
 
 375                wxItemKind kind = wxITEM_NORMAL,
 
 376                wxMenu* subMenu = NULL);
 
 379     // Turn it back on again
 
 380     %typemap(out) wxEvtHandler* { $result = wxPyMake_wxObject($1, $owner); }
 
 384     wxMenu *GetMenu() const;
 
 385     void SetMenu(wxMenu* menu);
 
 390     bool IsSeparator() const;
 
 392     // the item's text (or name)
 
 394     // NB: the item's text includes the accelerators and mnemonics info (if
 
 395     //     any), i.e. it may contain '&' or '_' or "\t..." and thus is
 
 396     //     different from the item's label which only contains the text shown
 
 398     virtual void SetText(const wxString& str);
 
 399     wxString GetLabel() const;
 
 400     const wxString& GetText() const;
 
 402     // get the label from text 
 
 403     static wxString GetLabelFromText(const wxString& text);
 
 405     // what kind of menu item we are
 
 406     wxItemKind GetKind() const;
 
 407     void SetKind(wxItemKind kind);
 
 409     virtual void SetCheckable(bool checkable);
 
 410     bool IsCheckable() const;
 
 412     bool IsSubMenu() const;
 
 413     void SetSubMenu(wxMenu *menu);
 
 414     wxMenu *GetSubMenu() const;
 
 417     virtual void Enable(bool enable = true);
 
 418     virtual bool IsEnabled() const;
 
 420     virtual void Check(bool check = true);
 
 421     virtual bool IsChecked() const;
 
 424     // help string (displayed in the status bar by default)
 
 425     void SetHelp(const wxString& str);
 
 426     const wxString& GetHelp() const;
 
 428     // get our accelerator or NULL (caller must delete the pointer)
 
 429     virtual wxAcceleratorEntry *GetAccel() const;
 
 431     // set the accel for this item - this may also be done indirectly with
 
 433     virtual void SetAccel(wxAcceleratorEntry *accel);
 
 435     void SetBitmap(const wxBitmap& bitmap);
 
 436     const wxBitmap& GetBitmap();
 
 438     // wxOwnerDrawn methods
 
 440     void SetFont(const wxFont& font);
 
 442     void SetTextColour(const wxColour& colText);
 
 443     wxColour GetTextColour();
 
 444     void SetBackgroundColour(const wxColour& colBack);
 
 445     wxColour GetBackgroundColour();
 
 446     void SetBitmaps(const wxBitmap& bmpChecked,
 
 447                     const wxBitmap& bmpUnchecked = wxNullBitmap);
 
 449     void SetDisabledBitmap( const wxBitmap& bmpDisabled );
 
 450     const wxBitmap& GetDisabledBitmap() const;
 
 452     void SetMarginWidth(int nWidth);
 
 453     int GetMarginWidth();
 
 454     static int GetDefaultMarginWidth();
 
 457     // switch on/off owner-drawing the item
 
 458     void SetOwnerDrawn(bool ownerDrawn = true);
 
 459     void ResetOwnerDrawn();
 
 462         void SetFont(const wxFont& font) {}
 
 463         wxFont GetFont() { return wxNullFont; }
 
 464         void SetTextColour(const wxColour& colText) {}
 
 465         wxColour GetTextColour() { return wxNullColour; }
 
 466         void SetBackgroundColour(const wxColour& colBack) {}
 
 467         wxColour GetBackgroundColour() { return wxNullColour; }
 
 469         void SetBitmaps(const wxBitmap& bmpChecked,
 
 470                         const wxBitmap& bmpUnchecked = wxNullBitmap)
 
 471             { self->SetBitmap( bmpChecked ); }
 
 473         void SetDisabledBitmap( const wxBitmap& bmpDisabled ) {}
 
 474         const wxBitmap& GetDisabledBitmap() const { return wxNullBitmap; }
 
 476         void SetMarginWidth(int nWidth) {}
 
 477         int GetMarginWidth() { return 0; }
 
 478         static int GetDefaultMarginWidth() { return 0; }
 
 479         bool IsOwnerDrawn() { return false; }
 
 480         void SetOwnerDrawn(bool ownerDrawn = true) {}
 
 481         void ResetOwnerDrawn() {}
 
 485     %property(Accel, GetAccel, SetAccel, doc="See `GetAccel` and `SetAccel`");
 
 486     %property(BackgroundColour, GetBackgroundColour, SetBackgroundColour, doc="See `GetBackgroundColour` and `SetBackgroundColour`");
 
 487     %property(Bitmap, GetBitmap, SetBitmap, doc="See `GetBitmap` and `SetBitmap`");
 
 488     %property(DisabledBitmap, GetDisabledBitmap, SetDisabledBitmap, doc="See `GetDisabledBitmap` and `SetDisabledBitmap`");
 
 489     %property(Font, GetFont, SetFont, doc="See `GetFont` and `SetFont`");
 
 490     %property(Help, GetHelp, SetHelp, doc="See `GetHelp` and `SetHelp`");
 
 491     %property(Id, GetId, SetId, doc="See `GetId` and `SetId`");
 
 492     %property(Kind, GetKind, SetKind, doc="See `GetKind` and `SetKind`");
 
 493     %property(Label, GetLabel, doc="See `GetLabel`");
 
 494     %property(MarginWidth, GetMarginWidth, SetMarginWidth, doc="See `GetMarginWidth` and `SetMarginWidth`");
 
 495     %property(Menu, GetMenu, SetMenu, doc="See `GetMenu` and `SetMenu`");
 
 496     %property(SubMenu, GetSubMenu, SetSubMenu, doc="See `GetSubMenu` and `SetSubMenu`");
 
 497     %property(Text, GetText, SetText, doc="See `GetText` and `SetText`");
 
 498     %property(TextColour, GetTextColour, SetTextColour, doc="See `GetTextColour` and `SetTextColour`");
 
 502 //---------------------------------------------------------------------------
 
 503 //---------------------------------------------------------------------------