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.

195 lines
6.0 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-2015 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. m_X = 0;
  59. m_UpperY = 0;
  60. m_LowerY = 0;
  61. }
  62. MSG_PANEL_ITEM() :
  63. m_Pad( MSG_PANEL_DEFAULT_PAD )
  64. {
  65. m_X = 0;
  66. m_UpperY = 0;
  67. m_LowerY = 0;
  68. m_Color = UNSPECIFIED_COLOR;
  69. }
  70. void SetUpperText( const wxString& aUpperText ) { m_UpperText = aUpperText; }
  71. const wxString& GetUpperText() const { return m_UpperText; }
  72. void SetLowerText( const wxString& aLowerText ) { m_LowerText = aLowerText; }
  73. const wxString& GetLowerText() const { return m_LowerText; }
  74. void SetColor( EDA_COLOR_T aColor ) { m_Color = aColor; }
  75. EDA_COLOR_T GetColor() const { return m_Color; }
  76. void SetPadding( int aPad ) { m_Pad = aPad; }
  77. int GetPadding() const { return m_Pad; }
  78. };
  79. typedef std::vector<MSG_PANEL_ITEM> MSG_PANEL_ITEMS;
  80. typedef MSG_PANEL_ITEMS::iterator MSG_PANEL_ITEMS_ITER;
  81. typedef MSG_PANEL_ITEMS::const_iterator MSG_PANEL_ITEMS_CITER;
  82. /**
  83. * class EDA_MSG_PANEL
  84. * is a panel to display various information messages.
  85. */
  86. class EDA_MSG_PANEL : public wxPanel
  87. {
  88. protected:
  89. MSG_PANEL_ITEMS m_Items;
  90. int m_last_x; ///< the last used x coordinate
  91. wxSize m_fontSize;
  92. void showItem( wxDC& dc, const MSG_PANEL_ITEM& aItem );
  93. void erase( wxDC* DC );
  94. /**
  95. * Function getFontSize
  96. * computes the height and width of a 'W' in the system font.
  97. */
  98. static wxSize computeFontSize();
  99. /**
  100. * Calculate the width and height of a text string using the system UI font.
  101. */
  102. wxSize computeTextSize( const wxString& text ) const;
  103. public:
  104. EDA_MSG_PANEL( wxWindow* aParent, int aId,
  105. const wxPoint& aPosition, const wxSize& aSize,
  106. long style=wxTAB_TRAVERSAL, const wxString &name=wxPanelNameStr);
  107. ~EDA_MSG_PANEL();
  108. /**
  109. * Function GetRequiredHeight
  110. * returns the required height (in pixels) of a EDA_MSG_PANEL. This takes
  111. * into consideration the system gui font, wxSYS_DEFAULT_GUI_FONT.
  112. */
  113. static int GetRequiredHeight();
  114. void OnPaint( wxPaintEvent& aEvent );
  115. void EraseMsgBox();
  116. /**
  117. * Function SetMessage
  118. * sets a message at \a aXPosition to \a aUpperText and \a aLowerText in the message panel.
  119. *
  120. * @param aXPosition The horizontal position to display the message or less than zero
  121. * to set the message using the last message position.
  122. * @param aUpperText The text to be displayed in top line.
  123. * @param aLowerText The text to be displayed in bottom line.
  124. * @param aColor Color of the text to display.
  125. */
  126. void SetMessage( int aXPosition, const wxString& aUpperText,
  127. const wxString& aLowerText, EDA_COLOR_T aColor );
  128. /**
  129. * Function AppendMessage
  130. * appends a message to the message panel.
  131. *
  132. * This method automatically adjusts for the width of the text string.
  133. * Making consecutive calls to AppendMessage will append each message
  134. * to the right of the last message. This message is not compatible
  135. * with Affiche_1_Parametre.
  136. *
  137. * @param aUpperText The message upper text.
  138. * @param aLowerText The message lower text.
  139. * @param aColor A color ID from the KiCad color list (see colors.h).
  140. * @param aPad Number of spaces to pad between messages (default = 4).
  141. */
  142. void AppendMessage( const wxString& aUpperText, const wxString& aLowerText,
  143. EDA_COLOR_T aColor, int aPad = 6 );
  144. /**
  145. * Function AppendMessage
  146. * appends \a aMessageItem to the message panel.
  147. *
  148. * @param aMessageItem is a reference to an #MSG_PANEL_ITEM containing the message to
  149. * append to the panel.
  150. */
  151. void AppendMessage( const MSG_PANEL_ITEM& aMessageItem )
  152. {
  153. AppendMessage( aMessageItem.GetUpperText(), aMessageItem.GetLowerText(),
  154. aMessageItem.GetColor(), aMessageItem.GetPadding() );
  155. }
  156. DECLARE_EVENT_TABLE()
  157. };
  158. #endif // _MSGPANEL_H_