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 <[email protected]>
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 <functional>
25#include <optional>
26#include <wx/event.h>
27#include <wx/infobar.h>
28#include <wx/timer.h>
29#include <wx/panel.h>
30#include <wx/sizer.h>
31
32
33class wxAuiManager;
34class wxHyperlinkCtrl;
35
36
37enum
38{
41};
42
43
44wxDECLARE_EVENT( KIEVT_SHOW_INFOBAR, wxCommandEvent );
45wxDECLARE_EVENT( KIEVT_DISMISS_INFOBAR, wxCommandEvent );
46
74class WX_INFOBAR : public wxInfoBarGeneric
75{
76public:
84 WX_INFOBAR( wxWindow* aParent, wxAuiManager* aMgr = nullptr, wxWindowID aWinid = wxID_ANY );
85
87
88
92 enum class MESSAGE_TYPE
93 {
94 GENERIC,
95 OUTDATED_SAVE,
96 DRC_RULES_ERROR,
97 DRC_VIOLATION
98 };
99
101
111 void SetShowTime( int aTime );
112
118 void AddCloseButton( const wxString& aTooltip = _( "Hide this message." ) );
119
126 void AddButton( wxButton* aButton );
127
134 void AddButton( wxHyperlinkCtrl* aHypertextButton );
135
143 void AddButton( wxWindowID aId, const wxString& aLabel = wxEmptyString ) override;
144
148 void RemoveAllButtons();
149
150 bool HasCloseButton() const;
151
157 void SetCallback( std::function<void(void)> aCallback )
158 {
159 m_callback = aCallback;
160 }
161
170 void ShowMessageFor( const wxString& aMessage, int aTime, int aFlags = wxICON_INFORMATION,
172
179 void ShowMessage( const wxString& aMessage, int aFlags = wxICON_INFORMATION ) override;
180
188 void ShowMessage( const wxString& aMessage, int aFlags, MESSAGE_TYPE aType );
189
194 void Dismiss() override;
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
217protected:
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
251protected:
254 wxTimer* m_showTimer;
255 wxAuiManager* m_auiManager;
257
258 std::optional<std::function<void(void)>> m_callback;
259
260 DECLARE_EVENT_TABLE()
261};
262
263
278class EDA_INFOBAR_PANEL : public wxPanel
279{
280public:
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
302protected:
303 // The sizer containing the infobar and the other object
304 wxFlexGridSizer* m_mainSizer;
305};
306
307#endif // INFOBAR_H_
A wxPanel derived class that hold an infobar and another control.
Definition: infobar.h:279
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:356
wxFlexGridSizer * m_mainSizer
Definition: infobar.h:304
void AddInfoBar(WX_INFOBAR *aInfoBar)
Add the given infobar object to the panel.
Definition: infobar.cpp:369
void AddOtherItem(wxWindow *aOtherItem)
Add the other item to the panel.
Definition: infobar.cpp:379
A modified version of the wxInfoBar class that allows us to:
Definition: infobar.h:75
void SetShowTime(int aTime)
Set the time period to show the infobar.
Definition: infobar.cpp:103
void RemoveAllButtons()
Remove all the buttons that have been added by the user.
Definition: infobar.cpp:286
void ShowMessageFor(const wxString &aMessage, int aTime, int aFlags=wxICON_INFORMATION, MESSAGE_TYPE aType=WX_INFOBAR::MESSAGE_TYPE::GENERIC)
Show the infobar with the provided message and icon for a specific period of time.
Definition: infobar.cpp:128
bool HasCloseButton() const
Definition: infobar.cpp:310
MESSAGE_TYPE m_type
The type of message being displayed.
Definition: infobar.h:256
~WX_INFOBAR()
Definition: infobar.cpp:97
void updateAuiLayout(bool aShow)
Update the AUI pane to show or hide this infobar.
Definition: infobar.cpp:217
std::optional< std::function< void(void)> > m_callback
Optional callback made when closing infobar.
Definition: infobar.h:258
bool IsLocked()
Returns true if the infobar is being updated.
Definition: infobar.h:212
int m_showTime
The time to show the infobar. 0 = don't auto hide.
Definition: infobar.h:252
bool m_updateLock
True if this infobar requested the UI update.
Definition: infobar.h:253
void onShowInfoBar(wxCommandEvent &aEvent)
Event handler for showing the infobar using a wxCommandEvent of the type KIEVT_SHOW_INFOBAR.
Definition: infobar.cpp:326
void onDismissInfoBar(wxCommandEvent &aEvent)
Event handler for dismissing the infobar using a wxCommandEvent of the type KIEVT_DISMISS_INFOBAR.
Definition: infobar.cpp:334
void AddButton(wxButton *aButton)
Add an already created button to the infobar.
Definition: infobar.cpp:245
MESSAGE_TYPE
Sets the type of message for special handling if needed.
Definition: infobar.h:93
@ GENERIC
GENERIC Are messages that do not have special handling.
void QueueShowMessage(const wxString &aMessage, int aFlags=wxICON_INFORMATION)
Send the infobar an event telling it to show a message.
Definition: infobar.cpp:109
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 onCloseButton(wxCommandEvent &aEvent)
Event handler for the close button.
Definition: infobar.cpp:340
void Dismiss() override
Dismisses the infobar and updates the containing layout and AUI manager (if one is provided).
Definition: infobar.cpp:175
void AddCloseButton(const wxString &aTooltip=_("Hide this message."))
Add the default close button to the infobar on the right side.
Definition: infobar.cpp:276
MESSAGE_TYPE GetMessageType() const
Definition: infobar.h:100
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:157
wxTimer * m_showTimer
The timer counting the autoclose period.
Definition: infobar.h:254
void onTimer(wxTimerEvent &aEvent)
Event handler for the automatic closing timer.
Definition: infobar.cpp:346
void ShowMessage(const wxString &aMessage, int aFlags=wxICON_INFORMATION) override
Show the info bar with the provided message and icon.
Definition: infobar.cpp:142
wxAuiManager * m_auiManager
The AUI manager that contains this infobar.
Definition: infobar.h:255
void onSize(wxSizeEvent &aEvent)
Definition: infobar.cpp:195
void QueueDismiss()
Send the infobar an event telling it to hide itself.
Definition: infobar.cpp:120
#define _(s)
@ ID_CLOSE_INFOBAR
ID for the close button on the frame's infobar.
Definition: infobar.h:40
wxDECLARE_EVENT(KIEVT_SHOW_INFOBAR, wxCommandEvent)