From a3a8d81d487ae4f03d8b70bce20bddbfc48c5776 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Tue, 27 Jul 2010 17:04:44 +0000 Subject: [PATCH] Let wxMSW report wxDataViewCustomRenderer::LeftClick() report the click position relative to the inner cell, not the window - as in wxGTK, fixes #12270: wxDataViewCustomRenderer::LeftClick behaves differently under wxGTK and wxMSW git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65117 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/generic/datavgen.cpp | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index 3222eb1213..32846cda9c 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -3785,7 +3785,44 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event ) custom->SetValue( value ); wxRect cell_rect( xpos, GetLineStart( current ), col->GetWidth(), GetLineHeight( current ) ); - /* ignore ret */ custom->LeftClick( event.GetPosition(), cell_rect, + + // Report position relative to the cell's custom area, i.e. + // no the entire space as given by the control but the one + // used by the renderer after calculation of alignment etc. + + // adjust the rectangle ourselves to account for the alignment + wxRect rectItem = cell_rect; + const int align = custom->GetAlignment(); + if ( align != wxDVR_DEFAULT_ALIGNMENT ) + { + const wxSize size = custom->GetSize(); + + if ( size.x >= 0 && size.x < cell_rect.width ) + { + if ( align & wxALIGN_CENTER_HORIZONTAL ) + rectItem.x += (cell_rect.width - size.x)/2; + else if ( align & wxALIGN_RIGHT ) + rectItem.x += cell_rect.width - size.x; + // else: wxALIGN_LEFT is the default + } + + if ( size.y >= 0 && size.y < cell_rect.height ) + { + if ( align & wxALIGN_CENTER_VERTICAL ) + rectItem.y += (cell_rect.height - size.y)/2; + else if ( align & wxALIGN_BOTTOM ) + rectItem.y += cell_rect.height - size.y; + // else: wxALIGN_TOP is the default + } + } + + wxPoint pos( event.GetPosition() ); + pos.x -= rectItem.x; + pos.y -= rectItem.y; + + m_owner->CalcUnscrolledPosition( pos.x, pos.y, &pos.x, &pos.y ); + + /* ignore ret */ custom->LeftClick( pos, cell_rect, model, item, col->GetModelColumn()); } } -- 2.50.0