25#include "wx/artprov.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>
43BEGIN_EVENT_TABLE(
WX_INFOBAR, wxInfoBarGeneric )
54 : wxInfoBarGeneric( aParent, aWinid ),
65 SetBackgroundColour( bg );
66 SetForegroundColour( fg );
70 SetShowHideEffects( wxSHOW_EFFECT_ROLL_TO_BOTTOM, wxSHOW_EFFECT_ROLL_TO_TOP );
71 SetEffectDuration( 200 );
74 SetShowHideEffects( wxSHOW_EFFECT_NONE, wxSHOW_EFFECT_NONE );
84 wxSizer* sizer = GetSizer();
85 wxSize iconSize = wxArtProvider::GetSizeHint( wxART_BUTTON );
96 sizer->SetItemMinSize( (
size_t) 0, iconSize.x, sy );
125 wxCommandEvent* evt =
new wxCommandEvent( KIEVT_SHOW_INFOBAR );
127 evt->SetString( aMessage.c_str() );
128 evt->SetInt( aFlags );
130 GetEventHandler()->QueueEvent( evt );
136 wxCommandEvent* evt =
new wxCommandEvent( KIEVT_DISMISS_INFOBAR );
138 GetEventHandler()->QueueEvent( evt );
167 wxInfoBarGeneric::ShowMessage(
m_message, aFlags );
176 m_type = MESSAGE_TYPE::GENERIC;
195 if( !IsShownOnScreen() )
204 wxInfoBarGeneric::Dismiss();
220 SetBackgroundColour( bg );
221 SetForegroundColour( fg );
225 wxString tooltip = btn->GetToolTipText();
243 wxSizer* sizer = GetSizer();
245 if( !sizer || sizer->GetItemCount() == 0 )
248#if wxCHECK_VERSION( 3, 3, 0 )
254 wxWindow* icon = sizer->GetItem( (
size_t) 0 )->GetWindow();
259 sizer->Prepend( icon, 0, wxLEFT | wxRIGHT, 5 );
276 int barWidth = GetSize().GetWidth();
277 wxSizer* sizer = GetSizer();
284 #if wxCHECK_VERSION( 3, 3, 0 )
285 wxSizerItem* outerSizer = sizer->GetItem( (
size_t) 0 );
286 wxSizerItem* textSizer =
nullptr;
288 if (outerSizer->IsSizer())
290 wxBoxSizer* innerSizer1 =
dynamic_cast<wxBoxSizer*
>( outerSizer->GetSizer() );
291 wxBoxSizer* innerSizer2 =
292 dynamic_cast<wxBoxSizer*
>( innerSizer1->GetItem((
size_t)0)->GetSizer() );
295 textSizer = innerSizer2->GetItem( 1 );
298 wxSizerItem* textSizer = sizer->GetItem( 1 );
303 if( wxStaticText* textCtrl =
dynamic_cast<wxStaticText*
>( textSizer->GetWindow() ) )
307 int parentWidth = m_parent->GetClientSize().GetWidth();
309 if( barWidth != parentWidth )
310 SetSize( parentWidth, GetSize().GetHeight() );
314 if( wxStaticText* textCtrl =
dynamic_cast<wxStaticText*
>( textSizer->GetWindow() ) )
322 textCtrl->Wrap( -1 );
323 wxString wrapped_text = textCtrl->GetLabel();
324 int line_count = wrapped_text.Freq(
'\n' ) + 1;
326 wxWindowDC dc( textCtrl );
327 dc.GetTextExtent( wxT(
"Xp" ), &txt_h, &txt_v );
329 int height = txt_v * line_count;
330 int margins = txt_v - 1;
331 SetMinSize( wxSize( GetSize().GetWidth(), height + margins ) );
333 textCtrl->Wrap( -1 );
344 int width = m_parent->GetClientSize().GetWidth();
347 for( wxWindow* child : m_parent->GetChildren() )
351 if( !bar || !bar->IsShown() )
354 int height = bar->GetEffectiveMinSize().GetHeight();
356 bar->SetSize( 0, y, width, height );
365 canvas->UpdateOverlayExclusions();
377 canvas->ForceRefresh();
380 canvas->RequestRefresh();
391 wxButton* button =
new wxButton(
this, aId, aLabel );
399 wxSizer* sizer = GetSizer();
406 aButton->SetWindowVariant( wxWINDOW_VARIANT_SMALL );
409 auto element = sizer->Add( aButton, wxSizerFlags( 0 ).Centre().Border( wxRIGHT ) );
411 element->SetFlag( wxSTRETCH_MASK );
413 if( IsShownOnScreen() )
423 wxSizer* sizer = GetSizer();
424 wxHyperlinkCtrl* button =
new wxHyperlinkCtrl(
this, wxID_ANY, aLinkText, wxEmptyString );
426 button->Bind( wxEVT_COMMAND_HYPERLINK, aFn );
428 sizer->Add( button, wxSizerFlags().Centre().Border( wxRIGHT ).Shaped() );
430 if( IsShownOnScreen() )
440 wxBitmapButton* button = wxBitmapButton::NewCloseButton(
this,
ID_CLOSE_INFOBAR );
442 button->SetToolTip( aTooltip );
450 wxSizer* sizer = GetSizer();
452 if( sizer->GetItemCount() == 0 )
456 if( sizer->GetItem( sizer->GetItemCount() - 1 )->IsSpacer() )
459 for(
int i = (
int) sizer->GetItemCount() - 1; i >= 0; i-- )
461 wxSizerItem* sItem = sizer->GetItem( i );
464 if( sItem->IsSpacer() )
467 if( wxWindow* button = sItem->GetWindow() )
469 sizer->Detach( button );
484 wxSizer* sizer = GetSizer();
489 if( sizer->GetItemCount() == 0 )
492 if( sizer->GetItem( sizer->GetItemCount() - 1 )->IsSpacer() )
495 wxSizerItem* item = sizer->GetItem( sizer->GetItemCount() - 1 );
497 if( item && item->GetWindow() && item->GetWindow()->GetId() ==
ID_CLOSE_INFOBAR )
498 return static_cast<wxBitmapButton*
>( item->GetWindow() );
508 ShowMessage( aEvent.GetString(), aEvent.GetInt() );
535 const wxSize& aSize,
long aStyle,
const wxString& aName )
536 : wxPanel( aParent, aId, aPos, aSize, aStyle, aName )
549 wxASSERT( aInfoBar );
551 aInfoBar->Reparent(
this );
559 wxASSERT( aOtherItem );
561 aOtherItem->Reparent(
this );
571 m_message.reset(
new wxString( aText ) );
598 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.
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.
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
void Finalize() override
Update the infobar with the reported text.
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 refreshParent()
Repaint the parent so that the area the infobar covered is not left stale.
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.
bool m_overlay
True if this infobar is drawn on top of its parent.
INFOBAR_MESSAGE_TYPE MESSAGE_TYPE
void AddLink(const wxString &aLinkText, const std::function< void(wxHyperlinkEvent &)> &aFn)
Add a hypertext link to the infobar.
WX_INFOBAR(wxWindow *aParent, wxWindowID aWinid=wxID_ANY, bool aOverlay=false)
Construct an infobar.
void stackOverlays()
Lay out every overlay infobar sharing this one's parent as a top-anchored stack, so that two infobars...
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.
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.
void onSize(wxSizeEvent &aEvent)
void QueueDismiss()
Send the infobar an event telling it to hide itself.
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.