wxWidgets 3.3 compatibility: properties API

This commit is contained in:
Jon Evans 2024-03-20 21:51:35 -04:00
parent 773d241863
commit e7b6573717
6 changed files with 176 additions and 8 deletions

View File

@ -76,7 +76,11 @@ wxPGWindowList PG_UNIT_EDITOR::CreateControls( wxPropertyGrid* aPropGrid, wxPGPr
{
wxASSERT( m_unitBinder );
#if wxCHECK_VERSION( 3, 3, 0 )
wxString text = aProperty->GetValueAsString( wxPGPropValFormatFlags::EditableValue );
#else
wxString text = aProperty->GetValueAsString( wxPG_EDITABLE_VALUE );
#endif
wxWindow* win = aPropGrid->GenerateEditorTextCtrl( aPos, aSize, text, nullptr, 0,
aProperty->GetMaxLength() );
wxPGWindowList ret( win, nullptr );

View File

@ -303,15 +303,25 @@ PGPROPERTY_DISTANCE::~PGPROPERTY_DISTANCE()
}
#if wxCHECK_VERSION( 3, 3, 0 )
bool PGPROPERTY_DISTANCE::StringToDistance( wxVariant& aVariant, const wxString& aText,
int aArgFlags ) const
wxPGPropValFormatFlags aFlags ) const
#else
bool PGPROPERTY_DISTANCE::StringToDistance( wxVariant& aVariant, const wxString& aText,
int aFlags ) const
#endif
{
// TODO(JE): Are there actual use cases for this?
wxCHECK_MSG( false, false, wxS( "PGPROPERTY_DISTANCE::StringToDistance should not be used." ) );
}
wxString PGPROPERTY_DISTANCE::DistanceToString( wxVariant& aVariant, int aArgFlags ) const
#if wxCHECK_VERSION( 3, 3, 0 )
wxString PGPROPERTY_DISTANCE::DistanceToString( wxVariant& aVariant,
wxPGPropValFormatFlags aFlags ) const
#else
wxString PGPROPERTY_DISTANCE::DistanceToString( wxVariant& aVariant, int aFlags ) const
#endif
{
long distanceIU;
@ -349,15 +359,25 @@ PGPROPERTY_AREA::PGPROPERTY_AREA( EDA_DRAW_FRAME* aParentFrame ) :
}
#if wxCHECK_VERSION( 3, 3, 0 )
bool PGPROPERTY_AREA::StringToValue( wxVariant& aVariant, const wxString& aText,
wxPGPropValFormatFlags aArgFlags ) const
#else
bool PGPROPERTY_AREA::StringToValue( wxVariant& aVariant, const wxString& aText,
int aArgFlags ) const
#endif
{
// TODO(JE): Are there actual use cases for this?
wxCHECK_MSG( false, false, wxS( "PGPROPERTY_AREA::StringToValue should not be used." ) );
}
#if wxCHECK_VERSION( 3, 3, 0 )
wxString PGPROPERTY_AREA::ValueToString( wxVariant& aVariant,
wxPGPropValFormatFlags aArgFlags ) const
#else
wxString PGPROPERTY_AREA::ValueToString( wxVariant& aVariant, int aArgFlags ) const
#endif
{
wxCHECK( aVariant.GetType() == wxPG_VARIANT_TYPE_LONGLONG, wxEmptyString );
@ -432,15 +452,25 @@ const wxPGEditor* PGPROPERTY_RATIO::DoGetEditorClass() const
}
#if wxCHECK_VERSION( 3, 3, 0 )
bool PGPROPERTY_RATIO::StringToValue( wxVariant& aVariant, const wxString& aText,
wxPGPropValFormatFlags aArgFlags ) const
#else
bool PGPROPERTY_RATIO::StringToValue( wxVariant& aVariant, const wxString& aText,
int aArgFlags ) const
#endif
{
// TODO(JE): Are there actual use cases for this?
wxCHECK_MSG( false, false, wxS( "PGPROPERTY_RATIO::StringToValue should not be used." ) );
}
#if wxCHECK_VERSION( 3, 3, 0 )
wxString PGPROPERTY_RATIO::ValueToString( wxVariant& aVariant,
wxPGPropValFormatFlags aArgFlags ) const
#else
wxString PGPROPERTY_RATIO::ValueToString( wxVariant& aVariant, int aArgFlags ) const
#endif
{
double value;
@ -490,7 +520,13 @@ wxValidator* PGPROPERTY_RATIO::DoGetValidator() const
}
bool PGPROPERTY_ANGLE::StringToValue( wxVariant& aVariant, const wxString& aText, int aArgFlags ) const
#if wxCHECK_VERSION( 3, 3, 0 )
bool PGPROPERTY_ANGLE::StringToValue( wxVariant& aVariant, const wxString& aText,
wxPGPropValFormatFlags aArgFlags ) const
#else
bool PGPROPERTY_ANGLE::StringToValue( wxVariant& aVariant, const wxString& aText,
int aArgFlags ) const
#endif
{
double value = 0.0;
@ -512,7 +548,12 @@ bool PGPROPERTY_ANGLE::StringToValue( wxVariant& aVariant, const wxString& aText
}
#if wxCHECK_VERSION( 3, 3, 0 )
wxString PGPROPERTY_ANGLE::ValueToString( wxVariant& aVariant,
wxPGPropValFormatFlags aArgFlags ) const
#else
wxString PGPROPERTY_ANGLE::ValueToString( wxVariant& aVariant, int aArgFlags ) const
#endif
{
if( aVariant.GetType() == wxPG_VARIANT_TYPE_DOUBLE )
{
@ -570,7 +611,12 @@ void PGPROPERTY_COLORENUM::OnCustomPaint( wxDC& aDC, const wxRect& aRect,
}
#if wxCHECK_VERSION( 3, 3, 0 )
wxString PGPROPERTY_STRING::ValueToString( wxVariant& aValue,
wxPGPropValFormatFlags aFlags ) const
#else
wxString PGPROPERTY_STRING::ValueToString( wxVariant& aValue, int aFlags ) const
#endif
{
if( aValue.GetType() != wxPG_VARIANT_TYPE_STRING )
return wxEmptyString;
@ -579,8 +625,13 @@ wxString PGPROPERTY_STRING::ValueToString( wxVariant& aValue, int aFlags ) const
}
#if wxCHECK_VERSION( 3, 3, 0 )
bool PGPROPERTY_STRING::StringToValue( wxVariant& aVariant, const wxString& aString,
wxPGPropValFormatFlags aArgFlags ) const
#else
bool PGPROPERTY_STRING::StringToValue( wxVariant& aVariant, const wxString& aString,
int aFlags ) const
#endif
{
aVariant = EscapeString( aString, CTX_QUOTED_STR );
return true;
@ -608,19 +659,33 @@ PGPROPERTY_COLOR4D::PGPROPERTY_COLOR4D( const wxString& aLabel, const wxString&
m_backgroundColor( aBackgroundColor )
{
SetEditor( PG_COLOR_EDITOR::EDITOR_NAME );
#if wxCHECK_VERSION( 3, 3, 0 )
SetFlag( wxPGPropertyFlags::NoEditor );
#else
SetFlag( wxPG_PROP_NOEDITOR );
#endif
}
#if wxCHECK_VERSION( 3, 3, 0 )
bool PGPROPERTY_COLOR4D::StringToValue( wxVariant& aVariant, const wxString& aString,
wxPGPropValFormatFlags aArgFlags ) const
#else
bool PGPROPERTY_COLOR4D::StringToValue( wxVariant& aVariant, const wxString& aString,
int aFlags ) const
#endif
{
aVariant.SetData( new COLOR4D_VARIANT_DATA( aString ) );
return true;
}
#if wxCHECK_VERSION( 3, 3, 0 )
wxString PGPROPERTY_COLOR4D::ValueToString( wxVariant& aValue,
wxPGPropValFormatFlags aFlags ) const
#else
wxString PGPROPERTY_COLOR4D::ValueToString( wxVariant& aValue, int aFlags ) const
#endif
{
wxString ret;

View File

@ -87,11 +87,11 @@ PROPERTIES_PANEL::PROPERTIES_PANEL( wxWindow* aParent, EDA_BASE_FRAME* aFrame )
#endif
#if wxCHECK_VERSION( 3, 3, 0 )
m_grid->AddActionTrigger( wxPGKeyboardActions::NextProperty, WXK_RETURN );
m_grid->AddActionTrigger( wxPGKeyboardActions::NextProperty, WXK_NUMPAD_ENTER );
m_grid->AddActionTrigger( wxPGKeyboardActions::NextProperty, WXK_DOWN );
m_grid->AddActionTrigger( wxPGKeyboardActions::PrevProperty, WXK_UP );
m_grid->AddActionTrigger( wxPGKeyboardActions::Edit, WXK_SPACE );
m_grid->AddActionTrigger( wxPGKeyboardAction::NextProperty, WXK_RETURN );
m_grid->AddActionTrigger( wxPGKeyboardAction::NextProperty, WXK_NUMPAD_ENTER );
m_grid->AddActionTrigger( wxPGKeyboardAction::NextProperty, WXK_DOWN );
m_grid->AddActionTrigger( wxPGKeyboardAction::PrevProperty, WXK_UP );
m_grid->AddActionTrigger( wxPGKeyboardAction::Edit, WXK_SPACE );
#else
m_grid->AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_RETURN );
m_grid->AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_NUMPAD_ENTER );

View File

@ -236,7 +236,12 @@ SIM_ENUM_PROPERTY::SIM_ENUM_PROPERTY( const wxString& aLabel, const wxString& aN
}
#if wxCHECK_VERSION( 3, 3, 0 )
bool SIM_ENUM_PROPERTY::IntToValue( wxVariant& aVariant, int aNumber,
wxPGPropValFormatFlags aArgFlags ) const
#else
bool SIM_ENUM_PROPERTY::IntToValue( wxVariant& aVariant, int aNumber, int aArgFlags ) const
#endif
{
if( m_disabled )
return false;

View File

@ -115,7 +115,12 @@ public:
SIM_ENUM_PROPERTY( const wxString& aLabel, const wxString& aName, SIM_MODEL& aModel,
int aParamIndex, const wxArrayString& aValues );
#if wxCHECK_VERSION( 3, 3, 0 )
bool IntToValue( wxVariant& aVariant, int aNumber,
wxPGPropValFormatFlags aArgFlags = wxPGPropValFormatFlags::Null ) const override;
#else
bool IntToValue( wxVariant& aVariant, int aNumber, int aArgFlags = 0 ) const override;
#endif
};
#endif // SIM_PROPERTY_H

View File

@ -48,8 +48,15 @@ public:
ORIGIN_TRANSFORMS::COORD_TYPES_T CoordType() const { return m_coordType; }
protected:
#if wxCHECK_VERSION( 3, 3, 0 )
bool StringToDistance( wxVariant& aVariant, const wxString& aText,
wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const;
wxString DistanceToString( wxVariant& aVariant,
wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const;
#else
bool StringToDistance( wxVariant& aVariant, const wxString& aText, int aArgFlags = 0 ) const;
wxString DistanceToString( wxVariant& aVariant, int aArgFlags = 0 ) const;
#endif
protected:
EDA_DRAW_FRAME* m_parentFrame;
@ -62,11 +69,21 @@ class PGPROPERTY_AREA : public wxIntProperty
public:
PGPROPERTY_AREA( EDA_DRAW_FRAME* aParentFrame );
virtual ~PGPROPERTY_AREA() = default;
protected:
#if wxCHECK_VERSION( 3, 3, 0 )
bool StringToValue( wxVariant& aVariant, const wxString& aText,
wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const override;
wxString ValueToString( wxVariant& aVariant,
wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const override;
#else
bool StringToValue( wxVariant& aVariant, const wxString& aText,
int aArgFlags = 0 ) const override;
wxString ValueToString( wxVariant& aVariant, int aArgFlags = 0 ) const override;
#endif
wxValidator* DoGetValidator() const override;
@ -80,6 +97,21 @@ class PGPROPERTY_SIZE : public wxUIntProperty, public PGPROPERTY_DISTANCE
public:
PGPROPERTY_SIZE( EDA_DRAW_FRAME* aParentFrame );
virtual ~PGPROPERTY_SIZE() = default;
#if wxCHECK_VERSION( 3, 3, 0 )
bool StringToValue( wxVariant& aVariant, const wxString& aText,
wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const override
{
return StringToDistance( aVariant, aText, aFlags );
}
wxString ValueToString( wxVariant& aVariant,
wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const override
{
return DistanceToString( aVariant, aFlags );
}
#else
bool StringToValue( wxVariant& aVariant, const wxString& aText,
int aArgFlags = 0 ) const override
{
@ -90,6 +122,7 @@ public:
{
return DistanceToString( aVariant, aArgFlags );
}
#endif
bool ValidateValue( wxVariant& aValue, wxPGValidationInfo& aValidationInfo ) const override;
@ -102,6 +135,21 @@ class PGPROPERTY_COORD : public wxIntProperty, public PGPROPERTY_DISTANCE
public:
PGPROPERTY_COORD( EDA_DRAW_FRAME* aParentFrame, ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType );
virtual ~PGPROPERTY_COORD() = default;
#if wxCHECK_VERSION( 3, 3, 0 )
bool StringToValue( wxVariant& aVariant, const wxString& aText,
wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const override
{
return StringToDistance( aVariant, aText, aFlags );
}
wxString ValueToString( wxVariant& aVariant,
wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const override
{
return DistanceToString( aVariant, aFlags );
}
#else
bool StringToValue( wxVariant& aVariant, const wxString& aText,
int aArgFlags = 0 ) const override
{
@ -112,6 +160,7 @@ public:
{
return DistanceToString( aVariant, aArgFlags );
}
#endif
wxValidator* DoGetValidator() const override;
};
@ -127,9 +176,19 @@ public:
{
}
virtual ~PGPROPERTY_ANGLE() = default;
#if wxCHECK_VERSION( 3, 3, 0 )
bool StringToValue( wxVariant& aVariant, const wxString& aText,
wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const override;
wxString ValueToString( wxVariant& aVariant,
wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const override;
#else
bool StringToValue( wxVariant& aVariant, const wxString& aText,
int aArgFlags = 0 ) const override;
wxString ValueToString( wxVariant& aVariant, int aArgFlags = 0 ) const override;
#endif
void SetScale( double aScale )
{
@ -155,9 +214,15 @@ public:
wxEnumProperty( wxPG_LABEL, wxPG_LABEL, *aChoices, 0 ),
m_colorFunc( []( int aDummy ) { return wxNullColour; } )
{
#if wxCHECK_VERSION( 3, 3, 0 )
SetFlag( wxPGPropertyFlags::CustomImage );
#else
SetFlag( wxPG_PROP_CUSTOMIMAGE );
#endif
}
virtual ~PGPROPERTY_COLORENUM() = default;
wxSize OnMeasureImage( int aItem = -1 ) const override;
void OnCustomPaint( wxDC& aDC, const wxRect& aRect, wxPGPaintData& aPaintData ) override;
@ -186,10 +251,18 @@ public:
virtual ~PGPROPERTY_RATIO() = default;
#if wxCHECK_VERSION( 3, 3, 0 )
bool StringToValue( wxVariant& aVariant, const wxString& aText,
wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const override;
wxString ValueToString( wxVariant& aVariant,
wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const override;
#else
bool StringToValue( wxVariant& aVariant, const wxString& aText,
int aArgFlags = 0 ) const override;
wxString ValueToString( wxVariant& aVariant, int aArgFlags = 0 ) const override;
#endif
bool ValidateValue( wxVariant& aValue, wxPGValidationInfo& aValidationInfo ) const override;
@ -206,10 +279,18 @@ public:
virtual ~PGPROPERTY_STRING() = default;
#if wxCHECK_VERSION( 3, 3, 0 )
bool StringToValue( wxVariant& aVariant, const wxString& aText,
wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const override;
wxString ValueToString( wxVariant& aVariant,
wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const override;
#else
wxString ValueToString( wxVariant& aValue, int aFlags = 0 ) const override;
bool StringToValue( wxVariant& aVariant, const wxString& aString,
int aFlags = 0 ) const override;
#endif
};
@ -234,10 +315,18 @@ public:
virtual ~PGPROPERTY_COLOR4D() = default;
#if wxCHECK_VERSION( 3, 3, 0 )
bool StringToValue( wxVariant& aVariant, const wxString& aText,
wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const override;
wxString ValueToString( wxVariant& aVariant,
wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const override;
#else
wxString ValueToString( wxVariant& aValue, int aFlags = 0 ) const override;
bool StringToValue( wxVariant &aVariant, const wxString &aText,
int aFlags = 0 ) const override;
#endif
void SetBackgroundColor( const KIGFX::COLOR4D& aColor ) { m_backgroundColor = aColor; }
const KIGFX::COLOR4D& GetBackgroundColor() const { return m_backgroundColor; }