KiCad PCB EDA Suite
WX_INFOBAR Class Reference

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

#include <infobar.h>

Inheritance diagram for WX_INFOBAR:

Public Member Functions

 WX_INFOBAR (wxWindow *aParent, wxAuiManager *aMgr=nullptr, wxWindowID aWinid=wxID_ANY)
 Construct an infobar that can exist inside an AUI managed frame. More...
 
 ~WX_INFOBAR ()
 
void SetShowTime (int aTime)
 Set the time period to show the infobar. More...
 
void AddCloseButton (const wxString &aTooltip=_("Hide this message."))
 Add the default close button to the infobar on the right side. More...
 
void AddButton (wxButton *aButton)
 Add an already created button to the infobar. More...
 
void AddButton (wxHyperlinkCtrl *aHypertextButton)
 Add an already created hypertext link to the infobar. More...
 
void AddButton (wxWindowID aId, const wxString &aLabel=wxEmptyString) override
 Add a button with the provided ID and text. More...
 
void RemoveAllButtons ()
 Remove all the buttons that have been added by the user. More...
 
void ShowMessageFor (const wxString &aMessage, int aTime, int aFlags=wxICON_INFORMATION)
 Show the infobar with the provided message and icon for a specific period of time. More...
 
void ShowMessage (const wxString &aMessage, int aFlags=wxICON_INFORMATION) override
 Show the info bar with the provided message and icon. More...
 
void Dismiss () override
 Dismisses the infobar and updates the containing layout and AUI manager (if one is provided). More...
 
void QueueShowMessage (const wxString &aMessage, int aFlags=wxICON_INFORMATION)
 Send the infobar an event telling it to show a message. More...
 
void QueueDismiss ()
 Send the infobar an event telling it to hide itself. More...
 
bool IsLocked ()
 Returns true if the infobar is being updated. More...
 

Protected Member Functions

void OnShowInfoBar (wxCommandEvent &aEvent)
 Event handler for showing the infobar using a wxCommandEvent of the type KIEVT_SHOW_INFOBAR. More...
 
void OnDismissInfoBar (wxCommandEvent &aEvent)
 Event handler for dismissing the infobar using a wxCommandEvent of the type KIEVT_DISMISS_INFOBAR. More...
 
void OnCloseButton (wxCommandEvent &aEvent)
 Event handler for the close button. More...
 
void OnTimer (wxTimerEvent &aEvent)
 Event handler for the automatic closing timer. More...
 
void UpdateAuiLayout (bool aShow)
 Update the AUI pane to show or hide this infobar. More...
 

Protected Attributes

int m_showTime
 The time to show the infobar. 0 = don't auto hide. More...
 
bool m_updateLock
 True if this infobar requested the UI update. More...
 
wxTimer * m_showTimer
 The timer counting the autoclose period. More...
 
wxAuiManager * m_auiManager
 The AUI manager that contains this infobar. More...
 

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 automaticly hiding the infobar after a time period
  • Show/hide using events
  • Place it inside an AUI manager

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 70 of file infobar.h.

Constructor & Destructor Documentation

◆ WX_INFOBAR()

WX_INFOBAR::WX_INFOBAR ( wxWindow *  aParent,
wxAuiManager *  aMgr = nullptr,
wxWindowID  aWinid = wxID_ANY 
)

Construct an infobar that can exist inside an AUI managed frame.

Parameters
aParentis the parent
aMgris the AUI manager that this infobar is added to
aWinIdis the ID for this infobar object

Definition at line 44 of file infobar.cpp.

45  : wxInfoBarGeneric( aParent, aWinid ),
46  m_showTime( 0 ),
47  m_updateLock( false ),
48  m_showTimer( nullptr ),
49  m_auiManager( aMgr )
50 {
51  m_showTimer = new wxTimer( this, ID_CLOSE_INFOBAR );
52 
53  // Don't use any effects since they leave the sizer area visible under the infobar
54  SetShowHideEffects( wxSHOW_EFFECT_NONE, wxSHOW_EFFECT_NONE );
55 
56  // The infobar seems to start too small, so increase its height
57  int sx, sy;
58  GetSize( &sx, &sy );
59  sy = 1.5 * sy;
60  SetSize( sx, sy );
61 
62  // The bitmap gets cutoff sometimes with the default size, so force it to be the same
63  // height as the infobar.
64  wxSizer* sizer = GetSizer();
65  wxSize iconSize = wxArtProvider::GetSizeHint( wxART_BUTTON );
66 
67  sizer->SetItemMinSize( (size_t) 0, iconSize.x, sy );
68 
69  // Forcefully remove all existing buttons added by the wx constructors.
70  // The default close button doesn't work with the AUI manager update scheme, so this
71  // ensures any close button displayed is ours.
73 
74  Layout();
75 }
wxTimer * m_showTimer
The timer counting the autoclose period.
Definition: infobar.h:211
ID for the close button on the frame's infobar.
Definition: infobar.h:36
void RemoveAllButtons()
Remove all the buttons that have been added by the user.
Definition: infobar.cpp:226
wxAuiManager * m_auiManager
The AUI manager that contains this infobar.
Definition: infobar.h:212
bool m_updateLock
True if this infobar requested the UI update.
Definition: infobar.h:210
int m_showTime
The time to show the infobar. 0 = don't auto hide.
Definition: infobar.h:209

References ID_CLOSE_INFOBAR.

◆ ~WX_INFOBAR()

WX_INFOBAR::~WX_INFOBAR ( )

Definition at line 78 of file infobar.cpp.

79 {
80  delete m_showTimer;
81 }
wxTimer * m_showTimer
The timer counting the autoclose period.
Definition: infobar.h:211

References m_showTimer.

Member Function Documentation

◆ AddButton() [1/3]

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 185 of file infobar.cpp.

186 {
187  wxSizer* sizer = GetSizer();
188 
189  wxASSERT( aButton );
190 
191 #ifdef __WXMAC__
192  // Based on the code in the original class:
193  // smaller buttons look better in the (narrow) info bar under OS X
194  aButton->SetWindowVariant( wxWINDOW_VARIANT_SMALL );
195 #endif // __WXMAC__
196  sizer->Add( aButton, wxSizerFlags().Centre().Border( wxRIGHT ) );
197 
198  if( IsShown() )
199  sizer->Layout();
200 }

Referenced by AddButton(), AddCloseButton(), ZONE_FILLER_TOOL::FillAllZones(), APPEARANCE_CONTROLS::onReadOnlySwatch(), and ROUTER_TOOL::onViaCommand().

◆ AddButton() [2/3]

void WX_INFOBAR::AddButton ( wxHyperlinkCtrl *  aHypertextButton)

Add an already created hypertext link to the infobar.

New buttons are added in the right-most position.

Parameters
aHypertextButtonis the button to add

Definition at line 203 of file infobar.cpp.

204 {
205  wxSizer* sizer = GetSizer();
206 
207  wxASSERT( aHypertextButton );
208 
209  sizer->Add( aHypertextButton, wxSizerFlags().Centre().Border( wxRIGHT ) );
210 
211  if( IsShown() )
212  sizer->Layout();
213 }

◆ AddButton() [3/3]

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 positon.

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

Definition at line 177 of file infobar.cpp.

178 {
179  wxButton* button = new wxButton( this, aId, aLabel );
180 
181  AddButton( button );
182 }
void AddButton(wxButton *aButton)
Add an already created button to the infobar.
Definition: infobar.cpp:185

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 216 of file infobar.cpp.

217 {
218  wxBitmapButton* button = wxBitmapButton::NewCloseButton( this, ID_CLOSE_INFOBAR );
219 
220  button->SetToolTip( aTooltip );
221 
222  AddButton( button );
223 }
void AddButton(wxButton *aButton)
Add an already created button to the infobar.
Definition: infobar.cpp:185
ID for the close button on the frame's infobar.
Definition: infobar.h:36

References AddButton(), and ID_CLOSE_INFOBAR.

Referenced by PL_EDITOR_FRAME::LoadPageLayoutDescrFile(), APPEARANCE_CONTROLS::onReadOnlySwatch(), OnShowInfoBar(), SCH_EDIT_FRAME::OpenProjectFiles(), and SCH_EDIT_FRAME::ShowFindReplaceStatus().

◆ Dismiss()

void WX_INFOBAR::Dismiss ( )
override

Dismisses the infobar and updates the containing layout and AUI manager (if one is provided).

Definition at line 140 of file infobar.cpp.

141 {
142  // Don't do anything if we requested the UI update
143  if( m_updateLock )
144  return;
145 
146  m_updateLock = true;
147 
148  wxInfoBarGeneric::Dismiss();
149 
150  if( m_auiManager )
151  UpdateAuiLayout( false );
152 
153  m_updateLock = false;
154 }
wxAuiManager * m_auiManager
The AUI manager that contains this infobar.
Definition: infobar.h:212
bool m_updateLock
True if this infobar requested the UI update.
Definition: infobar.h:210
void UpdateAuiLayout(bool aShow)
Update the AUI pane to show or hide this infobar.
Definition: infobar.cpp:157

References m_auiManager, m_updateLock, and UpdateAuiLayout().

Referenced by SCH_EDIT_FRAME::ClearFindReplaceStatus(), PAD_TOOL::EditPad(), DISPLAY_FOOTPRINTS_FRAME::InitDisplay(), LIB_EDIT_FRAME::LoadOneLibraryPartAux(), PL_EDITOR_FRAME::LoadPageLayoutDescrFile(), OnCloseButton(), OnDismissInfoBar(), OnTimer(), and SCH_EDIT_FRAME::OpenProjectFiles().

◆ IsLocked()

bool WX_INFOBAR::IsLocked ( )
inline

Returns true if the infobar is being updated.

Definition at line 172 of file infobar.h.

173  {
174  return m_updateLock;
175  }
bool m_updateLock
True if this infobar requested the UI update.
Definition: infobar.h:210

References m_updateLock.

Referenced by EDA_DRAW_PANEL_GAL::onSize().

◆ 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 264 of file infobar.cpp.

265 {
266  Dismiss();
267 }
void Dismiss() override
Dismisses the infobar and updates the containing layout and AUI manager (if one is provided).
Definition: infobar.cpp:140

References Dismiss().

◆ 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 258 of file infobar.cpp.

259 {
260  Dismiss();
261 }
void Dismiss() override
Dismisses the infobar and updates the containing layout and AUI manager (if one is provided).
Definition: infobar.cpp:140

References Dismiss().

◆ 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 250 of file infobar.cpp.

251 {
253  AddCloseButton();
254  ShowMessage( aEvent.GetString(), aEvent.GetInt() );
255 }
void ShowMessage(const wxString &aMessage, int aFlags=wxICON_INFORMATION) override
Show the info bar with the provided message and icon.
Definition: infobar.cpp:120
void RemoveAllButtons()
Remove all the buttons that have been added by the user.
Definition: infobar.cpp:226
void AddCloseButton(const wxString &aTooltip=_("Hide this message."))
Add the default close button to the infobar on the right side.
Definition: infobar.cpp:216

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

◆ OnTimer()

void WX_INFOBAR::OnTimer ( wxTimerEvent &  aEvent)
protected

Event handler for the automatic closing timer.

Definition at line 270 of file infobar.cpp.

271 {
272  // Reset and clear the timer
273  m_showTimer->Stop();
274  m_showTime = 0;
275 
276  Dismiss();
277 }
wxTimer * m_showTimer
The timer counting the autoclose period.
Definition: infobar.h:211
void Dismiss() override
Dismisses the infobar and updates the containing layout and AUI manager (if one is provided).
Definition: infobar.cpp:140
int m_showTime
The time to show the infobar. 0 = don't auto hide.
Definition: infobar.h:209

References Dismiss(), m_showTime, and m_showTimer.

◆ QueueDismiss()

void WX_INFOBAR::QueueDismiss ( )

Send the infobar an event telling it to hide itself.

Definition at line 101 of file infobar.cpp.

102 {
103  wxCommandEvent* evt = new wxCommandEvent( KIEVT_DISMISS_INFOBAR );
104 
105  GetEventHandler()->QueueEvent( evt );
106 }

Referenced by INFOBAR_REPORTER::Finalize().

◆ 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 90 of file infobar.cpp.

91 {
92  wxCommandEvent* evt = new wxCommandEvent( KIEVT_SHOW_INFOBAR );
93 
94  evt->SetString( aMessage.c_str() );
95  evt->SetInt( aFlags );
96 
97  GetEventHandler()->QueueEvent( evt );
98 }

Referenced by INFOBAR_REPORTER::Finalize().

◆ RemoveAllButtons()

void WX_INFOBAR::RemoveAllButtons ( )

Remove all the buttons that have been added by the user.

Definition at line 226 of file infobar.cpp.

227 {
228  wxSizer* sizer = GetSizer();
229 
230  if( sizer->GetItemCount() == 0 )
231  return;
232 
233  // The last item is already the spacer
234  if( sizer->GetItem( sizer->GetItemCount() - 1 )->IsSpacer() )
235  return;
236 
237  for( int i = sizer->GetItemCount() - 1; i >= 0; i-- )
238  {
239  wxSizerItem* sItem = sizer->GetItem( i );
240 
241  // The spacer is the end of the custom buttons
242  if( sItem->IsSpacer() )
243  break;
244 
245  delete sItem->GetWindow();
246  }
247 }

Referenced by FOOTPRINT_EDIT_FRAME::AddModuleToBoard(), AUTOPLACE_TOOL::autoplace(), PAD_TOOL::EditPad(), ZONE_FILLER_TOOL::FillAllZones(), PL_EDITOR_FRAME::LoadPageLayoutDescrFile(), APPEARANCE_CONTROLS::onReadOnlySwatch(), OnShowInfoBar(), ROUTER_TOOL::onViaCommand(), SCH_EDIT_FRAME::OpenProjectFiles(), LIB_EDIT_FRAME::SetCurPart(), SCH_EDIT_FRAME::ShowFindReplaceStatus(), EDA_BASE_FRAME::ShowInfoBarError(), EDA_BASE_FRAME::ShowInfoBarMsg(), and EDA_BASE_FRAME::ShowInfoBarWarning().

◆ 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 84 of file infobar.cpp.

85 {
86  m_showTime = aTime;
87 }
int m_showTime
The time to show the infobar. 0 = don't auto hide.
Definition: infobar.h:209

References m_showTime.

◆ ShowMessage()

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 120 of file infobar.cpp.

121 {
122  // Don't do anything if we requested the UI update
123  if( m_updateLock )
124  return;
125 
126  m_updateLock = true;
127 
128  wxInfoBarGeneric::ShowMessage( aMessage, aFlags );
129 
130  if( m_auiManager )
131  UpdateAuiLayout( true );
132 
133  if( m_showTime > 0 )
134  m_showTimer->StartOnce( m_showTime );
135 
136  m_updateLock = false;
137 }
wxTimer * m_showTimer
The timer counting the autoclose period.
Definition: infobar.h:211
wxAuiManager * m_auiManager
The AUI manager that contains this infobar.
Definition: infobar.h:212
bool m_updateLock
True if this infobar requested the UI update.
Definition: infobar.h:210
void UpdateAuiLayout(bool aShow)
Update the AUI pane to show or hide this infobar.
Definition: infobar.cpp:157
int m_showTime
The time to show the infobar. 0 = don't auto hide.
Definition: infobar.h:209

References m_auiManager, m_showTime, m_showTimer, m_updateLock, and UpdateAuiLayout().

Referenced by FOOTPRINT_EDIT_FRAME::AddModuleToBoard(), DIALOG_BOARD_SETUP::DIALOG_BOARD_SETUP(), DIALOG_ERC::DIALOG_ERC(), DIALOG_SCHEMATIC_SETUP::DIALOG_SCHEMATIC_SETUP(), PAD_TOOL::EditPad(), PL_EDITOR_FRAME::LoadPageLayoutDescrFile(), OnShowInfoBar(), SCH_EDIT_FRAME::OpenProjectFiles(), LIB_EDIT_FRAME::SetCurPart(), ShowMessageFor(), and DIALOG_ERC::testErc().

◆ ShowMessageFor()

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

Show the infobar with the provided message and icon for a specific period of time.

Parameters
aMessageis the message to display
aTimeis the amount of time in milliseconds to show the infobar
aFlagsis the flag containing the icon to display on the left side of the infobar

Definition at line 109 of file infobar.cpp.

110 {
111  // Don't do anything if we requested the UI update
112  if( m_updateLock )
113  return;
114 
115  m_showTime = aTime;
116  ShowMessage( aMessage, aFlags );
117 }
void ShowMessage(const wxString &aMessage, int aFlags=wxICON_INFORMATION) override
Show the info bar with the provided message and icon.
Definition: infobar.cpp:120
bool m_updateLock
True if this infobar requested the UI update.
Definition: infobar.h:210
int m_showTime
The time to show the infobar. 0 = don't auto hide.
Definition: infobar.h:209

References m_showTime, m_updateLock, and ShowMessage().

Referenced by AUTOPLACE_TOOL::autoplace(), ZONE_FILLER_TOOL::FillAllZones(), APPEARANCE_CONTROLS::onReadOnlySwatch(), ROUTER_TOOL::onViaCommand(), SCH_EDIT_FRAME::ShowFindReplaceStatus(), EDA_BASE_FRAME::ShowInfoBarError(), EDA_BASE_FRAME::ShowInfoBarMsg(), and EDA_BASE_FRAME::ShowInfoBarWarning().

◆ UpdateAuiLayout()

void WX_INFOBAR::UpdateAuiLayout ( bool  aShow)
protected

Update the AUI pane to show or hide this infobar.

Parameters
aShowis true to show the pane

Definition at line 157 of file infobar.cpp.

158 {
159  wxASSERT( m_auiManager );
160 
161  wxAuiPaneInfo& pane = m_auiManager->GetPane( this );
162 
163  // If the infobar is in a pane, then show/hide the pane
164  if( pane.IsOk() )
165  {
166  if( aShow )
167  pane.Show();
168  else
169  pane.Hide();
170  }
171 
172  // Update the AUI manager regardless
173  m_auiManager->Update();
174 }
wxAuiManager * m_auiManager
The AUI manager that contains this infobar.
Definition: infobar.h:212

References m_auiManager.

Referenced by Dismiss(), and ShowMessage().

Member Data Documentation

◆ m_auiManager

wxAuiManager* WX_INFOBAR::m_auiManager
protected

The AUI manager that contains this infobar.

Definition at line 212 of file infobar.h.

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

◆ m_showTime

int WX_INFOBAR::m_showTime
protected

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

Definition at line 209 of file infobar.h.

Referenced by OnTimer(), SetShowTime(), ShowMessage(), and ShowMessageFor().

◆ m_showTimer

wxTimer* WX_INFOBAR::m_showTimer
protected

The timer counting the autoclose period.

Definition at line 211 of file infobar.h.

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

◆ m_updateLock

bool WX_INFOBAR::m_updateLock
protected

True if this infobar requested the UI update.

Definition at line 210 of file infobar.h.

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


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