2009-11-23 15:16:50 +00:00
|
|
|
/****************/
|
|
|
|
/* msgpanel.cpp */
|
|
|
|
/****************/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "wxstruct.h"
|
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "colors.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()
|
|
|
|
|
|
|
|
|
2011-04-12 14:19:59 +00:00
|
|
|
EDA_MSG_PANEL::EDA_MSG_PANEL( EDA_DRAW_FRAME* parent, int id,
|
|
|
|
const wxPoint& pos, const wxSize& size ) :
|
2007-10-03 19:45:32 +00:00
|
|
|
wxPanel( parent, id, pos, size )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-10-03 19:45:32 +00:00
|
|
|
m_Parent = parent;
|
2009-04-15 19:53:41 +00:00
|
|
|
SetFont( wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ) );
|
|
|
|
SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
|
2008-03-31 13:46:00 +00:00
|
|
|
m_last_x = 0;
|
2009-08-07 04:44:42 +00:00
|
|
|
|
|
|
|
m_fontSize = computeFontSize();
|
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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-12 14:19:59 +00:00
|
|
|
wxSize EDA_MSG_PANEL::computeFontSize()
|
2009-08-07 04:44:42 +00:00
|
|
|
{
|
|
|
|
// Get size of the wxSYS_DEFAULT_GUI_FONT
|
|
|
|
wxSize fontSizeInPixels;
|
|
|
|
|
|
|
|
wxScreenDC dc;
|
|
|
|
|
|
|
|
dc.SetFont( wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ) );
|
|
|
|
dc.GetTextExtent( wxT( "W" ), &fontSizeInPixels.x, &fontSizeInPixels.y );
|
|
|
|
|
|
|
|
return fontSizeInPixels;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-12 14:19:59 +00:00
|
|
|
int EDA_MSG_PANEL::GetRequiredHeight()
|
2009-08-07 04:44:42 +00:00
|
|
|
{
|
|
|
|
// make space for two rows of text plus a number of pixels between them.
|
|
|
|
return 2 * computeFontSize().y + 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-12 14:19:59 +00:00
|
|
|
wxSize EDA_MSG_PANEL::computeTextSize( const wxString& text )
|
2009-09-18 14:56:05 +00:00
|
|
|
{
|
|
|
|
// Get size of the wxSYS_DEFAULT_GUI_FONT
|
|
|
|
wxSize textSizeInPixels;
|
|
|
|
|
|
|
|
wxScreenDC dc;
|
|
|
|
|
|
|
|
dc.SetFont( wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ) );
|
|
|
|
dc.GetTextExtent( text, &textSizeInPixels.x, &textSizeInPixels.y );
|
|
|
|
|
|
|
|
return textSizeInPixels;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-12 14:19:59 +00:00
|
|
|
void EDA_MSG_PANEL::OnPaint( wxPaintEvent& event )
|
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 ) );
|
|
|
|
dc.SetFont( wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ) );
|
2008-03-31 13:46:00 +00:00
|
|
|
|
2007-10-10 18:01:14 +00:00
|
|
|
for( unsigned i=0; i<m_Items.size(); ++i )
|
|
|
|
showItem( dc, m_Items[i] );
|
2008-03-31 13:46:00 +00:00
|
|
|
|
2007-10-10 18:01:14 +00:00
|
|
|
event.Skip();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2011-04-12 14:19:59 +00:00
|
|
|
void EDA_MSG_PANEL::AppendMessage( const wxString& textUpper,
|
|
|
|
const wxString& textLower,
|
|
|
|
int color, int pad )
|
2009-09-18 14:56:05 +00:00
|
|
|
{
|
|
|
|
wxString text;
|
|
|
|
wxSize drawSize = GetClientSize();
|
|
|
|
|
|
|
|
text = ( textUpper.Len() > textLower.Len() ) ? textUpper : textLower;
|
|
|
|
text.Append( ' ', pad );
|
|
|
|
|
2011-09-01 12:54:34 +00:00
|
|
|
EDA_MSG_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;
|
|
|
|
|
|
|
|
item.m_UpperText = textUpper;
|
|
|
|
item.m_LowerText = textLower;
|
|
|
|
item.m_Color = color;
|
|
|
|
m_Items.push_back( item );
|
|
|
|
m_last_x += computeTextSize( text ).x;
|
|
|
|
|
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,
|
|
|
|
const wxString& aLowerText, int aColor )
|
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
|
|
|
|
2011-09-01 12:54:34 +00:00
|
|
|
EDA_MSG_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;
|
|
|
|
item.m_Color = aColor;
|
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
|
|
|
|
2007-10-10 18:01:14 +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-03 19:45:32 +00:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-01 12:54:34 +00:00
|
|
|
void EDA_MSG_PANEL::showItem( wxDC& dc, const EDA_MSG_ITEM& aItem )
|
2007-10-10 18:01:14 +00:00
|
|
|
{
|
|
|
|
int color = aItem.m_Color;
|
2008-03-31 13:46:00 +00:00
|
|
|
|
2007-10-10 18:01:14 +00:00
|
|
|
if( color >= 0 )
|
|
|
|
{
|
|
|
|
color &= MASKCOLOR;
|
2008-03-31 13:46:00 +00:00
|
|
|
dc.SetTextForeground( wxColour( ColorRefs[color].m_Red,
|
2007-10-10 18:01:14 +00:00
|
|
|
ColorRefs[color].m_Green,
|
|
|
|
ColorRefs[color].m_Blue ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !aItem.m_UpperText.IsEmpty() )
|
|
|
|
{
|
2009-10-13 09:00:46 +00:00
|
|
|
dc.DrawText( aItem.m_UpperText, aItem.m_X, aItem.m_UpperY );
|
2007-10-10 18:01:14 +00:00
|
|
|
}
|
2008-03-31 13:46:00 +00:00
|
|
|
|
2007-10-10 18:01:14 +00:00
|
|
|
if( !aItem.m_LowerText.IsEmpty() )
|
|
|
|
{
|
2009-10-13 09:00:46 +00:00
|
|
|
dc.DrawText( aItem.m_LowerText, aItem.m_X, aItem.m_LowerY );
|
2007-10-03 19:45:32 +00:00
|
|
|
}
|
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
|
|
|
|
2011-04-12 14:19:59 +00:00
|
|
|
void EDA_MSG_PANEL::erase( wxDC* DC )
|
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();
|
2009-04-15 19:53:41 +00:00
|
|
|
wxColor 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 );
|
|
|
|
brush.SetStyle( wxSOLID );
|
2008-03-31 13:46:00 +00:00
|
|
|
|
2007-10-03 19:45:32 +00:00
|
|
|
DC->SetPen( pen );
|
|
|
|
DC->SetBrush( brush );
|
|
|
|
|
|
|
|
DC->DrawRectangle( 0, 0, size.x, size.y );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|