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 
26 
27 #include <kicad_string.h>
28 
29 HTML_MESSAGE_BOX::HTML_MESSAGE_BOX( wxWindow* aParent, const wxString& aTitle,
30  const wxPoint& aPosition, const wxSize& aSize ) :
31  DIALOG_DISPLAY_HTML_TEXT_BASE( aParent, wxID_ANY, aTitle, aPosition, aSize )
32 {
33  m_htmlWindow->SetLayoutDirection( wxLayout_LeftToRight );
34  ListClear();
35 
36  // Gives a default logical size (the actual size depends on the display definition)
37  if( aSize != wxDefaultSize )
38  setSizeInDU( aSize.x, aSize.y );
39 
40  Center();
41 
42  m_sdbSizer1OK->SetDefault();
43 }
44 
45 
47 {
48  // Prevent wxWidgets bug which fails to release when closing the window on an <esc>.
49  if( m_htmlWindow->HasCapture() )
50  m_htmlWindow->ReleaseMouse();
51 }
52 
53 
54 void HTML_MESSAGE_BOX::OnOKButtonClick( wxCommandEvent& event )
55 {
56  // the dialog can be shown quasi-model, modal, or not modeless.
57  // therefore, use the right way to close it.
58  if( IsQuasiModal() )
59  EndQuasiModal( wxID_OK );
60  else if( IsModal() )
61  EndModal( wxID_OK );
62  else
63  Destroy();
64 }
65 
66 
68 {
69  m_htmlWindow->SetPage( wxEmptyString );
70 }
71 
72 
73 void HTML_MESSAGE_BOX::ListSet( const wxString& aList )
74 {
75  wxArrayString strings_list;
76  wxStringSplit( aList, strings_list, wxChar( '\n' ) );
77 
78  wxString msg = wxT( "<ul>" );
79 
80  for ( unsigned ii = 0; ii < strings_list.GetCount(); ii++ )
81  {
82  msg += wxT( "<li>" );
83  msg += strings_list.Item( ii ) + wxT( "</li>" );
84  }
85 
86  msg += wxT( "</ul>" );
87 
88  m_htmlWindow->AppendToPage( msg );
89 }
90 
91 
92 void HTML_MESSAGE_BOX::ListSet( const wxArrayString& aList )
93 {
94  wxString msg = wxT( "<ul>" );
95 
96  for( unsigned ii = 0; ii < aList.GetCount(); ii++ )
97  {
98  msg += wxT( "<li>" );
99  msg += aList.Item( ii ) + wxT( "</li>" );
100  }
101 
102  msg += wxT( "</ul>" );
103 
104  m_htmlWindow->AppendToPage( msg );
105 }
106 
107 
108 void HTML_MESSAGE_BOX::MessageSet( const wxString& message )
109 {
110  wxString message_value = wxString::Format(
111  wxT( "<b>%s</b><br>" ), message );
112 
113  m_htmlWindow->AppendToPage( message_value );
114 }
115 
116 
117 void HTML_MESSAGE_BOX::AddHTML_Text( const wxString& message )
118 {
119  m_htmlWindow->AppendToPage( message );
120 }
121 
122 
124 {
125  m_sdbSizer1->Show( false );
126  Layout();
127 
128  Show( true );
129 }
130 
131 
132 void HTML_MESSAGE_BOX::OnCharHook( wxKeyEvent& aEvent )
133 {
134  // shift-return (Mac default) or Ctrl-Return (GTK) for OK
135  if( aEvent.GetKeyCode() == WXK_ESCAPE )
136  {
137  wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
138  return;
139  }
140 
141  aEvent.Skip();
142 }
void setSizeInDU(int x, int y)
Set the dialog to the given dimensions in "dialog units".
bool IsQuasiModal() const
Definition: dialog_shim.h:107
virtual bool IsModal() const
Return true if the frame is shown in our modal mode and false if the frame is shown as an usual frame...
Class DIALOG_DISPLAY_HTML_TEXT_BASE.
void ListSet(const wxString &aList)
Add a list of items.
~HTML_MESSAGE_BOX() override
void MessageSet(const wxString &message)
Add a message (in bold) to message list.
bool Show(bool show) override
void wxStringSplit(const wxString &aText, wxArrayString &aStrings, wxChar aSplitter)
Split aString to a string list separated at aSplitter.
Definition: string.cpp:807
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
void ShowModeless()
Show a modeless version of the dialog (without an OK button).
void OnOKButtonClick(wxCommandEvent &event) override
void EndQuasiModal(int retCode)
void AddHTML_Text(const wxString &message)
Add HTML text (without any change) to message list.
virtual void OnCharHook(wxKeyEvent &aEvt) override
HTML_MESSAGE_BOX(wxWindow *aParent, const wxString &aTitle=wxEmptyString, const wxPoint &aPosition=wxDefaultPosition, const wxSize &aSize=wxDefaultSize)