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