You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

240 lines
6.2 KiB

18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
  5. * Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
  6. * Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. /**
  26. * @file msgpanel.cpp
  27. * @brief Message panel implementation file.
  28. */
  29. #include <msgpanel.h>
  30. BEGIN_EVENT_TABLE( EDA_MSG_PANEL, wxPanel )
  31. EVT_PAINT( EDA_MSG_PANEL::OnPaint )
  32. END_EVENT_TABLE()
  33. EDA_MSG_PANEL::EDA_MSG_PANEL( wxWindow* aParent, int aId,
  34. const wxPoint& aPosition, const wxSize& aSize,
  35. long style, const wxString &name ) :
  36. wxPanel( aParent, aId, aPosition, aSize, style, name )
  37. {
  38. SetFont( wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ) );
  39. SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
  40. m_last_x = 0;
  41. m_fontSize = computeFontSize();
  42. }
  43. EDA_MSG_PANEL::~EDA_MSG_PANEL()
  44. {
  45. }
  46. wxSize EDA_MSG_PANEL::computeFontSize()
  47. {
  48. // Get size of the wxSYS_DEFAULT_GUI_FONT
  49. wxSize fontSizeInPixels;
  50. wxScreenDC dc;
  51. dc.SetFont( wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ) );
  52. dc.GetTextExtent( wxT( "W" ), &fontSizeInPixels.x, &fontSizeInPixels.y );
  53. return fontSizeInPixels;
  54. }
  55. int EDA_MSG_PANEL::GetRequiredHeight()
  56. {
  57. // make space for two rows of text plus a number of pixels between them.
  58. return 2 * computeFontSize().y + 0;
  59. }
  60. wxSize EDA_MSG_PANEL::computeTextSize( const wxString& aText ) const
  61. {
  62. // Get size of the wxSYS_DEFAULT_GUI_FONT
  63. wxSize textSizeInPixels;
  64. wxScreenDC dc;
  65. dc.SetFont( wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ) );
  66. dc.GetTextExtent( aText, &textSizeInPixels.x, &textSizeInPixels.y );
  67. return textSizeInPixels;
  68. }
  69. void EDA_MSG_PANEL::OnPaint( wxPaintEvent& aEvent )
  70. {
  71. wxPaintDC dc( this );
  72. erase( &dc );
  73. dc.SetBackground( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
  74. dc.SetBackgroundMode( wxSOLID );
  75. dc.SetTextBackground( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
  76. dc.SetFont( wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ) );
  77. for( unsigned i=0; i<m_Items.size(); ++i )
  78. showItem( dc, m_Items[i] );
  79. aEvent.Skip();
  80. }
  81. void EDA_MSG_PANEL::AppendMessage( const wxString& aUpperText,
  82. const wxString& aLowerText,
  83. COLOR4D aColor, int aPad )
  84. {
  85. wxString text;
  86. wxSize drawSize = GetClientSize();
  87. text = ( aUpperText.Len() > aLowerText.Len() ) ? aUpperText : aLowerText;
  88. text.Append( ' ', aPad );
  89. MSG_PANEL_ITEM item;
  90. /* Don't put the first message a window client position 0. Offset by
  91. * one 'W' character width. */
  92. if( m_last_x == 0 )
  93. m_last_x = m_fontSize.x;
  94. item.m_X = m_last_x;
  95. item.m_UpperY = ( drawSize.y / 2 ) - m_fontSize.y;
  96. item.m_LowerY = drawSize.y - m_fontSize.y;
  97. item.m_UpperText = aUpperText;
  98. item.m_LowerText = aLowerText;
  99. item.m_Color = aColor;
  100. m_Items.push_back( item );
  101. m_last_x += computeTextSize( text ).x;
  102. // Add an extra space between texts for a better look:
  103. m_last_x += m_fontSize.x;
  104. Refresh();
  105. }
  106. void EDA_MSG_PANEL::SetMessage( int aXPosition, const wxString& aUpperText,
  107. const wxString& aLowerText, COLOR4D aColor )
  108. {
  109. wxPoint pos;
  110. wxSize drawSize = GetClientSize();
  111. if( aXPosition >= 0 )
  112. m_last_x = pos.x = aXPosition * (m_fontSize.x + 2);
  113. else
  114. pos.x = m_last_x;
  115. MSG_PANEL_ITEM item;
  116. item.m_X = pos.x;
  117. item.m_UpperY = (drawSize.y / 2) - m_fontSize.y;
  118. item.m_LowerY = drawSize.y - m_fontSize.y;
  119. item.m_UpperText = aUpperText;
  120. item.m_LowerText = aLowerText;
  121. item.m_Color = aColor;
  122. int ndx;
  123. // update the vector, which is sorted by m_X
  124. int limit = m_Items.size();
  125. for( ndx=0; ndx<limit; ++ndx )
  126. {
  127. // replace any item with same X
  128. if( m_Items[ndx].m_X == item.m_X )
  129. {
  130. m_Items[ndx] = item;
  131. break;
  132. }
  133. if( m_Items[ndx].m_X > item.m_X )
  134. {
  135. m_Items.insert( m_Items.begin() + ndx, item );
  136. break;
  137. }
  138. }
  139. if( ndx == limit ) // mutually exclusive with two above if tests
  140. {
  141. m_Items.push_back( item );
  142. }
  143. Refresh();
  144. }
  145. void EDA_MSG_PANEL::showItem( wxDC& aDC, const MSG_PANEL_ITEM& aItem )
  146. {
  147. // COLOR4D color = aItem.m_Color;
  148. COLOR4D color = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT );
  149. aDC.SetTextForeground( color.ToColour() );
  150. if( !aItem.m_UpperText.IsEmpty() )
  151. {
  152. aDC.DrawText( aItem.m_UpperText, aItem.m_X, aItem.m_UpperY );
  153. }
  154. if( !aItem.m_LowerText.IsEmpty() )
  155. {
  156. aDC.DrawText( aItem.m_LowerText, aItem.m_X, aItem.m_LowerY );
  157. }
  158. }
  159. void EDA_MSG_PANEL::EraseMsgBox()
  160. {
  161. m_Items.clear();
  162. m_last_x = 0;
  163. Refresh();
  164. }
  165. void EDA_MSG_PANEL::erase( wxDC* aDC )
  166. {
  167. wxPen pen;
  168. wxBrush brush;
  169. wxSize size = GetClientSize();
  170. wxColour color = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE );
  171. pen.SetColour( color );
  172. brush.SetColour( color );
  173. brush.SetStyle( wxBRUSHSTYLE_SOLID );
  174. aDC->SetPen( pen );
  175. aDC->SetBrush( brush );
  176. aDC->DrawRectangle( 0, 0, size.x, size.y );
  177. }