diff --git a/common/eda_base_frame.cpp b/common/eda_base_frame.cpp index 1c82c44945..6c7555b8cf 100644 --- a/common/eda_base_frame.cpp +++ b/common/eda_base_frame.cpp @@ -192,6 +192,27 @@ EDA_BASE_FRAME::EDA_BASE_FRAME( wxWindow* aParent, FRAME_T aFrameType, const wxS commonInit( aFrameType ); + Bind( wxEVT_DPI_CHANGED, + [&]( wxDPIChangedEvent& aEvent ) + { +#ifdef __WXMSW__ + // Workaround to update toolbar sizes on MSW + wxAuiPaneInfoArray& panes = m_auimgr.GetAllPanes(); + + for( wxAuiPaneInfo& pinfo : panes ) + { + pinfo.best_size = pinfo.window->GetSize(); + + // But we still shouldn't make it too small. + pinfo.best_size.IncTo( pinfo.window->GetBestSize() ); + pinfo.best_size.IncTo( pinfo.min_size ); + } + + m_auimgr.Update(); +#endif + + aEvent.Skip(); + } ); } @@ -318,6 +339,18 @@ bool EDA_BASE_FRAME::ProcessEvent( wxEvent& aEvent ) } #endif +#ifdef __WXMSW__ + // When changing DPI to a lower value, somehow, called from wxNonOwnedWindow::HandleDPIChange, + // our sizers compute a min size that is larger than the old frame size. wx then sets this wrong size. + // This shouldn't be needed since the OS have already sent a size event. + // Avoid this wx behaviour by pretending we've processed the event even if we use Skip in handlers. + if( aEvent.GetEventType() == wxEVT_DPI_CHANGED ) + { + wxFrame::ProcessEvent( aEvent ); + return true; + } +#endif + if( !wxFrame::ProcessEvent( aEvent ) ) return false; diff --git a/common/eda_draw_frame.cpp b/common/eda_draw_frame.cpp index c9debc6074..44d58a5a5f 100644 --- a/common/eda_draw_frame.cpp +++ b/common/eda_draw_frame.cpp @@ -150,7 +150,7 @@ EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame m_messagePanel->SetSize( m_frameSize.x, m_msgFrameHeight ); Bind( wxEVT_DPI_CHANGED, - [&]( wxDPIChangedEvent& ) + [&]( wxDPIChangedEvent& aEvent ) { if( ( GetWindowStyle() & wxFRAME_NO_TASKBAR ) == 0 ) updateStatusBarWidths(); @@ -168,7 +168,7 @@ EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame m_messagePanel->SetPosition( wxPoint( 0, m_frameSize.y ) ); m_messagePanel->SetSize( m_frameSize.x, m_msgFrameHeight ); - // Don't skip, otherwise the frame gets too big + aEvent.Skip(); } ); } diff --git a/common/widgets/bitmap_button.cpp b/common/widgets/bitmap_button.cpp index c3d71e1357..09527c6e3f 100644 --- a/common/widgets/bitmap_button.cpp +++ b/common/widgets/bitmap_button.cpp @@ -284,7 +284,7 @@ void BITMAP_BUTTON::OnDPIChanged( wxDPIChangedEvent& aEvent ) invalidateBestSize(); } - // Don't skip, otherwise the button gets too big + aEvent.Skip(); } diff --git a/common/widgets/msgpanel.cpp b/common/widgets/msgpanel.cpp index 699a2555c5..880b51694a 100644 --- a/common/widgets/msgpanel.cpp +++ b/common/widgets/msgpanel.cpp @@ -38,6 +38,7 @@ BEGIN_EVENT_TABLE( EDA_MSG_PANEL, wxPanel ) EVT_DPI_CHANGED( EDA_MSG_PANEL::OnDPIChanged ) + EVT_SIZE( EDA_MSG_PANEL::OnSize ) EVT_PAINT( EDA_MSG_PANEL::OnPaint ) END_EVENT_TABLE() @@ -93,6 +94,21 @@ void EDA_MSG_PANEL::OnDPIChanged( wxDPIChangedEvent& aEvent ) } +void EDA_MSG_PANEL::rebuildItems() +{ + m_last_x = 0; + + for( MSG_PANEL_ITEM& item : m_Items ) + updateItemPos( item ); +} + + +void EDA_MSG_PANEL::OnSize( wxSizeEvent& aEvent ) +{ + rebuildItems(); +} + + void EDA_MSG_PANEL::OnPaint( wxPaintEvent& aEvent ) { wxPaintDC dc( this ); @@ -111,16 +127,15 @@ void EDA_MSG_PANEL::OnPaint( wxPaintEvent& aEvent ) } -void EDA_MSG_PANEL::AppendMessage( const wxString& aUpperText, const wxString& aLowerText, - int aPadding ) +void EDA_MSG_PANEL::updateItemPos( MSG_PANEL_ITEM& item ) { - wxString text; - wxSize drawSize = GetClientSize(); + wxString text; + wxString upperText = item.GetUpperText(); + wxString lowerText = item.GetLowerText(); + wxSize drawSize = GetClientSize(); - text = ( aUpperText.Len() > aLowerText.Len() ) ? aUpperText : aLowerText; - text.Append( ' ', aPadding ); - - MSG_PANEL_ITEM item; + text = ( upperText.Len() > lowerText.Len() ) ? upperText : lowerText; + text.Append( ' ', item.GetPadding() ); /* Don't put the first message a window client position 0. Offset by * one 'W' character width. */ @@ -132,62 +147,22 @@ void EDA_MSG_PANEL::AppendMessage( const wxString& aUpperText, const wxString& a item.m_UpperY = ( drawSize.y / 2 ) - m_fontSize.y; item.m_LowerY = drawSize.y - m_fontSize.y; - item.m_UpperText = aUpperText; - item.m_LowerText = aLowerText; - m_Items.push_back( item ); m_last_x += GetTextExtent( text ).x; // Add an extra space between texts for a better look: m_last_x += m_fontSize.x; - - Refresh(); } -void EDA_MSG_PANEL::SetMessage( int aXPosition, const wxString& aUpperText, - const wxString& aLowerText ) +void EDA_MSG_PANEL::AppendMessage( const wxString& aUpperText, const wxString& aLowerText, int aPadding ) { - wxPoint pos; - wxSize drawSize = GetClientSize(); - - if( aXPosition >= 0 ) - m_last_x = pos.x = aXPosition * (m_fontSize.x + 2); - else - pos.x = m_last_x; - MSG_PANEL_ITEM item; - item.m_X = pos.x; - - item.m_UpperY = (drawSize.y / 2) - m_fontSize.y; - item.m_LowerY = drawSize.y - m_fontSize.y; - item.m_UpperText = aUpperText; item.m_LowerText = aLowerText; - int ndx; - - // update the vector, which is sorted by m_X - int limit = m_Items.size(); - - for( ndx = 0; ndx < limit; ++ndx ) - { - // replace any item with same X - if( m_Items[ndx].m_X == item.m_X ) - { - m_Items[ndx] = item; - break; - } - - if( m_Items[ndx].m_X > item.m_X ) - { - m_Items.insert( m_Items.begin() + ndx, item ); - break; - } - } - - if( ndx == limit ) // mutually exclusive with two above if tests - m_Items.push_back( item ); + updateItemPos( item ); + m_Items.push_back( item ); Refresh(); } diff --git a/common/widgets/wx_grid.cpp b/common/widgets/wx_grid.cpp index eea3f18634..1127694db0 100644 --- a/common/widgets/wx_grid.cpp +++ b/common/widgets/wx_grid.cpp @@ -244,7 +244,7 @@ void WX_GRID::onDPIChanged(wxDPIChangedEvent& aEvt) wxGrid::SetColLabelSize( wxGRID_AUTOSIZE ); } ); - // Don't skip, otherwise the grid gets too big + aEvt.Skip(); } diff --git a/include/widgets/msgpanel.h b/include/widgets/msgpanel.h index 4f469a4d02..c9f6fe61ed 100644 --- a/include/widgets/msgpanel.h +++ b/include/widgets/msgpanel.h @@ -107,21 +107,12 @@ public: void OnPaint( wxPaintEvent& aEvent ); void OnDPIChanged( wxDPIChangedEvent& aEvent ); + void OnSize( wxSizeEvent& aEvent ); void EraseMsgBox(); wxSize DoGetBestSize() const override; wxSize DoGetBestClientSize() const override; - /** - * Set a message at \a aXPosition to \a aUpperText and \a aLowerText in the message panel. - * - * @param aXPosition The horizontal position to display the message or less than zero - * to set the message using the last message position. - * @param aUpperText The text to be displayed in top line. - * @param aLowerText The text to be displayed in bottom line. - */ - void SetMessage( int aXPosition, const wxString& aUpperText, const wxString& aLowerText ); - /** * Append a message to the message panel. * @@ -153,6 +144,10 @@ public: protected: void updateFontSize(); + void rebuildItems(); + + void updateItemPos( MSG_PANEL_ITEM& aItem ); + void showItem( wxDC& dc, const MSG_PANEL_ITEM& aItem ); void erase( wxDC* DC ); diff --git a/kicad/kicad_manager_frame.cpp b/kicad/kicad_manager_frame.cpp index 144b0c203f..ba0e81f402 100644 --- a/kicad/kicad_manager_frame.cpp +++ b/kicad/kicad_manager_frame.cpp @@ -304,14 +304,6 @@ KICAD_MANAGER_FRAME::KICAD_MANAGER_FRAME( wxWindow* parent, const wxString& titl // Ensure the window is on top Raise(); - - Bind( wxEVT_DPI_CHANGED, - [&]( wxDPIChangedEvent& ) - { - m_auimgr.Update(); - - // Don't skip, otherwise the frame gets too big - } ); }