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.

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