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