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 wxString m_message;
266
267 std::optional<std::function<void(void)>> m_callback;
268
269 DECLARE_EVENT_TABLE()
270};
271
272
287class EDA_INFOBAR_PANEL : public wxPanel
288{
289public:
290 EDA_INFOBAR_PANEL( wxWindow* aParent, wxWindowID aId = wxID_ANY,
291 const wxPoint& aPos = wxDefaultPosition,
292 const wxSize& aSize = wxSize( -1,-1 ),
293 long aStyle = wxTAB_TRAVERSAL,
294 const wxString& aName = wxEmptyString );
295
301 void AddInfoBar( WX_INFOBAR* aInfoBar );
302
309 void AddOtherItem( wxWindow* aOtherItem );
310
311protected:
312 // The sizer containing the infobar and the other object
313 wxFlexGridSizer* m_mainSizer;
314};
315
316
327{
328public:
330 REPORTER(), m_messageSet( false ), m_infoBar( aInfoBar ),
332 {
333 }
334
335 virtual ~INFOBAR_REPORTER() {};
336
337 REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
338
339 bool HasMessage() const override;
340
344 void Finalize();
345
346private:
349 std::unique_ptr<wxString> m_message;
351};
352#endif // INFOBAR_H_
A wxPanel derived class that hold an infobar and another control.
Definition: wx_infobar.h:288
wxFlexGridSizer * m_mainSizer
Definition: wx_infobar.h:313
void AddInfoBar(WX_INFOBAR *aInfoBar)
Add the given infobar object to the panel.
Definition: wx_infobar.cpp:443
void AddOtherItem(wxWindow *aOtherItem)
Add the other item to the panel.
Definition: wx_infobar.cpp:453
A wrapper for reporting to a WX_INFOBAR UI element.
Definition: wx_infobar.h:327
INFOBAR_REPORTER(WX_INFOBAR *aInfoBar)
Definition: wx_infobar.h:329
WX_INFOBAR * m_infoBar
Definition: wx_infobar.h:348
void Finalize()
Update the infobar with the reported text.
Definition: wx_infobar.cpp:481
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: wx_infobar.cpp:465
SEVERITY m_severity
Definition: wx_infobar.h:350
std::unique_ptr< wxString > m_message
Definition: wx_infobar.h:349
virtual ~INFOBAR_REPORTER()
Definition: wx_infobar.h:335
bool HasMessage() const override
Returns true if the reporter client is non-empty.
Definition: wx_infobar.cpp:475
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:351
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:375
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:279
std::optional< std::function< void(void)> > m_callback
Optional callback made when closing infobar.
Definition: wx_infobar.h:267
bool IsLocked()
Returns true if the infobar is being updated.
Definition: wx_infobar.h:215
wxString m_message
The original message without wrapping.
Definition: wx_infobar.h:265
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:400
void onDismissInfoBar(wxCommandEvent &aEvent)
Event handler for dismissing the infobar using a wxCommandEvent of the type KIEVT_DISMISS_INFOBAR.
Definition: wx_infobar.cpp:408
void AddButton(wxButton *aButton)
Add an already created button to the infobar.
Definition: wx_infobar.cpp:307
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:414
wxBitmapButton * GetCloseButton() const
Definition: wx_infobar.cpp:381
void Dismiss() override
Dismisses the infobar and updates the containing layout and AUI manager (if one is provided).
Definition: wx_infobar.cpp:190
void onThemeChange(wxSysColourChangedEvent &aEvent)
Event handler for the color theme change event.
Definition: wx_infobar.cpp:213
void AddCloseButton(const wxString &aTooltip=_("Hide this message."))
Add the default close button to the infobar on the right side.
Definition: wx_infobar.cpp:341
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:420
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:263
void onSize(wxSizeEvent &aEvent)
Definition: wx_infobar.cpp:229
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)