diff --git a/common/widgets/unit_binder.cpp b/common/widgets/unit_binder.cpp index 0b608921dc..606a55ea93 100644 --- a/common/widgets/unit_binder.cpp +++ b/common/widgets/unit_binder.cpp @@ -38,12 +38,12 @@ wxDEFINE_EVENT( DELAY_FOCUS, wxCommandEvent ); UNIT_BINDER::UNIT_BINDER( EDA_DRAW_FRAME* aParent, wxStaticText* aLabel, wxWindow* aValue, wxStaticText* aUnitLabel, bool aUseMils, bool allowEval ) : - m_label( aLabel ), - m_value( aValue ), - m_unitLabel( aUnitLabel ), - m_eval( aParent->GetUserUnits(), aUseMils ) + m_frame( aParent ), + m_label( aLabel ), + m_value( aValue ), + m_unitLabel( aUnitLabel ), + m_eval( aParent->GetUserUnits(), aUseMils ) { - // Fix the units (to the current units) for the life of the binder m_units = aParent->GetUserUnits(); m_useMils = aUseMils; m_allowEval = allowEval && dynamic_cast( m_value ); @@ -63,6 +63,14 @@ UNIT_BINDER::UNIT_BINDER( EDA_DRAW_FRAME* aParent, m_value->Connect( wxEVT_SET_FOCUS, wxFocusEventHandler( UNIT_BINDER::onSetFocus ), NULL, this ); m_value->Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( UNIT_BINDER::onKillFocus ), NULL, this ); Connect( DELAY_FOCUS, wxCommandEventHandler( UNIT_BINDER::delayedFocusHandler ), NULL, this ); + + m_frame->Connect( UNITS_CHANGED, wxCommandEventHandler( UNIT_BINDER::onUnitsChanged ), nullptr, this ); +} + + +UNIT_BINDER::~UNIT_BINDER() +{ + m_frame->Disconnect( UNITS_CHANGED, wxCommandEventHandler( UNIT_BINDER::onUnitsChanged ), nullptr, this ); } @@ -74,6 +82,18 @@ void UNIT_BINDER::SetUnits( EDA_UNITS aUnits, bool aUseMils ) } +void UNIT_BINDER::onUnitsChanged( wxCommandEvent& aEvent ) +{ + int temp = (int) GetValue(); + + SetUnits( m_frame->GetUserUnits(), m_useMils ); + + SetValue( temp ); + + aEvent.Skip(); +} + + void UNIT_BINDER::onSetFocus( wxFocusEvent& aEvent ) { auto textEntry = dynamic_cast( m_value ); diff --git a/include/widgets/unit_binder.h b/include/widgets/unit_binder.h index a1e12a0082..ce4abca57f 100644 --- a/include/widgets/unit_binder.h +++ b/include/widgets/unit_binder.h @@ -56,6 +56,8 @@ public: wxStaticText* aLabel, wxWindow* aValue, wxStaticText* aUnitLabel, bool aUseMils = false, bool aAllowEval = true ); + ~UNIT_BINDER() override; + /** * Function SetUnits * Normally not needed (as the UNIT_BINDER inherits from the parent frame), but can be @@ -148,6 +150,10 @@ protected: void onKillFocus( wxFocusEvent& aEvent ); void delayedFocusHandler( wxCommandEvent& aEvent ); + void onUnitsChanged( wxCommandEvent& aEvent ); + + EDA_DRAW_FRAME* m_frame; + ///> The bound widgets wxStaticText* m_label; wxWindow* m_value;