1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxListCtrl
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
12 A list control presents lists in a number of formats: list view, report view,
13 icon view and small icon view. In any case, elements are numbered from zero.
14 For all these modes, the items are stored in the control and must be added to
15 it using wxListCtrl::InsertItem method.
17 A special case of report view quite different from the other modes of the list
18 control is a virtual control in which the items data (including text, images
19 and attributes) is managed by the main program and is requested by the control
20 itself only when needed which allows to have controls with millions of items
21 without consuming much memory. To use virtual list control you must use
22 wxListCtrl::SetItemCount first and overload at least wxListCtrl::OnGetItemText
23 (and optionally wxListCtrl::OnGetItemImage or wxListCtrl::OnGetItemColumnImage and
24 wxListCtrl::OnGetItemAttr) to return the information about the items when the
27 Virtual list control can be used as a normal one except that no operations
28 which can take time proportional to the number of items in the control happen
29 -- this is required to allow having a practically infinite number of items.
30 For example, in a multiple selection virtual list control, the selections won't
31 be sent when many items are selected at once because this could mean iterating
34 Using many of wxListCtrl features is shown in the
35 @ref page_samples_listctrl "corresponding sample".
37 To intercept events from a list control, use the event table macros described
40 <b>wxMac Note</b>: Starting with wxWidgets 2.8, wxListCtrl uses a native
41 implementation for report mode, and uses a generic implementation for other
42 modes. You can use the generic implementation for report mode as well by setting
43 the @c mac.listctrl.always_use_generic system option (see wxSystemOptions) to 1.
48 Multicolumn list view, with optional small icons. Columns are
49 computed automatically, i.e. you don't set columns as in
50 @c wxLC_REPORT. In other words, the list wraps, unlike a wxListBox.
52 Single or multicolumn report view, with optional header.
54 The application provides items text on demand. May only be used
57 Large icon view, with optional labels.
58 @style{wxLC_SMALL_ICON}
59 Small icon view, with optional labels.
60 @style{wxLC_ALIGN_TOP}
61 Icons align to the top. Win32 default, Win32 only.
62 @style{wxLC_ALIGN_LEFT}
63 Icons align to the left.
64 @style{wxLC_AUTOARRANGE}
65 Icons arrange themselves. Win32 only.
66 @style{wxLC_EDIT_LABELS}
67 Labels are editable: the application will be notified when editing
69 @style{wxLC_NO_HEADER}
70 No header in report mode.
71 @style{wxLC_SINGLE_SEL}
72 Single selection (default is multiple).
73 @style{wxLC_SORT_ASCENDING}
74 Sort in ascending order. (You must still supply a comparison callback
75 in wxListCtrl::SortItems.)
76 @style{wxLC_SORT_DESCENDING}
77 Sort in descending order. (You must still supply a comparison callback
78 in wxListCtrl::SortItems.)
80 Draws light horizontal rules between rows in report mode.
82 Draws light vertical rules between columns in report mode.
86 @beginEventEmissionTable{wxListEvent}
87 @event{EVT_LIST_BEGIN_DRAG(id, func)}
88 Begin dragging with the left mouse button.
89 @event{EVT_LIST_BEGIN_RDRAG(id, func)}
90 Begin dragging with the right mouse button..
91 @event{EVT_BEGIN_LABEL_EDIT(id, func)}
92 Begin editing a label. This can be prevented by calling Veto().
93 @event{EVT_LIST_END_LABEL_EDIT(id, func)}
94 Finish editing a label. This can be prevented by calling Veto().
95 @event{EVT_LIST_DELETE_ITEM(id, func)}
97 @event{EVT_LIST_DELETE_ALL_ITEMS(id, func)}
98 All items were deleted.
99 @event{EVT_LIST_ITEM_SELECTED(id, func)}
100 The item has been selected.
101 @event{EVT_LIST_ITEM_DESELECTED(id, func)}
102 The item has been deselected.
103 @event{EVT_LIST_ITEM_ACTIVATED(id, func)}
104 The item has been activated (ENTER or double click).
105 @event{EVT_LIST_ITEM_FOCUSED(id, func)}
106 The currently focused item has changed.
107 @event{EVT_LIST_ITEM_MIDDLE_CLICK(id, func)}
108 The middle mouse button has been clicked on an item.
109 @event{EVT_LIST_ITEM_RIGHT_CLICK(id, func)}
110 The right mouse button has been clicked on an item.
111 @event{EVT_LIST_KEY_DOWN(id, func)}
112 A key has been pressed.
113 @event{EVT_LIST_INSERT_ITEM(id, func)}
114 An item has been inserted.
115 @event{EVT_LIST_COL_CLICK(id, func)}
116 A column (m_col) has been left-clicked.
117 @event{EVT_LIST_COL_RIGHT_CLICK(id, func)}
118 A column (m_col) has been right-clicked.
119 @event{EVT_LIST_COL_BEGIN_DRAG(id, func)}
120 The user started resizing a column - can be vetoed.
121 @event{EVT_LIST_COL_DRAGGING(id, func)}
122 The divider between columns is being dragged.
123 @event{EVT_LIST_COL_END_DRAG(id, func)}
124 A column has been resized by the user.
125 @event{EVT_LIST_CACHE_HINT(id, func)}
126 Prepare cache for a virtual list control.
132 @appearance{listctrl.png}
134 @see @ref overview_listctrl, wxListView, wxListBox, wxTreeCtrl, wxImageList,
135 wxListEvent, wxListItem, wxEditableListBox
137 class wxListCtrl
: public wxControl
146 Constructor, creating and showing a list control.
149 Parent window. Must not be @NULL.
151 Window identifier. The value wxID_ANY indicates a default value.
154 If ::wxDefaultPosition is specified then a default position is chosen.
157 If ::wxDefaultSize is specified then the window is sized appropriately.
159 Window style. See wxListCtrl.
165 @see Create(), wxValidator
167 wxListCtrl(wxWindow
* parent
, wxWindowID id
,
168 const wxPoint
& pos
= wxDefaultPosition
,
169 const wxSize
& size
= wxDefaultSize
,
170 long style
= wxLC_ICON
,
171 const wxValidator
& validator
= wxDefaultValidator
,
172 const wxString
& name
= wxListCtrlNameStr
);
175 Destructor, destroying the list control.
177 virtual ~wxListCtrl();
180 Arranges the items in icon or small icon view.
181 This only has effect on Win32. @a flag is one of:
182 - wxLIST_ALIGN_DEFAULT: Default alignment.
183 - wxLIST_ALIGN_LEFT: Align to the left side of the control.
184 - wxLIST_ALIGN_TOP: Align to the top side of the control.
185 - wxLIST_ALIGN_SNAP_TO_GRID: Snap to grid.
187 bool Arrange(int flag
= wxLIST_ALIGN_DEFAULT
);
190 Sets the image list associated with the control and takes ownership of it
191 (i.e. the control will, unlike when using SetImageList(), delete the list
192 when destroyed). @a which is one of @c wxIMAGE_LIST_NORMAL, @c wxIMAGE_LIST_SMALL,
193 @c wxIMAGE_LIST_STATE (the last is unimplemented).
197 void AssignImageList(wxImageList
* imageList
, int which
);
200 Deletes all items and all columns.
205 Creates the list control. See wxListCtrl() for further details.
207 bool Create(wxWindow
* parent
, wxWindowID id
,
208 const wxPoint
& pos
= wxDefaultPosition
,
209 const wxSize
& size
= wxDefaultSize
,
210 long style
= wxLC_ICON
,
211 const wxValidator
& validator
= wxDefaultValidator
,
212 const wxString
& name
= wxListCtrlNameStr
);
215 Deletes all items in the list control.
217 @note This function does @e not send the @c wxEVT_COMMAND_LIST_DELETE_ITEM
218 event because deleting many items from the control would be too slow
219 then (unlike wxListCtrl::DeleteItem).
221 bool DeleteAllItems();
226 bool DeleteColumn(int col
);
229 Deletes the specified item.
230 This function sends the @c wxEVT_COMMAND_LIST_DELETE_ITEM event for the
233 @see DeleteAllItems()
235 bool DeleteItem(long item
);
238 Starts editing the label of the given item.
240 This function generates a @c EVT_LIST_BEGIN_LABEL_EDIT event which can be
241 vetoed so that no text control will appear for in-place editing.
243 If the user changed the label (i.e. s/he does not press ESC or leave
244 the text control without changes, a @c EVT_LIST_END_LABEL_EDIT event
245 will be sent which can be vetoed as well.
247 wxTextCtrl
* EditLabel(long item
,
248 wxClassInfo
* textControlClass
= CLASSINFO(wxTextCtrl
));
251 Ensures this item is visible.
253 bool EnsureVisible(long item
);
256 Find an item whose label matches this string, starting from start or the
257 beginning if start is @c -1. The string comparison is case insensitive.
259 If @a partial is @true then this method will look for items which begin with @a str.
261 long FindItem(long start
, const wxString
& str
,
262 bool partial
= false);
265 Find an item whose data matches this data, starting from start or the
266 beginning if 'start' is @c -1.
268 long FindItem(long start
, wxUIntPtr data
);
271 Find an item nearest this position in the specified direction,
272 starting from @a start or the beginning if @a start is -1.
274 long FindItem(long start
, const wxPoint
& pt
, int direction
);
277 Gets information about this column.
278 See SetItem() for more information.
280 bool GetColumn(int col
, wxListItem
& item
) const;
283 Returns the number of columns.
285 int GetColumnCount() const;
288 Gets the column index from its position in visual order.
290 After calling SetColumnsOrder(), the index returned by this function
291 corresponds to the value of the element number @a pos in the array
292 returned by GetColumnsOrder().
294 Please see SetColumnsOrder() documentation for an example and
295 additional remarks about the columns ordering.
297 @see GetColumnOrder()
299 int GetColumnIndexFromOrder(int pos
) const;
302 Gets the column visual order position.
304 This function returns the index of the column which appears at the
305 given visual position, e.g. calling it with @a col equal to 0 returns
306 the index of the first shown column.
308 Please see SetColumnsOrder() documentation for an example and
309 additional remarks about the columns ordering.
311 @see GetColumnsOrder(), GetColumnIndexFromOrder()
313 int GetColumnOrder(int col
) const;
316 Gets the column width (report view only).
318 int GetColumnWidth(int col
) const;
321 Returns the array containing the orders of all columns.
323 On error, an empty array is returned.
325 Please see SetColumnsOrder() documentation for an example and
326 additional remarks about the columns ordering.
328 @see GetColumnOrder(), GetColumnIndexFromOrder()
330 wxArrayInt
GetColumnsOrder() const;
333 Gets the number of items that can fit vertically in the visible area of
334 the list control (list or report view) or the total number of items in
335 the list control (icon or small icon view).
337 int GetCountPerPage() const;
340 Returns the edit control being currently used to edit a label.
341 Returns @NULL if no label is being edited.
343 @note It is currently only implemented for wxMSW and the generic version,
344 not for the native Mac OS X version.
346 wxTextCtrl
* GetEditControl() const;
349 Returns the specified image list. @a which may be one of:
350 - wxIMAGE_LIST_NORMAL: The normal (large icon) image list.
351 - wxIMAGE_LIST_SMALL: The small icon image list.
352 - wxIMAGE_LIST_STATE: The user-defined state image list (unimplemented).
354 wxImageList
* GetImageList(int which
) const;
357 Gets information about the item. See SetItem() for more information.
359 You must call @e info.SetId() to set the ID of item you're interested in
360 before calling this method, and @e info.SetMask() with the flags indicating
361 what fields you need to retrieve from @a info.
363 bool GetItem(wxListItem
& info
) const;
366 Returns the colour for this item.
367 If the item has no specific colour, returns an invalid colour
368 (and not the default background control of the control itself).
370 @see GetItemTextColour()
372 wxColour
GetItemBackgroundColour(long item
) const;
375 Returns the number of items in the list control.
377 int GetItemCount() const;
380 Gets the application-defined data associated with this item.
382 wxUIntPtr
GetItemData(long item
) const;
385 Returns the item's font.
387 wxFont
GetItemFont(long item
) const;
390 Returns the position of the item, in icon or small icon view.
392 bool GetItemPosition(long item
, wxPoint
& pos
) const;
395 Returns the rectangle representing the item's size and position, in physical
398 @a code is one of wxLIST_RECT_BOUNDS, wxLIST_RECT_ICON, wxLIST_RECT_LABEL.
400 bool GetItemRect(long item
, wxRect
& rect
,
401 int code
= wxLIST_RECT_BOUNDS
) const;
404 Retrieves the spacing between icons in pixels: horizontal spacing is
405 returned as @c x component of the wxSize object and the vertical spacing
406 as its @c y component.
408 wxSize
GetItemSpacing() const;
411 Gets the item state. For a list of state flags, see SetItem().
412 The @a stateMask indicates which state flags are of interest.
414 int GetItemState(long item
, long stateMask
) const;
417 Gets the item text for this item.
419 wxString
GetItemText(long item
) const;
422 Returns the colour for this item.
424 If the item has no specific colour, returns an invalid colour (and not the
425 default foreground control of the control itself as this wouldn't allow
426 distinguishing between items having the same colour as the current control
427 foreground and items with default colour which, hence, have always the
428 same colour as the control).
430 wxColour
GetItemTextColour(long item
) const;
433 Searches for an item with the given geometry or state, starting from
434 @a item but excluding the @a item itself.
436 If @a item is -1, the first item that matches the specified flags will be returned.
437 Returns the first item with given state following @a item or -1 if no such item found.
438 This function may be used to find all selected items in the control like this:
444 item = listctrl->GetNextItem(item,
446 wxLIST_STATE_SELECTED);
450 // this item is selected - do whatever is needed with it
451 wxLogMessage("Item %ld is selected.", item);
455 @a geometry can be one of:
456 - wxLIST_NEXT_ABOVE: Searches for an item above the specified item.
457 - wxLIST_NEXT_ALL: Searches for subsequent item by index.
458 - wxLIST_NEXT_BELOW: Searches for an item below the specified item.
459 - wxLIST_NEXT_LEFT: Searches for an item to the left of the specified item.
460 - wxLIST_NEXT_RIGHT: Searches for an item to the right of the specified item.
462 @note this parameter is only supported by wxMSW currently and ignored on
465 @a state can be a bitlist of the following:
466 - wxLIST_STATE_DONTCARE: Don't care what the state is.
467 - wxLIST_STATE_DROPHILITED: The item indicates it is a drop target.
468 - wxLIST_STATE_FOCUSED: The item has the focus.
469 - wxLIST_STATE_SELECTED: The item is selected.
470 - wxLIST_STATE_CUT: The item is selected as part of a cut and paste operation.
472 long GetNextItem(long item
, int geometry
= wxLIST_NEXT_ALL
,
473 int state
= wxLIST_STATE_DONTCARE
) const;
476 Returns the number of selected items in the list control.
478 int GetSelectedItemCount() const;
481 Returns the rectangle representing the size and position, in physical
482 coordinates, of the given subitem, i.e. the part of the row @a item in the
485 This method is only meaningfull when the wxListCtrl is in the report mode.
486 If @a subItem parameter is equal to the special value
487 @c wxLIST_GETSUBITEMRECT_WHOLEITEM the return value is the same as
490 @a code can be one of @c wxLIST_RECT_BOUNDS, @c wxLIST_RECT_ICON or
491 @c wxLIST_RECT_LABEL.
495 bool GetSubItemRect(long item
, long subItem
, wxRect
& rect
,
496 int code
= wxLIST_RECT_BOUNDS
) const;
499 Gets the text colour of the list control.
501 wxColour
GetTextColour() const;
504 Gets the index of the topmost visible item when in list or report view.
506 long GetTopItem() const;
509 Returns the rectangle taken by all items in the control. In other words, if the
510 controls client size were equal to the size of this rectangle, no scrollbars
511 would be needed and no free space would be left.
513 Note that this function only works in the icon and small icon views, not in
514 list or report views (this is a limitation of the native Win32 control).
516 wxRect
GetViewRect() const;
519 Determines which item (if any) is at the specified point, giving details
520 in @a flags. Returns index of the item or @c wxNOT_FOUND if no item is at
523 @a flags will be a combination of the following flags:
524 - wxLIST_HITTEST_ABOVE: Above the client area.
525 - wxLIST_HITTEST_BELOW: Below the client area.
526 - wxLIST_HITTEST_NOWHERE: In the client area but below the last item.
527 - wxLIST_HITTEST_ONITEMICON: On the bitmap associated with an item.
528 - wxLIST_HITTEST_ONITEMLABEL: On the label (string) associated with an item.
529 - wxLIST_HITTEST_ONITEMRIGHT: In the area to the right of an item.
530 - wxLIST_HITTEST_ONITEMSTATEICON: On the state icon for a tree view item
531 that is in a user-defined state.
532 - wxLIST_HITTEST_TOLEFT: To the right of the client area.
533 - wxLIST_HITTEST_TORIGHT: To the left of the client area.
534 - wxLIST_HITTEST_ONITEM: Combination of @c wxLIST_HITTEST_ONITEMICON,
535 @c wxLIST_HITTEST_ONITEMLABEL, @c wxLIST_HITTEST_ONITEMSTATEICON.
537 If @a ptrSubItem is not @NULL and the wxListCtrl is in the report
538 mode the subitem (or column) number will also be provided.
539 This feature is only available in version 2.7.0 or higher and is currently only
540 implemented under wxMSW and requires at least comctl32.dll of verion 4.70 on
541 the host system or the value stored in @a ptrSubItem will be always -1.
542 To compile this feature into wxWidgets library you need to have access to
543 commctrl.h of version 4.70 that is provided by Microsoft.
545 long HitTest(const wxPoint
& point
, int& flags
, long* ptrSubItem
= NULL
) const;
548 For report view mode (only), inserts a column. For more details, see SetItem().
550 long InsertColumn(long col
, wxListItem
& info
);
553 For report view mode (only), inserts a column. For more details, see SetItem().
555 long InsertColumn(long col
, const wxString
& heading
,
556 int format
= wxLIST_FORMAT_LEFT
,
560 Inserts an item, returning the index of the new item if successful, -1 otherwise.
565 long InsertItem(wxListItem
& info
);
568 Insert an string item.
571 Index of the new item, supplied by the application
575 long InsertItem(long index
, const wxString
& label
);
578 Insert an image item.
581 Index of the new item, supplied by the application
583 Index into the image list associated with this control and view style
585 long InsertItem(long index
, int imageIndex
);
588 Insert an image/string item.
591 Index of the new item, supplied by the application
595 Index into the image list associated with this control and view style
597 long InsertItem(long index
, const wxString
& label
,
601 Redraws the given @e item.
603 This is only useful for the virtual list controls as without calling this
604 function the displayed value of the item doesn't change even when the
605 underlying data does change.
609 void RefreshItem(long item
);
612 Redraws the items between @a itemFrom and @e itemTo.
613 The starting item must be less than or equal to the ending one.
615 Just as RefreshItem() this is only useful for virtual list controls.
617 void RefreshItems(long itemFrom
, long itemTo
);
620 Scrolls the list control. If in icon, small icon or report view mode,
621 @a dx specifies the number of pixels to scroll. If in list view mode,
622 @a dx specifies the number of columns to scroll. @a dy always specifies
623 the number of pixels to scroll vertically.
625 @note This method is currently only implemented in the Windows version.
627 bool ScrollList(int dx
, int dy
);
630 Sets the background colour.
632 Note that the wxWindow::GetBackgroundColour() function of wxWindow base
633 class can be used to retrieve the current background colour.
635 virtual bool SetBackgroundColour(const wxColour
& col
);
638 Sets information about this column.
639 See SetItem() for more information.
641 bool SetColumn(int col
, wxListItem
& item
);
644 Sets the column width.
646 @a width can be a width in pixels or @c wxLIST_AUTOSIZE (-1) or
647 @c wxLIST_AUTOSIZE_USEHEADER (-2).
649 @c wxLIST_AUTOSIZE will resize the column to the length of its longest item.
651 @c wxLIST_AUTOSIZE_USEHEADER will resize the column to the length of the
652 header (Win32) or 80 pixels (other platforms).
654 In small or normal icon view, @a col must be -1, and the column width is set
657 bool SetColumnWidth(int col
, int width
);
660 Changes the order in which the columns are shown.
662 By default, the columns of a list control appear on the screen in order
663 of their indices, i.e. the column 0 appears first, the column 1 next
664 and so on. However by using this function it is possible to arbitrarily
665 reorder the columns visual order and the user can also rearrange the
666 columns interactively by dragging them. In this case, the index of the
667 column is not the same as its order and the functions GetColumnOrder()
668 and GetColumnIndexFromOrder() should be used to translate between them.
669 Notice that all the other functions still work with the column indices,
670 i.e. the visual positioning of the columns on screen doesn't affect the
671 code setting or getting their values for example.
673 The @a orders array must have the same number elements as the number of
674 columns and contain each position exactly once. Its n-th element
675 contains the index of the column to be shown in n-th position, so for a
676 control with three columns passing an array with elements 2, 0 and 1
677 results in the third column being displayed first, the first one next
678 and the second one last.
682 wxListCtrl *list = new wxListCtrl(...);
683 for ( int i = 0; i < 3; i++ )
684 list->InsertColumn(i, wxString::Format("Column %d", i));
690 list->SetColumnsOrder(order);
692 // now list->GetColumnsOrder() will return order and
693 // list->GetColumnIndexFromOrder(n) will return order[n] and
694 // list->GetColumnOrder() will return 1, 2 and 0 for the column 0,
695 // 1 and 2 respectively
698 Please notice that this function makes sense for report view only and
699 currently is only implemented in wxMSW port. To avoid explicit tests
700 for @c __WXMSW__ in your code, please use @c wxHAS_LISTCTRL_COLUMN_ORDER
701 as this will allow it to start working under the other platforms when
702 support for the column reordering is added there.
704 @see GetColumnsOrder()
706 bool SetColumnsOrder(const wxArrayInt
& orders
) const;
709 Sets the image list associated with the control.
711 @a which is one of @c wxIMAGE_LIST_NORMAL, @c wxIMAGE_LIST_SMALL,
712 @c wxIMAGE_LIST_STATE (the last is unimplemented).
714 This method does not take ownership of the image list, you have to
717 @see AssignImageList()
719 void SetImageList(wxImageList
* imageList
, int which
);
722 Sets the data of an item.
724 Using the wxListItem's mask and state mask, you can change only selected
725 attributes of a wxListCtrl item.
727 bool SetItem(wxListItem
& info
);
730 Sets an item string field at a particular column.
732 long SetItem(long index
, int column
, const wxString
& label
, int imageId
= -1);
735 Sets the background colour for this item.
736 This function only works in report view mode.
737 The colour can be retrieved using GetItemBackgroundColour().
739 void SetItemBackgroundColour(long item
, const wxColour
& col
);
742 Sets the image associated with the item.
743 In report view, you can specify the column.
744 The image is an index into the image list associated with the list control.
746 bool SetItemColumnImage(long item
, long column
, int image
);
749 This method can only be used with virtual list controls.
751 It is used to indicate to the control the number of items it contains.
752 After calling it, the main program should be ready to handle calls to
753 various item callbacks (such as wxListCtrl::OnGetItemText) for all
754 items in the range from 0 to @a count.
756 Notice that the control is not necessarily redrawn after this call as
757 it may be undesirable if an item which is not visible on the screen
758 anyhow was added to or removed from a control displaying many items, if
759 you do need to refresh the display you can just call Refresh() manually.
761 void SetItemCount(long count
);
764 Associates application-defined data with this item.
766 Notice that this function cannot be used to associate pointers with the control
767 items, use SetItemPtrData() instead.
769 bool SetItemData(long item
, long data
);
772 Sets the item's font.
774 void SetItemFont(long item
, const wxFont
& font
);
777 Sets the unselected and selected images associated with the item.
778 The images are indices into the image list associated with the list control.
780 bool SetItemImage(long item
, int image
, int selImage
= -1);
783 Sets the unselected and selected images associated with the item.
784 The images are indices into the image list associated with the list control.
787 This form is deprecated: @a selImage is not used; use the other
788 SetItemImage() overload.
790 bool SetItemImage(long item
, int image
, int selImage
= -1);
793 Sets the position of the item, in icon or small icon view. Windows only.
795 bool SetItemPosition(long item
, const wxPoint
& pos
);
798 Associates application-defined data with this item.
800 The @a data parameter may be either an integer or a pointer cast to the
801 @c wxUIntPtr type which is guaranteed to be large enough to be able to
802 contain all integer types and pointers.
806 bool SetItemPtrData(long item
, wxUIntPtr data
);
809 Sets the item state. For a list of state flags, see SetItem().
810 The @b stateMask indicates which state flags are valid.
812 bool SetItemState(long item
, long state
, long stateMask
);
815 Sets the item text for this item.
817 void SetItemText(long item
, const wxString
& text
);
820 Sets the colour for this item.
821 This function only works in report view.
822 The colour can be retrieved using GetItemTextColour().
824 void SetItemTextColour(long item
, const wxColour
& col
);
827 Adds or removes a single window style.
829 void SetSingleStyle(long style
, bool add
= true);
832 Sets the text colour of the list control.
834 void SetTextColour(const wxColour
& col
);
837 Sets the whole window style, deleting all items.
839 void SetWindowStyleFlag(long style
);
842 Call this function to sort the items in the list control. Sorting is done
843 using the specified @a fnSortCallBack function. This function must have the
846 int wxCALLBACK wxListCompareFunction(long item1, long item2, wxIntPtr sortData)
849 It is called each time when the two items must be compared and should return 0
850 if the items are equal, negative value if the first item is less than the
851 second one and positive value if the first one is greater than the second one
852 (the same convention as used by @c qsort(3)).
854 The parameter @e item1 is the client data associated with the first item (NOT the index).
855 The parameter @e item2 is the client data associated with the second item (NOT the index).
856 The parameter @e data is the value passed to SortItems() itself.
858 Notice that the control may only be sorted on client data associated with
859 the items, so you must use SetItemData if you want to be able to sort the
860 items in the control.
862 Please see the @ref page_samples_listctrl for an example of using this function.
864 bool SortItems(wxListCtrlCompare fnSortCallBack
, wxIntPtr data
);
869 This function may be overloaded in the derived class for a control with
870 @c wxLC_VIRTUAL style. It should return the attribute for the specified
871 @c item or @NULL to use the default appearance parameters.
873 wxListCtrl will not delete the pointer or keep a reference of it.
874 You can return the same wxListItemAttr pointer for every OnGetItemAttr() call.
876 The base class version always returns @NULL.
878 @see OnGetItemImage(), OnGetItemColumnImage(), OnGetItemText(),
879 OnGetItemColumnAttr()
881 virtual wxListItemAttr
* OnGetItemAttr(long item
) const;
884 This function may be overridden in the derived class for a control with
885 @c wxLC_VIRTUAL style.
887 It should return the attribute for the for the specified @a item and @a
888 column or @NULL to use the default appearance parameters.
890 The base class version returns @c OnGetItemAttr(item).
892 @note Currently this function is only called under wxMSW, the other
893 ports only support OnGetItemAttr()
895 @see OnGetItemAttr(), OnGetItemText(),
896 OnGetItemImage(), OnGetItemColumnImage(),
898 virtual wxListItemAttr
* OnGetItemColumnAttr(long item
, long column
) const;
901 Overload this function in the derived class for a control with
902 @c wxLC_VIRTUAL and @c wxLC_REPORT styles in order to specify the image
903 index for the given line and column.
905 The base class version always calls OnGetItemImage() for the first column, else
908 @see OnGetItemText(), OnGetItemImage(), OnGetItemAttr(),
909 OnGetItemColumnAttr()
911 virtual int OnGetItemColumnImage(long item
, long column
) const;
914 This function must be overloaded in the derived class for a control with
915 @c wxLC_VIRTUAL style having an "image list" (see SetImageList(); if the
916 control doesn't have an image list, it is not necessary to overload it).
917 It should return the index of the items image in the controls image list
920 In a control with @c wxLC_REPORT style, OnGetItemImage() only gets called for
921 the first column of each line.
923 The base class version always returns -1.
925 @see OnGetItemText(), OnGetItemColumnImage(), OnGetItemAttr()
927 virtual int OnGetItemImage(long item
) const;
930 This function @b must be overloaded in the derived class for a control with
931 @c wxLC_VIRTUAL style. It should return the string containing the text of
932 the given @a column for the specified @c item.
934 @see SetItemCount(), OnGetItemImage(), OnGetItemColumnImage(), OnGetItemAttr()
936 virtual wxString
OnGetItemText(long item
, long column
) const;
944 A list event holds information about events associated with wxListCtrl objects.
946 @beginEventTable{wxListEvent}
947 @event{EVT_LIST_BEGIN_DRAG(id, func)}
948 Begin dragging with the left mouse button.
949 @event{EVT_LIST_BEGIN_RDRAG(id, func)}
950 Begin dragging with the right mouse button.
951 @event{EVT_LIST_BEGIN_LABEL_EDIT(id, func)}
952 Begin editing a label. This can be prevented by calling Veto().
953 @event{EVT_LIST_END_LABEL_EDIT(id, func)}
954 Finish editing a label. This can be prevented by calling Veto().
955 @event{EVT_LIST_DELETE_ITEM(id, func)}
957 @event{EVT_LIST_DELETE_ALL_ITEMS(id, func)}
959 @event{EVT_LIST_ITEM_SELECTED(id, func)}
960 The item has been selected.
961 @event{EVT_LIST_ITEM_DESELECTED(id, func)}
962 The item has been deselected.
963 @event{EVT_LIST_ITEM_ACTIVATED(id, func)}
964 The item has been activated (ENTER or double click).
965 @event{EVT_LIST_ITEM_FOCUSED(id, func)}
966 The currently focused item has changed.
967 @event{EVT_LIST_ITEM_MIDDLE_CLICK(id, func)}
968 The middle mouse button has been clicked on an item.
969 @event{EVT_LIST_ITEM_RIGHT_CLICK(id, func)}
970 The right mouse button has been clicked on an item.
971 @event{EVT_LIST_KEY_DOWN(id, func)}
972 A key has been pressed.
973 @event{EVT_LIST_INSERT_ITEM(id, func)}
974 An item has been inserted.
975 @event{EVT_LIST_COL_CLICK(id, func)}
976 A column (m_col) has been left-clicked.
977 @event{EVT_LIST_COL_RIGHT_CLICK(id, func)}
978 A column (m_col) (which can be -1 if the click occurred outside any column)
979 has been right-clicked.
980 @event{EVT_LIST_COL_BEGIN_DRAG(id, func)}
981 The user started resizing a column - can be vetoed.
982 @event{EVT_LIST_COL_DRAGGING(id, func)}
983 The divider between columns is being dragged.
984 @event{EVT_LIST_COL_END_DRAG(id, func)}
985 A column has been resized by the user.
986 @event{EVT_LIST_CACHE_HINT(id, func)}
987 Prepare cache for a virtual list control
996 class wxListEvent
: public wxNotifyEvent
1002 wxListEvent(wxEventType commandType
= wxEVT_NULL
, int id
= 0);
1005 For @c EVT_LIST_CACHE_HINT event only: return the first item which the
1006 list control advises us to cache.
1008 long GetCacheFrom() const;
1011 For @c EVT_LIST_CACHE_HINT event only: return the last item (inclusive)
1012 which the list control advises us to cache.
1014 long GetCacheTo() const;
1017 The column position: it is only used with @c COL events.
1019 For the column dragging events, it is the column to the left of the divider
1020 being dragged, for the column click events it may be -1 if the user clicked
1021 in the list control header outside any column.
1023 int GetColumn() const;
1028 long GetData() const;
1033 int GetImage() const;
1038 long GetIndex() const;
1041 An item object, used by some events. See also wxListCtrl::SetItem.
1043 const wxListItem
& GetItem() const;
1046 Key code if the event is a keypress event.
1048 int GetKeyCode() const;
1051 The (new) item label for @c EVT_LIST_END_LABEL_EDIT event.
1053 const wxString
& GetLabel() const;
1058 long GetMask() const;
1061 The position of the mouse pointer if the event is a drag event.
1063 wxPoint
GetPoint() const;
1068 const wxString
& GetText() const;
1071 This method only makes sense for @c EVT_LIST_END_LABEL_EDIT message and
1072 returns @true if it the label editing has been cancelled by the user
1073 (GetLabel() returns an empty string in this case but it doesn't allow the
1074 application to distinguish between really cancelling the edit and the
1075 admittedly rare case when the user wants to rename it to an empty string).
1077 bool IsEditCancelled() const;
1083 @class wxListItemAttr
1085 Represents the attributes (color, font, ...) of a wxListCtrl's wxListItem.
1090 @see @ref overview_listctrl, wxListCtrl, wxListItem
1092 class wxListItemAttr
1096 Default Constructor.
1101 Construct a wxListItemAttr with the specified foreground and
1102 background colors and font.
1104 wxListItemAttr(const wxColour
& colText
,
1105 const wxColour
& colBack
,
1106 const wxFont
& font
);
1109 Returns the currently set background color.
1111 const wxColour
& GetBackgroundColour() const;
1114 Returns the currently set font.
1116 const wxFont
& GetFont() const;
1119 Returns the currently set text color.
1121 const wxColour
& GetTextColour() const;
1124 Returns @true if the currently set background color is valid.
1126 bool HasBackgroundColour() const;
1129 Returns @true if the currently set font is valid.
1131 bool HasFont() const;
1134 Returns @true if the currently set text color is valid.
1136 bool HasTextColour() const;
1139 Sets a new background color.
1141 void SetBackgroundColour(const wxColour
& colour
);
1146 void SetFont(const wxFont
& font
);
1149 Sets a new text color.
1151 void SetTextColour(const wxColour
& colour
);
1159 This class currently simply presents a simpler to use interface for the
1160 wxListCtrl -- it can be thought of as a @e façade for that complicated class.
1162 Using it is preferable to using wxListCtrl directly whenever possible because
1163 in the future some ports might implement wxListView but not the full set of
1164 wxListCtrl features.
1166 Other than different interface, this class is identical to wxListCtrl.
1167 In particular, it uses the same events, same window styles and so on.
1171 @appearance{listview.png}
1173 @see wxListView::SetColumnImage
1175 class wxListView
: public wxListCtrl
1179 Resets the column image -- after calling this function, no image will be shown.
1182 the column to clear image for
1184 @see SetColumnImage()
1186 void ClearColumnImage(int col
);
1189 Sets focus to the item with the given @a index.
1191 void Focus(long index
);
1194 Returns the first selected item in a (presumably) multiple selection control.
1195 Together with GetNextSelected() it can be used to iterate over all selected
1196 items in the control.
1198 @return The first selected item, if any, -1 otherwise.
1200 long GetFirstSelected() const;
1203 Returns the currently focused item or -1 if none.
1205 @see IsSelected(), Focus()
1207 long GetFocusedItem() const;
1210 Used together with GetFirstSelected() to iterate over all selected items
1213 @return Returns the next selected item or -1 if there are no more of them.
1215 long GetNextSelected(long item
) const;
1218 Returns @true if the item with the given @a index is selected,
1221 @see GetFirstSelected(), GetNextSelected()
1223 bool IsSelected(long index
) const;
1226 Selects or unselects the given item.
1229 the item to select or unselect
1231 if @true (default), selects the item, otherwise unselects it
1233 @see wxListCtrl::SetItemState
1235 void Select(long n
, bool on
= true);
1238 Sets the column image for the specified column.
1239 To use the column images, the control must have a valid image list with
1243 the column to set image for
1245 the index of the column image in the controls image list
1247 void SetColumnImage(int col
, int image
);
1252 Column format (MSW only except wxLIST_FORMAT_LEFT).
1254 enum wxListColumnFormat
1257 wxLIST_FORMAT_RIGHT
,
1258 wxLIST_FORMAT_CENTRE
,
1259 wxLIST_FORMAT_CENTER
= wxLIST_FORMAT_CENTRE
1265 This class stores information about a wxListCtrl item or column.
1267 wxListItem is a class which contains informations about:
1268 - Zero based item position; see SetId() and GetId().
1269 - Zero based column index; see SetColumn() and GetColumn().
1270 - The label (or header for columns); see SetText() and GetText().
1271 - The zero based index into an image list; see GetImage() and SetImage().
1272 - Application defined data; see SetData() and GetData().
1273 - For columns only: the width of the column; see SetWidth() and GetWidth().
1274 - For columns only: the format of the column; one of @c wxLIST_FORMAT_LEFT,
1275 @c wxLIST_FORMAT_RIGHT, @c wxLIST_FORMAT_CENTRE. See SetAlign() and GetAlign().
1276 - The state of the item; see SetState() and GetState().
1277 This is a bitlist of the following flags:
1278 - @c wxLIST_STATE_FOCUSED: The item has the focus.
1279 - @c wxLIST_STATE_SELECTED: The item is selected.
1280 - @c wxLIST_STATE_DONTCARE: Don't care what the state is. Win32 only.
1281 - @c wxLIST_STATE_DROPHILITED: The item is highlighted to receive a drop event. Win32 only.
1282 - @c wxLIST_STATE_CUT: The item is in the cut state. Win32 only.
1283 - A mask indicating which state flags are valid; this is a bitlist of the
1284 flags reported above for the item state. See SetStateMask() and GetStateMask().
1285 - A mask indicating which fields of this class are valid; see SetMask() and GetMask().
1286 This is a bitlist of the following flags:
1287 - @c wxLIST_MASK_STATE: The state field is valid.
1288 - @c wxLIST_MASK_TEXT: The label field is valid.
1289 - @c wxLIST_MASK_IMAGE: The image field is valid.
1290 - @c wxLIST_MASK_DATA: The application-defined data field is valid.
1291 - @c wxLIST_MASK_WIDTH: The column width field is valid.
1292 - @c wxLIST_MASK_FORMAT: The column format field is valid.
1294 The wxListItem object can also contain item-specific colour and font
1295 information: for this you need to call one of SetTextColour(), SetBackgroundColour()
1296 or SetFont() functions on it passing it the colour/font to use.
1297 If the colour/font is not specified, the default list control colour/font is used.
1304 class wxListItem
: public wxObject
1313 Resets the item state to the default.
1318 Returns the alignment for this item.
1319 Can be one of @c wxLIST_FORMAT_LEFT, @c wxLIST_FORMAT_RIGHT or @c wxLIST_FORMAT_CENTRE.
1321 wxListColumnFormat
GetAlign() const;
1324 Returns the background colour for this item.
1326 wxColour
GetBackgroundColour() const;
1329 Returns the zero-based column; meaningful only in report mode.
1331 int GetColumn() const;
1334 Returns client data associated with the control.
1335 Please note that client data is associated with the item and not with subitems.
1337 wxUIntPtr
GetData() const;
1340 Returns the font used to display the item.
1342 wxFont
GetFont() const;
1345 Returns the zero-based item position.
1350 Returns the zero-based index of the image associated with the item into
1353 int GetImage() const;
1356 Returns a bit mask indicating which fields of the structure are valid.
1358 Can be any combination of the following values:
1359 - wxLIST_MASK_STATE: @b GetState is valid.
1360 - wxLIST_MASK_TEXT: @b GetText is valid.
1361 - wxLIST_MASK_IMAGE: @b GetImage is valid.
1362 - wxLIST_MASK_DATA: @b GetData is valid.
1363 - wxLIST_MASK_WIDTH: @b GetWidth is valid.
1364 - wxLIST_MASK_FORMAT: @b GetFormat is valid.
1366 long GetMask() const;
1369 Returns a bit field representing the state of the item.
1371 Can be any combination of:
1372 - wxLIST_STATE_DONTCARE: Don't care what the state is. Win32 only.
1373 - wxLIST_STATE_DROPHILITED: The item is highlighted to receive a drop event. Win32 only.
1374 - wxLIST_STATE_FOCUSED: The item has the focus.
1375 - wxLIST_STATE_SELECTED: The item is selected.
1376 - wxLIST_STATE_CUT: The item is in the cut state. Win32 only.
1378 long GetState() const;
1381 Returns the label/header text.
1383 const wxString
& GetText() const;
1386 Returns the text colour.
1388 wxColour
GetTextColour() const;
1391 Meaningful only for column headers in report mode. Returns the column width.
1393 int GetWidth() const;
1396 Sets the alignment for the item. See also GetAlign()
1398 void SetAlign(wxListColumnFormat align
);
1401 Sets the background colour for the item.
1403 void SetBackgroundColour(const wxColour
& colBack
);
1406 Sets the zero-based column. Meaningful only in report mode.
1408 void SetColumn(int col
);
1412 Sets client data for the item.
1413 Please note that client data is associated with the item and not with subitems.
1415 void SetData(long data
);
1416 void SetData(void* data
);
1420 Sets the font for the item.
1422 void SetFont(const wxFont
& font
);
1425 Sets the zero-based item position.
1427 void SetId(long id
);
1430 Sets the zero-based index of the image associated with the item
1431 into the image list.
1433 void SetImage(int image
);
1436 Sets the mask of valid fields. See GetMask().
1438 void SetMask(long mask
);
1441 Sets the item state flags (note that the valid state flags are influenced
1442 by the value of the state mask, see wxListItem::SetStateMask).
1444 See GetState() for valid flag values.
1446 void SetState(long state
);
1449 Sets the bitmask that is used to determine which of the state flags
1450 are to be set. See also SetState().
1452 void SetStateMask(long stateMask
);
1455 Sets the text label for the item.
1457 void SetText(const wxString
& text
);
1460 Sets the text colour for the item.
1462 void SetTextColour(const wxColour
& colText
);
1465 Meaningful only for column headers in report mode. Sets the column width.
1467 void SetWidth(int width
);