diff --git a/include/wx/generic/private/grid.h b/include/wx/generic/private/grid.h index 35225b6a52..172738df55 100644 --- a/include/wx/generic/private/grid.h +++ b/include/wx/generic/private/grid.h @@ -1007,16 +1007,16 @@ private: wxGridDataTypeInfoArray m_typeinfo; }; -// Returns the rectangle for showing a check box in a cell with the given -// alignment. +// Returns the rectangle for showing something of the given size in a cell with +// the given alignment. // // The function is used by wxGridCellBoolEditor and wxGridCellBoolRenderer to // draw a check mark and position wxCheckBox respectively. wxRect -wxGetGridCheckBoxRect(wxWindow* win, - const wxRect& cellRect, - int hAlign, - int vAlign); +wxGetContentRect(wxSize contentSize, + const wxRect& cellRect, + int hAlign, + int vAlign); #endif // wxUSE_GRID #endif // _WX_GENERIC_GRID_PRIVATE_H_ diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index bfbaf2b352..d4983e04e0 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -10332,57 +10332,55 @@ wxGridCellEditor* wxGridTypeRegistry::GetEditor(int index) return editor; } -wxRect wxGetGridCheckBoxRect(wxWindow* win, - const wxRect& cellRect, - int hAlign, - int vAlign) +wxRect +wxGetContentRect(wxSize contentSize, + const wxRect& cellRect, + int hAlign, + int vAlign) { - wxSize checkBoxSize = - wxRendererNative::Get().GetCheckBoxSize(win, wxCONTROL_CELL); - // Keep square aspect ratio for the checkbox, but ensure that it fits into // the available space, even if it's smaller than the standard size. const wxCoord minSize = wxMin(cellRect.width, cellRect.height); - if ( checkBoxSize.x >= minSize || checkBoxSize.y >= minSize ) + if ( contentSize.x >= minSize || contentSize.y >= minSize ) { // It must still have positive size, however. const int fittingSize = wxMax(1, minSize - 2*GRID_CELL_CHECKBOX_MARGIN); - checkBoxSize.x = - checkBoxSize.y = fittingSize; + contentSize.x = + contentSize.y = fittingSize; } - wxRect checkBoxRect(checkBoxSize); + wxRect contentRect(contentSize); if ( hAlign & wxALIGN_CENTER_HORIZONTAL ) { - checkBoxRect = checkBoxRect.CentreIn(cellRect, wxHORIZONTAL); + contentRect = contentRect.CentreIn(cellRect, wxHORIZONTAL); } else if ( hAlign & wxALIGN_RIGHT ) { - checkBoxRect.SetX(cellRect.x + cellRect.width - - checkBoxSize.x - GRID_CELL_CHECKBOX_MARGIN); + contentRect.SetX(cellRect.x + cellRect.width + - contentSize.x - GRID_CELL_CHECKBOX_MARGIN); } else // ( hAlign == wxALIGN_LEFT ) and invalid alignment value { - checkBoxRect.SetX(cellRect.x + GRID_CELL_CHECKBOX_MARGIN); + contentRect.SetX(cellRect.x + GRID_CELL_CHECKBOX_MARGIN); } if ( vAlign & wxALIGN_CENTER_VERTICAL ) { - checkBoxRect = checkBoxRect.CentreIn(cellRect, wxVERTICAL); + contentRect = contentRect.CentreIn(cellRect, wxVERTICAL); } else if ( vAlign & wxALIGN_BOTTOM ) { - checkBoxRect.SetY(cellRect.y + cellRect.height - - checkBoxRect.y - GRID_CELL_CHECKBOX_MARGIN); + contentRect.SetY(cellRect.y + cellRect.height + - contentRect.y - GRID_CELL_CHECKBOX_MARGIN); } else // wxALIGN_TOP { - checkBoxRect.SetY(cellRect.y + GRID_CELL_CHECKBOX_MARGIN); + contentRect.SetY(cellRect.y + GRID_CELL_CHECKBOX_MARGIN); } - return checkBoxRect; + return contentRect; } #endif // wxUSE_GRID diff --git a/src/generic/gridctrl.cpp b/src/generic/gridctrl.cpp index 29e3056da5..585a8e6341 100644 --- a/src/generic/gridctrl.cpp +++ b/src/generic/gridctrl.cpp @@ -937,11 +937,8 @@ wxSize wxGridCellBoolRenderer::GetBestSize(wxGrid& grid, // compute it only once (no locks for MT safeness in GUI thread...) if ( !ms_sizeCheckMark.x ) { - // Use rectangle big enough for the check box to fit into it. - const wxRect r(0, 0, 1000, 1000); - ms_sizeCheckMark = - wxGetGridCheckBoxRect(&grid, r, wxALIGN_LEFT, wxALIGN_TOP).GetSize(); + wxRendererNative::Get().GetCheckBoxSize(&grid, wxCONTROL_CELL); } return ms_sizeCheckMark; @@ -960,8 +957,9 @@ void wxGridCellBoolRenderer::Draw(wxGrid& grid, int vAlign = wxALIGN_CENTRE_VERTICAL; attr.GetNonDefaultAlignment(&hAlign, &vAlign); - const wxRect - checkBoxRect = wxGetGridCheckBoxRect(&grid, rect, hAlign, vAlign); + const wxRect checkBoxRect = + wxGetContentRect(GetBestSize(grid, attr, dc, row, col), + rect, hAlign, vAlign); bool value; if ( grid.GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL) ) diff --git a/src/generic/grideditors.cpp b/src/generic/grideditors.cpp index 08abef4efa..3fb11821ea 100644 --- a/src/generic/grideditors.cpp +++ b/src/generic/grideditors.cpp @@ -1223,16 +1223,11 @@ void wxGridCellBoolEditor::SetSize(const wxRect& r) if (GetCellAttr()) GetCellAttr()->GetNonDefaultAlignment(&hAlign, &vAlign); - const wxRect - checkBoxRect = wxGetGridCheckBoxRect(GetWindow(), r, hAlign, vAlign); + const wxRect checkBoxRect = + wxGetContentRect(m_control->GetSize(), r, hAlign, vAlign); - // resize the control if required - if ( m_control->GetSize() != checkBoxRect.GetSize() ) - { - m_control->SetSize(checkBoxRect.GetSize()); - } - - // and move it + // Don't resize the checkbox, it should have its default (and fitting) + // size, but do move it to the right position. m_control->Move(checkBoxRect.GetPosition()); }