]>
Commit | Line | Data |
---|---|---|
7bf85405 RD |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: controls2.i | |
3 | // Purpose: More control (widget) classes for wxPython | |
4 | // | |
5 | // Author: Robin Dunn | |
6 | // | |
7 | // Created: 6/10/98 | |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) 1998 by Total Control Software | |
10 | // Licence: wxWindows license | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
03e9bead | 13 | %module controls2 |
7bf85405 | 14 | |
03e9bead | 15 | %{ |
7bf85405 RD |
16 | #include "helpers.h" |
17 | #include <wx/listctrl.h> | |
18 | #include <wx/treectrl.h> | |
7bf85405 RD |
19 | %} |
20 | ||
21 | //---------------------------------------------------------------------- | |
22 | ||
23 | %include typemaps.i | |
24 | %include my_typemaps.i | |
25 | ||
26 | // Import some definitions of other classes, etc. | |
27 | %import _defs.i | |
28 | %import misc.i | |
29 | %import windows.i | |
30 | %import gdi.i | |
31 | %import events.i | |
32 | %import controls.i | |
33 | ||
b8b8dda7 | 34 | %pragma(python) code = "import wx" |
9c039d08 | 35 | |
7bf85405 RD |
36 | //---------------------------------------------------------------------- |
37 | ||
38 | %{ | |
39 | extern wxValidator wxPyDefaultValidator; | |
40 | %} | |
41 | ||
42 | //---------------------------------------------------------------------- | |
43 | ||
af309447 RD |
44 | enum { |
45 | wxLIST_MASK_TEXT, | |
46 | wxLIST_MASK_IMAGE, | |
47 | wxLIST_MASK_DATA, | |
48 | wxLIST_MASK_WIDTH, | |
49 | wxLIST_MASK_FORMAT, | |
bb0054cd | 50 | wxLIST_MASK_STATE, |
af309447 RD |
51 | wxLIST_STATE_DONTCARE, |
52 | wxLIST_STATE_DROPHILITED, | |
53 | wxLIST_STATE_FOCUSED, | |
54 | wxLIST_STATE_SELECTED, | |
55 | wxLIST_STATE_CUT, | |
56 | wxLIST_HITTEST_ABOVE, | |
57 | wxLIST_HITTEST_BELOW, | |
58 | wxLIST_HITTEST_NOWHERE, | |
59 | wxLIST_HITTEST_ONITEMICON, | |
60 | wxLIST_HITTEST_ONITEMLABEL, | |
61 | wxLIST_HITTEST_ONITEMRIGHT, | |
62 | wxLIST_HITTEST_ONITEMSTATEICON, | |
63 | wxLIST_HITTEST_TOLEFT, | |
64 | wxLIST_HITTEST_TORIGHT, | |
65 | wxLIST_HITTEST_ONITEM, | |
66 | wxLIST_NEXT_ABOVE, | |
67 | wxLIST_NEXT_ALL, | |
68 | wxLIST_NEXT_BELOW, | |
69 | wxLIST_NEXT_LEFT, | |
70 | wxLIST_NEXT_RIGHT, | |
71 | wxLIST_ALIGN_DEFAULT, | |
72 | wxLIST_ALIGN_LEFT, | |
73 | wxLIST_ALIGN_TOP, | |
74 | wxLIST_ALIGN_SNAP_TO_GRID, | |
75 | wxLIST_FORMAT_LEFT, | |
76 | wxLIST_FORMAT_RIGHT, | |
77 | wxLIST_FORMAT_CENTRE, | |
78 | wxLIST_FORMAT_CENTER, | |
79 | wxLIST_AUTOSIZE, | |
80 | wxLIST_AUTOSIZE_USEHEADER, | |
81 | wxLIST_RECT_BOUNDS, | |
82 | wxLIST_RECT_ICON, | |
83 | wxLIST_RECT_LABEL, | |
84 | wxLIST_FIND_UP, | |
85 | wxLIST_FIND_DOWN, | |
86 | wxLIST_FIND_LEFT, | |
87 | wxLIST_FIND_RIGHT, | |
88 | }; | |
89 | ||
90 | ||
7bf85405 RD |
91 | class wxListItem { |
92 | public: | |
93 | long m_mask; // Indicates what fields are valid | |
94 | long m_itemId; // The zero-based item position | |
95 | int m_col; // Zero-based column, if in report mode | |
96 | long m_state; // The state of the item | |
97 | long m_stateMask; // Which flags of m_state are valid (uses same flags) | |
98 | wxString m_text; // The label/header text | |
99 | int m_image; // The zero-based index into an image list | |
100 | long m_data; // App-defined data | |
101 | // wxColour *m_colour; // only wxGLC, not supported by Windows ;-> | |
102 | ||
103 | // For columns only | |
104 | int m_format; // left, right, centre | |
105 | int m_width; // width of column | |
106 | ||
107 | wxListItem(); | |
108 | ~wxListItem(); | |
109 | }; | |
110 | ||
111 | class wxListEvent: public wxCommandEvent { | |
112 | public: | |
113 | int m_code; | |
114 | long m_itemIndex; | |
115 | long m_oldItemIndex; | |
116 | int m_col; | |
117 | bool m_cancelled; | |
118 | wxPoint m_pointDrag; | |
119 | wxListItem m_item; | |
120 | }; | |
121 | ||
122 | ||
123 | ||
124 | ||
125 | class wxListCtrl : public wxControl { | |
126 | public: | |
127 | wxListCtrl(wxWindow* parent, wxWindowID id, | |
128 | const wxPoint& pos = wxPyDefaultPosition, | |
129 | const wxSize& size = wxPyDefaultSize, | |
130 | long style = wxLC_ICON, | |
131 | const wxValidator& validator = wxPyDefaultValidator, | |
132 | char* name = "listCtrl"); | |
133 | ||
b8b8dda7 | 134 | %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)" |
9c039d08 | 135 | |
7bf85405 RD |
136 | bool Arrange(int flag = wxLIST_ALIGN_DEFAULT); |
137 | bool DeleteItem(long item); | |
138 | bool DeleteAllItems(); | |
139 | bool DeleteColumn(int col); | |
140 | bool DeleteAllColumns(void); | |
141 | void ClearAll(void); | |
4f22cf8d | 142 | #ifdef __WXMSW__ |
7bf85405 RD |
143 | wxTextCtrl* EditLabel(long item); |
144 | bool EndEditLabel(bool cancel); | |
4f22cf8d | 145 | wxTextCtrl* GetEditControl(); |
fb5e0af0 | 146 | #endif |
7bf85405 RD |
147 | bool EnsureVisible(long item); |
148 | long FindItem(long start, const wxString& str, bool partial = FALSE); | |
149 | %name(FindItemData)long FindItem(long start, long data); | |
150 | %name(FindItemAtPos)long FindItem(long start, const wxPoint& pt, | |
151 | int direction); | |
152 | bool GetColumn(int col, wxListItem& item); | |
153 | int GetColumnWidth(int col); | |
154 | int GetCountPerPage(); | |
7bf85405 RD |
155 | wxImageList* GetImageList(int which); |
156 | long GetItemData(long item); | |
157 | ||
158 | %addmethods { | |
0699c864 | 159 | %new wxListItem* GetItem(long itemId) { |
7bf85405 | 160 | wxListItem* info = new wxListItem; |
0699c864 | 161 | info->m_itemId = itemId; |
7bf85405 RD |
162 | self->GetItem(*info); |
163 | return info; | |
164 | } | |
165 | %new wxPoint* GetItemPosition(long item) { | |
166 | wxPoint* pos = new wxPoint; | |
167 | self->GetItemPosition(item, *pos); | |
168 | return pos; | |
169 | } | |
170 | %new wxRect* GetItemRect(long item, int code = wxLIST_RECT_BOUNDS) { | |
171 | wxRect* rect= new wxRect; | |
172 | self->GetItemRect(item, *rect, code); | |
173 | return rect; | |
174 | } | |
175 | } | |
176 | ||
177 | int GetItemState(long item, long stateMask); | |
178 | int GetItemCount(); | |
179 | int GetItemSpacing(bool isSmall); | |
180 | wxString GetItemText(long item); | |
181 | long GetNextItem(long item, | |
182 | int geometry = wxLIST_NEXT_ALL, | |
183 | int state = wxLIST_STATE_DONTCARE); | |
184 | int GetSelectedItemCount(); | |
fb5e0af0 | 185 | #ifdef __WXMSW__ |
7bf85405 | 186 | wxColour GetTextColour(); |
4f22cf8d | 187 | void SetTextColour(const wxColour& col); |
fb5e0af0 | 188 | #endif |
7bf85405 RD |
189 | long GetTopItem(); |
190 | long HitTest(const wxPoint& point, int& OUTPUT); | |
0699c864 | 191 | %name(InsertColumnWith)long InsertColumn(long col, wxListItem& info); |
7bf85405 RD |
192 | long InsertColumn(long col, const wxString& heading, |
193 | int format = wxLIST_FORMAT_LEFT, | |
194 | int width = -1); | |
195 | ||
196 | long InsertItem(wxListItem& info); | |
197 | %name(InsertStringItem) long InsertItem(long index, const wxString& label); | |
198 | %name(InsertImageItem) long InsertItem(long index, int imageIndex); | |
199 | %name(InsertImageStringItem)long InsertItem(long index, const wxString& label, | |
200 | int imageIndex); | |
201 | ||
202 | bool ScrollList(int dx, int dy); | |
203 | void SetBackgroundColour(const wxColour& col); | |
204 | bool SetColumn(int col, wxListItem& item); | |
205 | bool SetColumnWidth(int col, int width); | |
206 | void SetImageList(wxImageList* imageList, int which); | |
af309447 | 207 | |
7bf85405 | 208 | bool SetItem(wxListItem& info); |
af309447 | 209 | %name(SetStringItem)long SetItem(long index, int col, const wxString& label, |
7bf85405 | 210 | int imageId = -1); |
af309447 | 211 | |
7bf85405 RD |
212 | bool SetItemData(long item, long data); |
213 | bool SetItemImage(long item, int image, int selImage); | |
214 | bool SetItemPosition(long item, const wxPoint& pos); | |
215 | bool SetItemState(long item, long state, long stateMask); | |
216 | void SetItemText(long item, const wxString& text); | |
217 | void SetSingleStyle(long style, bool add = TRUE); | |
7bf85405 RD |
218 | void SetWindowStyleFlag(long style); |
219 | // TODO: bool SortItems(wxListCtrlCompare fn, long data); | |
220 | }; | |
221 | ||
222 | ||
223 | ||
224 | //---------------------------------------------------------------------- | |
225 | ||
226 | ||
d5c9047a RD |
227 | class wxTreeItemId { |
228 | public: | |
229 | wxTreeItemId(); | |
230 | ~wxTreeItemId(); | |
bb0054cd | 231 | bool IsOk(); |
d5c9047a | 232 | |
d5c9047a RD |
233 | }; |
234 | ||
235 | ||
236 | ||
cf694132 RD |
237 | %{ |
238 | class wxPyTreeItemData : public wxTreeItemData { | |
d5c9047a | 239 | public: |
cf694132 RD |
240 | wxPyTreeItemData(PyObject* obj = NULL) { |
241 | if (obj == NULL) | |
242 | obj = Py_None; | |
243 | Py_INCREF(obj); | |
244 | m_obj = obj; | |
245 | } | |
d5c9047a | 246 | |
cf694132 | 247 | ~wxPyTreeItemData() { |
bb0054cd RD |
248 | #ifdef WXP_WITH_THREAD |
249 | PyEval_RestoreThread(wxPyEventThreadState); | |
250 | #endif | |
cf694132 | 251 | Py_DECREF(m_obj); |
bb0054cd RD |
252 | #ifdef WXP_WITH_THREAD |
253 | PyEval_SaveThread(); | |
254 | #endif | |
cf694132 RD |
255 | } |
256 | ||
257 | PyObject* GetData() { | |
258 | Py_INCREF(m_obj); | |
259 | return m_obj; | |
260 | } | |
261 | ||
262 | void SetData(PyObject* obj) { | |
263 | Py_DECREF(m_obj); | |
264 | m_obj = obj; | |
265 | Py_INCREF(obj); | |
266 | } | |
267 | ||
268 | PyObject* m_obj; | |
d5c9047a | 269 | }; |
cf694132 | 270 | %} |
d5c9047a RD |
271 | |
272 | ||
273 | ||
cf694132 RD |
274 | %name(wxTreeItemData) class wxPyTreeItemData { |
275 | public: | |
276 | wxPyTreeItemData(PyObject* obj = NULL); | |
277 | ||
278 | PyObject* GetData(); | |
279 | void SetData(PyObject* obj); | |
280 | ||
281 | const wxTreeItemId& GetId(); | |
282 | void SetId(const wxTreeItemId& id); | |
283 | }; | |
284 | ||
285 | ||
d5c9047a RD |
286 | |
287 | class wxTreeEvent : public wxCommandEvent { | |
288 | public: | |
289 | wxTreeItemId GetItem(); | |
290 | wxTreeItemId GetOldItem(); | |
291 | wxPoint GetPoint(); | |
292 | int GetCode(); | |
293 | void Veto(); | |
294 | }; | |
295 | ||
296 | ||
297 | // These are for the GetFirstChild/GetNextChild methods below | |
298 | %typemap(python, in) long& INOUT = long* INOUT; | |
299 | %typemap(python, argout) long& INOUT = long* INOUT; | |
300 | ||
301 | ||
302 | class wxTreeCtrl : public wxControl { | |
303 | public: | |
304 | wxTreeCtrl(wxWindow *parent, wxWindowID id = -1, | |
305 | const wxPoint& pos = wxPyDefaultPosition, | |
306 | const wxSize& size = wxPyDefaultSize, | |
307 | long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT, | |
308 | const wxValidator& validator = wxPyDefaultValidator, | |
309 | char* name = "wxTreeCtrl"); | |
310 | ||
b8b8dda7 | 311 | %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)" |
d5c9047a RD |
312 | |
313 | size_t GetCount(); | |
314 | unsigned int GetIndent(); | |
315 | void SetIndent(unsigned int indent); | |
316 | wxImageList *GetImageList(); | |
317 | wxImageList *GetStateImageList(); | |
318 | void SetImageList(wxImageList *imageList); | |
319 | void SetStateImageList(wxImageList *imageList); | |
320 | ||
321 | wxString GetItemText(const wxTreeItemId& item); | |
322 | int GetItemImage(const wxTreeItemId& item); | |
323 | int GetItemSelectedImage(const wxTreeItemId& item); | |
d5c9047a RD |
324 | |
325 | void SetItemText(const wxTreeItemId& item, const wxString& text); | |
326 | void SetItemImage(const wxTreeItemId& item, int image); | |
327 | void SetItemSelectedImage(const wxTreeItemId& item, int image); | |
08127323 | 328 | void SetItemHasChildren(const wxTreeItemId& item, bool hasChildren = TRUE); |
d5c9047a | 329 | |
cf694132 RD |
330 | %addmethods { |
331 | // [Get|Set]ItemData substitutes. Automatically create wxPyTreeItemData | |
332 | // if needed. | |
333 | wxPyTreeItemData* GetItemData(const wxTreeItemId& item) { | |
334 | wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item); | |
335 | if (data == NULL) { | |
336 | data = new wxPyTreeItemData(); | |
337 | self->SetItemData(item, data); | |
338 | } | |
339 | return data; | |
340 | } | |
341 | ||
342 | void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) { | |
343 | self->SetItemData(item, data); | |
344 | } | |
345 | ||
346 | // [Get|Set]PyData are short-cuts. Also made somewhat crash-proof by | |
347 | // automatically creating data classes. | |
348 | PyObject* GetPyData(const wxTreeItemId& item) { | |
349 | wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item); | |
350 | if (data == NULL) { | |
351 | data = new wxPyTreeItemData(); | |
352 | self->SetItemData(item, data); | |
353 | } | |
354 | return data->GetData(); | |
355 | } | |
356 | ||
357 | void SetPyData(const wxTreeItemId& item, PyObject* obj) { | |
358 | wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item); | |
359 | if (data == NULL) { | |
360 | data = new wxPyTreeItemData(obj); | |
361 | self->SetItemData(item, data); | |
362 | } else | |
363 | data->SetData(obj); | |
364 | } | |
365 | } | |
366 | ||
367 | ||
d5c9047a RD |
368 | bool IsVisible(const wxTreeItemId& item); |
369 | bool ItemHasChildren(const wxTreeItemId& item); | |
370 | bool IsExpanded(const wxTreeItemId& item); | |
371 | bool IsSelected(const wxTreeItemId& item); | |
372 | ||
373 | wxTreeItemId GetRootItem(); | |
374 | wxTreeItemId GetSelection(); | |
375 | wxTreeItemId GetParent(const wxTreeItemId& item); | |
376 | ||
bb0054cd RD |
377 | size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = TRUE); |
378 | ||
d5c9047a RD |
379 | wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& INOUT); |
380 | wxTreeItemId GetNextChild(const wxTreeItemId& item, long& INOUT); | |
381 | wxTreeItemId GetNextSibling(const wxTreeItemId& item); | |
382 | wxTreeItemId GetPrevSibling(const wxTreeItemId& item); | |
383 | wxTreeItemId GetFirstVisibleItem(); | |
384 | wxTreeItemId GetNextVisible(const wxTreeItemId& item); | |
385 | wxTreeItemId GetPrevVisible(const wxTreeItemId& item); | |
386 | ||
387 | ||
388 | wxTreeItemId AddRoot(const wxString& text, | |
389 | int image = -1, int selectedImage = -1, | |
cf694132 | 390 | wxPyTreeItemData *data = NULL); |
d5c9047a RD |
391 | wxTreeItemId PrependItem(const wxTreeItemId& parent, |
392 | const wxString& text, | |
393 | int image = -1, int selectedImage = -1, | |
cf694132 | 394 | wxPyTreeItemData *data = NULL); |
d5c9047a RD |
395 | wxTreeItemId InsertItem(const wxTreeItemId& parent, |
396 | const wxTreeItemId& idPrevious, | |
397 | const wxString& text, | |
398 | int image = -1, int selectedImage = -1, | |
cf694132 | 399 | wxPyTreeItemData *data = NULL); |
d5c9047a RD |
400 | wxTreeItemId AppendItem(const wxTreeItemId& parent, |
401 | const wxString& text, | |
402 | int image = -1, int selectedImage = -1, | |
cf694132 | 403 | wxPyTreeItemData *data = NULL); |
d5c9047a RD |
404 | |
405 | void Delete(const wxTreeItemId& item); | |
08127323 | 406 | void DeleteChildren(const wxTreeItemId& item); |
d5c9047a RD |
407 | void DeleteAllItems(); |
408 | ||
409 | void Expand(const wxTreeItemId& item); | |
410 | void Collapse(const wxTreeItemId& item); | |
411 | void CollapseAndReset(const wxTreeItemId& item); | |
412 | void Toggle(const wxTreeItemId& item); | |
413 | ||
414 | void Unselect(); | |
415 | void SelectItem(const wxTreeItemId& item); | |
416 | void EnsureVisible(const wxTreeItemId& item); | |
417 | void ScrollTo(const wxTreeItemId& item); | |
418 | ||
419 | wxTextCtrl* EditLabel(const wxTreeItemId& item); | |
420 | // **** figure out how to do this | |
421 | // wxClassInfo* textCtrlClass = CLASSINFO(wxTextCtrl)); | |
422 | wxTextCtrl* GetEditControl(); | |
423 | void EndEditLabel(const wxTreeItemId& item, bool discardChanges = FALSE); | |
424 | ||
60e05667 | 425 | // void SortChildren(const wxTreeItemId& item); |
d5c9047a RD |
426 | // **** And this too |
427 | // wxTreeItemCmpFunc *cmpFunction = NULL); | |
428 | ||
b8b8dda7 RD |
429 | void SetItemBold(const wxTreeItemId& item, bool bold = TRUE); |
430 | bool IsBold(const wxTreeItemId& item) const; | |
431 | wxTreeItemId HitTest(const wxPoint& point); | |
c127177f RD |
432 | |
433 | %pragma(python) addtoclass = " | |
434 | # Redefine a couple methods that SWIG gets a bit confused on... | |
435 | def GetFirstChild(self,arg0,arg1): | |
436 | val1, val2 = controls2c.wxTreeCtrl_GetFirstChild(self.this,arg0.this,arg1) | |
437 | val1 = wxTreeItemIdPtr(val1) | |
438 | val1.thisown = 1 | |
439 | return (val1,val2) | |
440 | def GetNextChild(self,arg0,arg1): | |
bb0054cd | 441 | val1, val2 = controls2c.wxTreeCtrl_GetNextChild(self.this,arg0.this,arg1) |
c127177f RD |
442 | val1 = wxTreeItemIdPtr(val1) |
443 | val1.thisown = 1 | |
444 | return (val1,val2) | |
445 | " | |
d5c9047a RD |
446 | }; |
447 | ||
d5c9047a | 448 | |
7bf85405 RD |
449 | //---------------------------------------------------------------------- |
450 | ||
9c039d08 | 451 | #ifdef SKIPTHIS |
fb5e0af0 | 452 | #ifdef __WXMSW__ |
7bf85405 RD |
453 | class wxTabEvent : public wxCommandEvent { |
454 | public: | |
455 | }; | |
456 | ||
457 | ||
458 | ||
459 | class wxTabCtrl : public wxControl { | |
460 | public: | |
461 | wxTabCtrl(wxWindow* parent, wxWindowID id, | |
462 | const wxPoint& pos = wxPyDefaultPosition, | |
463 | const wxSize& size = wxPyDefaultSize, | |
464 | long style = 0, | |
465 | char* name = "tabCtrl"); | |
466 | ||
b8b8dda7 | 467 | %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)" |
9c039d08 | 468 | |
7bf85405 RD |
469 | bool DeleteAllItems(); |
470 | bool DeleteItem(int item); | |
471 | wxImageList* GetImageList(); | |
472 | int GetItemCount(); | |
473 | // TODO: void* GetItemData(); | |
474 | int GetItemImage(int item); | |
475 | ||
476 | %addmethods { | |
477 | %new wxRect* GetItemRect(int item) { | |
478 | wxRect* rect = new wxRect; | |
479 | self->GetItemRect(item, *rect); | |
480 | return rect; | |
481 | } | |
482 | } | |
483 | ||
484 | wxString GetItemText(int item); | |
485 | bool GetRowCount(); | |
486 | int GetSelection(); | |
487 | int HitTest(const wxPoint& pt, long& OUTPUT); | |
488 | void InsertItem(int item, const wxString& text, | |
489 | int imageId = -1, void* clientData = NULL); | |
490 | // TODO: bool SetItemData(int item, void* data); | |
491 | bool SetItemImage(int item, int image); | |
492 | void SetImageList(wxImageList* imageList); | |
493 | void SetItemSize(const wxSize& size); | |
494 | bool SetItemText(int item, const wxString& text); | |
495 | void SetPadding(const wxSize& padding); | |
496 | int SetSelection(int item); | |
497 | ||
498 | }; | |
499 | ||
9c039d08 | 500 | #endif |
fb5e0af0 RD |
501 | #endif |
502 | ||
7bf85405 RD |
503 | //---------------------------------------------------------------------- |
504 | ||
505 |