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 <core/optional.h>
25 #include <wx/event.h>
26 #include <wx/infobar.h>
27 #include <wx/timer.h>
28 #include <wx/panel.h>
29 #include <wx/sizer.h>
30 
31 
32 class wxAuiManager;
33 class wxHyperlinkCtrl;
34 
35 
36 enum
37 {
40 };
41 
42 
43 wxDECLARE_EVENT( KIEVT_SHOW_INFOBAR, wxCommandEvent );
44 wxDECLARE_EVENT( KIEVT_DISMISS_INFOBAR, wxCommandEvent );
45 
73 class WX_INFOBAR : public wxInfoBarGeneric
74 {
75 public:
83  WX_INFOBAR( wxWindow* aParent, wxAuiManager* aMgr = nullptr, wxWindowID aWinid = wxID_ANY );
84 
85  ~WX_INFOBAR();
86 
87 
91  enum class MESSAGE_TYPE
92  {
93  GENERIC,
95  };
96 
106  void SetShowTime( int aTime );
107 
113  void AddCloseButton( const wxString& aTooltip = _( "Hide this message." ) );
114 
121  void AddButton( wxButton* aButton );
122 
129  void AddButton( wxHyperlinkCtrl* aHypertextButton );
130 
138  void AddButton( wxWindowID aId, const wxString& aLabel = wxEmptyString ) override;
139 
143  void RemoveAllButtons();
144 
145  bool HasCloseButton() const;
146 
152  void SetCallback( std::function<void(void)> aCallback )
153  {
154  m_callback = aCallback;
155  }
156 
165  void ShowMessageFor( const wxString& aMessage, int aTime, int aFlags = wxICON_INFORMATION );
166 
173  void ShowMessage( const wxString& aMessage, int aFlags = wxICON_INFORMATION ) override;
174 
182  void ShowMessage( const wxString& aMessage, int aFlags, MESSAGE_TYPE aType );
183 
188  void Dismiss() override;
189 
194  void DismissOutdatedSave();
195 
202  void QueueShowMessage( const wxString& aMessage, int aFlags = wxICON_INFORMATION );
203 
207  void QueueDismiss();
208 
212  bool IsLocked()
213  {
214  return m_updateLock;
215  }
216 
217 protected:
223  void onShowInfoBar( wxCommandEvent& aEvent );
224 
229  void onDismissInfoBar( wxCommandEvent& aEvent );
230 
235  void onCloseButton( wxCommandEvent& aEvent );
236 
240  void onTimer( wxTimerEvent& aEvent );
241 
242  void onSize( wxSizeEvent& aEvent );
243 
249  void updateAuiLayout( bool aShow );
250 
251 protected:
254  wxTimer* m_showTimer;
255  wxAuiManager* m_auiManager;
257 
258  OPT<std::function<void(void)>> m_callback;
259 
260  DECLARE_EVENT_TABLE()
261 };
262 
263 
278 class EDA_INFOBAR_PANEL : public wxPanel
279 {
280 public:
281  EDA_INFOBAR_PANEL( wxWindow* aParent, wxWindowID aId = wxID_ANY,
282  const wxPoint& aPos = wxDefaultPosition,
283  const wxSize& aSize = wxSize( -1,-1 ),
284  long aStyle = wxTAB_TRAVERSAL,
285  const wxString& aName = wxEmptyString );
286 
292  void AddInfoBar( WX_INFOBAR* aInfoBar );
293 
300  void AddOtherItem( wxWindow* aOtherItem );
301 
302 protected:
303  // The sizer containing the infobar and the other object
304  wxFlexGridSizer* m_mainSizer;
305 };
306 
307 #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:123
void ShowMessage(const wxString &aMessage, int aFlags=wxICON_INFORMATION) override
Show the info bar with the provided message and icon.
Definition: infobar.cpp:134
A wxPanel derived class that hold an infobar and another control.
Definition: infobar.h:278
MESSAGE_TYPE
Sets the type of message for special handling if needed.
Definition: infobar.h:91
void AddButton(wxButton *aButton)
Add an already created button to the infobar.
Definition: infobar.cpp:246
void onTimer(wxTimerEvent &aEvent)
Event handler for the automatic closing timer.
Definition: infobar.cpp:347
void onSize(wxSizeEvent &aEvent)
Definition: infobar.cpp:196
void updateAuiLayout(bool aShow)
Update the AUI pane to show or hide this infobar.
Definition: infobar.cpp:218
void onCloseButton(wxCommandEvent &aEvent)
Event handler for the close button.
Definition: infobar.cpp:341
GENERIC Are messages that do not have special handling.
wxTimer * m_showTimer
The timer counting the autoclose period.
Definition: infobar.h:254
void onShowInfoBar(wxCommandEvent &aEvent)
Event handler for showing the infobar using a wxCommandEvent of the type KIEVT_SHOW_INFOBAR.
Definition: infobar.cpp:327
OPT< std::function< void(void)> > m_callback
Optional callback made when closing infobar.
Definition: infobar.h:258
~WX_INFOBAR()
Definition: infobar.cpp:92
bool HasCloseButton() const
Definition: infobar.cpp:311
bool IsLocked()
Returns true if the infobar is being updated.
Definition: infobar.h:212
void Dismiss() override
Dismisses the infobar and updates the containing layout and AUI manager (if one is provided).
Definition: infobar.cpp:176
ID for the close button on the frame's infobar.
Definition: infobar.h:39
void SetCallback(std::function< void(void)> aCallback)
Provide a callback to be called when the infobar is dismissed (either by user action or timer).
Definition: infobar.h:152
void AddOtherItem(wxWindow *aOtherItem)
Add the other item to the panel.
Definition: infobar.cpp:380
#define _(s)
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:47
void RemoveAllButtons()
Remove all the buttons that have been added by the user.
Definition: infobar.cpp:287
void QueueShowMessage(const wxString &aMessage, int aFlags=wxICON_INFORMATION)
Send the infobar an event telling it to show a message.
Definition: infobar.cpp:104
void DismissOutdatedSave()
Dismisses the infobar for outdated save warnings and updates the containing layout and AUI manager (i...
Definition: infobar.cpp:167
A modified version of the wxInfoBar class that allows us to:
Definition: infobar.h:73
void SetShowTime(int aTime)
Set the time period to show the infobar.
Definition: infobar.cpp:98
void QueueDismiss()
Send the infobar an event telling it to hide itself.
Definition: infobar.cpp:115
wxFlexGridSizer * m_mainSizer
Definition: infobar.h:304
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:357
wxAuiManager * m_auiManager
The AUI manager that contains this infobar.
Definition: infobar.h:255
OUTDATED_SAVE Messages that should be cleared on save.
boost::optional< T > OPT
Definition: optional.h:7
void onDismissInfoBar(wxCommandEvent &aEvent)
Event handler for dismissing the infobar using a wxCommandEvent of the type KIEVT_DISMISS_INFOBAR.
Definition: infobar.cpp:335
bool m_updateLock
True if this infobar requested the UI update.
Definition: infobar.h:253
wxDECLARE_EVENT(KIEVT_SHOW_INFOBAR, wxCommandEvent)
void AddInfoBar(WX_INFOBAR *aInfoBar)
Add the given infobar object to the panel.
Definition: infobar.cpp:370
MESSAGE_TYPE m_type
The type of message being displayed.
Definition: infobar.h:256
int m_showTime
The time to show the infobar. 0 = don't auto hide.
Definition: infobar.h:252
void AddCloseButton(const wxString &aTooltip=_("Hide this message."))
Add the default close button to the infobar on the right side.
Definition: infobar.cpp:277