/src/libreoffice/embeddedobj/source/general/dummyobject.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 <com/sun/star/embed/EmbedStates.hpp> |
21 | | #include <com/sun/star/embed/UnreachableStateException.hpp> |
22 | | #include <com/sun/star/embed/WrongStateException.hpp> |
23 | | #include <com/sun/star/embed/Aspects.hpp> |
24 | | #include <com/sun/star/embed/EmbedMapUnits.hpp> |
25 | | #include <com/sun/star/embed/EntryInitModes.hpp> |
26 | | #include <com/sun/star/embed/NoVisualAreaSizeException.hpp> |
27 | | #include <com/sun/star/io/IOException.hpp> |
28 | | #include <com/sun/star/lang/DisposedException.hpp> |
29 | | #include <com/sun/star/lang/IllegalArgumentException.hpp> |
30 | | #include <com/sun/star/lang/NoSupportException.hpp> |
31 | | |
32 | | #include <comphelper/multicontainer2.hxx> |
33 | | #include <cppuhelper/supportsservice.hxx> |
34 | | #include <osl/diagnose.h> |
35 | | #include <dummyobject.hxx> |
36 | | |
37 | | |
38 | | using namespace ::com::sun::star; |
39 | | |
40 | | |
41 | | void ODummyEmbeddedObject::CheckInit_WrongState() |
42 | 0 | { |
43 | 0 | if ( m_bDisposed ) |
44 | 0 | throw lang::DisposedException(); |
45 | | |
46 | 0 | if ( m_nObjectState == -1 ) |
47 | 0 | throw embed::WrongStateException( u"The object has no persistence!"_ustr, |
48 | 0 | static_cast< ::cppu::OWeakObject* >(this) ); |
49 | 0 | } |
50 | | |
51 | | void ODummyEmbeddedObject::CheckInit_Runtime() |
52 | 0 | { |
53 | 0 | if ( m_bDisposed ) |
54 | 0 | throw lang::DisposedException(); |
55 | | |
56 | 0 | if ( m_nObjectState == -1 ) |
57 | 0 | throw uno::RuntimeException( u"The object has no persistence!"_ustr, |
58 | 0 | static_cast< ::cppu::OWeakObject* >(this) ); |
59 | 0 | } |
60 | | void ODummyEmbeddedObject::PostEvent_Impl( const OUString& aEventName ) |
61 | 0 | { |
62 | 0 | if ( !m_pInterfaceContainer ) |
63 | 0 | return; |
64 | | |
65 | 0 | comphelper::OInterfaceContainerHelper2* pIC = m_pInterfaceContainer->getContainer( |
66 | 0 | cppu::UnoType<document::XEventListener>::get()); |
67 | 0 | if( !pIC ) |
68 | 0 | return; |
69 | | |
70 | 0 | document::EventObject aEvent; |
71 | 0 | aEvent.EventName = aEventName; |
72 | 0 | aEvent.Source.set( static_cast< ::cppu::OWeakObject* >( this ) ); |
73 | | // For now all the events are sent as object events |
74 | | // aEvent.Source = ( xSource.is() ? xSource |
75 | | // : uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >( this ) ) ); |
76 | 0 | comphelper::OInterfaceIteratorHelper2 aIt( *pIC ); |
77 | 0 | while( aIt.hasMoreElements() ) |
78 | 0 | { |
79 | 0 | try |
80 | 0 | { |
81 | 0 | static_cast<document::XEventListener *>(aIt.next())->notifyEvent( aEvent ); |
82 | 0 | } |
83 | 0 | catch( const uno::RuntimeException& ) |
84 | 0 | { |
85 | 0 | aIt.remove(); |
86 | 0 | } |
87 | | |
88 | | // the listener could dispose the object. |
89 | 0 | if ( m_bDisposed ) |
90 | 0 | return; |
91 | 0 | } |
92 | 0 | } |
93 | | |
94 | | |
95 | | ODummyEmbeddedObject::~ODummyEmbeddedObject() |
96 | 0 | { |
97 | 0 | } |
98 | | |
99 | | |
100 | | void SAL_CALL ODummyEmbeddedObject::changeState( sal_Int32 nNewState ) |
101 | 0 | { |
102 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
103 | 0 | CheckInit_WrongState(); |
104 | |
|
105 | 0 | if ( nNewState == embed::EmbedStates::LOADED ) |
106 | 0 | return; |
107 | | |
108 | 0 | throw embed::UnreachableStateException(); |
109 | 0 | } |
110 | | |
111 | | |
112 | | uno::Sequence< sal_Int32 > SAL_CALL ODummyEmbeddedObject::getReachableStates() |
113 | 0 | { |
114 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
115 | 0 | CheckInit_WrongState(); |
116 | |
|
117 | 0 | return { embed::EmbedStates::LOADED }; |
118 | 0 | } |
119 | | |
120 | | |
121 | | sal_Int32 SAL_CALL ODummyEmbeddedObject::getCurrentState() |
122 | 0 | { |
123 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
124 | 0 | CheckInit_WrongState(); |
125 | |
|
126 | 0 | return m_nObjectState; |
127 | 0 | } |
128 | | |
129 | | |
130 | | void SAL_CALL ODummyEmbeddedObject::doVerb( sal_Int32 ) |
131 | 0 | { |
132 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
133 | 0 | CheckInit_WrongState(); |
134 | | |
135 | | // no supported verbs |
136 | 0 | } |
137 | | |
138 | | |
139 | | uno::Sequence< embed::VerbDescriptor > SAL_CALL ODummyEmbeddedObject::getSupportedVerbs() |
140 | 0 | { |
141 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
142 | 0 | CheckInit_WrongState(); |
143 | |
|
144 | 0 | return uno::Sequence< embed::VerbDescriptor >(); |
145 | 0 | } |
146 | | |
147 | | |
148 | | void SAL_CALL ODummyEmbeddedObject::setClientSite( |
149 | | const uno::Reference< embed::XEmbeddedClient >& xClient ) |
150 | 0 | { |
151 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
152 | 0 | CheckInit_WrongState(); |
153 | |
|
154 | 0 | m_xClientSite = xClient; |
155 | 0 | } |
156 | | |
157 | | |
158 | | uno::Reference< embed::XEmbeddedClient > SAL_CALL ODummyEmbeddedObject::getClientSite() |
159 | 0 | { |
160 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
161 | 0 | CheckInit_WrongState(); |
162 | |
|
163 | 0 | return m_xClientSite; |
164 | 0 | } |
165 | | |
166 | | |
167 | | void SAL_CALL ODummyEmbeddedObject::update() |
168 | 0 | { |
169 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
170 | 0 | CheckInit_WrongState(); |
171 | 0 | } |
172 | | |
173 | | |
174 | | void SAL_CALL ODummyEmbeddedObject::setUpdateMode( sal_Int32 ) |
175 | 0 | { |
176 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
177 | 0 | CheckInit_WrongState(); |
178 | 0 | } |
179 | | |
180 | | |
181 | | sal_Int64 SAL_CALL ODummyEmbeddedObject::getStatus( sal_Int64 ) |
182 | 0 | { |
183 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
184 | 0 | CheckInit_WrongState(); |
185 | |
|
186 | 0 | return 0; |
187 | 0 | } |
188 | | |
189 | | |
190 | | void SAL_CALL ODummyEmbeddedObject::setContainerName( const OUString& ) |
191 | 0 | { |
192 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
193 | 0 | CheckInit_Runtime(); |
194 | 0 | } |
195 | | |
196 | | |
197 | | void SAL_CALL ODummyEmbeddedObject::setVisualAreaSize( sal_Int64 nAspect, const awt::Size& aSize ) |
198 | 0 | { |
199 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
200 | 0 | CheckInit_WrongState(); |
201 | |
|
202 | 0 | OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!" ); |
203 | 0 | if ( nAspect == embed::Aspects::MSOLE_ICON ) |
204 | | // no representation can be retrieved |
205 | 0 | throw embed::WrongStateException( u"Illegal call!"_ustr, |
206 | 0 | static_cast< ::cppu::OWeakObject* >(this) ); |
207 | | |
208 | 0 | m_nCachedAspect = nAspect; |
209 | 0 | m_aCachedSize = aSize; |
210 | 0 | m_bHasCachedSize = true; |
211 | 0 | } |
212 | | |
213 | | |
214 | | awt::Size SAL_CALL ODummyEmbeddedObject::getVisualAreaSize( sal_Int64 nAspect ) |
215 | 0 | { |
216 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
217 | 0 | CheckInit_WrongState(); |
218 | |
|
219 | 0 | OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!" ); |
220 | 0 | if ( nAspect == embed::Aspects::MSOLE_ICON ) |
221 | | // no representation can be retrieved |
222 | 0 | throw embed::WrongStateException( u"Illegal call!"_ustr, |
223 | 0 | static_cast< ::cppu::OWeakObject* >(this) ); |
224 | | |
225 | 0 | if ( !m_bHasCachedSize || m_nCachedAspect != nAspect ) |
226 | 0 | throw embed::NoVisualAreaSizeException( |
227 | 0 | u"No size available!"_ustr, |
228 | 0 | static_cast< ::cppu::OWeakObject* >(this) ); |
229 | | |
230 | 0 | return m_aCachedSize; |
231 | 0 | } |
232 | | |
233 | | |
234 | | sal_Int32 SAL_CALL ODummyEmbeddedObject::getMapUnit( sal_Int64 nAspect ) |
235 | 0 | { |
236 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
237 | 0 | CheckInit_Runtime(); |
238 | |
|
239 | 0 | OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!" ); |
240 | 0 | if ( nAspect == embed::Aspects::MSOLE_ICON ) |
241 | | // no representation can be retrieved |
242 | 0 | throw embed::WrongStateException( u"Illegal call!"_ustr, |
243 | 0 | static_cast< ::cppu::OWeakObject* >(this) ); |
244 | | |
245 | 0 | return embed::EmbedMapUnits::ONE_100TH_MM; |
246 | 0 | } |
247 | | |
248 | | |
249 | | embed::VisualRepresentation SAL_CALL ODummyEmbeddedObject::getPreferredVisualRepresentation( sal_Int64 ) |
250 | 0 | { |
251 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
252 | 0 | CheckInit_WrongState(); |
253 | | |
254 | | // no representation can be retrieved |
255 | 0 | throw embed::WrongStateException( u"Illegal call!"_ustr, |
256 | 0 | static_cast< ::cppu::OWeakObject* >(this) ); |
257 | 0 | } |
258 | | |
259 | | |
260 | | void SAL_CALL ODummyEmbeddedObject::setPersistentEntry( |
261 | | const uno::Reference< embed::XStorage >& xStorage, |
262 | | const OUString& sEntName, |
263 | | sal_Int32 nEntryConnectionMode, |
264 | | const uno::Sequence< beans::PropertyValue >& /* lArguments */, |
265 | | const uno::Sequence< beans::PropertyValue >& /* lObjArgs */ ) |
266 | 0 | { |
267 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
268 | 0 | if ( m_bDisposed ) |
269 | 0 | throw lang::DisposedException(); // TODO |
270 | | |
271 | 0 | if ( !xStorage.is() ) |
272 | 0 | throw lang::IllegalArgumentException( u"No parent storage is provided!"_ustr, |
273 | 0 | static_cast< ::cppu::OWeakObject* >(this), |
274 | 0 | 1 ); |
275 | | |
276 | 0 | if ( sEntName.isEmpty() ) |
277 | 0 | throw lang::IllegalArgumentException( u"Empty element name is provided!"_ustr, |
278 | 0 | static_cast< ::cppu::OWeakObject* >(this), |
279 | 0 | 2 ); |
280 | | |
281 | 0 | if ( ( m_nObjectState != -1 || nEntryConnectionMode == embed::EntryInitModes::NO_INIT ) |
282 | 0 | && ( m_nObjectState == -1 || nEntryConnectionMode != embed::EntryInitModes::NO_INIT ) ) |
283 | 0 | { |
284 | 0 | throw embed::WrongStateException( |
285 | 0 | u"Can't change persistent representation of activated object!"_ustr, |
286 | 0 | static_cast< ::cppu::OWeakObject* >(this) ); |
287 | 0 | } |
288 | | |
289 | 0 | if ( m_bWaitSaveCompleted ) |
290 | 0 | { |
291 | 0 | if ( nEntryConnectionMode != embed::EntryInitModes::NO_INIT ) |
292 | 0 | throw embed::WrongStateException( |
293 | 0 | u"The object waits for saveCompleted() call!"_ustr, |
294 | 0 | static_cast< ::cppu::OWeakObject* >(this) ); |
295 | | |
296 | 0 | saveCompleted( m_xParentStorage != xStorage || m_aEntryName != sEntName ); |
297 | |
|
298 | 0 | } |
299 | | |
300 | 0 | if ( nEntryConnectionMode != embed::EntryInitModes::DEFAULT_INIT |
301 | 0 | && nEntryConnectionMode != embed::EntryInitModes::NO_INIT ) |
302 | 0 | throw lang::IllegalArgumentException( u"Wrong connection mode is provided!"_ustr, |
303 | 0 | static_cast< ::cppu::OWeakObject* >(this), |
304 | 0 | 3 ); |
305 | | |
306 | 0 | if ( !xStorage->hasByName( sEntName ) ) |
307 | 0 | throw lang::IllegalArgumentException( u"Wrong entry is provided!"_ustr, |
308 | 0 | static_cast< ::cppu::OWeakObject* >(this), |
309 | 0 | 2 ); |
310 | | |
311 | 0 | m_xParentStorage = xStorage; |
312 | 0 | m_aEntryName = sEntName; |
313 | 0 | m_nObjectState = embed::EmbedStates::LOADED; |
314 | 0 | } |
315 | | |
316 | | |
317 | | void SAL_CALL ODummyEmbeddedObject::storeToEntry( const uno::Reference< embed::XStorage >& xStorage, |
318 | | const OUString& sEntName, |
319 | | const uno::Sequence< beans::PropertyValue >& /* lArguments */, |
320 | | const uno::Sequence< beans::PropertyValue >& /* lObjArgs */ ) |
321 | 0 | { |
322 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
323 | 0 | CheckInit_WrongState(); |
324 | |
|
325 | 0 | if ( m_bWaitSaveCompleted ) |
326 | 0 | throw embed::WrongStateException( |
327 | 0 | u"The object waits for saveCompleted() call!"_ustr, |
328 | 0 | static_cast< ::cppu::OWeakObject* >(this) ); |
329 | | |
330 | 0 | m_xParentStorage->copyElementTo( m_aEntryName, xStorage, sEntName ); |
331 | 0 | } |
332 | | |
333 | | |
334 | | void SAL_CALL ODummyEmbeddedObject::storeAsEntry( const uno::Reference< embed::XStorage >& xStorage, |
335 | | const OUString& sEntName, |
336 | | const uno::Sequence< beans::PropertyValue >& /* lArguments */, |
337 | | const uno::Sequence< beans::PropertyValue >& /* lObjArgs */ ) |
338 | 0 | { |
339 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
340 | 0 | CheckInit_WrongState(); |
341 | |
|
342 | 0 | if ( m_bWaitSaveCompleted ) |
343 | 0 | throw embed::WrongStateException( |
344 | 0 | u"The object waits for saveCompleted() call!"_ustr, |
345 | 0 | static_cast< ::cppu::OWeakObject* >(this) ); |
346 | | |
347 | 0 | PostEvent_Impl( u"OnSaveAs"_ustr ); |
348 | |
|
349 | 0 | m_xParentStorage->copyElementTo( m_aEntryName, xStorage, sEntName ); |
350 | |
|
351 | 0 | m_bWaitSaveCompleted = true; |
352 | 0 | m_xNewParentStorage = xStorage; |
353 | 0 | m_aNewEntryName = sEntName; |
354 | 0 | } |
355 | | |
356 | | |
357 | | void SAL_CALL ODummyEmbeddedObject::saveCompleted( sal_Bool bUseNew ) |
358 | 0 | { |
359 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
360 | 0 | CheckInit_WrongState(); |
361 | | |
362 | | // it is allowed to call saveCompleted( false ) for nonstored objects |
363 | 0 | if ( !m_bWaitSaveCompleted && !bUseNew ) |
364 | 0 | return; |
365 | | |
366 | 0 | OSL_ENSURE( m_bWaitSaveCompleted, "Unexpected saveCompleted() call!" ); |
367 | 0 | if ( !m_bWaitSaveCompleted ) |
368 | 0 | throw io::IOException(); // TODO: illegal call |
369 | | |
370 | 0 | OSL_ENSURE( m_xNewParentStorage.is() , "Internal object information is broken!" ); |
371 | 0 | if ( !m_xNewParentStorage.is() ) |
372 | 0 | throw uno::RuntimeException(); // TODO: broken internal information |
373 | | |
374 | 0 | if ( bUseNew ) |
375 | 0 | { |
376 | 0 | m_xParentStorage = m_xNewParentStorage; |
377 | 0 | m_aEntryName = m_aNewEntryName; |
378 | |
|
379 | 0 | PostEvent_Impl( u"OnSaveAsDone"_ustr ); |
380 | 0 | } |
381 | |
|
382 | 0 | m_xNewParentStorage.clear(); |
383 | 0 | m_aNewEntryName.clear(); |
384 | 0 | m_bWaitSaveCompleted = false; |
385 | 0 | } |
386 | | |
387 | | |
388 | | sal_Bool SAL_CALL ODummyEmbeddedObject::hasEntry() |
389 | 0 | { |
390 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
391 | 0 | CheckInit_WrongState(); |
392 | |
|
393 | 0 | if ( m_bWaitSaveCompleted ) |
394 | 0 | throw embed::WrongStateException( |
395 | 0 | u"The object waits for saveCompleted() call!"_ustr, |
396 | 0 | static_cast< ::cppu::OWeakObject* >(this) ); |
397 | | |
398 | 0 | if ( !m_aEntryName.isEmpty() ) |
399 | 0 | return true; |
400 | | |
401 | 0 | return false; |
402 | 0 | } |
403 | | |
404 | | |
405 | | OUString SAL_CALL ODummyEmbeddedObject::getEntryName() |
406 | 0 | { |
407 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
408 | 0 | CheckInit_WrongState(); |
409 | |
|
410 | 0 | if ( m_bWaitSaveCompleted ) |
411 | 0 | throw embed::WrongStateException( |
412 | 0 | u"The object waits for saveCompleted() call!"_ustr, |
413 | 0 | static_cast< ::cppu::OWeakObject* >(this) ); |
414 | | |
415 | 0 | return m_aEntryName; |
416 | 0 | } |
417 | | |
418 | | |
419 | | void SAL_CALL ODummyEmbeddedObject::storeOwn() |
420 | 0 | { |
421 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
422 | 0 | CheckInit_WrongState(); |
423 | |
|
424 | 0 | if ( m_bWaitSaveCompleted ) |
425 | 0 | throw embed::WrongStateException( |
426 | 0 | u"The object waits for saveCompleted() call!"_ustr, |
427 | 0 | static_cast< ::cppu::OWeakObject* >(this) ); |
428 | | |
429 | | // the object can not be activated or changed |
430 | 0 | } |
431 | | |
432 | | |
433 | | sal_Bool SAL_CALL ODummyEmbeddedObject::isReadonly() |
434 | 0 | { |
435 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
436 | 0 | CheckInit_WrongState(); |
437 | |
|
438 | 0 | if ( m_bWaitSaveCompleted ) |
439 | 0 | throw embed::WrongStateException( |
440 | 0 | u"The object waits for saveCompleted() call!"_ustr, |
441 | 0 | static_cast< ::cppu::OWeakObject* >(this) ); |
442 | | |
443 | | // this object can not be changed |
444 | 0 | return true; |
445 | 0 | } |
446 | | |
447 | | |
448 | | void SAL_CALL ODummyEmbeddedObject::reload( |
449 | | const uno::Sequence< beans::PropertyValue >& /* lArguments */, |
450 | | const uno::Sequence< beans::PropertyValue >& /* lObjArgs */ ) |
451 | 0 | { |
452 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
453 | 0 | CheckInit_WrongState(); |
454 | |
|
455 | 0 | if ( m_bWaitSaveCompleted ) |
456 | 0 | throw embed::WrongStateException( |
457 | 0 | u"The object waits for saveCompleted() call!"_ustr, |
458 | 0 | static_cast< ::cppu::OWeakObject* >(this) ); |
459 | | |
460 | | // nothing to reload |
461 | 0 | } |
462 | | |
463 | | |
464 | | uno::Sequence< sal_Int8 > SAL_CALL ODummyEmbeddedObject::getClassID() |
465 | 0 | { |
466 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
467 | 0 | CheckInit_Runtime(); |
468 | | |
469 | | // currently the class ID is empty |
470 | | // TODO/LATER: should a special class ID be used in this case? |
471 | 0 | return uno::Sequence< sal_Int8 >(); |
472 | 0 | } |
473 | | |
474 | | |
475 | | OUString SAL_CALL ODummyEmbeddedObject::getClassName() |
476 | 0 | { |
477 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
478 | 0 | if ( m_bDisposed ) |
479 | 0 | throw lang::DisposedException(); // TODO |
480 | | |
481 | 0 | return OUString(); |
482 | 0 | } |
483 | | |
484 | | |
485 | | void SAL_CALL ODummyEmbeddedObject::setClassInfo( |
486 | | const uno::Sequence< sal_Int8 >& /*aClassID*/, const OUString& /*aClassName*/ ) |
487 | 0 | { |
488 | 0 | throw lang::NoSupportException(); |
489 | 0 | } |
490 | | |
491 | | |
492 | | uno::Reference< util::XCloseable > SAL_CALL ODummyEmbeddedObject::getComponent() |
493 | 0 | { |
494 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
495 | 0 | CheckInit_Runtime(); |
496 | |
|
497 | 0 | return uno::Reference< util::XCloseable >(); |
498 | 0 | } |
499 | | |
500 | | |
501 | | void SAL_CALL ODummyEmbeddedObject::addStateChangeListener( const uno::Reference< embed::XStateChangeListener >& xListener ) |
502 | 0 | { |
503 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
504 | 0 | if ( m_bDisposed ) |
505 | 0 | return; |
506 | | |
507 | 0 | if ( !m_pInterfaceContainer ) |
508 | 0 | m_pInterfaceContainer.reset(new comphelper::OMultiTypeInterfaceContainerHelper2( m_aMutex )); |
509 | |
|
510 | 0 | m_pInterfaceContainer->addInterface( cppu::UnoType<embed::XStateChangeListener>::get(), |
511 | 0 | xListener ); |
512 | 0 | } |
513 | | |
514 | | |
515 | | void SAL_CALL ODummyEmbeddedObject::removeStateChangeListener( |
516 | | const uno::Reference< embed::XStateChangeListener >& xListener ) |
517 | 0 | { |
518 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
519 | 0 | if ( m_pInterfaceContainer ) |
520 | 0 | m_pInterfaceContainer->removeInterface( cppu::UnoType<embed::XStateChangeListener>::get(), |
521 | 0 | xListener ); |
522 | 0 | } |
523 | | |
524 | | |
525 | | void SAL_CALL ODummyEmbeddedObject::close( sal_Bool bDeliverOwnership ) |
526 | 0 | { |
527 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
528 | 0 | if ( m_bDisposed ) |
529 | 0 | throw lang::DisposedException(); // TODO |
530 | | |
531 | 0 | uno::Reference< uno::XInterface > xSelfHold( static_cast< ::cppu::OWeakObject* >( this ) ); |
532 | 0 | lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >( this ) ); |
533 | |
|
534 | 0 | if ( m_pInterfaceContainer ) |
535 | 0 | { |
536 | 0 | comphelper::OInterfaceContainerHelper2* pContainer = |
537 | 0 | m_pInterfaceContainer->getContainer( cppu::UnoType<util::XCloseListener>::get()); |
538 | 0 | if ( pContainer != nullptr ) |
539 | 0 | { |
540 | 0 | comphelper::OInterfaceIteratorHelper2 pIterator(*pContainer); |
541 | 0 | while (pIterator.hasMoreElements()) |
542 | 0 | { |
543 | 0 | try |
544 | 0 | { |
545 | 0 | static_cast<util::XCloseListener*>(pIterator.next())->queryClosing( aSource, bDeliverOwnership ); |
546 | 0 | } |
547 | 0 | catch( const uno::RuntimeException& ) |
548 | 0 | { |
549 | 0 | pIterator.remove(); |
550 | 0 | } |
551 | 0 | } |
552 | 0 | } |
553 | |
|
554 | 0 | pContainer = m_pInterfaceContainer->getContainer( |
555 | 0 | cppu::UnoType<util::XCloseListener>::get()); |
556 | 0 | if ( pContainer != nullptr ) |
557 | 0 | { |
558 | 0 | comphelper::OInterfaceIteratorHelper2 pCloseIterator(*pContainer); |
559 | 0 | while (pCloseIterator.hasMoreElements()) |
560 | 0 | { |
561 | 0 | try |
562 | 0 | { |
563 | 0 | static_cast<util::XCloseListener*>(pCloseIterator.next())->notifyClosing( aSource ); |
564 | 0 | } |
565 | 0 | catch( const uno::RuntimeException& ) |
566 | 0 | { |
567 | 0 | pCloseIterator.remove(); |
568 | 0 | } |
569 | 0 | } |
570 | 0 | } |
571 | |
|
572 | 0 | m_pInterfaceContainer->disposeAndClear( aSource ); |
573 | 0 | } |
574 | |
|
575 | 0 | m_bDisposed = true; // the object is disposed now for outside |
576 | 0 | } |
577 | | |
578 | | |
579 | | void SAL_CALL ODummyEmbeddedObject::addCloseListener( const uno::Reference< util::XCloseListener >& xListener ) |
580 | 0 | { |
581 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
582 | 0 | if ( m_bDisposed ) |
583 | 0 | return; |
584 | | |
585 | 0 | if ( !m_pInterfaceContainer ) |
586 | 0 | m_pInterfaceContainer.reset(new comphelper::OMultiTypeInterfaceContainerHelper2( m_aMutex )); |
587 | |
|
588 | 0 | m_pInterfaceContainer->addInterface( cppu::UnoType<util::XCloseListener>::get(), xListener ); |
589 | 0 | } |
590 | | |
591 | | |
592 | | void SAL_CALL ODummyEmbeddedObject::removeCloseListener( const uno::Reference< util::XCloseListener >& xListener ) |
593 | 0 | { |
594 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
595 | 0 | if ( m_pInterfaceContainer ) |
596 | 0 | m_pInterfaceContainer->removeInterface( cppu::UnoType<util::XCloseListener>::get(), |
597 | 0 | xListener ); |
598 | 0 | } |
599 | | |
600 | | |
601 | | void SAL_CALL ODummyEmbeddedObject::addEventListener( const uno::Reference< document::XEventListener >& xListener ) |
602 | 0 | { |
603 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
604 | 0 | if ( m_bDisposed ) |
605 | 0 | return; |
606 | | |
607 | 0 | if ( !m_pInterfaceContainer ) |
608 | 0 | m_pInterfaceContainer.reset(new comphelper::OMultiTypeInterfaceContainerHelper2( m_aMutex )); |
609 | |
|
610 | 0 | m_pInterfaceContainer->addInterface( cppu::UnoType<document::XEventListener>::get(), xListener ); |
611 | 0 | } |
612 | | |
613 | | |
614 | | void SAL_CALL ODummyEmbeddedObject::removeEventListener( const uno::Reference< document::XEventListener >& xListener ) |
615 | 0 | { |
616 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
617 | 0 | if ( m_pInterfaceContainer ) |
618 | 0 | m_pInterfaceContainer->removeInterface( cppu::UnoType<document::XEventListener>::get(), |
619 | 0 | xListener ); |
620 | 0 | } |
621 | | |
622 | | OUString SAL_CALL ODummyEmbeddedObject::getImplementationName() |
623 | 0 | { |
624 | 0 | return u"com.sun.star.comp.embed.ODummyEmbeddedObject"_ustr; |
625 | 0 | } |
626 | | |
627 | | sal_Bool SAL_CALL ODummyEmbeddedObject::supportsService(const OUString& ServiceName) |
628 | 0 | { |
629 | 0 | return cppu::supportsService(this, ServiceName); |
630 | 0 | } |
631 | | |
632 | | uno::Sequence<OUString> SAL_CALL ODummyEmbeddedObject::getSupportedServiceNames() |
633 | 0 | { |
634 | 0 | return { u"com.sun.star.comp.embed.ODummyEmbeddedObject"_ustr }; |
635 | 0 | } |
636 | | |
637 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |