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));
 
  58     // the most generic form of Append() - append anything
 
  59     %Rename(AppendItem, wxMenuItem*, Append(wxMenuItem *item));
 
  61     // insert a break in the menu (only works when appending the items, not
 
  65     // insert an item before given position
 
  66     %Rename(InsertItem, wxMenuItem*, Insert(size_t pos, wxMenuItem *item));
 
  68     // insert an item before given position
 
  69     wxMenuItem* Insert(size_t pos,
 
  72                        const wxString& help = wxPyEmptyString,
 
  73                        wxItemKind kind = wxITEM_NORMAL);
 
  76     wxMenuItem* InsertSeparator(size_t pos);
 
  78     // insert a check item
 
  79     wxMenuItem* InsertCheckItem(size_t pos,
 
  82                                 const wxString& help = wxPyEmptyString);
 
  84     // insert a radio item
 
  85     wxMenuItem* InsertRadioItem(size_t pos,
 
  88                                 const wxString& help = wxPyEmptyString);
 
  91     %Rename(InsertMenu, wxMenuItem*, Insert(size_t pos,
 
  95                                          const wxString& help = wxPyEmptyString));
 
  97     // prepend an item to the menu
 
  98     %Rename(PrependItem,  wxMenuItem*, Prepend(wxMenuItem *item));
 
 100     // prepend any item to the menu
 
 101     wxMenuItem* Prepend(int id,
 
 102                         const wxString& text,
 
 103                         const wxString& help = wxPyEmptyString,
 
 104                         wxItemKind kind = wxITEM_NORMAL);
 
 106     // prepend a separator
 
 107     wxMenuItem*  PrependSeparator();
 
 109     // prepend a check item
 
 110     wxMenuItem* PrependCheckItem(int id,
 
 111                                  const wxString& text,
 
 112                                  const wxString& help = wxPyEmptyString);
 
 114     // prepend a radio item
 
 115     wxMenuItem*  PrependRadioItem(int id,
 
 116                                   const wxString& text,
 
 117                                   const wxString& help = wxPyEmptyString);
 
 120     %Rename(PrependMenu,  wxMenuItem*, Prepend(int id,
 
 121                                            const wxString& text,
 
 123                                            const wxString& help = wxPyEmptyString));
 
 125     // detach an item from the menu, but don't delete it so that it can be
 
 126     // added back later (but if it's not, the caller is responsible for
 
 128     wxMenuItem *Remove(int id);
 
 129     %Rename(RemoveItem,  wxMenuItem*, Remove(wxMenuItem *item));
 
 131     // delete an item from the menu (submenus are not destroyed by this
 
 132     // function, see Destroy)
 
 134     %Rename(DeleteItem,  bool, Delete(wxMenuItem *item));
 
 136     // delete the item from menu and destroy it (if it's a submenu)
 
 137     %extend { void Destroy() { delete self; } }
 
 138     %Rename(DestroyId,  bool, Destroy(int id));
 
 139     %Rename(DestroyItem,  bool, Destroy(wxMenuItem *item));
 
 143     size_t GetMenuItemCount() const;
 
 145         PyObject* GetMenuItems() {
 
 146             wxMenuItemList& list = self->GetMenuItems();
 
 147             return wxPy_ConvertList(&list);
 
 152     int FindItem(const wxString& item) const;
 
 153     %Rename(FindItemById, wxMenuItem*, FindItem(int id /*, wxMenu **menu = NULL*/) const);
 
 156     wxMenuItem* FindItemByPosition(size_t position) const;
 
 158     // get/set items attributes
 
 159     void Enable(int id, bool enable);
 
 160     bool IsEnabled(int id) const;
 
 162     void Check(int id, bool check);
 
 163     bool IsChecked(int id) const;
 
 165     void SetLabel(int id, const wxString& label);
 
 166     wxString GetLabel(int id) const;
 
 168     virtual void SetHelpString(int id, const wxString& helpString);
 
 169     virtual wxString GetHelpString(int id) const;
 
 173     virtual void SetTitle(const wxString& title);
 
 174     const wxString GetTitle() const;
 
 177     void SetEventHandler(wxEvtHandler *handler);
 
 178     wxEvtHandler *GetEventHandler() const;
 
 181     void SetInvokingWindow(wxWindow *win);
 
 182     wxWindow *GetInvokingWindow() const;
 
 185     long GetStyle() const { return m_style; }
 
 188     // Updates the UI for a menu and all submenus recursively. source is the
 
 189     // object that has the update event handlers defined for it. If NULL, the
 
 190     // menu or associated window will be used.
 
 191     void UpdateUI(wxEvtHandler* source = NULL);
 
 193     // get the menu bar this menu is attached to (may be NULL, always NULL for
 
 195     wxMenuBar *GetMenuBar() const;
 
 197 // TODO:  Should these be exposed?
 
 198     // called when the menu is attached/detached to/from a menu bar
 
 199     virtual void Attach(wxMenuBarBase *menubar);
 
 200     virtual void Detach();
 
 202     // is the menu attached to a menu bar (or is it a popup one)?
 
 203     bool IsAttached() const;
 
 205     // set/get the parent of this menu
 
 206     void SetParent(wxMenu *parent);
 
 207     wxMenu *GetParent() const;
 
 210 //---------------------------------------------------------------------------
 
 213 MustHaveApp(wxMenuBar);
 
 215 class wxMenuBar : public wxWindow
 
 218     %pythonAppend wxMenuBar         "self._setOORInfo(self)"
 
 219     %typemap(out) wxMenuBar*;    // turn off this typemap
 
 221     wxMenuBar(long style = 0);
 
 223     // Turn it back on again
 
 224     %typemap(out) wxMenuBar* { $result = wxPyMake_wxObject($1, $owner); }
 
 226     // append a menu to the end of menubar, return True if ok
 
 227     virtual bool Append(wxMenu *menu, const wxString& title);
 
 229     // insert a menu before the given position into the menubar, return True
 
 231     virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title);
 
 234     // get the number of menus in the menu bar
 
 235     size_t GetMenuCount() const;
 
 237     // get the menu at given position
 
 238     wxMenu *GetMenu(size_t pos) const;
 
 240     // replace the menu at given position with another one, returns the
 
 241     // previous menu (which should be deleted by the caller)
 
 242     virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
 
 244     // delete the menu at given position from the menu bar, return the pointer
 
 245     // to the menu (which should be  deleted by the caller)
 
 246     virtual wxMenu *Remove(size_t pos);
 
 248     // enable or disable a submenu
 
 249     virtual void EnableTop(size_t pos, bool enable);
 
 251     // is the menu enabled?
 
 252     virtual bool IsEnabledTop(size_t pos) const;
 
 254     // get or change the label of the menu at given position
 
 255     virtual void SetLabelTop(size_t pos, const wxString& label);
 
 256     virtual wxString GetLabelTop(size_t pos) const;
 
 259     // by menu and item names, returns wxNOT_FOUND if not found or id of the
 
 261     virtual int FindMenuItem(const wxString& menu, const wxString& item) const;
 
 263     // find item by id (in any menu), returns NULL if not found
 
 265     // if menu is !NULL, it will be filled with wxMenu this item belongs to
 
 266     %Rename(FindItemById, virtual wxMenuItem*, FindItem(int id /*, wxMenu **menu = NULL*/) const);
 
 268     // find menu by its caption, return wxNOT_FOUND on failure
 
 269     int FindMenu(const wxString& title);
 
 272     // all these functions just use FindItem() and then call an appropriate
 
 275     // NB: under MSW, these methods can only be used after the menubar had
 
 276     //     been attached to the frame
 
 278     void Enable(int id, bool enable);
 
 279     void Check(int id, bool check);
 
 280     bool IsChecked(int id) const;
 
 281     bool IsEnabled(int id) const;
 
 282     // TODO: bool IsEnabled() const;
 
 284     void SetLabel(int id, const wxString &label);
 
 285     wxString GetLabel(int id) const;
 
 287     void SetHelpString(int id, const wxString& helpString);
 
 288     wxString GetHelpString(int id) const;
 
 291     // get the frame we are attached to (may return NULL)
 
 292     wxFrame *GetFrame() const;
 
 294     // returns True if we're attached to a frame
 
 295     bool IsAttached() const;
 
 297     // associate the menubar with the frame
 
 298     virtual void Attach(wxFrame *frame);
 
 300     // called before deleting the menubar normally
 
 301     virtual void Detach();
 
 304     static void SetAutoWindowMenu( bool enable );
 
 305     static bool GetAutoWindowMenu();
 
 308         static void SetAutoWindowMenu( bool enable ) {}
 
 309         static bool GetAutoWindowMenu() { return false; }
 
 314 //---------------------------------------------------------------------------
 
 317 class wxMenuItem : public wxObject {
 
 319     wxMenuItem(wxMenu* parentMenu=NULL, int id=wxID_ANY,
 
 320                const wxString& text = wxPyEmptyString,
 
 321                const wxString& help = wxPyEmptyString,
 
 322                wxItemKind kind = wxITEM_NORMAL,
 
 323                wxMenu* subMenu = NULL);
 
 326     wxMenu *GetMenu() const;
 
 327     void SetMenu(wxMenu* menu);
 
 332     bool IsSeparator() const;
 
 334     // the item's text (or name)
 
 336     // NB: the item's text includes the accelerators and mnemonics info (if
 
 337     //     any), i.e. it may contain '&' or '_' or "\t..." and thus is
 
 338     //     different from the item's label which only contains the text shown
 
 340     virtual void SetText(const wxString& str);
 
 341     wxString GetLabel() const;
 
 342     const wxString& GetText() const;
 
 344     // get the label from text 
 
 345     static wxString GetLabelFromText(const wxString& text);
 
 347     // what kind of menu item we are
 
 348     wxItemKind GetKind() const;
 
 349     void SetKind(wxItemKind kind);
 
 351     virtual void SetCheckable(bool checkable);
 
 352     bool IsCheckable() const;
 
 354     bool IsSubMenu() const;
 
 355     void SetSubMenu(wxMenu *menu);
 
 356     wxMenu *GetSubMenu() const;
 
 359     virtual void Enable(bool enable = true);
 
 360     virtual bool IsEnabled() const;
 
 362     virtual void Check(bool check = true);
 
 363     virtual bool IsChecked() const;
 
 366     // help string (displayed in the status bar by default)
 
 367     void SetHelp(const wxString& str);
 
 368     const wxString& GetHelp() const;
 
 370     // get our accelerator or NULL (caller must delete the pointer)
 
 371     virtual wxAcceleratorEntry *GetAccel() const;
 
 373     // set the accel for this item - this may also be done indirectly with
 
 375     virtual void SetAccel(wxAcceleratorEntry *accel);
 
 378     // wxOwnerDrawn methods
 
 380     void SetFont(const wxFont& font);
 
 382     void SetTextColour(const wxColour& colText);
 
 383     wxColour GetTextColour();
 
 384     void SetBackgroundColour(const wxColour& colBack);
 
 385     wxColour GetBackgroundColour();
 
 386     void SetBitmaps(const wxBitmap& bmpChecked,
 
 387                     const wxBitmap& bmpUnchecked = wxNullBitmap);
 
 389     void SetDisabledBitmap( const wxBitmap& bmpDisabled );
 
 390     const wxBitmap& GetDisabledBitmap() const;
 
 392     void SetMarginWidth(int nWidth);
 
 393     int GetMarginWidth();
 
 394     static int GetDefaultMarginWidth();
 
 397     // switch on/off owner-drawing the item
 
 398     void SetOwnerDrawn(bool ownerDrawn = true);
 
 399     void ResetOwnerDrawn();
 
 402         void SetFont(const wxFont& font) {}
 
 403         wxFont GetFont() { return wxNullFont; }
 
 404         void SetTextColour(const wxColour& colText) {}
 
 405         wxColour GetTextColour() { return wxNullColour; }
 
 406         void SetBackgroundColour(const wxColour& colBack) {}
 
 407         wxColour GetBackgroundColour() { return wxNullColour; }
 
 408         void SetBitmaps(const wxBitmap& bmpChecked,
 
 409                         const wxBitmap& bmpUnchecked = wxNullBitmap) {}
 
 411         void SetDisabledBitmap( const wxBitmap& bmpDisabled ) {}
 
 412         const wxBitmap& GetDisabledBitmap() const { return wxNullBitmap; }
 
 414         void SetMarginWidth(int nWidth) {}
 
 415         int GetMarginWidth() { return 0; }
 
 416         static int GetDefaultMarginWidth() { return 0; }
 
 417         bool IsOwnerDrawn() { return false; }
 
 418         void SetOwnerDrawn(bool ownerDrawn = true) {}
 
 419         void ResetOwnerDrawn() {}
 
 423     void SetBitmap(const wxBitmap& bitmap);
 
 424     const wxBitmap& GetBitmap();
 
 427 //---------------------------------------------------------------------------
 
 428 //---------------------------------------------------------------------------