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 The 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
79
80
81bool HTML_WINDOW::ScrollToAnchor( const wxString& aAnchor )
82{
83 // Check if we have content loaded
84 if( !GetInternalRepresentation() )
85 return false;
86
87 // Try to scroll to the anchor
88 bool result = wxHtmlWindow::ScrollToAnchor( aAnchor );
89 return result;
90}
91
92
93void HTML_WINDOW::onThemeChanged( wxSysColourChangedEvent &aEvent )
94{
96}
97
98
99void HTML_WINDOW::onRightClick( wxMouseEvent& event )
100{
101 wxMenu popup;
102 popup.Append( wxID_COPY, "Copy" );
103 PopupMenu( &popup );
104}
105
106
107void HTML_WINDOW::onMenuEvent( wxMenuEvent& event )
108{
109 if( event.GetId() == wxID_COPY )
110 {
111 wxLogNull doNotLog; // disable logging of failed clipboard actions
112
113 if( wxTheClipboard->Open() )
114 {
115 bool primarySelection = wxTheClipboard->IsUsingPrimarySelection();
116 wxTheClipboard->UsePrimarySelection( false ); // required to use the main clipboard
117 wxTheClipboard->SetData( new wxTextDataObject( SelectionToText() ) );
118 wxTheClipboard->Flush(); // Allow data to be available after closing KiCad
119 wxTheClipboard->Close();
120 wxTheClipboard->UsePrimarySelection( primarySelection );
121 }
122 }
123}
124
125
bool SetPage(const wxString &aSource) override
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"))
void onRightClick(wxMouseEvent &event)
wxString m_pageSource
Definition html_window.h:61
void onMenuEvent(wxMenuEvent &event)
void onThemeChanged(wxSysColourChangedEvent &aEvent)
bool ScrollToAnchor(const wxString &aAnchor)
bool AppendToPage(const wxString &aSource)
void ThemeChanged()
wxString result
Test unit parsing edge cases and error handling.