diff options
author | Mikhail Voitenko <mav@openoffice.org> | 2003-10-27 12:05:38 +0000 |
---|---|---|
committer | Mikhail Voitenko <mav@openoffice.org> | 2003-10-27 12:05:38 +0000 |
commit | 8ff77785fb57ca358e3efa52c9270b3a66c25b06 (patch) | |
tree | 8149d0b0a1be9421a01ebeb1511bf86148bfb535 /embeddedobj | |
parent | d92b62a941ea3a824c4f4b91621f16e88cf4ba59 (diff) |
#112739# initial version
Diffstat (limited to 'embeddedobj')
-rw-r--r-- | embeddedobj/prj/build.lst | 5 | ||||
-rw-r--r-- | embeddedobj/prj/d.lst | 0 | ||||
-rw-r--r-- | embeddedobj/source/commonembedding/embedobj.cxx | 444 | ||||
-rw-r--r-- | embeddedobj/source/commonembedding/makefile.mk | 95 | ||||
-rw-r--r-- | embeddedobj/source/commonembedding/miscobj.cxx | 451 | ||||
-rw-r--r-- | embeddedobj/source/commonembedding/persistence.cxx | 1003 | ||||
-rw-r--r-- | embeddedobj/source/commonembedding/visobj.cxx | 183 | ||||
-rw-r--r-- | embeddedobj/source/general/docholder.cxx | 583 | ||||
-rw-r--r-- | embeddedobj/source/general/intercept.cxx | 474 | ||||
-rw-r--r-- | embeddedobj/source/general/makefile.mk | 99 | ||||
-rw-r--r-- | embeddedobj/source/inc/closepreventer.hxx | 79 | ||||
-rw-r--r-- | embeddedobj/source/inc/commonembobj.hxx | 443 | ||||
-rw-r--r-- | embeddedobj/source/inc/docholder.hxx | 175 | ||||
-rw-r--r-- | embeddedobj/source/inc/intercept.hxx | 219 | ||||
-rw-r--r-- | embeddedobj/util/exports.dxp | 3 | ||||
-rw-r--r-- | embeddedobj/util/makefile.mk | 106 |
16 files changed, 4362 insertions, 0 deletions
diff --git a/embeddedobj/prj/build.lst b/embeddedobj/prj/build.lst new file mode 100644 index 000000000000..4c80b5bd3df4 --- /dev/null +++ b/embeddedobj/prj/build.lst @@ -0,0 +1,5 @@ +es embeddedobj : offuh sal cppu cppuhelper NULL +es embeddedobj usr1 - all eo_mkout NULL +es embeddedobj\source\commonembedding nmake - all eo_commonembed NULL +es embeddedobj\source\general nmake - all eo_general NULL +es embeddedobj\util nmake - all eo_util eo_commonembed eo_general NULL diff --git a/embeddedobj/prj/d.lst b/embeddedobj/prj/d.lst new file mode 100644 index 000000000000..e69de29bb2d1 --- /dev/null +++ b/embeddedobj/prj/d.lst diff --git a/embeddedobj/source/commonembedding/embedobj.cxx b/embeddedobj/source/commonembedding/embedobj.cxx new file mode 100644 index 000000000000..aa980a59024c --- /dev/null +++ b/embeddedobj/source/commonembedding/embedobj.cxx @@ -0,0 +1,444 @@ +/************************************************************************* + * + * $RCSfile: embedobj.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: mav $ $Date: 2003-10-27 12:57:28 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COM_SUN_STAR_EMBED_EMBEDSTATES_HPP_ +#include <com/sun/star/embed/EmbedStates.hpp> +#endif +#ifndef _COM_SUN_STAR_EMBED_EMBEDVERBS_HPP_ +#include <com/sun/star/embed/EmbedVerbs.hpp> +#endif +#ifndef _COM_SUN_STAR_EMBED_EMBEDUPDATEMODES_HPP_ +#include <com/sun/star/embed/EmbedUpdateModes.hpp> +#endif +#ifndef _COM_SUN_STAR_EMBED_XEMBEDDEDCLIENT_HPP_ +#include <com/sun/star/embed/XEmbeddedClient.hpp> +#endif + +#ifndef _COM_SUN_STAR_UTIL_XCLOSEBROADCASTER_HPP_ +#include <com/sun/star/util/XCloseBroadcaster.hpp> +#endif +#ifndef _COM_SUN_STAR_UTIL_XCLOSEABLE_HPP_ +#include <com/sun/star/util/XCloseable.hpp> +#endif +#ifndef _COM_SUN_STAR_UTIL_XMODIFIABLE_HPP_ +#include <com/sun/star/util/XModifiable.hpp> +#endif + +#ifndef _COM_SUN_STAR_FRAME_XFRAME_HPP_ +#include <com/sun/star/frame/XFrame.hpp> +#endif +#ifndef _COM_SUN_STAR_FRAME_XCOMPONENTLOADER_HPP_ +#include <com/sun/star/frame/XComponentLoader.hpp> +#endif +#ifndef _COM_SUN_STAR_FRAME_XDISPATCHPROVIDERINTERCEPTION_HPP_ +#include <com/sun/star/frame/XDispatchProviderInterception.hpp> +#endif + +#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_ +#include <com/sun/star/lang/DisposedException.hpp> +#endif + + +#include "commonembobj.hxx" +#include "convert.hxx" +#include "intercept.hxx" + + +using namespace ::com::sun::star; + +//---------------------------------------------- +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 +} + +//---------------------------------------------- +void OCommonEmbeddedObject::SwitchStateTo_Impl( sal_Int32 nNextState ) +{ + // TODO: may be needs interaction handler to detect wherether the object state + // can be changed even after errors + + if ( m_nObjectState == embed::EmbedStates::EMBED_LOADED ) + { + if ( nNextState == embed::EmbedStates::EMBED_RUNNING ) + { + if ( m_bIsLink ) + { + m_pDocHolder->SetDocument( LoadLink_Impl(), m_bReadOnly ); + } + else + { + // 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 + + m_pDocHolder->SetDocument( LoadDocumentFromStorage_Impl( m_xObjectStorage ), m_bReadOnly ); + } + + if ( !m_pDocHolder->GetDocument().is() ) + embed::UnreachableStateException(); //TODO: can't open document + + m_nObjectState = nNextState; + } + else + { + OSL_ENSURE( sal_False, "Unacceptable state switch!\n" ); + throw uno::RuntimeException(); // TODO + } + } + else if ( m_nObjectState == embed::EmbedStates::EMBED_RUNNING ) + { + if ( nNextState == embed::EmbedStates::EMBED_LOADED ) + { + // actually frame should not exist at this point + m_pDocHolder->CloseDocument(); + + m_nObjectState = nNextState; + } + else if ( nNextState == embed::EmbedStates::EMBED_ACTIVE ) + { + // create frame and load document in the frame + m_pDocHolder->Show(); + + m_nObjectState = nNextState; + } + else + { + OSL_ENSURE( sal_False, "Unacceptable state switch!\n" ); + throw uno::RuntimeException(); // TODO + } + } + else if ( m_nObjectState == embed::EmbedStates::EMBED_ACTIVE ) + { + if ( nNextState == embed::EmbedStates::EMBED_RUNNING ) + { + uno::Reference< util::XModifiable > xModif( m_pDocHolder->GetDocument(), uno::UNO_QUERY ); + if ( !xModif.is() ) + throw uno::RuntimeException(); + + // store document if it is modified + if ( xModif->isModified() ) + { + try { + m_xClientSite->saveObject(); + } + catch( embed::ObjectSaveVetoException& ) + { + } + catch( uno::Exception& e ) + { + throw embed::StorageWTException( + ::rtl::OUString::createFromAscii( "The client could not store the object!" ), + uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >( this ) ), + uno::makeAny( e ) ); + } + } + + m_pDocHolder->CloseFrame(); + // when Hide() method is fixed the frame will not be closed but hided + // m_pDocHolder->Hide(); + + m_nObjectState = nNextState; + } + else + { + OSL_ENSURE( sal_False, "Unacceptable state switch!\n" ); + throw uno::RuntimeException(); // TODO + } + } + else + throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object is in unacceptable state!\n" ), + uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) ); +} + +//---------------------------------------------- +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() ) + throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object is in unacceptable state!\n" ), + uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) ); + + 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( + ::rtl::OUString::createFromAscii( "The state either not reachable, or the object allows the state only as an intermediate one!\n" ), + uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ), + m_nObjectState, + nNewState ); + + return m_pIntermediateStatesSeqs[nCurInd][nDestInd]; +} + +//---------------------------------------------- +void SAL_CALL OCommonEmbeddedObject::changeState( sal_Int32 nNewState ) + throw ( embed::UnreachableStateException, + embed::WrongStateException, + uno::Exception, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if ( m_bDisposed ) + throw lang::DisposedException(); // TODO + + if ( m_nObjectState == -1 ) + throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ), + uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) ); + + // in case the object is already in requested state + if ( m_nObjectState == nNewState ) + return; + + // retrieve sequence of states that should be passed to reach desired state + uno::Sequence< sal_Int32 > aIntermediateStates = GetIntermediateStatesSequence_Impl( nNewState ); + + for ( sal_Int32 nInd = 0; nInd < aIntermediateStates.getLength(); nInd++ ) + SwitchStateTo_Impl( aIntermediateStates[nInd] ); + + SwitchStateTo_Impl( nNewState ); +} + +//---------------------------------------------- +uno::Sequence< sal_Int32 > SAL_CALL OCommonEmbeddedObject::getReachableStates() + throw ( embed::WrongStateException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if ( m_bDisposed ) + throw lang::DisposedException(); // TODO + + if ( m_nObjectState == -1 ) + throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ), + uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) ); + + return m_aAcceptedStates; +} + +//---------------------------------------------- +sal_Int32 SAL_CALL OCommonEmbeddedObject::getCurrentState() + throw ( embed::WrongStateException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if ( m_bDisposed ) + throw lang::DisposedException(); // TODO + + if ( m_nObjectState == -1 ) + throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ), + uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) ); + + return m_nObjectState; +} + +//---------------------------------------------- +void SAL_CALL OCommonEmbeddedObject::doVerb( sal_Int32 nVerbID ) + throw ( lang::IllegalArgumentException, + embed::WrongStateException, + embed::UnreachableStateException, + uno::Exception, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if ( m_bDisposed ) + throw lang::DisposedException(); // TODO + + if ( m_nObjectState == -1 ) + throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ), + uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) ); + + // for internal documents this call is just a duplicate of changeState + changeState( ConvertVerbToState_Impl( nVerbID ) ); +} + +//---------------------------------------------- +uno::Sequence< sal_Int32 > SAL_CALL OCommonEmbeddedObject::getSupportedVerbs() + throw ( embed::WrongStateException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if ( m_bDisposed ) + throw lang::DisposedException(); // TODO + + if ( m_nObjectState == -1 ) + throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ), + uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) ); + + uno::Sequence< sal_Int32 > aResult; + sal_Int32 nResLen = 0; + + // verbs list will be set on initialization depending from document type + for ( sal_Int32 nStatesInd = 0; nStatesInd < m_aAcceptedStates.getLength(); nStatesInd++ ) + for ( sal_Int32 nVerbInd = 0; nVerbInd < m_aVerbTable.getLength(); nVerbInd++ ) + if ( m_aVerbTable[nVerbInd][1] == m_aAcceptedStates[nStatesInd] ) + { + aResult.realloc( ++nResLen ); + aResult[nResLen-1] = m_aVerbTable[nVerbInd][0]; + } + + return aResult; +} + +//---------------------------------------------- +void SAL_CALL OCommonEmbeddedObject::setClientSite( + const uno::Reference< embed::XEmbeddedClient >& xClient ) + throw ( embed::WrongStateException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if ( m_bDisposed ) + throw lang::DisposedException(); // TODO + + if ( m_nObjectState == -1 ) + throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ), + uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) ); + + m_xClientSite = xClient; +} + +//---------------------------------------------- +uno::Reference< embed::XEmbeddedClient > SAL_CALL OCommonEmbeddedObject::getClientSite() + throw ( embed::WrongStateException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if ( m_bDisposed ) + throw lang::DisposedException(); // TODO + + if ( m_nObjectState == -1 ) + throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ), + uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) ); + + return m_xClientSite; +} + +//---------------------------------------------- +void SAL_CALL OCommonEmbeddedObject::update() + throw ( embed::WrongStateException, + uno::Exception, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if ( m_bDisposed ) + throw lang::DisposedException(); // TODO + + if ( m_nObjectState == -1 ) + throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ), + uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) ); + + if ( m_nUpdateMode == embed::EmbedUpdateModes::EMBED_EXPLICIT_UPDATE ) + { + // TODO: update view representation + } + else + { + // the object must be up to date + OSL_ENSURE( m_nUpdateMode == embed::EmbedUpdateModes::EMBED_ALWAYS_UPDATE, "Unknown update mode!\n" ); + } +} + +//---------------------------------------------- +void SAL_CALL OCommonEmbeddedObject::setUpdateMode( sal_Int32 nMode ) + throw ( embed::WrongStateException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if ( m_bDisposed ) + throw lang::DisposedException(); // TODO + + if ( m_nObjectState == -1 ) + throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ), + uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) ); + + OSL_ENSURE( nMode == embed::EmbedUpdateModes::EMBED_ALWAYS_UPDATE + || nMode == embed::EmbedUpdateModes::EMBED_EXPLICIT_UPDATE, + "Unknown update mode!\n" ); + m_nUpdateMode = nMode; +} + +//---------------------------------------------- +sal_Int64 SAL_CALL OCommonEmbeddedObject::getStatus( sal_Int64 nAspect ) + throw ( embed::WrongStateException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if ( m_bDisposed ) + throw lang::DisposedException(); // TODO + + return 0; + // TODO: + // the status information must be filled in from configuration during object contruction +} + diff --git a/embeddedobj/source/commonembedding/makefile.mk b/embeddedobj/source/commonembedding/makefile.mk new file mode 100644 index 000000000000..2394383356bc --- /dev/null +++ b/embeddedobj/source/commonembedding/makefile.mk @@ -0,0 +1,95 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1 $ +# +# last change: $Author: mav $ $Date: 2003-10-27 12:57:21 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (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.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. + +PRJNAME=embeddedobj +TARGET=embedobj + + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +LIBTARGET=NO +USE_DEFFILE=NO + +# --- Files -------------------------------------------------------- + +SLOFILES = \ + $(SLO)$/miscobj.obj\ + $(SLO)$/persistence.obj\ + $(SLO)$/embedobj.obj\ + $(SLO)$/visobj.obj + + +EXCEPTIONSFILES= \ + $(SLO)$/miscobj.obj\ + $(SLO)$/persistence.obj\ + $(SLO)$/embedobj.obj\ + $(SLO)$/visobj.obj + + +# --- Targets ------------------------------------------------------- + +.INCLUDE : target.mk + diff --git a/embeddedobj/source/commonembedding/miscobj.cxx b/embeddedobj/source/commonembedding/miscobj.cxx new file mode 100644 index 000000000000..36540d7f5681 --- /dev/null +++ b/embeddedobj/source/commonembedding/miscobj.cxx @@ -0,0 +1,451 @@ +/************************************************************************* + * + * $RCSfile: miscobj.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: mav $ $Date: 2003-10-27 12:57:29 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include <commonembobj.hxx> + +#ifndef _COM_SUN_STAR_EMBED_EMBEDSTATES_HPP_ +#include <com/sun/star/embed/EmbedStates.hpp> +#endif +#ifndef _COM_SUN_STAR_EMBED_EMBEDVERBS_HPP_ +#include <com/sun/star/embed/EmbedVerbs.hpp> +#endif +#ifndef _COM_SUN_STAR_EMBED_XSTORAGE_HPP_ +#include <com/sun/star/embed/XStorage.hpp> +#endif +#ifndef _COM_SUN_STAR_EMBED_EMBEDUPDATEMODES_HPP_ +#include <com/sun/star/embed/EmbedUpdateModes.hpp> +#endif + +#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_ +#include <com/sun/star/lang/DisposedException.hpp> +#endif + +#include <cppuhelper/typeprovider.hxx> +#include <cppuhelper/interfacecontainer.h> + +#include "closepreventer.hxx" +#include "intercept.hxx" + +using namespace ::com::sun::star; + +//------------------------------------------------------ +OCommonEmbeddedObject::OCommonEmbeddedObject( const uno::Reference< lang::XMultiServiceFactory >& xFactory, + const uno::Sequence< sal_Int8 >& aClassID, + const ::rtl::OUString& aClassName, + const ::rtl::OUString& aDocServiceName ) +: m_pDocHolder( NULL ) +, m_pInterfaceContainer( NULL ) +, m_bReadOnly( sal_False ) +, m_bDisposed( sal_False ) +, m_nObjectState( -1 ) +, m_nUpdateMode ( embed::EmbedUpdateModes::EMBED_ALWAYS_UPDATE ) +, m_xFactory( xFactory ) +, m_aClassID( aClassID ) +, m_aClassName( aClassName ) +, m_aDocServiceName( aDocServiceName ) +, m_aAcceptedStates( NUM_SUPPORTED_STATES ) +, m_aVerbTable( NUM_SUPPORTED_VERBS ) +, m_bWaitSaveCompleted( sal_False ) +, m_bIsLink( sal_False ) +{ + CommonInit_Impl(); +} + +//------------------------------------------------------ +OCommonEmbeddedObject::OCommonEmbeddedObject( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory, + const ::com::sun::star::uno::Sequence< sal_Int8 >& aClassID, + const ::rtl::OUString& aClassName, + const ::rtl::OUString& aDocServiceName, + const ::rtl::OUString& aLinkFilterName, + const ::rtl::OUString& aLinkURL ) +: m_pDocHolder( NULL ) +, m_pInterfaceContainer( NULL ) +, m_bReadOnly( sal_False ) +, m_bDisposed( sal_False ) +, m_nObjectState( embed::EmbedStates::EMBED_LOADED ) +, m_nUpdateMode ( embed::EmbedUpdateModes::EMBED_ALWAYS_UPDATE ) +, m_xFactory( xFactory ) +, m_aClassID( aClassID ) +, m_aClassName( aClassName ) +, m_aDocServiceName( aDocServiceName ) +, m_aAcceptedStates( NUM_SUPPORTED_STATES ) +, m_aVerbTable( NUM_SUPPORTED_VERBS ) +, m_bWaitSaveCompleted( sal_False ) +, m_bIsLink( sal_True ) +, m_aLinkFilterName( aLinkFilterName ) +, m_aLinkURL( aLinkURL ) +{ + OSL_ENSURE( m_aLinkURL.getLength(), "The link for linked object must not be empty!\n" ); + + // linked object has no persistence so it is in loaded state starting from creation + CommonInit_Impl(); +} + +//------------------------------------------------------ +void OCommonEmbeddedObject::CommonInit_Impl() +{ + OSL_ENSURE( m_xFactory.is(), "No ServiceFactory is provided!\n" ); + if ( !m_xFactory.is() ) + throw uno::RuntimeException(); + + m_pDocHolder = new DocumentHolder( m_xFactory, this ); + m_pDocHolder->acquire(); + + // accepted states + m_aAcceptedStates[0] = embed::EmbedStates::EMBED_LOADED; + m_aAcceptedStates[1] = embed::EmbedStates::EMBED_RUNNING; + m_aAcceptedStates[2] = embed::EmbedStates::EMBED_ACTIVE; + + // intermediate states + m_pIntermediateStatesSeqs[0][2].realloc( 1 ); + m_pIntermediateStatesSeqs[0][2][0] = embed::EmbedStates::EMBED_RUNNING; + + m_pIntermediateStatesSeqs[2][0].realloc( 1 ); + m_pIntermediateStatesSeqs[2][0][0] = embed::EmbedStates::EMBED_RUNNING; + + // verbs table + m_aVerbTable[0].realloc( 2 ); + m_aVerbTable[0][0] = embed::EmbedVerbs::MS_OLEVERB_PRIMARY; + m_aVerbTable[0][1] = embed::EmbedStates::EMBED_ACTIVE; + + m_aVerbTable[1].realloc( 2 ); + m_aVerbTable[1][0] = embed::EmbedVerbs::MS_OLEVERB_SHOW; + m_aVerbTable[1][1] = embed::EmbedStates::EMBED_ACTIVE; + + m_aVerbTable[2].realloc( 2 ); + m_aVerbTable[2][0] = embed::EmbedVerbs::MS_OLEVERB_OPEN; + m_aVerbTable[2][1] = embed::EmbedStates::EMBED_ACTIVE; + + m_xClosePreventer = uno::Reference< util::XCloseListener >( + static_cast< ::cppu::OWeakObject* >( new OClosePreventer() ), + uno::UNO_QUERY ); +} + +//------------------------------------------------------ +OCommonEmbeddedObject::~OCommonEmbeddedObject() +{ + if ( m_pInterfaceContainer ) + { + delete m_pInterfaceContainer; + m_pInterfaceContainer = NULL; + } + + if ( m_pDocHolder ) + { + m_pDocHolder->CloseFrame(); + m_pDocHolder->CloseDocument(); + m_pDocHolder->FreeOffice(); + + m_pDocHolder->release(); + m_pDocHolder = NULL; + } +} + +//------------------------------------------------------ +void OCommonEmbeddedObject::PostEvent_Impl( const ::rtl::OUString& aEventName ) +{ + if ( m_pInterfaceContainer ) + { + ::cppu::OInterfaceContainerHelper* pIC = m_pInterfaceContainer->getContainer( + ::getCppuType((const uno::Reference< document::XEventListener >*)0) ); + if( pIC ) + { + document::EventObject aEvent( (embed::XEmbeddedObject*)this, aEventName ); + ::cppu::OInterfaceIteratorHelper aIt( *pIC ); + while( aIt.hasMoreElements() ) + { + try + { + ((document::XEventListener *)aIt.next())->notifyEvent( aEvent ); + } + catch( uno::RuntimeException& ) + { + aIt.remove(); + } + } + } + } +} + +//------------------------------------------------------ +uno::Any SAL_CALL OCommonEmbeddedObject::queryInterface( const uno::Type& rType ) + throw( uno::RuntimeException ) +{ + uno::Any aReturn; + + aReturn <<= ::cppu::queryInterface( rType, + static_cast< embed::XEmbeddedObject* >( this ), + static_cast< embed::XVisualObject* >( this ), + static_cast< embed::XEmbedPersist* >( this ), + static_cast< embed::XClassifiedObject* >( this ), + static_cast< embed::XComponentSupplier* >( this ), + static_cast< document::XEventBroadcaster* >( this ) ); + + if ( aReturn.hasValue() ) + return aReturn; + else + return ::cppu::OWeakObject::queryInterface( rType ) ; + +} + +//------------------------------------------------------ +void SAL_CALL OCommonEmbeddedObject::acquire() + throw() +{ + ::cppu::OWeakObject::acquire() ; +} + +//------------------------------------------------------ +void SAL_CALL OCommonEmbeddedObject::release() + throw() +{ + ::cppu::OWeakObject::release() ; +} + +//------------------------------------------------------ +uno::Sequence< uno::Type > SAL_CALL OCommonEmbeddedObject::getTypes() + throw( uno::RuntimeException ) +{ + static ::cppu::OTypeCollection* pTypeCollection = NULL; + + if ( !pTypeCollection ) + { + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if ( !pTypeCollection ) + { + static ::cppu::OTypeCollection aTypeCollection( + ::getCppuType( (const uno::Reference< lang::XTypeProvider >*)NULL ), + ::getCppuType( (const uno::Reference< embed::XEmbeddedObject >*)NULL ), + ::getCppuType( (const uno::Reference< embed::XVisualObject >*)NULL ), + ::getCppuType( (const uno::Reference< embed::XEmbedPersist >*)NULL ), + ::getCppuType( (const uno::Reference< embed::XClassifiedObject >*)NULL ), + ::getCppuType( (const uno::Reference< embed::XComponentSupplier >*)NULL ), + ::getCppuType( (const uno::Reference< document::XEventBroadcaster >*)NULL ) ); + + pTypeCollection = &aTypeCollection ; + } + } + + return pTypeCollection->getTypes() ; + +} + +//------------------------------------------------------ +uno::Sequence< sal_Int8 > SAL_CALL OCommonEmbeddedObject::getImplementationId() + throw( uno::RuntimeException ) +{ + static ::cppu::OImplementationId* pID = NULL ; + + if ( !pID ) + { + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ) ; + if ( !pID ) + { + static ::cppu::OImplementationId aID( sal_False ) ; + pID = &aID ; + } + } + + return pID->getImplementationId() ; +} + +//------------------------------------------------------ +uno::Sequence< sal_Int8 > SAL_CALL OCommonEmbeddedObject::getClassID() + throw ( uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if ( m_bDisposed ) + throw lang::DisposedException(); // TODO + + return m_aClassID; +} + +//------------------------------------------------------ +::rtl::OUString SAL_CALL OCommonEmbeddedObject::getClassName() + throw ( uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if ( m_bDisposed ) + throw lang::DisposedException(); // TODO + + return m_aClassName; +} + +//------------------------------------------------------ +void SAL_CALL OCommonEmbeddedObject::setClassInfo( + const uno::Sequence< sal_Int8 >& aClassID, const ::rtl::OUString& aClassName ) + throw ( lang::NoSupportException, + uno::RuntimeException ) +{ + // the object class info can not be changed explicitly + throw lang::NoSupportException(); //TODO: +} + +//------------------------------------------------------ +uno::Reference< lang::XComponent > SAL_CALL OCommonEmbeddedObject::getComponent() + throw ( uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if ( m_bDisposed ) + throw lang::DisposedException(); // TODO + + // add an exception + if ( m_nObjectState == -1 ) + { + // the object is still not loaded + throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Can't store object without persistence!\n" ), + uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) ); + } + + if ( m_bWaitSaveCompleted ) + throw embed::WrongStateException( + ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ), + uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) ); + + return uno::Reference< lang::XComponent >( m_pDocHolder->GetDocument(), uno::UNO_QUERY ); +} + +//------------------------------------------------------ +void SAL_CALL OCommonEmbeddedObject::addEventListener( const uno::Reference< document::XEventListener >& xListener ) + throw ( uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if ( m_bDisposed ) + throw lang::DisposedException(); // TODO + + if ( !m_pInterfaceContainer ) + m_pInterfaceContainer = new ::cppu::OMultiTypeInterfaceContainerHelper( m_aMutex ); + + m_pInterfaceContainer->addInterface( ::getCppuType( (const uno::Reference< document::XEventListener >*)0 ), xListener ); +} + +//------------------------------------------------------ +void SAL_CALL OCommonEmbeddedObject::removeEventListener( const uno::Reference< document::XEventListener >& xListener ) + throw ( uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if ( m_bDisposed ) + throw lang::DisposedException(); // TODO + + if ( m_pInterfaceContainer ) + m_pInterfaceContainer->removeInterface( ::getCppuType( (const uno::Reference< document::XEventListener >*)0 ), + xListener ); +} + +//------------------------------------------------------ +void SAL_CALL OCommonEmbeddedObject::dispose() + throw ( uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if ( m_bDisposed ) + throw lang::DisposedException(); // TODO + + if ( m_pInterfaceContainer ) + { + lang::EventObject aEvent( (embed::XEmbeddedObject*)this ); + m_pInterfaceContainer->disposeAndClear( aEvent ); + + delete m_pInterfaceContainer; + m_pInterfaceContainer = NULL; + } + + if ( m_pDocHolder ) + { + m_pDocHolder->CloseFrame(); + m_pDocHolder->CloseDocument(); + m_pDocHolder->FreeOffice(); + + m_pDocHolder->release(); + m_pDocHolder = NULL; + } + + m_bDisposed = true; +} + +//------------------------------------------------------ +void SAL_CALL OCommonEmbeddedObject::addEventListener( const uno::Reference< lang::XEventListener >& xListener ) + throw ( uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if ( m_bDisposed ) + throw lang::DisposedException(); // TODO + + if ( !m_pInterfaceContainer ) + m_pInterfaceContainer = new ::cppu::OMultiTypeInterfaceContainerHelper( m_aMutex ); + + m_pInterfaceContainer->addInterface( ::getCppuType( (const uno::Reference< lang::XEventListener >*)0 ), xListener ); +} + +//------------------------------------------------------ +void SAL_CALL OCommonEmbeddedObject::removeEventListener( + const uno::Reference< lang::XEventListener >& xListener ) + throw ( uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if ( m_bDisposed ) + throw lang::DisposedException(); // TODO + + if ( m_pInterfaceContainer ) + m_pInterfaceContainer->removeInterface( ::getCppuType( (const uno::Reference< lang::XEventListener >*)0 ), + xListener ); +} + diff --git a/embeddedobj/source/commonembedding/persistence.cxx b/embeddedobj/source/commonembedding/persistence.cxx new file mode 100644 index 000000000000..55985fe6652d --- /dev/null +++ b/embeddedobj/source/commonembedding/persistence.cxx @@ -0,0 +1,1003 @@ +/************************************************************************* + * + * $RCSfile: persistence.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: mav $ $Date: 2003-10-27 12:57:29 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include <commonembobj.hxx> + +#ifndef _COM_SUN_STAR_EMBED_EMBEDSTATES_HPP_ +#include <com/sun/star/embed/EmbedStates.hpp> +#endif +#ifndef _COM_SUN_STAR_EMBED_EMBEDVERBS_HPP_ +#include <com/sun/star/embed/EmbedVerbs.hpp> +#endif +#ifndef _COM_SUN_STAR_EMBED_ENTRYINITMODES_HPP_ +#include <com/sun/star/embed/EntryInitModes.hpp> +#endif +#ifndef _COM_SUN_STAR_EMBED_XSTORAGE_HPP_ +#include <com/sun/star/embed/XStorage.hpp> +#endif +#ifndef _COM_SUN_STAR_EMBED_ELEMENTMODES_HPP_ +#include <com/sun/star/embed/ElementModes.hpp> +#endif +#ifndef _COM_SUN_STAR_EMBED_EMBEDUPDATEMODES_HPP_ +#include <com/sun/star/embed/EmbedUpdateModes.hpp> +#endif + +#ifndef _COM_SUN_STAR_FRAME_XMODEL_HPP_ +#include <com/sun/star/frame/XModel.hpp> +#endif +#ifndef _COM_SUN_STAR_FRAME_XSTORABLE_HPP_ +#include <com/sun/star/frame/XStorable.hpp> +#endif +#ifndef _COM_SUN_STAR_FRAME_XLOADABLE_HPP_ +#include <com/sun/star/frame/XLoadable.hpp> +#endif +#ifndef _COM_SUN_STAR_FRAME_XCOMPONENTLOADER_HPP_ +#include <com/sun/star/frame/XComponentLoader.hpp> +#endif + +#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XSingleServiceFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_ +#include <com/sun/star/lang/DisposedException.hpp> +#endif + +#ifndef _COM_SUN_STAR_UTIL_XMODIFIABLE_HPP_ +#include <com/sun/star/util/XModifiable.hpp> +#endif + +#ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCEESS_HPP_ +#include <com/sun/star/container/XNameAccess.hpp> +#endif + +#ifndef _COM_SUN_STAR_UTIL_XCLOSEABLE_HPP_ +#include <com/sun/star/util/XCloseable.hpp> +#endif + +#include "convert.hxx" + +using namespace ::com::sun::star; + + +//------------------------------------------------------ +uno::Sequence< beans::PropertyValue > addAsTemplate( const uno::Sequence< beans::PropertyValue >& aOrig ) +{ + sal_Bool bAsTemplateSet = sal_False; + sal_Int32 nLength = aOrig.getLength(); + uno::Sequence< beans::PropertyValue > aResult( nLength ); + + for ( sal_Int32 nInd = 0; nInd < nLength; nInd++ ) + { + aResult[nInd].Name = aOrig[nInd].Name; + if ( aResult[nInd].Name.equalsAscii( "AsTemplate" ) ) + { + aResult[nInd].Value <<= sal_True; + bAsTemplateSet = sal_True; + } + else + aResult[nInd].Value = aOrig[nInd].Value; + } + + if ( !bAsTemplateSet ) + { + aResult.realloc( nLength + 1 ); + aResult[nLength].Name = ::rtl::OUString::createFromAscii( "AsTemplate" ); + aResult[nLength].Value <<= sal_True; + } + + return aResult; +} + +//------------------------------------------------------ +uno::Reference< io::XInputStream > createTempInpStreamFromStor( + const uno::Reference< embed::XStorage >& xStorage, + const uno::Reference< lang::XMultiServiceFactory >& xFactory ) +{ + OSL_ENSURE( xStorage.is(), "The storage can not be empty!" ); + + uno::Reference< io::XInputStream > xResult; + + const ::rtl::OUString aServiceName ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.io.TempFile" ) ); + uno::Reference < io::XStream > xTempStream = uno::Reference < io::XStream > ( + xFactory->createInstance ( aServiceName ), + uno::UNO_QUERY ); + if ( xTempStream.is() ) + { + uno::Reference < lang::XSingleServiceFactory > xStorageFactory( + xFactory->createInstance ( ::rtl::OUString::createFromAscii( "com.sun.star.embed.StorageFactory" ) ), + uno::UNO_QUERY ); + + uno::Sequence< uno::Any > aArgs( 2 ); + aArgs[0] <<= xTempStream; + aArgs[1] <<= embed::ElementModes::ELEMENT_READWRITE; + uno::Reference< embed::XStorage > xTempStorage( xStorageFactory->createInstanceWithArguments( aArgs ), + uno::UNO_QUERY ); + if ( !xTempStorage.is() ) + throw uno::RuntimeException(); // TODO: + + try + { + xStorage->copyToStorage( xTempStorage ); + } catch( uno::Exception& e ) + { + throw embed::StorageWTException( + ::rtl::OUString::createFromAscii( "Can't copy storage!" ), + uno::Reference< uno::XInterface >(), + uno::makeAny( e ) ); + } + + try { + uno::Reference< lang::XComponent > xComponent( xTempStorage, uno::UNO_QUERY ); + OSL_ENSURE( xComponent.is(), "Wrong storage implementation!" ); + if ( xComponent.is() ) + xComponent->dispose(); + } + catch ( uno::Exception& ) + { + } + + try { + uno::Reference< io::XOutputStream > xTempOut = xTempStream->getOutputStream(); + if ( xTempOut.is() ) + xTempOut->closeOutput(); + } + catch ( uno::Exception& ) + { + } + + xResult = xTempStream->getInputStream(); + } + + return xResult; + +} + +//------------------------------------------------------ +uno::Reference< frame::XModel > OCommonEmbeddedObject::InitNewDocument_Impl() +{ + uno::Reference< frame::XModel > xDocument( m_xFactory->createInstance( GetDocumentServiceName() ), + uno::UNO_QUERY ); + + uno::Reference< frame::XLoadable > xLoadable( xDocument, uno::UNO_QUERY ); + if ( !xLoadable.is() ) + throw uno::RuntimeException(); + + try + { + xLoadable->initNew(); + } + catch( uno::Exception& ) + { + uno::Reference< util::XCloseable > xCloseable( xDocument, uno::UNO_QUERY ); + if ( xCloseable.is() ) + { + try + { + xCloseable->close( sal_True ); + } + catch( uno::Exception& ) + { + } + } + + throw; // TODO + } + + return xDocument; +} + +//------------------------------------------------------ +uno::Reference< frame::XModel > OCommonEmbeddedObject::LoadLink_Impl() +{ + uno::Reference< frame::XModel > xDocument( m_xFactory->createInstance( GetDocumentServiceName() ), + uno::UNO_QUERY ); + + uno::Reference< frame::XLoadable > xLoadable( xDocument, uno::UNO_QUERY ); + if ( !xLoadable.is() ) + throw uno::RuntimeException(); + + uno::Sequence< beans::PropertyValue > aArgs( 2 ); + aArgs[0].Name = ::rtl::OUString::createFromAscii( "URL" ); + aArgs[0].Value <<= m_aLinkURL; + aArgs[1].Name = ::rtl::OUString::createFromAscii( "FilterName" ); + aArgs[1].Value <<= m_aLinkFilterName; + + try + { + xLoadable->load( aArgs ); + } + catch( uno::Exception& ) + { + uno::Reference< util::XCloseable > xCloseable( xDocument, uno::UNO_QUERY ); + if ( xCloseable.is() ) + { + try + { + xCloseable->close( sal_True ); + } + catch( uno::Exception& ) + { + } + } + + throw; // TODO + } + + return xDocument; + +} + +//------------------------------------------------------ +uno::Reference< frame::XModel > OCommonEmbeddedObject::LoadDocumentFromStorage_Impl( + const uno::Reference< embed::XStorage >& xStorage ) +{ + OSL_ENSURE( xStorage.is(), "The storage can not be empty!" ); + + uno::Reference< frame::XModel > xDocument( m_xFactory->createInstance( GetDocumentServiceName() ), + uno::UNO_QUERY ); + + uno::Reference< frame::XLoadable > xLoadable( xDocument, uno::UNO_QUERY ); + if ( !xLoadable.is() ) + throw uno::RuntimeException(); + + uno::Reference< io::XInputStream > xTempInpStream = createTempInpStreamFromStor( xStorage, m_xFactory ); + if ( !xTempInpStream.is() ) + throw uno::RuntimeException(); + + ::rtl::OUString aFilterName = GetDefaultFilterFromServName( GetDocumentServiceName() ); + OSL_ENSURE( aFilterName.getLength(), "Wrong document service name!" ); + if ( !aFilterName.getLength() ) + throw uno::RuntimeException(); // this point should not be reachable + + uno::Sequence< beans::PropertyValue > aArgs( 5 ); + aArgs[0].Name = ::rtl::OUString::createFromAscii( "URL" ); + aArgs[0].Value <<= ::rtl::OUString::createFromAscii( "private:stream" ); + aArgs[1].Name = ::rtl::OUString::createFromAscii( "InputStream" ); + aArgs[1].Value <<= xTempInpStream; + aArgs[2].Name = ::rtl::OUString::createFromAscii( "ReadOnly" ); + aArgs[2].Value <<= m_bReadOnly; + aArgs[3].Name = ::rtl::OUString::createFromAscii( "FilterName" ); + aArgs[3].Value <<= aFilterName; + aArgs[4].Name = ::rtl::OUString::createFromAscii( "AsTemplate" ); + aArgs[4].Value <<= sal_True; + + try + { + xLoadable->load( aArgs ); + } + catch( uno::Exception& ) + { + uno::Reference< util::XCloseable > xCloseable( xDocument, uno::UNO_QUERY ); + if ( xCloseable.is() ) + { + try + { + xCloseable->close( sal_True ); + } + catch( uno::Exception& ) + { + } + } + + throw; // TODO + } + + return xDocument; +} + +//------------------------------------------------------ +uno::Reference< io::XInputStream > OCommonEmbeddedObject::StoreDocumentToTempStream_Impl() +{ + uno::Reference < io::XOutputStream > xTempOut( + m_xFactory->createInstance ( ::rtl::OUString::createFromAscii( "com.sun.star.io.TempFile" ) ), + uno::UNO_QUERY ); + uno::Reference< io::XInputStream > aResult( xTempOut, uno::UNO_QUERY ); + + if ( !xTempOut.is() || !aResult.is() ) + throw uno::RuntimeException(); // TODO: + + uno::Reference< frame::XStorable > xStorable( m_pDocHolder->GetDocument(), uno::UNO_QUERY ); + if( !xStorable.is() ) + throw uno::RuntimeException(); // TODO: + + ::rtl::OUString aFilterName = GetDefaultFilterFromServName( GetDocumentServiceName() ); + OSL_ENSURE( aFilterName.getLength(), "Wrong document service name!" ); + + uno::Sequence< beans::PropertyValue > aArgs( 2 ); + aArgs[0].Name = ::rtl::OUString::createFromAscii( "FilterName" ); + aArgs[0].Value <<= aFilterName; + aArgs[1].Name = ::rtl::OUString::createFromAscii( "OutputStream" ); + aArgs[1].Value <<= xTempOut; + + xStorable->storeToURL( ::rtl::OUString::createFromAscii( "private:stream" ), aArgs ); + try + { + xTempOut->closeOutput(); + } + catch( uno::Exception& ) + { + OSL_ENSURE( sal_False, "Looks like stream was closed already" ); + } + + return aResult; +} + +//------------------------------------------------------ +void OCommonEmbeddedObject::SaveObject_Impl() +{ + if ( m_xClientSite.is() ) + { + try { + m_xClientSite->saveObject(); + } + catch( uno::Exception& ) + { + OSL_ENSURE( sal_False, "The object was not stored!\n" ); + } + } +} + +//------------------------------------------------------ +void OCommonEmbeddedObject::StoreDocToStorage_Impl( const uno::Reference< embed::XStorage >& xStorage ) +{ + OSL_ENSURE( xStorage.is(), "No storage is provided for storing!" ); + + if ( !xStorage.is() ) + throw uno::RuntimeException(); // TODO: + + // store document to temporary stream based on temporary file + uno::Reference < io::XInputStream > xTempIn = StoreDocumentToTempStream_Impl(); + OSL_ENSURE( xTempIn.is(), "The stream reference can not be empty!\n" ); + + // open storage based on document temporary file for reading + uno::Reference < lang::XSingleServiceFactory > xStorageFactory( + m_xFactory->createInstance ( ::rtl::OUString::createFromAscii( "com.sun.star.embed.StorageFactory" ) ), + uno::UNO_QUERY ); + + uno::Sequence< uno::Any > aArgs(1); + aArgs[0] <<= xTempIn; + uno::Reference< embed::XStorage > xTempStorage( xStorageFactory->createInstanceWithArguments( aArgs ), + uno::UNO_QUERY ); + if ( !xTempStorage.is() ) + throw uno::RuntimeException(); // TODO: + + // object storage must be commited automatically + xTempStorage->copyToStorage( xStorage ); +} + +//------------------------------------------------------ +uno::Reference< frame::XModel > OCommonEmbeddedObject::CreateDocFromMediaDescr_Impl( + const uno::Sequence< beans::PropertyValue >& aMedDescr ) +{ + uno::Reference< frame::XModel > xDocument( m_xFactory->createInstance( GetDocumentServiceName() ), + uno::UNO_QUERY ); + + uno::Reference< frame::XLoadable > xLoadable( xDocument, uno::UNO_QUERY ); + if ( !xLoadable.is() ) + throw uno::RuntimeException(); + + try + { + xLoadable->load( addAsTemplate( aMedDescr ) ); + } + catch( uno::Exception& ) + { + uno::Reference< util::XCloseable > xCloseable( xDocument, uno::UNO_QUERY ); + if ( xCloseable.is() ) + { + try + { + xCloseable->close( sal_True ); + } + catch( uno::Exception& ) + { + } + } + + throw; // TODO + } + + return xDocument; +} + +//------------------------------------------------------ +uno::Reference< frame::XModel > OCommonEmbeddedObject::CreateTempDocFromLink_Impl() +{ + uno::Reference< frame::XModel > xResult; + + OSL_ENSURE( m_bIsLink, "The object is not a linked one!\n" ); + + uno::Sequence< beans::PropertyValue > aTempMediaDescr; + + if ( m_pDocHolder->GetDocument().is() ) + { + aTempMediaDescr.realloc( 4 ); + aTempMediaDescr[0].Name = ::rtl::OUString::createFromAscii( "URL" ); + aTempMediaDescr[0].Value <<= ::rtl::OUString::createFromAscii( "private:stream" ); + aTempMediaDescr[1].Name = ::rtl::OUString::createFromAscii( "InputStream" ); + aTempMediaDescr[1].Value <<= StoreDocumentToTempStream_Impl(); + aTempMediaDescr[2].Name = ::rtl::OUString::createFromAscii( "FilterName" ); + aTempMediaDescr[2].Value <<= GetDefaultFilterFromServName( GetDocumentServiceName() ); + aTempMediaDescr[3].Name = ::rtl::OUString::createFromAscii( "AsTemplate" ); + aTempMediaDescr[3].Value <<= sal_True; + } + else + { + aTempMediaDescr.realloc( 3 ); + aTempMediaDescr[0].Name = ::rtl::OUString::createFromAscii( "URL" ); + aTempMediaDescr[0].Value <<= m_aLinkURL; + aTempMediaDescr[1].Name = ::rtl::OUString::createFromAscii( "FilterName" ); + aTempMediaDescr[1].Value <<= m_aLinkFilterName; + aTempMediaDescr[2].Name = ::rtl::OUString::createFromAscii( "AsTemplate" ); + aTempMediaDescr[2].Value <<= sal_True; + } + + xResult = CreateDocFromMediaDescr_Impl( aTempMediaDescr ); + + return xResult; +} + +//------------------------------------------------------ +void SAL_CALL OCommonEmbeddedObject::setPersistentEntry( + const uno::Reference< embed::XStorage >& xStorage, + const ::rtl::OUString& sEntName, + sal_Int32 nEntryConnectionMode, + const uno::Sequence< beans::PropertyValue >& lArguments ) + throw ( lang::IllegalArgumentException, + embed::WrongStateException, + io::IOException, + uno::Exception, + uno::RuntimeException ) +{ + // the type of the object must be already set + // a kind of typedetection should be done in the factory + + ::osl::MutexGuard aGuard( m_aMutex ); + if ( m_bDisposed ) + throw lang::DisposedException(); // TODO + + if ( !xStorage.is() ) + throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "No parent storage is provided!\n" ), + uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ), + 1 ); + + if ( !sEntName.getLength() ) + throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Empty element name is provided!\n" ), + uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ), + 2 ); + + // May be EMBED_LOADED should be forbidden here ??? + if ( ( m_nObjectState != -1 || nEntryConnectionMode == embed::EntryInitModes::ENTRY_NO_INIT ) + && ( m_nObjectState == -1 || nEntryConnectionMode != embed::EntryInitModes::ENTRY_NO_INIT ) ) + { + // if the object is not loaded + // it can not get persistant representation without initialization + + // if the object is loaded + // it can switch persistant representation only without initialization + + throw embed::WrongStateException( + ::rtl::OUString::createFromAscii( "Can't change persistant representation of activated object!\n" ), + uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) ); + } + + if ( m_bWaitSaveCompleted ) + throw embed::WrongStateException( + ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ), + uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) ); + + uno::Reference< container::XNameAccess > xNameAccess( xStorage, uno::UNO_QUERY ); + if ( !xNameAccess.is() ) + throw uno::RuntimeException(); //TODO + + // detect entry existence + sal_Bool bElExists = xNameAccess->hasByName( sEntName ); + + m_bReadOnly = sal_False; + for ( sal_Int32 nInd = 0; nInd < lArguments.getLength(); nInd++ ) + if ( lArguments[nInd].Name.equalsAscii( "ReadOnly" ) ) + lArguments[nInd].Value >>= m_bReadOnly; + + sal_Int32 nStorageMode = m_bReadOnly ? embed::ElementModes::ELEMENT_READ : embed::ElementModes::ELEMENT_READWRITE; + + m_xObjectStorage = xStorage->openStorageElement( sEntName, nStorageMode ); + m_xParentStorage = xStorage; + m_aEntryName = sEntName; + + // the object should be based on the storage ??? TODO + if ( bElExists && !xStorage->isStorageElement( sEntName ) ) + throw io::IOException(); // TODO access denied + + if ( nEntryConnectionMode == embed::EntryInitModes::ENTRY_DEFAULT_INIT ) + { + if ( bElExists ) + { + // the initialization from existing storage allows to leave object in loaded state + m_nObjectState = embed::EmbedStates::EMBED_LOADED; + } + else + { + m_pDocHolder->SetDocument( InitNewDocument_Impl(), m_bReadOnly ); + if ( !m_pDocHolder->GetDocument().is() ) + throw io::IOException(); // TODO: can not create document + + m_nObjectState = embed::EmbedStates::EMBED_RUNNING; + } + } + else + { + if ( ( nStorageMode & embed::ElementModes::ELEMENT_READWRITE ) != embed::ElementModes::ELEMENT_READWRITE ) + throw io::IOException(); + + if ( nEntryConnectionMode == embed::EntryInitModes::ENTRY_NO_INIT ) + { + // the document just already changed its storage to store to + if ( m_bIsLink ) + { + // for linked object it means that it becomes embedded object + // the document must switch it's persistence also + + // the document is a new embedded object so it must be marked as modified + uno::Reference< frame::XModel > xDocument = CreateTempDocFromLink_Impl(); + uno::Reference< util::XModifiable > xModif( m_pDocHolder->GetDocument(), uno::UNO_QUERY ); + if ( !xModif.is() ) + throw uno::RuntimeException(); + try + { + xModif->setModified( sal_True ); + } + catch( uno::Exception& ) + {} + + m_pDocHolder->SetDocument( xDocument, m_bReadOnly ); + OSL_ENSURE( m_pDocHolder->GetDocument().is(), "If document cant be created, an exception must be thrown!\n" ); + + if ( m_nObjectState == embed::EmbedStates::EMBED_LOADED ) + m_nObjectState = embed::EmbedStates::EMBED_RUNNING; + else if ( m_nObjectState == embed::EmbedStates::EMBED_ACTIVE ) + m_pDocHolder->Show(); + + m_bIsLink = sal_False; + m_aLinkFilterName = ::rtl::OUString(); + m_aLinkURL = ::rtl::OUString(); + + } + } + else if ( nEntryConnectionMode == embed::EntryInitModes::ENTRY_TRUNCATE_INIT ) + { + // TODO: + m_pDocHolder->SetDocument( InitNewDocument_Impl(), m_bReadOnly ); + + if ( !m_pDocHolder->GetDocument().is() ) + throw io::IOException(); // TODO: can not create document + + m_nObjectState = embed::EmbedStates::EMBED_RUNNING; + } + else if ( nEntryConnectionMode == embed::EntryInitModes::ENTRY_MEDIA_DESCRIPTOR_INIT ) + { + m_pDocHolder->SetDocument( CreateDocFromMediaDescr_Impl( lArguments ), m_bReadOnly ); + m_nObjectState = embed::EmbedStates::EMBED_RUNNING; + } + //else if ( nEntryConnectionMode == embed::EntryInitModes::ENTRY_TRANSFERABLE_INIT ) + //{ + //TODO: + //} + else + throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Wrong connection mode is provided!\n" ), + uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ), + 3 ); + } +} + +//------------------------------------------------------ +void SAL_CALL OCommonEmbeddedObject::storeOwn() + throw ( embed::WrongStateException, + io::IOException, + uno::Exception, + uno::RuntimeException ) +{ + // during switching from Activated to Running and from Running to Loaded states the object will + // ask container to store the object, the container has to make decision + // to do so or not + + ::osl::MutexGuard aGuard( m_aMutex ); + if ( m_bDisposed ) + throw lang::DisposedException(); // TODO + + if ( m_nObjectState == -1 ) + { + // the object is still not loaded + throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Can't store object without persistence!\n" ), + uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) ); + } + + if ( m_bWaitSaveCompleted ) + throw embed::WrongStateException( + ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ), + uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) ); + + if ( m_bReadOnly ) + throw io::IOException(); // TODO: access denied + + if ( m_nObjectState == embed::EmbedStates::EMBED_LOADED ) + return; // nothing to do, the object is in loaded state + + OSL_ENSURE( m_pDocHolder->GetDocument().is(), "If an object is activated or in running state it must have a document!\n" ); + if ( !m_pDocHolder->GetDocument().is() ) + throw uno::RuntimeException(); + + if ( m_bIsLink ) + { + // TODO: just store the document to it's location + uno::Reference< frame::XStorable > xStorable( m_pDocHolder->GetDocument(), uno::UNO_QUERY ); + if ( !xStorable.is() ) + throw uno::RuntimeException(); // TODO + + xStorable->store(); + } + else + { + OSL_ENSURE( m_xParentStorage.is() && m_xObjectStorage.is(), "The object has no valid persistence!\n" ); + + if ( !m_xObjectStorage.is() ) + throw io::IOException(); //TODO: access denied + + StoreDocToStorage_Impl( m_xObjectStorage ); + } + + // TODO: + // notify listeners + if ( m_nUpdateMode == embed::EmbedUpdateModes::EMBED_ALWAYS_UPDATE ) + { + // TODO: update visual representation + } +} + +//------------------------------------------------------ +void SAL_CALL OCommonEmbeddedObject::storeToEntry( const uno::Reference< embed::XStorage >& xStorage, + const ::rtl::OUString& sEntName, + const uno::Sequence< beans::PropertyValue >& lArguments ) + throw ( lang::IllegalArgumentException, + embed::WrongStateException, + io::IOException, + uno::Exception, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if ( m_bDisposed ) + throw lang::DisposedException(); // TODO + + if ( m_nObjectState == -1 ) + { + // the object is still not loaded + throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Can't store object without persistence!\n" ), + uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) ); + } + + if ( m_bWaitSaveCompleted ) + throw embed::WrongStateException( + ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ), + uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) ); + + OSL_ENSURE( m_bIsLink || m_xParentStorage.is() && m_xObjectStorage.is(), "The object has no valid persistence!\n" ); + + uno::Reference< embed::XStorage > xSubStorage = + xStorage->openStorageElement( sEntName, embed::ElementModes::ELEMENT_READWRITE ); + + if ( !xSubStorage.is() ) + throw uno::RuntimeException(); //TODO + + StoreDocToStorage_Impl( xSubStorage ); + + // TODO: should the listener notification be done? +} + +//------------------------------------------------------ +void SAL_CALL OCommonEmbeddedObject::storeAsEntry( const uno::Reference< embed::XStorage >& xStorage, + const ::rtl::OUString& sEntName, + const uno::Sequence< beans::PropertyValue >& lArguments ) + throw ( lang::IllegalArgumentException, + embed::WrongStateException, + io::IOException, + uno::Exception, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if ( m_bDisposed ) + throw lang::DisposedException(); // TODO + + if ( m_nObjectState == -1 ) + { + // the object is still not loaded + throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Can't store object without persistence!\n" ), + uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) ); + } + + if ( m_bWaitSaveCompleted ) + throw embed::WrongStateException( + ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ), + uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) ); + + OSL_ENSURE( m_bIsLink || m_xParentStorage.is() && m_xObjectStorage.is(), "The object has no valid persistence!\n" ); + + uno::Reference< embed::XStorage > xSubStorage = + xStorage->openStorageElement( sEntName, embed::ElementModes::ELEMENT_READWRITE ); + + if ( !xSubStorage.is() ) + throw uno::RuntimeException(); //TODO + + StoreDocToStorage_Impl( xSubStorage ); + + m_bWaitSaveCompleted = sal_True; + m_xNewObjectStorage = xSubStorage; + m_xNewParentStorage = xStorage; + m_aEntryName = sEntName; + + // TODO: register listeners for storages above, in case thay are disposed + // an exception will be thrown on saveCompleted( true ) + + // TODO: should the listener notification be done here or in saveCompleted? +} + +//------------------------------------------------------ +void SAL_CALL OCommonEmbeddedObject::saveCompleted( sal_Bool bUseNew ) + throw ( embed::WrongStateException, + uno::Exception, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if ( m_bDisposed ) + throw lang::DisposedException(); // TODO + + if ( m_nObjectState == -1 ) + { + // the object is still not loaded + throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Can't store object without persistence!\n" ), + uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) ); + } + + OSL_ENSURE( m_bWaitSaveCompleted, "Unexpected saveCompleted() call!\n" ); + if ( !m_bWaitSaveCompleted ) + throw io::IOException(); // TODO: illegal call + + OSL_ENSURE( m_xNewObjectStorage.is() && m_xNewParentStorage.is() , "Internal object information is broken!\n" ); + if ( !m_xNewObjectStorage.is() || !m_xNewParentStorage.is() ) + throw uno::RuntimeException(); // TODO: broken internal information + + if ( bUseNew ) + { + // the link object is not linked any more + m_bIsLink = sal_False; + m_aLinkURL = ::rtl::OUString(); + + try { + uno::Reference< lang::XComponent > xComponent( m_xObjectStorage, uno::UNO_QUERY ); + OSL_ENSURE( xComponent.is(), "Wrong storage implementation!" ); + if ( xComponent.is() ) + xComponent->dispose(); + } + catch ( uno::Exception& ) + { + } + + m_xObjectStorage = m_xNewObjectStorage; + m_xParentStorage = m_xNewParentStorage; + m_aEntryName = m_aNewEntryName; + } + + m_xNewObjectStorage = uno::Reference< embed::XStorage >(); + m_xNewParentStorage = uno::Reference< embed::XStorage >(); + m_aNewEntryName = ::rtl::OUString(); + m_bWaitSaveCompleted = sal_False; + + if ( bUseNew ) + { + // TODO: notify listeners + + if ( m_nUpdateMode == embed::EmbedUpdateModes::EMBED_ALWAYS_UPDATE ) + { + // TODO: update visual representation + } + } +} + +//------------------------------------------------------ +sal_Bool SAL_CALL OCommonEmbeddedObject::hasEntry() + throw ( embed::WrongStateException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if ( m_bDisposed ) + throw lang::DisposedException(); // TODO + + if ( m_bWaitSaveCompleted ) + throw embed::WrongStateException( + ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ), + uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) ); + + if ( m_xObjectStorage.is() ) + return sal_True; + + return sal_False; +} + +//------------------------------------------------------ +::rtl::OUString SAL_CALL OCommonEmbeddedObject::getEntryName() + throw ( embed::WrongStateException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if ( m_bDisposed ) + throw lang::DisposedException(); // TODO + + if ( m_nObjectState == -1 ) + { + // the object is still not loaded + throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object persistence is not initialized!\n" ), + uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) ); + } + + if ( m_bWaitSaveCompleted ) + throw embed::WrongStateException( + ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ), + uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) ); + + return m_aEntryName; +} + +//------------------------------------------------------ +sal_Bool SAL_CALL OCommonEmbeddedObject::isReadonly() + throw ( embed::WrongStateException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if ( m_bDisposed ) + throw lang::DisposedException(); // TODO + + if ( m_nObjectState == -1 ) + { + // the object is still not loaded + throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object persistence is not initialized!\n" ), + uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) ); + } + + if ( m_bWaitSaveCompleted ) + throw embed::WrongStateException( + ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ), + uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) ); + + return m_bReadOnly; +} + +//------------------------------------------------------ +void SAL_CALL OCommonEmbeddedObject::reload( + const uno::Sequence< beans::PropertyValue >& lArguments ) + throw ( lang::IllegalArgumentException, + embed::WrongStateException, + io::IOException, + uno::Exception, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if ( m_bDisposed ) + throw lang::DisposedException(); // TODO + + if ( m_nObjectState == -1 ) + { + // the object is still not loaded + throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object persistence is not initialized!\n" ), + uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) ); + } + + if ( m_bWaitSaveCompleted ) + throw embed::WrongStateException( + ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ), + uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) ); + + // TODO: + // throw away current document + // load new document from current storage + // use meaningfull part of lArguments +} + +//------------------------------------------------------ +sal_Bool SAL_CALL OCommonEmbeddedObject::isLink() + throw ( embed::WrongStateException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if ( m_bDisposed ) + throw lang::DisposedException(); // TODO + + if ( m_bWaitSaveCompleted ) + throw embed::WrongStateException( + ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ), + uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) ); + + return m_bIsLink; +} + +//------------------------------------------------------ +::rtl::OUString SAL_CALL OCommonEmbeddedObject::getLinkURL() + throw ( ::com::sun::star::embed::WrongStateException, + ::com::sun::star::uno::Exception, + ::com::sun::star::uno::RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if ( m_bDisposed ) + throw lang::DisposedException(); // TODO + + if ( m_bWaitSaveCompleted ) + throw embed::WrongStateException( + ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ), + uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) ); + + if ( !m_bIsLink ) + throw embed::WrongStateException( + ::rtl::OUString::createFromAscii( "The object is not a link object!\n" ), + uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) ); + + return m_aLinkURL; +} + diff --git a/embeddedobj/source/commonembedding/visobj.cxx b/embeddedobj/source/commonembedding/visobj.cxx new file mode 100644 index 000000000000..fd291e476928 --- /dev/null +++ b/embeddedobj/source/commonembedding/visobj.cxx @@ -0,0 +1,183 @@ +/************************************************************************* + * + * $RCSfile: visobj.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: mav $ $Date: 2003-10-27 12:57:29 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COM_SUN_STAR_EMBED_ASPECTS_HPP_ +#include <com/sun/star/embed/Aspects.hpp> +#endif +#ifndef _COM_SUN_STAR_EMBED_EMBEDSTATES_HPP_ +#include <com/sun/star/embed/EmbedStates.hpp> +#endif + +#ifndef _COM_SUN_STAR_DATATRANSFER_XTRANSFERABLE_HPP_ +#include <com/sun/star/datatransfer/XTransferable.hpp> +#endif + +#ifndef _COM_SUN_STAR_UNO_SEQUENCE_HXX_ +#include <com/sun/star/uno/Sequence.hxx> +#endif + +#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_ +#include <com/sun/star/lang/DisposedException.hpp> +#endif + + +#include <commonembobj.hxx> + + +using namespace ::com::sun::star; + +void SAL_CALL OCommonEmbeddedObject::setContainerName( const ::rtl::OUString& sName ) + throw ( uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if ( m_bDisposed ) + throw lang::DisposedException(); // TODO + + m_aContainerName = sName; +} + +void SAL_CALL OCommonEmbeddedObject::setVisAreaSize( sal_Int64 nAspect, const awt::Size& aSize ) + throw ( lang::IllegalArgumentException, + embed::WrongStateException, + uno::Exception, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if ( m_bDisposed ) + throw lang::DisposedException(); // TODO + + if ( m_nObjectState == -1 || m_nObjectState == embed::EmbedStates::EMBED_LOADED ) + throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The own object has no model!\n" ), + uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) ); + + if ( nAspect == embed::Aspects::MSASPECT_CONTENT ) + { + if ( !m_pDocHolder->SetExtent( aSize ) ) + throw uno::Exception(); // TODO: + } + else + { + // TODO: do something for other aspects + } +} + +awt::Size SAL_CALL OCommonEmbeddedObject::getVisAreaSize( sal_Int64 nAspect ) + throw ( lang::IllegalArgumentException, + embed::WrongStateException, + uno::Exception, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if ( m_bDisposed ) + throw lang::DisposedException(); // TODO + + if ( m_nObjectState == -1 || m_nObjectState == embed::EmbedStates::EMBED_LOADED ) + throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The own object has no model!\n" ), + uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) ); + + if ( nAspect == embed::Aspects::MSASPECT_CONTENT ) + { + awt::Size aResult; + if ( !m_pDocHolder->GetExtent( &aResult ) ) + throw uno::Exception(); // TODO: + return aResult; + } + else + { + // TODO: do something for other aspects + } +} + +// Probably will be removed!!! +uno::Any SAL_CALL OCommonEmbeddedObject::getVisualCache( sal_Int64 nAspect ) + throw ( uno::Exception, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if ( m_bDisposed ) + throw lang::DisposedException(); // TODO + + if ( m_nObjectState == -1 || m_nObjectState == embed::EmbedStates::EMBED_LOADED ) + throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The own object has no model!\n" ), + uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) ); +#if 0 + OSL_ENSURE( m_xDocument.is(), "Running or Active object has no model!\n" ); + + if ( m_xDocument.is() ) + { + // TODO: return for the aspect of the document + uno::Reference< datatransfer::XTransferable > xTransferable( m_xDocument, uno::UNO_QUERY ); + if ( xTransferable.is() ) + { + datatransfer::DataFlavor aDataFlavor( + ::rtl::OUString::createFromAscii( "application/x-openoffice;windows_formatname=\"Image EMF\"" ), + ::rtl::OUString::createFromAscii( "Image EMF" ), + ::getCppuType( (const uno::Sequence< sal_Int8 >*) NULL ) ); + + return xTransferable->getTransferData( aDataFlavor ); + } + } +#endif + + return uno::makeAny( uno::Sequence< sal_Int8 >() ); +} + + diff --git a/embeddedobj/source/general/docholder.cxx b/embeddedobj/source/general/docholder.cxx new file mode 100644 index 000000000000..22a990065bdc --- /dev/null +++ b/embeddedobj/source/general/docholder.cxx @@ -0,0 +1,583 @@ +/************************************************************************* + * + * $RCSfile: docholder.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: mav $ $Date: 2003-10-27 12:58:19 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 ( 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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor( s ): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COM_SUN_STAR_FRAME_XCOMPONENTLOADER_HPP_ +#include <com/sun/star/frame/XComponentLoader.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_UTIL_XCLOSEBROADCASTER_HPP_ +#include <com/sun/star/util/XCloseBroadcaster.hpp> +#endif +#ifndef _COM_SUN_STAR_UTIL_XCLOSEABLE_HPP_ +#include <com/sun/star/util/XCloseAble.hpp> +#endif +#ifndef _COM_SUN_STAR_CONTAINER_XNAMEACESS_HPP_ +#include <com/sun/star/container/XNameAccess.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_ +#include <com/sun/star/beans/XPropertySet.hpp> +#endif +#ifndef _COM_SUN_STAR_FRAME_XMODEL_HPP_ +#include <com/sun/star/frame/XModel.hpp> +#endif +#ifndef _COM_SUN_STAR_FRAME_XDESKTOP_HPP_ +#include <com/sun/star/frame/XDesktop.hpp> +#endif +#ifndef _COM_SUN_STAR_FRAME_XFRAMESSUPPLIER_HPP_ +#include <com/sun/star/frame/XFramesSupplier.hpp> +#endif +#ifndef _COM_SUN_STAR_FRAME_FRAMESEARCHFLAG_HPP_ +#include <com/sun/star/frame/FrameSearchFlag.hpp> +#endif +#ifndef _COM_SUN_STAR_UTIL_XMODIFYBROADCASTER_HPP_ +#include <com/sun/star/util/XModifyBroadcaster.hpp> +#endif +#ifndef _COM_SUN_STAR_FRAME_XDISPATCHPROVIDERINTERCEPTION_HPP_ +#include <com/sun/star/frame/XDispatchProviderInterception.hpp> +#endif +#ifndef _COM_SUN_STAR_AWT_XTOPWINDOW_HPP_ +#include <com/sun/star/awt/XTopWindow.hpp> +#endif +#ifndef _COM_SUN_STAR_AWT_POSSIZE_HPP_ +#include <com/sun/star/awt/PosSize.hpp> +#endif +#ifndef _COM_SUN_STAR_AWT_XVIEW_HPP_ +#include <com/sun/star/awt/XView.hpp> +#endif +#ifndef _COM_SUN_STAR_BRIDGE_XBRIDGESUPPLIER2_HPP_ +#include <com/sun/star/bridge/XBridgeSupplier2.hpp> +#endif +#ifndef _COM_SUN_STAR_BRIDGE_MODELDEPENDENT_HPP_ +#include <com/sun/star/bridge/ModelDependent.hpp> +#endif + +#ifndef _OSL_DIAGNOSE_H_ +#include <osl/diagnose.h> +#endif +#ifndef _RTL_PROCESS_H_ +#include <rtl/process.h> +#endif + +#include "docholder.hxx" +#include "commonembobj.hxx" +#include "intercept.hxx" + + +using namespace ::com::sun::star; + + +DocumentHolder::DocumentHolder( const uno::Reference< lang::XMultiServiceFactory >& xFactory, + OCommonEmbeddedObject* pEmbObj ) +: m_xFactory( xFactory ), + m_pEmbedObj( pEmbObj ), + m_pInterceptor( NULL ), + m_bReadOnly( sal_False ) +{ + const ::rtl::OUString aServiceName ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.frame.Desktop" ) ); + uno::Reference< frame::XDesktop > xDesktop( m_xFactory->createInstance( aServiceName ), uno::UNO_QUERY ); + if ( xDesktop.is() ) + xDesktop->addTerminateListener( ( frame::XTerminateListener* )this ); +} + +DocumentHolder::~DocumentHolder() +{ + if( m_xFrame.is() ) + CloseFrame(); + + if ( m_xDocument.is() ) + CloseDocument(); + + if ( m_xFactory.is() ) + FreeOffice(); + + if ( m_pInterceptor ) + { + m_pInterceptor->DisconnectDocHolder(); + m_pInterceptor->release(); + } +} + +void DocumentHolder::CloseFrame() +{ + uno::Reference< util::XCloseBroadcaster > xCloseBroadcaster( m_xFrame, uno::UNO_QUERY ); + if ( xCloseBroadcaster.is() ) + xCloseBroadcaster->removeCloseListener( ( util::XCloseListener* )this ); + + uno::Reference<util::XCloseable> xCloseable( + m_xFrame,uno::UNO_QUERY ); + if( xCloseable.is() ) + try { + xCloseable->close( sal_True ); + } + catch( const uno::Exception& ) { + } + else { + uno::Reference<lang::XComponent> xComp( m_xFrame,uno::UNO_QUERY ); + if( xComp.is() ) + xComp->dispose(); + } + + m_xFrame = uno::Reference< frame::XFrame >(); +} + +void DocumentHolder::FreeOffice() +{ + const ::rtl::OUString aServiceName ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.frame.Desktop" ) ); + uno::Reference< frame::XDesktop > xDesktop( m_xFactory->createInstance( aServiceName ), uno::UNO_QUERY ); + if ( xDesktop.is() ) + { + xDesktop->removeTerminateListener( ( frame::XTerminateListener* )this ); + + uno::Reference< frame::XFramesSupplier > xFramesSupplier( xDesktop, uno::UNO_QUERY ); + if ( xFramesSupplier.is() ) + { + uno::Reference< frame::XFrames > xFrames = xFramesSupplier->getFrames(); + if ( xFrames.is() && !xFrames->hasElements() ) + { + try + { + xDesktop->terminate(); + } + catch( uno::Exception & ) + {} + } + } + + m_xFactory = uno::Reference< lang::XMultiServiceFactory >(); + } +} + +void DocumentHolder::CloseDocument() +{ + uno::Reference< util::XCloseBroadcaster > xBroadcaster( m_xDocument, uno::UNO_QUERY ); + if ( xBroadcaster.is() ) + { + xBroadcaster->removeCloseListener( ( util::XCloseListener* )this ); + + uno::Reference< document::XEventBroadcaster > xEventBroadcaster( m_xDocument, uno::UNO_QUERY ); + if ( xEventBroadcaster.is() ) + xEventBroadcaster->removeEventListener( ( document::XEventListener* )this ); + + uno::Reference< util::XCloseable > xCloseable( xBroadcaster, uno::UNO_QUERY ); + if ( xCloseable.is() ) + { + try + { + xCloseable->close( sal_True ); + } + catch( uno::Exception& ) + {} + } + } + + m_xDocument = uno::Reference< frame::XModel >(); +} + +uno::Reference< frame::XFrame > DocumentHolder::GetDocFrame() +{ + if ( !m_xFrame.is() ) + { + uno::Reference< frame::XFrame > xDesktopFrame( + m_xFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.frame.Desktop" ) ), + uno::UNO_QUERY ); + + if( !xDesktopFrame.is() ) + throw uno::RuntimeException(); + + m_xFrame = xDesktopFrame->findFrame( rtl::OUString::createFromAscii( "_blank" ), 0 ); + + uno::Reference< frame::XDispatchProviderInterception > xInterception( m_xFrame, uno::UNO_QUERY ); + if ( xInterception.is() ) + { + if ( m_pInterceptor ) + { + m_pInterceptor->DisconnectDocHolder(); + m_pInterceptor->release(); + m_pInterceptor = NULL; + } + + m_pInterceptor = new Interceptor( this ); + m_pInterceptor->acquire(); + + xInterception->registerDispatchProviderInterceptor( m_pInterceptor ); + } + + uno::Reference< util::XCloseBroadcaster > xCloseBroadcaster( m_xFrame, uno::UNO_QUERY ); + if ( xCloseBroadcaster.is() ) + xCloseBroadcaster->addCloseListener( ( util::XCloseListener* )this ); + } + + if ( m_xDocument.is() ) + LoadDocToFrame(); + + return m_xFrame; +} + +void DocumentHolder::SetDocument( const uno::Reference< frame::XModel >& xDoc, sal_Bool bReadOnly ) +{ + if ( m_xDocument.is() ) + CloseDocument(); + + m_xDocument = xDoc; + m_bReadOnly = bReadOnly; + + uno::Reference< util::XCloseBroadcaster > xBroadcaster( m_xDocument, uno::UNO_QUERY ); + if ( xBroadcaster.is() ) + xBroadcaster->addCloseListener( ( util::XCloseListener* )this ); + + uno::Reference< document::XEventBroadcaster > xEventBroadcaster( m_xDocument, uno::UNO_QUERY ); + if ( xEventBroadcaster.is() ) + xEventBroadcaster->addEventListener( ( document::XEventListener* )this ); + + if ( m_xDocument.is() ) + { + // set the document mode to embedded + uno::Sequence< beans::PropertyValue > aSeq( 1 ); + aSeq[0].Name = ::rtl::OUString::createFromAscii( "SetEmbedded" ); + aSeq[0].Value <<= sal_True; + m_xDocument->attachResource( ::rtl::OUString(), aSeq ); + } + + if ( m_xFrame.is() ) + LoadDocToFrame(); +} + +void DocumentHolder::LoadDocToFrame() +{ + if ( m_xFrame.is() && m_xDocument.is() ) + { + // load new document in to the frame + uno::Reference< frame::XComponentLoader > xComponentLoader( m_xFrame, uno::UNO_QUERY ); + if( !xComponentLoader.is() ) + throw uno::RuntimeException(); + + uno::Sequence< beans::PropertyValue > aArgs( 2 ); + aArgs[0].Name = ::rtl::OUString::createFromAscii( "Model" ); + aArgs[0].Value <<= m_xDocument; + aArgs[1].Name = ::rtl::OUString::createFromAscii( "ReadOnly" ); + aArgs[1].Value <<= m_bReadOnly; + + xComponentLoader->loadComponentFromURL( rtl::OUString::createFromAscii( "private:object" ), + rtl::OUString::createFromAscii( "_self" ), + 0, + aArgs ); + + SetTitle( m_aDocumentNamePart ); + } +} + +void DocumentHolder::Show() +{ + if( m_xFrame.is() ) + { + m_xFrame->activate(); + uno::Reference<awt::XTopWindow> xTopWindow( m_xFrame->getContainerWindow(),uno::UNO_QUERY ); + if( xTopWindow.is() ) + xTopWindow->toFront(); + } + else + GetDocFrame(); +} + +void DocumentHolder::SetTitle( const rtl::OUString& aDocumentName ) +{ + // TODO: to have a different title for links + if( m_xFrame.is() ) + { + rtl::OUString aFilterName; + uno::Sequence<beans::PropertyValue> aSeq; + if( m_xDocument.is() ) + { + aSeq = m_xDocument->getArgs(); + for( sal_Int32 j = 0; j < aSeq.getLength(); ++j ) + { + if( aSeq[j].Name == rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterName" ) ) ) + { + aSeq[j].Value >>= aFilterName; + break; + } + } + } + + if( aFilterName.getLength() ) + { + uno::Reference<container::XNameAccess> xNameAccess( + m_xFactory->createInstance( + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.FilterFactory" ) ) ), + uno::UNO_QUERY ); + try { + if( xNameAccess.is() && ( xNameAccess->getByName( aFilterName ) >>= aSeq ) ) + { + for( sal_Int32 j = 0; j < aSeq.getLength(); ++j ) + if( aSeq[j].Name == rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UIName" ) ) ) + { + aSeq[j].Value >>= aFilterName; + break; + } + } + } + catch( const uno::Exception& ) + { + } + } + + // set the title + uno::Reference<beans::XPropertySet> xPropSet( m_xFrame,uno::UNO_QUERY ); + if( xPropSet.is() ) + { + uno::Any aAny; + static const sal_Unicode u[] = { ' ','( ',0 }; + static const sal_Unicode c[] = { ' )',0 }; + rtl::OUString aTotalName( aFilterName ); + aTotalName += rtl::OUString( u ); + aTotalName += aDocumentName; + aTotalName += rtl::OUString( c ); + aAny <<= aTotalName; + + try + { + xPropSet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) ), + aAny ); + } + catch( const uno::Exception& ) + { + } + } + } + + m_aDocumentNamePart = aDocumentName; + + if( m_pInterceptor ) + m_pInterceptor->GenerateFeatureStateEvent(); +} + +void DocumentHolder::SetContainerName( const rtl::OUString& aContainerName ) +{ + m_aContainerName = aContainerName; +} + +void DocumentHolder::Hide() +{ + if( m_xFrame.is() ) + m_xFrame->deactivate(); +} + +sal_Bool DocumentHolder::SetVisArea( const awt::Rectangle& aRect ) +{ + if ( m_xDocument.is() ) + { + uno::Sequence< beans::PropertyValue > aArgs = m_xDocument->getArgs(); + for ( sal_Int32 nInd = 0; nInd < aArgs.getLength(); nInd++ ) + if ( aArgs[nInd].Name.equalsAscii( "WinExtent" ) ) + { + // should allways be there + uno::Sequence< sal_Int32 > aSeqRect( 4 ); + + aSeqRect[0] = aRect.X; + aSeqRect[1] = aRect.Y; + aSeqRect[2] = aRect.X + aRect.Width; + aSeqRect[3] = aRect.Y + aRect.Height; + + aArgs[nInd].Value <<= aSeqRect; + + m_xDocument->attachResource( m_xDocument->getURL(), aArgs ); + return sal_True; + } + + OSL_ENSURE( sal_False, "WinExtent seems not to be implemented!\n" ); + } + + return sal_False; +} + +sal_Bool DocumentHolder::GetVisArea( awt::Rectangle *pRect ) +{ + if ( pRect && m_xDocument.is() ) + { + uno::Sequence< beans::PropertyValue > aArgs = m_xDocument->getArgs(); + for ( sal_Int32 nInd = 0; nInd < aArgs.getLength(); nInd++ ) + if ( aArgs[nInd].Name.equalsAscii( "WinExtent" ) ) + { + uno::Sequence< sal_Int32 > aRect; + if ( ( aArgs[nInd].Value >>= aRect ) && aRect.getLength() == 4 ) + { + pRect->X = aRect[0]; + pRect->Y = aRect[1]; + pRect->Width = aRect[2] - pRect->X; + pRect->Height = aRect[3] - pRect->Y; + + return sal_True; + } + + break; + } + } + + return sal_False; +} + +sal_Bool DocumentHolder::SetExtent( const awt::Size& aSize ) +{ + if ( m_xDocument.is() ) + { + uno::Sequence< beans::PropertyValue > aArgs = m_xDocument->getArgs(); + for ( sal_Int32 nInd = 0; nInd < aArgs.getLength(); nInd++ ) + if ( aArgs[nInd].Name.equalsAscii( "WinExtent" ) ) + { + // should allways be there + uno::Sequence< sal_Int32 > aRect; + if ( ( aArgs[nInd].Value >>= aRect ) && aRect.getLength() == 4 ) + { + aRect[2] = aRect[0] + aSize.Width; + aRect[3] = aRect[1] + aSize.Height; + + aArgs[nInd].Value <<= aRect; + + m_xDocument->attachResource( m_xDocument->getURL(), aArgs ); + return sal_True; + } + } + + OSL_ENSURE( sal_False, "WinExtent seems not to be implemented!\n" ); + } + + return sal_False; +} + +sal_Bool DocumentHolder::GetExtent( awt::Size *pSize ) +{ + awt::Rectangle aRect; + if ( pSize && GetVisArea( &aRect ) ) + { + pSize->Width = aRect.Width; + pSize->Height = aRect.Height; + + return sal_True; + } + + return sal_False; +} + +void SAL_CALL DocumentHolder::disposing( const com::sun::star::lang::EventObject& aSource ) +{ + if ( m_xDocument.is() && m_xDocument == aSource.Source ) + m_xDocument = uno::Reference< frame::XModel >(); + + if( m_xFrame.is() && m_xFrame == aSource.Source ) + m_xFrame = uno::Reference< frame::XFrame >(); +} + + +void SAL_CALL DocumentHolder::queryClosing( const lang::EventObject& aSource, sal_Bool bGetsOwnership ) + throw( util::CloseVetoException ) +{ + if ( m_xDocument.is() && m_xDocument == aSource.Source ) + throw util::CloseVetoException(); +} + +void SAL_CALL DocumentHolder::notifyClosing( const lang::EventObject& aSource ) +{ + uno::Reference< util::XCloseBroadcaster > xEventBroadcaster( + aSource.Source, uno::UNO_QUERY ); + if ( xEventBroadcaster.is() ) + xEventBroadcaster->removeCloseListener( ( util::XCloseListener* )this ); + + if ( m_xDocument.is() && m_xDocument == aSource.Source ) + m_xDocument = uno::Reference< frame::XModel >(); + + if( m_xFrame.is() && m_xFrame == aSource.Source ) + m_xFrame = uno::Reference< frame::XFrame >(); +} + +void SAL_CALL DocumentHolder::queryTermination( const lang::EventObject& aSource ) + throw( frame::TerminationVetoException ) +{ + if ( m_xDocument.is() ) + throw frame::TerminationVetoException(); +} + +void SAL_CALL DocumentHolder::notifyTermination( const lang::EventObject& aSource ) +{ + OSL_ENSURE( !m_xDocument.is(), "Just a disaster..." ); + + uno::Reference< frame::XDesktop > xDesktop( aSource.Source, uno::UNO_QUERY ); + + if ( xDesktop.is() ) + xDesktop->removeTerminateListener( ( frame::XTerminateListener* )this ); +} + +void SAL_CALL DocumentHolder::modified( const lang::EventObject& aEvent ) + throw ( uno::RuntimeException ) +{ + if( m_pEmbedObj ) + m_pEmbedObj->update(); // TODO ??? +} + +void SAL_CALL DocumentHolder::notifyEvent( const ::com::sun::star::document::EventObject& Event ) + throw ( ::com::sun::star::uno::RuntimeException ) +{ + if( m_pEmbedObj && Event.Source == m_xDocument ) + m_pEmbedObj->PostEvent_Impl( Event.EventName ); +} + + diff --git a/embeddedobj/source/general/intercept.cxx b/embeddedobj/source/general/intercept.cxx new file mode 100644 index 000000000000..c098c18eb3d2 --- /dev/null +++ b/embeddedobj/source/general/intercept.cxx @@ -0,0 +1,474 @@ +/************************************************************************* + * + * $RCSfile: intercept.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: mav $ $Date: 2003-10-27 12:58:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COM_SUN_STAR_EMBED_EMBEDSTATES_HPP_ +#include <com/sun/star/embed/EmbedStates.hpp> +#endif + +#ifndef _CPPUHELPER_WEAK_HXX_ +#include <cppuhelper/weak.hxx> +#endif + +#include "intercept.hxx" +#include "docholder.hxx" +#include "commonembobj.hxx" + +using namespace ::com::sun::star; + + +#define IUL 5 + + +uno::Sequence<::rtl::OUString> Interceptor::m_aInterceptedURL(IUL); + +struct equalOUString +{ + bool operator()( + const rtl::OUString& rKey1, + const rtl::OUString& rKey2 ) const + { + return !!( rKey1 == rKey2 ); + } +}; + + +struct hashOUString +{ + size_t operator()( const rtl::OUString& rName ) const + { + return rName.hashCode(); + } +}; + + + +class StatusChangeListenerContainer + : public ::cppu::OMultiTypeInterfaceContainerHelperVar< +rtl::OUString,hashOUString,equalOUString> +{ +public: + StatusChangeListenerContainer( ::osl::Mutex& aMutex ) + : cppu::OMultiTypeInterfaceContainerHelperVar< + rtl::OUString,hashOUString,equalOUString>(aMutex) + { + } +}; + + +void Interceptor::DisconnectDocHolder() +{ + osl::MutexGuard aGuard( m_aMutex ); + m_pDocHolder = NULL; +} + +void SAL_CALL +Interceptor::addEventListener( + const uno::Reference<lang::XEventListener >& Listener ) + throw( uno::RuntimeException ) +{ + osl::MutexGuard aGuard( m_aMutex ); + + if ( ! m_pDisposeEventListeners ) + m_pDisposeEventListeners = + new cppu::OInterfaceContainerHelper( m_aMutex ); + + m_pDisposeEventListeners->addInterface( Listener ); +} + + +void SAL_CALL +Interceptor::removeEventListener( + const uno::Reference< lang::XEventListener >& Listener ) + throw( uno::RuntimeException ) +{ + osl::MutexGuard aGuard( m_aMutex ); + + if ( m_pDisposeEventListeners ) + m_pDisposeEventListeners->removeInterface( Listener ); +} + + +void SAL_CALL Interceptor::dispose() +{ + lang::EventObject aEvt; + aEvt.Source = static_cast< frame::XDispatch* >( this ); + + osl::MutexGuard aGuard(m_aMutex); + + if ( m_pDisposeEventListeners && m_pDisposeEventListeners->getLength() ) + m_pDisposeEventListeners->disposeAndClear( aEvt ); + + if(m_pStatCL) + m_pStatCL->disposeAndClear( aEvt ); + + m_xSlaveDispatchProvider = 0; + m_xMasterDispatchProvider = 0; +} + + + +Interceptor::Interceptor( DocumentHolder* pDocHolder ) + : m_pDocHolder( pDocHolder ), + m_pStatCL(0), + m_pDisposeEventListeners(0) +{ + m_aInterceptedURL[0] = rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM(".uno:Save")); + m_aInterceptedURL[1] = rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM(".uno:SaveAll")); + m_aInterceptedURL[2] = rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM(".uno:CloseDoc")); + m_aInterceptedURL[3] = rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM(".uno:CloseWin")); + m_aInterceptedURL[4] = rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM(".uno:CloseFrame")); +} + + +Interceptor::~Interceptor() +{ + if( m_pDisposeEventListeners ) + delete m_pDisposeEventListeners; + + if(m_pStatCL) + delete m_pStatCL; +} + + + +//XDispatch +void SAL_CALL +Interceptor::dispatch( + const util::URL& URL, + const uno::Sequence< + beans::PropertyValue >& Arguments ) + throw (uno::RuntimeException) +{ + osl::MutexGuard aGuard(m_aMutex); + if( m_pDocHolder ) + if(URL.Complete == m_aInterceptedURL[0]) + m_pDocHolder->GetEmbedObject()->SaveObject_Impl(); + else if(URL.Complete == m_aInterceptedURL[2] || + URL.Complete == m_aInterceptedURL[3] || + URL.Complete == m_aInterceptedURL[4]) + { + try { + m_pDocHolder->GetEmbedObject()->changeState( embed::EmbedStates::EMBED_RUNNING ); + } + catch( uno::Exception& ) + { + } + } +} + +void Interceptor::GenerateFeatureStateEvent() +{ + if(m_pStatCL) + { + for(int i = 0; i < IUL; ++i) + { + if( i == 1 ) + continue; + + cppu::OInterfaceContainerHelper* pICH = + m_pStatCL->getContainer(m_aInterceptedURL[i]); + uno::Sequence<uno::Reference<uno::XInterface> > aSeq; + if(pICH) + aSeq = pICH->getElements(); + if(!aSeq.getLength()) + continue; + + frame::FeatureStateEvent aStateEvent; + aStateEvent.IsEnabled = sal_True; + aStateEvent.Requery = sal_False; + if(i == 0) + { + aStateEvent.FeatureURL.Complete = m_aInterceptedURL[0]; + aStateEvent.FeatureDescriptor = rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM("Update")); + aStateEvent.State <<= (rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM("($1) ")) + m_pDocHolder->GetTitle() ); + + } + else + { + aStateEvent.FeatureURL.Complete = m_aInterceptedURL[i]; + aStateEvent.FeatureDescriptor = rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM("Close and Return")); + aStateEvent.State <<= (rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM("($2) ")) + m_pDocHolder->GetTitle() ); + + } + + for(sal_Int32 k = 0; k < aSeq.getLength(); ++k) + { + uno::Reference<frame::XStatusListener> + Control(aSeq[k],uno::UNO_QUERY); + if(Control.is()) + Control->statusChanged(aStateEvent); + + } + } + } +} + + +void SAL_CALL +Interceptor::addStatusListener( + const uno::Reference< + frame::XStatusListener >& Control, + const util::URL& URL ) + throw ( + uno::RuntimeException + ) +{ + if(!Control.is()) + return; + + if(URL.Complete == m_aInterceptedURL[0]) + { // Save + frame::FeatureStateEvent aStateEvent; + aStateEvent.FeatureURL.Complete = m_aInterceptedURL[0]; + aStateEvent.FeatureDescriptor = rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM("Update")); + aStateEvent.IsEnabled = sal_True; + aStateEvent.Requery = sal_False; + aStateEvent.State <<= (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("($1) ")) + m_pDocHolder->GetTitle() ); + Control->statusChanged(aStateEvent); + + { + osl::MutexGuard aGuard(m_aMutex); + if(!m_pStatCL) + m_pStatCL = + new StatusChangeListenerContainer(m_aMutex); + } + + m_pStatCL->addInterface(URL.Complete,Control); + return; + } + + sal_Int32 i = 2; + if(URL.Complete == m_aInterceptedURL[i] || + URL.Complete == m_aInterceptedURL[++i] || + URL.Complete == m_aInterceptedURL[++i] ) + { // Close and return + frame::FeatureStateEvent aStateEvent; + aStateEvent.FeatureURL.Complete = m_aInterceptedURL[i]; + aStateEvent.FeatureDescriptor = rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM("Close and Return")); + aStateEvent.IsEnabled = sal_True; + aStateEvent.Requery = sal_False; + aStateEvent.State <<= (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("($2) ")) + m_pDocHolder->GetTitle() ); + Control->statusChanged(aStateEvent); + + + { + osl::MutexGuard aGuard(m_aMutex); + if(!m_pStatCL) + m_pStatCL = + new StatusChangeListenerContainer(m_aMutex); + } + + m_pStatCL->addInterface(URL.Complete,Control); + return; + } +} + + +void SAL_CALL +Interceptor::removeStatusListener( + const uno::Reference< + frame::XStatusListener >& Control, + const util::URL& URL ) + throw ( + uno::RuntimeException + ) +{ + if(!(Control.is() && m_pStatCL)) + return; + else { + m_pStatCL->removeInterface(URL.Complete,Control); + return; + } +} + + +//XInterceptorInfo +uno::Sequence< ::rtl::OUString > +SAL_CALL +Interceptor::getInterceptedURLs( ) + throw ( + uno::RuntimeException + ) +{ + // now implemented as update + + return m_aInterceptedURL; +} + + +// XDispatchProvider + +uno::Reference< frame::XDispatch > SAL_CALL +Interceptor::queryDispatch( + const util::URL& URL, + const ::rtl::OUString& TargetFrameName, + sal_Int32 SearchFlags ) + throw ( + uno::RuntimeException + ) +{ + osl::MutexGuard aGuard(m_aMutex); + if(URL.Complete == m_aInterceptedURL[0]) + return (frame::XDispatch*)this; + else if(URL.Complete == m_aInterceptedURL[1]) + return (frame::XDispatch*)0 ; + else if(URL.Complete == m_aInterceptedURL[2]) + return (frame::XDispatch*)this; + else if(URL.Complete == m_aInterceptedURL[3]) + return (frame::XDispatch*)this; + else if(URL.Complete == m_aInterceptedURL[4]) + return (frame::XDispatch*)this; + else { + if(m_xSlaveDispatchProvider.is()) + return m_xSlaveDispatchProvider->queryDispatch( + URL,TargetFrameName,SearchFlags); + else + return uno::Reference<frame::XDispatch>(0); + } +} + +uno::Sequence< uno::Reference< frame::XDispatch > > SAL_CALL +Interceptor::queryDispatches( + const uno::Sequence<frame::DispatchDescriptor >& Requests ) + throw ( + uno::RuntimeException + ) +{ + uno::Sequence< uno::Reference< frame::XDispatch > > aRet; + osl::MutexGuard aGuard(m_aMutex); + if(m_xSlaveDispatchProvider.is()) + aRet = m_xSlaveDispatchProvider->queryDispatches(Requests); + else + aRet.realloc(Requests.getLength()); + + for(sal_Int32 i = 0; i < Requests.getLength(); ++i) + if(m_aInterceptedURL[0] == Requests[i].FeatureURL.Complete) + aRet[i] = (frame::XDispatch*) this; + else if(m_aInterceptedURL[1] == Requests[i].FeatureURL.Complete) + aRet[i] = (frame::XDispatch*) 0; + else if(m_aInterceptedURL[2] == Requests[i].FeatureURL.Complete) + aRet[i] = (frame::XDispatch*) this; + else if(m_aInterceptedURL[3] == Requests[i].FeatureURL.Complete) + aRet[i] = (frame::XDispatch*) this; + else if(m_aInterceptedURL[4] == Requests[i].FeatureURL.Complete) + aRet[i] = (frame::XDispatch*) this; + + return aRet; +} + + + +//XDispatchProviderInterceptor + +uno::Reference< frame::XDispatchProvider > SAL_CALL +Interceptor::getSlaveDispatchProvider( ) + throw ( + uno::RuntimeException + ) +{ + osl::MutexGuard aGuard(m_aMutex); + return m_xSlaveDispatchProvider; +} + +void SAL_CALL +Interceptor::setSlaveDispatchProvider( + const uno::Reference< frame::XDispatchProvider >& NewDispatchProvider ) + throw ( + uno::RuntimeException + ) +{ + osl::MutexGuard aGuard(m_aMutex); + m_xSlaveDispatchProvider = NewDispatchProvider; +} + + +uno::Reference< frame::XDispatchProvider > SAL_CALL +Interceptor::getMasterDispatchProvider( ) + throw ( + uno::RuntimeException + ) +{ + osl::MutexGuard aGuard(m_aMutex); + return m_xMasterDispatchProvider; +} + + +void SAL_CALL +Interceptor::setMasterDispatchProvider( + const uno::Reference< frame::XDispatchProvider >& NewSupplier ) + throw ( + uno::RuntimeException + ) +{ + osl::MutexGuard aGuard(m_aMutex); + m_xMasterDispatchProvider = NewSupplier; +} diff --git a/embeddedobj/source/general/makefile.mk b/embeddedobj/source/general/makefile.mk new file mode 100644 index 000000000000..19ff473879af --- /dev/null +++ b/embeddedobj/source/general/makefile.mk @@ -0,0 +1,99 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1 $ +# +# last change: $Author: mav $ $Date: 2003-10-27 12:58:08 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (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.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. + +PRJNAME=embeddedobj +TARGET=embedobj + + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +LIBTARGET=NO +USE_DEFFILE=NO + +# --- Files -------------------------------------------------------- + +SLOFILES = \ + $(SLO)$/xfactory.obj\ + $(SLO)$/register.obj\ + $(SLO)$/convert.obj\ + $(SLO)$/closepreventer.obj\ + $(SLO)$/docholder.obj\ + $(SLO)$/intercept.obj + + +EXCEPTIONSFILES= \ + $(SLO)$/xfactory.obj\ + $(SLO)$/register.obj\ + $(SLO)$/convert.obj\ + $(SLO)$/closepreventer.obj\ + $(SLO)$/docholder.obj\ + $(SLO)$/intercept.obj + + +# --- Targets ------------------------------------------------------- + +.INCLUDE : target.mk + diff --git a/embeddedobj/source/inc/closepreventer.hxx b/embeddedobj/source/inc/closepreventer.hxx new file mode 100644 index 000000000000..b1278bffd6aa --- /dev/null +++ b/embeddedobj/source/inc/closepreventer.hxx @@ -0,0 +1,79 @@ +/************************************************************************* + * + * $RCSfile: closepreventer.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: mav $ $Date: 2003-10-27 13:00:38 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COM_SUN_STAR_UTIL_XCLOSELISTENER_HPP_ +#include <com/sun/star/util/XCloseListener.hpp> +#endif + +#ifndef _CPPUHELPER_IMPLBASE1_HXX_ +#include <cppuhelper/implbase1.hxx> +#endif + +class OClosePreventer : public ::cppu::WeakImplHelper1 < ::com::sun::star::util::XCloseListener > +{ + virtual void SAL_CALL queryClosing( const ::com::sun::star::lang::EventObject& Source, sal_Bool GetsOwnership ) + throw( ::com::sun::star::util::CloseVetoException ); + + virtual void SAL_CALL notifyClosing( const com::sun::star::lang::EventObject& Source ); + + virtual void SAL_CALL disposing( const com::sun::star::lang::EventObject& Source ); +}; + diff --git a/embeddedobj/source/inc/commonembobj.hxx b/embeddedobj/source/inc/commonembobj.hxx new file mode 100644 index 000000000000..12cc35a5c6e2 --- /dev/null +++ b/embeddedobj/source/inc/commonembobj.hxx @@ -0,0 +1,443 @@ +/************************************************************************* + * + * $RCSfile: commonembobj.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: mav $ $Date: 2003-10-27 13:00:38 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _INC_COMMONEMBOBJ_HXX_ +#define _INC_COMMONEMBOBJ_HXX_ + +#ifndef _COM_SUN_STAR_UNO_SEQUENCE_HXX_ +#include <com/sun/star/uno/Sequence.hxx> +#endif +#ifndef _COM_SUN_STAR_UNO_REFERENCE_HXX_ +#include <com/sun/star/uno/Reference.hxx> +#endif +#ifndef _COM_SUN_STAR_UNO_ANY_HXX_ +#include <com/sun/star/uno/Any.hxx> +#endif + +#ifndef _COM_SUN_STAR_EMBED_XEMBEDDEDOBJECT_HPP_ +#include <com/sun/star/embed/XEmbeddedObject.hpp> +#endif +#ifndef _COM_SUN_STAR_EMBED_XVISUALOBJECT_HPP_ +#include <com/sun/star/embed/XVisualObject.hpp> +#endif +#ifndef _COM_SUN_STAR_EMBED_XEMBEDPERSIST_HPP_ +#include <com/sun/star/embed/XEmbedPersist.hpp> +#endif +#ifndef _COM_SUN_STAR_EMBED_XLINKAGESUPPORT_HPP_ +#include <com/sun/star/embed/XLinkageSupport.hpp> +#endif +#ifndef _COM_SUN_STAR_EMBED_XCLASSIFIEDOBJECT_HPP_ +#include <com/sun/star/embed/XClassifiedObject.hpp> +#endif +#ifndef _COM_SUN_STAR_EMBED_XCOMPONENTSUPPLIER_HPP_ +#include <com/sun/star/embed/XComponentSupplier.hpp> +#endif + +#ifndef _COM_SUN_STAR_DOCUMENT_XEVENTBROADCASTER_HPP_ +#include <com/sun/star/document/XEventBroadcaster.hpp> +#endif + +#ifndef _CPPUHELPER_WEAK_HXX_ +#include <cppuhelper/weak.hxx> +#endif + +namespace com { namespace sun { namespace star { + namespace embed { + class XStorage; + } + namespace frame { + class XModel; + class XFrame; + } + namespace lang { + class XMultiServiceFactory; + } + namespace util { + class XCloseListener; + } +}}} + +namespace cppu { + class OMultiTypeInterfaceContainerHelper; +} + +#define NUM_SUPPORTED_STATES 3 +#define NUM_SUPPORTED_VERBS 3 + +#include "docholder.hxx" + +class Interceptor; + +class OCommonEmbeddedObject : public ::com::sun::star::embed::XEmbeddedObject + , public ::com::sun::star::embed::XVisualObject + , public ::com::sun::star::embed::XEmbedPersist + , public ::com::sun::star::embed::XLinkageSupport + , public ::com::sun::star::embed::XClassifiedObject + , public ::com::sun::star::embed::XComponentSupplier + , public ::com::sun::star::document::XEventBroadcaster + , public ::cppu::OWeakObject +{ + ::osl::Mutex m_aMutex; + + DocumentHolder* m_pDocHolder; + + ::cppu::OMultiTypeInterfaceContainerHelper* m_pInterfaceContainer; + + sal_Bool m_bReadOnly; + + sal_Int32 m_bDisposed; + sal_Int32 m_nObjectState; + sal_Int32 m_nUpdateMode; + + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xFactory; + + ::com::sun::star::uno::Sequence< sal_Int8 > m_aClassID; + ::rtl::OUString m_aClassName; + + ::rtl::OUString m_aDocServiceName; + + ::com::sun::star::uno::Sequence< sal_Int32 > m_aAcceptedStates; + ::com::sun::star::uno::Sequence< sal_Int32 > m_pIntermediateStatesSeqs[NUM_SUPPORTED_STATES][NUM_SUPPORTED_STATES]; + ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< sal_Int32 > > m_aVerbTable; + + ::com::sun::star::uno::Reference< ::com::sun::star::embed::XEmbeddedClient > m_xClientSite; + + ::rtl::OUString m_aContainerName; + + ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloseListener > m_xClosePreventer; + + Interceptor* m_pInterceptor; + + // following information will be used between SaveAs and SaveCompleted + sal_Bool m_bWaitSaveCompleted; + ::rtl::OUString m_aNewEntryName; + ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > m_xNewParentStorage; + ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > m_xNewObjectStorage; + + sal_Bool m_bIsLink; + + // embedded object related stuff + ::rtl::OUString m_aEntryName; + ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > m_xParentStorage; + ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > m_xObjectStorage; + + // link related stuff + ::rtl::OUString m_aLinkURL; + ::rtl::OUString m_aLinkFilterName; + +private: + void CommonInit_Impl(); + + ::rtl::OUString GetDocumentServiceName() { return m_aDocServiceName; } + + ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > StoreDocumentToTempStream_Impl(); + + sal_Int32 ConvertVerbToState_Impl( sal_Int32 nVerb ); + + void SwitchStateTo_Impl( sal_Int32 nNextState ); + + ::com::sun::star::uno::Sequence< sal_Int32 > GetIntermediateStatesSequence_Impl( sal_Int32 nNewState ); + + ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > LoadDocumentFromStorage_Impl( + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage ); + + ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > LoadLink_Impl(); + + ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > InitNewDocument_Impl(); + + void StoreDocToStorage_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage ); + + ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > CreateDocFromMediaDescr_Impl( + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aMedDescr ); + + ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > CreateTempDocFromLink_Impl(); + +public: + OCommonEmbeddedObject( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory, + const ::com::sun::star::uno::Sequence< sal_Int8 >& aClassID, + const ::rtl::OUString& aClassName, + const ::rtl::OUString& aDocServiceName ); + + // no persistance for linked objects, so the url is provided in constructor + OCommonEmbeddedObject( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory, + const ::com::sun::star::uno::Sequence< sal_Int8 >& aClassID, + const ::rtl::OUString& aClassName, + const ::rtl::OUString& aDocServiceName, + const ::rtl::OUString& aLinkFilterName, + const ::rtl::OUString& aLinkURL ); + + virtual ~OCommonEmbeddedObject(); + + void SaveObject_Impl(); + + // not a real listener and should not be + void PostEvent_Impl( const ::rtl::OUString& aEventName ); + +// XInterface + + virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& rType ) + throw( ::com::sun::star::uno::RuntimeException ) ; + + virtual void SAL_CALL acquire() + throw(); + + virtual void SAL_CALL release() + throw(); + +// XTypeProvider + + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() + throw( ::com::sun::star::uno::RuntimeException ) ; + + virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() + throw( ::com::sun::star::uno::RuntimeException ) ; + +// XEmbeddedObject + + virtual void SAL_CALL changeState( sal_Int32 nNewState ) + throw ( ::com::sun::star::embed::UnreachableStateException, + ::com::sun::star::embed::WrongStateException, + ::com::sun::star::uno::Exception, + ::com::sun::star::uno::RuntimeException ); + + virtual ::com::sun::star::uno::Sequence< sal_Int32 > SAL_CALL getReachableStates() + throw ( ::com::sun::star::embed::WrongStateException, + ::com::sun::star::uno::RuntimeException ); + + virtual sal_Int32 SAL_CALL getCurrentState() + throw ( ::com::sun::star::embed::WrongStateException, + ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL doVerb( sal_Int32 nVerbID ) + throw ( ::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::embed::WrongStateException, + ::com::sun::star::embed::UnreachableStateException, + ::com::sun::star::uno::Exception, + ::com::sun::star::uno::RuntimeException ); + + virtual ::com::sun::star::uno::Sequence< sal_Int32 > SAL_CALL getSupportedVerbs() + throw ( ::com::sun::star::embed::WrongStateException, + ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL setClientSite( + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XEmbeddedClient >& xClient ) + throw ( ::com::sun::star::embed::WrongStateException, + ::com::sun::star::uno::RuntimeException ); + + virtual ::com::sun::star::uno::Reference< ::com::sun::star::embed::XEmbeddedClient > SAL_CALL getClientSite() + throw ( ::com::sun::star::embed::WrongStateException, + ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL update() + throw ( ::com::sun::star::embed::WrongStateException, + ::com::sun::star::uno::Exception, + ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL setUpdateMode( sal_Int32 nMode ) + throw ( ::com::sun::star::embed::WrongStateException, + ::com::sun::star::uno::RuntimeException ); + + virtual sal_Int64 SAL_CALL getStatus( sal_Int64 nAspect ) + throw ( ::com::sun::star::embed::WrongStateException, + ::com::sun::star::uno::RuntimeException ); + + +// XVisualObject + + virtual void SAL_CALL setContainerName( const ::rtl::OUString& sName ) + throw ( ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL setVisAreaSize( sal_Int64 nAspect, const ::com::sun::star::awt::Size& aSize ) + throw ( ::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::embed::WrongStateException, + ::com::sun::star::uno::Exception, + ::com::sun::star::uno::RuntimeException ); + + virtual ::com::sun::star::awt::Size SAL_CALL getVisAreaSize( sal_Int64 nAspect ) + throw ( ::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::embed::WrongStateException, + ::com::sun::star::uno::Exception, + ::com::sun::star::uno::RuntimeException ); + + virtual ::com::sun::star::uno::Any SAL_CALL getVisualCache( sal_Int64 nAspect ) + throw ( ::com::sun::star::uno::Exception, + ::com::sun::star::uno::RuntimeException ); + + +// XEmbedPersist + + virtual void SAL_CALL setPersistentEntry( + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage, + const ::rtl::OUString& sEntName, + sal_Int32 nEntryConnectionMode, + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lArguments ) + throw ( ::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::embed::WrongStateException, + ::com::sun::star::io::IOException, + ::com::sun::star::uno::Exception, + ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL storeOwn() + throw ( ::com::sun::star::embed::WrongStateException, + ::com::sun::star::io::IOException, + ::com::sun::star::uno::Exception, + ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL storeToEntry( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage, const ::rtl::OUString& sEntName, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lArguments ) + throw ( ::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::embed::WrongStateException, + ::com::sun::star::io::IOException, + ::com::sun::star::uno::Exception, + ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL storeAsEntry( + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage, + const ::rtl::OUString& sEntName, + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lArguments ) + throw ( ::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::embed::WrongStateException, + ::com::sun::star::io::IOException, + ::com::sun::star::uno::Exception, + ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL saveCompleted( sal_Bool bUseNew ) + throw ( ::com::sun::star::embed::WrongStateException, + ::com::sun::star::uno::Exception, + ::com::sun::star::uno::RuntimeException ); + + virtual sal_Bool SAL_CALL hasEntry() + throw ( ::com::sun::star::embed::WrongStateException, + ::com::sun::star::uno::RuntimeException ); + + virtual ::rtl::OUString SAL_CALL getEntryName() + throw ( ::com::sun::star::embed::WrongStateException, + ::com::sun::star::uno::RuntimeException ); + + virtual sal_Bool SAL_CALL isReadonly() + throw ( ::com::sun::star::embed::WrongStateException, + ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL reload( + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lArguments ) + throw ( ::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::embed::WrongStateException, + ::com::sun::star::io::IOException, + ::com::sun::star::uno::Exception, + ::com::sun::star::uno::RuntimeException ); + +// XLinkageSupport + + virtual sal_Bool SAL_CALL isLink() + throw ( ::com::sun::star::embed::WrongStateException, + ::com::sun::star::uno::RuntimeException); + + virtual ::rtl::OUString SAL_CALL getLinkURL() + throw ( ::com::sun::star::embed::WrongStateException, + ::com::sun::star::uno::Exception, + ::com::sun::star::uno::RuntimeException); + +// XClassifiedObject + + virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getClassID() + throw ( ::com::sun::star::uno::RuntimeException ); + + virtual ::rtl::OUString SAL_CALL getClassName() + throw ( ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL setClassInfo( + const ::com::sun::star::uno::Sequence< sal_Int8 >& aClassID, const ::rtl::OUString& aClassName ) + throw ( ::com::sun::star::lang::NoSupportException, + ::com::sun::star::uno::RuntimeException ); + + +// XComponentSupplier + + virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > SAL_CALL getComponent() + throw ( ::com::sun::star::uno::RuntimeException ); + + +// XEventBroadcaster + virtual void SAL_CALL addEventListener( + const ::com::sun::star::uno::Reference< ::com::sun::star::document::XEventListener >& Listener ) + throw ( ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL removeEventListener( + const ::com::sun::star::uno::Reference< ::com::sun::star::document::XEventListener >& Listener ) + throw ( ::com::sun::star::uno::RuntimeException ); + +// XComponent + virtual void SAL_CALL dispose() + throw ( ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL addEventListener( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) + throw ( ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL removeEventListener( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) + throw (::com::sun::star::uno::RuntimeException); + +}; + +#endif + diff --git a/embeddedobj/source/inc/docholder.hxx b/embeddedobj/source/inc/docholder.hxx new file mode 100644 index 000000000000..c59f4659d2e0 --- /dev/null +++ b/embeddedobj/source/inc/docholder.hxx @@ -0,0 +1,175 @@ +/************************************************************************* + * + * $RCSfile: docholder.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: mav $ $Date: 2003-10-27 13:00:39 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 ( 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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor( s ): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _DOCHOLDER_HXX_ +#define _DOCHOLDER_HXX_ + +#ifndef _COM_SUN_STAR_UTIL_XCLOSELISTENER_HPP_ +#include <com/sun/star/util/XCloseListener.hpp> +#endif +#ifndef _COM_SUN_STAR_FRAME_XTERMINATELISTENER_HPP_ +#include <com/sun/star/frame/XTerminateListener.hpp> +#endif +#ifndef _COM_SUN_STAR_UTIL_XMODIFYLISTENER_HPP_ +#include <com/sun/star/util/XModifyListener.hpp> +#endif +#ifndef _COM_SUN_STAR_DOCUMENT_XEVENTLISTENER_HPP_ +#include <com/sun/star/document/XEventListener.hpp> +#endif +#ifndef _COM_SUN_STAR_FRAME_XFRAME_HPP_ +#include <com/sun/star/frame/XFrame.hpp> +#endif +#ifndef _COM_SUN_STAR_AWT_SIZE_HPP_ +#include <com/sun/star/awt/Size.hpp> +#endif +#ifndef _COM_SUN_STAR_AWT_RECTANGLE_HPP_ +#include <com/sun/star/awt/Rectangle.hpp> +#endif + +#ifndef _CPPUHELPER_IMPLBASE4_HXX_ +#include <cppuhelper/implbase4.hxx> +#endif + +class OCommonEmbeddedObject; +class Interceptor; + +class DocumentHolder : + public ::cppu::WeakImplHelper4< + ::com::sun::star::util::XCloseListener, + ::com::sun::star::frame::XTerminateListener, + ::com::sun::star::util::XModifyListener, + ::com::sun::star::document::XEventListener > +{ +private: + + OCommonEmbeddedObject* m_pEmbedObj; + Interceptor* m_pInterceptor; + + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xFactory; + + ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > m_xDocument; + + ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > m_xFrame; + + ::rtl::OUString m_aContainerName; + ::rtl::OUString m_aDocumentNamePart; + + sal_Bool m_bReadOnly; + + ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > GetDocFrame(); + void LoadDocToFrame(); + +public: + + DocumentHolder( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory, + OCommonEmbeddedObject* pEmbObj ); + ~DocumentHolder(); + + OCommonEmbeddedObject* GetEmbedObject() { return m_pEmbedObj; } + + void SetDocument( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& xDoc, sal_Bool bReadOnly ); + + void FreeOffice(); + void CloseDocument(); + void CloseFrame(); + + void SetTitle(const rtl::OUString& aDocumentName); + rtl::OUString GetTitle() const { return m_aDocumentNamePart; } + + void SetContainerName(const rtl::OUString& aContainerName); + rtl::OUString GetContainerName() const { return m_aContainerName; } + + void Show(); + + void Hide(); + + sal_Bool SetVisArea( const ::com::sun::star::awt::Rectangle& aRect ); + sal_Bool GetVisArea( ::com::sun::star::awt::Rectangle *pRect ); + sal_Bool SetExtent( const ::com::sun::star::awt::Size& aSize ); + sal_Bool GetExtent( ::com::sun::star::awt::Size *pSize ); + + ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > GetDocument() { return m_xDocument; } + +// XEventListener + virtual void SAL_CALL disposing( const com::sun::star::lang::EventObject& aSource ); + +// XCloseListener + virtual void SAL_CALL queryClosing( const com::sun::star::lang::EventObject& aSource, sal_Bool bGetsOwnership ) + throw( ::com::sun::star::util::CloseVetoException ); + + virtual void SAL_CALL notifyClosing( const com::sun::star::lang::EventObject& aSource ); + +// XTerminateListener + virtual void SAL_CALL queryTermination( const com::sun::star::lang::EventObject& aSource ) + throw( ::com::sun::star::frame::TerminationVetoException ); + + virtual void SAL_CALL notifyTermination( const com::sun::star::lang::EventObject& aSource ); + +// XModifyListener + virtual void SAL_CALL modified( const ::com::sun::star::lang::EventObject& aEvent ) throw ( ::com::sun::star::uno::RuntimeException ); + +// XEventListener + virtual void SAL_CALL notifyEvent( const ::com::sun::star::document::EventObject& Event ) throw ( ::com::sun::star::uno::RuntimeException ); + +}; + +#endif + diff --git a/embeddedobj/source/inc/intercept.hxx b/embeddedobj/source/inc/intercept.hxx new file mode 100644 index 000000000000..e208887cd8eb --- /dev/null +++ b/embeddedobj/source/inc/intercept.hxx @@ -0,0 +1,219 @@ +/************************************************************************* + * + * $RCSfile: intercept.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: mav $ $Date: 2003-10-27 13:00:39 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _INTERCEPT_HXX_ +#define _INTERCEPT_HXX_ + +#ifndef _OSL_MUTEX_HXX_ +#include <osl/mutex.hxx> +#endif +#ifndef _CPPUHELPER_IMPLBASE3_HXX_ +#include <cppuhelper/implbase3.hxx> +#endif +#ifndef _CPPUHELPER_INTERFACECONTAINER_HXX_ +#include <cppuhelper/interfacecontainer.hxx> +#endif +#ifndef _COM_SUN_STAR_FRAME_XDISPATCHPROVIDERINTERCEPTOR_HPP_ +#include <com/sun/star/frame/XDispatchProviderInterceptor.hpp> +#endif +#ifndef _COM_SUN_STAR_FRAME_XINTERCEPTORINFO_HPP_ +#include <com/sun/star/frame/XInterceptorInfo.hpp> +#endif +#ifndef _COM_SUN_STAR_FRAME_XDISPATCH_HPP_ +#include <com/sun/star/frame/XDispatch.hpp> +#endif + + +class StatusChangeListenerContainer; +class DocumentHolder; + +class Interceptor : public ::cppu::WeakImplHelper3< ::com::sun::star::frame::XDispatchProviderInterceptor, + ::com::sun::star::frame::XInterceptorInfo, + ::com::sun::star::frame::XDispatch> +{ +public: + + Interceptor( DocumentHolder* pDocHolder ); + ~Interceptor(); + + void GenerateFeatureStateEvent(); + + void DisconnectDocHolder(); + // overwritten to release the statuslistner. + + // XComponent + virtual void SAL_CALL + addEventListener( + const com::sun::star::uno::Reference< com::sun::star::lang::XEventListener >& xListener ) + throw( com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + removeEventListener( const com::sun::star::uno::Reference< com::sun::star::lang::XEventListener >& aListener ) + throw( com::sun::star::uno::RuntimeException ); + + void SAL_CALL + dispose() throw(::com::sun::star::uno::RuntimeException); + + + //XDispatch + virtual void SAL_CALL + dispatch( + const ::com::sun::star::util::URL& URL, + const ::com::sun::star::uno::Sequence< + ::com::sun::star::beans::PropertyValue >& Arguments ) + throw (::com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL + addStatusListener( + const ::com::sun::star::uno::Reference< + ::com::sun::star::frame::XStatusListener >& Control, + const ::com::sun::star::util::URL& URL ) + throw ( + ::com::sun::star::uno::RuntimeException + ); + + virtual void SAL_CALL + removeStatusListener( + const ::com::sun::star::uno::Reference< + ::com::sun::star::frame::XStatusListener >& Control, + const ::com::sun::star::util::URL& URL ) + throw ( + ::com::sun::star::uno::RuntimeException + ); + + //XInterceptorInfo + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > + SAL_CALL getInterceptedURLs( ) + throw ( + ::com::sun::star::uno::RuntimeException + ); + + //XDispatchProvider ( inherited by XDispatchProviderInterceptor ) + virtual ::com::sun::star::uno::Reference< + ::com::sun::star::frame::XDispatch > SAL_CALL + queryDispatch( + const ::com::sun::star::util::URL& URL, + const ::rtl::OUString& TargetFrameName, + sal_Int32 SearchFlags ) + throw ( + ::com::sun::star::uno::RuntimeException + ); + + virtual ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::frame::XDispatch > > SAL_CALL + queryDispatches( + const ::com::sun::star::uno::Sequence< + ::com::sun::star::frame::DispatchDescriptor >& Requests ) + throw ( + ::com::sun::star::uno::RuntimeException + ); + + + //XDispatchProviderInterceptor + virtual ::com::sun::star::uno::Reference< + ::com::sun::star::frame::XDispatchProvider > SAL_CALL + getSlaveDispatchProvider( ) + throw ( + ::com::sun::star::uno::RuntimeException + ); + + virtual void SAL_CALL + setSlaveDispatchProvider( + const ::com::sun::star::uno::Reference< + ::com::sun::star::frame::XDispatchProvider >& NewDispatchProvider ) + throw ( + ::com::sun::star::uno::RuntimeException + ); + + virtual ::com::sun::star::uno::Reference< + ::com::sun::star::frame::XDispatchProvider > SAL_CALL + getMasterDispatchProvider( ) + throw ( + ::com::sun::star::uno::RuntimeException + ); + + virtual void SAL_CALL + setMasterDispatchProvider( + const ::com::sun::star::uno::Reference< + ::com::sun::star::frame::XDispatchProvider >& NewSupplier ) + throw ( + ::com::sun::star::uno::RuntimeException + ); + + +private: + + osl::Mutex m_aMutex; + + DocumentHolder* m_pDocHolder; + + ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider > m_xSlaveDispatchProvider; + ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider > m_xMasterDispatchProvider; + + static ::com::sun::star::uno::Sequence<::rtl::OUString> m_aInterceptedURL; + + cppu::OInterfaceContainerHelper* m_pDisposeEventListeners; + StatusChangeListenerContainer* m_pStatCL; +}; + +#endif + diff --git a/embeddedobj/util/exports.dxp b/embeddedobj/util/exports.dxp new file mode 100644 index 000000000000..9630d7e06768 --- /dev/null +++ b/embeddedobj/util/exports.dxp @@ -0,0 +1,3 @@ +component_getImplementationEnvironment +component_writeInfo +component_getFactory diff --git a/embeddedobj/util/makefile.mk b/embeddedobj/util/makefile.mk new file mode 100644 index 000000000000..c75488d686ab --- /dev/null +++ b/embeddedobj/util/makefile.mk @@ -0,0 +1,106 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1 $ +# +# last change: $Author: mav $ $Date: 2003-10-27 13:04:03 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (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.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=.. + +PRJNAME=embeddedobj +TARGET=embobj +LIBTARGET=NO +USE_DEFFILE=TRUE + +# --- Settings ----------------------------------------------------------- + +.INCLUDE : settings.mk + +# --- Files -------------------------------------------------------- + +SHL1TARGET= $(TARGET) + +SHL1IMPLIB= i$(TARGET) +SHL1OBJS= \ + $(SLO)$/miscobj.obj\ + $(SLO)$/persistence.obj\ + $(SLO)$/embedobj.obj\ + $(SLO)$/visobj.obj\ + $(SLO)$/xfactory.obj\ + $(SLO)$/register.obj\ + $(SLO)$/convert.obj\ + $(SLO)$/docholder.obj\ + $(SLO)$/closepreventer.obj\ + $(SLO)$/intercept.obj + + +SHL1STDLIBS=\ + $(SALLIB) \ + $(CPPULIB) \ + $(CPPUHELPERLIB) \ + +SHL1DEF= $(MISC)$/$(SHL1TARGET).def + +DEF1NAME= $(SHL1TARGET) +DEF1EXPORTFILE= exports.dxp + +# --- Targets ------------------------------------------------------------- + +.INCLUDE : target.mk + + |