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/EmbedVerbs.hpp>
# include <com/sun/star/embed/EmbedUpdateModes.hpp>
# 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>
2003-10-27 12:05:38 +00:00
# include <com/sun/star/util/XCloseBroadcaster.hpp>
# include <com/sun/star/util/XCloseable.hpp>
# include <com/sun/star/util/XModifiable.hpp>
# include <com/sun/star/frame/XFrame.hpp>
# include <com/sun/star/frame/XComponentLoader.hpp>
# include <com/sun/star/frame/XDispatchProviderInterception.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>
2012-09-19 13:15:15 +02:00
# include <comphelper/processfactory.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
# include "commonembobj.hxx"
# include "intercept.hxx"
2014-06-25 14:57:44 +02:00
# include "embedobj.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 ,
" Offset must not be less then zero! " ) ;
aResult . X = aRect1 . X > aRect2 . X ? aRect1 . X : aRect2 . X ;
aResult . Y = aRect1 . Y > aRect2 . Y ? aRect1 . Y : aRect2 . Y ;
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 ;
aResult . Width = ( nRight1 < nRight2 ? nRight1 : nRight2 ) - aResult . X ;
aResult . Height = ( nBottom1 < nBottom2 ? nBottom1 : nBottom2 ) - aResult . Y ;
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 )
{
for ( sal_Int32 nInd = 0 ; nInd < m_aVerbTable . getLength ( ) ; nInd + + )
if ( m_aVerbTable [ nInd ] [ 0 ] = = nVerb )
return m_aVerbTable [ nInd ] [ 1 ] ;
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 ( )
{
uno : : Reference < util : : XModifiable > xModif ( m_pDocHolder - > GetComponent ( ) , uno : : UNO_QUERY ) ;
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!
// store document if it is modified
if ( xModif . is ( ) & & xModif - > isModified ( ) )
{
try {
2006-02-01 18:04:41 +00:00
xClientSite - > saveObject ( ) ;
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
{
}
2011-12-09 02:56:30 +09:00
catch ( const uno : : Exception & e )
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 ) ,
2004-10-04 18:49:03 +00:00
uno : : makeAny ( e ) ) ;
}
}
m_pDocHolder - > CloseFrame ( ) ;
2006-02-01 18:04:41 +00:00
xClientSite - > visibilityChanged ( sal_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
{
if ( m_pInterfaceContainer )
{
: : cppu : : OInterfaceContainerHelper * pContainer = m_pInterfaceContainer - > getContainer (
2014-05-17 00:23:39 +02:00
cppu : : UnoType < embed : : XStateChangeListener > : : get ( ) ) ;
2015-11-10 10:14:40 +01:00
if ( pContainer ! = nullptr )
2004-05-10 16:51:00 +00:00
{
2004-11-09 14:11:09 +00:00
lang : : EventObject aSource ( static_cast < : : cppu : : OWeakObject * > ( this ) ) ;
: : cppu : : OInterfaceIteratorHelper pIterator ( * pContainer ) ;
// should be locked after the method is finished successfully
rGuard . clear ( ) ;
while ( pIterator . hasMoreElements ( ) )
2004-08-02 16:43:51 +00:00
{
2004-11-09 14:11:09 +00:00
try
{
if ( bBeforeChange )
2014-10-01 12:59:38 +02:00
static_cast < embed : : XStateChangeListener * > ( pIterator . next ( ) ) - > changingState ( aSource , nOldState , nNewState ) ;
2004-11-09 14:11:09 +00:00
else
2014-10-01 12:59:38 +02:00
static_cast < embed : : XStateChangeListener * > ( pIterator . next ( ) ) - > stateChanged ( aSource , nOldState , nNewState ) ;
2004-11-09 14:11:09 +00:00
}
2011-12-09 02:56:30 +09:00
catch ( const uno : : Exception & )
2004-11-09 14:11:09 +00:00
{
// even if the listener complains ignore it for now
}
2005-01-05 11:46:53 +00:00
if ( m_bDisposed )
return ;
2004-05-10 16:51:00 +00:00
}
2004-11-09 14:11:09 +00: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 )
{
// TODO: may be needs interaction handler to detect wherether 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
2003-10-27 12:05:38 +00:00
if ( m_bIsLink )
{
2004-10-04 18:49:03 +00:00
m_pDocHolder - > SetComponent ( LoadLink_Impl ( ) , m_bReadOnly ) ;
2003-10-27 12:05:38 +00:00
}
else
{
2004-10-04 18:49:03 +00:00
uno : : Reference < embed : : XEmbedPersist > xPersist ( static_cast < embed : : XClassifiedObject * > ( this ) , uno : : UNO_QUERY ) ;
if ( xPersist . is ( ) )
{
// 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
autorecovery: save/recover forms and reports
Still some lose ends. Most notably, the current code contains cases for other sub component types,
but has no real implementation - attempting to save/recover those other types will yield multiple
assertions only. Also, recovery of SRB-reports has not been tested, yet, chances are good there's
some work ahead here.
Other known open issues:
- recovering sub components immediately shows them, instead of initially hiding them, and showing
only when the main document window is shown
- the implementation currently is no real session save, which would require saving information about
*unmodified* open sub components (though not their actual content), and restoring them upon
recovery.
- doing an implicit "connect" at the controller of the to-be-recovered database document is a requirement
to actually load the sub components, but might yield problems in case this requires interaction
(e.g. a login). Need to investigate
- the "recovery" storage is not removed from the database document storage after un/successful recovery
- cancelling the recovery of a "modified" database document always suggests to store this doc somewhere
2010-01-15 15:21:15 +01:00
m_pDocHolder - > SetComponent ( LoadDocumentFromStorage_Impl ( ) , m_bReadOnly ) ;
2004-10-04 18:49:03 +00:00
}
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 (
2013-01-08 15:29:57 +02:00
m_xContext - > getServiceManager ( ) - > createInstanceWithArgumentsAndContext ( GetDocumentServiceName ( ) , aArgs , m_xContext ) ,
uno : : UNO_QUERY ) ;
2005-11-10 15:28:38 +00:00
uno : : Reference < container : : XChild > xChild ( xDocument , uno : : UNO_QUERY ) ;
if ( xChild . is ( ) )
xChild - > setParent ( m_xParent ) ;
2004-10-04 18:49:03 +00:00
m_pDocHolder - > SetComponent ( xDocument , m_bReadOnly ) ;
}
2003-10-27 12:05:38 +00:00
}
2004-10-04 18:49:03 +00:00
if ( ! m_pDocHolder - > 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! " ) ;
2003-10-27 12:05:38 +00:00
throw uno : : RuntimeException ( ) ; // TODO
}
}
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
{
2009-04-23 13:48:24 +00:00
m_nClonedMapUnit = m_pDocHolder - > GetMapUnit ( embed : : Aspects : : MSOLE_CONTENT ) ;
m_bHasClonedSize = m_pDocHolder - > GetExtent ( embed : : Aspects : : MSOLE_CONTENT , & m_aClonedSize ) ;
2003-10-27 12:05:38 +00:00
// actually frame should not exist at this point
2014-04-17 11:39:18 +02:00
m_pDocHolder - > 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 ) ;
if ( xInplaceClient . is ( ) & & xInplaceClient - > canInplaceActivate ( ) )
{
xInplaceClient - > activatingInplace ( ) ;
uno : : Reference < embed : : XWindowSupplier > xClientWindowSupplier ( xInplaceClient , uno : : UNO_QUERY ) ;
if ( ! xClientWindowSupplier . is ( ) )
throw uno : : RuntimeException ( ) ; // TODO: the inplace client implementation must support XWinSupp
m_xClientWindow = xClientWindowSupplier - > getWindow ( ) ;
m_aOwnRectangle = xInplaceClient - > getPlacement ( ) ;
m_aClipRectangle = xInplaceClient - > getClipRectangle ( ) ;
awt : : Rectangle aRectangleToShow = GetRectangleInterception ( m_aOwnRectangle , m_aClipRectangle ) ;
// 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 ) ;
if ( ! xClientWindowPeer . is ( ) )
throw uno : : RuntimeException ( ) ; // TODO: the container window must support the interface
// dispatch provider may not be provided
uno : : Reference < frame : : XDispatchProvider > xContainerDP = xInplaceClient - > getInplaceDispatchProvider ( ) ;
2014-04-17 11:39:18 +02:00
bool bOk = m_pDocHolder - > ShowInplace ( xClientWindowPeer , aRectangleToShow , xContainerDP ) ;
2004-10-04 18:49:03 +00:00
m_nObjectState = nNextState ;
if ( ! bOk )
{
SwitchStateTo_Impl ( embed : : EmbedStates : : RUNNING ) ;
throw embed : : WrongStateException ( ) ; //TODO: can't activate inplace
}
}
else
throw embed : : WrongStateException ( ) ; //TODO: can't activate inplace
}
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
m_pDocHolder - > Show ( ) ;
2003-11-14 14:33:20 +00:00
2004-10-04 18:49:03 +00:00
m_xClientSite - > visibilityChanged ( sal_True ) ;
m_nObjectState = nNextState ;
}
else
{
2013-05-27 00:22:20 +03:00
SAL_WARN ( " embeddedobj.common " , " Unacceptable state switch! " ) ;
2004-10-04 18:49:03 +00:00
throw uno : : RuntimeException ( ) ; // TODO
}
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
{
2004-10-04 18:49:03 +00:00
uno : : Reference < embed : : XInplaceClient > xInplaceClient ( m_xClientSite , uno : : UNO_QUERY ) ;
if ( ! xInplaceClient . is ( ) )
2003-10-27 12:05:38 +00:00
throw uno : : RuntimeException ( ) ;
2004-10-04 18:49:03 +00:00
m_xClientSite - > visibilityChanged ( sal_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 ( ) ;
if ( xContainerLM . is ( ) )
2005-03-23 13:19:45 +00:00
{
2006-11-01 17:19:51 +00:00
// dispatch provider may not be provided
uno : : Reference < frame : : XDispatchProvider > xContainerDP = xInplaceClient - > getInplaceDispatchProvider ( ) ;
2005-03-23 13:19:45 +00:00
2006-11-01 17:19:51 +00:00
// get the container module name
2013-04-07 12:06:47 +02:00
OUString aModuleName ;
2006-11-01 17:19:51 +00:00
try
{
uno : : Reference < embed : : XComponentSupplier > xCompSupl ( m_xClientSite , uno : : UNO_QUERY_THROW ) ;
uno : : Reference < uno : : XInterface > xContDoc ( xCompSupl - > getComponent ( ) , uno : : UNO_QUERY_THROW ) ;
2005-03-23 13:19:45 +00:00
2013-01-08 15:29:57 +02:00
uno : : Reference < frame : : XModuleManager2 > xManager ( frame : : ModuleManager : : create ( m_xContext ) ) ;
2005-03-23 13:19:45 +00:00
2006-11-01 17:19:51 +00:00
aModuleName = xManager - > identify ( xContDoc ) ;
}
2011-12-09 02:56:30 +09:00
catch ( const uno : : Exception & )
2006-11-01 17:19:51 +00:00
{ }
2004-10-04 18:49:03 +00:00
2006-11-01 17:19:51 +00: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 ( ) ;
2014-04-17 11:39:18 +02:00
bool bOk = m_pDocHolder - > ShowUI ( xContainerLM , xContainerDP , aModuleName ) ;
2006-11-01 17:19:51 +00:00
xContainerLM - > unlock ( ) ;
if ( bOk )
{
m_nObjectState = nNextState ;
m_pDocHolder - > ResizeHatchWindow ( ) ;
}
else
{
xInplaceClient - > deactivatedUI ( ) ;
throw embed : : WrongStateException ( ) ; //TODO: can't activate UI
}
2003-10-27 12:05:38 +00:00
}
2004-10-04 18:49:03 +00:00
else
throw embed : : WrongStateException ( ) ; //TODO: can't activate UI
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! " ) ;
2004-10-04 18:49:03 +00:00
throw uno : : RuntimeException ( ) ; // TODO
}
}
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! " ) ;
2003-10-27 12:05:38 +00:00
throw uno : : RuntimeException ( ) ; // TODO
}
}
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 ( ) )
2015-07-14 14:22:03 +02:00
bOk = m_pDocHolder - > HideUI ( xContainerLM ) ;
2004-10-04 18:49:03 +00:00
if ( bOk )
{
m_nObjectState = nNextState ;
2006-11-01 17:19:51 +00:00
m_pDocHolder - > ResizeHatchWindow ( ) ;
2015-07-14 14:22:03 +02:00
xInplaceClient - > deactivatedUI ( ) ;
2004-10-04 18:49:03 +00:00
}
else
throw embed : : WrongStateException ( ) ; //TODO: can't activate UI
}
}
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
2003-10-27 12:05:38 +00:00
uno : : Sequence < sal_Int32 > OCommonEmbeddedObject : : GetIntermediateStatesSequence_Impl ( sal_Int32 nNewState )
{
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 )
throw ( embed : : UnreachableStateException ,
embed : : WrongStateException ,
uno : : Exception ,
2014-02-25 21:31:58 +01:00
uno : : RuntimeException , std : : exception )
2003-10-27 12:05:38 +00:00
{
2004-08-02 16:43:51 +00:00
{
: : osl : : ResettableMutexGuard aGuard ( m_aMutex ) ;
if ( m_bDisposed )
throw lang : : DisposedException ( ) ; // TODO
2003-10-27 12:05:38 +00:00
2004-08-02 16:43:51 +00:00
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
2005-02-25 08:20:55 +00:00
sal_Int32 nOldState = m_nObjectState ;
2004-10-04 18:49:03 +00:00
2005-02-25 08:20:55 +00:00
if ( m_nTargetState ! = - 1 )
{
// means that the object is currently trying to reach the target state
2013-04-07 12:06:47 +02:00
throw embed : : StateChangeInProgressException ( OUString ( ) ,
2005-02-25 08:20:55 +00:00
uno : : Reference < uno : : XInterface > ( ) ,
m_nTargetState ) ;
2004-10-04 18:49:03 +00:00
}
2005-02-25 08:20:55 +00:00
else
{
TargetStateControl_Impl aControl ( m_nTargetState , nNewState ) ;
2003-10-27 12:05:38 +00:00
2005-02-25 08:20:55 +00:00
// in case the object is already in requested state
if ( m_nObjectState = = nNewState )
{
// if active object is activated again, bring it's window to top
if ( m_nObjectState = = embed : : EmbedStates : : ACTIVE )
m_pDocHolder - > Show ( ) ;
2004-05-10 16:51:00 +00:00
2005-02-25 08:20:55 +00:00
return ;
}
2003-10-27 12:05:38 +00:00
2005-02-25 08:20:55 +00: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
2005-02-25 08:20:55 +00:00
// notify listeners that the object is going to change the state
2014-04-17 11:39:18 +02:00
StateChangeNotification_Impl ( true , nOldState , nNewState , aGuard ) ;
2004-05-10 16:51:00 +00:00
2005-02-25 08:20:55 +00:00
try {
for ( sal_Int32 nInd = 0 ; nInd < aIntermediateStates . getLength ( ) ; nInd + + )
SwitchStateTo_Impl ( aIntermediateStates [ nInd ] ) ;
2004-05-10 16:51:00 +00:00
2005-02-25 08:20:55 +00:00
SwitchStateTo_Impl ( nNewState ) ;
}
2011-12-09 02:56:30 +09:00
catch ( const uno : : Exception & )
2005-02-25 08:20:55 +00:00
{
if ( nOldState ! = m_nObjectState )
// notify listeners that the object has changed the state
2014-04-17 11:39:18 +02:00
StateChangeNotification_Impl ( false , nOldState , m_nObjectState , aGuard ) ;
2005-02-25 08:20:55 +00:00
throw ;
}
2004-08-02 16:43:51 +00:00
}
2004-05-10 16:51:00 +00:00
2004-08-02 16:43:51 +00:00
// notify listeners that the object has changed the state
2014-04-17 11:39:18 +02:00
StateChangeNotification_Impl ( false , nOldState , nNewState , aGuard ) ;
2010-12-03 10:58:55 +01:00
// let the object window be shown
if ( nNewState = = embed : : EmbedStates : : UI_ACTIVE | | nNewState = = embed : : EmbedStates : : INPLACE_ACTIVE )
2015-11-06 09:35:43 +01:00
PostEvent_Impl ( " OnVisAreaChanged " ) ;
2004-08-02 16:43:51 +00:00
}
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 ( )
throw ( embed : : WrongStateException ,
2014-02-25 21:31:58 +01:00
uno : : RuntimeException , std : : exception )
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
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 ( )
throw ( embed : : WrongStateException ,
2014-02-25 21:31:58 +01:00
uno : : RuntimeException , std : : exception )
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
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 )
throw ( lang : : IllegalArgumentException ,
embed : : WrongStateException ,
embed : : UnreachableStateException ,
uno : : Exception ,
2014-02-25 21:31:58 +01:00
uno : : RuntimeException , std : : exception )
2003-10-27 12:05:38 +00:00
{
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
2010-12-03 10:58:55 +01:00
: : osl : : ResettableMutexGuard 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
throw ( embed : : WrongStateException ,
2014-02-25 21:31:58 +01:00
uno : : RuntimeException , std : : exception )
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 )
throw ( embed : : WrongStateException ,
2014-02-25 21:31:58 +01:00
uno : : RuntimeException , std : : exception )
2003-10-27 12:05:38 +00:00
{
: : 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 ( )
throw ( embed : : WrongStateException ,
2014-02-25 21:31:58 +01:00
uno : : RuntimeException , std : : exception )
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
return m_xClientSite ;
}
2014-02-22 21:20:15 +01:00
2003-10-27 12:05:38 +00:00
void SAL_CALL OCommonEmbeddedObject : : update ( )
throw ( embed : : WrongStateException ,
uno : : Exception ,
2014-02-25 21:31:58 +01:00
uno : : RuntimeException , std : : exception )
2003-10-27 12:05:38 +00:00
{
: : 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 )
throw ( embed : : WrongStateException ,
2014-02-25 21:31:58 +01:00
uno : : RuntimeException , std : : exception )
2003-10-27 12:05:38 +00:00
{
: : 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 ,
2003-10-27 12:05:38 +00:00
" Unknown update mode! \n " ) ;
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
throw ( embed : : WrongStateException ,
2014-02-25 21:31:58 +01:00
uno : : RuntimeException , std : : exception )
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 )
2014-02-25 21:31:58 +01:00
throw ( uno : : RuntimeException , std : : exception )
2004-05-10 16:51:00 +00:00
{
: : osl : : MutexGuard aGuard ( m_aMutex ) ;
if ( m_bDisposed )
throw lang : : DisposedException ( ) ; // TODO
m_aContainerName = sName ;
}
2015-09-29 15:07:23 +02:00
css : : uno : : Reference < css : : uno : : XInterface > SAL_CALL OCommonEmbeddedObject : : getParent ( ) throw ( css : : uno : : RuntimeException , std : : exception )
2005-04-04 07:07:56 +00:00
{
return m_xParent ;
}
2015-09-29 15:07:23 +02:00
void SAL_CALL OCommonEmbeddedObject : : setParent ( const css : : uno : : Reference < css : : uno : : XInterface > & xParent ) throw ( css : : lang : : NoSupportException , css : : uno : : RuntimeException , std : : exception )
2005-04-04 07:07:56 +00:00
{
m_xParent = xParent ;
if ( m_nObjectState ! = - 1 & & m_nObjectState ! = embed : : EmbedStates : : LOADED )
{
uno : : Reference < container : : XChild > xChild ( m_pDocHolder - > GetComponent ( ) , uno : : UNO_QUERY ) ;
if ( xChild . is ( ) )
xChild - > setParent ( xParent ) ;
}
}
2004-05-10 16:51:00 +00:00
2009-09-14 10:57:16 +00:00
// XDefaultSizeTransmitter
2015-09-29 15:07:23 +02:00
void SAL_CALL OCommonEmbeddedObject : : setDefaultSize ( const css : : awt : : Size & rSize_100TH_MM ) throw ( css : : uno : : RuntimeException , std : : exception )
2009-09-14 10:57:16 +00:00
{
//#i103460# charts do not necessaryly 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
m_aDefaultSizeForChart_In_100TH_MM = rSize_100TH_MM ;
}
2010-10-12 15:53:47 +02:00
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */