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 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: codec.cxx,v $ * $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 * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
...@@ -106,7 +106,7 @@ BOOL GalleryCodec::IsCoded( SvStream& rStm, UINT32& rVersion ) ...@@ -106,7 +106,7 @@ BOOL GalleryCodec::IsCoded( SvStream& rStm, UINT32& rVersion )
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
ULONG GalleryCodec::Write( SvMemoryStream& rStmToWrite ) void GalleryCodec::Write( SvStream& rStmToWrite )
{ {
UINT32 nPos, nCompSize; UINT32 nPos, nCompSize;
...@@ -122,23 +122,20 @@ ULONG GalleryCodec::Write( SvMemoryStream& rStmToWrite ) ...@@ -122,23 +122,20 @@ ULONG GalleryCodec::Write( SvMemoryStream& rStmToWrite )
ZCodec aCodec; ZCodec aCodec;
aCodec.BeginCompression(); aCodec.BeginCompression();
aCodec.Write( rStm, static_cast< const BYTE* >( rStmToWrite.GetData() ), nSize ); aCodec.Compress( rStmToWrite, rStm );
aCodec.EndCompression(); aCodec.EndCompression();
nCompSize = rStm.Tell() - nPos - 4UL; nCompSize = rStm.Tell() - nPos - 4UL;
rStm.Seek( nPos ); rStm.Seek( nPos );
rStm << nCompSize; rStm << nCompSize;
rStm.Seek( STREAM_SEEK_TO_END ); rStm.Seek( STREAM_SEEK_TO_END );
return 0UL;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
ULONG GalleryCodec::Read( SvMemoryStream& rStmToRead ) void GalleryCodec::Read( SvStream& rStmToRead )
{ {
UINT32 nVersion = 0; UINT32 nVersion = 0;
UINT32 nReadBytes = 0;
if( IsCoded( rStm, nVersion ) ) if( IsCoded( rStm, nVersion ) )
{ {
...@@ -150,78 +147,59 @@ ULONG GalleryCodec::Read( SvMemoryStream& rStmToRead ) ...@@ -150,78 +147,59 @@ ULONG GalleryCodec::Read( SvMemoryStream& rStmToRead )
// decompress // decompress
if( 1 == nVersion ) 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++; BYTE* pCompressedBuffer = new BYTE[ nCompressedSize ]; rStm.Read( pCompressedBuffer, nCompressedSize );
BYTE* pInBuf = pCompressedBuffer;
if ( nRunByte > 2 ) BYTE* pOutBuf = new BYTE[ nUnCompressedSize ];
BYTE* pTmpBuf = pOutBuf;
BYTE* pLast = pOutBuf + nUnCompressedSize - 1;
ULONG nIndex = 0UL, nCountByte, nRunByte;
BOOL bEndDecoding = FALSE;
do
{ {
// absolutes Fuellen nCountByte = *pInBuf++;
memcpy( &pTmpBuf[ nIndex ], pInBuf, nRunByte );
pInBuf += nRunByte; if ( !nCountByte )
nIndex += nRunByte; {
nRunByte = *pInBuf++;
// WORD-Alignment beachten
if ( nRunByte & 1 ) if ( nRunByte > 2 )
pInBuf++; {
// 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 while ( !bEndDecoding && ( pTmpBuf <= pLast ) );
bEndDecoding = TRUE;
rStmToRead.Write( pOutBuf, nUnCompressedSize );
delete[] pOutBuf;
delete[] pCompressedBuffer;
} }
else else if( 2 == nVersion )
{ {
const BYTE cVal = *pInBuf++; ZCodec aCodec;
memset( &pTmpBuf[ nIndex ], cVal, nCountByte ); aCodec.BeginCompression();
nIndex += nCountByte; 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 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: codec.hxx,v $ * $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 * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
...@@ -74,15 +74,12 @@ private: ...@@ -74,15 +74,12 @@ private:
SvStream& rStm; SvStream& rStm;
BYTE* ImpReadRLEBuffer( SvStream& rIStm, ULONG nCompressedSize, ULONG nUnCompressedSize );
BYTE* ImpReadZBuffer( SvStream& rIStm, ULONG nCompressedSize, ULONG nUnCompressedSize );
public: public:
GalleryCodec( SvStream& rIOStm ); GalleryCodec( SvStream& rIOStm );
~GalleryCodec(); ~GalleryCodec();
ULONG Write( SvMemoryStream& rStmToWrite ); void Write( SvStream& rStmToWrite );
ULONG Read( SvMemoryStream& rStmToRead ); void Read( SvStream& rStmToRead );
static BOOL IsCoded( SvStream& rStm, UINT32& rVersion ); static BOOL IsCoded( SvStream& rStm, UINT32& rVersion );
}; };
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: galmisc.cxx,v $ * $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 * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
...@@ -306,23 +306,30 @@ BOOL CreateIMapGraphic( const FmFormModel& rModel, Graphic& rGraphic, ImageMap& ...@@ -306,23 +306,30 @@ BOOL CreateIMapGraphic( const FmFormModel& rModel, Graphic& rGraphic, ImageMap&
// - GetReducedString - // - 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 ); if( aPath.Len() > nMaxLen )
aStr += String( RTL_CONSTASCII_USTRINGPARAM( "..." ) ); {
aStr += '/'; aReduced = aPath.Copy( 0, (USHORT)( nMaxLen - aName.Len() - 4 ) );
aStr += aName; 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 ...@@ -536,7 +543,6 @@ GalleryTransferable::GalleryTransferable( GalleryTheme* pTheme, ULONG nObjectPos
mpTheme( pTheme ), mpTheme( pTheme ),
meObjectKind( mpTheme->GetObjectKind( nObjectPos ) ), meObjectKind( mpTheme->GetObjectKind( nObjectPos ) ),
mnObjectPos( nObjectPos ), mnObjectPos( nObjectPos ),
mpModel( NULL ),
mpGraphicObject( NULL ), mpGraphicObject( NULL ),
mpImageMap( NULL ), mpImageMap( NULL ),
mpURL( NULL ), mpURL( NULL ),
...@@ -586,14 +592,17 @@ void GalleryTransferable::InitData() ...@@ -586,14 +592,17 @@ void GalleryTransferable::InitData()
{ {
Graphic aGraphic; Graphic aGraphic;
if( mpTheme->GetGraphic( mnObjectPos, aGraphic ) ) if( mpTheme->GetGraphic( mnObjectPos, aGraphic ) )
mpGraphicObject = new GraphicObject( aGraphic ); mpGraphicObject = new GraphicObject( aGraphic );
mpModel = new FmFormModel; mxModelStream = new SotStorageStream( String() );
mpModel->GetItemPool().FreezeIdRanges(); mxModelStream->SetBufferSize( 16348 );
if( !mpTheme->GetModel( mnObjectPos, *mpModel ) ) if( !mpTheme->GetModelStream( mnObjectPos, mxModelStream ) )
delete mpModel, mpModel = NULL; mxModelStream.Clear();
else
mxModelStream->Seek( 0 );
} }
break; break;
...@@ -615,8 +624,9 @@ void GalleryTransferable::AddSupportedFormats() ...@@ -615,8 +624,9 @@ void GalleryTransferable::AddSupportedFormats()
if( mpURL ) if( mpURL )
AddFormat( FORMAT_FILE ); AddFormat( FORMAT_FILE );
if( mpModel ) if( mxModelStream.Is() )
{ {
/*!!!
Graphic aGraphic; Graphic aGraphic;
ImageMap aImageMap; ImageMap aImageMap;
...@@ -628,6 +638,7 @@ void GalleryTransferable::AddSupportedFormats() ...@@ -628,6 +638,7 @@ void GalleryTransferable::AddSupportedFormats()
AddFormat( SOT_FORMATSTR_ID_SVIM ); AddFormat( SOT_FORMATSTR_ID_SVIM );
} }
else else
*/
AddFormat( SOT_FORMATSTR_ID_DRAWING ); AddFormat( SOT_FORMATSTR_ID_DRAWING );
} }
...@@ -657,9 +668,9 @@ sal_Bool GalleryTransferable::GetData( const ::com::sun::star::datatransfer::Dat ...@@ -657,9 +668,9 @@ sal_Bool GalleryTransferable::GetData( const ::com::sun::star::datatransfer::Dat
InitData(); 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 ) else if( ( SOT_FORMATSTR_ID_SVIM == nFormat ) && mpImageMap )
{ {
...@@ -694,21 +705,7 @@ sal_Bool GalleryTransferable::WriteObject( SotStorageStreamRef& rxOStm, void* pU ...@@ -694,21 +705,7 @@ sal_Bool GalleryTransferable::WriteObject( SotStorageStreamRef& rxOStm, void* pU
if( pUserObject ) if( pUserObject )
{ {
FmFormModel* pModel = static_cast< FmFormModel* >( pUserObject ); *rxOStm << *static_cast< SotStorageStream* >( 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 );
bRet = ( rxOStm->GetError() == ERRCODE_NONE ); bRet = ( rxOStm->GetError() == ERRCODE_NONE );
} }
...@@ -727,7 +724,7 @@ void GalleryTransferable::DragFinished( sal_Int8 nDropAction ) ...@@ -727,7 +724,7 @@ void GalleryTransferable::DragFinished( sal_Int8 nDropAction )
void GalleryTransferable::ObjectReleased() void GalleryTransferable::ObjectReleased()
{ {
delete mpModel, mpModel = NULL; mxModelStream.Clear();
delete mpGraphicObject, mpGraphicObject = NULL; delete mpGraphicObject, mpGraphicObject = NULL;
delete mpImageMap, mpImageMap = NULL; delete mpImageMap, mpImageMap = NULL;
delete mpURL, mpURL = NULL; delete mpURL, mpURL = NULL;
...@@ -741,6 +738,7 @@ void GalleryTransferable::CopyToClipboard( Window* pWindow ) ...@@ -741,6 +738,7 @@ void GalleryTransferable::CopyToClipboard( Window* pWindow )
TransferableHelper::CopyToClipboard( pWindow ); TransferableHelper::CopyToClipboard( pWindow );
} }
// ------------------------------------------------------------------------
void GalleryTransferable::StartDrag( Window* pWindow, sal_Int8 nDragSourceActions, void GalleryTransferable::StartDrag( Window* pWindow, sal_Int8 nDragSourceActions,
sal_Int32 nDragPointer, sal_Int32 nDragImage ) sal_Int32 nDragPointer, sal_Int32 nDragImage )
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: galtheme.cxx,v $ * $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 * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
...@@ -1031,6 +1031,106 @@ BOOL GalleryTheme::InsertModel( const FmFormModel& rModel, ULONG nInsertPos ) ...@@ -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 ) BOOL GalleryTheme::GetURL( ULONG nPos, INetURLObject& rURL, BOOL bProgress )
{ {
const GalleryObject* pObject = ImplGetGalleryObject( nPos ); const GalleryObject* pObject = ImplGetGalleryObject( nPos );
...@@ -1091,14 +1191,7 @@ BOOL GalleryTheme::InsertTransferable( const ::com::sun::star::uno::Reference< : ...@@ -1091,14 +1191,7 @@ BOOL GalleryTheme::InsertTransferable( const ::com::sun::star::uno::Reference< :
SotStorageStreamRef xModelStm; SotStorageStreamRef xModelStm;
if( aDataHelper.GetSotStorageStream( SOT_FORMATSTR_ID_DRAWING, xModelStm ) ) if( aDataHelper.GetSotStorageStream( SOT_FORMATSTR_ID_DRAWING, xModelStm ) )
{ bRet = InsertModelStream( xModelStm, nInsertPos );
FmFormModel aModel;
aModel.GetItemPool().FreezeIdRanges();
if( GallerySvDrawImport( *xModelStm, aModel ) )
bRet = InsertModel( aModel, nInsertPos );
}
} }
else if( aDataHelper.HasFormat( FORMAT_FILE ) ) 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