]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_listctrl.i
Recent changes in SWIG make this patch no longer necessary
[wxWidgets.git] / wxPython / src / _listctrl.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: _listctrl.i
3 // Purpose: SWIG interface file for wxListCtrl and related classes
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 10-June-1998
8 // RCS-ID: $Id$
9 // Copyright: (c) 2002 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13 // Not a %module
14
15
16 //---------------------------------------------------------------------------
17
18 %{
19 #include <wx/listctrl.h>
20
21 const wxChar* wxListCtrlNameStr = _T("wxListCtrl");
22 DECLARE_DEF_STRING(ListCtrlNameStr);
23 %}
24
25 //---------------------------------------------------------------------------
26 %newgroup
27
28 enum {
29 // style flags
30 wxLC_VRULES,
31 wxLC_HRULES,
32
33 wxLC_ICON,
34 wxLC_SMALL_ICON,
35 wxLC_LIST,
36 wxLC_REPORT,
37
38 wxLC_ALIGN_TOP,
39 wxLC_ALIGN_LEFT,
40 wxLC_AUTOARRANGE,
41 wxLC_VIRTUAL,
42 wxLC_EDIT_LABELS,
43 wxLC_NO_HEADER,
44 wxLC_NO_SORT_HEADER,
45 wxLC_SINGLE_SEL,
46 wxLC_SORT_ASCENDING,
47 wxLC_SORT_DESCENDING,
48
49 wxLC_MASK_TYPE,
50 wxLC_MASK_ALIGN,
51 wxLC_MASK_SORT
52 };
53
54
55 enum {
56 // Mask flags to tell app/GUI what fields of wxListItem are valid
57 wxLIST_MASK_STATE,
58 wxLIST_MASK_TEXT,
59 wxLIST_MASK_IMAGE,
60 wxLIST_MASK_DATA,
61 wxLIST_SET_ITEM,
62 wxLIST_MASK_WIDTH,
63 wxLIST_MASK_FORMAT,
64
65 // State flags for indicating the state of an item
66 wxLIST_STATE_DONTCARE,
67 wxLIST_STATE_DROPHILITED,
68 wxLIST_STATE_FOCUSED,
69 wxLIST_STATE_SELECTED,
70 wxLIST_STATE_CUT,
71 wxLIST_STATE_DISABLED,
72 wxLIST_STATE_FILTERED,
73 wxLIST_STATE_INUSE,
74 wxLIST_STATE_PICKED,
75 wxLIST_STATE_SOURCE,
76
77 // Hit test flags, used in HitTest
78 wxLIST_HITTEST_ABOVE,
79 wxLIST_HITTEST_BELOW,
80 wxLIST_HITTEST_NOWHERE,
81 wxLIST_HITTEST_ONITEMICON,
82 wxLIST_HITTEST_ONITEMLABEL,
83 wxLIST_HITTEST_ONITEMRIGHT,
84 wxLIST_HITTEST_ONITEMSTATEICON,
85 wxLIST_HITTEST_TOLEFT,
86 wxLIST_HITTEST_TORIGHT,
87 wxLIST_HITTEST_ONITEM,
88 };
89
90
91 // Flags for GetNextItem (MSW only except wxLIST_NEXT_ALL)
92 enum
93 {
94 wxLIST_NEXT_ABOVE, // Searches for an item above the specified item
95 wxLIST_NEXT_ALL, // Searches for subsequent item by index
96 wxLIST_NEXT_BELOW, // Searches for an item below the specified item
97 wxLIST_NEXT_LEFT, // Searches for an item to the left of the specified item
98 wxLIST_NEXT_RIGHT // Searches for an item to the right of the specified item
99 };
100
101 // Alignment flags for Arrange (MSW only except wxLIST_ALIGN_LEFT)
102 enum
103 {
104 wxLIST_ALIGN_DEFAULT,
105 wxLIST_ALIGN_LEFT,
106 wxLIST_ALIGN_TOP,
107 wxLIST_ALIGN_SNAP_TO_GRID
108 };
109
110 // Column format (MSW only except wxLIST_FORMAT_LEFT)
111 enum wxListColumnFormat
112 {
113 wxLIST_FORMAT_LEFT,
114 wxLIST_FORMAT_RIGHT,
115 wxLIST_FORMAT_CENTRE,
116 wxLIST_FORMAT_CENTER = wxLIST_FORMAT_CENTRE
117 };
118
119 // Autosize values for SetColumnWidth
120 enum
121 {
122 wxLIST_AUTOSIZE = -1,
123 wxLIST_AUTOSIZE_USEHEADER = -2 // partly supported by generic version
124 };
125
126 // Flag values for GetItemRect
127 enum
128 {
129 wxLIST_RECT_BOUNDS,
130 wxLIST_RECT_ICON,
131 wxLIST_RECT_LABEL
132 };
133
134 // Flag values for FindItem (MSW only)
135 enum
136 {
137 wxLIST_FIND_UP,
138 wxLIST_FIND_DOWN,
139 wxLIST_FIND_LEFT,
140 wxLIST_FIND_RIGHT
141 };
142
143
144
145 //---------------------------------------------------------------------------
146 %newgroup
147
148 // wxListItemAttr: a structure containing the visual attributes of an item
149 class wxListItemAttr
150 {
151 public:
152 // ctors
153 //wxListItemAttr();
154 wxListItemAttr(const wxColour& colText = wxNullColour,
155 const wxColour& colBack = wxNullColour,
156 const wxFont& font = wxNullFont);
157
158
159 // setters
160 void SetTextColour(const wxColour& colText);
161 void SetBackgroundColour(const wxColour& colBack);
162 void SetFont(const wxFont& font);
163
164 // accessors
165 bool HasTextColour();
166 bool HasBackgroundColour();
167 bool HasFont();
168
169 wxColour GetTextColour();
170 wxColour GetBackgroundColour();
171 wxFont GetFont();
172
173 %extend { void Destroy() { delete self; } }
174 };
175
176
177
178
179 //---------------------------------------------------------------------------
180 %newgroup
181
182 // wxListItem: the item or column info, used to exchange data with wxListCtrl
183 class wxListItem : public wxObject {
184 public:
185 wxListItem();
186 ~wxListItem();
187
188 // resetting
189 void Clear();
190 void ClearAttributes();
191
192 // setters
193 void SetMask(long mask);
194 void SetId(long id);
195 void SetColumn(int col);
196 void SetState(long state);
197 void SetStateMask(long stateMask);
198 void SetText(const wxString& text);
199 void SetImage(int image);
200 void SetData(long data);
201
202 void SetWidth(int width);
203 void SetAlign(wxListColumnFormat align);
204
205 void SetTextColour(const wxColour& colText);
206 void SetBackgroundColour(const wxColour& colBack);
207 void SetFont(const wxFont& font);
208
209 // accessors
210 long GetMask();
211 long GetId();
212 int GetColumn();
213 long GetState();
214 const wxString& GetText();
215 int GetImage();
216 long GetData();
217
218 int GetWidth();
219 wxListColumnFormat GetAlign();
220
221 wxListItemAttr *GetAttributes();
222 bool HasAttributes();
223
224 wxColour GetTextColour() const;
225 wxColour GetBackgroundColour() const;
226 wxFont GetFont() const;
227
228 // these members are public for compatibility
229 long m_mask; // Indicates what fields are valid
230 long m_itemId; // The zero-based item position
231 int m_col; // Zero-based column, if in report mode
232 long m_state; // The state of the item
233 long m_stateMask;// Which flags of m_state are valid (uses same flags)
234 wxString m_text; // The label/header text
235 int m_image; // The zero-based index into an image list
236 long m_data; // App-defined data
237
238 // For columns only
239 int m_format; // left, right, centre
240 int m_width; // width of column
241
242 };
243
244
245 //---------------------------------------------------------------------------
246 %newgroup
247
248
249 // wxListEvent - the event class for the wxListCtrl notifications
250 class wxListEvent: public wxNotifyEvent {
251 public:
252 wxListEvent(wxEventType commandType = wxEVT_NULL, int id = 0);
253
254 int m_code;
255 long m_oldItemIndex;
256 long m_itemIndex;
257 int m_col;
258 wxPoint m_pointDrag;
259 %immutable;
260 wxListItem m_item;
261 %mutable;
262
263 int GetKeyCode();
264 %pythoncode { GetCode = GetKeyCode }
265 long GetIndex();
266 int GetColumn();
267 wxPoint GetPoint();
268 %pythoncode { GetPostiion = GetPoint }
269 const wxString& GetLabel();
270 const wxString& GetText();
271 int GetImage();
272 long GetData();
273 long GetMask();
274 const wxListItem& GetItem();
275
276 long GetCacheFrom();
277 long GetCacheTo();
278
279 // was label editing canceled? (for wxEVT_COMMAND_LIST_END_LABEL_EDIT only)
280 bool IsEditCancelled() const;
281 void SetEditCanceled(bool editCancelled);
282 };
283
284 /* List control event types */
285 %constant wxEventType wxEVT_COMMAND_LIST_BEGIN_DRAG;
286 %constant wxEventType wxEVT_COMMAND_LIST_BEGIN_RDRAG;
287 %constant wxEventType wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT;
288 %constant wxEventType wxEVT_COMMAND_LIST_END_LABEL_EDIT;
289 %constant wxEventType wxEVT_COMMAND_LIST_DELETE_ITEM;
290 %constant wxEventType wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS;
291 %constant wxEventType wxEVT_COMMAND_LIST_GET_INFO;
292 %constant wxEventType wxEVT_COMMAND_LIST_SET_INFO;
293 %constant wxEventType wxEVT_COMMAND_LIST_ITEM_SELECTED;
294 %constant wxEventType wxEVT_COMMAND_LIST_ITEM_DESELECTED;
295 %constant wxEventType wxEVT_COMMAND_LIST_KEY_DOWN;
296 %constant wxEventType wxEVT_COMMAND_LIST_INSERT_ITEM;
297 %constant wxEventType wxEVT_COMMAND_LIST_COL_CLICK;
298 %constant wxEventType wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK;
299 %constant wxEventType wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK;
300 %constant wxEventType wxEVT_COMMAND_LIST_ITEM_ACTIVATED;
301 %constant wxEventType wxEVT_COMMAND_LIST_CACHE_HINT;
302 %constant wxEventType wxEVT_COMMAND_LIST_COL_RIGHT_CLICK;
303 %constant wxEventType wxEVT_COMMAND_LIST_COL_BEGIN_DRAG;
304 %constant wxEventType wxEVT_COMMAND_LIST_COL_DRAGGING;
305 %constant wxEventType wxEVT_COMMAND_LIST_COL_END_DRAG;
306 %constant wxEventType wxEVT_COMMAND_LIST_ITEM_FOCUSED;
307
308
309
310 %pythoncode {
311
312 EVT_LIST_BEGIN_DRAG = wx.PyEventBinder(wxEVT_COMMAND_LIST_BEGIN_DRAG , 1)
313 EVT_LIST_BEGIN_RDRAG = wx.PyEventBinder(wxEVT_COMMAND_LIST_BEGIN_RDRAG , 1)
314 EVT_LIST_BEGIN_LABEL_EDIT = wx.PyEventBinder(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT , 1)
315 EVT_LIST_END_LABEL_EDIT = wx.PyEventBinder(wxEVT_COMMAND_LIST_END_LABEL_EDIT , 1)
316 EVT_LIST_DELETE_ITEM = wx.PyEventBinder(wxEVT_COMMAND_LIST_DELETE_ITEM , 1)
317 EVT_LIST_DELETE_ALL_ITEMS = wx.PyEventBinder(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS , 1)
318 EVT_LIST_GET_INFO = wx.PyEventBinder(wxEVT_COMMAND_LIST_GET_INFO , 1)
319 EVT_LIST_SET_INFO = wx.PyEventBinder(wxEVT_COMMAND_LIST_SET_INFO , 1)
320 EVT_LIST_ITEM_SELECTED = wx.PyEventBinder(wxEVT_COMMAND_LIST_ITEM_SELECTED , 1)
321 EVT_LIST_ITEM_DESELECTED = wx.PyEventBinder(wxEVT_COMMAND_LIST_ITEM_DESELECTED , 1)
322 EVT_LIST_KEY_DOWN = wx.PyEventBinder(wxEVT_COMMAND_LIST_KEY_DOWN , 1)
323 EVT_LIST_INSERT_ITEM = wx.PyEventBinder(wxEVT_COMMAND_LIST_INSERT_ITEM , 1)
324 EVT_LIST_COL_CLICK = wx.PyEventBinder(wxEVT_COMMAND_LIST_COL_CLICK , 1)
325 EVT_LIST_ITEM_RIGHT_CLICK = wx.PyEventBinder(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK , 1)
326 EVT_LIST_ITEM_MIDDLE_CLICK = wx.PyEventBinder(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK, 1)
327 EVT_LIST_ITEM_ACTIVATED = wx.PyEventBinder(wxEVT_COMMAND_LIST_ITEM_ACTIVATED , 1)
328 EVT_LIST_CACHE_HINT = wx.PyEventBinder(wxEVT_COMMAND_LIST_CACHE_HINT , 1)
329 EVT_LIST_COL_RIGHT_CLICK = wx.PyEventBinder(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK , 1)
330 EVT_LIST_COL_BEGIN_DRAG = wx.PyEventBinder(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG , 1)
331 EVT_LIST_COL_DRAGGING = wx.PyEventBinder(wxEVT_COMMAND_LIST_COL_DRAGGING , 1)
332 EVT_LIST_COL_END_DRAG = wx.PyEventBinder(wxEVT_COMMAND_LIST_COL_END_DRAG , 1)
333 EVT_LIST_ITEM_FOCUSED = wx.PyEventBinder(wxEVT_COMMAND_LIST_ITEM_FOCUSED , 1)
334 }
335
336 //---------------------------------------------------------------------------
337 %newgroup
338
339
340 %{ // Python aware sorting function for wxPyListCtrl
341 static int wxCALLBACK wxPyListCtrl_SortItems(long item1, long item2, long funcPtr) {
342 int retval = 0;
343 PyObject* func = (PyObject*)funcPtr;
344 wxPyBeginBlockThreads();
345
346 PyObject* args = Py_BuildValue("(ii)", item1, item2);
347 PyObject* result = PyEval_CallObject(func, args);
348 Py_DECREF(args);
349 if (result) {
350 retval = PyInt_AsLong(result);
351 Py_DECREF(result);
352 }
353
354 wxPyEndBlockThreads();
355 return retval;
356 }
357 %}
358
359
360
361 %{ // C++ Version of a Python aware class
362 class wxPyListCtrl : public wxListCtrl {
363 DECLARE_ABSTRACT_CLASS(wxPyListCtrl);
364 public:
365 wxPyListCtrl() : wxListCtrl() {}
366 wxPyListCtrl(wxWindow* parent, wxWindowID id,
367 const wxPoint& pos,
368 const wxSize& size,
369 long style,
370 const wxValidator& validator,
371 const wxString& name) :
372 wxListCtrl(parent, id, pos, size, style, validator, name) {}
373
374 bool Create(wxWindow* parent, wxWindowID id,
375 const wxPoint& pos,
376 const wxSize& size,
377 long style,
378 const wxValidator& validator,
379 const wxString& name) {
380 return wxListCtrl::Create(parent, id, pos, size, style, validator, name);
381 }
382
383 DEC_PYCALLBACK_STRING_LONGLONG(OnGetItemText);
384 DEC_PYCALLBACK_INT_LONG(OnGetItemImage);
385 DEC_PYCALLBACK_LISTATTR_LONG(OnGetItemAttr);
386
387 PYPRIVATE;
388 };
389
390 IMPLEMENT_ABSTRACT_CLASS(wxPyListCtrl, wxListCtrl);
391
392 IMP_PYCALLBACK_STRING_LONGLONG(wxPyListCtrl, wxListCtrl, OnGetItemText);
393 IMP_PYCALLBACK_INT_LONG(wxPyListCtrl, wxListCtrl, OnGetItemImage);
394 IMP_PYCALLBACK_LISTATTR_LONG(wxPyListCtrl, wxListCtrl, OnGetItemAttr);
395 %}
396
397
398
399
400
401 %name(ListCtrl)class wxPyListCtrl : public wxControl {
402 public:
403
404 %addtofunc wxPyListCtrl "self._setOORInfo(self);self._setCallbackInfo(self, ListCtrl)"
405 %addtofunc wxPyListCtrl() ""
406
407 wxPyListCtrl(wxWindow* parent, wxWindowID id = -1,
408 const wxPoint& pos = wxDefaultPosition,
409 const wxSize& size = wxDefaultSize,
410 long style = wxLC_ICON,
411 const wxValidator& validator = wxDefaultValidator,
412 const wxString& name = wxPyListCtrlNameStr);
413 %name(PreListCtrl)wxPyListCtrl();
414
415 bool Create(wxWindow* parent, wxWindowID id = -1,
416 const wxPoint& pos = wxDefaultPosition,
417 const wxSize& size = wxDefaultSize,
418 long style = wxLC_ICON,
419 const wxValidator& validator = wxDefaultValidator,
420 const wxString& name = wxPyListCtrlNameStr);
421
422 void _setCallbackInfo(PyObject* self, PyObject* _class);
423
424
425 // Set the control colours
426 bool SetForegroundColour(const wxColour& col);
427 bool SetBackgroundColour(const wxColour& col);
428
429 // Gets information about this column
430 %addtofunc GetColumn "if val is not None: val.thisown = 1"; // %newobject doesn't work with OOR typemap
431 %extend {
432 wxListItem* GetColumn(int col) {
433 wxListItem item;
434 item.SetMask( wxLIST_MASK_STATE |
435 wxLIST_MASK_TEXT |
436 wxLIST_MASK_IMAGE |
437 wxLIST_MASK_DATA |
438 wxLIST_SET_ITEM |
439 wxLIST_MASK_WIDTH |
440 wxLIST_MASK_FORMAT
441 );
442 if (self->GetColumn(col, item))
443 return new wxListItem(item);
444 else
445 return NULL;
446 }
447 }
448
449 // Sets information about this column
450 bool SetColumn(int col, wxListItem& item) ;
451
452 // Gets the column width
453 int GetColumnWidth(int col) const;
454
455 // Sets the column width
456 bool SetColumnWidth(int col, int width) ;
457
458 // Gets the number of items that can fit vertically in the
459 // visible area of the list control (list or report view)
460 // or the total number of items in the list control (icon
461 // or small icon view)
462 int GetCountPerPage() const;
463
464 // return the total area occupied by all the items (icon/small icon only)
465 wxRect GetViewRect() const;
466
467 #ifdef __WXMSW__
468 // Gets the edit control for editing labels.
469 wxTextCtrl* GetEditControl() const;
470 #endif
471
472 // Gets information about the item
473 %addtofunc GetItem "if val is not None: val.thisown = 1"; // %newobject doesn't work with OOR typemap
474 %extend {
475 wxListItem* GetItem(long itemId, int col=0) {
476 wxListItem* info = new wxListItem;
477 info->m_itemId = itemId;
478 info->m_col = col;
479 info->m_mask = 0xFFFF;
480 self->GetItem(*info);
481 return info;
482 }
483 }
484
485 // Sets information about the item
486 bool SetItem(wxListItem& info) ;
487
488 // Sets a string field at a particular column
489 %name(SetStringItem)long SetItem(long index, int col, const wxString& label, int imageId = -1);
490
491 // Gets the item state
492 int GetItemState(long item, long stateMask) const ;
493
494 // Sets the item state
495 bool SetItemState(long item, long state, long stateMask) ;
496
497 // Sets the item image
498 bool SetItemImage(long item, int image, int selImage) ;
499
500 // Gets the item text
501 wxString GetItemText(long item) const ;
502
503 // Sets the item text
504 void SetItemText(long item, const wxString& str) ;
505
506 // Gets the item data
507 long GetItemData(long item) const ;
508
509 // Sets the item data
510 bool SetItemData(long item, long data) ;
511
512
513 //bool GetItemRect(long item, wxRect& rect, int code = wxLIST_RECT_BOUNDS) const ;
514 //bool GetItemPosition(long item, wxPoint& pos) const ;
515
516 // Gets the item position
517 %extend {
518 wxPoint GetItemPosition(long item) {
519 wxPoint pos;
520 self->GetItemPosition(item, pos);
521 return pos;
522 }
523 // Gets the item rectangle
524 wxRect GetItemRect(long item, int code = wxLIST_RECT_BOUNDS) {
525 wxRect rect;
526 self->GetItemRect(item, rect, code);
527 return rect;
528 }
529 }
530
531
532 // Sets the item position
533 bool SetItemPosition(long item, const wxPoint& pos) ;
534
535 // Gets the number of items in the list control
536 int GetItemCount() const;
537
538 // Gets the number of columns in the list control
539 int GetColumnCount() const;
540
541 // get the horizontal and vertical components of the item spacing
542 wxSize GetItemSpacing() const;
543
544 #ifndef __WXMSW__
545 void SetItemSpacing( int spacing, bool isSmall = FALSE );
546 #endif
547
548 // Gets the number of selected items in the list control
549 int GetSelectedItemCount() const;
550
551 // Gets the text colour of the listview
552 wxColour GetTextColour() const;
553
554 // Sets the text colour of the listview
555 void SetTextColour(const wxColour& col);
556
557 // Gets the index of the topmost visible item when in
558 // list or report view
559 long GetTopItem() const ;
560
561 // Add or remove a single window style
562 void SetSingleStyle(long style, bool add = TRUE) ;
563
564 // Set the whole window style
565 void SetWindowStyleFlag(long style) ;
566
567 // Searches for an item, starting from 'item'.
568 // item can be -1 to find the first item that matches the
569 // specified flags.
570 // Returns the item or -1 if unsuccessful.
571 long GetNextItem(long item, int geometry = wxLIST_NEXT_ALL, int state = wxLIST_STATE_DONTCARE) const ;
572
573 // Gets one of the three image lists
574 wxImageList *GetImageList(int which) const ;
575
576 // Sets the image list
577 void SetImageList(wxImageList *imageList, int which);
578
579 // is there a way to tell SWIG to disown this???
580
581 %addtofunc AssignImageList "args[1].thisown = 0";
582 void AssignImageList(wxImageList *imageList, int which);
583
584 // returns true if it is a virtual list control
585 bool IsVirtual() const;
586
587 // refresh items selectively (only useful for virtual list controls)
588 void RefreshItem(long item);
589 void RefreshItems(long itemFrom, long itemTo);
590
591 // Arranges the items
592 bool Arrange(int flag = wxLIST_ALIGN_DEFAULT);
593
594 // Deletes an item
595 bool DeleteItem(long item);
596
597 // Deletes all items
598 bool DeleteAllItems() ;
599
600 // Deletes a column
601 bool DeleteColumn(int col);
602
603 // Deletes all columns
604 bool DeleteAllColumns();
605
606 // Clears items, and columns if there are any.
607 void ClearAll();
608
609 #ifdef __WXMSW__
610 // Edit the label
611 wxTextCtrl* EditLabel(long item /*, wxClassInfo* textControlClass = CLASSINFO(wxTextCtrl)*/);
612
613 // End label editing, optionally cancelling the edit
614 bool EndEditLabel(bool cancel);
615 #else
616 void EditLabel(long item);
617 #endif
618
619 // Ensures this item is visible
620 bool EnsureVisible(long item) ;
621
622 // Find an item whose label matches this string, starting from the item after 'start'
623 // or the beginning if 'start' is -1.
624 long FindItem(long start, const wxString& str, bool partial = FALSE);
625
626 // Find an item whose data matches this data, starting from the item after 'start'
627 // or the beginning if 'start' is -1.
628 %name(FindItemData) long FindItem(long start, long data);
629
630 // Find an item nearest this position in the specified direction, starting from
631 // the item after 'start' or the beginning if 'start' is -1.
632 %name(FindItemAtPos) long FindItem(long start, const wxPoint& pt, int direction);
633
634 // Determines which item (if any) is at the specified point,
635 // giving details in the second return value (see wxLIST_HITTEST_... flags above)
636 long HitTest(const wxPoint& point, int& OUTPUT);
637
638 // Inserts an item, returning the index of the new item if successful,
639 // -1 otherwise.
640 long InsertItem(wxListItem& info);
641
642 // Insert a string item
643 %name(InsertStringItem) long InsertItem(long index, const wxString& label);
644
645 // Insert an image item
646 %name(InsertImageItem) long InsertItem(long index, int imageIndex);
647
648 // Insert an image/string item
649 %name(InsertImageStringItem) long InsertItem(long index, const wxString& label, int imageIndex);
650
651 // For list view mode (only), inserts a column.
652 %name(InsertColumnInfo) long InsertColumn(long col, wxListItem& info);
653
654 long InsertColumn(long col,
655 const wxString& heading,
656 int format = wxLIST_FORMAT_LEFT,
657 int width = -1);
658
659 // set the number of items in a virtual list control
660 void SetItemCount(long count);
661
662 // Scrolls the list control. If in icon, small icon or report view mode,
663 // x specifies the number of pixels to scroll. If in list view mode, x
664 // specifies the number of columns to scroll.
665 // If in icon, small icon or list view mode, y specifies the number of pixels
666 // to scroll. If in report view mode, y specifies the number of lines to scroll.
667 bool ScrollList(int dx, int dy);
668
669 void SetItemTextColour( long item, const wxColour& col);
670 wxColour GetItemTextColour( long item ) const;
671 void SetItemBackgroundColour( long item, const wxColour &col);
672 wxColour GetItemBackgroundColour( long item ) const;
673
674
675 %pythoncode {
676 %#
677 %# Some helpers...
678 def Select(self, idx, on=1):
679 '''[de]select an item'''
680 if on: state = wxLIST_STATE_SELECTED
681 else: state = 0
682 self.SetItemState(idx, state, wxLIST_STATE_SELECTED)
683
684 def Focus(self, idx):
685 '''Focus and show the given item'''
686 self.SetItemState(idx, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED)
687 self.EnsureVisible(idx)
688
689 def GetFocusedItem(self):
690 '''get the currently focused item or -1 if none'''
691 return self.GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED)
692
693 def GetFirstSelected(self, *args):
694 '''return first selected item, or -1 when none'''
695 return self.GetNextSelected(-1)
696
697 def GetNextSelected(self, item):
698 '''return subsequent selected items, or -1 when no more'''
699 return self.GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED)
700
701 def IsSelected(self, idx):
702 '''return TRUE if the item is selected'''
703 return self.GetItemState(idx, wxLIST_STATE_SELECTED) != 0
704
705 def SetColumnImage(self, col, image):
706 item = self.GetColumn(col)
707 # preserve all other attributes too
708 item.SetMask( wxLIST_MASK_STATE |
709 wxLIST_MASK_TEXT |
710 wxLIST_MASK_IMAGE |
711 wxLIST_MASK_DATA |
712 wxLIST_SET_ITEM |
713 wxLIST_MASK_WIDTH |
714 wxLIST_MASK_FORMAT )
715 item.SetImage(image)
716 self.SetColumn(col, item)
717
718 def ClearColumnImage(self, col):
719 self.SetColumnImage(col, -1)
720
721 def Append(self, entry):
722 '''Append an item to the list control. The entry parameter should be a
723 sequence with an item for each column'''
724 if len(entry):
725 if wx.wxUSE_UNICODE:
726 cvtfunc = unicode
727 else:
728 cvtfunc = str
729 pos = self.GetItemCount()
730 self.InsertStringItem(pos, cvtfunc(entry[0]))
731 for i in range(1, len(entry)):
732 self.SetStringItem(pos, i, cvtfunc(entry[i]))
733 return pos
734 }
735
736
737 // bool SortItems(wxListCtrlCompare fn, long data);
738 %extend {
739 // Sort items.
740 // func is a function which takes 2 long arguments: item1, item2.
741 // item1 is the long data associated with a first item (NOT the index).
742 // item2 is the long data associated with a second item (NOT the index).
743 // The return value is a negative number if the first item should precede the second
744 // item, a positive number of the second item should precede the first,
745 // or zero if the two items are equivalent.
746 bool SortItems(PyObject* func) {
747 if (!PyCallable_Check(func))
748 return FALSE;
749 return self->SortItems((wxListCtrlCompare)wxPyListCtrl_SortItems, (long)func);
750 }
751 }
752
753
754 %extend {
755 wxWindow* GetMainWindow() {
756 #ifdef __WXMSW__
757 return self;
758 #else
759 return (wxWindow*)self->m_mainWin;
760 #endif
761 }
762 }
763 };
764
765
766
767 //---------------------------------------------------------------------------
768 %newgroup
769
770
771 // wxListView: a class which provides a little better API for list control
772 class wxListView : public wxPyListCtrl
773 {
774 public:
775 %addtofunc wxListView "self._setOORInfo(self)"
776 %addtofunc wxListView() ""
777
778 wxListView( wxWindow *parent,
779 wxWindowID id = -1,
780 const wxPoint& pos = wxDefaultPosition,
781 const wxSize& size = wxDefaultSize,
782 long style = wxLC_REPORT,
783 const wxValidator& validator = wxDefaultValidator,
784 const wxString& name = wxPyListCtrlNameStr);
785 %name(PreListView)wxListView();
786
787 bool Create( wxWindow *parent,
788 wxWindowID id = -1,
789 const wxPoint& pos = wxDefaultPosition,
790 const wxSize& size = wxDefaultSize,
791 long style = wxLC_REPORT,
792 const wxValidator& validator = wxDefaultValidator,
793 const wxString& name = wxPyListCtrlNameStr);
794
795 // [de]select an item
796 void Select(long n, bool on = TRUE);
797
798 // focus and show the given item
799 void Focus(long index);
800
801 // get the currently focused item or -1 if none
802 long GetFocusedItem() const;
803
804 // get first and subsequent selected items, return -1 when no more
805 long GetNextSelected(long item) const;
806 long GetFirstSelected() const;
807
808 // return TRUE if the item is selected
809 bool IsSelected(long index);
810
811 void SetColumnImage(int col, int image);
812 void ClearColumnImage(int col);
813 };
814
815
816
817 //---------------------------------------------------------------------------
818
819 %init %{
820 // Map renamed classes back to their common name for OOR
821 wxPyPtrTypeMap_Add("wxListCtrl", "wxPyListCtrl");
822 %}
823
824 //---------------------------------------------------------------------------