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 //---------------------------------------------------------------------------
20 class wxMenu : public wxEvtHandler
23 %pythonAppend wxMenu "self._setOORInfo(self)"
24 wxMenu(const wxString& title = wxPyEmptyString, long style = 0);
27 // append any kind of item (normal/check/radio/separator)
28 wxMenuItem* Append(int id,
30 const wxString& help = wxPyEmptyString,
31 wxItemKind kind = wxITEM_NORMAL);
33 // append a separator to the menu
34 wxMenuItem* AppendSeparator();
36 // append a check item
37 wxMenuItem* AppendCheckItem(int id,
39 const wxString& help = wxPyEmptyString);
41 // append a radio item
42 wxMenuItem* AppendRadioItem(int id,
44 const wxString& help = wxPyEmptyString);
46 %name(AppendMenu) wxMenuItem* Append(int id,
49 const wxString& help = wxPyEmptyString);
51 // the most generic form of Append() - append anything
52 %name(AppendItem) wxMenuItem* Append(wxMenuItem *item);
54 // insert a break in the menu (only works when appending the items, not
58 // insert an item before given position
59 %name(InsertItem) wxMenuItem* Insert(size_t pos, wxMenuItem *item);
61 // insert an item before given position
62 wxMenuItem* Insert(size_t pos,
65 const wxString& help = wxPyEmptyString,
66 wxItemKind kind = wxITEM_NORMAL);
69 wxMenuItem* InsertSeparator(size_t pos);
71 // insert a check item
72 wxMenuItem* InsertCheckItem(size_t pos,
75 const wxString& help = wxPyEmptyString);
77 // insert a radio item
78 wxMenuItem* InsertRadioItem(size_t pos,
81 const wxString& help = wxPyEmptyString);
84 %name(InsertMenu) wxMenuItem* Insert(size_t pos,
88 const wxString& help = wxPyEmptyString);
90 // prepend an item to the menu
91 %name(PrependItem) wxMenuItem* Prepend(wxMenuItem *item);
93 // prepend any item to the menu
94 wxMenuItem* Prepend(int id,
96 const wxString& help = wxPyEmptyString,
97 wxItemKind kind = wxITEM_NORMAL);
99 // prepend a separator
100 wxMenuItem* PrependSeparator();
102 // prepend a check item
103 wxMenuItem* PrependCheckItem(int id,
104 const wxString& text,
105 const wxString& help = wxPyEmptyString);
107 // prepend a radio item
108 wxMenuItem* PrependRadioItem(int id,
109 const wxString& text,
110 const wxString& help = wxPyEmptyString);
113 %name(PrependMenu) wxMenuItem* Prepend(int id,
114 const wxString& text,
116 const wxString& help = wxPyEmptyString);
118 // detach an item from the menu, but don't delete it so that it can be
119 // added back later (but if it's not, the caller is responsible for
121 wxMenuItem *Remove(int id);
122 %name(RemoveItem) wxMenuItem *Remove(wxMenuItem *item);
124 // delete an item from the menu (submenus are not destroyed by this
125 // function, see Destroy)
127 %name(DeleteItem) bool Delete(wxMenuItem *item);
129 // delete the item from menu and destroy it (if it's a submenu)
130 %extend { void Destroy() { delete self; } }
131 %name(DestroyId) bool Destroy(int id);
132 %name(DestroyItem) bool Destroy(wxMenuItem *item);
136 size_t GetMenuItemCount() const;
138 PyObject* GetMenuItems() {
139 wxMenuItemList& list = self->GetMenuItems();
140 return wxPy_ConvertList(&list);
145 int FindItem(const wxString& item) const;
146 %name(FindItemById) wxMenuItem* FindItem(int id /*, wxMenu **menu = NULL*/) const;
149 wxMenuItem* FindItemByPosition(size_t position) const;
151 // get/set items attributes
152 void Enable(int id, bool enable);
153 bool IsEnabled(int id) const;
155 void Check(int id, bool check);
156 bool IsChecked(int id) const;
158 void SetLabel(int id, const wxString& label);
159 wxString GetLabel(int id) const;
161 virtual void SetHelpString(int id, const wxString& helpString);
162 virtual wxString GetHelpString(int id) const;
166 virtual void SetTitle(const wxString& title);
167 const wxString GetTitle() const;
170 void SetEventHandler(wxEvtHandler *handler);
171 wxEvtHandler *GetEventHandler() const;
174 void SetInvokingWindow(wxWindow *win);
175 wxWindow *GetInvokingWindow() const;
178 long GetStyle() const { return m_style; }
181 // Updates the UI for a menu and all submenus recursively. source is the
182 // object that has the update event handlers defined for it. If NULL, the
183 // menu or associated window will be used.
184 void UpdateUI(wxEvtHandler* source = NULL);
186 // get the menu bar this menu is attached to (may be NULL, always NULL for
188 wxMenuBar *GetMenuBar() const;
190 // TODO: Should these be exposed?
191 // called when the menu is attached/detached to/from a menu bar
192 virtual void Attach(wxMenuBarBase *menubar);
193 virtual void Detach();
195 // is the menu attached to a menu bar (or is it a popup one)?
196 bool IsAttached() const;
198 // set/get the parent of this menu
199 void SetParent(wxMenu *parent);
200 wxMenu *GetParent() const;
203 //---------------------------------------------------------------------------
206 class wxMenuBar : public wxWindow
209 %pythonAppend wxMenuBar "self._setOORInfo(self)"
210 wxMenuBar(long style = 0);
213 // append a menu to the end of menubar, return True if ok
214 virtual bool Append(wxMenu *menu, const wxString& title);
216 // insert a menu before the given position into the menubar, return True
218 virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title);
221 // get the number of menus in the menu bar
222 size_t GetMenuCount() const;
224 // get the menu at given position
225 wxMenu *GetMenu(size_t pos) const;
227 // replace the menu at given position with another one, returns the
228 // previous menu (which should be deleted by the caller)
229 virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
231 // delete the menu at given position from the menu bar, return the pointer
232 // to the menu (which should be deleted by the caller)
233 virtual wxMenu *Remove(size_t pos);
235 // enable or disable a submenu
236 virtual void EnableTop(size_t pos, bool enable);
238 // is the menu enabled?
239 virtual bool IsEnabledTop(size_t WXUNUSED(pos)) const { return True; }
241 // get or change the label of the menu at given position
242 virtual void SetLabelTop(size_t pos, const wxString& label);
243 virtual wxString GetLabelTop(size_t pos) const;
246 // by menu and item names, returns wxNOT_FOUND if not found or id of the
248 virtual int FindMenuItem(const wxString& menu, const wxString& item) const;
250 // find item by id (in any menu), returns NULL if not found
252 // if menu is !NULL, it will be filled with wxMenu this item belongs to
253 %name(FindItemById) virtual wxMenuItem* FindItem(int id /*, wxMenu **menu = NULL*/) const;
255 // find menu by its caption, return wxNOT_FOUND on failure
256 int FindMenu(const wxString& title) const;
259 // all these functions just use FindItem() and then call an appropriate
262 // NB: under MSW, these methods can only be used after the menubar had
263 // been attached to the frame
265 void Enable(int id, bool enable);
266 void Check(int id, bool check);
267 bool IsChecked(int id) const;
268 bool IsEnabled(int id) const;
270 void SetLabel(int id, const wxString &label);
271 wxString GetLabel(int id) const;
273 void SetHelpString(int id, const wxString& helpString);
274 wxString GetHelpString(int id) const;
277 // get the frame we are attached to (may return NULL)
278 wxFrame *GetFrame() const;
280 // returns True if we're attached to a frame
281 bool IsAttached() const;
283 // associate the menubar with the frame
284 virtual void Attach(wxFrame *frame);
286 // called before deleting the menubar normally
287 virtual void Detach();
290 //---------------------------------------------------------------------------
293 class wxMenuItem : public wxObject {
295 wxMenuItem(wxMenu* parentMenu=NULL, int id=wxID_ANY,
296 const wxString& text = wxPyEmptyString,
297 const wxString& help = wxPyEmptyString,
298 wxItemKind kind = wxITEM_NORMAL,
299 wxMenu* subMenu = NULL);
302 wxMenu *GetMenu() const;
303 void SetMenu(wxMenu* menu);
308 bool IsSeparator() const;
310 // the item's text (or name)
312 // NB: the item's text includes the accelerators and mnemonics info (if
313 // any), i.e. it may contain '&' or '_' or "\t..." and thus is
314 // different from the item's label which only contains the text shown
316 virtual void SetText(const wxString& str);
317 wxString GetLabel() const;
318 const wxString& GetText() const;
320 // get the label from text
321 static wxString GetLabelFromText(const wxString& text);
323 // what kind of menu item we are
324 wxItemKind GetKind() const;
325 void SetKind(wxItemKind kind);
327 virtual void SetCheckable(bool checkable);
328 bool IsCheckable() const;
330 bool IsSubMenu() const;
331 void SetSubMenu(wxMenu *menu);
332 wxMenu *GetSubMenu() const;
335 virtual void Enable(bool enable = True);
336 virtual bool IsEnabled() const;
338 virtual void Check(bool check = True);
339 virtual bool IsChecked() const;
342 // help string (displayed in the status bar by default)
343 void SetHelp(const wxString& str);
344 const wxString& GetHelp() const;
346 // get our accelerator or NULL (caller must delete the pointer)
347 virtual wxAcceleratorEntry *GetAccel() const;
349 // set the accel for this item - this may also be done indirectly with
351 virtual void SetAccel(wxAcceleratorEntry *accel);
354 // wxOwnerDrawn methods
356 void SetFont(const wxFont& font);
358 void SetTextColour(const wxColour& colText);
359 wxColour GetTextColour();
360 void SetBackgroundColour(const wxColour& colBack);
361 wxColour GetBackgroundColour();
362 void SetBitmaps(const wxBitmap& bmpChecked,
363 const wxBitmap& bmpUnchecked = wxNullBitmap);
365 void SetDisabledBitmap( const wxBitmap& bmpDisabled );
366 const wxBitmap& GetDisabledBitmap() const;
368 void SetMarginWidth(int nWidth);
369 int GetMarginWidth();
370 static int GetDefaultMarginWidth();
373 // switch on/off owner-drawing the item
374 void SetOwnerDrawn(bool ownerDrawn = True);
375 void ResetOwnerDrawn();
377 // just to keep the global renamers in sync
379 static int GetDefaultMarginWidth() { return 0; }
383 void SetBitmap(const wxBitmap& bitmap);
384 const wxBitmap& GetBitmap();
387 //---------------------------------------------------------------------------
388 //---------------------------------------------------------------------------