]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/controls2.i
A couple little fixes for wxSTC
[wxWidgets.git] / 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 #include <wx/imaglist.h>
23 %}
24
25 //----------------------------------------------------------------------
26
27 %include typemaps.i
28 %include my_typemaps.i
29
30 // Import some definitions of other classes, etc.
31 %import _defs.i
32 %import misc.i
33 %import windows.i
34 %import gdi.i
35 %import events.i
36 %import controls.i
37
38 %pragma(python) code = "import wx"
39
40
41 //----------------------------------------------------------------------
42 //----------------------------------------------------------------------
43
44 enum {
45 /* List control event types */
46 wxEVT_COMMAND_LIST_BEGIN_DRAG,
47 wxEVT_COMMAND_LIST_BEGIN_RDRAG,
48 wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT,
49 wxEVT_COMMAND_LIST_END_LABEL_EDIT,
50 wxEVT_COMMAND_LIST_DELETE_ITEM,
51 wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS,
52 wxEVT_COMMAND_LIST_GET_INFO,
53 wxEVT_COMMAND_LIST_SET_INFO,
54 wxEVT_COMMAND_LIST_ITEM_SELECTED,
55 wxEVT_COMMAND_LIST_ITEM_DESELECTED,
56 wxEVT_COMMAND_LIST_KEY_DOWN,
57 wxEVT_COMMAND_LIST_INSERT_ITEM,
58 wxEVT_COMMAND_LIST_COL_CLICK,
59 wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK,
60 wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK,
61 wxEVT_COMMAND_LIST_ITEM_ACTIVATED,
62 wxEVT_COMMAND_LIST_CACHE_HINT,
63 wxEVT_COMMAND_LIST_COL_RIGHT_CLICK,
64 wxEVT_COMMAND_LIST_COL_BEGIN_DRAG,
65 wxEVT_COMMAND_LIST_COL_DRAGGING,
66 wxEVT_COMMAND_LIST_COL_END_DRAG,
67
68 };
69
70
71 %pragma(python) code = "
72 def EVT_LIST_BEGIN_DRAG(win, id, func):
73 win.Connect(id, -1, wxEVT_COMMAND_LIST_BEGIN_DRAG, func)
74
75 def EVT_LIST_BEGIN_RDRAG(win, id, func):
76 win.Connect(id, -1, wxEVT_COMMAND_LIST_BEGIN_RDRAG, func)
77
78 def EVT_LIST_BEGIN_LABEL_EDIT(win, id, func):
79 win.Connect(id, -1, wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, func)
80
81 def EVT_LIST_END_LABEL_EDIT(win, id, func):
82 win.Connect(id, -1, wxEVT_COMMAND_LIST_END_LABEL_EDIT, func)
83
84 def EVT_LIST_DELETE_ITEM(win, id, func):
85 win.Connect(id, -1, wxEVT_COMMAND_LIST_DELETE_ITEM, func)
86
87 def EVT_LIST_DELETE_ALL_ITEMS(win, id, func):
88 win.Connect(id, -1, wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, func)
89
90 def EVT_LIST_GET_INFO(win, id, func):
91 win.Connect(id, -1, wxEVT_COMMAND_LIST_GET_INFO, func)
92
93 def EVT_LIST_SET_INFO(win, id, func):
94 win.Connect(id, -1, wxEVT_COMMAND_LIST_SET_INFO, func)
95
96 def EVT_LIST_ITEM_SELECTED(win, id, func):
97 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_SELECTED, func)
98
99 def EVT_LIST_ITEM_DESELECTED(win, id, func):
100 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_DESELECTED, func)
101
102 def EVT_LIST_KEY_DOWN(win, id, func):
103 win.Connect(id, -1, wxEVT_COMMAND_LIST_KEY_DOWN, func)
104
105 def EVT_LIST_INSERT_ITEM(win, id, func):
106 win.Connect(id, -1, wxEVT_COMMAND_LIST_INSERT_ITEM, func)
107
108 def EVT_LIST_COL_CLICK(win, id, func):
109 win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_CLICK, func)
110
111 def EVT_LIST_COL_RIGHT_CLICK(win, id, func):
112 win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_RIGHT_CLICK, func)
113
114 def EVT_LIST_COL_BEGIN_DRAG(win, id, func):
115 win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_BEGIN_DRAG, func)
116
117 def EVT_LIST_COL_DRAGGING(win, id, func):
118 win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_DRAGGING, func)
119
120 def EVT_LIST_COL_END_DRAG(win, id, func):
121 win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_END_DRAG, func)
122
123 def EVT_LIST_ITEM_RIGHT_CLICK(win, id, func):
124 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, func)
125
126 def EVT_LIST_ITEM_MIDDLE_CLICK(win, id, func):
127 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK, func)
128
129 def EVT_LIST_ITEM_ACTIVATED(win, id, func):
130 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_ACTIVATED, func)
131
132 def EVT_LIST_CACHE_HINT(win, id, func):
133 win.Connect(id, -1, wxEVT_COMMAND_LIST_CACHE_HINT, func)
134 "
135
136
137 enum {
138 /* Style flags */
139 wxLC_VRULES,
140 wxLC_HRULES,
141
142 wxLC_ICON,
143 wxLC_SMALL_ICON,
144 wxLC_LIST,
145 wxLC_REPORT,
146
147 wxLC_ALIGN_TOP,
148 wxLC_ALIGN_LEFT,
149 wxLC_AUTOARRANGE,
150 wxLC_VIRTUAL,
151 wxLC_EDIT_LABELS,
152 wxLC_NO_HEADER,
153 wxLC_NO_SORT_HEADER,
154 wxLC_SINGLE_SEL,
155 wxLC_SORT_ASCENDING,
156 wxLC_SORT_DESCENDING,
157
158 wxLC_MASK_TYPE,
159 wxLC_MASK_ALIGN,
160 wxLC_MASK_SORT,
161
162 wxLC_USER_TEXT,
163 };
164
165
166 enum {
167 // Mask flags
168 wxLIST_MASK_STATE,
169 wxLIST_MASK_TEXT,
170 wxLIST_MASK_IMAGE,
171 wxLIST_MASK_DATA,
172 wxLIST_SET_ITEM,
173 wxLIST_MASK_WIDTH,
174 wxLIST_MASK_FORMAT,
175
176 // State flags
177 wxLIST_STATE_DONTCARE,
178 wxLIST_STATE_DROPHILITED,
179 wxLIST_STATE_FOCUSED,
180 wxLIST_STATE_SELECTED,
181 wxLIST_STATE_CUT,
182
183 // Hit test flags
184 wxLIST_HITTEST_ABOVE,
185 wxLIST_HITTEST_BELOW,
186 wxLIST_HITTEST_NOWHERE,
187 wxLIST_HITTEST_ONITEMICON,
188 wxLIST_HITTEST_ONITEMLABEL,
189 wxLIST_HITTEST_ONITEMRIGHT,
190 wxLIST_HITTEST_ONITEMSTATEICON,
191 wxLIST_HITTEST_TOLEFT,
192 wxLIST_HITTEST_TORIGHT,
193 wxLIST_HITTEST_ONITEM,
194
195 // Flags for GetNextItem
196 wxLIST_NEXT_ABOVE,
197 wxLIST_NEXT_ALL,
198 wxLIST_NEXT_BELOW,
199 wxLIST_NEXT_LEFT,
200 wxLIST_NEXT_RIGHT,
201
202 // Alignment flags
203 wxLIST_ALIGN_DEFAULT,
204 wxLIST_ALIGN_LEFT,
205 wxLIST_ALIGN_TOP,
206 wxLIST_ALIGN_SNAP_TO_GRID,
207
208 // Autosize values for SetColumnWidth
209 wxLIST_AUTOSIZE = -1,
210 wxLIST_AUTOSIZE_USEHEADER = -2,
211
212 // Flag values for GetItemRect
213 wxLIST_RECT_BOUNDS,
214 wxLIST_RECT_ICON,
215 wxLIST_RECT_LABEL,
216
217 // Flag values for FindItem (MSW only)
218 wxLIST_FIND_UP,
219 wxLIST_FIND_DOWN,
220 wxLIST_FIND_LEFT,
221 wxLIST_FIND_RIGHT,
222
223
224 };
225
226
227
228 enum wxListColumnFormat
229 {
230 wxLIST_FORMAT_LEFT,
231 wxLIST_FORMAT_RIGHT,
232 wxLIST_FORMAT_CENTRE,
233 wxLIST_FORMAT_CENTER = wxLIST_FORMAT_CENTRE
234 };
235
236
237
238
239 class wxListItemAttr
240 {
241 public:
242 // ctors
243 //wxListItemAttr();
244 wxListItemAttr(const wxColour& colText = wxNullColour,
245 const wxColour& colBack = wxNullColour,
246 const wxFont& font = wxNullFont);
247
248
249 // setters
250 void SetTextColour(const wxColour& colText);
251 void SetBackgroundColour(const wxColour& colBack);
252 void SetFont(const wxFont& font);
253
254 // accessors
255 bool HasTextColour();
256 bool HasBackgroundColour();
257 bool HasFont();
258
259 const wxColour& GetTextColour();
260 const wxColour& GetBackgroundColour();
261 const wxFont& GetFont();
262 };
263
264
265 class wxListItem : public wxObject {
266 public:
267 wxListItem();
268 ~wxListItem();
269
270 // resetting
271 void Clear();
272 void ClearAttributes();
273
274 // setters
275 void SetMask(long mask);
276 void SetId(long id);
277 void SetColumn(int col);
278 void SetState(long state);
279 void SetStateMask(long stateMask);
280 void SetText(const wxString& text);
281 void SetImage(int image);
282 void SetData(long data);
283
284 void SetWidth(int width);
285 void SetAlign(wxListColumnFormat align);
286
287 void SetTextColour(const wxColour& colText);
288 void SetBackgroundColour(const wxColour& colBack);
289 void SetFont(const wxFont& font);
290
291 // accessors
292 long GetMask();
293 long GetId();
294 int GetColumn();
295 long GetState();
296 const wxString& GetText();
297 int GetImage();
298 long GetData();
299
300 int GetWidth();
301 wxListColumnFormat GetAlign();
302
303 wxListItemAttr *GetAttributes();
304 bool HasAttributes();
305
306 wxColour GetTextColour() const;
307 wxColour GetBackgroundColour() const;
308 wxFont GetFont() const;
309
310 // these members are public for compatibility
311 long m_mask; // Indicates what fields are valid
312 long m_itemId; // The zero-based item position
313 int m_col; // Zero-based column, if in report mode
314 long m_state; // The state of the item
315 long m_stateMask;// Which flags of m_state are valid (uses same flags)
316 wxString m_text; // The label/header text
317 int m_image; // The zero-based index into an image list
318 long m_data; // App-defined data
319
320 // For columns only
321 int m_format; // left, right, centre
322 int m_width; // width of column
323
324 };
325
326
327 class wxListEvent: public wxNotifyEvent {
328 public:
329 wxListEvent(wxEventType commandType = wxEVT_NULL, int id = 0);
330
331 int m_code;
332 long m_itemIndex;
333 long m_oldItemIndex;
334 int m_col;
335 bool m_cancelled;
336 wxPoint m_pointDrag;
337 wxListItem m_item;
338
339 int GetCode();
340 long GetIndex();
341 long GetOldIndex();
342 long GetOldItem();
343 int GetColumn();
344 bool Cancelled();
345 wxPoint GetPoint();
346 const wxString& GetLabel();
347 const wxString& GetText();
348 int GetImage();
349 long GetData();
350 long GetMask();
351 const wxListItem& GetItem();
352
353 long GetCacheFrom();
354 long GetCacheTo();
355 };
356
357
358 %{ // C++ Version of a Python aware class
359 class wxPyListCtrl : public wxListCtrl {
360 DECLARE_ABSTRACT_CLASS(wxPyListCtrl);
361 public:
362 wxPyListCtrl() : wxListCtrl() {}
363 wxPyListCtrl(wxWindow* parent, wxWindowID id,
364 const wxPoint& pos,
365 const wxSize& size,
366 long style,
367 const wxValidator& validator,
368 char* name) :
369 wxListCtrl(parent, id, pos, size, style, validator, name) {}
370
371 bool Create(wxWindow* parent, wxWindowID id,
372 const wxPoint& pos,
373 const wxSize& size,
374 long style,
375 const wxValidator& validator,
376 char* name) {
377 return wxListCtrl::Create(parent, id, pos, size, style, validator, name);
378 }
379
380 DEC_PYCALLBACK_STRING_LONGLONG(OnGetItemText);
381 DEC_PYCALLBACK_INT_LONG(OnGetItemImage);
382 DEC_PYCALLBACK_LISTATTR_LONG(OnGetItemAttr);
383
384 PYPRIVATE;
385 };
386
387 IMPLEMENT_ABSTRACT_CLASS(wxPyListCtrl, wxListCtrl);
388
389 IMP_PYCALLBACK_STRING_LONGLONG(wxPyListCtrl, wxListCtrl, OnGetItemText);
390 IMP_PYCALLBACK_INT_LONG(wxPyListCtrl, wxListCtrl, OnGetItemImage);
391 IMP_PYCALLBACK_LISTATTR_LONG(wxPyListCtrl, wxListCtrl, OnGetItemAttr);
392 %}
393
394
395 %name(wxListCtrl)class wxPyListCtrl : public wxControl {
396 public:
397 wxPyListCtrl(wxWindow* parent, wxWindowID id = -1,
398 const wxPoint& pos = wxDefaultPosition,
399 const wxSize& size = wxDefaultSize,
400 long style = wxLC_ICON,
401 const wxValidator& validator = wxDefaultValidator,
402 char* name = "listCtrl");
403 %name(wxPreListCtrl)wxPyListCtrl();
404
405 bool Create(wxWindow* parent, wxWindowID id = -1,
406 const wxPoint& pos = wxDefaultPosition,
407 const wxSize& size = wxDefaultSize,
408 long style = wxLC_ICON,
409 const wxValidator& validator = wxDefaultValidator,
410 char* name = "listCtrl");
411
412 void _setSelf(PyObject* self, PyObject* _class);
413 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxListCtrl)"
414
415
416 // Set the control colours
417 bool SetForegroundColour(const wxColour& col);
418 bool SetBackgroundColour(const wxColour& col);
419
420 // Gets information about this column
421 bool GetColumn(int col, wxListItem& item) const;
422
423 // Sets information about this column
424 bool SetColumn(int col, wxListItem& item) ;
425
426 // Gets the column width
427 int GetColumnWidth(int col) const;
428
429 // Sets the column width
430 bool SetColumnWidth(int col, int width) ;
431
432 // Gets the number of items that can fit vertically in the
433 // visible area of the list control (list or report view)
434 // or the total number of items in the list control (icon
435 // or small icon view)
436 int GetCountPerPage() const;
437
438 #ifdef __WXMSW__
439 // Gets the edit control for editing labels.
440 wxTextCtrl* GetEditControl() const;
441 #endif
442
443 //bool GetItem(wxListItem& info) const ;
444 %addmethods {
445 // Gets information about the item
446 %new wxListItem* GetItem(long itemId, int col=0) {
447 wxListItem* info = new wxListItem;
448 info->m_itemId = itemId;
449 info->m_col = col;
450 info->m_mask = 0xFFFF;
451 self->GetItem(*info);
452 return info;
453 }
454 } // The OOR typemaps don't know what to do with the %new, so fix it up.
455 %pragma(python) addtoclass = "
456 def GetItem(self, *_args, **_kwargs):
457 val = apply(controls2c.wxListCtrl_GetItem,(self,) + _args, _kwargs)
458 val.thisown = 1
459 return val
460 "
461
462
463 // Sets information about the item
464 bool SetItem(wxListItem& info) ;
465
466 // Sets a string field at a particular column
467 %name(SetStringItem)long SetItem(long index, int col, const wxString& label, int imageId = -1);
468
469 // Gets the item state
470 int GetItemState(long item, long stateMask) const ;
471
472 // Sets the item state
473 bool SetItemState(long item, long state, long stateMask) ;
474
475 // Sets the item image
476 bool SetItemImage(long item, int image, int selImage) ;
477
478 // Gets the item text
479 wxString GetItemText(long item) const ;
480
481 // Sets the item text
482 void SetItemText(long item, const wxString& str) ;
483
484 // Gets the item data
485 long GetItemData(long item) const ;
486
487 // Sets the item data
488 bool SetItemData(long item, long data) ;
489
490
491 //bool GetItemRect(long item, wxRect& rect, int code = wxLIST_RECT_BOUNDS) const ;
492 //bool GetItemPosition(long item, wxPoint& pos) const ;
493
494 // Gets the item position
495 %addmethods {
496 %new wxPoint* GetItemPosition(long item) {
497 wxPoint* pos = new wxPoint;
498 self->GetItemPosition(item, *pos);
499 return pos;
500 }
501 // Gets the item rectangle
502 %new wxRect* GetItemRect(long item, int code = wxLIST_RECT_BOUNDS) {
503 wxRect* rect= new wxRect;
504 self->GetItemRect(item, *rect, code);
505 return rect;
506 }
507 }
508
509
510 // Sets the item position
511 bool SetItemPosition(long item, const wxPoint& pos) ;
512
513 // Gets the number of items in the list control
514 int GetItemCount() const;
515
516 // Gets the number of columns in the list control
517 int GetColumnCount() const { return m_colCount; }
518
519 // Retrieves the spacing between icons in pixels.
520 // If small is TRUE, gets the spacing for the small icon
521 // view, otherwise the large icon view.
522 int GetItemSpacing(bool isSmall) const;
523
524 // Gets the number of selected items in the list control
525 int GetSelectedItemCount() const;
526
527 // Gets the text colour of the listview
528 wxColour GetTextColour() const;
529
530 // Sets the text colour of the listview
531 void SetTextColour(const wxColour& col);
532
533 // Gets the index of the topmost visible item when in
534 // list or report view
535 long GetTopItem() const ;
536
537 // Add or remove a single window style
538 void SetSingleStyle(long style, bool add = TRUE) ;
539
540 // Set the whole window style
541 void SetWindowStyleFlag(long style) ;
542
543 // Searches for an item, starting from 'item'.
544 // item can be -1 to find the first item that matches the
545 // specified flags.
546 // Returns the item or -1 if unsuccessful.
547 long GetNextItem(long item, int geometry = wxLIST_NEXT_ALL, int state = wxLIST_STATE_DONTCARE) const ;
548
549 // Gets one of the three image lists
550 wxImageList *GetImageList(int which) const ;
551
552 // Sets the image list
553 void SetImageList(wxImageList *imageList, int which) ;
554 void AssignImageList(wxImageList *imageList, int which) ;
555 %pragma(python) addtomethod = "AssignImageList:_args[0].thisown = 0"
556
557 // returns true if it is a virtual list control
558 bool IsVirtual() const;
559
560 // refresh items selectively (only useful for virtual list controls)
561 void RefreshItem(long item);
562 void RefreshItems(long itemFrom, long itemTo);
563
564
565
566
567 // Arranges the items
568 bool Arrange(int flag = wxLIST_ALIGN_DEFAULT);
569
570 // Deletes an item
571 bool DeleteItem(long item);
572
573 // Deletes all items
574 bool DeleteAllItems() ;
575
576 // Deletes a column
577 bool DeleteColumn(int col);
578
579 // Deletes all columns
580 bool DeleteAllColumns();
581
582 // Clears items, and columns if there are any.
583 void ClearAll();
584
585 #ifdef __WXMSW__
586 // Edit the label
587 wxTextCtrl* EditLabel(long item /*, wxClassInfo* textControlClass = CLASSINFO(wxTextCtrl)*/);
588
589 // End label editing, optionally cancelling the edit
590 bool EndEditLabel(bool cancel);
591 #endif
592
593 // Ensures this item is visible
594 bool EnsureVisible(long item) ;
595
596 // Find an item whose label matches this string, starting from the item after 'start'
597 // or the beginning if 'start' is -1.
598 long FindItem(long start, const wxString& str, bool partial = FALSE);
599
600 // Find an item whose data matches this data, starting from the item after 'start'
601 // or the beginning if 'start' is -1.
602 %name(FindItemData)long FindItem(long start, long data);
603
604 // Find an item nearest this position in the specified direction, starting from
605 // the item after 'start' or the beginning if 'start' is -1.
606 %name(FindItemAtPos)long FindItem(long start, const wxPoint& pt, int direction);
607
608 // Determines which item (if any) is at the specified point,
609 // giving details in the second return value (see wxLIST_HITTEST_... flags above)
610 long HitTest(const wxPoint& point, int& OUTPUT);
611
612 // Inserts an item, returning the index of the new item if successful,
613 // -1 otherwise.
614 long InsertItem(wxListItem& info);
615
616 // Insert a string item
617 %name(InsertStringItem)long InsertItem(long index, const wxString& label);
618
619 // Insert an image item
620 %name(InsertImageItem)long InsertItem(long index, int imageIndex);
621
622 // Insert an image/string item
623 %name(InsertImageStringItem)long InsertItem(long index, const wxString& label, int imageIndex);
624
625 // For list view mode (only), inserts a column.
626 %name(InsertColumnInfo)long InsertColumn(long col, wxListItem& info);
627
628 long InsertColumn(long col,
629 const wxString& heading,
630 int format = wxLIST_FORMAT_LEFT,
631 int width = -1);
632
633 // set the number of items in a virtual list control
634 void SetItemCount(long count);
635
636 // Scrolls the list control. If in icon, small icon or report view mode,
637 // x specifies the number of pixels to scroll. If in list view mode, x
638 // specifies the number of columns to scroll.
639 // If in icon, small icon or list view mode, y specifies the number of pixels
640 // to scroll. If in report view mode, y specifies the number of lines to scroll.
641 bool ScrollList(int dx, int dy);
642
643 // bool SortItems(wxListCtrlCompare fn, long data);
644 %addmethods {
645 // Sort items.
646 // func is a function which takes 2 long arguments: item1, item2.
647 // item1 is the long data associated with a first item (NOT the index).
648 // item2 is the long data associated with a second item (NOT the index).
649 // The return value is a negative number if the first item should precede the second
650 // item, a positive number of the second item should precede the first,
651 // or zero if the two items are equivalent.
652 bool SortItems(PyObject* func) {
653 if (!PyCallable_Check(func))
654 return FALSE;
655 return self->SortItems(wxPyListCtrl_SortItems, (long)func);
656 }
657 }
658
659 %pragma(python) addtoclass = "
660 # Some helpers...
661
662 def Select(self, idx, on=1):
663 '''[de]select an item'''
664 if on: state = wxLIST_STATE_SELECTED
665 else: state = 0
666 self.SetItemState(idx, state, wxLIST_STATE_SELECTED)
667
668 def Focus(self, idx):
669 '''Focus and show the given item'''
670 self.SetItemState(idx, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED)
671 self.EnsureVisible(idx)
672
673 def GetFocusedItem(self):
674 '''get the currently focused item or -1 if none'''
675 return self.GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED)
676
677 def IsSelected(self, idx):
678 '''return TRUE if the item is selected'''
679 return self.GetItemState(idx, wxLIST_STATE_SELECTED) != 0
680
681 def SetColumnImage(self, col, image):
682 item = wxListItem()
683 item.SetMask(wxLIST_MASK_IMAGE)
684 item.SetImage(image)
685 self.SetColumn(col, item)
686
687 def ClearColumnImage(self, col):
688 self.SetColumnImage(col, -1)
689 "
690 };
691
692
693
694 %{ // Python aware sorting function for wxPyListCtrl
695 int wxCALLBACK wxPyListCtrl_SortItems(long item1, long item2, long funcPtr) {
696 int retval = 0;
697 PyObject* func = (PyObject*)funcPtr;
698 bool doSave = wxPyRestoreThread();
699
700 PyObject* args = Py_BuildValue("(ii)", item1, item2);
701 PyObject* result = PyEval_CallObject(func, args);
702 Py_DECREF(args);
703 if (result) {
704 retval = PyInt_AsLong(result);
705 Py_DECREF(result);
706 }
707
708 wxPySaveThread(doSave);
709 return retval;
710 }
711
712 %}
713
714 //----------------------------------------------------------------------
715
716 class wxListView : public wxPyListCtrl
717 {
718 public:
719 wxListView( wxWindow *parent,
720 wxWindowID id = -1,
721 const wxPoint& pos = wxDefaultPosition,
722 const wxSize& size = wxDefaultSize,
723 long style = wxLC_REPORT,
724 const wxValidator& validator = wxDefaultValidator,
725 const wxString &name = "listctrl" );
726 %name(wxPreListView)wxListView();
727
728 bool Create( wxWindow *parent,
729 wxWindowID id = -1,
730 const wxPoint& pos = wxDefaultPosition,
731 const wxSize& size = wxDefaultSize,
732 long style = wxLC_REPORT,
733 const wxValidator& validator = wxDefaultValidator,
734 const wxString &name = "listctrl" );
735
736
737 // [de]select an item
738 void Select(long n, bool on = TRUE);
739
740 // focus and show the given item
741 void Focus(long index);
742
743 // get the currently focused item or -1 if none
744 long GetFocusedItem() const;
745
746 // get first and subsequent selected items, return -1 when no more
747 long GetNextSelected(long item) const;
748 long GetFirstSelected() const;
749
750 // return TRUE if the item is selected
751 bool IsSelected(long index);
752
753 void SetColumnImage(int col, int image);
754 void ClearColumnImage(int col);
755 };
756
757
758 //----------------------------------------------------------------------
759
760 // wxTreeCtrl flags
761 enum {
762 wxTR_NO_BUTTONS,
763 wxTR_HAS_BUTTONS,
764 wxTR_TWIST_BUTTONS,
765 wxTR_NO_LINES,
766 wxTR_MAC_BUTTONS,
767
768 wxTR_SINGLE,
769 wxTR_MULTIPLE,
770 wxTR_EXTENDED,
771
772 wxTR_EDIT_LABELS,
773 wxTR_LINES_AT_ROOT,
774 wxTR_HIDE_ROOT,
775 wxTR_ROW_LINES,
776 wxTR_HAS_VARIABLE_ROW_HEIGHT,
777
778 wxTR_DEFAULT_STYLE,
779 };
780
781 enum wxTreeItemIcon
782 {
783 wxTreeItemIcon_Normal, // not selected, not expanded
784 wxTreeItemIcon_Selected, // selected, not expanded
785 wxTreeItemIcon_Expanded, // not selected, expanded
786 wxTreeItemIcon_SelectedExpanded, // selected, expanded
787 wxTreeItemIcon_Max
788 };
789
790
791 // constants for HitTest
792 enum {
793 wxTREE_HITTEST_ABOVE,
794 wxTREE_HITTEST_BELOW,
795 wxTREE_HITTEST_NOWHERE,
796 wxTREE_HITTEST_ONITEMBUTTON,
797 wxTREE_HITTEST_ONITEMICON,
798 wxTREE_HITTEST_ONITEMINDENT,
799 wxTREE_HITTEST_ONITEMLABEL,
800 wxTREE_HITTEST_ONITEMRIGHT,
801 wxTREE_HITTEST_ONITEMSTATEICON,
802 wxTREE_HITTEST_TOLEFT,
803 wxTREE_HITTEST_TORIGHT,
804 wxTREE_HITTEST_ONITEMUPPERPART,
805 wxTREE_HITTEST_ONITEMLOWERPART,
806 wxTREE_HITTEST_ONITEM
807 };
808
809
810 enum {
811 /* Tree control event types */
812 wxEVT_COMMAND_TREE_BEGIN_DRAG,
813 wxEVT_COMMAND_TREE_BEGIN_RDRAG,
814 wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT,
815 wxEVT_COMMAND_TREE_END_LABEL_EDIT,
816 wxEVT_COMMAND_TREE_DELETE_ITEM,
817 wxEVT_COMMAND_TREE_GET_INFO,
818 wxEVT_COMMAND_TREE_SET_INFO,
819 wxEVT_COMMAND_TREE_ITEM_EXPANDED,
820 wxEVT_COMMAND_TREE_ITEM_EXPANDING,
821 wxEVT_COMMAND_TREE_ITEM_COLLAPSED,
822 wxEVT_COMMAND_TREE_ITEM_COLLAPSING,
823 wxEVT_COMMAND_TREE_SEL_CHANGED,
824 wxEVT_COMMAND_TREE_SEL_CHANGING,
825 wxEVT_COMMAND_TREE_KEY_DOWN,
826 wxEVT_COMMAND_TREE_ITEM_ACTIVATED,
827 wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK,
828 wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK,
829 wxEVT_COMMAND_TREE_END_DRAG,
830 };
831
832
833 %pragma(python) code = "
834 # wxTreeCtrl events
835 def EVT_TREE_BEGIN_DRAG(win, id, func):
836 win.Connect(id, -1, wxEVT_COMMAND_TREE_BEGIN_DRAG, func)
837
838 def EVT_TREE_BEGIN_RDRAG(win, id, func):
839 win.Connect(id, -1, wxEVT_COMMAND_TREE_BEGIN_RDRAG, func)
840
841 def EVT_TREE_END_DRAG(win, id, func):
842 win.Connect(id, -1, wxEVT_COMMAND_TREE_END_DRAG, func)
843
844 def EVT_TREE_BEGIN_LABEL_EDIT(win, id, func):
845 win.Connect(id, -1, wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, func)
846
847 def EVT_TREE_END_LABEL_EDIT(win, id, func):
848 win.Connect(id, -1, wxEVT_COMMAND_TREE_END_LABEL_EDIT, func)
849
850 def EVT_TREE_GET_INFO(win, id, func):
851 win.Connect(id, -1, wxEVT_COMMAND_TREE_GET_INFO, func)
852
853 def EVT_TREE_SET_INFO(win, id, func):
854 win.Connect(id, -1, wxEVT_COMMAND_TREE_SET_INFO, func)
855
856 def EVT_TREE_ITEM_EXPANDED(win, id, func):
857 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_EXPANDED, func)
858
859 def EVT_TREE_ITEM_EXPANDING(win, id, func):
860 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_EXPANDING, func)
861
862 def EVT_TREE_ITEM_COLLAPSED(win, id, func):
863 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_COLLAPSED, func)
864
865 def EVT_TREE_ITEM_COLLAPSING(win, id, func):
866 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_COLLAPSING, func)
867
868 def EVT_TREE_SEL_CHANGED(win, id, func):
869 win.Connect(id, -1, wxEVT_COMMAND_TREE_SEL_CHANGED, func)
870
871 def EVT_TREE_SEL_CHANGING(win, id, func):
872 win.Connect(id, -1, wxEVT_COMMAND_TREE_SEL_CHANGING, func)
873
874 def EVT_TREE_KEY_DOWN(win, id, func):
875 win.Connect(id, -1, wxEVT_COMMAND_TREE_KEY_DOWN, func)
876
877 def EVT_TREE_DELETE_ITEM(win, id, func):
878 win.Connect(id, -1, wxEVT_COMMAND_TREE_DELETE_ITEM, func)
879
880 def EVT_TREE_ITEM_ACTIVATED(win, id, func):
881 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_ACTIVATED, func)
882
883 def EVT_TREE_ITEM_RIGHT_CLICK(win, id, func):
884 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, func)
885
886 def EVT_TREE_ITEM_MIDDLE_CLICK(win, id, func):
887 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK, func)
888 "
889
890
891 class wxTreeItemAttr
892 {
893 public:
894 // ctors
895 //wxTreeItemAttr() { }
896 wxTreeItemAttr(const wxColour& colText = wxNullColour,
897 const wxColour& colBack = wxNullColour,
898 const wxFont& font = wxNullFont);
899
900 // setters
901 void SetTextColour(const wxColour& colText);
902 void SetBackgroundColour(const wxColour& colBack);
903 void SetFont(const wxFont& font);
904
905 // accessors
906 bool HasTextColour();
907 bool HasBackgroundColour();
908 bool HasFont();
909
910 const wxColour& GetTextColour();
911 const wxColour& GetBackgroundColour();
912 const wxFont& GetFont();
913 };
914
915
916 class wxTreeItemId {
917 public:
918 wxTreeItemId();
919 ~wxTreeItemId();
920 bool IsOk();
921
922 %addmethods {
923 int __cmp__(wxTreeItemId* other) {
924 if (! other) return -1;
925 return *self != *other;
926 }
927 }
928 };
929
930
931
932 %{
933 class wxPyTreeItemData : public wxTreeItemData {
934 public:
935 wxPyTreeItemData(PyObject* obj = NULL) {
936 if (obj == NULL)
937 obj = Py_None;
938 Py_INCREF(obj);
939 m_obj = obj;
940 }
941
942 ~wxPyTreeItemData() {
943 bool doSave = wxPyRestoreThread();
944 Py_DECREF(m_obj);
945 wxPySaveThread(doSave);
946 }
947
948 PyObject* GetData() {
949 Py_INCREF(m_obj);
950 return m_obj;
951 }
952
953 void SetData(PyObject* obj) {
954 bool doSave = wxPyRestoreThread();
955 Py_DECREF(m_obj);
956 wxPySaveThread(doSave);
957 m_obj = obj;
958 Py_INCREF(obj);
959 }
960
961 PyObject* m_obj;
962 };
963 %}
964
965
966
967 %name(wxTreeItemData) class wxPyTreeItemData : public wxObject {
968 public:
969 wxPyTreeItemData(PyObject* obj = NULL);
970
971 PyObject* GetData();
972 void SetData(PyObject* obj);
973
974 const wxTreeItemId& GetId();
975 void SetId(const wxTreeItemId& id);
976 };
977
978
979
980 class wxTreeEvent : public wxNotifyEvent {
981 public:
982 wxTreeEvent(wxEventType commandType = wxEVT_NULL, int id = 0);
983
984 wxTreeItemId GetItem();
985 wxTreeItemId GetOldItem();
986 wxPoint GetPoint();
987 int GetCode();
988 const wxString& GetLabel();
989 };
990
991
992
993 %{ // C++ version of Python aware wxTreeCtrl
994 class wxPyTreeCtrl : public wxTreeCtrl {
995 DECLARE_ABSTRACT_CLASS(wxPyTreeCtrl);
996 public:
997 wxPyTreeCtrl() : wxTreeCtrl() {}
998 wxPyTreeCtrl(wxWindow *parent, wxWindowID id,
999 const wxPoint& pos,
1000 const wxSize& size,
1001 long style,
1002 const wxValidator& validator,
1003 char* name) :
1004 wxTreeCtrl(parent, id, pos, size, style, validator, name) {}
1005
1006 bool Create(wxWindow *parent, wxWindowID id,
1007 const wxPoint& pos,
1008 const wxSize& size,
1009 long style,
1010 const wxValidator& validator,
1011 char* name) {
1012 return wxTreeCtrl::Create(parent, id, pos, size, style, validator, name);
1013 }
1014
1015
1016 int OnCompareItems(const wxTreeItemId& item1,
1017 const wxTreeItemId& item2) {
1018 int rval = 0;
1019 bool doSave = wxPyRestoreThread();
1020 if (m_myInst.findCallback("OnCompareItems"))
1021 rval = m_myInst.callCallback(Py_BuildValue(
1022 "(OO)",
1023 wxPyConstructObject((void*)&item1, "wxTreeItemId"),
1024 wxPyConstructObject((void*)&item2, "wxTreeItemId")));
1025 else
1026 rval = wxTreeCtrl::OnCompareItems(item1, item2);
1027 wxPySaveThread(doSave);
1028 return rval;
1029 }
1030 PYPRIVATE;
1031 };
1032
1033 IMPLEMENT_ABSTRACT_CLASS(wxPyTreeCtrl, wxTreeCtrl);
1034
1035 %}
1036
1037 // These are for the GetFirstChild/GetNextChild methods below
1038 %typemap(python, in) long& INOUT = long* INOUT;
1039 %typemap(python, argout) long& INOUT = long* INOUT;
1040
1041
1042 %name(wxTreeCtrl)class wxPyTreeCtrl : public wxControl {
1043 public:
1044 wxPyTreeCtrl(wxWindow *parent, wxWindowID id = -1,
1045 const wxPoint& pos = wxDefaultPosition,
1046 const wxSize& size = wxDefaultSize,
1047 long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT,
1048 const wxValidator& validator = wxDefaultValidator,
1049 char* name = "wxTreeCtrl");
1050 %name(wxPreTreeCtrl)wxPyTreeCtrl();
1051
1052 bool Create(wxWindow *parent, wxWindowID id = -1,
1053 const wxPoint& pos = wxDefaultPosition,
1054 const wxSize& size = wxDefaultSize,
1055 long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT,
1056 const wxValidator& validator = wxDefaultValidator,
1057 char* name = "wxTreeCtrl");
1058
1059 void _setSelf(PyObject* self, PyObject* _class);
1060 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxTreeCtrl)"
1061
1062 size_t GetCount();
1063 unsigned int GetIndent();
1064 void SetIndent(unsigned int indent);
1065 wxImageList *GetImageList();
1066 wxImageList *GetStateImageList();
1067 void SetImageList(wxImageList *imageList);
1068 void SetStateImageList(wxImageList *imageList);
1069 void AssignImageList(wxImageList* imageList);
1070 %pragma(python) addtomethod = "AssignImageList:_args[0].thisown = 0"
1071 void AssignStateImageList(wxImageList* imageList);
1072 %pragma(python) addtomethod = "AssignStateImageList:_args[0].thisown = 0"
1073
1074 unsigned int GetSpacing();
1075 void SetSpacing(unsigned int spacing);
1076
1077 wxString GetItemText(const wxTreeItemId& item);
1078 int GetItemImage(const wxTreeItemId& item,
1079 wxTreeItemIcon which = wxTreeItemIcon_Normal);
1080 int GetItemSelectedImage(const wxTreeItemId& item);
1081
1082 void SetItemText(const wxTreeItemId& item, const wxString& text);
1083 void SetItemImage(const wxTreeItemId& item, int image,
1084 wxTreeItemIcon which = wxTreeItemIcon_Normal);
1085 void SetItemSelectedImage(const wxTreeItemId& item, int image);
1086 void SetItemHasChildren(const wxTreeItemId& item, bool hasChildren = TRUE);
1087
1088 %addmethods {
1089 // [Get|Set]ItemData substitutes. Automatically create wxPyTreeItemData
1090 // if needed.
1091 wxPyTreeItemData* GetItemData(const wxTreeItemId& item) {
1092 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
1093 if (data == NULL) {
1094 data = new wxPyTreeItemData();
1095 data->SetId(item); // set the id
1096 self->SetItemData(item, data);
1097 }
1098 return data;
1099 }
1100
1101 void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) {
1102 data->SetId(item); // set the id
1103 self->SetItemData(item, data);
1104 }
1105
1106 // [Get|Set]PyData are short-cuts. Also made somewhat crash-proof by
1107 // automatically creating data classes.
1108 PyObject* GetPyData(const wxTreeItemId& item) {
1109 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
1110 if (data == NULL) {
1111 data = new wxPyTreeItemData();
1112 data->SetId(item); // set the id
1113 self->SetItemData(item, data);
1114 }
1115 return data->GetData();
1116 }
1117
1118 void SetPyData(const wxTreeItemId& item, PyObject* obj) {
1119 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
1120 if (data == NULL) {
1121 data = new wxPyTreeItemData(obj);
1122 data->SetId(item); // set the id
1123 self->SetItemData(item, data);
1124 } else
1125 data->SetData(obj);
1126 }
1127 }
1128
1129
1130 bool IsVisible(const wxTreeItemId& item);
1131 bool ItemHasChildren(const wxTreeItemId& item);
1132 bool IsExpanded(const wxTreeItemId& item);
1133 bool IsSelected(const wxTreeItemId& item);
1134
1135 wxTreeItemId GetRootItem();
1136 wxTreeItemId GetSelection();
1137 %name(GetItemParent) wxTreeItemId GetParent(const wxTreeItemId& item);
1138 //size_t GetSelections(wxArrayTreeItemIds& selection);
1139 %addmethods {
1140 PyObject* GetSelections() {
1141 bool doSave = wxPyRestoreThread();
1142 PyObject* rval = PyList_New(0);
1143 wxArrayTreeItemIds array;
1144 size_t num, x;
1145 num = self->GetSelections(array);
1146 for (x=0; x < num; x++) {
1147 wxTreeItemId *tii = new wxTreeItemId(array.Item(x));
1148 PyObject* item = wxPyConstructObject((void*)tii, "wxTreeItemId", TRUE);
1149 PyList_Append(rval, item);
1150 }
1151 wxPySaveThread(doSave);
1152 return rval;
1153 }
1154 }
1155
1156
1157
1158 size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = TRUE);
1159
1160 wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& INOUT);
1161 wxTreeItemId GetNextChild(const wxTreeItemId& item, long& INOUT);
1162 wxTreeItemId GetNextSibling(const wxTreeItemId& item);
1163 wxTreeItemId GetPrevSibling(const wxTreeItemId& item);
1164 wxTreeItemId GetFirstVisibleItem();
1165 wxTreeItemId GetNextVisible(const wxTreeItemId& item);
1166 wxTreeItemId GetPrevVisible(const wxTreeItemId& item);
1167 wxTreeItemId GetLastChild(const wxTreeItemId& item);
1168
1169
1170
1171 wxTreeItemId AddRoot(const wxString& text,
1172 int image = -1, int selectedImage = -1,
1173 wxPyTreeItemData *data = NULL);
1174 wxTreeItemId PrependItem(const wxTreeItemId& parent,
1175 const wxString& text,
1176 int image = -1, int selectedImage = -1,
1177 wxPyTreeItemData *data = NULL);
1178 wxTreeItemId InsertItem(const wxTreeItemId& parent,
1179 const wxTreeItemId& idPrevious,
1180 const wxString& text,
1181 int image = -1, int selectedImage = -1,
1182 wxPyTreeItemData *data = NULL);
1183 %name(InsertItemBefore)
1184 wxTreeItemId InsertItem(const wxTreeItemId& parent,
1185 size_t before,
1186 const wxString& text,
1187 int image = -1, int selectedImage = -1,
1188 wxTreeItemData *data = NULL);
1189 wxTreeItemId AppendItem(const wxTreeItemId& parent,
1190 const wxString& text,
1191 int image = -1, int selectedImage = -1,
1192 wxPyTreeItemData *data = NULL);
1193
1194 void Delete(const wxTreeItemId& item);
1195 void DeleteChildren(const wxTreeItemId& item);
1196 void DeleteAllItems();
1197
1198 void Expand(const wxTreeItemId& item);
1199 void Collapse(const wxTreeItemId& item);
1200 void CollapseAndReset(const wxTreeItemId& item);
1201 void Toggle(const wxTreeItemId& item);
1202
1203 void Unselect();
1204 void UnselectAll();
1205 void SelectItem(const wxTreeItemId& item);
1206 void EnsureVisible(const wxTreeItemId& item);
1207 void ScrollTo(const wxTreeItemId& item);
1208 #ifdef __WXMSW__
1209 wxTextCtrl* EditLabel(const wxTreeItemId& item);
1210 wxTextCtrl* GetEditControl();
1211 void EndEditLabel(const wxTreeItemId& item, int discardChanges = FALSE);
1212 #else
1213 void EditLabel(const wxTreeItemId& item);
1214 #endif
1215
1216 void SortChildren(const wxTreeItemId& item);
1217
1218 void SetItemBold(const wxTreeItemId& item, int bold = TRUE);
1219 bool IsBold(const wxTreeItemId& item) const;
1220 wxTreeItemId HitTest(const wxPoint& point, int& OUTPUT);
1221
1222
1223
1224 void SetItemTextColour(const wxTreeItemId& item, const wxColour& col);
1225 void SetItemBackgroundColour(const wxTreeItemId& item, const wxColour& col);
1226 void SetItemFont(const wxTreeItemId& item, const wxFont& font);
1227
1228 #ifdef __WXMSW__
1229 void SetItemDropHighlight(const wxTreeItemId& item, int highlight = TRUE);
1230
1231 //bool GetBoundingRect(const wxTreeItemId& item, wxRect& rect, int textOnly = FALSE)
1232 %addmethods {
1233 PyObject* GetBoundingRect(const wxTreeItemId& item, int textOnly = FALSE) {
1234 wxRect rect;
1235 if (self->GetBoundingRect(item, rect, textOnly)) {
1236 bool doSave = wxPyRestoreThread();
1237 wxRect* r = new wxRect(rect);
1238 PyObject* val = wxPyConstructObject((void*)r, "wxRect");
1239 wxPySaveThread(doSave);
1240 return val;
1241 }
1242 else {
1243 Py_INCREF(Py_None);
1244 return Py_None;
1245 }
1246 }
1247 }
1248 #endif
1249
1250 %pragma(python) addtoclass = "
1251 # Redefine some methods that SWIG gets a bit confused on...
1252 def GetFirstChild(self, *_args, **_kwargs):
1253 val1,val2 = apply(controls2c.wxTreeCtrl_GetFirstChild,(self,) + _args, _kwargs)
1254 val1 = wxTreeItemIdPtr(val1)
1255 val1.thisown = 1
1256 return (val1,val2)
1257 def GetNextChild(self, *_args, **_kwargs):
1258 val1,val2 = apply(controls2c.wxTreeCtrl_GetNextChild,(self,) + _args, _kwargs)
1259 val1 = wxTreeItemIdPtr(val1)
1260 val1.thisown = 1
1261 return (val1,val2)
1262 def HitTest(self, *_args, **_kwargs):
1263 val1, val2 = apply(controls2c.wxTreeCtrl_HitTest,(self,) + _args, _kwargs)
1264 val1 = wxTreeItemIdPtr(val1)
1265 val1.thisown = 1
1266 return (val1,val2)
1267 "
1268 };
1269
1270
1271 //----------------------------------------------------------------------
1272
1273 %init %{
1274 wxPyPtrTypeMap_Add("wxTreeItemData", "wxPyTreeItemData");
1275 wxPyPtrTypeMap_Add("wxTreeCtrl", "wxPyTreeCtrl");
1276 %}
1277
1278 //----------------------------------------------------------------------
1279
1280