// wxHtmlWindow Test - Tests HTML Window in WASM // KiCad uses wxHtmlWindow for About dialogs, error formatting, and descriptions // instead of wxRichTextCtrl #include "wx/wxprec.h" #ifndef WX_PRECOMP #include "wx/wx.h" #endif #include "wx/html/htmlwin.h" #ifdef __EMSCRIPTEN__ #include #endif class HtmlWinTestApp : public wxApp { public: virtual bool OnInit() override; }; class HtmlWinTestFrame : public wxFrame { public: HtmlWinTestFrame(); private: wxHtmlWindow* m_htmlWin; wxTextCtrl* m_log; void LogEvent(const wxString& msg); void SetBasicContent(); void SetTableContent(); void SetLongContent(); void OnLinkClicked(wxHtmlLinkEvent& evt); void OnBasicContent(wxCommandEvent& evt); void OnTableContent(wxCommandEvent& evt); void OnLongContent(wxCommandEvent& evt); void OnKiCadAbout(wxCommandEvent& evt); wxDECLARE_EVENT_TABLE(); }; enum { ID_HTML = wxID_HIGHEST + 1, ID_BASIC_CONTENT, ID_TABLE_CONTENT, ID_LONG_CONTENT, ID_KICAD_ABOUT }; wxBEGIN_EVENT_TABLE(HtmlWinTestFrame, wxFrame) EVT_HTML_LINK_CLICKED(ID_HTML, HtmlWinTestFrame::OnLinkClicked) EVT_BUTTON(ID_BASIC_CONTENT, HtmlWinTestFrame::OnBasicContent) EVT_BUTTON(ID_TABLE_CONTENT, HtmlWinTestFrame::OnTableContent) EVT_BUTTON(ID_LONG_CONTENT, HtmlWinTestFrame::OnLongContent) EVT_BUTTON(ID_KICAD_ABOUT, HtmlWinTestFrame::OnKiCadAbout) wxEND_EVENT_TABLE() wxIMPLEMENT_APP(HtmlWinTestApp); bool HtmlWinTestApp::OnInit() { if (!wxApp::OnInit()) return false; HtmlWinTestFrame* frame = new HtmlWinTestFrame(); frame->Show(true); return true; } HtmlWinTestFrame::HtmlWinTestFrame() : wxFrame(nullptr, wxID_ANY, "wxHtmlWindow WASM Test", wxDefaultPosition, wxSize(700, 650)) { wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL); wxStaticText* desc = new wxStaticText(this, wxID_ANY, "wxHtmlWindow Test\n\n" "KiCad uses HtmlWindow for About dialogs, error messages, and symbol descriptions.\n" "Click buttons to load different HTML content."); mainSizer->Add(desc, 0, wxALL, 10); // Button bar wxBoxSizer* btnSizer = new wxBoxSizer(wxHORIZONTAL); btnSizer->Add(new wxButton(this, ID_BASIC_CONTENT, "Basic HTML"), 0, wxALL, 5); btnSizer->Add(new wxButton(this, ID_TABLE_CONTENT, "Tables"), 0, wxALL, 5); btnSizer->Add(new wxButton(this, ID_LONG_CONTENT, "Long Content"), 0, wxALL, 5); btnSizer->Add(new wxButton(this, ID_KICAD_ABOUT, "KiCad-style About"), 0, wxALL, 5); mainSizer->Add(btnSizer, 0, wxALIGN_CENTER); // HTML Window m_htmlWin = new wxHtmlWindow(this, ID_HTML, wxDefaultPosition, wxSize(-1, 300), wxHW_SCROLLBAR_AUTO | wxSUNKEN_BORDER); mainSizer->Add(m_htmlWin, 1, wxEXPAND | wxALL, 10); // Event log wxStaticBoxSizer* logBox = new wxStaticBoxSizer(wxVERTICAL, this, "Event Log"); m_log = new wxTextCtrl(this, wxID_ANY, "", wxDefaultPosition, wxSize(-1, 120), wxTE_MULTILINE | wxTE_READONLY); logBox->Add(m_log, 1, wxEXPAND | wxALL, 5); mainSizer->Add(logBox, 0, wxEXPAND | wxALL, 10); SetSizer(mainSizer); CreateStatusBar(); SetStatusText("Ready"); // Set initial content SetBasicContent(); LogEvent("HtmlWindow test app started"); LogEvent("Initial content loaded"); #ifdef __EMSCRIPTEN__ EM_ASM({ console.log('[HTMLWIN_TEST] wxHtmlWindow test app started successfully'); }); #endif } void HtmlWinTestFrame::LogEvent(const wxString& msg) { #ifdef __EMSCRIPTEN__ EM_ASM({ console.log('[HTMLWIN_EVENT] ' + UTF8ToString($0)); }, msg.c_str().AsChar()); #endif if (!m_log) return; m_log->AppendText(msg + "\n"); SetStatusText(msg); } void HtmlWinTestFrame::SetBasicContent() { wxString html = R"(

Basic HTML Test

This tests bold, italic, and underlined text.

Lists

  1. Ordered item 1
  2. Ordered item 2
  3. Ordered item 3

Links

Click this test link to fire an event.

Another second link for testing.

Colors

Red text, green text, blue text.

Horizontal Rule


Content below the line.

)"; m_htmlWin->SetPage(html); LogEvent("Loaded basic HTML content"); } void HtmlWinTestFrame::SetTableContent() { wxString html = R"(

Table Test

This tests HTML tables similar to KiCad's component info display.

Component Properties

Property Value
Reference U1
Value STM32F103C8
Footprint LQFP-48
Datasheet View PDF

Pin Table

Pin Name Type Net
1 VCC Power +3V3
2 GND Power GND
3 PA0 I/O Net1
4 PA1 I/O Net2
)"; m_htmlWin->SetPage(html); LogEvent("Loaded table HTML content"); } void HtmlWinTestFrame::SetLongContent() { wxString html = R"(

Long Scrollable Content

This tests scrolling behavior with long content.

)"; // Generate long content for (int i = 1; i <= 30; i++) { html += wxString::Format( "

Section %d

\n" "

This is paragraph %d of the long content test. " "It contains enough text to verify scrolling works correctly " "in the wxHtmlWindow WASM implementation.

\n", i, i ); } html += ""; m_htmlWin->SetPage(html); LogEvent("Loaded long scrollable content (30 sections)"); } void HtmlWinTestFrame::OnLinkClicked(wxHtmlLinkEvent& evt) { wxString href = evt.GetLinkInfo().GetHref(); LogEvent(wxString::Format("Link clicked: '%s'", href)); #ifdef __EMSCRIPTEN__ EM_ASM({ console.log('[HTMLWIN_LINK] Link clicked: ' + UTF8ToString($0)); }, href.c_str().AsChar()); #endif } void HtmlWinTestFrame::OnBasicContent(wxCommandEvent& WXUNUSED(evt)) { SetBasicContent(); } void HtmlWinTestFrame::OnTableContent(wxCommandEvent& WXUNUSED(evt)) { SetTableContent(); } void HtmlWinTestFrame::OnLongContent(wxCommandEvent& WXUNUSED(evt)) { SetLongContent(); } void HtmlWinTestFrame::OnKiCadAbout(wxCommandEvent& WXUNUSED(evt)) { wxString html = R"(

KiCad EDA

Version 8.0.0

An open source EDA suite for schematic capture
and PCB design.


Build: WASM (Emscripten)
Platform: Web Browser
wxWidgets: 3.3.0

Libraries

wxWidgets | Boost | OpenCASCADE

License

KiCad is free software licensed under the
GNU General Public License v3

Copyright (c) 2024 KiCad Developers

)"; m_htmlWin->SetPage(html); LogEvent("Loaded KiCad-style About content"); }