2000-09-18 23:16:46 +00:00
/*************************************************************************
*
2005-09-08 12:30:10 +00:00
* OpenOffice . org - a multi - platform office productivity suite
2000-09-18 23:16:46 +00:00
*
2005-09-08 12:30:10 +00:00
* $ RCSfile : documentdefinition . cxx , v $
2000-09-18 23:16:46 +00:00
*
2007-07-06 06:54:16 +00:00
* $ Revision : 1.43 $
2000-09-18 23:16:46 +00:00
*
2007-07-06 06:54:16 +00:00
* last change : $ Author : rt $ $ Date : 2007 - 07 - 06 07 : 54 : 16 $
2000-09-18 23:16:46 +00:00
*
2005-09-08 12:30:10 +00:00
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1 .
2000-09-18 23:16:46 +00:00
*
*
2005-09-08 12:30:10 +00:00
* GNU Lesser General Public License Version 2.1
* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
* Copyright 2005 by Sun Microsystems , Inc .
* 901 San Antonio Road , Palo Alto , CA 94303 , USA
2000-09-18 23:16:46 +00:00
*
2005-09-08 12:30:10 +00:00
* 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 .
2000-09-18 23:16:46 +00:00
*
2005-09-08 12:30:10 +00:00
* 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 .
2000-09-18 23:16:46 +00:00
*
2005-09-08 12:30:10 +00:00
* 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
2000-09-18 23:16:46 +00:00
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2006-09-17 05:40:25 +00:00
// MARKER(update_precomp.py): autogen include statement, do not remove
# include "precompiled_dbaccess.hxx"
2000-09-18 23:16:46 +00:00
# ifndef _DBA_COREDATAACCESS_DOCUMENTDEFINITION_HXX_
# include "documentdefinition.hxx"
# endif
2000-10-25 06:42:28 +00:00
# ifndef DBACCESS_SHARED_DBASTRINGS_HRC
# include "dbastrings.hrc"
2000-09-18 23:16:46 +00:00
# endif
2005-01-05 11:28:50 +00:00
# ifndef DBACORE_SDBCORETOOLS_HXX
# include "sdbcoretools.hxx"
# endif
2000-09-18 23:16:46 +00:00
# ifndef _TOOLS_DEBUG_HXX
# include <tools/debug.hxx>
# endif
2006-01-03 15:14:52 +00:00
# ifndef TOOLS_DIAGNOSE_EX_H
# include <tools/diagnose_ex.h>
# endif
2000-10-11 10:21:40 +00:00
# ifndef _COMPHELPER_PROPERTY_HXX_
# include <comphelper/property.hxx>
2000-09-18 23:16:46 +00:00
# endif
2000-10-11 10:21:40 +00:00
# ifndef _COMPHELPER_SEQUENCE_HXX_
# include <comphelper/sequence.hxx>
2000-09-18 23:16:46 +00:00
# endif
2005-01-21 16:04:28 +00:00
# ifndef _COMPHELPER_MEDIADESCRIPTOR_HXX_
# include <comphelper/mediadescriptor.hxx>
# endif
2004-08-02 14:10:37 +00:00
# ifndef _SO_CLSIDS_HXX
# include <so3/clsids.hxx>
# endif
# ifndef _COM_SUN_STAR_AWT_XTOPWINDOW_HPP_
# include <com/sun/star/awt/XTopWindow.hpp>
# endif
2005-03-15 10:33:00 +00:00
# ifndef _COM_SUN_STAR_AWT_SIZE_HPP_
# include <com/sun/star/awt/Size.hpp>
# endif
2000-09-18 23:16:46 +00:00
# ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_
# include <com/sun/star/lang/DisposedException.hpp>
# endif
2000-10-25 06:42:28 +00:00
# ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_
# include <com/sun/star/beans/PropertyAttribute.hpp>
# endif
2004-08-02 14:10:37 +00:00
# ifndef _COM_SUN_STAR_FRAME_XMODEL_HPP_
# include <com/sun/star/frame/XModel.hpp>
# endif
# ifndef _COM_SUN_STAR_FRAME_XCONTROLLER_HPP_
# include <com/sun/star/frame/XController.hpp>
# endif
# ifndef _COM_SUN_STAR_TASK_XJOBEXECUTOR_HPP_
# include <com/sun/star/task/XJobExecutor.hpp>
# endif
# ifndef _COM_SUN_STAR_FRAME_XDISPATCHPROVIDERINTERCEPTION_HPP_
# include <com/sun/star/frame/XDispatchProviderInterception.hpp>
# endif
2007-04-16 15:24:31 +00:00
# ifndef _COM_SUN_STAR_FRAME_XFRAMESSUPPLIER_HPP_
# include <com/sun/star/frame/XFramesSupplier.hpp>
# endif
2004-08-02 14:10:37 +00:00
# ifndef _COM_SUN_STAR_UCB_INSERTCOMMANDARGUMENT_HPP_
# include <com/sun/star/ucb/InsertCommandArgument.hpp>
# endif
2007-07-06 06:54:16 +00:00
# include <com/sun/star/report/XReportDefinition.hpp>
# include <com/sun/star/report/XReportEngine.hpp>
2004-08-02 14:10:37 +00:00
# ifndef _COM_SUN_STAR_UCB_OPENMODE_HPP_
# include <com/sun/star/ucb/OpenMode.hpp>
# endif
# ifndef _COM_SUN_STAR_XEMBEDOBJECTFACTORY_HPP_
# include <com/sun/star/embed/XEmbedObjectFactory.hpp>
# endif
# ifndef _COM_SUN_STAR_XEMBEDOBJECTCREATOR_HPP_
# include <com/sun/star/embed/XEmbedObjectCreator.hpp>
# endif
2005-01-05 11:28:50 +00:00
# ifndef _COM_SUN_STAR_EMBED_ASPECTS_HPP_
# include <com/sun/star/embed/Aspects.hpp>
# endif
2004-08-02 14:10:37 +00:00
# ifndef _UCBHELPER_CANCELCOMMANDEXECUTION_HXX_
# include <ucbhelper/cancelcommandexecution.hxx>
# endif
# ifndef _COM_SUN_STAR_UCB_UNSUPPORTEDDATASINKEXCEPTION_HPP_
# include <com/sun/star/ucb/UnsupportedDataSinkException.hpp>
# endif
# ifndef _COM_SUN_STAR_UCB_UNSUPPORTEDOPENMODEEXCEPTION_HPP_
# include <com/sun/star/ucb/UnsupportedOpenModeException.hpp>
# endif
# ifndef _COM_SUN_STAR_ELEMENTMODES_HPP_
# include <com/sun/star/embed/ElementModes.hpp>
# endif
# ifndef _COM_SUN_STAR_XEMBEDPERSIST_HPP_
# include <com/sun/star/embed/XEmbedPersist.hpp>
# endif
# ifndef _COM_SUN_STAR_EMBEDSTATES_HPP_
# include <com/sun/star/embed/EmbedStates.hpp>
# endif
# ifndef _COM_SUN_STAR_XCOMPONENTSUPPLIER_HPP_
# include <com/sun/star/embed/XComponentSupplier.hpp>
# endif
# ifndef _COM_SUN_STAR_ENTRYINITMODES_HPP_
# include <com/sun/star/embed/EntryInitModes.hpp>
# endif
# ifndef _COM_SUN_STAR_UCB_MISSINGPROPERTIESEXCEPTION_HPP_
# include <com/sun/star/ucb/MissingPropertiesException.hpp>
# endif
# ifndef _COM_SUN_STAR_UCB_MISSINGINPUTSTREAMEXCEPTION_HPP_
# include <com/sun/star/ucb/MissingInputStreamException.hpp>
# endif
# ifndef _COM_SUN_STAR_UCB_OPENCOMMANDARGUMENT2_HPP_
# include <com/sun/star/ucb/OpenCommandArgument2.hpp>
# endif
# ifndef _COM_SUN_STAR_UTIL_XCLOSEBROADCASTER_HPP_
# include <com/sun/star/util/XCloseBroadcaster.hpp>
# endif
2007-04-16 15:24:31 +00:00
# ifndef _COM_SUN_STAR_FRAME_XMODULE_HPP_
# include <com/sun/star/frame/XModule.hpp>
# endif
2004-08-02 14:10:37 +00:00
# ifndef _COM_SUN_STAR_DATATRANSFER_DATAFLAVOR_HPP_
# include <com/sun/star/datatransfer/DataFlavor.hpp>
# endif
# ifndef _COM_SUN_STAR_DATATRANSFER_XTRANSFERABLE_HPP_
# include <com/sun/star/datatransfer/XTransferable.hpp>
# endif
# ifndef _COM_SUN_STAR_CONTAINER_XNAMECONTAINER_HPP_
# include <com/sun/star/container/XNameContainer.hpp>
# endif
# ifndef _COM_SUN_STAR_XTRANSACTEDOBJECT_HPP_
# include <com/sun/star/embed/XTransactedObject.hpp>
# endif
2005-01-05 11:28:50 +00:00
# ifndef _COM_SUN_STAR_EMBED_XCOMMONEMBEDPERSIST_HPP_
# include <com/sun/star/embed/XCommonEmbedPersist.hpp>
# endif
2004-08-02 14:10:37 +00:00
# ifndef DBA_INTERCEPT_HXX
# include "intercept.hxx"
# endif
# ifndef _COM_SUN_STAR_SDB_XINTERACTIONDOCUMENTSAVE_HPP_
# include <com/sun/star/sdb/XInteractionDocumentSave.hpp>
# endif
# ifndef _COM_SUN_STAR_TASK_XINTERACTIONHANDLER_HPP_
# include <com/sun/star/task/XInteractionHandler.hpp>
# endif
# ifndef _COM_SUN_STAR_SDB_DOCUMENTSAVEREQUEST_HPP_
# include <com/sun/star/sdb/DocumentSaveRequest.hpp>
# endif
# ifndef _COM_SUN_STAR_DOCUMENT_XDOCUMENTINFOSUPPLIER_HPP_
# include <com/sun/star/document/XDocumentInfoSupplier.hpp>
# endif
# ifndef _COM_SUN_STAR_DOCUMENT_MACROEXECMODE_HPP_
# include <com/sun/star/document/MacroExecMode.hpp>
# endif
2006-01-03 15:14:52 +00:00
# ifndef _COM_SUN_STAR_DRAWING_XDRAWPAGESUPPLIER_HPP_
# include <com/sun/star/drawing/XDrawPageSupplier.hpp>
# endif
# ifndef _COM_SUN_STAR_CONTAINER_XINDEXCONTAINER_HPP_
# include <com/sun/star/container/XIndexContainer.hpp>
# endif
# ifndef _COM_SUN_STAR_FORM_XFORMSSUPPLIER_HPP_
# include <com/sun/star/form/XFormsSupplier.hpp>
# endif
# ifndef _COM_SUN_STAR_FORM_XFORM_HPP_
# include <com/sun/star/form/XForm.hpp>
# endif
2004-08-02 14:10:37 +00:00
# ifndef _COMPHELPER_INTERACTION_HXX_
# include <comphelper/interaction.hxx>
# endif
# ifndef _CONNECTIVITY_DBTOOLS_HXX_
# include <connectivity/dbtools.hxx>
# endif
# ifndef _SV_SVAPP_HXX
# include <vcl/svapp.hxx>
# endif
# ifndef _VOS_MUTEX_HXX_
# include <vos/mutex.hxx>
# endif
# ifndef _COM_SUN_STAR_VIEW_XVIEWSETTINGSSUPPLIER_HPP_
# include <com/sun/star/view/XViewSettingsSupplier.hpp>
# endif
# ifndef _DBA_CORE_RESOURCE_HXX_
# include "core_resource.hxx"
# endif
# ifndef _DBA_CORE_RESOURCE_HRC_
# include "core_resource.hrc"
# endif
# ifndef _DBA_COREDATAACCESS_DATASOURCE_HXX_
# include "datasource.hxx"
# endif
# ifndef _COM_SUN_STAR_EMBED_XSTATECHANGEBROADCASTER_HPP_
# include <com/sun/star/embed/XStateChangeBroadcaster.hpp>
# endif
# ifndef _COM_SUN_STAR_TASK_XINTERACTIONAPPROVE_HPP_
# include <com/sun/star/task/XInteractionApprove.hpp>
# endif
# ifndef _COM_SUN_STAR_TASK_XINTERACTIONDISAPPROVE_HPP_
# include <com/sun/star/task/XInteractionDisapprove.hpp>
# endif
2005-03-16 14:49:18 +00:00
# ifndef _COM_SUN_STAR_FRAME_XLAYOUTMANAGER_HPP_
# include <com/sun/star/frame/XLayoutManager.hpp>
2005-03-15 10:33:00 +00:00
# endif
2004-08-02 14:10:37 +00:00
# ifndef _CPPUHELPER_COMPBASE1_HXX_
# include <cppuhelper/compbase1.hxx>
# endif
# ifndef _COM_SUN_STAR_FRAME_FRAMESEARCHFLAG_HPP_
# include <com/sun/star/frame/FrameSearchFlag.hpp>
# endif
2005-01-05 11:28:50 +00:00
# ifndef _COMPHELPER_SEQUENCEASHASHMAP_HXX_
# include <comphelper/sequenceashashmap.hxx>
# endif
2007-07-06 06:54:16 +00:00
# ifndef _COMPHELPER_MIMECONFIGHELPER_HXX_
# include <comphelper/mimeconfighelper.hxx>
# endif
# ifndef _COMPHELPER_STORAGEHELPER_HXX
# include <comphelper/storagehelper.hxx>
# endif
2000-09-18 23:16:46 +00:00
2007-07-06 06:54:16 +00:00
using namespace : : com : : sun : : star ;
2004-08-02 14:10:37 +00:00
using namespace : : com : : sun : : star : : view ;
2000-09-18 23:16:46 +00:00
using namespace : : com : : sun : : star : : uno ;
using namespace : : com : : sun : : star : : util ;
2004-08-02 14:10:37 +00:00
using namespace : : com : : sun : : star : : ucb ;
2000-09-18 23:16:46 +00:00
using namespace : : com : : sun : : star : : beans ;
2004-08-02 14:10:37 +00:00
using namespace : : com : : sun : : star : : lang ;
using namespace : : com : : sun : : star : : awt ;
using namespace : : com : : sun : : star : : embed ;
using namespace : : com : : sun : : star : : frame ;
using namespace : : com : : sun : : star : : document ;
using namespace : : com : : sun : : star : : sdbc ;
using namespace : : com : : sun : : star : : sdb ;
using namespace : : com : : sun : : star : : io ;
using namespace : : com : : sun : : star : : container ;
using namespace : : com : : sun : : star : : datatransfer ;
using namespace : : com : : sun : : star : : task ;
2006-01-03 15:14:52 +00:00
using namespace : : com : : sun : : star : : form ;
using namespace : : com : : sun : : star : : drawing ;
2000-09-18 23:16:46 +00:00
using namespace : : osl ;
2000-10-11 10:21:40 +00:00
using namespace : : comphelper ;
2000-09-18 23:16:46 +00:00
using namespace : : cppu ;
2005-03-10 15:35:30 +00:00
namespace css = : : com : : sun : : star ;
2000-10-18 15:16:39 +00:00
2005-01-05 11:28:50 +00:00
# define DEFAULT_WIDTH 15000
# define DEFAULT_HEIGHT 10000
2000-10-18 15:16:39 +00:00
//........................................................................
namespace dbaccess
{
2005-10-24 07:29:02 +00:00
//==================================================================
// OEmbedObjectHolder
//==================================================================
typedef : : cppu : : WeakComponentImplHelper1 < : : com : : sun : : star : : embed : : XStateChangeListener > TEmbedObjectHolder ;
class OEmbedObjectHolder : public : : comphelper : : OBaseMutex
, public TEmbedObjectHolder
{
Reference < XEmbeddedObject > m_xBroadCaster ;
ODocumentDefinition * m_pDefinition ;
sal_Bool m_bInStateChange ;
protected :
virtual void SAL_CALL disposing ( ) ;
public :
OEmbedObjectHolder ( const Reference < XEmbeddedObject > & _xBroadCaster , ODocumentDefinition * _pDefinition )
: TEmbedObjectHolder ( m_aMutex )
, m_xBroadCaster ( _xBroadCaster )
, m_pDefinition ( _pDefinition )
, m_bInStateChange ( sal_False )
2004-08-02 14:10:37 +00:00
{
2005-10-24 07:29:02 +00:00
osl_incrementInterlockedCount ( & m_refCount ) ;
2004-08-02 14:10:37 +00:00
{
if ( m_xBroadCaster . is ( ) )
m_xBroadCaster - > addStateChangeListener ( this ) ;
}
2005-10-24 07:29:02 +00:00
osl_decrementInterlockedCount ( & m_refCount ) ;
2004-08-02 14:10:37 +00:00
}
2005-10-24 07:29:02 +00:00
virtual void SAL_CALL changingState ( const : : com : : sun : : star : : lang : : EventObject & aEvent , : : sal_Int32 nOldState , : : sal_Int32 nNewState ) throw ( : : com : : sun : : star : : embed : : WrongStateException , : : com : : sun : : star : : uno : : RuntimeException ) ;
virtual void SAL_CALL stateChanged ( const : : com : : sun : : star : : lang : : EventObject & aEvent , : : sal_Int32 nOldState , : : sal_Int32 nNewState ) throw ( : : com : : sun : : star : : uno : : RuntimeException ) ;
virtual void SAL_CALL disposing ( const : : com : : sun : : star : : lang : : EventObject & Source ) throw ( : : com : : sun : : star : : uno : : RuntimeException ) ;
} ;
//------------------------------------------------------------------
void SAL_CALL OEmbedObjectHolder : : disposing ( )
{
if ( m_xBroadCaster . is ( ) )
m_xBroadCaster - > removeStateChangeListener ( this ) ;
m_xBroadCaster = NULL ;
m_pDefinition = NULL ;
}
//------------------------------------------------------------------
2006-06-20 01:45:23 +00:00
void SAL_CALL OEmbedObjectHolder : : changingState ( const : : com : : sun : : star : : lang : : EventObject & /*aEvent*/ , : : sal_Int32 /*nOldState*/ , : : sal_Int32 /*nNewState*/ ) throw ( : : com : : sun : : star : : embed : : WrongStateException , : : com : : sun : : star : : uno : : RuntimeException )
2005-10-24 07:29:02 +00:00
{
}
//------------------------------------------------------------------
void SAL_CALL OEmbedObjectHolder : : stateChanged ( const : : com : : sun : : star : : lang : : EventObject & aEvent , : : sal_Int32 nOldState , : : sal_Int32 nNewState ) throw ( : : com : : sun : : star : : uno : : RuntimeException )
{
if ( ! m_bInStateChange & & nNewState = = EmbedStates : : RUNNING & & nOldState = = EmbedStates : : ACTIVE & & m_pDefinition )
2004-08-02 14:10:37 +00:00
{
2005-10-24 07:29:02 +00:00
m_bInStateChange = sal_True ;
Reference < XInterface > xInt ( static_cast < : : cppu : : OWeakObject * > ( m_pDefinition ) , UNO_QUERY ) ;
2004-08-02 14:10:37 +00:00
{
2005-10-24 07:29:02 +00:00
Reference < XEmbeddedObject > xEmbeddedObject ( aEvent . Source , UNO_QUERY ) ;
if ( xEmbeddedObject . is ( ) )
xEmbeddedObject - > changeState ( EmbedStates : : LOADED ) ;
2004-08-02 14:10:37 +00:00
}
2005-10-24 07:29:02 +00:00
m_bInStateChange = sal_False ;
2004-08-02 14:10:37 +00:00
}
2005-10-24 07:29:02 +00:00
}
//------------------------------------------------------------------
2006-06-20 01:45:23 +00:00
void SAL_CALL OEmbedObjectHolder : : disposing ( const : : com : : sun : : star : : lang : : EventObject & /*Source*/ ) throw ( : : com : : sun : : star : : uno : : RuntimeException )
2005-10-24 07:29:02 +00:00
{
m_xBroadCaster = NULL ;
}
//==================================================================
// OEmbeddedClientHelper
//==================================================================
typedef : : cppu : : WeakImplHelper1 < XEmbeddedClient
> EmbeddedClientHelper_BASE ;
2004-08-02 14:10:37 +00:00
class OEmbeddedClientHelper : public EmbeddedClientHelper_BASE
{
ODocumentDefinition * m_pClient ;
public :
OEmbeddedClientHelper ( ODocumentDefinition * _pClient ) : m_pClient ( _pClient ) { }
2000-10-18 15:16:39 +00:00
2004-08-02 14:10:37 +00:00
virtual void SAL_CALL saveObject ( ) throw ( ObjectSaveVetoException , Exception , RuntimeException )
{
}
2006-06-20 01:45:23 +00:00
virtual void SAL_CALL onShowWindow ( sal_Bool /*bVisible*/ ) throw ( RuntimeException )
2004-08-02 14:10:37 +00:00
{
}
// XComponentSupplier
virtual Reference < : : com : : sun : : star : : util : : XCloseable > SAL_CALL getComponent ( ) throw ( RuntimeException )
{
2005-12-21 12:36:04 +00:00
return Reference < css : : util : : XCloseable > ( ) ;
2004-08-02 14:10:37 +00:00
}
2000-09-18 23:16:46 +00:00
2004-08-02 14:10:37 +00:00
// XEmbeddedClient
2006-06-20 01:45:23 +00:00
virtual void SAL_CALL visibilityChanged ( : : sal_Bool /*bVisible*/ ) throw ( WrongStateException , RuntimeException )
2004-08-02 14:10:37 +00:00
{
}
inline void resetClient ( ODocumentDefinition * _pClient ) { m_pClient = _pClient ; }
} ;
2005-10-24 07:29:02 +00:00
//==================================================================
// LifetimeCoupler
//==================================================================
typedef : : cppu : : WeakImplHelper1 < css : : lang : : XEventListener
> LifetimeCoupler_Base ;
/** helper class which couples the lifetime of a component to the lifetim
of another component
Instances of this class are constructed with two components . The first is
simply held by reference , and thus kept alive . The second one is observed
for < code > disposing < / code > calls - if they occur , i . e . if the component dies ,
the reference to the first component is cleared .
This way , you can ensure that a certain component is kept alive as long
as a second component is not disposed .
*/
class LifetimeCoupler : public LifetimeCoupler_Base
{
private :
Reference < XInterface > m_xClient ;
public :
2005-10-24 08:03:01 +00:00
inline static void couple ( const Reference < XInterface > & _rxClient , const Reference < XComponent > & _rxActor )
2005-10-24 07:29:02 +00:00
{
Reference < css : : lang : : XEventListener > xEnsureDelete ( new LifetimeCoupler ( _rxClient , _rxActor ) ) ;
}
private :
inline LifetimeCoupler ( const Reference < XInterface > & _rxClient , const Reference < XComponent > & _rxActor )
: m_xClient ( _rxClient )
{
DBG_ASSERT ( _rxActor . is ( ) , " LifetimeCoupler::LifetimeCoupler: this will crash! " ) ;
osl_incrementInterlockedCount ( & m_refCount ) ;
{
_rxActor - > addEventListener ( this ) ;
}
osl_decrementInterlockedCount ( & m_refCount ) ;
DBG_ASSERT ( m_refCount , " LifetimeCoupler::LifetimeCoupler: the actor is not holding us by hard ref - this won't work! " ) ;
}
virtual void SAL_CALL disposing ( const css : : lang : : EventObject & Source ) throw ( RuntimeException ) ;
protected :
} ;
//------------------------------------------------------------------
2006-06-20 01:45:23 +00:00
void SAL_CALL LifetimeCoupler : : disposing ( const css : : lang : : EventObject & /*Source*/ ) throw ( RuntimeException )
2005-10-24 07:29:02 +00:00
{
m_xClient . clear ( ) ;
}
2004-08-02 14:10:37 +00:00
//==================================================================
// ODocumentSaveContinuation
//==================================================================
class ODocumentSaveContinuation : public OInteraction < XInteractionDocumentSave >
{
: : rtl : : OUString m_sName ;
Reference < XContent > m_xParentContainer ;
2000-09-18 23:16:46 +00:00
2004-08-02 14:10:37 +00:00
public :
ODocumentSaveContinuation ( ) { }
inline Reference < XContent > getContent ( ) const { return m_xParentContainer ; }
inline : : rtl : : OUString getName ( ) const { return m_sName ; }
// XInteractionDocumentSave
virtual void SAL_CALL setName ( const : : rtl : : OUString & _sName , const Reference < XContent > & _xParent ) throw ( RuntimeException ) ;
} ;
//------------------------------------------------------------------
void SAL_CALL ODocumentSaveContinuation : : setName ( const : : rtl : : OUString & _sName , const Reference < XContent > & _xParent ) throw ( RuntimeException )
{
m_sName = _sName ;
m_xParentContainer = _xParent ;
}
2007-07-06 06:54:16 +00:00
: : rtl : : OUString ODocumentDefinition : : GetDocumentServiceFromMediaType ( const Reference < XStorage > & xStorage
, const : : rtl : : OUString & sEntName
, const Reference < XMultiServiceFactory > & _xORB
, Sequence < sal_Int8 > & _rClassId
)
2001-02-07 12:15:00 +00:00
{
2004-08-02 14:10:37 +00:00
: : rtl : : OUString sResult ;
try
{
if ( xStorage - > isStorageElement ( sEntName ) )
{
// the object must be based on storage
2001-02-07 12:15:00 +00:00
2004-08-02 14:10:37 +00:00
Reference < XPropertySet > xPropSet ( xStorage - > openStorageElement ( sEntName , ElementModes : : READ ) , UNO_QUERY ) ;
if ( ! xPropSet . is ( ) )
throw RuntimeException ( ) ;
: : rtl : : OUString aMediaType ;
try {
Any aAny = xPropSet - > getPropertyValue ( : : rtl : : OUString : : createFromAscii ( " MediaType " ) ) ;
aAny > > = aMediaType ;
}
catch ( Exception & )
{
}
2007-07-06 06:54:16 +00:00
: : comphelper : : MimeConfigurationHelper aConfigHelper ( _xORB ) ;
sResult = aConfigHelper . GetDocServiceNameFromMediaType ( aMediaType ) ;
_rClassId = aConfigHelper . GetSequenceClassIDRepresentation ( aConfigHelper . GetExplicitlyRegisteredObjClassID ( aMediaType ) ) ;
if ( ! _rClassId . getLength ( ) & & sResult . getLength ( ) )
{
Reference < XNameAccess > xObjConfig = aConfigHelper . GetObjConfiguration ( ) ;
if ( xObjConfig . is ( ) )
{
try
{
Sequence < : : rtl : : OUString > aClassIDs = xObjConfig - > getElementNames ( ) ;
for ( sal_Int32 nInd = 0 ; nInd < aClassIDs . getLength ( ) ; nInd + + )
{
Reference < XNameAccess > xObjectProps ;
: : rtl : : OUString aEntryDocName ;
if ( ( xObjConfig - > getByName ( aClassIDs [ nInd ] ) > > = xObjectProps ) & & xObjectProps . is ( )
& & ( xObjectProps - > getByName ( : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " ObjectDocumentServiceName " ) )
) > > = aEntryDocName )
& & aEntryDocName . equals ( sResult ) )
{
_rClassId = aConfigHelper . GetSequenceClassIDRepresentation ( aClassIDs [ nInd ] ) ;
break ;
}
}
}
catch ( Exception & )
{ }
}
}
2004-08-02 14:10:37 +00:00
try
{
: : comphelper : : disposeComponent ( xPropSet ) ;
}
catch ( Exception & )
{
}
}
}
catch ( Exception & )
{
}
return sResult ;
}
// -----------------------------------------------------------------------------
//==========================================================================
//= ODocumentDefinition
//==========================================================================
DBG_NAME ( ODocumentDefinition )
2000-09-18 23:16:46 +00:00
//--------------------------------------------------------------------------
2004-08-02 14:10:37 +00:00
ODocumentDefinition : : ODocumentDefinition ( const Reference < XInterface > & _rxContainer
, const Reference < XMultiServiceFactory > & _xORB
, const TContentPtr & _pImpl
, sal_Bool _bForm
, const Sequence < sal_Int8 > & _aClassID
, const Reference < XConnection > & _xConnection
)
: OContentHelper ( _xORB , _rxContainer , _pImpl )
, OPropertyStateContainer ( m_aBHelper )
, m_pInterceptor ( NULL )
, m_bForm ( _bForm )
2005-01-21 16:04:28 +00:00
, m_bOpenInDesign ( sal_False )
2005-09-23 11:06:25 +00:00
, m_bInExecute ( sal_False )
2006-06-20 01:45:23 +00:00
, m_pClientHelper ( NULL )
2000-09-18 23:16:46 +00:00
{
DBG_CTOR ( ODocumentDefinition , NULL ) ;
2004-08-02 14:10:37 +00:00
registerProperties ( ) ;
if ( _aClassID . getLength ( ) )
loadEmbeddedObject ( _aClassID , _xConnection ) ;
2000-09-18 23:16:46 +00:00
}
//--------------------------------------------------------------------------
ODocumentDefinition : : ~ ODocumentDefinition ( )
{
DBG_DTOR ( ODocumentDefinition , NULL ) ;
2004-08-02 14:10:37 +00:00
if ( ! m_aBHelper . bInDispose & & ! m_aBHelper . bDisposed )
{
acquire ( ) ;
dispose ( ) ;
}
2000-09-18 23:16:46 +00:00
2004-08-02 14:10:37 +00:00
if ( m_pInterceptor )
{
2005-10-24 07:29:02 +00:00
m_pInterceptor - > dispose ( ) ;
2004-08-02 14:10:37 +00:00
m_pInterceptor - > release ( ) ;
m_pInterceptor = NULL ;
}
}
// -----------------------------------------------------------------------------
void ODocumentDefinition : : closeObject ( )
2000-09-18 23:16:46 +00:00
{
2004-08-02 14:10:37 +00:00
: : osl : : MutexGuard aGuard ( m_aMutex ) ;
if ( m_xEmbeddedObject . is ( ) )
{
try
{
Reference < com : : sun : : star : : util : : XCloseable > xCloseable ( m_xEmbeddedObject , UNO_QUERY ) ;
if ( xCloseable . is ( ) )
xCloseable - > close ( sal_True ) ;
}
catch ( Exception )
{
}
m_xEmbeddedObject = NULL ;
if ( m_pClientHelper )
2004-12-03 13:34:52 +00:00
{
2004-08-02 14:10:37 +00:00
m_pClientHelper - > resetClient ( NULL ) ;
2004-12-03 13:34:52 +00:00
m_pClientHelper - > release ( ) ;
m_pClientHelper = NULL ;
}
2004-08-02 14:10:37 +00:00
}
2000-09-18 23:16:46 +00:00
}
2004-08-02 14:10:37 +00:00
// -----------------------------------------------------------------------------
void SAL_CALL ODocumentDefinition : : disposing ( )
2000-09-18 23:16:46 +00:00
{
2004-08-02 14:10:37 +00:00
OContentHelper : : disposing ( ) ;
: : osl : : MutexGuard aGuard ( m_aMutex ) ;
closeObject ( ) ;
: : comphelper : : disposeComponent ( m_xListener ) ;
2006-02-07 09:19:11 +00:00
m_xDesktop = NULL ;
2000-09-18 23:16:46 +00:00
}
2004-08-02 14:10:37 +00:00
// -----------------------------------------------------------------------------
IMPLEMENT_TYPEPROVIDER3 ( ODocumentDefinition , OContentHelper , OPropertyStateContainer , ODocumentDefinition_Base ) ;
IMPLEMENT_FORWARD_XINTERFACE3 ( ODocumentDefinition , OContentHelper , OPropertyStateContainer , ODocumentDefinition_Base )
IMPLEMENT_SERVICE_INFO1 ( ODocumentDefinition , " com.sun.star.comp.dba.ODocumentDefinition " , SERVICE_SDB_DOCUMENTDEFINITION )
2000-09-18 23:16:46 +00:00
//--------------------------------------------------------------------------
2004-08-02 14:10:37 +00:00
void ODocumentDefinition : : registerProperties ( )
2000-09-18 23:16:46 +00:00
{
2004-08-02 14:10:37 +00:00
registerProperty ( PROPERTY_NAME , PROPERTY_ID_NAME , PropertyAttribute : : BOUND | PropertyAttribute : : READONLY | PropertyAttribute : : CONSTRAINED ,
& m_pImpl - > m_aProps . aTitle , : : getCppuType ( & m_pImpl - > m_aProps . aTitle ) ) ;
registerProperty ( PROPERTY_AS_TEMPLATE , PROPERTY_ID_AS_TEMPLATE , PropertyAttribute : : BOUND | PropertyAttribute : : READONLY | PropertyAttribute : : CONSTRAINED ,
& m_pImpl - > m_aProps . bAsTemplate , : : getCppuType ( & m_pImpl - > m_aProps . bAsTemplate ) ) ;
registerProperty ( PROPERTY_PERSISTENT_NAME , PROPERTY_ID_PERSISTENT_NAME , PropertyAttribute : : BOUND | PropertyAttribute : : READONLY | PropertyAttribute : : CONSTRAINED ,
& m_pImpl - > m_aProps . sPersistentName , : : getCppuType ( & m_pImpl - > m_aProps . sPersistentName ) ) ;
registerProperty ( : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " IsForm " ) ) , PROPERTY_ID_IS_FORM , PropertyAttribute : : BOUND | PropertyAttribute : : READONLY | PropertyAttribute : : CONSTRAINED ,
& m_bForm , : : getCppuType ( & m_bForm ) ) ;
2000-09-18 23:16:46 +00:00
}
2004-08-02 14:10:37 +00:00
// -----------------------------------------------------------------------------
Reference < XPropertySetInfo > SAL_CALL ODocumentDefinition : : getPropertySetInfo ( ) throw ( RuntimeException )
2000-09-18 23:16:46 +00:00
{
2004-08-02 14:10:37 +00:00
Reference < XPropertySetInfo > xInfo ( createPropertySetInfo ( getInfoHelper ( ) ) ) ;
return xInfo ;
2000-09-18 23:16:46 +00:00
}
//--------------------------------------------------------------------------
2004-08-02 14:10:37 +00:00
IPropertyArrayHelper & ODocumentDefinition : : getInfoHelper ( )
2000-09-18 23:16:46 +00:00
{
2004-08-02 14:10:37 +00:00
return * getArrayHelper ( ) ;
2000-09-18 23:16:46 +00:00
}
2004-08-02 14:10:37 +00:00
2000-09-18 23:16:46 +00:00
//--------------------------------------------------------------------------
2004-08-02 14:10:37 +00:00
IPropertyArrayHelper * ODocumentDefinition : : createArrayHelper ( ) const
2000-09-18 23:16:46 +00:00
{
2004-08-02 14:10:37 +00:00
Sequence < Property > aProps ;
describeProperties ( aProps ) ;
return new OPropertyArrayHelper ( aProps ) ;
2000-09-18 23:16:46 +00:00
}
2005-09-23 11:06:25 +00:00
class OExecuteImpl
{
sal_Bool & m_rbSet ;
public :
OExecuteImpl ( sal_Bool & _rbSet ) : m_rbSet ( _rbSet ) { m_rbSet = sal_True ; }
~ OExecuteImpl ( ) { m_rbSet = sal_False ; }
} ;
// -----------------------------------------------------------------------------
namespace
{
bool lcl_extractOpenMode ( const Any & _rValue , sal_Int32 & /* [out] */ _rMode )
{
OpenCommandArgument aOpenCommand ;
if ( _rValue > > = aOpenCommand )
_rMode = aOpenCommand . Mode ;
else
{
2006-06-20 01:45:23 +00:00
OpenCommandArgument2 aOpenCommand2 ;
if ( _rValue > > = aOpenCommand2 )
_rMode = aOpenCommand2 . Mode ;
2005-09-23 11:06:25 +00:00
else
return false ;
}
return true ;
}
}
2006-02-07 09:19:11 +00:00
// -----------------------------------------------------------------------------
void ODocumentDefinition : : impl_removeFrameFromDesktop_throw ( const Reference < XFrame > & _rxFrame )
{
if ( ! m_xDesktop . is ( ) )
m_xDesktop . set ( m_xORB - > createInstance ( SERVICE_FRAME_DESKTOP ) , UNO_QUERY_THROW ) ;
Reference < XFrames > xFrames ( m_xDesktop - > getFrames ( ) , UNO_QUERY_THROW ) ;
xFrames - > remove ( _rxFrame ) ;
}
2007-04-16 15:24:31 +00:00
// -----------------------------------------------------------------------------
void ODocumentDefinition : : impl_appendFrameToDocumentFrames_throw ( const Reference < XFrame > & _rxFrame )
{
Reference < XModel > xDatabaseDocumentModel ;
if ( m_pImpl - > m_pDataSource )
xDatabaseDocumentModel = m_pImpl - > m_pDataSource - > getModel_noCreate ( ) ;
Reference < XController > xDatabaseDocumentController ;
if ( xDatabaseDocumentModel . is ( ) )
xDatabaseDocumentController = xDatabaseDocumentModel - > getCurrentController ( ) ;
Reference < XFramesSupplier > xDatabaseDocumentFramesSupp ;
if ( xDatabaseDocumentController . is ( ) )
xDatabaseDocumentFramesSupp = xDatabaseDocumentFramesSupp . query ( xDatabaseDocumentController - > getFrame ( ) ) ;
Reference < XFrames > xDatabaseDocumentFrames ;
if ( xDatabaseDocumentFramesSupp . is ( ) )
xDatabaseDocumentFrames = xDatabaseDocumentFramesSupp - > getFrames ( ) ;
OSL_ENSURE ( xDatabaseDocumentFrames . is ( ) , " ODocumentDefinition::impl_appendFrameToDocumentFrames_throw: cannot append the component frame to the document's frame! " ) ;
if ( xDatabaseDocumentFrames . is ( ) )
xDatabaseDocumentFrames - > append ( _rxFrame ) ;
}
2005-10-24 07:29:02 +00:00
// -----------------------------------------------------------------------------
void ODocumentDefinition : : impl_onActivateEmbeddedObject ( bool _bOpenedInDesignMode )
{
try
{
Reference < XModel > xModel ( getComponent ( ) , UNO_QUERY ) ;
Reference < XController > xController ( xModel . is ( ) ? xModel - > getCurrentController ( ) : Reference < XController > ( ) ) ;
if ( ! xController . is ( ) )
return ;
2006-02-07 09:19:11 +00:00
if ( ! m_xListener . is ( ) )
2005-10-24 07:29:02 +00:00
// it's the first time the embedded object has been activated
// create an OEmbedObjectHolder
m_xListener = new OEmbedObjectHolder ( m_xEmbeddedObject , this ) ;
2006-02-07 09:19:11 +00:00
Reference < XFrame > xFrame ( xController - > getFrame ( ) ) ;
if ( xFrame . is ( ) )
{
2007-04-16 15:24:31 +00:00
// raise the window to top (especially necessary if this is not the first activation)
2006-02-07 09:19:11 +00:00
Reference < XTopWindow > xTopWindow ( xFrame - > getContainerWindow ( ) , UNO_QUERY_THROW ) ;
xTopWindow - > toFront ( ) ;
2007-04-16 15:24:31 +00:00
// remove the frame from the desktop's frame collection because we need full control of it.
impl_removeFrameFromDesktop_throw ( xFrame ) ;
// ensure that the component's frame is a child of the database document's frame
impl_appendFrameToDocumentFrames_throw ( xFrame ) ;
2005-10-24 07:29:02 +00:00
}
2006-02-07 09:19:11 +00:00
// ensure that we ourself are kept alive as long as the embedded object's frame is
// opened
LifetimeCoupler : : couple ( * this , Reference < XComponent > ( xFrame , UNO_QUERY_THROW ) ) ;
// init the edit view
2005-10-24 07:29:02 +00:00
if ( _bOpenedInDesignMode )
impl_initObjectEditView ( xController ) ;
}
2006-02-07 09:19:11 +00:00
catch ( const RuntimeException & )
2005-10-24 07:29:02 +00:00
{
2006-02-07 09:19:11 +00:00
DBG_UNHANDLED_EXCEPTION ( ) ;
2005-10-24 07:29:02 +00:00
}
}
// -----------------------------------------------------------------------------
namespace
{
// =========================================================================
// = PreserveVisualAreaSize
// =========================================================================
/** stack-guard for preserving the size of the VisArea of an XModel
*/
class PreserveVisualAreaSize
{
private :
Reference < XVisualObject > m_xVisObject ;
: : com : : sun : : star : : awt : : Size m_aOriginalSize ;
public :
inline PreserveVisualAreaSize ( const Reference < XModel > & _rxModel )
: m_xVisObject ( _rxModel , UNO_QUERY )
{
if ( m_xVisObject . is ( ) )
{
try
{
m_aOriginalSize = m_xVisObject - > getVisualAreaSize ( Aspects : : MSOLE_CONTENT ) ;
}
catch ( Exception & )
{
DBG_ERROR ( " PreserveVisualAreaSize::PreserveVisualAreaSize: caught an exception! " ) ;
}
}
}
inline ~ PreserveVisualAreaSize ( )
{
if ( m_xVisObject . is ( ) & & m_aOriginalSize . Width & & m_aOriginalSize . Height )
{
try
{
m_xVisObject - > setVisualAreaSize ( Aspects : : MSOLE_CONTENT , m_aOriginalSize ) ;
}
catch ( Exception & )
{
DBG_ERROR ( " PreserveVisualAreaSize::~PreserveVisualAreaSize: caught an exception! " ) ;
}
}
}
} ;
// =========================================================================
// = LayoutManagerLock
// =========================================================================
/** helper class for stack-usage which during its lifetime locks a layout manager
*/
class LayoutManagerLock
{
private :
Reference < XLayoutManager > m_xLayoutManager ;
public :
inline LayoutManagerLock ( const Reference < XController > & _rxController )
{
DBG_ASSERT ( _rxController . is ( ) , " LayoutManagerLock::LayoutManagerLock: this will crash! " ) ;
Reference < XFrame > xFrame ( _rxController - > getFrame ( ) ) ;
try
{
Reference < XPropertySet > xPropSet ( xFrame , UNO_QUERY_THROW ) ;
m_xLayoutManager . set (
xPropSet - > getPropertyValue ( : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " LayoutManager " ) ) ) ,
UNO_QUERY_THROW ) ;
m_xLayoutManager - > lock ( ) ;
}
catch ( Exception & )
{
DBG_ERROR ( " LayoutManagerLock::LayoutManagerLock: caught an exception! " ) ;
}
}
inline ~ LayoutManagerLock ( )
{
try
{
// unlock the layout manager
if ( m_xLayoutManager . is ( ) )
m_xLayoutManager - > unlock ( ) ;
}
catch ( Exception & )
{
DBG_ERROR ( " LayoutManagerLock::~LayoutManagerLock: caught an exception! " ) ;
}
}
} ;
}
// -----------------------------------------------------------------------------
void ODocumentDefinition : : impl_initObjectEditView ( const Reference < XController > & _rxController )
{
if ( ! m_bForm )
// currently, only forms need to be initialized
return ;
try
{
Reference < XViewSettingsSupplier > xSettingsSupplier ( _rxController , UNO_QUERY_THROW ) ;
Reference < XPropertySet > xViewSettings ( xSettingsSupplier - > getViewSettings ( ) , UNO_QUERY_THROW ) ;
// The visual area size can be changed by the setting of the following properties
// so it should be restored later
PreserveVisualAreaSize aPreserveVisAreaSize ( _rxController - > getModel ( ) ) ;
// Layout manager should not layout while the size is still not restored
// so it will stay locked for this time
LayoutManagerLock aLockLayout ( _rxController ) ;
// setting of the visual properties
xViewSettings - > setPropertyValue ( : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " ShowRulers " ) ) , makeAny ( sal_True ) ) ;
xViewSettings - > setPropertyValue ( : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " ShowVertRuler " ) ) , makeAny ( sal_True ) ) ;
xViewSettings - > setPropertyValue ( : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " ShowHoriRuler " ) ) , makeAny ( sal_True ) ) ;
xViewSettings - > setPropertyValue ( : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " IsRasterVisible " ) ) , makeAny ( sal_True ) ) ;
xViewSettings - > setPropertyValue ( : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " IsSnapToRaster " ) ) , makeAny ( sal_True ) ) ;
xViewSettings - > setPropertyValue ( : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " ShowOnlineLayout " ) ) , makeAny ( sal_True ) ) ;
xViewSettings - > setPropertyValue ( : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " RasterSubdivisionX " ) ) , makeAny ( sal_Int32 ( 5 ) ) ) ;
xViewSettings - > setPropertyValue ( : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " RasterSubdivisionY " ) ) , makeAny ( sal_Int32 ( 5 ) ) ) ;
Reference < XModifiable > xModifiable ( _rxController - > getModel ( ) , UNO_QUERY_THROW ) ;
xModifiable - > setModified ( sal_False ) ;
}
2006-06-20 01:45:23 +00:00
catch ( const Exception & )
2005-10-24 07:29:02 +00:00
{
2006-06-20 01:45:23 +00:00
DBG_UNHANDLED_EXCEPTION ( ) ;
2005-10-24 07:29:02 +00:00
}
}
2004-08-02 14:10:37 +00:00
// -----------------------------------------------------------------------------
Any SAL_CALL ODocumentDefinition : : execute ( const Command & aCommand , sal_Int32 CommandId , const Reference < XCommandEnvironment > & Environment ) throw ( Exception , CommandAbortedException , RuntimeException )
2000-09-18 23:16:46 +00:00
{
2004-08-02 14:10:37 +00:00
Any aRet ;
: : osl : : MutexGuard aGuard ( m_aMutex ) ;
2005-09-23 11:06:25 +00:00
if ( ! m_bInExecute )
2004-08-02 14:10:37 +00:00
{
2005-09-23 11:06:25 +00:00
OExecuteImpl aExecuteGuard ( m_bInExecute ) ;
sal_Bool bOpenInDesign = aCommand . Name . equalsAscii ( " openDesign " ) ;
sal_Bool bOpenForMail = aCommand . Name . equalsAscii ( " openForMail " ) ;
if ( aCommand . Name . compareToAscii ( " open " ) = = 0 | | bOpenInDesign | | bOpenForMail )
2004-08-02 14:10:37 +00:00
{
2005-09-23 11:06:25 +00:00
//////////////////////////////////////////////////////////////////
// open command for a folder content
//////////////////////////////////////////////////////////////////
Reference < XConnection > xConnection ;
sal_Int32 nOpenMode = OpenMode : : DOCUMENT ;
lcl_extractOpenMode ( aCommand . Argument , nOpenMode ) ;
Sequence < PropertyValue > aArguments ;
if ( aCommand . Argument > > = aArguments )
2004-08-02 14:10:37 +00:00
{
2005-09-23 11:06:25 +00:00
const PropertyValue * pIter = aArguments . getConstArray ( ) ;
const PropertyValue * pEnd = pIter + aArguments . getLength ( ) ;
2004-08-02 14:10:37 +00:00
for ( ; pIter ! = pEnd ; + + pIter )
{
if ( pIter - > Name = = PROPERTY_ACTIVECONNECTION )
xConnection . set ( pIter - > Value , UNO_QUERY ) ;
2005-09-23 11:06:25 +00:00
else
lcl_extractOpenMode ( pIter - > Value , nOpenMode ) ;
2004-08-02 14:10:37 +00:00
}
}
2005-09-23 11:06:25 +00:00
if ( xConnection . is ( ) )
m_xLastKnownConnection = xConnection ;
if ( ( nOpenMode = = OpenMode : : ALL )
| | ( nOpenMode = = OpenMode : : FOLDERS )
| | ( nOpenMode = = OpenMode : : DOCUMENTS )
| | ( nOpenMode = = OpenMode : : DOCUMENT_SHARE_DENY_NONE )
| | ( nOpenMode = = OpenMode : : DOCUMENT_SHARE_DENY_WRITE )
)
2004-08-02 14:10:37 +00:00
{
2005-09-23 11:06:25 +00:00
// opening as folder is not supported
2004-08-02 14:10:37 +00:00
ucbhelper : : cancelCommandExecution (
2005-09-23 11:06:25 +00:00
makeAny ( UnsupportedOpenModeException (
2004-08-02 14:10:37 +00:00
rtl : : OUString ( ) ,
static_cast < cppu : : OWeakObject * > ( this ) ,
2005-09-23 11:06:25 +00:00
sal_Int16 ( nOpenMode ) ) ) ,
Environment ) ;
// Unreachable
DBG_ERROR ( " unreachable " ) ;
}
2000-09-18 23:16:46 +00:00
2004-08-02 14:10:37 +00:00
Reference < XModel > xModel ;
if ( m_pImpl - > m_aProps . sPersistentName . getLength ( ) )
{
2005-01-21 16:04:28 +00:00
m_bOpenInDesign = bOpenInDesign ;
2004-08-02 14:10:37 +00:00
loadEmbeddedObject ( Sequence < sal_Int8 > ( ) , xConnection , ! bOpenInDesign ) ;
if ( m_xEmbeddedObject . is ( ) )
{
2005-10-24 07:29:02 +00:00
xModel . set ( getComponent ( ) , UNO_QUERY ) ;
2007-07-06 06:54:16 +00:00
Reference < report : : XReportDefinition > xReportDefinition ( xModel , UNO_QUERY ) ;
2005-10-24 07:29:02 +00:00
2007-07-06 06:54:16 +00:00
if ( ! bOpenForMail & & ! ( ! bOpenInDesign & & xReportDefinition . is ( ) ) )
2005-01-21 16:04:28 +00:00
{
2007-04-16 15:24:31 +00:00
Reference < XModule > xModule ( xModel , UNO_QUERY ) ;
if ( xModule . is ( ) )
{
if ( m_bForm )
xModule - > setIdentifier ( : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " com.sun.star.sdb.FormDesign " ) ) ) ;
2007-07-06 06:54:16 +00:00
else if ( ! xReportDefinition . is ( ) )
2007-04-16 15:24:31 +00:00
xModule - > setIdentifier ( : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " com.sun.star.sdb.TextReportDesign " ) ) ) ;
}
2005-01-21 16:04:28 +00:00
m_xEmbeddedObject - > changeState ( EmbedStates : : ACTIVE ) ;
2005-10-24 07:29:02 +00:00
impl_onActivateEmbeddedObject ( bOpenInDesign ) ;
2004-08-02 14:10:37 +00:00
}
2007-07-06 06:54:16 +00:00
else if ( ! bOpenInDesign & & xReportDefinition . is ( ) )
{
// we are in ReadOnly mode
// we would like to open the Writer or Calc with the report direct, without design it.
Reference < report : : XReportEngine > xReportEngine ( m_xORB - > createInstance ( : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " com.sun.star.comp.report.OReportEngineJFree " ) ) ) , UNO_QUERY ) ;
xReportEngine - > setReportDefinition ( xReportDefinition ) ;
xReportEngine - > setActiveConnection ( m_xLastKnownConnection ) ;
aRet < < = xReportEngine - > createDocumentAlive ( NULL ) ;
return aRet ;
}
2005-10-24 07:29:02 +00:00
fillReportData ( ! bOpenInDesign ) ;
aRet < < = xModel ;
2004-08-02 14:10:37 +00:00
}
}
}
2005-09-23 11:06:25 +00:00
else if ( aCommand . Name . equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( " copyTo " ) ) )
{
Sequence < Any > aIni ;
aCommand . Argument > > = aIni ;
if ( aIni . getLength ( ) ! = 2 )
{
OSL_ENSURE ( sal_False , " Wrong argument type! " ) ;
ucbhelper : : cancelCommandExecution (
makeAny ( IllegalArgumentException (
rtl : : OUString ( ) ,
static_cast < cppu : : OWeakObject * > ( this ) ,
- 1 ) ) ,
Environment ) ;
// Unreachable
}
Reference < XStorage > xStorage ( aIni [ 0 ] , UNO_QUERY ) ;
: : rtl : : OUString sPersistentName ;
aIni [ 1 ] > > = sPersistentName ;
loadEmbeddedObject ( Sequence < sal_Int8 > ( ) , Reference < XConnection > ( ) , sal_False ) ;
Reference < XEmbedPersist > xPersist ( m_xEmbeddedObject , UNO_QUERY ) ;
if ( xPersist . is ( ) )
{
xPersist - > storeToEntry ( xStorage , sPersistentName , Sequence < PropertyValue > ( ) , Sequence < PropertyValue > ( ) ) ;
xPersist - > storeOwn ( ) ;
2006-07-13 14:21:45 +00:00
m_xEmbeddedObject - > changeState ( EmbedStates : : LOADED ) ;
2005-09-23 11:06:25 +00:00
}
else
throw CommandAbortedException ( ) ;
}
else if ( aCommand . Name . equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( " preview " ) ) )
2004-08-02 14:10:37 +00:00
{
2005-09-23 11:06:25 +00:00
generateNewImage ( aRet ) ;
2004-08-02 14:10:37 +00:00
}
2005-09-23 11:06:25 +00:00
else if ( aCommand . Name . equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( " insert " ) ) )
2004-08-02 14:10:37 +00:00
{
2005-09-23 11:06:25 +00:00
Sequence < Any > aIni ;
aCommand . Argument > > = aIni ;
if ( aIni . getLength ( ) > 0 & & aIni . getLength ( ) < 2 )
{
OSL_ENSURE ( sal_False , " Wrong argument type! " ) ;
ucbhelper : : cancelCommandExecution (
makeAny ( IllegalArgumentException (
rtl : : OUString ( ) ,
static_cast < cppu : : OWeakObject * > ( this ) ,
- 1 ) ) ,
Environment ) ;
// Unreachable
}
: : rtl : : OUString sURL ;
aIni [ 0 ] > > = sURL ;
insert ( sURL , Environment ) ;
2004-08-02 14:10:37 +00:00
}
2005-09-23 11:06:25 +00:00
else if ( aCommand . Name . equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( " getdocumentinfo " ) ) )
2004-08-02 14:10:37 +00:00
{
2005-09-23 11:06:25 +00:00
fillDocumentInfo ( aRet ) ;
2004-08-02 14:10:37 +00:00
}
2005-09-23 11:06:25 +00:00
else if ( aCommand . Name . equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( " delete " ) ) )
{
//////////////////////////////////////////////////////////////////
// delete
//////////////////////////////////////////////////////////////////
closeObject ( ) ;
Reference < XStorage > xStorage = getStorage ( ) ;
if ( xStorage . is ( ) )
xStorage - > removeElement ( m_pImpl - > m_aProps . sPersistentName ) ;
dispose ( ) ;
}
else
aRet = OContentHelper : : execute ( aCommand , CommandId , Environment ) ;
2004-08-02 14:10:37 +00:00
}
return aRet ;
2000-09-18 23:16:46 +00:00
}
2004-08-02 14:10:37 +00:00
// -----------------------------------------------------------------------------
2006-01-03 15:14:52 +00:00
namespace
{
void lcl_resetChildFormsToEmptyDataSource ( const Reference < XIndexAccess > & _rxFormsContainer )
{
OSL_PRECOND ( _rxFormsContainer . is ( ) , " lcl_resetChildFormsToEmptyDataSource: illegal call! " ) ;
sal_Int32 count = _rxFormsContainer - > getCount ( ) ;
for ( sal_Int32 i = 0 ; i < count ; + + i )
{
Reference < XForm > xForm ( _rxFormsContainer - > getByIndex ( i ) , UNO_QUERY ) ;
if ( ! xForm . is ( ) )
continue ;
// if the element is a form, reset its DataSourceName property to an empty string
try
{
Reference < XPropertySet > xFormProps ( xForm , UNO_QUERY_THROW ) ;
xFormProps - > setPropertyValue ( PROPERTY_DATASOURCENAME , makeAny ( : : rtl : : OUString ( ) ) ) ;
}
catch ( const Exception & )
{
DBG_UNHANDLED_EXCEPTION ( ) ;
}
// if the element is a container itself, step down the component hierarchy
Reference < XIndexAccess > xContainer ( xForm , UNO_QUERY ) ;
if ( xContainer . is ( ) )
lcl_resetChildFormsToEmptyDataSource ( xContainer ) ;
}
}
void lcl_resetFormsToEmptyDataSource ( const Reference < XEmbeddedObject > & _rxEmbeddedObject )
{
try
{
Reference < XComponentSupplier > xCompProv ( _rxEmbeddedObject , UNO_QUERY_THROW ) ;
Reference < XDrawPageSupplier > xSuppPage ( xCompProv - > getComponent ( ) , UNO_QUERY_THROW ) ;
// if this interface does not exist, then either getComponent returned NULL,
// or the document is a multi-page document. The latter is allowed, but currently
// simply not handled by this code, as it would not normally happen.
Reference < XFormsSupplier > xSuppForms ( xSuppPage - > getDrawPage ( ) , UNO_QUERY_THROW ) ;
Reference < XIndexAccess > xForms ( xSuppForms - > getForms ( ) , UNO_QUERY_THROW ) ;
lcl_resetChildFormsToEmptyDataSource ( xForms ) ;
}
catch ( const Exception & )
{
DBG_UNHANDLED_EXCEPTION ( ) ;
}
}
}
// -----------------------------------------------------------------------------
2004-08-02 14:10:37 +00:00
void ODocumentDefinition : : insert ( const : : rtl : : OUString & _sURL , const Reference < XCommandEnvironment > & Environment )
throw ( Exception )
{
osl : : ClearableGuard < osl : : Mutex > aGuard ( m_aMutex ) ;
// Check, if all required properties were set.
if ( ! _sURL . getLength ( ) | | m_xEmbeddedObject . is ( ) )
{
OSL_ENSURE ( sal_False , " Content::insert - property value missing! " ) ;
Sequence < rtl : : OUString > aProps ( 1 ) ;
aProps [ 0 ] = PROPERTY_URL ;
ucbhelper : : cancelCommandExecution (
makeAny ( MissingPropertiesException (
rtl : : OUString ( ) ,
static_cast < cppu : : OWeakObject * > ( this ) ,
aProps ) ) ,
Environment ) ;
// Unreachable
}
if ( ! m_xEmbeddedObject . is ( ) )
{
Reference < XStorage > xStorage = getStorage ( ) ;
if ( xStorage . is ( ) )
{
Reference < XEmbedObjectCreator > xEmbedFactory ( m_xORB - > createInstance ( : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " com.sun.star.embed.EmbeddedObjectCreator " ) ) ) , UNO_QUERY ) ;
if ( xEmbedFactory . is ( ) )
{
Sequence < PropertyValue > aEmpty , aMediaDesc ( 1 ) ;
aMediaDesc [ 0 ] . Name = PROPERTY_URL ;
aMediaDesc [ 0 ] . Value < < = _sURL ;
m_xEmbeddedObject . set ( xEmbedFactory - > createInstanceInitFromMediaDescriptor ( xStorage
, m_pImpl - > m_aProps . sPersistentName
, aMediaDesc
, aEmpty ) , UNO_QUERY ) ;
2006-01-03 15:14:52 +00:00
lcl_resetFormsToEmptyDataSource ( m_xEmbeddedObject ) ;
// #i57669# / 2005-12-01 / frank.schoenheit@sun.com
2004-08-02 14:10:37 +00:00
Reference < XEmbedPersist > xPersist ( m_xEmbeddedObject , UNO_QUERY ) ;
if ( xPersist . is ( ) )
{
xPersist - > storeOwn ( ) ;
}
try
{
Reference < com : : sun : : star : : util : : XCloseable > xCloseable ( m_xEmbeddedObject , UNO_QUERY ) ;
if ( xCloseable . is ( ) )
xCloseable - > close ( sal_True ) ;
}
catch ( Exception )
{
}
m_xEmbeddedObject = NULL ;
}
}
}
2000-09-18 23:16:46 +00:00
2004-08-02 14:10:37 +00:00
// @@@
// storeData();
2000-10-25 06:42:28 +00:00
2004-08-02 14:10:37 +00:00
aGuard . clear ( ) ;
// inserted();
}
// -----------------------------------------------------------------------------
sal_Bool ODocumentDefinition : : save ( sal_Bool _bApprove )
2000-09-18 23:16:46 +00:00
{
2004-08-02 14:10:37 +00:00
// default handling: instantiate an interaction handler and let it handle the parameter request
2005-09-23 11:06:25 +00:00
if ( ! m_bOpenInDesign )
return sal_False ;
2004-08-02 14:10:37 +00:00
try
{
{
: : vos : : OGuard aSolarGuard ( Application : : GetSolarMutex ( ) ) ;
// the request
Reference < XNameAccess > xName ( m_xParentContainer , UNO_QUERY ) ;
DocumentSaveRequest aRequest ;
aRequest . Name = m_pImpl - > m_aProps . aTitle ;
if ( ! aRequest . Name . getLength ( ) )
{
if ( m_bForm )
aRequest . Name = DBACORE_RESSTRING ( RID_STR_FORM ) ;
else
aRequest . Name = DBACORE_RESSTRING ( RID_STR_REPORT ) ;
aRequest . Name = : : dbtools : : createUniqueName ( xName , aRequest . Name ) ;
}
aRequest . Content . set ( m_xParentContainer , UNO_QUERY ) ;
OInteractionRequest * pRequest = new OInteractionRequest ( makeAny ( aRequest ) ) ;
Reference < XInteractionRequest > xRequest ( pRequest ) ;
// some knittings
// two continuations allowed: OK and Cancel
ODocumentSaveContinuation * pDocuSave = NULL ;
if ( ! m_pImpl - > m_aProps . aTitle . getLength ( ) )
{
pDocuSave = new ODocumentSaveContinuation ;
pRequest - > addContinuation ( pDocuSave ) ;
}
OInteraction < XInteractionApprove > * pApprove = NULL ;
if ( _bApprove )
{
pApprove = new OInteraction < XInteractionApprove > ;
pRequest - > addContinuation ( pApprove ) ;
}
OInteraction < XInteractionDisapprove > * pDisApprove = new OInteraction < XInteractionDisapprove > ;
pRequest - > addContinuation ( pDisApprove ) ;
OInteractionAbort * pAbort = new OInteractionAbort ;
pRequest - > addContinuation ( pAbort ) ;
// create the handler, let it handle the request
Reference < XInteractionHandler > xHandler ( m_xORB - > createInstance ( SERVICE_SDB_INTERACTION_HANDLER ) , UNO_QUERY ) ;
if ( xHandler . is ( ) )
xHandler - > handle ( xRequest ) ;
if ( pAbort - > wasSelected ( ) )
return sal_False ;
if ( pDisApprove - > wasSelected ( ) )
return sal_True ;
if ( pDocuSave & & pDocuSave - > wasSelected ( ) )
{
: : osl : : MutexGuard aGuard ( m_aMutex ) ;
Reference < XNameContainer > xNC ( pDocuSave - > getContent ( ) , UNO_QUERY ) ;
if ( xNC . is ( ) )
{
m_pImpl - > m_aProps . aTitle = pDocuSave - > getName ( ) ;
Reference < XContent > xContent = this ;
xNC - > insertByName ( pDocuSave - > getName ( ) , makeAny ( xContent ) ) ;
2005-01-21 16:04:28 +00:00
updateDocumentTitle ( ) ;
2004-08-02 14:10:37 +00:00
}
}
}
: : osl : : MutexGuard aGuard ( m_aMutex ) ;
Reference < XEmbedPersist > xPersist ( m_xEmbeddedObject , UNO_QUERY ) ;
if ( xPersist . is ( ) )
{
xPersist - > storeOwn ( ) ;
2004-11-26 16:02:35 +00:00
notifyDataSourceModified ( ) ;
2004-08-02 14:10:37 +00:00
}
}
catch ( Exception & )
{
2005-01-05 11:28:50 +00:00
OSL_ENSURE ( 0 , " ODocumentDefinition::save: caught an Exception (tried to let the InteractionHandler handle it)! " ) ;
2004-08-02 14:10:37 +00:00
}
return sal_True ;
2000-09-18 23:16:46 +00:00
}
2004-08-02 14:10:37 +00:00
// -----------------------------------------------------------------------------
2005-01-05 11:28:50 +00:00
void ODocumentDefinition : : fillLoadArgs ( Sequence < PropertyValue > & _rArgs , Sequence < PropertyValue > & _rEmbeddedObjectDescriptor , const Reference < XConnection > & _xConnection , sal_Bool _bReadOnly )
{
sal_Int32 nLen = _rArgs . getLength ( ) ;
{
Sequence < PropertyValue > aDocumentContext ( 2 ) ;
aDocumentContext [ 0 ] . Name = : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " ActiveConnection " ) ) ;
aDocumentContext [ 0 ] . Value < < = _xConnection ;
aDocumentContext [ 1 ] . Name = PROPERTY_APPLYFORMDESIGNMODE ;
aDocumentContext [ 1 ] . Value < < = ! _bReadOnly ;
_rArgs . realloc ( nLen + 1 ) ;
_rArgs [ nLen ] . Name = : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " ComponentData " ) ) ;
_rArgs [ nLen + + ] . Value < < = aDocumentContext ;
}
2007-07-06 06:54:16 +00:00
_rArgs . realloc ( nLen + 2 ) ;
2005-01-05 11:28:50 +00:00
_rArgs [ nLen ] . Name = : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " ReadOnly " ) ) ;
_rArgs [ nLen + + ] . Value < < = _bReadOnly ;
_rArgs [ nLen ] . Name = : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " MacroExecutionMode " ) ) ;
_rArgs [ nLen + + ] . Value < < = MacroExecMode : : USE_CONFIG ;
if ( m_pImpl - > m_aProps . aTitle . getLength ( ) )
{
_rArgs . realloc ( nLen + 1 ) ;
_rArgs [ nLen ] . Name = : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " DocumentTitle " ) ) ;
_rArgs [ nLen + + ] . Value < < = m_pImpl - > m_aProps . aTitle ;
}
if ( m_pInterceptor )
{
2005-10-24 07:29:02 +00:00
m_pInterceptor - > dispose ( ) ;
2005-01-05 11:28:50 +00:00
m_pInterceptor - > release ( ) ;
m_pInterceptor = NULL ;
}
m_pInterceptor = new OInterceptor ( this , _bReadOnly ) ;
m_pInterceptor - > acquire ( ) ;
Reference < XDispatchProviderInterceptor > xInterceptor = m_pInterceptor ;
_rEmbeddedObjectDescriptor . realloc ( 1 ) ;
nLen = 0 ;
_rEmbeddedObjectDescriptor [ nLen ] . Name = : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " OutplaceDispatchInterceptor " ) ) ;
_rEmbeddedObjectDescriptor [ nLen + + ] . Value < < = xInterceptor ;
}
// -----------------------------------------------------------------------------
2004-08-02 14:10:37 +00:00
void ODocumentDefinition : : loadEmbeddedObject ( const Sequence < sal_Int8 > & _aClassID , const Reference < XConnection > & _xConnection , sal_Bool _bReadOnly )
{
if ( ! m_xEmbeddedObject . is ( ) )
{
Reference < XStorage > xStorage = getStorage ( ) ;
if ( xStorage . is ( ) )
{
Reference < XEmbedObjectFactory > xEmbedFactory ( m_xORB - > createInstance ( : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " com.sun.star.embed.OOoEmbeddedObjectFactory " ) ) ) , UNO_QUERY ) ;
if ( xEmbedFactory . is ( ) )
{
: : rtl : : OUString sDocumentService ;
2005-01-05 11:28:50 +00:00
sal_Bool bSetSize = sal_False ;
2004-08-02 14:10:37 +00:00
sal_Int32 nEntryConnectionMode = EntryInitModes : : DEFAULT_INIT ;
Sequence < sal_Int8 > aClassID = _aClassID ;
if ( aClassID . getLength ( ) )
{
nEntryConnectionMode = EntryInitModes : : TRUNCATE_INIT ;
2005-01-05 11:28:50 +00:00
bSetSize = sal_True ;
2004-08-02 14:10:37 +00:00
}
else
{
2007-07-06 06:54:16 +00:00
sDocumentService = GetDocumentServiceFromMediaType ( xStorage , m_pImpl - > m_aProps . sPersistentName , m_xORB , aClassID ) ;
if ( ! aClassID . getLength ( ) )
{
if ( m_bForm )
aClassID = MimeConfigurationHelper : : GetSequenceClassID ( SO3_SW_CLASSID ) ;
else
{
: : comphelper : : MimeConfigurationHelper aConfigHelper ( m_xORB ) ;
aClassID = aConfigHelper . GetSequenceClassIDFromObjectName ( ( : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " Report " ) ) ) ) ;
}
}
2004-08-02 14:10:37 +00:00
}
2007-07-06 06:54:16 +00:00
OSL_ENSURE ( aClassID . getLength ( ) , " No Class ID " ) ;
2005-01-05 11:28:50 +00:00
Sequence < PropertyValue > aArgs , aEmbeddedObjectDescriptor ;
fillLoadArgs ( aArgs , aEmbeddedObjectDescriptor , _xConnection , _bReadOnly ) ;
2004-08-02 14:10:37 +00:00
m_xEmbeddedObject . set ( xEmbedFactory - > createInstanceUserInit ( aClassID
, sDocumentService
, xStorage
, m_pImpl - > m_aProps . sPersistentName
, nEntryConnectionMode
, aArgs
, aEmbeddedObjectDescriptor
) , UNO_QUERY ) ;
if ( m_xEmbeddedObject . is ( ) )
{
if ( ! m_pClientHelper )
2004-12-03 13:34:52 +00:00
{
2004-08-02 14:10:37 +00:00
m_pClientHelper = new OEmbeddedClientHelper ( this ) ;
2004-12-03 13:34:52 +00:00
m_pClientHelper - > acquire ( ) ;
}
2004-08-02 14:10:37 +00:00
Reference < XEmbeddedClient > xClient = m_pClientHelper ;
m_xEmbeddedObject - > setClientSite ( xClient ) ;
2005-01-05 11:28:50 +00:00
m_xEmbeddedObject - > changeState ( EmbedStates : : RUNNING ) ;
if ( bSetSize )
{
: : com : : sun : : star : : awt : : Size aSize ;
aSize . Width = DEFAULT_WIDTH ;
aSize . Height = DEFAULT_HEIGHT ;
m_xEmbeddedObject - > setVisualAreaSize ( Aspects : : MSOLE_CONTENT , aSize ) ;
}
2004-08-02 14:10:37 +00:00
}
}
}
}
else if ( m_xEmbeddedObject - > getCurrentState ( ) = = EmbedStates : : LOADED )
{
2005-01-05 11:28:50 +00:00
if ( ! m_pClientHelper )
2005-12-21 12:36:04 +00:00
{
2005-01-05 11:28:50 +00:00
m_pClientHelper = new OEmbeddedClientHelper ( this ) ;
2005-12-21 12:36:04 +00:00
m_pClientHelper - > acquire ( ) ;
}
2005-01-05 11:28:50 +00:00
Reference < XEmbeddedClient > xClient = m_pClientHelper ;
m_xEmbeddedObject - > setClientSite ( xClient ) ;
Sequence < PropertyValue > aArgs , aEmbeddedObjectDescriptor ;
fillLoadArgs ( aArgs , aEmbeddedObjectDescriptor , _xConnection , _bReadOnly ) ;
Reference < XCommonEmbedPersist > xCommon ( m_xEmbeddedObject , UNO_QUERY ) ;
OSL_ENSURE ( xCommon . is ( ) , " unsupported interface! " ) ;
if ( xCommon . is ( ) )
xCommon - > reload ( aArgs , aEmbeddedObjectDescriptor ) ;
2004-08-02 14:10:37 +00:00
m_xEmbeddedObject - > changeState ( EmbedStates : : RUNNING ) ;
}
2005-02-17 10:04:03 +00:00
2004-08-02 14:10:37 +00:00
Reference < XModel > xModel ( getComponent ( ) , UNO_QUERY ) ;
2005-02-17 10:04:03 +00:00
// set the OfficeDatabaseDocument instance as parent of the embedded document
// #i40358# / 2005-01-19 / frank.schoenheit@sun.com
Reference < XChild > xDepdendDocAsChild ( xModel , UNO_QUERY ) ;
if ( xDepdendDocAsChild . is ( ) )
{
try
{
if ( ! xDepdendDocAsChild - > getParent ( ) . is ( ) )
{ // first encounter
xDepdendDocAsChild - > setParent ( getDataSource ( m_xParentContainer ) ) ;
}
}
catch ( const Exception & )
{
OSL_ENSURE ( sal_False , " ODocumentDefinition::loadEmbeddedObject: caught an exception while setting the parent of the embedded object! " ) ;
}
}
2004-08-02 14:10:37 +00:00
if ( xModel . is ( ) )
{
Sequence < PropertyValue > aArgs = xModel - > getArgs ( ) ;
2005-01-21 16:04:28 +00:00
: : comphelper : : MediaDescriptor aHelper ( aArgs ) ;
2006-07-13 14:21:45 +00:00
aHelper [ : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " ReadOnly " ) ) ] < < = _bReadOnly ;
2004-08-02 14:10:37 +00:00
2005-01-21 16:04:28 +00:00
if ( m_pImpl - > m_aProps . aTitle . getLength ( ) )
2006-07-13 14:21:45 +00:00
aHelper [
: : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " DocumentTitle " ) ) ] < < = m_pImpl - > m_aProps . aTitle ;
2004-08-02 14:10:37 +00:00
2006-07-13 14:21:45 +00:00
aHelper [
: : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " MacroExecutionMode " ) ) ] < < = MacroExecMode : : USE_CONFIG ;
2004-08-02 14:10:37 +00:00
2005-01-21 16:04:28 +00:00
aHelper > > aArgs ;
2004-08-02 14:10:37 +00:00
xModel - > attachResource ( xModel - > getURL ( ) , aArgs ) ;
}
}
// -----------------------------------------------------------------------------
void ODocumentDefinition : : generateNewImage ( Any & _rImage )
2000-09-18 23:16:46 +00:00
{
2005-07-08 09:37:18 +00:00
loadEmbeddedObject ( Sequence < sal_Int8 > ( ) , Reference < XConnection > ( ) , sal_True ) ;
2004-08-02 14:10:37 +00:00
if ( m_xEmbeddedObject . is ( ) )
2000-09-18 23:16:46 +00:00
{
2004-08-02 14:10:37 +00:00
try
{
Reference < XTransferable > xTransfer ( getComponent ( ) , UNO_QUERY ) ;
if ( xTransfer . is ( ) )
{
DataFlavor aFlavor ;
aFlavor . MimeType = : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " image/png " ) ) ;
aFlavor . HumanPresentableName = : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " Portable Network Graphics " ) ) ;
aFlavor . DataType = : : getCppuType ( static_cast < const Sequence < sal_Int8 > * > ( NULL ) ) ;
_rImage = xTransfer - > getTransferData ( aFlavor ) ;
}
}
catch ( Exception )
{
}
2000-09-18 23:16:46 +00:00
}
}
2004-08-02 14:10:37 +00:00
// -----------------------------------------------------------------------------
2006-08-15 09:45:43 +00:00
void ODocumentDefinition : : getPropertyDefaultByHandle ( sal_Int32 /*_nHandle*/ , Any & _rDefault ) const
2004-08-02 14:10:37 +00:00
{
2006-08-15 09:45:43 +00:00
_rDefault . clear ( ) ;
2004-08-02 14:10:37 +00:00
}
// -----------------------------------------------------------------------------
void ODocumentDefinition : : fillDocumentInfo ( Any & _rInfo )
2000-09-18 23:16:46 +00:00
{
2005-07-08 09:37:18 +00:00
loadEmbeddedObject ( Sequence < sal_Int8 > ( ) , Reference < XConnection > ( ) , sal_True ) ;
2004-08-02 14:10:37 +00:00
if ( m_xEmbeddedObject . is ( ) )
2000-09-18 23:16:46 +00:00
{
2004-08-02 14:10:37 +00:00
try
{
Reference < XDocumentInfoSupplier > xDocSup ( getComponent ( ) , UNO_QUERY ) ;
if ( xDocSup . is ( ) )
_rInfo < < = xDocSup - > getDocumentInfo ( ) ;
}
catch ( Exception e )
{
}
2000-09-18 23:16:46 +00:00
}
}
2004-08-02 14:10:37 +00:00
// -----------------------------------------------------------------------------
Reference < : : com : : sun : : star : : util : : XCloseable > ODocumentDefinition : : getComponent ( ) throw ( RuntimeException )
{
OSL_ENSURE ( m_xEmbeddedObject . is ( ) , " Illegal call for embeddedObject " ) ;
Reference < : : com : : sun : : star : : util : : XCloseable > xComp ;
if ( m_xEmbeddedObject . is ( ) )
{
int nOldState = m_xEmbeddedObject - > getCurrentState ( ) ;
int nState = nOldState ;
if ( nOldState = = EmbedStates : : LOADED )
{
m_xEmbeddedObject - > changeState ( EmbedStates : : RUNNING ) ;
nState = EmbedStates : : RUNNING ;
}
2000-09-18 23:16:46 +00:00
2004-08-02 14:10:37 +00:00
if ( nState = = EmbedStates : : ACTIVE | | nState = = EmbedStates : : RUNNING )
{
Reference < XComponentSupplier > xCompProv ( m_xEmbeddedObject , UNO_QUERY ) ;
if ( xCompProv . is ( ) )
{
xComp = xCompProv - > getComponent ( ) ;
OSL_ENSURE ( xComp . is ( ) , " No valid component " ) ;
}
}
}
return xComp ;
}
// -----------------------------------------------------------------------------
2007-05-10 09:12:45 +00:00
void SAL_CALL ODocumentDefinition : : rename ( const : : rtl : : OUString & _rNewName ) throw ( SQLException , ElementExistException , RuntimeException )
2000-09-18 23:16:46 +00:00
{
2004-08-02 14:10:37 +00:00
try
2000-09-18 23:16:46 +00:00
{
2004-08-02 14:10:37 +00:00
osl : : ClearableGuard < osl : : Mutex > aGuard ( m_aMutex ) ;
2007-05-10 09:12:45 +00:00
if ( _rNewName . equals ( m_pImpl - > m_aProps . aTitle ) )
2005-03-23 08:53:43 +00:00
return ;
2005-03-10 15:35:30 +00:00
2007-05-10 09:12:45 +00:00
// document definitions are organized in a hierarchicalway, so reject names
// which contain a /, as this is reserved for hierarchy level separation
if ( _rNewName . indexOf ( ' / ' ) ! = - 1 )
{
: : dbtools : : throwGenericSQLException (
DBA_RES ( RID_STR_NO_SLASH_IN_OBJECT_NAME ) , * this ) ;
}
2005-03-23 08:53:43 +00:00
sal_Int32 nHandle = PROPERTY_ID_NAME ;
2007-05-10 09:12:45 +00:00
Any aOld = makeAny ( m_pImpl - > m_aProps . aTitle ) ;
Any aNew = makeAny ( _rNewName ) ;
2005-03-23 08:53:43 +00:00
aGuard . clear ( ) ;
2004-08-02 14:10:37 +00:00
fire ( & nHandle , & aNew , & aOld , 1 , sal_True ) ;
2007-05-10 09:12:45 +00:00
m_pImpl - > m_aProps . aTitle = _rNewName ;
2004-08-02 14:10:37 +00:00
fire ( & nHandle , & aNew , & aOld , 1 , sal_False ) ;
2005-01-21 16:04:28 +00:00
2005-03-23 08:53:43 +00:00
: : osl : : ClearableGuard < : : osl : : Mutex > aGuard2 ( m_aMutex ) ;
2005-01-21 16:04:28 +00:00
if ( m_xEmbeddedObject . is ( ) & & m_xEmbeddedObject - > getCurrentState ( ) = = EmbedStates : : ACTIVE )
updateDocumentTitle ( ) ;
2004-08-02 14:10:37 +00:00
}
catch ( const PropertyVetoException & )
{
2007-05-10 09:12:45 +00:00
throw ElementExistException ( _rNewName , * this ) ;
2000-09-18 23:16:46 +00:00
}
}
2004-08-02 14:10:37 +00:00
// -----------------------------------------------------------------------------
Reference < XStorage > ODocumentDefinition : : getStorage ( ) const
2000-09-18 23:16:46 +00:00
{
2004-08-02 14:10:37 +00:00
static const : : rtl : : OUString s_sForms = : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " forms " ) ) ;
static const : : rtl : : OUString s_sReports = : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " reports " ) ) ;
2005-07-08 09:37:18 +00:00
return m_pImpl - > m_pDataSource
? m_pImpl - > m_pDataSource - > getStorage ( m_bForm ? s_sForms : s_sReports )
: Reference < XStorage > ( ) ;
2000-09-18 23:16:46 +00:00
}
2004-08-02 14:10:37 +00:00
// -----------------------------------------------------------------------------
sal_Bool ODocumentDefinition : : isModified ( )
2000-09-18 23:16:46 +00:00
{
2004-08-02 14:10:37 +00:00
osl : : ClearableGuard < osl : : Mutex > aGuard ( m_aMutex ) ;
sal_Bool bRet = sal_False ;
if ( m_xEmbeddedObject . is ( ) )
{
Reference < XModifiable > xModel ( getComponent ( ) , UNO_QUERY ) ;
bRet = xModel . is ( ) & & xModel - > isModified ( ) ;
}
return bRet ;
2000-09-18 23:16:46 +00:00
}
2004-08-02 14:10:37 +00:00
// -----------------------------------------------------------------------------
2005-09-23 11:06:25 +00:00
bool ODocumentDefinition : : prepareClose ( )
{
if ( ! m_xEmbeddedObject . is ( ) )
return true ;
try
{
// suspend the controller. Embedded objects are not allowed to rais
// own UI on their own decision, instead, this has always to be triggered
// by the embedding component. Thus, we do the suspend call here.
// #i49370# / 2005-06-09 / frank.schoenheit@sun.com
Reference < XModel > xModel ( getComponent ( ) , UNO_QUERY ) ;
Reference < XController > xController ;
if ( xModel . is ( ) )
xController = xModel - > getCurrentController ( ) ;
OSL_ENSURE ( xController . is ( ) , " ODocumentDefinition::prepareClose: no controller! " ) ;
if ( ! xController . is ( ) )
return sal_False ;
sal_Bool bCouldSuspend = xController - > suspend ( sal_True ) ;
if ( ! bCouldSuspend )
// controller vetoed the closing
return false ;
if ( isModified ( ) & & ! save ( sal_True ) )
{
if ( bCouldSuspend )
// revert suspension
xController - > suspend ( sal_False ) ;
// saving failed or was cancelled
return false ;
}
}
catch ( const Exception & )
{
2007-05-10 09:12:45 +00:00
DBG_UNHANDLED_EXCEPTION ( ) ;
2005-09-23 11:06:25 +00:00
}
return true ;
}
// -----------------------------------------------------------------------------
2004-08-02 14:10:37 +00:00
void ODocumentDefinition : : fillReportData ( sal_Bool _bFill )
2000-09-18 23:16:46 +00:00
{
2005-01-21 16:04:28 +00:00
if ( ! m_bForm & & _bFill & & m_pImpl - > m_aProps . bAsTemplate & & ! m_bOpenInDesign ) // open a report in alive mode, so we need to fill it
2000-09-18 23:16:46 +00:00
{
2005-03-18 15:32:48 +00:00
Sequence < Any > aArgs ( 2 ) ;
2004-08-02 14:10:37 +00:00
PropertyValue aValue ;
aValue . Name = : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " TextDocument " ) ) ;
aValue . Value < < = getComponent ( ) ;
aArgs [ 0 ] < < = aValue ;
2005-03-18 15:32:48 +00:00
aValue . Name = : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " ActiveConnection " ) ) ;
aValue . Value < < = m_xLastKnownConnection ;
aArgs [ 1 ] < < = aValue ;
2004-08-02 14:10:37 +00:00
Reference < XJobExecutor > xExecuteable ( m_xORB - > createInstanceWithArguments ( : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " com.sun.star.wizards.report.CallReportWizard " ) ) , aArgs ) , UNO_QUERY ) ;
if ( xExecuteable . is ( ) )
xExecuteable - > trigger ( : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " fill " ) ) ) ;
2000-09-18 23:16:46 +00:00
}
}
2005-01-05 11:28:50 +00:00
// -----------------------------------------------------------------------------
2005-01-21 16:04:28 +00:00
void ODocumentDefinition : : updateDocumentTitle ( )
{
if ( m_pImpl - > m_aProps . aTitle . getLength ( ) )
{
Reference < XModel > xModel ( getComponent ( ) , UNO_QUERY ) ;
if ( xModel . is ( ) )
{
Sequence < PropertyValue > aArgs = xModel - > getArgs ( ) ;
: : comphelper : : MediaDescriptor aHelper ( aArgs ) ;
2006-07-13 14:21:45 +00:00
aHelper [ : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " DocumentTitle " ) ) ] < < = m_pImpl - > m_aProps . aTitle ;
2005-01-21 16:04:28 +00:00
aHelper > > aArgs ;
xModel - > attachResource ( xModel - > getURL ( ) , aArgs ) ;
}
}
}
2000-10-18 15:16:39 +00:00
//........................................................................
} // namespace dbaccess
//........................................................................
2000-09-18 23:16:46 +00:00