diff --git a/common/widgets/wx_infobar.cpp b/common/widgets/wx_infobar.cpp index 49b6f2714f..a2fa6cf4d9 100644 --- a/common/widgets/wx_infobar.cpp +++ b/common/widgets/wx_infobar.cpp @@ -23,12 +23,13 @@ #include #include "wx/artprov.h" #include +#include #include +#include #include #include +#include #include -#include -#include #include #ifdef __WXMSW__ @@ -158,10 +159,10 @@ void WX_INFOBAR::ShowMessage( const wxString& aMessage, int aFlags ) m_updateLock = true; - wxString msg = aMessage; - msg.Trim(); + m_message = aMessage; + m_message.Trim(); - wxInfoBarGeneric::ShowMessage( msg, aFlags ); + wxInfoBarGeneric::ShowMessage( m_message, aFlags ); if( m_auiManager ) updateAuiLayout( true ); @@ -228,6 +229,18 @@ void WX_INFOBAR::onThemeChange( wxSysColourChangedEvent& aEvent ) void WX_INFOBAR::onSize( wxSizeEvent& aEvent ) { int barWidth = GetSize().GetWidth(); + wxSizer* sizer = GetSizer(); + + if( !sizer ) + return; + + wxSizerItem* text = sizer->GetItem( 1 ); + + if( text ) + { + if( auto textCtrl = dynamic_cast( text->GetWindow() ) ) + textCtrl->SetLabelText( m_message ); + } // Calculate the horizontal size: because the infobar is shown on top of the draw canvas // it is adjusted to the canvas width. @@ -239,10 +252,26 @@ void WX_INFOBAR::onSize( wxSizeEvent& aEvent ) if( frame && frame->GetToolCanvas() ) parentWidth = frame->GetToolCanvas()->GetSize().GetWidth(); - if( barWidth != parentWidth ) SetSize( parentWidth, GetSize().GetHeight() ); + if( text ) + { + if( auto textCtrl = dynamic_cast( text->GetWindow() ) ) + { + // Re-wrap the text (this is done automatically later but we need it now) + // And count how many lines we need. If we have embedded newlines, then + // multiply the number of lines by the text min height to find the correct + // min height for the control. The min height of the text control will be the size + // of a single line of text. This assumes that two lines of text are larger + // than the height of the icon for the bar. + textCtrl->Wrap( text->GetSize().GetWidth() ); + wxString new_text = textCtrl->GetLabel(); + int height = ( new_text.Freq( '\n' ) + 1 ) * text->GetMinSize().GetHeight(); + SetMinSize( wxSize( GetSize().GetWidth(), height ) ); + } + } + aEvent.Skip(); } @@ -287,7 +316,9 @@ void WX_INFOBAR::AddButton( wxButton* aButton ) aButton->SetWindowVariant( wxWINDOW_VARIANT_SMALL ); #endif // __WXMAC__ - sizer->Add( aButton, wxSizerFlags().Centre().Border( wxRIGHT ) ); + auto element = sizer->Add( aButton, wxSizerFlags( 0 ).Centre().Border( wxRIGHT ) ); + + element->SetFlag( wxSTRETCH_MASK ); if( IsShownOnScreen() ) sizer->Layout(); @@ -300,7 +331,7 @@ void WX_INFOBAR::AddButton( wxHyperlinkCtrl* aHypertextButton ) wxASSERT( aHypertextButton ); - sizer->Add( aHypertextButton, wxSizerFlags().Centre().Border( wxRIGHT ) ); + sizer->Add( aHypertextButton, wxSizerFlags().Centre().Border( wxRIGHT ).Shaped() ); if( IsShownOnScreen() ) sizer->Layout(); diff --git a/include/widgets/wx_infobar.h b/include/widgets/wx_infobar.h index 9fb2a40b1d..6f80255cc7 100644 --- a/include/widgets/wx_infobar.h +++ b/include/widgets/wx_infobar.h @@ -262,6 +262,7 @@ protected: wxTimer* m_showTimer; ///< The timer counting the autoclose period wxAuiManager* m_auiManager; ///< The AUI manager that contains this infobar MESSAGE_TYPE m_type; ///< The type of message being displayed + wxString m_message; ///< The original message without wrapping std::optional> m_callback; ///< Optional callback made when closing infobar