KiCad PCB EDA Suite
Loading...
Searching...
No Matches
html_window.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) 2021 MikoĊ‚aj Wielgus <[email protected]>
5 * Copyright (C) 2021-2024 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/menu.h>
26#include <wx/clipbrd.h>
27#include <wx/log.h>
28#include <wx/settings.h>
29#include <widgets/html_window.h>
30
31
32HTML_WINDOW::HTML_WINDOW( wxWindow* aParent, wxWindowID aId, const wxPoint& aPos,
33 const wxSize& aSize, long aStyle, const wxString& aName ) :
34 wxHtmlWindow( aParent, aId, aPos, aSize, aStyle, aName )
35{
36 Bind( wxEVT_SYS_COLOUR_CHANGED,
37 wxSysColourChangedEventHandler( HTML_WINDOW::onThemeChanged ), this );
38
39 Connect( wxEVT_RIGHT_UP, wxMouseEventHandler( HTML_WINDOW::onRightClick ), nullptr, this );
40}
41
42
44{
45 // Disconnect Events
46 Disconnect( wxEVT_RIGHT_UP, wxMouseEventHandler( HTML_WINDOW::onRightClick ), nullptr, this );
47}
48
49
50bool HTML_WINDOW::SetPage( const wxString& aSource )
51{
52 m_pageSource = aSource;
53
54 wxColour fgColor = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT );
55 wxColour bgColor = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW );
56 wxColour linkColor = wxSystemSettings::GetColour( wxSYS_COLOUR_HOTLIGHT );
57
58 wxString html = wxString::Format( wxT( "<html>\n<body text='%s' bgcolor='%s' link='%s'>\n" ),
59 fgColor.GetAsString( wxC2S_HTML_SYNTAX ),
60 bgColor.GetAsString( wxC2S_HTML_SYNTAX ),
61 linkColor.GetAsString( wxC2S_HTML_SYNTAX ) );
62 html.Append( aSource );
63 html.Append( wxT( "\n</body>\n</html>" ) );
64
65 return wxHtmlWindow::SetPage( html );
66}
67
68
69bool HTML_WINDOW::AppendToPage( const wxString& aSource )
70{
71 return SetPage( m_pageSource + aSource );
72}
73
74
76{
78}
79
80
81void HTML_WINDOW::onThemeChanged( wxSysColourChangedEvent &aEvent )
82{
84}
85
86
87void HTML_WINDOW::onRightClick( wxMouseEvent& event )
88{
89 wxMenu popup;
90 popup.Append( wxID_COPY, "Copy" );
91 PopupMenu( &popup );
92}
93
94
95void HTML_WINDOW::onMenuEvent( wxMenuEvent& event )
96{
97 if( event.GetId() == wxID_COPY )
98 {
99 wxLogNull doNotLog; // disable logging of failed clipboard actions
100
101 if( wxTheClipboard->Open() )
102 {
103 bool primarySelection = wxTheClipboard->IsUsingPrimarySelection();
104 wxTheClipboard->UsePrimarySelection( false ); // required to use the main clipboard
105 wxTheClipboard->SetData( new wxTextDataObject( SelectionToText() ) );
106 wxTheClipboard->Flush(); // Allow data to be available after closing KiCad
107 wxTheClipboard->Close();
108 wxTheClipboard->UsePrimarySelection( primarySelection );
109 }
110 }
111}
112
113
bool SetPage(const wxString &aSource) override
Definition: html_window.cpp:50
HTML_WINDOW(wxWindow *aParent, wxWindowID aId=wxID_ANY, const wxPoint &aPos=wxDefaultPosition, const wxSize &aSize=wxDefaultSize, long aStyle=wxHW_DEFAULT_STYLE, const wxString &aName=wxT("htmlWindow"))
Definition: html_window.cpp:32
void onRightClick(wxMouseEvent &event)
Definition: html_window.cpp:87
wxString m_pageSource
Definition: html_window.h:55
void onMenuEvent(wxMenuEvent &event)
Definition: html_window.cpp:95
void onThemeChanged(wxSysColourChangedEvent &aEvent)
Definition: html_window.cpp:81
bool AppendToPage(const wxString &aSource)
Definition: html_window.cpp:69
void ThemeChanged()
Definition: html_window.cpp:75