tdf#94947 Set preset-id for user defined motion paths.
User defined motion paths ( curve, polygon, freeform line )
did not have preset-id. Set the preset-id so that the
preset type will be highlighted in the custom animation
pane after editing.
"libo-motionpath-curve", "libo-motionpath-polygon",
and "libo-motionpath-freeform-line" are used for the three
user defined motion paths.
This patch is related to tdf#94947, though it doesn't
make the original document display correctly by guessing
the missing preset-id, but it prevent empty preset-id
to be generated when creating those three motion path
animation.
Change-Id: I50c0133bea32e022b07e5d8c0a024810844f124d
Reviewed-on: https://gerrit.libreoffice.org/83079
Tested-by: Jenkins
Reviewed-by: Mark Hung <marklh9@gmail.com>
diff --git a/officecfg/registry/data/org/openoffice/Office/UI/Effects.xcu b/officecfg/registry/data/org/openoffice/Office/UI/Effects.xcu
index c635e03..1f385b6 100644
--- a/officecfg/registry/data/org/openoffice/Office/UI/Effects.xcu
+++ b/officecfg/registry/data/org/openoffice/Office/UI/Effects.xcu
@@ -700,6 +700,21 @@
<value xml:lang="en-US">Whip</value>
</prop>
</node>
<node oor:name="libo-motionpath-curve" oor:op="replace">
<prop oor:name="Label" oor:type="xs:string">
<value xml:lang="en-US">Curve</value>
</prop>
</node>
<node oor:name="libo-motionpath-polygon" oor:op="replace">
<prop oor:name="Label" oor:type="xs:string">
<value xml:lang="en-US">Polygon</value>
</prop>
</node>
<node oor:name="libo-motionpath-freeform-line" oor:op="replace">
<prop oor:name="Label" oor:type="xs:string">
<value xml:lang="en-US">Freeform Line</value>
</prop>
</node>
<node oor:name="ooo-motionpath-4-point-star" oor:op="replace">
<prop oor:name="Label" oor:type="xs:string">
<value xml:lang="en-US">4 Point Star</value>
diff --git a/sd/inc/CustomAnimationEffect.hxx b/sd/inc/CustomAnimationEffect.hxx
index cf2cfe7..962ce9b 100644
--- a/sd/inc/CustomAnimationEffect.hxx
+++ b/sd/inc/CustomAnimationEffect.hxx
@@ -71,7 +71,7 @@ public:
SAL_DLLPRIVATE const OUString& getProperty() const { return maProperty; }
SAL_DLLPRIVATE sal_Int16 getPresetClass() const { return mnPresetClass; }
SAL_DLLPRIVATE void setPresetClass( sal_Int16 nPresetClass );
SAL_DLLPRIVATE void setPresetClassAndId( sal_Int16 nPresetClass, const OUString& rPresetId );
SAL_DLLPRIVATE sal_Int16 getNodeType() const { return mnNodeType; }
void setNodeType( sal_Int16 nNodeType );
@@ -271,7 +271,7 @@ public:
SAL_DLLPRIVATE virtual css::uno::Reference< css::animations::XAnimationNode > getRootNode();
SAL_DLLPRIVATE CustomAnimationEffectPtr append( const CustomAnimationPresetPtr& pDescriptor, const css::uno::Any& rTarget, double fDuration );
SAL_DLLPRIVATE CustomAnimationEffectPtr append( const SdrPathObj& rPathObj, const css::uno::Any& rTarget, double fDuration );
SAL_DLLPRIVATE CustomAnimationEffectPtr append( const SdrPathObj& rPathObj, const css::uno::Any& rTarget, double fDuration, const OUString& rPresetId );
void append( const CustomAnimationEffectPtr& pEffect );
SAL_DLLPRIVATE void replace( const CustomAnimationEffectPtr& pEffect, const CustomAnimationPresetPtr& pDescriptor, double fDuration );
SAL_DLLPRIVATE void replace( const CustomAnimationEffectPtr& pEffect, const CustomAnimationPresetPtr& pDescriptor, const OUString& rPresetSubType, double fDuration );
diff --git a/sd/source/core/CustomAnimationEffect.cxx b/sd/source/core/CustomAnimationEffect.cxx
index f940e44..a4b1d64 100644
--- a/sd/source/core/CustomAnimationEffect.cxx
+++ b/sd/source/core/CustomAnimationEffect.cxx
@@ -397,12 +397,13 @@ sal_Int32 CustomAnimationEffect::get_node_type( const Reference< XAnimationNode
return nNodeType;
}
void CustomAnimationEffect::setPresetClass( sal_Int16 nPresetClass )
void CustomAnimationEffect::setPresetClassAndId( sal_Int16 nPresetClass, const OUString& rPresetId )
{
if( mnPresetClass == nPresetClass )
if( mnPresetClass == nPresetClass && maPresetId == rPresetId )
return;
mnPresetClass = nPresetClass;
maPresetId = rPresetId;
if( !mxNode.is() )
return;
@@ -410,7 +411,8 @@ void CustomAnimationEffect::setPresetClass( sal_Int16 nPresetClass )
// and change it
Sequence< NamedValue > aUserData( mxNode->getUserData() );
sal_Int32 nLength = aUserData.getLength();
bool bFound = false;
bool bFoundPresetClass = false;
bool bFoundPresetId = false;
if( nLength )
{
NamedValue* pProp = std::find_if(aUserData.begin(), aUserData.end(),
@@ -418,16 +420,32 @@ void CustomAnimationEffect::setPresetClass( sal_Int16 nPresetClass )
if (pProp != aUserData.end())
{
pProp->Value <<= mnPresetClass;
bFound = true;
bFoundPresetClass = true;
}
pProp = std::find_if(aUserData.begin(), aUserData.end(),
[](const NamedValue& rProp) { return rProp.Name == "preset-id"; });
if (pProp != aUserData.end())
{
pProp->Value <<= mnPresetClass;
bFoundPresetId = true;
}
}
// no "preset-class" entry inside user data, so add it
if( !bFound )
if( !bFoundPresetClass )
{
aUserData.realloc( nLength + 1);
aUserData[nLength].Name = "preset-class";
aUserData[nLength].Value <<= mnPresetClass;
++nLength;
}
if( !bFoundPresetId && maPresetId.getLength() > 0 )
{
aUserData.realloc( nLength + 1);
aUserData[nLength].Name = "preset-id";
aUserData[nLength].Value <<= maPresetId;
}
mxNode->setUserData( aUserData );
@@ -1687,7 +1705,7 @@ CustomAnimationEffectPtr EffectSequenceHelper::append( const CustomAnimationPres
return pEffect;
}
CustomAnimationEffectPtr EffectSequenceHelper::append( const SdrPathObj& rPathObj, const Any& rTarget, double fDuration /* = -1.0 */ )
CustomAnimationEffectPtr EffectSequenceHelper::append( const SdrPathObj& rPathObj, const Any& rTarget, double fDuration /* = -1.0 */, const OUString& rPresetId )
{
CustomAnimationEffectPtr pEffect;
@@ -1713,7 +1731,7 @@ CustomAnimationEffectPtr EffectSequenceHelper::append( const SdrPathObj& rPathOb
pEffect->setTarget( rTarget );
pEffect->setTargetSubItem( nSubItem );
pEffect->setNodeType( css::presentation::EffectNodeType::ON_CLICK );
pEffect->setPresetClass( css::presentation::EffectPresetClass::MOTIONPATH );
pEffect->setPresetClassAndId( css::presentation::EffectPresetClass::MOTIONPATH, rPresetId );
pEffect->setAcceleration( 0.5 );
pEffect->setDecelerate( 0.5 );
pEffect->setFill( AnimationFill::HOLD );
diff --git a/sd/source/core/EffectMigration.cxx b/sd/source/core/EffectMigration.cxx
index cac5a88..5bc0809 100644
--- a/sd/source/core/EffectMigration.cxx
+++ b/sd/source/core/EffectMigration.cxx
@@ -1281,7 +1281,7 @@ void EffectMigration::SetAnimationPath( SvxShape* pShape, SdrPathObj const * pPa
{
std::shared_ptr< sd::MainSequence > pMainSequence( pPage->getMainSequence() );
if( pMainSequence.get() )
CustomAnimationEffectPtr pCreated( pMainSequence->append( *pPathObj, makeAny( xShape ), -1.0 ) );
CustomAnimationEffectPtr pCreated( pMainSequence->append( *pPathObj, makeAny( xShape ), -1.0, "" ) );
}
}
}
diff --git a/sd/source/ui/animations/CustomAnimationPane.cxx b/sd/source/ui/animations/CustomAnimationPane.cxx
index c63e4d0..42b5055 100644
--- a/sd/source/ui/animations/CustomAnimationPane.cxx
+++ b/sd/source/ui/animations/CustomAnimationPane.cxx
@@ -637,6 +637,17 @@ void CustomAnimationPane::updateControls()
}
}
// If preset id is missing and category is motion path.
if (nAnimationPos < 0 && nCategoryPos == 3)
{
if (rsPresetId == "libo-motionpath-curve")
mpLBAnimation->SelectEntryPos(mnCurvePathPos);
else if (rsPresetId == "libo-motionpath-polygon")
mpLBAnimation->SelectEntryPos(mnPolygonPathPos);
else if (rsPresetId == "libo-motionpath-freeform-line")
mpLBAnimation->SelectEntryPos(mnFreeformPathPos);
}
sal_uInt16 nPos = 0xffff;
sal_Int16 nNodeType = pEffect->getNodeType();
diff --git a/sd/source/ui/func/fuconbez.cxx b/sd/source/ui/func/fuconbez.cxx
index 072d743f..7630ea0 100644
--- a/sd/source/ui/func/fuconbez.cxx
+++ b/sd/source/ui/func/fuconbez.cxx
@@ -242,9 +242,24 @@ bool FuConstructBezierPolygon::MouseButtonUp(const MouseEvent& rMEvt )
double fDuration = 0.0;
*pTarget++ >>= fDuration;
bool bFirst = true;
OUString sPresetId;
switch(nSlotId)
{
case SID_DRAW_BEZIER_NOFILL:
sPresetId = "libo-motionpath-curve";
break;
case SID_DRAW_POLYGON_NOFILL:
sPresetId = "libo-motionpath-polygon";
break;
case SID_DRAW_FREELINE_NOFILL:
sPresetId = "libo-motionpath-freeform-line";
break;
}
while( --nTCount )
{
CustomAnimationEffectPtr pCreated( pMainSequence->append( *pPathObj, *pTarget++, fDuration ) );
CustomAnimationEffectPtr pCreated( pMainSequence->append( *pPathObj, *pTarget++, fDuration, sPresetId) );
if( bFirst )
bFirst = false;
else