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 KiCad Developers, see CHANGELOG.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  wxPoint aPos, wxSize aSize) :
33  DIALOG_DISPLAY_HTML_TEXT_BASE( parent, wxID_ANY, aTitle, aPos, aSize )
34 {
35  m_htmlWindow->SetLayoutDirection( wxLayout_LeftToRight );
36  ListClear();
37  Center();
38 }
39 
40 
41 void HTML_MESSAGE_BOX::OnCloseButtonClick( wxCommandEvent& event )
42 {
43  // the dialog can be shown modal or not modal.
44  // therefore, use the right way to close it.
45  if( IsModal() )
46  EndModal( 0 );
47  else
48  Destroy();
49 }
50 
51 
53 {
54  m_htmlWindow->SetPage( wxEmptyString );
55 }
56 
57 
58 void HTML_MESSAGE_BOX::ListSet( const wxString& aList )
59 {
60  wxArrayString strings_list;
61  wxStringSplit( aList, strings_list, wxChar( '\n' ) );
62 
63  wxString msg = wxT( "<ul>" );
64 
65  for ( unsigned ii = 0; ii < strings_list.GetCount(); ii++ )
66  {
67  msg += wxT( "<li>" );
68  msg += strings_list.Item( ii ) + wxT( "</li>" );
69  }
70 
71  msg += wxT( "</ul>" );
72 
73  m_htmlWindow->AppendToPage( msg );
74 }
75 
76 
77 void HTML_MESSAGE_BOX::ListSet( const wxArrayString& aList )
78 {
79  wxString msg = wxT( "<ul>" );
80 
81  for( unsigned ii = 0; ii < aList.GetCount(); ii++ )
82  {
83  msg += wxT( "<li>" );
84  msg += aList.Item( ii ) + wxT( "</li>" );
85  }
86 
87  msg += wxT( "</ul>" );
88 
89  m_htmlWindow->AppendToPage( msg );
90 }
91 
92 
93 void HTML_MESSAGE_BOX::MessageSet( const wxString& message )
94 {
95  wxString message_value = wxString::Format(
96  wxT( "<b>%s</b><br>" ), GetChars( message ) );
97 
98  m_htmlWindow->AppendToPage( message_value );
99 }
100 
101 
102 void HTML_MESSAGE_BOX::AddHTML_Text( const wxString& message )
103 {
104  m_htmlWindow->AppendToPage( message );
105 }
106 
void wxStringSplit(const wxString &aText, wxArrayString &aStrings, wxChar aSplitter)
Function wxStringSplit splits aString to a string list separated at aSplitter.
Definition: common.cpp:137
HTML_MESSAGE_BOX(wxWindow *parent, const wxString &aTitle, wxPoint aPos=wxDefaultPosition, wxSize aSize=wxSize(450, 250))
Constructor.
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 MessageSet(const wxString &message)
Function MessageSet adds a message (in bold) to message list.
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.