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.
 
bool Layout () override
 Lay out the infobar, keeping the links and buttons level with the first line of a multi-line message.
 

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.
 
wxWindow * m_anchor
 The window this infobar spans, its parent unless hosted.
 
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.
 
wxBoxSizer * m_buttonArea
 The links and buttons, laid out apart from the message.
 
wxStaticText * m_messageText
 The message control, which wxInfoBarGeneric keeps private.
 
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 76 of file wx_infobar.h.

Member Typedef Documentation

◆ MESSAGE_TYPE

Definition at line 98 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.

Where the platform cannot draw a child over a canvas, an overlay infobar is hosted in a window of its own and aParent is not its direct parent.

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 80 of file wx_infobar.cpp.

References GENERIC, DPI_SCALING_COMMON::GetContentScaleFactor(), KIPLATFORM::UI::GetInfoBarColours(), ID_CLOSE_INFOBAR, Layout(), m_anchor, m_buttonArea, m_messageText, m_overlay, m_showTime, m_showTimer, m_type, m_updateLock, onSize(), overlayParent(), and text.

Referenced by stackOverlays().

◆ ~WX_INFOBAR()

WX_INFOBAR::~WX_INFOBAR ( )

Definition at line 159 of file wx_infobar.cpp.

References m_anchor, 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 488 of file wx_infobar.cpp.

References Layout(), and m_buttonArea.

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 480 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 528 of file wx_infobar.cpp.

References AddButton(), and ID_CLOSE_INFOBAR.

Referenced by APPEARANCE_CONTROLS::onReadOnlySwatch(), onShowInfoBar(), 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 511 of file wx_infobar.cpp.

References Layout(), and m_buttonArea.

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 357 of file wx_infobar.cpp.

References dc, m_anchor, and 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 299 of file wx_infobar.cpp.

References doSize(), and Layout().

Referenced by ShowMessage().

◆ GetCloseButton()

wxBitmapButton * WX_INFOBAR::GetCloseButton ( ) const

Definition at line 550 of file wx_infobar.cpp.

References ID_CLOSE_INFOBAR, and m_buttonArea.

Referenced by HasCloseButton(), and onThemeChange().

◆ GetMessageType()

MESSAGE_TYPE WX_INFOBAR::GetMessageType ( ) const
inline

Definition at line 100 of file wx_infobar.h.

References m_type.

Referenced by DRAWING_TOOL::DrawVia().

◆ HasCloseButton()

bool WX_INFOBAR::HasCloseButton ( ) const

◆ Layout()

bool WX_INFOBAR::Layout ( )
override

Lay out the infobar, keeping the links and buttons level with the first line of a multi-line message.

Definition at line 323 of file wx_infobar.cpp.

References m_buttonArea, m_messageText, text, and top().

Referenced by AddButton(), AddLink(), FixSize(), onThemeChange(), and WX_INFOBAR().

◆ 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 578 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 572 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 564 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 348 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 268 of file wx_infobar.cpp.

References GetCloseButton(), KIPLATFORM::UI::GetInfoBarColours(), ID_CLOSE_INFOBAR, and Layout().

Referenced by wxDEFINE_EVENT().

◆ onTimer()

void WX_INFOBAR::onTimer ( wxTimerEvent & aEvent)
protected

Event handler for the automatic closing timer.

Definition at line 584 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 184 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 173 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 460 of file wx_infobar.cpp.

References m_anchor, and 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 159 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 167 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 233 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 206 of file wx_infobar.cpp.

References FixSize(), KIPLATFORM::UI::KeepAboveExternalRendering(), 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 422 of file wx_infobar.cpp.

References m_anchor, m_overlay, and WX_INFOBAR().

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

Member Data Documentation

◆ m_anchor

wxWindow* WX_INFOBAR::m_anchor
protected

The window this infobar spans, its parent unless hosted.

Definition at line 271 of file wx_infobar.h.

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

◆ m_buttonArea

wxBoxSizer* WX_INFOBAR::m_buttonArea
protected

The links and buttons, laid out apart from the message.

Definition at line 275 of file wx_infobar.h.

Referenced by AddButton(), AddLink(), GetCloseButton(), Layout(), RemoveAllButtons(), and WX_INFOBAR().

◆ m_callback

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

Optional callback made when closing infobar.

Definition at line 278 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 274 of file wx_infobar.h.

Referenced by doSize(), and ShowMessage().

◆ m_messageText

wxStaticText* WX_INFOBAR::m_messageText
protected

The message control, which wxInfoBarGeneric keeps private.

Definition at line 276 of file wx_infobar.h.

Referenced by Layout(), and WX_INFOBAR().

◆ m_overlay

bool WX_INFOBAR::m_overlay
protected

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

Definition at line 270 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 268 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 272 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 273 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 269 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: