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>
32
33
34class wxAuiManager;
35class wxHyperlinkCtrl;
36
37
38enum
39{
42};
43
44
45wxDECLARE_EVENT( KIEVT_SHOW_INFOBAR, wxCommandEvent );
46wxDECLARE_EVENT( KIEVT_DISMISS_INFOBAR, wxCommandEvent );
47
75class WX_INFOBAR : public wxInfoBarGeneric
76{
77public:
85 WX_INFOBAR( wxWindow* aParent, wxAuiManager* aMgr = nullptr, wxWindowID aWinid = wxID_ANY );
86
88
89
93 enum class MESSAGE_TYPE
94 {
95 GENERIC,
99 };
100
102
112 void SetShowTime( int aTime );
113
119 void AddCloseButton( const wxString& aTooltip = _( "Hide this message." ) );
120
127 void AddButton( wxButton* aButton );
128
135 void AddButton( wxHyperlinkCtrl* aHypertextButton );
136
144 void AddButton( wxWindowID aId, const wxString& aLabel = wxEmptyString ) override;
145
149 void RemoveAllButtons();
150
151 bool HasCloseButton() const;
152
153 wxBitmapButton* GetCloseButton() const;
154
160 void SetCallback( std::function<void(void)> aCallback )
161 {
162 m_callback = aCallback;
163 }
164
173 void ShowMessageFor( const wxString& aMessage, int aTime, int aFlags = wxICON_INFORMATION,
175
182 void ShowMessage( const wxString& aMessage, int aFlags = wxICON_INFORMATION ) override;
183
191 void ShowMessage( const wxString& aMessage, int aFlags, MESSAGE_TYPE aType );
192
197 void Dismiss() override;
198
205 void QueueShowMessage( const wxString& aMessage, int aFlags = wxICON_INFORMATION );
206
210 void QueueDismiss();
211
215 bool IsLocked()
216 {
217 return m_updateLock;
218 }
219
220protected:
226 void onShowInfoBar( wxCommandEvent& aEvent );
227
232 void onDismissInfoBar( wxCommandEvent& aEvent );
233
238 void onCloseButton( wxCommandEvent& aEvent );
239
243 void onThemeChange( wxSysColourChangedEvent& aEvent );
244
248 void onTimer( wxTimerEvent& aEvent );
249
250 void onSize( wxSizeEvent& aEvent );
251
257 void updateAuiLayout( bool aShow );
258
259protected:
262 wxTimer* m_showTimer;
263 wxAuiManager* m_auiManager;
265
266 std::optional<std::function<void(void)>> m_callback;
267
268 DECLARE_EVENT_TABLE()
269};
270
271
286class EDA_INFOBAR_PANEL : public wxPanel
287{
288public:
289 EDA_INFOBAR_PANEL( wxWindow* aParent, wxWindowID aId = wxID_ANY,
290 const wxPoint& aPos = wxDefaultPosition,
291 const wxSize& aSize = wxSize( -1,-1 ),
292 long aStyle = wxTAB_TRAVERSAL,
293 const wxString& aName = wxEmptyString );
294
300 void AddInfoBar( WX_INFOBAR* aInfoBar );
301
308 void AddOtherItem( wxWindow* aOtherItem );
309
310protected:
311 // The sizer containing the infobar and the other object
312 wxFlexGridSizer* m_mainSizer;
313};
314
315
326{
327public:
329 REPORTER(), m_messageSet( false ), m_infoBar( aInfoBar ),
331 {
332 }
333
334 virtual ~INFOBAR_REPORTER() {};
335
336 REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
337
338 bool HasMessage() const override;
339
343 void Finalize();
344
345private:
348 std::unique_ptr<wxString> m_message;
350};
351#endif // INFOBAR_H_
A wxPanel derived class that hold an infobar and another control.
Definition: wx_infobar.h:287
wxFlexGridSizer * m_mainSizer
Definition: wx_infobar.h:312
void AddInfoBar(WX_INFOBAR *aInfoBar)
Add the given infobar object to the panel.
Definition: wx_infobar.cpp:412
void AddOtherItem(wxWindow *aOtherItem)
Add the other item to the panel.
Definition: wx_infobar.cpp:422
A wrapper for reporting to a WX_INFOBAR UI element.
Definition: wx_infobar.h:326
INFOBAR_REPORTER(WX_INFOBAR *aInfoBar)
Definition: wx_infobar.h:328
WX_INFOBAR * m_infoBar
Definition: wx_infobar.h:347
void Finalize()
Update the infobar with the reported text.
Definition: wx_infobar.cpp:450
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: wx_infobar.cpp:434
SEVERITY m_severity
Definition: wx_infobar.h:349
std::unique_ptr< wxString > m_message
Definition: wx_infobar.h:348
virtual ~INFOBAR_REPORTER()
Definition: wx_infobar.h:334
bool HasMessage() const override
Returns true if the reporter client is non-empty.
Definition: wx_infobar.cpp:444
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:72
A modified version of the wxInfoBar class that allows us to:
Definition: wx_infobar.h:76
void SetShowTime(int aTime)
Set the time period to show the infobar.
Definition: wx_infobar.cpp:114
void RemoveAllButtons()
Remove all the buttons that have been added by the user.
Definition: wx_infobar.cpp:320
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: wx_infobar.cpp:139
bool HasCloseButton() const
Definition: wx_infobar.cpp:344
MESSAGE_TYPE m_type
The type of message being displayed.
Definition: wx_infobar.h:264
void updateAuiLayout(bool aShow)
Update the AUI pane to show or hide this infobar.
Definition: wx_infobar.cpp:250
std::optional< std::function< void(void)> > m_callback
Optional callback made when closing infobar.
Definition: wx_infobar.h:266
bool IsLocked()
Returns true if the infobar is being updated.
Definition: wx_infobar.h:215
int m_showTime
The time to show the infobar. 0 = don't auto hide.
Definition: wx_infobar.h:260
bool m_updateLock
True if this infobar requested the UI update.
Definition: wx_infobar.h:261
void onShowInfoBar(wxCommandEvent &aEvent)
Event handler for showing the infobar using a wxCommandEvent of the type KIEVT_SHOW_INFOBAR.
Definition: wx_infobar.cpp:369
void onDismissInfoBar(wxCommandEvent &aEvent)
Event handler for dismissing the infobar using a wxCommandEvent of the type KIEVT_DISMISS_INFOBAR.
Definition: wx_infobar.cpp:377
void AddButton(wxButton *aButton)
Add an already created button to the infobar.
Definition: wx_infobar.cpp:278
MESSAGE_TYPE
Sets the type of message for special handling if needed.
Definition: wx_infobar.h:94
@ OUTDATED_SAVE
OUTDATED_SAVE Messages that should be cleared on save.
@ 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: wx_infobar.cpp:120
void onCloseButton(wxCommandEvent &aEvent)
Event handler for the close button.
Definition: wx_infobar.cpp:383
wxBitmapButton * GetCloseButton() const
Definition: wx_infobar.cpp:350
void Dismiss() override
Dismisses the infobar and updates the containing layout and AUI manager (if one is provided).
Definition: wx_infobar.cpp:189
void onThemeChange(wxSysColourChangedEvent &aEvent)
Event handler for the color theme change event.
Definition: wx_infobar.cpp:212
void AddCloseButton(const wxString &aTooltip=_("Hide this message."))
Add the default close button to the infobar on the right side.
Definition: wx_infobar.cpp:310
MESSAGE_TYPE GetMessageType() const
Definition: wx_infobar.h:101
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:160
wxTimer * m_showTimer
The timer counting the autoclose period.
Definition: wx_infobar.h:262
void onTimer(wxTimerEvent &aEvent)
Event handler for the automatic closing timer.
Definition: wx_infobar.cpp:389
void ShowMessage(const wxString &aMessage, int aFlags=wxICON_INFORMATION) override
Show the info bar with the provided message and icon.
Definition: wx_infobar.cpp:153
wxAuiManager * m_auiManager
The AUI manager that contains this infobar.
Definition: wx_infobar.h:263
void onSize(wxSizeEvent &aEvent)
Definition: wx_infobar.cpp:228
void QueueDismiss()
Send the infobar an event telling it to hide itself.
Definition: wx_infobar.cpp:131
#define _(s)
SEVERITY
@ RPT_SEVERITY_UNDEFINED
@ ID_CLOSE_INFOBAR
ID for the close button on the frame's infobar.
Definition: wx_infobar.h:41
wxDECLARE_EVENT(KIEVT_SHOW_INFOBAR, wxCommandEvent)