]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_menu.i
Various tweaks, docstring fixes, etc.
[wxWidgets.git] / wxPython / src / _menu.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: _menu.i
3 // Purpose: SWIG interface defs for wxMenuBar, wxMenu and wxMenuItem
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 24-June-1997
8 // RCS-ID: $Id$
9 // Copyright: (c) 2003 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13 // Not a %module
14
15
16 //---------------------------------------------------------------------------
17 %newgroup
18
19
20 class wxMenu : public wxEvtHandler
21 {
22 public:
23 %pythonAppend wxMenu "self._setOORInfo(self)"
24 wxMenu(const wxString& title = wxPyEmptyString, long style = 0);
25
26
27 // append any kind of item (normal/check/radio/separator)
28 wxMenuItem* Append(int id,
29 const wxString& text,
30 const wxString& help = wxPyEmptyString,
31 wxItemKind kind = wxITEM_NORMAL);
32
33 // append a separator to the menu
34 wxMenuItem* AppendSeparator();
35
36 // append a check item
37 wxMenuItem* AppendCheckItem(int id,
38 const wxString& text,
39 const wxString& help = wxPyEmptyString);
40
41 // append a radio item
42 wxMenuItem* AppendRadioItem(int id,
43 const wxString& text,
44 const wxString& help = wxPyEmptyString);
45 // append a submenu
46 %name(AppendMenu) wxMenuItem* Append(int id,
47 const wxString& text,
48 wxMenu *submenu,
49 const wxString& help = wxPyEmptyString);
50
51 // the most generic form of Append() - append anything
52 %name(AppendItem) wxMenuItem* Append(wxMenuItem *item);
53
54 // insert a break in the menu (only works when appending the items, not
55 // inserting them)
56 virtual void Break();
57
58 // insert an item before given position
59 %name(InsertItem) wxMenuItem* Insert(size_t pos, wxMenuItem *item);
60
61 // insert an item before given position
62 wxMenuItem* Insert(size_t pos,
63 int id,
64 const wxString& text,
65 const wxString& help = wxPyEmptyString,
66 wxItemKind kind = wxITEM_NORMAL);
67
68 // insert a separator
69 wxMenuItem* InsertSeparator(size_t pos);
70
71 // insert a check item
72 wxMenuItem* InsertCheckItem(size_t pos,
73 int id,
74 const wxString& text,
75 const wxString& help = wxPyEmptyString);
76
77 // insert a radio item
78 wxMenuItem* InsertRadioItem(size_t pos,
79 int id,
80 const wxString& text,
81 const wxString& help = wxPyEmptyString);
82
83 // insert a submenu
84 %name(InsertMenu) wxMenuItem* Insert(size_t pos,
85 int id,
86 const wxString& text,
87 wxMenu *submenu,
88 const wxString& help = wxPyEmptyString);
89
90 // prepend an item to the menu
91 %name(PrependItem) wxMenuItem* Prepend(wxMenuItem *item);
92
93 // prepend any item to the menu
94 wxMenuItem* Prepend(int id,
95 const wxString& text,
96 const wxString& help = wxPyEmptyString,
97 wxItemKind kind = wxITEM_NORMAL);
98
99 // prepend a separator
100 wxMenuItem* PrependSeparator();
101
102 // prepend a check item
103 wxMenuItem* PrependCheckItem(int id,
104 const wxString& text,
105 const wxString& help = wxPyEmptyString);
106
107 // prepend a radio item
108 wxMenuItem* PrependRadioItem(int id,
109 const wxString& text,
110 const wxString& help = wxPyEmptyString);
111
112 // prepend a submenu
113 %name(PrependMenu) wxMenuItem* Prepend(int id,
114 const wxString& text,
115 wxMenu *submenu,
116 const wxString& help = wxPyEmptyString);
117
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
120 // deleting it!)
121 wxMenuItem *Remove(int id);
122 %name(RemoveItem) wxMenuItem *Remove(wxMenuItem *item);
123
124 // delete an item from the menu (submenus are not destroyed by this
125 // function, see Destroy)
126 bool Delete(int id);
127 %name(DeleteItem) bool Delete(wxMenuItem *item);
128
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);
133
134
135 // get the items
136 size_t GetMenuItemCount() const;
137 %extend {
138 PyObject* GetMenuItems() {
139 wxMenuItemList& list = self->GetMenuItems();
140 return wxPy_ConvertList(&list);
141 }
142 }
143
144 // search
145 int FindItem(const wxString& item) const;
146 %name(FindItemById) wxMenuItem* FindItem(int id /*, wxMenu **menu = NULL*/) const;
147
148 // find by position
149 wxMenuItem* FindItemByPosition(size_t position) const;
150
151 // get/set items attributes
152 void Enable(int id, bool enable);
153 bool IsEnabled(int id) const;
154
155 void Check(int id, bool check);
156 bool IsChecked(int id) const;
157
158 void SetLabel(int id, const wxString& label);
159 wxString GetLabel(int id) const;
160
161 virtual void SetHelpString(int id, const wxString& helpString);
162 virtual wxString GetHelpString(int id) const;
163
164
165 // the title
166 virtual void SetTitle(const wxString& title);
167 const wxString GetTitle() const;
168
169 // event handler
170 void SetEventHandler(wxEvtHandler *handler);
171 wxEvtHandler *GetEventHandler() const;
172
173 // invoking window
174 void SetInvokingWindow(wxWindow *win);
175 wxWindow *GetInvokingWindow() const;
176
177 // style
178 long GetStyle() const { return m_style; }
179
180
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);
185
186 // get the menu bar this menu is attached to (may be NULL, always NULL for
187 // popup menus)
188 wxMenuBar *GetMenuBar() const;
189
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();
194
195 // is the menu attached to a menu bar (or is it a popup one)?
196 bool IsAttached() const;
197
198 // set/get the parent of this menu
199 void SetParent(wxMenu *parent);
200 wxMenu *GetParent() const;
201 };
202
203 //---------------------------------------------------------------------------
204 %newgroup
205
206 class wxMenuBar : public wxWindow
207 {
208 public:
209 %pythonAppend wxMenuBar "self._setOORInfo(self)"
210 wxMenuBar(long style = 0);
211
212
213 // append a menu to the end of menubar, return True if ok
214 virtual bool Append(wxMenu *menu, const wxString& title);
215
216 // insert a menu before the given position into the menubar, return True
217 // if inserted ok
218 virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title);
219
220
221 // get the number of menus in the menu bar
222 size_t GetMenuCount() const;
223
224 // get the menu at given position
225 wxMenu *GetMenu(size_t pos) const;
226
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);
230
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);
234
235 // enable or disable a submenu
236 virtual void EnableTop(size_t pos, bool enable);
237
238 // is the menu enabled?
239 virtual bool IsEnabledTop(size_t WXUNUSED(pos)) const { return True; }
240
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;
244
245
246 // by menu and item names, returns wxNOT_FOUND if not found or id of the
247 // found item
248 virtual int FindMenuItem(const wxString& menu, const wxString& item) const;
249
250 // find item by id (in any menu), returns NULL if not found
251 //
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;
254
255 // find menu by its caption, return wxNOT_FOUND on failure
256 int FindMenu(const wxString& title) const;
257
258
259 // all these functions just use FindItem() and then call an appropriate
260 // method on it
261 //
262 // NB: under MSW, these methods can only be used after the menubar had
263 // been attached to the frame
264
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;
269
270 void SetLabel(int id, const wxString &label);
271 wxString GetLabel(int id) const;
272
273 void SetHelpString(int id, const wxString& helpString);
274 wxString GetHelpString(int id) const;
275
276
277 // get the frame we are attached to (may return NULL)
278 wxFrame *GetFrame() const;
279
280 // returns True if we're attached to a frame
281 bool IsAttached() const;
282
283 // associate the menubar with the frame
284 virtual void Attach(wxFrame *frame);
285
286 // called before deleting the menubar normally
287 virtual void Detach();
288 };
289
290 //---------------------------------------------------------------------------
291 %newgroup
292
293 class wxMenuItem : public wxObject {
294 public:
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);
300
301 // the menu we're in
302 wxMenu *GetMenu() const;
303 void SetMenu(wxMenu* menu);
304
305 // get/set id
306 void SetId(int id);
307 int GetId() const;
308 bool IsSeparator() const;
309
310 // the item's text (or name)
311 //
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
315 // in the menu
316 virtual void SetText(const wxString& str);
317 wxString GetLabel() const;
318 const wxString& GetText() const;
319
320 // get the label from text
321 static wxString GetLabelFromText(const wxString& text);
322
323 // what kind of menu item we are
324 wxItemKind GetKind() const;
325 void SetKind(wxItemKind kind);
326
327 virtual void SetCheckable(bool checkable);
328 bool IsCheckable() const;
329
330 bool IsSubMenu() const;
331 void SetSubMenu(wxMenu *menu);
332 wxMenu *GetSubMenu() const;
333
334 // state
335 virtual void Enable(bool enable = True);
336 virtual bool IsEnabled() const;
337
338 virtual void Check(bool check = True);
339 virtual bool IsChecked() const;
340 void Toggle();
341
342 // help string (displayed in the status bar by default)
343 void SetHelp(const wxString& str);
344 const wxString& GetHelp() const;
345
346 // get our accelerator or NULL (caller must delete the pointer)
347 virtual wxAcceleratorEntry *GetAccel() const;
348
349 // set the accel for this item - this may also be done indirectly with
350 // SetText()
351 virtual void SetAccel(wxAcceleratorEntry *accel);
352
353
354 // wxOwnerDrawn methods
355 #ifdef __WXMSW__
356 void SetFont(const wxFont& font);
357 wxFont GetFont();
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);
364
365 void SetDisabledBitmap( const wxBitmap& bmpDisabled );
366 const wxBitmap& GetDisabledBitmap() const;
367
368 void SetMarginWidth(int nWidth);
369 int GetMarginWidth();
370 static int GetDefaultMarginWidth();
371 bool IsOwnerDrawn();
372
373 // switch on/off owner-drawing the item
374 void SetOwnerDrawn(bool ownerDrawn = True);
375 void ResetOwnerDrawn();
376 #else
377 // just to keep the global renamers in sync
378 %extend {
379 static int GetDefaultMarginWidth() { return 0; }
380 }
381 #endif
382
383 void SetBitmap(const wxBitmap& bitmap);
384 const wxBitmap& GetBitmap();
385 };
386
387 //---------------------------------------------------------------------------
388 //---------------------------------------------------------------------------