Kaydet (Commit) 95a9655a authored tarafından Kai Ahrens's avatar Kai Ahrens

#94204#: write XML stream directly to storage

üst 401f6f58
......@@ -2,9 +2,9 @@
*
* $RCSfile: codec.cxx,v $
*
* $Revision: 1.2 $
* $Revision: 1.3 $
*
* last change: $Author: ka $ $Date: 2001-11-07 08:42:05 $
* last change: $Author: ka $ $Date: 2001-11-08 19:00:17 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
......@@ -106,7 +106,7 @@ BOOL GalleryCodec::IsCoded( SvStream& rStm, UINT32& rVersion )
// -----------------------------------------------------------------------------
ULONG GalleryCodec::Write( SvMemoryStream& rStmToWrite )
void GalleryCodec::Write( SvStream& rStmToWrite )
{
UINT32 nPos, nCompSize;
......@@ -122,23 +122,20 @@ ULONG GalleryCodec::Write( SvMemoryStream& rStmToWrite )
ZCodec aCodec;
aCodec.BeginCompression();
aCodec.Write( rStm, static_cast< const BYTE* >( rStmToWrite.GetData() ), nSize );
aCodec.Compress( rStmToWrite, rStm );
aCodec.EndCompression();
nCompSize = rStm.Tell() - nPos - 4UL;
rStm.Seek( nPos );
rStm << nCompSize;
rStm.Seek( STREAM_SEEK_TO_END );
return 0UL;
}
// -----------------------------------------------------------------------------
ULONG GalleryCodec::Read( SvMemoryStream& rStmToRead )
void GalleryCodec::Read( SvStream& rStmToRead )
{
UINT32 nVersion = 0;
UINT32 nReadBytes = 0;
UINT32 nVersion = 0;
if( IsCoded( rStm, nVersion ) )
{
......@@ -150,78 +147,59 @@ ULONG GalleryCodec::Read( SvMemoryStream& rStmToRead )
// decompress
if( 1 == nVersion )
pUnCompressedBuffer = ImpReadRLEBuffer( rStm, nCompressedSize, nUnCompressedSize );
else if( 2 == nVersion )
pUnCompressedBuffer = ImpReadZBuffer( rStm, nCompressedSize, nUnCompressedSize );
if( pUnCompressedBuffer )
rStmToRead.SetBuffer( reinterpret_cast< char* >( pUnCompressedBuffer ), nUnCompressedSize, TRUE, nUnCompressedSize );
}
return nReadBytes;
}
// -----------------------------------------------------------------------------
BYTE* GalleryCodec::ImpReadRLEBuffer( SvStream& rIStm, ULONG nCompressedSize, ULONG nUnCompressedSize )
{
BYTE* pCompressedBuffer = new BYTE[ nCompressedSize ]; rIStm.Read( pCompressedBuffer, nCompressedSize );
BYTE* pInBuf = pCompressedBuffer;
BYTE* pOutBuf = new BYTE[ nUnCompressedSize ];
BYTE* pTmpBuf = pOutBuf;
BYTE* pLast = pOutBuf + nUnCompressedSize - 1;
ULONG nIndex = 0UL;
ULONG nCountByte;
ULONG nRunByte;
BOOL bEndDecoding = FALSE;
do
{
nCountByte = *pInBuf++;
if ( !nCountByte )
{
nRunByte = *pInBuf++;
if ( nRunByte > 2 )
BYTE* pCompressedBuffer = new BYTE[ nCompressedSize ]; rStm.Read( pCompressedBuffer, nCompressedSize );
BYTE* pInBuf = pCompressedBuffer;
BYTE* pOutBuf = new BYTE[ nUnCompressedSize ];
BYTE* pTmpBuf = pOutBuf;
BYTE* pLast = pOutBuf + nUnCompressedSize - 1;
ULONG nIndex = 0UL, nCountByte, nRunByte;
BOOL bEndDecoding = FALSE;
do
{
// absolutes Fuellen
memcpy( &pTmpBuf[ nIndex ], pInBuf, nRunByte );
pInBuf += nRunByte;
nIndex += nRunByte;
// WORD-Alignment beachten
if ( nRunByte & 1 )
pInBuf++;
nCountByte = *pInBuf++;
if ( !nCountByte )
{
nRunByte = *pInBuf++;
if ( nRunByte > 2 )
{
// absolutes Fuellen
memcpy( &pTmpBuf[ nIndex ], pInBuf, nRunByte );
pInBuf += nRunByte;
nIndex += nRunByte;
// WORD-Alignment beachten
if ( nRunByte & 1 )
pInBuf++;
}
else if ( nRunByte == 1 ) // Ende des Bildes
bEndDecoding = TRUE;
}
else
{
const BYTE cVal = *pInBuf++;
memset( &pTmpBuf[ nIndex ], cVal, nCountByte );
nIndex += nCountByte;
}
}
else if ( nRunByte == 1 ) // Ende des Bildes
bEndDecoding = TRUE;
while ( !bEndDecoding && ( pTmpBuf <= pLast ) );
rStmToRead.Write( pOutBuf, nUnCompressedSize );
delete[] pOutBuf;
delete[] pCompressedBuffer;
}
else
else if( 2 == nVersion )
{
const BYTE cVal = *pInBuf++;
ZCodec aCodec;
memset( &pTmpBuf[ nIndex ], cVal, nCountByte );
nIndex += nCountByte;
aCodec.BeginCompression();
aCodec.Decompress( rStm, rStmToRead );
aCodec.EndCompression();
}
}
while ( !bEndDecoding && ( pTmpBuf <= pLast ) );
delete[] pCompressedBuffer;
return pOutBuf;
}
// -----------------------------------------------------------------------------
BYTE* GalleryCodec::ImpReadZBuffer( SvStream& rIStm, ULONG nCompressedSize, ULONG nUnCompressedSize )
{
ZCodec aCodec;
BYTE* pOutBuf = new BYTE[ nUnCompressedSize ];
aCodec.BeginCompression();
aCodec.Read( rIStm, pOutBuf, nUnCompressedSize );
aCodec.EndCompression();
return pOutBuf;
}
......@@ -2,9 +2,9 @@
*
* $RCSfile: codec.hxx,v $
*
* $Revision: 1.2 $
* $Revision: 1.3 $
*
* last change: $Author: ka $ $Date: 2001-11-07 08:42:05 $
* last change: $Author: ka $ $Date: 2001-11-08 19:00:17 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
......@@ -74,15 +74,12 @@ private:
SvStream& rStm;
BYTE* ImpReadRLEBuffer( SvStream& rIStm, ULONG nCompressedSize, ULONG nUnCompressedSize );
BYTE* ImpReadZBuffer( SvStream& rIStm, ULONG nCompressedSize, ULONG nUnCompressedSize );
public:
GalleryCodec( SvStream& rIOStm );
~GalleryCodec();
ULONG Write( SvMemoryStream& rStmToWrite );
ULONG Read( SvMemoryStream& rStmToRead );
void Write( SvStream& rStmToWrite );
void Read( SvStream& rStmToRead );
static BOOL IsCoded( SvStream& rStm, UINT32& rVersion );
};
......@@ -2,9 +2,9 @@
*
* $RCSfile: galmisc.cxx,v $
*
* $Revision: 1.20 $
* $Revision: 1.21 $
*
* last change: $Author: ka $ $Date: 2001-11-07 08:43:31 $
* last change: $Author: ka $ $Date: 2001-11-08 19:03:02 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
......@@ -306,23 +306,30 @@ BOOL CreateIMapGraphic( const FmFormModel& rModel, Graphic& rGraphic, ImageMap&
// - GetReducedString -
// --------------------
String GetReducedString( const INetURLObject& rURL )
String GetReducedString( const INetURLObject& rURL, ULONG nMaxLen )
{
String aStr;
String aReduced( rURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS ) );
if ( rURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS ).Len() > 30 )
aReduced = aReduced.GetToken( aReduced.GetTokenCount( '/' ) - 1, '/' );
if( INET_PROT_PRIV_SOFFICE != rURL.GetProtocol() )
{
const String aName( rURL.GetName() );
sal_Unicode aDelimiter;
const String aPath( rURL.getFSysPath( INetURLObject::FSYS_DETECT, &aDelimiter ) );
const String aName( aReduced );
aStr = rURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS ).Copy( 0, 30 - aName.Len() - 4 );
aStr += String( RTL_CONSTASCII_USTRINGPARAM( "..." ) );
aStr += '/';
aStr += aName;
if( aPath.Len() > nMaxLen )
{
aReduced = aPath.Copy( 0, (USHORT)( nMaxLen - aName.Len() - 4 ) );
aReduced += String( RTL_CONSTASCII_USTRINGPARAM( "..." ) );
aReduced += aDelimiter;
aReduced += aName;
}
else
aReduced = aPath;
}
else
aStr = rURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS );
return aStr;
return aReduced;
}
// -----------------------------------------------------------------------------
......@@ -536,7 +543,6 @@ GalleryTransferable::GalleryTransferable( GalleryTheme* pTheme, ULONG nObjectPos
mpTheme( pTheme ),
meObjectKind( mpTheme->GetObjectKind( nObjectPos ) ),
mnObjectPos( nObjectPos ),
mpModel( NULL ),
mpGraphicObject( NULL ),
mpImageMap( NULL ),
mpURL( NULL ),
......@@ -586,14 +592,17 @@ void GalleryTransferable::InitData()
{
Graphic aGraphic;
if( mpTheme->GetGraphic( mnObjectPos, aGraphic ) )
mpGraphicObject = new GraphicObject( aGraphic );
mpModel = new FmFormModel;
mpModel->GetItemPool().FreezeIdRanges();
mxModelStream = new SotStorageStream( String() );
mxModelStream->SetBufferSize( 16348 );
if( !mpTheme->GetModel( mnObjectPos, *mpModel ) )
delete mpModel, mpModel = NULL;
if( !mpTheme->GetModelStream( mnObjectPos, mxModelStream ) )
mxModelStream.Clear();
else
mxModelStream->Seek( 0 );
}
break;
......@@ -615,8 +624,9 @@ void GalleryTransferable::AddSupportedFormats()
if( mpURL )
AddFormat( FORMAT_FILE );
if( mpModel )
if( mxModelStream.Is() )
{
/*!!!
Graphic aGraphic;
ImageMap aImageMap;
......@@ -628,6 +638,7 @@ void GalleryTransferable::AddSupportedFormats()
AddFormat( SOT_FORMATSTR_ID_SVIM );
}
else
*/
AddFormat( SOT_FORMATSTR_ID_DRAWING );
}
......@@ -657,9 +668,9 @@ sal_Bool GalleryTransferable::GetData( const ::com::sun::star::datatransfer::Dat
InitData();
if( ( SOT_FORMATSTR_ID_DRAWING == nFormat ) && mpModel )
if( ( SOT_FORMATSTR_ID_DRAWING == nFormat ) && mxModelStream.Is() )
{
bRet = SetObject( mpModel, 0, rFlavor );
bRet = SetObject( &mxModelStream, 0, rFlavor );
}
else if( ( SOT_FORMATSTR_ID_SVIM == nFormat ) && mpImageMap )
{
......@@ -694,21 +705,7 @@ sal_Bool GalleryTransferable::WriteObject( SotStorageStreamRef& rxOStm, void* pU
if( pUserObject )
{
FmFormModel* pModel = static_cast< FmFormModel* >( pUserObject );
pModel->BurnInStyleSheetAttributes();
pModel->SetStreamingSdrModel( TRUE );
pModel->RemoveNotPersistentObjects( TRUE );
rxOStm->SetBufferSize( 16348 );
{
com::sun::star::uno::Reference< com::sun::star::io::XOutputStream > xDocOut( new utl::OOutputStreamWrapper( *rxOStm ) );
if( xDocOut.is() && SvxDrawingLayerExport( pModel, xDocOut ) )
rxOStm->Commit();
}
pModel->SetStreamingSdrModel( FALSE );
*rxOStm << *static_cast< SotStorageStream* >( pUserObject );
bRet = ( rxOStm->GetError() == ERRCODE_NONE );
}
......@@ -727,7 +724,7 @@ void GalleryTransferable::DragFinished( sal_Int8 nDropAction )
void GalleryTransferable::ObjectReleased()
{
delete mpModel, mpModel = NULL;
mxModelStream.Clear();
delete mpGraphicObject, mpGraphicObject = NULL;
delete mpImageMap, mpImageMap = NULL;
delete mpURL, mpURL = NULL;
......@@ -741,6 +738,7 @@ void GalleryTransferable::CopyToClipboard( Window* pWindow )
TransferableHelper::CopyToClipboard( pWindow );
}
// ------------------------------------------------------------------------
void GalleryTransferable::StartDrag( Window* pWindow, sal_Int8 nDragSourceActions,
sal_Int32 nDragPointer, sal_Int32 nDragImage )
......
......@@ -2,9 +2,9 @@
*
* $RCSfile: galtheme.cxx,v $
*
* $Revision: 1.22 $
* $Revision: 1.23 $
*
* last change: $Author: ka $ $Date: 2001-11-07 08:43:31 $
* last change: $Author: ka $ $Date: 2001-11-08 19:03:02 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
......@@ -1031,6 +1031,106 @@ BOOL GalleryTheme::InsertModel( const FmFormModel& rModel, ULONG nInsertPos )
// -----------------------------------------------------------------------------
BOOL GalleryTheme::GetModelStream( ULONG nPos, SotStorageStreamRef& rxModelStream, BOOL bProgress )
{
const GalleryObject* pObject = ImplGetGalleryObject( nPos );
BOOL bRet = FALSE;
if( pObject && ( SGA_OBJ_SVDRAW == pObject->eObjKind ) )
{
const INetURLObject aURL( ImplGetURL( pObject ) );
SvStorageRef xStor( GetSvDrawStorage() );
if( xStor.Is() )
{
const String aStmName( GetSvDrawStreamNameFromURL( aURL ) );
SvStorageStreamRef xIStm( xStor->OpenStream( aStmName, STREAM_READ ) );
if( xIStm.Is() && !xIStm->GetError() )
{
UINT32 nVersion = 0;
xIStm->SetBufferSize( 16348 );
if( GalleryCodec::IsCoded( *xIStm, nVersion ) )
{
if( 1 == nVersion )
{
FmFormModel aModel;
aModel.GetItemPool().FreezeIdRanges();
if( GallerySvDrawImport( *xIStm, aModel ) )
{
aModel.BurnInStyleSheetAttributes();
aModel.SetStreamingSdrModel( TRUE );
aModel.RemoveNotPersistentObjects( TRUE );
{
com::sun::star::uno::Reference<com::sun::star::io::XOutputStream> xDocOut( new utl::OOutputStreamWrapper( *rxModelStream ) );
if( SvxDrawingLayerExport( &aModel, xDocOut ) )
rxModelStream->Commit();
}
aModel.SetStreamingSdrModel( FALSE );
}
}
else if( 2 == nVersion )
{
GalleryCodec aCodec( *xIStm );
aCodec.Read( *rxModelStream );
}
bRet = ( rxModelStream->GetError() == ERRCODE_NONE );
}
xIStm->SetBufferSize( 0 );
}
}
}
return bRet;
}
// -----------------------------------------------------------------------------
BOOL GalleryTheme::InsertModelStream( const SotStorageStreamRef& rxModelStream, ULONG nInsertPos )
{
INetURLObject aURL( ImplCreateUniqueURL( SGA_OBJ_SVDRAW ) );
SvStorageRef xStor( GetSvDrawStorage() );
BOOL bRet = FALSE;
if( xStor.Is() )
{
const String aStmName( GetSvDrawStreamNameFromURL( aURL ) );
SvStorageStreamRef xOStm( xStor->OpenStream( aStmName, STREAM_WRITE | STREAM_TRUNC ) );
if( xOStm.Is() && !xOStm->GetError() )
{
GalleryCodec aCodec( *xOStm );
SvMemoryStream aMemStm( 65535, 65535 );
xOStm->SetBufferSize( 16348 );
aCodec.Write( *rxModelStream );
if( !xOStm->GetError() )
{
xOStm->Seek( 0 );
SgaObjectSvDraw aObjSvDraw( *xOStm, aURL );
bRet = InsertObject( aObjSvDraw, nInsertPos );
}
xOStm->SetBufferSize( 0L );
xOStm->Commit();
}
}
return bRet;
}
// -----------------------------------------------------------------------------
BOOL GalleryTheme::GetURL( ULONG nPos, INetURLObject& rURL, BOOL bProgress )
{
const GalleryObject* pObject = ImplGetGalleryObject( nPos );
......@@ -1091,14 +1191,7 @@ BOOL GalleryTheme::InsertTransferable( const ::com::sun::star::uno::Reference< :
SotStorageStreamRef xModelStm;
if( aDataHelper.GetSotStorageStream( SOT_FORMATSTR_ID_DRAWING, xModelStm ) )
{
FmFormModel aModel;
aModel.GetItemPool().FreezeIdRanges();
if( GallerySvDrawImport( *xModelStm, aModel ) )
bRet = InsertModel( aModel, nInsertPos );
}
bRet = InsertModelStream( xModelStm, nInsertPos );
}
else if( aDataHelper.HasFormat( FORMAT_FILE ) )
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment