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
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#pragma once
22
23#include <functional>
24#include <optional>
25#include <wx/event.h>
26#include <wx/infobar.h>
27#include <wx/timer.h>
28#include <wx/panel.h>
29#include <wx/sizer.h>
30#include <reporter.h>
32#include <wx/hyperlink.h>
33
34
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:
92 WX_INFOBAR( wxWindow* aParent, wxWindowID aWinId = wxID_ANY, bool aOverlay = false );
93
95
96
98
100
110 void SetShowTime( int aTime );
111
117 void AddCloseButton( const wxString& aTooltip = _( "Hide this message." ) );
118
125 void AddButton( wxButton* aButton );
126
133 void AddLink( const wxString& aLinkText, const std::function<void( wxHyperlinkEvent& )>& aFn );
134
142 void AddButton( wxWindowID aId, const wxString& aLabel = wxEmptyString ) override;
143
147 void RemoveAllButtons();
148
149 bool HasCloseButton() const;
150
151 wxBitmapButton* GetCloseButton() const;
152
158 void SetCallback( std::function<void(void)> aCallback )
159 {
160 m_callback = aCallback;
161 }
162
172 void ShowMessageFor( const wxString& aMessage, int aTime, int aFlags = wxICON_INFORMATION,
173 MESSAGE_TYPE aType = WX_INFOBAR::MESSAGE_TYPE::GENERIC );
174
181 void ShowMessage( const wxString& aMessage, int aFlags = wxICON_INFORMATION ) override;
182
190 void ShowMessage( const wxString& aMessage, int aFlags, MESSAGE_TYPE aType );
191
196 void Dismiss() override;
197
204 void QueueShowMessage( const wxString& aMessage, int aFlags = wxICON_INFORMATION );
205
209 void QueueDismiss();
210
214 void FixSize();
215
216protected:
222 void onShowInfoBar( wxCommandEvent& aEvent );
223
228 void onDismissInfoBar( wxCommandEvent& aEvent );
229
234 void onCloseButton( wxCommandEvent& aEvent );
235
239 void onThemeChange( wxSysColourChangedEvent& aEvent );
240
244 void onTimer( wxTimerEvent& aEvent );
245
246 void onSize( wxSizeEvent& aEvent );
247 void doSize();
248
253 void stackOverlays();
254
258 void refreshParent();
259
260protected:
264 wxWindow* m_anchor;
265 wxTimer* m_showTimer;
267 wxString m_message;
268
269 std::optional<std::function<void(void)>> m_callback;
270
271 DECLARE_EVENT_TABLE()
272};
273
274
289class EDA_INFOBAR_PANEL : public wxPanel
290{
291public:
292 EDA_INFOBAR_PANEL( wxWindow* aParent, wxWindowID aId = wxID_ANY,
293 const wxPoint& aPos = wxDefaultPosition,
294 const wxSize& aSize = wxSize( -1,-1 ),
295 long aStyle = wxTAB_TRAVERSAL,
296 const wxString& aName = wxEmptyString );
297
303 void AddInfoBar( WX_INFOBAR* aInfoBar );
304
311 void AddOtherItem( wxWindow* aOtherItem );
312
313protected:
314 // The sizer containing the infobar and the other object
315 wxFlexGridSizer* m_mainSizer;
316};
317
318
329{
330public:
332 REPORTER(),
333 m_messageSet( false ),
334 m_infoBar( aInfoBar ),
336 {
337 }
338
339 virtual ~INFOBAR_REPORTER() {};
340
341 REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
342
343 bool HasMessage() const override;
344
348 void Finalize() override;
349
350private:
353 std::unique_ptr<wxString> m_message;
355};
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:315
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:331
WX_INFOBAR * m_infoBar
Definition wx_infobar.h:352
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
void Finalize() override
Update the infobar with the reported text.
SEVERITY m_severity
Definition wx_infobar.h:354
std::unique_ptr< wxString > m_message
Definition wx_infobar.h:353
virtual ~INFOBAR_REPORTER()
Definition wx_infobar.h:339
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:76
void FixSize()
Address some long-standing bugs regarding infobars comming up only partial-width.
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 refreshParent()
Repaint the parent so that the area the infobar covered is not left stale.
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:266
bool m_overlay
True if this infobar is drawn on top of its parent.
Definition wx_infobar.h:263
INFOBAR_MESSAGE_TYPE MESSAGE_TYPE
Definition wx_infobar.h:97
void AddLink(const wxString &aLinkText, const std::function< void(wxHyperlinkEvent &)> &aFn)
Add a hypertext link to the infobar.
void stackOverlays()
Lay out every overlay infobar sharing this one's parent as a top-anchored stack, so that two infobars...
std::optional< std::function< void(void)> > m_callback
Optional callback made when closing infobar.
Definition wx_infobar.h:269
wxString m_message
The original message without wrapping.
Definition wx_infobar.h:267
WX_INFOBAR(wxWindow *aParent, wxWindowID aWinId=wxID_ANY, bool aOverlay=false)
Construct an infobar.
int m_showTime
The time to show the infobar. 0 = don't auto hide.
Definition wx_infobar.h:261
bool m_updateLock
True if this infobar requested the UI update.
Definition wx_infobar.h:262
void onShowInfoBar(wxCommandEvent &aEvent)
Event handler for showing the infobar using a wxCommandEvent of the type KIEVT_SHOW_INFOBAR.
void doSize()
wxWindow * m_anchor
The window this infobar spans, its parent unless hosted.
Definition wx_infobar.h:264
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.
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:99
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:265
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.
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:41
wxDECLARE_EVENT(KIEVT_SHOW_INFOBAR, wxCommandEvent)
INFOBAR_MESSAGE_TYPE
Sets the type of message for special handling if needed.