diff --git a/include/wx/listbase.h b/include/wx/listbase.h index 70744034db..4a41262e5c 100644 --- a/include/wx/listbase.h +++ b/include/wx/listbase.h @@ -433,6 +433,9 @@ protected: // return the text for the given column of the given item 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 // only be called for the first column. See OnGetItemColumnImage for // details. diff --git a/interface/wx/listctrl.h b/interface/wx/listctrl.h index fac32dd53b..d90b30d19c 100644 --- a/interface/wx/listctrl.h +++ b/interface/wx/listctrl.h @@ -1271,6 +1271,13 @@ public: @param enable If @true, enable checkboxes, otherwise disable checkboxes. @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 */ bool EnableCheckBoxes(bool enable = true); @@ -1312,7 +1319,7 @@ protected: The base class version always returns @NULL. @see OnGetItemImage(), OnGetItemColumnImage(), OnGetItemText(), - OnGetItemColumnAttr() + OnGetItemColumnAttr(), OnGetItemIsChecked() */ virtual wxItemAttr* OnGetItemAttr(long item) const; @@ -1370,6 +1377,17 @@ protected: @see SetItemCount(), OnGetItemImage(), OnGetItemColumnImage(), OnGetItemAttr() */ 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; }; diff --git a/src/common/listctrlcmn.cpp b/src/common/listctrlcmn.cpp index ba6292fa1c..ead815ed70 100644 --- a/src/common/listctrlcmn.cpp +++ b/src/common/listctrlcmn.cpp @@ -261,6 +261,15 @@ wxString wxListCtrlBase::OnGetItemText(long WXUNUSED(item), long WXUNUSED(col)) 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 { wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL),