Kaydet (Commit) 4a0e2d6d authored tarafından Cédric Bosdonnat's avatar Cédric Bosdonnat

n#747471, n#693238: Textboxes import is a mess with OLE objects inside

üst d0644be5
...@@ -191,8 +191,6 @@ DomainMapper_Impl::DomainMapper_Impl( ...@@ -191,8 +191,6 @@ DomainMapper_Impl::DomainMapper_Impl(
m_bIsFirstSection( true ), m_bIsFirstSection( true ),
m_bIsColumnBreakDeferred( false ), m_bIsColumnBreakDeferred( false ),
m_bIsPageBreakDeferred( false ), m_bIsPageBreakDeferred( false ),
m_bIsInShape( false ),
m_bShapeContextAdded( false ),
m_pLastSectionContext( ), m_pLastSectionContext( ),
m_nCurrentTabStopIndex( 0 ), m_nCurrentTabStopIndex( 0 ),
m_sCurrentParaStyleId(), m_sCurrentParaStyleId(),
...@@ -584,37 +582,6 @@ void DomainMapper_Impl::clearDeferredBreaks() ...@@ -584,37 +582,6 @@ void DomainMapper_Impl::clearDeferredBreaks()
m_bIsPageBreakDeferred = false; m_bIsPageBreakDeferred = false;
} }
bool lcl_removeShape( const uno::Reference< text::XTextDocument >& rDoc, const uno::Reference< drawing::XShape >& rShape, TextContentStack& rAnchoredStack,TextAppendStack& rTextAppendStack )
{
bool bRet = false;
// probably unecessary but just double check that indeed the top of Anchored stack
// does contain the shape we intend to remove
uno::Reference< drawing::XShape > xAnchorShape(rAnchoredStack.top( ), uno::UNO_QUERY );
if ( xAnchorShape == rShape )
{
// because we only want to process the embedded object and not the associated
// shape we need to get rid of that shape from the Draw page and Anchored and
// Append stacks so it wont be processed further
try
{
uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(rDoc, uno::UNO_QUERY_THROW);
uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage();
if ( xDrawPage.is() )
{
xDrawPage->remove( rShape );
}
rAnchoredStack.pop();
rTextAppendStack.pop();
bRet = true;
}
catch( uno::Exception& )
{
}
}
return bRet;
}
void lcl_MoveBorderPropertiesToFrame(uno::Sequence<beans::PropertyValue>& rFrameProperties, void lcl_MoveBorderPropertiesToFrame(uno::Sequence<beans::PropertyValue>& rFrameProperties,
uno::Reference<text::XTextRange> xStartTextRange, uno::Reference<text::XTextRange> xStartTextRange,
...@@ -1049,21 +1016,6 @@ void DomainMapper_Impl::finishParagraph( PropertyMapPtr pPropertyMap ) ...@@ -1049,21 +1016,6 @@ void DomainMapper_Impl::finishParagraph( PropertyMapPtr pPropertyMap )
xTextAppend->finishParagraph( aProperties ); xTextAppend->finishParagraph( aProperties );
getTableManager( ).handle(xTextRange); getTableManager( ).handle(xTextRange);
// Set the anchor of the objects to the created paragraph
while ( m_aAnchoredStack.size( ) > 0 && !m_bIsInShape )
{
uno::Reference< text::XTextContent > xObj = m_aAnchoredStack.top( );
try
{
xObj->attach( xTextRange );
}
catch ( uno::RuntimeException& )
{
// this is normal: the shape is already attached
}
m_aAnchoredStack.pop( );
}
// Get the end of paragraph character inserted // Get the end of paragraph character inserted
uno::Reference< text::XTextCursor > xCur = xTextRange->getText( )->createTextCursor( ); uno::Reference< text::XTextCursor > xCur = xTextRange->getText( )->createTextCursor( );
xCur->gotoEnd( false ); xCur->gotoEnd( false );
...@@ -1202,11 +1154,9 @@ void DomainMapper_Impl::appendOLE( const ::rtl::OUString& rStreamName, OLEHandle ...@@ -1202,11 +1154,9 @@ void DomainMapper_Impl::appendOLE( const ::rtl::OUString& rStreamName, OLEHandle
// gives a better ( visually ) result // gives a better ( visually ) result
xOLEProperties->setPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_ANCHOR_TYPE ), uno::makeAny( text::TextContentAnchorType_AS_CHARACTER ) ); xOLEProperties->setPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_ANCHOR_TYPE ), uno::makeAny( text::TextContentAnchorType_AS_CHARACTER ) );
// remove ( if valid ) associated shape ( used for graphic replacement ) // remove ( if valid ) associated shape ( used for graphic replacement )
if ( m_bShapeContextAdded ) m_aAnchoredStack.top( ).bToRemove = true;
{ RemoveLastParagraph();
if ( lcl_removeShape( m_xTextDocument, pOLEHandler->getShape(), m_aAnchoredStack, m_aTextAppendStack ) ) m_aTextAppendStack.pop();
m_bShapeContextAdded = false; // ensure PopShapeContext processing doesn't pop the append stack
}
// //
appendTextContent( xOLE, uno::Sequence< beans::PropertyValue >() ); appendTextContent( xOLE, uno::Sequence< beans::PropertyValue >() );
...@@ -1543,12 +1493,10 @@ void DomainMapper_Impl::PushShapeContext( const uno::Reference< drawing::XShape ...@@ -1543,12 +1493,10 @@ void DomainMapper_Impl::PushShapeContext( const uno::Reference< drawing::XShape
if (m_aTextAppendStack.empty()) if (m_aTextAppendStack.empty())
return; return;
uno::Reference<text::XTextAppend> xTextAppend = m_aTextAppendStack.top().xTextAppend; uno::Reference<text::XTextAppend> xTextAppend = m_aTextAppendStack.top().xTextAppend;
m_bIsInShape = true;
try try
{ {
// Add the shape to the text append stack // Add the shape to the text append stack
m_aTextAppendStack.push( uno::Reference< text::XTextAppend >( xShape, uno::UNO_QUERY_THROW ) ); m_aTextAppendStack.push( uno::Reference< text::XTextAppend >( xShape, uno::UNO_QUERY_THROW ) );
m_bShapeContextAdded = true;
// Add the shape to the anchored objects stack // Add the shape to the anchored objects stack
uno::Reference< text::XTextContent > xTxtContent( xShape, uno::UNO_QUERY_THROW ); uno::Reference< text::XTextContent > xTxtContent( xShape, uno::UNO_QUERY_THROW );
...@@ -1587,13 +1535,45 @@ void DomainMapper_Impl::PushShapeContext( const uno::Reference< drawing::XShape ...@@ -1587,13 +1535,45 @@ void DomainMapper_Impl::PushShapeContext( const uno::Reference< drawing::XShape
void DomainMapper_Impl::PopShapeContext() void DomainMapper_Impl::PopShapeContext()
{ {
if ( m_bShapeContextAdded ) if ( m_aAnchoredStack.size() > 0 )
{ {
RemoveLastParagraph(); // For OLE object replacement shape, the text append context was already removed
m_aTextAppendStack.pop(); // or the OLE object couldn't be inserted.
m_bShapeContextAdded = false; if ( !m_aAnchoredStack.top().bToRemove )
{
RemoveLastParagraph();
m_aTextAppendStack.pop();
}
uno::Reference< text::XTextContent > xObj = m_aAnchoredStack.top( ).xTextContent;
try
{
appendTextContent( xObj, uno::Sequence< beans::PropertyValue >() );
}
catch ( uno::RuntimeException& )
{
// this is normal: the shape is already attached
}
// Remove the shape if required (most likely replacement shape for OLE object)
if ( m_aAnchoredStack.top().bToRemove )
{
try
{
uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(m_xTextDocument, uno::UNO_QUERY_THROW);
uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage();
if ( xDrawPage.is() )
{
uno::Reference<drawing::XShape> xShape( xObj, uno::UNO_QUERY_THROW );
xDrawPage->remove( xShape );
}
}
catch( uno::Exception& )
{
}
}
m_aAnchoredStack.pop();
} }
m_bIsInShape = false;
} }
......
...@@ -183,13 +183,22 @@ struct TextAppendContext ...@@ -183,13 +183,22 @@ struct TextAppendContext
xTextAppend( xAppend ){} xTextAppend( xAppend ){}
}; };
struct AnchoredContext
{
::com::sun::star::uno::Reference< ::com::sun::star::text::XTextContent > xTextContent;
bool bToRemove;
AnchoredContext( const ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextContent >& xContent ) :
xTextContent( xContent ), bToRemove( false ) {}
};
typedef boost::shared_ptr<FieldContext> FieldContextPtr; typedef boost::shared_ptr<FieldContext> FieldContextPtr;
typedef std::stack<ContextType> ContextStack; typedef std::stack<ContextType> ContextStack;
typedef std::stack<PropertyMapPtr> PropertyStack; typedef std::stack<PropertyMapPtr> PropertyStack;
typedef std::stack< TextAppendContext > TextAppendStack; typedef std::stack< TextAppendContext > TextAppendStack;
typedef std::stack<FieldContextPtr> FieldStack; typedef std::stack<FieldContextPtr> FieldStack;
typedef std::stack< com::sun::star::uno::Reference< com::sun::star::text::XTextContent > > TextContentStack; typedef std::stack< AnchoredContext > TextContentStack;
...@@ -285,8 +294,7 @@ private: ...@@ -285,8 +294,7 @@ private:
TextAppendStack m_aTextAppendStack; TextAppendStack m_aTextAppendStack;
TextContentStack TextContentStack m_aAnchoredStack;
m_aAnchoredStack;
FieldStack m_aFieldStack; FieldStack m_aFieldStack;
bool m_bFieldMode; bool m_bFieldMode;
...@@ -294,8 +302,6 @@ private: ...@@ -294,8 +302,6 @@ private:
bool m_bIsFirstSection; bool m_bIsFirstSection;
bool m_bIsColumnBreakDeferred; bool m_bIsColumnBreakDeferred;
bool m_bIsPageBreakDeferred; bool m_bIsPageBreakDeferred;
bool m_bIsInShape;
bool m_bShapeContextAdded;
LineNumberSettings m_aLineNumberSettings; LineNumberSettings m_aLineNumberSettings;
...@@ -474,7 +480,7 @@ public: ...@@ -474,7 +480,7 @@ public:
bool IsStyleSheetImport()const { return m_bInStyleSheetImport;} bool IsStyleSheetImport()const { return m_bInStyleSheetImport;}
void SetAnyTableImport( bool bSet ) { m_bInAnyTableImport = bSet;} void SetAnyTableImport( bool bSet ) { m_bInAnyTableImport = bSet;}
bool IsAnyTableImport()const { return m_bInAnyTableImport;} bool IsAnyTableImport()const { return m_bInAnyTableImport;}
bool IsInShape()const { return m_bIsInShape;} bool IsInShape()const { return m_aAnchoredStack.size() > 0;}
void PushShapeContext( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > xShape ); void PushShapeContext( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > xShape );
void PopShapeContext(); void PopShapeContext();
......
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