From 7dd65abaf76574619e24eae13638aad49de1aee7 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sat, 6 Feb 2016 17:20:40 +0100 Subject: [PATCH] Implemented checking checkboxes. --- include/wx/generic/private/listctrl.h | 1 + src/generic/listctrl.cpp | 26 +++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/include/wx/generic/private/listctrl.h b/include/wx/generic/private/listctrl.h index 7c13269955..86cc91607a 100644 --- a/include/wx/generic/private/listctrl.h +++ b/include/wx/generic/private/listctrl.h @@ -850,6 +850,7 @@ private: // Compute the minimal width needed to fully display the column header. int ComputeMinHeaderWidth(const wxListHeaderData* header) const; + bool IsClickInsideCheckbox(long item, int x, int y); // the height of one line using the current font wxCoord m_lineHeight; diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index 0ee4531998..068acd5a1d 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -2579,11 +2579,18 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event ) { if ( IsSingleSel() || !IsHighlighted(current) ) { - HighlightAll( false ); + if (IsClickInsideCheckbox(current, x, y)) + { + CheckItem(current, !IsItemChecked(current)); + } + else + { + HighlightAll(false); - ChangeCurrent(current); + ChangeCurrent(current); - ReverseHighlight(m_current); + ReverseHighlight(m_current); + } } else // multi sel & current is highlighted & no mod keys { @@ -3739,6 +3746,19 @@ bool wxListMainWindow::IsItemChecked(long item) const return line->IsChecked(); } +bool wxListMainWindow::IsClickInsideCheckbox(long item, int x, int y) +{ + if (HasCheckboxes()) { + wxRect lineRect = GetLineRect(item); + wxSize cbSize = wxRendererNative::Get().GetCheckBoxSize(this); + int yOffset = (lineRect.height - cbSize.GetHeight()) / 2; + wxRect rr(0, lineRect.y + yOffset, cbSize.GetWidth(), cbSize.GetHeight()); + + return (rr.Contains(wxPoint(x, y))); + } + return false; +} + // ---------------------------------------------------------------------------- // geometry calculation // ----------------------------------------------------------------------------