diff --git a/include/wx/generic/grid.h b/include/wx/generic/grid.h index 3e728afa23..c88b2a6122 100644 --- a/include/wx/generic/grid.h +++ b/include/wx/generic/grid.h @@ -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; diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index bcb3ca6a98..1036e1bee6 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -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 )