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* aParent, const wxString& aTitle,
32  const wxPoint& aPosition, const wxSize& aSize ) :
33  DIALOG_DISPLAY_HTML_TEXT_BASE( aParent, wxID_ANY, aTitle, aPosition, aSize )
34 {
35  m_htmlWindow->SetLayoutDirection( wxLayout_LeftToRight );
36  ListClear();
37 
38  // Gives a default logical size (the actual size depends on the display definition)
39  if( aSize != wxDefaultSize )
40  SetSizeInDU( aSize.x, aSize.y );
41 
42  Center();
43 
44  m_sdbSizer1OK->SetDefault();
45 }
46 
47 
49 {
50  // Prevent wxWidgets bug which fails to release when closing the window on an <esc>.
51  if( m_htmlWindow->HasCapture() )
52  m_htmlWindow->ReleaseMouse();
53 }
54 
55 
56 void HTML_MESSAGE_BOX::OnOKButtonClick( wxCommandEvent& event )
57 {
58  // the dialog can be shown quasi-model, modal, or not modeless.
59  // therefore, use the right way to close it.
60  if( IsQuasiModal() )
61  EndQuasiModal( wxID_OK );
62  else if( IsModal() )
63  EndModal( wxID_OK );
64  else
65  Destroy();
66 }
67 
68 
70 {
71  m_htmlWindow->SetPage( wxEmptyString );
72 }
73 
74 
75 void HTML_MESSAGE_BOX::ListSet( const wxString& aList )
76 {
77  wxArrayString strings_list;
78  wxStringSplit( aList, strings_list, wxChar( '\n' ) );
79 
80  wxString msg = wxT( "<ul>" );
81 
82  for ( unsigned ii = 0; ii < strings_list.GetCount(); ii++ )
83  {
84  msg += wxT( "<li>" );
85  msg += strings_list.Item( ii ) + wxT( "</li>" );
86  }
87 
88  msg += wxT( "</ul>" );
89 
90  m_htmlWindow->AppendToPage( msg );
91 }
92 
93 
94 void HTML_MESSAGE_BOX::ListSet( const wxArrayString& aList )
95 {
96  wxString msg = wxT( "<ul>" );
97 
98  for( unsigned ii = 0; ii < aList.GetCount(); ii++ )
99  {
100  msg += wxT( "<li>" );
101  msg += aList.Item( ii ) + wxT( "</li>" );
102  }
103 
104  msg += wxT( "</ul>" );
105 
106  m_htmlWindow->AppendToPage( msg );
107 }
108 
109 
110 void HTML_MESSAGE_BOX::MessageSet( const wxString& message )
111 {
112  wxString message_value = wxString::Format(
113  wxT( "<b>%s</b><br>" ), GetChars( message ) );
114 
115  m_htmlWindow->AppendToPage( message_value );
116 }
117 
118 
119 void HTML_MESSAGE_BOX::AddHTML_Text( const wxString& message )
120 {
121  m_htmlWindow->AppendToPage( message );
122 }
123 
void wxStringSplit(const wxString &aText, wxArrayString &aStrings, wxChar aSplitter)
Split aString to a string list separated at aSplitter.
Definition: common.cpp:188
This file contains miscellaneous commonly used macros and functions.
Class DIALOG_DISPLAY_HTML_TEXT_BASE.
void ListSet(const wxString &aList)
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".
bool IsQuasiModal()
Definition: dialog_shim.h:127
~HTML_MESSAGE_BOX() override
void MessageSet(const wxString &message)
Add a message (in bold) to message list.
void OnOKButtonClick(wxCommandEvent &event) override
void EndQuasiModal(int retCode)
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:101
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)
Add HTML text (without any change) to message list.
The common library.
HTML_MESSAGE_BOX(wxWindow *aParent, const wxString &aTitle=wxEmptyString, const wxPoint &aPosition=wxDefaultPosition, const wxSize &aSize=wxDefaultSize)