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