Remove all wxWidgets build dependencies from REPORTER object header.

This commit is contained in:
Wayne Stambaugh 2021-08-16 07:49:22 -04:00
parent 1a252b4f96
commit 8e1015fcc4
4 changed files with 74 additions and 38 deletions

View File

@ -201,9 +201,14 @@ bool STATUSBAR_REPORTER::HasMessage() const
} }
INFOBAR_REPORTER::~INFOBAR_REPORTER()
{
}
REPORTER& INFOBAR_REPORTER::Report( const wxString& aText, SEVERITY aSeverity ) REPORTER& INFOBAR_REPORTER::Report( const wxString& aText, SEVERITY aSeverity )
{ {
m_message = aText; m_message.reset( new wxString( aText ) );
m_severity = aSeverity; m_severity = aSeverity;
m_messageSet = true; m_messageSet = true;
@ -213,7 +218,7 @@ REPORTER& INFOBAR_REPORTER::Report( const wxString& aText, SEVERITY aSeverity )
bool INFOBAR_REPORTER::HasMessage() const 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; case RPT_SEVERITY_IGNORE: icon = wxICON_INFORMATION; break;
} }
if( m_message.EndsWith( "\n" ) ) if( m_message->EndsWith( "\n" ) )
m_message = m_message.Left( m_message.Length() - 1 ); *m_message = m_message->Left( m_message->Length() - 1 );
if( HasMessage() ) if( HasMessage() )
m_infoBar->QueueShowMessage( m_message, icon ); m_infoBar->QueueShowMessage( *m_message, icon );
else else
m_infoBar->QueueDismiss(); m_infoBar->QueueDismiss();
} }

View File

@ -1,8 +1,8 @@
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2013 Wayne Stambaugh <stambaughw@verizon.net> * Copyright (C) 2013 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 2013-2020 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2013-2021 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -25,17 +25,23 @@
#ifndef _REPORTER_H_ #ifndef _REPORTER_H_
#define _REPORTER_H_ #define _REPORTER_H_
#include <memory>
#include <eda_units.h> #include <eda_units.h>
#include <wx/string.h> #include <widgets/report_severity.h>
#include <widgets/ui_common.h>
/** /**
* @file reporter.h * @file reporter.h
* @author Wayne Stambaugh * @author Wayne Stambaugh
* @note A special thanks to Dick Hollenbeck who came up with the idea that inspired * @note A special thanks to Dick Hollenbeck who came up with the idea that inspired
* me to write this. * 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 wxStatusBar;
class wxTextCtrl; class wxTextCtrl;
class WX_HTML_REPORT_PANEL; class WX_HTML_REPORT_PANEL;
@ -108,9 +114,6 @@ public:
REPORTER& Report( const char* aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ); REPORTER& Report( const char* aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED );
REPORTER& operator <<( const wxString& aText ) { return Report( aText ); } 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. * Returns true if the reporter client is non-empty.
@ -133,8 +136,6 @@ public:
*/ */
class WX_TEXT_CTRL_REPORTER : public REPORTER class WX_TEXT_CTRL_REPORTER : public REPORTER
{ {
wxTextCtrl* m_textCtrl;
public: public:
WX_TEXT_CTRL_REPORTER( wxTextCtrl* aTextCtrl ) : WX_TEXT_CTRL_REPORTER( wxTextCtrl* aTextCtrl ) :
REPORTER(), REPORTER(),
@ -150,6 +151,9 @@ public:
SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override; SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
bool HasMessage() const override; bool HasMessage() const override;
private:
wxTextCtrl* m_textCtrl;
}; };
@ -158,8 +162,6 @@ public:
*/ */
class WX_STRING_REPORTER : public REPORTER class WX_STRING_REPORTER : public REPORTER
{ {
wxString* m_string;
public: public:
WX_STRING_REPORTER( wxString* aString ) : WX_STRING_REPORTER( wxString* aString ) :
REPORTER(), REPORTER(),
@ -174,6 +176,9 @@ public:
REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override; REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
bool HasMessage() const override; bool HasMessage() const override;
private:
wxString* m_string;
}; };
@ -182,8 +187,6 @@ public:
*/ */
class WX_HTML_PANEL_REPORTER : public REPORTER class WX_HTML_PANEL_REPORTER : public REPORTER
{ {
WX_HTML_REPORT_PANEL* m_panel;
public: public:
WX_HTML_PANEL_REPORTER( WX_HTML_REPORT_PANEL* aPanel ) : WX_HTML_PANEL_REPORTER( WX_HTML_REPORT_PANEL* aPanel ) :
REPORTER(), REPORTER(),
@ -205,6 +208,9 @@ public:
SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override; SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
bool HasMessage() const override; bool HasMessage() const override;
private:
WX_HTML_REPORT_PANEL* m_panel;
}; };
@ -313,11 +319,12 @@ public:
: REPORTER(), : REPORTER(),
m_messageSet( false ), m_messageSet( false ),
m_infoBar( aInfoBar ), m_infoBar( aInfoBar ),
m_message( wxEmptyString ),
m_severity( RPT_SEVERITY_UNDEFINED ) m_severity( RPT_SEVERITY_UNDEFINED )
{ {
} }
virtual ~INFOBAR_REPORTER();
REPORTER& Report( const wxString& aText, REPORTER& Report( const wxString& aText,
SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override; SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
@ -329,10 +336,10 @@ public:
void Finalize(); void Finalize();
private: private:
bool m_messageSet; bool m_messageSet;
WX_INFOBAR* m_infoBar; WX_INFOBAR* m_infoBar;
wxString m_message; std::unique_ptr<wxString> m_message;
SEVERITY m_severity; SEVERITY m_severity;
}; };
#endif // _REPORTER_H_ #endif // _REPORTER_H_

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#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_

View File

@ -26,6 +26,7 @@
#ifndef UI_COMMON_H #ifndef UI_COMMON_H
#define UI_COMMON_H #define UI_COMMON_H
#include "report_severity.h" // enum SEVERITY
#include <wx/string.h> #include <wx/string.h>
#include <wx/font.h> #include <wx/font.h>
@ -75,17 +76,16 @@ bool EnsureTextCtrlWidth( wxTextCtrl* aCtrl, const wxString* aString = nullptr )
void SelectReferenceNumber( wxTextEntry* aTextEntry ); 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 * @param aFocus Control that has focus, if null, wxWidgets will be queried
*/ */
bool IsInputControlFocused( wxWindow* aFocus = nullptr ); 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 * @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 * @return True if control is input and editable OR control is not a input. False if control is
* input and not editable. * 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 ); SEVERITY SeverityFromString( const wxString& aSeverity );
wxString SeverityToString( const SEVERITY& aSeverity ); wxString SeverityToString( const SEVERITY& aSeverity );