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.

184 lines
5.7 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
  5. * Copyright (C) 2011-2012 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.h
  27. * @brief Message panel definition file.
  28. */
  29. #ifndef _MSGPANEL_H_
  30. #define _MSGPANEL_H_
  31. #include <colors.h>
  32. #include <wx/window.h>
  33. #include <vector>
  34. #define MSG_PANEL_DEFAULT_PAD 6 ///< The default number of spaces between each text string.
  35. class EDA_MSG_PANEL;
  36. /**
  37. * Class EDA_MSG_ITEM
  38. * is used EDA_MSG_PANEL as the item type for displaying messages.
  39. */
  40. class MSG_PANEL_ITEM
  41. {
  42. int m_X;
  43. int m_UpperY;
  44. int m_LowerY;
  45. wxString m_UpperText;
  46. wxString m_LowerText;
  47. EDA_COLOR_T m_Color;
  48. int m_Pad;
  49. friend class EDA_MSG_PANEL;
  50. public:
  51. MSG_PANEL_ITEM( const wxString& aUpperText, const wxString& aLowerText, EDA_COLOR_T aColor,
  52. int aPad = MSG_PANEL_DEFAULT_PAD ) :
  53. m_UpperText( aUpperText ),
  54. m_LowerText( aLowerText ),
  55. m_Color( aColor ),
  56. m_Pad( aPad )
  57. {
  58. }
  59. MSG_PANEL_ITEM()
  60. {
  61. }
  62. void SetUpperText( const wxString& aUpperText ) { m_UpperText = aUpperText; }
  63. const wxString& GetUpperText() const { return m_UpperText; }
  64. void SetLowerText( const wxString& aLowerText ) { m_LowerText = aLowerText; }
  65. const wxString& GetLowerText() const { return m_LowerText; }
  66. void SetColor( EDA_COLOR_T aColor ) { m_Color = aColor; }
  67. EDA_COLOR_T GetColor() const { return m_Color; }
  68. void SetPadding( int aPad ) { m_Pad = aPad; }
  69. int GetPadding() const { return m_Pad; }
  70. };
  71. typedef std::vector<MSG_PANEL_ITEM> MSG_PANEL_ITEMS;
  72. typedef MSG_PANEL_ITEMS::iterator MSG_PANEL_ITEMS_ITER;
  73. typedef MSG_PANEL_ITEMS::const_iterator MSG_PANEL_ITEMS_CITER;
  74. /**
  75. * class EDA_MSG_PANEL
  76. * is a panel to display various information messages.
  77. */
  78. class EDA_MSG_PANEL : public wxPanel
  79. {
  80. protected:
  81. MSG_PANEL_ITEMS m_Items;
  82. int m_last_x; ///< the last used x coordinate
  83. wxSize m_fontSize;
  84. void showItem( wxDC& dc, const MSG_PANEL_ITEM& aItem );
  85. void erase( wxDC* DC );
  86. /**
  87. * Function getFontSize
  88. * computes the height and width of a 'W' in the system font.
  89. */
  90. static wxSize computeFontSize();
  91. /**
  92. * Calculate the width and height of a text string using the system UI font.
  93. */
  94. wxSize computeTextSize( const wxString& text ) const;
  95. public:
  96. EDA_MSG_PANEL( wxWindow* aParent, int aId, const wxPoint& aPosition, const wxSize& aSize );
  97. ~EDA_MSG_PANEL();
  98. /**
  99. * Function GetRequiredHeight
  100. * returns the required height (in pixels) of a EDA_MSG_PANEL. This takes
  101. * into consideration the system gui font, wxSYS_DEFAULT_GUI_FONT.
  102. */
  103. static int GetRequiredHeight();
  104. void OnPaint( wxPaintEvent& aEvent );
  105. void EraseMsgBox();
  106. /**
  107. * Function SetMessage
  108. * sets a message at \a aXPosition to \a aUpperText and \a aLowerText in the message panel.
  109. *
  110. * @param aXPosition The horizontal position to display the message or less than zero
  111. * to set the message using the last message position.
  112. * @param aUpperText The text to be displayed in top line.
  113. * @param aLowerText The text to be displayed in bottom line.
  114. * @param aColor Color of the text to display.
  115. */
  116. void SetMessage( int aXPosition, const wxString& aUpperText,
  117. const wxString& aLowerText, EDA_COLOR_T aColor );
  118. /**
  119. * Function AppendMessage
  120. * appends a message to the message panel.
  121. *
  122. * This method automatically adjusts for the width of the text string.
  123. * Making consecutive calls to AppendMessage will append each message
  124. * to the right of the last message. This message is not compatible
  125. * with Affiche_1_Parametre.
  126. *
  127. * @param aUpperText The message upper text.
  128. * @param aLowerText The message lower text.
  129. * @param aColor A color ID from the KiCad color list (see colors.h).
  130. * @param aPad Number of spaces to pad between messages (default = 4).
  131. */
  132. void AppendMessage( const wxString& aUpperText, const wxString& aLowerText,
  133. EDA_COLOR_T aColor, int aPad = 6 );
  134. /**
  135. * Function AppendMessage
  136. * appends \a aMessageItem to the message panel.
  137. *
  138. * @param aMessageItem is a reference to an #MSG_PANEL_ITEM containing the message to
  139. * append to the panel.
  140. */
  141. void AppendMessage( const MSG_PANEL_ITEM& aMessageItem )
  142. {
  143. AppendMessage( aMessageItem.GetUpperText(), aMessageItem.GetLowerText(),
  144. aMessageItem.GetColor(), aMessageItem.GetPadding() );
  145. }
  146. DECLARE_EVENT_TABLE()
  147. };
  148. #endif // _MSGPANEL_H_