22#include <wx/clipbrd.h>
23#include <wx/combobox.h>
24#include <wx/stattext.h>
25#include <wx/textentry.h>
32#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 ) :
54 m_iuScale( &aUnitsProvider->GetIuScale() ),
55 m_units( aUnitsProvider->GetUserUnits() ),
59 m_eval( aUnitsProvider->GetUserUnits() ),
74 while( parent && !
dynamic_cast<DIALOG_SHIM*
>( parent ) )
75 parent = parent->GetParent();
84 wxTextEntry* textEntry =
dynamic_cast<wxTextEntry*
>(
m_valueCtrl );
96 minWidth = dc.GetTextExtent( wxT(
"XXX.XXXXX" ) ).GetWidth();
102 minWidth = dc.GetTextExtent( wxT(
"XXX.XXXXXXXX" ) ).GetWidth();
105 if(
minSize.GetWidth() < minWidth )
110 textEntry->ChangeValue( wxT(
"-0" ) );
112 textEntry->ChangeValue( wxT(
"0" ) );
120 m_valueCtrl->Connect( wxEVT_DESTROY, wxWindowDestroyEventHandler( UNIT_BINDER::onValueCtrlDestroyed ),
122 m_valueCtrl->Connect( wxEVT_SET_FOCUS, wxFocusEventHandler( UNIT_BINDER::onSetFocus ), nullptr, this );
123 m_valueCtrl->Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( UNIT_BINDER::onKillFocus ), nullptr, this );
124 m_valueCtrl->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( UNIT_BINDER::onClick ), nullptr, this );
125 m_valueCtrl->Connect( wxEVT_COMBOBOX, wxCommandEventHandler( UNIT_BINDER::onComboBox ), nullptr, this );
200 wxComboBox*
const combo =
dynamic_cast<wxComboBox*
>(
m_valueCtrl );
201 std::vector<long long int> comboValues;
206 for(
unsigned int i = 0; i < combo->GetCount(); i++ )
208 const wxString value = combo->GetString( i );
210 comboValues.push_back( conv );
233 wxTextEntry* textEntry =
dynamic_cast<wxTextEntry*
>(
m_valueCtrl );
239 textEntry->SelectAll();
249 wxComboBox* combo =
dynamic_cast<wxComboBox*
>(
m_valueCtrl );
252 const wxString value = combo->GetStringSelection();
287 wxTextEntry* textEntry =
dynamic_cast<wxTextEntry*
>(
m_valueCtrl );
293 wxString oldStr =
m_eval.OriginalText();
295 if( oldStr.length() && oldStr != textEntry->GetValue() )
297 textEntry->ChangeValue( oldStr );
308 textEntry->SelectAll();
318 wxTextEntry* textEntry =
dynamic_cast<wxTextEntry*
>(
m_valueCtrl );
322 wxString value = textEntry->GetValue();
323 bool success =
m_eval.Process( value );
325 if( success && !value.IsEmpty() )
339 textEntry->ChangeValue( value );
343 if( wxTheClipboard->Open() )
345 wxString sel = textEntry->GetStringSelection();
346 bool clipTarget = wxTheClipboard->IsUsingPrimarySelection();
347 wxTheClipboard->UsePrimarySelection(
true );
348 wxTheClipboard->SetData(
new wxTextDataObject( sel ) );
349 wxTheClipboard->UsePrimarySelection( clipTarget );
350 wxTheClipboard->Close();
364 wxString desc = aLabel->GetLabel();
366 desc.EndsWith( wxT(
":" ), &desc );
395 default: conversions = 1;
break;
398 double boundIU = aBound;
400 for(
int i = 0; i < conversions; ++i )
401 boundIU =
FromUserUnit( aIuScale, aBoundUnits, boundIU );
407 StringFromValue( aIuScale, aDisplayUnits, boundIU, addUnitsText, aDataType ) };
413 wxTextEntry* textEntry =
dynamic_cast<wxTextEntry*
>(
m_valueCtrl );
432 textEntry->SelectAll();
435 wxPostEvent(
this, wxCommandEvent( DELAY_FOCUS ) );
446 textEntry->SelectAll();
449 wxPostEvent(
this, wxCommandEvent( DELAY_FOCUS ) );
476 if( displayValue == 0 && !std::signbit( displayValue ) &&
m_negativeZero )
491 wxTextEntry* textEntry =
dynamic_cast<wxTextEntry*
>(
m_valueCtrl );
492 wxStaticText* staticText =
dynamic_cast<wxStaticText*
>(
m_valueCtrl );
494 wxString value = aValue;
505 textEntry->SetValue( value );
506 else if( staticText )
507 staticText->SetLabel( value );
525 textValue = wxT(
"-" ) + textValue;
537 if( displayValue == 0 && !std::signbit( displayValue ) &&
m_negativeZero )
538 textValue = wxT(
"-" ) + textValue;
564 wxTextEntry* textEntry =
dynamic_cast<wxTextEntry*
>(
m_valueCtrl );
565 wxStaticText* staticText =
dynamic_cast<wxStaticText*
>(
m_valueCtrl );
567 wxString value = aValue;
578 textEntry->ChangeValue( value );
579 else if( staticText )
580 staticText->SetLabel( value );
592 wxTextEntry* textEntry =
dynamic_cast<wxTextEntry*
>(
m_valueCtrl );
593 wxStaticText* staticText =
dynamic_cast<wxStaticText*
>(
m_valueCtrl );
598 value = textEntry->GetValue();
603 value = textEntry->GetValue();
605 else if( staticText )
607 value = staticText->GetLabel();
624 int64_t tmp = aValue;
626 if( !aValueUsesUserUnits )
629 aValue =
static_cast<double>( tmp ) /
scale;
631 if( !aValueUsesUserUnits )
641 wxTextEntry* textEntry =
dynamic_cast<wxTextEntry*
>(
m_valueCtrl );
642 wxStaticText* staticText =
dynamic_cast<wxStaticText*
>(
m_valueCtrl );
647 value = textEntry->GetValue();
652 value = textEntry->GetValue();
654 else if( staticText )
656 value = staticText->GetLabel();
678 wxComboBox* cb =
dynamic_cast<wxComboBox*
>(
m_valueCtrl );
683 for(
long long int value : aOptions )
690 wxComboBox* cb =
dynamic_cast<wxComboBox*
>(
m_valueCtrl );
695 for(
double value : aOptions )
702 wxTextEntry* te =
dynamic_cast<wxTextEntry*
>(
m_valueCtrl );
713 if( wxTextEntry* te =
dynamic_cast<wxTextEntry*
>(
m_valueCtrl ) )
714 return te->GetValue().IsEmpty();
722 if( wxTextEntry* te =
dynamic_cast<wxTextEntry*
>(
m_valueCtrl ) )
723 return te->SetValue( wxEmptyString );
776 UNIT_BINDER( aParent, nullptr, nullptr, nullptr, true, false )
797 [&]( wxShowEvent& e )
constexpr EDA_IU_SCALE schIUScale
Dialog helper object to sit in the inheritance tree between wxDialog and any class written by wxFormB...
The base frame for deriving all KiCad main window classes.
The base class for create windows for drawing purpose.
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
double setPrecision(double aValue, bool aValueUsesUserUnits) const
When m_precision > 0 truncate the value aValue to show only m_precision digits in mantissa.
ORIGIN_TRANSFORMS::COORD_TYPES_T m_coordType
Type of coordinate for display origin transforms.
wxString getTextForValue(long long int aValue) const
virtual void ChangeDoubleValue(double aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion WITHOUT trigger...
void onKillFocus(wxFocusEvent &aEvent)
void Enable(bool aEnable)
Enable/disable the label, widget and units label.
void onClick(wxMouseEvent &aEvent)
DIALOG_SHIM * m_dialogShim
The dialog this binder registered itself with, or nullptr if it isn't owned by a dialog.
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...
virtual double GetDoubleValue() const
Return the current value in Internal Units.
wxString getTextForDoubleValue(double aValue) const
const EDA_IU_SCALE * m_iuScale
Currently used units.
virtual EDA_ANGLE GetAngleValue()
bool m_negativeZero
Indicates "-0" should be displayed for 0.
virtual long long int GetValue() const
Return the current value in Internal Units.
static RANGE_BOUND ConvertRangeBound(const EDA_IU_SCALE &aIuScale, EDA_UNITS aBoundUnits, double aBound, EDA_UNITS aDisplayUnits, EDA_DATA_TYPE aDataType)
Convert a range bound and format its display string honoring aDataType.
wxStaticText * m_unitLabel
Can be nullptr.
bool m_unitsInValue
Units label should be included in value text.
void onSetFocus(wxFocusEvent &aEvent)
void onComboBox(wxCommandEvent &aEvent)
UNIT_BINDER(EDA_DRAW_FRAME *aParent, wxStaticText *aLabel, wxWindow *aValueCtrl, wxStaticText *aUnitLabel, bool aAllowEval=true, bool aBindFocusEvent=true)
wxStaticText * m_label
The bound widgets.
ORIGIN_TRANSFORMS & m_originTransforms
A reference to an ORIGIN_TRANSFORMS object.
long m_selStart
Selection start and end of the original text.
virtual void SetDoubleOptionsList(std::span< const double > aOptions)
void onValueCtrlDestroyed(wxWindowDestroyEvent &aEvent)
virtual void SetOptionsList(std::span< const long long int > aOptions)
Set the list of options for a combobox control.
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)
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
bool UnitsInvariant() const
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.
bool IsNull() const
Return true if the control holds no value (ie: empty string, not 0).
void onUnitsChanged(wxCommandEvent &aEvent)
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message 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)
Convert 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)
Return 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)
Convert aTextValue to a double.
KICOMMON_API double ToUserUnit(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnit, double aValue)
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.
A range bound converted to internal units together with its user-facing display string.
#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)