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