Kicad-ize the numeric evaluator.

Naming conventions, code formatting, and wxStrings.

(cherry picked from commit 4a0d7a8)
This commit is contained in:
Jeff Young
2018-07-17 15:10:01 +01:00
parent 0f78f97232
commit f0f9e4a1cb
10 changed files with 360 additions and 394 deletions
+15 -14
View File
@@ -27,7 +27,8 @@
TEXT_CTRL_EVAL::TEXT_CTRL_EVAL( wxWindow* aParent, wxWindowID aId, const
wxString& aValue, const wxPoint& aPos, const wxSize& aSize, long aStyle,
const wxValidator& aValidator, const wxString& aName )
: wxTextCtrl( aParent, aId, aValue, aPos, aSize, aStyle | wxTE_PROCESS_ENTER, aValidator, aName )
: wxTextCtrl( aParent, aId, aValue, aPos, aSize, aStyle | wxTE_PROCESS_ENTER, aValidator, aName ),
m_eval( g_UserUnit )
{
Connect( wxEVT_SET_FOCUS,
wxFocusEventHandler( TEXT_CTRL_EVAL::onTextFocusGet ), NULL, this );
@@ -38,19 +39,19 @@ TEXT_CTRL_EVAL::TEXT_CTRL_EVAL( wxWindow* aParent, wxWindowID aId, const
}
void TEXT_CTRL_EVAL::SetValue( const wxString& aValue )
{
wxTextCtrl::SetValue( aValue );
m_eval.clear( this );
}
void TEXT_CTRL_EVAL::SetValue( const wxString& aValue )
{
wxTextCtrl::SetValue( aValue );
m_eval.Clear();
}
void TEXT_CTRL_EVAL::onTextFocusGet( wxFocusEvent& aEvent )
{
auto oldStr = m_eval.textInput( this );
wxString oldStr = m_eval.OriginalText();
if( oldStr )
wxTextCtrl::SetValue( wxString::FromUTF8( oldStr ) );
if( oldStr.length() )
SetValue( oldStr );
aEvent.Skip();
}
@@ -76,8 +77,8 @@ void TEXT_CTRL_EVAL::onTextEnter( wxCommandEvent& aEvent )
void TEXT_CTRL_EVAL::evaluate()
{
if( GetValue().IsEmpty() )
wxTextCtrl::SetValue( "0" );
wxTextCtrl::SetValue( "0" );
if( m_eval.process( GetValue().mb_str(), this ) )
wxTextCtrl::SetValue( wxString::FromUTF8( m_eval.result() ) );
if( m_eval.Process( GetValue() ) )
SetValue( m_eval.Result() );
}