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
168 void ShowMessageFor( const wxString& aMessage, int aTime, int aFlags = wxICON_INFORMATION,
169 MESSAGE_TYPE aType = WX_INFOBAR::MESSAGE_TYPE::GENERIC );
170
177 void ShowMessage( const wxString& aMessage, int aFlags = wxICON_INFORMATION ) override;
178
186 void ShowMessage( const wxString& aMessage, int aFlags, MESSAGE_TYPE aType );
187
192 void Dismiss() override;
193
200 void QueueShowMessage( const wxString& aMessage, int aFlags = wxICON_INFORMATION );
201
205 void QueueDismiss();
206
210 void FixSize();
211
212protected:
218 void onShowInfoBar( wxCommandEvent& aEvent );
219
224 void onDismissInfoBar( wxCommandEvent& aEvent );
225
230 void onCloseButton( wxCommandEvent& aEvent );
231
235 void onThemeChange( wxSysColourChangedEvent& aEvent );
236
240 void onTimer( wxTimerEvent& aEvent );
241
242 void onSize( wxSizeEvent& aEvent );
243 void doSize();
244
249 void stackOverlays();
250
254 void refreshParent();
255
256protected:
260 wxTimer* m_showTimer;
262 wxString m_message;
263
264 std::optional<std::function<void(void)>> m_callback;
265
266 DECLARE_EVENT_TABLE()
267};
268
269
284class EDA_INFOBAR_PANEL : public wxPanel
285{
286public:
287 EDA_INFOBAR_PANEL( wxWindow* aParent, wxWindowID aId = wxID_ANY,
288 const wxPoint& aPos = wxDefaultPosition,
289 const wxSize& aSize = wxSize( -1,-1 ),
290 long aStyle = wxTAB_TRAVERSAL,
291 const wxString& aName = wxEmptyString );
292
298 void AddInfoBar( WX_INFOBAR* aInfoBar );
299
306 void AddOtherItem( wxWindow* aOtherItem );
307
308protected:
309 // The sizer containing the infobar and the other object
310 wxFlexGridSizer* m_mainSizer;
311};
312
313
324{
325public:
327 REPORTER(),
328 m_messageSet( false ),
329 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() override;
344
345private:
348 std::unique_ptr<wxString> m_message;
350};
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:310
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:326
WX_INFOBAR * m_infoBar
Definition wx_infobar.h:347
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: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 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:261
bool m_overlay
True if this infobar is drawn on top of its parent.
Definition wx_infobar.h:259
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.
WX_INFOBAR(wxWindow *aParent, wxWindowID aWinid=wxID_ANY, bool aOverlay=false)
Construct an 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:264
wxString m_message
The original message without wrapping.
Definition wx_infobar.h:262
int m_showTime
The time to show the infobar. 0 = don't auto hide.
Definition wx_infobar.h:257
bool m_updateLock
True if this infobar requested the UI update.
Definition wx_infobar.h:258
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:260
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.