Fix generic wxDataViewToggleRenderer hit testing with any alignment.

This change reverts the changes of r73835 and r73838 to
wxDataViewToggleRenderer::WXActivateCell() and instead fix the bug with mouse
hit testing in this function in the wxDataViewMainWindow::OnMouse() itself.
The problem there was that it offset the coordinates of the event differently
depending on whether the column alignment was set or left as default. Now
always make the coordinates relative to the item (not cell) rectangle for
compatibility with GTK+ native version, which is enough to make the original,
i.e. before the changes of r73835, code work.

See #15144.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73854 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2013-04-25 13:16:29 +00:00
parent bd7c46cfc6
commit 4e231c294d

View File

@ -1090,7 +1090,7 @@ bool wxDataViewToggleRenderer::Render( wxRect cell, wxDC *dc, int WXUNUSED(state
return true;
}
bool wxDataViewToggleRenderer::WXActivateCell(const wxRect& cellRect,
bool wxDataViewToggleRenderer::WXActivateCell(const wxRect& WXUNUSED(cellRect),
wxDataViewModel *model,
const wxDataViewItem& item,
unsigned int col,
@ -1100,18 +1100,7 @@ bool wxDataViewToggleRenderer::WXActivateCell(const wxRect& cellRect,
{
// Only react to clicks directly on the checkbox, not elsewhere in the
// same cell.
//
// We suppose that the checkbox is centred in the total cell rectangle
// as this is how it's rendered, at least under MSW. If this turns out
// to be a wrong assumption, we probably would need to do the hit test
// checking in wxRendererNative but for now this simple solution works.
wxRect checkRect = wxRect(GetSize()).CentreIn(cellRect);
// After centering in cellRect, we need to pull it back to (0, 0) as
// the mouse coordinates passed to us are relative to cellRect already.
checkRect.Offset(-cellRect.GetPosition());
if ( !checkRect.Contains(mouseEvent->GetPosition()) )
if ( !wxRect(GetSize()).Contains(mouseEvent->GetPosition()) )
return false;
}
@ -4390,33 +4379,38 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
GetLineHeight( current ) );
// Report position relative to the cell's custom area, i.e.
// no the entire space as given by the control but the one
// not the entire space as given by the control but the one
// used by the renderer after calculation of alignment etc.
//
// Notice that this results in negative coordinates when clicking
// in the upper left corner of a centre-aligned cell which doesn't
// fill its column entirely so this is somewhat surprising, but we
// do it like this for compatibility with the native GTK+ version,
// see #12270.
// adjust the rectangle ourselves to account for the alignment
int align = cell->GetAlignment();
if ( align == wxDVR_DEFAULT_ALIGNMENT )
align = wxALIGN_CENTRE;
wxRect rectItem = cell_rect;
const int align = cell->GetAlignment();
if ( align != wxDVR_DEFAULT_ALIGNMENT )
const wxSize size = cell->GetSize();
if ( size.x >= 0 && size.x < cell_rect.width )
{
const wxSize size = cell->GetSize();
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.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
}
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
}
wxMouseEvent event2(event);