Add minimal DPI change handler to wxGrid

This handler redoes wxGrid layout and refreshes it to at least avoid
ugly display artifacts when moving wxGrid window between displays with
different DPI.
This commit is contained in:
Vadim Zeitlin 2020-03-31 16:59:49 +02:00
parent 393f5c8e2b
commit 5e761ad99f
2 changed files with 26 additions and 2 deletions

View File

@ -2415,6 +2415,13 @@ protected:
friend class wxGridHeaderCtrl;
private:
// This is called from both Create() and OnDPIChanged() to (re)initialize
// the values in pixels, which depend on the current DPI.
void InitPixelFields();
// Event handler for DPI change event recomputes pixel values and relays
// out the grid.
void OnDPIChanged(wxDPIChangedEvent& event);
// implement wxScrolledCanvas method to return m_gridWin size
virtual wxSize GetSizeAvailableForScrollTarget(const wxSize& size) wxOVERRIDE;

View File

@ -2317,6 +2317,7 @@ void wxGridWindow::OnFocus(wxFocusEvent& event)
wxBEGIN_EVENT_TABLE( wxGrid, wxScrolledCanvas )
EVT_SIZE( wxGrid::OnSize )
EVT_DPI_CHANGED( wxGrid::OnDPIChanged )
EVT_KEY_DOWN( wxGrid::OnKeyDown )
EVT_KEY_UP( wxGrid::OnKeyUp )
EVT_CHAR ( wxGrid::OnChar )
@ -2457,8 +2458,11 @@ void wxGrid::Create()
m_labelBackgroundColour = m_rowLabelWin->GetBackgroundColour();
m_labelTextColour = m_rowLabelWin->GetForegroundColour();
// now that we have the grid window, use its font to compute the default
// row height
InitPixelFields();
}
void wxGrid::InitPixelFields()
{
m_defaultRowHeight = m_gridWin->GetCharHeight();
#if defined(__WXMOTIF__) || defined(__WXGTK__) || defined(__WXQT__) // see also text ctrl sizing in ShowCellEditControl()
m_defaultRowHeight += 8;
@ -5346,6 +5350,19 @@ void wxGrid::OnSize(wxSizeEvent& WXUNUSED(event))
}
}
void wxGrid::OnDPIChanged(wxDPIChangedEvent& event)
{
InitPixelFields();
InvalidateBestSize();
CalcWindowSizes();
Refresh();
event.Skip();
}
void wxGrid::OnKeyDown( wxKeyEvent& event )
{
if ( m_inOnKeyDown )