From 851d11ba2cf7ae6677960ffa350122e3aac20110 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 22 Nov 2019 01:07:20 +0100 Subject: [PATCH] Determine the checkbox size in wxGetGridCheckBoxRect() itself It doesn't make much sense to pass the size to the function supposed to compute it, so call wxRendererNative::GetCheckBoxSize() from the function itself instead of forcing its callers to do it. No real changes. --- include/wx/generic/private/grid.h | 16 ++++++++++------ src/generic/grid.cpp | 10 +++++++--- src/generic/gridctrl.cpp | 12 +++++------- src/generic/grideditors.cpp | 8 +------- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/include/wx/generic/private/grid.h b/include/wx/generic/private/grid.h index d0c01a16af..35225b6a52 100644 --- a/include/wx/generic/private/grid.h +++ b/include/wx/generic/private/grid.h @@ -1007,12 +1007,16 @@ private: wxGridDataTypeInfoArray m_typeinfo; }; -// Returns the rect of the check box in a cell with the given alignmens -// and the size. -// The function is used by wxGridCellBoolEditor and wxGridCellBoolRenderer. -wxRect wxGetGridCheckBoxRect(const wxSize& checkBoxSize, - const wxRect& cellRect, - int hAlign, int vAlign); +// Returns the rectangle for showing a check box 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); #endif // wxUSE_GRID #endif // _WX_GENERIC_GRID_PRIVATE_H_ diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 2648f750a9..bae0b7d7b5 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -10332,13 +10332,17 @@ wxGridCellEditor* wxGridTypeRegistry::GetEditor(int index) return editor; } -wxRect wxGetGridCheckBoxRect(const wxSize& checkBoxSize, +wxRect wxGetGridCheckBoxRect(wxWindow* win, const wxRect& cellRect, - int hAlign, int WXUNUSED(vAlign)) + int hAlign, + int WXUNUSED(vAlign)) { - // TODO: support vAlign + const wxSize checkBoxSize = + wxRendererNative::Get().GetCheckBoxSize(win, wxCONTROL_CELL); wxRect checkBoxRect; + + // TODO: support vAlign checkBoxRect.SetY(cellRect.y + cellRect.height / 2 - checkBoxSize.y / 2); wxCoord minSize = wxMin(cellRect.width, cellRect.height); diff --git a/src/generic/gridctrl.cpp b/src/generic/gridctrl.cpp index ea0d6d7a15..29e3056da5 100644 --- a/src/generic/gridctrl.cpp +++ b/src/generic/gridctrl.cpp @@ -937,8 +937,11 @@ 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 = - wxRendererNative::Get().GetCheckBoxSize(&grid, wxCONTROL_CELL); + wxGetGridCheckBoxRect(&grid, r, wxALIGN_LEFT, wxALIGN_TOP).GetSize(); } return ms_sizeCheckMark; @@ -958,12 +961,7 @@ void wxGridCellBoolRenderer::Draw(wxGrid& grid, attr.GetNonDefaultAlignment(&hAlign, &vAlign); const wxRect - checkBoxRect = wxGetGridCheckBoxRect - ( - GetBestSize(grid, attr, dc, row, col), - rect, - hAlign, vAlign - ); + checkBoxRect = wxGetGridCheckBoxRect(&grid, 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 65755042c9..c07686f469 100644 --- a/src/generic/grideditors.cpp +++ b/src/generic/grideditors.cpp @@ -1224,13 +1224,7 @@ void wxGridCellBoolEditor::SetSize(const wxRect& r) GetCellAttr()->GetNonDefaultAlignment(&hAlign, &vAlign); const wxRect - checkBoxRect = wxGetGridCheckBoxRect - ( - wxRendererNative::Get(). - GetCheckBoxSize(GetWindow(), wxCONTROL_CELL), - r, - hAlign, vAlign - ); + checkBoxRect = wxGetGridCheckBoxRect(GetWindow(), r, hAlign, vAlign); // resize the control if required if ( m_control->GetSize() != checkBoxRect.GetSize() )