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 (C) 2020 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
32
33class wxAuiManager;
34class wxHyperlinkCtrl;
35
36
37enum
38{
41};
42
43
44wxDECLARE_EVENT( KIEVT_SHOW_INFOBAR, wxCommandEvent );
45wxDECLARE_EVENT( KIEVT_DISMISS_INFOBAR, wxCommandEvent );
46
74class WX_INFOBAR : public wxInfoBarGeneric
75{
76public:
84 WX_INFOBAR( wxWindow* aParent, wxAuiManager* aMgr = nullptr, wxWindowID aWinid = wxID_ANY );
85
87
88
92 enum class MESSAGE_TYPE
93 {
94 GENERIC,
98 };
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 AddButton( wxHyperlinkCtrl* aHypertextButton );
135
143 void AddButton( wxWindowID aId, const wxString& aLabel = wxEmptyString ) override;
144
148 void RemoveAllButtons();
149
150 bool HasCloseButton() const;
151
157 void SetCallback( std::function<void(void)> aCallback )
158 {
159 m_callback = aCallback;
160 }
161
170 void ShowMessageFor( const wxString& aMessage, int aTime, int aFlags = wxICON_INFORMATION,
172
179 void ShowMessage( const wxString& aMessage, int aFlags = wxICON_INFORMATION ) override;
180
188 void ShowMessage( const wxString& aMessage, int aFlags, MESSAGE_TYPE aType );
189
194 void Dismiss() override;
195
202 void QueueShowMessage( const wxString& aMessage, int aFlags = wxICON_INFORMATION );
203
207 void QueueDismiss();
208
212 bool IsLocked()
213 {
214 return m_updateLock;
215 }
216
217protected:
223 void onShowInfoBar( wxCommandEvent& aEvent );
224
229 void onDismissInfoBar( wxCommandEvent& aEvent );
230
235 void onCloseButton( wxCommandEvent& aEvent );
236
240 void onTimer( wxTimerEvent& aEvent );
241
242 void onSize( wxSizeEvent& aEvent );
243
249 void updateAuiLayout( bool aShow );
250
251protected:
254 wxTimer* m_showTimer;
255 wxAuiManager* m_auiManager;
257
258 std::optional<std::function<void(void)>> m_callback;
259
260 DECLARE_EVENT_TABLE()
261};
262
263
278class EDA_INFOBAR_PANEL : public wxPanel
279{
280public:
281 EDA_INFOBAR_PANEL( wxWindow* aParent, wxWindowID aId = wxID_ANY,
282 const wxPoint& aPos = wxDefaultPosition,
283 const wxSize& aSize = wxSize( -1,-1 ),
284 long aStyle = wxTAB_TRAVERSAL,
285 const wxString& aName = wxEmptyString );
286
292 void AddInfoBar( WX_INFOBAR* aInfoBar );
293
300 void AddOtherItem( wxWindow* aOtherItem );
301
302protected:
303 // The sizer containing the infobar and the other object
304 wxFlexGridSizer* m_mainSizer;
305};
306
307#endif // INFOBAR_H_
A wxPanel derived class that hold an infobar and another control.
Definition: wx_infobar.h:279
wxFlexGridSizer * m_mainSizer
Definition: wx_infobar.h:304
void AddInfoBar(WX_INFOBAR *aInfoBar)
Add the given infobar object to the panel.
Definition: wx_infobar.cpp:384
void AddOtherItem(wxWindow *aOtherItem)
Add the other item to the panel.
Definition: wx_infobar.cpp:394
A modified version of the wxInfoBar class that allows us to:
Definition: wx_infobar.h:75
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:301
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:325
MESSAGE_TYPE m_type
The type of message being displayed.
Definition: wx_infobar.h:256
void updateAuiLayout(bool aShow)
Update the AUI pane to show or hide this infobar.
Definition: wx_infobar.cpp:232
std::optional< std::function< void(void)> > m_callback
Optional callback made when closing infobar.
Definition: wx_infobar.h:258
bool IsLocked()
Returns true if the infobar is being updated.
Definition: wx_infobar.h:212
int m_showTime
The time to show the infobar. 0 = don't auto hide.
Definition: wx_infobar.h:252
bool m_updateLock
True if this infobar requested the UI update.
Definition: wx_infobar.h:253
void onShowInfoBar(wxCommandEvent &aEvent)
Event handler for showing the infobar using a wxCommandEvent of the type KIEVT_SHOW_INFOBAR.
Definition: wx_infobar.cpp:341
void onDismissInfoBar(wxCommandEvent &aEvent)
Event handler for dismissing the infobar using a wxCommandEvent of the type KIEVT_DISMISS_INFOBAR.
Definition: wx_infobar.cpp:349
void AddButton(wxButton *aButton)
Add an already created button to the infobar.
Definition: wx_infobar.cpp:260
MESSAGE_TYPE
Sets the type of message for special handling if needed.
Definition: wx_infobar.h:93
@ 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:355
void Dismiss() override
Dismisses the infobar and updates the containing layout and AUI manager (if one is provided).
Definition: wx_infobar.cpp:187
void AddCloseButton(const wxString &aTooltip=_("Hide this message."))
Add the default close button to the infobar on the right side.
Definition: wx_infobar.cpp:291
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:157
wxTimer * m_showTimer
The timer counting the autoclose period.
Definition: wx_infobar.h:254
void onTimer(wxTimerEvent &aEvent)
Event handler for the automatic closing timer.
Definition: wx_infobar.cpp:361
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:255
void onSize(wxSizeEvent &aEvent)
Definition: wx_infobar.cpp:210
void QueueDismiss()
Send the infobar an event telling it to hide itself.
Definition: wx_infobar.cpp:132
#define _(s)
@ ID_CLOSE_INFOBAR
ID for the close button on the frame's infobar.
Definition: wx_infobar.h:40
wxDECLARE_EVENT(KIEVT_SHOW_INFOBAR, wxCommandEvent)