26#include <wx/clipbrd.h>
27#include <wx/stattext.h>
28#include <wx/textentry.h>
34#include "wx/dcclient.h"
41 wxStaticText* aUnitLabel,
bool allowEval,
bool aBindFrameEvents ) :
42 UNIT_BINDER( aParent, aParent, aLabel, aValueCtrl, aUnitLabel, allowEval, aBindFrameEvents )
47 wxStaticText* aLabel, wxWindow* aValueCtrl, wxStaticText* aUnitLabel,
48 bool aAllowEval,
bool aBindFocusEvent ) :
49 m_bindFocusEvent( aBindFocusEvent ),
51 m_valueCtrl( aValueCtrl ),
52 m_unitLabel( aUnitLabel ),
53 m_iuScale( &aUnitsProvider->GetIuScale() ),
54 m_negativeZero( false ),
58 m_unitsInValue( false ),
59 m_originTransforms( aUnitsProvider->GetOriginTransforms() ),
62 init( aUnitsProvider );
64 wxTextEntry* textEntry =
dynamic_cast<wxTextEntry*
>(
m_valueCtrl );
73 int minWidth = dc.GetTextExtent( wxT(
"XXX.XXXXXXXXXX" ) ).GetWidth();
75 if(
minSize.GetWidth() < minWidth )
80 textEntry->ChangeValue( wxT(
"-0" ) );
82 textEntry->ChangeValue( wxT(
"0" ) );
106 aEventSource->Connect( EDA_EVT_UNITS_CHANGED,
173 if(
m_units != EDA_UNITS::UNSCALED
174 &&
m_units != EDA_UNITS::DEGREES
175 &&
m_units != EDA_UNITS::PERCENT )
192 wxTextEntry* textEntry =
dynamic_cast<wxTextEntry*
>(
m_valueCtrl );
198 textEntry->SelectAll();
208 wxTextEntry* textEntry =
dynamic_cast<wxTextEntry*
>(
m_valueCtrl );
216 if( oldStr.length() && oldStr != textEntry->GetValue() )
218 textEntry->ChangeValue( oldStr );
229 textEntry->SelectAll();
239 wxTextEntry* textEntry =
dynamic_cast<wxTextEntry*
>(
m_valueCtrl );
251 if( !(
m_units == EDA_UNITS::DEGREES ||
m_units == EDA_UNITS::PERCENT ) )
257 textEntry->ChangeValue( value );
261 if( wxTheClipboard->Open() )
263 wxString sel = textEntry->GetStringSelection();
264 bool clipTarget = wxTheClipboard->IsUsingPrimarySelection();
265 wxTheClipboard->UsePrimarySelection(
true );
266 wxTheClipboard->SetData(
new wxTextDataObject( sel ) );
267 wxTheClipboard->UsePrimarySelection( clipTarget );
268 wxTheClipboard->Close();
282 wxString desc = aLabel->GetLabel();
284 desc.EndsWith( wxT(
":" ), &desc );
301 wxTextEntry* textEntry =
dynamic_cast<wxTextEntry*
>(
m_valueCtrl );
321 textEntry->SelectAll();
324 wxPostEvent(
this, wxCommandEvent( DELAY_FOCUS ) );
338 textEntry->SelectAll();
341 wxPostEvent(
this, wxCommandEvent( DELAY_FOCUS ) );
370 if( displayValue == 0 && !std::signbit( displayValue ) &&
m_negativeZero )
385 wxTextEntry* textEntry =
dynamic_cast<wxTextEntry*
>(
m_valueCtrl );
386 wxStaticText* staticText =
dynamic_cast<wxStaticText*
>(
m_valueCtrl );
388 wxString value = aValue;
392 if( !(
m_units == EDA_UNITS::DEGREES ||
m_units == EDA_UNITS::PERCENT ) )
399 textEntry->SetValue( value );
400 else if( staticText )
401 staticText->SetLabel( value );
433 if( displayValue == 0 && !std::signbit( displayValue ) &&
m_negativeZero )
448 wxTextEntry* textEntry =
dynamic_cast<wxTextEntry*
>(
m_valueCtrl );
449 wxStaticText* staticText =
dynamic_cast<wxStaticText*
>(
m_valueCtrl );
451 wxString value = aValue;
455 if( !(
m_units == EDA_UNITS::DEGREES ||
m_units == EDA_UNITS::PERCENT ) )
462 textEntry->ChangeValue( value );
463 else if( staticText )
464 staticText->SetLabel( value );
476 wxTextEntry* textEntry =
dynamic_cast<wxTextEntry*
>(
m_valueCtrl );
477 wxStaticText* staticText =
dynamic_cast<wxStaticText*
>(
m_valueCtrl );
485 value = textEntry->GetValue();
487 else if( staticText )
489 value = staticText->GetLabel();
507 int64_t tmp = aValue;
508 if( !aValueUsesUserUnits )
513 aValue =
static_cast<double>( tmp ) /
scale;
515 if( !aValueUsesUserUnits )
525 wxTextEntry* textEntry =
dynamic_cast<wxTextEntry*
>(
m_valueCtrl );
526 wxStaticText* staticText =
dynamic_cast<wxStaticText*
>(
m_valueCtrl );
534 value = textEntry->GetValue();
536 else if( staticText )
538 value = staticText->GetLabel();
561 wxTextEntry* te =
dynamic_cast<wxTextEntry*
>(
m_valueCtrl );
572 wxTextEntry* textEntry =
dynamic_cast<wxTextEntry*
>(
m_valueCtrl );
573 wxStaticText* staticText =
dynamic_cast<wxStaticText*
>(
m_valueCtrl );
578 return textEntry->GetValue();
579 else if( staticText )
580 return staticText->GetLabel();
582 return wxEmptyString;
635 UNIT_BINDER( aParent, nullptr, nullptr, nullptr, true, false )
656 [&]( wxShowEvent& e )
The base frame for deriving all KiCad main window classes.
The base class for create windows for drawing purpose.
wxString OriginalText() const
void SetDefaultUnits(EDA_UNITS aUnits)
bool Process(const wxString &aString)
void SetControl(wxWindow *aControl)
PROPERTY_EDITOR_UNIT_BINDER(EDA_DRAW_FRAME *aParent)
virtual ~PROPERTY_EDITOR_UNIT_BINDER()
const EDA_IU_SCALE & GetIuScale() const
EDA_UNITS GetUserUnits() const
ORIGIN_TRANSFORMS::COORD_TYPES_T m_coordType
Type of coordinate for display origin transforms.
virtual void ChangeDoubleValue(double aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion WITHOUT trigger...
wxString GetOriginalText() const
Return the pre-evaluated text (or the current text if evaluation is not supported).
void onKillFocus(wxFocusEvent &aEvent)
virtual long long int GetValue()
Return the current value in Internal Units.
void Enable(bool aEnable)
Enable/disable the label, widget and units label.
void onClick(wxMouseEvent &aEvent)
virtual void SetPrecision(int aLength)
Normally not needed, but can be used to set the precision when using internal units that are floats (...
virtual void SetUnits(EDA_UNITS aUnits)
Normally not needed (as the UNIT_BINDER inherits from the parent frame), but can be used to set to DE...
const EDA_IU_SCALE * m_iuScale
virtual EDA_ANGLE GetAngleValue()
bool m_negativeZero
Indicates "-0" should be displayed for 0.
wxStaticText * m_unitLabel
Can be nullptr.
bool m_unitsInValue
Units label should be included in value text.
void onSetFocus(wxFocusEvent &aEvent)
UNIT_BINDER(EDA_DRAW_FRAME *aParent, wxStaticText *aLabel, wxWindow *aValueCtrl, wxStaticText *aUnitLabel, bool aAllowEval=true, bool aBindFocusEvent=true)
ORIGIN_TRANSFORMS & m_originTransforms
A reference to an ORIGIN_TRANSFORMS object.
bool m_bindFocusEvent
The bound widgets.
long m_selStart
Selection start and end of the original text.
virtual double GetDoubleValue()
Return the current value in Internal Units.
double setPrecision(double aValue, bool aValueUsesUserUnits)
When m_precision > 0 truncate the value aValue to show only m_precision digits in mantissa.
bool IsIndeterminate() const
Return true if the control holds the indeterminate value (for instance, if it represents a multiple s...
void SetDataType(EDA_DATA_TYPE aDataType)
Used to override the datatype of the displayed property (default is DISTANCE)
void delayedFocusHandler(wxCommandEvent &aEvent)
virtual void SetAngleValue(const EDA_ANGLE &aValue)
void SetLabel(const wxString &aLabel)
void init(UNITS_PROVIDER *aProvider)
virtual void ChangeAngleValue(const EDA_ANGLE &aValue)
virtual void SetDoubleValue(double aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
virtual ~UNIT_BINDER() override
virtual bool Validate(double aMin, double aMax, EDA_UNITS aUnits=EDA_UNITS::UNSCALED)
Validate the control against the given range, informing the user of any errors found.
virtual void ChangeValue(int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion WITHOUT trigger...
virtual void SetValue(long long int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
void Show(bool aShow, bool aResize=false)
Show/hide the label, widget and units label.
void onUnitsChanged(wxCommandEvent &aEvent)
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
This file is part of the common library.
const int minSize
Push and Shove router track width and via size dialog.
EDA_DATA_TYPE
The type of unit.
KICOMMON_API double FromUserUnit(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnit, double aValue)
Return in internal units the value aValue given in a real unit such as "in", "mm",...
KICOMMON_API long long int ValueFromString(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, const wxString &aTextValue, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Function ValueFromString converts aTextValue in aUnits to internal units used by the application.
KICOMMON_API wxString StringFromValue(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, double aValue, bool aAddUnitsText=false, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Returns the string from aValue according to aUnits (inch, mm ...) for display.
KICOMMON_API double DoubleValueFromString(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, const wxString &aTextValue, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Function DoubleValueFromString converts aTextValue to a double.
KICOMMON_API double ToUserUnit(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnit, double aValue)
Function To_User_Unit convert aValue in internal units to the appropriate user units defined by aUnit...
KICOMMON_API wxString GetLabel(EDA_UNITS aUnits, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Get the units string for a given units type.
int GetUserUnits()
Return the currently selected user unit value for the interface.
#define INDETERMINATE_ACTION
#define INDETERMINATE_STATE
Used for holding indeterminate values, such as with multiple selections holding different values or c...
wxDEFINE_EVENT(DELAY_FOCUS, wxCommandEvent)
wxString valueDescriptionFromLabel(wxStaticText *aLabel)