Fix wxStatusBar font and position after DPI changes

Update the font of the associated wxDC so ellipsization uses the correct font
size.
This commit is contained in:
Maarten Bent
2019-09-03 22:07:49 +02:00
parent 4713301cf5
commit e312569b94
3 changed files with 23 additions and 3 deletions

View File

@@ -72,6 +72,8 @@ protected:
// implementation of the public SetStatusWidths()
void MSWUpdateFieldsWidths();
virtual void MSWUpdateFontOnDPIChange(const wxSize& newDPI) wxOVERRIDE;
// used by DoUpdateStatusText()
wxClientDC *m_pDC;

View File

@@ -335,6 +335,14 @@ void wxFrame::PositionStatusBar()
//else: no adjustments necessary for the toolbar on top
#endif // wxUSE_TOOLBAR
// GetSize returns the height of the clientSize in which the statusbar
// height is subtracted (see wxFrame::DoGetClientSize). When the DPI of the
// window changes, the statusbar height will likely change so we need to
// account for this difference. If not, the statusbar will be positioned
// too high or low.
int shOld;
m_frameStatusBar->GetSize(NULL, &shOld);
// Resize the status bar to its default height, as it could have been set
// to a wrong value before by WM_SIZE sent during the frame creation and
// our status bars preserve their programmatically set size to avoid being
@@ -342,8 +350,9 @@ void wxFrame::PositionStatusBar()
// this here, the status bar would retain the possibly wrong current height.
m_frameStatusBar->SetSize(x, h, w, wxDefaultCoord, wxSIZE_AUTO_HEIGHT);
int sw, sh;
m_frameStatusBar->GetSize(&sw, &sh);
int sh;
m_frameStatusBar->GetSize(NULL, &sh);
h += shOld - sh;
// Since we wish the status bar to be directly under the client area,
// we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.

View File

@@ -166,7 +166,8 @@ bool wxStatusBar::SetFont(const wxFont& font)
if (!wxWindow::SetFont(font))
return false;
if (m_pDC) m_pDC->SetFont(font);
if ( m_pDC )
m_pDC->SetFont(m_font);
return true;
}
@@ -256,6 +257,14 @@ void wxStatusBar::MSWUpdateFieldsWidths()
delete [] pWidths;
}
void wxStatusBar::MSWUpdateFontOnDPIChange(const wxSize& newDPI)
{
wxStatusBarBase::MSWUpdateFontOnDPIChange(newDPI);
if ( m_pDC && m_font.IsOk() )
m_pDC->SetFont(m_font);
}
void wxStatusBar::DoUpdateStatusText(int nField)
{
if (!m_pDC)