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
17 * along with this program. If not, see <https://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 KI_ERROR msg;
61 msg.SetTitle( aText ).SetSeverity( aSeverity );
62 m_messages.push_back( std::move( msg ) );
63
64 if( m_immediateMode )
65 {
66 Flush();
67 int px, py, x, y;
68 GetScrollPixelsPerUnit( &px, &py );
69 GetVirtualSize( &x, &y );
70 Scroll( -1, y * py );
71 }
72
73 return *this;
74}
75
76
78{
79 REPORTER::Report( aError );
80 m_messages.push_back( aError );
81
82 if( m_immediateMode )
83 {
84 Flush();
85 int px, py, x, y;
86 GetScrollPixelsPerUnit( &px, &py );
87 GetVirtualSize( &x, &y );
88 Scroll( -1, y * py );
89 }
90
91 return *this;
92}
93
94
96{
97 wxString html;
98
99 for( const KI_ERROR& msg : m_messages )
100 html += generateHtml( msg );
101
102 SetPage( html );
103}
104
105
106wxString WX_HTML_REPORT_BOX::generateHtml( const wxString& aLine )
107{
108 // wxWidgets default linespacing is about 110% of font-height (which is way too small),
109 // and the default paragraph spacing is about 200% (which is too big). The heading,
110 // bullet lists, etc. line spacing is fine.
111 //
112 // And of course they provide no way to set it, which leaves us with very few options.
113 // Fortunately we know we're dealing mostly with single lines in the reporter so we apply
114 // an egregious hack and enforce a minimum linespacing by inserting an invisible img
115 // element with appropriate height
116
117 wxFont font = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
118 int additionalLineSpacing = KiROUND( font.GetPixelSize().y * 0.6 );
119
120 return wxString::Format( wxT( "<img align=texttop height=%d width=0 src=#>%s<br>" ),
121 additionalLineSpacing, aLine );
122}
123
124
126{
127 // TODO make better
128 return generateHtml( aError.AsString() );
129}
130
131
133{
135 m_messages.clear();
136}
137
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:995
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"))
Holds a structured error message.
Definition ki_error.h:38
wxString AsString() const
Definition ki_error.cpp:27
KI_ERROR & SetSeverity(SEVERITY aSeverity)
Definition ki_error.h:76
KI_ERROR & SetTitle(const wxString &aTitle)
Definition ki_error.h:58
virtual void Clear()
Definition reporter.h:162
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
Definition reporter.h:102
REPORTER()
Definition reporter.h:75
void Clear() override
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
Indicates messages should be flushed as they are added.
void Flush()
Build the HTML messages page.
std::vector< KI_ERROR > m_messages
copy of the report, stored for filtering.
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)
EDA_UNITS
Definition eda_units.h:44
SEVERITY
static const long long MM