]>
Commit | Line | Data |
---|---|---|
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 | ||
20 | class wxMenu : public wxEvtHandler | |
21 | { | |
22 | public: | |
23 | %addtofunc wxMenu "self._setOORInfo(self)" | |
24 | wxMenu(const wxString& title = wxPyEmptyString, long style = 0); | |
25 | ||
26 | ||
27 | // append any kind of item (normal/check/radio/separator) | |
28 | void Append(int itemid, | |
29 | const wxString& text, | |
30 | const wxString& help = wxPyEmptyString, | |
31 | wxItemKind kind = wxITEM_NORMAL); | |
32 | ||
33 | // append a separator to the menu | |
34 | void AppendSeparator(); | |
35 | ||
36 | // append a check item | |
37 | void AppendCheckItem(int itemid, | |
38 | const wxString& text, | |
39 | const wxString& help = wxPyEmptyString); | |
40 | ||
41 | // append a radio item | |
42 | void AppendRadioItem(int itemid, | |
43 | const wxString& text, | |
44 | const wxString& help = wxPyEmptyString); | |
45 | // append a submenu | |
46 | %name(AppendMenu)void Append(int itemid, | |
47 | const wxString& text, | |
48 | wxMenu *submenu, | |
49 | const wxString& help = wxPyEmptyString); | |
50 | ||
51 | // the most generic form of Append() - append anything | |
52 | %name(AppendItem) void Append(wxMenuItem *item); | |
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 | |
59 | %name(InsertItem) bool Insert(size_t pos, wxMenuItem *item); | |
60 | ||
61 | // insert an item before given position | |
62 | void Insert(size_t pos, | |
63 | int itemid, | |
64 | const wxString& text, | |
65 | const wxString& help = wxPyEmptyString, | |
66 | wxItemKind kind = wxITEM_NORMAL); | |
67 | ||
68 | // insert a separator | |
69 | void InsertSeparator(size_t pos); | |
70 | ||
71 | // insert a check item | |
72 | void InsertCheckItem(size_t pos, | |
73 | int itemid, | |
74 | const wxString& text, | |
75 | const wxString& help = wxPyEmptyString); | |
76 | ||
77 | // insert a radio item | |
78 | void InsertRadioItem(size_t pos, | |
79 | int itemid, | |
80 | const wxString& text, | |
81 | const wxString& help = wxPyEmptyString); | |
82 | ||
83 | // insert a submenu | |
84 | %name(InsertMenu) void Insert(size_t pos, | |
85 | int itemid, | |
86 | const wxString& text, | |
87 | wxMenu *submenu, | |
88 | const wxString& help = wxPyEmptyString); | |
89 | ||
90 | // prepend an item to the menu | |
91 | %name(PrependItem)void Prepend(wxMenuItem *item); | |
92 | ||
93 | // prepend any item to the menu | |
94 | void Prepend(int itemid, | |
95 | const wxString& text, | |
96 | const wxString& help = wxPyEmptyString, | |
97 | wxItemKind kind = wxITEM_NORMAL); | |
98 | ||
99 | // prepend a separator | |
100 | void PrependSeparator(); | |
101 | ||
102 | // prepend a check item | |
103 | void PrependCheckItem(int itemid, | |
104 | const wxString& text, | |
105 | const wxString& help = wxPyEmptyString); | |
106 | ||
107 | // prepend a radio item | |
108 | void PrependRadioItem(int itemid, | |
109 | const wxString& text, | |
110 | const wxString& help = wxPyEmptyString); | |
111 | ||
112 | // prepend a submenu | |
113 | %name(PrependMenu)void Prepend(int itemid, | |
114 | const wxString& text, | |
115 | wxMenu *submenu, | |
116 | const wxString& help = wxPyEmptyString); | |
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!) | |
121 | wxMenuItem *Remove(int itemid); | |
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) | |
126 | bool Delete(int itemid); | |
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; } } | |
131 | %name(DestroyId) bool Destroy(int itemid); | |
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; | |
146 | %name(FindItemById) wxMenuItem* FindItem(int itemid /*, wxMenu **menu = NULL*/) const; | |
147 | ||
148 | // find by position | |
149 | wxMenuItem* FindItemByPosition(size_t position) const; | |
150 | ||
151 | // get/set items attributes | |
152 | void Enable(int itemid, bool enable); | |
153 | bool IsEnabled(int itemid) const; | |
154 | ||
155 | void Check(int itemid, bool check); | |
156 | bool IsChecked(int itemid) const; | |
157 | ||
158 | void SetLabel(int itemid, const wxString& label); | |
159 | wxString GetLabel(int itemid) const; | |
160 | ||
161 | virtual void SetHelpString(int itemid, const wxString& helpString); | |
162 | virtual wxString GetHelpString(int itemid) const; | |
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 | ||
206 | class wxMenuBar : public wxWindow | |
207 | { | |
208 | public: | |
209 | %addtofunc wxMenuBar "self._setOORInfo(self)" | |
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 | |
253 | %name(FindItemById) virtual wxMenuItem* FindItem(int itemid /*, wxMenu **menu = NULL*/) const; | |
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 | ||
265 | void Enable(int itemid, bool enable); | |
266 | void Check(int itemid, bool check); | |
267 | bool IsChecked(int itemid) const; | |
268 | bool IsEnabled(int itemid) const; | |
269 | ||
270 | void SetLabel(int itemid, const wxString &label); | |
271 | wxString GetLabel(int itemid) const; | |
272 | ||
273 | void SetHelpString(int itemid, const wxString& helpString); | |
274 | wxString GetHelpString(int itemid) const; | |
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 | ||
293 | class wxMenuItem : public wxObject { | |
294 | public: | |
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 | |
306 | void SetId(int itemid); | |
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 | //--------------------------------------------------------------------------- |