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.
This commit is contained in:
Vadim Zeitlin
2019-11-22 01:07:20 +01:00
parent f4756eaa2f
commit 851d11ba2c
4 changed files with 23 additions and 23 deletions

View File

@@ -1007,12 +1007,16 @@ private:
wxGridDataTypeInfoArray m_typeinfo; wxGridDataTypeInfoArray m_typeinfo;
}; };
// Returns the rect of the check box in a cell with the given alignmens // Returns the rectangle for showing a check box in a cell with the given
// and the size. // alignment.
// The function is used by wxGridCellBoolEditor and wxGridCellBoolRenderer. //
wxRect wxGetGridCheckBoxRect(const wxSize& checkBoxSize, // The function is used by wxGridCellBoolEditor and wxGridCellBoolRenderer to
const wxRect& cellRect, // draw a check mark and position wxCheckBox respectively.
int hAlign, int vAlign); wxRect
wxGetGridCheckBoxRect(wxWindow* win,
const wxRect& cellRect,
int hAlign,
int vAlign);
#endif // wxUSE_GRID #endif // wxUSE_GRID
#endif // _WX_GENERIC_GRID_PRIVATE_H_ #endif // _WX_GENERIC_GRID_PRIVATE_H_

View File

@@ -10332,13 +10332,17 @@ wxGridCellEditor* wxGridTypeRegistry::GetEditor(int index)
return editor; return editor;
} }
wxRect wxGetGridCheckBoxRect(const wxSize& checkBoxSize, wxRect wxGetGridCheckBoxRect(wxWindow* win,
const wxRect& cellRect, 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; wxRect checkBoxRect;
// TODO: support vAlign
checkBoxRect.SetY(cellRect.y + cellRect.height / 2 - checkBoxSize.y / 2); checkBoxRect.SetY(cellRect.y + cellRect.height / 2 - checkBoxSize.y / 2);
wxCoord minSize = wxMin(cellRect.width, cellRect.height); wxCoord minSize = wxMin(cellRect.width, cellRect.height);

View File

@@ -937,8 +937,11 @@ wxSize wxGridCellBoolRenderer::GetBestSize(wxGrid& grid,
// compute it only once (no locks for MT safeness in GUI thread...) // compute it only once (no locks for MT safeness in GUI thread...)
if ( !ms_sizeCheckMark.x ) 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 = ms_sizeCheckMark =
wxRendererNative::Get().GetCheckBoxSize(&grid, wxCONTROL_CELL); wxGetGridCheckBoxRect(&grid, r, wxALIGN_LEFT, wxALIGN_TOP).GetSize();
} }
return ms_sizeCheckMark; return ms_sizeCheckMark;
@@ -958,12 +961,7 @@ void wxGridCellBoolRenderer::Draw(wxGrid& grid,
attr.GetNonDefaultAlignment(&hAlign, &vAlign); attr.GetNonDefaultAlignment(&hAlign, &vAlign);
const wxRect const wxRect
checkBoxRect = wxGetGridCheckBoxRect checkBoxRect = wxGetGridCheckBoxRect(&grid, rect, hAlign, vAlign);
(
GetBestSize(grid, attr, dc, row, col),
rect,
hAlign, vAlign
);
bool value; bool value;
if ( grid.GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL) ) if ( grid.GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL) )

View File

@@ -1224,13 +1224,7 @@ void wxGridCellBoolEditor::SetSize(const wxRect& r)
GetCellAttr()->GetNonDefaultAlignment(&hAlign, &vAlign); GetCellAttr()->GetNonDefaultAlignment(&hAlign, &vAlign);
const wxRect const wxRect
checkBoxRect = wxGetGridCheckBoxRect checkBoxRect = wxGetGridCheckBoxRect(GetWindow(), r, hAlign, vAlign);
(
wxRendererNative::Get().
GetCheckBoxSize(GetWindow(), wxCONTROL_CELL),
r,
hAlign, vAlign
);
// resize the control if required // resize the control if required
if ( m_control->GetSize() != checkBoxRect.GetSize() ) if ( m_control->GetSize() != checkBoxRect.GetSize() )