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