]>
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(); |
8bf5d46e RD |
146 | #else |
147 | void EditLabel(long item); | |
fb5e0af0 | 148 | #endif |
7bf85405 RD |
149 | bool EnsureVisible(long item); |
150 | long FindItem(long start, const wxString& str, bool partial = FALSE); | |
151 | %name(FindItemData)long FindItem(long start, long data); | |
152 | %name(FindItemAtPos)long FindItem(long start, const wxPoint& pt, | |
153 | int direction); | |
154 | bool GetColumn(int col, wxListItem& item); | |
155 | int GetColumnWidth(int col); | |
156 | int GetCountPerPage(); | |
7bf85405 RD |
157 | wxImageList* GetImageList(int which); |
158 | long GetItemData(long item); | |
159 | ||
160 | %addmethods { | |
0699c864 | 161 | %new wxListItem* GetItem(long itemId) { |
7bf85405 | 162 | wxListItem* info = new wxListItem; |
0699c864 | 163 | info->m_itemId = itemId; |
7bf85405 RD |
164 | self->GetItem(*info); |
165 | return info; | |
166 | } | |
167 | %new wxPoint* GetItemPosition(long item) { | |
168 | wxPoint* pos = new wxPoint; | |
169 | self->GetItemPosition(item, *pos); | |
170 | return pos; | |
171 | } | |
172 | %new wxRect* GetItemRect(long item, int code = wxLIST_RECT_BOUNDS) { | |
173 | wxRect* rect= new wxRect; | |
174 | self->GetItemRect(item, *rect, code); | |
175 | return rect; | |
176 | } | |
177 | } | |
178 | ||
179 | int GetItemState(long item, long stateMask); | |
180 | int GetItemCount(); | |
181 | int GetItemSpacing(bool isSmall); | |
182 | wxString GetItemText(long item); | |
183 | long GetNextItem(long item, | |
184 | int geometry = wxLIST_NEXT_ALL, | |
185 | int state = wxLIST_STATE_DONTCARE); | |
186 | int GetSelectedItemCount(); | |
fb5e0af0 | 187 | #ifdef __WXMSW__ |
7bf85405 | 188 | wxColour GetTextColour(); |
4f22cf8d | 189 | void SetTextColour(const wxColour& col); |
fb5e0af0 | 190 | #endif |
7bf85405 RD |
191 | long GetTopItem(); |
192 | long HitTest(const wxPoint& point, int& OUTPUT); | |
0699c864 | 193 | %name(InsertColumnWith)long InsertColumn(long col, wxListItem& info); |
7bf85405 RD |
194 | long InsertColumn(long col, const wxString& heading, |
195 | int format = wxLIST_FORMAT_LEFT, | |
196 | int width = -1); | |
197 | ||
198 | long InsertItem(wxListItem& info); | |
199 | %name(InsertStringItem) long InsertItem(long index, const wxString& label); | |
200 | %name(InsertImageItem) long InsertItem(long index, int imageIndex); | |
201 | %name(InsertImageStringItem)long InsertItem(long index, const wxString& label, | |
202 | int imageIndex); | |
203 | ||
204 | bool ScrollList(int dx, int dy); | |
205 | void SetBackgroundColour(const wxColour& col); | |
206 | bool SetColumn(int col, wxListItem& item); | |
207 | bool SetColumnWidth(int col, int width); | |
208 | void SetImageList(wxImageList* imageList, int which); | |
af309447 | 209 | |
7bf85405 | 210 | bool SetItem(wxListItem& info); |
af309447 | 211 | %name(SetStringItem)long SetItem(long index, int col, const wxString& label, |
7bf85405 | 212 | int imageId = -1); |
af309447 | 213 | |
7bf85405 RD |
214 | bool SetItemData(long item, long data); |
215 | bool SetItemImage(long item, int image, int selImage); | |
216 | bool SetItemPosition(long item, const wxPoint& pos); | |
217 | bool SetItemState(long item, long state, long stateMask); | |
218 | void SetItemText(long item, const wxString& text); | |
219 | void SetSingleStyle(long style, bool add = TRUE); | |
7bf85405 RD |
220 | void SetWindowStyleFlag(long style); |
221 | // TODO: bool SortItems(wxListCtrlCompare fn, long data); | |
222 | }; | |
223 | ||
224 | ||
225 | ||
226 | //---------------------------------------------------------------------- | |
227 | ||
228 | ||
d5c9047a RD |
229 | class wxTreeItemId { |
230 | public: | |
231 | wxTreeItemId(); | |
232 | ~wxTreeItemId(); | |
bb0054cd | 233 | bool IsOk(); |
d5c9047a | 234 | |
d5c9047a RD |
235 | }; |
236 | ||
237 | ||
238 | ||
cf694132 RD |
239 | %{ |
240 | class wxPyTreeItemData : public wxTreeItemData { | |
d5c9047a | 241 | public: |
cf694132 RD |
242 | wxPyTreeItemData(PyObject* obj = NULL) { |
243 | if (obj == NULL) | |
244 | obj = Py_None; | |
245 | Py_INCREF(obj); | |
246 | m_obj = obj; | |
247 | } | |
d5c9047a | 248 | |
cf694132 | 249 | ~wxPyTreeItemData() { |
bb0054cd RD |
250 | #ifdef WXP_WITH_THREAD |
251 | PyEval_RestoreThread(wxPyEventThreadState); | |
252 | #endif | |
cf694132 | 253 | Py_DECREF(m_obj); |
bb0054cd RD |
254 | #ifdef WXP_WITH_THREAD |
255 | PyEval_SaveThread(); | |
256 | #endif | |
cf694132 RD |
257 | } |
258 | ||
259 | PyObject* GetData() { | |
260 | Py_INCREF(m_obj); | |
261 | return m_obj; | |
262 | } | |
263 | ||
264 | void SetData(PyObject* obj) { | |
265 | Py_DECREF(m_obj); | |
266 | m_obj = obj; | |
267 | Py_INCREF(obj); | |
268 | } | |
269 | ||
270 | PyObject* m_obj; | |
d5c9047a | 271 | }; |
cf694132 | 272 | %} |
d5c9047a RD |
273 | |
274 | ||
275 | ||
cf694132 RD |
276 | %name(wxTreeItemData) class wxPyTreeItemData { |
277 | public: | |
278 | wxPyTreeItemData(PyObject* obj = NULL); | |
279 | ||
280 | PyObject* GetData(); | |
281 | void SetData(PyObject* obj); | |
282 | ||
283 | const wxTreeItemId& GetId(); | |
284 | void SetId(const wxTreeItemId& id); | |
285 | }; | |
286 | ||
287 | ||
d5c9047a | 288 | |
8bf5d46e | 289 | class wxTreeEvent : public wxNotifyEvent { |
d5c9047a RD |
290 | public: |
291 | wxTreeItemId GetItem(); | |
292 | wxTreeItemId GetOldItem(); | |
293 | wxPoint GetPoint(); | |
294 | int GetCode(); | |
8bf5d46e | 295 | const wxString& GetLabel(); |
d5c9047a RD |
296 | }; |
297 | ||
298 | ||
299 | // These are for the GetFirstChild/GetNextChild methods below | |
300 | %typemap(python, in) long& INOUT = long* INOUT; | |
301 | %typemap(python, argout) long& INOUT = long* INOUT; | |
302 | ||
303 | ||
304 | class wxTreeCtrl : public wxControl { | |
305 | public: | |
306 | wxTreeCtrl(wxWindow *parent, wxWindowID id = -1, | |
307 | const wxPoint& pos = wxPyDefaultPosition, | |
308 | const wxSize& size = wxPyDefaultSize, | |
309 | long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT, | |
310 | const wxValidator& validator = wxPyDefaultValidator, | |
311 | char* name = "wxTreeCtrl"); | |
312 | ||
b8b8dda7 | 313 | %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)" |
d5c9047a RD |
314 | |
315 | size_t GetCount(); | |
316 | unsigned int GetIndent(); | |
317 | void SetIndent(unsigned int indent); | |
318 | wxImageList *GetImageList(); | |
319 | wxImageList *GetStateImageList(); | |
320 | void SetImageList(wxImageList *imageList); | |
321 | void SetStateImageList(wxImageList *imageList); | |
322 | ||
323 | wxString GetItemText(const wxTreeItemId& item); | |
324 | int GetItemImage(const wxTreeItemId& item); | |
325 | int GetItemSelectedImage(const wxTreeItemId& item); | |
d5c9047a RD |
326 | |
327 | void SetItemText(const wxTreeItemId& item, const wxString& text); | |
328 | void SetItemImage(const wxTreeItemId& item, int image); | |
329 | void SetItemSelectedImage(const wxTreeItemId& item, int image); | |
08127323 | 330 | void SetItemHasChildren(const wxTreeItemId& item, bool hasChildren = TRUE); |
d5c9047a | 331 | |
cf694132 RD |
332 | %addmethods { |
333 | // [Get|Set]ItemData substitutes. Automatically create wxPyTreeItemData | |
334 | // if needed. | |
335 | wxPyTreeItemData* GetItemData(const wxTreeItemId& item) { | |
336 | wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item); | |
337 | if (data == NULL) { | |
338 | data = new wxPyTreeItemData(); | |
339 | self->SetItemData(item, data); | |
340 | } | |
341 | return data; | |
342 | } | |
343 | ||
344 | void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) { | |
345 | self->SetItemData(item, data); | |
346 | } | |
347 | ||
348 | // [Get|Set]PyData are short-cuts. Also made somewhat crash-proof by | |
349 | // automatically creating data classes. | |
350 | PyObject* GetPyData(const wxTreeItemId& item) { | |
351 | wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item); | |
352 | if (data == NULL) { | |
353 | data = new wxPyTreeItemData(); | |
354 | self->SetItemData(item, data); | |
355 | } | |
356 | return data->GetData(); | |
357 | } | |
358 | ||
359 | void SetPyData(const wxTreeItemId& item, PyObject* obj) { | |
360 | wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item); | |
361 | if (data == NULL) { | |
362 | data = new wxPyTreeItemData(obj); | |
363 | self->SetItemData(item, data); | |
364 | } else | |
365 | data->SetData(obj); | |
366 | } | |
367 | } | |
368 | ||
369 | ||
d5c9047a RD |
370 | bool IsVisible(const wxTreeItemId& item); |
371 | bool ItemHasChildren(const wxTreeItemId& item); | |
372 | bool IsExpanded(const wxTreeItemId& item); | |
373 | bool IsSelected(const wxTreeItemId& item); | |
374 | ||
375 | wxTreeItemId GetRootItem(); | |
376 | wxTreeItemId GetSelection(); | |
377 | wxTreeItemId GetParent(const wxTreeItemId& item); | |
378 | ||
bb0054cd RD |
379 | size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = TRUE); |
380 | ||
d5c9047a RD |
381 | wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& INOUT); |
382 | wxTreeItemId GetNextChild(const wxTreeItemId& item, long& INOUT); | |
383 | wxTreeItemId GetNextSibling(const wxTreeItemId& item); | |
384 | wxTreeItemId GetPrevSibling(const wxTreeItemId& item); | |
385 | wxTreeItemId GetFirstVisibleItem(); | |
386 | wxTreeItemId GetNextVisible(const wxTreeItemId& item); | |
387 | wxTreeItemId GetPrevVisible(const wxTreeItemId& item); | |
388 | ||
389 | ||
390 | wxTreeItemId AddRoot(const wxString& text, | |
391 | int image = -1, int selectedImage = -1, | |
cf694132 | 392 | wxPyTreeItemData *data = NULL); |
d5c9047a RD |
393 | wxTreeItemId PrependItem(const wxTreeItemId& parent, |
394 | const wxString& text, | |
395 | int image = -1, int selectedImage = -1, | |
cf694132 | 396 | wxPyTreeItemData *data = NULL); |
d5c9047a RD |
397 | wxTreeItemId InsertItem(const wxTreeItemId& parent, |
398 | const wxTreeItemId& idPrevious, | |
399 | const wxString& text, | |
400 | int image = -1, int selectedImage = -1, | |
cf694132 | 401 | wxPyTreeItemData *data = NULL); |
d5c9047a RD |
402 | wxTreeItemId AppendItem(const wxTreeItemId& parent, |
403 | const wxString& text, | |
404 | int image = -1, int selectedImage = -1, | |
cf694132 | 405 | wxPyTreeItemData *data = NULL); |
d5c9047a RD |
406 | |
407 | void Delete(const wxTreeItemId& item); | |
08127323 | 408 | void DeleteChildren(const wxTreeItemId& item); |
d5c9047a RD |
409 | void DeleteAllItems(); |
410 | ||
411 | void Expand(const wxTreeItemId& item); | |
412 | void Collapse(const wxTreeItemId& item); | |
413 | void CollapseAndReset(const wxTreeItemId& item); | |
414 | void Toggle(const wxTreeItemId& item); | |
415 | ||
416 | void Unselect(); | |
8bf5d46e | 417 | void UnselectAll(); |
d5c9047a RD |
418 | void SelectItem(const wxTreeItemId& item); |
419 | void EnsureVisible(const wxTreeItemId& item); | |
420 | void ScrollTo(const wxTreeItemId& item); | |
8bf5d46e | 421 | #ifdef __WXMSW__ |
d5c9047a | 422 | wxTextCtrl* EditLabel(const wxTreeItemId& item); |
d5c9047a RD |
423 | wxTextCtrl* GetEditControl(); |
424 | void EndEditLabel(const wxTreeItemId& item, bool discardChanges = FALSE); | |
8bf5d46e RD |
425 | #else |
426 | void EditLabel(const wxTreeItemId& item); | |
427 | #endif | |
d5c9047a | 428 | |
60e05667 | 429 | // void SortChildren(const wxTreeItemId& item); |
d5c9047a RD |
430 | // **** And this too |
431 | // wxTreeItemCmpFunc *cmpFunction = NULL); | |
432 | ||
b8b8dda7 RD |
433 | void SetItemBold(const wxTreeItemId& item, bool bold = TRUE); |
434 | bool IsBold(const wxTreeItemId& item) const; | |
435 | wxTreeItemId HitTest(const wxPoint& point); | |
c127177f RD |
436 | |
437 | %pragma(python) addtoclass = " | |
438 | # Redefine a couple methods that SWIG gets a bit confused on... | |
439 | def GetFirstChild(self,arg0,arg1): | |
440 | val1, val2 = controls2c.wxTreeCtrl_GetFirstChild(self.this,arg0.this,arg1) | |
441 | val1 = wxTreeItemIdPtr(val1) | |
442 | val1.thisown = 1 | |
443 | return (val1,val2) | |
444 | def GetNextChild(self,arg0,arg1): | |
bb0054cd | 445 | val1, val2 = controls2c.wxTreeCtrl_GetNextChild(self.this,arg0.this,arg1) |
c127177f RD |
446 | val1 = wxTreeItemIdPtr(val1) |
447 | val1.thisown = 1 | |
448 | return (val1,val2) | |
449 | " | |
d5c9047a RD |
450 | }; |
451 | ||
d5c9047a | 452 | |
7bf85405 RD |
453 | //---------------------------------------------------------------------- |
454 | ||
9c039d08 | 455 | #ifdef SKIPTHIS |
fb5e0af0 | 456 | #ifdef __WXMSW__ |
7bf85405 RD |
457 | class wxTabEvent : public wxCommandEvent { |
458 | public: | |
459 | }; | |
460 | ||
461 | ||
462 | ||
463 | class wxTabCtrl : public wxControl { | |
464 | public: | |
465 | wxTabCtrl(wxWindow* parent, wxWindowID id, | |
466 | const wxPoint& pos = wxPyDefaultPosition, | |
467 | const wxSize& size = wxPyDefaultSize, | |
468 | long style = 0, | |
469 | char* name = "tabCtrl"); | |
470 | ||
b8b8dda7 | 471 | %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)" |
9c039d08 | 472 | |
7bf85405 RD |
473 | bool DeleteAllItems(); |
474 | bool DeleteItem(int item); | |
475 | wxImageList* GetImageList(); | |
476 | int GetItemCount(); | |
477 | // TODO: void* GetItemData(); | |
478 | int GetItemImage(int item); | |
479 | ||
480 | %addmethods { | |
481 | %new wxRect* GetItemRect(int item) { | |
482 | wxRect* rect = new wxRect; | |
483 | self->GetItemRect(item, *rect); | |
484 | return rect; | |
485 | } | |
486 | } | |
487 | ||
488 | wxString GetItemText(int item); | |
489 | bool GetRowCount(); | |
490 | int GetSelection(); | |
491 | int HitTest(const wxPoint& pt, long& OUTPUT); | |
492 | void InsertItem(int item, const wxString& text, | |
493 | int imageId = -1, void* clientData = NULL); | |
494 | // TODO: bool SetItemData(int item, void* data); | |
495 | bool SetItemImage(int item, int image); | |
496 | void SetImageList(wxImageList* imageList); | |
497 | void SetItemSize(const wxSize& size); | |
498 | bool SetItemText(int item, const wxString& text); | |
499 | void SetPadding(const wxSize& padding); | |
500 | int SetSelection(int item); | |
501 | ||
502 | }; | |
503 | ||
9c039d08 | 504 | #endif |
fb5e0af0 RD |
505 | #endif |
506 | ||
7bf85405 RD |
507 | //---------------------------------------------------------------------- |
508 | ||
509 |