KiCad PCB EDA Suite
html_message_box.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-2021 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 <wx/clipbrd.h>
26#include <wx/log.h>
27#include <wx/textctrl.h>
28#include <string_utils.h>
30
31
32HTML_MESSAGE_BOX::HTML_MESSAGE_BOX( wxWindow* aParent, const wxString& aTitle,
33 const wxPoint& aPosition, const wxSize& aSize ) :
34 DIALOG_DISPLAY_HTML_TEXT_BASE( aParent, wxID_ANY, aTitle, aPosition, aSize )
35{
36 m_htmlWindow->SetLayoutDirection( wxLayout_LeftToRight );
37 ListClear();
38
39 // Gives a default logical size (the actual size depends on the display definition)
40 if( aSize != wxDefaultSize )
41 setSizeInDU( aSize.x, aSize.y );
42
43 Center();
44
46
47 reload();
48
49 Bind( wxEVT_SYS_COLOUR_CHANGED,
50 wxSysColourChangedEventHandler( HTML_MESSAGE_BOX::onThemeChanged ), this );
51}
52
53
55{
56 // Prevent wxWidgets bug which fails to release when closing the window on an <esc>.
57 if( m_htmlWindow->HasCapture() )
58 m_htmlWindow->ReleaseMouse();
59}
60
61
63{
65}
66
67
68void HTML_MESSAGE_BOX::onThemeChanged( wxSysColourChangedEvent &aEvent )
69{
70 reload();
71
72 aEvent.Skip();
73}
74
75
77{
78 m_source.clear();
79 reload();
80}
81
82
83void HTML_MESSAGE_BOX::ListSet( const wxString& aList )
84{
85 wxArrayString strings_list;
86 wxStringSplit( aList, strings_list, wxChar( '\n' ) );
87
88 wxString msg = wxT( "<ul>" );
89
90 for ( unsigned ii = 0; ii < strings_list.GetCount(); ii++ )
91 {
92 msg += wxT( "<li>" );
93 msg += strings_list.Item( ii ) + wxT( "</li>" );
94 }
95
96 msg += wxT( "</ul>" );
97
98 m_source += msg;
99 reload();
100}
101
102
103void HTML_MESSAGE_BOX::ListSet( const wxArrayString& aList )
104{
105 wxString msg = wxT( "<ul>" );
106
107 for( unsigned ii = 0; ii < aList.GetCount(); ii++ )
108 {
109 msg += wxT( "<li>" );
110 msg += aList.Item( ii ) + wxT( "</li>" );
111 }
112
113 msg += wxT( "</ul>" );
114
115 m_source += msg;
116 reload();
117}
118
119
120void HTML_MESSAGE_BOX::MessageSet( const wxString& message )
121{
122 wxString message_value = wxString::Format( wxT( "<b>%s</b><br>" ), message );
123
124 m_source += message_value;
125 reload();
126}
127
128
129void HTML_MESSAGE_BOX::AddHTML_Text( const wxString& message )
130{
131 m_source += message;
132 reload();
133}
134
135
137{
138 reload();
139
140 m_sdbSizer1->Show( false );
141 Layout();
142
143 Show( true );
144}
145
146
147void HTML_MESSAGE_BOX::OnCharHook( wxKeyEvent& aEvent )
148{
149 // shift-return (Mac default) or Ctrl-Return (GTK) for OK
150 if( aEvent.GetKeyCode() == WXK_ESCAPE )
151 {
152 wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
153 return;
154 }
155 else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() == 'A' )
156 {
157 m_htmlWindow->SelectAll();
158 return;
159 }
160 else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() == 'C' )
161 {
162 wxLogNull doNotLog; // disable logging of failed clipboard actions
163
164 if( wxTheClipboard->Open() )
165 {
166 wxTheClipboard->SetData( new wxTextDataObject( m_htmlWindow->SelectionToText() ) );
167 wxTheClipboard->Flush(); // Allow data to be available after closing KiCad
168 wxTheClipboard->Close();
169 }
170
171 return;
172 }
173
174 aEvent.Skip();
175}
Class DIALOG_DISPLAY_HTML_TEXT_BASE.
bool Show(bool show) override
void SetupStandardButtons(std::map< int, wxString > aLabels={})
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)
Add a message (in bold) to message list.
void onThemeChanged(wxSysColourChangedEvent &aEvent)
virtual void OnCharHook(wxKeyEvent &aEvt) override
HTML_MESSAGE_BOX(wxWindow *aParent, const wxString &aTitle=wxEmptyString, const wxPoint &aPosition=wxDefaultPosition, const wxSize &aSize=wxDefaultSize)
void AddHTML_Text(const wxString &message)
Add HTML text (without any change) to message list.
void ListSet(const wxString &aList)
Add a list of items.
void ShowModeless()
Show a modeless version of the dialog (without an OK button).
bool SetPage(const wxString &aSource) override
Definition: html_window.cpp:38
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 wxStringSplit(const wxString &aText, wxArrayString &aStrings, wxChar aSplitter)
Split aString to a string list separated at aSplitter.