]> git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/src/controls2.i
804b3465c793d07afb5eb8c8fde84ada16fff750
[wxWidgets.git] / utils / wxPython / src / controls2.i
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
13 %module controls2
14
15 %{
16 #include "helpers.h"
17 #ifdef __WXMSW__
18 #include <windows.h>
19 #endif
20 #include <wx/listctrl.h>
21 #include <wx/treectrl.h>
22 %}
23
24 //----------------------------------------------------------------------
25
26 %include typemaps.i
27 %include my_typemaps.i
28
29 // Import some definitions of other classes, etc.
30 %import _defs.i
31 %import misc.i
32 %import windows.i
33 %import gdi.i
34 %import events.i
35 %import controls.i
36
37 %pragma(python) code = "import wx"
38
39 //----------------------------------------------------------------------
40
41 %{
42 extern wxValidator wxPyDefaultValidator;
43 %}
44
45 //----------------------------------------------------------------------
46
47 enum {
48 wxLIST_MASK_TEXT,
49 wxLIST_MASK_IMAGE,
50 wxLIST_MASK_DATA,
51 wxLIST_MASK_WIDTH,
52 wxLIST_MASK_FORMAT,
53 wxLIST_MASK_STATE,
54 wxLIST_STATE_DONTCARE,
55 wxLIST_STATE_DROPHILITED,
56 wxLIST_STATE_FOCUSED,
57 wxLIST_STATE_SELECTED,
58 wxLIST_STATE_CUT,
59 wxLIST_HITTEST_ABOVE,
60 wxLIST_HITTEST_BELOW,
61 wxLIST_HITTEST_NOWHERE,
62 wxLIST_HITTEST_ONITEMICON,
63 wxLIST_HITTEST_ONITEMLABEL,
64 wxLIST_HITTEST_ONITEMRIGHT,
65 wxLIST_HITTEST_ONITEMSTATEICON,
66 wxLIST_HITTEST_TOLEFT,
67 wxLIST_HITTEST_TORIGHT,
68 wxLIST_HITTEST_ONITEM,
69 wxLIST_NEXT_ABOVE,
70 wxLIST_NEXT_ALL,
71 wxLIST_NEXT_BELOW,
72 wxLIST_NEXT_LEFT,
73 wxLIST_NEXT_RIGHT,
74 wxLIST_ALIGN_DEFAULT,
75 wxLIST_ALIGN_LEFT,
76 wxLIST_ALIGN_TOP,
77 wxLIST_ALIGN_SNAP_TO_GRID,
78 wxLIST_FORMAT_LEFT,
79 wxLIST_FORMAT_RIGHT,
80 wxLIST_FORMAT_CENTRE,
81 wxLIST_FORMAT_CENTER,
82 wxLIST_AUTOSIZE,
83 wxLIST_AUTOSIZE_USEHEADER,
84 wxLIST_RECT_BOUNDS,
85 wxLIST_RECT_ICON,
86 wxLIST_RECT_LABEL,
87 wxLIST_FIND_UP,
88 wxLIST_FIND_DOWN,
89 wxLIST_FIND_LEFT,
90 wxLIST_FIND_RIGHT,
91 };
92
93
94 class wxListItem {
95 public:
96 long m_mask; // Indicates what fields are valid
97 long m_itemId; // The zero-based item position
98 int m_col; // Zero-based column, if in report mode
99 long m_state; // The state of the item
100 long m_stateMask; // Which flags of m_state are valid (uses same flags)
101 wxString m_text; // The label/header text
102 int m_image; // The zero-based index into an image list
103 long m_data; // App-defined data
104 // wxColour *m_colour; // only wxGLC, not supported by Windows ;->
105
106 // For columns only
107 int m_format; // left, right, centre
108 int m_width; // width of column
109
110 wxListItem();
111 ~wxListItem();
112 };
113
114 class wxListEvent: public wxCommandEvent {
115 public:
116 int m_code;
117 long m_itemIndex;
118 long m_oldItemIndex;
119 int m_col;
120 bool m_cancelled;
121 wxPoint m_pointDrag;
122 wxListItem m_item;
123 };
124
125
126
127
128 class wxListCtrl : public wxControl {
129 public:
130 wxListCtrl(wxWindow* parent, wxWindowID id,
131 const wxPoint& pos = wxPyDefaultPosition,
132 const wxSize& size = wxPyDefaultSize,
133 long style = wxLC_ICON,
134 const wxValidator& validator = wxPyDefaultValidator,
135 char* name = "listCtrl");
136
137 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
138
139 bool Arrange(int flag = wxLIST_ALIGN_DEFAULT);
140 bool DeleteItem(long item);
141 bool DeleteAllItems();
142 bool DeleteColumn(int col);
143 bool DeleteAllColumns(void);
144 void ClearAll(void);
145 #ifdef __WXMSW__
146 wxTextCtrl* EditLabel(long item);
147 bool EndEditLabel(bool cancel);
148 wxTextCtrl* GetEditControl();
149 #else
150 void EditLabel(long item);
151 #endif
152 bool EnsureVisible(long item);
153 long FindItem(long start, const wxString& str, bool partial = FALSE);
154 %name(FindItemData)long FindItem(long start, long data);
155 %name(FindItemAtPos)long FindItem(long start, const wxPoint& pt,
156 int direction);
157 bool GetColumn(int col, wxListItem& item);
158 int GetColumnWidth(int col);
159 int GetCountPerPage();
160 wxImageList* GetImageList(int which);
161 long GetItemData(long item);
162
163 %addmethods {
164 %new wxListItem* GetItem(long itemId, int col=0) {
165 wxListItem* info = new wxListItem;
166 info->m_itemId = itemId;
167 info->m_col = col;
168 self->GetItem(*info);
169 return info;
170 }
171 %new wxPoint* GetItemPosition(long item) {
172 wxPoint* pos = new wxPoint;
173 self->GetItemPosition(item, *pos);
174 return pos;
175 }
176 %new wxRect* GetItemRect(long item, int code = wxLIST_RECT_BOUNDS) {
177 wxRect* rect= new wxRect;
178 self->GetItemRect(item, *rect, code);
179 return rect;
180 }
181 }
182
183 int GetItemState(long item, long stateMask);
184 int GetItemCount();
185 int GetItemSpacing(bool isSmall);
186 wxString GetItemText(long item);
187 long GetNextItem(long item,
188 int geometry = wxLIST_NEXT_ALL,
189 int state = wxLIST_STATE_DONTCARE);
190 int GetSelectedItemCount();
191 #ifdef __WXMSW__
192 wxColour GetTextColour();
193 void SetTextColour(const wxColour& col);
194 #endif
195 long GetTopItem();
196 long HitTest(const wxPoint& point, int& OUTPUT);
197 %name(InsertColumnWith)long InsertColumn(long col, wxListItem& info);
198 long InsertColumn(long col, const wxString& heading,
199 int format = wxLIST_FORMAT_LEFT,
200 int width = -1);
201
202 long InsertItem(wxListItem& info);
203 %name(InsertStringItem) long InsertItem(long index, const wxString& label);
204 %name(InsertImageItem) long InsertItem(long index, int imageIndex);
205 %name(InsertImageStringItem)long InsertItem(long index, const wxString& label,
206 int imageIndex);
207
208 bool ScrollList(int dx, int dy);
209 void SetBackgroundColour(const wxColour& col);
210 bool SetColumn(int col, wxListItem& item);
211 bool SetColumnWidth(int col, int width);
212 void SetImageList(wxImageList* imageList, int which);
213
214 bool SetItem(wxListItem& info);
215 %name(SetStringItem)long SetItem(long index, int col, const wxString& label,
216 int imageId = -1);
217
218 bool SetItemData(long item, long data);
219 bool SetItemImage(long item, int image, int selImage);
220 bool SetItemPosition(long item, const wxPoint& pos);
221 bool SetItemState(long item, long state, long stateMask);
222 void SetItemText(long item, const wxString& text);
223 void SetSingleStyle(long style, bool add = TRUE);
224 void SetWindowStyleFlag(long style);
225 // TODO: bool SortItems(wxListCtrlCompare fn, long data);
226 };
227
228
229
230 //----------------------------------------------------------------------
231
232
233 class wxTreeItemId {
234 public:
235 wxTreeItemId();
236 ~wxTreeItemId();
237 bool IsOk();
238
239 };
240
241
242
243 %{
244 class wxPyTreeItemData : public wxTreeItemData {
245 public:
246 wxPyTreeItemData(PyObject* obj = NULL) {
247 if (obj == NULL)
248 obj = Py_None;
249 Py_INCREF(obj);
250 m_obj = obj;
251 }
252
253 ~wxPyTreeItemData() {
254 bool doSave = wxPyRestoreThread();
255 Py_DECREF(m_obj);
256 wxPySaveThread(doSave);
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;
271 };
272 %}
273
274
275
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
288
289 class wxTreeEvent : public wxNotifyEvent {
290 public:
291 wxTreeItemId GetItem();
292 wxTreeItemId GetOldItem();
293 wxPoint GetPoint();
294 int GetCode();
295 const wxString& GetLabel();
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
313 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
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 unsigned int GetSpacing();
324 void SetSpacing(unsigned int spacing);
325
326 wxString GetItemText(const wxTreeItemId& item);
327 int GetItemImage(const wxTreeItemId& item);
328 int GetItemSelectedImage(const wxTreeItemId& item);
329
330 void SetItemText(const wxTreeItemId& item, const wxString& text);
331 void SetItemImage(const wxTreeItemId& item, int image);
332 void SetItemSelectedImage(const wxTreeItemId& item, int image);
333 void SetItemHasChildren(const wxTreeItemId& item, bool hasChildren = TRUE);
334
335 %addmethods {
336 // [Get|Set]ItemData substitutes. Automatically create wxPyTreeItemData
337 // if needed.
338 wxPyTreeItemData* GetItemData(const wxTreeItemId& item) {
339 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
340 if (data == NULL) {
341 data = new wxPyTreeItemData();
342 self->SetItemData(item, data);
343 }
344 return data;
345 }
346
347 void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) {
348 self->SetItemData(item, data);
349 }
350
351 // [Get|Set]PyData are short-cuts. Also made somewhat crash-proof by
352 // automatically creating data classes.
353 PyObject* GetPyData(const wxTreeItemId& item) {
354 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
355 if (data == NULL) {
356 data = new wxPyTreeItemData();
357 self->SetItemData(item, data);
358 }
359 return data->GetData();
360 }
361
362 void SetPyData(const wxTreeItemId& item, PyObject* obj) {
363 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
364 if (data == NULL) {
365 data = new wxPyTreeItemData(obj);
366 self->SetItemData(item, data);
367 } else
368 data->SetData(obj);
369 }
370 }
371
372
373 bool IsVisible(const wxTreeItemId& item);
374 bool ItemHasChildren(const wxTreeItemId& item);
375 bool IsExpanded(const wxTreeItemId& item);
376 bool IsSelected(const wxTreeItemId& item);
377
378 wxTreeItemId GetRootItem();
379 wxTreeItemId GetSelection();
380 wxTreeItemId GetParent(const wxTreeItemId& item);
381 //size_t GetSelections(wxArrayTreeItemIds& selection);
382 %addmethods {
383 PyObject* GetSelections() {
384 PyObject* rval = PyList_New(0);
385 wxArrayTreeItemIds array;
386 size_t num, x;
387 num = self->GetSelections(array);
388 for (x=0; x < num; x++) {
389 PyObject* item = wxPyConstructObject((void*)&array.Item(x),
390 "wxTreeItemId");
391 PyList_Append(rval, item);
392 }
393 return rval;
394 }
395 }
396
397
398
399 size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = TRUE);
400
401 wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& INOUT);
402 wxTreeItemId GetNextChild(const wxTreeItemId& item, long& INOUT);
403 wxTreeItemId GetNextSibling(const wxTreeItemId& item);
404 wxTreeItemId GetPrevSibling(const wxTreeItemId& item);
405 wxTreeItemId GetFirstVisibleItem();
406 wxTreeItemId GetNextVisible(const wxTreeItemId& item);
407 wxTreeItemId GetPrevVisible(const wxTreeItemId& item);
408 wxTreeItemId GetLastChild(const wxTreeItemId& item);
409
410
411
412 wxTreeItemId AddRoot(const wxString& text,
413 int image = -1, int selectedImage = -1,
414 wxPyTreeItemData *data = NULL);
415 wxTreeItemId PrependItem(const wxTreeItemId& parent,
416 const wxString& text,
417 int image = -1, int selectedImage = -1,
418 wxPyTreeItemData *data = NULL);
419 wxTreeItemId InsertItem(const wxTreeItemId& parent,
420 const wxTreeItemId& idPrevious,
421 const wxString& text,
422 int image = -1, int selectedImage = -1,
423 wxPyTreeItemData *data = NULL);
424 wxTreeItemId AppendItem(const wxTreeItemId& parent,
425 const wxString& text,
426 int image = -1, int selectedImage = -1,
427 wxPyTreeItemData *data = NULL);
428
429 void Delete(const wxTreeItemId& item);
430 void DeleteChildren(const wxTreeItemId& item);
431 void DeleteAllItems();
432
433 void Expand(const wxTreeItemId& item);
434 void Collapse(const wxTreeItemId& item);
435 void CollapseAndReset(const wxTreeItemId& item);
436 void Toggle(const wxTreeItemId& item);
437
438 void Unselect();
439 void UnselectAll();
440 void SelectItem(const wxTreeItemId& item);
441 void EnsureVisible(const wxTreeItemId& item);
442 void ScrollTo(const wxTreeItemId& item);
443 #ifdef __WXMSW__
444 wxTextCtrl* EditLabel(const wxTreeItemId& item);
445 wxTextCtrl* GetEditControl();
446 void EndEditLabel(const wxTreeItemId& item, int discardChanges = FALSE);
447 #else
448 void EditLabel(const wxTreeItemId& item);
449 #endif
450
451 void SortChildren(const wxTreeItemId& item);
452
453 void SetItemBold(const wxTreeItemId& item, int bold = TRUE);
454 bool IsBold(const wxTreeItemId& item) const;
455 wxTreeItemId HitTest(const wxPoint& point);
456
457 #ifdef __WXMSW__
458 void SetItemDropHighlight(const wxTreeItemId& item, int highlight = TRUE);
459
460 //bool GetBoundingRect(const wxTreeItemId& item, wxRect& rect, int textOnly = FALSE)
461 %addmethods {
462 PyObject* GetBoundingRect(const wxTreeItemId& item, int textOnly = FALSE) {
463 wxRect rect;
464 if (self->GetBoundingRect(item, rect, textOnly))
465 return wxPyConstructObject((void*)&rect, "wxRect");
466 else {
467 Py_INCREF(Py_None);
468 return Py_None;
469 }
470 }
471 }
472 #endif
473
474 %pragma(python) addtoclass = "
475 # Redefine a couple methods that SWIG gets a bit confused on...
476 def GetFirstChild(self,arg0,arg1):
477 val1, val2 = controls2c.wxTreeCtrl_GetFirstChild(self.this,arg0.this,arg1)
478 val1 = wxTreeItemIdPtr(val1)
479 val1.thisown = 1
480 return (val1,val2)
481 def GetNextChild(self,arg0,arg1):
482 val1, val2 = controls2c.wxTreeCtrl_GetNextChild(self.this,arg0.this,arg1)
483 val1 = wxTreeItemIdPtr(val1)
484 val1.thisown = 1
485 return (val1,val2)
486 "
487 };
488
489
490 //----------------------------------------------------------------------
491
492 #ifdef SKIPTHIS
493 #ifdef __WXMSW__
494 class wxTabEvent : public wxCommandEvent {
495 public:
496 };
497
498
499
500 class wxTabCtrl : public wxControl {
501 public:
502 wxTabCtrl(wxWindow* parent, wxWindowID id,
503 const wxPoint& pos = wxPyDefaultPosition,
504 const wxSize& size = wxPyDefaultSize,
505 long style = 0,
506 char* name = "tabCtrl");
507
508 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
509
510 bool DeleteAllItems();
511 bool DeleteItem(int item);
512 wxImageList* GetImageList();
513 int GetItemCount();
514 // TODO: void* GetItemData();
515 int GetItemImage(int item);
516
517 %addmethods {
518 %new wxRect* GetItemRect(int item) {
519 wxRect* rect = new wxRect;
520 self->GetItemRect(item, *rect);
521 return rect;
522 }
523 }
524
525 wxString GetItemText(int item);
526 bool GetRowCount();
527 int GetSelection();
528 int HitTest(const wxPoint& pt, long& OUTPUT);
529 void InsertItem(int item, const wxString& text,
530 int imageId = -1, void* clientData = NULL);
531 // TODO: bool SetItemData(int item, void* data);
532 bool SetItemImage(int item, int image);
533 void SetImageList(wxImageList* imageList);
534 void SetItemSize(const wxSize& size);
535 bool SetItemText(int item, const wxString& text);
536 void SetPadding(const wxSize& padding);
537 int SetSelection(int item);
538
539 };
540
541 #endif
542 #endif
543
544 //----------------------------------------------------------------------
545
546