/src/libreoffice/embeddedobj/source/msole/olemisc.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | #include <sal/config.h> |
21 | | |
22 | | #include <cassert> |
23 | | |
24 | | #include <com/sun/star/embed/EmbedUpdateModes.hpp> |
25 | | #include <com/sun/star/embed/EmbedStates.hpp> |
26 | | #include <com/sun/star/embed/WrongStateException.hpp> |
27 | | #include <com/sun/star/lang/NoSupportException.hpp> |
28 | | #include <com/sun/star/lang/XComponent.hpp> |
29 | | #include <com/sun/star/lang/DisposedException.hpp> |
30 | | |
31 | | #include <comphelper/multicontainer2.hxx> |
32 | | #include <comphelper/sequenceashashmap.hxx> |
33 | | #include <cppuhelper/supportsservice.hxx> |
34 | | #include <osl/diagnose.h> |
35 | | |
36 | | #include <oleembobj.hxx> |
37 | | #include <utility> |
38 | | #include "olepersist.hxx" |
39 | | |
40 | | #include "ownview.hxx" |
41 | | |
42 | | #include "olecomponent.hxx" |
43 | | |
44 | | using namespace ::com::sun::star; |
45 | | |
46 | | |
47 | | OleEmbeddedObject::OleEmbeddedObject( uno::Reference< uno::XComponentContext > xContext, |
48 | | const uno::Sequence< sal_Int8 >& aClassID, |
49 | | OUString aClassName ) |
50 | 38 | : m_bReadOnly( false ) |
51 | 38 | , m_bDisposed( false ) |
52 | 38 | , m_nObjectState( -1 ) |
53 | 38 | , m_nTargetState( -1 ) |
54 | 38 | , m_nUpdateMode ( embed::EmbedUpdateModes::ALWAYS_UPDATE ) |
55 | 38 | , m_xContext(std::move( xContext )) |
56 | 38 | , m_aClassID( aClassID ) |
57 | 38 | , m_aClassName(std::move( aClassName )) |
58 | 38 | , m_bWaitSaveCompleted( false ) |
59 | 38 | , m_bNewVisReplInStream( true ) |
60 | 38 | , m_bStoreLoaded( false ) |
61 | 38 | , m_bVisReplInitialized( false ) |
62 | 38 | , m_bVisReplInStream( false ) |
63 | 38 | , m_bStoreVisRepl( false ) |
64 | 38 | , m_bIsLink( false ) |
65 | 38 | , m_bHasCachedSize( false ) |
66 | 38 | , m_nCachedAspect( 0 ) |
67 | 38 | , m_bHasSizeToSet( false ) |
68 | 38 | , m_nAspectToSet( 0 ) |
69 | 38 | , m_bGotStatus( false ) |
70 | 38 | , m_nStatus( 0 ) |
71 | 38 | , m_nStatusAspect( 0 ) |
72 | 38 | , m_bFromClipboard( false ) |
73 | 38 | , m_bTriedConversion( false ) |
74 | 38 | { |
75 | 38 | } |
76 | | |
77 | | |
78 | | // In case of loading from persistent entry the classID of the object |
79 | | // will be retrieved from the entry, during construction it is unknown |
80 | | OleEmbeddedObject::OleEmbeddedObject( uno::Reference< uno::XComponentContext > xContext, bool bLink ) |
81 | 0 | : m_bReadOnly( false ) |
82 | 0 | , m_bDisposed( false ) |
83 | 0 | , m_nObjectState( -1 ) |
84 | 0 | , m_nTargetState( -1 ) |
85 | 0 | , m_nUpdateMode( embed::EmbedUpdateModes::ALWAYS_UPDATE ) |
86 | 0 | , m_xContext(std::move( xContext )) |
87 | 0 | , m_bWaitSaveCompleted( false ) |
88 | 0 | , m_bNewVisReplInStream( true ) |
89 | 0 | , m_bStoreLoaded( false ) |
90 | 0 | , m_bVisReplInitialized( false ) |
91 | 0 | , m_bVisReplInStream( false ) |
92 | 0 | , m_bStoreVisRepl( false ) |
93 | 0 | , m_bIsLink( bLink ) |
94 | 0 | , m_bHasCachedSize( false ) |
95 | 0 | , m_nCachedAspect( 0 ) |
96 | 0 | , m_bHasSizeToSet( false ) |
97 | 0 | , m_nAspectToSet( 0 ) |
98 | 0 | , m_bGotStatus( false ) |
99 | 0 | , m_nStatus( 0 ) |
100 | 0 | , m_nStatusAspect( 0 ) |
101 | 0 | , m_bFromClipboard( false ) |
102 | 0 | , m_bTriedConversion( false ) |
103 | 0 | { |
104 | 0 | } |
105 | | #ifdef _WIN32 |
106 | | |
107 | | // this constructor let object be initialized from clipboard |
108 | | OleEmbeddedObject::OleEmbeddedObject( const uno::Reference< uno::XComponentContext >& xContext ) |
109 | | : m_bReadOnly( false ) |
110 | | , m_bDisposed( false ) |
111 | | , m_nObjectState( -1 ) |
112 | | , m_nTargetState( -1 ) |
113 | | , m_nUpdateMode( embed::EmbedUpdateModes::ALWAYS_UPDATE ) |
114 | | , m_xContext( xContext ) |
115 | | , m_bWaitSaveCompleted( false ) |
116 | | , m_bNewVisReplInStream( true ) |
117 | | , m_bStoreLoaded( false ) |
118 | | , m_bVisReplInitialized( false ) |
119 | | , m_bVisReplInStream( false ) |
120 | | , m_bStoreVisRepl( false ) |
121 | | , m_bIsLink( false ) |
122 | | , m_bHasCachedSize( false ) |
123 | | , m_nCachedAspect( 0 ) |
124 | | , m_bHasSizeToSet( false ) |
125 | | , m_nAspectToSet( 0 ) |
126 | | , m_bGotStatus( false ) |
127 | | , m_nStatus( 0 ) |
128 | | , m_nStatusAspect( 0 ) |
129 | | , m_bFromClipboard( true ) |
130 | | , m_bTriedConversion( false ) |
131 | | { |
132 | | } |
133 | | #endif |
134 | | |
135 | | OleEmbeddedObject::~OleEmbeddedObject() |
136 | 38 | { |
137 | 38 | OSL_ENSURE( !m_pInterfaceContainer && !m_pOleComponent && !m_xObjectStream.is(), |
138 | 38 | "The object is not closed! DISASTER is possible!" ); |
139 | | |
140 | 38 | if ( m_pOleComponent || m_pInterfaceContainer || m_xObjectStream.is() ) |
141 | 38 | { |
142 | | // the component must be cleaned during closing |
143 | 38 | osl_atomic_increment(&m_refCount); // to avoid crash |
144 | 38 | try { |
145 | 38 | Dispose(); |
146 | 38 | } catch( const uno::Exception& ) {} |
147 | 38 | } |
148 | | |
149 | 38 | if ( !m_aTempURL.isEmpty() ) |
150 | 0 | KillFile_Impl( m_aTempURL, m_xContext ); |
151 | | |
152 | 38 | if ( !m_aTempDumpURL.isEmpty() ) |
153 | 0 | KillFile_Impl( m_aTempDumpURL, m_xContext ); |
154 | 38 | } |
155 | | |
156 | | |
157 | | void OleEmbeddedObject::MakeEventListenerNotification_Impl( const OUString& aEventName, |
158 | | osl::ResettableMutexGuard& guard ) |
159 | 0 | { |
160 | 0 | if ( !m_pInterfaceContainer ) |
161 | 0 | return; |
162 | | |
163 | 0 | comphelper::OInterfaceContainerHelper2* pContainer = |
164 | 0 | m_pInterfaceContainer->getContainer( |
165 | 0 | cppu::UnoType<document::XEventListener>::get()); |
166 | 0 | if ( pContainer == nullptr ) |
167 | 0 | return; |
168 | | |
169 | 0 | auto proc = [&guard, aEvent = document::EventObject(getXWeak(), aEventName)]( |
170 | 0 | const uno::Reference<document::XEventListener>& xListener) |
171 | 0 | { |
172 | 0 | try |
173 | 0 | { |
174 | 0 | osl::ResettableMutexGuardScopedReleaser area(guard); |
175 | 0 | xListener->notifyEvent(aEvent); |
176 | 0 | } |
177 | 0 | catch (const lang::DisposedException&) |
178 | 0 | { |
179 | 0 | throw; // forEach handles this |
180 | 0 | } |
181 | 0 | catch (const uno::RuntimeException&) |
182 | 0 | { |
183 | 0 | } |
184 | 0 | }; |
185 | 0 | pContainer->forEach<document::XEventListener>(proc); |
186 | 0 | } |
187 | | #ifdef _WIN32 |
188 | | |
189 | | void OleEmbeddedObject::StateChangeNotification_Impl( bool bBeforeChange, sal_Int32 nOldState, sal_Int32 nNewState, |
190 | | osl::ResettableMutexGuard& guard ) |
191 | | { |
192 | | if (!m_pInterfaceContainer) |
193 | | return; |
194 | | |
195 | | comphelper::OInterfaceContainerHelper2* pContainer = m_pInterfaceContainer->getContainer( |
196 | | cppu::UnoType<embed::XStateChangeListener>::get()); |
197 | | if (!pContainer) |
198 | | return; |
199 | | |
200 | | auto proc |
201 | | = [bBeforeChange, nOldState, nNewState, &guard, aSource = lang::EventObject(getXWeak())]( |
202 | | const uno::Reference<embed::XStateChangeListener>& xListener) |
203 | | { |
204 | | try |
205 | | { |
206 | | osl::ResettableMutexGuardScopedReleaser area(guard); |
207 | | if (bBeforeChange) |
208 | | xListener->changingState(aSource, nOldState, nNewState); |
209 | | else |
210 | | xListener->stateChanged(aSource, nOldState, nNewState); |
211 | | } |
212 | | catch (const lang::DisposedException&) |
213 | | { |
214 | | throw; // forEach handles this |
215 | | } |
216 | | catch (const uno::Exception&) |
217 | | { |
218 | | // even if the listener complains ignore it for now |
219 | | } |
220 | | }; |
221 | | pContainer->forEach<embed::XStateChangeListener>(proc); |
222 | | } |
223 | | #endif |
224 | | |
225 | | void OleEmbeddedObject::GetRidOfComponent(osl::ResettableMutexGuard* guard) |
226 | 0 | { |
227 | | #ifdef _WIN32 |
228 | | if ( m_pOleComponent ) |
229 | | { |
230 | | if ( m_nObjectState != -1 && m_nObjectState != embed::EmbedStates::LOADED ) |
231 | | SaveObject_Impl(); |
232 | | |
233 | | m_pOleComponent->removeCloseListener( m_xClosePreventer ); |
234 | | // When releasing the guard below, avoid a case when two threads are doing the same; |
235 | | // store the reference on stack and clear m_pOleComponent in advance |
236 | | rtl::Reference<OleComponent> pOleComponent(std::move(m_pOleComponent)); |
237 | | try |
238 | | { |
239 | | std::optional<osl::ResettableMutexGuardScopedReleaser> oReleaser; |
240 | | if (guard) |
241 | | oReleaser.emplace(*guard); |
242 | | pOleComponent->close(false); |
243 | | } |
244 | | catch( const uno::Exception& ) |
245 | | { |
246 | | m_pOleComponent = std::move(pOleComponent); |
247 | | // TODO: there should be a special listener to wait for component closing |
248 | | // and to notify object, may be object itself can be such a listener |
249 | | m_pOleComponent->addCloseListener( m_xClosePreventer ); |
250 | | throw; |
251 | | } |
252 | | |
253 | | pOleComponent->disconnectEmbeddedObject(); |
254 | | } |
255 | | #else |
256 | 0 | (void)guard; |
257 | 0 | #endif |
258 | 0 | } |
259 | | |
260 | | |
261 | | void OleEmbeddedObject::Dispose(osl::ResettableMutexGuard* guard) |
262 | 38 | { |
263 | 38 | if ( m_pInterfaceContainer ) |
264 | 0 | { |
265 | 0 | lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >( this ) ); |
266 | 0 | m_pInterfaceContainer->disposeAndClear( aSource ); |
267 | 0 | m_pInterfaceContainer.reset(); |
268 | 0 | } |
269 | | |
270 | 38 | if ( m_xOwnView.is() ) |
271 | 0 | { |
272 | 0 | m_xOwnView->Close(); |
273 | 0 | m_xOwnView.clear(); |
274 | 0 | } |
275 | | |
276 | 38 | if ( m_pOleComponent ) |
277 | 0 | try { |
278 | 0 | GetRidOfComponent(guard); |
279 | 0 | } catch( const uno::Exception& ) |
280 | 0 | { |
281 | 0 | m_bDisposed = true; |
282 | 0 | throw; // TODO: there should be a special listener that will close object when |
283 | | // component is finally closed |
284 | 0 | } |
285 | | |
286 | 38 | if ( m_xObjectStream.is() ) |
287 | 38 | { |
288 | 38 | uno::Reference< lang::XComponent > xComp( m_xObjectStream, uno::UNO_QUERY ); |
289 | 38 | OSL_ENSURE( xComp.is(), "Storage stream doesn't support XComponent!" ); |
290 | | |
291 | 38 | if ( xComp.is() ) |
292 | 38 | { |
293 | 38 | try { |
294 | 38 | xComp->dispose(); |
295 | 38 | } catch( const uno::Exception& ) {} |
296 | 38 | } |
297 | 38 | m_xObjectStream.clear(); |
298 | 38 | } |
299 | | |
300 | 38 | m_xParentStorage.clear(); |
301 | 38 | m_xClientSite.clear(); |
302 | 38 | m_xClosePreventer.clear(); |
303 | 38 | m_xNewCachedVisRepl.clear(); |
304 | 38 | m_xNewParentStorage.clear(); |
305 | 38 | m_xNewObjectStream.clear(); |
306 | 38 | m_xCachedVisualRepresentation.clear(); |
307 | 38 | m_xWrappedObject.clear(); |
308 | 38 | m_xParent.clear(); |
309 | 38 | m_pOleComponent.clear(); |
310 | | |
311 | 38 | m_bDisposed = true; |
312 | 38 | } |
313 | | |
314 | | |
315 | | uno::Sequence< sal_Int8 > SAL_CALL OleEmbeddedObject::getClassID() |
316 | 0 | { |
317 | | // begin wrapping related part ==================== |
318 | 0 | uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject; |
319 | 0 | if ( xWrappedObject.is() ) |
320 | 0 | { |
321 | | // the object was converted to OOo embedded object, the current implementation is now only a wrapper |
322 | 0 | return xWrappedObject->getClassID(); |
323 | 0 | } |
324 | | // end wrapping related part ==================== |
325 | | |
326 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
327 | 0 | if ( m_bDisposed ) |
328 | 0 | throw lang::DisposedException(); // TODO |
329 | | |
330 | 0 | return m_aClassID; |
331 | 0 | } |
332 | | |
333 | | |
334 | | OUString SAL_CALL OleEmbeddedObject::getClassName() |
335 | 0 | { |
336 | | // begin wrapping related part ==================== |
337 | 0 | uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject; |
338 | 0 | if ( xWrappedObject.is() ) |
339 | 0 | { |
340 | | // the object was converted to OOo embedded object, the current implementation is now only a wrapper |
341 | 0 | return xWrappedObject->getClassName(); |
342 | 0 | } |
343 | | // end wrapping related part ==================== |
344 | | |
345 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
346 | 0 | if ( m_bDisposed ) |
347 | 0 | throw lang::DisposedException(); // TODO |
348 | | |
349 | 0 | return m_aClassName; |
350 | 0 | } |
351 | | |
352 | | |
353 | | void SAL_CALL OleEmbeddedObject::setClassInfo( |
354 | | const uno::Sequence< sal_Int8 >& aClassID, const OUString& aClassName ) |
355 | 0 | { |
356 | | // begin wrapping related part ==================== |
357 | 0 | uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject; |
358 | 0 | if ( xWrappedObject.is() ) |
359 | 0 | { |
360 | | // the object was converted to OOo embedded object, the current implementation is now only a wrapper |
361 | 0 | xWrappedObject->setClassInfo( aClassID, aClassName ); |
362 | 0 | return; |
363 | 0 | } |
364 | | // end wrapping related part ==================== |
365 | | |
366 | | // the object class info can not be changed explicitly |
367 | 0 | throw lang::NoSupportException(); //TODO: |
368 | 0 | } |
369 | | |
370 | | |
371 | | uno::Reference< util::XCloseable > SAL_CALL OleEmbeddedObject::getComponent() |
372 | 0 | { |
373 | | // begin wrapping related part ==================== |
374 | 0 | uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject; |
375 | 0 | if ( xWrappedObject.is() ) |
376 | 0 | { |
377 | | // the object was converted to OOo embedded object, the current implementation is now only a wrapper |
378 | 0 | return xWrappedObject->getComponent(); |
379 | 0 | } |
380 | | // end wrapping related part ==================== |
381 | | |
382 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
383 | 0 | if ( m_bDisposed ) |
384 | 0 | throw lang::DisposedException(); // TODO |
385 | | |
386 | 0 | if ( m_nObjectState == -1 ) // || m_nObjectState == embed::EmbedStates::LOADED ) |
387 | 0 | { |
388 | | // the object is still not running |
389 | 0 | throw uno::RuntimeException( u"The object is not loaded!"_ustr, |
390 | 0 | static_cast< ::cppu::OWeakObject* >(this) ); |
391 | 0 | } |
392 | | |
393 | | #if defined(_WIN32) |
394 | | if (m_pOleComponent.is()) |
395 | | { |
396 | | return uno::Reference< util::XCloseable >( m_pOleComponent ); |
397 | | } |
398 | | #endif |
399 | | |
400 | 0 | assert(!m_pOleComponent.is()); |
401 | | // TODO/LATER: Is it correct??? |
402 | 0 | return uno::Reference< util::XCloseable >(); |
403 | | // throw uno::RuntimeException(); // TODO |
404 | 0 | } |
405 | | |
406 | | |
407 | | void SAL_CALL OleEmbeddedObject::addStateChangeListener( const uno::Reference< embed::XStateChangeListener >& xListener ) |
408 | 0 | { |
409 | | // begin wrapping related part ==================== |
410 | 0 | if ( m_xWrappedObject.is() ) |
411 | 0 | { |
412 | | // the object was converted to OOo embedded object, the current implementation is now only a wrapper |
413 | 0 | m_xWrappedObject->addStateChangeListener( xListener ); |
414 | 0 | return; |
415 | 0 | } |
416 | | // end wrapping related part ==================== |
417 | | |
418 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
419 | 0 | if ( m_bDisposed ) |
420 | 0 | throw lang::DisposedException(); // TODO |
421 | | |
422 | 0 | if ( !m_pInterfaceContainer ) |
423 | 0 | m_pInterfaceContainer.reset(new comphelper::OMultiTypeInterfaceContainerHelper2( m_aMutex )); |
424 | |
|
425 | 0 | m_pInterfaceContainer->addInterface( cppu::UnoType<embed::XStateChangeListener>::get(), |
426 | 0 | xListener ); |
427 | 0 | } |
428 | | |
429 | | |
430 | | void SAL_CALL OleEmbeddedObject::removeStateChangeListener( |
431 | | const uno::Reference< embed::XStateChangeListener >& xListener ) |
432 | 0 | { |
433 | | // begin wrapping related part ==================== |
434 | 0 | if ( m_xWrappedObject.is() ) |
435 | 0 | { |
436 | | // the object was converted to OOo embedded object, the current implementation is now only a wrapper |
437 | 0 | m_xWrappedObject->removeStateChangeListener( xListener ); |
438 | 0 | return; |
439 | 0 | } |
440 | | // end wrapping related part ==================== |
441 | | |
442 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
443 | 0 | if ( m_pInterfaceContainer ) |
444 | 0 | m_pInterfaceContainer->removeInterface( cppu::UnoType<embed::XStateChangeListener>::get(), |
445 | 0 | xListener ); |
446 | 0 | } |
447 | | |
448 | | |
449 | | void SAL_CALL OleEmbeddedObject::close( sal_Bool bDeliverOwnership ) |
450 | 0 | { |
451 | | // begin wrapping related part ==================== |
452 | 0 | uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject; |
453 | 0 | if ( xWrappedObject.is() ) |
454 | 0 | { |
455 | | // the object was converted to OOo embedded object, the current implementation is now only a wrapper |
456 | 0 | xWrappedObject->close( bDeliverOwnership ); |
457 | 0 | return; |
458 | 0 | } |
459 | | // end wrapping related part ==================== |
460 | | |
461 | 0 | osl::ResettableMutexGuard aGuard(m_aMutex); |
462 | 0 | if ( m_bDisposed ) |
463 | 0 | throw lang::DisposedException(); // TODO |
464 | | |
465 | 0 | uno::Reference< uno::XInterface > xSelfHold( static_cast< ::cppu::OWeakObject* >( this ) ); |
466 | 0 | lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >( this ) ); |
467 | |
|
468 | 0 | if ( m_pInterfaceContainer ) |
469 | 0 | { |
470 | 0 | comphelper::OInterfaceContainerHelper2* pContainer = |
471 | 0 | m_pInterfaceContainer->getContainer( cppu::UnoType<util::XCloseListener>::get()); |
472 | 0 | if ( pContainer != nullptr ) |
473 | 0 | { |
474 | 0 | comphelper::OInterfaceIteratorHelper2 pIterator(*pContainer); |
475 | 0 | while (pIterator.hasMoreElements()) |
476 | 0 | { |
477 | 0 | try |
478 | 0 | { |
479 | 0 | static_cast<util::XCloseListener*>(pIterator.next())->queryClosing( aSource, bDeliverOwnership ); |
480 | 0 | } |
481 | 0 | catch( const uno::RuntimeException& ) |
482 | 0 | { |
483 | 0 | pIterator.remove(); |
484 | 0 | } |
485 | 0 | } |
486 | 0 | } |
487 | |
|
488 | 0 | pContainer = m_pInterfaceContainer->getContainer( |
489 | 0 | cppu::UnoType<util::XCloseListener>::get()); |
490 | 0 | if ( pContainer != nullptr ) |
491 | 0 | { |
492 | 0 | comphelper::OInterfaceIteratorHelper2 pCloseIterator(*pContainer); |
493 | 0 | while (pCloseIterator.hasMoreElements()) |
494 | 0 | { |
495 | 0 | try |
496 | 0 | { |
497 | 0 | static_cast<util::XCloseListener*>(pCloseIterator.next())->notifyClosing( aSource ); |
498 | 0 | } |
499 | 0 | catch( const uno::RuntimeException& ) |
500 | 0 | { |
501 | 0 | pCloseIterator.remove(); |
502 | 0 | } |
503 | 0 | } |
504 | 0 | } |
505 | 0 | } |
506 | |
|
507 | 0 | Dispose(&aGuard); |
508 | 0 | } |
509 | | |
510 | | |
511 | | void SAL_CALL OleEmbeddedObject::addCloseListener( const uno::Reference< util::XCloseListener >& xListener ) |
512 | 0 | { |
513 | | // begin wrapping related part ==================== |
514 | 0 | uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject; |
515 | 0 | if ( xWrappedObject.is() ) |
516 | 0 | { |
517 | | // the object was converted to OOo embedded object, the current implementation is now only a wrapper |
518 | 0 | xWrappedObject->addCloseListener( xListener ); |
519 | 0 | return; |
520 | 0 | } |
521 | | // end wrapping related part ==================== |
522 | | |
523 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
524 | 0 | if ( m_bDisposed ) |
525 | 0 | throw lang::DisposedException(); // TODO |
526 | | |
527 | 0 | if ( !m_pInterfaceContainer ) |
528 | 0 | m_pInterfaceContainer.reset(new comphelper::OMultiTypeInterfaceContainerHelper2( m_aMutex )); |
529 | |
|
530 | 0 | m_pInterfaceContainer->addInterface( cppu::UnoType<util::XCloseListener>::get(), xListener ); |
531 | 0 | } |
532 | | |
533 | | |
534 | | void SAL_CALL OleEmbeddedObject::removeCloseListener( const uno::Reference< util::XCloseListener >& xListener ) |
535 | 0 | { |
536 | | // begin wrapping related part ==================== |
537 | 0 | uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject; |
538 | 0 | if ( xWrappedObject.is() ) |
539 | 0 | { |
540 | | // the object was converted to OOo embedded object, the current implementation is now only a wrapper |
541 | 0 | xWrappedObject->removeCloseListener( xListener ); |
542 | 0 | return; |
543 | 0 | } |
544 | | // end wrapping related part ==================== |
545 | | |
546 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
547 | 0 | if ( m_bDisposed ) |
548 | 0 | throw lang::DisposedException(); // TODO |
549 | | |
550 | 0 | if ( m_pInterfaceContainer ) |
551 | 0 | m_pInterfaceContainer->removeInterface( cppu::UnoType<util::XCloseListener>::get(), |
552 | 0 | xListener ); |
553 | 0 | } |
554 | | |
555 | | |
556 | | void SAL_CALL OleEmbeddedObject::addEventListener( const uno::Reference< document::XEventListener >& xListener ) |
557 | 0 | { |
558 | | // begin wrapping related part ==================== |
559 | 0 | uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject; |
560 | 0 | if ( xWrappedObject.is() ) |
561 | 0 | { |
562 | | // the object was converted to OOo embedded object, the current implementation is now only a wrapper |
563 | 0 | xWrappedObject->addEventListener( xListener ); |
564 | 0 | return; |
565 | 0 | } |
566 | | // end wrapping related part ==================== |
567 | | |
568 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
569 | 0 | if ( m_bDisposed ) |
570 | 0 | throw lang::DisposedException(); // TODO |
571 | | |
572 | 0 | if ( !m_pInterfaceContainer ) |
573 | 0 | m_pInterfaceContainer.reset(new comphelper::OMultiTypeInterfaceContainerHelper2( m_aMutex )); |
574 | |
|
575 | 0 | m_pInterfaceContainer->addInterface( cppu::UnoType<document::XEventListener>::get(), xListener ); |
576 | 0 | } |
577 | | |
578 | | |
579 | | void SAL_CALL OleEmbeddedObject::removeEventListener( |
580 | | const uno::Reference< document::XEventListener >& xListener ) |
581 | 0 | { |
582 | | // begin wrapping related part ==================== |
583 | 0 | uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject; |
584 | 0 | if ( xWrappedObject.is() ) |
585 | 0 | { |
586 | | // the object was converted to OOo embedded object, the current implementation is now only a wrapper |
587 | 0 | xWrappedObject->removeEventListener( xListener ); |
588 | 0 | return; |
589 | 0 | } |
590 | | // end wrapping related part ==================== |
591 | | |
592 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
593 | 0 | if ( m_bDisposed ) |
594 | 0 | throw lang::DisposedException(); // TODO |
595 | | |
596 | 0 | if ( m_pInterfaceContainer ) |
597 | 0 | m_pInterfaceContainer->removeInterface( cppu::UnoType<document::XEventListener>::get(), |
598 | 0 | xListener ); |
599 | 0 | } |
600 | | |
601 | | // XInplaceObject ( wrapper related implementation ) |
602 | | |
603 | | void SAL_CALL OleEmbeddedObject::setObjectRectangles( const awt::Rectangle& aPosRect, |
604 | | const awt::Rectangle& aClipRect ) |
605 | 0 | { |
606 | | // begin wrapping related part ==================== |
607 | 0 | uno::Reference< embed::XInplaceObject > xWrappedObject( m_xWrappedObject, uno::UNO_QUERY ); |
608 | 0 | if ( xWrappedObject.is() ) |
609 | 0 | { |
610 | | // the object was converted to OOo embedded object, the current implementation is now only a wrapper |
611 | 0 | xWrappedObject->setObjectRectangles( aPosRect, aClipRect ); |
612 | 0 | return; |
613 | 0 | } |
614 | | // end wrapping related part ==================== |
615 | | |
616 | 0 | throw embed::WrongStateException(); |
617 | 0 | } |
618 | | |
619 | | |
620 | | void SAL_CALL OleEmbeddedObject::enableModeless( sal_Bool bEnable ) |
621 | 0 | { |
622 | | // begin wrapping related part ==================== |
623 | 0 | uno::Reference< embed::XInplaceObject > xWrappedObject( m_xWrappedObject, uno::UNO_QUERY ); |
624 | 0 | if ( xWrappedObject.is() ) |
625 | 0 | { |
626 | | // the object was converted to OOo embedded object, the current implementation is now only a wrapper |
627 | 0 | xWrappedObject->enableModeless( bEnable ); |
628 | 0 | return; |
629 | 0 | } |
630 | | // end wrapping related part ==================== |
631 | | |
632 | 0 | throw embed::WrongStateException(); |
633 | 0 | } |
634 | | |
635 | | |
636 | | void SAL_CALL OleEmbeddedObject::translateAccelerators( |
637 | | const uno::Sequence< awt::KeyEvent >& aKeys ) |
638 | 0 | { |
639 | | // begin wrapping related part ==================== |
640 | 0 | uno::Reference< embed::XInplaceObject > xWrappedObject( m_xWrappedObject, uno::UNO_QUERY ); |
641 | 0 | if ( xWrappedObject.is() ) |
642 | 0 | { |
643 | | // the object was converted to OOo embedded object, the current implementation is now only a wrapper |
644 | 0 | xWrappedObject->translateAccelerators( aKeys ); |
645 | 0 | return; |
646 | 0 | } |
647 | | // end wrapping related part ==================== |
648 | |
|
649 | 0 | } |
650 | | |
651 | | // XChild |
652 | | |
653 | | css::uno::Reference< css::uno::XInterface > SAL_CALL OleEmbeddedObject::getParent() |
654 | 0 | { |
655 | | // begin wrapping related part ==================== |
656 | 0 | uno::Reference< container::XChild > xWrappedObject( m_xWrappedObject, uno::UNO_QUERY ); |
657 | 0 | if ( xWrappedObject.is() ) |
658 | 0 | { |
659 | | // the object was converted to OOo embedded object, the current implementation is now only a wrapper |
660 | 0 | return xWrappedObject->getParent(); |
661 | 0 | } |
662 | | // end wrapping related part ==================== |
663 | | |
664 | 0 | return m_xParent; |
665 | 0 | } |
666 | | |
667 | | |
668 | | void SAL_CALL OleEmbeddedObject::setParent( const css::uno::Reference< css::uno::XInterface >& xParent ) |
669 | 0 | { |
670 | | // begin wrapping related part ==================== |
671 | 0 | uno::Reference< container::XChild > xWrappedObject( m_xWrappedObject, uno::UNO_QUERY ); |
672 | 0 | if ( xWrappedObject.is() ) |
673 | 0 | { |
674 | | // the object was converted to OOo embedded object, the current implementation is now only a wrapper |
675 | 0 | xWrappedObject->setParent( xParent ); |
676 | 0 | return; |
677 | 0 | } |
678 | | // end wrapping related part ==================== |
679 | | |
680 | 0 | m_xParent = xParent; |
681 | 0 | } |
682 | | |
683 | | void OleEmbeddedObject::setStream(const css::uno::Reference<css::io::XStream>& xStream) |
684 | 0 | { |
685 | 0 | m_xObjectStream = xStream; |
686 | 0 | } |
687 | | |
688 | | css::uno::Reference<css::io::XStream> OleEmbeddedObject::getStream() |
689 | 0 | { |
690 | 0 | return m_xObjectStream; |
691 | 0 | } |
692 | | |
693 | | void OleEmbeddedObject::initialize(const uno::Sequence<uno::Any>& rArguments) |
694 | 0 | { |
695 | 0 | if (!rArguments.hasElements()) |
696 | 0 | return; |
697 | | |
698 | 0 | comphelper::SequenceAsHashMap aValues(rArguments[0]); |
699 | 0 | auto it = aValues.find(u"StreamReadOnly"_ustr); |
700 | 0 | if (it != aValues.end()) |
701 | 0 | it->second >>= m_bStreamReadOnly; |
702 | 0 | } |
703 | | |
704 | | OUString SAL_CALL OleEmbeddedObject::getImplementationName() |
705 | 0 | { |
706 | 0 | return u"com.sun.star.comp.embed.OleEmbeddedObject"_ustr; |
707 | 0 | } |
708 | | |
709 | | sal_Bool SAL_CALL OleEmbeddedObject::supportsService(const OUString& ServiceName) |
710 | 0 | { |
711 | 0 | return cppu::supportsService(this, ServiceName); |
712 | 0 | } |
713 | | |
714 | | uno::Sequence<OUString> SAL_CALL OleEmbeddedObject::getSupportedServiceNames() |
715 | 0 | { |
716 | 0 | return { u"com.sun.star.comp.embed.OleEmbeddedObject"_ustr }; |
717 | 0 | } |
718 | | |
719 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |