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 )
62 for( wxWindow* child : aParent->GetChildren() )
64 if( child->GetName() == OVERLAY_HOST_NAME )
70 host->SetName( OVERLAY_HOST_NAME );
79 : wxInfoBarGeneric(
overlayParent( aParent, aOverlay ), aWinid ),
91 SetBackgroundColour( bg );
92 SetForegroundColour( fg );
96 SetShowHideEffects( wxSHOW_EFFECT_ROLL_TO_BOTTOM, wxSHOW_EFFECT_ROLL_TO_TOP );
97 SetEffectDuration( 200 );
100 SetShowHideEffects( wxSHOW_EFFECT_NONE, wxSHOW_EFFECT_NONE );
110 wxSizer* sizer = GetSizer();
111 wxSize iconSize = wxArtProvider::GetSizeHint( wxART_BUTTON );
122 sizer->SetItemMinSize( (
size_t) 0, iconSize.x, sy );
128 wxSizerItem* lastItem = sizer->GetItem( sizer->GetItemCount() - 1 );
130 if( wxWindow* defaultCloseButton = lastItem ? lastItem->GetWindow() :
nullptr )
132 sizer->Detach( defaultCloseButton );
133 defaultCloseButton->Hide();
158 wxCommandEvent* evt =
new wxCommandEvent( KIEVT_SHOW_INFOBAR );
160 evt->SetString( aMessage.c_str() );
161 evt->SetInt( aFlags );
163 GetEventHandler()->QueueEvent( evt );
169 wxCommandEvent* evt =
new wxCommandEvent( KIEVT_DISMISS_INFOBAR );
171 GetEventHandler()->QueueEvent( evt );
200 wxInfoBarGeneric::ShowMessage(
m_message, aFlags );
211 m_type = MESSAGE_TYPE::GENERIC;
230 if( !IsShownOnScreen() )
239 wxInfoBarGeneric::Dismiss();
255 SetBackgroundColour( bg );
256 SetForegroundColour( fg );
261 wxBitmapButton* fresh = wxBitmapButton::NewCloseButton(
this,
ID_CLOSE_INFOBAR );
263 fresh->SetWindowVariant( wxWINDOW_VARIANT_SMALL );
265 fresh->SetToolTip( btn->GetToolTipText() );
266 GetSizer()->Replace( btn, fresh,
true );
284 wxSizer* sizer = GetSizer();
286 if( !sizer || sizer->GetItemCount() == 0 )
289#if wxCHECK_VERSION( 3, 3, 0 )
295 wxWindow* icon = sizer->GetItem( (
size_t) 0 )->GetWindow();
300 sizer->Prepend( icon, 0, wxLEFT | wxRIGHT, 5 );
317 int barWidth = GetSize().GetWidth();
318 wxSizer* sizer = GetSizer();
325 #if wxCHECK_VERSION( 3, 3, 0 )
326 wxSizerItem* outerSizer = sizer->GetItem( (
size_t) 0 );
327 wxSizerItem* textSizer =
nullptr;
329 if (outerSizer->IsSizer())
331 wxBoxSizer* innerSizer1 =
dynamic_cast<wxBoxSizer*
>( outerSizer->GetSizer() );
332 wxBoxSizer* innerSizer2 =
333 dynamic_cast<wxBoxSizer*
>( innerSizer1->GetItem((
size_t)0)->GetSizer() );
336 textSizer = innerSizer2->GetItem( 1 );
339 wxSizerItem* textSizer = sizer->GetItem( 1 );
344 if( wxStaticText* textCtrl =
dynamic_cast<wxStaticText*
>( textSizer->GetWindow() ) )
348 int parentWidth =
m_anchor->GetClientSize().GetWidth();
350 if( barWidth != parentWidth )
351 SetSize( parentWidth, GetSize().GetHeight() );
355 if( wxStaticText* textCtrl =
dynamic_cast<wxStaticText*
>( textSizer->GetWindow() ) )
363 textCtrl->Wrap( -1 );
364 wxString wrapped_text = textCtrl->GetLabel();
365 int line_count = wrapped_text.Freq(
'\n' ) + 1;
367 wxWindowDC dc( textCtrl );
368 dc.GetTextExtent( wxT(
"Xp" ), &txt_h, &txt_v );
370 int height = txt_v * line_count;
371 int margins = txt_v - 1;
372 SetMinSize( wxSize( GetSize().GetWidth(), height + margins ) );
374 textCtrl->Wrap( -1 );
385 int width =
m_anchor->GetClientSize().GetWidth();
388 for( wxWindow* child : m_parent->GetChildren() )
392 if( !bar || !bar->IsShown() )
395 int height = bar->GetEffectiveMinSize().GetHeight();
397 bar->SetSize( 0, y, width, height );
408 m_parent->SetSize( wxDefaultCoord, wxDefaultCoord, width, y );
410 m_parent->Show( y > 0 );
414 canvas->UpdateOverlayExclusions();
426 canvas->ForceRefresh();
429 canvas->RequestRefresh();
440 wxButton* button =
new wxButton(
this, aId, aLabel );
448 wxSizer* sizer = GetSizer();
455 aButton->SetWindowVariant( wxWINDOW_VARIANT_SMALL );
458 auto element = sizer->Add( aButton, wxSizerFlags( 0 ).Centre().Border( wxRIGHT ) );
460 element->SetFlag( wxSTRETCH_MASK );
462 if( IsShownOnScreen() )
472 wxSizer* sizer = GetSizer();
473 wxHyperlinkCtrl* button =
new wxHyperlinkCtrl(
this, wxID_ANY, aLinkText, wxEmptyString );
475 button->Bind( wxEVT_COMMAND_HYPERLINK, aFn );
477 sizer->Add( button, wxSizerFlags().Centre().Border( wxRIGHT ).Shaped() );
479 if( IsShownOnScreen() )
489 wxBitmapButton* button = wxBitmapButton::NewCloseButton(
this,
ID_CLOSE_INFOBAR );
491 button->SetToolTip( aTooltip );
499 wxSizer* sizer = GetSizer();
501 if( sizer->GetItemCount() == 0 )
505 if( sizer->GetItem( sizer->GetItemCount() - 1 )->IsSpacer() )
508 for(
int i = (
int) sizer->GetItemCount() - 1; i >= 0; i-- )
510 wxSizerItem* sItem = sizer->GetItem( i );
513 if( sItem->IsSpacer() )
516 if( wxWindow* button = sItem->GetWindow() )
518 sizer->Detach( button );
533 wxSizer* sizer = GetSizer();
538 if( sizer->GetItemCount() == 0 )
541 if( sizer->GetItem( sizer->GetItemCount() - 1 )->IsSpacer() )
544 wxSizerItem* item = sizer->GetItem( sizer->GetItemCount() - 1 );
546 if( item && item->GetWindow() && item->GetWindow()->GetId() ==
ID_CLOSE_INFOBAR )
547 return static_cast<wxBitmapButton*
>( item->GetWindow() );
557 ShowMessage( aEvent.GetString(), aEvent.GetInt() );
584 const wxSize& aSize,
long aStyle,
const wxString& aName )
585 : wxPanel( aParent, aId, aPos, aSize, aStyle, aName )
598 wxASSERT( aInfoBar );
600 aInfoBar->Reparent(
this );
608 wxASSERT( aOtherItem );
610 aOtherItem->Reparent(
this );
620 m_message.reset(
new wxString( aText ) );
647 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.
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.
WX_INFOBAR(wxWindow *aParent, wxWindowID aWinId=wxID_ANY, bool aOverlay=false)
Construct an infobar.
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.
wxWindow * m_anchor
The window this infobar spans, its parent unless hosted.
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)
static wxWindow * overlayParent(wxWindow *aParent, bool aOverlay)
static const wxString OVERLAY_HOST_NAME
@ ID_CLOSE_INFOBAR
ID for the close button on the frame's infobar.
@ GENERIC
GENERIC Are messages that do not have special handling.