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/wx.h>
28 
29 
30 class wxAuiManager;
31 class wxHyperlinkCtrl;
32 
33 
34 enum
35 {
38 };
39 
40 
41 wxDECLARE_EVENT( KIEVT_SHOW_INFOBAR, wxCommandEvent );
42 wxDECLARE_EVENT( KIEVT_DISMISS_INFOBAR, wxCommandEvent );
43 
71 class WX_INFOBAR : public wxInfoBarGeneric
72 {
73 public:
81  WX_INFOBAR( wxWindow* aParent, wxAuiManager* aMgr = nullptr, wxWindowID aWinid = wxID_ANY );
82 
83  ~WX_INFOBAR();
84 
85 
89  enum class MESSAGE_TYPE
90  {
91  GENERIC,
93  };
94 
104  void SetShowTime( int aTime );
105 
111  void AddCloseButton( const wxString& aTooltip = _( "Hide this message." ) );
112 
119  void AddButton( wxButton* aButton );
120 
127  void AddButton( wxHyperlinkCtrl* aHypertextButton );
128 
136  void AddButton( wxWindowID aId, const wxString& aLabel = wxEmptyString ) override;
137 
141  void RemoveAllButtons();
142 
143  bool HasCloseButton() const;
144 
150  void SetCallback( std::function<void(void)> aCallback )
151  {
152  m_callback = aCallback;
153  }
154 
163  void ShowMessageFor( const wxString& aMessage, int aTime, int aFlags = wxICON_INFORMATION );
164 
171  void ShowMessage( const wxString& aMessage, int aFlags = wxICON_INFORMATION ) override;
172 
180  void ShowMessage( const wxString& aMessage, int aFlags, MESSAGE_TYPE aType );
181 
186  void Dismiss() override;
187 
192  void DismissOutdatedSave();
193 
200  void QueueShowMessage( const wxString& aMessage, int aFlags = wxICON_INFORMATION );
201 
205  void QueueDismiss();
206 
210  bool IsLocked()
211  {
212  return m_updateLock;
213  }
214 
215 protected:
221  void onShowInfoBar( wxCommandEvent& aEvent );
222 
227  void onDismissInfoBar( wxCommandEvent& aEvent );
228 
233  void onCloseButton( wxCommandEvent& aEvent );
234 
238  void onTimer( wxTimerEvent& aEvent );
239 
240  void onSize( wxSizeEvent& aEvent );
241 
247  void updateAuiLayout( bool aShow );
248 
249 protected:
252  wxTimer* m_showTimer;
253  wxAuiManager* m_auiManager;
255 
256  OPT<std::function<void(void)>> m_callback;
257 
258  DECLARE_EVENT_TABLE()
259 };
260 
261 
276 class EDA_INFOBAR_PANEL : public wxPanel
277 {
278 public:
279  EDA_INFOBAR_PANEL( wxWindow* aParent, wxWindowID aId = wxID_ANY,
280  const wxPoint& aPos = wxDefaultPosition,
281  const wxSize& aSize = wxSize( -1,-1 ),
282  long aStyle = wxTAB_TRAVERSAL,
283  const wxString& aName = wxEmptyString );
284 
290  void AddInfoBar( WX_INFOBAR* aInfoBar );
291 
298  void AddOtherItem( wxWindow* aOtherItem );
299 
300 protected:
301  // The sizer containing the infobar and the other object
302  wxFlexGridSizer* m_mainSizer;
303 };
304 
305 #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:113
void ShowMessage(const wxString &aMessage, int aFlags=wxICON_INFORMATION) override
Show the info bar with the provided message and icon.
Definition: infobar.cpp:124
A wxPanel derived class that hold an infobar and another control.
Definition: infobar.h:276
MESSAGE_TYPE
Sets the type of message for special handling if needed.
Definition: infobar.h:89
void AddButton(wxButton *aButton)
Add an already created button to the infobar.
Definition: infobar.cpp:236
void onTimer(wxTimerEvent &aEvent)
Event handler for the automatic closing timer.
Definition: infobar.cpp:337
void onSize(wxSizeEvent &aEvent)
Definition: infobar.cpp:186
void updateAuiLayout(bool aShow)
Update the AUI pane to show or hide this infobar.
Definition: infobar.cpp:208
void onCloseButton(wxCommandEvent &aEvent)
Event handler for the close button.
Definition: infobar.cpp:331
GENERIC Are messages that do not have special handling.
wxTimer * m_showTimer
The timer counting the autoclose period.
Definition: infobar.h:252
void onShowInfoBar(wxCommandEvent &aEvent)
Event handler for showing the infobar using a wxCommandEvent of the type KIEVT_SHOW_INFOBAR.
Definition: infobar.cpp:317
OPT< std::function< void(void)> > m_callback
Optional callback made when closing infobar.
Definition: infobar.h:256
~WX_INFOBAR()
Definition: infobar.cpp:82
bool HasCloseButton() const
Definition: infobar.cpp:301
bool IsLocked()
Returns true if the infobar is being updated.
Definition: infobar.h:210
void Dismiss() override
Dismisses the infobar and updates the containing layout and AUI manager (if one is provided).
Definition: infobar.cpp:166
ID for the close button on the frame's infobar.
Definition: infobar.h:37
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:150
void AddOtherItem(wxWindow *aOtherItem)
Add the other item to the panel.
Definition: infobar.cpp:370
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:45
void RemoveAllButtons()
Remove all the buttons that have been added by the user.
Definition: infobar.cpp:277
void QueueShowMessage(const wxString &aMessage, int aFlags=wxICON_INFORMATION)
Send the infobar an event telling it to show a message.
Definition: infobar.cpp:94
void DismissOutdatedSave()
Dismisses the infobar for outdated save warnings and updates the containing layout and AUI manager (i...
Definition: infobar.cpp:157
A modified version of the wxInfoBar class that allows us to:
Definition: infobar.h:71
void SetShowTime(int aTime)
Set the time period to show the infobar.
Definition: infobar.cpp:88
void QueueDismiss()
Send the infobar an event telling it to hide itself.
Definition: infobar.cpp:105
#define _(s)
Definition: 3d_actions.cpp:33
wxFlexGridSizer * m_mainSizer
Definition: infobar.h:302
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:347
wxAuiManager * m_auiManager
The AUI manager that contains this infobar.
Definition: infobar.h:253
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:325
bool m_updateLock
True if this infobar requested the UI update.
Definition: infobar.h:251
wxDECLARE_EVENT(KIEVT_SHOW_INFOBAR, wxCommandEvent)
void AddInfoBar(WX_INFOBAR *aInfoBar)
Add the given infobar object to the panel.
Definition: infobar.cpp:360
MESSAGE_TYPE m_type
The type of message being displayed.
Definition: infobar.h:254
int m_showTime
The time to show the infobar. 0 = don't auto hide.
Definition: infobar.h:250
void AddCloseButton(const wxString &aTooltip=_("Hide this message."))
Add the default close button to the infobar on the right side.
Definition: infobar.cpp:267