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

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

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

References ID_CLOSE_INFOBAR.

◆ ~WX_INFOBAR()

WX_INFOBAR::~WX_INFOBAR ( )

Definition at line 77 of file infobar.cpp.

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

References m_showTimer.

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

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

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

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

Definition at line 176 of file infobar.cpp.

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

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

203 {
204  wxBitmapButton* button = wxBitmapButton::NewCloseButton( this, ID_CLOSE_INFOBAR );
205 
206  button->SetToolTip( aTooltip );
207 
208  AddButton( button );
209 }
void AddButton(wxButton *aButton)
Add an already created button to the infobar.
Definition: infobar.cpp:184
ID for the close button on the frame's infobar.
Definition: infobar.h:34

References AddButton(), and ID_CLOSE_INFOBAR.

Referenced by PL_EDITOR_FRAME::LoadPageLayoutDescrFile(), 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 139 of file infobar.cpp.

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

References m_auiManager, m_updateLock, and UpdateAuiLayout().

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

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

251 {
252  Dismiss();
253 }
void Dismiss() override
Dismisses the infobar and updates the containing layout and AUI manager (if one is provided).
Definition: infobar.cpp:139

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

245 {
246  Dismiss();
247 }
void Dismiss() override
Dismisses the infobar and updates the containing layout and AUI manager (if one is provided).
Definition: infobar.cpp:139

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

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

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

◆ OnTimer()

void WX_INFOBAR::OnTimer ( wxTimerEvent &  aEvent)
protected

Event handler for the automatic closing timer.

Definition at line 256 of file infobar.cpp.

257 {
258  // Reset and clear the timer
259  m_showTimer->Stop();
260  m_showTime = 0;
261 
262  Dismiss();
263 }
wxTimer * m_showTimer
The timer counting the autoclose period.
Definition: infobar.h:193
void Dismiss() override
Dismisses the infobar and updates the containing layout and AUI manager (if one is provided).
Definition: infobar.cpp:139
int m_showTime
The time to show the infobar. 0 = don't auto hide.
Definition: infobar.h:191

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

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

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

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

Referenced by INFOBAR_REPORTER::Finalize().

◆ RemoveAllButtons()

void WX_INFOBAR::RemoveAllButtons ( )

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

Definition at line 212 of file infobar.cpp.

213 {
214  wxSizer* sizer = GetSizer();
215 
216  if( sizer->GetItemCount() == 0 )
217  return;
218 
219  // The last item is already the spacer
220  if( sizer->GetItem( sizer->GetItemCount() - 1 )->IsSpacer() )
221  return;
222 
223  for( int i = sizer->GetItemCount() - 1; i >= 0; i-- )
224  {
225  wxSizerItem* sItem = sizer->GetItem( i );
226 
227  // The spacer is the end of the custom buttons
228  if( sItem->IsSpacer() )
229  break;
230 
231  delete sItem->GetWindow();
232  }
233 }

Referenced by PAD_TOOL::EditPad(), PL_EDITOR_FRAME::LoadPageLayoutDescrFile(), OnShowInfoBar(), SCH_EDIT_FRAME::OpenProjectFiles(), and SCH_EDIT_FRAME::ShowFindReplaceStatus().

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

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

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

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

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

Referenced by PAD_TOOL::EditPad(), PL_EDITOR_FRAME::LoadPageLayoutDescrFile(), OnShowInfoBar(), SCH_EDIT_FRAME::OpenProjectFiles(), and ShowMessageFor().

◆ 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 to show the infobar
aFlagsis the flag containing the icon to display on the left side of the infobar

Definition at line 108 of file infobar.cpp.

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

References m_showTime, m_updateLock, and ShowMessage().

Referenced by SCH_EDIT_FRAME::ShowFindReplaceStatus().

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

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

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 194 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 191 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 193 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 192 of file infobar.h.

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


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