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:
void setHiddenMasterShape( sal_Bool bHiddenMasterShape ) { mbHiddenMasterShape = bHiddenMasterShape; }
void setSubType( sal_Int32 nSubType ) { mnSubType = nSubType; }
sal_Int32 getSubType() const { return mnSubType; }
void setSubTypeIndex( sal_uInt32 nSubTypeIndex ) { mnSubTypeIndex = nSubTypeIndex; }
sal_Int32 getSubTypeIndex() const { return mnSubTypeIndex; }
void setSubTypeIndex( sal_Int32 nSubTypeIndex ) { moSubTypeIndex = nSubTypeIndex; }
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)
void setDefaults();
......@@ -232,7 +232,7 @@ protected:
rtl::OUString msName;
rtl::OUString msId;
sal_Int32 mnSubType; // if this type is not zero, then the shape is a placeholder
sal_Int32 mnSubTypeIndex;
OptValue< sal_Int32 > moSubTypeIndex;
ShapeStyleRefMap maShapeStyleRefs;
......
......@@ -219,6 +219,10 @@ public:
inline Type& use() { mbHasValue = true; return maValue; }
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 ); }
private:
......
......@@ -84,7 +84,6 @@ Shape::Shape( const sal_Char* pServiceName )
, mpCustomShapePropertiesPtr( new CustomShapeProperties )
, mpMasterTextListStyle( new TextListStyle )
, mnSubType( 0 )
, mnSubTypeIndex( -1 )
, meFrameType( FRAMETYPE_GENERIC )
, mnRotation( 0 )
, mbFlipH( false )
......@@ -114,7 +113,7 @@ Shape::Shape( const ShapePtr& pSourceShape )
, msName( pSourceShape->msName )
, msId( pSourceShape->msId )
, mnSubType( pSourceShape->mnSubType )
, mnSubTypeIndex( pSourceShape->mnSubTypeIndex )
, moSubTypeIndex( pSourceShape->moSubTypeIndex )
, maShapeStyleRefs( pSourceShape->maShapeStyleRefs )
, maSize( pSourceShape->maSize )
, maPosition( pSourceShape->maPosition )
......
......@@ -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
static oox::drawingml::ShapePtr findPlaceholder( sal_Int32 nFirstPlaceholder, sal_Int32 nSecondPlaceholder, std::vector< oox::drawingml::ShapePtr >& rShapes )
{
oox::drawingml::ShapePtr pPlaceholder = findPlaceholder( nFirstPlaceholder, rShapes );
return !nSecondPlaceholder || pPlaceholder.get() ? pPlaceholder : findPlaceholder( nSecondPlaceholder, rShapes );
oox::drawingml::ShapePtr pPlaceholder = PPTShape::findPlaceholder( nFirstPlaceholder, rShapes );
return !nSecondPlaceholder || pPlaceholder.get() ? pPlaceholder : PPTShape::findPlaceholder( nSecondPlaceholder, rShapes );
}
Reference< XFastContextHandler > PPTGraphicShapeContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException)
......@@ -145,8 +105,8 @@ Reference< XFastContextHandler > PPTGraphicShapeContext::createFastChildContext(
{
// TODO: use id to shape map
SlidePersistPtr pMasterPersist( mpSlidePersistPtr->getMasterPersist() );
if ( pMasterPersist.get() )
pPlaceholder = findPlaceholderByIndex( nIdx, pMasterPersist->getShapes()->getChildren() );
if ( pMasterPersist.get() && xAttribs->hasAttribute( XML_idx ) )
pPlaceholder = PPTShape::findPlaceholderByIndex( nIdx, pMasterPersist->getShapes()->getChildren() );
}
if ( !pPlaceholder.get() && ( ( eShapeLocation == Slide ) || ( eShapeLocation == Layout ) ) )
{
......
......@@ -262,10 +262,10 @@ void PPTShape::addShape(
OSL_TRACE("shape service: %s", rtl::OUStringToOString(sServiceName, RTL_TEXTENCODING_UTF8 ).getStr());
// use placeholder index if possible
if( mnSubType && getSubTypeIndex() && getSubTypeIndex() != -1 && rSlidePersist.getMasterPersist().get() ) {
oox::drawingml::ShapePtr pPlaceholder = PPTShape::findPlaceholderByIndex( getSubTypeIndex(), rSlidePersist.getMasterPersist()->getShapes()->getChildren() );
if( mnSubType && getSubTypeIndex().has() && rSlidePersist.getMasterPersist().get() ) {
oox::drawingml::ShapePtr pPlaceholder = PPTShape::findPlaceholderByIndex( getSubTypeIndex().get(), rSlidePersist.getMasterPersist()->getShapes()->getChildren() );
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() ) {
PPTShape* pPPTPlaceholder = dynamic_cast< PPTShape* >( pPlaceholder.get() );
......@@ -290,7 +290,7 @@ void PPTShape::addShape(
OSL_TRACE("placeholder has parent placeholder: %s type: %s index: %d",
rtl::OUStringToOString( pPPTPlaceholder->mpPlaceholder->getId(), RTL_TEXTENCODING_UTF8 ).getStr(),
lclDebugSubType( pPPTPlaceholder->mpPlaceholder->getSubType() ),
pPPTPlaceholder->mpPlaceholder->getSubTypeIndex() );
pPPTPlaceholder->mpPlaceholder->getSubTypeIndex().get() );
OSL_TRACE("has textbody %d", pPPTPlaceholder->mpPlaceholder->getTextBody() != NULL );
TextListStylePtr pPlaceholderStyle = getSubTypeTextListStyle( rSlidePersist, pPPTPlaceholder->mpPlaceholder->getSubType() );
if( pPPTPlaceholder->mpPlaceholder->getTextBody() )
......@@ -403,13 +403,10 @@ oox::drawingml::ShapePtr PPTShape::findPlaceholderByIndex( const sal_Int32 nIdx,
{
oox::drawingml::ShapePtr aShapePtr;
if( nIdx == -1)
return aShapePtr;
std::vector< oox::drawingml::ShapePtr >::reverse_iterator aRevIter( rShapes.rbegin() );
while( aRevIter != rShapes.rend() )
{
if ( (*aRevIter)->getSubTypeIndex() == nIdx )
if ( (*aRevIter)->getSubTypeIndex().has() && (*aRevIter)->getSubTypeIndex().get() == nIdx )
{
aShapePtr = *aRevIter;
break;
......
......@@ -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 aTmpShapePtr;
std::vector< oox::drawingml::ShapePtr >::reverse_iterator aRevIter( rShapes.rbegin() );
while( aRevIter != rShapes.rend() )
{
if ( (*aRevIter)->getSubType() == nMasterPlaceholder )
{
if ( ( nSubTypeIndex == -1 ) || ( nSubTypeIndex == (*aRevIter)->getSubTypeIndex() ) )
if( !oSubTypeIndex.has() && aTmpShapePtr == NULL )
aTmpShapePtr = *aRevIter;
if( (*aRevIter)->getSubTypeIndex() == oSubTypeIndex )
{
aShapePtr = *aRevIter;
break;
}
}
std::vector< oox::drawingml::ShapePtr >& rChildren = (*aRevIter)->getChildren();
aShapePtr = findPlaceholder( nMasterPlaceholder, nSubTypeIndex, rChildren );
aShapePtr = findPlaceholder( nMasterPlaceholder, oSubTypeIndex, rChildren );
if ( aShapePtr.get() )
break;
++aRevIter;
}
if( aShapePtr == NULL )
return aTmpShapePtr;
return aShapePtr;
}
// if nFirstPlaceholder can't be found, it will be searched for 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 );
return !nSecondPlaceholder || pPlaceholder.get() ? pPlaceholder : findPlaceholder( nSecondPlaceholder, nSubTypeIndex, rShapes );
oox::drawingml::ShapePtr pPlaceholder = findPlaceholder( nFirstPlaceholder, oSubTypeIndex, rShapes );
return !nSecondPlaceholder || pPlaceholder.get() ? pPlaceholder : findPlaceholder( nSecondPlaceholder, oSubTypeIndex, rShapes );
}
Reference< XFastContextHandler > PPTShapeContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException)
......@@ -168,7 +173,8 @@ Reference< XFastContextHandler > PPTShapeContext::createFastChildContext( sal_In
oox::drawingml::ShapePtr pPlaceholder;
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() )
pPlaceholder = findPlaceholder( nFirstPlaceholder, nSecondPlaceholder, pPPTShapePtr->getSubTypeIndex(),
mpSlidePersistPtr->getShapes()->getChildren() );
......@@ -177,7 +183,8 @@ Reference< XFastContextHandler > PPTShapeContext::createFastChildContext( sal_In
{
SlidePersistPtr pMasterPersist( mpSlidePersistPtr->getMasterPersist() );
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() )
pPlaceholder = findPlaceholder( nFirstPlaceholder, nSecondPlaceholder,
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