KiCad PCB EDA Suite
Loading...
Searching...
No Matches
WX_INFOBAR Class Reference

A modified version of the wxInfoBar class that allows us to: More...

#include <wx_infobar.h>

Inheritance diagram for WX_INFOBAR:

Public Types

using MESSAGE_TYPE = INFOBAR_MESSAGE_TYPE
 

Public Member Functions

 WX_INFOBAR (wxWindow *aParent, wxWindowID aWinid=wxID_ANY, bool aOverlay=false)
 Construct an infobar.
 
 ~WX_INFOBAR ()
 
MESSAGE_TYPE GetMessageType () const
 
void SetShowTime (int aTime)
 Set the time period to show the infobar.
 
void AddCloseButton (const wxString &aTooltip=_("Hide this message."))
 Add the default close button to the infobar on the right side.
 
void AddButton (wxButton *aButton)
 Add an already created button to the infobar.
 
void AddLink (const wxString &aLinkText, const std::function< void(wxHyperlinkEvent &)> &aFn)
 Add a hypertext link to the infobar.
 
void AddButton (wxWindowID aId, const wxString &aLabel=wxEmptyString) override
 Add a button with the provided ID and text.
 
void RemoveAllButtons ()
 Remove all the buttons that have been added by the user.
 
bool HasCloseButton () const
 
wxBitmapButton * GetCloseButton () const
 
void SetCallback (std::function< void(void)> aCallback)
 Provide a callback to be called when the infobar is dismissed (either by user action or timer).
 
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.
 
void ShowMessage (const wxString &aMessage, int aFlags=wxICON_INFORMATION) override
 Show the info bar with the provided message and icon.
 
void ShowMessage (const wxString &aMessage, int aFlags, MESSAGE_TYPE aType)
 Show the info bar with the provided message and icon, setting the type.
 
void Dismiss () override
 Dismisses the infobar and updates the containing layout and AUI manager (if one is provided).
 
void QueueShowMessage (const wxString &aMessage, int aFlags=wxICON_INFORMATION)
 Send the infobar an event telling it to show a message.
 
void QueueDismiss ()
 Send the infobar an event telling it to hide itself.
 
void FixSize ()
 Address some long-standing bugs regarding infobars comming up only partial-width.
 

Protected Member Functions

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 onCloseButton (wxCommandEvent &aEvent)
 Event handler for the close button.
 
void onThemeChange (wxSysColourChangedEvent &aEvent)
 Event handler for the color theme change event.
 
void onTimer (wxTimerEvent &aEvent)
 Event handler for the automatic closing timer.
 
void onSize (wxSizeEvent &aEvent)
 
void doSize ()
 
void stackOverlays ()
 Lay out every overlay infobar sharing this one's parent as a top-anchored stack, so that two infobars on the same canvas do not cover each other.
 
void refreshParent ()
 Repaint the parent so that the area the infobar covered is not left stale.
 

Protected Attributes

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.
 
bool m_overlay
 True if this infobar is drawn on top of its parent.
 
wxTimer * m_showTimer
 The timer counting the autoclose period.
 
MESSAGE_TYPE m_type
 The type of message being displayed.
 
wxString m_message
 The original message without wrapping.
 
std::optional< std::function< void(void)> > m_callback
 Optional callback made when closing infobar.
 

Detailed Description

A modified version of the wxInfoBar class that allows us to:

  • Show the close button along with the other buttons
  • Remove all user-provided buttons at once
  • Allow automatically hiding the infobar after a time period
  • Show/hide using events
  • Overlay it on a drawing canvas

This inherits from the generic infobar because the native infobar on GTK doesn't include the icon on the left and it looks worse.

There are 2 events associated with the infobar:

KIEVT_SHOW_INFOBAR: An event that tells the infobar to show a message.

The message text is contained inside the string component, and the message flag is contained inside the int component.

Sample event creation code: wxCommandEvent* evt = new wxCommandEvent( KIEVT_SHOW_INFOBAR ); evt->SetString( "A message to show" ); evt->SetInt( wxICON_WARNING );

KIEVT_DISMISS_INFOBAR: An event that tells the infobar to hide itself.

Definition at line 75 of file wx_infobar.h.

Member Typedef Documentation

◆ MESSAGE_TYPE

Definition at line 94 of file wx_infobar.h.

Constructor & Destructor Documentation

◆ WX_INFOBAR()

WX_INFOBAR::WX_INFOBAR ( wxWindow * aParent,
wxWindowID aWinid = wxID_ANY,
bool aOverlay = false )

Construct an infobar.

In overlay mode the infobar is drawn on top of its parent and does not take space from it, so a drawing canvas parent keeps its size and does not have to repaint. Otherwise the infobar is laid out by the parent's sizer.

Parameters
aParentis the parent
aWinIdis the ID for this infobar object
aOverlayis true to overlay the parent instead of being laid out by its sizer

Definition at line 53 of file wx_infobar.cpp.

References GENERIC, DPI_SCALING_COMMON::GetContentScaleFactor(), KIPLATFORM::UI::GetInfoBarColours(), ID_CLOSE_INFOBAR, m_overlay, m_showTime, m_showTimer, m_type, m_updateLock, onSize(), RemoveAllButtons(), and WX_INFOBAR().

Referenced by stackOverlays(), and WX_INFOBAR().

◆ ~WX_INFOBAR()

WX_INFOBAR::~WX_INFOBAR ( )

Definition at line 109 of file wx_infobar.cpp.

References m_showTimer, and onSize().

Member Function Documentation

◆ AddButton() [1/2]

void WX_INFOBAR::AddButton ( wxButton * aButton)

Add an already created button to the infobar.

New buttons are added in the right-most position.

Parameters
aButtonis the button to add

Definition at line 397 of file wx_infobar.cpp.

Referenced by AddButton(), and AddCloseButton().

◆ AddButton() [2/2]

void WX_INFOBAR::AddButton ( wxWindowID aId,
const wxString & aLabel = wxEmptyString )
override

Add a button with the provided ID and text.

The new button is created on the right-most position.

Parameters
aIdis the ID to assign to the button
aLabelis the text for the button

Definition at line 389 of file wx_infobar.cpp.

References AddButton().

◆ AddCloseButton()

void WX_INFOBAR::AddCloseButton ( const wxString & aTooltip = _( "Hide this message." ))

Add the default close button to the infobar on the right side.

Parameters
aTooltipis the tooltip to give the close button

Definition at line 438 of file wx_infobar.cpp.

References AddButton(), and ID_CLOSE_INFOBAR.

Referenced by APPEARANCE_CONTROLS::onReadOnlySwatch(), onShowInfoBar(), onThemeChange(), EDIT_TOOL::Properties(), SCH_EDIT_TOOL::Properties(), SYMBOL_EDITOR_EDIT_TOOL::Properties(), APPEARANCE_CONTROLS_3D::rebuildLayers(), FOOTPRINT_EDIT_FRAME::updateInfoBar(), and SYMBOL_EDIT_FRAME::updateInfoBar().

◆ AddLink()

void WX_INFOBAR::AddLink ( const wxString & aLinkText,
const std::function< void(wxHyperlinkEvent &)> & aFn )

Add a hypertext link to the infobar.

Link is added in the right-most position.

Parameters
aLinkTextis the text to show
aFnis the function to execute if the link is clicked

Definition at line 421 of file wx_infobar.cpp.

Referenced by ZONE_FILLER_TOOL::FillAllZones(), APPEARANCE_CONTROLS::onReadOnlySwatch(), EDIT_TOOL::Properties(), SCH_EDIT_TOOL::Properties(), SYMBOL_EDITOR_EDIT_TOOL::Properties(), PCB_CONTROL::unfilledZoneCheck(), FOOTPRINT_EDIT_FRAME::updateInfoBar(), SYMBOL_EDIT_FRAME::updateInfoBar(), and ZONE_FILLER_TOOL::ZoneFillDirty().

◆ Dismiss()

void WX_INFOBAR::Dismiss ( )
override

◆ doSize()

void WX_INFOBAR::doSize ( )
protected

Definition at line 274 of file wx_infobar.cpp.

References m_message.

Referenced by FixSize(), and onSize().

◆ FixSize()

void WX_INFOBAR::FixSize ( )

Address some long-standing bugs regarding infobars comming up only partial-width.

Definition at line 241 of file wx_infobar.cpp.

References doSize().

Referenced by ShowMessage().

◆ GetCloseButton()

wxBitmapButton * WX_INFOBAR::GetCloseButton ( ) const

Definition at line 482 of file wx_infobar.cpp.

References ID_CLOSE_INFOBAR.

Referenced by HasCloseButton(), and onThemeChange().

◆ GetMessageType()

MESSAGE_TYPE WX_INFOBAR::GetMessageType ( ) const
inline

Definition at line 96 of file wx_infobar.h.

References m_type.

Referenced by DRAWING_TOOL::DrawVia().

◆ HasCloseButton()

bool WX_INFOBAR::HasCloseButton ( ) const

◆ onCloseButton()

void WX_INFOBAR::onCloseButton ( wxCommandEvent & aEvent)
protected

Event handler for the close button.

This is bound to ID_CLOSE_INFOBAR on the infobar.

Definition at line 518 of file wx_infobar.cpp.

References Dismiss().

Referenced by wxDEFINE_EVENT().

◆ onDismissInfoBar()

void WX_INFOBAR::onDismissInfoBar ( wxCommandEvent & aEvent)
protected

Event handler for dismissing the infobar using a wxCommandEvent of the type KIEVT_DISMISS_INFOBAR.

Definition at line 512 of file wx_infobar.cpp.

References Dismiss().

Referenced by wxDEFINE_EVENT().

◆ onShowInfoBar()

void WX_INFOBAR::onShowInfoBar ( wxCommandEvent & aEvent)
protected

Event handler for showing the infobar using a wxCommandEvent of the type KIEVT_SHOW_INFOBAR.

The message is stored inside the string field, and the icon flag is stored inside the int field.

Definition at line 504 of file wx_infobar.cpp.

References AddCloseButton(), RemoveAllButtons(), and ShowMessage().

Referenced by wxDEFINE_EVENT().

◆ onSize()

void WX_INFOBAR::onSize ( wxSizeEvent & aEvent)
protected

Definition at line 265 of file wx_infobar.cpp.

References doSize(), and stackOverlays().

Referenced by WX_INFOBAR(), and ~WX_INFOBAR().

◆ onThemeChange()

void WX_INFOBAR::onThemeChange ( wxSysColourChangedEvent & aEvent)
protected

Event handler for the color theme change event.

Definition at line 216 of file wx_infobar.cpp.

References AddCloseButton(), GetCloseButton(), KIPLATFORM::UI::GetInfoBarColours(), and RemoveAllButtons().

Referenced by wxDEFINE_EVENT().

◆ onTimer()

void WX_INFOBAR::onTimer ( wxTimerEvent & aEvent)
protected

Event handler for the automatic closing timer.

Definition at line 524 of file wx_infobar.cpp.

References Dismiss(), m_showTime, and m_showTimer.

Referenced by wxDEFINE_EVENT().

◆ QueueDismiss()

void WX_INFOBAR::QueueDismiss ( )

Send the infobar an event telling it to hide itself.

Definition at line 134 of file wx_infobar.cpp.

◆ QueueShowMessage()

void WX_INFOBAR::QueueShowMessage ( const wxString & aMessage,
int aFlags = wxICON_INFORMATION )

Send the infobar an event telling it to show a message.

Parameters
aMessageis the message to display
aFlagsis the flag containing the icon to display on the left side of the infobar

Definition at line 123 of file wx_infobar.cpp.

◆ refreshParent()

void WX_INFOBAR::refreshParent ( )
protected

Repaint the parent so that the area the infobar covered is not left stale.

Definition at line 369 of file wx_infobar.cpp.

References m_overlay.

Referenced by Dismiss().

◆ RemoveAllButtons()

◆ SetCallback()

void WX_INFOBAR::SetCallback ( std::function< void(void)> aCallback)
inline

Provide a callback to be called when the infobar is dismissed (either by user action or timer).

Parameters
aCallback

Definition at line 155 of file wx_infobar.h.

References m_callback.

◆ SetShowTime()

void WX_INFOBAR::SetShowTime ( int aTime)

Set the time period to show the infobar.

This only applies for the next showing of the infobar, so it must be reset every time. A value of 0 disables the automatic hiding (this is the default).

Parameters
aTimeis the time in milliseconds to show the infobar

Definition at line 117 of file wx_infobar.cpp.

References m_showTime.

◆ ShowMessage() [1/2]

void WX_INFOBAR::ShowMessage ( const wxString & aMessage,
int aFlags,
MESSAGE_TYPE aType )

Show the info bar with the provided message and icon, setting the type.

Parameters
aMessageis the message to display
aFlagsis the flag containing the icon to display on the left side of the infobar
aTypeis the type of message being displayed

Definition at line 181 of file wx_infobar.cpp.

References m_type, m_updateLock, and ShowMessage().

◆ ShowMessage() [2/2]

void WX_INFOBAR::ShowMessage ( const wxString & aMessage,
int aFlags = wxICON_INFORMATION )
override

Show the info bar with the provided message and icon.

Parameters
aMessageis the message to display
aFlagsis the flag containing the icon to display on the left side of the infobar

Definition at line 156 of file wx_infobar.cpp.

References FixSize(), m_message, m_showTime, m_showTimer, m_type, m_updateLock, and stackOverlays().

Referenced by PAD_TOOL::enterPadEditMode(), onShowInfoBar(), ShowMessage(), ShowMessageFor(), FOOTPRINT_EDIT_FRAME::updateInfoBar(), and SYMBOL_EDIT_FRAME::updateInfoBar().

◆ ShowMessageFor()

void WX_INFOBAR::ShowMessageFor ( const wxString & aMessage,
int aTime,
int aFlags = wxICON_INFORMATION,
MESSAGE_TYPE aType = WX_INFOBAR::MESSAGE_TYPE::GENERIC )

◆ stackOverlays()

void WX_INFOBAR::stackOverlays ( )
protected

Lay out every overlay infobar sharing this one's parent as a top-anchored stack, so that two infobars on the same canvas do not cover each other.

Definition at line 339 of file wx_infobar.cpp.

References m_overlay, and WX_INFOBAR().

Referenced by Dismiss(), onSize(), and ShowMessage().

Member Data Documentation

◆ m_callback

std::optional<std::function<void(void)> > WX_INFOBAR::m_callback
protected

Optional callback made when closing infobar.

Definition at line 264 of file wx_infobar.h.

Referenced by Dismiss(), and SetCallback().

◆ m_message

wxString WX_INFOBAR::m_message
protected

The original message without wrapping.

Definition at line 262 of file wx_infobar.h.

Referenced by doSize(), and ShowMessage().

◆ m_overlay

bool WX_INFOBAR::m_overlay
protected

True if this infobar is drawn on top of its parent.

Definition at line 259 of file wx_infobar.h.

Referenced by refreshParent(), stackOverlays(), and WX_INFOBAR().

◆ m_showTime

int WX_INFOBAR::m_showTime
protected

The time to show the infobar. 0 = don't auto hide.

Definition at line 257 of file wx_infobar.h.

Referenced by onTimer(), SetShowTime(), ShowMessage(), ShowMessageFor(), and WX_INFOBAR().

◆ m_showTimer

wxTimer* WX_INFOBAR::m_showTimer
protected

The timer counting the autoclose period.

Definition at line 260 of file wx_infobar.h.

Referenced by onTimer(), ShowMessage(), WX_INFOBAR(), and ~WX_INFOBAR().

◆ m_type

MESSAGE_TYPE WX_INFOBAR::m_type
protected

The type of message being displayed.

Definition at line 261 of file wx_infobar.h.

Referenced by GetMessageType(), ShowMessage(), ShowMessage(), ShowMessageFor(), and WX_INFOBAR().

◆ m_updateLock

bool WX_INFOBAR::m_updateLock
protected

True if this infobar requested the UI update.

Definition at line 258 of file wx_infobar.h.

Referenced by Dismiss(), ShowMessage(), ShowMessage(), ShowMessageFor(), and WX_INFOBAR().


The documentation for this class was generated from the following files: