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 | |
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>
-rw-r--r-- | include/svtools/embedtransfer.hxx | 6 | ||||
-rw-r--r-- | sd/source/ui/app/sdxfer.cxx | 20 | ||||
-rw-r--r-- | sd/source/ui/inc/sdxfer.hxx | 3 | ||||
-rw-r--r-- | svtools/source/misc/embedhlp.cxx | 50 | ||||
-rw-r--r-- | svtools/source/misc/embedtransfer.cxx | 13 | ||||
-rw-r--r-- | svx/source/gallery2/galtheme.cxx | 10 | ||||
-rw-r--r-- | svx/source/svdraw/svdoole2.cxx | 20 |
7 files changed, 62 insertions, 60 deletions
diff --git a/include/svtools/embedtransfer.hxx b/include/svtools/embedtransfer.hxx index 98bab1683aa8..03e41bcf1592 100644 --- a/include/svtools/embedtransfer.hxx +++ b/include/svtools/embedtransfer.hxx @@ -21,17 +21,17 @@ #include <svtools/svtdllapi.h> #include <vcl/transfer.hxx> -#include <memory> +#include <vcl/graph.hxx> +#include <optional> namespace com :: sun :: star :: embed { class XEmbeddedObject; } -class Graphic; class SVT_DLLPUBLIC SvEmbedTransferHelper final : public TransferableHelper { private: css::uno::Reference< css::embed::XEmbeddedObject > m_xObj; - std::unique_ptr<Graphic> m_pGraphic; + std::optional<Graphic> m_oGraphic; sal_Int64 m_nAspect; OUString maParentShellID; diff --git a/sd/source/ui/app/sdxfer.cxx b/sd/source/ui/app/sdxfer.cxx index d5a6e3c1fadf..3c3fdcd6d912 100644 --- a/sd/source/ui/app/sdxfer.cxx +++ b/sd/source/ui/app/sdxfer.cxx @@ -129,7 +129,7 @@ SdTransferable::~SdTransferable() if( mbOwnDocument ) delete mpSdDrawDocumentIntern; - mpGraphic.reset(); + moGraphic.reset(); mpBookmark.reset(); mpImageMap.reset(); @@ -146,7 +146,7 @@ void SdTransferable::CreateObjectReplacement( SdrObject* pObj ) return; mpOLEDataHelper.reset(); - mpGraphic.reset(); + moGraphic.reset(); mpBookmark.reset(); mpImageMap.reset(); @@ -164,7 +164,7 @@ void SdTransferable::CreateObjectReplacement( SdrObject* pObj ) // The EmbedDataHelper should bring the graphic in future const Graphic* pObjGr = pOleObj->GetGraphic(); if ( pObjGr ) - mpGraphic.reset( new Graphic( *pObjGr ) ); + moGraphic.emplace(*pObjGr); } } catch( uno::Exception& ) @@ -172,7 +172,7 @@ void SdTransferable::CreateObjectReplacement( SdrObject* pObj ) } else if( dynamic_cast< const SdrGrafObj *>( pObj ) != nullptr && (mpSourceDoc && !SdDrawDocument::GetAnimationInfo( pObj )) ) { - mpGraphic.reset( new Graphic( static_cast< SdrGrafObj* >( pObj )->GetTransformedGraphic() ) ); + moGraphic.emplace( static_cast< SdrGrafObj* >( pObj )->GetTransformedGraphic() ); } else if( pObj->IsUnoObj() && SdrInventor::FmForm == pObj->GetObjInventor() && ( pObj->GetObjIdentifier() == SdrObjKind::FormButton ) ) { @@ -394,14 +394,14 @@ void SdTransferable::AddSupportedFormats() for( const auto& rItem : aVector ) AddFormat( rItem ); } - else if( mpGraphic ) + else if( moGraphic ) { // #i25616# AddFormat( SotClipboardFormatId::DRAWING ); AddFormat( SotClipboardFormatId::SVXB ); - if( mpGraphic->GetType() == GraphicType::Bitmap ) + if( moGraphic->GetType() == GraphicType::Bitmap ) { AddFormat( SotClipboardFormatId::PNG ); AddFormat( SotClipboardFormatId::BITMAP ); @@ -457,8 +457,8 @@ bool SdTransferable::GetData( const DataFlavor& rFlavor, const OUString& rDestDo else if( mpOLEDataHelper && mpOLEDataHelper->HasFormat( rFlavor ) ) { // TODO/LATER: support all the graphical formats, the embedded object scenario should not have separated handling - if( nFormat == SotClipboardFormatId::GDIMETAFILE && mpGraphic ) - bOK = SetGDIMetaFile( mpGraphic->GetGDIMetaFile() ); + if( nFormat == SotClipboardFormatId::GDIMETAFILE && moGraphic ) + bOK = SetGDIMetaFile( moGraphic->GetGDIMetaFile() ); else bOK = SetAny( mpOLEDataHelper->GetAny(rFlavor, rDestDoc) ); } @@ -523,9 +523,9 @@ bool SdTransferable::GetData( const DataFlavor& rFlavor, const OUString& rDestDo { bOK = SetString( mpBookmark->GetURL() ); } - else if( ( nFormat == SotClipboardFormatId::SVXB ) && mpGraphic ) + else if( ( nFormat == SotClipboardFormatId::SVXB ) && moGraphic ) { - bOK = SetGraphic( *mpGraphic ); + bOK = SetGraphic( *moGraphic ); } else if( ( nFormat == SotClipboardFormatId::SVIM ) && mpImageMap ) { diff --git a/sd/source/ui/inc/sdxfer.hxx b/sd/source/ui/inc/sdxfer.hxx index 5e25ba682711..8393e8f7aea0 100644 --- a/sd/source/ui/inc/sdxfer.hxx +++ b/sd/source/ui/inc/sdxfer.hxx @@ -19,6 +19,7 @@ #pragma once +#include <vcl/graph.hxx> #include <vcl/transfer.hxx> #include <vcl/vclptr.hxx> #include <sfx2/objsh.hxx> @@ -125,7 +126,7 @@ private: SdDrawDocument* mpSourceDoc; VclPtr<VirtualDevice> mpVDev; std::unique_ptr<INetBookmark> mpBookmark; - std::unique_ptr<Graphic> mpGraphic; + std::optional<Graphic> moGraphic; std::unique_ptr<ImageMap> mpImageMap; ::tools::Rectangle maVisArea; Point maStartPos; 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 ) ) { diff --git a/svx/source/gallery2/galtheme.cxx b/svx/source/gallery2/galtheme.cxx index be3430acbf15..94940f355a42 100644 --- a/svx/source/gallery2/galtheme.cxx +++ b/svx/source/gallery2/galtheme.cxx @@ -538,7 +538,7 @@ bool GalleryTheme::InsertTransferable(const uno::Reference< datatransfer::XTrans if( rxTransferable.is() ) { TransferableDataHelper aDataHelper( rxTransferable ); - std::unique_ptr<Graphic> pGraphic; + std::optional<Graphic> oGraphic; if( aDataHelper.HasFormat( SotClipboardFormatId::DRAWING ) ) { @@ -591,10 +591,10 @@ bool GalleryTheme::InsertTransferable(const uno::Reference< datatransfer::XTrans nFormat = SotClipboardFormatId::BITMAP; if( nFormat != SotClipboardFormatId::NONE && aDataHelper.GetGraphic( nFormat, aGraphic ) ) - pGraphic.reset(new Graphic( aGraphic )); + oGraphic.emplace( aGraphic ); } - if( pGraphic ) + if( oGraphic ) { bRet = false; @@ -611,7 +611,7 @@ bool GalleryTheme::InsertTransferable(const uno::Reference< datatransfer::XTrans if( aModel.GetModel() ) { SdrPage* pPage = aModel.GetModel()->GetPage(0); - rtl::Reference<SdrGrafObj> pGrafObj = new SdrGrafObj(*aModel.GetModel(), *pGraphic ); + rtl::Reference<SdrGrafObj> pGrafObj = new SdrGrafObj(*aModel.GetModel(), *oGraphic ); pGrafObj->AppendUserData( std::unique_ptr<SdrObjUserData>(new SgaIMapInfo( aImageMap )) ); pPage->InsertObject( pGrafObj.get() ); @@ -621,7 +621,7 @@ bool GalleryTheme::InsertTransferable(const uno::Reference< datatransfer::XTrans } if( !bRet ) - bRet = InsertGraphic( *pGraphic, nInsertPos ); + bRet = InsertGraphic( *oGraphic, nInsertPos ); } } diff --git a/svx/source/svdraw/svdoole2.cxx b/svx/source/svdraw/svdoole2.cxx index 6419c1041061..304ed04a0051 100644 --- a/svx/source/svdraw/svdoole2.cxx +++ b/svx/source/svdraw/svdoole2.cxx @@ -598,7 +598,7 @@ class SdrOle2ObjImpl public: svt::EmbeddedObjectRef mxObjRef; - std::unique_ptr<Graphic> mxGraphic; + std::optional<Graphic> moGraphic; OUString maProgName; OUString aPersistName; // name of object in persist rtl::Reference<SdrLightEmbeddedClient_Impl> mxLightClient; // must be registered as client only using AddOwnLightClient() call @@ -642,7 +642,7 @@ public: ~SdrOle2ObjImpl() { - mxGraphic.reset(); + moGraphic.reset(); if (mxModifyListener.is()) { @@ -723,9 +723,9 @@ SdrOle2Obj::SdrOle2Obj(SdrModel& rSdrModel, SdrOle2Obj const & rSource) mpImpl->maProgName = rSource.mpImpl->maProgName; mpImpl->mbFrame = rSource.mpImpl->mbFrame; - if (rSource.mpImpl->mxGraphic) + if (rSource.mpImpl->moGraphic) { - mpImpl->mxGraphic.reset(new Graphic(*rSource.mpImpl->mxGraphic)); + mpImpl->moGraphic.emplace(*rSource.mpImpl->moGraphic); } if( IsEmptyPresObj() ) @@ -827,7 +827,7 @@ bool SdrOle2Obj::isUiActive() const void SdrOle2Obj::SetGraphic(const Graphic& rGrf) { // only for setting a preview graphic - mpImpl->mxGraphic.reset(new Graphic(rGrf)); + mpImpl->moGraphic.emplace(rGrf); SetChanged(); BroadcastObjectChange(); @@ -835,7 +835,7 @@ void SdrOle2Obj::SetGraphic(const Graphic& rGrf) void SdrOle2Obj::ClearGraphic() { - mpImpl->mxGraphic.reset(); + mpImpl->moGraphic.reset(); SetChanged(); BroadcastObjectChange(); @@ -1318,7 +1318,7 @@ void SdrOle2Obj::SetObjRef( const css::uno::Reference < css::embed::XEmbeddedObj if ( mpImpl->mxObjRef.is() ) { - mpImpl->mxGraphic.reset(); + mpImpl->moGraphic.reset(); if ( mpImpl->mxObjRef->getStatus( GetAspect() ) & embed::EmbedMisc::EMBED_NEVERRESIZE ) SetResizeProtect(true); @@ -1636,7 +1636,7 @@ const Graphic* SdrOle2Obj::GetGraphic() const { if ( mpImpl->mxObjRef.is() ) return mpImpl->mxObjRef.GetGraphic(); - return mpImpl->mxGraphic.get(); + return mpImpl->moGraphic ? &*mpImpl->moGraphic : nullptr; } void SdrOle2Obj::GetNewReplacement() @@ -1823,7 +1823,7 @@ void SdrOle2Obj::SetGraphicToObj( const Graphic& aGraphic ) // if the object isn't valid, e.g. link to something that doesn't exist, set the fallback // graphic as mxGraphic so SdrOle2Obj::GetGraphic will show the fallback if (const Graphic* pObjGraphic = mpImpl->mxObjRef.is() ? nullptr : mpImpl->mxObjRef.GetGraphic()) - mpImpl->mxGraphic.reset(new Graphic(*pObjGraphic)); + mpImpl->moGraphic.emplace(*pObjGraphic); } void SdrOle2Obj::SetGraphicToObj( const uno::Reference< io::XInputStream >& xGrStream, const OUString& aMediaType ) @@ -1832,7 +1832,7 @@ void SdrOle2Obj::SetGraphicToObj( const uno::Reference< io::XInputStream >& xGrS // if the object isn't valid, e.g. link to something that doesn't exist, set the fallback // graphic as mxGraphic so SdrOle2Obj::GetGraphic will show the fallback if (const Graphic* pObjGraphic = mpImpl->mxObjRef.is() ? nullptr : mpImpl->mxObjRef.GetGraphic()) - mpImpl->mxGraphic.reset(new Graphic(*pObjGraphic)); + mpImpl->moGraphic.emplace(*pObjGraphic); } bool SdrOle2Obj::IsCalc() const |