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.

129 lines
3.4 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2014-2018 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #include <html_messagebox.h>
  25. #include <kicad_string.h>
  26. HTML_MESSAGE_BOX::HTML_MESSAGE_BOX( wxWindow* aParent, const wxString& aTitle,
  27. const wxPoint& aPosition, const wxSize& aSize ) :
  28. DIALOG_DISPLAY_HTML_TEXT_BASE( aParent, wxID_ANY, aTitle, aPosition, aSize )
  29. {
  30. m_htmlWindow->SetLayoutDirection( wxLayout_LeftToRight );
  31. ListClear();
  32. // Gives a default logical size (the actual size depends on the display definition)
  33. if( aSize != wxDefaultSize )
  34. SetSizeInDU( aSize.x, aSize.y );
  35. Center();
  36. m_sdbSizer1OK->SetDefault();
  37. }
  38. HTML_MESSAGE_BOX::~HTML_MESSAGE_BOX()
  39. {
  40. // Prevent wxWidgets bug which fails to release when closing the window on an <esc>.
  41. if( m_htmlWindow->HasCapture() )
  42. m_htmlWindow->ReleaseMouse();
  43. }
  44. void HTML_MESSAGE_BOX::OnOKButtonClick( wxCommandEvent& event )
  45. {
  46. // the dialog can be shown quasi-model, modal, or not modeless.
  47. // therefore, use the right way to close it.
  48. if( IsQuasiModal() )
  49. EndQuasiModal( wxID_OK );
  50. else if( IsModal() )
  51. EndModal( wxID_OK );
  52. else
  53. Destroy();
  54. }
  55. void HTML_MESSAGE_BOX::ListClear()
  56. {
  57. m_htmlWindow->SetPage( wxEmptyString );
  58. }
  59. void HTML_MESSAGE_BOX::ListSet( const wxString& aList )
  60. {
  61. wxArrayString strings_list;
  62. wxStringSplit( aList, strings_list, wxChar( '\n' ) );
  63. wxString msg = wxT( "<ul>" );
  64. for ( unsigned ii = 0; ii < strings_list.GetCount(); ii++ )
  65. {
  66. msg += wxT( "<li>" );
  67. msg += strings_list.Item( ii ) + wxT( "</li>" );
  68. }
  69. msg += wxT( "</ul>" );
  70. m_htmlWindow->AppendToPage( msg );
  71. }
  72. void HTML_MESSAGE_BOX::ListSet( const wxArrayString& aList )
  73. {
  74. wxString msg = wxT( "<ul>" );
  75. for( unsigned ii = 0; ii < aList.GetCount(); ii++ )
  76. {
  77. msg += wxT( "<li>" );
  78. msg += aList.Item( ii ) + wxT( "</li>" );
  79. }
  80. msg += wxT( "</ul>" );
  81. m_htmlWindow->AppendToPage( msg );
  82. }
  83. void HTML_MESSAGE_BOX::MessageSet( const wxString& message )
  84. {
  85. wxString message_value = wxString::Format(
  86. wxT( "<b>%s</b><br>" ), message );
  87. m_htmlWindow->AppendToPage( message_value );
  88. }
  89. void HTML_MESSAGE_BOX::AddHTML_Text( const wxString& message )
  90. {
  91. m_htmlWindow->AppendToPage( message );
  92. }
  93. void HTML_MESSAGE_BOX::ShowModeless()
  94. {
  95. m_sdbSizer1->Show( false );
  96. Layout();
  97. Show( true );
  98. }