KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 <wx/uri.h>
29#include <string_utils.h>
31#include <build_version.h>
32
33
34HTML_MESSAGE_BOX::HTML_MESSAGE_BOX( wxWindow* aParent, const wxString& aTitle,
35 const wxPoint& aPosition, const wxSize& aSize ) :
36 DIALOG_DISPLAY_HTML_TEXT_BASE( aParent, wxID_ANY, aTitle, aPosition, aSize )
37{
38 m_htmlWindow->SetLayoutDirection( wxLayout_LeftToRight );
39 ListClear();
40
41 // Gives a default logical size (the actual size depends on the display definition)
42 if( aSize != wxDefaultSize )
43 setSizeInDU( aSize.x, aSize.y );
44
45 Center();
46
48
49 reload();
50
51 Bind( wxEVT_SYS_COLOUR_CHANGED,
52 wxSysColourChangedEventHandler( HTML_MESSAGE_BOX::onThemeChanged ), this );
53}
54
55
57{
58 // Prevent wxWidgets bug which fails to release when closing the window on an <esc>.
59 if( m_htmlWindow->HasCapture() )
60 m_htmlWindow->ReleaseMouse();
61}
62
63
65{
67}
68
69
70void HTML_MESSAGE_BOX::onThemeChanged( wxSysColourChangedEvent &aEvent )
71{
72 reload();
73
74 aEvent.Skip();
75}
76
77
79{
80 m_source.clear();
81 reload();
82}
83
84
85void HTML_MESSAGE_BOX::ListSet( const wxString& aList )
86{
87 wxArrayString strings_list;
88 wxStringSplit( aList, strings_list, wxChar( '\n' ) );
89
90 wxString msg = wxT( "<ul>" );
91
92 for ( unsigned ii = 0; ii < strings_list.GetCount(); ii++ )
93 {
94 msg += wxT( "<li>" );
95 msg += strings_list.Item( ii ) + wxT( "</li>" );
96 }
97
98 msg += wxT( "</ul>" );
99
100 m_source += msg;
101 reload();
102}
103
104
105void HTML_MESSAGE_BOX::ListSet( const wxArrayString& aList )
106{
107 wxString msg = wxT( "<ul>" );
108
109 for( unsigned ii = 0; ii < aList.GetCount(); ii++ )
110 {
111 msg += wxT( "<li>" );
112 msg += aList.Item( ii ) + wxT( "</li>" );
113 }
114
115 msg += wxT( "</ul>" );
116
117 m_source += msg;
118 reload();
119}
120
121
122void HTML_MESSAGE_BOX::MessageSet( const wxString& message )
123{
124 wxString message_value = wxString::Format( wxT( "<b>%s</b><br>" ), message );
125
126 m_source += message_value;
127 reload();
128}
129
130
131void HTML_MESSAGE_BOX::AddHTML_Text( const wxString& message )
132{
133 m_source += message;
134 reload();
135}
136
137
139{
140 reload();
141
142 m_sdbSizer1->Show( false );
143 Layout();
144
145 Show( true );
146}
147
148
149void HTML_MESSAGE_BOX::OnHTMLLinkClicked( wxHtmlLinkEvent& event )
150{
151 wxString href = event.GetLinkInfo().GetHref();
152
153 if( href.StartsWith( wxS( "https://docs.kicad.org/" ) ) )
154 {
155 href.Replace( wxS( "GetMajorMinorVersion" ), GetMajorMinorVersion() );
156
157 wxURI uri( href );
158 wxLaunchDefaultBrowser( uri.BuildURI() );
159 }
160}
161
162
163void HTML_MESSAGE_BOX::OnCharHook( wxKeyEvent& aEvent )
164{
165 // shift-return (Mac default) or Ctrl-Return (GTK) for OK
166 if( aEvent.GetKeyCode() == WXK_ESCAPE )
167 {
168 wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
169 return;
170 }
171 else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() == 'A' )
172 {
173 m_htmlWindow->SelectAll();
174 return;
175 }
176 else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() == 'C' )
177 {
178 wxLogNull doNotLog; // disable logging of failed clipboard actions
179
180 if( wxTheClipboard->Open() )
181 {
182 wxTheClipboard->SetData( new wxTextDataObject( m_htmlWindow->SelectionToText() ) );
183 wxTheClipboard->Flush(); // Allow data to be available after closing KiCad
184 wxTheClipboard->Close();
185 }
186
187 return;
188 }
189
190 aEvent.Skip();
191}
wxString GetMajorMinorVersion()
Get only the major and minor version in a string major.minor.
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".
void OnHTMLLinkClicked(wxHtmlLinkEvent &event) override
~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:50
void wxStringSplit(const wxString &aText, wxArrayString &aStrings, wxChar aSplitter)
Split aString to a string list separated at aSplitter.