KiCad PCB EDA Suite
Loading...
Searching...
No Matches
wx_html_report_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) 2020-2022 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 2 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20
21#include <math/util.h>
22#include <common.h>
23#include <wx/settings.h>
24#include <wx/textctrl.h>
25#include "wx_html_report_box.h"
26
27
28WX_HTML_REPORT_BOX::WX_HTML_REPORT_BOX( wxWindow* parent, wxWindowID id, const wxPoint& pos,
29 const wxSize& size, long style ) :
30 HTML_WINDOW( parent, id, pos, size, style ),
31 m_units( EDA_UNITS::MILLIMETRES ),
32 m_immediateMode( false )
33{
34 Flush();
35
36 Bind( wxEVT_SYS_COLOUR_CHANGED,
37 wxSysColourChangedEventHandler( WX_HTML_REPORT_BOX::onThemeChanged ), this );
38}
39
40
41void WX_HTML_REPORT_BOX::onThemeChanged( wxSysColourChangedEvent &aEvent )
42{
43 Flush();
44
45 aEvent.Skip();
46}
47
48
49REPORTER& WX_HTML_REPORT_BOX::Report( const wxString& aText, SEVERITY aSeverity )
50{
51 m_messages.push_back( aText );
52
53 if( m_immediateMode )
54 {
55 Flush();
56 int px, py, x, y;
57 GetScrollPixelsPerUnit( &px, &py );
58 GetVirtualSize( &x, &y );
59 Scroll( -1, y * py );
60 }
61
62 return *this;
63}
64
66{
67 wxString html;
68
69 for( const wxString& line : m_messages )
70 html += generateHtml( line );
71
72 SetPage( html );
73}
74
75
76wxString WX_HTML_REPORT_BOX::generateHtml( const wxString& aLine )
77{
78 // wxWidgets default linespacing is about 110% of font-height (which is way too small),
79 // and the default paragraph spacing is about 200% (which is too big). The heading,
80 // bullet lists, etc. line spacing is fine.
81 //
82 // And of course they provide no way to set it, which leaves us with very few options.
83 // Fortunately we know we're dealing mostly with single lines in the reporter so we apply
84 // an egregious hack and enforce a minimum linespacing by inserting an invisible img
85 // element with appropriate height
86
87 wxFont font = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
88 int additionalLineSpacing = KiROUND( font.GetPixelSize().y * 0.6 );
89
90 return wxString::Format( wxT( "<img align=texttop height=%d width=0 src=#>%s<br>" ),
91 additionalLineSpacing, aLine );
92}
93
94
96{
97 m_messages.clear();
98}
99
Add dark theme support to wxHtmlWindow.
Definition: html_window.h:34
bool SetPage(const wxString &aSource) override
Definition: html_window.cpp:38
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:71
std::vector< wxString > m_messages
void Clear()
Delete the stored messages.
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
bool m_immediateMode
copy of the report, stored for filtering
void Flush()
Build the HTML messages page.
WX_HTML_REPORT_BOX(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(500, 300), long style=wxTAB_TRAVERSAL)
wxString generateHtml(const wxString &aLine)
void onThemeChanged(wxSysColourChangedEvent &aEvent)
The common library.
EDA_UNITS
Definition: eda_units.h:46
SEVERITY
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:118