From 54dd494ff2365df78c031d9bec75d1db581afb42 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Sun, 4 Dec 2022 16:49:46 -0800 Subject: [PATCH] Remove frame dependency from UNIT_BINDER Place the frame information into the event data instead of keeping a pointer (potentially invalid) into the frame --- common/eda_base_frame.cpp | 1 + common/widgets/unit_binder.cpp | 15 ++++++++------- include/widgets/unit_binder.h | 3 +-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/common/eda_base_frame.cpp b/common/eda_base_frame.cpp index 6e46ad8e67..b15df7a632 100644 --- a/common/eda_base_frame.cpp +++ b/common/eda_base_frame.cpp @@ -1336,6 +1336,7 @@ void EDA_BASE_FRAME::ChangeUserUnits( EDA_UNITS aUnits ) unitsChangeRefresh(); wxCommandEvent e( UNITS_CHANGED ); + e.SetClientData( this ); ProcessEventLocally( e ); } diff --git a/common/widgets/unit_binder.cpp b/common/widgets/unit_binder.cpp index e969eba7f7..14a0db12ab 100644 --- a/common/widgets/unit_binder.cpp +++ b/common/widgets/unit_binder.cpp @@ -45,22 +45,21 @@ UNIT_BINDER::UNIT_BINDER( EDA_DRAW_FRAME* aParent, wxStaticText* aLabel, wxWindo UNIT_BINDER::UNIT_BINDER( UNITS_PROVIDER* aUnitsProvider, wxWindow* aEventSource, wxStaticText* aLabel, wxWindow* aValueCtrl, wxStaticText* aUnitLabel, bool aAllowEval, bool aBindFocusEvent ) : - m_unitsProvider( aUnitsProvider ), m_eventSource( aEventSource ), m_bindFocusEvent( aBindFocusEvent ), m_label( aLabel ), m_valueCtrl( aValueCtrl ), m_unitLabel( aUnitLabel ), - m_iuScale( m_unitsProvider->GetIuScale() ), + m_iuScale( aUnitsProvider->GetIuScale() ), m_negativeZero( false ), m_dataType( EDA_DATA_TYPE::DISTANCE ), m_precision( 0 ), - m_eval( m_unitsProvider->GetUserUnits() ), + m_eval( aUnitsProvider->GetUserUnits() ), m_unitsInValue( false ), m_originTransforms( aUnitsProvider->GetOriginTransforms() ), m_coordType( ORIGIN_TRANSFORMS::NOT_A_COORD ) { - init(); + init( aUnitsProvider ); m_allowEval = aAllowEval && ( !m_valueCtrl || dynamic_cast( m_valueCtrl ) ); wxTextEntry* textEntry = dynamic_cast( m_valueCtrl ); @@ -116,9 +115,9 @@ UNIT_BINDER::~UNIT_BINDER() } -void UNIT_BINDER::init() +void UNIT_BINDER::init( UNITS_PROVIDER* aProvider ) { - m_units = m_unitsProvider->GetUserUnits(); + m_units = aProvider->GetUserUnits(); m_needsEval = false; m_selStart = 0; m_selEnd = 0; @@ -153,13 +152,15 @@ void UNIT_BINDER::SetDataType( EDA_DATA_TYPE aDataType ) void UNIT_BINDER::onUnitsChanged( wxCommandEvent& aEvent ) { + UNITS_PROVIDER* provider = static_cast( aEvent.GetClientData() ); + if( m_units != EDA_UNITS::UNSCALED && m_units != EDA_UNITS::DEGREES && m_units != EDA_UNITS::PERCENT ) { int temp = (int) GetValue(); - SetUnits( m_unitsProvider->GetUserUnits() ); + SetUnits( provider->GetUserUnits() ); SetValue( temp ); } diff --git a/include/widgets/unit_binder.h b/include/widgets/unit_binder.h index a72fa094f4..02ba083f67 100644 --- a/include/widgets/unit_binder.h +++ b/include/widgets/unit_binder.h @@ -199,7 +199,7 @@ public: } protected: - void init(); + void init( UNITS_PROVIDER* aProvider ); void onClick( wxMouseEvent& aEvent ); void onSetFocus( wxFocusEvent& aEvent ); @@ -222,7 +222,6 @@ protected: double setPrecision( double aValue, bool aValueUsesUserUnits ); protected: - UNITS_PROVIDER* m_unitsProvider; wxWindow* m_eventSource; bool m_bindFocusEvent;