1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: stgole.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sot.hxx"
34 #include "rtl/string.h"
35 #include "rtl/string.h"
37 #include "storinfo.hxx" // Read/WriteClipboardFormat()
39 #include <tools/debug.hxx>
40 #if defined(_MSC_VER) && (_MSC_VER>=1400)
41 #pragma warning(disable: 4342)
43 ///////////////////////// class StgInternalStream ////////////////////////
45 StgInternalStream::StgInternalStream
46 ( BaseStorage
& rStg
, const String
& rName
, BOOL bWr
)
50 ? STREAM_WRITE
| STREAM_SHARE_DENYALL
51 : STREAM_READ
| STREAM_SHARE_DENYWRITE
| STREAM_NOCREATE
;
52 pStrm
= rStg
.OpenStream( rName
, nMode
);
54 // set the error code right here in the stream
55 SetError( rStg
.GetError() );
56 SetBufferSize( 1024 );
59 StgInternalStream::~StgInternalStream()
64 ULONG
StgInternalStream::GetData( void* pData
, ULONG nSize
)
68 nSize
= pStrm
->Read( pData
, nSize
);
69 SetError( pStrm
->GetError() );
76 ULONG
StgInternalStream::PutData( const void* pData
, ULONG nSize
)
80 nSize
= pStrm
->Write( pData
, nSize
);
81 SetError( pStrm
->GetError() );
88 ULONG
StgInternalStream::SeekPos( ULONG nPos
)
90 return pStrm
? pStrm
->Seek( nPos
) : 0;
93 void StgInternalStream::FlushData()
98 SetError( pStrm
->GetError() );
102 void StgInternalStream::Commit()
108 ///////////////////////// class StgCompObjStream /////////////////////////
110 StgCompObjStream::StgCompObjStream( BaseStorage
& rStg
, BOOL bWr
)
111 : StgInternalStream( rStg
, String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "\1CompObj" ) ), bWr
)
113 memset( &aClsId
, 0, sizeof( ClsId
) );
117 BOOL
StgCompObjStream::Load()
119 memset( &aClsId
, 0, sizeof( ClsId
) );
122 if( GetError() != SVSTREAM_OK
)
124 Seek( 8L ); // skip the first part
132 // higher bits are ignored
134 sal_Char
* p
= new sal_Char
[ (USHORT
) nLen1
];
135 if( Read( p
, nLen1
) == (ULONG
) nLen1
)
137 aUserName
= nLen1
? String( p
, gsl_getSystemTextEncoding() ) : String();
138 /* // Now we can read the CB format
145 delete p, p = new char[ nLen2 ];
146 if( Read( p, nLen2 ) == (ULONG) nLen2 && nLen2 )
147 nCbFormat = Exchange::RegisterFormatName( String( p ) );
149 SetError( SVSTREAM_GENERALERROR );
151 else if( nLen2 == -1L )
152 // Windows clipboard format
155 // unknown identifier
156 SetError( SVSTREAM_GENERALERROR );
158 nCbFormat
= ReadClipboardFormat( *this );
161 SetError( SVSTREAM_GENERALERROR
);
164 return BOOL( GetError() == SVSTREAM_OK
);
167 BOOL
StgCompObjStream::Store()
169 if( GetError() != SVSTREAM_OK
)
172 ByteString
aAsciiUserName( aUserName
, RTL_TEXTENCODING_ASCII_US
);
173 *this << (INT16
) 1 // Version?
174 << (INT16
) -2 // 0xFFFE = Byte Order Indicator
175 << (INT32
) 0x0A03 // Windows 3.10
177 << aClsId
// Class ID
178 << (INT32
) (aAsciiUserName
.Len() + 1)
179 << (const char *)aAsciiUserName
.GetBuffer()
180 << (UINT8
) 0; // string terminator
181 /* // determine the clipboard format string
183 if( nCbFormat > FORMAT_GDIMETAFILE )
184 aCbFmt = Exchange::GetFormatName( nCbFormat );
186 *this << (INT32) aCbFmt.Len() + 1
187 << (const char*) aCbFmt
190 *this << (INT32) -1 // for Windows
191 << (INT32) nCbFormat;
193 *this << (INT32) 0; // no clipboard format
195 WriteClipboardFormat( *this, nCbFormat
);
196 *this << (INT32
) 0; // terminator
198 return BOOL( GetError() == SVSTREAM_OK
);
201 /////////////////////////// class StgOleStream ///////////////////////////
203 StgOleStream::StgOleStream( BaseStorage
& rStg
, BOOL bWr
)
204 : StgInternalStream( rStg
, String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "\1Ole" ) ), bWr
)
209 BOOL
StgOleStream::Load()
212 if( GetError() != SVSTREAM_OK
)
216 *this >> version
>> nFlags
;
217 return BOOL( GetError() == SVSTREAM_OK
);
220 BOOL
StgOleStream::Store()
222 if( GetError() != SVSTREAM_OK
)
225 *this << (INT32
) 0x02000001 // OLE version, format
226 << (INT32
) nFlags
// Object flags
227 << (INT32
) 0 // Update Options
228 << (INT32
) 0 // reserved
229 << (INT32
) 0; // Moniker 1
231 return BOOL( GetError() == SVSTREAM_OK
);