1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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/Aspects.hpp>
28 #include <com/sun/star/embed/EmbedMapUnits.hpp>
29 #include <com/sun/star/embed/EntryInitModes.hpp>
30 #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
31 #include <com/sun/star/lang/DisposedException.hpp>
33 #include <cppuhelper/interfacecontainer.h>
35 #include <dummyobject.hxx>
38 using namespace ::com::sun::star
;
41 void ODummyEmbeddedObject::CheckInit_WrongState()
44 throw lang::DisposedException();
46 if ( m_nObjectState
== -1 )
47 throw embed::WrongStateException( "The object has no persistence!",
48 static_cast< ::cppu::OWeakObject
* >(this) );
51 void ODummyEmbeddedObject::CheckInit_Runtime()
54 throw lang::DisposedException();
56 if ( m_nObjectState
== -1 )
57 throw uno::RuntimeException( "The object has no persistence!",
58 static_cast< ::cppu::OWeakObject
* >(this) );
60 void ODummyEmbeddedObject::PostEvent_Impl( const OUString
& aEventName
)
62 if ( m_pInterfaceContainer
)
64 ::cppu::OInterfaceContainerHelper
* pIC
= m_pInterfaceContainer
->getContainer(
65 cppu::UnoType
<document::XEventListener
>::get());
68 document::EventObject aEvent
;
69 aEvent
.EventName
= aEventName
;
70 aEvent
.Source
= uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >( this ) );
71 // For now all the events are sent as object events
72 // aEvent.Source = ( xSource.is() ? xSource
73 // : uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >( this ) ) );
74 ::cppu::OInterfaceIteratorHelper
aIt( *pIC
);
75 while( aIt
.hasMoreElements() )
79 static_cast<document::XEventListener
*>(aIt
.next())->notifyEvent( aEvent
);
81 catch( const uno::RuntimeException
& )
86 // the listener could dispose the object.
95 ODummyEmbeddedObject::~ODummyEmbeddedObject()
100 void SAL_CALL
ODummyEmbeddedObject::changeState( sal_Int32 nNewState
)
101 throw ( embed::UnreachableStateException
,
102 embed::WrongStateException
,
104 uno::RuntimeException
, std::exception
)
106 ::osl::MutexGuard
aGuard( m_aMutex
);
107 CheckInit_WrongState();
109 if ( nNewState
== embed::EmbedStates::LOADED
)
112 throw embed::UnreachableStateException();
116 uno::Sequence
< sal_Int32
> SAL_CALL
ODummyEmbeddedObject::getReachableStates()
117 throw ( embed::WrongStateException
,
118 uno::RuntimeException
, std::exception
)
120 ::osl::MutexGuard
aGuard( m_aMutex
);
121 CheckInit_WrongState();
123 uno::Sequence
< sal_Int32
> aResult( 1 );
124 aResult
[0] = embed::EmbedStates::LOADED
;
130 sal_Int32 SAL_CALL
ODummyEmbeddedObject::getCurrentState()
131 throw ( embed::WrongStateException
,
132 uno::RuntimeException
, std::exception
)
134 ::osl::MutexGuard
aGuard( m_aMutex
);
135 CheckInit_WrongState();
137 return m_nObjectState
;
141 void SAL_CALL
ODummyEmbeddedObject::doVerb( sal_Int32
)
142 throw ( lang::IllegalArgumentException
,
143 embed::WrongStateException
,
144 embed::UnreachableStateException
,
146 uno::RuntimeException
, std::exception
)
148 ::osl::MutexGuard
aGuard( m_aMutex
);
149 CheckInit_WrongState();
151 // no supported verbs
155 uno::Sequence
< embed::VerbDescriptor
> SAL_CALL
ODummyEmbeddedObject::getSupportedVerbs()
156 throw ( embed::WrongStateException
,
157 uno::RuntimeException
, std::exception
)
159 ::osl::MutexGuard
aGuard( m_aMutex
);
160 CheckInit_WrongState();
162 return uno::Sequence
< embed::VerbDescriptor
>();
166 void SAL_CALL
ODummyEmbeddedObject::setClientSite(
167 const uno::Reference
< embed::XEmbeddedClient
>& xClient
)
168 throw ( embed::WrongStateException
,
169 uno::RuntimeException
, std::exception
)
171 ::osl::MutexGuard
aGuard( m_aMutex
);
172 CheckInit_WrongState();
174 m_xClientSite
= xClient
;
178 uno::Reference
< embed::XEmbeddedClient
> SAL_CALL
ODummyEmbeddedObject::getClientSite()
179 throw ( embed::WrongStateException
,
180 uno::RuntimeException
, std::exception
)
182 ::osl::MutexGuard
aGuard( m_aMutex
);
183 CheckInit_WrongState();
185 return m_xClientSite
;
189 void SAL_CALL
ODummyEmbeddedObject::update()
190 throw ( embed::WrongStateException
,
192 uno::RuntimeException
, std::exception
)
194 ::osl::MutexGuard
aGuard( m_aMutex
);
195 CheckInit_WrongState();
199 void SAL_CALL
ODummyEmbeddedObject::setUpdateMode( sal_Int32
)
200 throw ( embed::WrongStateException
,
201 uno::RuntimeException
, std::exception
)
203 ::osl::MutexGuard
aGuard( m_aMutex
);
204 CheckInit_WrongState();
208 sal_Int64 SAL_CALL
ODummyEmbeddedObject::getStatus( sal_Int64
)
209 throw ( embed::WrongStateException
,
210 uno::RuntimeException
, std::exception
)
212 ::osl::MutexGuard
aGuard( m_aMutex
);
213 CheckInit_WrongState();
219 void SAL_CALL
ODummyEmbeddedObject::setContainerName( const OUString
& )
220 throw ( uno::RuntimeException
, std::exception
)
222 ::osl::MutexGuard
aGuard( m_aMutex
);
227 void SAL_CALL
ODummyEmbeddedObject::setVisualAreaSize( sal_Int64 nAspect
, const awt::Size
& aSize
)
228 throw ( lang::IllegalArgumentException
,
229 embed::WrongStateException
,
231 uno::RuntimeException
, std::exception
)
233 ::osl::MutexGuard
aGuard( m_aMutex
);
234 CheckInit_WrongState();
236 OSL_ENSURE( nAspect
!= embed::Aspects::MSOLE_ICON
, "For iconified objects no graphical replacement is required!\n" );
237 if ( nAspect
== embed::Aspects::MSOLE_ICON
)
238 // no representation can be retrieved
239 throw embed::WrongStateException( "Illegal call!",
240 static_cast< ::cppu::OWeakObject
* >(this) );
242 m_nCachedAspect
= nAspect
;
243 m_aCachedSize
= aSize
;
244 m_bHasCachedSize
= true;
248 awt::Size SAL_CALL
ODummyEmbeddedObject::getVisualAreaSize( sal_Int64 nAspect
)
249 throw ( lang::IllegalArgumentException
,
250 embed::WrongStateException
,
252 uno::RuntimeException
, std::exception
)
254 ::osl::MutexGuard
aGuard( m_aMutex
);
255 CheckInit_WrongState();
257 OSL_ENSURE( nAspect
!= embed::Aspects::MSOLE_ICON
, "For iconified objects no graphical replacement is required!\n" );
258 if ( nAspect
== embed::Aspects::MSOLE_ICON
)
259 // no representation can be retrieved
260 throw embed::WrongStateException( "Illegal call!",
261 static_cast< ::cppu::OWeakObject
* >(this) );
263 if ( !m_bHasCachedSize
|| m_nCachedAspect
!= nAspect
)
264 throw embed::NoVisualAreaSizeException(
265 "No size available!",
266 static_cast< ::cppu::OWeakObject
* >(this) );
268 return m_aCachedSize
;
272 sal_Int32 SAL_CALL
ODummyEmbeddedObject::getMapUnit( sal_Int64 nAspect
)
273 throw ( uno::Exception
,
274 uno::RuntimeException
, std::exception
)
276 ::osl::MutexGuard
aGuard( m_aMutex
);
279 OSL_ENSURE( nAspect
!= embed::Aspects::MSOLE_ICON
, "For iconified objects no graphical replacement is required!\n" );
280 if ( nAspect
== embed::Aspects::MSOLE_ICON
)
281 // no representation can be retrieved
282 throw embed::WrongStateException( "Illegal call!",
283 static_cast< ::cppu::OWeakObject
* >(this) );
285 return embed::EmbedMapUnits::ONE_100TH_MM
;
289 embed::VisualRepresentation SAL_CALL
ODummyEmbeddedObject::getPreferredVisualRepresentation( sal_Int64
)
290 throw ( lang::IllegalArgumentException
,
291 embed::WrongStateException
,
293 uno::RuntimeException
, std::exception
)
295 ::osl::MutexGuard
aGuard( m_aMutex
);
296 CheckInit_WrongState();
298 // no representation can be retrieved
299 throw embed::WrongStateException( "Illegal call!",
300 static_cast< ::cppu::OWeakObject
* >(this) );
304 void SAL_CALL
ODummyEmbeddedObject::setPersistentEntry(
305 const uno::Reference
< embed::XStorage
>& xStorage
,
306 const OUString
& sEntName
,
307 sal_Int32 nEntryConnectionMode
,
308 const uno::Sequence
< beans::PropertyValue
>& /* lArguments */,
309 const uno::Sequence
< beans::PropertyValue
>& /* lObjArgs */ )
310 throw ( lang::IllegalArgumentException
,
311 embed::WrongStateException
,
314 uno::RuntimeException
, std::exception
)
316 ::osl::MutexGuard
aGuard( m_aMutex
);
318 throw lang::DisposedException(); // TODO
320 if ( !xStorage
.is() )
321 throw lang::IllegalArgumentException( "No parent storage is provided!",
322 static_cast< ::cppu::OWeakObject
* >(this),
325 if ( sEntName
.isEmpty() )
326 throw lang::IllegalArgumentException( "Empty element name is provided!",
327 static_cast< ::cppu::OWeakObject
* >(this),
330 if ( ( m_nObjectState
!= -1 || nEntryConnectionMode
== embed::EntryInitModes::NO_INIT
)
331 && ( m_nObjectState
== -1 || nEntryConnectionMode
!= embed::EntryInitModes::NO_INIT
) )
333 throw embed::WrongStateException(
334 "Can't change persistent representation of activated object!",
335 static_cast< ::cppu::OWeakObject
* >(this) );
338 if ( m_bWaitSaveCompleted
)
340 if ( nEntryConnectionMode
== embed::EntryInitModes::NO_INIT
)
341 saveCompleted( ( m_xParentStorage
!= xStorage
|| !m_aEntryName
.equals( sEntName
) ) );
343 throw embed::WrongStateException(
344 "The object waits for saveCompleted() call!",
345 static_cast< ::cppu::OWeakObject
* >(this) );
348 if ( nEntryConnectionMode
== embed::EntryInitModes::DEFAULT_INIT
349 || nEntryConnectionMode
== embed::EntryInitModes::NO_INIT
)
351 if ( xStorage
->hasByName( sEntName
) )
354 m_xParentStorage
= xStorage
;
355 m_aEntryName
= sEntName
;
356 m_nObjectState
= embed::EmbedStates::LOADED
;
359 throw lang::IllegalArgumentException( "Wrong entry is provided!",
360 static_cast< ::cppu::OWeakObject
* >(this),
365 throw lang::IllegalArgumentException( "Wrong connection mode is provided!",
366 static_cast< ::cppu::OWeakObject
* >(this),
371 void SAL_CALL
ODummyEmbeddedObject::storeToEntry( const uno::Reference
< embed::XStorage
>& xStorage
,
372 const OUString
& sEntName
,
373 const uno::Sequence
< beans::PropertyValue
>& /* lArguments */,
374 const uno::Sequence
< beans::PropertyValue
>& /* lObjArgs */ )
375 throw ( lang::IllegalArgumentException
,
376 embed::WrongStateException
,
379 uno::RuntimeException
, std::exception
)
381 ::osl::MutexGuard
aGuard( m_aMutex
);
382 CheckInit_WrongState();
384 if ( m_bWaitSaveCompleted
)
385 throw embed::WrongStateException(
386 "The object waits for saveCompleted() call!",
387 static_cast< ::cppu::OWeakObject
* >(this) );
389 m_xParentStorage
->copyElementTo( m_aEntryName
, xStorage
, sEntName
);
393 void SAL_CALL
ODummyEmbeddedObject::storeAsEntry( const uno::Reference
< embed::XStorage
>& xStorage
,
394 const OUString
& sEntName
,
395 const uno::Sequence
< beans::PropertyValue
>& /* lArguments */,
396 const uno::Sequence
< beans::PropertyValue
>& /* lObjArgs */ )
397 throw ( lang::IllegalArgumentException
,
398 embed::WrongStateException
,
401 uno::RuntimeException
, std::exception
)
403 ::osl::MutexGuard
aGuard( m_aMutex
);
404 CheckInit_WrongState();
406 if ( m_bWaitSaveCompleted
)
407 throw embed::WrongStateException(
408 "The object waits for saveCompleted() call!",
409 static_cast< ::cppu::OWeakObject
* >(this) );
411 PostEvent_Impl( OUString( "OnSaveAs" ) );
413 m_xParentStorage
->copyElementTo( m_aEntryName
, xStorage
, sEntName
);
415 m_bWaitSaveCompleted
= true;
416 m_xNewParentStorage
= xStorage
;
417 m_aNewEntryName
= sEntName
;
421 void SAL_CALL
ODummyEmbeddedObject::saveCompleted( sal_Bool bUseNew
)
422 throw ( embed::WrongStateException
,
424 uno::RuntimeException
, std::exception
)
426 ::osl::MutexGuard
aGuard( m_aMutex
);
427 CheckInit_WrongState();
429 // it is allowed to call saveCompleted( false ) for nonstored objects
430 if ( !m_bWaitSaveCompleted
&& !bUseNew
)
433 OSL_ENSURE( m_bWaitSaveCompleted
, "Unexpected saveCompleted() call!\n" );
434 if ( !m_bWaitSaveCompleted
)
435 throw io::IOException(); // TODO: illegal call
437 OSL_ENSURE( m_xNewParentStorage
.is() , "Internal object information is broken!\n" );
438 if ( !m_xNewParentStorage
.is() )
439 throw uno::RuntimeException(); // TODO: broken internal information
443 m_xParentStorage
= m_xNewParentStorage
;
444 m_aEntryName
= m_aNewEntryName
;
446 PostEvent_Impl( OUString( "OnSaveAsDone" ) );
449 m_xNewParentStorage
= uno::Reference
< embed::XStorage
>();
450 m_aNewEntryName
.clear();
451 m_bWaitSaveCompleted
= false;
455 sal_Bool SAL_CALL
ODummyEmbeddedObject::hasEntry()
456 throw ( embed::WrongStateException
,
457 uno::RuntimeException
, std::exception
)
459 ::osl::MutexGuard
aGuard( m_aMutex
);
460 CheckInit_WrongState();
462 if ( m_bWaitSaveCompleted
)
463 throw embed::WrongStateException(
464 "The object waits for saveCompleted() call!",
465 static_cast< ::cppu::OWeakObject
* >(this) );
467 if ( !m_aEntryName
.isEmpty() )
474 OUString SAL_CALL
ODummyEmbeddedObject::getEntryName()
475 throw ( embed::WrongStateException
,
476 uno::RuntimeException
, std::exception
)
478 ::osl::MutexGuard
aGuard( m_aMutex
);
479 CheckInit_WrongState();
481 if ( m_bWaitSaveCompleted
)
482 throw embed::WrongStateException(
483 "The object waits for saveCompleted() call!",
484 static_cast< ::cppu::OWeakObject
* >(this) );
490 void SAL_CALL
ODummyEmbeddedObject::storeOwn()
491 throw ( embed::WrongStateException
,
494 uno::RuntimeException
, std::exception
)
496 ::osl::MutexGuard
aGuard( m_aMutex
);
497 CheckInit_WrongState();
499 if ( m_bWaitSaveCompleted
)
500 throw embed::WrongStateException(
501 "The object waits for saveCompleted() call!",
502 static_cast< ::cppu::OWeakObject
* >(this) );
504 // the object can not be activated or changed
509 sal_Bool SAL_CALL
ODummyEmbeddedObject::isReadonly()
510 throw ( embed::WrongStateException
,
511 uno::RuntimeException
, std::exception
)
513 ::osl::MutexGuard
aGuard( m_aMutex
);
514 CheckInit_WrongState();
516 if ( m_bWaitSaveCompleted
)
517 throw embed::WrongStateException(
518 "The object waits for saveCompleted() call!",
519 static_cast< ::cppu::OWeakObject
* >(this) );
521 // this object can not be changed
526 void SAL_CALL
ODummyEmbeddedObject::reload(
527 const uno::Sequence
< beans::PropertyValue
>& /* lArguments */,
528 const uno::Sequence
< beans::PropertyValue
>& /* lObjArgs */ )
529 throw ( lang::IllegalArgumentException
,
530 embed::WrongStateException
,
533 uno::RuntimeException
, std::exception
)
535 ::osl::MutexGuard
aGuard( m_aMutex
);
536 CheckInit_WrongState();
538 if ( m_bWaitSaveCompleted
)
539 throw embed::WrongStateException(
540 "The object waits for saveCompleted() call!",
541 static_cast< ::cppu::OWeakObject
* >(this) );
547 uno::Sequence
< sal_Int8
> SAL_CALL
ODummyEmbeddedObject::getClassID()
548 throw ( uno::RuntimeException
, std::exception
)
550 ::osl::MutexGuard
aGuard( m_aMutex
);
553 // currently the class ID is empty
554 // TODO/LATER: should a special class ID be used in this case?
555 return uno::Sequence
< sal_Int8
>();
559 OUString SAL_CALL
ODummyEmbeddedObject::getClassName()
560 throw ( uno::RuntimeException
, std::exception
)
562 ::osl::MutexGuard
aGuard( m_aMutex
);
564 throw lang::DisposedException(); // TODO
570 void SAL_CALL
ODummyEmbeddedObject::setClassInfo(
571 const uno::Sequence
< sal_Int8
>& /*aClassID*/, const OUString
& /*aClassName*/ )
572 throw ( lang::NoSupportException
,
573 uno::RuntimeException
, std::exception
)
575 throw lang::NoSupportException();
579 uno::Reference
< util::XCloseable
> SAL_CALL
ODummyEmbeddedObject::getComponent()
580 throw ( uno::RuntimeException
, std::exception
)
582 ::osl::MutexGuard
aGuard( m_aMutex
);
585 return uno::Reference
< util::XCloseable
>();
589 void SAL_CALL
ODummyEmbeddedObject::addStateChangeListener( const uno::Reference
< embed::XStateChangeListener
>& xListener
)
590 throw ( uno::RuntimeException
, std::exception
)
592 ::osl::MutexGuard
aGuard( m_aMutex
);
596 if ( !m_pInterfaceContainer
)
597 m_pInterfaceContainer
= new ::cppu::OMultiTypeInterfaceContainerHelper( m_aMutex
);
599 m_pInterfaceContainer
->addInterface( cppu::UnoType
<embed::XStateChangeListener
>::get(),
604 void SAL_CALL
ODummyEmbeddedObject::removeStateChangeListener(
605 const uno::Reference
< embed::XStateChangeListener
>& xListener
)
606 throw (uno::RuntimeException
, std::exception
)
608 ::osl::MutexGuard
aGuard( m_aMutex
);
609 if ( m_pInterfaceContainer
)
610 m_pInterfaceContainer
->removeInterface( cppu::UnoType
<embed::XStateChangeListener
>::get(),
615 void SAL_CALL
ODummyEmbeddedObject::close( sal_Bool bDeliverOwnership
)
616 throw ( util::CloseVetoException
,
617 uno::RuntimeException
, std::exception
)
619 ::osl::MutexGuard
aGuard( m_aMutex
);
621 throw lang::DisposedException(); // TODO
623 uno::Reference
< uno::XInterface
> xSelfHold( static_cast< ::cppu::OWeakObject
* >( this ) );
624 lang::EventObject
aSource( static_cast< ::cppu::OWeakObject
* >( this ) );
626 if ( m_pInterfaceContainer
)
628 ::cppu::OInterfaceContainerHelper
* pContainer
=
629 m_pInterfaceContainer
->getContainer( cppu::UnoType
<util::XCloseListener
>::get());
630 if ( pContainer
!= NULL
)
632 ::cppu::OInterfaceIteratorHelper
pIterator(*pContainer
);
633 while (pIterator
.hasMoreElements())
637 static_cast<util::XCloseListener
*>(pIterator
.next())->queryClosing( aSource
, bDeliverOwnership
);
639 catch( const uno::RuntimeException
& )
646 pContainer
= m_pInterfaceContainer
->getContainer(
647 cppu::UnoType
<util::XCloseListener
>::get());
648 if ( pContainer
!= NULL
)
650 ::cppu::OInterfaceIteratorHelper
pCloseIterator(*pContainer
);
651 while (pCloseIterator
.hasMoreElements())
655 static_cast<util::XCloseListener
*>(pCloseIterator
.next())->notifyClosing( aSource
);
657 catch( const uno::RuntimeException
& )
659 pCloseIterator
.remove();
664 m_pInterfaceContainer
->disposeAndClear( aSource
);
667 m_bDisposed
= true; // the object is disposed now for outside
671 void SAL_CALL
ODummyEmbeddedObject::addCloseListener( const uno::Reference
< util::XCloseListener
>& xListener
)
672 throw ( uno::RuntimeException
, std::exception
)
674 ::osl::MutexGuard
aGuard( m_aMutex
);
678 if ( !m_pInterfaceContainer
)
679 m_pInterfaceContainer
= new ::cppu::OMultiTypeInterfaceContainerHelper( m_aMutex
);
681 m_pInterfaceContainer
->addInterface( cppu::UnoType
<util::XCloseListener
>::get(), xListener
);
685 void SAL_CALL
ODummyEmbeddedObject::removeCloseListener( const uno::Reference
< util::XCloseListener
>& xListener
)
686 throw (uno::RuntimeException
, std::exception
)
688 ::osl::MutexGuard
aGuard( m_aMutex
);
689 if ( m_pInterfaceContainer
)
690 m_pInterfaceContainer
->removeInterface( cppu::UnoType
<util::XCloseListener
>::get(),
695 void SAL_CALL
ODummyEmbeddedObject::addEventListener( const uno::Reference
< document::XEventListener
>& xListener
)
696 throw ( uno::RuntimeException
, std::exception
)
698 ::osl::MutexGuard
aGuard( m_aMutex
);
702 if ( !m_pInterfaceContainer
)
703 m_pInterfaceContainer
= new ::cppu::OMultiTypeInterfaceContainerHelper( m_aMutex
);
705 m_pInterfaceContainer
->addInterface( cppu::UnoType
<document::XEventListener
>::get(), xListener
);
709 void SAL_CALL
ODummyEmbeddedObject::removeEventListener( const uno::Reference
< document::XEventListener
>& xListener
)
710 throw ( uno::RuntimeException
, std::exception
)
712 ::osl::MutexGuard
aGuard( m_aMutex
);
713 if ( m_pInterfaceContainer
)
714 m_pInterfaceContainer
->removeInterface( cppu::UnoType
<document::XEventListener
>::get(),
718 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */