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 The 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/menu.h>
26#include <wx/clipbrd.h>
27#include <wx/log.h>
28#include "wx_html_report_box.h"
29
30
31WX_HTML_REPORT_BOX::WX_HTML_REPORT_BOX( wxWindow* parent, wxWindowID id, const wxPoint& pos,
32 const wxSize& size, long style ) :
33 HTML_WINDOW( parent, id, pos, size, style ),
35 m_immediateMode( false )
36{
37 Flush();
38
39 Bind( wxEVT_SYS_COLOUR_CHANGED, wxSysColourChangedEventHandler( WX_HTML_REPORT_BOX::onThemeChanged ), this );
40}
41
42
44{
45 // Disconnect Events
46 Unbind( wxEVT_SYS_COLOUR_CHANGED, wxSysColourChangedEventHandler( WX_HTML_REPORT_BOX::onThemeChanged ), this );
47}
48
49
50void WX_HTML_REPORT_BOX::onThemeChanged( wxSysColourChangedEvent &aEvent )
51{
52 Flush();
53
54 aEvent.Skip();
55}
56
57
58REPORTER& WX_HTML_REPORT_BOX::Report( const wxString& aText, SEVERITY aSeverity )
59{
60 m_messages.push_back( aText );
61
62 if( m_immediateMode )
63 {
64 Flush();
65 int px, py, x, y;
66 GetScrollPixelsPerUnit( &px, &py );
67 GetVirtualSize( &x, &y );
68 Scroll( -1, y * py );
69 }
70
71 return *this;
72}
73
74
76{
77 wxString html;
78
79 for( const wxString& line : m_messages )
80 html += generateHtml( line );
81
82 SetPage( html );
83}
84
85
86wxString WX_HTML_REPORT_BOX::generateHtml( const wxString& aLine )
87{
88 // wxWidgets default linespacing is about 110% of font-height (which is way too small),
89 // and the default paragraph spacing is about 200% (which is too big). The heading,
90 // bullet lists, etc. line spacing is fine.
91 //
92 // And of course they provide no way to set it, which leaves us with very few options.
93 // Fortunately we know we're dealing mostly with single lines in the reporter so we apply
94 // an egregious hack and enforce a minimum linespacing by inserting an invisible img
95 // element with appropriate height
96
97 wxFont font = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
98 int additionalLineSpacing = KiROUND( font.GetPixelSize().y * 0.6 );
99
100 return wxString::Format( wxT( "<img align=texttop height=%d width=0 src=#>%s<br>" ),
101 additionalLineSpacing, aLine );
102}
103
104
106{
108 m_messages.clear();
109}
110
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:990
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"))
virtual void Clear()
Definition reporter.h:153
REPORTER()
Definition reporter.h:75
void Clear() override
Delete the stored messages.
std::vector< wxString > m_messages
copy of the report, stored for filtering.
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
bool m_immediateMode
Indicates messages should be flushed as they are added.
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:48
SEVERITY