2011-12-16 13:32:23 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
|
|
|
|
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
|
2021-09-11 12:44:12 +00:00
|
|
|
* Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-12-16 13:32:23 +00:00
|
|
|
*
|
|
|
|
* 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 2
|
|
|
|
* 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, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2020-10-25 04:49:02 +00:00
|
|
|
#include <widgets/msgpanel.h>
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2020-10-18 11:31:07 +00:00
|
|
|
#include <wx/dcscreen.h>
|
|
|
|
#include <wx/dcclient.h>
|
2020-10-18 16:45:34 +00:00
|
|
|
#include <wx/settings.h>
|
2021-03-25 20:54:31 +00:00
|
|
|
#include <wx/toplevel.h>
|
2020-10-18 11:31:07 +00:00
|
|
|
|
2021-09-08 19:17:46 +00:00
|
|
|
#include <widgets/ui_common.h>
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-04-12 14:19:59 +00:00
|
|
|
BEGIN_EVENT_TABLE( EDA_MSG_PANEL, wxPanel )
|
|
|
|
EVT_PAINT( EDA_MSG_PANEL::OnPaint )
|
2007-05-06 16:03:28 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
|
2021-07-21 23:14:56 +00:00
|
|
|
EDA_MSG_PANEL::EDA_MSG_PANEL( wxWindow* aParent, int aId, const wxPoint& aPosition,
|
|
|
|
const wxSize& aSize, long style, const wxString &name ) :
|
2014-05-15 06:32:24 +00:00
|
|
|
wxPanel( aParent, aId, aPosition, aSize, style, name )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2021-09-11 19:07:33 +00:00
|
|
|
SetFont( KIUI::GetStatusFont( this ) );
|
2009-04-15 19:53:41 +00:00
|
|
|
SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
|
2020-12-10 01:21:24 +00:00
|
|
|
|
|
|
|
// informs wx not to paint the background itself as we will paint it later in erase()
|
|
|
|
SetBackgroundStyle( wxBG_STYLE_PAINT );
|
|
|
|
|
2008-03-31 13:46:00 +00:00
|
|
|
m_last_x = 0;
|
2009-08-07 04:44:42 +00:00
|
|
|
|
2021-09-08 19:17:46 +00:00
|
|
|
m_fontSize = GetTextExtent( wxT( "W" ) );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-12 14:19:59 +00:00
|
|
|
EDA_MSG_PANEL::~EDA_MSG_PANEL()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-12 11:17:22 +00:00
|
|
|
int EDA_MSG_PANEL::GetRequiredHeight( wxWindow* aWindow )
|
2009-08-07 04:44:42 +00:00
|
|
|
{
|
2013-01-12 17:32:24 +00:00
|
|
|
wxSize fontSizeInPixels;
|
2022-03-14 03:31:06 +00:00
|
|
|
wxWindowDC dc( aWindow );
|
2009-08-07 04:44:42 +00:00
|
|
|
|
2021-09-12 11:17:22 +00:00
|
|
|
dc.SetFont( KIUI::GetControlFont( aWindow ) );
|
2009-08-07 04:44:42 +00:00
|
|
|
dc.GetTextExtent( wxT( "W" ), &fontSizeInPixels.x, &fontSizeInPixels.y );
|
|
|
|
|
|
|
|
// make space for two rows of text plus a number of pixels between them.
|
2021-09-12 11:17:22 +00:00
|
|
|
return 2 * fontSizeInPixels.y + 0;
|
2009-08-07 04:44:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-12 17:32:24 +00:00
|
|
|
void EDA_MSG_PANEL::OnPaint( wxPaintEvent& aEvent )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-10-03 19:45:32 +00:00
|
|
|
wxPaintDC dc( this );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2008-03-31 13:46:00 +00:00
|
|
|
erase( &dc );
|
2007-10-10 18:01:14 +00:00
|
|
|
|
2009-04-15 19:53:41 +00:00
|
|
|
dc.SetBackground( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
|
2007-10-10 18:01:14 +00:00
|
|
|
dc.SetBackgroundMode( wxSOLID );
|
2009-04-15 19:53:41 +00:00
|
|
|
dc.SetTextBackground( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
|
2021-09-11 19:07:33 +00:00
|
|
|
dc.SetFont( KIUI::GetControlFont( this ) );
|
2008-03-31 13:46:00 +00:00
|
|
|
|
2021-03-25 20:54:31 +00:00
|
|
|
for( const MSG_PANEL_ITEM& item : m_Items )
|
|
|
|
showItem( dc, item );
|
2008-03-31 13:46:00 +00:00
|
|
|
|
2013-01-12 17:32:24 +00:00
|
|
|
aEvent.Skip();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2013-01-12 17:32:24 +00:00
|
|
|
|
2020-11-18 15:36:47 +00:00
|
|
|
void EDA_MSG_PANEL::AppendMessage( const wxString& aUpperText, const wxString& aLowerText,
|
|
|
|
int aPadding )
|
2009-09-18 14:56:05 +00:00
|
|
|
{
|
|
|
|
wxString text;
|
|
|
|
wxSize drawSize = GetClientSize();
|
|
|
|
|
2013-01-12 17:32:24 +00:00
|
|
|
text = ( aUpperText.Len() > aLowerText.Len() ) ? aUpperText : aLowerText;
|
2020-11-18 15:36:47 +00:00
|
|
|
text.Append( ' ', aPadding );
|
2009-09-18 14:56:05 +00:00
|
|
|
|
2013-01-12 17:32:24 +00:00
|
|
|
MSG_PANEL_ITEM item;
|
2009-09-18 14:56:05 +00:00
|
|
|
|
|
|
|
/* Don't put the first message a window client position 0. Offset by
|
|
|
|
* one 'W' character width. */
|
|
|
|
if( m_last_x == 0 )
|
|
|
|
m_last_x = m_fontSize.x;
|
|
|
|
|
|
|
|
item.m_X = m_last_x;
|
|
|
|
|
|
|
|
item.m_UpperY = ( drawSize.y / 2 ) - m_fontSize.y;
|
|
|
|
item.m_LowerY = drawSize.y - m_fontSize.y;
|
|
|
|
|
2013-01-12 17:32:24 +00:00
|
|
|
item.m_UpperText = aUpperText;
|
|
|
|
item.m_LowerText = aLowerText;
|
2009-09-18 14:56:05 +00:00
|
|
|
m_Items.push_back( item );
|
2021-09-08 20:34:02 +00:00
|
|
|
m_last_x += GetTextExtent( text ).x;
|
2009-09-18 14:56:05 +00:00
|
|
|
|
2009-10-11 13:04:47 +00:00
|
|
|
// Add an extra space between texts for a better look:
|
|
|
|
m_last_x += m_fontSize.x;
|
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
Refresh();
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-10-03 19:45:32 +00:00
|
|
|
|
2011-04-12 14:19:59 +00:00
|
|
|
void EDA_MSG_PANEL::SetMessage( int aXPosition, const wxString& aUpperText,
|
2020-11-18 15:36:47 +00:00
|
|
|
const wxString& aLowerText )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-04-12 14:19:59 +00:00
|
|
|
wxPoint pos;
|
|
|
|
wxSize drawSize = GetClientSize();
|
2007-10-03 19:45:32 +00:00
|
|
|
|
2011-04-12 14:19:59 +00:00
|
|
|
if( aXPosition >= 0 )
|
|
|
|
m_last_x = pos.x = aXPosition * (m_fontSize.x + 2);
|
2007-10-03 19:45:32 +00:00
|
|
|
else
|
2008-03-31 13:46:00 +00:00
|
|
|
pos.x = m_last_x;
|
2007-10-03 19:45:32 +00:00
|
|
|
|
2013-01-12 17:32:24 +00:00
|
|
|
MSG_PANEL_ITEM item;
|
2008-03-31 13:46:00 +00:00
|
|
|
|
2007-10-10 18:01:14 +00:00
|
|
|
item.m_X = pos.x;
|
2008-03-31 13:46:00 +00:00
|
|
|
|
2009-08-07 04:44:42 +00:00
|
|
|
item.m_UpperY = (drawSize.y / 2) - m_fontSize.y;
|
|
|
|
item.m_LowerY = drawSize.y - m_fontSize.y;
|
2008-03-31 13:46:00 +00:00
|
|
|
|
2011-04-12 14:19:59 +00:00
|
|
|
item.m_UpperText = aUpperText;
|
|
|
|
item.m_LowerText = aLowerText;
|
2008-03-31 13:46:00 +00:00
|
|
|
|
2007-10-10 18:01:14 +00:00
|
|
|
int ndx;
|
|
|
|
|
2008-03-31 13:46:00 +00:00
|
|
|
// update the vector, which is sorted by m_X
|
2007-10-10 18:01:14 +00:00
|
|
|
int limit = m_Items.size();
|
2011-04-12 14:19:59 +00:00
|
|
|
|
2021-07-21 23:14:56 +00:00
|
|
|
for( ndx = 0; ndx < limit; ++ndx )
|
2007-10-03 19:45:32 +00:00
|
|
|
{
|
2007-10-10 18:01:14 +00:00
|
|
|
// replace any item with same X
|
|
|
|
if( m_Items[ndx].m_X == item.m_X )
|
|
|
|
{
|
|
|
|
m_Items[ndx] = item;
|
|
|
|
break;
|
|
|
|
}
|
2008-03-31 13:46:00 +00:00
|
|
|
|
2007-10-10 18:01:14 +00:00
|
|
|
if( m_Items[ndx].m_X > item.m_X )
|
|
|
|
{
|
2009-11-23 15:16:50 +00:00
|
|
|
m_Items.insert( m_Items.begin() + ndx, item );
|
2007-10-10 18:01:14 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-10-03 19:45:32 +00:00
|
|
|
}
|
2008-03-31 13:46:00 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
if( ndx == limit ) // mutually exclusive with two above if tests
|
2007-10-10 18:01:14 +00:00
|
|
|
m_Items.push_back( item );
|
2008-03-31 13:46:00 +00:00
|
|
|
|
|
|
|
Refresh();
|
2007-10-10 18:01:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-12 17:32:24 +00:00
|
|
|
void EDA_MSG_PANEL::showItem( wxDC& aDC, const MSG_PANEL_ITEM& aItem )
|
2007-10-10 18:01:14 +00:00
|
|
|
{
|
2021-03-25 20:54:31 +00:00
|
|
|
COLOR4D color;
|
|
|
|
|
|
|
|
// Change the text to a disabled color when the window isn't active
|
|
|
|
wxTopLevelWindow* tlw = dynamic_cast<wxTopLevelWindow*>( wxGetTopLevelParent( this ) );
|
|
|
|
|
|
|
|
if( tlw && !tlw->IsActive() )
|
|
|
|
color = wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT );
|
|
|
|
else
|
|
|
|
color = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT );
|
2008-03-31 13:46:00 +00:00
|
|
|
|
2017-02-20 16:57:41 +00:00
|
|
|
aDC.SetTextForeground( color.ToColour() );
|
2007-10-10 18:01:14 +00:00
|
|
|
|
|
|
|
if( !aItem.m_UpperText.IsEmpty() )
|
2013-01-12 17:32:24 +00:00
|
|
|
aDC.DrawText( aItem.m_UpperText, aItem.m_X, aItem.m_UpperY );
|
2008-03-31 13:46:00 +00:00
|
|
|
|
2007-10-10 18:01:14 +00:00
|
|
|
if( !aItem.m_LowerText.IsEmpty() )
|
2013-01-12 17:32:24 +00:00
|
|
|
aDC.DrawText( aItem.m_LowerText, aItem.m_X, aItem.m_LowerY );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-10-03 19:45:32 +00:00
|
|
|
|
2011-04-12 14:19:59 +00:00
|
|
|
void EDA_MSG_PANEL::EraseMsgBox()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2008-03-31 13:46:00 +00:00
|
|
|
m_Items.clear();
|
|
|
|
m_last_x = 0;
|
|
|
|
Refresh();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2011-09-01 12:54:34 +00:00
|
|
|
|
2013-01-12 17:32:24 +00:00
|
|
|
void EDA_MSG_PANEL::erase( wxDC* aDC )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-10-03 19:45:32 +00:00
|
|
|
wxPen pen;
|
|
|
|
wxBrush brush;
|
|
|
|
|
2008-03-31 13:46:00 +00:00
|
|
|
wxSize size = GetClientSize();
|
2017-02-20 16:57:41 +00:00
|
|
|
wxColour color = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE );
|
2008-03-31 13:46:00 +00:00
|
|
|
|
2007-10-03 19:45:32 +00:00
|
|
|
pen.SetColour( color );
|
2008-03-31 13:46:00 +00:00
|
|
|
|
2007-10-03 19:45:32 +00:00
|
|
|
brush.SetColour( color );
|
2014-01-08 01:34:04 +00:00
|
|
|
brush.SetStyle( wxBRUSHSTYLE_SOLID );
|
2008-03-31 13:46:00 +00:00
|
|
|
|
2013-01-12 17:32:24 +00:00
|
|
|
aDC->SetPen( pen );
|
|
|
|
aDC->SetBrush( brush );
|
|
|
|
aDC->DrawRectangle( 0, 0, size.x, size.y );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|