Add virtual function to provide virtual wxListCtrl checkbox state

This commit is contained in:
Maarten Bent
2019-05-05 14:24:30 +02:00
parent ceaf2aa803
commit 353b0aabba
3 changed files with 31 additions and 1 deletions

View File

@@ -433,6 +433,9 @@ protected:
// return the text for the given column of the given item // return the text for the given column of the given item
virtual wxString OnGetItemText(long item, long column) const; virtual wxString OnGetItemText(long item, long column) const;
// return whether the given item is checked
virtual bool OnGetItemIsChecked(long item) const;
// return the icon for the given item. In report view, OnGetItemImage will // return the icon for the given item. In report view, OnGetItemImage will
// only be called for the first column. See OnGetItemColumnImage for // only be called for the first column. See OnGetItemColumnImage for
// details. // details.

View File

@@ -1271,6 +1271,13 @@ public:
@param enable If @true, enable checkboxes, otherwise disable checkboxes. @param enable If @true, enable checkboxes, otherwise disable checkboxes.
@return @true if checkboxes are supported, @false otherwise. @return @true if checkboxes are supported, @false otherwise.
In a list control with wxLC_VIRTUAL style you have to keep track of the
checkbox state. When a checkbox is clicked (EVT_LIST_ITEM_CHECKED
or EVT_LIST_ITEM_UNCHECKED) you have to update the state and refresh
the item yourself.
@see OnGetItemIsChecked() RefreshItem()
@since 3.1.0 @since 3.1.0
*/ */
bool EnableCheckBoxes(bool enable = true); bool EnableCheckBoxes(bool enable = true);
@@ -1312,7 +1319,7 @@ protected:
The base class version always returns @NULL. The base class version always returns @NULL.
@see OnGetItemImage(), OnGetItemColumnImage(), OnGetItemText(), @see OnGetItemImage(), OnGetItemColumnImage(), OnGetItemText(),
OnGetItemColumnAttr() OnGetItemColumnAttr(), OnGetItemIsChecked()
*/ */
virtual wxItemAttr* OnGetItemAttr(long item) const; virtual wxItemAttr* OnGetItemAttr(long item) const;
@@ -1370,6 +1377,17 @@ protected:
@see SetItemCount(), OnGetItemImage(), OnGetItemColumnImage(), OnGetItemAttr() @see SetItemCount(), OnGetItemImage(), OnGetItemColumnImage(), OnGetItemAttr()
*/ */
virtual wxString OnGetItemText(long item, long column) const; virtual wxString OnGetItemText(long item, long column) const;
/**
This function @b must be overridden in the derived class for a control with
@c wxLC_VIRTUAL style that uses checkboxes. It should return whether the
checkbox of the specified @c item is checked.
@see EnableCheckBoxes(), OnGetItemText()
@since 3.1.2
*/
virtual bool OnGetItemIsChecked(long item) const;
}; };

View File

@@ -261,6 +261,15 @@ wxString wxListCtrlBase::OnGetItemText(long WXUNUSED(item), long WXUNUSED(col))
return wxEmptyString; return wxEmptyString;
} }
bool wxListCtrlBase::OnGetItemIsChecked(long WXUNUSED(item)) const
{
// this is a pure virtual function, in fact - which is not really pure
// because the controls which are not virtual don't need to implement it
wxFAIL_MSG("wxListCtrl::OnGetItemIsChecked not supposed to be called");
return false;
}
int wxListCtrlBase::OnGetItemImage(long WXUNUSED(item)) const int wxListCtrlBase::OnGetItemImage(long WXUNUSED(item)) const
{ {
wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL), wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL),