diff options
author | Michael Stahl <mstahl@redhat.com> | 2014-08-15 23:21:05 +0200 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2014-08-20 16:40:08 +0200 |
commit | 00b5f1ef2e06d5ae2ce7469710e85c4a06c20a5f (patch) | |
tree | 1ecc3c0d541f1d6be7ce4128f7feaa6d466eed9d /sw | |
parent | bcbab38792f47cb1e27a8fb4bc0523ea135a2e75 (diff) |
i#105557: thread-safe caching of SwXFrame instances
Replace SwXFrames::GetObject() with factory functions that use the
WeakReference SwFrmFmt::m_wXObject to cache the instance in a thread-safe
way.
Change-Id: If56e4d7f95cb4f2e112139f228fb832ae9bf7d76
Diffstat (limited to 'sw')
-rw-r--r-- | sw/inc/unocoll.hxx | 1 | ||||
-rw-r--r-- | sw/inc/unoframe.hxx | 12 | ||||
-rw-r--r-- | sw/source/core/doc/textboxhelper.cxx | 12 | ||||
-rw-r--r-- | sw/source/core/layout/atrfrm.cxx | 4 | ||||
-rw-r--r-- | sw/source/core/unocore/unocoll.cxx | 16 | ||||
-rw-r--r-- | sw/source/core/unocore/unocrsrhelper.cxx | 5 | ||||
-rw-r--r-- | sw/source/core/unocore/unodraw.cxx | 18 | ||||
-rw-r--r-- | sw/source/core/unocore/unoframe.cxx | 41 | ||||
-rw-r--r-- | sw/source/core/unocore/unoobj2.cxx | 22 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.cxx | 6 | ||||
-rw-r--r-- | sw/source/filter/xml/xmltexti.cxx | 45 |
11 files changed, 127 insertions, 55 deletions
diff --git a/sw/inc/unocoll.hxx b/sw/inc/unocoll.hxx index 26034303ecd6..5c4caef407a9 100644 --- a/sw/inc/unocoll.hxx +++ b/sw/inc/unocoll.hxx @@ -338,7 +338,6 @@ public: virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames(void) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE; FlyCntType GetType()const{return eType;} - static SwXFrame* GetObject( SwFrmFmt& rFmt, FlyCntType eType ); }; diff --git a/sw/inc/unoframe.hxx b/sw/inc/unoframe.hxx index afd243736a44..23af07c96fab 100644 --- a/sw/inc/unoframe.hxx +++ b/sw/inc/unoframe.hxx @@ -78,13 +78,14 @@ protected: virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew) SAL_OVERRIDE; virtual ~SwXFrame(); -public: + SwXFrame(FlyCntType eSet, const SfxItemPropertySet* pPropSet, SwDoc *pDoc ); //Descriptor-If SwXFrame(SwFrmFmt& rFrmFmt, FlyCntType eSet, const SfxItemPropertySet* pPropSet); +public: static const ::com::sun::star::uno::Sequence< sal_Int8 > & getUnoTunnelId(); //XUnoTunnel @@ -174,6 +175,9 @@ public: SwXTextFrame(SwDoc *pDoc); SwXTextFrame(SwFrmFmt& rFmt); + static SW_DLLPUBLIC css::uno::Reference<css::text::XTextFrame> + CreateXTextFrame(SwDoc & rDoc, SwFrmFmt * pFrmFmt); + // FIXME: EVIL HACK: make available for SwXFrame::attachToRange void SetDoc(SwDoc *const pDoc) { SwXText::SetDoc(pDoc); }; @@ -241,6 +245,9 @@ public: SwXTextGraphicObject( SwDoc *pDoc ); SwXTextGraphicObject(SwFrmFmt& rFmt); + static css::uno::Reference<css::text::XTextContent> + CreateXTextGraphicObject(SwDoc & rDoc, SwFrmFmt * pFrmFmt); + virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& aType ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; virtual void SAL_CALL acquire( ) throw() SAL_OVERRIDE; virtual void SAL_CALL release( ) throw() SAL_OVERRIDE; @@ -287,6 +294,9 @@ public: SwXTextEmbeddedObject( SwDoc *pDoc ); SwXTextEmbeddedObject(SwFrmFmt& rFmt); + static css::uno::Reference<css::text::XTextContent> + CreateXTextEmbeddedObject(SwDoc & rDoc, SwFrmFmt * pFrmFmt); + virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& aType ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; virtual void SAL_CALL acquire( ) throw() SAL_OVERRIDE; virtual void SAL_CALL release( ) throw() SAL_OVERRIDE; diff --git a/sw/source/core/doc/textboxhelper.cxx b/sw/source/core/doc/textboxhelper.cxx index 1e06d49dca04..c4de3668a6c3 100644 --- a/sw/source/core/doc/textboxhelper.cxx +++ b/sw/source/core/doc/textboxhelper.cxx @@ -225,7 +225,9 @@ void lcl_queryInterface(SwFrmFmt* pShape, uno::Any& rAny) { if (SwFrmFmt* pFmt = SwTextBoxHelper::findTextBox(pShape)) { - uno::Reference<T> xInterface(static_cast<cppu::OWeakObject*>(SwXFrames::GetObject(*pFmt, FLYCNTTYPE_FRM)), uno::UNO_QUERY); + uno::Reference<T> const xInterface( + SwXTextFrame::CreateXTextFrame(*pFmt->GetDoc(), pFmt), + uno::UNO_QUERY); rAny <<= xInterface; } } @@ -419,7 +421,9 @@ void SwTextBoxHelper::syncProperty(SwFrmFmt* pShape, sal_uInt16 nWID, sal_uInt8 case MID_ANCHOR_ANCHORTYPE: if (aValue.get<text::TextContentAnchorType>() == text::TextContentAnchorType_AS_CHARACTER) { - uno::Reference<beans::XPropertySet> xPropertySet(static_cast<cppu::OWeakObject*>(SwXFrames::GetObject(*pFmt, FLYCNTTYPE_FRM)), uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> const xPropertySet( + SwXTextFrame::CreateXTextFrame(*pFmt->GetDoc(), pFmt), + uno::UNO_QUERY); xPropertySet->setPropertyValue(UNO_NAME_SURROUND, uno::makeAny(text::WrapTextMode_THROUGHT)); return; } @@ -483,7 +487,9 @@ void SwTextBoxHelper::syncProperty(SwFrmFmt* pShape, sal_uInt16 nWID, sal_uInt8 } } - uno::Reference<beans::XPropertySet> xPropertySet(static_cast<cppu::OWeakObject*>(SwXFrames::GetObject(*pFmt, FLYCNTTYPE_FRM)), uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> const xPropertySet( + SwXTextFrame::CreateXTextFrame(*pFmt->GetDoc(), pFmt), + uno::UNO_QUERY); xPropertySet->setPropertyValue(aPropertyName, aValue); } } diff --git a/sw/source/core/layout/atrfrm.cxx b/sw/source/core/layout/atrfrm.cxx index 328d4f184810..8188ed738fed 100644 --- a/sw/source/core/layout/atrfrm.cxx +++ b/sw/source/core/layout/atrfrm.cxx @@ -1554,8 +1554,8 @@ bool SwFmtAnchor::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const SwFrmFmt* pFmt = m_pCntntAnchor->nNode.GetNode().GetFlyFmt(); if(pFmt) { - uno::Reference<container::XNamed> xNamed = SwXFrames::GetObject( *pFmt, FLYCNTTYPE_FRM ); - uno::Reference<text::XTextFrame> xRet(xNamed, uno::UNO_QUERY); + uno::Reference<text::XTextFrame> const xRet( + SwXTextFrame::CreateXTextFrame(*pFmt->GetDoc(), pFmt)); rVal <<= xRet; } } diff --git a/sw/source/core/unocore/unocoll.cxx b/sw/source/core/unocore/unocoll.cxx index e42f7c1ce5ad..2ea9473a0907 100644 --- a/sw/source/core/unocore/unocoll.cxx +++ b/sw/source/core/unocore/unocoll.cxx @@ -1287,22 +1287,6 @@ sal_Bool SwXFrames::hasElements(void) throw(uno::RuntimeException, std::exceptio return GetDoc()->GetFlyCount(eType) > 0; } -SwXFrame* SwXFrames::GetObject(SwFrmFmt& rFmt, FlyCntType eType) -{ - SwXFrame* pFrm = SwIterator<SwXFrame,SwFmt>::FirstElement( rFmt ); - if(pFrm) return pFrm; - switch(eType) - { - case FLYCNTTYPE_FRM: - return new SwXTextFrame(rFmt); - case FLYCNTTYPE_GRF: - return new SwXTextGraphicObject(rFmt); - case FLYCNTTYPE_OLE: - return new SwXTextEmbeddedObject(rFmt); - default: - return NULL; - } -} OUString SwXTextFrames::getImplementationName(void) throw( RuntimeException, std::exception ) { diff --git a/sw/source/core/unocore/unocrsrhelper.cxx b/sw/source/core/unocore/unocrsrhelper.cxx index d2fc1770cd1d..cc5a0333860d 100644 --- a/sw/source/core/unocore/unocrsrhelper.cxx +++ b/sw/source/core/unocore/unocrsrhelper.cxx @@ -570,8 +570,9 @@ bool getCrsrPropertyValue(const SfxItemPropertySimpleEntry& rEntry { if( pAny ) { - uno::Reference< XTextFrame > xFrm = (SwXTextFrame*) SwXFrames::GetObject(*pFmt, FLYCNTTYPE_FRM); - pAny->setValue(&xFrm, cppu::UnoType<XTextFrame>::get()); + uno::Reference<XTextFrame> const xFrame( + SwXTextFrame::CreateXTextFrame(*pFmt->GetDoc(), pFmt)); + (*pAny) <<= xFrame; } } else diff --git a/sw/source/core/unocore/unodraw.cxx b/sw/source/core/unocore/unodraw.cxx index d05805814c51..891bc28b5b1e 100644 --- a/sw/source/core/unocore/unodraw.cxx +++ b/sw/source/core/unocore/unodraw.cxx @@ -311,7 +311,6 @@ uno::Reference< drawing::XShape > SwFmDrawPage::_CreateShape( SdrObject *pObj ) SwFlyDrawContact* pFlyContact = (SwFlyDrawContact*)pObj->GetUserCall(); if(pFlyContact) { - FlyCntType eType = FLYCNTTYPE_ALL; SwFrmFmt* pFlyFmt = pFlyContact->GetFmt(); SwDoc* pDoc = pFlyFmt->GetDoc(); const SwNodeIndex* pIdx; @@ -322,19 +321,26 @@ uno::Reference< drawing::XShape > SwFmDrawPage::_CreateShape( SdrObject *pObj ) { const SwNode* pNd = pDoc->GetNodes()[ pIdx->GetIndex() + 1 ]; if(!pNd->IsNoTxtNode()) - eType = FLYCNTTYPE_FRM; + { + xRet.set(SwXTextFrame::CreateXTextFrame(*pDoc, pFlyFmt), + uno::UNO_QUERY); + } else if( pNd->IsGrfNode() ) - eType = FLYCNTTYPE_GRF; + { + xRet.set(SwXTextGraphicObject::CreateXTextGraphicObject( + *pDoc, pFlyFmt), uno::UNO_QUERY); + } else if( pNd->IsOLENode() ) - eType = FLYCNTTYPE_OLE; + { + xRet.set(SwXTextEmbeddedObject::CreateXTextEmbeddedObject( + *pDoc, pFlyFmt), uno::UNO_QUERY); + } } else { OSL_FAIL( "<SwFmDrawPage::_CreateShape(..)> - could not retrieve type. Thus, no shape created." ); return xRet; } - OSL_ENSURE( eType != FLYCNTTYPE_ALL, "unexpected FlyCntType value for eType" ); - xRet = SwXFrames::GetObject( *pFlyFmt, eType ); } } else diff --git a/sw/source/core/unocore/unoframe.cxx b/sw/source/core/unocore/unoframe.cxx index b7eba3751961..5a7b6d7c139d 100644 --- a/sw/source/core/unocore/unoframe.cxx +++ b/sw/source/core/unocore/unoframe.cxx @@ -1231,6 +1231,28 @@ SwXFrame::~SwXFrame() delete pProps; } +template<class Interface, class Impl> +uno::Reference<Interface> +CreateXFrame(SwDoc & rDoc, SwFrmFmt *const pFrmFmt) +{ + assert(!pFrmFmt || &rDoc == pFrmFmt->GetDoc()); + uno::Reference<Interface> xFrame; + if (pFrmFmt) + { + xFrame.set(pFrmFmt->GetXObject(), uno::UNO_QUERY); // cached? + } + if (!xFrame.is()) + { + Impl *const pNew((pFrmFmt) ? new Impl(*pFrmFmt) : new Impl(&rDoc)); + xFrame.set(pNew); + if (pFrmFmt) + { + pFrmFmt->SetXObject(xFrame); + } + } + return xFrame; +} + OUString SwXFrame::getName(void) throw( uno::RuntimeException, std::exception ) { SolarMutexGuard aGuard; @@ -3084,6 +3106,12 @@ SwXTextFrame::~SwXTextFrame() { } +uno::Reference<text::XTextFrame> +SwXTextFrame::CreateXTextFrame(SwDoc & rDoc, SwFrmFmt *const pFrmFmt) +{ + return CreateXFrame<text::XTextFrame, SwXTextFrame>(rDoc, pFrmFmt); +} + void SAL_CALL SwXTextFrame::acquire( )throw() { SwXFrame::acquire(); @@ -3362,6 +3390,12 @@ SwXTextGraphicObject::~SwXTextGraphicObject() } +uno::Reference<text::XTextContent> +SwXTextGraphicObject::CreateXTextGraphicObject(SwDoc & rDoc, SwFrmFmt *const pFrmFmt) +{ + return CreateXFrame<text::XTextContent, SwXTextGraphicObject>(rDoc, pFrmFmt); +} + void SAL_CALL SwXTextGraphicObject::acquire( )throw() { SwXFrame::acquire(); @@ -3487,6 +3521,13 @@ SwXTextEmbeddedObject::~SwXTextEmbeddedObject() { } + +uno::Reference<text::XTextContent> +SwXTextEmbeddedObject::CreateXTextEmbeddedObject(SwDoc & rDoc, SwFrmFmt *const pFrmFmt) +{ + return CreateXFrame<text::XTextContent, SwXTextEmbeddedObject>(rDoc, pFrmFmt); +} + void SAL_CALL SwXTextEmbeddedObject::acquire()throw() { SwXFrame::acquire(); diff --git a/sw/source/core/unocore/unoobj2.cxx b/sw/source/core/unocore/unoobj2.cxx index 0e4442f23be9..801275784b94 100644 --- a/sw/source/core/unocore/unoobj2.cxx +++ b/sw/source/core/unocore/unoobj2.cxx @@ -1776,12 +1776,22 @@ lcl_CreateNextObject(SwUnoCrsr& i_rUnoCrsr, SwNode const*const pNd = i_rUnoCrsr.GetDoc()->GetNodes()[ pIdx->GetIndex() + 1 ]; - const FlyCntType eType = (!pNd->IsNoTxtNode()) ? FLYCNTTYPE_FRM - : ( (pNd->IsGrfNode()) ? FLYCNTTYPE_GRF : FLYCNTTYPE_OLE ); - - const uno::Reference< container::XNamed > xFrame = - SwXFrames::GetObject(*pFormat, eType); - o_rNextObject.set(xFrame, uno::UNO_QUERY); + if (!pNd->IsNoTxtNode()) + { + o_rNextObject.set(SwXTextFrame::CreateXTextFrame( + *pFormat->GetDoc(), pFormat)); + } + else if (pNd->IsGrfNode()) + { + o_rNextObject.set(SwXTextGraphicObject::CreateXTextGraphicObject( + *pFormat->GetDoc(), pFormat)); + } + else + { + assert(pNd->IsOLENode()); + o_rNextObject.set(SwXTextEmbeddedObject::CreateXTextEmbeddedObject( + *pFormat->GetDoc(), pFormat)); + } } return o_rNextObject.is(); diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index 9f43f7f8bb5e..05a22ba4a52d 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -7523,7 +7523,11 @@ void DocxAttributeOutput::FormatFillGradient( const XFillGradientItem& rFillGrad } else if (m_oFillStyle && *m_oFillStyle == drawing::FillStyle_GRADIENT && m_rExport.SdrExporter().getDMLTextFrameSyntax()) { - uno::Reference<beans::XPropertySet> xPropertySet = SwXFrames::GetObject(const_cast<SwFrmFmt&>(m_rExport.mpParentFrame->GetFrmFmt()), FLYCNTTYPE_FRM); + SwFrmFmt & rFormat( + const_cast<SwFrmFmt&>(m_rExport.mpParentFrame->GetFrmFmt())); + uno::Reference<beans::XPropertySet> const xPropertySet( + SwXTextFrame::CreateXTextFrame(*rFormat.GetDoc(), &rFormat), + uno::UNO_QUERY); m_rDrawingML.SetFS(m_pSerializer); m_rDrawingML.WriteGradientFill(xPropertySet); } diff --git a/sw/source/filter/xml/xmltexti.cxx b/sw/source/filter/xml/xmltexti.cxx index d97338a96a9a..63d8927c494e 100644 --- a/sw/source/filter/xml/xmltexti.cxx +++ b/sw/source/filter/xml/xmltexti.cxx @@ -357,11 +357,13 @@ uno::Reference< XPropertySet > SwXMLTextImportHelper::createAndInsertOLEObject( pOLENd->SetOLESizeInvalid( true ); } - SwXFrame *pXFrame = SwXFrames::GetObject( *pFrmFmt, FLYCNTTYPE_OLE ); - xPropSet = pXFrame; + xPropSet.set(SwXTextEmbeddedObject::CreateXTextEmbeddedObject( + *pDoc, pFrmFmt), uno::UNO_QUERY); if( pDoc->getIDocumentDrawModelAccess().GetDrawModel() ) - SwXFrame::GetOrCreateSdrObject(* - static_cast<SwFlyFrmFmt*>( pXFrame->GetFrmFmt() ) ); // req for z-order + { + // req for z-order + SwXFrame::GetOrCreateSdrObject(*static_cast<SwFlyFrmFmt*>(pFrmFmt)); + } if( !rTblName.isEmpty() ) { const SwFmtCntnt& rCntnt = pFrmFmt->GetCntnt(); @@ -595,11 +597,13 @@ uno::Reference< XPropertySet > SwXMLTextImportHelper::createAndInsertOOoLink( // TODO/LATER: in future may need a way to set replacement image url to the link ( may be even to the object ), needs oasis cws??? - SwXFrame *pXFrame = SwXFrames::GetObject( *pFrmFmt, FLYCNTTYPE_OLE ); - xPropSet = pXFrame; + xPropSet.set(SwXTextEmbeddedObject::CreateXTextEmbeddedObject( + *pDoc, pFrmFmt), uno::UNO_QUERY); if( pDoc->getIDocumentDrawModelAccess().GetDrawModel() ) + { SwXFrame::GetOrCreateSdrObject(* - static_cast<SwFlyFrmFmt*>( pXFrame->GetFrmFmt() ) ); // req for z-order + static_cast<SwFlyFrmFmt*>(pFrmFmt)); // req for z-order + } } } catch ( uno::Exception& ) @@ -652,11 +656,13 @@ uno::Reference< XPropertySet > SwXMLTextImportHelper::createAndInsertApplet( &aAppletImpl.GetItemSet(), NULL, NULL); - SwXFrame *pXFrame = SwXFrames::GetObject( *pFrmFmt, FLYCNTTYPE_OLE ); - xPropSet = pXFrame; + xPropSet.set(SwXTextEmbeddedObject::CreateXTextEmbeddedObject( + *pDoc, pFrmFmt), uno::UNO_QUERY); if( pDoc->getIDocumentDrawModelAccess().GetDrawModel() ) - SwXFrame::GetOrCreateSdrObject(* - static_cast<SwFlyFrmFmt*>( pXFrame->GetFrmFmt() ) ); // req for z-order + { + // req for z-order + SwXFrame::GetOrCreateSdrObject(*static_cast<SwFlyFrmFmt*>(pFrmFmt)); + } return xPropSet; } @@ -725,11 +731,13 @@ uno::Reference< XPropertySet > SwXMLTextImportHelper::createAndInsertPlugin( &aItemSet, NULL, NULL); - SwXFrame *pXFrame = SwXFrames::GetObject( *pFrmFmt, FLYCNTTYPE_OLE ); - xPropSet = pXFrame; + xPropSet.set(SwXTextEmbeddedObject::CreateXTextEmbeddedObject( + *pDoc, pFrmFmt), uno::UNO_QUERY); if( pDoc->getIDocumentDrawModelAccess().GetDrawModel() ) + { SwXFrame::GetOrCreateSdrObject(* - static_cast<SwFlyFrmFmt*>( pXFrame->GetFrmFmt() ) ); // req for z-order + static_cast<SwFlyFrmFmt*>(pFrmFmt)); // req for z-order + } } } catch ( uno::Exception& ) @@ -876,11 +884,14 @@ uno::Reference< XPropertySet > SwXMLTextImportHelper::createAndInsertFloatingFra &aItemSet, NULL, NULL); - SwXFrame *pXFrame = SwXFrames::GetObject( *pFrmFmt, FLYCNTTYPE_OLE ); - xPropSet = pXFrame; + xPropSet.set(SwXTextEmbeddedObject::CreateXTextEmbeddedObject( + *pDoc, pFrmFmt), uno::UNO_QUERY); if( pDoc->getIDocumentDrawModelAccess().GetDrawModel() ) + { + // req for z-order SwXFrame::GetOrCreateSdrObject(* - static_cast<SwFlyFrmFmt*>( pXFrame->GetFrmFmt() ) ); // req for z-order + static_cast<SwFlyFrmFmt*>(pFrmFmt)); + } } } catch ( uno::Exception& ) |