]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_listctrl.i
Better markup.
[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_WXSTRING2(ListCtrlNameStr, _T("wxListCtrl"));
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_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 EVT_LIST_GET_INFO = wx._deprecated(EVT_LIST_GET_INFO)
336 EVT_LIST_SET_INFO = wx._deprecated(EVT_LIST_SET_INFO)
337 }
338
339 //---------------------------------------------------------------------------
340 %newgroup
341
342
343 %{ // Python aware sorting function for wxPyListCtrl
344 static int wxCALLBACK wxPyListCtrl_SortItems(long item1, long item2, long funcPtr) {
345 int retval = 0;
346 PyObject* func = (PyObject*)funcPtr;
347 bool blocked = wxPyBeginBlockThreads();
348
349 PyObject* args = Py_BuildValue("(ii)", item1, item2);
350 PyObject* result = PyEval_CallObject(func, args);
351 Py_DECREF(args);
352 if (result) {
353 retval = PyInt_AsLong(result);
354 Py_DECREF(result);
355 }
356
357 wxPyEndBlockThreads(blocked);
358 return retval;
359 }
360 %}
361
362
363
364 %{ // C++ Version of a Python aware class
365 class wxPyListCtrl : public wxListCtrl {
366 DECLARE_ABSTRACT_CLASS(wxPyListCtrl);
367 public:
368 wxPyListCtrl() : wxListCtrl() {}
369 wxPyListCtrl(wxWindow* parent, wxWindowID id,
370 const wxPoint& pos,
371 const wxSize& size,
372 long style,
373 const wxValidator& validator,
374 const wxString& name) :
375 wxListCtrl(parent, id, pos, size, style, validator, name) {}
376
377 bool Create(wxWindow* parent, wxWindowID id,
378 const wxPoint& pos,
379 const wxSize& size,
380 long style,
381 const wxValidator& validator,
382 const wxString& name) {
383 return wxListCtrl::Create(parent, id, pos, size, style, validator, name);
384 }
385
386 DEC_PYCALLBACK_STRING_LONGLONG(OnGetItemText);
387 DEC_PYCALLBACK_INT_LONG(OnGetItemImage);
388 DEC_PYCALLBACK_LISTATTR_LONG(OnGetItemAttr);
389
390 PYPRIVATE;
391 };
392
393 IMPLEMENT_ABSTRACT_CLASS(wxPyListCtrl, wxListCtrl);
394
395 IMP_PYCALLBACK_STRING_LONGLONG(wxPyListCtrl, wxListCtrl, OnGetItemText);
396 IMP_PYCALLBACK_INT_LONG(wxPyListCtrl, wxListCtrl, OnGetItemImage);
397 IMP_PYCALLBACK_LISTATTR_LONG(wxPyListCtrl, wxListCtrl, OnGetItemAttr);
398 %}
399
400
401
402
403
404 MustHaveApp(wxPyListCtrl);
405
406 %name(ListCtrl)class wxPyListCtrl : public wxControl {
407 public:
408
409 %pythonAppend wxPyListCtrl "self._setOORInfo(self);self._setCallbackInfo(self, ListCtrl)"
410 %pythonAppend wxPyListCtrl() ""
411
412 wxPyListCtrl(wxWindow* parent, wxWindowID id = -1,
413 const wxPoint& pos = wxDefaultPosition,
414 const wxSize& size = wxDefaultSize,
415 long style = wxLC_ICON,
416 const wxValidator& validator = wxDefaultValidator,
417 const wxString& name = wxPyListCtrlNameStr);
418 %name(PreListCtrl)wxPyListCtrl();
419
420 bool Create(wxWindow* parent, wxWindowID id = -1,
421 const wxPoint& pos = wxDefaultPosition,
422 const wxSize& size = wxDefaultSize,
423 long style = wxLC_ICON,
424 const wxValidator& validator = wxDefaultValidator,
425 const wxString& name = wxPyListCtrlNameStr);
426
427 void _setCallbackInfo(PyObject* self, PyObject* _class);
428
429
430 // Set the control colours
431 bool SetForegroundColour(const wxColour& col);
432 bool SetBackgroundColour(const wxColour& col);
433
434 // Gets information about this column
435 %pythonAppend GetColumn "if val is not None: val.thisown = 1"; // %newobject doesn't work with OOR typemap
436 %extend {
437 wxListItem* GetColumn(int col) {
438 wxListItem item;
439 item.SetMask( wxLIST_MASK_STATE |
440 wxLIST_MASK_TEXT |
441 wxLIST_MASK_IMAGE |
442 wxLIST_MASK_DATA |
443 wxLIST_SET_ITEM |
444 wxLIST_MASK_WIDTH |
445 wxLIST_MASK_FORMAT
446 );
447 if (self->GetColumn(col, item))
448 return new wxListItem(item);
449 else
450 return NULL;
451 }
452 }
453
454 // Sets information about this column
455 bool SetColumn(int col, wxListItem& item) ;
456
457 // Gets the column width
458 int GetColumnWidth(int col) const;
459
460 // Sets the column width
461 bool SetColumnWidth(int col, int width) ;
462
463 // Gets the number of items that can fit vertically in the
464 // visible area of the list control (list or report view)
465 // or the total number of items in the list control (icon
466 // or small icon view)
467 int GetCountPerPage() const;
468
469 // return the total area occupied by all the items (icon/small icon only)
470 wxRect GetViewRect() const;
471
472 #ifdef __WXMSW__
473 // Gets the edit control for editing labels.
474 wxTextCtrl* GetEditControl() const;
475 #endif
476
477 // Gets information about the item
478 %pythonAppend GetItem "if val is not None: val.thisown = 1"; // %newobject doesn't work with OOR typemap
479 %extend {
480 wxListItem* GetItem(long itemId, int col=0) {
481 wxListItem* info = new wxListItem;
482 info->m_itemId = itemId;
483 info->m_col = col;
484 info->m_mask = 0xFFFF;
485 self->GetItem(*info);
486 return info;
487 }
488 }
489
490 // Sets information about the item
491 bool SetItem(wxListItem& info) ;
492
493 // Sets a string field at a particular column
494 %name(SetStringItem)long SetItem(long index, int col, const wxString& label, int imageId = -1);
495
496 // Gets the item state
497 int GetItemState(long item, long stateMask) const ;
498
499 // Sets the item state
500 bool SetItemState(long item, long state, long stateMask) ;
501
502 // Sets the item image
503 bool SetItemImage(long item, int image, int selImage=-1) ;
504
505 // Gets the item text
506 wxString GetItemText(long item) const ;
507
508 // Sets the item text
509 void SetItemText(long item, const wxString& str) ;
510
511 // Gets the item data
512 long GetItemData(long item) const ;
513
514 // Sets the item data
515 bool SetItemData(long item, long data) ;
516
517
518 //bool GetItemRect(long item, wxRect& rect, int code = wxLIST_RECT_BOUNDS) const ;
519 //bool GetItemPosition(long item, wxPoint& pos) const ;
520
521 // Gets the item position
522 %extend {
523 wxPoint GetItemPosition(long item) {
524 wxPoint pos;
525 self->GetItemPosition(item, pos);
526 return pos;
527 }
528 // Gets the item rectangle
529 wxRect GetItemRect(long item, int code = wxLIST_RECT_BOUNDS) {
530 wxRect rect;
531 self->GetItemRect(item, rect, code);
532 return rect;
533 }
534 }
535
536
537 // Sets the item position
538 bool SetItemPosition(long item, const wxPoint& pos) ;
539
540 // Gets the number of items in the list control
541 int GetItemCount() const;
542
543 // Gets the number of columns in the list control
544 int GetColumnCount() const;
545
546 // get the horizontal and vertical components of the item spacing
547 wxSize GetItemSpacing() const;
548
549 #ifndef __WXMSW__
550 void SetItemSpacing( int spacing, bool isSmall = false );
551 #endif
552
553 // Gets the number of selected items in the list control
554 int GetSelectedItemCount() const;
555
556 // Gets the text colour of the listview
557 wxColour GetTextColour() const;
558
559 // Sets the text colour of the listview
560 void SetTextColour(const wxColour& col);
561
562 // Gets the index of the topmost visible item when in
563 // list or report view
564 long GetTopItem() const ;
565
566 // Add or remove a single window style
567 void SetSingleStyle(long style, bool add = true) ;
568
569 // Set the whole window style
570 void SetWindowStyleFlag(long style) ;
571
572 // Searches for an item, starting from 'item'.
573 // item can be -1 to find the first item that matches the
574 // specified flags.
575 // Returns the item or -1 if unsuccessful.
576 long GetNextItem(long item, int geometry = wxLIST_NEXT_ALL, int state = wxLIST_STATE_DONTCARE) const ;
577
578 // Gets one of the three image lists
579 wxImageList *GetImageList(int which) const ;
580
581 // Sets the image list
582 void SetImageList(wxImageList *imageList, int which);
583
584 // is there a way to tell SWIG to disown this???
585
586 %apply SWIGTYPE *DISOWN { wxImageList *imageList };
587 void AssignImageList(wxImageList *imageList, int which);
588 %clear wxImageList *imageList;
589
590 // are we in report mode?
591 bool InReportView() const;
592
593 // returns True if it is a virtual list control
594 bool IsVirtual() const;
595
596 // refresh items selectively (only useful for virtual list controls)
597 void RefreshItem(long item);
598 void RefreshItems(long itemFrom, long itemTo);
599
600 // Arranges the items
601 bool Arrange(int flag = wxLIST_ALIGN_DEFAULT);
602
603 // Deletes an item
604 bool DeleteItem(long item);
605
606 // Deletes all items
607 bool DeleteAllItems() ;
608
609 // Deletes a column
610 bool DeleteColumn(int col);
611
612 // Deletes all columns
613 bool DeleteAllColumns();
614
615 // Clears items, and columns if there are any.
616 void ClearAll();
617
618 #ifdef __WXMSW__
619 // Edit the label
620 wxTextCtrl* EditLabel(long item /*, wxClassInfo* textControlClass = CLASSINFO(wxTextCtrl)*/);
621
622 // End label editing, optionally cancelling the edit
623 bool EndEditLabel(bool cancel);
624 #else
625 void EditLabel(long item);
626 #endif
627
628 // Ensures this item is visible
629 bool EnsureVisible(long item) ;
630
631 // Find an item whose label matches this string, starting from the item after 'start'
632 // or the beginning if 'start' is -1.
633 long FindItem(long start, const wxString& str, bool partial = false);
634
635 // Find an item whose data matches this data, starting from the item after 'start'
636 // or the beginning if 'start' is -1.
637 %name(FindItemData) long FindItem(long start, long data);
638
639 // Find an item nearest this position in the specified direction, starting from
640 // the item after 'start' or the beginning if 'start' is -1.
641 %name(FindItemAtPos) long FindItem(long start, const wxPoint& pt, int direction);
642
643
644 DocDeclAStr(
645 long, HitTest(const wxPoint& point, int& OUTPUT),
646 "HitTest(Point point) -> (item, where)",
647 "Determines which item (if any) is at the specified point, giving
648 details in the second return value (see wxLIST_HITTEST_... flags.)", "");
649
650 // Inserts an item, returning the index of the new item if successful,
651 // -1 otherwise.
652 long InsertItem(wxListItem& info);
653
654 // Insert a string item
655 %name(InsertStringItem) long InsertItem(long index, const wxString& label);
656
657 // Insert an image item
658 %name(InsertImageItem) long InsertItem(long index, int imageIndex);
659
660 // Insert an image/string item
661 %name(InsertImageStringItem) long InsertItem(long index, const wxString& label, int imageIndex);
662
663 // For list view mode (only), inserts a column.
664 %name(InsertColumnInfo) long InsertColumn(long col, wxListItem& info);
665
666 long InsertColumn(long col,
667 const wxString& heading,
668 int format = wxLIST_FORMAT_LEFT,
669 int width = -1);
670
671 // set the number of items in a virtual list control
672 void SetItemCount(long count);
673
674 // Scrolls the list control. If in icon, small icon or report view mode,
675 // x specifies the number of pixels to scroll. If in list view mode, x
676 // specifies the number of columns to scroll.
677 // If in icon, small icon or list view mode, y specifies the number of pixels
678 // to scroll. If in report view mode, y specifies the number of lines to scroll.
679 bool ScrollList(int dx, int dy);
680
681 void SetItemTextColour( long item, const wxColour& col);
682 wxColour GetItemTextColour( long item ) const;
683 void SetItemBackgroundColour( long item, const wxColour &col);
684 wxColour GetItemBackgroundColour( long item ) const;
685
686
687 %pythoncode {
688 %#
689 %# Some helpers...
690 def Select(self, idx, on=1):
691 '''[de]select an item'''
692 if on: state = wx.LIST_STATE_SELECTED
693 else: state = 0
694 self.SetItemState(idx, state, wx.LIST_STATE_SELECTED)
695
696 def Focus(self, idx):
697 '''Focus and show the given item'''
698 self.SetItemState(idx, wx.LIST_STATE_FOCUSED, wx.LIST_STATE_FOCUSED)
699 self.EnsureVisible(idx)
700
701 def GetFocusedItem(self):
702 '''get the currently focused item or -1 if none'''
703 return self.GetNextItem(-1, wx.LIST_NEXT_ALL, wx.LIST_STATE_FOCUSED)
704
705 def GetFirstSelected(self, *args):
706 '''return first selected item, or -1 when none'''
707 return self.GetNextSelected(-1)
708
709 def GetNextSelected(self, item):
710 '''return subsequent selected items, or -1 when no more'''
711 return self.GetNextItem(item, wx.LIST_NEXT_ALL, wx.LIST_STATE_SELECTED)
712
713 def IsSelected(self, idx):
714 '''return True if the item is selected'''
715 return self.GetItemState(idx, wx.LIST_STATE_SELECTED) != 0
716
717 def SetColumnImage(self, col, image):
718 item = self.GetColumn(col)
719 %# preserve all other attributes too
720 item.SetMask( wx.LIST_MASK_STATE |
721 wx.LIST_MASK_TEXT |
722 wx.LIST_MASK_IMAGE |
723 wx.LIST_MASK_DATA |
724 wx.LIST_SET_ITEM |
725 wx.LIST_MASK_WIDTH |
726 wx.LIST_MASK_FORMAT )
727 item.SetImage(image)
728 self.SetColumn(col, item)
729
730 def ClearColumnImage(self, col):
731 self.SetColumnImage(col, -1)
732
733 def Append(self, entry):
734 '''Append an item to the list control. The entry parameter should be a
735 sequence with an item for each column'''
736 if len(entry):
737 if wx.USE_UNICODE:
738 cvtfunc = unicode
739 else:
740 cvtfunc = str
741 pos = self.GetItemCount()
742 self.InsertStringItem(pos, cvtfunc(entry[0]))
743 for i in range(1, len(entry)):
744 self.SetStringItem(pos, i, cvtfunc(entry[i]))
745 return pos
746 }
747
748
749 // bool SortItems(wxListCtrlCompare fn, long data);
750 %extend {
751 // Sort items.
752 // func is a function which takes 2 long arguments: item1, item2.
753 // item1 is the long data associated with a first item (NOT the index).
754 // item2 is the long data associated with a second item (NOT the index).
755 // The return value is a negative number if the first item should precede the second
756 // item, a positive number of the second item should precede the first,
757 // or zero if the two items are equivalent.
758 bool SortItems(PyObject* func) {
759 if (!PyCallable_Check(func))
760 return false;
761 return self->SortItems((wxListCtrlCompare)wxPyListCtrl_SortItems, (long)func);
762 }
763 }
764
765
766 %extend {
767 wxWindow* GetMainWindow() {
768 #ifdef __WXMSW__
769 return self;
770 #else
771 return (wxWindow*)self->m_mainWin;
772 #endif
773 }
774 }
775
776 static wxVisualAttributes
777 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
778 };
779
780
781
782 //---------------------------------------------------------------------------
783 %newgroup
784
785
786 MustHaveApp(wxListView);
787
788 // wxListView: a class which provides a little better API for list control
789 class wxListView : public wxPyListCtrl
790 {
791 public:
792 %pythonAppend wxListView "self._setOORInfo(self)"
793 %pythonAppend wxListView() ""
794
795 wxListView( wxWindow *parent,
796 wxWindowID id = -1,
797 const wxPoint& pos = wxDefaultPosition,
798 const wxSize& size = wxDefaultSize,
799 long style = wxLC_REPORT,
800 const wxValidator& validator = wxDefaultValidator,
801 const wxString& name = wxPyListCtrlNameStr);
802 %name(PreListView)wxListView();
803
804 bool Create( wxWindow *parent,
805 wxWindowID id = -1,
806 const wxPoint& pos = wxDefaultPosition,
807 const wxSize& size = wxDefaultSize,
808 long style = wxLC_REPORT,
809 const wxValidator& validator = wxDefaultValidator,
810 const wxString& name = wxPyListCtrlNameStr);
811
812 // [de]select an item
813 void Select(long n, bool on = true);
814
815 // focus and show the given item
816 void Focus(long index);
817
818 // get the currently focused item or -1 if none
819 long GetFocusedItem() const;
820
821 // get first and subsequent selected items, return -1 when no more
822 long GetNextSelected(long item) const;
823 long GetFirstSelected() const;
824
825 // return True if the item is selected
826 bool IsSelected(long index);
827
828 void SetColumnImage(int col, int image);
829 void ClearColumnImage(int col);
830 };
831
832
833
834 //---------------------------------------------------------------------------
835
836 %init %{
837 // Map renamed classes back to their common name for OOR
838 wxPyPtrTypeMap_Add("wxListCtrl", "wxPyListCtrl");
839 %}
840
841 //---------------------------------------------------------------------------