]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_menu.i
Removed GetVisible and SetVisible
[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
59 %disownarg(wxMenuItem*);
60 // the most generic form of Append() - append anything
61 %Rename(AppendItem, wxMenuItem*, Append(wxMenuItem *item));
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
68
69 // insert a break in the menu (only works when appending the items, not
70 // inserting them)
71 virtual void Break();
72
73 // insert an item before given position
74 wxMenuItem* Insert(size_t pos,
75 int id,
76 const wxString& text,
77 const wxString& help = wxPyEmptyString,
78 wxItemKind kind = wxITEM_NORMAL);
79
80 // insert a separator
81 wxMenuItem* InsertSeparator(size_t pos);
82
83 // insert a check item
84 wxMenuItem* InsertCheckItem(size_t pos,
85 int id,
86 const wxString& text,
87 const wxString& help = wxPyEmptyString);
88
89 // insert a radio item
90 wxMenuItem* InsertRadioItem(size_t pos,
91 int id,
92 const wxString& text,
93 const wxString& help = wxPyEmptyString);
94
95 // insert a submenu
96 %Rename(InsertMenu, wxMenuItem*, Insert(size_t pos,
97 int id,
98 const wxString& text,
99 wxMenu *submenu,
100 const wxString& help = wxPyEmptyString));
101
102 // prepend any item to the menu
103 wxMenuItem* Prepend(int id,
104 const wxString& text,
105 const wxString& help = wxPyEmptyString,
106 wxItemKind kind = wxITEM_NORMAL);
107
108 // prepend a separator
109 wxMenuItem* PrependSeparator();
110
111 // prepend a check item
112 wxMenuItem* PrependCheckItem(int id,
113 const wxString& text,
114 const wxString& help = wxPyEmptyString);
115
116 // prepend a radio item
117 wxMenuItem* PrependRadioItem(int id,
118 const wxString& text,
119 const wxString& help = wxPyEmptyString);
120
121 // prepend a submenu
122 %Rename(PrependMenu, wxMenuItem*, Prepend(int id,
123 const wxString& text,
124 wxMenu *submenu,
125 const wxString& help = wxPyEmptyString));
126
127
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!)
131 %newobject Remove;
132 wxMenuItem *Remove(int id);
133 %Rename(RemoveItem, wxMenuItem*, Remove(wxMenuItem *item));
134
135 // delete an item from the menu (submenus are not destroyed by this
136 // function, see Destroy)
137 bool Delete(int id);
138 %Rename(DeleteItem, bool, Delete(wxMenuItem *item));
139
140 %pythonAppend Destroy "args[0].thisown = 0"
141 %extend { void Destroy() { delete self; } }
142
143 // delete the item from menu and destroy it (if it's a submenu)
144 %Rename(DestroyId, bool, Destroy(int id));
145 %Rename(DestroyItem, bool, Destroy(wxMenuItem *item));
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;
159 %Rename(FindItemById, wxMenuItem*, FindItem(int id /*, wxMenu **menu = NULL*/) const);
160
161 // find by position
162 wxMenuItem* FindItemByPosition(size_t position) const;
163
164 // get/set items attributes
165 void Enable(int id, bool enable);
166 bool IsEnabled(int id) const;
167
168 void Check(int id, bool check);
169 bool IsChecked(int id) const;
170
171 void SetLabel(int id, const wxString& label);
172 wxString GetLabel(int id) const;
173
174 virtual void SetHelpString(int id, const wxString& helpString);
175 virtual wxString GetHelpString(int id) const;
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
219 MustHaveApp(wxMenuBar);
220
221 class wxMenuBar : public wxWindow
222 {
223 public:
224 %pythonAppend wxMenuBar "self._setOORInfo(self)"
225 %typemap(out) wxMenuBar*; // turn off this typemap
226
227 wxMenuBar(long style = 0);
228
229 // Turn it back on again
230 %typemap(out) wxMenuBar* { $result = wxPyMake_wxObject($1, $owner); }
231
232 // append a menu to the end of menubar, return True if ok
233 virtual bool Append(wxMenu *menu, const wxString& title);
234
235 // insert a menu before the given position into the menubar, return True
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?
258 virtual bool IsEnabledTop(size_t pos) const;
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
272 %Rename(FindItemById, virtual wxMenuItem*, FindItem(int id /*, wxMenu **menu = NULL*/) const);
273
274 // find menu by its caption, return wxNOT_FOUND on failure
275 int FindMenu(const wxString& title);
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
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;
288 // TODO: bool IsEnabled() const;
289
290 void SetLabel(int id, const wxString &label);
291 wxString GetLabel(int id) const;
292
293 void SetHelpString(int id, const wxString& helpString);
294 wxString GetHelpString(int id) const;
295
296
297 // get the frame we are attached to (may return NULL)
298 wxFrame *GetFrame() const;
299
300 // returns True if we're attached to a frame
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();
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
318 };
319
320 //---------------------------------------------------------------------------
321 %newgroup
322
323 class wxMenuItem : public wxObject {
324 public:
325 wxMenuItem(wxMenu* parentMenu=NULL, int id=wxID_ANY,
326 const wxString& text = wxPyEmptyString,
327 const wxString& help = wxPyEmptyString,
328 wxItemKind kind = wxITEM_NORMAL,
329 wxMenu* subMenu = NULL);
330 ~wxMenuItem();
331
332 // the menu we're in
333 wxMenu *GetMenu() const;
334 void SetMenu(wxMenu* menu);
335
336 // get/set id
337 void SetId(int id);
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;
356 void SetKind(wxItemKind kind);
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
366 virtual void Enable(bool enable = true);
367 virtual bool IsEnabled() const;
368
369 virtual void Check(bool check = true);
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
384 void SetBitmap(const wxBitmap& bitmap);
385 const wxBitmap& GetBitmap();
386
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
407 void SetOwnerDrawn(bool ownerDrawn = true);
408 void ResetOwnerDrawn();
409 #else
410 %extend {
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; }
417
418 void SetBitmaps(const wxBitmap& bmpChecked,
419 const wxBitmap& bmpUnchecked = wxNullBitmap)
420 { self->SetBitmap( bmpChecked ); }
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; }
427 static int GetDefaultMarginWidth() { return 0; }
428 bool IsOwnerDrawn() { return false; }
429 void SetOwnerDrawn(bool ownerDrawn = true) {}
430 void ResetOwnerDrawn() {}
431 }
432 #endif
433 };
434
435 //---------------------------------------------------------------------------
436 //---------------------------------------------------------------------------