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