fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / sot / source / sdstor / stgole.cxx
blobac7682b4af10435bad76f8045c2eb0f1bee0f835
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
21 #include "stgole.hxx"
22 #include "sot/storinfo.hxx" // Read/WriteClipboardFormat()
24 #ifdef _MSC_VER
25 #pragma warning(disable: 4342)
26 #endif
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()
45 delete pStrm;
48 sal_uLong StgInternalStream::GetData( void* pData, sal_uLong nSize )
50 if( pStrm )
52 nSize = pStrm->Read( pData, nSize );
53 SetError( pStrm->GetError() );
54 return nSize;
56 else
57 return 0;
60 sal_uLong StgInternalStream::PutData( const void* pData, sal_uLong nSize )
62 if( pStrm )
64 nSize = pStrm->Write( pData, nSize );
65 SetError( pStrm->GetError() );
66 return nSize;
68 else
69 return 0;
72 sal_uLong StgInternalStream::SeekPos( sal_uLong nPos )
74 return pStrm ? pStrm->Seek( nPos ) : 0;
77 void StgInternalStream::FlushData()
79 if( pStrm )
81 pStrm->Flush();
82 SetError( pStrm->GetError() );
86 void StgInternalStream::Commit()
88 Flush();
89 pStrm->Commit();
92 ///////////////////////// class StgCompObjStream /////////////////////////
94 StgCompObjStream::StgCompObjStream( BaseStorage& rStg, sal_Bool bWr )
95 : StgInternalStream( rStg, OUString("\1CompObj"), bWr )
97 memset( &aClsId, 0, sizeof( ClsId ) );
98 nCbFormat = 0;
101 sal_Bool StgCompObjStream::Load()
103 memset( &aClsId, 0, sizeof( ClsId ) );
104 nCbFormat = 0;
105 aUserName.Erase();
106 if( GetError() != SVSTREAM_OK )
107 return sal_False;
108 Seek( 8L ); // skip the first part
109 sal_Int32 nMarker = 0;
110 *this >> nMarker;
111 if( nMarker == -1L )
113 *this >> aClsId;
114 sal_Int32 nLen1 = 0;
115 *this >> nLen1;
116 if ( nLen1 > 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 ];
122 p[nStrLen] = 0;
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 );
134 else
135 SetError( SVSTREAM_GENERALERROR );
136 delete [] p;
139 return sal_Bool( GetError() == SVSTREAM_OK );
142 sal_Bool StgCompObjStream::Store()
144 if( GetError() != SVSTREAM_OK )
145 return sal_False;
146 Seek( 0L );
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
151 << (sal_Int32) -1L
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
158 Commit();
159 return sal_Bool( GetError() == SVSTREAM_OK );
162 /////////////////////////// class StgOleStream ///////////////////////////
164 StgOleStream::StgOleStream( BaseStorage& rStg, sal_Bool bWr )
165 : StgInternalStream( rStg, OUString("\1Ole"), bWr )
167 nFlags = 0;
170 sal_Bool StgOleStream::Load()
172 nFlags = 0;
173 if( GetError() != SVSTREAM_OK )
174 return sal_False;
175 sal_Int32 version = 0;
176 Seek( 0L );
177 *this >> version >> nFlags;
178 return sal_Bool( GetError() == SVSTREAM_OK );
181 sal_Bool StgOleStream::Store()
183 if( GetError() != SVSTREAM_OK )
184 return sal_False;
185 Seek( 0L );
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
191 Commit();
192 return sal_Bool( GetError() == SVSTREAM_OK );
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */