diff --git a/include/wx/listbase.h b/include/wx/listbase.h index 07e70447c8..88e964b652 100644 --- a/include/wx/listbase.h +++ b/include/wx/listbase.h @@ -460,6 +460,12 @@ public: void SetAlternateRowColour(const wxColour& colour); wxColour GetAlternateRowColour() const { return m_alternateRowColour.GetBackgroundColour(); } + //checkboxes + virtual bool HasCheckboxes() const { return false; } + virtual void EnableCheckboxes(bool WXUNUSED(enable) = true) { } + virtual bool IsItemChecked(long WXUNUSED(item)) const { return false; } + virtual void CheckItem(long WXUNUSED(item), bool WXUNUSED(check)) { } + protected: // Real implementations methods to which our public forwards. virtual long DoInsertColumn(long col, const wxListItem& info) = 0; @@ -563,6 +569,8 @@ wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_LIST_COL_BEGIN_DRAG, wxListEve wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_LIST_COL_DRAGGING, wxListEvent ); wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_LIST_COL_END_DRAG, wxListEvent ); wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_LIST_ITEM_FOCUSED, wxListEvent ); +wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_LIST_ITEM_CHECKED, wxListEvent ); +wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_LIST_ITEM_UNCHECKED, wxListEvent ); typedef void (wxEvtHandler::*wxListEventFunction)(wxListEvent&); @@ -593,6 +601,8 @@ typedef void (wxEvtHandler::*wxListEventFunction)(wxListEvent&); #define EVT_LIST_ITEM_MIDDLE_CLICK(id, fn) wx__DECLARE_LISTEVT(ITEM_MIDDLE_CLICK, id, fn) #define EVT_LIST_ITEM_ACTIVATED(id, fn) wx__DECLARE_LISTEVT(ITEM_ACTIVATED, id, fn) #define EVT_LIST_ITEM_FOCUSED(id, fn) wx__DECLARE_LISTEVT(ITEM_FOCUSED, id, fn) +#define EVT_LIST_ITEM_CHECKED(id, fn) wx__DECLARE_LISTEVT(ITEM_CHECKED, id, fn) +#define EVT_LIST_ITEM_UNCHECKED(id, fn) wx__DECLARE_LISTEVT(ITEM_UNCHECKED, id, fn) #define EVT_LIST_CACHE_HINT(id, fn) wx__DECLARE_LISTEVT(CACHE_HINT, id, fn) diff --git a/include/wx/msw/listctrl.h b/include/wx/msw/listctrl.h index 48449f8b1c..facef5eff0 100644 --- a/include/wx/msw/listctrl.h +++ b/include/wx/msw/listctrl.h @@ -216,6 +216,12 @@ public: void SetItemFont( long item, const wxFont &f); wxFont GetItemFont( long item ) const; + // Checkbox state of an item + bool HasCheckboxes() const; + void EnableCheckboxes(bool enable = true); + bool IsItemChecked(long item) const; + void CheckItem(long item, bool check); + // Gets the number of selected items in the list control int GetSelectedItemCount() const; diff --git a/src/common/listctrlcmn.cpp b/src/common/listctrlcmn.cpp index 0b4ddf6a5e..25f29b8042 100644 --- a/src/common/listctrlcmn.cpp +++ b/src/common/listctrlcmn.cpp @@ -52,6 +52,8 @@ wxDEFINE_EVENT( wxEVT_LIST_ITEM_RIGHT_CLICK, wxListEvent ); wxDEFINE_EVENT( wxEVT_LIST_ITEM_MIDDLE_CLICK, wxListEvent ); wxDEFINE_EVENT( wxEVT_LIST_ITEM_ACTIVATED, wxListEvent ); wxDEFINE_EVENT( wxEVT_LIST_ITEM_FOCUSED, wxListEvent ); +wxDEFINE_EVENT( wxEVT_LIST_ITEM_CHECKED, wxListEvent ); +wxDEFINE_EVENT( wxEVT_LIST_ITEM_UNCHECKED, wxListEvent ); wxDEFINE_EVENT( wxEVT_LIST_CACHE_HINT, wxListEvent ); // ----------------------------------------------------------------------------- diff --git a/src/msw/listctrl.cpp b/src/msw/listctrl.cpp index 2019554161..6f58ced593 100644 --- a/src/msw/listctrl.cpp +++ b/src/msw/listctrl.cpp @@ -1211,6 +1211,28 @@ wxFont wxListCtrl::GetItemFont( long item ) const return f; } +bool wxListCtrl::HasCheckboxes() const +{ + DWORD currStyle = ListView_GetExtendedListViewStyle(GetHwnd()); + return ((currStyle & LVS_EX_CHECKBOXES) > 0); +} + +void wxListCtrl::EnableCheckboxes(bool enable) +{ + DWORD cbStyle = enable ? LVS_EX_CHECKBOXES : 0; + ListView_SetExtendedListViewStyleEx(GetHwnd(), LVS_EX_CHECKBOXES, cbStyle); +} + +void wxListCtrl::CheckItem(long item, bool state) +{ + ListView_SetCheckState(GetHwnd(), (UINT)item, (BOOL)state); +} + +bool wxListCtrl::IsItemChecked(long item) const +{ + return (ListView_GetCheckState(GetHwnd(), (UINT)item) != 0); +} + // Gets the number of selected items in the list control int wxListCtrl::GetSelectedItemCount() const { @@ -2213,6 +2235,30 @@ bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) ? wxEVT_LIST_ITEM_SELECTED : wxEVT_LIST_ITEM_DESELECTED; } + + if ((stNew & LVIS_STATEIMAGEMASK) != (stOld & LVIS_STATEIMAGEMASK)) + { + if (stOld == INDEXTOSTATEIMAGEMASK(0)) + { + // item does not yet have a state + // occurs when checkboxes are enabled and when a new item is added + eventType = wxEVT_NULL; + } + else if (stNew == INDEXTOSTATEIMAGEMASK(1)) + { + eventType = wxEVT_LIST_ITEM_UNCHECKED; + } + else if (stNew == INDEXTOSTATEIMAGEMASK(2)) + { + eventType = wxEVT_LIST_ITEM_CHECKED; + } + else { + eventType = wxEVT_NULL; + wxLogDebug(wxT("Unknown LVIS_STATEIMAGE state: %u"), stNew); + } + + event.m_itemIndex = iItem; + } } if ( eventType == wxEVT_NULL )