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;
36class wxStaticText;
37
38
39enum
40{
43};
44
45
46wxDECLARE_EVENT( KIEVT_SHOW_INFOBAR, wxCommandEvent );
47wxDECLARE_EVENT( KIEVT_DISMISS_INFOBAR, wxCommandEvent );
48
76class WX_INFOBAR : public wxInfoBarGeneric
77{
78public:
93 WX_INFOBAR( wxWindow* aParent, wxWindowID aWinId = wxID_ANY, bool aOverlay = false );
94
96
97
99
101
111 void SetShowTime( int aTime );
112
118 void AddCloseButton( const wxString& aTooltip = _( "Hide this message." ) );
119
126 void AddButton( wxButton* aButton );
127
134 void AddLink( const wxString& aLinkText, const std::function<void( wxHyperlinkEvent& )>& aFn );
135
143 void AddButton( wxWindowID aId, const wxString& aLabel = wxEmptyString ) override;
144
148 void RemoveAllButtons();
149
150 bool HasCloseButton() const;
151
152 wxBitmapButton* GetCloseButton() const;
153
159 void SetCallback( std::function<void(void)> aCallback )
160 {
161 m_callback = aCallback;
162 }
163
173 void ShowMessageFor( const wxString& aMessage, int aTime, int aFlags = wxICON_INFORMATION,
174 MESSAGE_TYPE aType = WX_INFOBAR::MESSAGE_TYPE::GENERIC );
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 void FixSize();
216
221 bool Layout() override;
222
223protected:
229 void onShowInfoBar( wxCommandEvent& aEvent );
230
235 void onDismissInfoBar( wxCommandEvent& aEvent );
236
241 void onCloseButton( wxCommandEvent& aEvent );
242
246 void onThemeChange( wxSysColourChangedEvent& aEvent );
247
251 void onTimer( wxTimerEvent& aEvent );
252
253 void onSize( wxSizeEvent& aEvent );
254 void doSize();
255
260 void stackOverlays();
261
265 void refreshParent();
266
267protected:
271 wxWindow* m_anchor;
272 wxTimer* m_showTimer;
274 wxString m_message;
275 wxBoxSizer* m_buttonArea;
276 wxStaticText* m_messageText;
277
278 std::optional<std::function<void(void)>> m_callback;
279
280 DECLARE_EVENT_TABLE()
281};
282
283
298class EDA_INFOBAR_PANEL : public wxPanel
299{
300public:
301 EDA_INFOBAR_PANEL( wxWindow* aParent, wxWindowID aId = wxID_ANY,
302 const wxPoint& aPos = wxDefaultPosition,
303 const wxSize& aSize = wxSize( -1,-1 ),
304 long aStyle = wxTAB_TRAVERSAL,
305 const wxString& aName = wxEmptyString );
306
312 void AddInfoBar( WX_INFOBAR* aInfoBar );
313
320 void AddOtherItem( wxWindow* aOtherItem );
321
322protected:
323 // The sizer containing the infobar and the other object
324 wxFlexGridSizer* m_mainSizer;
325};
326
327
338{
339public:
341 REPORTER(),
342 m_messageSet( false ),
343 m_infoBar( aInfoBar ),
345 {
346 }
347
348 virtual ~INFOBAR_REPORTER() {};
349
350 REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
351
352 bool HasMessage() const override;
353
357 void Finalize() override;
358
359private:
362 std::unique_ptr<wxString> m_message;
364};
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:324
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:340
WX_INFOBAR * m_infoBar
Definition wx_infobar.h:361
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:363
std::unique_ptr< wxString > m_message
Definition wx_infobar.h:362
virtual ~INFOBAR_REPORTER()
Definition wx_infobar.h:348
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:77
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:273
bool m_overlay
True if this infobar is drawn on top of its parent.
Definition wx_infobar.h:270
INFOBAR_MESSAGE_TYPE MESSAGE_TYPE
Definition wx_infobar.h:98
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:278
wxString m_message
The original message without wrapping.
Definition wx_infobar.h:274
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:268
bool m_updateLock
True if this infobar requested the UI update.
Definition wx_infobar.h:269
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:271
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
wxStaticText * m_messageText
The message control, which wxInfoBarGeneric keeps private.
Definition wx_infobar.h:276
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.
wxBoxSizer * m_buttonArea
The links and buttons, laid out apart from the message.
Definition wx_infobar.h:275
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:100
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:159
wxTimer * m_showTimer
The timer counting the autoclose period.
Definition wx_infobar.h:272
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.
bool Layout() override
Lay out the infobar, keeping the links and buttons level with the first line of a multi-line message.
#define _(s)
SEVERITY
@ RPT_SEVERITY_UNDEFINED
@ ID_CLOSE_INFOBAR
ID for the close button on the frame's infobar.
Definition wx_infobar.h:42
wxDECLARE_EVENT(KIEVT_SHOW_INFOBAR, wxCommandEvent)
INFOBAR_MESSAGE_TYPE
Sets the type of message for special handling if needed.