Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <oleembobj.hxx>
30 : : #include <com/sun/star/embed/EmbedStates.hpp>
31 : : #include <com/sun/star/embed/EmbedVerbs.hpp>
32 : : #include <com/sun/star/embed/EntryInitModes.hpp>
33 : : #include <com/sun/star/embed/XStorage.hpp>
34 : : #include <com/sun/star/embed/XTransactedObject.hpp>
35 : : #include <com/sun/star/embed/ElementModes.hpp>
36 : : #include <com/sun/star/embed/EmbedUpdateModes.hpp>
37 : : #include <com/sun/star/embed/Aspects.hpp>
38 : : #include <com/sun/star/embed/XOptimizedStorage.hpp>
39 : : #include <com/sun/star/lang/XComponent.hpp>
40 : : #include <com/sun/star/lang/DisposedException.hpp>
41 : : #include <com/sun/star/container/XNameAccess.hpp>
42 : : #include <com/sun/star/container/XNameContainer.hpp>
43 : : #include <com/sun/star/io/XSeekable.hpp>
44 : : #include <com/sun/star/io/XTruncate.hpp>
45 : : #include <com/sun/star/beans/XPropertySet.hpp>
46 : : #include <com/sun/star/ucb/SimpleFileAccess.hpp>
47 : : #include <com/sun/star/ucb/XSimpleFileAccess2.hpp>
48 : :
49 : : #include <rtl/logfile.hxx>
50 : :
51 : : #include <comphelper/componentcontext.hxx>
52 : : #include <comphelper/storagehelper.hxx>
53 : : #include <comphelper/mimeconfighelper.hxx>
54 : : #include <comphelper/classids.hxx>
55 : :
56 : :
57 : : #include <olecomponent.hxx>
58 : : #include <closepreventer.hxx>
59 : :
60 : : using namespace ::com::sun::star;
61 : : using namespace ::comphelper;
62 : :
63 : : //-------------------------------------------------------------------------
64 : 0 : sal_Bool KillFile_Impl( const ::rtl::OUString& aURL, const uno::Reference< lang::XMultiServiceFactory >& xFactory )
65 : : {
66 [ # # ]: 0 : if ( !xFactory.is() )
67 : 0 : return sal_False;
68 : :
69 : 0 : sal_Bool bRet = sal_False;
70 : :
71 : : try
72 : : {
73 : : uno::Reference < ucb::XSimpleFileAccess2 > xAccess(
74 [ # # ][ # # ]: 0 : ucb::SimpleFileAccess::create( comphelper::ComponentContext(xFactory).getUNOContext() ) );
[ # # ][ # # ]
75 : :
76 [ # # ][ # # ]: 0 : xAccess->kill( aURL );
77 [ # # ]: 0 : bRet = sal_True;
78 : : }
79 : 0 : catch( const uno::Exception& )
80 : : {
81 : : }
82 : :
83 : 0 : return bRet;
84 : : }
85 : :
86 : : //----------------------------------------------
87 : 0 : ::rtl::OUString GetNewTempFileURL_Impl( const uno::Reference< lang::XMultiServiceFactory >& xFactory )
88 : : {
89 : : OSL_ENSURE( xFactory.is(), "No factory is provided!\n" );
90 : :
91 : 0 : ::rtl::OUString aResult;
92 : :
93 : : uno::Reference < beans::XPropertySet > xTempFile(
94 [ # # ]: 0 : xFactory->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.TempFile" ) )),
95 [ # # ][ # # ]: 0 : uno::UNO_QUERY );
[ # # ]
96 : :
97 [ # # ]: 0 : if ( !xTempFile.is() )
98 [ # # ]: 0 : throw uno::RuntimeException(); // TODO
99 : :
100 : : try {
101 [ # # ][ # # ]: 0 : xTempFile->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "RemoveFile" )), uno::makeAny( sal_False ) );
[ # # ][ # # ]
102 [ # # ][ # # ]: 0 : uno::Any aUrl = xTempFile->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Uri" ) ));
[ # # ][ # # ]
103 : 0 : aUrl >>= aResult;
104 : : }
105 [ # # ]: 0 : catch ( const uno::Exception& )
106 : : {
107 : : }
108 : :
109 [ # # ]: 0 : if ( aResult.isEmpty() )
110 [ # # ]: 0 : throw uno::RuntimeException(); // TODO: can not create tempfile
111 : :
112 : 0 : return aResult;
113 : : }
114 : :
115 : : //-----------------------------------------------
116 : 0 : ::rtl::OUString GetNewFilledTempFile_Impl( const uno::Reference< io::XInputStream >& xInStream,
117 : : const uno::Reference< lang::XMultiServiceFactory >& xFactory )
118 : : throw ( io::IOException,
119 : : uno::RuntimeException )
120 : : {
121 : : OSL_ENSURE( xInStream.is() && xFactory.is(), "Wrong parameters are provided!\n" );
122 : :
123 : 0 : ::rtl::OUString aResult = GetNewTempFileURL_Impl( xFactory );
124 : :
125 [ # # ]: 0 : if ( !aResult.isEmpty() )
126 : : {
127 : : try {
128 : : uno::Reference < ucb::XSimpleFileAccess2 > xTempAccess(
129 [ # # ][ # # ]: 0 : ucb::SimpleFileAccess::create( comphelper::ComponentContext(xFactory).getUNOContext() ) );
[ # # ][ # # ]
130 : :
131 [ # # ][ # # ]: 0 : uno::Reference< io::XOutputStream > xTempOutStream = xTempAccess->openFileWrite( aResult );
132 [ # # ]: 0 : if ( xTempOutStream.is() )
133 : : {
134 : : // copy stream contents to the file
135 [ # # ]: 0 : ::comphelper::OStorageHelper::CopyInputToOutput( xInStream, xTempOutStream );
136 [ # # ][ # # ]: 0 : xTempOutStream->closeOutput();
137 [ # # ]: 0 : xTempOutStream = uno::Reference< io::XOutputStream >();
138 : : }
139 : : else
140 [ # # ]: 0 : throw io::IOException(); // TODO:
141 : : }
142 : 0 : catch( const packages::WrongPasswordException& )
143 : : {
144 [ # # ]: 0 : KillFile_Impl( aResult, xFactory );
145 [ # # ]: 0 : throw io::IOException(); //TODO:
146 : : }
147 : 0 : catch( const io::IOException& )
148 : : {
149 [ # # ]: 0 : KillFile_Impl( aResult, xFactory );
150 : 0 : throw;
151 : : }
152 : 0 : catch( const uno::RuntimeException& )
153 : : {
154 [ # # ]: 0 : KillFile_Impl( aResult, xFactory );
155 : 0 : throw;
156 : : }
157 [ # # # # : 0 : catch( const uno::Exception& )
# # # ]
158 : : {
159 [ # # ]: 0 : KillFile_Impl( aResult, xFactory );
160 : 0 : aResult = ::rtl::OUString();
161 : : }
162 : : }
163 : :
164 : 0 : return aResult;
165 : : }
166 : : #ifdef WNT
167 : : ::rtl::OUString GetNewFilledTempFile_Impl( const uno::Reference< embed::XOptimizedStorage >& xParentStorage, const ::rtl::OUString& aEntryName, const uno::Reference< lang::XMultiServiceFactory >& xFactory )
168 : : throw( io::IOException, uno::RuntimeException )
169 : : {
170 : : ::rtl::OUString aResult;
171 : :
172 : : try
173 : : {
174 : : uno::Reference < beans::XPropertySet > xTempFile(
175 : : xFactory->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.TempFile" ) )),
176 : : uno::UNO_QUERY );
177 : : uno::Reference < io::XStream > xTempStream( xTempFile, uno::UNO_QUERY_THROW );
178 : :
179 : : xParentStorage->copyStreamElementData( aEntryName, xTempStream );
180 : :
181 : : xTempFile->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "RemoveFile" )), uno::makeAny( sal_False ) );
182 : : uno::Any aUrl = xTempFile->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Uri" ) ));
183 : : aUrl >>= aResult;
184 : : }
185 : : catch( const uno::RuntimeException& )
186 : : {
187 : : throw;
188 : : }
189 : : catch( const uno::Exception& )
190 : : {
191 : : }
192 : :
193 : : if ( aResult.isEmpty() )
194 : : throw io::IOException();
195 : :
196 : : return aResult;
197 : : }
198 : :
199 : : //------------------------------------------------------
200 : : void SetStreamMediaType_Impl( const uno::Reference< io::XStream >& xStream, const ::rtl::OUString& aMediaType )
201 : : {
202 : : uno::Reference< beans::XPropertySet > xPropSet( xStream, uno::UNO_QUERY );
203 : : if ( !xPropSet.is() )
204 : : throw uno::RuntimeException(); // TODO: all the storage streams must support XPropertySet
205 : :
206 : : xPropSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "MediaType" )), uno::makeAny( aMediaType ) );
207 : : }
208 : : #endif
209 : : //------------------------------------------------------
210 : 0 : void LetCommonStoragePassBeUsed_Impl( const uno::Reference< io::XStream >& xStream )
211 : : {
212 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xPropSet( xStream, uno::UNO_QUERY );
213 [ # # ]: 0 : if ( !xPropSet.is() )
214 [ # # ]: 0 : throw uno::RuntimeException(); // Only StorageStreams must be provided here, they must implement the interface
215 : :
216 [ # # ]: 0 : xPropSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "UseCommonStoragePasswordEncryption" )),
217 [ # # ][ # # ]: 0 : uno::makeAny( (sal_Bool)sal_True ) );
[ # # ]
218 : 0 : }
219 : : #ifdef WNT
220 : : //------------------------------------------------------
221 : : void VerbExecutionController::StartControlExecution()
222 : : {
223 : : osl::MutexGuard aGuard( m_aVerbExecutionMutex );
224 : :
225 : : // the class is used to detect STAMPIT object, that can never be active
226 : : if ( !m_bVerbExecutionInProgress && !m_bWasEverActive )
227 : : {
228 : : m_bVerbExecutionInProgress = sal_True;
229 : : m_nVerbExecutionThreadIdentifier = osl_getThreadIdentifier( NULL );
230 : : m_bChangedOnVerbExecution = sal_False;
231 : : }
232 : : }
233 : :
234 : : //------------------------------------------------------
235 : : sal_Bool VerbExecutionController::EndControlExecution_WasModified()
236 : : {
237 : : osl::MutexGuard aGuard( m_aVerbExecutionMutex );
238 : :
239 : : sal_Bool bResult = sal_False;
240 : : if ( m_bVerbExecutionInProgress && m_nVerbExecutionThreadIdentifier == osl_getThreadIdentifier( NULL ) )
241 : : {
242 : : bResult = m_bChangedOnVerbExecution;
243 : : m_bVerbExecutionInProgress = sal_False;
244 : : }
245 : :
246 : : return bResult;
247 : : }
248 : :
249 : : //------------------------------------------------------
250 : : void VerbExecutionController::ModificationNotificationIsDone()
251 : : {
252 : : osl::MutexGuard aGuard( m_aVerbExecutionMutex );
253 : :
254 : : if ( m_bVerbExecutionInProgress && osl_getThreadIdentifier( NULL ) == m_nVerbExecutionThreadIdentifier )
255 : : m_bChangedOnVerbExecution = sal_True;
256 : : }
257 : : #endif
258 : : //-----------------------------------------------
259 : 0 : void VerbExecutionController::LockNotification()
260 : : {
261 [ # # ]: 0 : osl::MutexGuard aGuard( m_aVerbExecutionMutex );
262 [ # # ]: 0 : if ( m_nNotificationLock < SAL_MAX_INT32 )
263 [ # # ]: 0 : m_nNotificationLock++;
264 : 0 : }
265 : :
266 : : //-----------------------------------------------
267 : 0 : void VerbExecutionController::UnlockNotification()
268 : : {
269 [ # # ]: 0 : osl::MutexGuard aGuard( m_aVerbExecutionMutex );
270 [ # # ]: 0 : if ( m_nNotificationLock > 0 )
271 [ # # ]: 0 : m_nNotificationLock--;
272 : 0 : }
273 : :
274 : : //-----------------------------------------------
275 : 0 : uno::Reference< io::XStream > OleEmbeddedObject::GetNewFilledTempStream_Impl( const uno::Reference< io::XInputStream >& xInStream )
276 : : throw( io::IOException )
277 : : {
278 : : OSL_ENSURE( xInStream.is(), "Wrong parameter is provided!\n" );
279 : :
280 : : uno::Reference < io::XStream > xTempFile(
281 [ # # ]: 0 : m_xFactory->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.TempFile" ) )),
282 [ # # ][ # # ]: 0 : uno::UNO_QUERY_THROW );
[ # # ]
283 : :
284 [ # # ][ # # ]: 0 : uno::Reference< io::XOutputStream > xTempOutStream = xTempFile->getOutputStream();
285 [ # # ]: 0 : if ( xTempOutStream.is() )
286 : : {
287 [ # # ]: 0 : ::comphelper::OStorageHelper::CopyInputToOutput( xInStream, xTempOutStream );
288 [ # # ][ # # ]: 0 : xTempOutStream->flush();
289 : : }
290 : : else
291 [ # # ]: 0 : throw io::IOException(); // TODO:
292 : :
293 : 0 : return xTempFile;
294 : : }
295 : :
296 : : //------------------------------------------------------
297 : 0 : uno::Reference< io::XStream > OleEmbeddedObject::TryToGetAcceptableFormat_Impl( const uno::Reference< io::XStream >& xStream )
298 : : throw ( uno::Exception )
299 : : {
300 : : // TODO/LATER: Actually this should be done by a centralized component ( may be a graphical filter )
301 [ # # ]: 0 : if ( !m_xFactory.is() )
302 [ # # ]: 0 : throw uno::RuntimeException();
303 : :
304 [ # # ][ # # ]: 0 : uno::Reference< io::XInputStream > xInStream = xStream->getInputStream();
305 [ # # ]: 0 : if ( !xInStream.is() )
306 [ # # ]: 0 : throw uno::RuntimeException();
307 : :
308 [ # # ]: 0 : uno::Reference< io::XSeekable > xSeek( xStream, uno::UNO_QUERY_THROW );
309 [ # # ][ # # ]: 0 : xSeek->seek( 0 );
310 : :
311 [ # # ]: 0 : uno::Sequence< sal_Int8 > aData( 8 );
312 [ # # ][ # # ]: 0 : sal_Int32 nRead = xInStream->readBytes( aData, 8 );
313 [ # # ][ # # ]: 0 : xSeek->seek( 0 );
314 : :
315 [ # # ][ # # ]: 0 : if ( ( nRead >= 2 && aData[0] == 'B' && aData[1] == 'M' )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
316 [ # # ][ # # ]: 0 : || ( nRead >= 4 && aData[0] == 1 && aData[1] == 0 && aData[2] == 9 && aData[3] == 0 ) )
[ # # ][ # # ]
317 : : {
318 : : // it should be a bitmap or a Metafile
319 : 0 : return xStream;
320 : : }
321 : :
322 : :
323 : 0 : sal_uInt32 nHeaderOffset = 0;
324 [ # # ][ # # ]: 0 : if ( ( nRead >= 8 && aData[0] == -1 && aData[1] == -1 && aData[2] == -1 && aData[3] == -1 )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
325 [ # # ][ # # ]: 0 : && ( aData[4] == 2 || aData[4] == 3 || aData[4] == 14 ) && aData[5] == 0 && aData[6] == 0 && aData[7] == 0 )
[ # # ][ # # ]
[ # # ][ # # ]
326 : : {
327 : 0 : nHeaderOffset = 40;
328 [ # # ][ # # ]: 0 : xSeek->seek( 8 );
329 : :
330 : : // TargetDevice might be used in future, currently the cache has specified NULL
331 [ # # ]: 0 : uno::Sequence< sal_Int8 > aHeadData( 4 );
332 [ # # ][ # # ]: 0 : nRead = xInStream->readBytes( aHeadData, 4 );
333 : 0 : sal_uInt32 nLen = 0;
334 [ # # ][ # # ]: 0 : if ( nRead == 4 && aHeadData.getLength() == 4 )
[ # # ]
335 [ # # ][ # # ]: 0 : nLen = ( ( ( (sal_uInt32)aHeadData[3] * 0x100 + (sal_uInt32)aHeadData[2] ) * 0x100 ) + (sal_uInt32)aHeadData[1] ) * 0x100 + (sal_uInt32)aHeadData[0];
[ # # ][ # # ]
336 [ # # ]: 0 : if ( nLen > 4 )
337 : : {
338 [ # # ][ # # ]: 0 : xInStream->skipBytes( nLen - 4 );
339 : 0 : nHeaderOffset += nLen - 4;
340 [ # # ]: 0 : }
341 : :
342 : : }
343 [ # # ]: 0 : else if ( nRead > 4 )
344 : : {
345 : : // check whether the first bytes represent the size
346 : 0 : sal_uInt32 nSize = 0;
347 [ # # ]: 0 : for ( sal_Int32 nInd = 3; nInd >= 0; nInd-- )
348 [ # # ]: 0 : nSize = ( nSize << 8 ) + (sal_uInt8)aData[nInd];
349 : :
350 [ # # ][ # # ]: 0 : if ( nSize == xSeek->getLength() - 4 )
[ # # ]
351 : 0 : nHeaderOffset = 4;
352 : : }
353 : :
354 [ # # ]: 0 : if ( nHeaderOffset )
355 : : {
356 : : // this is either a bitmap or a metafile clipboard format, retrieve the pure stream
357 : : uno::Reference < io::XStream > xResult(
358 [ # # ]: 0 : m_xFactory->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.TempFile" ) )),
359 [ # # ][ # # ]: 0 : uno::UNO_QUERY_THROW );
[ # # ]
360 [ # # ]: 0 : uno::Reference < io::XSeekable > xResultSeek( xResult, uno::UNO_QUERY_THROW );
361 [ # # ][ # # ]: 0 : uno::Reference < io::XOutputStream > xResultOut = xResult->getOutputStream();
362 [ # # ][ # # ]: 0 : uno::Reference < io::XInputStream > xResultIn = xResult->getInputStream();
363 [ # # ][ # # ]: 0 : if ( !xResultOut.is() || !xResultIn.is() )
[ # # ]
364 [ # # ]: 0 : throw uno::RuntimeException();
365 : :
366 [ # # ][ # # ]: 0 : xSeek->seek( nHeaderOffset ); // header size for these formats
367 [ # # ]: 0 : ::comphelper::OStorageHelper::CopyInputToOutput( xInStream, xResultOut );
368 [ # # ][ # # ]: 0 : xResultOut->closeOutput();
369 [ # # ][ # # ]: 0 : xResultSeek->seek( 0 );
370 [ # # ][ # # ]: 0 : xSeek->seek( 0 );
371 : :
372 : 0 : return xResult;
373 : : }
374 : :
375 [ # # ]: 0 : return uno::Reference< io::XStream >();
376 : : }
377 : :
378 : : //------------------------------------------------------
379 : 0 : void OleEmbeddedObject::InsertVisualCache_Impl( const uno::Reference< io::XStream >& xTargetStream,
380 : : const uno::Reference< io::XStream >& xCachedVisualRepresentation )
381 : : throw ( uno::Exception )
382 : : {
383 : : OSL_ENSURE( xTargetStream.is() && xCachedVisualRepresentation.is(), "Invalid argumants!\n" );
384 : :
385 [ # # ][ # # ]: 0 : if ( !xTargetStream.is() || !xCachedVisualRepresentation.is() )
[ # # ]
386 [ # # ]: 0 : throw uno::RuntimeException();
387 : :
388 [ # # ]: 0 : uno::Sequence< uno::Any > aArgs( 2 );
389 [ # # ][ # # ]: 0 : aArgs[0] <<= xTargetStream;
390 [ # # ][ # # ]: 0 : aArgs[1] <<= (sal_Bool)sal_True; // do not create copy
391 : :
392 : : uno::Reference< container::XNameContainer > xNameContainer(
393 [ # # ]: 0 : m_xFactory->createInstanceWithArguments(
394 : : ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.embed.OLESimpleStorage" )),
395 : 0 : aArgs ),
396 [ # # ][ # # ]: 0 : uno::UNO_QUERY );
[ # # ]
397 : :
398 [ # # ]: 0 : if ( !xNameContainer.is() )
399 [ # # ]: 0 : throw uno::RuntimeException();
400 : :
401 [ # # ]: 0 : uno::Reference< io::XSeekable > xCachedSeek( xCachedVisualRepresentation, uno::UNO_QUERY_THROW );
402 [ # # ]: 0 : if ( xCachedSeek.is() )
403 [ # # ][ # # ]: 0 : xCachedSeek->seek( 0 );
404 : :
405 : : uno::Reference < io::XStream > xTempFile(
406 [ # # ]: 0 : m_xFactory->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.TempFile" ) )),
407 [ # # ][ # # ]: 0 : uno::UNO_QUERY_THROW );
[ # # ]
408 : :
409 [ # # ]: 0 : uno::Reference< io::XSeekable > xTempSeek( xTempFile, uno::UNO_QUERY_THROW );
410 [ # # ][ # # ]: 0 : uno::Reference< io::XOutputStream > xTempOutStream = xTempFile->getOutputStream();
411 [ # # ]: 0 : if ( xTempOutStream.is() )
412 : : {
413 : : // the OlePres stream must have additional header
414 : : // TODO/LATER: might need to be extended in future ( actually makes sence only for SO7 format )
415 [ # # ][ # # ]: 0 : uno::Reference< io::XInputStream > xInCacheStream = xCachedVisualRepresentation->getInputStream();
416 [ # # ]: 0 : if ( !xInCacheStream.is() )
417 [ # # ]: 0 : throw uno::RuntimeException();
418 : :
419 : : // write 0xFFFFFFFF at the beginning
420 [ # # ]: 0 : uno::Sequence< sal_Int8 > aData( 4 );
421 [ # # ]: 0 : *( (sal_uInt32*)aData.getArray() ) = 0xFFFFFFFF;
422 : :
423 [ # # ][ # # ]: 0 : xTempOutStream->writeBytes( aData );
424 : :
425 : : // write clipboard format
426 [ # # ]: 0 : uno::Sequence< sal_Int8 > aSigData( 2 );
427 [ # # ][ # # ]: 0 : xInCacheStream->readBytes( aSigData, 2 );
428 [ # # ]: 0 : if ( aSigData.getLength() < 2 )
429 [ # # ]: 0 : throw io::IOException();
430 : :
431 [ # # ][ # # ]: 0 : if ( aSigData[0] == 'B' && aSigData[1] == 'M' )
[ # # ][ # # ]
[ # # ]
432 : : {
433 : : // it's a bitmap
434 [ # # ][ # # ]: 0 : aData[0] = 0x02; aData[1] = 0; aData[2] = 0; aData[3] = 0;
[ # # ][ # # ]
435 : : }
436 : : else
437 : : {
438 : : // treat it as a metafile
439 [ # # ][ # # ]: 0 : aData[0] = 0x03; aData[1] = 0; aData[2] = 0; aData[3] = 0;
[ # # ][ # # ]
440 : : }
441 [ # # ][ # # ]: 0 : xTempOutStream->writeBytes( aData );
442 : :
443 : : // write job related information
444 [ # # ][ # # ]: 0 : aData[0] = 0x04; aData[1] = 0; aData[2] = 0; aData[3] = 0;
[ # # ][ # # ]
445 [ # # ][ # # ]: 0 : xTempOutStream->writeBytes( aData );
446 : :
447 : : // write aspect
448 [ # # ][ # # ]: 0 : aData[0] = 0x01; aData[1] = 0; aData[2] = 0; aData[3] = 0;
[ # # ][ # # ]
449 [ # # ][ # # ]: 0 : xTempOutStream->writeBytes( aData );
450 : :
451 : : // write l-index
452 [ # # ]: 0 : *( (sal_uInt32*)aData.getArray() ) = 0xFFFFFFFF;
453 [ # # ][ # # ]: 0 : xTempOutStream->writeBytes( aData );
454 : :
455 : : // write adv. flags
456 [ # # ][ # # ]: 0 : aData[0] = 0x02; aData[1] = 0; aData[2] = 0; aData[3] = 0;
[ # # ][ # # ]
457 [ # # ][ # # ]: 0 : xTempOutStream->writeBytes( aData );
458 : :
459 : : // write compression
460 [ # # ]: 0 : *( (sal_uInt32*)aData.getArray() ) = 0x0;
461 [ # # ][ # # ]: 0 : xTempOutStream->writeBytes( aData );
462 : :
463 : : // get the size
464 [ # # ]: 0 : awt::Size aSize = getVisualAreaSize( embed::Aspects::MSOLE_CONTENT );
465 : 0 : sal_Int32 nIndex = 0;
466 : :
467 : : // write width
468 [ # # ]: 0 : for ( nIndex = 0; nIndex < 4; nIndex++ )
469 : : {
470 [ # # ]: 0 : aData[nIndex] = (sal_Int8)( aSize.Width % 0x100 );
471 : 0 : aSize.Width /= 0x100;
472 : : }
473 [ # # ][ # # ]: 0 : xTempOutStream->writeBytes( aData );
474 : :
475 : : // write height
476 [ # # ]: 0 : for ( nIndex = 0; nIndex < 4; nIndex++ )
477 : : {
478 [ # # ]: 0 : aData[nIndex] = (sal_Int8)( aSize.Height % 0x100 );
479 : 0 : aSize.Height /= 0x100;
480 : : }
481 [ # # ][ # # ]: 0 : xTempOutStream->writeBytes( aData );
482 : :
483 : : // write garbage, it will be overwritten by the size
484 [ # # ][ # # ]: 0 : xTempOutStream->writeBytes( aData );
485 : :
486 : : // write first bytes that was used to detect the type
487 [ # # ][ # # ]: 0 : xTempOutStream->writeBytes( aSigData );
488 : :
489 : : // write the rest of the stream
490 [ # # ]: 0 : ::comphelper::OStorageHelper::CopyInputToOutput( xInCacheStream, xTempOutStream );
491 : :
492 : : // write the size of the stream
493 [ # # ][ # # ]: 0 : sal_Int64 nLength = xTempSeek->getLength() - 40;
494 [ # # ][ # # ]: 0 : if ( nLength < 0 || nLength >= 0xFFFFFFFF )
495 : : {
496 : : OSL_FAIL( "Length is not acceptable!" );
497 : 0 : return;
498 : : }
499 [ # # ]: 0 : for ( sal_Int32 nInd = 0; nInd < 4; nInd++ )
500 : : {
501 [ # # ]: 0 : aData[nInd] = (sal_Int8)( ( (sal_uInt64) nLength ) % 0x100 );
502 : 0 : nLength /= 0x100;
503 : : }
504 [ # # ][ # # ]: 0 : xTempSeek->seek( 36 );
505 [ # # ][ # # ]: 0 : xTempOutStream->writeBytes( aData );
506 : :
507 [ # # ][ # # ]: 0 : xTempOutStream->flush();
508 : :
509 [ # # ][ # # ]: 0 : xTempSeek->seek( 0 );
510 [ # # ]: 0 : if ( xCachedSeek.is() )
511 [ # # ][ # # ]: 0 : xCachedSeek->seek( 0 );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
512 : : }
513 : : else
514 [ # # ]: 0 : throw io::IOException(); // TODO:
515 : :
516 : : // insert the result file as replacement image
517 [ # # ]: 0 : ::rtl::OUString aCacheName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "\002OlePres000" ));
518 [ # # ][ # # ]: 0 : if ( xNameContainer->hasByName( aCacheName ) )
[ # # ]
519 [ # # ][ # # ]: 0 : xNameContainer->replaceByName( aCacheName, uno::makeAny( xTempFile ) );
[ # # ]
520 : : else
521 [ # # ][ # # ]: 0 : xNameContainer->insertByName( aCacheName, uno::makeAny( xTempFile ) );
[ # # ]
522 : :
523 [ # # ]: 0 : uno::Reference< embed::XTransactedObject > xTransacted( xNameContainer, uno::UNO_QUERY );
524 [ # # ]: 0 : if ( !xTransacted.is() )
525 [ # # ]: 0 : throw uno::RuntimeException();
526 : :
527 [ # # ][ # # ]: 0 : xTransacted->commit();
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
528 : : }
529 : :
530 : : //------------------------------------------------------
531 : 0 : void OleEmbeddedObject::RemoveVisualCache_Impl( const uno::Reference< io::XStream >& xTargetStream )
532 : : throw ( uno::Exception )
533 : : {
534 : : OSL_ENSURE( xTargetStream.is(), "Invalid argumant!\n" );
535 [ # # ]: 0 : if ( !xTargetStream.is() )
536 [ # # ]: 0 : throw uno::RuntimeException();
537 : :
538 [ # # ]: 0 : uno::Sequence< uno::Any > aArgs( 2 );
539 [ # # ][ # # ]: 0 : aArgs[0] <<= xTargetStream;
540 [ # # ][ # # ]: 0 : aArgs[1] <<= (sal_Bool)sal_True; // do not create copy
541 : : uno::Reference< container::XNameContainer > xNameContainer(
542 [ # # ]: 0 : m_xFactory->createInstanceWithArguments(
543 : : ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.embed.OLESimpleStorage" )),
544 : 0 : aArgs ),
545 [ # # ][ # # ]: 0 : uno::UNO_QUERY );
[ # # ]
546 : :
547 [ # # ]: 0 : if ( !xNameContainer.is() )
548 [ # # ]: 0 : throw uno::RuntimeException();
549 : :
550 [ # # ]: 0 : for ( sal_uInt8 nInd = 0; nInd < 10; nInd++ )
551 : : {
552 [ # # ]: 0 : ::rtl::OUString aStreamName(RTL_CONSTASCII_USTRINGPARAM( "\002OlePres00" ));
553 : 0 : aStreamName += ::rtl::OUString::valueOf( (sal_Int32)nInd );
554 [ # # ][ # # ]: 0 : if ( xNameContainer->hasByName( aStreamName ) )
[ # # ]
555 [ # # ][ # # ]: 0 : xNameContainer->removeByName( aStreamName );
556 : 0 : }
557 : :
558 [ # # ]: 0 : uno::Reference< embed::XTransactedObject > xTransacted( xNameContainer, uno::UNO_QUERY );
559 [ # # ]: 0 : if ( !xTransacted.is() )
560 [ # # ]: 0 : throw uno::RuntimeException();
561 : :
562 [ # # ][ # # ]: 0 : xTransacted->commit();
[ # # ]
563 : 0 : }
564 : :
565 : : //------------------------------------------------------
566 : 0 : void OleEmbeddedObject::SetVisReplInStream( sal_Bool bExists )
567 : : {
568 : 0 : m_bVisReplInitialized = sal_True;
569 : 0 : m_bVisReplInStream = bExists;
570 : 0 : }
571 : :
572 : : //------------------------------------------------------
573 : 0 : sal_Bool OleEmbeddedObject::HasVisReplInStream()
574 : : {
575 [ # # ]: 0 : if ( !m_bVisReplInitialized )
576 : : {
577 [ # # ]: 0 : if ( m_xCachedVisualRepresentation.is() )
578 : 0 : SetVisReplInStream( sal_True );
579 : : else
580 : : {
581 : : RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObject::HasVisualReplInStream, analizing" );
582 : :
583 : 0 : uno::Reference< io::XInputStream > xStream;
584 : :
585 : : OSL_ENSURE( !m_pOleComponent || !m_aTempURL.isEmpty(), "The temporary file must exist if there is a component!\n" );
586 [ # # ]: 0 : if ( !m_aTempURL.isEmpty() )
587 : : {
588 : : try
589 : : {
590 : : // open temporary file for reading
591 : : uno::Reference < ucb::XSimpleFileAccess2 > xTempAccess(
592 [ # # ][ # # ]: 0 : ucb::SimpleFileAccess::create( comphelper::ComponentContext(m_xFactory).getUNOContext() ) );
[ # # ][ # # ]
593 : :
594 [ # # ][ # # ]: 0 : xStream = xTempAccess->openFileRead( m_aTempURL );
[ # # ][ # # ]
595 : : }
596 [ # # ]: 0 : catch( const uno::Exception& )
597 : : {}
598 : : }
599 : :
600 [ # # ]: 0 : if ( !xStream.is() )
601 [ # # ][ # # ]: 0 : xStream = m_xObjectStream->getInputStream();
[ # # ]
602 : :
603 [ # # ]: 0 : if ( xStream.is() )
604 : : {
605 : 0 : sal_Bool bExists = sal_False;
606 : :
607 [ # # ]: 0 : uno::Sequence< uno::Any > aArgs( 2 );
608 [ # # ][ # # ]: 0 : aArgs[0] <<= xStream;
609 [ # # ][ # # ]: 0 : aArgs[1] <<= (sal_Bool)sal_True; // do not create copy
610 : : uno::Reference< container::XNameContainer > xNameContainer(
611 [ # # ]: 0 : m_xFactory->createInstanceWithArguments(
612 : : ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.embed.OLESimpleStorage" )),
613 : 0 : aArgs ),
614 [ # # ][ # # ]: 0 : uno::UNO_QUERY );
[ # # ][ # # ]
615 : :
616 [ # # ]: 0 : if ( xNameContainer.is() )
617 : : {
618 [ # # ][ # # ]: 0 : for ( sal_uInt8 nInd = 0; nInd < 10 && !bExists; nInd++ )
[ # # ]
619 : : {
620 [ # # ]: 0 : ::rtl::OUString aStreamName(RTL_CONSTASCII_USTRINGPARAM( "\002OlePres00" ));
621 : 0 : aStreamName += ::rtl::OUString::valueOf( (sal_Int32)nInd );
622 : : try
623 : : {
624 [ # # ][ # # ]: 0 : bExists = xNameContainer->hasByName( aStreamName );
625 : : }
626 [ # # ]: 0 : catch( const uno::Exception& )
627 : : {}
628 : 0 : }
629 : : }
630 : :
631 [ # # ]: 0 : SetVisReplInStream( bExists );
632 : 0 : }
633 : : }
634 : : }
635 : :
636 : 0 : return m_bVisReplInStream;
637 : : }
638 : :
639 : : //------------------------------------------------------
640 : 0 : uno::Reference< io::XStream > OleEmbeddedObject::TryToRetrieveCachedVisualRepresentation_Impl(
641 : : const uno::Reference< io::XStream >& xStream,
642 : : sal_Bool bAllowToRepair50 )
643 : : throw ()
644 : : {
645 : 0 : uno::Reference< io::XStream > xResult;
646 : :
647 [ # # ]: 0 : if ( xStream.is() )
648 : : {
649 : : RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObject::TryToRetrieveCachedVisualRepresentation, retrieving" );
650 : :
651 : 0 : uno::Reference< container::XNameContainer > xNameContainer;
652 [ # # ]: 0 : uno::Sequence< uno::Any > aArgs( 2 );
653 [ # # ][ # # ]: 0 : aArgs[0] <<= xStream;
654 [ # # ][ # # ]: 0 : aArgs[1] <<= (sal_Bool)sal_True; // do not create copy
655 : : try
656 : : {
657 : : xNameContainer = uno::Reference< container::XNameContainer >(
658 [ # # ]: 0 : m_xFactory->createInstanceWithArguments(
659 : : ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.embed.OLESimpleStorage" )),
660 : 0 : aArgs ),
661 [ # # ][ # # ]: 0 : uno::UNO_QUERY );
[ # # ][ # # ]
[ # # ]
662 : : }
663 [ # # ]: 0 : catch( const uno::Exception& )
664 : : {}
665 : :
666 [ # # ]: 0 : if ( xNameContainer.is() )
667 : : {
668 [ # # ]: 0 : for ( sal_uInt8 nInd = 0; nInd < 10; nInd++ )
669 : : {
670 [ # # ]: 0 : ::rtl::OUString aStreamName(RTL_CONSTASCII_USTRINGPARAM( "\002OlePres00" ));
671 : 0 : aStreamName += ::rtl::OUString::valueOf( (sal_Int32)nInd );
672 : 0 : uno::Reference< io::XStream > xCachedCopyStream;
673 : : try
674 : : {
675 [ # # ][ # # ]: 0 : if ( ( xNameContainer->getByName( aStreamName ) >>= xCachedCopyStream ) && xCachedCopyStream.is() )
[ # # ][ # # ]
[ # # ]
[ # # # # ]
[ # # ]
676 : : {
677 [ # # ][ # # ]: 0 : xResult = TryToGetAcceptableFormat_Impl( xCachedCopyStream );
[ # # ]
678 [ # # ]: 0 : if ( xResult.is() )
679 : : break;
680 : : }
681 : : }
682 [ # # ]: 0 : catch( const uno::Exception& )
683 : : {}
684 : :
685 [ # # ]: 0 : if ( nInd == 0 )
686 : : {
687 : : // to be compatible with the old versions Ole10Native is checked after OlePress000
688 [ # # ]: 0 : aStreamName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "\001Ole10Native" ) );
689 : : try
690 : : {
691 [ # # ][ # # ]: 0 : if ( ( xNameContainer->getByName( aStreamName ) >>= xCachedCopyStream ) && xCachedCopyStream.is() )
[ # # ][ # # ]
[ # # ]
[ # # # # ]
[ # # ]
692 : : {
693 [ # # ][ # # ]: 0 : xResult = TryToGetAcceptableFormat_Impl( xCachedCopyStream );
[ # # ]
694 [ # # ]: 0 : if ( xResult.is() )
695 : : break;
696 : : }
697 : : }
698 [ # # ]: 0 : catch( const uno::Exception& )
699 : : {}
700 : : }
701 [ # # ][ # # ]: 0 : }
702 : :
703 : : try
704 : : {
705 [ # # ][ # # ]: 0 : if ( bAllowToRepair50 && !xResult.is() )
[ # # ]
706 : : {
707 [ # # ]: 0 : ::rtl::OUString aOrigContName( RTL_CONSTASCII_USTRINGPARAM( "Ole-Object" ) );
708 [ # # ][ # # ]: 0 : if ( xNameContainer->hasByName( aOrigContName ) )
[ # # ]
709 : : {
710 [ # # ]: 0 : uno::Reference< embed::XClassifiedObject > xClassified( xNameContainer, uno::UNO_QUERY_THROW );
711 [ # # ]: 0 : uno::Sequence< sal_Int8 > aClassID;
712 [ # # ][ # # ]: 0 : if ( MimeConfigurationHelper::ClassIDsEqual( xClassified->getClassID(), MimeConfigurationHelper::GetSequenceClassID( SO3_OUT_CLASSID ) ) )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
713 : : {
714 : : // this is an OLE object wrongly stored in 5.0 format
715 : : // this object must be repaired since SO7 has done it
716 : :
717 [ # # ][ # # ]: 0 : uno::Reference< io::XOutputStream > xOutputStream = xStream->getOutputStream();
718 [ # # ]: 0 : uno::Reference< io::XTruncate > xTruncate( xOutputStream, uno::UNO_QUERY_THROW );
719 : :
720 : 0 : uno::Reference< io::XInputStream > xOrigInputStream;
721 [ # # ][ # # ]: 0 : if ( ( xNameContainer->getByName( aOrigContName ) >>= xOrigInputStream )
[ # # # # ]
[ # # ]
[ # # # # ]
[ # # ]
722 : 0 : && xOrigInputStream.is() )
723 : : {
724 : : // the provided input stream must be based on temporary medium and must be independent
725 : : // from the stream the storage is based on
726 [ # # ]: 0 : uno::Reference< io::XSeekable > xOrigSeekable( xOrigInputStream, uno::UNO_QUERY );
727 [ # # ]: 0 : if ( xOrigSeekable.is() )
728 [ # # ][ # # ]: 0 : xOrigSeekable->seek( 0 );
729 : :
730 [ # # ]: 0 : uno::Reference< lang::XComponent > xNameContDisp( xNameContainer, uno::UNO_QUERY_THROW );
731 [ # # ][ # # ]: 0 : xNameContDisp->dispose(); // free the original stream
732 : :
733 [ # # ][ # # ]: 0 : xTruncate->truncate();
734 [ # # ]: 0 : ::comphelper::OStorageHelper::CopyInputToOutput( xOrigInputStream, xOutputStream );
735 [ # # ][ # # ]: 0 : xOutputStream->flush();
736 : :
737 [ # # ][ # # ]: 0 : if ( xStream == m_xObjectStream )
738 : : {
739 [ # # ]: 0 : if ( !m_aTempURL.isEmpty() )
740 : : {
741 : : // this is the own stream, so the temporary URL must be cleaned if it exists
742 [ # # ]: 0 : KillFile_Impl( m_aTempURL, m_xFactory );
743 : 0 : m_aTempURL = ::rtl::OUString();
744 : : }
745 : :
746 : : #ifdef WNT
747 : : // retry to create the component after recovering
748 : : GetRidOfComponent();
749 : :
750 : : try
751 : : {
752 : : CreateOleComponentAndLoad_Impl( NULL );
753 : : m_aClassID = m_pOleComponent->GetCLSID(); // was not set during consruction
754 : : }
755 : : catch( const uno::Exception& )
756 : : {
757 : : GetRidOfComponent();
758 : : }
759 : : #endif
760 : : }
761 : :
762 [ # # ]: 0 : xResult = TryToRetrieveCachedVisualRepresentation_Impl( xStream, sal_False );
763 : 0 : }
764 [ # # ]: 0 : }
765 [ # # ]: 0 : }
766 : : }
767 : : }
768 [ # # ]: 0 : catch( const uno::Exception& )
769 : : {}
770 [ # # ]: 0 : }
771 : : }
772 : :
773 : 0 : return xResult;
774 : : }
775 : :
776 : : //------------------------------------------------------
777 : 0 : void OleEmbeddedObject::SwitchOwnPersistence( const uno::Reference< embed::XStorage >& xNewParentStorage,
778 : : const uno::Reference< io::XStream >& xNewObjectStream,
779 : : const ::rtl::OUString& aNewName )
780 : : {
781 [ # # ][ # # ]: 0 : if ( xNewParentStorage == m_xParentStorage && aNewName.equals( m_aEntryName ) )
[ # # ]
782 : : {
783 : : OSL_ENSURE( xNewObjectStream == m_xObjectStream, "The streams must be the same!\n" );
784 : 0 : return;
785 : : }
786 : :
787 : : try {
788 [ # # ]: 0 : uno::Reference< lang::XComponent > xComponent( m_xObjectStream, uno::UNO_QUERY );
789 : : OSL_ENSURE( !m_xObjectStream.is() || xComponent.is(), "Wrong stream implementation!" );
790 [ # # ]: 0 : if ( xComponent.is() )
791 [ # # ][ # # ]: 0 : xComponent->dispose();
[ # # ]
792 : : }
793 : 0 : catch ( const uno::Exception& )
794 : : {
795 : : }
796 : :
797 : 0 : m_xObjectStream = xNewObjectStream;
798 : 0 : m_xParentStorage = xNewParentStorage;
799 : 0 : m_aEntryName = aNewName;
800 : : }
801 : :
802 : : //------------------------------------------------------
803 : 0 : void OleEmbeddedObject::SwitchOwnPersistence( const uno::Reference< embed::XStorage >& xNewParentStorage,
804 : : const ::rtl::OUString& aNewName )
805 : : {
806 [ # # ][ # # ]: 0 : if ( xNewParentStorage == m_xParentStorage && aNewName.equals( m_aEntryName ) )
[ # # ][ # # ]
807 : 0 : return;
808 : :
809 [ # # ]: 0 : sal_Int32 nStreamMode = m_bReadOnly ? embed::ElementModes::READ : embed::ElementModes::READWRITE;
810 : :
811 [ # # ][ # # ]: 0 : uno::Reference< io::XStream > xNewOwnStream = xNewParentStorage->openStreamElement( aNewName, nStreamMode );
812 : : OSL_ENSURE( xNewOwnStream.is(), "The method can not return empty reference!" );
813 : :
814 [ # # ]: 0 : SwitchOwnPersistence( xNewParentStorage, xNewOwnStream, aNewName );
815 : : }
816 : :
817 : : #ifdef WNT
818 : : //----------------------------------------------
819 : : sal_Bool OleEmbeddedObject::SaveObject_Impl()
820 : : {
821 : : sal_Bool bResult = sal_False;
822 : :
823 : : if ( m_xClientSite.is() )
824 : : {
825 : : try
826 : : {
827 : : m_xClientSite->saveObject();
828 : : bResult = sal_True;
829 : : }
830 : : catch( const uno::Exception& )
831 : : {
832 : : }
833 : : }
834 : :
835 : : return bResult;
836 : : }
837 : :
838 : : //----------------------------------------------
839 : : sal_Bool OleEmbeddedObject::OnShowWindow_Impl( sal_Bool bShow )
840 : : {
841 : : ::osl::ResettableMutexGuard aGuard( m_aMutex );
842 : :
843 : : sal_Bool bResult = sal_False;
844 : :
845 : : OSL_ENSURE( m_nObjectState != -1, "The object has no persistence!\n" );
846 : : OSL_ENSURE( m_nObjectState != embed::EmbedStates::LOADED, "The object get OnShowWindow in loaded state!\n" );
847 : : if ( m_nObjectState == -1 || m_nObjectState == embed::EmbedStates::LOADED )
848 : : return sal_False;
849 : :
850 : : // the object is either activated or deactivated
851 : : sal_Int32 nOldState = m_nObjectState;
852 : : if ( bShow && m_nObjectState == embed::EmbedStates::RUNNING )
853 : : {
854 : : m_nObjectState = embed::EmbedStates::ACTIVE;
855 : : m_aVerbExecutionController.ObjectIsActive();
856 : :
857 : : aGuard.clear();
858 : : StateChangeNotification_Impl( sal_False, nOldState, m_nObjectState );
859 : : }
860 : : else if ( !bShow && m_nObjectState == embed::EmbedStates::ACTIVE )
861 : : {
862 : : m_nObjectState = embed::EmbedStates::RUNNING;
863 : : aGuard.clear();
864 : : StateChangeNotification_Impl( sal_False, nOldState, m_nObjectState );
865 : : }
866 : :
867 : : if ( m_xClientSite.is() )
868 : : {
869 : : try
870 : : {
871 : : m_xClientSite->visibilityChanged( bShow );
872 : : bResult = sal_True;
873 : : }
874 : : catch( const uno::Exception& )
875 : : {
876 : : }
877 : : }
878 : :
879 : : return bResult;
880 : : }
881 : :
882 : : //------------------------------------------------------
883 : : void OleEmbeddedObject::OnIconChanged_Impl()
884 : : {
885 : : // TODO/LATER: currently this notification seems to be impossible
886 : : // MakeEventListenerNotification_Impl( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "OnIconChanged" )) );
887 : : }
888 : :
889 : : //------------------------------------------------------
890 : : void OleEmbeddedObject::OnViewChanged_Impl()
891 : : {
892 : : if ( m_bDisposed )
893 : : throw lang::DisposedException();
894 : :
895 : : // For performance reasons the notification currently is ignored, STAMPIT object is the exception,
896 : : // it can never be active and never call SaveObject, so it is the only way to detect that it is changed
897 : :
898 : : // ==== the STAMPIT related solution =============================
899 : : // the following variable is used to detect whether the object was modified during verb execution
900 : : m_aVerbExecutionController.ModificationNotificationIsDone();
901 : :
902 : : // The following things are controlled by VerbExecutionController:
903 : : // - if the verb execution is in progress and the view is changed the object will be stored
904 : : // after the execution, so there is no need to send the notification.
905 : : // - the STAMPIT object can never be active.
906 : : if ( m_aVerbExecutionController.CanDoNotification()
907 : : && m_pOleComponent && m_nUpdateMode == embed::EmbedUpdateModes::ALWAYS_UPDATE )
908 : : {
909 : : OSL_ENSURE( MimeConfigurationHelper::ClassIDsEqual( m_aClassID, MimeConfigurationHelper::GetSequenceClassID( 0x852ee1c9, 0x9058, 0x44ba, 0x8c,0x6c,0x0c,0x5f,0xc6,0x6b,0xdb,0x8d ) )
910 : : || MimeConfigurationHelper::ClassIDsEqual( m_aClassID, MimeConfigurationHelper::GetSequenceClassID( 0xcf1b4491, 0xbea3, 0x4c9f, 0xa7,0x0f,0x22,0x1b,0x1e,0xca,0xef,0x3e ) ),
911 : : "Expected to be triggered for STAMPIT only! Please contact developers!\n" );
912 : :
913 : : // The view is changed while the object is in running state, save the new object
914 : : m_xCachedVisualRepresentation = uno::Reference< io::XStream >();
915 : : SaveObject_Impl();
916 : : MakeEventListenerNotification_Impl( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "OnVisAreaChanged" )) );
917 : : }
918 : : // ===============================================================
919 : : }
920 : :
921 : : //------------------------------------------------------
922 : : void OleEmbeddedObject::OnClosed_Impl()
923 : : {
924 : : if ( m_bDisposed )
925 : : throw lang::DisposedException();
926 : :
927 : : if ( m_nObjectState != embed::EmbedStates::LOADED )
928 : : {
929 : : sal_Int32 nOldState = m_nObjectState;
930 : : m_nObjectState = embed::EmbedStates::LOADED;
931 : : StateChangeNotification_Impl( sal_False, nOldState, m_nObjectState );
932 : : }
933 : : }
934 : :
935 : : //------------------------------------------------------
936 : : ::rtl::OUString OleEmbeddedObject::CreateTempURLEmpty_Impl()
937 : : {
938 : : OSL_ENSURE( m_aTempURL.isEmpty(), "The object has already the temporary file!" );
939 : : m_aTempURL = GetNewTempFileURL_Impl( m_xFactory );
940 : :
941 : : return m_aTempURL;
942 : : }
943 : :
944 : : //------------------------------------------------------
945 : : ::rtl::OUString OleEmbeddedObject::GetTempURL_Impl()
946 : : {
947 : : if ( m_aTempURL.isEmpty() )
948 : : {
949 : : RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObject::GetTempURL_Impl, tempfile creation" );
950 : :
951 : : // if there is no temporary file, it will be created from the own entry
952 : : uno::Reference< embed::XOptimizedStorage > xOptParStorage( m_xParentStorage, uno::UNO_QUERY );
953 : : if ( xOptParStorage.is() )
954 : : {
955 : : m_aTempURL = GetNewFilledTempFile_Impl( xOptParStorage, m_aEntryName, m_xFactory );
956 : : }
957 : : else if ( m_xObjectStream.is() )
958 : : {
959 : : // load object from the stream
960 : : uno::Reference< io::XInputStream > xInStream = m_xObjectStream->getInputStream();
961 : : if ( !xInStream.is() )
962 : : throw io::IOException(); // TODO: access denied
963 : :
964 : : m_aTempURL = GetNewFilledTempFile_Impl( xInStream, m_xFactory );
965 : : }
966 : : }
967 : :
968 : : return m_aTempURL;
969 : : }
970 : :
971 : : //------------------------------------------------------
972 : : void OleEmbeddedObject::CreateOleComponent_Impl( OleComponent* pOleComponent )
973 : : {
974 : : if ( !m_pOleComponent )
975 : : {
976 : : m_pOleComponent = pOleComponent ? pOleComponent : new OleComponent( m_xFactory, this );
977 : : m_pOleComponent->acquire(); // TODO: needs holder?
978 : :
979 : : if ( !m_xClosePreventer.is() )
980 : : m_xClosePreventer = uno::Reference< util::XCloseListener >(
981 : : static_cast< ::cppu::OWeakObject* >( new OClosePreventer ),
982 : : uno::UNO_QUERY );
983 : :
984 : : m_pOleComponent->addCloseListener( m_xClosePreventer );
985 : : }
986 : : }
987 : :
988 : : //------------------------------------------------------
989 : : void OleEmbeddedObject::CreateOleComponentAndLoad_Impl( OleComponent* pOleComponent )
990 : : {
991 : : if ( !m_pOleComponent )
992 : : {
993 : : if ( !m_xObjectStream.is() )
994 : : throw uno::RuntimeException();
995 : :
996 : : CreateOleComponent_Impl( pOleComponent );
997 : :
998 : : // after the loading the object can appear as a link
999 : : // will be detected later by olecomponent
1000 : :
1001 : : GetTempURL_Impl();
1002 : : if ( m_aTempURL.isEmpty() )
1003 : : throw uno::RuntimeException(); // TODO
1004 : :
1005 : : m_pOleComponent->LoadEmbeddedObject( m_aTempURL );
1006 : : }
1007 : : }
1008 : :
1009 : : //------------------------------------------------------
1010 : : void OleEmbeddedObject::CreateOleComponentFromClipboard_Impl( OleComponent* pOleComponent )
1011 : : {
1012 : : if ( !m_pOleComponent )
1013 : : {
1014 : : if ( !m_xObjectStream.is() )
1015 : : throw uno::RuntimeException();
1016 : :
1017 : : CreateOleComponent_Impl( pOleComponent );
1018 : :
1019 : : // after the loading the object can appear as a link
1020 : : // will be detected later by olecomponent
1021 : : m_pOleComponent->CreateObjectFromClipboard();
1022 : : }
1023 : : }
1024 : :
1025 : : //------------------------------------------------------
1026 : : uno::Reference< io::XOutputStream > OleEmbeddedObject::GetStreamForSaving()
1027 : : {
1028 : : if ( !m_xObjectStream.is() )
1029 : : throw uno::RuntimeException(); //TODO:
1030 : :
1031 : : uno::Reference< io::XOutputStream > xOutStream = m_xObjectStream->getOutputStream();
1032 : : if ( !xOutStream.is() )
1033 : : throw io::IOException(); //TODO: access denied
1034 : :
1035 : : uno::Reference< io::XTruncate > xTruncate( xOutStream, uno::UNO_QUERY );
1036 : : if ( !xTruncate.is() )
1037 : : throw uno::RuntimeException(); //TODO:
1038 : :
1039 : : xTruncate->truncate();
1040 : :
1041 : : return xOutStream;
1042 : : }
1043 : :
1044 : : //----------------------------------------------
1045 : : void OleEmbeddedObject::StoreObjectToStream( uno::Reference< io::XOutputStream > xOutStream )
1046 : : throw ( uno::Exception )
1047 : : {
1048 : : // this method should be used only on windows
1049 : : if ( m_pOleComponent )
1050 : : m_pOleComponent->StoreOwnTmpIfNecessary();
1051 : :
1052 : : // now all the changes should be in temporary location
1053 : : if ( m_aTempURL.isEmpty() )
1054 : : throw uno::RuntimeException();
1055 : :
1056 : : // open temporary file for reading
1057 : : uno::Reference < ucb::XSimpleFileAccess2 > xTempAccess(
1058 : : ucb::SimpleFileAccess::create( comphelper::ComponentContext(m_xFactory).getUNOContext() ) );
1059 : :
1060 : : uno::Reference< io::XInputStream > xTempInStream = xTempAccess->openFileRead( m_aTempURL );
1061 : : OSL_ENSURE( xTempInStream.is(), "The object's temporary file can not be reopened for reading!\n" );
1062 : :
1063 : : // TODO: use bStoreVisReplace
1064 : :
1065 : : if ( xTempInStream.is() )
1066 : : {
1067 : : // write all the contents to XOutStream
1068 : : uno::Reference< io::XTruncate > xTrunc( xOutStream, uno::UNO_QUERY );
1069 : : if ( !xTrunc.is() )
1070 : : throw uno::RuntimeException(); //TODO:
1071 : :
1072 : : xTrunc->truncate();
1073 : :
1074 : : ::comphelper::OStorageHelper::CopyInputToOutput( xTempInStream, xOutStream );
1075 : : }
1076 : : else
1077 : : throw io::IOException(); // TODO:
1078 : :
1079 : : // TODO: should the view replacement be in the stream ???
1080 : : // probably it must be specified on storing
1081 : : }
1082 : : #endif
1083 : : //------------------------------------------------------
1084 : 0 : void OleEmbeddedObject::StoreToLocation_Impl(
1085 : : const uno::Reference< embed::XStorage >& xStorage,
1086 : : const ::rtl::OUString& sEntName,
1087 : : const uno::Sequence< beans::PropertyValue >& lObjArgs,
1088 : : sal_Bool bSaveAs )
1089 : : throw ( uno::Exception )
1090 : : {
1091 : : // TODO: use lObjArgs
1092 : : // TODO: exchange StoreVisualReplacement by SO file format version?
1093 : :
1094 [ # # ]: 0 : if ( m_nObjectState == -1 )
1095 : : {
1096 : : // the object is still not loaded
1097 : : throw embed::WrongStateException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Can't store object without persistence!\n" )),
1098 [ # # ][ # # ]: 0 : uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
[ # # ]
1099 : : }
1100 : :
1101 [ # # ]: 0 : if ( m_bWaitSaveCompleted )
1102 : : throw embed::WrongStateException(
1103 : : ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "The object waits for saveCompleted() call!\n" )),
1104 [ # # ][ # # ]: 0 : uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
[ # # ]
1105 : :
1106 : : OSL_ENSURE( m_xParentStorage.is() && m_xObjectStream.is(), "The object has no valid persistence!\n" );
1107 : :
1108 : 0 : sal_Bool bVisReplIsStored = sal_False;
1109 : :
1110 : 0 : sal_Bool bTryOptimization = sal_False;
1111 : 0 : sal_Bool bStoreVis = m_bStoreVisRepl;
1112 : 0 : uno::Reference< io::XStream > xCachedVisualRepresentation;
1113 [ # # ]: 0 : for ( sal_Int32 nInd = 0; nInd < lObjArgs.getLength(); nInd++ )
1114 : : {
1115 [ # # ]: 0 : if ( lObjArgs[nInd].Name == "StoreVisualReplacement" )
1116 : 0 : lObjArgs[nInd].Value >>= bStoreVis;
1117 [ # # ]: 0 : else if ( lObjArgs[nInd].Name == "VisualReplacement" )
1118 [ # # ]: 0 : lObjArgs[nInd].Value >>= xCachedVisualRepresentation;
1119 [ # # ]: 0 : else if ( lObjArgs[nInd].Name == "CanTryOptimization" )
1120 : 0 : lObjArgs[nInd].Value >>= bTryOptimization;
1121 : : }
1122 : :
1123 : : // ignore visual representation provided from outside if it should not be stored
1124 [ # # ]: 0 : if ( !bStoreVis )
1125 [ # # ]: 0 : xCachedVisualRepresentation = uno::Reference< io::XStream >();
1126 : :
1127 [ # # ][ # # ]: 0 : if ( bStoreVis && !HasVisReplInStream() && !xCachedVisualRepresentation.is() )
[ # # ][ # # ]
[ # # ]
1128 [ # # ]: 0 : throw io::IOException(); // TODO: there is no cached visual representation and nothing is provided from outside
1129 : :
1130 : : // if the representation is provided from outside it should be copied to a local stream
1131 : 0 : sal_Bool bNeedLocalCache = xCachedVisualRepresentation.is();
1132 : :
1133 : 0 : uno::Reference< io::XStream > xTargetStream;
1134 : :
1135 : 0 : sal_Bool bStoreLoaded = sal_False;
1136 [ # # ]: 0 : if ( m_nObjectState == embed::EmbedStates::LOADED
1137 : : #ifdef WNT
1138 : : // if the object was NOT modified after storing it can be just copied
1139 : : // as if it was in loaded state
1140 : : || ( m_pOleComponent && !m_pOleComponent->IsDirty() )
1141 : : #endif
1142 : : )
1143 : : {
1144 : 0 : sal_Bool bOptimizedCopyingDone = sal_False;
1145 : :
1146 [ # # ][ # # ]: 0 : if ( bTryOptimization && bStoreVis == HasVisReplInStream() )
[ # # ][ # # ]
1147 : : {
1148 : : try
1149 : : {
1150 [ # # ]: 0 : uno::Reference< embed::XOptimizedStorage > xSourceOptStor( m_xParentStorage, uno::UNO_QUERY_THROW );
1151 [ # # ]: 0 : uno::Reference< embed::XOptimizedStorage > xTargetOptStor( xStorage, uno::UNO_QUERY_THROW );
1152 [ # # ][ # # ]: 0 : xSourceOptStor->copyElementDirectlyTo( m_aEntryName, xTargetOptStor, sEntName );
1153 [ # # ]: 0 : bOptimizedCopyingDone = sal_True;
1154 : : }
1155 [ # # ]: 0 : catch( const uno::Exception& )
1156 : : {
1157 : : }
1158 : : }
1159 : :
1160 [ # # ]: 0 : if ( !bOptimizedCopyingDone )
1161 : : {
1162 : : // if optimized copying fails a normal one should be tried
1163 [ # # ][ # # ]: 0 : m_xParentStorage->copyElementTo( m_aEntryName, xStorage, sEntName );
1164 : : }
1165 : :
1166 : : // the locally retrieved representation is always preferable
1167 : : // since the object is in loaded state the representation is unchanged
1168 [ # # ]: 0 : if ( m_xCachedVisualRepresentation.is() )
1169 : : {
1170 [ # # ]: 0 : xCachedVisualRepresentation = m_xCachedVisualRepresentation;
1171 : 0 : bNeedLocalCache = sal_False;
1172 : : }
1173 : :
1174 [ # # ]: 0 : bVisReplIsStored = HasVisReplInStream();
1175 : 0 : bStoreLoaded = sal_True;
1176 : : }
1177 : : #ifdef WNT
1178 : : else if ( m_pOleComponent )
1179 : : {
1180 : : xTargetStream =
1181 : : xStorage->openStreamElement( sEntName, embed::ElementModes::READWRITE );
1182 : : if ( !xTargetStream.is() )
1183 : : throw io::IOException(); //TODO: access denied
1184 : :
1185 : : SetStreamMediaType_Impl( xTargetStream, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "application/vnd.sun.star.oleobject" ) ));
1186 : : uno::Reference< io::XOutputStream > xOutStream = xTargetStream->getOutputStream();
1187 : : if ( !xOutStream.is() )
1188 : : throw io::IOException(); //TODO: access denied
1189 : :
1190 : : StoreObjectToStream( xOutStream );
1191 : : bVisReplIsStored = sal_True;
1192 : :
1193 : : if ( bSaveAs )
1194 : : {
1195 : : // no need to do it on StoreTo since in this case the replacement is in the stream
1196 : : // and there is no need to cache it even if it is thrown away because the object
1197 : : // is not changed by StoreTo action
1198 : :
1199 : : uno::Reference< io::XStream > xTmpCVRepresentation =
1200 : : TryToRetrieveCachedVisualRepresentation_Impl( xTargetStream );
1201 : :
1202 : : // the locally retrieved representation is always preferable
1203 : : if ( xTmpCVRepresentation.is() )
1204 : : {
1205 : : xCachedVisualRepresentation = xTmpCVRepresentation;
1206 : : bNeedLocalCache = sal_False;
1207 : : }
1208 : : }
1209 : : }
1210 : : #endif
1211 : : else
1212 : : {
1213 [ # # ]: 0 : throw io::IOException(); // TODO
1214 : : }
1215 : :
1216 [ # # ]: 0 : if ( !xTargetStream.is() )
1217 : : {
1218 : : xTargetStream =
1219 [ # # ][ # # ]: 0 : xStorage->openStreamElement( sEntName, embed::ElementModes::READWRITE );
[ # # ]
1220 [ # # ]: 0 : if ( !xTargetStream.is() )
1221 [ # # ]: 0 : throw io::IOException(); //TODO: access denied
1222 : : }
1223 : :
1224 [ # # ]: 0 : LetCommonStoragePassBeUsed_Impl( xTargetStream );
1225 : :
1226 [ # # ]: 0 : if ( bStoreVis != bVisReplIsStored )
1227 : : {
1228 [ # # ]: 0 : if ( bStoreVis )
1229 : : {
1230 [ # # ]: 0 : if ( !xCachedVisualRepresentation.is() )
1231 [ # # ]: 0 : xCachedVisualRepresentation = TryToRetrieveCachedVisualRepresentation_Impl( xTargetStream );
1232 : :
1233 : : OSL_ENSURE( xCachedVisualRepresentation.is(), "No representation is available!" );
1234 : :
1235 : : // the following copying will be done in case it is SaveAs anyway
1236 : : // if it is not SaveAs the seekable access is not required currently
1237 : : // TODO/LATER: may be required in future
1238 [ # # ]: 0 : if ( bSaveAs )
1239 : : {
1240 [ # # ]: 0 : uno::Reference< io::XSeekable > xCachedSeek( xCachedVisualRepresentation, uno::UNO_QUERY );
1241 [ # # ]: 0 : if ( !xCachedSeek.is() )
1242 : : {
1243 : : xCachedVisualRepresentation
1244 [ # # ][ # # ]: 0 : = GetNewFilledTempStream_Impl( xCachedVisualRepresentation->getInputStream() );
[ # # ][ # # ]
1245 : 0 : bNeedLocalCache = sal_False;
1246 : 0 : }
1247 : : }
1248 : :
1249 [ # # ]: 0 : InsertVisualCache_Impl( xTargetStream, xCachedVisualRepresentation );
1250 : : }
1251 : : else
1252 : : {
1253 : : // the removed representation could be cached by this method
1254 [ # # ]: 0 : if ( !xCachedVisualRepresentation.is() )
1255 [ # # ]: 0 : xCachedVisualRepresentation = TryToRetrieveCachedVisualRepresentation_Impl( xTargetStream );
1256 : :
1257 [ # # ]: 0 : RemoveVisualCache_Impl( xTargetStream );
1258 : : }
1259 : : }
1260 : :
1261 [ # # ]: 0 : if ( bSaveAs )
1262 : : {
1263 : 0 : m_bWaitSaveCompleted = sal_True;
1264 [ # # ]: 0 : m_xNewObjectStream = xTargetStream;
1265 [ # # ]: 0 : m_xNewParentStorage = xStorage;
1266 : 0 : m_aNewEntryName = sEntName;
1267 : 0 : m_bNewVisReplInStream = bStoreVis;
1268 : 0 : m_bStoreLoaded = bStoreLoaded;
1269 : :
1270 [ # # ]: 0 : if ( xCachedVisualRepresentation.is() )
1271 : : {
1272 [ # # ]: 0 : if ( bNeedLocalCache )
1273 [ # # ][ # # ]: 0 : m_xNewCachedVisRepl = GetNewFilledTempStream_Impl( xCachedVisualRepresentation->getInputStream() );
[ # # ][ # # ]
[ # # ]
1274 : : else
1275 [ # # ]: 0 : m_xNewCachedVisRepl = xCachedVisualRepresentation;
1276 : : }
1277 : :
1278 : : // TODO: register listeners for storages above, in case they are disposed
1279 : : // an exception will be thrown on saveCompleted( true )
1280 : : }
1281 : : else
1282 : : {
1283 [ # # ]: 0 : uno::Reference< lang::XComponent > xComp( xTargetStream, uno::UNO_QUERY );
1284 [ # # ]: 0 : if ( xComp.is() )
1285 : : {
1286 : : try {
1287 [ # # ][ # # ]: 0 : xComp->dispose();
1288 [ # # ]: 0 : } catch( const uno::Exception& )
1289 : : {
1290 : : }
1291 : 0 : }
1292 : 0 : }
1293 : 0 : }
1294 : :
1295 : : //------------------------------------------------------
1296 : 0 : void SAL_CALL OleEmbeddedObject::setPersistentEntry(
1297 : : const uno::Reference< embed::XStorage >& xStorage,
1298 : : const ::rtl::OUString& sEntName,
1299 : : sal_Int32 nEntryConnectionMode,
1300 : : const uno::Sequence< beans::PropertyValue >& lArguments,
1301 : : const uno::Sequence< beans::PropertyValue >& lObjArgs )
1302 : : throw ( lang::IllegalArgumentException,
1303 : : embed::WrongStateException,
1304 : : io::IOException,
1305 : : uno::Exception,
1306 : : uno::RuntimeException )
1307 : : {
1308 : : RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObject::setPersistentEntry" );
1309 : :
1310 : : // begin wrapping related part ====================
1311 [ # # ]: 0 : uno::Reference< embed::XEmbedPersist > xWrappedObject( m_xWrappedObject, uno::UNO_QUERY );
1312 [ # # ]: 0 : if ( xWrappedObject.is() )
1313 : : {
1314 : : // the object was converted to OOo embedded object, the current implementation is now only a wrapper
1315 [ # # ][ # # ]: 0 : xWrappedObject->setPersistentEntry( xStorage, sEntName, nEntryConnectionMode, lArguments, lObjArgs );
1316 : 0 : return;
1317 : : }
1318 : : // end wrapping related part ====================
1319 : :
1320 : : // TODO: use lObjArgs
1321 : :
1322 : : // the type of the object must be already set
1323 : : // a kind of typedetection should be done in the factory;
1324 : : // the only exception is object initialized from a stream,
1325 : : // the class ID will be detected from the stream
1326 : :
1327 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
1328 [ # # ]: 0 : if ( m_bDisposed )
1329 [ # # ]: 0 : throw lang::DisposedException(); // TODO
1330 : :
1331 [ # # ]: 0 : if ( !xStorage.is() )
1332 : : throw lang::IllegalArgumentException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "No parent storage is provided!\n" )),
1333 : : uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
1334 [ # # ][ # # ]: 0 : 1 );
[ # # ]
1335 : :
1336 [ # # ]: 0 : if ( sEntName.isEmpty() )
1337 : : throw lang::IllegalArgumentException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Empty element name is provided!\n" )),
1338 : : uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
1339 [ # # ][ # # ]: 0 : 2 );
[ # # ]
1340 : :
1341 : : // May be LOADED should be forbidden here ???
1342 [ # # ][ # # ]: 0 : if ( ( m_nObjectState != -1 || nEntryConnectionMode == embed::EntryInitModes::NO_INIT )
[ # # ][ # # ]
1343 : : && ( m_nObjectState == -1 || nEntryConnectionMode != embed::EntryInitModes::NO_INIT ) )
1344 : : {
1345 : : // if the object is not loaded
1346 : : // it can not get persistant representation without initialization
1347 : :
1348 : : // if the object is loaded
1349 : : // it can switch persistant representation only without initialization
1350 : :
1351 : : throw embed::WrongStateException(
1352 : : ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Can't change persistant representation of activated object!\n" )),
1353 [ # # ][ # # ]: 0 : uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
[ # # ]
1354 : : }
1355 : :
1356 [ # # ]: 0 : if ( m_bWaitSaveCompleted )
1357 : : {
1358 [ # # ]: 0 : if ( nEntryConnectionMode == embed::EntryInitModes::NO_INIT )
1359 [ # # ][ # # ]: 0 : saveCompleted( ( m_xParentStorage != xStorage || !m_aEntryName.equals( sEntName ) ) );
[ # # ][ # # ]
1360 : : else
1361 : : throw embed::WrongStateException(
1362 : : ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "The object waits for saveCompleted() call!\n" )),
1363 [ # # ][ # # ]: 0 : uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
[ # # ]
1364 : : }
1365 : :
1366 [ # # ]: 0 : uno::Reference< container::XNameAccess > xNameAccess( xStorage, uno::UNO_QUERY );
1367 [ # # ]: 0 : if ( !xNameAccess.is() )
1368 [ # # ]: 0 : throw uno::RuntimeException(); //TODO
1369 : :
1370 : : // detect entry existence
1371 [ # # ][ # # ]: 0 : sal_Bool bElExists = xNameAccess->hasByName( sEntName );
1372 : :
1373 : 0 : m_bReadOnly = sal_False;
1374 [ # # ]: 0 : for ( sal_Int32 nInd = 0; nInd < lArguments.getLength(); nInd++ )
1375 [ # # ]: 0 : if ( lArguments[nInd].Name == "ReadOnly" )
1376 : 0 : lArguments[nInd].Value >>= m_bReadOnly;
1377 : :
1378 : : #ifdef WNT
1379 : : sal_Int32 nStorageMode = m_bReadOnly ? embed::ElementModes::READ : embed::ElementModes::READWRITE;
1380 : : #endif
1381 : :
1382 [ # # ]: 0 : SwitchOwnPersistence( xStorage, sEntName );
1383 : :
1384 [ # # ]: 0 : for ( sal_Int32 nInd = 0; nInd < lObjArgs.getLength(); nInd++ )
1385 [ # # ]: 0 : if ( lObjArgs[nInd].Name == "StoreVisualReplacement" )
1386 : 0 : lObjArgs[nInd].Value >>= m_bStoreVisRepl;
1387 : :
1388 : : #ifdef WNT
1389 : : if ( nEntryConnectionMode == embed::EntryInitModes::DEFAULT_INIT )
1390 : : {
1391 : : if ( m_bFromClipboard )
1392 : : {
1393 : : // the object should be initialized from clipboard
1394 : : // inpossibility to initialize the object means error here
1395 : : CreateOleComponentFromClipboard_Impl( NULL );
1396 : : m_aClassID = m_pOleComponent->GetCLSID(); // was not set during consruction
1397 : : m_pOleComponent->RunObject();
1398 : : m_nObjectState = embed::EmbedStates::RUNNING;
1399 : : }
1400 : : else if ( bElExists )
1401 : : {
1402 : : // load object from the stream
1403 : : // after the loading the object can appear as a link
1404 : : // will be detected by olecomponent
1405 : : try
1406 : : {
1407 : : CreateOleComponentAndLoad_Impl( NULL );
1408 : : m_aClassID = m_pOleComponent->GetCLSID(); // was not set during consruction
1409 : : }
1410 : : catch( const uno::Exception& )
1411 : : {
1412 : : // TODO/LATER: detect classID of the object if possible
1413 : : // means that the object inprocess server could not be successfuly instantiated
1414 : : GetRidOfComponent();
1415 : : }
1416 : :
1417 : : m_nObjectState = embed::EmbedStates::LOADED;
1418 : : }
1419 : : else
1420 : : {
1421 : : // create a new object
1422 : : CreateOleComponent_Impl();
1423 : : m_pOleComponent->CreateNewEmbeddedObject( m_aClassID );
1424 : : m_pOleComponent->RunObject();
1425 : : m_nObjectState = embed::EmbedStates::RUNNING;
1426 : : }
1427 : : }
1428 : : else
1429 : : {
1430 : : if ( ( nStorageMode & embed::ElementModes::READWRITE ) != embed::ElementModes::READWRITE )
1431 : : throw io::IOException();
1432 : :
1433 : : if ( nEntryConnectionMode == embed::EntryInitModes::NO_INIT )
1434 : : {
1435 : : // the document just already changed its stream to store to;
1436 : : // the links to OLE documents switch their persistence in the same way
1437 : : // as normal embedded objects
1438 : : }
1439 : : else if ( nEntryConnectionMode == embed::EntryInitModes::TRUNCATE_INIT )
1440 : : {
1441 : : // create a new object, that will be stored in specified stream
1442 : : CreateOleComponent_Impl();
1443 : :
1444 : : m_pOleComponent->CreateNewEmbeddedObject( m_aClassID );
1445 : : m_pOleComponent->RunObject();
1446 : : m_nObjectState = embed::EmbedStates::RUNNING;
1447 : : }
1448 : : else if ( nEntryConnectionMode == embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT )
1449 : : {
1450 : : // use URL ( may be content or stream later ) from MediaDescriptor to initialize object
1451 : : ::rtl::OUString aURL;
1452 : : for ( sal_Int32 nInd = 0; nInd < lArguments.getLength(); nInd++ )
1453 : : if ( lArguments[nInd].Name == "URL" )
1454 : : lArguments[nInd].Value >>= aURL;
1455 : :
1456 : : if ( aURL.isEmpty() )
1457 : : throw lang::IllegalArgumentException(
1458 : : ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Empty URL is provided in the media descriptor!\n" )),
1459 : : uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
1460 : : 4 );
1461 : :
1462 : : CreateOleComponent_Impl();
1463 : :
1464 : : // TODO: the m_bIsLink value must be set already
1465 : : if ( !m_bIsLink )
1466 : : m_pOleComponent->CreateObjectFromFile( aURL );
1467 : : else
1468 : : m_pOleComponent->CreateLinkFromFile( aURL );
1469 : :
1470 : : m_pOleComponent->RunObject();
1471 : : m_aClassID = m_pOleComponent->GetCLSID(); // was not set during consruction
1472 : :
1473 : : m_nObjectState = embed::EmbedStates::RUNNING;
1474 : : }
1475 : : //else if ( nEntryConnectionMode == embed::EntryInitModes::TRANSFERABLE_INIT )
1476 : : //{
1477 : : //TODO:
1478 : : //}
1479 : : else
1480 : : throw lang::IllegalArgumentException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Wrong connection mode is provided!\n" )),
1481 : : uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
1482 : : 3 );
1483 : : }
1484 : : #else
1485 : : // On unix the ole object can not do anything except storing itself somewere
1486 [ # # ][ # # ]: 0 : if ( nEntryConnectionMode == embed::EntryInitModes::DEFAULT_INIT && bElExists )
1487 : : {
1488 : : // TODO/LATER: detect classID of the object
1489 : : // can be a real problem for the links
1490 : :
1491 : 0 : m_nObjectState = embed::EmbedStates::LOADED;
1492 : : }
1493 [ # # ]: 0 : else if ( nEntryConnectionMode == embed::EntryInitModes::NO_INIT )
1494 : : {
1495 : : // do nothing, the object has already switched it's persistence
1496 : : }
1497 : : else
1498 : : throw lang::IllegalArgumentException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Wrong connection mode is provided!\n" )),
1499 : : uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
1500 [ # # ][ # # ]: 0 : 3 );
[ # # ][ # # ]
[ # # ]
1501 : :
1502 : : #endif
1503 : : }
1504 : :
1505 : : //------------------------------------------------------
1506 : 0 : void SAL_CALL OleEmbeddedObject::storeToEntry( const uno::Reference< embed::XStorage >& xStorage,
1507 : : const ::rtl::OUString& sEntName,
1508 : : const uno::Sequence< beans::PropertyValue >& lArguments,
1509 : : const uno::Sequence< beans::PropertyValue >& lObjArgs )
1510 : : throw ( lang::IllegalArgumentException,
1511 : : embed::WrongStateException,
1512 : : io::IOException,
1513 : : uno::Exception,
1514 : : uno::RuntimeException )
1515 : : {
1516 : : RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObject::storeToEntry" );
1517 : :
1518 : : // begin wrapping related part ====================
1519 [ # # ]: 0 : uno::Reference< embed::XEmbedPersist > xWrappedObject( m_xWrappedObject, uno::UNO_QUERY );
1520 [ # # ]: 0 : if ( xWrappedObject.is() )
1521 : : {
1522 : : // the object was converted to OOo embedded object, the current implementation is now only a wrapper
1523 [ # # ][ # # ]: 0 : xWrappedObject->storeToEntry( xStorage, sEntName, lArguments, lObjArgs );
1524 : 0 : return;
1525 : : }
1526 : : // end wrapping related part ====================
1527 : :
1528 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
1529 [ # # ]: 0 : if ( m_bDisposed )
1530 [ # # ]: 0 : throw lang::DisposedException(); // TODO
1531 : :
1532 [ # # ]: 0 : VerbExecutionControllerGuard aVerbGuard( m_aVerbExecutionController );
1533 : :
1534 [ # # ][ # # ]: 0 : StoreToLocation_Impl( xStorage, sEntName, lObjArgs, sal_False );
[ # # ][ # # ]
1535 : :
1536 : : // TODO: should the listener notification be done?
1537 : : }
1538 : :
1539 : : //------------------------------------------------------
1540 : 0 : void SAL_CALL OleEmbeddedObject::storeAsEntry( const uno::Reference< embed::XStorage >& xStorage,
1541 : : const ::rtl::OUString& sEntName,
1542 : : const uno::Sequence< beans::PropertyValue >& lArguments,
1543 : : const uno::Sequence< beans::PropertyValue >& lObjArgs )
1544 : : throw ( lang::IllegalArgumentException,
1545 : : embed::WrongStateException,
1546 : : io::IOException,
1547 : : uno::Exception,
1548 : : uno::RuntimeException )
1549 : : {
1550 : : RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObject::storeAsEntry" );
1551 : :
1552 : : // begin wrapping related part ====================
1553 [ # # ]: 0 : uno::Reference< embed::XEmbedPersist > xWrappedObject( m_xWrappedObject, uno::UNO_QUERY );
1554 [ # # ]: 0 : if ( xWrappedObject.is() )
1555 : : {
1556 : : // the object was converted to OOo embedded object, the current implementation is now only a wrapper
1557 [ # # ][ # # ]: 0 : xWrappedObject->storeAsEntry( xStorage, sEntName, lArguments, lObjArgs );
1558 : 0 : return;
1559 : : }
1560 : : // end wrapping related part ====================
1561 : :
1562 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
1563 [ # # ]: 0 : if ( m_bDisposed )
1564 [ # # ]: 0 : throw lang::DisposedException(); // TODO
1565 : :
1566 [ # # ]: 0 : VerbExecutionControllerGuard aVerbGuard( m_aVerbExecutionController );
1567 : :
1568 [ # # ][ # # ]: 0 : StoreToLocation_Impl( xStorage, sEntName, lObjArgs, sal_True );
[ # # ][ # # ]
1569 : :
1570 : : // TODO: should the listener notification be done here or in saveCompleted?
1571 : : }
1572 : :
1573 : : //------------------------------------------------------
1574 : 0 : void SAL_CALL OleEmbeddedObject::saveCompleted( sal_Bool bUseNew )
1575 : : throw ( embed::WrongStateException,
1576 : : uno::Exception,
1577 : : uno::RuntimeException )
1578 : : {
1579 : : RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObject::saveCompleted" );
1580 : :
1581 : : // begin wrapping related part ====================
1582 [ # # ]: 0 : uno::Reference< embed::XEmbedPersist > xWrappedObject( m_xWrappedObject, uno::UNO_QUERY );
1583 [ # # ]: 0 : if ( xWrappedObject.is() )
1584 : : {
1585 : : // the object was converted to OOo embedded object, the current implementation is now only a wrapper
1586 [ # # ][ # # ]: 0 : xWrappedObject->saveCompleted( bUseNew );
1587 : : return;
1588 : : }
1589 : : // end wrapping related part ====================
1590 : :
1591 [ # # ]: 0 : ::osl::ResettableMutexGuard aGuard( m_aMutex );
1592 [ # # ]: 0 : if ( m_bDisposed )
1593 [ # # ]: 0 : throw lang::DisposedException(); // TODO
1594 : :
1595 [ # # ]: 0 : if ( m_nObjectState == -1 )
1596 : : {
1597 : : // the object is still not loaded
1598 : : throw embed::WrongStateException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Can't store object without persistence!\n" )),
1599 [ # # ][ # # ]: 0 : uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
[ # # ]
1600 : : }
1601 : :
1602 : : // it is allowed to call saveCompleted( false ) for nonstored objects
1603 [ # # ][ # # ]: 0 : if ( !m_bWaitSaveCompleted && !bUseNew )
1604 : : return;
1605 : :
1606 : : OSL_ENSURE( m_bWaitSaveCompleted, "Unexpected saveCompleted() call!\n" );
1607 [ # # ]: 0 : if ( !m_bWaitSaveCompleted )
1608 [ # # ]: 0 : throw io::IOException(); // TODO: illegal call
1609 : :
1610 : : OSL_ENSURE( m_xNewObjectStream.is() && m_xNewParentStorage.is() , "Internal object information is broken!\n" );
1611 [ # # ][ # # ]: 0 : if ( !m_xNewObjectStream.is() || !m_xNewParentStorage.is() )
[ # # ]
1612 [ # # ]: 0 : throw uno::RuntimeException(); // TODO: broken internal information
1613 : :
1614 [ # # ]: 0 : if ( bUseNew )
1615 : : {
1616 [ # # ]: 0 : SwitchOwnPersistence( m_xNewParentStorage, m_xNewObjectStream, m_aNewEntryName );
1617 : 0 : m_bStoreVisRepl = m_bNewVisReplInStream;
1618 : 0 : SetVisReplInStream( m_bNewVisReplInStream );
1619 [ # # ]: 0 : m_xCachedVisualRepresentation = m_xNewCachedVisRepl;
1620 : : }
1621 : : else
1622 : : {
1623 : : // close remembered stream
1624 : : try {
1625 [ # # ]: 0 : uno::Reference< lang::XComponent > xComponent( m_xNewObjectStream, uno::UNO_QUERY );
1626 : : OSL_ENSURE( xComponent.is(), "Wrong storage implementation!" );
1627 [ # # ]: 0 : if ( xComponent.is() )
1628 [ # # ][ # # ]: 0 : xComponent->dispose();
[ # # ]
1629 : : }
1630 [ # # ]: 0 : catch ( const uno::Exception& )
1631 : : {
1632 : : }
1633 : : }
1634 : :
1635 : 0 : sal_Bool bStoreLoaded = m_bStoreLoaded;
1636 : :
1637 [ # # ]: 0 : m_xNewObjectStream = uno::Reference< io::XStream >();
1638 [ # # ]: 0 : m_xNewParentStorage = uno::Reference< embed::XStorage >();
1639 : 0 : m_aNewEntryName = ::rtl::OUString();
1640 : 0 : m_bWaitSaveCompleted = sal_False;
1641 : 0 : m_bNewVisReplInStream = sal_False;
1642 [ # # ][ # # ]: 0 : m_xNewCachedVisRepl = uno::Reference< io::XStream >();
1643 : 0 : m_bStoreLoaded = sal_False;
1644 : :
1645 [ # # ][ # # ]: 0 : if ( bUseNew && m_pOleComponent && m_nUpdateMode == embed::EmbedUpdateModes::ALWAYS_UPDATE && !bStoreLoaded
[ # # ][ # # ]
[ # # ]
1646 : : && m_nObjectState != embed::EmbedStates::LOADED )
1647 : : {
1648 : : // the object replacement image should be updated, so the cached size as well
1649 : 0 : m_bHasCachedSize = sal_False;
1650 : : try
1651 : : {
1652 : : // the call will cache the size in case of success
1653 : : // probably it might need to be done earlier, while the object is in active state
1654 [ # # ]: 0 : getVisualAreaSize( embed::Aspects::MSOLE_CONTENT );
1655 : : }
1656 [ # # ]: 0 : catch( const uno::Exception& )
1657 : : {}
1658 : : }
1659 : :
1660 [ # # ]: 0 : aGuard.clear();
1661 [ # # ]: 0 : if ( bUseNew )
1662 : : {
1663 [ # # ][ # # ]: 0 : MakeEventListenerNotification_Impl( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "OnSaveAsDone" ) ));
1664 : :
1665 : : // the object can be changed only on windows
1666 : : // the notification should be done only if the object is not in loaded state
1667 [ # # ][ # # ]: 0 : if ( m_pOleComponent && m_nUpdateMode == embed::EmbedUpdateModes::ALWAYS_UPDATE && !bStoreLoaded )
[ # # ]
1668 : : {
1669 [ # # ][ # # ]: 0 : MakeEventListenerNotification_Impl( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "OnVisAreaChanged" ) ));
1670 : : }
1671 [ # # ][ # # ]: 0 : }
[ # # ]
1672 : : }
1673 : :
1674 : : //------------------------------------------------------
1675 : 0 : sal_Bool SAL_CALL OleEmbeddedObject::hasEntry()
1676 : : throw ( embed::WrongStateException,
1677 : : uno::RuntimeException )
1678 : : {
1679 : : // begin wrapping related part ====================
1680 [ # # ]: 0 : uno::Reference< embed::XEmbedPersist > xWrappedObject( m_xWrappedObject, uno::UNO_QUERY );
1681 [ # # ]: 0 : if ( xWrappedObject.is() )
1682 : : {
1683 : : // the object was converted to OOo embedded object, the current implementation is now only a wrapper
1684 [ # # ][ # # ]: 0 : return xWrappedObject->hasEntry();
1685 : : }
1686 : : // end wrapping related part ====================
1687 : :
1688 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
1689 [ # # ]: 0 : if ( m_bDisposed )
1690 [ # # ]: 0 : throw lang::DisposedException(); // TODO
1691 : :
1692 [ # # ]: 0 : if ( m_bWaitSaveCompleted )
1693 : : throw embed::WrongStateException(
1694 : : ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "The object waits for saveCompleted() call!\n" )),
1695 [ # # ][ # # ]: 0 : uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
[ # # ]
1696 : :
1697 [ # # ]: 0 : if ( m_xObjectStream.is() )
1698 : 0 : return sal_True;
1699 : :
1700 [ # # ]: 0 : return sal_False;
1701 : : }
1702 : :
1703 : : //------------------------------------------------------
1704 : 0 : ::rtl::OUString SAL_CALL OleEmbeddedObject::getEntryName()
1705 : : throw ( embed::WrongStateException,
1706 : : uno::RuntimeException )
1707 : : {
1708 : : // begin wrapping related part ====================
1709 [ # # ]: 0 : uno::Reference< embed::XEmbedPersist > xWrappedObject( m_xWrappedObject, uno::UNO_QUERY );
1710 [ # # ]: 0 : if ( xWrappedObject.is() )
1711 : : {
1712 : : // the object was converted to OOo embedded object, the current implementation is now only a wrapper
1713 [ # # ][ # # ]: 0 : return xWrappedObject->getEntryName();
1714 : : }
1715 : : // end wrapping related part ====================
1716 : :
1717 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
1718 [ # # ]: 0 : if ( m_bDisposed )
1719 [ # # ]: 0 : throw lang::DisposedException(); // TODO
1720 : :
1721 [ # # ]: 0 : if ( m_nObjectState == -1 )
1722 : : {
1723 : : // the object is still not loaded
1724 : : throw embed::WrongStateException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "The object persistence is not initialized!\n" )),
1725 [ # # ][ # # ]: 0 : uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
[ # # ]
1726 : : }
1727 : :
1728 [ # # ]: 0 : if ( m_bWaitSaveCompleted )
1729 : : throw embed::WrongStateException(
1730 : : ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "The object waits for saveCompleted() call!\n" )),
1731 [ # # ][ # # ]: 0 : uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
[ # # ]
1732 : :
1733 [ # # ]: 0 : return m_aEntryName;
1734 : : }
1735 : :
1736 : :
1737 : : //------------------------------------------------------
1738 : 0 : void SAL_CALL OleEmbeddedObject::storeOwn()
1739 : : throw ( embed::WrongStateException,
1740 : : io::IOException,
1741 : : uno::Exception,
1742 : : uno::RuntimeException )
1743 : : {
1744 : : RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObject::storeOwn" );
1745 : :
1746 : : // begin wrapping related part ====================
1747 [ # # ]: 0 : uno::Reference< embed::XEmbedPersist > xWrappedObject( m_xWrappedObject, uno::UNO_QUERY );
1748 [ # # ]: 0 : if ( xWrappedObject.is() )
1749 : : {
1750 : : // the object was converted to OOo embedded object, the current implementation is now only a wrapper
1751 [ # # ][ # # ]: 0 : xWrappedObject->storeOwn();
1752 : 0 : return;
1753 : : }
1754 : : // end wrapping related part ====================
1755 : :
1756 : : // during switching from Activated to Running and from Running to Loaded states the object will
1757 : : // ask container to store the object, the container has to make decision
1758 : : // to do so or not
1759 : :
1760 [ # # ]: 0 : ::osl::ResettableMutexGuard aGuard( m_aMutex );
1761 [ # # ]: 0 : if ( m_bDisposed )
1762 [ # # ]: 0 : throw lang::DisposedException(); // TODO
1763 : :
1764 [ # # ]: 0 : VerbExecutionControllerGuard aVerbGuard( m_aVerbExecutionController );
1765 : :
1766 [ # # ]: 0 : if ( m_nObjectState == -1 )
1767 : : {
1768 : : // the object is still not loaded
1769 : : throw embed::WrongStateException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Can't store object without persistence!\n" )),
1770 [ # # ][ # # ]: 0 : uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
[ # # ]
1771 : : }
1772 : :
1773 [ # # ]: 0 : if ( m_bWaitSaveCompleted )
1774 : : throw embed::WrongStateException(
1775 : : ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "The object waits for saveCompleted() call!\n" )),
1776 [ # # ][ # # ]: 0 : uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
[ # # ]
1777 : :
1778 [ # # ]: 0 : if ( m_bReadOnly )
1779 [ # # ]: 0 : throw io::IOException(); // TODO: access denied
1780 : :
1781 [ # # ]: 0 : LetCommonStoragePassBeUsed_Impl( m_xObjectStream );
1782 : :
1783 : 0 : sal_Bool bStoreLoaded = sal_True;
1784 : :
1785 : : #ifdef WNT
1786 : : if ( m_nObjectState != embed::EmbedStates::LOADED && m_pOleComponent && m_pOleComponent->IsDirty() )
1787 : : {
1788 : : bStoreLoaded = sal_False;
1789 : :
1790 : : OSL_ENSURE( m_xParentStorage.is() && m_xObjectStream.is(), "The object has no valid persistence!\n" );
1791 : :
1792 : : if ( !m_xObjectStream.is() )
1793 : : throw io::IOException(); //TODO: access denied
1794 : :
1795 : : SetStreamMediaType_Impl( m_xObjectStream, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "application/vnd.sun.star.oleobject" ) ));
1796 : : uno::Reference< io::XOutputStream > xOutStream = m_xObjectStream->getOutputStream();
1797 : : if ( !xOutStream.is() )
1798 : : throw io::IOException(); //TODO: access denied
1799 : :
1800 : : // TODO: does this work for links too?
1801 : : StoreObjectToStream( GetStreamForSaving() );
1802 : :
1803 : : // the replacement is changed probably, and it must be in the object stream
1804 : : if ( !m_pOleComponent->IsWorkaroundActive() )
1805 : : m_xCachedVisualRepresentation = uno::Reference< io::XStream >();
1806 : : SetVisReplInStream( sal_True );
1807 : : }
1808 : : #endif
1809 : :
1810 [ # # ][ # # ]: 0 : if ( m_bStoreVisRepl != HasVisReplInStream() )
1811 : : {
1812 [ # # ]: 0 : if ( m_bStoreVisRepl )
1813 : : {
1814 : : // the m_xCachedVisualRepresentation must be set or it should be already stored
1815 [ # # ]: 0 : if ( m_xCachedVisualRepresentation.is() )
1816 [ # # ]: 0 : InsertVisualCache_Impl( m_xObjectStream, m_xCachedVisualRepresentation );
1817 : : else
1818 : : {
1819 [ # # ]: 0 : m_xCachedVisualRepresentation = TryToRetrieveCachedVisualRepresentation_Impl( m_xObjectStream );
1820 : : OSL_ENSURE( m_xCachedVisualRepresentation.is(), "No representation is available!" );
1821 : : }
1822 : : }
1823 : : else
1824 : : {
1825 [ # # ]: 0 : if ( !m_xCachedVisualRepresentation.is() )
1826 [ # # ][ # # ]: 0 : m_xCachedVisualRepresentation = TryToRetrieveCachedVisualRepresentation_Impl( m_xObjectStream );
1827 [ # # ]: 0 : RemoveVisualCache_Impl( m_xObjectStream );
1828 : : }
1829 : :
1830 : 0 : SetVisReplInStream( m_bStoreVisRepl );
1831 : : }
1832 : :
1833 [ # # ][ # # ]: 0 : if ( m_pOleComponent && m_nUpdateMode == embed::EmbedUpdateModes::ALWAYS_UPDATE && !bStoreLoaded )
[ # # ]
1834 : : {
1835 : : // the object replacement image should be updated, so the cached size as well
1836 : 0 : m_bHasCachedSize = sal_False;
1837 : : try
1838 : : {
1839 : : // the call will cache the size in case of success
1840 : : // probably it might need to be done earlier, while the object is in active state
1841 [ # # ]: 0 : getVisualAreaSize( embed::Aspects::MSOLE_CONTENT );
1842 : : }
1843 [ # # ]: 0 : catch( const uno::Exception& )
1844 : : {}
1845 : : }
1846 : :
1847 [ # # ]: 0 : aGuard.clear();
1848 : :
1849 [ # # ][ # # ]: 0 : MakeEventListenerNotification_Impl( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "OnSaveDone" ) ));
1850 : :
1851 : : // the object can be changed only on Windows
1852 : : // the notification should be done only if the object is not in loaded state
1853 [ # # ][ # # ]: 0 : if ( m_pOleComponent && m_nUpdateMode == embed::EmbedUpdateModes::ALWAYS_UPDATE && !bStoreLoaded )
[ # # ]
1854 [ # # ][ # # ]: 0 : MakeEventListenerNotification_Impl( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "OnVisAreaChanged" ) ));
[ # # ][ # # ]
[ # # ]
1855 : : }
1856 : :
1857 : : //------------------------------------------------------
1858 : 0 : sal_Bool SAL_CALL OleEmbeddedObject::isReadonly()
1859 : : throw ( embed::WrongStateException,
1860 : : uno::RuntimeException )
1861 : : {
1862 : : // begin wrapping related part ====================
1863 [ # # ]: 0 : uno::Reference< embed::XEmbedPersist > xWrappedObject( m_xWrappedObject, uno::UNO_QUERY );
1864 [ # # ]: 0 : if ( xWrappedObject.is() )
1865 : : {
1866 : : // the object was converted to OOo embedded object, the current implementation is now only a wrapper
1867 [ # # ][ # # ]: 0 : return xWrappedObject->isReadonly();
1868 : : }
1869 : : // end wrapping related part ====================
1870 : :
1871 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
1872 [ # # ]: 0 : if ( m_bDisposed )
1873 [ # # ]: 0 : throw lang::DisposedException(); // TODO
1874 : :
1875 [ # # ]: 0 : if ( m_nObjectState == -1 )
1876 : : {
1877 : : // the object is still not loaded
1878 : : throw embed::WrongStateException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "The object persistence is not initialized!\n" )),
1879 [ # # ][ # # ]: 0 : uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
[ # # ]
1880 : : }
1881 : :
1882 [ # # ]: 0 : if ( m_bWaitSaveCompleted )
1883 : : throw embed::WrongStateException(
1884 : : ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "The object waits for saveCompleted() call!\n" )),
1885 [ # # ][ # # ]: 0 : uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
[ # # ]
1886 : :
1887 [ # # ]: 0 : return m_bReadOnly;
1888 : : }
1889 : :
1890 : : //------------------------------------------------------
1891 : 0 : void SAL_CALL OleEmbeddedObject::reload(
1892 : : const uno::Sequence< beans::PropertyValue >& lArguments,
1893 : : const uno::Sequence< beans::PropertyValue >& lObjArgs )
1894 : : throw ( lang::IllegalArgumentException,
1895 : : embed::WrongStateException,
1896 : : io::IOException,
1897 : : uno::Exception,
1898 : : uno::RuntimeException )
1899 : : {
1900 : : // begin wrapping related part ====================
1901 [ # # ]: 0 : uno::Reference< embed::XEmbedPersist > xWrappedObject( m_xWrappedObject, uno::UNO_QUERY );
1902 [ # # ]: 0 : if ( xWrappedObject.is() )
1903 : : {
1904 : : // the object was converted to OOo embedded object, the current implementation is now only a wrapper
1905 [ # # ][ # # ]: 0 : xWrappedObject->reload( lArguments, lObjArgs );
1906 : 0 : return;
1907 : : }
1908 : : // end wrapping related part ====================
1909 : :
1910 : : // TODO: use lObjArgs
1911 : :
1912 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
1913 [ # # ]: 0 : if ( m_bDisposed )
1914 [ # # ]: 0 : throw lang::DisposedException(); // TODO
1915 : :
1916 [ # # ]: 0 : if ( m_nObjectState == -1 )
1917 : : {
1918 : : // the object is still not loaded
1919 : : throw embed::WrongStateException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "The object persistence is not initialized!\n" )),
1920 [ # # ][ # # ]: 0 : uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
[ # # ]
1921 : : }
1922 : :
1923 [ # # ]: 0 : if ( m_bWaitSaveCompleted )
1924 : : throw embed::WrongStateException(
1925 : : ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "The object waits for saveCompleted() call!\n" )),
1926 [ # # ][ # # ]: 0 : uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
[ # # ][ # # ]
[ # # ]
1927 : :
1928 : : // TODO:
1929 : : // throw away current document
1930 : : // load new document from current storage
1931 : : // use meaningfull part of lArguments
1932 : : }
1933 : :
1934 : : //------------------------------------------------------
1935 : 0 : void SAL_CALL OleEmbeddedObject::breakLink( const uno::Reference< embed::XStorage >& xStorage,
1936 : : const ::rtl::OUString& sEntName )
1937 : : throw ( lang::IllegalArgumentException,
1938 : : embed::WrongStateException,
1939 : : io::IOException,
1940 : : uno::Exception,
1941 : : uno::RuntimeException )
1942 : : {
1943 : : // begin wrapping related part ====================
1944 [ # # ]: 0 : uno::Reference< embed::XLinkageSupport > xWrappedObject( m_xWrappedObject, uno::UNO_QUERY );
1945 [ # # ]: 0 : if ( xWrappedObject.is() )
1946 : : {
1947 : : // the object was converted to OOo embedded object, the current implementation is now only a wrapper
1948 [ # # ][ # # ]: 0 : xWrappedObject->breakLink( xStorage, sEntName );
1949 : 0 : return;
1950 : : }
1951 : : // end wrapping related part ====================
1952 : :
1953 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
1954 [ # # ]: 0 : if ( m_bDisposed )
1955 [ # # ]: 0 : throw lang::DisposedException(); // TODO
1956 : :
1957 [ # # ]: 0 : if ( !xStorage.is() )
1958 : : throw lang::IllegalArgumentException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "No parent storage is provided!\n" )),
1959 : : uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
1960 [ # # ][ # # ]: 0 : 1 );
[ # # ]
1961 : :
1962 [ # # ]: 0 : if ( sEntName.isEmpty() )
1963 : : throw lang::IllegalArgumentException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Empty element name is provided!\n" )),
1964 : : uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
1965 [ # # ][ # # ]: 0 : 2 );
[ # # ]
1966 : :
1967 : : // TODO: The object must be at least in Running state;
1968 [ # # ][ # # ]: 0 : if ( !m_bIsLink || m_nObjectState == -1 || !m_pOleComponent )
[ # # ]
1969 : : {
1970 : : // it must be a linked initialized object
1971 : : throw embed::WrongStateException(
1972 : : ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "The object is not a valid linked object!\n" )),
1973 [ # # ][ # # ]: 0 : uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
[ # # ]
1974 : : }
1975 : :
1976 [ # # ]: 0 : if ( m_bReadOnly )
1977 [ # # ]: 0 : throw io::IOException(); // TODO: Access denied
1978 : :
1979 [ # # ]: 0 : if ( m_bWaitSaveCompleted )
1980 : : throw embed::WrongStateException(
1981 : : ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "The object waits for saveCompleted() call!\n" )),
1982 [ # # ][ # # ]: 0 : uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
[ # # ]
1983 : :
1984 : :
1985 : : #ifdef WNT
1986 : : if ( m_pOleComponent )
1987 : : {
1988 : : // TODO: create an object based on the link
1989 : :
1990 : : // disconnect the old temporary URL
1991 : : ::rtl::OUString aOldTempURL = m_aTempURL;
1992 : : m_aTempURL = ::rtl::OUString();
1993 : :
1994 : : OleComponent* pNewOleComponent = new OleComponent( m_xFactory, this );
1995 : : try {
1996 : : pNewOleComponent->InitEmbeddedCopyOfLink( m_pOleComponent );
1997 : : }
1998 : : catch ( const uno::Exception& )
1999 : : {
2000 : : delete pNewOleComponent;
2001 : : if ( !m_aTempURL.isEmpty() )
2002 : : KillFile_Impl( m_aTempURL, m_xFactory );
2003 : : m_aTempURL = aOldTempURL;
2004 : : throw;
2005 : : }
2006 : :
2007 : : try {
2008 : : GetRidOfComponent();
2009 : : }
2010 : : catch( const uno::Exception& )
2011 : : {
2012 : : delete pNewOleComponent;
2013 : : if ( !m_aTempURL.isEmpty() )
2014 : : KillFile_Impl( m_aTempURL, m_xFactory );
2015 : : m_aTempURL = aOldTempURL;
2016 : : throw;
2017 : : }
2018 : :
2019 : : KillFile_Impl( aOldTempURL, m_xFactory );
2020 : :
2021 : : CreateOleComponent_Impl( pNewOleComponent );
2022 : :
2023 : : if ( m_xParentStorage != xStorage || !m_aEntryName.equals( sEntName ) )
2024 : : SwitchOwnPersistence( xStorage, sEntName );
2025 : :
2026 : : if ( m_nObjectState != embed::EmbedStates::LOADED )
2027 : : {
2028 : : // TODO: should we activate the new object if the link was activated?
2029 : :
2030 : : sal_Int32 nTargetState = m_nObjectState;
2031 : : m_nObjectState = embed::EmbedStates::LOADED;
2032 : :
2033 : : if ( m_nObjectState == embed::EmbedStates::RUNNING )
2034 : : m_pOleComponent->RunObject(); // the object already was in running state, the server must be installed
2035 : : else // m_nObjectState == embed::EmbedStates::ACTIVE
2036 : : {
2037 : : m_pOleComponent->RunObject(); // the object already was in running state, the server must be installed
2038 : : m_pOleComponent->ExecuteVerb( embed::EmbedVerbs::MS_OLEVERB_OPEN );
2039 : : }
2040 : :
2041 : : m_nObjectState = nTargetState;
2042 : : }
2043 : :
2044 : : m_bIsLink = sal_False;
2045 : : m_aLinkURL = ::rtl::OUString();
2046 : : }
2047 : : else
2048 : : #endif
2049 : : {
2050 [ # # ]: 0 : throw io::IOException(); //TODO:
2051 : 0 : }
2052 : : }
2053 : :
2054 : : //------------------------------------------------------
2055 : 0 : sal_Bool SAL_CALL OleEmbeddedObject::isLink()
2056 : : throw ( embed::WrongStateException,
2057 : : uno::RuntimeException )
2058 : : {
2059 : : // begin wrapping related part ====================
2060 [ # # ]: 0 : uno::Reference< embed::XLinkageSupport > xWrappedObject( m_xWrappedObject, uno::UNO_QUERY );
2061 [ # # ]: 0 : if ( xWrappedObject.is() )
2062 : : {
2063 : : // the object was converted to OOo embedded object, the current implementation is now only a wrapper
2064 [ # # ][ # # ]: 0 : return xWrappedObject->isLink();
2065 : : }
2066 : : // end wrapping related part ====================
2067 : :
2068 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
2069 [ # # ]: 0 : if ( m_bDisposed )
2070 [ # # ]: 0 : throw lang::DisposedException(); // TODO
2071 : :
2072 [ # # ]: 0 : return m_bIsLink;
2073 : : }
2074 : :
2075 : : //------------------------------------------------------
2076 : 0 : ::rtl::OUString SAL_CALL OleEmbeddedObject::getLinkURL()
2077 : : throw ( embed::WrongStateException,
2078 : : uno::Exception,
2079 : : uno::RuntimeException )
2080 : : {
2081 : : // begin wrapping related part ====================
2082 [ # # ]: 0 : uno::Reference< embed::XLinkageSupport > xWrappedObject( m_xWrappedObject, uno::UNO_QUERY );
2083 [ # # ]: 0 : if ( xWrappedObject.is() )
2084 : : {
2085 : : // the object was converted to OOo embedded object, the current implementation is now only a wrapper
2086 [ # # ][ # # ]: 0 : return xWrappedObject->getLinkURL();
2087 : : }
2088 : : // end wrapping related part ====================
2089 : :
2090 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
2091 [ # # ]: 0 : if ( m_bDisposed )
2092 [ # # ]: 0 : throw lang::DisposedException(); // TODO
2093 : :
2094 [ # # ]: 0 : if ( m_bWaitSaveCompleted )
2095 : : throw embed::WrongStateException(
2096 : : ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "The object waits for saveCompleted() call!\n" )),
2097 [ # # ][ # # ]: 0 : uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
[ # # ]
2098 : :
2099 [ # # ]: 0 : if ( !m_bIsLink )
2100 : : throw embed::WrongStateException(
2101 : : ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "The object is not a link object!\n" )),
2102 [ # # ][ # # ]: 0 : uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
[ # # ]
2103 : :
2104 : : // TODO: probably the link URL can be retrieved from OLE
2105 : :
2106 [ # # ]: 0 : return m_aLinkURL;
2107 : : }
2108 : :
2109 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|