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:
89 WX_INFOBAR( wxWindow* aParent, wxWindowID aWinId = wxID_ANY, bool aOverlay = false );
90
92
93
95
97
107 void SetShowTime( int aTime );
108
114 void AddCloseButton( const wxString& aTooltip = _( "Hide this message." ) );
115
122 void AddButton( wxButton* aButton );
123
130 void AddLink( const wxString& aLinkText, const std::function<void( wxHyperlinkEvent& )>& aFn );
131
139 void AddButton( wxWindowID aId, const wxString& aLabel = wxEmptyString ) override;
140
144 void RemoveAllButtons();
145
146 bool HasCloseButton() const;
147
148 wxBitmapButton* GetCloseButton() const;
149
155 void SetCallback( std::function<void(void)> aCallback )
156 {
157 m_callback = aCallback;
158 }
159
169 void ShowMessageFor( const wxString& aMessage, int aTime, int aFlags = wxICON_INFORMATION,
170 MESSAGE_TYPE aType = WX_INFOBAR::MESSAGE_TYPE::GENERIC );
171
178 void ShowMessage( const wxString& aMessage, int aFlags = wxICON_INFORMATION ) override;
179
187 void ShowMessage( const wxString& aMessage, int aFlags, MESSAGE_TYPE aType );
188
193 void Dismiss() override;
194
201 void QueueShowMessage( const wxString& aMessage, int aFlags = wxICON_INFORMATION );
202
206 void QueueDismiss();
207
211 void FixSize();
212
213protected:
219 void onShowInfoBar( wxCommandEvent& aEvent );
220
225 void onDismissInfoBar( wxCommandEvent& aEvent );
226
231 void onCloseButton( wxCommandEvent& aEvent );
232
236 void onThemeChange( wxSysColourChangedEvent& aEvent );
237
241 void onTimer( wxTimerEvent& aEvent );
242
243 void onSize( wxSizeEvent& aEvent );
244 void doSize();
245
250 void stackOverlays();
251
255 void refreshParent();
256
257protected:
261 wxTimer* m_showTimer;
263 wxString m_message;
264
265 std::optional<std::function<void(void)>> m_callback;
266
267 DECLARE_EVENT_TABLE()
268};
269
270
285class EDA_INFOBAR_PANEL : public wxPanel
286{
287public:
288 EDA_INFOBAR_PANEL( wxWindow* aParent, wxWindowID aId = wxID_ANY,
289 const wxPoint& aPos = wxDefaultPosition,
290 const wxSize& aSize = wxSize( -1,-1 ),
291 long aStyle = wxTAB_TRAVERSAL,
292 const wxString& aName = wxEmptyString );
293
299 void AddInfoBar( WX_INFOBAR* aInfoBar );
300
307 void AddOtherItem( wxWindow* aOtherItem );
308
309protected:
310 // The sizer containing the infobar and the other object
311 wxFlexGridSizer* m_mainSizer;
312};
313
314
325{
326public:
328 REPORTER(),
329 m_messageSet( false ),
330 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() override;
345
346private:
349 std::unique_ptr<wxString> m_message;
351};
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:311
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:327
WX_INFOBAR * m_infoBar
Definition wx_infobar.h:348
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: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 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:262
bool m_overlay
True if this infobar is drawn on top of its parent.
Definition wx_infobar.h:260
INFOBAR_MESSAGE_TYPE MESSAGE_TYPE
Definition wx_infobar.h:94
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:265
wxString m_message
The original message without wrapping.
Definition wx_infobar.h:263
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:258
bool m_updateLock
True if this infobar requested the UI update.
Definition wx_infobar.h:259
void onShowInfoBar(wxCommandEvent &aEvent)
Event handler for showing the infobar using a wxCommandEvent of the type KIEVT_SHOW_INFOBAR.
void doSize()
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:96
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:155
wxTimer * m_showTimer
The timer counting the autoclose period.
Definition wx_infobar.h:261
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.