Implemented checking checkboxes.

This commit is contained in:
Maarten Bent
2016-02-06 17:20:40 +01:00
parent 3b89a3c7c5
commit 7dd65abaf7
2 changed files with 24 additions and 3 deletions

View File

@@ -850,6 +850,7 @@ private:
// Compute the minimal width needed to fully display the column header. // Compute the minimal width needed to fully display the column header.
int ComputeMinHeaderWidth(const wxListHeaderData* header) const; int ComputeMinHeaderWidth(const wxListHeaderData* header) const;
bool IsClickInsideCheckbox(long item, int x, int y);
// the height of one line using the current font // the height of one line using the current font
wxCoord m_lineHeight; wxCoord m_lineHeight;

View File

@@ -2578,6 +2578,12 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event )
if ( IsSingleSel() || !(cmdModifierDown || event.ShiftDown()) ) if ( IsSingleSel() || !(cmdModifierDown || event.ShiftDown()) )
{ {
if ( IsSingleSel() || !IsHighlighted(current) ) if ( IsSingleSel() || !IsHighlighted(current) )
{
if (IsClickInsideCheckbox(current, x, y))
{
CheckItem(current, !IsItemChecked(current));
}
else
{ {
HighlightAll(false); HighlightAll(false);
@@ -2585,6 +2591,7 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event )
ReverseHighlight(m_current); ReverseHighlight(m_current);
} }
}
else // multi sel & current is highlighted & no mod keys else // multi sel & current is highlighted & no mod keys
{ {
m_lineSelectSingleOnUp = current; m_lineSelectSingleOnUp = current;
@@ -3739,6 +3746,19 @@ bool wxListMainWindow::IsItemChecked(long item) const
return line->IsChecked(); 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 // geometry calculation
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------