From faad5ee1ce7f55fea67f77f710f5b697973578fd Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Thu, 7 Oct 2021 01:44:27 +0200 Subject: [PATCH] Use system text and background colors in PCB calculator wxHtmlWindow forces white background and black text. Force it back to system settings. --- common/CMakeLists.txt | 1 + common/html_window.cpp | 55 +++++++++++++++++++ include/html_window.h | 48 ++++++++++++++++ .../dialogs/panel_attenuators_base.cpp | 6 +- .../dialogs/panel_attenuators_base.fbp | 15 +++-- .../dialogs/panel_attenuators_base.h | 10 ++-- pcb_calculator/dialogs/panel_eserie_base.cpp | 4 +- pcb_calculator/dialogs/panel_eserie_base.fbp | 12 ++-- pcb_calculator/dialogs/panel_eserie_base.h | 10 ++-- .../dialogs/panel_track_width_base.cpp | 4 +- .../dialogs/panel_track_width_base.fbp | 8 ++- .../dialogs/panel_track_width_base.h | 10 ++-- 12 files changed, 153 insertions(+), 30 deletions(-) create mode 100644 common/html_window.cpp create mode 100644 include/html_window.h diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 035e54c685..e29a623ece 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -347,6 +347,7 @@ set( COMMON_SRCS grid_tricks.cpp hotkey_store.cpp hotkeys_basic.cpp + html_window.cpp kiface_base.cpp kiid.cpp kiway.cpp diff --git a/common/html_window.cpp b/common/html_window.cpp new file mode 100644 index 0000000000..c500575626 --- /dev/null +++ b/common/html_window.cpp @@ -0,0 +1,55 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2021 Mikołaj Wielgus + * Copyright (C) 2021 KiCad Developers, see AUTHORS.TXT for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include +#include + + +HTML_WINDOW::HTML_WINDOW( wxWindow* aParent, wxWindowID aId, const wxPoint& aPos, + const wxSize& aSize, long aStyle, const wxString& aName ) + : wxHtmlWindow( aParent, aId, aPos, aSize, aStyle, aName ) +{ + Bind( wxEVT_SYS_COLOUR_CHANGED, + wxSysColourChangedEventHandler( HTML_WINDOW::onThemeChanged ), this ); +} + + +bool HTML_WINDOW::SetPage( const wxString& aSource ) +{ + m_pageSource = aSource; + + wxColour bg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ); + wxColour fg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT ); + + return wxHtmlWindow::SetPage( "\n" + + aSource + + "\n" ); +} + + +void HTML_WINDOW::onThemeChanged( wxSysColourChangedEvent &aEvent ) +{ + SetPage( m_pageSource ); +} diff --git a/include/html_window.h b/include/html_window.h new file mode 100644 index 0000000000..c952a86a18 --- /dev/null +++ b/include/html_window.h @@ -0,0 +1,48 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2021 Mikołaj Wielgus + * Copyright (C) 2021 KiCad Developers, see AUTHORS.TXT for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef HTML_WINDOW_H +#define HTML_WINDOW_H + +#include + +/** + * Add dark theme support to wxHtmlWindow. + */ +class HTML_WINDOW : public wxHtmlWindow +{ +public: + HTML_WINDOW( wxWindow* aParent, wxWindowID aId=wxID_ANY, const wxPoint& aPos=wxDefaultPosition, + const wxSize& aSize=wxDefaultSize, long aStyle=wxHW_DEFAULT_STYLE, + const wxString& aName="htmlWindow" ); + + bool SetPage( const wxString& aSource ) override; + +private: + void onThemeChanged( wxSysColourChangedEvent &aEvent ); + + wxString m_pageSource; +}; + +#endif /* HTML_WINDOW_H */ diff --git a/pcb_calculator/dialogs/panel_attenuators_base.cpp b/pcb_calculator/dialogs/panel_attenuators_base.cpp index 7a9284bd50..658669be3a 100644 --- a/pcb_calculator/dialogs/panel_attenuators_base.cpp +++ b/pcb_calculator/dialogs/panel_attenuators_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Oct 26 2018) +// C++ code generated with wxFormBuilder (version 3.10.0) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -157,7 +157,7 @@ PANEL_ATTENUATORS_BASE::PANEL_ATTENUATORS_BASE( wxWindow* parent, wxWindowID id, bSizerMessages->Add( bSizerIndentLabel, 0, wxLEFT, 6 ); - m_Attenuator_Messages = new wxHtmlWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHW_NO_SELECTION|wxHW_SCROLLBAR_AUTO ); + m_Attenuator_Messages = new HTML_WINDOW( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHW_NO_SELECTION|wxHW_SCROLLBAR_AUTO ); bSizerMessages->Add( m_Attenuator_Messages, 1, wxEXPAND|wxBOTTOM|wxRIGHT, 8 ); @@ -169,7 +169,7 @@ PANEL_ATTENUATORS_BASE::PANEL_ATTENUATORS_BASE( wxWindow* parent, wxWindowID id, wxStaticBoxSizer* sbRightSizerFormula; sbRightSizerFormula = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Formula") ), wxVERTICAL ); - m_panelAttFormula = new wxHtmlWindow( sbRightSizerFormula->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_AUTO ); + m_panelAttFormula = new HTML_WINDOW( sbRightSizerFormula->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_AUTO ); sbRightSizerFormula->Add( m_panelAttFormula, 1, wxEXPAND|wxBOTTOM, 5 ); diff --git a/pcb_calculator/dialogs/panel_attenuators_base.fbp b/pcb_calculator/dialogs/panel_attenuators_base.fbp index b803ea43e5..1009f4ae2e 100644 --- a/pcb_calculator/dialogs/panel_attenuators_base.fbp +++ b/pcb_calculator/dialogs/panel_attenuators_base.fbp @@ -1,6 +1,6 @@ - + C++ @@ -14,6 +14,7 @@ panel_attenuators_base 1000 none + 1 panel_attenuators_base @@ -25,6 +26,7 @@ 1 1 UI + 0 0 0 @@ -46,6 +48,7 @@ 500,300 ; ; forward_declare + 0 wxTAB_TRAVERSAL @@ -821,6 +824,7 @@ + 0 @@ -894,6 +898,7 @@ + 0 @@ -1546,11 +1551,11 @@ - + 3 wxEXPAND|wxLEFT 1 - + bSizerMessages wxVERTICAL @@ -1677,7 +1682,7 @@ 1 wxHW_NO_SELECTION|wxHW_SCROLLBAR_AUTO - + HTML_WINDOW; html_window.h; 0 @@ -1751,7 +1756,7 @@ 1 wxHW_SCROLLBAR_AUTO - + HTML_WINDOW; html_window.h; 0 diff --git a/pcb_calculator/dialogs/panel_attenuators_base.h b/pcb_calculator/dialogs/panel_attenuators_base.h index dda78e06da..4fd5211b2d 100644 --- a/pcb_calculator/dialogs/panel_attenuators_base.h +++ b/pcb_calculator/dialogs/panel_attenuators_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Oct 26 2018) +// C++ code generated with wxFormBuilder (version 3.10.0) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -10,6 +10,7 @@ #include #include #include +#include "html_window.h" #include #include #include @@ -63,10 +64,10 @@ class PANEL_ATTENUATORS_BASE : public wxPanel wxTextCtrl* m_Att_R3_Value; wxStaticText* m_attR3Unit; wxStaticText* m_staticTextAttMsg; - wxHtmlWindow* m_Attenuator_Messages; - wxHtmlWindow* m_panelAttFormula; + HTML_WINDOW* m_Attenuator_Messages; + HTML_WINDOW* m_panelAttFormula; - // Virtual event handlers, overide them in your derived class + // Virtual event handlers, override them in your derived class virtual void OnAttenuatorSelection( wxCommandEvent& event ) { event.Skip(); } virtual void OnCalculateAttenuator( wxCommandEvent& event ) { event.Skip(); } @@ -74,6 +75,7 @@ class PANEL_ATTENUATORS_BASE : public wxPanel public: PANEL_ATTENUATORS_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 500,300 ), long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString ); + ~PANEL_ATTENUATORS_BASE(); }; diff --git a/pcb_calculator/dialogs/panel_eserie_base.cpp b/pcb_calculator/dialogs/panel_eserie_base.cpp index 2f926e3ca2..2b569885b6 100644 --- a/pcb_calculator/dialogs/panel_eserie_base.cpp +++ b/pcb_calculator/dialogs/panel_eserie_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Oct 26 2018) +// C++ code generated with wxFormBuilder (version 3.10.0) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -183,7 +183,7 @@ PANEL_E_SERIE_BASE::PANEL_E_SERIE_BASE( wxWindow* parent, wxWindowID id, const w wxStaticBoxSizer* sbLowerSizerEseriesHelp; sbLowerSizerEseriesHelp = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Help") ), wxVERTICAL ); - m_panelESeriesHelp = new wxHtmlWindow( sbLowerSizerEseriesHelp->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_AUTO ); + m_panelESeriesHelp = new HTML_WINDOW( sbLowerSizerEseriesHelp->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_AUTO ); sbLowerSizerEseriesHelp->Add( m_panelESeriesHelp, 1, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); diff --git a/pcb_calculator/dialogs/panel_eserie_base.fbp b/pcb_calculator/dialogs/panel_eserie_base.fbp index d23b1634f2..c312e06376 100644 --- a/pcb_calculator/dialogs/panel_eserie_base.fbp +++ b/pcb_calculator/dialogs/panel_eserie_base.fbp @@ -1,6 +1,6 @@ - + C++ @@ -14,6 +14,7 @@ panel_eserie_base 1000 none + 1 panel_eserie_base @@ -25,6 +26,7 @@ 1 1 UI + 0 0 0 @@ -46,6 +48,7 @@ 677,453 ; ; forward_declare + 0 wxTAB_TRAVERSAL @@ -2016,6 +2019,7 @@ + 0 @@ -2100,11 +2104,11 @@ bLowerESerie wxHORIZONTAL none - + 5 wxEXPAND|wxTOP|wxRIGHT|wxLEFT 1 - + wxID_ANY Help @@ -2162,7 +2166,7 @@ 1 wxHW_SCROLLBAR_AUTO - + HTML_WINDOW; html_window.h; 0 diff --git a/pcb_calculator/dialogs/panel_eserie_base.h b/pcb_calculator/dialogs/panel_eserie_base.h index 9a696aae4e..8585e0c884 100644 --- a/pcb_calculator/dialogs/panel_eserie_base.h +++ b/pcb_calculator/dialogs/panel_eserie_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Oct 26 2018) +// C++ code generated with wxFormBuilder (version 3.10.0) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -10,6 +10,7 @@ #include #include #include +#include "html_window.h" #include #include #include @@ -21,10 +22,10 @@ #include #include #include +#include #include #include #include -#include #include #include @@ -70,9 +71,9 @@ class PANEL_E_SERIE_BASE : public wxPanel wxStaticText* m_ESeriesAltPercent1; wxStaticLine* m_staticline7; wxButton* m_buttonEScalculate; - wxHtmlWindow* m_panelESeriesHelp; + HTML_WINDOW* m_panelESeriesHelp; - // Virtual event handlers, overide them in your derived class + // Virtual event handlers, override them in your derived class virtual void OnESeriesSelection( wxCommandEvent& event ) { event.Skip(); } virtual void OnCalculateESeries( wxCommandEvent& event ) { event.Skip(); } @@ -80,6 +81,7 @@ class PANEL_E_SERIE_BASE : public wxPanel public: PANEL_E_SERIE_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 677,453 ), long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString ); + ~PANEL_E_SERIE_BASE(); }; diff --git a/pcb_calculator/dialogs/panel_track_width_base.cpp b/pcb_calculator/dialogs/panel_track_width_base.cpp index 54f5f678a0..1ffec237c3 100644 --- a/pcb_calculator/dialogs/panel_track_width_base.cpp +++ b/pcb_calculator/dialogs/panel_track_width_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Oct 26 2018) +// C++ code generated with wxFormBuilder (version 3.10.0) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -79,7 +79,7 @@ PANEL_TRACK_WIDTH_BASE::PANEL_TRACK_WIDTH_BASE( wxWindow* parent, wxWindowID id, bSizeLeft->Add( sbSizerTW_Prms, 0, wxALL|wxEXPAND, 5 ); - m_htmlWinFormulas = new wxHtmlWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHW_NO_SELECTION|wxHW_SCROLLBAR_AUTO ); + m_htmlWinFormulas = new HTML_WINDOW( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHW_NO_SELECTION|wxHW_SCROLLBAR_AUTO ); bSizeLeft->Add( m_htmlWinFormulas, 1, wxEXPAND|wxALL, 8 ); diff --git a/pcb_calculator/dialogs/panel_track_width_base.fbp b/pcb_calculator/dialogs/panel_track_width_base.fbp index fc95b21ea6..d5dd29f773 100644 --- a/pcb_calculator/dialogs/panel_track_width_base.fbp +++ b/pcb_calculator/dialogs/panel_track_width_base.fbp @@ -1,6 +1,6 @@ - + C++ @@ -14,6 +14,7 @@ panel_track_width_base 1000 none + 1 panel_track_width_base @@ -25,6 +26,7 @@ 1 1 UI + 0 0 0 @@ -46,6 +48,7 @@ 623,457 ; ; forward_declare + 0 wxTAB_TRAVERSAL @@ -897,7 +900,7 @@ 1 wxHW_NO_SELECTION|wxHW_SCROLLBAR_AUTO - + HTML_WINDOW; html_window.h; 0 @@ -3569,6 +3572,7 @@ + 0 diff --git a/pcb_calculator/dialogs/panel_track_width_base.h b/pcb_calculator/dialogs/panel_track_width_base.h index e266c6b157..5c5e322424 100644 --- a/pcb_calculator/dialogs/panel_track_width_base.h +++ b/pcb_calculator/dialogs/panel_track_width_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Oct 26 2018) +// C++ code generated with wxFormBuilder (version 3.10.0) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -13,6 +13,7 @@ class UNIT_SELECTOR_LEN; class UNIT_SELECTOR_THICKNESS; +#include "html_window.h" #include #include #include @@ -25,10 +26,10 @@ class UNIT_SELECTOR_THICKNESS; #include #include #include +#include #include #include #include -#include #include /////////////////////////////////////////////////////////////////////////// @@ -54,7 +55,7 @@ class PANEL_TRACK_WIDTH_BASE : public wxPanel wxStaticText* m_staticText103; wxTextCtrl* m_TWResistivity; wxStaticText* m_resistivityUnits; - wxHtmlWindow* m_htmlWinFormulas; + HTML_WINDOW* m_htmlWinFormulas; wxStaticText* m_staticTextExtWidth; wxTextCtrl* m_ExtTrackWidthValue; UNIT_SELECTOR_LEN* m_TW_ExtTrackWidth_choiceUnit; @@ -99,7 +100,7 @@ class PANEL_TRACK_WIDTH_BASE : public wxPanel wxStaticText* m_staticText7911; wxButton* m_buttonTrackWidthReset; - // Virtual event handlers, overide them in your derived class + // Virtual event handlers, override them in your derived class virtual void OnTWCalculateFromCurrent( wxCommandEvent& event ) { event.Skip(); } virtual void OnTWParametersChanged( wxCommandEvent& event ) { event.Skip(); } virtual void OnTWCalculateFromExtWidth( wxCommandEvent& event ) { event.Skip(); } @@ -110,6 +111,7 @@ class PANEL_TRACK_WIDTH_BASE : public wxPanel public: PANEL_TRACK_WIDTH_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 623,457 ), long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString ); + ~PANEL_TRACK_WIDTH_BASE(); };