]>
Commit | Line | Data |
---|---|---|
d14a1e28 RD |
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 | ||
ab1f7d2a RD |
20 | MustHaveApp(wxMenu); |
21 | ||
d14a1e28 RD |
22 | class wxMenu : public wxEvtHandler |
23 | { | |
24 | public: | |
2b9048c5 | 25 | %pythonAppend wxMenu "self._setOORInfo(self)" |
b39c3fa0 RD |
26 | %typemap(out) wxMenu*; // turn off this typemap |
27 | ||
d14a1e28 RD |
28 | wxMenu(const wxString& title = wxPyEmptyString, long style = 0); |
29 | ||
b39c3fa0 RD |
30 | // Turn it back on again |
31 | %typemap(out) wxMenu* { $result = wxPyMake_wxObject($1, $owner); } | |
d14a1e28 | 32 | |
b39c3fa0 | 33 | |
d14a1e28 | 34 | // append any kind of item (normal/check/radio/separator) |
38356217 RD |
35 | wxMenuItem* Append(int id, |
36 | const wxString& text, | |
37 | const wxString& help = wxPyEmptyString, | |
38 | wxItemKind kind = wxITEM_NORMAL); | |
d14a1e28 RD |
39 | |
40 | // append a separator to the menu | |
38356217 | 41 | wxMenuItem* AppendSeparator(); |
d14a1e28 RD |
42 | |
43 | // append a check item | |
38356217 RD |
44 | wxMenuItem* AppendCheckItem(int id, |
45 | const wxString& text, | |
46 | const wxString& help = wxPyEmptyString); | |
d14a1e28 RD |
47 | |
48 | // append a radio item | |
38356217 RD |
49 | wxMenuItem* AppendRadioItem(int id, |
50 | const wxString& text, | |
51 | const wxString& help = wxPyEmptyString); | |
d14a1e28 | 52 | // append a submenu |
1b8c7ba6 RD |
53 | %Rename(AppendMenu, wxMenuItem*, Append(int id, |
54 | const wxString& text, | |
55 | wxMenu *submenu, | |
56 | const wxString& help = wxPyEmptyString)); | |
d14a1e28 | 57 | |
c5633576 RD |
58 | |
59 | %disownarg(wxMenuItem*); | |
d14a1e28 | 60 | // the most generic form of Append() - append anything |
1b8c7ba6 | 61 | %Rename(AppendItem, wxMenuItem*, Append(wxMenuItem *item)); |
c5633576 RD |
62 | // insert an item before given position |
63 | %Rename(InsertItem, wxMenuItem*, Insert(size_t pos, wxMenuItem *item)); | |
64 | // prepend an item to the menu | |
65 | %Rename(PrependItem, wxMenuItem*, Prepend(wxMenuItem *item)); | |
66 | %cleardisown(wxMenuItem*); | |
67 | ||
d14a1e28 RD |
68 | |
69 | // insert a break in the menu (only works when appending the items, not | |
70 | // inserting them) | |
71 | virtual void Break(); | |
72 | ||
d14a1e28 | 73 | // insert an item before given position |
38356217 RD |
74 | wxMenuItem* Insert(size_t pos, |
75 | int id, | |
76 | const wxString& text, | |
77 | const wxString& help = wxPyEmptyString, | |
78 | wxItemKind kind = wxITEM_NORMAL); | |
d14a1e28 RD |
79 | |
80 | // insert a separator | |
38356217 | 81 | wxMenuItem* InsertSeparator(size_t pos); |
d14a1e28 RD |
82 | |
83 | // insert a check item | |
38356217 RD |
84 | wxMenuItem* InsertCheckItem(size_t pos, |
85 | int id, | |
86 | const wxString& text, | |
87 | const wxString& help = wxPyEmptyString); | |
d14a1e28 RD |
88 | |
89 | // insert a radio item | |
38356217 RD |
90 | wxMenuItem* InsertRadioItem(size_t pos, |
91 | int id, | |
92 | const wxString& text, | |
93 | const wxString& help = wxPyEmptyString); | |
d14a1e28 RD |
94 | |
95 | // insert a submenu | |
1b8c7ba6 | 96 | %Rename(InsertMenu, wxMenuItem*, Insert(size_t pos, |
38356217 RD |
97 | int id, |
98 | const wxString& text, | |
99 | wxMenu *submenu, | |
1b8c7ba6 | 100 | const wxString& help = wxPyEmptyString)); |
d14a1e28 | 101 | |
d14a1e28 | 102 | // prepend any item to the menu |
38356217 RD |
103 | wxMenuItem* Prepend(int id, |
104 | const wxString& text, | |
105 | const wxString& help = wxPyEmptyString, | |
106 | wxItemKind kind = wxITEM_NORMAL); | |
d14a1e28 RD |
107 | |
108 | // prepend a separator | |
38356217 | 109 | wxMenuItem* PrependSeparator(); |
d14a1e28 RD |
110 | |
111 | // prepend a check item | |
38356217 RD |
112 | wxMenuItem* PrependCheckItem(int id, |
113 | const wxString& text, | |
114 | const wxString& help = wxPyEmptyString); | |
d14a1e28 RD |
115 | |
116 | // prepend a radio item | |
38356217 RD |
117 | wxMenuItem* PrependRadioItem(int id, |
118 | const wxString& text, | |
119 | const wxString& help = wxPyEmptyString); | |
d14a1e28 RD |
120 | |
121 | // prepend a submenu | |
1b8c7ba6 | 122 | %Rename(PrependMenu, wxMenuItem*, Prepend(int id, |
38356217 RD |
123 | const wxString& text, |
124 | wxMenu *submenu, | |
1b8c7ba6 | 125 | const wxString& help = wxPyEmptyString)); |
d14a1e28 | 126 | |
c5633576 | 127 | |
d14a1e28 RD |
128 | // detach an item from the menu, but don't delete it so that it can be |
129 | // added back later (but if it's not, the caller is responsible for | |
130 | // deleting it!) | |
c5633576 | 131 | %newobject Remove; |
b227da6a | 132 | wxMenuItem *Remove(int id); |
1b8c7ba6 | 133 | %Rename(RemoveItem, wxMenuItem*, Remove(wxMenuItem *item)); |
d14a1e28 RD |
134 | |
135 | // delete an item from the menu (submenus are not destroyed by this | |
136 | // function, see Destroy) | |
b227da6a | 137 | bool Delete(int id); |
1b8c7ba6 | 138 | %Rename(DeleteItem, bool, Delete(wxMenuItem *item)); |
d14a1e28 | 139 | |
214c4fbe | 140 | %pythonAppend Destroy "args[0].thisown = 0" |
d14a1e28 | 141 | %extend { void Destroy() { delete self; } } |
214c4fbe RD |
142 | |
143 | // delete the item from menu and destroy it (if it's a submenu) | |
1b8c7ba6 RD |
144 | %Rename(DestroyId, bool, Destroy(int id)); |
145 | %Rename(DestroyItem, bool, Destroy(wxMenuItem *item)); | |
d14a1e28 RD |
146 | |
147 | ||
148 | // get the items | |
149 | size_t GetMenuItemCount() const; | |
150 | %extend { | |
151 | PyObject* GetMenuItems() { | |
152 | wxMenuItemList& list = self->GetMenuItems(); | |
153 | return wxPy_ConvertList(&list); | |
154 | } | |
155 | } | |
156 | ||
157 | // search | |
158 | int FindItem(const wxString& item) const; | |
1b8c7ba6 | 159 | %Rename(FindItemById, wxMenuItem*, FindItem(int id /*, wxMenu **menu = NULL*/) const); |
d14a1e28 RD |
160 | |
161 | // find by position | |
162 | wxMenuItem* FindItemByPosition(size_t position) const; | |
163 | ||
164 | // get/set items attributes | |
b227da6a RD |
165 | void Enable(int id, bool enable); |
166 | bool IsEnabled(int id) const; | |
d14a1e28 | 167 | |
b227da6a RD |
168 | void Check(int id, bool check); |
169 | bool IsChecked(int id) const; | |
d14a1e28 | 170 | |
b227da6a RD |
171 | void SetLabel(int id, const wxString& label); |
172 | wxString GetLabel(int id) const; | |
d14a1e28 | 173 | |
b227da6a RD |
174 | virtual void SetHelpString(int id, const wxString& helpString); |
175 | virtual wxString GetHelpString(int id) const; | |
d14a1e28 RD |
176 | |
177 | ||
178 | // the title | |
179 | virtual void SetTitle(const wxString& title); | |
180 | const wxString GetTitle() const; | |
181 | ||
182 | // event handler | |
183 | void SetEventHandler(wxEvtHandler *handler); | |
184 | wxEvtHandler *GetEventHandler() const; | |
185 | ||
186 | // invoking window | |
187 | void SetInvokingWindow(wxWindow *win); | |
188 | wxWindow *GetInvokingWindow() const; | |
189 | ||
190 | // style | |
191 | long GetStyle() const { return m_style; } | |
192 | ||
193 | ||
194 | // Updates the UI for a menu and all submenus recursively. source is the | |
195 | // object that has the update event handlers defined for it. If NULL, the | |
196 | // menu or associated window will be used. | |
197 | void UpdateUI(wxEvtHandler* source = NULL); | |
198 | ||
199 | // get the menu bar this menu is attached to (may be NULL, always NULL for | |
200 | // popup menus) | |
201 | wxMenuBar *GetMenuBar() const; | |
202 | ||
203 | // TODO: Should these be exposed? | |
204 | // called when the menu is attached/detached to/from a menu bar | |
205 | virtual void Attach(wxMenuBarBase *menubar); | |
206 | virtual void Detach(); | |
207 | ||
208 | // is the menu attached to a menu bar (or is it a popup one)? | |
209 | bool IsAttached() const; | |
210 | ||
211 | // set/get the parent of this menu | |
212 | void SetParent(wxMenu *parent); | |
213 | wxMenu *GetParent() const; | |
214 | }; | |
215 | ||
216 | //--------------------------------------------------------------------------- | |
217 | %newgroup | |
218 | ||
ab1f7d2a RD |
219 | MustHaveApp(wxMenuBar); |
220 | ||
d14a1e28 RD |
221 | class wxMenuBar : public wxWindow |
222 | { | |
223 | public: | |
2b9048c5 | 224 | %pythonAppend wxMenuBar "self._setOORInfo(self)" |
b39c3fa0 RD |
225 | %typemap(out) wxMenuBar*; // turn off this typemap |
226 | ||
d14a1e28 RD |
227 | wxMenuBar(long style = 0); |
228 | ||
b39c3fa0 RD |
229 | // Turn it back on again |
230 | %typemap(out) wxMenuBar* { $result = wxPyMake_wxObject($1, $owner); } | |
d14a1e28 | 231 | |
dd9f7fea | 232 | // append a menu to the end of menubar, return True if ok |
d14a1e28 RD |
233 | virtual bool Append(wxMenu *menu, const wxString& title); |
234 | ||
dd9f7fea | 235 | // insert a menu before the given position into the menubar, return True |
d14a1e28 RD |
236 | // if inserted ok |
237 | virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title); | |
238 | ||
239 | ||
240 | // get the number of menus in the menu bar | |
241 | size_t GetMenuCount() const; | |
242 | ||
243 | // get the menu at given position | |
244 | wxMenu *GetMenu(size_t pos) const; | |
245 | ||
246 | // replace the menu at given position with another one, returns the | |
247 | // previous menu (which should be deleted by the caller) | |
248 | virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title); | |
249 | ||
250 | // delete the menu at given position from the menu bar, return the pointer | |
251 | // to the menu (which should be deleted by the caller) | |
252 | virtual wxMenu *Remove(size_t pos); | |
253 | ||
254 | // enable or disable a submenu | |
255 | virtual void EnableTop(size_t pos, bool enable); | |
256 | ||
257 | // is the menu enabled? | |
5fad19e3 | 258 | virtual bool IsEnabledTop(size_t pos) const; |
d14a1e28 RD |
259 | |
260 | // get or change the label of the menu at given position | |
261 | virtual void SetLabelTop(size_t pos, const wxString& label); | |
262 | virtual wxString GetLabelTop(size_t pos) const; | |
263 | ||
264 | ||
265 | // by menu and item names, returns wxNOT_FOUND if not found or id of the | |
266 | // found item | |
267 | virtual int FindMenuItem(const wxString& menu, const wxString& item) const; | |
268 | ||
269 | // find item by id (in any menu), returns NULL if not found | |
270 | // | |
271 | // if menu is !NULL, it will be filled with wxMenu this item belongs to | |
1b8c7ba6 | 272 | %Rename(FindItemById, virtual wxMenuItem*, FindItem(int id /*, wxMenu **menu = NULL*/) const); |
d14a1e28 RD |
273 | |
274 | // find menu by its caption, return wxNOT_FOUND on failure | |
be9b4caa | 275 | int FindMenu(const wxString& title); |
d14a1e28 RD |
276 | |
277 | ||
278 | // all these functions just use FindItem() and then call an appropriate | |
279 | // method on it | |
280 | // | |
281 | // NB: under MSW, these methods can only be used after the menubar had | |
282 | // been attached to the frame | |
283 | ||
b227da6a RD |
284 | void Enable(int id, bool enable); |
285 | void Check(int id, bool check); | |
286 | bool IsChecked(int id) const; | |
287 | bool IsEnabled(int id) const; | |
39d160c3 RD |
288 | // TODO: bool IsEnabled() const; |
289 | ||
b227da6a RD |
290 | void SetLabel(int id, const wxString &label); |
291 | wxString GetLabel(int id) const; | |
d14a1e28 | 292 | |
b227da6a RD |
293 | void SetHelpString(int id, const wxString& helpString); |
294 | wxString GetHelpString(int id) const; | |
d14a1e28 RD |
295 | |
296 | ||
297 | // get the frame we are attached to (may return NULL) | |
298 | wxFrame *GetFrame() const; | |
299 | ||
dd9f7fea | 300 | // returns True if we're attached to a frame |
d14a1e28 RD |
301 | bool IsAttached() const; |
302 | ||
303 | // associate the menubar with the frame | |
304 | virtual void Attach(wxFrame *frame); | |
305 | ||
306 | // called before deleting the menubar normally | |
307 | virtual void Detach(); | |
fdc53e13 RD |
308 | |
309 | #ifdef __WXMAC__ | |
310 | static void SetAutoWindowMenu( bool enable ); | |
311 | static bool GetAutoWindowMenu(); | |
312 | #else | |
313 | %extend { | |
314 | static void SetAutoWindowMenu( bool enable ) {} | |
315 | static bool GetAutoWindowMenu() { return false; } | |
316 | } | |
317 | #endif | |
d14a1e28 RD |
318 | }; |
319 | ||
320 | //--------------------------------------------------------------------------- | |
321 | %newgroup | |
322 | ||
323 | class wxMenuItem : public wxObject { | |
324 | public: | |
c6a26577 | 325 | wxMenuItem(wxMenu* parentMenu=NULL, int id=wxID_ANY, |
d14a1e28 RD |
326 | const wxString& text = wxPyEmptyString, |
327 | const wxString& help = wxPyEmptyString, | |
328 | wxItemKind kind = wxITEM_NORMAL, | |
329 | wxMenu* subMenu = NULL); | |
c5633576 | 330 | ~wxMenuItem(); |
d14a1e28 RD |
331 | |
332 | // the menu we're in | |
333 | wxMenu *GetMenu() const; | |
334 | void SetMenu(wxMenu* menu); | |
335 | ||
336 | // get/set id | |
b227da6a | 337 | void SetId(int id); |
d14a1e28 RD |
338 | int GetId() const; |
339 | bool IsSeparator() const; | |
340 | ||
341 | // the item's text (or name) | |
342 | // | |
343 | // NB: the item's text includes the accelerators and mnemonics info (if | |
344 | // any), i.e. it may contain '&' or '_' or "\t..." and thus is | |
345 | // different from the item's label which only contains the text shown | |
346 | // in the menu | |
347 | virtual void SetText(const wxString& str); | |
348 | wxString GetLabel() const; | |
349 | const wxString& GetText() const; | |
350 | ||
351 | // get the label from text | |
352 | static wxString GetLabelFromText(const wxString& text); | |
353 | ||
354 | // what kind of menu item we are | |
355 | wxItemKind GetKind() const; | |
c6a26577 | 356 | void SetKind(wxItemKind kind); |
d14a1e28 RD |
357 | |
358 | virtual void SetCheckable(bool checkable); | |
359 | bool IsCheckable() const; | |
360 | ||
361 | bool IsSubMenu() const; | |
362 | void SetSubMenu(wxMenu *menu); | |
363 | wxMenu *GetSubMenu() const; | |
364 | ||
365 | // state | |
a72f4631 | 366 | virtual void Enable(bool enable = true); |
d14a1e28 RD |
367 | virtual bool IsEnabled() const; |
368 | ||
a72f4631 | 369 | virtual void Check(bool check = true); |
d14a1e28 RD |
370 | virtual bool IsChecked() const; |
371 | void Toggle(); | |
372 | ||
373 | // help string (displayed in the status bar by default) | |
374 | void SetHelp(const wxString& str); | |
375 | const wxString& GetHelp() const; | |
376 | ||
377 | // get our accelerator or NULL (caller must delete the pointer) | |
378 | virtual wxAcceleratorEntry *GetAccel() const; | |
379 | ||
380 | // set the accel for this item - this may also be done indirectly with | |
381 | // SetText() | |
382 | virtual void SetAccel(wxAcceleratorEntry *accel); | |
383 | ||
17991ec0 RD |
384 | void SetBitmap(const wxBitmap& bitmap); |
385 | const wxBitmap& GetBitmap(); | |
386 | ||
d14a1e28 RD |
387 | // wxOwnerDrawn methods |
388 | #ifdef __WXMSW__ | |
389 | void SetFont(const wxFont& font); | |
390 | wxFont GetFont(); | |
391 | void SetTextColour(const wxColour& colText); | |
392 | wxColour GetTextColour(); | |
393 | void SetBackgroundColour(const wxColour& colBack); | |
394 | wxColour GetBackgroundColour(); | |
395 | void SetBitmaps(const wxBitmap& bmpChecked, | |
396 | const wxBitmap& bmpUnchecked = wxNullBitmap); | |
397 | ||
398 | void SetDisabledBitmap( const wxBitmap& bmpDisabled ); | |
399 | const wxBitmap& GetDisabledBitmap() const; | |
400 | ||
401 | void SetMarginWidth(int nWidth); | |
402 | int GetMarginWidth(); | |
403 | static int GetDefaultMarginWidth(); | |
404 | bool IsOwnerDrawn(); | |
405 | ||
406 | // switch on/off owner-drawing the item | |
a72f4631 | 407 | void SetOwnerDrawn(bool ownerDrawn = true); |
d14a1e28 RD |
408 | void ResetOwnerDrawn(); |
409 | #else | |
d14a1e28 | 410 | %extend { |
6a210755 RD |
411 | void SetFont(const wxFont& font) {} |
412 | wxFont GetFont() { return wxNullFont; } | |
413 | void SetTextColour(const wxColour& colText) {} | |
414 | wxColour GetTextColour() { return wxNullColour; } | |
415 | void SetBackgroundColour(const wxColour& colBack) {} | |
416 | wxColour GetBackgroundColour() { return wxNullColour; } | |
17991ec0 | 417 | |
6a210755 | 418 | void SetBitmaps(const wxBitmap& bmpChecked, |
17991ec0 RD |
419 | const wxBitmap& bmpUnchecked = wxNullBitmap) |
420 | { self->SetBitmap( bmpChecked ); } | |
6a210755 RD |
421 | |
422 | void SetDisabledBitmap( const wxBitmap& bmpDisabled ) {} | |
423 | const wxBitmap& GetDisabledBitmap() const { return wxNullBitmap; } | |
424 | ||
425 | void SetMarginWidth(int nWidth) {} | |
426 | int GetMarginWidth() { return 0; } | |
d14a1e28 | 427 | static int GetDefaultMarginWidth() { return 0; } |
6a210755 RD |
428 | bool IsOwnerDrawn() { return false; } |
429 | void SetOwnerDrawn(bool ownerDrawn = true) {} | |
430 | void ResetOwnerDrawn() {} | |
d14a1e28 RD |
431 | } |
432 | #endif | |
d14a1e28 RD |
433 | }; |
434 | ||
435 | //--------------------------------------------------------------------------- | |
436 | //--------------------------------------------------------------------------- |