include/svl/lckbitem.hxx | 7 ++-- sd/source/ui/app/sdmod1.cxx | 59 ++++------------------------------------ svl/source/items/lckbitem.cxx | 41 ++------------------------- sw/source/uibase/app/docsh2.cxx | 44 +++++++++-------------------- 4 files changed, 29 insertions(+), 122 deletions(-)
New commits: commit a08b519ef1fe4dc3ffd6ab8884068b5db38e1100 Author: Noel Grandin <noelgran...@gmail.com> AuthorDate: Sat Dec 30 16:11:04 2023 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Sat Dec 30 21:02:51 2023 +0100 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 <noel.gran...@collabora.co.uk> 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 <svl/poolitem.hxx> #include <svl/svldllapi.h> -#include <tools/stream.hxx> +#include <com/sun/star/uno/Sequence.hxx> +// 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<sal_Int8> 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<const SfxLockBytesItem&>(pSet->Get(SID_OUTLINE_TO_IMPRESS)).GetValue(); + css::uno::Sequence<sal_Int8> pBytes = static_cast<const SfxLockBytesItem&>(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<sal_Int8> 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<SvMemoryStream>(); - static const std::size_t nBufferSize = 4096; - ::std::unique_ptr<sal_Int8[]> 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<SvMemoryStream>(static_cast<void*>(const_cast<sal_Int8*>(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<const SfxLockBytesItem&>(rItem)._xVal == _xVal; + return SfxPoolItem::operator==(rItem) && static_cast<const SfxLockBytesItem&>(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; } commit 85aae7580a7cdebc42202c4ee242e076cda7132f Author: Noel Grandin <noelgran...@gmail.com> AuthorDate: Sat Dec 30 15:49:57 2023 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Sat Dec 30 21:02:40 2023 +0100 no need to use SvLockBytes in SwDocShell Change-Id: I5edab742faf2acd3bb0af881e1f96f2ffa3b6f80 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161446 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sw/source/uibase/app/docsh2.cxx b/sw/source/uibase/app/docsh2.cxx index b6ff29b695c4..7079c40a3b99 100644 --- a/sw/source/uibase/app/docsh2.cxx +++ b/sw/source/uibase/app/docsh2.cxx @@ -780,21 +780,13 @@ void SwDocShell::Execute(SfxRequest& rReq) pStrm->WriteChar( ' pStrm->Seek( STREAM_SEEK_TO_BEGIN ); - // Transfer ownership of stream to a lockbytes object - SvLockBytes aLockBytes( pStrm, true ); - SvLockBytesStat aStat; - if ( aLockBytes.Stat( &aStat ) == ERRCODE_NONE ) - { - sal_uInt32 nLen = aStat.nSize; - std::size_t nRead = 0; - uno::Sequence< sal_Int8 > aSeq( nLen ); - aLockBytes.ReadAt( 0, aSeq.getArray(), nLen, &nRead ); - - uno::Sequence< beans::PropertyValue > aArgs{ - comphelper::makePropertyValue("RtfOutline", aSeq) - }; - xHelper->executeDispatch( xProv, "SendOutlineToImpress", OUString(), 0, aArgs ); - } + uno::Sequence< sal_Int8 > aSeq( pStrm->TellEnd() ); + pStrm->ReadBytes( aSeq.getArray(), aSeq.getLength() ); + + uno::Sequence< beans::PropertyValue > aArgs{ + comphelper::makePropertyValue("RtfOutline", aSeq) + }; + xHelper->executeDispatch( xProv, "SendOutlineToImpress", OUString(), 0, aArgs ); } else ErrorHandler::HandleError( eErr ); @@ -844,21 +836,13 @@ void SwDocShell::Execute(SfxRequest& rReq) pStrm->WriteChar( ' pStrm->Seek( STREAM_SEEK_TO_BEGIN ); - // Transfer ownership of stream to a lockbytes object - SvLockBytes aLockBytes( pStrm.release(), true ); - SvLockBytesStat aStat; - if ( aLockBytes.Stat( &aStat ) == ERRCODE_NONE ) - { - sal_uInt32 nLen = aStat.nSize; - std::size_t nRead = 0; - uno::Sequence< sal_Int8 > aSeq( nLen ); - aLockBytes.ReadAt( 0, aSeq.getArray(), nLen, &nRead ); - - uno::Sequence< beans::PropertyValue > aArgs{ - comphelper::makePropertyValue("RtfOutline", aSeq) - }; - xHelper->executeDispatch( xProv, "SendOutlineToImpress", OUString(), 0, aArgs ); - } + uno::Sequence< sal_Int8 > aSeq( pStrm->TellEnd() ); + pStrm->ReadBytes( aSeq.getArray(), aSeq.getLength() ); + + uno::Sequence< beans::PropertyValue > aArgs{ + comphelper::makePropertyValue("RtfOutline", aSeq) + }; + xHelper->executeDispatch( xProv, "SendOutlineToImpress", OUString(), 0, aArgs ); } else {