From a08b519ef1fe4dc3ffd6ab8884068b5db38e1100 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Sat, 30 Dec 2023 16:11:04 +0200 Subject: [PATCH] simplify OutlineToImpressFinalizer, no need to use SvLockBytes Change-Id: Iaf83db0631ca0041915ccb61335cf2fc2a2142f3 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161447 Tested-by: Jenkins Reviewed-by: Noel Grandin --- include/svl/lckbitem.hxx | 7 +++-- sd/source/ui/app/sdmod1.cxx | 59 +++++------------------------------ svl/source/items/lckbitem.cxx | 41 +++--------------------- 3 files changed, 15 insertions(+), 92 deletions(-) diff --git a/include/svl/lckbitem.hxx b/include/svl/lckbitem.hxx index 5625a7aac098..af19872d05eb 100644 --- a/include/svl/lckbitem.hxx +++ b/include/svl/lckbitem.hxx @@ -21,11 +21,12 @@ #include #include -#include +#include +// Used by the OutlineToImpress functionality that copies an outline from writer to impress. class SVL_DLLPUBLIC SfxLockBytesItem final : public SfxPoolItem { - SvLockBytesRef _xVal; + css::uno::Sequence< sal_Int8 > mxVal; public: static SfxPoolItem* CreateDefault(); @@ -40,7 +41,7 @@ public: virtual bool operator==( const SfxPoolItem& ) const override; virtual SfxLockBytesItem* Clone( SfxItemPool *pPool = nullptr ) const override; - SvLockBytes* GetValue() const { return _xVal.get(); } + const css::uno::Sequence< sal_Int8 > & GetValue() const { return mxVal; } virtual bool PutValue ( const css::uno::Any& rVal, sal_uInt8 nMemberId ) override; diff --git a/sd/source/ui/app/sdmod1.cxx b/sd/source/ui/app/sdmod1.cxx index d6fc5c406efb..310ee95190ac 100644 --- a/sd/source/ui/app/sdmod1.cxx +++ b/sd/source/ui/app/sdmod1.cxx @@ -65,7 +65,7 @@ public: OutlineToImpressFinalizer ( ::sd::ViewShellBase& rBase, SdDrawDocument& rDocument, - SvLockBytes const & rBytes); + css::uno::Sequence const & rBytes); void operator() (bool bEventSeen); private: ::sd::ViewShellBase& mrBase; @@ -250,9 +250,9 @@ bool SdModule::OutlineToImpress(SfxRequest const & rRequest) if (pSet) { - SvLockBytes* pBytes = static_cast(pSet->Get(SID_OUTLINE_TO_IMPRESS)).GetValue(); + css::uno::Sequence pBytes = static_cast(pSet->Get(SID_OUTLINE_TO_IMPRESS)).GetValue(); - if (pBytes) + if (pBytes.getLength()) { SfxObjectShellLock xDocShell; ::sd::DrawDocShell* pDocSh; @@ -296,7 +296,7 @@ bool SdModule::OutlineToImpress(SfxRequest const & rRequest) FrameworkHelper::CreateResourceId( FrameworkHelper::msOutlineViewURL, FrameworkHelper::msCenterPaneURL), - OutlineToImpressFinalizer(*pBase, *pDoc, *pBytes)); + OutlineToImpressFinalizer(*pBase, *pDoc, pBytes)); } } } @@ -544,58 +544,13 @@ namespace { OutlineToImpressFinalizer::OutlineToImpressFinalizer ( ::sd::ViewShellBase& rBase, SdDrawDocument& rDocument, - SvLockBytes const & rBytes) + css::uno::Sequence const & rBytes) : mrBase(rBase), mrDocument(rDocument) { - // The given stream has a lifetime shorter than this new - // OutlineToImpressFinalizer object. Therefore a local copy of the - // stream is created. - const SvStream* pStream (rBytes.GetStream()); - if (pStream == nullptr) - return; - - // Create a memory stream and prepare to fill it with the content of + // Create a memory stream to fill it with the content of // the original stream. - mpStream = std::make_shared(); - static const std::size_t nBufferSize = 4096; - ::std::unique_ptr pBuffer (new sal_Int8[nBufferSize]); - - sal_uInt64 nReadPosition(0); - bool bLoop (true); - while (bLoop) - { - // Read the next part of the original stream. - std::size_t nReadByteCount (0); - const ErrCode nErrorCode ( - rBytes.ReadAt( - nReadPosition, - pBuffer.get(), - nBufferSize, - &nReadByteCount)); - - // Check the error code and stop copying the stream data when an - // error has occurred. - if (nErrorCode == ERRCODE_NONE) - { - if (nReadByteCount == 0) - bLoop = false; - } - else if (nErrorCode == ERRCODE_IO_PENDING) - ; - else - { - bLoop = false; - nReadByteCount = 0; - } - - // Append the read bytes to the end of the memory stream. - if (nReadByteCount > 0) - { - mpStream->WriteBytes(pBuffer.get(), nReadByteCount); - nReadPosition += nReadByteCount; - } - } + mpStream = std::make_shared(static_cast(const_cast(rBytes.getConstArray())), rBytes.getLength(), StreamMode::READ); // Rewind the memory stream so that in the operator() method its // content is properly read. diff --git a/svl/source/items/lckbitem.cxx b/svl/source/items/lckbitem.cxx index 87165ae50756..425e07fbb734 100644 --- a/svl/source/items/lckbitem.cxx +++ b/svl/source/items/lckbitem.cxx @@ -39,7 +39,7 @@ SfxLockBytesItem::~SfxLockBytesItem() bool SfxLockBytesItem::operator==( const SfxPoolItem& rItem ) const { - return SfxPoolItem::operator==(rItem) && static_cast(rItem)._xVal == _xVal; + return SfxPoolItem::operator==(rItem) && static_cast(rItem).mxVal == mxVal; } SfxLockBytesItem* SfxLockBytesItem::Clone(SfxItemPool *) const @@ -50,52 +50,19 @@ SfxLockBytesItem* SfxLockBytesItem::Clone(SfxItemPool *) const // virtual bool SfxLockBytesItem::PutValue( const css::uno::Any& rVal, sal_uInt8 ) { - css::uno::Sequence< sal_Int8 > aSeq; - if ( rVal >>= aSeq ) + if ( rVal >>= mxVal ) { - if ( aSeq.hasElements() ) - { - SvMemoryStream* pStream = new SvMemoryStream(); - pStream->WriteBytes( aSeq.getConstArray(), aSeq.getLength() ); - pStream->Seek(0); - - _xVal = new SvLockBytes( pStream, true ); - } - else - _xVal = nullptr; - return true; } - OSL_FAIL( "SfxLockBytesItem::PutValue - Wrong type!" ); + assert( false && "SfxLockBytesItem::PutValue - Wrong type!" ); return true; } // virtual bool SfxLockBytesItem::QueryValue( css::uno::Any& rVal, sal_uInt8 ) const { - if ( _xVal.is() ) - { - sal_uInt32 nLen; - SvLockBytesStat aStat; - - if ( _xVal->Stat( &aStat ) == ERRCODE_NONE ) - nLen = aStat.nSize; - else - return false; - - std::size_t nRead = 0; - css::uno::Sequence< sal_Int8 > aSeq( nLen ); - - _xVal->ReadAt( 0, aSeq.getArray(), nLen, &nRead ); - rVal <<= aSeq; - } - else - { - css::uno::Sequence< sal_Int8 > aSeq( 0 ); - rVal <<= aSeq; - } - + rVal <<= mxVal; return true; }