KiCad PCB EDA Suite
infobar.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2020 Ian McInerney <ian.s.mcinerney@ieee.org>
5  * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software: you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by the
9  * Free Software Foundation, either version 3 of the License, or (at your
10  * option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef INFOBAR_H_
22 #define INFOBAR_H_
23 
24 #include <wx/event.h>
25 #include <wx/infobar.h>
26 #include <wx/wx.h>
27 
28 
29 class wxAuiManager;
30 class wxHyperlinkCtrl;
31 
32 
33 enum
34 {
37 };
38 
39 
40 wxDECLARE_EVENT( KIEVT_SHOW_INFOBAR, wxCommandEvent );
41 wxDECLARE_EVENT( KIEVT_DISMISS_INFOBAR, wxCommandEvent );
42 
70 class WX_INFOBAR : public wxInfoBarGeneric
71 {
72 public:
80  WX_INFOBAR( wxWindow* aParent, wxAuiManager* aMgr = nullptr, wxWindowID aWinid = wxID_ANY );
81 
82  ~WX_INFOBAR();
83 
93  void SetShowTime( int aTime );
94 
100  void AddCloseButton( const wxString& aTooltip = _( "Hide this message." ) );
101 
108  void AddButton( wxButton* aButton );
109 
116  void AddButton( wxHyperlinkCtrl* aHypertextButton );
117 
125  void AddButton( wxWindowID aId, const wxString& aLabel = wxEmptyString ) override;
126 
130  void RemoveAllButtons();
131 
140  void ShowMessageFor( const wxString& aMessage, int aTime, int aFlags = wxICON_INFORMATION );
141 
148  void ShowMessage( const wxString& aMessage, int aFlags = wxICON_INFORMATION ) override;
149 
154  void Dismiss() override;
155 
162  void QueueShowMessage( const wxString& aMessage, int aFlags = wxICON_INFORMATION );
163 
167  void QueueDismiss();
168 
172  bool IsLocked()
173  {
174  return m_updateLock;
175  }
176 
177 protected:
183  void OnShowInfoBar( wxCommandEvent& aEvent );
184 
189  void OnDismissInfoBar( wxCommandEvent& aEvent );
190 
195  void OnCloseButton( wxCommandEvent& aEvent );
196 
200  void OnTimer( wxTimerEvent& aEvent );
201 
207  void UpdateAuiLayout( bool aShow );
208 
211  wxTimer* m_showTimer;
212  wxAuiManager* m_auiManager;
213 
214  DECLARE_EVENT_TABLE()
215 };
216 
217 
232 class EDA_INFOBAR_PANEL : public wxPanel
233 {
234 public:
235  EDA_INFOBAR_PANEL( wxWindow* aParent, wxWindowID aId = wxID_ANY,
236  const wxPoint& aPos = wxDefaultPosition,
237  const wxSize& aSize = wxSize( -1,-1 ),
238  long aStyle = wxTAB_TRAVERSAL,
239  const wxString& aName = wxEmptyString );
240 
246  void AddInfoBar( WX_INFOBAR* aInfoBar );
247 
254  void AddOtherItem( wxWindow* aOtherItem );
255 
256 protected:
257  // The sizer containing the infobar and the other object
258  wxFlexGridSizer* m_mainSizer;
259 };
260 
261 #endif // INFOBAR_H_
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.
Definition: infobar.cpp:109
void ShowMessage(const wxString &aMessage, int aFlags=wxICON_INFORMATION) override
Show the info bar with the provided message and icon.
Definition: infobar.cpp:120
A wxPanel derived class that hold an infobar and another control.
Definition: infobar.h:232
void AddButton(wxButton *aButton)
Add an already created button to the infobar.
Definition: infobar.cpp:185
wxTimer * m_showTimer
The timer counting the autoclose period.
Definition: infobar.h:211
void OnDismissInfoBar(wxCommandEvent &aEvent)
Event handler for dismissing the infobar using a wxCommandEvent of the type KIEVT_DISMISS_INFOBAR.
Definition: infobar.cpp:258
~WX_INFOBAR()
Definition: infobar.cpp:78
bool IsLocked()
Returns true if the infobar is being updated.
Definition: infobar.h:172
void Dismiss() override
Dismisses the infobar and updates the containing layout and AUI manager (if one is provided).
Definition: infobar.cpp:140
void AddOtherItem(wxWindow *aOtherItem)
Add the other item to the panel.
Definition: infobar.cpp:303
ID for the close button on the frame's infobar.
Definition: infobar.h:36
void OnShowInfoBar(wxCommandEvent &aEvent)
Event handler for showing the infobar using a wxCommandEvent of the type KIEVT_SHOW_INFOBAR.
Definition: infobar.cpp:250
WX_INFOBAR(wxWindow *aParent, wxAuiManager *aMgr=nullptr, wxWindowID aWinid=wxID_ANY)
Construct an infobar that can exist inside an AUI managed frame.
Definition: infobar.cpp:44
void OnTimer(wxTimerEvent &aEvent)
Event handler for the automatic closing timer.
Definition: infobar.cpp:270
void RemoveAllButtons()
Remove all the buttons that have been added by the user.
Definition: infobar.cpp:226
void QueueShowMessage(const wxString &aMessage, int aFlags=wxICON_INFORMATION)
Send the infobar an event telling it to show a message.
Definition: infobar.cpp:90
A modified version of the wxInfoBar class that allows us to:
Definition: infobar.h:70
void SetShowTime(int aTime)
Set the time period to show the infobar.
Definition: infobar.cpp:84
void QueueDismiss()
Send the infobar an event telling it to hide itself.
Definition: infobar.cpp:101
void OnCloseButton(wxCommandEvent &aEvent)
Event handler for the close button.
Definition: infobar.cpp:264
#define _(s)
Definition: 3d_actions.cpp:33
wxFlexGridSizer * m_mainSizer
Definition: infobar.h:258
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)
Definition: infobar.cpp:280
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
wxDECLARE_EVENT(KIEVT_SHOW_INFOBAR, wxCommandEvent)
void AddInfoBar(WX_INFOBAR *aInfoBar)
Add the given infobar object to the panel.
Definition: infobar.cpp:293
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
void AddCloseButton(const wxString &aTooltip=_("Hide this message."))
Add the default close button to the infobar on the right side.
Definition: infobar.cpp:216