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,
 
  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));
 
  59     %disownarg(wxMenuItem*);
 
  60     // the most generic form of Append() - append anything
 
  61     %Rename(AppendItem, wxMenuItem*, Append(wxMenuItem *item));
 
  62     // insert an item before given position
 
  63     %Rename(InsertItem, wxMenuItem*, Insert(size_t pos, wxMenuItem *item));
 
  64     // prepend an item to the menu
 
  65     %Rename(PrependItem,  wxMenuItem*, Prepend(wxMenuItem *item));
 
  66     %cleardisown(wxMenuItem*);
 
  69     // insert a break in the menu (only works when appending the items, not
 
  73     // insert an item before given position
 
  74     wxMenuItem* Insert(size_t pos,
 
  77                        const wxString& help = wxPyEmptyString,
 
  78                        wxItemKind kind = wxITEM_NORMAL);
 
  81     wxMenuItem* InsertSeparator(size_t pos);
 
  83     // insert a check item
 
  84     wxMenuItem* InsertCheckItem(size_t pos,
 
  87                                 const wxString& help = wxPyEmptyString);
 
  89     // insert a radio item
 
  90     wxMenuItem* InsertRadioItem(size_t pos,
 
  93                                 const wxString& help = wxPyEmptyString);
 
  96     %Rename(InsertMenu, wxMenuItem*, Insert(size_t pos,
 
 100                                          const wxString& help = wxPyEmptyString));
 
 102     // prepend any item to the menu
 
 103     wxMenuItem* Prepend(int id,
 
 104                         const wxString& text,
 
 105                         const wxString& help = wxPyEmptyString,
 
 106                         wxItemKind kind = wxITEM_NORMAL);
 
 108     // prepend a separator
 
 109     wxMenuItem*  PrependSeparator();
 
 111     // prepend a check item
 
 112     wxMenuItem* PrependCheckItem(int id,
 
 113                                  const wxString& text,
 
 114                                  const wxString& help = wxPyEmptyString);
 
 116     // prepend a radio item
 
 117     wxMenuItem*  PrependRadioItem(int id,
 
 118                                   const wxString& text,
 
 119                                   const wxString& help = wxPyEmptyString);
 
 122     %Rename(PrependMenu,  wxMenuItem*, Prepend(int id,
 
 123                                            const wxString& text,
 
 125                                            const wxString& help = wxPyEmptyString));
 
 128     // detach an item from the menu, but don't delete it so that it can be
 
 129     // added back later (but if it's not, the caller is responsible for
 
 132     wxMenuItem *Remove(int id);
 
 133     %Rename(RemoveItem,  wxMenuItem*, Remove(wxMenuItem *item));
 
 135     // delete an item from the menu (submenus are not destroyed by this
 
 136     // function, see Destroy)
 
 138     %Rename(DeleteItem,  bool, Delete(wxMenuItem *item));
 
 140     %pythonAppend Destroy "args[0].thisown = 0"
 
 141     %extend { void Destroy() { delete self; } }
 
 143     // delete the item from menu and destroy it (if it's a submenu)
 
 144     %Rename(DestroyId,  bool, Destroy(int id));
 
 145     %Rename(DestroyItem,  bool, Destroy(wxMenuItem *item));
 
 149     size_t GetMenuItemCount() const;
 
 151         PyObject* GetMenuItems() {
 
 152             wxMenuItemList& list = self->GetMenuItems();
 
 153             return wxPy_ConvertList(&list);
 
 158     int FindItem(const wxString& item) const;
 
 159     %Rename(FindItemById, wxMenuItem*, FindItem(int id /*, wxMenu **menu = NULL*/) const);
 
 162     wxMenuItem* FindItemByPosition(size_t position) const;
 
 164     // get/set items attributes
 
 165     void Enable(int id, bool enable);
 
 166     bool IsEnabled(int id) const;
 
 168     void Check(int id, bool check);
 
 169     bool IsChecked(int id) const;
 
 171     void SetLabel(int id, const wxString& label);
 
 172     wxString GetLabel(int id) const;
 
 174     virtual void SetHelpString(int id, const wxString& helpString);
 
 175     virtual wxString GetHelpString(int id) const;
 
 179     virtual void SetTitle(const wxString& title);
 
 180     const wxString GetTitle() const;
 
 183     void SetEventHandler(wxEvtHandler *handler);
 
 184     wxEvtHandler *GetEventHandler() const;
 
 187     void SetInvokingWindow(wxWindow *win);
 
 188     wxWindow *GetInvokingWindow() const;
 
 191     long GetStyle() const { return m_style; }
 
 194     // Updates the UI for a menu and all submenus recursively. source is the
 
 195     // object that has the update event handlers defined for it. If NULL, the
 
 196     // menu or associated window will be used.
 
 197     void UpdateUI(wxEvtHandler* source = NULL);
 
 199     // get the menu bar this menu is attached to (may be NULL, always NULL for
 
 201     wxMenuBar *GetMenuBar() const;
 
 203 // TODO:  Should these be exposed?
 
 204     // called when the menu is attached/detached to/from a menu bar
 
 205     virtual void Attach(wxMenuBarBase *menubar);
 
 206     virtual void Detach();
 
 208     // is the menu attached to a menu bar (or is it a popup one)?
 
 209     bool IsAttached() const;
 
 211     // set/get the parent of this menu
 
 212     void SetParent(wxMenu *parent);
 
 213     wxMenu *GetParent() const;
 
 216 //---------------------------------------------------------------------------
 
 219 MustHaveApp(wxMenuBar);
 
 221 class wxMenuBar : public wxWindow
 
 224     %pythonAppend wxMenuBar         "self._setOORInfo(self)"
 
 225     %typemap(out) wxMenuBar*;    // turn off this typemap
 
 227     wxMenuBar(long style = 0);
 
 229     // Turn it back on again
 
 230     %typemap(out) wxMenuBar* { $result = wxPyMake_wxObject($1, $owner); }
 
 232     // append a menu to the end of menubar, return True if ok
 
 233     virtual bool Append(wxMenu *menu, const wxString& title);
 
 235     // insert a menu before the given position into the menubar, return True
 
 237     virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title);
 
 240     // get the number of menus in the menu bar
 
 241     size_t GetMenuCount() const;
 
 243     // get the menu at given position
 
 244     wxMenu *GetMenu(size_t pos) const;
 
 246     // replace the menu at given position with another one, returns the
 
 247     // previous menu (which should be deleted by the caller)
 
 248     virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
 
 250     // delete the menu at given position from the menu bar, return the pointer
 
 251     // to the menu (which should be  deleted by the caller)
 
 252     virtual wxMenu *Remove(size_t pos);
 
 254     // enable or disable a submenu
 
 255     virtual void EnableTop(size_t pos, bool enable);
 
 257     // is the menu enabled?
 
 258     virtual bool IsEnabledTop(size_t pos) const;
 
 260     // get or change the label of the menu at given position
 
 261     virtual void SetLabelTop(size_t pos, const wxString& label);
 
 262     virtual wxString GetLabelTop(size_t pos) const;
 
 265     // by menu and item names, returns wxNOT_FOUND if not found or id of the
 
 267     virtual int FindMenuItem(const wxString& menu, const wxString& item) const;
 
 269     // find item by id (in any menu), returns NULL if not found
 
 271     // if menu is !NULL, it will be filled with wxMenu this item belongs to
 
 272     %Rename(FindItemById, virtual wxMenuItem*, FindItem(int id /*, wxMenu **menu = NULL*/) const);
 
 274     // find menu by its caption, return wxNOT_FOUND on failure
 
 275     int FindMenu(const wxString& title);
 
 278     // all these functions just use FindItem() and then call an appropriate
 
 281     // NB: under MSW, these methods can only be used after the menubar had
 
 282     //     been attached to the frame
 
 284     void Enable(int id, bool enable);
 
 285     void Check(int id, bool check);
 
 286     bool IsChecked(int id) const;
 
 287     bool IsEnabled(int id) const;
 
 288     // TODO: bool IsEnabled() const;
 
 290     void SetLabel(int id, const wxString &label);
 
 291     wxString GetLabel(int id) const;
 
 293     void SetHelpString(int id, const wxString& helpString);
 
 294     wxString GetHelpString(int id) const;
 
 297     // get the frame we are attached to (may return NULL)
 
 298     wxFrame *GetFrame() const;
 
 300     // returns True if we're attached to a frame
 
 301     bool IsAttached() const;
 
 303     // associate the menubar with the frame
 
 304     virtual void Attach(wxFrame *frame);
 
 306     // called before deleting the menubar normally
 
 307     virtual void Detach();
 
 310     static void SetAutoWindowMenu( bool enable );
 
 311     static bool GetAutoWindowMenu();
 
 314         static void SetAutoWindowMenu( bool enable ) {}
 
 315         static bool GetAutoWindowMenu() { return false; }
 
 320 //---------------------------------------------------------------------------
 
 323 class wxMenuItem : public wxObject {
 
 325     wxMenuItem(wxMenu* parentMenu=NULL, int id=wxID_ANY,
 
 326                const wxString& text = wxPyEmptyString,
 
 327                const wxString& help = wxPyEmptyString,
 
 328                wxItemKind kind = wxITEM_NORMAL,
 
 329                wxMenu* subMenu = NULL);
 
 333     wxMenu *GetMenu() const;
 
 334     void SetMenu(wxMenu* menu);
 
 339     bool IsSeparator() const;
 
 341     // the item's text (or name)
 
 343     // NB: the item's text includes the accelerators and mnemonics info (if
 
 344     //     any), i.e. it may contain '&' or '_' or "\t..." and thus is
 
 345     //     different from the item's label which only contains the text shown
 
 347     virtual void SetText(const wxString& str);
 
 348     wxString GetLabel() const;
 
 349     const wxString& GetText() const;
 
 351     // get the label from text 
 
 352     static wxString GetLabelFromText(const wxString& text);
 
 354     // what kind of menu item we are
 
 355     wxItemKind GetKind() const;
 
 356     void SetKind(wxItemKind kind);
 
 358     virtual void SetCheckable(bool checkable);
 
 359     bool IsCheckable() const;
 
 361     bool IsSubMenu() const;
 
 362     void SetSubMenu(wxMenu *menu);
 
 363     wxMenu *GetSubMenu() const;
 
 366     virtual void Enable(bool enable = true);
 
 367     virtual bool IsEnabled() const;
 
 369     virtual void Check(bool check = true);
 
 370     virtual bool IsChecked() const;
 
 373     // help string (displayed in the status bar by default)
 
 374     void SetHelp(const wxString& str);
 
 375     const wxString& GetHelp() const;
 
 377     // get our accelerator or NULL (caller must delete the pointer)
 
 378     virtual wxAcceleratorEntry *GetAccel() const;
 
 380     // set the accel for this item - this may also be done indirectly with
 
 382     virtual void SetAccel(wxAcceleratorEntry *accel);
 
 384     void SetBitmap(const wxBitmap& bitmap);
 
 385     const wxBitmap& GetBitmap();
 
 387     // wxOwnerDrawn methods
 
 389     void SetFont(const wxFont& font);
 
 391     void SetTextColour(const wxColour& colText);
 
 392     wxColour GetTextColour();
 
 393     void SetBackgroundColour(const wxColour& colBack);
 
 394     wxColour GetBackgroundColour();
 
 395     void SetBitmaps(const wxBitmap& bmpChecked,
 
 396                     const wxBitmap& bmpUnchecked = wxNullBitmap);
 
 398     void SetDisabledBitmap( const wxBitmap& bmpDisabled );
 
 399     const wxBitmap& GetDisabledBitmap() const;
 
 401     void SetMarginWidth(int nWidth);
 
 402     int GetMarginWidth();
 
 403     static int GetDefaultMarginWidth();
 
 406     // switch on/off owner-drawing the item
 
 407     void SetOwnerDrawn(bool ownerDrawn = true);
 
 408     void ResetOwnerDrawn();
 
 411         void SetFont(const wxFont& font) {}
 
 412         wxFont GetFont() { return wxNullFont; }
 
 413         void SetTextColour(const wxColour& colText) {}
 
 414         wxColour GetTextColour() { return wxNullColour; }
 
 415         void SetBackgroundColour(const wxColour& colBack) {}
 
 416         wxColour GetBackgroundColour() { return wxNullColour; }
 
 418         void SetBitmaps(const wxBitmap& bmpChecked,
 
 419                         const wxBitmap& bmpUnchecked = wxNullBitmap)
 
 420             { self->SetBitmap( bmpChecked ); }
 
 422         void SetDisabledBitmap( const wxBitmap& bmpDisabled ) {}
 
 423         const wxBitmap& GetDisabledBitmap() const { return wxNullBitmap; }
 
 425         void SetMarginWidth(int nWidth) {}
 
 426         int GetMarginWidth() { return 0; }
 
 427         static int GetDefaultMarginWidth() { return 0; }
 
 428         bool IsOwnerDrawn() { return false; }
 
 429         void SetOwnerDrawn(bool ownerDrawn = true) {}
 
 430         void ResetOwnerDrawn() {}
 
 435 //---------------------------------------------------------------------------
 
 436 //---------------------------------------------------------------------------