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