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 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,
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,
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 %pythonAppend Destroy "args[0].thisown = 0"
144 %extend { void Destroy() { delete self; } }
146 // delete the item from menu and destroy it (if it's a submenu)
147 %Rename(DestroyId, bool, Destroy(int id));
148 %Rename(DestroyItem, bool, Destroy(wxMenuItem *item));
152 size_t GetMenuItemCount() const;
154 PyObject* GetMenuItems() {
155 wxMenuItemList& list = self->GetMenuItems();
156 return wxPy_ConvertList(&list);
161 int FindItem(const wxString& item) const;
162 %Rename(FindItemById, wxMenuItem*, FindItem(int id /*, wxMenu **menu = NULL*/) const);
165 wxMenuItem* FindItemByPosition(size_t position) const;
167 // get/set items attributes
168 void Enable(int id, bool enable);
169 bool IsEnabled(int id) const;
171 void Check(int id, bool check);
172 bool IsChecked(int id) const;
174 void SetLabel(int id, const wxString& label);
175 wxString GetLabel(int id) const;
177 virtual void SetHelpString(int id, const wxString& helpString);
178 virtual wxString GetHelpString(int id) const;
182 virtual void SetTitle(const wxString& title);
183 const wxString GetTitle() const;
186 void SetEventHandler(wxEvtHandler *handler);
187 wxEvtHandler *GetEventHandler() const;
190 void SetInvokingWindow(wxWindow *win);
191 wxWindow *GetInvokingWindow() const;
194 long GetStyle() const { return m_style; }
197 // Updates the UI for a menu and all submenus recursively. source is the
198 // object that has the update event handlers defined for it. If NULL, the
199 // menu or associated window will be used.
200 void UpdateUI(wxEvtHandler* source = NULL);
202 // get the menu bar this menu is attached to (may be NULL, always NULL for
204 wxMenuBar *GetMenuBar() const;
206 // TODO: Should these be exposed?
207 // called when the menu is attached/detached to/from a menu bar
208 virtual void Attach(wxMenuBarBase *menubar);
209 virtual void Detach();
211 // is the menu attached to a menu bar (or is it a popup one)?
212 bool IsAttached() const;
214 // set/get the parent of this menu
215 void SetParent(wxMenu *parent);
216 wxMenu *GetParent() const;
219 //---------------------------------------------------------------------------
222 MustHaveApp(wxMenuBar);
224 class wxMenuBar : public wxWindow
227 %pythonAppend wxMenuBar "self._setOORInfo(self)"
228 %typemap(out) wxMenuBar*; // turn off this typemap
230 wxMenuBar(long style = 0);
232 // Turn it back on again
233 %typemap(out) wxMenuBar* { $result = wxPyMake_wxObject($1, $owner); }
235 // append a menu to the end of menubar, return True if ok
236 virtual bool Append(wxMenu *menu, const wxString& title);
238 // insert a menu before the given position into the menubar, return True
240 virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title);
243 // get the number of menus in the menu bar
244 size_t GetMenuCount() const;
246 // get the menu at given position
247 wxMenu *GetMenu(size_t pos) const;
249 // replace the menu at given position with another one, returns the
250 // previous menu (which should be deleted by the caller)
251 virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
253 // delete the menu at given position from the menu bar, return the pointer
254 // to the menu (which should be deleted by the caller)
255 virtual wxMenu *Remove(size_t pos);
257 // enable or disable a submenu
258 virtual void EnableTop(size_t pos, bool enable);
260 // is the menu enabled?
261 virtual bool IsEnabledTop(size_t pos) const;
263 // get or change the label of the menu at given position
264 virtual void SetLabelTop(size_t pos, const wxString& label);
265 virtual wxString GetLabelTop(size_t pos) const;
268 // by menu and item names, returns wxNOT_FOUND if not found or id of the
270 virtual int FindMenuItem(const wxString& menu, const wxString& item) const;
272 // find item by id (in any menu), returns NULL if not found
274 // if menu is !NULL, it will be filled with wxMenu this item belongs to
275 %Rename(FindItemById, virtual wxMenuItem*, FindItem(int id /*, wxMenu **menu = NULL*/) const);
277 // find menu by its caption, return wxNOT_FOUND on failure
278 int FindMenu(const wxString& title);
281 // all these functions just use FindItem() and then call an appropriate
284 // NB: under MSW, these methods can only be used after the menubar had
285 // been attached to the frame
287 void Enable(int id, bool enable);
288 void Check(int id, bool check);
289 bool IsChecked(int id) const;
290 bool IsEnabled(int id) const;
291 // TODO: bool IsEnabled() const;
293 void SetLabel(int id, const wxString &label);
294 wxString GetLabel(int id) const;
296 void SetHelpString(int id, const wxString& helpString);
297 wxString GetHelpString(int id) const;
300 // get the frame we are attached to (may return NULL)
301 wxFrame *GetFrame() const;
303 // returns True if we're attached to a frame
304 bool IsAttached() const;
306 // associate the menubar with the frame
307 virtual void Attach(wxFrame *frame);
309 // called before deleting the menubar normally
310 virtual void Detach();
313 static void SetAutoWindowMenu( bool enable );
314 static bool GetAutoWindowMenu();
317 static void SetAutoWindowMenu( bool enable ) {}
318 static bool GetAutoWindowMenu() { return false; }
323 //---------------------------------------------------------------------------
326 class wxMenuItem : public wxObject {
328 wxMenuItem(wxMenu* parentMenu=NULL, int id=wxID_ANY,
329 const wxString& text = wxPyEmptyString,
330 const wxString& help = wxPyEmptyString,
331 wxItemKind kind = wxITEM_NORMAL,
332 wxMenu* subMenu = NULL);
336 wxMenu *GetMenu() const;
337 void SetMenu(wxMenu* menu);
342 bool IsSeparator() const;
344 // the item's text (or name)
346 // NB: the item's text includes the accelerators and mnemonics info (if
347 // any), i.e. it may contain '&' or '_' or "\t..." and thus is
348 // different from the item's label which only contains the text shown
350 virtual void SetText(const wxString& str);
351 wxString GetLabel() const;
352 const wxString& GetText() const;
354 // get the label from text
355 static wxString GetLabelFromText(const wxString& text);
357 // what kind of menu item we are
358 wxItemKind GetKind() const;
359 void SetKind(wxItemKind kind);
361 virtual void SetCheckable(bool checkable);
362 bool IsCheckable() const;
364 bool IsSubMenu() const;
365 void SetSubMenu(wxMenu *menu);
366 wxMenu *GetSubMenu() const;
369 virtual void Enable(bool enable = true);
370 virtual bool IsEnabled() const;
372 virtual void Check(bool check = true);
373 virtual bool IsChecked() const;
376 // help string (displayed in the status bar by default)
377 void SetHelp(const wxString& str);
378 const wxString& GetHelp() const;
380 // get our accelerator or NULL (caller must delete the pointer)
381 virtual wxAcceleratorEntry *GetAccel() const;
383 // set the accel for this item - this may also be done indirectly with
385 virtual void SetAccel(wxAcceleratorEntry *accel);
387 void SetBitmap(const wxBitmap& bitmap);
388 const wxBitmap& GetBitmap();
390 // wxOwnerDrawn methods
392 void SetFont(const wxFont& font);
394 void SetTextColour(const wxColour& colText);
395 wxColour GetTextColour();
396 void SetBackgroundColour(const wxColour& colBack);
397 wxColour GetBackgroundColour();
398 void SetBitmaps(const wxBitmap& bmpChecked,
399 const wxBitmap& bmpUnchecked = wxNullBitmap);
401 void SetDisabledBitmap( const wxBitmap& bmpDisabled );
402 const wxBitmap& GetDisabledBitmap() const;
404 void SetMarginWidth(int nWidth);
405 int GetMarginWidth();
406 static int GetDefaultMarginWidth();
409 // switch on/off owner-drawing the item
410 void SetOwnerDrawn(bool ownerDrawn = true);
411 void ResetOwnerDrawn();
414 void SetFont(const wxFont& font) {}
415 wxFont GetFont() { return wxNullFont; }
416 void SetTextColour(const wxColour& colText) {}
417 wxColour GetTextColour() { return wxNullColour; }
418 void SetBackgroundColour(const wxColour& colBack) {}
419 wxColour GetBackgroundColour() { return wxNullColour; }
421 void SetBitmaps(const wxBitmap& bmpChecked,
422 const wxBitmap& bmpUnchecked = wxNullBitmap)
423 { self->SetBitmap( bmpChecked ); }
425 void SetDisabledBitmap( const wxBitmap& bmpDisabled ) {}
426 const wxBitmap& GetDisabledBitmap() const { return wxNullBitmap; }
428 void SetMarginWidth(int nWidth) {}
429 int GetMarginWidth() { return 0; }
430 static int GetDefaultMarginWidth() { return 0; }
431 bool IsOwnerDrawn() { return false; }
432 void SetOwnerDrawn(bool ownerDrawn = true) {}
433 void ResetOwnerDrawn() {}
438 //---------------------------------------------------------------------------
439 //---------------------------------------------------------------------------