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 (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#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
158 void SetCallback( std::function<void(void)> aCallback )
159 {
160 m_callback = aCallback;
161 }
162
171 void ShowMessageFor( const wxString& aMessage, int aTime, int aFlags = wxICON_INFORMATION,
173
180 void ShowMessage( const wxString& aMessage, int aFlags = wxICON_INFORMATION ) override;
181
189 void ShowMessage( const wxString& aMessage, int aFlags, MESSAGE_TYPE aType );
190
195 void Dismiss() override;
196
203 void QueueShowMessage( const wxString& aMessage, int aFlags = wxICON_INFORMATION );
204
208 void QueueDismiss();
209
213 bool IsLocked()
214 {
215 return m_updateLock;
216 }
217
218protected:
224 void onShowInfoBar( wxCommandEvent& aEvent );
225
230 void onDismissInfoBar( wxCommandEvent& aEvent );
231
236 void onCloseButton( wxCommandEvent& aEvent );
237
241 void onTimer( wxTimerEvent& aEvent );
242
243 void onSize( wxSizeEvent& aEvent );
244
250 void updateAuiLayout( bool aShow );
251
252protected:
255 wxTimer* m_showTimer;
256 wxAuiManager* m_auiManager;
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(), m_messageSet( false ), m_infoBar( aInfoBar ),
324 {
325 }
326
327 virtual ~INFOBAR_REPORTER() {};
328
329 REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
330
331 bool HasMessage() const override;
332
336 void Finalize();
337
338private:
341 std::unique_ptr<wxString> m_message;
343};
344#endif // INFOBAR_H_
A wxPanel derived class that hold an infobar and another control.
Definition: wx_infobar.h:280
wxFlexGridSizer * m_mainSizer
Definition: wx_infobar.h:305
void AddInfoBar(WX_INFOBAR *aInfoBar)
Add the given infobar object to the panel.
Definition: wx_infobar.cpp:387
void AddOtherItem(wxWindow *aOtherItem)
Add the other item to the panel.
Definition: wx_infobar.cpp:397
A wrapper for reporting to a WX_INFOBAR UI element.
Definition: wx_infobar.h:319
INFOBAR_REPORTER(WX_INFOBAR *aInfoBar)
Definition: wx_infobar.h:321
WX_INFOBAR * m_infoBar
Definition: wx_infobar.h:340
void Finalize()
Update the infobar with the reported text.
Definition: wx_infobar.cpp:425
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: wx_infobar.cpp:409
SEVERITY m_severity
Definition: wx_infobar.h:342
std::unique_ptr< wxString > m_message
Definition: wx_infobar.h:341
virtual ~INFOBAR_REPORTER()
Definition: wx_infobar.h:327
bool HasMessage() const override
Returns true if the reporter client is non-empty.
Definition: wx_infobar.cpp:419
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:115
void RemoveAllButtons()
Remove all the buttons that have been added by the user.
Definition: wx_infobar.cpp:304
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:140
bool HasCloseButton() const
Definition: wx_infobar.cpp:328
MESSAGE_TYPE m_type
The type of message being displayed.
Definition: wx_infobar.h:257
void updateAuiLayout(bool aShow)
Update the AUI pane to show or hide this infobar.
Definition: wx_infobar.cpp:235
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:213
int m_showTime
The time to show the infobar. 0 = don't auto hide.
Definition: wx_infobar.h:253
bool m_updateLock
True if this infobar requested the UI update.
Definition: wx_infobar.h:254
void onShowInfoBar(wxCommandEvent &aEvent)
Event handler for showing the infobar using a wxCommandEvent of the type KIEVT_SHOW_INFOBAR.
Definition: wx_infobar.cpp:344
void onDismissInfoBar(wxCommandEvent &aEvent)
Event handler for dismissing the infobar using a wxCommandEvent of the type KIEVT_DISMISS_INFOBAR.
Definition: wx_infobar.cpp:352
void AddButton(wxButton *aButton)
Add an already created button to the infobar.
Definition: wx_infobar.cpp:263
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:121
void onCloseButton(wxCommandEvent &aEvent)
Event handler for the close button.
Definition: wx_infobar.cpp:358
void Dismiss() override
Dismisses the infobar and updates the containing layout and AUI manager (if one is provided).
Definition: wx_infobar.cpp:190
void AddCloseButton(const wxString &aTooltip=_("Hide this message."))
Add the default close button to the infobar on the right side.
Definition: wx_infobar.cpp:294
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:158
wxTimer * m_showTimer
The timer counting the autoclose period.
Definition: wx_infobar.h:255
void onTimer(wxTimerEvent &aEvent)
Event handler for the automatic closing timer.
Definition: wx_infobar.cpp:364
void ShowMessage(const wxString &aMessage, int aFlags=wxICON_INFORMATION) override
Show the info bar with the provided message and icon.
Definition: wx_infobar.cpp:154
wxAuiManager * m_auiManager
The AUI manager that contains this infobar.
Definition: wx_infobar.h:256
void onSize(wxSizeEvent &aEvent)
Definition: wx_infobar.cpp:213
void QueueDismiss()
Send the infobar an event telling it to hide itself.
Definition: wx_infobar.cpp:132
#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)