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 wxMenu(const wxString& title = wxPyEmptyString, long style = 0);
29 // append any kind of item (normal/check/radio/separator)
30 wxMenuItem* Append(int id,
32 const wxString& help = wxPyEmptyString,
33 wxItemKind kind = wxITEM_NORMAL);
35 // append a separator to the menu
36 wxMenuItem* AppendSeparator();
38 // append a check item
39 wxMenuItem* AppendCheckItem(int id,
41 const wxString& help = wxPyEmptyString);
43 // append a radio item
44 wxMenuItem* AppendRadioItem(int id,
46 const wxString& help = wxPyEmptyString);
48 %name(AppendMenu) wxMenuItem* Append(int id,
51 const wxString& help = wxPyEmptyString);
53 // the most generic form of Append() - append anything
54 %name(AppendItem) wxMenuItem* Append(wxMenuItem *item);
56 // insert a break in the menu (only works when appending the items, not
60 // insert an item before given position
61 %name(InsertItem) wxMenuItem* Insert(size_t pos, wxMenuItem *item);
63 // insert an item before given position
64 wxMenuItem* Insert(size_t pos,
67 const wxString& help = wxPyEmptyString,
68 wxItemKind kind = wxITEM_NORMAL);
71 wxMenuItem* InsertSeparator(size_t pos);
73 // insert a check item
74 wxMenuItem* InsertCheckItem(size_t pos,
77 const wxString& help = wxPyEmptyString);
79 // insert a radio item
80 wxMenuItem* InsertRadioItem(size_t pos,
83 const wxString& help = wxPyEmptyString);
86 %name(InsertMenu) wxMenuItem* Insert(size_t pos,
90 const wxString& help = wxPyEmptyString);
92 // prepend an item to the menu
93 %name(PrependItem) wxMenuItem* Prepend(wxMenuItem *item);
95 // prepend any item to the menu
96 wxMenuItem* Prepend(int id,
98 const wxString& help = wxPyEmptyString,
99 wxItemKind kind = wxITEM_NORMAL);
101 // prepend a separator
102 wxMenuItem* PrependSeparator();
104 // prepend a check item
105 wxMenuItem* PrependCheckItem(int id,
106 const wxString& text,
107 const wxString& help = wxPyEmptyString);
109 // prepend a radio item
110 wxMenuItem* PrependRadioItem(int id,
111 const wxString& text,
112 const wxString& help = wxPyEmptyString);
115 %name(PrependMenu) wxMenuItem* Prepend(int id,
116 const wxString& text,
118 const wxString& help = wxPyEmptyString);
120 // detach an item from the menu, but don't delete it so that it can be
121 // added back later (but if it's not, the caller is responsible for
123 wxMenuItem *Remove(int id);
124 %name(RemoveItem) wxMenuItem *Remove(wxMenuItem *item);
126 // delete an item from the menu (submenus are not destroyed by this
127 // function, see Destroy)
129 %name(DeleteItem) bool Delete(wxMenuItem *item);
131 // delete the item from menu and destroy it (if it's a submenu)
132 %extend { void Destroy() { delete self; } }
133 %name(DestroyId) bool Destroy(int id);
134 %name(DestroyItem) bool Destroy(wxMenuItem *item);
138 size_t GetMenuItemCount() const;
140 PyObject* GetMenuItems() {
141 wxMenuItemList& list = self->GetMenuItems();
142 return wxPy_ConvertList(&list);
147 int FindItem(const wxString& item) const;
148 %name(FindItemById) wxMenuItem* FindItem(int id /*, wxMenu **menu = NULL*/) const;
151 wxMenuItem* FindItemByPosition(size_t position) const;
153 // get/set items attributes
154 void Enable(int id, bool enable);
155 bool IsEnabled(int id) const;
157 void Check(int id, bool check);
158 bool IsChecked(int id) const;
160 void SetLabel(int id, const wxString& label);
161 wxString GetLabel(int id) const;
163 virtual void SetHelpString(int id, const wxString& helpString);
164 virtual wxString GetHelpString(int id) const;
168 virtual void SetTitle(const wxString& title);
169 const wxString GetTitle() const;
172 void SetEventHandler(wxEvtHandler *handler);
173 wxEvtHandler *GetEventHandler() const;
176 void SetInvokingWindow(wxWindow *win);
177 wxWindow *GetInvokingWindow() const;
180 long GetStyle() const { return m_style; }
183 // Updates the UI for a menu and all submenus recursively. source is the
184 // object that has the update event handlers defined for it. If NULL, the
185 // menu or associated window will be used.
186 void UpdateUI(wxEvtHandler* source = NULL);
188 // get the menu bar this menu is attached to (may be NULL, always NULL for
190 wxMenuBar *GetMenuBar() const;
192 // TODO: Should these be exposed?
193 // called when the menu is attached/detached to/from a menu bar
194 virtual void Attach(wxMenuBarBase *menubar);
195 virtual void Detach();
197 // is the menu attached to a menu bar (or is it a popup one)?
198 bool IsAttached() const;
200 // set/get the parent of this menu
201 void SetParent(wxMenu *parent);
202 wxMenu *GetParent() const;
205 //---------------------------------------------------------------------------
208 MustHaveApp(wxMenuBar);
210 class wxMenuBar : public wxWindow
213 %pythonAppend wxMenuBar "self._setOORInfo(self)"
214 wxMenuBar(long style = 0);
217 // append a menu to the end of menubar, return True if ok
218 virtual bool Append(wxMenu *menu, const wxString& title);
220 // insert a menu before the given position into the menubar, return True
222 virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title);
225 // get the number of menus in the menu bar
226 size_t GetMenuCount() const;
228 // get the menu at given position
229 wxMenu *GetMenu(size_t pos) const;
231 // replace the menu at given position with another one, returns the
232 // previous menu (which should be deleted by the caller)
233 virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
235 // delete the menu at given position from the menu bar, return the pointer
236 // to the menu (which should be deleted by the caller)
237 virtual wxMenu *Remove(size_t pos);
239 // enable or disable a submenu
240 virtual void EnableTop(size_t pos, bool enable);
242 // is the menu enabled?
243 virtual bool IsEnabledTop(size_t WXUNUSED(pos)) const { return True; }
245 // get or change the label of the menu at given position
246 virtual void SetLabelTop(size_t pos, const wxString& label);
247 virtual wxString GetLabelTop(size_t pos) const;
250 // by menu and item names, returns wxNOT_FOUND if not found or id of the
252 virtual int FindMenuItem(const wxString& menu, const wxString& item) const;
254 // find item by id (in any menu), returns NULL if not found
256 // if menu is !NULL, it will be filled with wxMenu this item belongs to
257 %name(FindItemById) virtual wxMenuItem* FindItem(int id /*, wxMenu **menu = NULL*/) const;
259 // find menu by its caption, return wxNOT_FOUND on failure
260 int FindMenu(const wxString& title) const;
263 // all these functions just use FindItem() and then call an appropriate
266 // NB: under MSW, these methods can only be used after the menubar had
267 // been attached to the frame
269 void Enable(int id, bool enable);
270 void Check(int id, bool check);
271 bool IsChecked(int id) const;
272 bool IsEnabled(int id) const;
274 void SetLabel(int id, const wxString &label);
275 wxString GetLabel(int id) const;
277 void SetHelpString(int id, const wxString& helpString);
278 wxString GetHelpString(int id) const;
281 // get the frame we are attached to (may return NULL)
282 wxFrame *GetFrame() const;
284 // returns True if we're attached to a frame
285 bool IsAttached() const;
287 // associate the menubar with the frame
288 virtual void Attach(wxFrame *frame);
290 // called before deleting the menubar normally
291 virtual void Detach();
294 //---------------------------------------------------------------------------
297 class wxMenuItem : public wxObject {
299 wxMenuItem(wxMenu* parentMenu=NULL, int id=wxID_ANY,
300 const wxString& text = wxPyEmptyString,
301 const wxString& help = wxPyEmptyString,
302 wxItemKind kind = wxITEM_NORMAL,
303 wxMenu* subMenu = NULL);
306 wxMenu *GetMenu() const;
307 void SetMenu(wxMenu* menu);
312 bool IsSeparator() const;
314 // the item's text (or name)
316 // NB: the item's text includes the accelerators and mnemonics info (if
317 // any), i.e. it may contain '&' or '_' or "\t..." and thus is
318 // different from the item's label which only contains the text shown
320 virtual void SetText(const wxString& str);
321 wxString GetLabel() const;
322 const wxString& GetText() const;
324 // get the label from text
325 static wxString GetLabelFromText(const wxString& text);
327 // what kind of menu item we are
328 wxItemKind GetKind() const;
329 void SetKind(wxItemKind kind);
331 virtual void SetCheckable(bool checkable);
332 bool IsCheckable() const;
334 bool IsSubMenu() const;
335 void SetSubMenu(wxMenu *menu);
336 wxMenu *GetSubMenu() const;
339 virtual void Enable(bool enable = True);
340 virtual bool IsEnabled() const;
342 virtual void Check(bool check = True);
343 virtual bool IsChecked() const;
346 // help string (displayed in the status bar by default)
347 void SetHelp(const wxString& str);
348 const wxString& GetHelp() const;
350 // get our accelerator or NULL (caller must delete the pointer)
351 virtual wxAcceleratorEntry *GetAccel() const;
353 // set the accel for this item - this may also be done indirectly with
355 virtual void SetAccel(wxAcceleratorEntry *accel);
358 // wxOwnerDrawn methods
360 void SetFont(const wxFont& font);
362 void SetTextColour(const wxColour& colText);
363 wxColour GetTextColour();
364 void SetBackgroundColour(const wxColour& colBack);
365 wxColour GetBackgroundColour();
366 void SetBitmaps(const wxBitmap& bmpChecked,
367 const wxBitmap& bmpUnchecked = wxNullBitmap);
369 void SetDisabledBitmap( const wxBitmap& bmpDisabled );
370 const wxBitmap& GetDisabledBitmap() const;
372 void SetMarginWidth(int nWidth);
373 int GetMarginWidth();
374 static int GetDefaultMarginWidth();
377 // switch on/off owner-drawing the item
378 void SetOwnerDrawn(bool ownerDrawn = True);
379 void ResetOwnerDrawn();
381 // just to keep the global renamers in sync
383 static int GetDefaultMarginWidth() { return 0; }
387 void SetBitmap(const wxBitmap& bitmap);
388 const wxBitmap& GetBitmap();
391 //---------------------------------------------------------------------------
392 //---------------------------------------------------------------------------