diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2022-09-09 20:18:12 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-09-10 11:47:14 +0200 |
commit | 94c5c9281ac09186242143191f3e383bef2a89a7 (patch) | |
tree | d4f4cec0d08dd442594533d085bcbb5f6aa44716 /svtools | |
parent | 37af3c83bda0d56cf6d0d7a58665cbcaa60a3cc1 (diff) |
unique_ptr->optional for Graphic
Graphic is just a wrapper around shared_ptr, so no need to
allocate this separately
Change-Id: I30de73ac8a7e29adbc5ffe681f3ce88cd700b68c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139738
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'svtools')
-rw-r--r-- | svtools/source/misc/embedhlp.cxx | 50 | ||||
-rw-r--r-- | svtools/source/misc/embedtransfer.cxx | 13 |
2 files changed, 32 insertions, 31 deletions
diff --git a/svtools/source/misc/embedhlp.cxx b/svtools/source/misc/embedhlp.cxx index 827a2d9a41a9..c3e13a551b44 100644 --- a/svtools/source/misc/embedhlp.cxx +++ b/svtools/source/misc/embedhlp.cxx @@ -241,7 +241,7 @@ struct EmbeddedObjectRef_Impl OUString aPersistName; OUString aMediaType; comphelper::EmbeddedObjectContainer* pContainer; - std::unique_ptr<Graphic> pGraphic; + std::optional<Graphic> oGraphic; sal_Int64 nViewAspect; bool bIsLocked:1; bool bNeedUpdate:1; @@ -275,8 +275,8 @@ struct EmbeddedObjectRef_Impl mnGraphicVersion(0), aDefaultSizeForChart_In_100TH_MM(r.aDefaultSizeForChart_In_100TH_MM) { - if (r.pGraphic && !r.bNeedUpdate) - pGraphic.reset( new Graphic(*r.pGraphic) ); + if (r.oGraphic && !r.bNeedUpdate) + oGraphic.emplace(*r.oGraphic); } void dumpAsXml(xmlTextWriterPtr pWriter) const @@ -295,12 +295,12 @@ struct EmbeddedObjectRef_Impl (void)xmlTextWriterEndElement(pWriter); (void)xmlTextWriterStartElement(pWriter, BAD_CAST("pGraphic")); - (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", pGraphic.get()); - if (pGraphic) + (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", oGraphic ? &*oGraphic : nullptr); + if (oGraphic) { (void)xmlTextWriterWriteAttribute( pWriter, BAD_CAST("is-none"), - BAD_CAST(OString::boolean(pGraphic->IsNone()).getStr())); + BAD_CAST(OString::boolean(oGraphic->IsNone()).getStr())); } (void)xmlTextWriterEndElement(pWriter); @@ -407,8 +407,8 @@ void EmbeddedObjectRef::AssignToContainer( comphelper::EmbeddedObjectContainer* mpImpl->pContainer = pContainer; mpImpl->aPersistName = rPersistName; - if ( mpImpl->pGraphic && !mpImpl->bNeedUpdate && pContainer ) - SetGraphicToContainer( *mpImpl->pGraphic, *pContainer, mpImpl->aPersistName, OUString() ); + if ( mpImpl->oGraphic && !mpImpl->bNeedUpdate && pContainer ) + SetGraphicToContainer( *mpImpl->oGraphic, *pContainer, mpImpl->aPersistName, OUString() ); } comphelper::EmbeddedObjectContainer* EmbeddedObjectRef::GetContainer() const @@ -452,17 +452,17 @@ void EmbeddedObjectRef::GetReplacement( bool bUpdate ) if ( bUpdate ) { - if (mpImpl->pGraphic) - aOldGraphic = *mpImpl->pGraphic; + if (mpImpl->oGraphic) + aOldGraphic = *mpImpl->oGraphic; - mpImpl->pGraphic.reset(); + mpImpl->oGraphic.reset(); mpImpl->aMediaType.clear(); - mpImpl->pGraphic.reset( new Graphic ); + mpImpl->oGraphic.emplace(); mpImpl->mnGraphicVersion++; } - else if ( !mpImpl->pGraphic ) + else if ( !mpImpl->oGraphic ) { - mpImpl->pGraphic.reset( new Graphic ); + mpImpl->oGraphic.emplace(); mpImpl->mnGraphicVersion++; } else @@ -484,19 +484,19 @@ void EmbeddedObjectRef::GetReplacement( bool bUpdate ) if ( pGraphicStream ) { GraphicFilter& rGF = GraphicFilter::GetGraphicFilter(); - if( mpImpl->pGraphic ) - rGF.ImportGraphic( *mpImpl->pGraphic, u"", *pGraphicStream ); + if( mpImpl->oGraphic ) + rGF.ImportGraphic( *mpImpl->oGraphic, u"", *pGraphicStream ); mpImpl->mnGraphicVersion++; } - // note that UpdateReplacementOnDemand which resets mpImpl->pGraphic to null may have been called + // note that UpdateReplacementOnDemand which resets mpImpl->oGraphic to null may have been called // e.g. when exporting ooo58458-1.odt to doc - if (bUpdate && (!mpImpl->pGraphic || mpImpl->pGraphic->IsNone()) && !aOldGraphic.IsNone()) + if (bUpdate && (!mpImpl->oGraphic || mpImpl->oGraphic->IsNone()) && !aOldGraphic.IsNone()) { // We used to have an old graphic, tried to update and the update // failed. Go back to the old graphic instead of having no graphic at // all. - mpImpl->pGraphic.reset(new Graphic(aOldGraphic)); + mpImpl->oGraphic.emplace(aOldGraphic); SAL_WARN("svtools.misc", "EmbeddedObjectRef::GetReplacement: failed to update graphic"); } } @@ -508,7 +508,7 @@ const Graphic* EmbeddedObjectRef::GetGraphic() const if ( mpImpl->bNeedUpdate ) // bNeedUpdate will be set to false while retrieving new replacement const_cast < EmbeddedObjectRef* >(this)->GetReplacement(true); - else if ( !mpImpl->pGraphic ) + else if ( !mpImpl->oGraphic ) const_cast < EmbeddedObjectRef* >(this)->GetReplacement(false); } catch( const uno::Exception& ) @@ -516,7 +516,7 @@ const Graphic* EmbeddedObjectRef::GetGraphic() const DBG_UNHANDLED_EXCEPTION("svtools.misc", "Something went wrong on getting the graphic"); } - return mpImpl->pGraphic.get(); + return mpImpl->oGraphic ? &*mpImpl->oGraphic : nullptr; } Size EmbeddedObjectRef::GetSize( MapMode const * pTargetMapMode ) const @@ -583,7 +583,7 @@ Size EmbeddedObjectRef::GetSize( MapMode const * pTargetMapMode ) const void EmbeddedObjectRef::SetGraphicStream( const uno::Reference< io::XInputStream >& xInGrStream, const OUString& rMediaType ) { - mpImpl->pGraphic.reset( new Graphic ); + mpImpl->oGraphic.emplace(); mpImpl->aMediaType = rMediaType; mpImpl->mnGraphicVersion++; @@ -592,7 +592,7 @@ void EmbeddedObjectRef::SetGraphicStream( const uno::Reference< io::XInputStream if ( pGraphicStream ) { GraphicFilter& rGF = GraphicFilter::GetGraphicFilter(); - rGF.ImportGraphic( *mpImpl->pGraphic, u"", *pGraphicStream ); + rGF.ImportGraphic( *mpImpl->oGraphic, u"", *pGraphicStream ); mpImpl->mnGraphicVersion++; if ( mpImpl->pContainer ) @@ -610,7 +610,7 @@ void EmbeddedObjectRef::SetGraphicStream( const uno::Reference< io::XInputStream void EmbeddedObjectRef::SetGraphic( const Graphic& rGraphic, const OUString& rMediaType ) { - mpImpl->pGraphic.reset( new Graphic( rGraphic ) ); + mpImpl->oGraphic.emplace( rGraphic ); mpImpl->aMediaType = rMediaType; mpImpl->mnGraphicVersion++; @@ -904,7 +904,7 @@ void EmbeddedObjectRef::UpdateOleObject( bool bUpdateOle ) void EmbeddedObjectRef::UpdateReplacementOnDemand() { - mpImpl->pGraphic.reset(); + mpImpl->oGraphic.reset(); mpImpl->bNeedUpdate = true; mpImpl->mnGraphicVersion++; diff --git a/svtools/source/misc/embedtransfer.cxx b/svtools/source/misc/embedtransfer.cxx index 388a9f0f87a9..6d604a9e3afd 100644 --- a/svtools/source/misc/embedtransfer.cxx +++ b/svtools/source/misc/embedtransfer.cxx @@ -45,9 +45,10 @@ SvEmbedTransferHelper::SvEmbedTransferHelper( const uno::Reference< embed::XEmbe const Graphic* pGraphic, sal_Int64 nAspect ) : m_xObj( xObj ) -, m_pGraphic( pGraphic ? new Graphic( *pGraphic ) : nullptr ) , m_nAspect( nAspect ) { + if (pGraphic) + m_oGraphic.emplace(*pGraphic); if( xObj.is() ) { TransferableObjectDescriptor aObjDesc; @@ -91,7 +92,7 @@ bool SvEmbedTransferHelper::GetData( const css::datatransfer::DataFlavor& rFlavo if( nFormat == SotClipboardFormatId::OBJECTDESCRIPTOR ) { TransferableObjectDescriptor aDesc; - FillTransferableObjectDescriptor( aDesc, m_xObj, m_pGraphic.get(), m_nAspect ); + FillTransferableObjectDescriptor( aDesc, m_xObj, m_oGraphic ? &*m_oGraphic : nullptr, m_nAspect ); bRet = SetTransferableObjectDescriptor( aDesc ); } else if( nFormat == SotClipboardFormatId::EMBED_SOURCE ) @@ -151,12 +152,12 @@ bool SvEmbedTransferHelper::GetData( const css::datatransfer::DataFlavor& rFlavo { } } - else if ( nFormat == SotClipboardFormatId::GDIMETAFILE && m_pGraphic ) + else if ( nFormat == SotClipboardFormatId::GDIMETAFILE && m_oGraphic ) { SvMemoryStream aMemStm( 65535, 65535 ); aMemStm.SetVersion( SOFFICE_FILEFORMAT_CURRENT ); - const GDIMetaFile& aMetaFile = m_pGraphic->GetGDIMetaFile(); + const GDIMetaFile& aMetaFile = m_oGraphic->GetGDIMetaFile(); SvmWriter aWriter( aMemStm ); aWriter.Write( aMetaFile ); uno::Any aAny; @@ -165,9 +166,9 @@ bool SvEmbedTransferHelper::GetData( const css::datatransfer::DataFlavor& rFlavo SetAny( aAny ); bRet = true; } - else if ( ( nFormat == SotClipboardFormatId::BITMAP || nFormat == SotClipboardFormatId::PNG ) && m_pGraphic ) + else if ( ( nFormat == SotClipboardFormatId::BITMAP || nFormat == SotClipboardFormatId::PNG ) && m_oGraphic ) { - bRet = SetBitmapEx( m_pGraphic->GetBitmapEx(), rFlavor ); + bRet = SetBitmapEx( m_oGraphic->GetBitmapEx(), rFlavor ); } else if ( m_xObj.is() && ::svt::EmbeddedObjectRef::TryRunningState( m_xObj ) ) { |