75 const wxPoint& aPos,
const wxSize& aSize )
const
79#if wxCHECK_VERSION( 3, 3, 0 )
80 wxString
text = aProperty->GetValueAsString( wxPGPropValFormatFlags::EditableValue );
82 wxString
text = aProperty->GetValueAsString( wxPG_EDITABLE_VALUE );
84 wxWindow* win = aPropGrid->GenerateEditorTextCtrl( aPos, aSize,
text,
nullptr, 0,
85 aProperty->GetMaxLength() );
86 wxPGWindowList ret( win,
nullptr );
118 wxVariant var = aProperty->GetValue();
120 if( var.GetType() == wxT(
"std::optional<int>" ) )
124 if( variantData->Value().has_value() )
125 m_unitBinder->ChangeValue( variantData->Value().value() );
129 else if( var.GetType() == wxPG_VARIANT_TYPE_LONG )
133 else if( var.GetType() == wxPG_VARIANT_TYPE_LONGLONG )
135 m_unitBinder->ChangeDoubleValue( var.GetLongLong().ToDouble() );
137 else if( var.GetType() == wxPG_VARIANT_TYPE_DOUBLE )
141 else if( var.GetType() == wxT(
"EDA_ANGLE" ) )
146 else if( !aProperty->IsValueUnspecified() )
148 wxFAIL_MSG( wxT(
"PG_UNIT_EDITOR should only be used with numeric properties!" ) );
154 wxWindow* aCtrl, wxEvent& aEvent )
const
156 if( aEvent.GetEventType() == wxEVT_LEFT_UP )
158 if( wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>( aCtrl ) )
160 if( !textCtrl->HasFocus() )
162 textCtrl->SelectAll();
168 return wxPGTextCtrlEditor::OnEvent( aPropGrid, aProperty, aCtrl, aEvent );
173 wxWindow* aCtrl )
const
178 wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>( aCtrl );
179 wxCHECK_MSG( textCtrl,
false,
"PG_UNIT_EDITOR requires a text control!" );
180 wxString textVal = textCtrl->GetValue();
182 if( textVal == wxT(
"<...>" ) )
194 if( aVariant.GetType() == wxT(
"EDA_ANGLE" ) )
197 changed = ( aVariant.IsNull() || angle != ad->
Angle() );
207 changed = ( aVariant.IsNull() || angle.
AsDegrees() != aVariant.GetDouble() );
219 changed = ( aVariant.IsNull() || result != aVariant.GetLongLong() );
227 else if( aVariant.GetType() == wxT(
"std::optional<int>" ) )
230 std::optional<int> result;
234 changed = ( aVariant.IsNull() || variantData->Value().has_value() );
238 aVariant = wxVariant( std::optional<int>() );
244 result = std::optional<int>(
m_unitBinder->GetValue() );
245 changed = ( aVariant.IsNull() || result != variantData->Value() );
249 aVariant = wxVariant( result );
257 changed = ( aVariant.IsNull() || result != aVariant.GetLong() );
268 if( !changed && aVariant.IsNull() )
282 const wxPoint& aPos,
const wxSize& aSize )
const
287 if( aProperty->IsValueUnspecified() )
288 aProperty->SetValueFromInt( 0 );
290 return wxPGCheckBoxEditor::CreateControls( aGrid, aProperty, aPos, aSize );
295 wxEvent& aEvent )
const
302 const wxPoint& aPos,
const wxSize& aSize )
const
313 colorProp->GetBackgroundColor(), defColor,
315 editor->SetPosition( aPos );
318 editor->Bind( COLOR_SWATCH_CHANGED,
319 [=]( wxCommandEvent& aEvt )
324 aGrid->ChangePropertyValue( colorProp, val );
327#if wxCHECK_VERSION( 3, 3, 0 )
328 if( aGrid->GetInternalFlags() & wxPropertyGrid::wxPG_FL_ACTIVATION_BY_CLICK )
330 if( aGrid->GetInternalFlags() & wxPG_FL_ACTIVATION_BY_CLICK )
336 editor->GetNewSwatchColor();
346 if(
auto swatch =
dynamic_cast<COLOR_SWATCH*
>( aCtrl ) )
356 if( aVariant.IsType( wxS(
"COLOR4D" ) ) )
373 wxWindow* aCtrl )
const
375 wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>( aCtrl );
376 wxCHECK_MSG( textCtrl,
false,
"PG_RATIO_EDITOR requires a text control!" );
377 wxString textVal = textCtrl->GetValue();
379 if( textVal == wxT(
"<...>" ) )
387 if( aVariant.GetType() == wxT(
"std::optional<double>" ) )
391 if( textVal.empty() )
393 changed = ( aVariant.IsNull() || variantData->Value().has_value() );
396 aVariant = wxVariant( std::optional<double>() );
401 textVal.ToDouble( &dblValue );
402 std::optional<double> result( dblValue );
403 changed = ( aVariant.IsNull() || result != variantData->Value() );
407 aVariant = wxVariant( result );
408 textCtrl->SetValue( wxString::Format( wxS(
"%g" ), dblValue ) );
415 textVal.ToDouble( &result );
416 changed = ( aVariant.IsNull() || result != aVariant.GetDouble() );
421 textCtrl->SetValue( wxString::Format( wxS(
"%g" ), result ) );
427 if( !changed && aVariant.IsNull() )
436 wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>( aCtrl );
437 wxVariant var = aProperty->GetValue();
439 wxCHECK_MSG( textCtrl, , wxT(
"PG_RATIO_EDITOR must be used with a textCtrl!" ) );
441 if( var.GetType() == wxT(
"std::optional<double>" ) )
446 if( variantData->Value().has_value() )
447 strValue = wxString::Format( wxS(
"%g" ), variantData->Value().value() );
451 else if( var.GetType() == wxPG_VARIANT_TYPE_DOUBLE )
453 textCtrl->ChangeValue( wxString::Format( wxS(
"%g" ), var.GetDouble() ) );
455 else if( !aProperty->IsValueUnspecified() )
457 wxFAIL_MSG( wxT(
"PG_RATIO_EDITOR should only be used with scale-free numeric "
const KIGFX::COLOR4D & Color()
A simple color swatch of the kind used to set layer colors.
const EDA_ANGLE & Angle()
void SetAngle(const EDA_ANGLE &aAngle)
The base class for create windows for drawing purpose.
A color representation with 4 components: red, green, blue, alpha.
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
A wxEnumProperty that displays a color next to the enum value.
wxPGWindowList CreateControls(wxPropertyGrid *aGrid, wxPGProperty *aProperty, const wxPoint &aPos, const wxSize &aSize) const override
static const wxString EDITOR_NAME
static const wxString EDITOR_NAME
wxPGWindowList CreateControls(wxPropertyGrid *aGrid, wxPGProperty *aProperty, const wxPoint &aPos, const wxSize &aSize) const override
bool OnEvent(wxPropertyGrid *aGrid, wxPGProperty *aProperty, wxWindow *aWindow, wxEvent &aEvent) const override
KIGFX::COLOR4D colorFromVariant(const wxVariant &aVariant) const
void UpdateControl(wxPGProperty *aProperty, wxWindow *aCtrl) const override
KIGFX::COLOR4D colorFromProperty(wxPGProperty *aProperty) const
bool GetValueFromControl(wxVariant &aVariant, wxPGProperty *aProperty, wxWindow *aCtrl) const override
static const wxString EDITOR_NAME
void UpdateControl(wxPGProperty *aProperty, wxWindow *aCtrl) const override
std::unique_ptr< PROPERTY_EDITOR_UNIT_BINDER > m_unitBinder
wxPGWindowList CreateControls(wxPropertyGrid *aPropGrid, wxPGProperty *aProperty, const wxPoint &aPos, const wxSize &aSize) const override
static const wxString EDITOR_NAME
void UpdateControl(wxPGProperty *aProperty, wxWindow *aCtrl) const override
void UpdateFrame(EDA_DRAW_FRAME *aFrame)
When restarting an editor, the instance of PG_UNIT_EDITOR may be the same but the referenced frame is...
PG_UNIT_EDITOR(EDA_DRAW_FRAME *aFrame)
bool GetValueFromControl(wxVariant &aVariant, wxPGProperty *aProperty, wxWindow *aCtrl) const override
bool OnEvent(wxPropertyGrid *aPropGrid, wxPGProperty *aProperty, wxWindow *aCtrl, wxEvent &aEvent) const override
static wxString BuildEditorName(EDA_DRAW_FRAME *aFrame)
virtual ~PG_UNIT_EDITOR()
EDA_UNITS GetUserUnits() const
static std::string strValue(double aValue)