1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "rtl/string.h"
22 #include "sot/storinfo.hxx" // Read/WriteClipboardFormat()
25 #pragma warning(disable: 4342)
27 ///////////////////////// class StgInternalStream ////////////////////////
29 StgInternalStream::StgInternalStream
30 ( BaseStorage
& rStg
, const String
& rName
, sal_Bool bWr
)
32 bIsWritable
= sal_True
;
33 sal_uInt16 nMode
= bWr
34 ? STREAM_WRITE
| STREAM_SHARE_DENYALL
35 : STREAM_READ
| STREAM_SHARE_DENYWRITE
| STREAM_NOCREATE
;
36 pStrm
= rStg
.OpenStream( rName
, nMode
);
38 // set the error code right here in the stream
39 SetError( rStg
.GetError() );
40 SetBufferSize( 1024 );
43 StgInternalStream::~StgInternalStream()
48 sal_uLong
StgInternalStream::GetData( void* pData
, sal_uLong nSize
)
52 nSize
= pStrm
->Read( pData
, nSize
);
53 SetError( pStrm
->GetError() );
60 sal_uLong
StgInternalStream::PutData( const void* pData
, sal_uLong nSize
)
64 nSize
= pStrm
->Write( pData
, nSize
);
65 SetError( pStrm
->GetError() );
72 sal_uLong
StgInternalStream::SeekPos( sal_uLong nPos
)
74 return pStrm
? pStrm
->Seek( nPos
) : 0;
77 void StgInternalStream::FlushData()
82 SetError( pStrm
->GetError() );
86 void StgInternalStream::Commit()
92 ///////////////////////// class StgCompObjStream /////////////////////////
94 StgCompObjStream::StgCompObjStream( BaseStorage
& rStg
, sal_Bool bWr
)
95 : StgInternalStream( rStg
, OUString("\1CompObj"), bWr
)
97 memset( &aClsId
, 0, sizeof( ClsId
) );
101 sal_Bool
StgCompObjStream::Load()
103 memset( &aClsId
, 0, sizeof( ClsId
) );
106 if( GetError() != SVSTREAM_OK
)
108 Seek( 8L ); // skip the first part
109 sal_Int32 nMarker
= 0;
118 // higher bits are ignored
119 sal_uLong nStrLen
= ::std::min( nLen1
, (sal_Int32
)0xFFFE );
121 sal_Char
* p
= new sal_Char
[ nStrLen
+1 ];
123 if( Read( p
, nStrLen
) == nStrLen
)
125 //The encoding here is "ANSI", which is pretty useless seeing as
126 //the actual codepage used doesn't seem to be specified/stored
127 //anywhere :-(. Might as well pick 1252 and be consistent on
128 //all platforms and envs
129 //http://www.openoffice.org/nonav/issues/showattachment.cgi/68668/Orginal%20Document.doc
130 //for a good edge-case example
131 aUserName
= nStrLen
? String( p
, RTL_TEXTENCODING_MS_1252
) : String();
132 nCbFormat
= ReadClipboardFormat( *this );
135 SetError( SVSTREAM_GENERALERROR
);
139 return sal_Bool( GetError() == SVSTREAM_OK
);
142 sal_Bool
StgCompObjStream::Store()
144 if( GetError() != SVSTREAM_OK
)
147 OString
aAsciiUserName(OUStringToOString(aUserName
, RTL_TEXTENCODING_MS_1252
));
148 *this << (sal_Int16
) 1 // Version?
149 << (sal_Int16
) -2 // 0xFFFE = Byte Order Indicator
150 << (sal_Int32
) 0x0A03 // Windows 3.10
152 << aClsId
// Class ID
153 << (sal_Int32
) (aAsciiUserName
.getLength() + 1)
154 << (const char *)aAsciiUserName
.getStr()
155 << (sal_uInt8
) 0; // string terminator
156 WriteClipboardFormat( *this, nCbFormat
);
157 *this << (sal_Int32
) 0; // terminator
159 return sal_Bool( GetError() == SVSTREAM_OK
);
162 /////////////////////////// class StgOleStream ///////////////////////////
164 StgOleStream::StgOleStream( BaseStorage
& rStg
, sal_Bool bWr
)
165 : StgInternalStream( rStg
, OUString("\1Ole"), bWr
)
170 sal_Bool
StgOleStream::Load()
173 if( GetError() != SVSTREAM_OK
)
175 sal_Int32 version
= 0;
177 *this >> version
>> nFlags
;
178 return sal_Bool( GetError() == SVSTREAM_OK
);
181 sal_Bool
StgOleStream::Store()
183 if( GetError() != SVSTREAM_OK
)
186 *this << (sal_Int32
) 0x02000001 // OLE version, format
187 << (sal_Int32
) nFlags
// Object flags
188 << (sal_Int32
) 0 // Update Options
189 << (sal_Int32
) 0 // reserved
190 << (sal_Int32
) 0; // Moniker 1
192 return sal_Bool( GetError() == SVSTREAM_OK
);
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */