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>
45BEGIN_EVENT_TABLE(
WX_INFOBAR, wxInfoBarGeneric )
64 for( wxWindow* child : aParent->GetChildren() )
66 if( child->GetName() == OVERLAY_HOST_NAME )
72 host->SetName( OVERLAY_HOST_NAME );
81 : wxInfoBarGeneric(
overlayParent( aParent, aOverlay ), aWinid ),
95 SetBackgroundColour( bg );
96 SetForegroundColour( fg );
100 SetShowHideEffects( wxSHOW_EFFECT_ROLL_TO_BOTTOM, wxSHOW_EFFECT_ROLL_TO_TOP );
101 SetEffectDuration( 200 );
104 SetShowHideEffects( wxSHOW_EFFECT_NONE, wxSHOW_EFFECT_NONE );
114 wxSizer* sizer = GetSizer();
115 wxSize iconSize = wxArtProvider::GetSizeHint( wxART_BUTTON );
126 sizer->SetItemMinSize( (
size_t) 0, iconSize.x, sy );
132 wxSizerItem* lastItem = sizer->GetItem( sizer->GetItemCount() - 1 );
134 if( wxWindow* defaultCloseButton = lastItem ? lastItem->GetWindow() :
nullptr )
136 sizer->Detach( defaultCloseButton );
137 defaultCloseButton->Hide();
142 sizer->Add(
m_buttonArea, wxSizerFlags().Expand().Border( wxLEFT ) );
144 for( wxWindow* child : GetChildren() )
146 if( wxStaticText*
text =
dynamic_cast<wxStaticText*
>( child ) )
175 wxCommandEvent* evt =
new wxCommandEvent( KIEVT_SHOW_INFOBAR );
177 evt->SetString( aMessage.c_str() );
178 evt->SetInt( aFlags );
180 GetEventHandler()->QueueEvent( evt );
186 wxCommandEvent* evt =
new wxCommandEvent( KIEVT_DISMISS_INFOBAR );
188 GetEventHandler()->QueueEvent( evt );
217 wxInfoBarGeneric::ShowMessage(
m_message, aFlags );
228 m_type = MESSAGE_TYPE::GENERIC;
247 if( !IsShownOnScreen() )
256 wxInfoBarGeneric::Dismiss();
272 SetBackgroundColour( bg );
273 SetForegroundColour( fg );
278 wxBitmapButton* fresh = wxBitmapButton::NewCloseButton(
this,
ID_CLOSE_INFOBAR );
280 fresh->SetWindowVariant( wxWINDOW_VARIANT_SMALL );
282 fresh->SetToolTip( btn->GetToolTipText() );
283 GetSizer()->Replace( btn, fresh,
true );
301 wxSizer* sizer = GetSizer();
303 if( !sizer || sizer->GetItemCount() == 0 )
306#if wxCHECK_VERSION( 3, 3, 0 )
312 wxWindow* icon = sizer->GetItem( (
size_t) 0 )->GetWindow();
317 sizer->Prepend( icon, 0, wxLEFT | wxRIGHT, 5 );
325 bool laidOut = wxInfoBarGeneric::Layout();
336 int lineCentre =
text.y +
text.height / ( 2 * lineCount );
337 int height = std::max( 2 * lineCentre,
m_buttonArea->GetMinSize().y );
338 int top = std::clamp( lineCentre - height / 2, 0, std::max( 0, GetClientSize().y - height ) );
359 int barWidth = GetSize().GetWidth();
360 wxSizer* sizer = GetSizer();
367 #if wxCHECK_VERSION( 3, 3, 0 )
368 wxSizerItem* outerSizer = sizer->GetItem( (
size_t) 0 );
369 wxSizerItem* textSizer =
nullptr;
371 if (outerSizer->IsSizer())
373 wxBoxSizer* innerSizer1 =
dynamic_cast<wxBoxSizer*
>( outerSizer->GetSizer() );
374 wxBoxSizer* innerSizer2 =
375 dynamic_cast<wxBoxSizer*
>( innerSizer1->GetItem((
size_t)0)->GetSizer() );
378 textSizer = innerSizer2->GetItem( 1 );
381 wxSizerItem* textSizer = sizer->GetItem( 1 );
386 if( wxStaticText* textCtrl =
dynamic_cast<wxStaticText*
>( textSizer->GetWindow() ) )
390 int parentWidth =
m_anchor->GetClientSize().GetWidth();
392 if( barWidth != parentWidth )
393 SetSize( parentWidth, GetSize().GetHeight() );
397 if( wxStaticText* textCtrl =
dynamic_cast<wxStaticText*
>( textSizer->GetWindow() ) )
405 textCtrl->Wrap( -1 );
406 wxString wrapped_text = textCtrl->GetLabel();
407 int line_count = wrapped_text.Freq(
'\n' ) + 1;
409 wxWindowDC
dc( textCtrl );
410 dc.GetTextExtent( wxT(
"Xp" ), &txt_h, &txt_v );
412 int height = txt_v * line_count;
413 int margins = txt_v - 1;
414 SetMinSize( wxSize( GetSize().GetWidth(), height + margins ) );
416 textCtrl->Wrap( -1 );
427 int width =
m_anchor->GetClientSize().GetWidth();
430 for( wxWindow* child : m_parent->GetChildren() )
434 if( !bar || !bar->IsShown() )
437 int height = bar->GetEffectiveMinSize().GetHeight();
439 bar->SetSize( 0, y, width, height );
450 m_parent->SetSize( wxDefaultCoord, wxDefaultCoord, width, y );
452 m_parent->Show( y > 0 );
456 canvas->UpdateOverlayExclusions();
468 canvas->ForceRefresh();
471 canvas->RequestRefresh();
482 wxButton* button =
new wxButton(
this, aId, aLabel );
490 wxSizer* sizer = GetSizer();
497 aButton->SetWindowVariant( wxWINDOW_VARIANT_SMALL );
503 if( IsShownOnScreen() )
513 wxSizer* sizer = GetSizer();
514 wxHyperlinkCtrl* button =
new wxHyperlinkCtrl(
this, wxID_ANY, aLinkText, wxEmptyString );
516 button->Bind( wxEVT_COMMAND_HYPERLINK, aFn );
518 m_buttonArea->Add( button, wxSizerFlags().Centre().Border( wxRIGHT ).Shaped() );
520 if( IsShownOnScreen() )
530 wxBitmapButton* button = wxBitmapButton::NewCloseButton(
this,
ID_CLOSE_INFOBAR );
532 button->SetToolTip( aTooltip );
557 if( item && item->GetWindow() && item->GetWindow()->GetId() ==
ID_CLOSE_INFOBAR )
558 return static_cast<wxBitmapButton*
>( item->GetWindow() );
568 ShowMessage( aEvent.GetString(), aEvent.GetInt() );
595 const wxSize& aSize,
long aStyle,
const wxString& aName )
596 : wxPanel( aParent, aId, aPos, aSize, aStyle, aName )
609 wxASSERT( aInfoBar );
611 aInfoBar->Reparent(
this );
619 wxASSERT( aOtherItem );
621 aOtherItem->Reparent(
this );
631 m_message.reset(
new wxString( aText ) );
658 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
wxStaticText * m_messageText
The message control, which wxInfoBarGeneric keeps private.
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.
wxBoxSizer * m_buttonArea
The links and buttons, laid out apart from the message.
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.
bool Layout() override
Lay out the infobar, keeping the links and buttons level with the first line of a multi-line message.
DATABASE_CONNECTION dc(odbcBackend(cs))
KIBIS top(path, &reporter)
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.