/* * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2020 Ian McInerney * 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 . */ #ifndef INFOBAR_H_ #define INFOBAR_H_ #include #include class wxAuiManager; /** * 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 * * Allow automaticly hiding the infobar after a time period * * This inherits from the generic infobar because the native infobar * on GTK doesn't include the icon on the left and it looks worse. */ 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 */ WX_INFOBAR( wxWindow* aParent, wxAuiManager* aMgr = nullptr, wxWindowID aWinid = wxID_ANY ); /** * 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 ); /** * 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 ); /** * Add a button with the provided ID and text. * The new button is created on the right-most positon. * * @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(); /** * Show the infobar with the provided message and icon for a specific period * of time. * * @param aMessage is the message to display * @param aTime is the amount of time to show the infobar * @param aFlags is the flag containing the icon to display on the left side of the infobar */ void ShowMessageFor( const wxString& aMessage, int aTime, int aFlags = wxICON_INFORMATION ); /** * 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; /** * Dismisses the infobar and updates the containing layout and AUI manager * (if one is provided). */ void Dismiss() override; protected: /** * Event handler for the close button. * This is bound to ID_CLOSE_INFOBAR on the infobar. */ void OnCloseButton( wxCommandEvent& aEvent ); /** * Event handler for the automatic closing timer. */ void OnTimer( wxTimerEvent& aEvent ); /** * Update the AUI pane to show or hide this infobar. * * @param aShow is true to show the pane */ void UpdateAuiLayout( bool aShow ); int m_showTime; ///< The time to show the infobar. 0 = don't auto hide wxTimer* m_showTimer; ///< The timer counting the autoclose period wxAuiManager* m_auiManager; ///< The AUI manager that contains this infobar DECLARE_EVENT_TABLE() }; /** * 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. * * 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 * */ 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_