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