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"
25 #pragma warning(disable: 4342)
27 ///////////////////////// class StgInternalStream ////////////////////////
29 StgInternalStream::StgInternalStream( BaseStorage
& rStg
, const OUString
& rName
, bool bWr
)
32 sal_uInt16 nMode
= bWr
33 ? STREAM_WRITE
| STREAM_SHARE_DENYALL
34 : STREAM_READ
| STREAM_SHARE_DENYWRITE
| STREAM_NOCREATE
;
35 pStrm
= rStg
.OpenStream( rName
, nMode
);
37 // set the error code right here in the stream
38 SetError( rStg
.GetError() );
39 SetBufferSize( 1024 );
42 StgInternalStream::~StgInternalStream()
47 sal_uLong
StgInternalStream::GetData( void* pData
, sal_uLong nSize
)
51 nSize
= pStrm
->Read( pData
, nSize
);
52 SetError( pStrm
->GetError() );
59 sal_uLong
StgInternalStream::PutData( const void* pData
, sal_uLong nSize
)
63 nSize
= pStrm
->Write( pData
, nSize
);
64 SetError( pStrm
->GetError() );
71 sal_uLong
StgInternalStream::SeekPos( sal_uLong nPos
)
73 return pStrm
? pStrm
->Seek( nPos
) : 0;
76 void StgInternalStream::FlushData()
81 SetError( pStrm
->GetError() );
85 void StgInternalStream::Commit()
91 ///////////////////////// class StgCompObjStream /////////////////////////
93 StgCompObjStream::StgCompObjStream( BaseStorage
& rStg
, bool bWr
)
94 : StgInternalStream( rStg
, OUString("\1CompObj"), bWr
)
96 memset( &aClsId
, 0, sizeof( ClsId
) );
100 bool StgCompObjStream::Load()
102 memset( &aClsId
, 0, sizeof( ClsId
) );
105 if( GetError() != SVSTREAM_OK
)
107 Seek( 8L ); // skip the first part
108 sal_Int32 nMarker
= 0;
117 // higher bits are ignored
118 sal_uLong nStrLen
= ::std::min( nLen1
, (sal_Int32
)0xFFFE );
120 sal_Char
* p
= new sal_Char
[ nStrLen
+1 ];
122 if( Read( p
, nStrLen
) == nStrLen
)
124 //The encoding here is "ANSI", which is pretty useless seeing as
125 //the actual codepage used doesn't seem to be specified/stored
126 //anywhere :-(. Might as well pick 1252 and be consistent on
127 //all platforms and envs
128 //http://www.openoffice.org/nonav/issues/showattachment.cgi/68668/Orginal%20Document.doc
129 //for a good edge-case example
130 aUserName
= nStrLen
? OUString( p
, nStrLen
, RTL_TEXTENCODING_MS_1252
) : OUString();
131 nCbFormat
= ReadClipboardFormat( *this );
134 SetError( SVSTREAM_GENERALERROR
);
138 return GetError() == SVSTREAM_OK
;
141 bool StgCompObjStream::Store()
143 if( GetError() != SVSTREAM_OK
)
146 OString
aAsciiUserName(OUStringToOString(aUserName
, RTL_TEXTENCODING_MS_1252
));
147 *this << (sal_Int16
) 1 // Version?
148 << (sal_Int16
) -2 // 0xFFFE = Byte Order Indicator
149 << (sal_Int32
) 0x0A03 // Windows 3.10
151 << aClsId
// Class ID
152 << (sal_Int32
) (aAsciiUserName
.getLength() + 1)
153 << (const char *)aAsciiUserName
.getStr()
154 << (sal_uInt8
) 0; // string terminator
155 WriteClipboardFormat( *this, nCbFormat
);
156 *this << (sal_Int32
) 0; // terminator
158 return GetError() == SVSTREAM_OK
;
161 /////////////////////////// class StgOleStream ///////////////////////////
163 StgOleStream::StgOleStream( BaseStorage
& rStg
, bool bWr
)
164 : StgInternalStream( rStg
, OUString("\1Ole"), bWr
)
169 bool StgOleStream::Load()
172 if( GetError() != SVSTREAM_OK
)
175 sal_Int32 version
= 0;
177 *this >> version
>> nFlags
;
178 return GetError() == SVSTREAM_OK
;
181 bool StgOleStream::Store()
183 if( GetError() != SVSTREAM_OK
)
187 *this << (sal_Int32
) 0x02000001 // OLE version, format
188 << (sal_Int32
) nFlags
// Object flags
189 << (sal_Int32
) 0 // Update Options
190 << (sal_Int32
) 0 // reserved
191 << (sal_Int32
) 0; // Moniker 1
193 return GetError() == SVSTREAM_OK
;
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */