2010-10-12 15:53:47 +02:00
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2012-09-27 13:52:10 +01:00
/*
* This file is part of the LibreOffice project .
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License , v . 2.0 . If a copy of the MPL was not distributed with this
* file , You can obtain one at http : //mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice :
*
* Licensed to the Apache Software Foundation ( ASF ) under one or more
* contributor license agreements . See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership . The ASF licenses this file to you under the Apache
* License , Version 2.0 ( the " License " ) ; you may not use this file
* except in compliance with the License . You may obtain a copy of
* the License at http : //www.apache.org/licenses/LICENSE-2.0 .
*/
2003-10-27 12:05:38 +00:00
# include <com/sun/star/embed/EmbedStates.hpp>
# include <com/sun/star/embed/EmbedUpdateModes.hpp>
2017-02-06 17:08:38 +01:00
# include <com/sun/star/embed/ObjectSaveVetoException.hpp>
# include <com/sun/star/embed/StorageWrappedTargetException.hpp>
# include <com/sun/star/embed/UnreachableStateException.hpp>
2003-10-27 12:05:38 +00:00
# include <com/sun/star/embed/XEmbeddedClient.hpp>
2004-10-04 18:49:03 +00:00
# include <com/sun/star/embed/XInplaceClient.hpp>
# include <com/sun/star/embed/XWindowSupplier.hpp>
2005-02-25 08:20:55 +00:00
# include <com/sun/star/embed/StateChangeInProgressException.hpp>
2009-04-23 13:48:24 +00:00
# include <com/sun/star/embed/Aspects.hpp>
2004-10-04 18:49:03 +00:00
# include <com/sun/star/awt/XWindowPeer.hpp>
2017-02-06 17:08:38 +01:00
# include <com/sun/star/io/IOException.hpp>
2003-10-27 12:05:38 +00:00
# include <com/sun/star/util/XCloseable.hpp>
# include <com/sun/star/util/XModifiable.hpp>
2012-09-04 14:56:48 +02:00
# include <com/sun/star/frame/ModuleManager.hpp>
2003-10-27 12:05:38 +00:00
# include <com/sun/star/lang/DisposedException.hpp>
2006-11-01 17:19:51 +00:00
# include <com/sun/star/embed/EmbedMisc.hpp>
2018-05-24 15:47:30 +02:00
# include <cppuhelper/exc_hlp.hxx>
2021-08-07 09:24:46 +02:00
# include <comphelper/multicontainer2.hxx>
2018-02-26 13:55:21 +01:00
# include <comphelper/lok.hxx>
2018-07-27 09:42:16 +02:00
# include <sal/log.hxx>
2006-11-01 17:19:51 +00:00
2012-11-07 16:14:33 +01:00
# include <vcl/svapp.hxx>
2006-01-20 08:50:04 +00:00
2005-02-25 08:20:55 +00:00
# include <targetstatecontrol.hxx>
2003-10-27 12:05:38 +00:00
2017-10-23 22:42:15 +02:00
# include <commonembobj.hxx>
2014-06-25 14:57:44 +02:00
# include "embedobj.hxx"
2019-08-16 14:16:36 +02:00
# include <specialobject.hxx>
2003-10-27 12:05:38 +00:00
using namespace : : com : : sun : : star ;
2004-10-04 18:49:03 +00:00
awt : : Rectangle GetRectangleInterception ( const awt : : Rectangle & aRect1 , const awt : : Rectangle & aRect2 )
{
awt : : Rectangle aResult ;
OSL_ENSURE ( aRect1 . Width > = 0 & & aRect2 . Width > = 0 & & aRect1 . Height > = 0 & & aRect2 . Height > = 0 ,
2019-09-10 10:37:56 +02:00
" Offset must not be less than zero! " ) ;
2004-10-04 18:49:03 +00:00
2018-01-08 17:01:49 +02:00
aResult . X = std : : max ( aRect1 . X , aRect2 . X ) ;
aResult . Y = std : : max ( aRect1 . Y , aRect2 . Y ) ;
2004-10-04 18:49:03 +00:00
sal_Int32 nRight1 = aRect1 . X + aRect1 . Width ;
sal_Int32 nBottom1 = aRect1 . Y + aRect1 . Height ;
sal_Int32 nRight2 = aRect2 . X + aRect2 . Width ;
sal_Int32 nBottom2 = aRect2 . Y + aRect2 . Height ;
2018-01-11 08:47:15 +02:00
aResult . Width = std : : min ( nRight1 , nRight2 ) - aResult . X ;
aResult . Height = std : : min ( nBottom1 , nBottom2 ) - aResult . Y ;
2004-10-04 18:49:03 +00:00
return aResult ;
}
2014-02-22 21:20:15 +01:00
2003-10-27 12:05:38 +00:00
sal_Int32 OCommonEmbeddedObject : : ConvertVerbToState_Impl ( sal_Int32 nVerb )
{
2020-05-07 15:34:12 +02:00
auto it = m_aVerbTable . find ( nVerb ) ;
if ( it ! = m_aVerbTable . end ( ) )
return it - > second ;
2003-10-27 12:05:38 +00:00
throw lang : : IllegalArgumentException ( ) ; // TODO: unexpected verb provided
}
2014-02-22 21:20:15 +01:00
2004-10-04 18:49:03 +00:00
void OCommonEmbeddedObject : : Deactivate ( )
{
2017-01-20 13:35:32 +02:00
uno : : Reference < util : : XModifiable > xModif ( m_xDocHolder - > GetComponent ( ) , uno : : UNO_QUERY ) ;
2004-10-04 18:49:03 +00:00
2006-02-01 18:04:41 +00:00
// no need to lock for the initialization
uno : : Reference < embed : : XEmbeddedClient > xClientSite = m_xClientSite ;
if ( ! xClientSite . is ( ) )
2004-10-04 18:49:03 +00:00
throw embed : : WrongStateException ( ) ; //TODO: client site is not set!
2020-03-05 10:59:35 +01:00
// tdf#131146 close frame before saving of the document
// (during CloseFrame() call some changes could be detected not registered in util::XModifiable)
m_xDocHolder - > CloseFrame ( ) ;
2004-10-04 18:49:03 +00:00
// store document if it is modified
if ( xModif . is ( ) & & xModif - > isModified ( ) )
{
try {
2006-02-01 18:04:41 +00:00
xClientSite - > saveObject ( ) ;
2021-04-08 10:30:15 +02:00
// tdf#141529 take note that an eventually used linked file
// got changed/saved/written and that we need to copy it back if the
// hosting file/document gets saved
if ( m_aLinkTempFile . is ( ) )
m_bLinkTempFileChanged = true ;
2004-10-04 18:49:03 +00:00
}
2011-12-09 02:56:30 +09:00
catch ( const embed : : ObjectSaveVetoException & )
2004-10-04 18:49:03 +00:00
{
}
2018-05-24 15:47:30 +02:00
catch ( const uno : : Exception & )
2004-10-04 18:49:03 +00:00
{
2018-05-24 15:47:30 +02:00
css : : uno : : Any anyEx = cppu : : getCaughtException ( ) ;
2004-10-04 18:49:03 +00:00
throw embed : : StorageWrappedTargetException (
2014-05-26 14:29:07 +02:00
" The client could not store the object! " ,
2014-05-26 15:26:03 +02:00
static_cast < : : cppu : : OWeakObject * > ( this ) ,
2018-05-24 15:47:30 +02:00
anyEx ) ;
2004-10-04 18:49:03 +00:00
}
}
2016-04-20 17:16:42 +02:00
xClientSite - > visibilityChanged ( false ) ;
2004-10-04 18:49:03 +00:00
}
2014-02-22 21:20:15 +01:00
2014-04-17 11:39:18 +02:00
void OCommonEmbeddedObject : : StateChangeNotification_Impl ( bool bBeforeChange , sal_Int32 nOldState , sal_Int32 nNewState , : : osl : : ResettableMutexGuard & rGuard )
2004-05-10 16:51:00 +00:00
{
2020-04-14 15:48:35 +02:00
if ( ! m_pInterfaceContainer )
return ;
2004-11-09 14:11:09 +00:00
2021-08-07 09:24:46 +02:00
comphelper : : OInterfaceContainerHelper2 * pContainer = m_pInterfaceContainer - > getContainer (
2020-04-14 15:48:35 +02:00
cppu : : UnoType < embed : : XStateChangeListener > : : get ( ) ) ;
if ( pContainer = = nullptr )
return ;
2004-11-09 14:11:09 +00:00
2020-04-14 15:48:35 +02:00
lang : : EventObject aSource ( static_cast < : : cppu : : OWeakObject * > ( this ) ) ;
2021-08-07 09:24:46 +02:00
comphelper : : OInterfaceIteratorHelper2 pIterator ( * pContainer ) ;
2020-04-14 15:48:35 +02:00
// should be locked after the method is finished successfully
rGuard . clear ( ) ;
2004-11-09 14:11:09 +00:00
2020-04-14 15:48:35 +02:00
while ( pIterator . hasMoreElements ( ) )
{
try
{
if ( bBeforeChange )
static_cast < embed : : XStateChangeListener * > ( pIterator . next ( ) ) - > changingState ( aSource , nOldState , nNewState ) ;
else
static_cast < embed : : XStateChangeListener * > ( pIterator . next ( ) ) - > stateChanged ( aSource , nOldState , nNewState ) ;
2004-05-10 16:51:00 +00:00
}
2020-04-14 15:48:35 +02:00
catch ( const uno : : Exception & )
{
// even if the listener complains ignore it for now
}
if ( m_bDisposed )
return ;
2004-05-10 16:51:00 +00:00
}
2020-04-14 15:48:35 +02:00
rGuard . reset ( ) ;
2004-05-10 16:51:00 +00:00
}
2014-02-22 21:20:15 +01:00
2003-10-27 12:05:38 +00:00
void OCommonEmbeddedObject : : SwitchStateTo_Impl ( sal_Int32 nNextState )
{
2016-04-26 09:56:47 +02:00
// TODO: may be needs interaction handler to detect whether the object state
2010-12-03 10:58:55 +01:00
// can be changed even after errors
2003-10-27 12:05:38 +00:00
2004-05-10 16:51:00 +00:00
if ( m_nObjectState = = embed : : EmbedStates : : LOADED )
2003-10-27 12:05:38 +00:00
{
2004-05-10 16:51:00 +00:00
if ( nNextState = = embed : : EmbedStates : : RUNNING )
2003-10-27 12:05:38 +00:00
{
2007-08-02 16:04:47 +00:00
// after the object reaches the running state the cloned size is not necessary any more
2014-04-17 11:39:18 +02:00
m_bHasClonedSize = false ;
2007-08-02 16:04:47 +00:00
2021-04-08 10:30:15 +02:00
if ( m_bIsLinkURL )
2003-10-27 12:05:38 +00:00
{
2017-01-20 13:35:32 +02:00
m_xDocHolder - > SetComponent ( LoadLink_Impl ( ) , m_bReadOnly ) ;
2003-10-27 12:05:38 +00:00
}
else
{
2019-08-16 14:16:36 +02:00
if ( ! dynamic_cast < OSpecialEmbeddedObject * > ( this ) )
{
// in case embedded object is in loaded state the contents must
// be stored in the related storage and the storage
// must be created already
if ( ! m_xObjectStorage . is ( ) )
throw io : : IOException ( ) ; //TODO: access denied
2003-10-27 12:05:38 +00:00
2019-08-16 14:16:36 +02:00
m_xDocHolder - > SetComponent ( LoadDocumentFromStorage_Impl ( ) , m_bReadOnly ) ;
}
else
{
// objects without persistence will be initialized internally
uno : : Sequence < uno : : Any > aArgs ( 1 ) ;
aArgs [ 0 ] < < = uno : : Reference < embed : : XEmbeddedObject > ( this ) ;
uno : : Reference < util : : XCloseable > xDocument (
m_xContext - > getServiceManager ( ) - > createInstanceWithArgumentsAndContext ( GetDocumentServiceName ( ) , aArgs , m_xContext ) ,
uno : : UNO_QUERY ) ;
uno : : Reference < container : : XChild > xChild ( xDocument , uno : : UNO_QUERY ) ;
if ( xChild . is ( ) )
xChild - > setParent ( m_xParent ) ;
m_xDocHolder - > SetComponent ( xDocument , m_bReadOnly ) ;
}
2003-10-27 12:05:38 +00:00
}
2017-01-20 13:35:32 +02:00
if ( ! m_xDocHolder - > GetComponent ( ) . is ( ) )
2007-08-02 12:31:19 +00:00
throw embed : : UnreachableStateException ( ) ; //TODO: can't open document
2003-10-27 12:05:38 +00:00
m_nObjectState = nNextState ;
}
else
{
2013-05-27 00:22:20 +03:00
SAL_WARN ( " embeddedobj.common " , " Unacceptable state switch! " ) ;
2020-12-23 19:46:09 +05:30
throw uno : : RuntimeException ( " invalid next state, only RUNNING state allowed " ) ; // TODO
2003-10-27 12:05:38 +00:00
}
}
2004-05-10 16:51:00 +00:00
else if ( m_nObjectState = = embed : : EmbedStates : : RUNNING )
2003-10-27 12:05:38 +00:00
{
2004-05-10 16:51:00 +00:00
if ( nNextState = = embed : : EmbedStates : : LOADED )
2003-10-27 12:05:38 +00:00
{
2017-01-20 13:35:32 +02:00
m_nClonedMapUnit = m_xDocHolder - > GetMapUnit ( embed : : Aspects : : MSOLE_CONTENT ) ;
m_bHasClonedSize = m_xDocHolder - > GetExtent ( embed : : Aspects : : MSOLE_CONTENT , & m_aClonedSize ) ;
2009-04-23 13:48:24 +00:00
2003-10-27 12:05:38 +00:00
// actually frame should not exist at this point
2017-01-20 13:35:32 +02:00
m_xDocHolder - > CloseDocument ( false , false ) ;
2003-10-27 12:05:38 +00:00
m_nObjectState = nNextState ;
}
2004-10-04 18:49:03 +00:00
else
2003-10-27 12:05:38 +00:00
{
2004-10-04 18:49:03 +00:00
if ( nNextState = = embed : : EmbedStates : : INPLACE_ACTIVE )
{
if ( ! m_xClientSite . is ( ) )
2014-05-26 14:29:07 +02:00
throw embed : : WrongStateException ( " client site not set, yet " , * this ) ;
2003-11-14 14:33:20 +00:00
2004-10-04 18:49:03 +00:00
uno : : Reference < embed : : XInplaceClient > xInplaceClient ( m_xClientSite , uno : : UNO_QUERY ) ;
2017-09-21 11:06:43 +02:00
if ( ! xInplaceClient . is ( ) | | ! xInplaceClient - > canInplaceActivate ( ) )
throw embed : : WrongStateException ( ) ; //TODO: can't activate inplace
xInplaceClient - > activatingInplace ( ) ;
2004-10-04 18:49:03 +00:00
2017-09-21 11:06:43 +02:00
uno : : Reference < embed : : XWindowSupplier > xClientWindowSupplier ( xInplaceClient , uno : : UNO_QUERY_THROW ) ;
2004-10-04 18:49:03 +00:00
2017-09-21 11:06:43 +02:00
m_xClientWindow = xClientWindowSupplier - > getWindow ( ) ;
m_aOwnRectangle = xInplaceClient - > getPlacement ( ) ;
m_aClipRectangle = xInplaceClient - > getClipRectangle ( ) ;
awt : : Rectangle aRectangleToShow = GetRectangleInterception ( m_aOwnRectangle , m_aClipRectangle ) ;
2004-10-04 18:49:03 +00:00
2017-09-21 11:06:43 +02:00
// create own window based on the client window
// place and resize the window according to the rectangles
uno : : Reference < awt : : XWindowPeer > xClientWindowPeer ( m_xClientWindow , uno : : UNO_QUERY_THROW ) ;
2004-10-04 18:49:03 +00:00
2017-09-21 11:06:43 +02:00
// dispatch provider may not be provided
uno : : Reference < frame : : XDispatchProvider > xContainerDP = xInplaceClient - > getInplaceDispatchProvider ( ) ;
bool bOk = m_xDocHolder - > ShowInplace ( xClientWindowPeer , aRectangleToShow , xContainerDP ) ;
m_nObjectState = nNextState ;
if ( ! bOk )
{
SwitchStateTo_Impl ( embed : : EmbedStates : : RUNNING ) ;
2004-10-04 18:49:03 +00:00
throw embed : : WrongStateException ( ) ; //TODO: can't activate inplace
2017-09-21 11:06:43 +02:00
}
2004-10-04 18:49:03 +00:00
}
else if ( nNextState = = embed : : EmbedStates : : ACTIVE )
{
if ( ! m_xClientSite . is ( ) )
throw embed : : WrongStateException ( ) ; //TODO: client site is not set!
2003-10-27 12:05:38 +00:00
2004-10-04 18:49:03 +00:00
// create frame and load document in the frame
2017-01-20 13:35:32 +02:00
m_xDocHolder - > Show ( ) ;
2003-11-14 14:33:20 +00:00
2016-04-20 17:16:42 +02:00
m_xClientSite - > visibilityChanged ( true ) ;
2004-10-04 18:49:03 +00:00
m_nObjectState = nNextState ;
}
else
{
2013-05-27 00:22:20 +03:00
SAL_WARN ( " embeddedobj.common " , " Unacceptable state switch! " ) ;
2020-12-23 19:46:09 +05:30
throw uno : : RuntimeException ( " invalid next state,only LOADED/INPLACE_ACTIVE/ACTIVE allowed " ) ; // TODO
2004-10-04 18:49:03 +00:00
}
2003-10-27 12:05:38 +00:00
}
}
2004-10-04 18:49:03 +00:00
else if ( m_nObjectState = = embed : : EmbedStates : : INPLACE_ACTIVE )
2003-10-27 12:05:38 +00:00
{
2004-05-10 16:51:00 +00:00
if ( nNextState = = embed : : EmbedStates : : RUNNING )
2003-10-27 12:05:38 +00:00
{
2017-02-14 16:10:56 +01:00
uno : : Reference < embed : : XInplaceClient > xInplaceClient ( m_xClientSite , uno : : UNO_QUERY_THROW ) ;
2003-10-27 12:05:38 +00:00
2016-04-20 17:16:42 +02:00
m_xClientSite - > visibilityChanged ( true ) ;
2003-11-14 14:24:28 +00:00
2004-10-04 18:49:03 +00:00
xInplaceClient - > deactivatedInplace ( ) ;
Deactivate ( ) ;
m_nObjectState = nNextState ;
}
else if ( nNextState = = embed : : EmbedStates : : UI_ACTIVE )
{
2006-11-01 17:19:51 +00:00
if ( ! ( m_nMiscStatus & embed : : EmbedMisc : : MS_EMBED_NOUIACTIVATE ) )
2003-10-27 12:05:38 +00:00
{
2006-11-01 17:19:51 +00:00
uno : : Reference < embed : : XInplaceClient > xInplaceClient ( m_xClientSite , uno : : UNO_QUERY_THROW ) ;
// TODO:
2015-09-29 15:07:23 +02:00
uno : : Reference < css : : frame : : XLayoutManager > xContainerLM =
2006-11-01 17:19:51 +00:00
xInplaceClient - > getLayoutManager ( ) ;
2017-09-21 11:06:43 +02:00
if ( ! xContainerLM . is ( ) )
throw embed : : WrongStateException ( ) ; //TODO: can't activate UI
// dispatch provider may not be provided
uno : : Reference < frame : : XDispatchProvider > xContainerDP = xInplaceClient - > getInplaceDispatchProvider ( ) ;
// get the container module name
OUString aModuleName ;
try
2005-03-23 13:19:45 +00:00
{
2017-09-21 11:06:43 +02:00
uno : : Reference < embed : : XComponentSupplier > xCompSupl ( m_xClientSite , uno : : UNO_QUERY_THROW ) ;
uno : : Reference < uno : : XInterface > xContDoc ( xCompSupl - > getComponent ( ) , uno : : UNO_QUERY_THROW ) ;
uno : : Reference < frame : : XModuleManager2 > xManager ( frame : : ModuleManager : : create ( m_xContext ) ) ;
aModuleName = xManager - > identify ( xContDoc ) ;
}
catch ( const uno : : Exception & )
{ }
2018-02-26 13:55:21 +01:00
if ( ! comphelper : : LibreOfficeKit : : isActive ( ) )
2017-09-21 11:06:43 +02:00
{
2018-02-26 13:55:21 +01:00
// if currently another object is UIactive it will be deactivated; usually this will activate the LM of
// the container. Locking the LM will prevent flicker.
xContainerLM - > lock ( ) ;
xInplaceClient - > activatingUI ( ) ;
bool bOk = m_xDocHolder - > ShowUI ( xContainerLM , xContainerDP , aModuleName ) ;
xContainerLM - > unlock ( ) ;
if ( bOk )
{
m_nObjectState = nNextState ;
m_xDocHolder - > ResizeHatchWindow ( ) ;
}
else
{
xInplaceClient - > deactivatedUI ( ) ;
2019-02-08 13:15:15 +02:00
throw embed : : WrongStateException ( ) ; //TODO: can't activate UI
2018-02-26 13:55:21 +01:00
}
2017-09-21 11:06:43 +02:00
}
2003-10-27 12:05:38 +00:00
}
2004-10-04 18:49:03 +00:00
}
else
{
2013-05-27 00:22:20 +03:00
SAL_WARN ( " embeddedobj.common " , " Unacceptable state switch! " ) ;
2020-12-23 19:46:09 +05:30
throw uno : : RuntimeException ( " invalid next state,only RUNNING/UI_ACTIVE allowed " ) ; // TODO
2004-10-04 18:49:03 +00:00
}
}
else if ( m_nObjectState = = embed : : EmbedStates : : ACTIVE )
{
if ( nNextState = = embed : : EmbedStates : : RUNNING )
{
Deactivate ( ) ;
2003-10-27 12:05:38 +00:00
m_nObjectState = nNextState ;
}
else
{
2013-05-27 00:22:20 +03:00
SAL_WARN ( " embeddedobj.common " , " Unacceptable state switch! " ) ;
2020-12-23 19:46:09 +05:30
throw uno : : RuntimeException ( " invalid next state, only RUNNING state allowed " ) ; // TODO
2003-10-27 12:05:38 +00:00
}
}
2004-10-04 18:49:03 +00:00
else if ( m_nObjectState = = embed : : EmbedStates : : UI_ACTIVE )
{
if ( nNextState = = embed : : EmbedStates : : INPLACE_ACTIVE )
{
uno : : Reference < embed : : XInplaceClient > xInplaceClient ( m_xClientSite , uno : : UNO_QUERY_THROW ) ;
2015-09-29 15:07:23 +02:00
uno : : Reference < css : : frame : : XLayoutManager > xContainerLM =
2004-10-04 18:49:03 +00:00
xInplaceClient - > getLayoutManager ( ) ;
2014-04-17 11:39:18 +02:00
bool bOk = false ;
2004-10-04 18:49:03 +00:00
if ( xContainerLM . is ( ) )
2017-01-20 13:35:32 +02:00
bOk = m_xDocHolder - > HideUI ( xContainerLM ) ;
2004-10-04 18:49:03 +00:00
2017-09-21 11:06:43 +02:00
if ( ! bOk )
2004-10-04 18:49:03 +00:00
throw embed : : WrongStateException ( ) ; //TODO: can't activate UI
2017-09-21 11:06:43 +02:00
m_nObjectState = nNextState ;
m_xDocHolder - > ResizeHatchWindow ( ) ;
xInplaceClient - > deactivatedUI ( ) ;
2004-10-04 18:49:03 +00:00
}
}
2003-10-27 12:05:38 +00:00
else
2014-05-26 14:29:07 +02:00
throw embed : : WrongStateException ( " The object is in unacceptable state! " ,
2014-05-26 15:26:03 +02:00
static_cast < : : cppu : : OWeakObject * > ( this ) ) ;
2003-10-27 12:05:38 +00:00
}
2014-02-22 21:20:15 +01:00
2016-07-18 09:22:27 +02:00
uno : : Sequence < sal_Int32 > const & OCommonEmbeddedObject : : GetIntermediateStatesSequence_Impl ( sal_Int32 nNewState )
2003-10-27 12:05:38 +00:00
{
sal_Int32 nCurInd = 0 ;
for ( nCurInd = 0 ; nCurInd < m_aAcceptedStates . getLength ( ) ; nCurInd + + )
if ( m_aAcceptedStates [ nCurInd ] = = m_nObjectState )
break ;
if ( nCurInd = = m_aAcceptedStates . getLength ( ) )
2014-05-26 14:29:07 +02:00
throw embed : : WrongStateException ( " The object is in unacceptable state! " ,
2014-05-26 15:26:03 +02:00
static_cast < : : cppu : : OWeakObject * > ( this ) ) ;
2003-10-27 12:05:38 +00:00
sal_Int32 nDestInd = 0 ;
for ( nDestInd = 0 ; nDestInd < m_aAcceptedStates . getLength ( ) ; nDestInd + + )
if ( m_aAcceptedStates [ nDestInd ] = = nNewState )
break ;
if ( nDestInd = = m_aAcceptedStates . getLength ( ) )
throw embed : : UnreachableStateException (
2014-05-26 14:29:07 +02:00
" The state either not reachable, or the object allows the state only as an intermediate one! " ,
2014-05-26 15:26:03 +02:00
static_cast < : : cppu : : OWeakObject * > ( this ) ,
2003-10-27 12:05:38 +00:00
m_nObjectState ,
nNewState ) ;
return m_pIntermediateStatesSeqs [ nCurInd ] [ nDestInd ] ;
}
2014-02-22 21:20:15 +01:00
2003-10-27 12:05:38 +00:00
void SAL_CALL OCommonEmbeddedObject : : changeState ( sal_Int32 nNewState )
{
2017-09-30 19:35:09 +02:00
: : osl : : ResettableMutexGuard aGuard ( m_aMutex ) ;
if ( m_bDisposed )
throw lang : : DisposedException ( ) ; // TODO
2003-10-27 12:05:38 +00:00
2017-09-30 19:35:09 +02:00
if ( m_nObjectState = = - 1 )
throw embed : : WrongStateException ( " The object has no persistence! " ,
static_cast < : : cppu : : OWeakObject * > ( this ) ) ;
2003-10-27 12:05:38 +00:00
2017-09-30 19:35:09 +02:00
sal_Int32 nOldState = m_nObjectState ;
2004-10-04 18:49:03 +00:00
2017-09-30 19:35:09 +02:00
if ( m_nTargetState ! = - 1 )
{
// means that the object is currently trying to reach the target state
throw embed : : StateChangeInProgressException ( OUString ( ) ,
uno : : Reference < uno : : XInterface > ( ) ,
m_nTargetState ) ;
}
else
{
TargetStateControl_Impl aControl ( m_nTargetState , nNewState ) ;
2003-10-27 12:05:38 +00:00
2017-09-30 19:35:09 +02:00
// in case the object is already in requested state
if ( m_nObjectState = = nNewState )
{
// if active object is activated again, bring its window to top
if ( m_nObjectState = = embed : : EmbedStates : : ACTIVE )
m_xDocHolder - > Show ( ) ;
2004-05-10 16:51:00 +00:00
2017-09-30 19:35:09 +02:00
return ;
}
2003-10-27 12:05:38 +00:00
2017-09-30 19:35:09 +02:00
// retrieve sequence of states that should be passed to reach desired state
uno : : Sequence < sal_Int32 > aIntermediateStates = GetIntermediateStatesSequence_Impl ( nNewState ) ;
2003-10-27 12:05:38 +00:00
2017-09-30 19:35:09 +02:00
// notify listeners that the object is going to change the state
StateChangeNotification_Impl ( true , nOldState , nNewState , aGuard ) ;
2004-05-10 16:51:00 +00:00
2017-09-30 19:35:09 +02:00
try {
2020-05-20 08:48:56 +02:00
for ( sal_Int32 state : aIntermediateStates )
SwitchStateTo_Impl ( state ) ;
2004-05-10 16:51:00 +00:00
2017-09-30 19:35:09 +02:00
SwitchStateTo_Impl ( nNewState ) ;
}
catch ( const uno : : Exception & )
{
if ( nOldState ! = m_nObjectState )
// notify listeners that the object has changed the state
StateChangeNotification_Impl ( false , nOldState , m_nObjectState , aGuard ) ;
2005-02-25 08:20:55 +00:00
2017-09-30 19:35:09 +02:00
throw ;
2004-08-02 16:43:51 +00:00
}
2017-09-30 19:35:09 +02:00
}
2004-05-10 16:51:00 +00:00
2017-09-30 19:35:09 +02:00
// notify listeners that the object has changed the state
StateChangeNotification_Impl ( false , nOldState , nNewState , aGuard ) ;
2010-12-03 10:58:55 +01:00
2017-09-30 19:35:09 +02:00
// let the object window be shown
if ( nNewState = = embed : : EmbedStates : : UI_ACTIVE | | nNewState = = embed : : EmbedStates : : INPLACE_ACTIVE )
PostEvent_Impl ( " OnVisAreaChanged " ) ;
2003-10-27 12:05:38 +00:00
}
2014-02-22 21:20:15 +01:00
2003-10-27 12:05:38 +00:00
uno : : Sequence < sal_Int32 > SAL_CALL OCommonEmbeddedObject : : getReachableStates ( )
{
if ( m_bDisposed )
throw lang : : DisposedException ( ) ; // TODO
if ( m_nObjectState = = - 1 )
2014-05-26 14:29:07 +02:00
throw embed : : WrongStateException ( " The object has no persistence! " ,
2014-05-26 15:26:03 +02:00
static_cast < : : cppu : : OWeakObject * > ( this ) ) ;
2003-10-27 12:05:38 +00:00
return m_aAcceptedStates ;
}
2014-02-22 21:20:15 +01:00
2003-10-27 12:05:38 +00:00
sal_Int32 SAL_CALL OCommonEmbeddedObject : : getCurrentState ( )
{
if ( m_bDisposed )
throw lang : : DisposedException ( ) ; // TODO
if ( m_nObjectState = = - 1 )
2014-05-26 14:29:07 +02:00
throw embed : : WrongStateException ( " The object has no persistence! " ,
2014-05-26 15:26:03 +02:00
static_cast < : : cppu : : OWeakObject * > ( this ) ) ;
2003-10-27 12:05:38 +00:00
return m_nObjectState ;
}
2014-02-22 21:20:15 +01:00
2003-10-27 12:05:38 +00:00
void SAL_CALL OCommonEmbeddedObject : : doVerb ( sal_Int32 nVerbID )
{
2012-11-07 16:14:33 +01:00
SolarMutexGuard aSolarGuard ;
//TODO: a gross hack to avoid deadlocks when this is called from the
// outside and OCommonEmbeddedObject::changeState, with m_aMutex locked,
// calls into framework code that tries to lock the solar mutex, while
// another thread (through Window::ImplCallPaint, say) calls
// OCommonEmbeddedObject::getComponent with the solar mutex locked and
// then tries to lock m_aMutex (see fdo#56818); the alternative would be
// to get locking done right in this class, but that looks like a
// daunting task
2019-04-07 11:48:47 +03:00
osl : : ClearableMutexGuard aGuard ( m_aMutex ) ;
2003-10-27 12:05:38 +00:00
if ( m_bDisposed )
throw lang : : DisposedException ( ) ; // TODO
if ( m_nObjectState = = - 1 )
2014-05-26 14:29:07 +02:00
throw embed : : WrongStateException ( " The object has no persistence! " ,
2014-05-26 15:26:03 +02:00
static_cast < : : cppu : : OWeakObject * > ( this ) ) ;
2003-10-27 12:05:38 +00:00
// for internal documents this call is just a duplicate of changeState
2004-10-04 18:49:03 +00:00
sal_Int32 nNewState = - 1 ;
try
{
nNewState = ConvertVerbToState_Impl ( nVerbID ) ;
}
2011-12-09 02:56:30 +09:00
catch ( const uno : : Exception & )
2004-10-04 18:49:03 +00:00
{ }
if ( nNewState = = - 1 )
{
// TODO/LATER: Save Copy as... verb ( -8 ) is implemented by container
// TODO/LATER: check if the verb is a supported one and if it is produce related operation
}
else
2010-11-15 22:12:46 +01:00
{
aGuard . clear ( ) ;
2004-10-04 18:49:03 +00:00
changeState ( nNewState ) ;
2010-11-15 22:12:46 +01:00
}
2003-10-27 12:05:38 +00:00
}
2014-02-22 21:20:15 +01:00
2004-05-10 16:51:00 +00:00
uno : : Sequence < embed : : VerbDescriptor > SAL_CALL OCommonEmbeddedObject : : getSupportedVerbs ( )
2003-10-27 12:05:38 +00:00
{
if ( m_bDisposed )
throw lang : : DisposedException ( ) ; // TODO
if ( m_nObjectState = = - 1 )
2014-05-26 14:29:07 +02:00
throw embed : : WrongStateException ( " The object has no persistence! " ,
2014-05-26 15:26:03 +02:00
static_cast < : : cppu : : OWeakObject * > ( this ) ) ;
2003-10-27 12:05:38 +00:00
2004-10-04 18:49:03 +00:00
return m_aObjectVerbs ;
2003-10-27 12:05:38 +00:00
}
2014-02-22 21:20:15 +01:00
2003-10-27 12:05:38 +00:00
void SAL_CALL OCommonEmbeddedObject : : setClientSite (
const uno : : Reference < embed : : XEmbeddedClient > & xClient )
{
: : osl : : MutexGuard aGuard ( m_aMutex ) ;
if ( m_bDisposed )
throw lang : : DisposedException ( ) ; // TODO
2005-11-10 15:12:36 +00:00
if ( m_xClientSite ! = xClient )
{
if ( m_nObjectState ! = embed : : EmbedStates : : LOADED & & m_nObjectState ! = embed : : EmbedStates : : RUNNING )
throw embed : : WrongStateException (
2014-05-26 14:29:07 +02:00
" The client site can not be set currently! " ,
2014-05-26 15:26:03 +02:00
static_cast < : : cppu : : OWeakObject * > ( this ) ) ;
2003-10-27 12:05:38 +00:00
2005-11-10 15:12:36 +00:00
m_xClientSite = xClient ;
}
2003-10-27 12:05:38 +00:00
}
2014-02-22 21:20:15 +01:00
2003-10-27 12:05:38 +00:00
uno : : Reference < embed : : XEmbeddedClient > SAL_CALL OCommonEmbeddedObject : : getClientSite ( )
{
if ( m_bDisposed )
throw lang : : DisposedException ( ) ; // TODO
if ( m_nObjectState = = - 1 )
2014-05-26 14:29:07 +02:00
throw embed : : WrongStateException ( " The object has no persistence! " ,
2014-05-26 15:26:03 +02:00
static_cast < : : cppu : : OWeakObject * > ( this ) ) ;
2003-10-27 12:05:38 +00:00
return m_xClientSite ;
}
2014-02-22 21:20:15 +01:00
2003-10-27 12:05:38 +00:00
void SAL_CALL OCommonEmbeddedObject : : update ( )
{
: : osl : : MutexGuard aGuard ( m_aMutex ) ;
if ( m_bDisposed )
throw lang : : DisposedException ( ) ; // TODO
if ( m_nObjectState = = - 1 )
2014-05-26 14:29:07 +02:00
throw embed : : WrongStateException ( " The object has no persistence! " ,
2014-05-26 15:26:03 +02:00
static_cast < : : cppu : : OWeakObject * > ( this ) ) ;
2003-10-27 12:05:38 +00:00
2015-11-06 09:35:43 +01:00
PostEvent_Impl ( " OnVisAreaChanged " ) ;
2003-10-27 12:05:38 +00:00
}
2014-02-22 21:20:15 +01:00
2003-10-27 12:05:38 +00:00
void SAL_CALL OCommonEmbeddedObject : : setUpdateMode ( sal_Int32 nMode )
{
: : osl : : MutexGuard aGuard ( m_aMutex ) ;
if ( m_bDisposed )
throw lang : : DisposedException ( ) ; // TODO
if ( m_nObjectState = = - 1 )
2014-05-26 14:29:07 +02:00
throw embed : : WrongStateException ( " The object has no persistence! " ,
2014-05-26 15:26:03 +02:00
static_cast < : : cppu : : OWeakObject * > ( this ) ) ;
2003-10-27 12:05:38 +00:00
2004-05-10 16:51:00 +00:00
OSL_ENSURE ( nMode = = embed : : EmbedUpdateModes : : ALWAYS_UPDATE
| | nMode = = embed : : EmbedUpdateModes : : EXPLICIT_UPDATE ,
2017-07-11 15:55:02 +02:00
" Unknown update mode! " ) ;
2003-10-27 12:05:38 +00:00
m_nUpdateMode = nMode ;
}
2014-02-22 21:20:15 +01:00
2006-06-19 23:28:05 +00:00
sal_Int64 SAL_CALL OCommonEmbeddedObject : : getStatus ( sal_Int64 )
2003-10-27 12:05:38 +00:00
{
if ( m_bDisposed )
throw lang : : DisposedException ( ) ; // TODO
2004-10-04 18:49:03 +00:00
return m_nMiscStatus ;
2003-10-27 12:05:38 +00:00
}
2014-02-22 21:20:15 +01:00
2013-04-07 12:06:47 +02:00
void SAL_CALL OCommonEmbeddedObject : : setContainerName ( const OUString & sName )
2004-05-10 16:51:00 +00:00
{
: : osl : : MutexGuard aGuard ( m_aMutex ) ;
if ( m_bDisposed )
throw lang : : DisposedException ( ) ; // TODO
m_aContainerName = sName ;
}
2017-01-26 12:28:58 +01:00
css : : uno : : Reference < css : : uno : : XInterface > SAL_CALL OCommonEmbeddedObject : : getParent ( )
2005-04-04 07:07:56 +00:00
{
return m_xParent ;
}
2017-01-26 12:28:58 +01:00
void SAL_CALL OCommonEmbeddedObject : : setParent ( const css : : uno : : Reference < css : : uno : : XInterface > & xParent )
2005-04-04 07:07:56 +00:00
{
m_xParent = xParent ;
if ( m_nObjectState ! = - 1 & & m_nObjectState ! = embed : : EmbedStates : : LOADED )
{
2017-01-20 13:35:32 +02:00
uno : : Reference < container : : XChild > xChild ( m_xDocHolder - > GetComponent ( ) , uno : : UNO_QUERY ) ;
2005-04-04 07:07:56 +00:00
if ( xChild . is ( ) )
xChild - > setParent ( xParent ) ;
}
}
2004-05-10 16:51:00 +00:00
2009-09-14 10:57:16 +00:00
// XDefaultSizeTransmitter
2017-01-26 12:28:58 +01:00
void SAL_CALL OCommonEmbeddedObject : : setDefaultSize ( const css : : awt : : Size & rSize_100TH_MM )
2009-09-14 10:57:16 +00:00
{
2019-05-14 21:25:20 +00:00
//#i103460# charts do not necessarily have an own size within ODF files, in this case they need to use the size settings from the surrounding frame, which is made available with this method
2009-09-14 10:57:16 +00:00
m_aDefaultSizeForChart_In_100TH_MM = rSize_100TH_MM ;
}
2010-10-12 15:53:47 +02:00
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */