20#include <com/sun/star/embed/EmbedStates.hpp>
21#include <com/sun/star/embed/EmbedUpdateModes.hpp>
22#include <com/sun/star/embed/ObjectSaveVetoException.hpp>
23#include <com/sun/star/embed/StorageWrappedTargetException.hpp>
24#include <com/sun/star/embed/UnreachableStateException.hpp>
25#include <com/sun/star/embed/XEmbeddedClient.hpp>
26#include <com/sun/star/embed/XInplaceClient.hpp>
27#include <com/sun/star/embed/XWindowSupplier.hpp>
28#include <com/sun/star/embed/StateChangeInProgressException.hpp>
29#include <com/sun/star/embed/Aspects.hpp>
31#include <com/sun/star/awt/XWindowPeer.hpp>
32#include <com/sun/star/io/IOException.hpp>
33#include <com/sun/star/util/XCloseable.hpp>
34#include <com/sun/star/util/XModifiable.hpp>
35#include <com/sun/star/frame/ModuleManager.hpp>
36#include <com/sun/star/lang/DisposedException.hpp>
38#include <com/sun/star/embed/EmbedMisc.hpp>
57 awt::Rectangle aResult;
59 OSL_ENSURE( aRect1.Width >= 0 && aRect2.Width >= 0 && aRect1.Height >= 0 && aRect2.Height >= 0,
60 "Offset must not be less than zero!" );
62 aResult.X = std::max(aRect1.X, aRect2.X);
63 aResult.Y = std::max(aRect1.Y, aRect2.Y);
65 sal_Int32 nRight1 = aRect1.X + aRect1.Width;
66 sal_Int32 nBottom1 = aRect1.Y + aRect1.Height;
67 sal_Int32 nRight2 = aRect2.X + aRect2.Width;
68 sal_Int32 nBottom2 = aRect2.Y + aRect2.Height;
69 aResult.Width = std::min( nRight1, nRight2 ) - aResult.X;
70 aResult.Height = std::min( nBottom1, nBottom2 ) - aResult.Y;
78 const IntermediateStatesMap & getIntermediateStatesMap()
80 static const IntermediateStatesMap
map = [] () {
81 IntermediateStatesMap tmp;
92 tmp[0][2] = { embed::EmbedStates::RUNNING };
94 tmp[0][3] = { embed::EmbedStates::RUNNING,
95 embed::EmbedStates::INPLACE_ACTIVE };
97 tmp[0][4] = {embed::EmbedStates::RUNNING};
99 tmp[1][3] = { embed::EmbedStates::INPLACE_ACTIVE };
101 tmp[2][0] = { embed::EmbedStates::RUNNING };
103 tmp[3][0] = { embed::EmbedStates::INPLACE_ACTIVE,
104 embed::EmbedStates::RUNNING };
106 tmp[3][1] = { embed::EmbedStates::INPLACE_ACTIVE };
108 tmp[4][0] = { embed::EmbedStates::RUNNING };
116 const css::uno::Sequence< sal_Int32 > & getAcceptedStates()
118 static const css::uno::Sequence< sal_Int32 > states {
119 embed::EmbedStates::LOADED,
120 embed::EmbedStates::RUNNING,
121 embed::EmbedStates::INPLACE_ACTIVE,
122 embed::EmbedStates::UI_ACTIVE,
123 embed::EmbedStates::ACTIVE };
136 throw lang::IllegalArgumentException();
142 uno::Reference< util::XModifiable > xModif(
m_xDocHolder->GetComponent(), uno::UNO_QUERY );
145 uno::Reference< embed::XEmbeddedClient > xClientSite =
m_xClientSite;
146 if ( !xClientSite.is() )
147 throw embed::WrongStateException();
154 if ( xModif.is() && xModif->isModified() )
157 xClientSite->saveObject();
165 catch(
const embed::ObjectSaveVetoException& )
168 catch(
const uno::Exception& )
171 throw embed::StorageWrappedTargetException(
172 "The client could not store the object!",
178 xClientSite->visibilityChanged(
false );
189 if ( pContainer ==
nullptr )
203 static_cast<embed::XStateChangeListener*
>(pIterator.
next())->changingState( aSource, nOldState, nNewState );
205 static_cast<embed::XStateChangeListener*
>(pIterator.
next())->stateChanged( aSource, nOldState, nNewState );
207 catch(
const uno::Exception& )
222 throw embed::WrongStateException(
"client site not set, yet", *
this );
224 uno::Reference< embed::XInplaceClient > xInplaceClient(
m_xClientSite, uno::UNO_QUERY );
225 if ( !xInplaceClient.is() || !xInplaceClient->canInplaceActivate() )
226 throw embed::WrongStateException();
227 xInplaceClient->activatingInplace();
229 uno::Reference< embed::XWindowSupplier > xClientWindowSupplier( xInplaceClient, uno::UNO_QUERY_THROW );
238 uno::Reference< awt::XWindowPeer > xClientWindowPeer(
m_xClientWindow, uno::UNO_QUERY_THROW );
241 uno::Reference< frame::XDispatchProvider > xContainerDP = xInplaceClient->getInplaceDispatchProvider();
242 bool bOk =
m_xDocHolder->ShowInplace( xClientWindowPeer, aRectangleToShow, xContainerDP );
247 throw embed::WrongStateException();
258 if ( nNextState == embed::EmbedStates::RUNNING )
275 throw io::IOException();
282 uno::Sequence < uno::Any > aArgs{
uno::Any(
283 uno::Reference < embed::XEmbeddedObject >(
this )) };
284 uno::Reference< util::XCloseable > xDocument(
288 uno::Reference < container::XChild > xChild( xDocument, uno::UNO_QUERY );
297 throw embed::UnreachableStateException();
303 SAL_WARN(
"embeddedobj.common",
"Unacceptable state switch!" );
304 throw uno::RuntimeException(
"invalid next state, only RUNNING state allowed");
309 if ( nNextState == embed::EmbedStates::LOADED )
321 if ( nNextState == embed::EmbedStates::INPLACE_ACTIVE )
325 else if ( nNextState == embed::EmbedStates::ACTIVE )
328 throw embed::WrongStateException();
338 SAL_WARN(
"embeddedobj.common",
"Unacceptable state switch!" );
339 throw uno::RuntimeException(
"invalid next state,only LOADED/INPLACE_ACTIVE/ACTIVE allowed");
345 if ( nNextState == embed::EmbedStates::RUNNING )
347 uno::Reference< embed::XInplaceClient > xInplaceClient(
m_xClientSite, uno::UNO_QUERY_THROW );
351 xInplaceClient->deactivatedInplace();
355 else if ( nNextState == embed::EmbedStates::UI_ACTIVE )
357 if ( !(
m_nMiscStatus & embed::EmbedMisc::MS_EMBED_NOUIACTIVATE) )
359 uno::Reference< embed::XInplaceClient > xInplaceClient(
m_xClientSite, uno::UNO_QUERY_THROW );
361 uno::Reference< css::frame::XLayoutManager > xContainerLM =
362 xInplaceClient->getLayoutManager();
363 if ( !xContainerLM.is() )
364 throw embed::WrongStateException();
366 uno::Reference< frame::XDispatchProvider > xContainerDP = xInplaceClient->getInplaceDispatchProvider();
369 OUString aModuleName;
372 uno::Reference< embed::XComponentSupplier > xCompSupl(
m_xClientSite, uno::UNO_QUERY_THROW );
373 uno::Reference< uno::XInterface > xContDoc( xCompSupl->getComponent(), uno::UNO_QUERY_THROW );
375 uno::Reference< frame::XModuleManager2 > xManager( frame::ModuleManager::create(
m_xContext ) );
377 aModuleName = xManager->identify( xContDoc );
379 catch(
const uno::Exception& )
386 xContainerLM->lock();
387 xInplaceClient->activatingUI();
388 bool bOk =
m_xDocHolder->ShowUI( xContainerLM, xContainerDP, aModuleName );
389 xContainerLM->unlock();
398 xInplaceClient->deactivatedUI();
399 throw embed::WrongStateException();
406 SAL_WARN(
"embeddedobj.common",
"Unacceptable state switch!" );
407 throw uno::RuntimeException(
"invalid next state,only RUNNING/UI_ACTIVE allowed");
412 if ( nNextState == embed::EmbedStates::RUNNING )
419 SAL_WARN(
"embeddedobj.common",
"Unacceptable state switch!" );
420 throw uno::RuntimeException(
"invalid next state, only RUNNING state allowed");
425 if ( nNextState == embed::EmbedStates::INPLACE_ACTIVE )
427 uno::Reference< embed::XInplaceClient > xInplaceClient(
m_xClientSite, uno::UNO_QUERY_THROW );
428 uno::Reference< css::frame::XLayoutManager > xContainerLM =
429 xInplaceClient->getLayoutManager();
432 if ( xContainerLM.is() )
436 throw embed::WrongStateException();
439 xInplaceClient->deactivatedUI();
443 throw embed::WrongStateException(
"The object is in unacceptable state!",
450 sal_Int32 nCurInd = 0;
451 auto & rAcceptedStates = getAcceptedStates();
452 for ( nCurInd = 0; nCurInd < rAcceptedStates.getLength(); nCurInd++ )
456 if ( nCurInd == rAcceptedStates.getLength() )
457 throw embed::WrongStateException(
"The object is in unacceptable state!",
460 sal_Int32 nDestInd = 0;
461 for ( nDestInd = 0; nDestInd < rAcceptedStates.getLength(); nDestInd++ )
462 if ( rAcceptedStates[nDestInd] == nNewState )
465 if ( nDestInd == rAcceptedStates.getLength() )
466 throw embed::UnreachableStateException(
467 "The state either not reachable, or the object allows the state only as an intermediate one!",
472 return getIntermediateStatesMap()[nCurInd][nDestInd];
478 ::osl::ResettableMutexGuard aGuard(
m_aMutex );
480 throw lang::DisposedException();
483 throw embed::WrongStateException(
"The object has no persistence!",
491 throw embed::StateChangeInProgressException( OUString(),
492 uno::Reference< uno::XInterface >(),
516 for ( sal_Int32 state : std::as_const(aIntermediateStates) )
521 catch(
const uno::Exception& )
535 if ( nNewState == embed::EmbedStates::UI_ACTIVE || nNewState == embed::EmbedStates::INPLACE_ACTIVE )
543 throw lang::DisposedException();
546 throw embed::WrongStateException(
"The object has no persistence!",
549 return getAcceptedStates();
556 throw lang::DisposedException();
559 throw embed::WrongStateException(
"The object has no persistence!",
578 osl::ClearableMutexGuard aGuard(
m_aMutex );
580 throw lang::DisposedException();
583 throw embed::WrongStateException(
"The object has no persistence!",
587 sal_Int32 nNewState = -1;
592 catch(
const uno::Exception& )
595 if ( nNewState == -1 )
611 throw lang::DisposedException();
614 throw embed::WrongStateException(
"The object has no persistence!",
622 const uno::Reference< embed::XEmbeddedClient >& xClient )
624 ::osl::MutexGuard aGuard(
m_aMutex );
626 throw lang::DisposedException();
631 throw embed::WrongStateException(
632 "The client site can not be set currently!",
643 throw lang::DisposedException();
646 throw embed::WrongStateException(
"The object has no persistence!",
655 ::osl::MutexGuard aGuard(
m_aMutex );
657 throw lang::DisposedException();
660 throw embed::WrongStateException(
"The object has no persistence!",
669 ::osl::MutexGuard aGuard(
m_aMutex );
671 throw lang::DisposedException();
674 throw embed::WrongStateException(
"The object has no persistence!",
677 OSL_ENSURE( nMode == embed::EmbedUpdateModes::ALWAYS_UPDATE
678 || nMode == embed::EmbedUpdateModes::EXPLICIT_UPDATE,
679 "Unknown update mode!" );
687 throw lang::DisposedException();
695 ::osl::MutexGuard aGuard(
m_aMutex );
697 throw lang::DisposedException();
704 ::osl::MutexGuard aGuard(
m_aMutex );
719 uno::Reference < container::XChild > xChild(
m_xDocHolder->GetComponent(), uno::UNO_QUERY );
721 xChild->setParent( xParent );
std::map< sal_Int32, sal_Int32 > m_aVerbTable
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getParent() override
css::awt::Size m_aDefaultSizeForChart_In_100TH_MM
css::uno::Reference< css::uno::XComponentContext > m_xContext
std::unique_ptr<::comphelper::OMultiTypeInterfaceContainerHelper2 > m_pInterfaceContainer
sal_Int32 ConvertVerbToState_Impl(sal_Int32 nVerb)
const OUString & GetDocumentServiceName() const
css::uno::Reference< css::uno::XInterface > m_xParent
void PostEvent_Impl(const OUString &aEventName)
void StateChangeNotification_Impl(bool bBeforeChange, sal_Int32 nOldState, sal_Int32 nNewState,::osl::ResettableMutexGuard &_rGuard)
css::uno::Sequence< css::embed::VerbDescriptor > m_aObjectVerbs
css::awt::Rectangle m_aClipRectangle
css::uno::Reference< css::awt::XWindow > m_xClientWindow
virtual void SAL_CALL setUpdateMode(sal_Int32 nMode) override
virtual void SAL_CALL changeState(sal_Int32 nNewState) override
css::awt::Rectangle m_aOwnRectangle
virtual void SAL_CALL setDefaultSize(const css::awt::Size &rSize_100TH_MM) override
css::uno::Reference< css::io::XTempFile > m_aLinkTempFile
virtual void SetOleState(bool bIsOleUpdate) override
void SetInplaceActiveState()
OUString m_aContainerName
bool m_bLinkTempFileChanged
virtual css::uno::Reference< css::embed::XEmbeddedClient > SAL_CALL getClientSite() override
css::uno::Reference< css::util::XCloseable > LoadLink_Impl()
sal_Int32 m_nClonedMapUnit
virtual void SAL_CALL setParent(const css::uno::Reference< css::uno::XInterface > &Parent) override
css::awt::Size m_aClonedSize
rtl::Reference< DocumentHolder > m_xDocHolder
virtual void SAL_CALL doVerb(sal_Int32 nVerbID) override
virtual sal_Int64 SAL_CALL getStatus(sal_Int64 nAspect) override
virtual css::uno::Sequence< css::embed::VerbDescriptor > SAL_CALL getSupportedVerbs() override
css::uno::Reference< css::embed::XEmbeddedClient > m_xClientSite
virtual sal_Int32 SAL_CALL getCurrentState() override
virtual void SAL_CALL setClientSite(const css::uno::Reference< css::embed::XEmbeddedClient > &xClient) override
css::uno::Sequence< sal_Int32 > const & GetIntermediateStatesSequence_Impl(sal_Int32 nNewState)
virtual void SAL_CALL setContainerName(const OUString &sName) override
virtual css::uno::Sequence< sal_Int32 > SAL_CALL getReachableStates() override
css::uno::Reference< css::util::XCloseable > LoadDocumentFromStorage_Impl()
void SwitchStateTo_Impl(sal_Int32 nNextState)
css::uno::Reference< css::embed::XStorage > m_xObjectStorage
virtual void SAL_CALL update() override
css::uno::XInterface * next()
bool hasMoreElements() const
#define NUM_SUPPORTED_STATES
awt::Rectangle GetRectangleInterception(const awt::Rectangle &aRect1, const awt::Rectangle &aRect2)
#define SAL_WARN(area, stream)
Any SAL_CALL getCaughtException()
std::map< OUString, rtl::Reference< Entity > > map