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