KiCad PCB EDA Suite
Loading...
Searching...
No Matches
wx_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 The 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#include <reporter.h>
33
34
35class wxAuiManager;
36class wxHyperlinkCtrl;
37
38
39enum
40{
43};
44
45
46wxDECLARE_EVENT( KIEVT_SHOW_INFOBAR, wxCommandEvent );
47wxDECLARE_EVENT( KIEVT_DISMISS_INFOBAR, wxCommandEvent );
48
76class WX_INFOBAR : public wxInfoBarGeneric
77{
78public:
86 WX_INFOBAR( wxWindow* aParent, wxAuiManager* aMgr = nullptr, wxWindowID aWinid = wxID_ANY );
87
89
90
92
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
145 wxBitmapButton* GetCloseButton() 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 MESSAGE_TYPE aType = WX_INFOBAR::MESSAGE_TYPE::GENERIC );
167
174 void ShowMessage( const wxString& aMessage, int aFlags = wxICON_INFORMATION ) override;
175
183 void ShowMessage( const wxString& aMessage, int aFlags, MESSAGE_TYPE aType );
184
189 void Dismiss() override;
190
197 void QueueShowMessage( const wxString& aMessage, int aFlags = wxICON_INFORMATION );
198
202 void QueueDismiss();
203
207 bool IsLocked()
208 {
209 return m_updateLock;
210 }
211
212protected:
218 void onShowInfoBar( wxCommandEvent& aEvent );
219
224 void onDismissInfoBar( wxCommandEvent& aEvent );
225
230 void onCloseButton( wxCommandEvent& aEvent );
231
235 void onThemeChange( wxSysColourChangedEvent& 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 wxString m_message;
258
259 std::optional<std::function<void(void)>> m_callback;
260
261 DECLARE_EVENT_TABLE()
262};
263
264
279class EDA_INFOBAR_PANEL : public wxPanel
280{
281public:
282 EDA_INFOBAR_PANEL( wxWindow* aParent, wxWindowID aId = wxID_ANY,
283 const wxPoint& aPos = wxDefaultPosition,
284 const wxSize& aSize = wxSize( -1,-1 ),
285 long aStyle = wxTAB_TRAVERSAL,
286 const wxString& aName = wxEmptyString );
287
293 void AddInfoBar( WX_INFOBAR* aInfoBar );
294
301 void AddOtherItem( wxWindow* aOtherItem );
302
303protected:
304 // The sizer containing the infobar and the other object
305 wxFlexGridSizer* m_mainSizer;
306};
307
308
319{
320public:
322 REPORTER(),
323 m_messageSet( false ),
324 m_infoBar( aInfoBar ),
326 {
327 }
328
329 virtual ~INFOBAR_REPORTER() {};
330
331 REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
332
333 bool HasMessage() const override;
334
338 void Finalize();
339
340private:
343 std::unique_ptr<wxString> m_message;
345};
346#endif // INFOBAR_H_
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)
wxFlexGridSizer * m_mainSizer
Definition wx_infobar.h:305
void AddInfoBar(WX_INFOBAR *aInfoBar)
Add the given infobar object to the panel.
void AddOtherItem(wxWindow *aOtherItem)
Add the other item to the panel.
INFOBAR_REPORTER(WX_INFOBAR *aInfoBar)
Definition wx_infobar.h:321
WX_INFOBAR * m_infoBar
Definition wx_infobar.h:342
void Finalize()
Update the infobar with the reported text.
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
SEVERITY m_severity
Definition wx_infobar.h:344
std::unique_ptr< wxString > m_message
Definition wx_infobar.h:343
virtual ~INFOBAR_REPORTER()
Definition wx_infobar.h:329
bool HasMessage() const override
Returns true if any messages were reported.
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:73
REPORTER()
Definition reporter.h:75
A modified version of the wxInfoBar class that allows us to:
Definition wx_infobar.h:77
void SetShowTime(int aTime)
Set the time period to show the infobar.
void RemoveAllButtons()
Remove all the buttons that have been added by the user.
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.
bool HasCloseButton() const
MESSAGE_TYPE m_type
The type of message being displayed.
Definition wx_infobar.h:256
INFOBAR_MESSAGE_TYPE MESSAGE_TYPE
Definition wx_infobar.h:91
void updateAuiLayout(bool aShow)
Update the AUI pane to show or hide this infobar.
std::optional< std::function< void(void)> > m_callback
Optional callback made when closing infobar.
Definition wx_infobar.h:259
bool IsLocked()
Returns true if the infobar is being updated.
Definition wx_infobar.h:207
wxString m_message
The original message without wrapping.
Definition wx_infobar.h:257
int m_showTime
The time to show the infobar. 0 = don't auto hide.
Definition wx_infobar.h:252
bool m_updateLock
True if this infobar requested the UI update.
Definition wx_infobar.h:253
void onShowInfoBar(wxCommandEvent &aEvent)
Event handler for showing the infobar using a wxCommandEvent of the type KIEVT_SHOW_INFOBAR.
void onDismissInfoBar(wxCommandEvent &aEvent)
Event handler for dismissing the infobar using a wxCommandEvent of the type KIEVT_DISMISS_INFOBAR.
void AddButton(wxButton *aButton)
Add an already created button to the infobar.
void QueueShowMessage(const wxString &aMessage, int aFlags=wxICON_INFORMATION)
Send the infobar an event telling it to show a message.
WX_INFOBAR(wxWindow *aParent, wxAuiManager *aMgr=nullptr, wxWindowID aWinid=wxID_ANY)
Construct an infobar that can exist inside an AUI managed frame.
void onCloseButton(wxCommandEvent &aEvent)
Event handler for the close button.
wxBitmapButton * GetCloseButton() const
void Dismiss() override
Dismisses the infobar and updates the containing layout and AUI manager (if one is provided).
void onThemeChange(wxSysColourChangedEvent &aEvent)
Event handler for the color theme change event.
void AddCloseButton(const wxString &aTooltip=_("Hide this message."))
Add the default close button to the infobar on the right side.
MESSAGE_TYPE GetMessageType() const
Definition wx_infobar.h:93
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 wx_infobar.h:152
wxTimer * m_showTimer
The timer counting the autoclose period.
Definition wx_infobar.h:254
void onTimer(wxTimerEvent &aEvent)
Event handler for the automatic closing timer.
void ShowMessage(const wxString &aMessage, int aFlags=wxICON_INFORMATION) override
Show the info bar with the provided message and icon.
wxAuiManager * m_auiManager
The AUI manager that contains this infobar.
Definition wx_infobar.h:255
void onSize(wxSizeEvent &aEvent)
void QueueDismiss()
Send the infobar an event telling it to hide itself.
#define _(s)
SEVERITY
@ RPT_SEVERITY_UNDEFINED
@ ID_CLOSE_INFOBAR
ID for the close button on the frame's infobar.
Definition wx_infobar.h:42
wxDECLARE_EVENT(KIEVT_SHOW_INFOBAR, wxCommandEvent)
INFOBAR_MESSAGE_TYPE
Sets the type of message for special handling if needed.