From: Vadim Zeitlin Date: Tue, 30 Aug 2011 13:40:40 +0000 (+0000) Subject: Fix computation of the item offset in generic wxDataViewCtrl code. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/c46ecbe3b5bd25dcc1e2bac012ad3dd8dff3e594?ds=inline Fix computation of the item offset in generic wxDataViewCtrl code. We need to account for the expander even for the items that don't have children when computing their offset as their parent still does have it, contributing to the total offset. This corrects the fixes of r68836 to also work for the leaf items. Also rename expanderOffset variable to more clear itemOffset. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@68960 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index f4f3b1f80b..8143e146c9 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -3524,23 +3524,22 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event ) // button) and also determine the offset of the real cell start, skipping // the indentation and the expander itself. bool hoverOverExpander = false; - int expanderOffset = 0; + int itemOffset = 0; if ((!IsList()) && (GetOwner()->GetExpanderColumn() == col)) { wxDataViewTreeNode * node = GetTreeNodeByRow(current); - if( node!=NULL && node->HasChildren() ) - { - int indent = node->GetIndentLevel(); - indent = GetOwner()->GetIndent()*indent; + int indent = node->GetIndentLevel(); + itemOffset = GetOwner()->GetIndent()*indent; + + if ( node->HasChildren() ) + { // we make the rectangle we are looking in a bit bigger than the actual // visual expander so the user can hit that little thing reliably - wxRect rect( xpos + indent, + wxRect rect(itemOffset, GetLineStart( current ) + (GetLineHeight(current) - m_lineHeight)/2, m_lineHeight, m_lineHeight); - expanderOffset = indent + m_lineHeight; - if( rect.Contains(x, y) ) { // So the mouse is over the expander @@ -3558,6 +3557,10 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event ) m_underMouse = node; } } + + // Account for the expander as well, even if this item doesn't have it, + // its parent does so it still counts for the offset. + itemOffset += m_lineHeight; } if (!hoverOverExpander) { @@ -3832,9 +3835,9 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event ) // notify cell about click cell->PrepareForItem(model, item, col->GetModelColumn()); - wxRect cell_rect( xpos + expanderOffset, + wxRect cell_rect( xpos + itemOffset, GetLineStart( current ), - col->GetWidth() - expanderOffset, + col->GetWidth() - itemOffset, GetLineHeight( current ) ); // Report position relative to the cell's custom area, i.e.