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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <id.h>
|
2021-04-29 03:24:19 +00:00
|
|
|
#include <kiplatform/ui.h>
|
2022-12-28 22:03:03 +00:00
|
|
|
#include <widgets/wx_infobar.h>
|
2020-06-01 23:05:55 +00:00
|
|
|
#include "wx/artprov.h"
|
2020-12-22 21:35:25 +00:00
|
|
|
#include <wx/aui/framemanager.h>
|
2020-05-20 01:31:47 +00:00
|
|
|
#include <wx/debug.h>
|
2020-05-18 23:44:58 +00:00
|
|
|
#include <wx/infobar.h>
|
2020-05-20 01:31:47 +00:00
|
|
|
#include <wx/sizer.h>
|
|
|
|
#include <wx/timer.h>
|
2020-10-16 11:20:37 +00:00
|
|
|
#include <wx/hyperlink.h>
|
2021-05-01 07:50:29 +00:00
|
|
|
#include <wx/bmpbuttn.h>
|
2020-12-29 10:13:07 +00:00
|
|
|
#include <eda_base_frame.h>
|
2020-05-18 23:44:58 +00:00
|
|
|
|
2023-05-21 01:57:08 +00:00
|
|
|
#ifdef __WXMSW__
|
|
|
|
#include <gal/dpi_scaling.h>
|
|
|
|
#endif
|
|
|
|
|
2020-05-18 23:44:58 +00:00
|
|
|
|
2020-06-03 23:00:40 +00:00
|
|
|
wxDEFINE_EVENT( KIEVT_SHOW_INFOBAR, wxCommandEvent );
|
|
|
|
wxDEFINE_EVENT( KIEVT_DISMISS_INFOBAR, wxCommandEvent );
|
|
|
|
|
2020-05-18 23:44:58 +00:00
|
|
|
BEGIN_EVENT_TABLE( WX_INFOBAR, wxInfoBarGeneric )
|
2020-12-12 03:18:43 +00:00
|
|
|
EVT_COMMAND( wxID_ANY, KIEVT_SHOW_INFOBAR, WX_INFOBAR::onShowInfoBar )
|
|
|
|
EVT_COMMAND( wxID_ANY, KIEVT_DISMISS_INFOBAR, WX_INFOBAR::onDismissInfoBar )
|
2020-06-03 23:00:40 +00:00
|
|
|
|
2020-12-12 03:18:43 +00:00
|
|
|
EVT_BUTTON( ID_CLOSE_INFOBAR, WX_INFOBAR::onCloseButton )
|
|
|
|
EVT_TIMER( ID_CLOSE_INFOBAR, WX_INFOBAR::onTimer )
|
2020-05-18 23:44:58 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
|
2020-12-22 21:35:25 +00:00
|
|
|
WX_INFOBAR::WX_INFOBAR( wxWindow* aParent, wxAuiManager* aMgr, wxWindowID aWinid )
|
2020-05-18 23:44:58 +00:00
|
|
|
: wxInfoBarGeneric( aParent, aWinid ),
|
2020-06-01 23:05:55 +00:00
|
|
|
m_showTime( 0 ),
|
2020-06-03 23:00:40 +00:00
|
|
|
m_updateLock( false ),
|
2020-12-22 21:35:25 +00:00
|
|
|
m_showTimer( nullptr ),
|
2021-02-16 23:42:39 +00:00
|
|
|
m_auiManager( aMgr ),
|
|
|
|
m_type( MESSAGE_TYPE::GENERIC )
|
2020-05-18 23:44:58 +00:00
|
|
|
{
|
2020-05-20 01:31:47 +00:00
|
|
|
m_showTimer = new wxTimer( this, ID_CLOSE_INFOBAR );
|
|
|
|
|
2021-04-01 17:08:58 +00:00
|
|
|
#ifdef __WXMAC__
|
|
|
|
// wxWidgets hard-codes wxSYS_COLOUR_INFOBK to { 0xFF, 0xFF, 0xD3 } on Mac.
|
2021-04-29 03:24:19 +00:00
|
|
|
if( KIPLATFORM::UI::IsDarkTheme() )
|
|
|
|
SetBackgroundColour( wxColour( 28, 27, 20 ) );
|
|
|
|
else
|
|
|
|
SetBackgroundColour( wxColour( 255, 249, 189 ) );
|
2021-04-01 10:24:36 +00:00
|
|
|
|
2021-08-27 11:47:42 +00:00
|
|
|
// Infobar is broken on Mac without the effects
|
2020-12-08 15:05:35 +00:00
|
|
|
SetShowHideEffects( wxSHOW_EFFECT_ROLL_TO_BOTTOM, wxSHOW_EFFECT_ROLL_TO_TOP );
|
2023-04-03 22:43:55 +00:00
|
|
|
SetEffectDuration( 200 );
|
2021-08-27 11:47:42 +00:00
|
|
|
#else
|
|
|
|
// Infobar freezes canvas on Windows with the effect, and GTK looks bad with it
|
|
|
|
SetShowHideEffects( wxSHOW_EFFECT_NONE, wxSHOW_EFFECT_NONE );
|
|
|
|
#endif
|
|
|
|
|
2020-05-20 19:13:47 +00:00
|
|
|
|
2020-06-01 23:05:55 +00:00
|
|
|
// The infobar seems to start too small, so increase its height
|
2020-05-18 23:44:58 +00:00
|
|
|
int sx, sy;
|
|
|
|
GetSize( &sx, &sy );
|
2020-06-01 23:05:55 +00:00
|
|
|
sy = 1.5 * sy;
|
|
|
|
|
|
|
|
// The bitmap gets cutoff sometimes with the default size, so force it to be the same
|
|
|
|
// height as the infobar.
|
|
|
|
wxSizer* sizer = GetSizer();
|
|
|
|
wxSize iconSize = wxArtProvider::GetSizeHint( wxART_BUTTON );
|
|
|
|
|
2023-05-21 01:57:08 +00:00
|
|
|
#ifdef __WXMSW__
|
|
|
|
DPI_SCALING dpi( nullptr, aParent );
|
|
|
|
iconSize.x *= dpi.GetContentScaleFactor();
|
|
|
|
sx *= dpi.GetContentScaleFactor();
|
|
|
|
sy *= dpi.GetContentScaleFactor();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
SetSize( sx, sy );
|
|
|
|
|
2020-06-01 23:05:55 +00:00
|
|
|
sizer->SetItemMinSize( (size_t) 0, iconSize.x, sy );
|
|
|
|
|
2020-06-03 23:00:40 +00:00
|
|
|
// Forcefully remove all existing buttons added by the wx constructors.
|
|
|
|
// The default close button doesn't work with the AUI manager update scheme, so this
|
|
|
|
// ensures any close button displayed is ours.
|
|
|
|
RemoveAllButtons();
|
|
|
|
|
2020-06-01 23:05:55 +00:00
|
|
|
Layout();
|
2020-12-11 12:09:37 +00:00
|
|
|
|
|
|
|
m_parent->Bind( wxEVT_SIZE, &WX_INFOBAR::onSize, this );
|
2020-05-18 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-03 23:00:40 +00:00
|
|
|
WX_INFOBAR::~WX_INFOBAR()
|
|
|
|
{
|
|
|
|
delete m_showTimer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-20 01:31:47 +00:00
|
|
|
void WX_INFOBAR::SetShowTime( int aTime )
|
|
|
|
{
|
|
|
|
m_showTime = aTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-03 23:00:40 +00:00
|
|
|
void WX_INFOBAR::QueueShowMessage( const wxString& aMessage, int aFlags )
|
|
|
|
{
|
|
|
|
wxCommandEvent* evt = new wxCommandEvent( KIEVT_SHOW_INFOBAR );
|
|
|
|
|
|
|
|
evt->SetString( aMessage.c_str() );
|
|
|
|
evt->SetInt( aFlags );
|
|
|
|
|
|
|
|
GetEventHandler()->QueueEvent( evt );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void WX_INFOBAR::QueueDismiss()
|
|
|
|
{
|
|
|
|
wxCommandEvent* evt = new wxCommandEvent( KIEVT_DISMISS_INFOBAR );
|
|
|
|
|
|
|
|
GetEventHandler()->QueueEvent( evt );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-01 20:51:08 +00:00
|
|
|
void WX_INFOBAR::ShowMessageFor( const wxString& aMessage, int aTime, int aFlags,
|
|
|
|
MESSAGE_TYPE aType )
|
2020-05-20 01:31:47 +00:00
|
|
|
{
|
2020-06-03 23:00:40 +00:00
|
|
|
// Don't do anything if we requested the UI update
|
|
|
|
if( m_updateLock )
|
|
|
|
return;
|
|
|
|
|
2020-05-20 01:31:47 +00:00
|
|
|
m_showTime = aTime;
|
|
|
|
ShowMessage( aMessage, aFlags );
|
2021-08-01 20:51:08 +00:00
|
|
|
|
|
|
|
m_type = aType;
|
2020-05-20 01:31:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-18 23:44:58 +00:00
|
|
|
void WX_INFOBAR::ShowMessage( const wxString& aMessage, int aFlags )
|
|
|
|
{
|
2020-06-03 23:00:40 +00:00
|
|
|
// Don't do anything if we requested the UI update
|
|
|
|
if( m_updateLock )
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_updateLock = true;
|
|
|
|
|
2020-05-18 23:44:58 +00:00
|
|
|
wxInfoBarGeneric::ShowMessage( aMessage, aFlags );
|
|
|
|
|
2020-12-22 21:35:25 +00:00
|
|
|
if( m_auiManager )
|
|
|
|
updateAuiLayout( true );
|
|
|
|
|
2020-05-20 01:31:47 +00:00
|
|
|
if( m_showTime > 0 )
|
|
|
|
m_showTimer->StartOnce( m_showTime );
|
2020-06-03 23:00:40 +00:00
|
|
|
|
2021-02-16 23:42:39 +00:00
|
|
|
m_type = MESSAGE_TYPE::GENERIC;
|
2020-06-03 23:00:40 +00:00
|
|
|
m_updateLock = false;
|
2020-05-18 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-16 23:42:39 +00:00
|
|
|
void WX_INFOBAR::ShowMessage( const wxString& aMessage, int aFlags, MESSAGE_TYPE aType )
|
|
|
|
{
|
|
|
|
// Don't do anything if we requested the UI update
|
|
|
|
if( m_updateLock )
|
|
|
|
return;
|
|
|
|
|
|
|
|
ShowMessage( aMessage, aFlags );
|
|
|
|
|
|
|
|
m_type = aType;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-18 23:44:58 +00:00
|
|
|
void WX_INFOBAR::Dismiss()
|
|
|
|
{
|
2022-12-18 10:54:49 +00:00
|
|
|
if( !IsShown() )
|
|
|
|
return;
|
|
|
|
|
2020-06-03 23:00:40 +00:00
|
|
|
// Don't do anything if we requested the UI update
|
|
|
|
if( m_updateLock )
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_updateLock = true;
|
|
|
|
|
2020-05-18 23:44:58 +00:00
|
|
|
wxInfoBarGeneric::Dismiss();
|
2020-05-20 01:31:47 +00:00
|
|
|
|
2020-12-22 21:35:25 +00:00
|
|
|
if( m_auiManager )
|
|
|
|
updateAuiLayout( false );
|
|
|
|
|
2021-01-04 17:51:50 +00:00
|
|
|
if( m_callback )
|
|
|
|
(*m_callback)();
|
|
|
|
|
2020-06-03 23:00:40 +00:00
|
|
|
m_updateLock = false;
|
2020-05-18 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2020-12-29 10:13:07 +00:00
|
|
|
|
2020-12-11 12:09:37 +00:00
|
|
|
void WX_INFOBAR::onSize( wxSizeEvent& aEvent )
|
2020-05-18 23:44:58 +00:00
|
|
|
{
|
2020-12-11 12:09:37 +00:00
|
|
|
int barWidth = GetSize().GetWidth();
|
2020-12-29 09:32:22 +00:00
|
|
|
|
|
|
|
// Calculate the horizontal size: because the infobar is shown on top of the draw canvas
|
|
|
|
// it is adjusted to the canvas width.
|
|
|
|
// On Mac, the canvas is the parent
|
2021-04-05 13:24:57 +00:00
|
|
|
// On other OS the parent is EDA_BASE_FRAME that contains the canvas
|
2020-12-21 16:44:10 +00:00
|
|
|
int parentWidth = m_parent->GetClientSize().GetWidth();
|
2020-12-29 09:32:22 +00:00
|
|
|
EDA_BASE_FRAME* frame = dynamic_cast<EDA_BASE_FRAME*>( m_parent );
|
|
|
|
|
|
|
|
if( frame && frame->GetToolCanvas() )
|
|
|
|
parentWidth = frame->GetToolCanvas()->GetSize().GetWidth();
|
|
|
|
|
2020-05-20 01:31:47 +00:00
|
|
|
|
2020-12-11 12:09:37 +00:00
|
|
|
if( barWidth != parentWidth )
|
|
|
|
SetSize( parentWidth, GetSize().GetHeight() );
|
2020-05-20 01:31:47 +00:00
|
|
|
|
2020-12-11 12:09:37 +00:00
|
|
|
aEvent.Skip();
|
2020-05-18 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-22 21:35:25 +00:00
|
|
|
void WX_INFOBAR::updateAuiLayout( bool aShow )
|
|
|
|
{
|
|
|
|
wxASSERT( m_auiManager );
|
|
|
|
|
|
|
|
wxAuiPaneInfo& pane = m_auiManager->GetPane( this );
|
|
|
|
|
|
|
|
// If the infobar is in a pane, then show/hide the pane
|
|
|
|
if( pane.IsOk() )
|
|
|
|
{
|
|
|
|
if( aShow )
|
|
|
|
pane.Show();
|
|
|
|
else
|
|
|
|
pane.Hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the AUI manager regardless
|
|
|
|
m_auiManager->Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-18 23:44:58 +00:00
|
|
|
void WX_INFOBAR::AddButton( wxWindowID aId, const wxString& aLabel )
|
|
|
|
{
|
|
|
|
wxButton* button = new wxButton( this, aId, aLabel );
|
|
|
|
|
|
|
|
AddButton( button );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void WX_INFOBAR::AddButton( wxButton* aButton )
|
|
|
|
{
|
|
|
|
wxSizer* sizer = GetSizer();
|
|
|
|
|
2020-05-20 01:31:47 +00:00
|
|
|
wxASSERT( aButton );
|
|
|
|
|
2020-05-18 23:44:58 +00:00
|
|
|
#ifdef __WXMAC__
|
|
|
|
// Based on the code in the original class:
|
|
|
|
// smaller buttons look better in the (narrow) info bar under OS X
|
|
|
|
aButton->SetWindowVariant( wxWINDOW_VARIANT_SMALL );
|
|
|
|
#endif // __WXMAC__
|
2020-05-20 19:13:47 +00:00
|
|
|
sizer->Add( aButton, wxSizerFlags().Centre().Border( wxRIGHT ) );
|
2020-05-18 23:44:58 +00:00
|
|
|
|
|
|
|
if( IsShown() )
|
|
|
|
sizer->Layout();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-16 11:20:37 +00:00
|
|
|
void WX_INFOBAR::AddButton( wxHyperlinkCtrl* aHypertextButton )
|
|
|
|
{
|
|
|
|
wxSizer* sizer = GetSizer();
|
|
|
|
|
|
|
|
wxASSERT( aHypertextButton );
|
|
|
|
|
|
|
|
sizer->Add( aHypertextButton, wxSizerFlags().Centre().Border( wxRIGHT ) );
|
|
|
|
|
|
|
|
if( IsShown() )
|
|
|
|
sizer->Layout();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-18 23:44:58 +00:00
|
|
|
void WX_INFOBAR::AddCloseButton( const wxString& aTooltip )
|
|
|
|
{
|
|
|
|
wxBitmapButton* button = wxBitmapButton::NewCloseButton( this, ID_CLOSE_INFOBAR );
|
|
|
|
|
|
|
|
button->SetToolTip( aTooltip );
|
|
|
|
|
|
|
|
AddButton( button );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void WX_INFOBAR::RemoveAllButtons()
|
|
|
|
{
|
|
|
|
wxSizer* sizer = GetSizer();
|
|
|
|
|
|
|
|
if( sizer->GetItemCount() == 0 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// The last item is already the spacer
|
|
|
|
if( sizer->GetItem( sizer->GetItemCount() - 1 )->IsSpacer() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
for( int i = sizer->GetItemCount() - 1; i >= 0; i-- )
|
|
|
|
{
|
|
|
|
wxSizerItem* sItem = sizer->GetItem( i );
|
|
|
|
|
|
|
|
// The spacer is the end of the custom buttons
|
|
|
|
if( sItem->IsSpacer() )
|
|
|
|
break;
|
|
|
|
|
|
|
|
delete sItem->GetWindow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-13 04:24:05 +00:00
|
|
|
bool WX_INFOBAR::HasCloseButton() const
|
|
|
|
{
|
|
|
|
wxSizer* sizer = GetSizer();
|
|
|
|
|
|
|
|
if( sizer->GetItemCount() == 0 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( sizer->GetItem( sizer->GetItemCount() - 1 )->IsSpacer() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
wxSizerItem* item = sizer->GetItem( sizer->GetItemCount() - 1 );
|
|
|
|
|
|
|
|
return ( item->GetWindow()->GetId() == ID_CLOSE_INFOBAR );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-12 03:18:43 +00:00
|
|
|
void WX_INFOBAR::onShowInfoBar( wxCommandEvent& aEvent )
|
2020-06-03 23:00:40 +00:00
|
|
|
{
|
|
|
|
RemoveAllButtons();
|
|
|
|
AddCloseButton();
|
|
|
|
ShowMessage( aEvent.GetString(), aEvent.GetInt() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-12 03:18:43 +00:00
|
|
|
void WX_INFOBAR::onDismissInfoBar( wxCommandEvent& aEvent )
|
2020-06-03 23:00:40 +00:00
|
|
|
{
|
|
|
|
Dismiss();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-12 03:18:43 +00:00
|
|
|
void WX_INFOBAR::onCloseButton( wxCommandEvent& aEvent )
|
2020-05-18 23:44:58 +00:00
|
|
|
{
|
|
|
|
Dismiss();
|
|
|
|
}
|
2020-05-20 01:31:47 +00:00
|
|
|
|
|
|
|
|
2020-12-12 03:18:43 +00:00
|
|
|
void WX_INFOBAR::onTimer( wxTimerEvent& aEvent )
|
2020-05-20 01:31:47 +00:00
|
|
|
{
|
|
|
|
// Reset and clear the timer
|
|
|
|
m_showTimer->Stop();
|
|
|
|
m_showTime = 0;
|
|
|
|
|
|
|
|
Dismiss();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EDA_INFOBAR_PANEL::EDA_INFOBAR_PANEL( wxWindow* aParent, wxWindowID aId, const wxPoint& aPos,
|
|
|
|
const wxSize& aSize, long aStyle, const wxString& aName )
|
|
|
|
: wxPanel( aParent, aId, aPos, aSize, aStyle, aName )
|
|
|
|
{
|
|
|
|
m_mainSizer = new wxFlexGridSizer( 1, 0, 0 );
|
|
|
|
|
|
|
|
m_mainSizer->SetFlexibleDirection( wxBOTH );
|
|
|
|
m_mainSizer->AddGrowableCol( 0, 1 );
|
|
|
|
|
|
|
|
SetSizer( m_mainSizer );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EDA_INFOBAR_PANEL::AddInfoBar( WX_INFOBAR* aInfoBar )
|
|
|
|
{
|
|
|
|
wxASSERT( aInfoBar );
|
|
|
|
|
|
|
|
aInfoBar->Reparent( this );
|
2020-05-20 17:59:39 +00:00
|
|
|
m_mainSizer->Add( aInfoBar, 1, wxEXPAND, 0 );
|
2020-05-20 01:31:47 +00:00
|
|
|
m_mainSizer->Layout();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EDA_INFOBAR_PANEL::AddOtherItem( wxWindow* aOtherItem )
|
|
|
|
{
|
|
|
|
wxASSERT( aOtherItem );
|
|
|
|
|
|
|
|
aOtherItem->Reparent( this );
|
2020-05-20 17:59:39 +00:00
|
|
|
m_mainSizer->Add( aOtherItem, 1, wxEXPAND, 0 );
|
2020-05-20 01:31:47 +00:00
|
|
|
|
|
|
|
m_mainSizer->AddGrowableRow( 1, 1 );
|
|
|
|
m_mainSizer->Layout();
|
|
|
|
}
|