Kaydet (Commit) eb5f2df4 authored tarafından Muthu Subramanian's avatar Muthu Subramanian

n758565: Wrong master slide shape being used.

* Changed <ph> idx to OptValue.
* Duplicate code removal.
üst a3b8ddf3
...@@ -130,8 +130,8 @@ public: ...@@ -130,8 +130,8 @@ public:
void setHiddenMasterShape( sal_Bool bHiddenMasterShape ) { mbHiddenMasterShape = bHiddenMasterShape; } void setHiddenMasterShape( sal_Bool bHiddenMasterShape ) { mbHiddenMasterShape = bHiddenMasterShape; }
void setSubType( sal_Int32 nSubType ) { mnSubType = nSubType; } void setSubType( sal_Int32 nSubType ) { mnSubType = nSubType; }
sal_Int32 getSubType() const { return mnSubType; } sal_Int32 getSubType() const { return mnSubType; }
void setSubTypeIndex( sal_uInt32 nSubTypeIndex ) { mnSubTypeIndex = nSubTypeIndex; } void setSubTypeIndex( sal_Int32 nSubTypeIndex ) { moSubTypeIndex = nSubTypeIndex; }
sal_Int32 getSubTypeIndex() const { return mnSubTypeIndex; } const OptValue< sal_Int32 >& getSubTypeIndex() const { return moSubTypeIndex; }
// setDefaults has to be called if styles are imported (OfficeXML is not storing properties having the default value) // setDefaults has to be called if styles are imported (OfficeXML is not storing properties having the default value)
void setDefaults(); void setDefaults();
...@@ -232,7 +232,7 @@ protected: ...@@ -232,7 +232,7 @@ protected:
rtl::OUString msName; rtl::OUString msName;
rtl::OUString msId; rtl::OUString msId;
sal_Int32 mnSubType; // if this type is not zero, then the shape is a placeholder sal_Int32 mnSubType; // if this type is not zero, then the shape is a placeholder
sal_Int32 mnSubTypeIndex; OptValue< sal_Int32 > moSubTypeIndex;
ShapeStyleRefMap maShapeStyleRefs; ShapeStyleRefMap maShapeStyleRefs;
......
...@@ -219,6 +219,10 @@ public: ...@@ -219,6 +219,10 @@ public:
inline Type& use() { mbHasValue = true; return maValue; } inline Type& use() { mbHasValue = true; return maValue; }
inline OptValue& operator=( const Type& rValue ) { set( rValue ); return *this; } inline OptValue& operator=( const Type& rValue ) { set( rValue ); return *this; }
inline bool operator==( const OptValue& rValue ) const {
return ( ( mbHasValue == false && rValue.mbHasValue == false ) ||
( mbHasValue == rValue.mbHasValue && maValue == rValue.maValue ) );
}
inline void assignIfUsed( const OptValue& rValue ) { if( rValue.mbHasValue ) set( rValue.maValue ); } inline void assignIfUsed( const OptValue& rValue ) { if( rValue.mbHasValue ) set( rValue.maValue ); }
private: private:
......
...@@ -84,7 +84,6 @@ Shape::Shape( const sal_Char* pServiceName ) ...@@ -84,7 +84,6 @@ Shape::Shape( const sal_Char* pServiceName )
, mpCustomShapePropertiesPtr( new CustomShapeProperties ) , mpCustomShapePropertiesPtr( new CustomShapeProperties )
, mpMasterTextListStyle( new TextListStyle ) , mpMasterTextListStyle( new TextListStyle )
, mnSubType( 0 ) , mnSubType( 0 )
, mnSubTypeIndex( -1 )
, meFrameType( FRAMETYPE_GENERIC ) , meFrameType( FRAMETYPE_GENERIC )
, mnRotation( 0 ) , mnRotation( 0 )
, mbFlipH( false ) , mbFlipH( false )
...@@ -114,7 +113,7 @@ Shape::Shape( const ShapePtr& pSourceShape ) ...@@ -114,7 +113,7 @@ Shape::Shape( const ShapePtr& pSourceShape )
, msName( pSourceShape->msName ) , msName( pSourceShape->msName )
, msId( pSourceShape->msId ) , msId( pSourceShape->msId )
, mnSubType( pSourceShape->mnSubType ) , mnSubType( pSourceShape->mnSubType )
, mnSubTypeIndex( pSourceShape->mnSubTypeIndex ) , moSubTypeIndex( pSourceShape->moSubTypeIndex )
, maShapeStyleRefs( pSourceShape->maShapeStyleRefs ) , maShapeStyleRefs( pSourceShape->maShapeStyleRefs )
, maSize( pSourceShape->maSize ) , maSize( pSourceShape->maSize )
, maPosition( pSourceShape->maPosition ) , maPosition( pSourceShape->maPosition )
......
...@@ -63,51 +63,11 @@ PPTGraphicShapeContext::PPTGraphicShapeContext( ContextHandler& rParent, const S ...@@ -63,51 +63,11 @@ PPTGraphicShapeContext::PPTGraphicShapeContext( ContextHandler& rParent, const S
{ {
} }
static oox::drawingml::ShapePtr findPlaceholder( const sal_Int32 nMasterPlaceholder, std::vector< oox::drawingml::ShapePtr >& rShapes )
{
oox::drawingml::ShapePtr aShapePtr;
std::vector< oox::drawingml::ShapePtr >::reverse_iterator aRevIter( rShapes.rbegin() );
while( aRevIter != rShapes.rend() )
{
if ( (*aRevIter)->getSubType() == nMasterPlaceholder )
{
aShapePtr = *aRevIter;
break;
}
std::vector< oox::drawingml::ShapePtr >& rChildren = (*aRevIter)->getChildren();
aShapePtr = findPlaceholder( nMasterPlaceholder, rChildren );
if ( aShapePtr.get() )
break;
++aRevIter;
}
return aShapePtr;
}
static oox::drawingml::ShapePtr findPlaceholderByIndex( const sal_Int32 nIdx, std::vector< oox::drawingml::ShapePtr >& rShapes )
{
oox::drawingml::ShapePtr aShapePtr;
std::vector< oox::drawingml::ShapePtr >::reverse_iterator aRevIter( rShapes.rbegin() );
while( aRevIter != rShapes.rend() )
{
if ( (*aRevIter)->getSubTypeIndex() == nIdx )
{
aShapePtr = *aRevIter;
break;
}
std::vector< oox::drawingml::ShapePtr >& rChildren = (*aRevIter)->getChildren();
aShapePtr = findPlaceholderByIndex( nIdx, rChildren );
if ( aShapePtr.get() )
break;
++aRevIter;
}
return aShapePtr;
}
// if nFirstPlaceholder can't be found, it will be searched for nSecondPlaceholder // if nFirstPlaceholder can't be found, it will be searched for nSecondPlaceholder
static oox::drawingml::ShapePtr findPlaceholder( sal_Int32 nFirstPlaceholder, sal_Int32 nSecondPlaceholder, std::vector< oox::drawingml::ShapePtr >& rShapes ) static oox::drawingml::ShapePtr findPlaceholder( sal_Int32 nFirstPlaceholder, sal_Int32 nSecondPlaceholder, std::vector< oox::drawingml::ShapePtr >& rShapes )
{ {
oox::drawingml::ShapePtr pPlaceholder = findPlaceholder( nFirstPlaceholder, rShapes ); oox::drawingml::ShapePtr pPlaceholder = PPTShape::findPlaceholder( nFirstPlaceholder, rShapes );
return !nSecondPlaceholder || pPlaceholder.get() ? pPlaceholder : findPlaceholder( nSecondPlaceholder, rShapes ); return !nSecondPlaceholder || pPlaceholder.get() ? pPlaceholder : PPTShape::findPlaceholder( nSecondPlaceholder, rShapes );
} }
Reference< XFastContextHandler > PPTGraphicShapeContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException) Reference< XFastContextHandler > PPTGraphicShapeContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException)
...@@ -145,8 +105,8 @@ Reference< XFastContextHandler > PPTGraphicShapeContext::createFastChildContext( ...@@ -145,8 +105,8 @@ Reference< XFastContextHandler > PPTGraphicShapeContext::createFastChildContext(
{ {
// TODO: use id to shape map // TODO: use id to shape map
SlidePersistPtr pMasterPersist( mpSlidePersistPtr->getMasterPersist() ); SlidePersistPtr pMasterPersist( mpSlidePersistPtr->getMasterPersist() );
if ( pMasterPersist.get() ) if ( pMasterPersist.get() && xAttribs->hasAttribute( XML_idx ) )
pPlaceholder = findPlaceholderByIndex( nIdx, pMasterPersist->getShapes()->getChildren() ); pPlaceholder = PPTShape::findPlaceholderByIndex( nIdx, pMasterPersist->getShapes()->getChildren() );
} }
if ( !pPlaceholder.get() && ( ( eShapeLocation == Slide ) || ( eShapeLocation == Layout ) ) ) if ( !pPlaceholder.get() && ( ( eShapeLocation == Slide ) || ( eShapeLocation == Layout ) ) )
{ {
......
...@@ -262,10 +262,10 @@ void PPTShape::addShape( ...@@ -262,10 +262,10 @@ void PPTShape::addShape(
OSL_TRACE("shape service: %s", rtl::OUStringToOString(sServiceName, RTL_TEXTENCODING_UTF8 ).getStr()); OSL_TRACE("shape service: %s", rtl::OUStringToOString(sServiceName, RTL_TEXTENCODING_UTF8 ).getStr());
// use placeholder index if possible // use placeholder index if possible
if( mnSubType && getSubTypeIndex() && getSubTypeIndex() != -1 && rSlidePersist.getMasterPersist().get() ) { if( mnSubType && getSubTypeIndex().has() && rSlidePersist.getMasterPersist().get() ) {
oox::drawingml::ShapePtr pPlaceholder = PPTShape::findPlaceholderByIndex( getSubTypeIndex(), rSlidePersist.getMasterPersist()->getShapes()->getChildren() ); oox::drawingml::ShapePtr pPlaceholder = PPTShape::findPlaceholderByIndex( getSubTypeIndex().get(), rSlidePersist.getMasterPersist()->getShapes()->getChildren() );
if( pPlaceholder.get()) { if( pPlaceholder.get()) {
OSL_TRACE("found placeholder with index: %d and type: %s", getSubTypeIndex(), lclDebugSubType( mnSubType )); OSL_TRACE("found placeholder with index: %d and type: %s", getSubTypeIndex().get(), lclDebugSubType( mnSubType ));
} }
if( pPlaceholder.get() ) { if( pPlaceholder.get() ) {
PPTShape* pPPTPlaceholder = dynamic_cast< PPTShape* >( pPlaceholder.get() ); PPTShape* pPPTPlaceholder = dynamic_cast< PPTShape* >( pPlaceholder.get() );
...@@ -290,7 +290,7 @@ void PPTShape::addShape( ...@@ -290,7 +290,7 @@ void PPTShape::addShape(
OSL_TRACE("placeholder has parent placeholder: %s type: %s index: %d", OSL_TRACE("placeholder has parent placeholder: %s type: %s index: %d",
rtl::OUStringToOString( pPPTPlaceholder->mpPlaceholder->getId(), RTL_TEXTENCODING_UTF8 ).getStr(), rtl::OUStringToOString( pPPTPlaceholder->mpPlaceholder->getId(), RTL_TEXTENCODING_UTF8 ).getStr(),
lclDebugSubType( pPPTPlaceholder->mpPlaceholder->getSubType() ), lclDebugSubType( pPPTPlaceholder->mpPlaceholder->getSubType() ),
pPPTPlaceholder->mpPlaceholder->getSubTypeIndex() ); pPPTPlaceholder->mpPlaceholder->getSubTypeIndex().get() );
OSL_TRACE("has textbody %d", pPPTPlaceholder->mpPlaceholder->getTextBody() != NULL ); OSL_TRACE("has textbody %d", pPPTPlaceholder->mpPlaceholder->getTextBody() != NULL );
TextListStylePtr pPlaceholderStyle = getSubTypeTextListStyle( rSlidePersist, pPPTPlaceholder->mpPlaceholder->getSubType() ); TextListStylePtr pPlaceholderStyle = getSubTypeTextListStyle( rSlidePersist, pPPTPlaceholder->mpPlaceholder->getSubType() );
if( pPPTPlaceholder->mpPlaceholder->getTextBody() ) if( pPPTPlaceholder->mpPlaceholder->getTextBody() )
...@@ -403,13 +403,10 @@ oox::drawingml::ShapePtr PPTShape::findPlaceholderByIndex( const sal_Int32 nIdx, ...@@ -403,13 +403,10 @@ oox::drawingml::ShapePtr PPTShape::findPlaceholderByIndex( const sal_Int32 nIdx,
{ {
oox::drawingml::ShapePtr aShapePtr; oox::drawingml::ShapePtr aShapePtr;
if( nIdx == -1)
return aShapePtr;
std::vector< oox::drawingml::ShapePtr >::reverse_iterator aRevIter( rShapes.rbegin() ); std::vector< oox::drawingml::ShapePtr >::reverse_iterator aRevIter( rShapes.rbegin() );
while( aRevIter != rShapes.rend() ) while( aRevIter != rShapes.rend() )
{ {
if ( (*aRevIter)->getSubTypeIndex() == nIdx ) if ( (*aRevIter)->getSubTypeIndex().has() && (*aRevIter)->getSubTypeIndex().get() == nIdx )
{ {
aShapePtr = *aRevIter; aShapePtr = *aRevIter;
break; break;
......
...@@ -62,35 +62,40 @@ PPTShapeContext::PPTShapeContext( ContextHandler& rParent, const SlidePersistPtr ...@@ -62,35 +62,40 @@ PPTShapeContext::PPTShapeContext( ContextHandler& rParent, const SlidePersistPtr
{ {
} }
oox::drawingml::ShapePtr findPlaceholder( const sal_Int32 nMasterPlaceholder, sal_Int32 nSubTypeIndex, std::vector< oox::drawingml::ShapePtr >& rShapes ) oox::drawingml::ShapePtr findPlaceholder( const sal_Int32 nMasterPlaceholder, const OptValue< sal_Int32 >& oSubTypeIndex, std::vector< oox::drawingml::ShapePtr >& rShapes )
{ {
oox::drawingml::ShapePtr aShapePtr; oox::drawingml::ShapePtr aShapePtr;
oox::drawingml::ShapePtr aTmpShapePtr;
std::vector< oox::drawingml::ShapePtr >::reverse_iterator aRevIter( rShapes.rbegin() ); std::vector< oox::drawingml::ShapePtr >::reverse_iterator aRevIter( rShapes.rbegin() );
while( aRevIter != rShapes.rend() ) while( aRevIter != rShapes.rend() )
{ {
if ( (*aRevIter)->getSubType() == nMasterPlaceholder ) if ( (*aRevIter)->getSubType() == nMasterPlaceholder )
{ {
if ( ( nSubTypeIndex == -1 ) || ( nSubTypeIndex == (*aRevIter)->getSubTypeIndex() ) ) if( !oSubTypeIndex.has() && aTmpShapePtr == NULL )
aTmpShapePtr = *aRevIter;
if( (*aRevIter)->getSubTypeIndex() == oSubTypeIndex )
{ {
aShapePtr = *aRevIter; aShapePtr = *aRevIter;
break; break;
} }
} }
std::vector< oox::drawingml::ShapePtr >& rChildren = (*aRevIter)->getChildren(); std::vector< oox::drawingml::ShapePtr >& rChildren = (*aRevIter)->getChildren();
aShapePtr = findPlaceholder( nMasterPlaceholder, nSubTypeIndex, rChildren ); aShapePtr = findPlaceholder( nMasterPlaceholder, oSubTypeIndex, rChildren );
if ( aShapePtr.get() ) if ( aShapePtr.get() )
break; break;
++aRevIter; ++aRevIter;
} }
if( aShapePtr == NULL )
return aTmpShapePtr;
return aShapePtr; return aShapePtr;
} }
// if nFirstPlaceholder can't be found, it will be searched for nSecondPlaceholder // if nFirstPlaceholder can't be found, it will be searched for nSecondPlaceholder
oox::drawingml::ShapePtr findPlaceholder( sal_Int32 nFirstPlaceholder, sal_Int32 nSecondPlaceholder, oox::drawingml::ShapePtr findPlaceholder( sal_Int32 nFirstPlaceholder, sal_Int32 nSecondPlaceholder,
sal_Int32 nSubTypeIndex, std::vector< oox::drawingml::ShapePtr >& rShapes ) const OptValue< sal_Int32 >& oSubTypeIndex, std::vector< oox::drawingml::ShapePtr >& rShapes )
{ {
oox::drawingml::ShapePtr pPlaceholder = findPlaceholder( nFirstPlaceholder, nSubTypeIndex, rShapes ); oox::drawingml::ShapePtr pPlaceholder = findPlaceholder( nFirstPlaceholder, oSubTypeIndex, rShapes );
return !nSecondPlaceholder || pPlaceholder.get() ? pPlaceholder : findPlaceholder( nSecondPlaceholder, nSubTypeIndex, rShapes ); return !nSecondPlaceholder || pPlaceholder.get() ? pPlaceholder : findPlaceholder( nSecondPlaceholder, oSubTypeIndex, rShapes );
} }
Reference< XFastContextHandler > PPTShapeContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException) Reference< XFastContextHandler > PPTShapeContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException)
...@@ -168,7 +173,8 @@ Reference< XFastContextHandler > PPTShapeContext::createFastChildContext( sal_In ...@@ -168,7 +173,8 @@ Reference< XFastContextHandler > PPTShapeContext::createFastChildContext( sal_In
oox::drawingml::ShapePtr pPlaceholder; oox::drawingml::ShapePtr pPlaceholder;
if ( eShapeLocation == Layout ) // for layout objects the referenced object can be found within the same shape tree if ( eShapeLocation == Layout ) // for layout objects the referenced object can be found within the same shape tree
{ {
pPlaceholder = PPTShape::findPlaceholderByIndex( pPPTShapePtr->getSubTypeIndex(), mpSlidePersistPtr->getShapes()->getChildren() ); if( pPPTShapePtr->getSubTypeIndex().has() )
pPlaceholder = PPTShape::findPlaceholderByIndex( pPPTShapePtr->getSubTypeIndex().get(), mpSlidePersistPtr->getShapes()->getChildren() );
if ( !pPlaceholder.get() ) if ( !pPlaceholder.get() )
pPlaceholder = findPlaceholder( nFirstPlaceholder, nSecondPlaceholder, pPPTShapePtr->getSubTypeIndex(), pPlaceholder = findPlaceholder( nFirstPlaceholder, nSecondPlaceholder, pPPTShapePtr->getSubTypeIndex(),
mpSlidePersistPtr->getShapes()->getChildren() ); mpSlidePersistPtr->getShapes()->getChildren() );
...@@ -177,7 +183,8 @@ Reference< XFastContextHandler > PPTShapeContext::createFastChildContext( sal_In ...@@ -177,7 +183,8 @@ Reference< XFastContextHandler > PPTShapeContext::createFastChildContext( sal_In
{ {
SlidePersistPtr pMasterPersist( mpSlidePersistPtr->getMasterPersist() ); SlidePersistPtr pMasterPersist( mpSlidePersistPtr->getMasterPersist() );
if ( pMasterPersist.get() ) { if ( pMasterPersist.get() ) {
pPlaceholder = PPTShape::findPlaceholderByIndex( pPPTShapePtr->getSubTypeIndex(), pMasterPersist->getShapes()->getChildren() ); if( pPPTShapePtr->getSubTypeIndex().has() )
pPlaceholder = PPTShape::findPlaceholderByIndex( pPPTShapePtr->getSubTypeIndex().get(), pMasterPersist->getShapes()->getChildren() );
if ( !pPlaceholder.get() ) if ( !pPlaceholder.get() )
pPlaceholder = findPlaceholder( nFirstPlaceholder, nSecondPlaceholder, pPlaceholder = findPlaceholder( nFirstPlaceholder, nSecondPlaceholder,
pPPTShapePtr->getSubTypeIndex(), pMasterPersist->getShapes()->getChildren() ); pPPTShapePtr->getSubTypeIndex(), pMasterPersist->getShapes()->getChildren() );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment