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