Improve grid editors placing
Remove the code in wxGrid::ShowCellEditControl() which moves grid editors unnecessarily and also remove workarounds that were required because of it in the editors SetSize() functions. This helps to ensure that the editor is placed at the same position the renderer draws the cell value, so that it doesn't jump around annoyingly when editing starts (which was especially noticeable for boolean-valued cells).
This commit is contained in:
committed by
Vadim Zeitlin
parent
6a21d6f2e4
commit
3ca9491c5f
@@ -31,6 +31,7 @@
|
||||
#include "wx/tokenzr.h"
|
||||
#include "wx/renderer.h"
|
||||
|
||||
#include "wx/generic/private/grid.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxGridCellRenderer
|
||||
@@ -936,7 +937,8 @@ wxSize wxGridCellBoolRenderer::GetBestSize(wxGrid& grid,
|
||||
// compute it only once (no locks for MT safeness in GUI thread...)
|
||||
if ( !ms_sizeCheckMark.x )
|
||||
{
|
||||
ms_sizeCheckMark = wxRendererNative::Get().GetCheckBoxSize(&grid);
|
||||
ms_sizeCheckMark =
|
||||
wxRendererNative::Get().GetCheckBoxSize(&grid, wxCONTROL_CELL);
|
||||
}
|
||||
|
||||
return ms_sizeCheckMark;
|
||||
@@ -951,43 +953,16 @@ void wxGridCellBoolRenderer::Draw(wxGrid& grid,
|
||||
{
|
||||
wxGridCellRenderer::Draw(grid, attr, dc, rect, row, col, isSelected);
|
||||
|
||||
// draw a check mark in the centre (ignoring alignment - TODO)
|
||||
wxSize size = GetBestSize(grid, attr, dc, row, col);
|
||||
|
||||
// don't draw outside the cell
|
||||
wxCoord minSize = wxMin(rect.width, rect.height);
|
||||
if ( size.x >= minSize || size.y >= minSize )
|
||||
{
|
||||
// and even leave (at least) 1 pixel margin
|
||||
size.x = size.y = minSize;
|
||||
}
|
||||
|
||||
// draw a border around checkmark
|
||||
int vAlign, hAlign;
|
||||
attr.GetAlignment(&hAlign, &vAlign);
|
||||
|
||||
wxRect rectBorder;
|
||||
if (hAlign == wxALIGN_CENTRE)
|
||||
{
|
||||
rectBorder.x = rect.x + rect.width / 2 - size.x / 2;
|
||||
rectBorder.y = rect.y + rect.height / 2 - size.y / 2;
|
||||
rectBorder.width = size.x;
|
||||
rectBorder.height = size.y;
|
||||
}
|
||||
else if (hAlign == wxALIGN_LEFT)
|
||||
{
|
||||
rectBorder.x = rect.x + 2;
|
||||
rectBorder.y = rect.y + rect.height / 2 - size.y / 2;
|
||||
rectBorder.width = size.x;
|
||||
rectBorder.height = size.y;
|
||||
}
|
||||
else if (hAlign == wxALIGN_RIGHT)
|
||||
{
|
||||
rectBorder.x = rect.x + rect.width - size.x - 2;
|
||||
rectBorder.y = rect.y + rect.height / 2 - size.y / 2;
|
||||
rectBorder.width = size.x;
|
||||
rectBorder.height = size.y;
|
||||
}
|
||||
const wxRect
|
||||
checkBoxRect = wxGetGridCheckBoxRect
|
||||
(
|
||||
GetBestSize(grid, attr, dc, row, col),
|
||||
rect,
|
||||
hAlign, vAlign
|
||||
);
|
||||
|
||||
bool value;
|
||||
if ( grid.GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL) )
|
||||
@@ -1000,11 +975,11 @@ void wxGridCellBoolRenderer::Draw(wxGrid& grid,
|
||||
value = wxGridCellBoolEditor::IsTrueValue(cellval);
|
||||
}
|
||||
|
||||
int flags = 0;
|
||||
int flags = wxCONTROL_CELL;
|
||||
if (value)
|
||||
flags |= wxCONTROL_CHECKED;
|
||||
|
||||
wxRendererNative::Get().DrawCheckBox( &grid, dc, rectBorder, flags );
|
||||
wxRendererNative::Get().DrawCheckBox( &grid, dc, checkBoxRect, flags );
|
||||
}
|
||||
|
||||
#endif // wxUSE_GRID
|
||||
|
Reference in New Issue
Block a user