2020-05-18 23:44:58 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2020 Ian McInerney <ian.s.mcinerney@ieee.org>
|
|
|
|
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2020-05-20 01:31:47 +00:00
|
|
|
#ifndef INFOBAR_H_
|
|
|
|
#define INFOBAR_H_
|
|
|
|
|
2022-08-25 22:50:47 +00:00
|
|
|
#include <functional>
|
|
|
|
#include <optional>
|
2020-06-03 23:00:40 +00:00
|
|
|
#include <wx/event.h>
|
2020-05-18 23:44:58 +00:00
|
|
|
#include <wx/infobar.h>
|
2021-05-01 07:50:29 +00:00
|
|
|
#include <wx/timer.h>
|
|
|
|
#include <wx/panel.h>
|
|
|
|
#include <wx/sizer.h>
|
2020-05-18 23:44:58 +00:00
|
|
|
|
2020-10-16 11:20:37 +00:00
|
|
|
|
2020-12-22 21:35:25 +00:00
|
|
|
class wxAuiManager;
|
2020-10-16 11:20:37 +00:00
|
|
|
class wxHyperlinkCtrl;
|
2020-05-18 23:44:58 +00:00
|
|
|
|
|
|
|
|
2020-06-03 23:00:40 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
/// ID for the close button on the frame's infobar
|
|
|
|
ID_CLOSE_INFOBAR = 2000,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
wxDECLARE_EVENT( KIEVT_SHOW_INFOBAR, wxCommandEvent );
|
|
|
|
wxDECLARE_EVENT( KIEVT_DISMISS_INFOBAR, wxCommandEvent );
|
|
|
|
|
2020-05-18 23:44:58 +00:00
|
|
|
/**
|
|
|
|
* A modified version of the wxInfoBar class that allows us to:
|
|
|
|
* * Show the close button along with the other buttons
|
|
|
|
* * Remove all user-provided buttons at once
|
2021-06-09 19:32:58 +00:00
|
|
|
* * Allow automatically hiding the infobar after a time period
|
2020-06-03 23:00:40 +00:00
|
|
|
* * Show/hide using events
|
|
|
|
* * Place it inside an AUI manager
|
2020-05-18 23:44:58 +00:00
|
|
|
*
|
|
|
|
* This inherits from the generic infobar because the native infobar
|
|
|
|
* on GTK doesn't include the icon on the left and it looks worse.
|
2020-06-03 23:00:40 +00:00
|
|
|
*
|
|
|
|
* There are 2 events associated with the infobar:
|
|
|
|
*
|
|
|
|
* KIEVT_SHOW_INFOBAR:
|
|
|
|
* An event that tells the infobar to show a message.
|
|
|
|
*
|
|
|
|
* The message text is contained inside the string component,
|
|
|
|
* and the message flag is contained inside the int component.
|
|
|
|
*
|
|
|
|
* Sample event creation code:
|
|
|
|
* wxCommandEvent* evt = new wxCommandEvent( KIEVT_SHOW_INFOBAR );
|
|
|
|
* evt->SetString( "A message to show" );
|
|
|
|
* evt->SetInt( wxICON_WARNING );
|
|
|
|
*
|
|
|
|
* KIEVT_DISMISS_INFOBAR:
|
|
|
|
* An event that tells the infobar to hide itself.
|
2020-05-18 23:44:58 +00:00
|
|
|
*/
|
|
|
|
class WX_INFOBAR : public wxInfoBarGeneric
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Construct an infobar that can exist inside an AUI managed frame.
|
|
|
|
*
|
|
|
|
* @param aParent is the parent
|
|
|
|
* @param aMgr is the AUI manager that this infobar is added to
|
|
|
|
* @param aWinId is the ID for this infobar object
|
|
|
|
*/
|
2020-12-22 21:35:25 +00:00
|
|
|
WX_INFOBAR( wxWindow* aParent, wxAuiManager* aMgr = nullptr, wxWindowID aWinid = wxID_ANY );
|
2020-05-18 23:44:58 +00:00
|
|
|
|
2020-06-03 23:00:40 +00:00
|
|
|
~WX_INFOBAR();
|
|
|
|
|
2021-02-16 23:42:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the type of message for special handling if needed
|
|
|
|
*/
|
|
|
|
enum class MESSAGE_TYPE
|
|
|
|
{
|
2021-08-01 20:51:08 +00:00
|
|
|
GENERIC, /**< GENERIC Are messages that do not have special handling */
|
|
|
|
OUTDATED_SAVE, /**< OUTDATED_SAVE Messages that should be cleared on save */
|
|
|
|
DRC_RULES_ERROR,
|
|
|
|
DRC_VIOLATION
|
2021-02-16 23:42:39 +00:00
|
|
|
};
|
|
|
|
|
2021-08-01 20:51:08 +00:00
|
|
|
MESSAGE_TYPE GetMessageType() const { return m_type; }
|
|
|
|
|
2020-05-20 01:31:47 +00:00
|
|
|
/**
|
|
|
|
* Set the time period to show the infobar.
|
|
|
|
*
|
|
|
|
* This only applies for the next showing of the infobar,
|
|
|
|
* so it must be reset every time. A value of 0 disables
|
|
|
|
* the automatic hiding (this is the default).
|
|
|
|
*
|
|
|
|
* @param aTime is the time in milliseconds to show the infobar
|
|
|
|
*/
|
|
|
|
void SetShowTime( int aTime );
|
|
|
|
|
2020-05-18 23:44:58 +00:00
|
|
|
/**
|
|
|
|
* Add the default close button to the infobar on the right side.
|
|
|
|
*
|
|
|
|
* @param aTooltip is the tooltip to give the close button
|
|
|
|
*/
|
|
|
|
void AddCloseButton( const wxString& aTooltip = _( "Hide this message." ) );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add an already created button to the infobar.
|
|
|
|
* New buttons are added in the right-most position.
|
|
|
|
*
|
|
|
|
* @param aButton is the button to add
|
|
|
|
*/
|
|
|
|
void AddButton( wxButton* aButton );
|
|
|
|
|
2020-10-16 11:20:37 +00:00
|
|
|
/**
|
|
|
|
* Add an already created hypertext link to the infobar.
|
|
|
|
* New buttons are added in the right-most position.
|
|
|
|
*
|
|
|
|
* @param aHypertextButton is the button to add
|
|
|
|
*/
|
|
|
|
void AddButton( wxHyperlinkCtrl* aHypertextButton );
|
|
|
|
|
2020-05-18 23:44:58 +00:00
|
|
|
/**
|
|
|
|
* Add a button with the provided ID and text.
|
2021-06-09 19:32:58 +00:00
|
|
|
* The new button is created on the right-most position.
|
2020-05-18 23:44:58 +00:00
|
|
|
*
|
|
|
|
* @param aId is the ID to assign to the button
|
|
|
|
* @param aLabel is the text for the button
|
|
|
|
*/
|
|
|
|
void AddButton( wxWindowID aId, const wxString& aLabel = wxEmptyString ) override;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove all the buttons that have been added by the user.
|
|
|
|
*/
|
|
|
|
void RemoveAllButtons();
|
|
|
|
|
2021-01-13 04:24:05 +00:00
|
|
|
bool HasCloseButton() const;
|
|
|
|
|
2021-01-04 17:51:50 +00:00
|
|
|
/**
|
|
|
|
* Provide a callback to be called when the infobar is dismissed (either by user action
|
|
|
|
* or timer).
|
|
|
|
* @param aCallback
|
|
|
|
*/
|
|
|
|
void SetCallback( std::function<void(void)> aCallback )
|
|
|
|
{
|
|
|
|
m_callback = aCallback;
|
|
|
|
}
|
|
|
|
|
2020-05-20 01:31:47 +00:00
|
|
|
/**
|
|
|
|
* Show the infobar with the provided message and icon for a specific period
|
|
|
|
* of time.
|
|
|
|
*
|
|
|
|
* @param aMessage is the message to display
|
2020-08-31 13:33:08 +00:00
|
|
|
* @param aTime is the amount of time in milliseconds to show the infobar
|
2020-05-20 01:31:47 +00:00
|
|
|
* @param aFlags is the flag containing the icon to display on the left side of the infobar
|
|
|
|
*/
|
2021-08-01 20:51:08 +00:00
|
|
|
void ShowMessageFor( const wxString& aMessage, int aTime, int aFlags = wxICON_INFORMATION,
|
|
|
|
MESSAGE_TYPE aType = WX_INFOBAR::MESSAGE_TYPE::GENERIC );
|
2020-05-20 01:31:47 +00:00
|
|
|
|
2020-05-18 23:44:58 +00:00
|
|
|
/**
|
|
|
|
* Show the info bar with the provided message and icon.
|
|
|
|
*
|
|
|
|
* @param aMessage is the message to display
|
|
|
|
* @param aFlags is the flag containing the icon to display on the left side of the infobar
|
|
|
|
*/
|
|
|
|
void ShowMessage( const wxString& aMessage, int aFlags = wxICON_INFORMATION ) override;
|
|
|
|
|
2021-02-16 23:42:39 +00:00
|
|
|
/**
|
|
|
|
* Show the info bar with the provided message and icon, setting the type
|
|
|
|
*
|
|
|
|
* @param aMessage is the message to display
|
|
|
|
* @param aFlags is the flag containing the icon to display on the left side of the infobar
|
|
|
|
* @param aType is the type of message being displayed
|
|
|
|
*/
|
|
|
|
void ShowMessage( const wxString& aMessage, int aFlags, MESSAGE_TYPE aType );
|
|
|
|
|
2020-05-18 23:44:58 +00:00
|
|
|
/**
|
|
|
|
* Dismisses the infobar and updates the containing layout and AUI manager
|
|
|
|
* (if one is provided).
|
|
|
|
*/
|
|
|
|
void Dismiss() override;
|
|
|
|
|
2020-06-03 23:00:40 +00:00
|
|
|
/**
|
|
|
|
* Send the infobar an event telling it to show a message.
|
|
|
|
*
|
|
|
|
* @param aMessage is the message to display
|
|
|
|
* @param aFlags is the flag containing the icon to display on the left side of the infobar
|
|
|
|
*/
|
|
|
|
void QueueShowMessage( const wxString& aMessage, int aFlags = wxICON_INFORMATION );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send the infobar an event telling it to hide itself.
|
|
|
|
*/
|
|
|
|
void QueueDismiss();
|
|
|
|
|
2020-09-24 22:13:53 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the infobar is being updated.
|
|
|
|
*/
|
|
|
|
bool IsLocked()
|
|
|
|
{
|
|
|
|
return m_updateLock;
|
|
|
|
}
|
|
|
|
|
2020-05-18 23:44:58 +00:00
|
|
|
protected:
|
2020-06-03 23:00:40 +00:00
|
|
|
/**
|
|
|
|
* Event handler for showing the infobar using a wxCommandEvent of the type
|
|
|
|
* KIEVT_SHOW_INFOBAR. The message is stored inside the string field, and the
|
|
|
|
* icon flag is stored inside the int field.
|
|
|
|
*/
|
2020-12-12 03:18:43 +00:00
|
|
|
void onShowInfoBar( wxCommandEvent& aEvent );
|
2020-06-03 23:00:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Event handler for dismissing the infobar using a wxCommandEvent of the type
|
|
|
|
* KIEVT_DISMISS_INFOBAR.
|
|
|
|
*/
|
2020-12-12 03:18:43 +00:00
|
|
|
void onDismissInfoBar( wxCommandEvent& aEvent );
|
2020-06-03 23:00:40 +00:00
|
|
|
|
2020-05-18 23:44:58 +00:00
|
|
|
/**
|
|
|
|
* Event handler for the close button.
|
|
|
|
* This is bound to ID_CLOSE_INFOBAR on the infobar.
|
|
|
|
*/
|
2020-12-12 03:18:43 +00:00
|
|
|
void onCloseButton( wxCommandEvent& aEvent );
|
2020-05-20 01:31:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Event handler for the automatic closing timer.
|
|
|
|
*/
|
2020-12-12 03:18:43 +00:00
|
|
|
void onTimer( wxTimerEvent& aEvent );
|
2020-05-18 23:44:58 +00:00
|
|
|
|
2020-12-11 12:09:37 +00:00
|
|
|
void onSize( wxSizeEvent& aEvent );
|
2020-05-18 23:44:58 +00:00
|
|
|
|
2020-12-22 21:35:25 +00:00
|
|
|
/**
|
|
|
|
* Update the AUI pane to show or hide this infobar.
|
|
|
|
*
|
|
|
|
* @param aShow is true to show the pane
|
|
|
|
*/
|
|
|
|
void updateAuiLayout( bool aShow );
|
|
|
|
|
2020-12-11 12:09:37 +00:00
|
|
|
protected:
|
2020-05-20 01:31:47 +00:00
|
|
|
int m_showTime; ///< The time to show the infobar. 0 = don't auto hide
|
2020-06-03 23:00:40 +00:00
|
|
|
bool m_updateLock; ///< True if this infobar requested the UI update
|
2020-05-20 01:31:47 +00:00
|
|
|
wxTimer* m_showTimer; ///< The timer counting the autoclose period
|
2020-12-22 21:35:25 +00:00
|
|
|
wxAuiManager* m_auiManager; ///< The AUI manager that contains this infobar
|
2021-02-16 23:42:39 +00:00
|
|
|
MESSAGE_TYPE m_type; ///< The type of message being displayed
|
2020-05-18 23:44:58 +00:00
|
|
|
|
2022-08-25 22:50:47 +00:00
|
|
|
std::optional<std::function<void(void)>> m_callback; ///< Optional callback made when closing infobar
|
2021-01-04 17:51:50 +00:00
|
|
|
|
2020-05-18 23:44:58 +00:00
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
};
|
2020-05-20 01:31:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A wxPanel derived class that hold an infobar and another control.
|
|
|
|
* The infobar is located at the top of the panel, and the other control
|
|
|
|
* is located below it.
|
|
|
|
*
|
|
|
|
* This allows the infobar to be controlled nicely by an AUI manager,
|
|
|
|
* since adding the infobar on its own to the AUI manager produces
|
|
|
|
* artifacts when showing/hiding it due to the AUI pane layout.
|
|
|
|
*
|
2020-05-21 17:22:12 +00:00
|
|
|
* Note that this implementation currently has issues on Windows with
|
|
|
|
* event processing inside the GAL canvas, see:
|
|
|
|
* https://gitlab.com/kicad/code/kicad/-/issues/4501
|
|
|
|
*
|
2020-05-20 01:31:47 +00:00
|
|
|
*/
|
|
|
|
class EDA_INFOBAR_PANEL : public wxPanel
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
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 );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add the given infobar object to the panel
|
|
|
|
*
|
|
|
|
* @param aInfoBar is the infobar to add
|
|
|
|
*/
|
|
|
|
void AddInfoBar( WX_INFOBAR* aInfoBar );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add the other item to the panel.
|
|
|
|
* This item will expand to fill up the vertical space left.
|
|
|
|
*
|
|
|
|
* @param aOtherItem is the item to add
|
|
|
|
*/
|
|
|
|
void AddOtherItem( wxWindow* aOtherItem );
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// The sizer containing the infobar and the other object
|
|
|
|
wxFlexGridSizer* m_mainSizer;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // INFOBAR_H_
|