]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/_listctrl.i
Add a grid sizer demo, and document the props accepted by SetSizerProps.
[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>
d14a1e28 20%}
ab1f7d2a 21
aeee37c3 22MAKE_CONST_WXSTRING(ListCtrlNameStr);
d14a1e28
RD
23
24//---------------------------------------------------------------------------
25%newgroup
26
27enum {
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
54enum {
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,
d0e2ede0 87
c25f90f6 88// GetSubItemRect constants
d0e2ede0 89 wxLIST_GETSUBITEMRECT_WHOLEITEM,
d14a1e28
RD
90};
91
92
93// Flags for GetNextItem (MSW only except wxLIST_NEXT_ALL)
94enum
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)
104enum
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)
113enum 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
122enum
123{
124 wxLIST_AUTOSIZE = -1,
125 wxLIST_AUTOSIZE_USEHEADER = -2 // partly supported by generic version
126};
127
128// Flag values for GetItemRect
129enum
130{
131 wxLIST_RECT_BOUNDS,
132 wxLIST_RECT_ICON,
133 wxLIST_RECT_LABEL
134};
135
136// Flag values for FindItem (MSW only)
137enum
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
151class wxListItemAttr
152{
153public:
154 // ctors
155 //wxListItemAttr();
156 wxListItemAttr(const wxColour& colText = wxNullColour,
157 const wxColour& colBack = wxNullColour,
158 const wxFont& font = wxNullFont);
214c4fbe 159 ~wxListItemAttr();
d14a1e28
RD
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
214c4fbe
RD
175 void AssignFrom(const wxListItemAttr& source);
176
4b5a79cf 177 %pythonPrepend Destroy "args[0].this.own(False)"
d14a1e28 178 %extend { void Destroy() { delete self; } }
76b8fa1d
RD
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`");
d14a1e28
RD
183};
184
185
186
187
188//---------------------------------------------------------------------------
189%newgroup
190
dd9f7fea 191
d14a1e28
RD
192// wxListItem: the item or column info, used to exchange data with wxListCtrl
193class wxListItem : public wxObject {
194public:
3ecece7e 195 // turn off this typemap
c25f90f6
RD
196 %typemap(out) wxListItem*;
197
d14a1e28
RD
198 wxListItem();
199 ~wxListItem();
200
3ecece7e
RD
201 // Turn it back on again
202 %typemap(out) wxListItem* { $result = wxPyMake_wxObject($1, $owner); }
203
d14a1e28
RD
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
76b8fa1d
RD
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`");
d14a1e28
RD
271};
272
273
274//---------------------------------------------------------------------------
275%newgroup
276
277
278// wxListEvent - the event class for the wxListCtrl notifications
279class wxListEvent: public wxNotifyEvent {
280public:
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();
bdcf3ef5 297 %pythoncode { GetPosition = GetPoint }
d14a1e28
RD
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);
76b8fa1d
RD
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`");
c25f90f6 324
d14a1e28
RD
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;
d14a1e28
RD
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
aeee37c3 349// WXWIN_COMPATIBILITY_2_4
2f91e3df 350#if 0
aeee37c3
RD
351%constant wxEventType wxEVT_COMMAND_LIST_GET_INFO;
352%constant wxEventType wxEVT_COMMAND_LIST_SET_INFO;
2f91e3df 353#endif
d14a1e28
RD
354
355%pythoncode {
356
357EVT_LIST_BEGIN_DRAG = wx.PyEventBinder(wxEVT_COMMAND_LIST_BEGIN_DRAG , 1)
358EVT_LIST_BEGIN_RDRAG = wx.PyEventBinder(wxEVT_COMMAND_LIST_BEGIN_RDRAG , 1)
359EVT_LIST_BEGIN_LABEL_EDIT = wx.PyEventBinder(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT , 1)
360EVT_LIST_END_LABEL_EDIT = wx.PyEventBinder(wxEVT_COMMAND_LIST_END_LABEL_EDIT , 1)
361EVT_LIST_DELETE_ITEM = wx.PyEventBinder(wxEVT_COMMAND_LIST_DELETE_ITEM , 1)
362EVT_LIST_DELETE_ALL_ITEMS = wx.PyEventBinder(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS , 1)
2f91e3df
KO
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
d14a1e28
RD
367EVT_LIST_ITEM_SELECTED = wx.PyEventBinder(wxEVT_COMMAND_LIST_ITEM_SELECTED , 1)
368EVT_LIST_ITEM_DESELECTED = wx.PyEventBinder(wxEVT_COMMAND_LIST_ITEM_DESELECTED , 1)
369EVT_LIST_KEY_DOWN = wx.PyEventBinder(wxEVT_COMMAND_LIST_KEY_DOWN , 1)
370EVT_LIST_INSERT_ITEM = wx.PyEventBinder(wxEVT_COMMAND_LIST_INSERT_ITEM , 1)
371EVT_LIST_COL_CLICK = wx.PyEventBinder(wxEVT_COMMAND_LIST_COL_CLICK , 1)
372EVT_LIST_ITEM_RIGHT_CLICK = wx.PyEventBinder(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK , 1)
373EVT_LIST_ITEM_MIDDLE_CLICK = wx.PyEventBinder(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK, 1)
374EVT_LIST_ITEM_ACTIVATED = wx.PyEventBinder(wxEVT_COMMAND_LIST_ITEM_ACTIVATED , 1)
375EVT_LIST_CACHE_HINT = wx.PyEventBinder(wxEVT_COMMAND_LIST_CACHE_HINT , 1)
376EVT_LIST_COL_RIGHT_CLICK = wx.PyEventBinder(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK , 1)
377EVT_LIST_COL_BEGIN_DRAG = wx.PyEventBinder(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG , 1)
378EVT_LIST_COL_DRAGGING = wx.PyEventBinder(wxEVT_COMMAND_LIST_COL_DRAGGING , 1)
379EVT_LIST_COL_END_DRAG = wx.PyEventBinder(wxEVT_COMMAND_LIST_COL_END_DRAG , 1)
380EVT_LIST_ITEM_FOCUSED = wx.PyEventBinder(wxEVT_COMMAND_LIST_ITEM_FOCUSED , 1)
5f24651b 381
2f91e3df
KO
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)
d14a1e28
RD
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;
6e6b3557 395 wxPyBlock_t blocked = wxPyBeginBlockThreads();
d14a1e28
RD
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
da32eb53 405 wxPyEndBlockThreads(blocked);
d14a1e28
RD
406 return retval;
407 }
408%}
409
410
411
412%{ // C++ Version of a Python aware class
413class wxPyListCtrl : public wxListCtrl {
4617be08 414 DECLARE_ABSTRACT_CLASS(wxPyListCtrl)
d14a1e28
RD
415public:
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);
d14a1e28
RD
435 DEC_PYCALLBACK_LISTATTR_LONG(OnGetItemAttr);
436
f5bd42d1
RD
437 // use the virtual version to avoid a confusing assert in the base class
438 DEC_PYCALLBACK_INT_LONG_virtual(OnGetItemImage);
e280c9ca 439 DEC_PYCALLBACK_INT_LONGLONG(OnGetItemColumnImage);
f5bd42d1 440
d14a1e28
RD
441 PYPRIVATE;
442};
443
444IMPLEMENT_ABSTRACT_CLASS(wxPyListCtrl, wxListCtrl);
445
446IMP_PYCALLBACK_STRING_LONGLONG(wxPyListCtrl, wxListCtrl, OnGetItemText);
d14a1e28 447IMP_PYCALLBACK_LISTATTR_LONG(wxPyListCtrl, wxListCtrl, OnGetItemAttr);
f5bd42d1 448IMP_PYCALLBACK_INT_LONG_virtual(wxPyListCtrl, wxListCtrl, OnGetItemImage);
c25f90f6 449IMP_PYCALLBACK_INT_LONGLONG(wxPyListCtrl, wxListCtrl, OnGetItemColumnImage);
e280c9ca 450
d14a1e28
RD
451%}
452
453
454
70d374ac
RD
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)
d14a1e28 458
ab1f7d2a
RD
459MustHaveApp(wxPyListCtrl);
460
1b8c7ba6
RD
461%rename(ListCtrl) wxPyListCtrl;
462class wxPyListCtrl : public wxControl {
d14a1e28 463public:
3ecece7e 464 // turn off this typemap
c25f90f6 465 %typemap(out) wxPyListCtrl*;
d14a1e28 466
c25f90f6 467 %pythonAppend wxPyListCtrl "self._setOORInfo(self);" setCallbackInfo(ListCtrl)
2b9048c5 468 %pythonAppend wxPyListCtrl() ""
f5bd42d1 469
d14a1e28
RD
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);
1b8c7ba6 476 %RenameCtor(PreListCtrl, wxPyListCtrl());
d14a1e28 477
3ecece7e
RD
478 // Turn it back on again
479 %typemap(out) wxPyListCtrl* { $result = wxPyMake_wxObject($1, $owner); }
480
d14a1e28
RD
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
f5bd42d1 490
d14a1e28
RD
491 // Set the control colours
492 bool SetForegroundColour(const wxColour& col);
493 bool SetBackgroundColour(const wxColour& col);
494
495 // Gets information about this column
2b9048c5 496 %pythonAppend GetColumn "if val is not None: val.thisown = 1"; // %newobject doesn't work with OOR typemap
d14a1e28
RD
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;
f5bd42d1 532
d14a1e28
RD
533 // Gets the edit control for editing labels.
534 wxTextCtrl* GetEditControl() const;
d14a1e28
RD
535
536 // Gets information about the item
2b9048c5 537 %pythonAppend GetItem "if val is not None: val.thisown = 1"; // %newobject doesn't work with OOR typemap
d14a1e28
RD
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
1b8c7ba6 553 %Rename(SetStringItem, long, SetItem(long index, int col, const wxString& label, int imageId = -1));
d14a1e28
RD
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
5f24651b 562 bool SetItemImage(long item, int image, int selImage=-1) ;
06db67bc 563 bool SetItemColumnImage( long item, long column, int image );
d14a1e28
RD
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 }
d0e2ede0 594
c25f90f6 595// MSW only so far...
d0e2ede0
RD
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// }
d14a1e28
RD
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;
15648073 615 %pythoncode { GetItemSpacing = wx._deprecated(GetItemSpacing) }
d14a1e28
RD
616
617#ifndef __WXMSW__
a72f4631 618 void SetItemSpacing( int spacing, bool isSmall = false );
15648073 619 %pythoncode { SetItemSpacing = wx._deprecated(SetItemSpacing) }
d14a1e28
RD
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
a72f4631 636 void SetSingleStyle(long style, bool add = true) ;
d14a1e28
RD
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
214c4fbe 653 %disownarg( wxImageList *imageList );
d14a1e28 654 void AssignImageList(wxImageList *imageList, int which);
214c4fbe 655 %cleardisown( wxImageList *imageList );
f5bd42d1 656
6e7db3c8
RD
657 // are we in report mode?
658 bool InReportView() const;
f5bd42d1 659
dd9f7fea 660 // returns True if it is a virtual list control
d14a1e28
RD
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.
a72f4631 700 long FindItem(long start, const wxString& str, bool partial = false);
d14a1e28
RD
701
702 // Find an item whose data matches this data, starting from the item after 'start'
703 // or the beginning if 'start' is -1.
1b8c7ba6 704 %Rename(FindItemData, long, FindItem(long start, long data));
d14a1e28
RD
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.
1b8c7ba6 708 %Rename(FindItemAtPos, long, FindItem(long start, const wxPoint& pt, int direction));
d14a1e28 709
322913ce
RD
710
711 DocDeclAStr(
712 long, HitTest(const wxPoint& point, int& OUTPUT),
713 "HitTest(Point point) -> (item, where)",
d07d2bc9 714 "Determines which item (if any) is at the specified point, giving
7c1f6b54 715details in the second return value (see wx.LIST_HITTEST flags.)", "");
d14a1e28 716
d0e2ede0
RD
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
721the second return value (see wx.LIST_HITTEST flags) and also the subItem, if
722any.", "",
723 HitTestSubItem);
724
c25f90f6 725
d14a1e28
RD
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
4617be08
RD
731 %Rename(InsertStringItem,
732 long, InsertItem(long index, const wxString& label, int imageIndex=-1));
d14a1e28
RD
733
734 // Insert an image item
4617be08
RD
735 %Rename(InsertImageItem,
736 long, InsertItem(long index, int imageIndex));
d14a1e28
RD
737
738 // Insert an image/string item
4617be08
RD
739 %Rename(InsertImageStringItem,
740 long, InsertItem(long index, const wxString& label, int imageIndex));
d14a1e28
RD
741
742 // For list view mode (only), inserts a column.
54ab2b20
RD
743 %Rename(InsertColumnItem, long, InsertColumn(long col, wxListItem& info));
744 %pythoncode { InsertColumnInfo = InsertColumnItem }
d14a1e28
RD
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
02b800ce
RD
766 // Font of an item.
767 void SetItemFont( long item, const wxFont &f);
768 wxFont GetItemFont( long item ) const;
d14a1e28
RD
769
770 %pythoncode {
771 %#
772 %# Some helpers...
773 def Select(self, idx, on=1):
774 '''[de]select an item'''
dd9f7fea 775 if on: state = wx.LIST_STATE_SELECTED
d14a1e28 776 else: state = 0
dd9f7fea 777 self.SetItemState(idx, state, wx.LIST_STATE_SELECTED)
d14a1e28
RD
778
779 def Focus(self, idx):
780 '''Focus and show the given item'''
dd9f7fea 781 self.SetItemState(idx, wx.LIST_STATE_FOCUSED, wx.LIST_STATE_FOCUSED)
d14a1e28
RD
782 self.EnsureVisible(idx)
783
784 def GetFocusedItem(self):
785 '''get the currently focused item or -1 if none'''
dd9f7fea 786 return self.GetNextItem(-1, wx.LIST_NEXT_ALL, wx.LIST_STATE_FOCUSED)
d14a1e28
RD
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'''
dd9f7fea 794 return self.GetNextItem(item, wx.LIST_NEXT_ALL, wx.LIST_STATE_SELECTED)
d14a1e28
RD
795
796 def IsSelected(self, idx):
dd9f7fea 797 '''return True if the item is selected'''
08e2c570 798 return (self.GetItemState(idx, wx.LIST_STATE_SELECTED) & wx.LIST_STATE_SELECTED) != 0
d14a1e28
RD
799
800 def SetColumnImage(self, col, image):
801 item = self.GetColumn(col)
dd9f7fea
RD
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 )
d14a1e28
RD
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):
dd9f7fea 820 if wx.USE_UNICODE:
d14a1e28
RD
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))
a72f4631 843 return false;
d14a1e28
RD
844 return self->SortItems((wxListCtrlCompare)wxPyListCtrl_SortItems, (long)func);
845 }
846 }
847
848
849 %extend {
850 wxWindow* GetMainWindow() {
6a223074 851 #if defined(__WXMSW__) || defined(__WXMAC__)
d14a1e28
RD
852 return self;
853 #else
854 return (wxWindow*)self->m_mainWin;
855 #endif
856 }
857 }
174051f6
RD
858
859 static wxVisualAttributes
860 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
76b8fa1d
RD
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`");
d14a1e28
RD
873};
874
875
876
877//---------------------------------------------------------------------------
878%newgroup
879
880
ab1f7d2a
RD
881MustHaveApp(wxListView);
882
d14a1e28
RD
883// wxListView: a class which provides a little better API for list control
884class wxListView : public wxPyListCtrl
885{
886public:
2b9048c5
RD
887 %pythonAppend wxListView "self._setOORInfo(self)"
888 %pythonAppend wxListView() ""
d14a1e28
RD
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);
1b8c7ba6 897 %RenameCtor(PreListView, wxListView());
d14a1e28
RD
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
a72f4631 908 void Select(long n, bool on = true);
d14a1e28
RD
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
dd9f7fea 920 // return True if the item is selected
d14a1e28
RD
921 bool IsSelected(long index);
922
923 void SetColumnImage(int col, int image);
924 void ClearColumnImage(int col);
76b8fa1d
RD
925
926 %property(FocusedItem, GetFocusedItem, doc="See `GetFocusedItem`");
d14a1e28
RD
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//---------------------------------------------------------------------------