24#include "wx/artprov.h"
25#include <wx/aui/framemanager.h>
26#include <wx/bmpbuttn.h>
28#include <wx/hyperlink.h>
29#include <wx/infobar.h>
31#include <wx/stattext.h>
33#include <wx/dcclient.h>
44BEGIN_EVENT_TABLE(
WX_INFOBAR, wxInfoBarGeneric )
55 : wxInfoBarGeneric( aParent, aWinid ),
66 SetBackgroundColour( bg );
67 SetForegroundColour( fg );
71 SetShowHideEffects( wxSHOW_EFFECT_ROLL_TO_BOTTOM, wxSHOW_EFFECT_ROLL_TO_TOP );
72 SetEffectDuration( 200 );
75 SetShowHideEffects( wxSHOW_EFFECT_NONE, wxSHOW_EFFECT_NONE );
85 wxSizer* sizer = GetSizer();
86 wxSize iconSize = wxArtProvider::GetSizeHint( wxART_BUTTON );
97 sizer->SetItemMinSize( (
size_t) 0, iconSize.x, sy );
126 wxCommandEvent* evt =
new wxCommandEvent( KIEVT_SHOW_INFOBAR );
128 evt->SetString( aMessage.c_str() );
129 evt->SetInt( aFlags );
131 GetEventHandler()->QueueEvent( evt );
137 wxCommandEvent* evt =
new wxCommandEvent( KIEVT_DISMISS_INFOBAR );
139 GetEventHandler()->QueueEvent( evt );
168 wxInfoBarGeneric::ShowMessage(
m_message, aFlags );
179 m_type = MESSAGE_TYPE::GENERIC;
198 if( !IsShownOnScreen() )
207 wxInfoBarGeneric::Dismiss();
223 SetBackgroundColour( bg );
224 SetForegroundColour( fg );
228 wxString tooltip = btn->GetToolTipText();
246 wxSizer* sizer = GetSizer();
248 if( !sizer || sizer->GetItemCount() == 0 )
251#if wxCHECK_VERSION( 3, 3, 0 )
257 wxWindow* icon = sizer->GetItem( (
size_t) 0 )->GetWindow();
262 sizer->Prepend( icon, 0, wxLEFT | wxRIGHT, 5 );
278 int barWidth = GetSize().GetWidth();
279 wxSizer* sizer = GetSizer();
286 #if wxCHECK_VERSION( 3, 3, 0 )
287 wxSizerItem* outerSizer = sizer->GetItem( (
size_t) 0 );
288 wxSizerItem* textSizer =
nullptr;
290 if (outerSizer->IsSizer())
292 wxBoxSizer* innerSizer1 =
dynamic_cast<wxBoxSizer*
>( outerSizer->GetSizer() );
293 wxBoxSizer* innerSizer2 =
294 dynamic_cast<wxBoxSizer*
>( innerSizer1->GetItem((
size_t)0)->GetSizer() );
297 textSizer = innerSizer2->GetItem( 1 );
300 wxSizerItem* textSizer = sizer->GetItem( 1 );
305 if( wxStaticText* textCtrl =
dynamic_cast<wxStaticText*
>( textSizer->GetWindow() ) )
313 int parentWidth = m_parent->GetClientSize().GetWidth();
319 if( barWidth != parentWidth )
320 SetSize( parentWidth, GetSize().GetHeight() );
324 if( wxStaticText* textCtrl =
dynamic_cast<wxStaticText*
>( textSizer->GetWindow() ) )
332 textCtrl->Wrap( -1 );
333 wxString wrapped_text = textCtrl->GetLabel();
334 int line_count = wrapped_text.Freq(
'\n' ) + 1;
336 wxWindowDC dc( textCtrl );
337 dc.GetTextExtent( wxT(
"Xp" ), &txt_h, &txt_v );
339 int height = txt_v * line_count;
340 int margins = txt_v - 1;
341 SetMinSize( wxSize( GetSize().GetWidth(), height + margins ) );
343 textCtrl->Wrap( -1 );
371 wxButton* button =
new wxButton(
this, aId, aLabel );
379 wxSizer* sizer = GetSizer();
386 aButton->SetWindowVariant( wxWINDOW_VARIANT_SMALL );
389 auto element = sizer->Add( aButton, wxSizerFlags( 0 ).Centre().Border( wxRIGHT ) );
391 element->SetFlag( wxSTRETCH_MASK );
393 if( IsShownOnScreen() )
403 wxSizer* sizer = GetSizer();
405 wxASSERT( aHypertextButton );
407 sizer->Add( aHypertextButton, wxSizerFlags().Centre().Border( wxRIGHT ).Shaped() );
409 if( IsShownOnScreen() )
419 wxBitmapButton* button = wxBitmapButton::NewCloseButton(
this,
ID_CLOSE_INFOBAR );
421 button->SetToolTip( aTooltip );
429 wxSizer* sizer = GetSizer();
431 if( sizer->GetItemCount() == 0 )
435 if( sizer->GetItem( sizer->GetItemCount() - 1 )->IsSpacer() )
438 for(
int i = (
int) sizer->GetItemCount() - 1; i >= 0; i-- )
440 wxSizerItem* sItem = sizer->GetItem( i );
443 if( sItem->IsSpacer() )
446 if( wxWindow* button = sItem->GetWindow() )
448 sizer->Detach( button );
463 wxSizer* sizer = GetSizer();
468 if( sizer->GetItemCount() == 0 )
471 if( sizer->GetItem( sizer->GetItemCount() - 1 )->IsSpacer() )
474 wxSizerItem* item = sizer->GetItem( sizer->GetItemCount() - 1 );
476 if( item && item->GetWindow() && item->GetWindow()->GetId() ==
ID_CLOSE_INFOBAR )
477 return static_cast<wxBitmapButton*
>( item->GetWindow() );
487 ShowMessage( aEvent.GetString(), aEvent.GetInt() );
514 const wxSize& aSize,
long aStyle,
const wxString& aName )
515 : wxPanel( aParent, aId, aPos, aSize, aStyle, aName )
528 wxASSERT( aInfoBar );
530 aInfoBar->Reparent(
this );
538 wxASSERT( aOtherItem );
540 aOtherItem->Reparent(
this );
550 m_message.reset(
new wxString( aText ) );
574 int icon = wxICON_NONE;
Class to handle configuration and automatic determination of the DPI scale to use for canvases.
double GetContentScaleFactor() const override
Get the content scale factor, which may be different from the scale factor on some platforms.
The base frame for deriving all KiCad main window classes.
EDA_INFOBAR_PANEL(wxWindow *aParent, wxWindowID aId=wxID_ANY, const wxPoint &aPos=wxDefaultPosition, const wxSize &aSize=wxSize(-1,-1), long aStyle=wxTAB_TRAVERSAL, const wxString &aName=wxEmptyString)
wxFlexGridSizer * m_mainSizer
void AddInfoBar(WX_INFOBAR *aInfoBar)
Add the given infobar object to the panel.
void AddOtherItem(wxWindow *aOtherItem)
Add the other item to the panel.
void Finalize()
Update the infobar with the reported text.
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
std::unique_ptr< wxString > m_message
bool HasMessage() const override
Returns true if any messages were reported.
A modified version of the wxInfoBar class that allows us to:
void FixSize()
Address some long-standing bugs regarding infobars comming up only partial-width.
void SetShowTime(int aTime)
Set the time period to show the infobar.
void RemoveAllButtons()
Remove all the buttons that have been added by the user.
void ShowMessageFor(const wxString &aMessage, int aTime, int aFlags=wxICON_INFORMATION, MESSAGE_TYPE aType=WX_INFOBAR::MESSAGE_TYPE::GENERIC)
Show the infobar with the provided message and icon for a specific period of time.
bool HasCloseButton() const
MESSAGE_TYPE m_type
The type of message being displayed.
INFOBAR_MESSAGE_TYPE MESSAGE_TYPE
void updateAuiLayout(bool aShow)
Update the AUI pane to show or hide this infobar.
std::optional< std::function< void(void)> > m_callback
Optional callback made when closing infobar.
wxString m_message
The original message without wrapping.
int m_showTime
The time to show the infobar. 0 = don't auto hide.
bool m_updateLock
True if this infobar requested the UI update.
void onShowInfoBar(wxCommandEvent &aEvent)
Event handler for showing the infobar using a wxCommandEvent of the type KIEVT_SHOW_INFOBAR.
void onDismissInfoBar(wxCommandEvent &aEvent)
Event handler for dismissing the infobar using a wxCommandEvent of the type KIEVT_DISMISS_INFOBAR.
void AddButton(wxButton *aButton)
Add an already created button to the infobar.
void QueueShowMessage(const wxString &aMessage, int aFlags=wxICON_INFORMATION)
Send the infobar an event telling it to show a message.
WX_INFOBAR(wxWindow *aParent, wxAuiManager *aMgr=nullptr, wxWindowID aWinid=wxID_ANY)
Construct an infobar that can exist inside an AUI managed frame.
void onCloseButton(wxCommandEvent &aEvent)
Event handler for the close button.
wxBitmapButton * GetCloseButton() const
void Dismiss() override
Dismisses the infobar and updates the containing layout and AUI manager (if one is provided).
void onThemeChange(wxSysColourChangedEvent &aEvent)
Event handler for the color theme change event.
void AddCloseButton(const wxString &aTooltip=_("Hide this message."))
Add the default close button to the infobar on the right side.
wxTimer * m_showTimer
The timer counting the autoclose period.
void onTimer(wxTimerEvent &aEvent)
Event handler for the automatic closing timer.
void ShowMessage(const wxString &aMessage, int aFlags=wxICON_INFORMATION) override
Show the info bar with the provided message and icon.
wxAuiManager * m_auiManager
The AUI manager that contains this infobar.
void onSize(wxSizeEvent &aEvent)
void QueueDismiss()
Send the infobar an event telling it to hide itself.
Base window classes and related definitions.
wxDEFINE_EVENT(KIEVT_SHOW_INFOBAR, wxCommandEvent)
@ ID_CLOSE_INFOBAR
ID for the close button on the frame's infobar.
@ GENERIC
GENERIC Are messages that do not have special handling.