From 8e1015fcc42d432cd98bcb768e4277a8efac8cce Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Mon, 16 Aug 2021 07:49:22 -0400 Subject: [PATCH] Remove all wxWidgets build dependencies from REPORTER object header. --- common/reporter.cpp | 15 +++++++---- include/reporter.h | 43 ++++++++++++++++++------------- include/widgets/report_severity.h | 36 ++++++++++++++++++++++++++ include/widgets/ui_common.h | 18 +++---------- 4 files changed, 74 insertions(+), 38 deletions(-) create mode 100644 include/widgets/report_severity.h diff --git a/common/reporter.cpp b/common/reporter.cpp index 020dc24783..11db29e7b5 100644 --- a/common/reporter.cpp +++ b/common/reporter.cpp @@ -201,9 +201,14 @@ bool STATUSBAR_REPORTER::HasMessage() const } +INFOBAR_REPORTER::~INFOBAR_REPORTER() +{ +} + + REPORTER& INFOBAR_REPORTER::Report( const wxString& aText, SEVERITY aSeverity ) { - m_message = aText; + m_message.reset( new wxString( aText ) ); m_severity = aSeverity; m_messageSet = true; @@ -213,7 +218,7 @@ REPORTER& INFOBAR_REPORTER::Report( const wxString& aText, SEVERITY aSeverity ) bool INFOBAR_REPORTER::HasMessage() const { - return !m_message.IsEmpty(); + return m_message && !m_message->IsEmpty(); } @@ -240,11 +245,11 @@ void INFOBAR_REPORTER::Finalize() case RPT_SEVERITY_IGNORE: icon = wxICON_INFORMATION; break; } - if( m_message.EndsWith( "\n" ) ) - m_message = m_message.Left( m_message.Length() - 1 ); + if( m_message->EndsWith( "\n" ) ) + *m_message = m_message->Left( m_message->Length() - 1 ); if( HasMessage() ) - m_infoBar->QueueShowMessage( m_message, icon ); + m_infoBar->QueueShowMessage( *m_message, icon ); else m_infoBar->QueueDismiss(); } diff --git a/include/reporter.h b/include/reporter.h index 28a136de67..daf82a5ba0 100644 --- a/include/reporter.h +++ b/include/reporter.h @@ -1,8 +1,8 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2013 Wayne Stambaugh - * Copyright (C) 2013-2020 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2013 Wayne Stambaugh + * Copyright (C) 2013-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 @@ -25,17 +25,23 @@ #ifndef _REPORTER_H_ #define _REPORTER_H_ +#include + #include -#include -#include +#include /** * @file reporter.h * @author Wayne Stambaugh * @note A special thanks to Dick Hollenbeck who came up with the idea that inspired * me to write this. + * @warning Do not add any dependencies to wxWidgets (or any other third party UI library ) + * to the REPORTER object. All wxWidgets objects should be defined by pointer or + * reference and forward declared so that using reporters in low level KiCad objects + * will not require pulling in wxWidgets to building them. */ +class wxString; class wxStatusBar; class wxTextCtrl; class WX_HTML_REPORT_PANEL; @@ -108,9 +114,6 @@ public: REPORTER& Report( const char* aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ); REPORTER& operator <<( const wxString& aText ) { return Report( aText ); } - REPORTER& operator <<( const wxChar* aText ) { return Report( wxString( aText ) ); } - REPORTER& operator <<( wxChar aChar ) { return Report( wxString( aChar ) ); } - REPORTER& operator <<( const char* aText ) { return Report( aText ); } /** * Returns true if the reporter client is non-empty. @@ -133,8 +136,6 @@ public: */ class WX_TEXT_CTRL_REPORTER : public REPORTER { - wxTextCtrl* m_textCtrl; - public: WX_TEXT_CTRL_REPORTER( wxTextCtrl* aTextCtrl ) : REPORTER(), @@ -150,6 +151,9 @@ public: SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override; bool HasMessage() const override; + +private: + wxTextCtrl* m_textCtrl; }; @@ -158,8 +162,6 @@ public: */ class WX_STRING_REPORTER : public REPORTER { - wxString* m_string; - public: WX_STRING_REPORTER( wxString* aString ) : REPORTER(), @@ -174,6 +176,9 @@ public: REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override; bool HasMessage() const override; + +private: + wxString* m_string; }; @@ -182,8 +187,6 @@ public: */ class WX_HTML_PANEL_REPORTER : public REPORTER { - WX_HTML_REPORT_PANEL* m_panel; - public: WX_HTML_PANEL_REPORTER( WX_HTML_REPORT_PANEL* aPanel ) : REPORTER(), @@ -205,6 +208,9 @@ public: SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override; bool HasMessage() const override; + +private: + WX_HTML_REPORT_PANEL* m_panel; }; @@ -313,11 +319,12 @@ public: : REPORTER(), m_messageSet( false ), m_infoBar( aInfoBar ), - m_message( wxEmptyString ), m_severity( RPT_SEVERITY_UNDEFINED ) { } + virtual ~INFOBAR_REPORTER(); + REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override; @@ -329,10 +336,10 @@ public: void Finalize(); private: - bool m_messageSet; - WX_INFOBAR* m_infoBar; - wxString m_message; - SEVERITY m_severity; + bool m_messageSet; + WX_INFOBAR* m_infoBar; + std::unique_ptr m_message; + SEVERITY m_severity; }; #endif // _REPORTER_H_ diff --git a/include/widgets/report_severity.h b/include/widgets/report_severity.h new file mode 100644 index 0000000000..5329689485 --- /dev/null +++ b/include/widgets/report_severity.h @@ -0,0 +1,36 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * 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 3 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, see . + */ + + +#ifndef _REPORT_SEVERITY_H_ +#define _REPORT_SEVERITY_H_ + +// Note: On windows, SEVERITY_ERROR collides with a system declaration, +// so we used RPT_SEVERITY _xxx instead of SEVERITY _xxx +enum SEVERITY { + RPT_SEVERITY_UNDEFINED = 0x00, + RPT_SEVERITY_INFO = 0x01, + RPT_SEVERITY_EXCLUSION = 0x02, + RPT_SEVERITY_ACTION = 0x04, + RPT_SEVERITY_WARNING = 0x08, + RPT_SEVERITY_ERROR = 0x10, + RPT_SEVERITY_IGNORE = 0x20 +}; + +#endif // _REPORT_SEVERITY_H_ diff --git a/include/widgets/ui_common.h b/include/widgets/ui_common.h index d0a5bf52df..0e9b6c7aad 100644 --- a/include/widgets/ui_common.h +++ b/include/widgets/ui_common.h @@ -26,6 +26,7 @@ #ifndef UI_COMMON_H #define UI_COMMON_H +#include "report_severity.h" // enum SEVERITY #include #include @@ -75,17 +76,16 @@ bool EnsureTextCtrlWidth( wxTextCtrl* aCtrl, const wxString* aString = nullptr ) void SelectReferenceNumber( wxTextEntry* aTextEntry ); /** - * Checks if a input control has focus + * Check if a input control has focus. * * @param aFocus Control that has focus, if null, wxWidgets will be queried */ bool IsInputControlFocused( wxWindow* aFocus = nullptr ); /** - * Checks if a input control has focus + * Check if a input control has focus. * * @param aFocus Control that test if editable - * * @return True if control is input and editable OR control is not a input. False if control is * input and not editable. */ @@ -95,18 +95,6 @@ bool IsModalDialogFocused(); } -// Note: On windows, SEVERITY_ERROR collides with a system declaration, -// so we used RPT_SEVERITY _xxx instead of SEVERITY _xxx -enum SEVERITY { - RPT_SEVERITY_UNDEFINED = 0x00, - RPT_SEVERITY_INFO = 0x01, - RPT_SEVERITY_EXCLUSION = 0x02, - RPT_SEVERITY_ACTION = 0x04, - RPT_SEVERITY_WARNING = 0x08, - RPT_SEVERITY_ERROR = 0x10, - RPT_SEVERITY_IGNORE = 0x20 -}; - SEVERITY SeverityFromString( const wxString& aSeverity ); wxString SeverityToString( const SEVERITY& aSeverity );