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