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.grandin@collabora.co.uk>
This commit is contained in:
parent
85aae7580a
commit
a08b519ef1
3 changed files with 15 additions and 92 deletions
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue