KiCad PCB EDA Suite
html_messagebox.cpp
Go to the documentation of this file.
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 
25 #include <fctsys.h>
26 #include <html_messagebox.h>
27 #include <macros.h>
28 #include <common.h>
29 
30 
31 HTML_MESSAGE_BOX::HTML_MESSAGE_BOX( wxWindow* parent, const wxString& aTitle) :
32  DIALOG_DISPLAY_HTML_TEXT_BASE( parent, wxID_ANY, aTitle )
33 {
34  m_htmlWindow->SetLayoutDirection( wxLayout_LeftToRight );
35  ListClear();
36 
37  // Gives a default logical size (the actual size depends on the display definition)
38  SetSizeInDU( 320, 120 );
39 
40  Center();
41 }
42 
43 
45 {
46  // Prevent wxWidgets bug which fails to release when closing the window on an <esc>.
47  if( m_htmlWindow->HasCapture() )
48  m_htmlWindow->ReleaseMouse();
49 }
50 
51 
52 void HTML_MESSAGE_BOX::OnCloseButtonClick( wxCommandEvent& event )
53 {
54  // the dialog can be shown modal or not modal.
55  // therefore, use the right way to close it.
56  if( IsModal() )
57  EndModal( 0 );
58  else
59  Destroy();
60 }
61 
62 
64 {
65  m_htmlWindow->SetPage( wxEmptyString );
66 }
67 
68 
69 void HTML_MESSAGE_BOX::ListSet( const wxString& aList )
70 {
71  wxArrayString strings_list;
72  wxStringSplit( aList, strings_list, wxChar( '\n' ) );
73 
74  wxString msg = wxT( "<ul>" );
75 
76  for ( unsigned ii = 0; ii < strings_list.GetCount(); ii++ )
77  {
78  msg += wxT( "<li>" );
79  msg += strings_list.Item( ii ) + wxT( "</li>" );
80  }
81 
82  msg += wxT( "</ul>" );
83 
84  m_htmlWindow->AppendToPage( msg );
85 }
86 
87 
88 void HTML_MESSAGE_BOX::ListSet( const wxArrayString& aList )
89 {
90  wxString msg = wxT( "<ul>" );
91 
92  for( unsigned ii = 0; ii < aList.GetCount(); ii++ )
93  {
94  msg += wxT( "<li>" );
95  msg += aList.Item( ii ) + wxT( "</li>" );
96  }
97 
98  msg += wxT( "</ul>" );
99 
100  m_htmlWindow->AppendToPage( msg );
101 }
102 
103 
104 void HTML_MESSAGE_BOX::MessageSet( const wxString& message )
105 {
106  wxString message_value = wxString::Format(
107  wxT( "<b>%s</b><br>" ), GetChars( message ) );
108 
109  m_htmlWindow->AppendToPage( message_value );
110 }
111 
112 
113 void HTML_MESSAGE_BOX::AddHTML_Text( const wxString& message )
114 {
115  m_htmlWindow->AppendToPage( message );
116 }
117 
void wxStringSplit(const wxString &aText, wxArrayString &aStrings, wxChar aSplitter)
Split aString to a string list separated at aSplitter.
Definition: common.cpp:183
This file contains miscellaneous commonly used macros and functions.
Class DIALOG_DISPLAY_HTML_TEXT_BASE.
void OnCloseButtonClick(wxCommandEvent &event) override
void ListSet(const wxString &aList)
Function ListSet Add a list of items.
Subclass of DIALOG_DISPLAY_HTML_TEXT_BASE, which is generated by wxFormBuilder.
void SetSizeInDU(int x, int y)
Set the dialog to the given dimensions in "dialog units".
~HTML_MESSAGE_BOX() override
void MessageSet(const wxString &message)
Function MessageSet adds a message (in bold) to message list.
HTML_MESSAGE_BOX(wxWindow *parent, const wxString &aTitle)
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
void AddHTML_Text(const wxString &message)
Function AddHTML_Text adds html text (without any change) to message list.
The common library.