LCOV - code coverage report
Current view: top level - dbaccess/source/core/dataaccess - documentdefinition.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 43 939 4.6 %
Date: 2015-06-13 12:38:46 Functions: 12 102 11.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "documentdefinition.hxx"
      21             : #include "dbastrings.hrc"
      22             : #include "sdbcoretools.hxx"
      23             : #include <tools/debug.hxx>
      24             : #include <tools/diagnose_ex.h>
      25             : #include <osl/diagnose.h>
      26             : #include <comphelper/property.hxx>
      27             : #include <comphelper/sequence.hxx>
      28             : #include <comphelper/namedvaluecollection.hxx>
      29             : #include <comphelper/classids.hxx>
      30             : #include <com/sun/star/frame/XUntitledNumbers.hpp>
      31             : #include <com/sun/star/awt/XTopWindow.hpp>
      32             : #include <com/sun/star/awt/Size.hpp>
      33             : #include <com/sun/star/lang/DisposedException.hpp>
      34             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      35             : #include <com/sun/star/frame/Desktop.hpp>
      36             : #include <com/sun/star/frame/XModel.hpp>
      37             : #include <com/sun/star/frame/XTitle.hpp>
      38             : #include <com/sun/star/frame/XController.hpp>
      39             : #include <com/sun/star/task/XJobExecutor.hpp>
      40             : #include <com/sun/star/frame/XDispatchProviderInterception.hpp>
      41             : #include <com/sun/star/frame/XFramesSupplier.hpp>
      42             : #include <com/sun/star/ucb/InsertCommandArgument.hpp>
      43             : #include <com/sun/star/report/XReportDefinition.hpp>
      44             : #include <com/sun/star/report/XReportEngine.hpp>
      45             : #include <com/sun/star/ucb/OpenMode.hpp>
      46             : #include <com/sun/star/embed/XEmbedObjectFactory.hpp>
      47             : #include <com/sun/star/embed/EmbeddedObjectCreator.hpp>
      48             : #include <com/sun/star/embed/Aspects.hpp>
      49             : #include <com/sun/star/embed/OOoEmbeddedObjectFactory.hpp>
      50             : #include <ucbhelper/cancelcommandexecution.hxx>
      51             : #include <com/sun/star/ucb/UnsupportedDataSinkException.hpp>
      52             : #include <com/sun/star/ucb/UnsupportedOpenModeException.hpp>
      53             : #include <com/sun/star/embed/ElementModes.hpp>
      54             : #include <com/sun/star/embed/XEmbedPersist.hpp>
      55             : #include <com/sun/star/embed/EmbedStates.hpp>
      56             : #include <com/sun/star/embed/XComponentSupplier.hpp>
      57             : #include <com/sun/star/embed/EntryInitModes.hpp>
      58             : #include <com/sun/star/ucb/MissingPropertiesException.hpp>
      59             : #include <com/sun/star/ucb/MissingInputStreamException.hpp>
      60             : #include <com/sun/star/ucb/OpenCommandArgument2.hpp>
      61             : #include <com/sun/star/util/XCloseBroadcaster.hpp>
      62             : #include <com/sun/star/frame/XModule.hpp>
      63             : #include <com/sun/star/datatransfer/DataFlavor.hpp>
      64             : #include <com/sun/star/datatransfer/XTransferable.hpp>
      65             : #include <com/sun/star/container/XNameContainer.hpp>
      66             : #include <com/sun/star/embed/XTransactedObject.hpp>
      67             : #include <com/sun/star/embed/XCommonEmbedPersist.hpp>
      68             : #include "intercept.hxx"
      69             : #include <com/sun/star/sdb/ErrorCondition.hpp>
      70             : #include <com/sun/star/sdb/XInteractionDocumentSave.hpp>
      71             : #include <com/sun/star/task/InteractionHandler.hpp>
      72             : #include <com/sun/star/sdb/DocumentSaveRequest.hpp>
      73             : #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
      74             : #include <com/sun/star/document/MacroExecMode.hpp>
      75             : #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
      76             : #include <com/sun/star/container/XIndexContainer.hpp>
      77             : #include <com/sun/star/form/XFormsSupplier.hpp>
      78             : #include <com/sun/star/form/XForm.hpp>
      79             : #include <comphelper/interaction.hxx>
      80             : #include <connectivity/dbtools.hxx>
      81             : #include <vcl/svapp.hxx>
      82             : #include <osl/mutex.hxx>
      83             : #include <sal/macros.h>
      84             : #include <com/sun/star/view/XViewSettingsSupplier.hpp>
      85             : #include "core_resource.hxx"
      86             : #include "core_resource.hrc"
      87             : #include "datasource.hxx"
      88             : #include <com/sun/star/embed/XStateChangeBroadcaster.hpp>
      89             : #include <com/sun/star/task/XInteractionApprove.hpp>
      90             : #include <com/sun/star/task/XInteractionDisapprove.hpp>
      91             : #include <com/sun/star/frame/XLayoutManager.hpp>
      92             : #include <cppuhelper/compbase1.hxx>
      93             : #include <cppuhelper/exc_hlp.hxx>
      94             : #include <com/sun/star/frame/FrameSearchFlag.hpp>
      95             : #include <comphelper/sequenceashashmap.hxx>
      96             : #include <comphelper/mimeconfighelper.hxx>
      97             : #include <comphelper/storagehelper.hxx>
      98             : #include <com/sun/star/container/XContentEnumerationAccess.hpp>
      99             : #include <com/sun/star/io/WrongFormatException.hpp>
     100             : #include <com/sun/star/sdb/application/XDatabaseDocumentUI.hpp>
     101             : #include <com/sun/star/sdb/application/DatabaseObject.hpp>
     102             : #include <com/sun/star/util/XModifiable2.hpp>
     103             : 
     104             : using namespace ::com::sun::star;
     105             : using namespace view;
     106             : using namespace uno;
     107             : using namespace util;
     108             : using namespace ucb;
     109             : using namespace beans;
     110             : using namespace lang;
     111             : using namespace awt;
     112             : using namespace embed;
     113             : using namespace frame;
     114             : using namespace document;
     115             : using namespace sdbc;
     116             : using namespace sdb;
     117             : using namespace io;
     118             : using namespace container;
     119             : using namespace datatransfer;
     120             : using namespace task;
     121             : using namespace form;
     122             : using namespace drawing;
     123             : using namespace ::osl;
     124             : using namespace ::comphelper;
     125             : using namespace ::cppu;
     126             : 
     127             : using sdb::application::XDatabaseDocumentUI;
     128             : namespace DatabaseObject = sdb::application::DatabaseObject;
     129             : 
     130             : #define DEFAULT_WIDTH  10000
     131             : #define DEFAULT_HEIGHT  7500
     132             : 
     133             : namespace dbaccess
     134             : {
     135             : 
     136             :     typedef ::boost::optional< bool > optional_bool;
     137             : 
     138             :     // helper
     139             :     namespace
     140             :     {
     141           0 :         OUString lcl_determineContentType_nothrow( const Reference< XStorage >& _rxContainerStorage,
     142             :             const OUString& _rEntityName )
     143             :         {
     144           0 :             OUString sContentType;
     145             :             try
     146             :             {
     147             :                 ::utl::SharedUNOComponent< XPropertySet > xStorageProps(
     148           0 :                     _rxContainerStorage->openStorageElement( _rEntityName, ElementModes::READ ), UNO_QUERY_THROW );
     149           0 :                 OSL_VERIFY( xStorageProps->getPropertyValue( INFO_MEDIATYPE ) >>= sContentType );
     150             :             }
     151           0 :             catch( const Exception& )
     152             :             {
     153             :                 DBG_UNHANDLED_EXCEPTION();
     154             :             }
     155           0 :             return sContentType;
     156             :         }
     157             :     }
     158             : 
     159             :     // OEmbedObjectHolder
     160             :     typedef ::cppu::WeakComponentImplHelper1<   embed::XStateChangeListener > TEmbedObjectHolder;
     161           0 :     class OEmbedObjectHolder :   public ::comphelper::OBaseMutex
     162             :                                 ,public TEmbedObjectHolder
     163             :     {
     164             :         Reference< XEmbeddedObject >    m_xBroadCaster;
     165             :         ODocumentDefinition*            m_pDefinition;
     166             :         bool                            m_bInStateChange;
     167             :     protected:
     168             :         virtual void SAL_CALL disposing() SAL_OVERRIDE;
     169             :     public:
     170           0 :         OEmbedObjectHolder(const Reference< XEmbeddedObject >& _xBroadCaster,ODocumentDefinition* _pDefinition)
     171             :             : TEmbedObjectHolder(m_aMutex)
     172             :             ,m_xBroadCaster(_xBroadCaster)
     173             :             ,m_pDefinition(_pDefinition)
     174           0 :             ,m_bInStateChange(false)
     175             :         {
     176           0 :             osl_atomic_increment( &m_refCount );
     177             :             {
     178           0 :                 if ( m_xBroadCaster.is() )
     179           0 :                     m_xBroadCaster->addStateChangeListener(this);
     180             :             }
     181           0 :             osl_atomic_decrement( &m_refCount );
     182           0 :         }
     183             : 
     184             :         virtual void SAL_CALL changingState( const lang::EventObject& aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState ) throw (embed::WrongStateException, uno::RuntimeException, std::exception) SAL_OVERRIDE;
     185             :         virtual void SAL_CALL stateChanged( const lang::EventObject& aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE;
     186             :         virtual void SAL_CALL disposing( const lang::EventObject& Source ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE;
     187             :     };
     188             : 
     189           0 :     void SAL_CALL OEmbedObjectHolder::disposing()
     190             :     {
     191           0 :         if ( m_xBroadCaster.is() )
     192           0 :             m_xBroadCaster->removeStateChangeListener(this);
     193           0 :         m_xBroadCaster = NULL;
     194           0 :         m_pDefinition = NULL;
     195           0 :     }
     196             : 
     197           0 :     void SAL_CALL OEmbedObjectHolder::changingState( const lang::EventObject& /*aEvent*/, ::sal_Int32 /*nOldState*/, ::sal_Int32 /*nNewState*/ ) throw (embed::WrongStateException, uno::RuntimeException, std::exception)
     198             :     {
     199           0 :     }
     200             : 
     201           0 :     void SAL_CALL OEmbedObjectHolder::stateChanged( const lang::EventObject& aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState ) throw (uno::RuntimeException, std::exception)
     202             :     {
     203           0 :         if ( !m_bInStateChange && nNewState == EmbedStates::RUNNING && nOldState == EmbedStates::ACTIVE && m_pDefinition )
     204             :         {
     205           0 :             m_bInStateChange = true;
     206           0 :             Reference<XInterface> xInt(static_cast< ::cppu::OWeakObject* >(m_pDefinition),UNO_QUERY);
     207             :             {
     208           0 :                 Reference<XEmbeddedObject> xEmbeddedObject(aEvent.Source,UNO_QUERY);
     209           0 :                 if ( xEmbeddedObject.is() )
     210           0 :                     xEmbeddedObject->changeState(EmbedStates::LOADED);
     211             :             }
     212           0 :             m_bInStateChange = false;
     213             :         }
     214           0 :     }
     215             : 
     216           0 :     void SAL_CALL OEmbedObjectHolder::disposing( const lang::EventObject& /*Source*/ ) throw (uno::RuntimeException, std::exception)
     217             :     {
     218           0 :         m_xBroadCaster = NULL;
     219           0 :     }
     220             : 
     221             :     // OEmbeddedClientHelper
     222             :     typedef ::cppu::WeakImplHelper1 <   XEmbeddedClient
     223             :                                     >   EmbeddedClientHelper_BASE;
     224           0 :     class OEmbeddedClientHelper : public EmbeddedClientHelper_BASE
     225             :     {
     226             :         ODocumentDefinition* m_pClient;
     227             :     public:
     228           0 :         OEmbeddedClientHelper(ODocumentDefinition* _pClient) :m_pClient(_pClient) {}
     229             : 
     230           0 :         virtual void SAL_CALL saveObject(  ) throw (ObjectSaveVetoException, Exception, RuntimeException, std::exception) SAL_OVERRIDE
     231             :         {
     232           0 :         }
     233             :         // XComponentSupplier
     234           0 :         virtual Reference< util::XCloseable > SAL_CALL getComponent(  ) throw (RuntimeException, std::exception) SAL_OVERRIDE
     235             :         {
     236           0 :             return Reference< css::util::XCloseable >();
     237             :         }
     238             : 
     239             :         // XEmbeddedClient
     240           0 :         virtual void SAL_CALL visibilityChanged( sal_Bool /*bVisible*/ ) throw (WrongStateException, RuntimeException, std::exception) SAL_OVERRIDE
     241             :         {
     242           0 :         }
     243           0 :         inline void resetClient(ODocumentDefinition* _pClient) { m_pClient = _pClient; }
     244             :     };
     245             : 
     246             :     // LockModifiable
     247             :     class LockModifiable
     248             :     {
     249             :     public:
     250           0 :         LockModifiable( const Reference< XInterface >& i_rModifiable )
     251           0 :             :m_xModifiable( i_rModifiable, UNO_QUERY )
     252             :         {
     253             :             OSL_ENSURE( m_xModifiable.is(), "LockModifiable::LockModifiable: invalid component!" );
     254           0 :             if ( m_xModifiable.is() )
     255             :             {
     256           0 :                 if ( !m_xModifiable->isSetModifiedEnabled() )
     257             :                 {
     258             :                     // somebody already locked that, no need to lock it, again, and no need to unlock it later
     259           0 :                     m_xModifiable.clear();
     260             :                 }
     261             :                 else
     262             :                 {
     263           0 :                     m_xModifiable->disableSetModified();
     264             :                 }
     265             :             }
     266           0 :         }
     267             : 
     268           0 :         ~LockModifiable()
     269           0 :         {
     270           0 :             if ( m_xModifiable.is() )
     271           0 :                 m_xModifiable->enableSetModified();
     272           0 :         }
     273             : 
     274             :     private:
     275             :         Reference< XModifiable2 >   m_xModifiable;
     276             :     };
     277             : 
     278             :     // LifetimeCoupler
     279             :     typedef ::cppu::WeakImplHelper1 <   css::lang::XEventListener
     280             :                                     >   LifetimeCoupler_Base;
     281             :     /** helper class which couples the lifetime of a component to the lifetime
     282             :         of another component
     283             : 
     284             :         Instances of this class are constructed with two components. The first is
     285             :         simply held by reference, and thus kept alive. The second one is observed
     286             :         for <code>disposing</code> calls - if they occur, i.e. if the component dies,
     287             :         the reference to the first component is cleared.
     288             : 
     289             :         This way, you can ensure that a certain component is kept alive as long
     290             :         as a second component is not disposed.
     291             :     */
     292           0 :     class LifetimeCoupler : public LifetimeCoupler_Base
     293             :     {
     294             :     private:
     295             :         Reference< XInterface > m_xClient;
     296             : 
     297             :     public:
     298           0 :         inline static void couple( const Reference< XInterface >& _rxClient, const Reference< XComponent >& _rxActor )
     299             :         {
     300           0 :             Reference< css::lang::XEventListener > xEnsureDelete( new LifetimeCoupler( _rxClient, _rxActor ) );
     301           0 :         }
     302             : 
     303             :     private:
     304           0 :         inline LifetimeCoupler( const Reference< XInterface >& _rxClient, const Reference< XComponent >& _rxActor )
     305           0 :             :m_xClient( _rxClient )
     306             :         {
     307             :             OSL_ENSURE( _rxActor.is(), "LifetimeCoupler::LifetimeCoupler: this will crash!" );
     308           0 :             osl_atomic_increment( &m_refCount );
     309             :             {
     310           0 :                 _rxActor->addEventListener( this );
     311             :             }
     312           0 :             osl_atomic_decrement( &m_refCount );
     313             :             OSL_ENSURE( m_refCount, "LifetimeCoupler::LifetimeCoupler: the actor is not holding us by hard ref - this won't work!" );
     314           0 :         }
     315             : 
     316             :         virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
     317             :     protected:
     318             :     };
     319             : 
     320           0 :     void SAL_CALL LifetimeCoupler::disposing( const css::lang::EventObject& /*Source*/ ) throw (RuntimeException, std::exception)
     321             :     {
     322           0 :         m_xClient.clear();
     323           0 :     }
     324             : 
     325             :     // ODocumentSaveContinuation
     326           0 :     class ODocumentSaveContinuation : public OInteraction< XInteractionDocumentSave >
     327             :     {
     328             :         OUString     m_sName;
     329             :         Reference<XContent> m_xParentContainer;
     330             : 
     331             :     public:
     332           0 :         ODocumentSaveContinuation() { }
     333             : 
     334           0 :         inline Reference<XContent>  getContent() const { return m_xParentContainer; }
     335           0 :         inline OUString      getName() const { return m_sName; }
     336             : 
     337             :         // XInteractionDocumentSave
     338             :         virtual void SAL_CALL setName( const OUString& _sName,const Reference<XContent>& _xParent) throw(RuntimeException, std::exception) SAL_OVERRIDE;
     339             :     };
     340             : 
     341           0 :     void SAL_CALL ODocumentSaveContinuation::setName( const OUString& _sName,const Reference<XContent>& _xParent) throw(RuntimeException, std::exception)
     342             :     {
     343           0 :         m_sName = _sName;
     344           0 :         m_xParentContainer = _xParent;
     345           0 :     }
     346             : 
     347           0 : OUString ODocumentDefinition::GetDocumentServiceFromMediaType( const Reference< XStorage >& _rxContainerStorage,
     348             :     const OUString& _rEntityName, const Reference< XComponentContext >& _rContext,
     349             :     Sequence< sal_Int8 >& _rClassId )
     350             : {
     351             :     return GetDocumentServiceFromMediaType(
     352             :         lcl_determineContentType_nothrow( _rxContainerStorage, _rEntityName ),
     353           0 :         _rContext, _rClassId );
     354             : }
     355             : 
     356           0 : OUString ODocumentDefinition::GetDocumentServiceFromMediaType( const OUString& _rMediaType,
     357             :     const Reference< XComponentContext >& _rContext, Sequence< sal_Int8 >& _rClassId )
     358             : {
     359           0 :     OUString sResult;
     360             :     try
     361             :     {
     362           0 :         ::comphelper::MimeConfigurationHelper aConfigHelper( _rContext );
     363           0 :         sResult = aConfigHelper.GetDocServiceNameFromMediaType( _rMediaType );
     364           0 :         _rClassId = comphelper::MimeConfigurationHelper::GetSequenceClassIDRepresentation(aConfigHelper.GetExplicitlyRegisteredObjClassID( _rMediaType ));
     365           0 :         if ( !_rClassId.getLength() && !sResult.isEmpty() )
     366             :         {
     367           0 :             Reference< XNameAccess > xObjConfig = aConfigHelper.GetObjConfiguration();
     368           0 :             if ( xObjConfig.is() )
     369             :             {
     370           0 :                 Sequence< OUString > aClassIDs = xObjConfig->getElementNames();
     371           0 :                 for ( sal_Int32 nInd = 0; nInd < aClassIDs.getLength(); nInd++ )
     372             :                 {
     373           0 :                     Reference< XNameAccess > xObjectProps;
     374           0 :                     OUString aEntryDocName;
     375             : 
     376           0 :                     if (    ( xObjConfig->getByName( aClassIDs[nInd] ) >>= xObjectProps ) && xObjectProps.is()
     377           0 :                          && ( xObjectProps->getByName("ObjectDocumentServiceName") >>= aEntryDocName )
     378           0 :                          && aEntryDocName.equals( sResult ) )
     379             :                     {
     380           0 :                         _rClassId = comphelper::MimeConfigurationHelper::GetSequenceClassIDRepresentation(aClassIDs[nInd]);
     381           0 :                         break;
     382             :                     }
     383           0 :                 }
     384           0 :             }
     385           0 :         }
     386             : #if OSL_DEBUG_LEVEL > 0
     387             :         // alternative, shorter approach
     388             :         const Sequence< NamedValue > aProps( aConfigHelper.GetObjectPropsByMediaType( _rMediaType ) );
     389             :         const ::comphelper::NamedValueCollection aMediaTypeProps( aProps );
     390             :         const OUString sAlternativeResult = aMediaTypeProps.getOrDefault( "ObjectDocumentServiceName", OUString() );
     391             :         OSL_ENSURE( sAlternativeResult == sResult, "ODocumentDefinition::GetDocumentServiceFromMediaType: failed, this approach is *not* equivalent (1)!" );
     392             :         const Sequence< sal_Int8 > aAlternativeClassID = aMediaTypeProps.getOrDefault( "ClassID", Sequence< sal_Int8 >() );
     393             :         OSL_ENSURE( aAlternativeClassID == _rClassId, "ODocumentDefinition::GetDocumentServiceFromMediaType: failed, this approach is *not* equivalent (2)!" );
     394             : #endif
     395             :     }
     396           0 :     catch ( const Exception& )
     397             :     {
     398             :         DBG_UNHANDLED_EXCEPTION();
     399             :     }
     400           0 :     return sResult;
     401             : }
     402             : 
     403             : // ODocumentDefinition
     404             : 
     405          14 : ODocumentDefinition::ODocumentDefinition( const Reference< XInterface >& _rxContainer, const Reference< XComponentContext >& _xORB,
     406             :                                           const TContentPtr& _pImpl, bool _bForm )
     407             :     :OContentHelper(_xORB,_rxContainer,_pImpl)
     408             :     ,OPropertyStateContainer(OContentHelper::rBHelper)
     409             :     ,m_pInterceptor(NULL)
     410             :     ,m_bForm(_bForm)
     411             :     ,m_bOpenInDesign(false)
     412             :     ,m_bInExecute(false)
     413             :     ,m_bRemoveListener(false)
     414          14 :     ,m_pClientHelper(NULL)
     415             : {
     416          14 :     registerProperties();
     417          14 : }
     418             : 
     419           0 : void ODocumentDefinition::initialLoad( const Sequence< sal_Int8 >& i_rClassID, const Sequence< PropertyValue >& i_rCreationArgs,
     420             :                                        const Reference< XConnection >& i_rConnection )
     421             : {
     422             :     OSL_ENSURE( i_rClassID.getLength(), "ODocumentDefinition::initialLoad: illegal class ID!" );
     423           0 :     if ( !i_rClassID.getLength() )
     424           0 :         return;
     425             : 
     426           0 :     loadEmbeddedObject( i_rConnection, i_rClassID, i_rCreationArgs, false, false );
     427             : }
     428             : 
     429          42 : ODocumentDefinition::~ODocumentDefinition()
     430             : {
     431          14 :     if ( !OContentHelper::rBHelper.bInDispose && !OContentHelper::rBHelper.bDisposed )
     432             :     {
     433           0 :         acquire();
     434           0 :         dispose();
     435             :     }
     436             : 
     437          14 :     if ( m_pInterceptor )
     438             :     {
     439           0 :         m_pInterceptor->dispose();
     440           0 :         m_pInterceptor->release();
     441           0 :         m_pInterceptor = NULL;
     442             :     }
     443          28 : }
     444             : 
     445          14 : void ODocumentDefinition::closeObject()
     446             : {
     447          14 :     ::osl::MutexGuard aGuard(m_aMutex);
     448          14 :     if ( m_xEmbeddedObject.is() )
     449             :     {
     450             :         try
     451             :         {
     452           0 :             Reference< com::sun::star::util::XCloseable> xCloseable(m_xEmbeddedObject,UNO_QUERY);
     453           0 :             if ( xCloseable.is() )
     454           0 :                 xCloseable->close(sal_True);
     455             :         }
     456           0 :         catch(const Exception&)
     457             :         {
     458             :         }
     459           0 :         m_xEmbeddedObject = NULL;
     460           0 :         if ( m_pClientHelper )
     461             :         {
     462           0 :             m_pClientHelper->resetClient(NULL);
     463           0 :             m_pClientHelper->release();
     464           0 :             m_pClientHelper = NULL;
     465             :         }
     466          14 :     }
     467          14 : }
     468             : 
     469          14 : void SAL_CALL ODocumentDefinition::disposing()
     470             : {
     471          14 :     OContentHelper::disposing();
     472          14 :     ::osl::MutexGuard aGuard(m_aMutex);
     473          14 :     closeObject();
     474          14 :     ::comphelper::disposeComponent(m_xListener);
     475          14 :     if ( m_bRemoveListener )
     476             :     {
     477           0 :         Reference<util::XCloseable> xCloseable(m_pImpl->m_pDataSource->getModel_noCreate(),UNO_QUERY);
     478           0 :         if ( xCloseable.is() )
     479           0 :             xCloseable->removeCloseListener(this);
     480          14 :     }
     481          14 : }
     482             : 
     483           0 : css::uno::Sequence<sal_Int8> ODocumentDefinition::getImplementationId()
     484             :     throw (css::uno::RuntimeException, std::exception)
     485             : {
     486           0 :     return css::uno::Sequence<sal_Int8>();
     487             : }
     488             : 
     489           0 : IMPLEMENT_GETTYPES3(ODocumentDefinition,OContentHelper,OPropertyStateContainer,ODocumentDefinition_Base);
     490         584 : IMPLEMENT_FORWARD_XINTERFACE3( ODocumentDefinition,OContentHelper,OPropertyStateContainer,ODocumentDefinition_Base)
     491           0 : IMPLEMENT_SERVICE_INFO1(ODocumentDefinition,"com.sun.star.comp.dba.ODocumentDefinition",SERVICE_SDB_DOCUMENTDEFINITION)
     492             : 
     493          14 : void ODocumentDefinition::registerProperties()
     494             : {
     495             : #define REGISTER_PROPERTY( name, location ) \
     496             :     registerProperty(   PROPERTY_##name, PROPERTY_ID_##name, PropertyAttribute::READONLY, &location, cppu::UnoType<decltype(location)>::get() );
     497             : 
     498             : #define REGISTER_PROPERTY_BV( name, location ) \
     499             :     registerProperty(   PROPERTY_##name, PROPERTY_ID_##name, PropertyAttribute::CONSTRAINED | PropertyAttribute::BOUND | PropertyAttribute::READONLY, &location, cppu::UnoType<decltype(location)>::get() );
     500             : 
     501          14 :     REGISTER_PROPERTY_BV( NAME,            m_pImpl->m_aProps.aTitle            );
     502          14 :     REGISTER_PROPERTY   ( AS_TEMPLATE,     m_pImpl->m_aProps.bAsTemplate       );
     503          14 :     REGISTER_PROPERTY   ( PERSISTENT_NAME, m_pImpl->m_aProps.sPersistentName   );
     504          14 :     REGISTER_PROPERTY   ( IS_FORM,         m_bForm                             );
     505          14 : }
     506             : 
     507          26 : void SAL_CALL ODocumentDefinition::getFastPropertyValue( Any& o_rValue, sal_Int32 i_nHandle ) const
     508             : {
     509          26 :     if ( i_nHandle == PROPERTY_ID_PERSISTENT_PATH )
     510             :     {
     511           0 :         OUString sPersistentPath;
     512           0 :         if ( !m_pImpl->m_aProps.sPersistentName.isEmpty() )
     513             :         {
     514           0 :             OUStringBuffer aBuffer;
     515           0 :             aBuffer.append( ODatabaseModelImpl::getObjectContainerStorageName( m_bForm ? ODatabaseModelImpl::E_FORM : ODatabaseModelImpl::E_REPORT ) );
     516           0 :             aBuffer.append( '/' );
     517           0 :             aBuffer.append( m_pImpl->m_aProps.sPersistentName );
     518           0 :             sPersistentPath = aBuffer.makeStringAndClear();
     519             :         }
     520           0 :         o_rValue <<= sPersistentPath;
     521          26 :         return;
     522             :     }
     523             : 
     524          26 :     OPropertyStateContainer::getFastPropertyValue( o_rValue, i_nHandle );
     525             : }
     526             : 
     527           0 : Reference< XPropertySetInfo > SAL_CALL ODocumentDefinition::getPropertySetInfo(  ) throw(RuntimeException, std::exception)
     528             : {
     529           0 :     Reference<XPropertySetInfo> xInfo( createPropertySetInfo( getInfoHelper() ) );
     530           0 :     return xInfo;
     531             : }
     532             : 
     533          80 : IPropertyArrayHelper& ODocumentDefinition::getInfoHelper()
     534             : {
     535          80 :     return *getArrayHelper();
     536             : }
     537             : 
     538          14 : IPropertyArrayHelper* ODocumentDefinition::createArrayHelper( ) const
     539             : {
     540             :     // properties maintained by our base class (see registerProperties)
     541          14 :     Sequence< Property > aProps;
     542          14 :     describeProperties( aProps );
     543             : 
     544             :     // properties not maintained by our base class
     545          28 :     Sequence< Property > aManualProps( 1 );
     546          14 :     aManualProps[0].Name = PROPERTY_PERSISTENT_PATH;
     547          14 :     aManualProps[0].Handle = PROPERTY_ID_PERSISTENT_PATH;
     548          14 :     aManualProps[0].Type = ::cppu::UnoType<OUString>::get();
     549          14 :     aManualProps[0].Attributes = PropertyAttribute::READONLY;
     550             : 
     551          28 :     return new OPropertyArrayHelper( ::comphelper::concatSequences( aProps, aManualProps ) );
     552             : }
     553             : 
     554             : class OExecuteImpl
     555             : {
     556             :     bool& m_rbSet;
     557             : public:
     558           0 :     OExecuteImpl(bool& _rbSet) : m_rbSet(_rbSet){ m_rbSet=true; }
     559           0 :     ~OExecuteImpl(){ m_rbSet = false; }
     560             : };
     561             : 
     562             : namespace
     563             : {
     564           0 :     bool lcl_extractOpenMode( const Any& _rValue, sal_Int32& _out_rMode )
     565             :     {
     566           0 :         OpenCommandArgument aOpenCommand;
     567           0 :         if ( _rValue >>= aOpenCommand )
     568           0 :             _out_rMode = aOpenCommand.Mode;
     569             :         else
     570             :         {
     571           0 :             OpenCommandArgument2 aOpenCommand2;
     572           0 :             if ( _rValue >>= aOpenCommand2 )
     573           0 :                 _out_rMode = aOpenCommand2.Mode;
     574             :             else
     575           0 :                 return false;
     576             :         }
     577           0 :         return true;
     578             :     }
     579             : }
     580             : 
     581           0 : void ODocumentDefinition::impl_removeFrameFromDesktop_throw( const Reference<XComponentContext> & _rxContext, const Reference< XFrame >& _rxFrame )
     582             : {
     583           0 :     Reference< XDesktop2 > xDesktop = Desktop::create( _rxContext );
     584           0 :     Reference< XFrames > xFrames( xDesktop->getFrames(), UNO_QUERY_THROW );
     585           0 :     xFrames->remove( _rxFrame );
     586           0 : }
     587             : 
     588           0 : void ODocumentDefinition::impl_onActivateEmbeddedObject_nothrow( const bool i_bReactivated )
     589             : {
     590             :     try
     591             :     {
     592           0 :         Reference< XModel > xModel( getComponent(), UNO_QUERY );
     593           0 :         Reference< XController > xController( xModel.is() ? xModel->getCurrentController() : Reference< XController >() );
     594           0 :         if ( !xController.is() )
     595           0 :             return;
     596             : 
     597           0 :         if ( !m_xListener.is() )
     598             :             // it's the first time the embedded object has been activated
     599             :             // create an OEmbedObjectHolder
     600           0 :             m_xListener = new OEmbedObjectHolder( m_xEmbeddedObject, this );
     601             : 
     602             :         // raise the window to top (especially necessary if this is not the first activation)
     603           0 :         Reference< XFrame > xFrame( xController->getFrame(), UNO_SET_THROW );
     604           0 :         Reference< XTopWindow > xTopWindow( xFrame->getContainerWindow(), UNO_QUERY_THROW );
     605           0 :         xTopWindow->toFront();
     606             : 
     607             :         // remove the frame from the desktop's frame collection because we need full control of it.
     608           0 :         impl_removeFrameFromDesktop_throw( m_aContext, xFrame );
     609             : 
     610             :         // ensure that we ourself are kept alive as long as the embedded object's frame is
     611             :         // opened
     612           0 :         LifetimeCoupler::couple( *this, xFrame.get() );
     613             : 
     614             :         // init the edit view
     615           0 :         if ( m_bForm && m_bOpenInDesign && !i_bReactivated )
     616           0 :             impl_initFormEditView( xController );
     617             :     }
     618           0 :     catch( const RuntimeException& )
     619             :     {
     620             :         DBG_UNHANDLED_EXCEPTION();
     621             :     }
     622             : }
     623             : 
     624             : namespace
     625             : {
     626             :     // PreserveVisualAreaSize
     627             :     /** stack-guard for preserving the size of the VisArea of an XModel
     628             :     */
     629             :     class PreserveVisualAreaSize
     630             :     {
     631             :     private:
     632             :         Reference< XVisualObject >  m_xVisObject;
     633             :         awt::Size m_aOriginalSize;
     634             : 
     635             :     public:
     636           0 :         inline PreserveVisualAreaSize( const Reference< XModel >& _rxModel )
     637           0 :             :m_xVisObject( _rxModel, UNO_QUERY )
     638             :         {
     639           0 :             if ( m_xVisObject.is() )
     640             :             {
     641             :                 try
     642             :                 {
     643           0 :                     m_aOriginalSize = m_xVisObject->getVisualAreaSize( Aspects::MSOLE_CONTENT );
     644             :                 }
     645           0 :                 catch ( const Exception& )
     646             :                 {
     647             :                     OSL_FAIL( "PreserveVisualAreaSize::PreserveVisualAreaSize: caught an exception!" );
     648             :                 }
     649             :             }
     650           0 :         }
     651             : 
     652           0 :         inline ~PreserveVisualAreaSize()
     653           0 :         {
     654           0 :             if ( m_xVisObject.is() && m_aOriginalSize.Width && m_aOriginalSize.Height )
     655             :             {
     656             :                 try
     657             :                 {
     658           0 :                     m_xVisObject->setVisualAreaSize( Aspects::MSOLE_CONTENT, m_aOriginalSize );
     659             :                 }
     660           0 :                 catch ( const Exception& )
     661             :                 {
     662             :                     OSL_FAIL( "PreserveVisualAreaSize::~PreserveVisualAreaSize: caught an exception!" );
     663             :                 }
     664             :             }
     665           0 :         }
     666             :     };
     667             : 
     668             :     // LayoutManagerLock
     669             :     /** helper class for stack-usage which during its lifetime locks a layout manager
     670             :     */
     671             :     class LayoutManagerLock
     672             :     {
     673             :     private:
     674             :         Reference< XLayoutManager > m_xLayoutManager;
     675             : 
     676             :     public:
     677           0 :         inline LayoutManagerLock( const Reference< XController >& _rxController )
     678           0 :         {
     679             :             OSL_ENSURE( _rxController.is(), "LayoutManagerLock::LayoutManagerLock: this will crash!" );
     680           0 :             Reference< XFrame > xFrame( _rxController->getFrame() );
     681             :             try
     682             :             {
     683           0 :                 Reference< XPropertySet > xPropSet( xFrame, UNO_QUERY_THROW );
     684             :                 m_xLayoutManager.set(
     685           0 :                     xPropSet->getPropertyValue( "LayoutManager" ),
     686           0 :                     UNO_QUERY_THROW );
     687           0 :                 m_xLayoutManager->lock();
     688             : 
     689             :             }
     690           0 :             catch( const Exception& )
     691             :             {
     692             :                 OSL_FAIL( "LayoutManagerLock::LayoutManagerLock: caught an exception!" );
     693           0 :             }
     694           0 :         }
     695             : 
     696           0 :         inline ~LayoutManagerLock()
     697           0 :         {
     698             :             try
     699             :             {
     700             :                 // unlock the layout manager
     701           0 :                 if ( m_xLayoutManager.is() )
     702           0 :                     m_xLayoutManager->unlock();
     703             :             }
     704           0 :             catch( const Exception& )
     705             :             {
     706             :                 OSL_FAIL( "LayoutManagerLock::~LayoutManagerLock: caught an exception!" );
     707             :             }
     708           0 :         }
     709             :     };
     710             : }
     711             : 
     712           0 : void ODocumentDefinition::impl_initFormEditView( const Reference< XController >& _rxController )
     713             : {
     714             :     try
     715             :     {
     716           0 :         Reference< XViewSettingsSupplier > xSettingsSupplier( _rxController, UNO_QUERY_THROW );
     717           0 :         Reference< XPropertySet > xViewSettings( xSettingsSupplier->getViewSettings(), UNO_QUERY_THROW );
     718             : 
     719             :         // the below code could indirectly tamper with the "modified" flag of the model, temporarily disable this
     720           0 :         LockModifiable aLockModify( _rxController->getModel() );
     721             : 
     722             :         // The visual area size can be changed by the setting of the following properties
     723             :         // so it should be restored later
     724           0 :         PreserveVisualAreaSize aPreserveVisAreaSize( _rxController->getModel() );
     725             : 
     726             :         // Layout manager should not layout while the size is still not restored
     727             :         // so it will stay locked for this time
     728           0 :         LayoutManagerLock aLockLayout( _rxController );
     729             : 
     730             :         // setting of the visual properties
     731           0 :         xViewSettings->setPropertyValue("ShowRulers",makeAny(sal_True));
     732           0 :         xViewSettings->setPropertyValue("ShowVertRuler",makeAny(sal_True));
     733           0 :         xViewSettings->setPropertyValue("ShowHoriRuler",makeAny(sal_True));
     734           0 :         xViewSettings->setPropertyValue("IsRasterVisible",makeAny(sal_True));
     735           0 :         xViewSettings->setPropertyValue("IsSnapToRaster",makeAny(sal_True));
     736           0 :         xViewSettings->setPropertyValue("ShowOnlineLayout",makeAny(sal_True));
     737           0 :         xViewSettings->setPropertyValue("RasterSubdivisionX",makeAny(sal_Int32(5)));
     738           0 :         xViewSettings->setPropertyValue("RasterSubdivisionY",makeAny(sal_Int32(5)));
     739             :     }
     740           0 :     catch( const Exception& )
     741             :     {
     742             :         DBG_UNHANDLED_EXCEPTION();
     743             :     }
     744           0 : }
     745             : 
     746           0 : void ODocumentDefinition::impl_showOrHideComponent_throw( const bool i_bShow )
     747             : {
     748           0 :     const sal_Int32 nCurrentState = m_xEmbeddedObject.is() ? m_xEmbeddedObject->getCurrentState() : EmbedStates::LOADED;
     749           0 :     switch ( nCurrentState )
     750             :     {
     751             :     default:
     752             :     case EmbedStates::LOADED:
     753           0 :         throw embed::WrongStateException( OUString(), *this );
     754             : 
     755             :     case EmbedStates::RUNNING:
     756           0 :         if ( !i_bShow )
     757             :             // fine, a running (and not yet active) object is never visible
     758           0 :             return;
     759             :         {
     760           0 :             LockModifiable aLockModify( impl_getComponent_throw() );
     761           0 :             m_xEmbeddedObject->changeState( EmbedStates::ACTIVE );
     762           0 :             impl_onActivateEmbeddedObject_nothrow( false );
     763             :         }
     764           0 :         break;
     765             : 
     766             :     case EmbedStates::ACTIVE:
     767             :     {
     768           0 :         Reference< XModel > xEmbeddedDoc( impl_getComponent_throw( true ), UNO_QUERY_THROW );
     769           0 :         Reference< XController > xEmbeddedController( xEmbeddedDoc->getCurrentController(), UNO_SET_THROW );
     770           0 :         Reference< XFrame > xEmbeddedFrame( xEmbeddedController->getFrame(), UNO_SET_THROW );
     771           0 :         Reference< XWindow > xEmbeddedWindow( xEmbeddedFrame->getContainerWindow(), UNO_SET_THROW );
     772           0 :         xEmbeddedWindow->setVisible( i_bShow );
     773             :     }
     774           0 :     break;
     775             :     }
     776             : }
     777             : 
     778           0 : Any ODocumentDefinition::onCommandOpenSomething( const Any& _rOpenArgument, const bool _bActivate,
     779             :         const Reference< XCommandEnvironment >& _rxEnvironment )
     780             : {
     781           0 :     OExecuteImpl aExecuteGuard( m_bInExecute );
     782             : 
     783           0 :     Reference< XConnection > xConnection;
     784           0 :     sal_Int32 nOpenMode = OpenMode::DOCUMENT;
     785             : 
     786           0 :     ::comphelper::NamedValueCollection aDocumentArgs;
     787             : 
     788             :     // for the document, default to the interaction handler as used for loading the DB doc
     789             :     // This might be overwritten below, when examining _rOpenArgument.
     790           0 :     const ::comphelper::NamedValueCollection& aDBDocArgs( m_pImpl->m_pDataSource->getMediaDescriptor() );
     791           0 :     Reference< XInteractionHandler > xHandler( aDBDocArgs.getOrDefault( "InteractionHandler", Reference< XInteractionHandler >() ) );
     792           0 :     if ( xHandler.is() )
     793           0 :         aDocumentArgs.put( "InteractionHandler", xHandler );
     794             : 
     795           0 :     ::boost::optional< sal_Int16 > aDocumentMacroMode;
     796             : 
     797           0 :     if ( !lcl_extractOpenMode( _rOpenArgument, nOpenMode ) )
     798             :     {
     799           0 :         Sequence< PropertyValue > aArguments;
     800           0 :         if ( _rOpenArgument >>= aArguments )
     801             :         {
     802           0 :             const PropertyValue* pIter = aArguments.getConstArray();
     803           0 :             const PropertyValue* pEnd  = pIter + aArguments.getLength();
     804           0 :             for ( ;pIter != pEnd; ++pIter )
     805             :             {
     806           0 :                 if ( pIter->Name == PROPERTY_ACTIVE_CONNECTION )
     807             :                 {
     808           0 :                     xConnection.set( pIter->Value, UNO_QUERY );
     809           0 :                     continue;
     810             :                 }
     811             : 
     812           0 :                 if ( lcl_extractOpenMode( pIter->Value, nOpenMode ) )
     813           0 :                     continue;
     814             : 
     815           0 :                 if ( pIter->Name == "MacroExecutionMode" )
     816             :                 {
     817           0 :                     sal_Int16 nMacroExecMode( !aDocumentMacroMode ? MacroExecMode::USE_CONFIG : *aDocumentMacroMode );
     818           0 :                     OSL_VERIFY( pIter->Value >>= nMacroExecMode );
     819           0 :                     aDocumentMacroMode.reset( nMacroExecMode );
     820           0 :                     continue;
     821             :                 }
     822             : 
     823             :                 // unknown argument -> pass to the loaded document
     824           0 :                 aDocumentArgs.put( pIter->Name, pIter->Value );
     825             :             }
     826           0 :         }
     827             :     }
     828             : 
     829           0 :     bool bExecuteDBDocMacros = m_pImpl->m_pDataSource->checkMacrosOnLoading();
     830             :         // Note that this call implies the user might be asked for the macro execution mode.
     831             :         // Normally, this would happen when the database document is loaded, and subsequent calls
     832             :         // will simply use the user's decision from this point in time.
     833             :         // However, it is possible to programmatically load forms/reports, without actually
     834             :         // loading the database document into a frame. In this case, the user will be asked
     835             :         // here and now.
     836             :         // #i87741#
     837             : 
     838             :     // allow the command arguments to downgrade the macro execution mode, but not to upgrade
     839             :     // it
     840           0 :     if  (   ( m_pImpl->m_pDataSource->getImposedMacroExecMode() == MacroExecMode::USE_CONFIG )
     841           0 :         &&  bExecuteDBDocMacros
     842             :         )
     843             :     {
     844             :         // while loading the whole database document, USE_CONFIG, was passed.
     845             :         // Additionally, *by now* executing macros from the DB doc is allowed (this is what bExecuteDBDocMacros
     846             :         // indicates). This means either one of:
     847             :         // 1. The DB doc or one of the sub docs contained macros and
     848             :         // 1a. the user explicitly allowed executing them
     849             :         // 1b. the configuration allows executing them without asking the user
     850             :         // 2. Neither the DB doc nor the sub docs contained macros, thus macro
     851             :         //    execution was silently enabled, assuming that any macro will be a
     852             :         //    user-created macro
     853             :         //
     854             :         // The problem with this: If the to-be-opened sub document has macros embedded in
     855             :         // the content.xml (which is valid ODF, but normally not produced by OOo itself),
     856             :         // then this has not been detected while loading the database document - it would
     857             :         // be too expensive, as it effectively would require loading all forms/reports.
     858             :         //
     859             :         // So, in such a case, and with 2. above, we would silently execute those macros,
     860             :         // regardless of the global security settings - which would be a security issue, of
     861             :         // course.
     862           0 :         if ( m_pImpl->m_pDataSource->determineEmbeddedMacros() == ODatabaseModelImpl::eNoMacros )
     863             :         {
     864             :             // this is case 2. from above
     865             :             // So, pass a USE_CONFIG to the to-be-loaded document. This means that
     866             :             // the user will be prompted with a security message upon opening this
     867             :             // sub document, in case the settings require this, *and* the document
     868             :             // contains scripts in the content.xml. But this is better than the security
     869             :             // issue we had before ...
     870           0 :             aDocumentMacroMode.reset( MacroExecMode::USE_CONFIG );
     871             :         }
     872             :     }
     873             : 
     874           0 :     if ( !aDocumentMacroMode )
     875             :     {
     876             :         // nobody so far felt responsible for setting it
     877             :         // => use the DBDoc-wide macro exec mode for the document, too
     878           0 :         aDocumentMacroMode.reset( bExecuteDBDocMacros ? MacroExecMode::ALWAYS_EXECUTE_NO_WARN : MacroExecMode::NEVER_EXECUTE );
     879             :     }
     880           0 :     aDocumentArgs.put( "MacroExecutionMode", *aDocumentMacroMode );
     881             : 
     882           0 :     if  (   ( nOpenMode == OpenMode::ALL )
     883           0 :         ||  ( nOpenMode == OpenMode::FOLDERS )
     884           0 :         ||  ( nOpenMode == OpenMode::DOCUMENTS )
     885           0 :         ||  ( nOpenMode == OpenMode::DOCUMENT_SHARE_DENY_NONE )
     886           0 :         ||  ( nOpenMode == OpenMode::DOCUMENT_SHARE_DENY_WRITE )
     887             :         )
     888             :     {
     889             :         // not supported
     890             :         ucbhelper::cancelCommandExecution(
     891             :                 makeAny( UnsupportedOpenModeException(
     892             :                                 OUString(),
     893             :                                 static_cast< cppu::OWeakObject * >( this ),
     894             :                                 sal_Int16( nOpenMode ) ) ),
     895           0 :                 _rxEnvironment );
     896             :         // Unreachable
     897             :         OSL_FAIL( "unreachable" );
     898             :       }
     899             : 
     900             :     OSL_ENSURE( !m_pImpl->m_aProps.sPersistentName.isEmpty(),
     901             :         "ODocumentDefinition::onCommandOpenSomething: no persistent name - cannot load!" );
     902           0 :     if ( m_pImpl->m_aProps.sPersistentName.isEmpty() )
     903           0 :         return Any();
     904             : 
     905             :     // embedded objects themself do not support the hidden flag. We implement support for
     906             :     // it by changing the STATE to RUNNING only, instead of ACTIVE.
     907           0 :     bool bOpenHidden = aDocumentArgs.getOrDefault( "Hidden", false );
     908           0 :     aDocumentArgs.remove( "Hidden" );
     909             : 
     910           0 :     loadEmbeddedObject( xConnection, Sequence< sal_Int8 >(), aDocumentArgs.getPropertyValues(), false, !m_bOpenInDesign );
     911             :     OSL_ENSURE( m_xEmbeddedObject.is(), "ODocumentDefinition::onCommandOpenSomething: what's this?" );
     912           0 :     if ( !m_xEmbeddedObject.is() )
     913           0 :         return Any();
     914             : 
     915           0 :     Reference< XModel > xModel( getComponent(), UNO_QUERY );
     916           0 :     Reference< report::XReportDefinition > xReportDefinition(xModel,UNO_QUERY);
     917             : 
     918           0 :     Reference< XModule > xModule( xModel, UNO_QUERY );
     919           0 :     if ( xModule.is() )
     920             :     {
     921           0 :         if ( m_bForm )
     922           0 :             xModule->setIdentifier( "com.sun.star.sdb.FormDesign" );
     923           0 :         else if ( !xReportDefinition.is() )
     924           0 :             xModule->setIdentifier( "com.sun.star.text.TextDocument" );
     925             : 
     926           0 :         updateDocumentTitle();
     927             :     }
     928             : 
     929           0 :     bool bIsAliveNewStyleReport = ( !m_bOpenInDesign && xReportDefinition.is() );
     930           0 :     if ( bIsAliveNewStyleReport )
     931             :     {
     932             :         // we are in ReadOnly mode
     933             :         // we would like to open the Writer or Calc with the report direct, without design it.
     934           0 :         Reference< report::XReportEngine > xReportEngine( m_aContext->getServiceManager()->createInstanceWithContext("com.sun.star.comp.report.OReportEngineJFree", m_aContext), UNO_QUERY_THROW );
     935             : 
     936           0 :         xReportEngine->setReportDefinition(xReportDefinition);
     937           0 :         xReportEngine->setActiveConnection(m_xLastKnownConnection);
     938           0 :         if ( bOpenHidden )
     939           0 :             return makeAny( xReportEngine->createDocumentModel() );
     940           0 :         return makeAny( xReportEngine->createDocumentAlive( NULL ) );
     941             :     }
     942             : 
     943           0 :     if ( _bActivate && !bOpenHidden )
     944             :     {
     945           0 :         LockModifiable aLockModify( impl_getComponent_throw() );
     946           0 :         m_xEmbeddedObject->changeState( EmbedStates::ACTIVE );
     947           0 :         impl_onActivateEmbeddedObject_nothrow( false );
     948             :     }
     949             :     else
     950             :     {
     951             :         // ensure that we ourself are kept alive as long as the document is open
     952           0 :         LifetimeCoupler::couple( *this, xModel.get() );
     953             :     }
     954             : 
     955           0 :     if ( !m_bForm && m_pImpl->m_aProps.bAsTemplate && !m_bOpenInDesign )
     956           0 :         ODocumentDefinition::fillReportData( m_aContext, getComponent(), xConnection );
     957             : 
     958           0 :     return makeAny( xModel );
     959             : }
     960             : 
     961           0 : Any SAL_CALL ODocumentDefinition::execute( const Command& aCommand, sal_Int32 CommandId, const Reference< XCommandEnvironment >& Environment ) throw (Exception, CommandAbortedException, RuntimeException, std::exception)
     962             : {
     963           0 :     Any aRet;
     964             : 
     965           0 :     bool bOpen = aCommand.Name == "open";
     966           0 :     bool bOpenInDesign = aCommand.Name == "openDesign";
     967           0 :     bool bOpenForMail = aCommand.Name == "openForMail";
     968           0 :     if ( bOpen || bOpenInDesign || bOpenForMail )
     969             :     {
     970             :         // opening the document involves a lot of VCL code, which is not thread-safe, but needs the SolarMutex locked.
     971             :         // Unfortunately, the DocumentDefinition, as well as the EmbeddedObject implementation, calls into VCL-dependent
     972             :         // components *without* releasing the own mutex, which is a guaranteed recipe for deadlocks.
     973             :         // We have control over this implementation here, and in modifying it to release the own mutex before calling into
     974             :         // the VCL-dependent components is not too difficult (was there, seen it).
     975             :         // However, we do /not/ have control over the EmbeddedObject implementation, and from a first look, it seems as
     976             :         // making it release the own mutex before calling SolarMutex-code is ... difficult, at least.
     977             :         // So, to be on the same side, we lock the SolarMutex here. Yes, it sucks.
     978           0 :         ::SolarMutexGuard aSolarGuard;
     979           0 :         ::osl::ClearableMutexGuard aGuard(m_aMutex);
     980           0 :         if ( m_bInExecute )
     981           0 :             return aRet;
     982             : 
     983           0 :         bool bActivateObject = true;
     984           0 :         if ( bOpenForMail )
     985             :         {
     986             :             OSL_FAIL( "ODocumentDefinition::execute: 'openForMail' should not be used anymore - use the 'Hidden' parameter instead!" );
     987           0 :             bActivateObject = false;
     988             :         }
     989             : 
     990             :         // if the object is already opened, do nothing
     991           0 :         if ( m_xEmbeddedObject.is() )
     992             :         {
     993           0 :             sal_Int32 nCurrentState = m_xEmbeddedObject->getCurrentState();
     994           0 :             bool bIsActive = ( nCurrentState == EmbedStates::ACTIVE );
     995             : 
     996           0 :             if ( bIsActive )
     997             :             {
     998             :                 // exception: new-style reports always create a new document when "open" is executed
     999           0 :                 Reference< report::XReportDefinition > xReportDefinition( impl_getComponent_throw( false ), UNO_QUERY );
    1000           0 :                 bool bIsAliveNewStyleReport = ( xReportDefinition.is() && ( bOpen || bOpenForMail ) );
    1001             : 
    1002           0 :                 if ( !bIsAliveNewStyleReport )
    1003             :                 {
    1004           0 :                     impl_onActivateEmbeddedObject_nothrow( true );
    1005           0 :                     return makeAny( getComponent() );
    1006           0 :                 }
    1007             :             }
    1008             :         }
    1009             : 
    1010           0 :         m_bOpenInDesign = bOpenInDesign || bOpenForMail;
    1011           0 :         return onCommandOpenSomething( aCommand.Argument, bActivateObject, Environment );
    1012             :     }
    1013             : 
    1014           0 :     ::osl::ClearableMutexGuard aGuard(m_aMutex);
    1015           0 :     if ( m_bInExecute )
    1016           0 :         return aRet;
    1017             : 
    1018           0 :     if ( aCommand.Name == "copyTo" )
    1019             :     {
    1020           0 :         Sequence<Any> aIni;
    1021           0 :         aCommand.Argument >>= aIni;
    1022           0 :         if ( aIni.getLength() != 2 )
    1023             :         {
    1024             :             OSL_FAIL( "Wrong argument type!" );
    1025             :             ucbhelper::cancelCommandExecution(
    1026             :                 makeAny( IllegalArgumentException(
    1027             :                                     OUString(),
    1028             :                                     static_cast< cppu::OWeakObject * >( this ),
    1029             :                                     -1 ) ),
    1030           0 :                 Environment );
    1031             :             // Unreachable
    1032             :         }
    1033           0 :         Reference< XStorage> xDest(aIni[0],UNO_QUERY);
    1034           0 :         OUString sPersistentName;
    1035           0 :         aIni[1] >>= sPersistentName;
    1036           0 :         Reference< XStorage> xStorage = getContainerStorage();
    1037             : 
    1038           0 :         xStorage->copyElementTo(m_pImpl->m_aProps.sPersistentName,xDest,sPersistentName);
    1039             :     }
    1040           0 :     else if ( aCommand.Name == "preview" )
    1041             :     {
    1042           0 :         onCommandPreview(aRet);
    1043             :     }
    1044           0 :     else if ( aCommand.Name == "insert" )
    1045             :     {
    1046           0 :         Sequence<Any> aIni;
    1047           0 :         aCommand.Argument >>= aIni;
    1048           0 :         if ( !aIni.getLength() )
    1049             :         {
    1050             :             OSL_FAIL( "Wrong argument count!" );
    1051             :             ucbhelper::cancelCommandExecution(
    1052             :                 makeAny( IllegalArgumentException(
    1053             :                                     OUString(),
    1054             :                                     static_cast< cppu::OWeakObject * >( this ),
    1055             :                                     -1 ) ),
    1056           0 :                 Environment );
    1057             :             // Unreachable
    1058             :         }
    1059           0 :         OUString sURL;
    1060           0 :         aIni[0] >>= sURL;
    1061           0 :         onCommandInsert( sURL, Environment );
    1062             :     }
    1063           0 :     else if (   aCommand.Name == "getdocumentinfo"   // compatibility
    1064           0 :             ||  aCommand.Name == "getDocumentInfo" )
    1065             :     {
    1066           0 :         onCommandGetDocumentProperties( aRet );
    1067             :     }
    1068           0 :     else if ( aCommand.Name == "delete" )
    1069             :     {
    1070             :         // delete
    1071           0 :         closeObject();
    1072           0 :         Reference< XStorage> xStorage = getContainerStorage();
    1073           0 :         if ( xStorage.is() )
    1074           0 :             xStorage->removeElement(m_pImpl->m_aProps.sPersistentName);
    1075             : 
    1076           0 :         dispose();
    1077             : 
    1078             :     }
    1079           0 :     else if (   aCommand.Name == "storeOwn" // compatibility
    1080           0 :             ||  aCommand.Name == "store"
    1081             :             )
    1082             :     {
    1083           0 :         impl_store_throw();
    1084             :     }
    1085           0 :     else if (   aCommand.Name == "shutdown" // compatibility
    1086           0 :             ||  aCommand.Name == "close"
    1087             :             )
    1088             :     {
    1089           0 :         aRet <<= impl_close_throw();
    1090             :     }
    1091           0 :     else if ( aCommand.Name == "show" )
    1092             :     {
    1093           0 :         impl_showOrHideComponent_throw( true );
    1094             :     }
    1095           0 :     else if ( aCommand.Name == "hide" )
    1096             :     {
    1097           0 :         impl_showOrHideComponent_throw( false );
    1098             :     }
    1099             :     else
    1100             :     {
    1101           0 :         aRet = OContentHelper::execute(aCommand,CommandId,Environment);
    1102             :     }
    1103             : 
    1104           0 :     return aRet;
    1105             : }
    1106             : 
    1107             : namespace
    1108             : {
    1109           0 :     void lcl_resetChildFormsToEmptyDataSource( const Reference< XIndexAccess>& _rxFormsContainer )
    1110             :     {
    1111             :         OSL_PRECOND( _rxFormsContainer.is(), "lcl_resetChildFormsToEmptyDataSource: illegal call!" );
    1112           0 :         sal_Int32 count = _rxFormsContainer->getCount();
    1113           0 :         for ( sal_Int32 i = 0; i < count; ++i )
    1114             :         {
    1115           0 :             Reference< XForm > xForm( _rxFormsContainer->getByIndex( i ), UNO_QUERY );
    1116           0 :             if ( !xForm.is() )
    1117           0 :                 continue;
    1118             : 
    1119             :             // if the element is a form, reset its DataSourceName property to an empty string
    1120             :             try
    1121             :             {
    1122           0 :                 Reference< XPropertySet > xFormProps( xForm, UNO_QUERY_THROW );
    1123           0 :                 xFormProps->setPropertyValue( PROPERTY_DATASOURCENAME, makeAny( OUString() ) );
    1124             :             }
    1125           0 :             catch( const Exception& )
    1126             :             {
    1127             :                 DBG_UNHANDLED_EXCEPTION();
    1128             :             }
    1129             : 
    1130             :             // if the element is a container itself, step down the component hierarchy
    1131           0 :             Reference< XIndexAccess > xContainer( xForm, UNO_QUERY );
    1132           0 :             if ( xContainer.is() )
    1133           0 :                 lcl_resetChildFormsToEmptyDataSource( xContainer );
    1134           0 :         }
    1135           0 :     }
    1136             : 
    1137           0 :     void lcl_resetFormsToEmptyDataSource( const Reference< XEmbeddedObject>& _rxEmbeddedObject )
    1138             :     {
    1139             :         try
    1140             :         {
    1141           0 :             Reference< XDrawPageSupplier > xSuppPage( _rxEmbeddedObject->getComponent(), UNO_QUERY_THROW );
    1142             :                 // if this interface does not exist, then either getComponent returned NULL,
    1143             :                 // or the document is a multi-page document. The latter is allowed, but currently
    1144             :                 // simply not handled by this code, as it would not normally happen.
    1145             : 
    1146           0 :             Reference< XFormsSupplier > xSuppForms( xSuppPage->getDrawPage(), UNO_QUERY_THROW );
    1147           0 :             Reference< XIndexAccess > xForms( xSuppForms->getForms(), UNO_QUERY_THROW );
    1148           0 :             lcl_resetChildFormsToEmptyDataSource( xForms );
    1149             :         }
    1150           0 :         catch( const Exception& )
    1151             :         {
    1152             :             DBG_UNHANDLED_EXCEPTION();
    1153             :         }
    1154             : 
    1155           0 :     }
    1156             : }
    1157             : 
    1158           0 : void ODocumentDefinition::onCommandInsert( const OUString& _sURL, const Reference< XCommandEnvironment >& Environment )
    1159             :     throw( Exception )
    1160             : {
    1161           0 :     osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex );
    1162             : 
    1163             :     // Check, if all required properties were set.
    1164           0 :     if ( _sURL.isEmpty() || m_xEmbeddedObject.is() )
    1165             :     {
    1166             :         OSL_FAIL( "Content::onCommandInsert - property value missing!" );
    1167             : 
    1168           0 :         Sequence< OUString > aProps( 1 );
    1169           0 :         aProps[ 0 ] = PROPERTY_URL;
    1170             :         ucbhelper::cancelCommandExecution(
    1171             :             makeAny( MissingPropertiesException(
    1172             :                                 OUString(),
    1173             :                                 static_cast< cppu::OWeakObject * >( this ),
    1174             :                                 aProps ) ),
    1175           0 :             Environment );
    1176             :         // Unreachable
    1177             :     }
    1178             : 
    1179           0 :     if ( !m_xEmbeddedObject.is() )
    1180             :     {
    1181           0 :         Reference< XStorage> xStorage = getContainerStorage();
    1182           0 :         if ( xStorage.is() )
    1183             :         {
    1184           0 :             Reference< XEmbeddedObjectCreator> xEmbedFactory = EmbeddedObjectCreator::create(m_aContext);
    1185           0 :             Sequence<PropertyValue> aEmpty,aMediaDesc(1);
    1186           0 :             aMediaDesc[0].Name = PROPERTY_URL;
    1187           0 :             aMediaDesc[0].Value <<= _sURL;
    1188           0 :             m_xEmbeddedObject.set(xEmbedFactory->createInstanceInitFromMediaDescriptor( xStorage
    1189           0 :                                                                             ,m_pImpl->m_aProps.sPersistentName
    1190             :                                                                             ,aMediaDesc
    1191           0 :                                                                             ,aEmpty),UNO_QUERY);
    1192             : 
    1193           0 :             lcl_resetFormsToEmptyDataSource( m_xEmbeddedObject );
    1194             :             // #i57669#
    1195             : 
    1196           0 :             Reference<XEmbedPersist> xPersist(m_xEmbeddedObject,UNO_QUERY);
    1197           0 :             if ( xPersist.is() )
    1198             :             {
    1199           0 :                 xPersist->storeOwn();
    1200             :             }
    1201             :             try
    1202             :             {
    1203           0 :                 Reference< com::sun::star::util::XCloseable> xCloseable(m_xEmbeddedObject,UNO_QUERY);
    1204           0 :                 if ( xCloseable.is() )
    1205           0 :                     xCloseable->close(sal_True);
    1206             :             }
    1207           0 :             catch(const Exception&)
    1208             :             {
    1209             :             }
    1210           0 :             m_xEmbeddedObject = NULL;
    1211           0 :         }
    1212             :     }
    1213             : 
    1214           0 :     aGuard.clear();
    1215           0 : }
    1216             : 
    1217           0 : bool ODocumentDefinition::save(bool _bApprove)
    1218             : {
    1219             :     // default handling: instantiate an interaction handler and let it handle the parameter request
    1220           0 :     if ( !m_bOpenInDesign )
    1221           0 :         return false;
    1222             :     try
    1223             :     {
    1224             : 
    1225             :         {
    1226           0 :             ::SolarMutexGuard aSolarGuard;
    1227             : 
    1228             :             // the request
    1229           0 :             Reference<XNameAccess> xName(m_xParentContainer,UNO_QUERY);
    1230           0 :             DocumentSaveRequest aRequest;
    1231           0 :             aRequest.Name = m_pImpl->m_aProps.aTitle;
    1232           0 :             if ( aRequest.Name.isEmpty() )
    1233             :             {
    1234           0 :                 if ( m_bForm )
    1235           0 :                     aRequest.Name = DBACORE_RESSTRING( RID_STR_FORM );
    1236             :                 else
    1237           0 :                     aRequest.Name = DBACORE_RESSTRING( RID_STR_REPORT );
    1238           0 :                 aRequest.Name = ::dbtools::createUniqueName(xName,aRequest.Name);
    1239             :             }
    1240             : 
    1241           0 :             aRequest.Content.set(m_xParentContainer,UNO_QUERY);
    1242           0 :             OInteractionRequest* pRequest = new OInteractionRequest(makeAny(aRequest));
    1243           0 :             Reference< XInteractionRequest > xRequest(pRequest);
    1244             :             // some knittings
    1245             :             // two continuations allowed: OK and Cancel
    1246           0 :             ODocumentSaveContinuation* pDocuSave = NULL;
    1247             : 
    1248           0 :             if ( m_pImpl->m_aProps.aTitle.isEmpty() )
    1249             :             {
    1250           0 :                 pDocuSave = new ODocumentSaveContinuation;
    1251           0 :                 pRequest->addContinuation(pDocuSave);
    1252             :             }
    1253           0 :             if ( _bApprove )
    1254             :             {
    1255           0 :                 OInteraction< XInteractionApprove >* pApprove = new OInteraction< XInteractionApprove >;
    1256           0 :                 pRequest->addContinuation(pApprove);
    1257             :             }
    1258             : 
    1259           0 :             OInteraction< XInteractionDisapprove >* pDisApprove = new OInteraction< XInteractionDisapprove >;
    1260           0 :             pRequest->addContinuation(pDisApprove);
    1261             : 
    1262           0 :             OInteractionAbort* pAbort = new OInteractionAbort;
    1263           0 :             pRequest->addContinuation(pAbort);
    1264             : 
    1265             :             // create the handler, let it handle the request
    1266           0 :             Reference< XInteractionHandler2 > xHandler( InteractionHandler::createWithParent(m_aContext, 0) );
    1267           0 :             xHandler->handle(xRequest);
    1268             : 
    1269           0 :             if ( pAbort->wasSelected() )
    1270           0 :                 return false;
    1271           0 :             if  ( pDisApprove->wasSelected() )
    1272           0 :                 return true;
    1273           0 :             if ( pDocuSave && pDocuSave->wasSelected() )
    1274             :             {
    1275           0 :                 Reference<XNameContainer> xNC( pDocuSave->getContent(), UNO_QUERY_THROW );
    1276             : 
    1277           0 :                 ::osl::ResettableMutexGuard aGuard( m_aMutex );
    1278           0 :                 NameChangeNotifier aNameChangeAndNotify( *this, pDocuSave->getName(), aGuard );
    1279           0 :                 m_pImpl->m_aProps.aTitle = pDocuSave->getName();
    1280             : 
    1281           0 :                 Reference< XContent> xContent = this;
    1282           0 :                 xNC->insertByName(pDocuSave->getName(),makeAny(xContent));
    1283             : 
    1284           0 :                 updateDocumentTitle();
    1285           0 :             }
    1286             :         }
    1287             : 
    1288           0 :         ::osl::MutexGuard aGuard(m_aMutex);
    1289           0 :         Reference<XEmbedPersist> xPersist(m_xEmbeddedObject,UNO_QUERY);
    1290           0 :         if ( xPersist.is() )
    1291             :         {
    1292           0 :             xPersist->storeOwn();
    1293           0 :             notifyDataSourceModified();
    1294           0 :         }
    1295             :     }
    1296           0 :     catch(const Exception&)
    1297             :     {
    1298             :         OSL_FAIL("ODocumentDefinition::save: caught an Exception (tried to let the InteractionHandler handle it)!");
    1299             :     }
    1300           0 :     return true;
    1301             : }
    1302             : 
    1303           0 : bool ODocumentDefinition::saveAs()
    1304             : {
    1305             :     // default handling: instantiate an interaction handler and let it handle the parameter request
    1306           0 :     if ( !m_bOpenInDesign )
    1307           0 :         return false;
    1308             : 
    1309             :     {
    1310           0 :         osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex );
    1311           0 :         if ( m_pImpl->m_aProps.aTitle.isEmpty() )
    1312             :         {
    1313           0 :             aGuard.clear();
    1314           0 :             return save(false); // (sal_False) : we don't want an approve dialog
    1315           0 :         }
    1316             :     }
    1317             :     try
    1318             :     {
    1319             :         {
    1320           0 :             ::SolarMutexGuard aSolarGuard;
    1321             : 
    1322             :             // the request
    1323           0 :             Reference<XNameAccess> xName(m_xParentContainer,UNO_QUERY);
    1324           0 :             DocumentSaveRequest aRequest;
    1325           0 :             aRequest.Name = m_pImpl->m_aProps.aTitle;
    1326             : 
    1327           0 :             aRequest.Content.set(m_xParentContainer,UNO_QUERY);
    1328           0 :             OInteractionRequest* pRequest = new OInteractionRequest(makeAny(aRequest));
    1329           0 :             Reference< XInteractionRequest > xRequest(pRequest);
    1330             :             // some knittings
    1331             :             // two continuations allowed: OK and Cancel
    1332           0 :             ODocumentSaveContinuation* pDocuSave = new ODocumentSaveContinuation;
    1333           0 :             pRequest->addContinuation(pDocuSave);
    1334           0 :             OInteraction< XInteractionDisapprove >* pDisApprove = new OInteraction< XInteractionDisapprove >;
    1335           0 :             pRequest->addContinuation(pDisApprove);
    1336           0 :             OInteractionAbort* pAbort = new OInteractionAbort;
    1337           0 :             pRequest->addContinuation(pAbort);
    1338             : 
    1339             :             // create the handler, let it handle the request
    1340           0 :             Reference< XInteractionHandler2 > xHandler( InteractionHandler::createWithParent(m_aContext, 0) );
    1341           0 :             xHandler->handle(xRequest);
    1342             : 
    1343           0 :             if ( pAbort->wasSelected() )
    1344           0 :                 return false;
    1345           0 :             if  ( pDisApprove->wasSelected() )
    1346           0 :                 return true;
    1347           0 :             if ( pDocuSave->wasSelected() )
    1348             :             {
    1349           0 :                 ::osl::MutexGuard aGuard(m_aMutex);
    1350           0 :                 Reference<XNameContainer> xNC(pDocuSave->getContent(),UNO_QUERY);
    1351           0 :                 if ( xNC.is() )
    1352             :                 {
    1353           0 :                     if ( m_pImpl->m_aProps.aTitle != pDocuSave->getName() )
    1354             :                     {
    1355             :                         try
    1356             :                         {
    1357           0 :                             Reference< XStorage> xStorage = getContainerStorage();
    1358             :                             static const char sBaseName[] = "Obj";
    1359             : 
    1360           0 :                             OUString sPersistentName = ::dbtools::createUniqueName(xStorage,sBaseName);
    1361           0 :                             xStorage->copyElementTo(m_pImpl->m_aProps.sPersistentName,xStorage,sPersistentName);
    1362             : 
    1363           0 :                             OUString sOldName = m_pImpl->m_aProps.aTitle;
    1364           0 :                             rename(pDocuSave->getName());
    1365           0 :                             updateDocumentTitle();
    1366             : 
    1367           0 :                             Sequence< Any > aArguments(3);
    1368           0 :                             PropertyValue aValue;
    1369             :                             // set as folder
    1370           0 :                             aValue.Name = PROPERTY_NAME;
    1371           0 :                             aValue.Value <<= sOldName;
    1372           0 :                             aArguments[0] <<= aValue;
    1373             : 
    1374           0 :                             aValue.Name = PROPERTY_PERSISTENT_NAME;
    1375           0 :                             aValue.Value <<= sPersistentName;
    1376           0 :                             aArguments[1] <<= aValue;
    1377             : 
    1378           0 :                             aValue.Name = PROPERTY_AS_TEMPLATE;
    1379           0 :                             aValue.Value <<= m_pImpl->m_aProps.bAsTemplate;
    1380           0 :                             aArguments[2] <<= aValue;
    1381             : 
    1382           0 :                             Reference< XMultiServiceFactory > xORB( m_xParentContainer, UNO_QUERY_THROW );
    1383           0 :                             Reference< XInterface > xComponent( xORB->createInstanceWithArguments( SERVICE_SDB_DOCUMENTDEFINITION, aArguments ) );
    1384           0 :                             Reference< XNameContainer > xNameContainer( m_xParentContainer, UNO_QUERY_THROW );
    1385           0 :                             xNameContainer->insertByName( sOldName, makeAny( xComponent ) );
    1386             :                         }
    1387           0 :                         catch(const Exception&)
    1388             :                         {
    1389             :                             DBG_UNHANDLED_EXCEPTION();
    1390             :                         }
    1391             :                     }
    1392           0 :                     Reference<XEmbedPersist> xPersist(m_xEmbeddedObject,UNO_QUERY);
    1393           0 :                     if ( xPersist.is() )
    1394             :                     {
    1395           0 :                         xPersist->storeOwn();
    1396           0 :                         notifyDataSourceModified();
    1397           0 :                     }
    1398           0 :                 }
    1399           0 :             }
    1400             :         }
    1401             : 
    1402             :     }
    1403           0 :     catch(const Exception&)
    1404             :     {
    1405             :         OSL_FAIL("ODocumentDefinition::save: caught an Exception (tried to let the InteractionHandler handle it)!");
    1406             :     }
    1407           0 :     return true;
    1408             : }
    1409             : 
    1410             : namespace
    1411             : {
    1412           0 :     void    lcl_putLoadArgs( ::comphelper::NamedValueCollection& _io_rArgs, const optional_bool& _bSuppressMacros, const optional_bool& _bReadOnly )
    1413             :     {
    1414           0 :         if ( !!_bSuppressMacros )
    1415             :         {
    1416           0 :             if ( *_bSuppressMacros )
    1417             :             {
    1418             :                 // if we're to suppress macros, do exactly this
    1419           0 :                 _io_rArgs.put( "MacroExecutionMode", MacroExecMode::NEVER_EXECUTE );
    1420             :             }
    1421             :             else
    1422             :             {
    1423             :                 // otherwise, put the setting only if not already present
    1424           0 :                 if ( !_io_rArgs.has( "MacroExecutionMode" ) )
    1425             :                 {
    1426           0 :                     _io_rArgs.put( "MacroExecutionMode", MacroExecMode::USE_CONFIG );
    1427             :                 }
    1428             :             }
    1429             :         }
    1430             : 
    1431           0 :         if ( !!_bReadOnly )
    1432           0 :             _io_rArgs.put( "ReadOnly", *_bReadOnly );
    1433           0 :     }
    1434             : }
    1435             : 
    1436             : namespace
    1437             : {
    1438           0 :     Reference< XFrame > lcl_getDatabaseDocumentFrame( ODatabaseModelImpl& _rImpl )
    1439             :     {
    1440           0 :         Reference< XModel > xDatabaseDocumentModel( _rImpl.getModel_noCreate() );
    1441             : 
    1442           0 :         Reference< XController > xDatabaseDocumentController;
    1443           0 :         if ( xDatabaseDocumentModel.is() )
    1444           0 :             xDatabaseDocumentController = xDatabaseDocumentModel->getCurrentController();
    1445             : 
    1446           0 :         Reference< XFrame > xFrame;
    1447           0 :         if ( xDatabaseDocumentController.is() )
    1448           0 :             xFrame = xDatabaseDocumentController->getFrame();
    1449             : 
    1450           0 :         return xFrame;
    1451             :     }
    1452             : }
    1453             : 
    1454           0 : bool ODocumentDefinition::objectSupportsEmbeddedScripts() const
    1455             : {
    1456           0 :     bool bAllowDocumentMacros = !m_pImpl->m_pDataSource
    1457           0 :                             ||  ( m_pImpl->m_pDataSource->determineEmbeddedMacros() == ODatabaseModelImpl::eSubDocumentMacros );
    1458             : 
    1459             :     // if *any* of the objects of the database document already has macros, we
    1460             :     // continue to allow it to have them, until the user does a migration.
    1461             :     // If there are no macros, we don't allow them to be created.
    1462             : 
    1463           0 :     return bAllowDocumentMacros;
    1464             : }
    1465             : 
    1466           0 : OUString ODocumentDefinition::determineContentType() const
    1467             : {
    1468           0 :     return lcl_determineContentType_nothrow( getContainerStorage(), m_pImpl->m_aProps.sPersistentName );
    1469             : }
    1470             : 
    1471           0 : void ODocumentDefinition::separateOpenCommandArguments( const Sequence< PropertyValue >& i_rOpenCommandArguments,
    1472             :         ::comphelper::NamedValueCollection& o_rDocumentLoadArgs, ::comphelper::NamedValueCollection& o_rEmbeddedObjectDescriptor )
    1473             : {
    1474           0 :     ::comphelper::NamedValueCollection aOpenCommandArguments( i_rOpenCommandArguments );
    1475             : 
    1476             :     const sal_Char* pObjectDescriptorArgs[] =
    1477             :     {
    1478             :         "RecoveryStorage"
    1479           0 :     };
    1480           0 :     for ( size_t i=0; i < sizeof( pObjectDescriptorArgs ) / sizeof( pObjectDescriptorArgs[0] ); ++i )
    1481             :     {
    1482           0 :         if ( aOpenCommandArguments.has( pObjectDescriptorArgs[i] ) )
    1483             :         {
    1484           0 :             o_rEmbeddedObjectDescriptor.put( pObjectDescriptorArgs[i], aOpenCommandArguments.get( pObjectDescriptorArgs[i] ) );
    1485           0 :             aOpenCommandArguments.remove( pObjectDescriptorArgs[i] );
    1486             :         }
    1487             :     }
    1488             : 
    1489           0 :     o_rDocumentLoadArgs.merge( aOpenCommandArguments, false );
    1490           0 : }
    1491             : 
    1492           0 : Sequence< PropertyValue > ODocumentDefinition::fillLoadArgs( const Reference< XConnection>& _xConnection, const bool _bSuppressMacros, const bool _bReadOnly,
    1493             :         const Sequence< PropertyValue >& i_rOpenCommandArguments, Sequence< PropertyValue >& _out_rEmbeddedObjectDescriptor )
    1494             : {
    1495             :     // (re-)create interceptor, and put it into the descriptor of the embedded object
    1496           0 :     if ( m_pInterceptor )
    1497             :     {
    1498           0 :         m_pInterceptor->dispose();
    1499           0 :         m_pInterceptor->release();
    1500           0 :         m_pInterceptor = NULL;
    1501             :     }
    1502             : 
    1503           0 :     m_pInterceptor = new OInterceptor( this );
    1504           0 :     m_pInterceptor->acquire();
    1505           0 :     Reference<XDispatchProviderInterceptor> xInterceptor = m_pInterceptor;
    1506             : 
    1507           0 :     ::comphelper::NamedValueCollection aEmbeddedDescriptor;
    1508           0 :     aEmbeddedDescriptor.put( "OutplaceDispatchInterceptor", xInterceptor );
    1509             : 
    1510           0 :     ::comphelper::NamedValueCollection aMediaDesc;
    1511           0 :     separateOpenCommandArguments( i_rOpenCommandArguments, aMediaDesc, aEmbeddedDescriptor );
    1512             : 
    1513             :     // create the OutplaceFrameProperties, and put them into the descriptor of the embedded object
    1514           0 :     ::comphelper::NamedValueCollection OutplaceFrameProperties;
    1515           0 :     OutplaceFrameProperties.put( "TopWindow", true );
    1516           0 :     OutplaceFrameProperties.put( "SupportPersistentWindowState", true );
    1517             : 
    1518           0 :     Reference< XFrame > xParentFrame;
    1519           0 :     if ( m_pImpl->m_pDataSource )
    1520           0 :         xParentFrame = lcl_getDatabaseDocumentFrame( *m_pImpl->m_pDataSource );
    1521           0 :     if ( !xParentFrame.is() )
    1522             :     { // i87957 we need a parent frame
    1523           0 :         Reference< XDesktop2 > xDesktop = Desktop::create( m_aContext );
    1524           0 :         xParentFrame.set( xDesktop, UNO_QUERY_THROW );
    1525           0 :         Reference<util::XCloseable> xCloseable(m_pImpl->m_pDataSource->getModel_noCreate(),UNO_QUERY);
    1526           0 :         if ( xCloseable.is() )
    1527             :         {
    1528           0 :             xCloseable->addCloseListener(this);
    1529           0 :             m_bRemoveListener = true;
    1530           0 :         }
    1531             :     }
    1532             :     OSL_ENSURE( xParentFrame.is(), "ODocumentDefinition::fillLoadArgs: no parent frame!" );
    1533           0 :     if  ( xParentFrame.is() )
    1534           0 :         OutplaceFrameProperties.put( "ParentFrame", xParentFrame );
    1535             : 
    1536           0 :     aEmbeddedDescriptor.put( "OutplaceFrameProperties", OutplaceFrameProperties.getNamedValues() );
    1537             : 
    1538             :     // tell the embedded object to have (or not have) script support
    1539           0 :     aEmbeddedDescriptor.put( "EmbeddedScriptSupport", objectSupportsEmbeddedScripts() );
    1540             : 
    1541             :     // tell the embedded object to not participate in the document recovery game - the DB doc will handle it
    1542           0 :     aEmbeddedDescriptor.put( "DocumentRecoverySupport", false );
    1543             : 
    1544             :     // pass the descriptor of the embedded object to the caller
    1545           0 :     aEmbeddedDescriptor >>= _out_rEmbeddedObjectDescriptor;
    1546             : 
    1547             :     // create the ComponentData, and put it into the document's media descriptor
    1548             :     {
    1549           0 :         ::comphelper::NamedValueCollection aComponentData;
    1550           0 :         aComponentData.put( "ActiveConnection", _xConnection );
    1551           0 :         aComponentData.put( "ApplyFormDesignMode", !_bReadOnly );
    1552           0 :         aMediaDesc.put( "ComponentData", aComponentData.getPropertyValues() );
    1553             :     }
    1554             : 
    1555           0 :     if ( !m_pImpl->m_aProps.aTitle.isEmpty() )
    1556           0 :         aMediaDesc.put( "DocumentTitle", m_pImpl->m_aProps.aTitle );
    1557             : 
    1558           0 :     aMediaDesc.put( "DocumentBaseURL", m_pImpl->m_pDataSource->getURL() );
    1559             : 
    1560             :     // put the common load arguments into the document's media descriptor
    1561           0 :     lcl_putLoadArgs( aMediaDesc, optional_bool( _bSuppressMacros ), optional_bool( _bReadOnly ) );
    1562             : 
    1563           0 :     return aMediaDesc.getPropertyValues();
    1564             : }
    1565             : 
    1566           0 : void ODocumentDefinition::loadEmbeddedObject( const Reference< XConnection >& i_rConnection, const Sequence< sal_Int8 >& _aClassID,
    1567             :         const Sequence< PropertyValue >& i_rOpenCommandArguments, const bool _bSuppressMacros, const bool _bReadOnly )
    1568             : {
    1569           0 :     if ( !m_xEmbeddedObject.is() )
    1570             :     {
    1571           0 :         Reference< XStorage> xStorage = getContainerStorage();
    1572           0 :         if ( xStorage.is() )
    1573             :         {
    1574           0 :             Reference< XEmbeddedObjectCreator> xEmbedFactory = OOoEmbeddedObjectFactory::create(m_aContext);
    1575           0 :             OUString sDocumentService;
    1576           0 :             bool bSetSize = false;
    1577           0 :             sal_Int32 nEntryConnectionMode = EntryInitModes::DEFAULT_INIT;
    1578           0 :             Sequence< sal_Int8 > aClassID = _aClassID;
    1579           0 :             if ( aClassID.getLength() )
    1580             :             {
    1581           0 :                 nEntryConnectionMode = EntryInitModes::TRUNCATE_INIT;
    1582           0 :                 bSetSize = true;
    1583             :             }
    1584             :             else
    1585             :             {
    1586           0 :                 sDocumentService = GetDocumentServiceFromMediaType( getContentType(), m_aContext, aClassID );
    1587             :                 // check if we are not a form and
    1588             :                 // the org.libreoffice.report.pentaho.SOReportJobFactory is not present.
    1589           0 :                 if ( !m_bForm && !(sDocumentService == "com.sun.star.text.TextDocument"))
    1590             :                 {
    1591             :                     // we seem to be a "new style" report, check if report extension is present.
    1592           0 :                     Reference< XContentEnumerationAccess > xEnumAccess( m_aContext->getServiceManager(), UNO_QUERY );
    1593           0 :                     const OUString sReportEngineServiceName = ::dbtools::getDefaultReportEngineServiceName(m_aContext);
    1594           0 :                     Reference< XEnumeration > xEnumDrivers = xEnumAccess->createContentEnumeration(sReportEngineServiceName);
    1595           0 :                     if ( !xEnumDrivers.is() || !xEnumDrivers->hasMoreElements() )
    1596             :                     {
    1597           0 :                         com::sun::star::io::WrongFormatException aWFE;
    1598           0 :                         aWFE.Message = DBACORE_RESSTRING( RID_STR_MISSING_EXTENSION );
    1599           0 :                         throw aWFE;
    1600           0 :                     }
    1601             :                 }
    1602           0 :                 if ( !aClassID.getLength() )
    1603             :                 {
    1604           0 :                     if ( m_bForm )
    1605           0 :                         aClassID = MimeConfigurationHelper::GetSequenceClassID(SO3_SW_CLASSID);
    1606             :                     else
    1607             :                     {
    1608           0 :                         aClassID = MimeConfigurationHelper::GetSequenceClassID(SO3_RPT_CLASSID_90);
    1609             :                     }
    1610             :                 }
    1611             :             }
    1612             : 
    1613             :             OSL_ENSURE( aClassID.getLength(),"No Class ID" );
    1614             : 
    1615           0 :             Sequence< PropertyValue > aEmbeddedObjectDescriptor;
    1616             :             Sequence< PropertyValue > aLoadArgs( fillLoadArgs(
    1617           0 :                 i_rConnection, _bSuppressMacros, _bReadOnly, i_rOpenCommandArguments, aEmbeddedObjectDescriptor ) );
    1618             : 
    1619           0 :             m_xEmbeddedObject.set(xEmbedFactory->createInstanceUserInit(aClassID
    1620             :                                                                         ,sDocumentService
    1621             :                                                                         ,xStorage
    1622           0 :                                                                         ,m_pImpl->m_aProps.sPersistentName
    1623             :                                                                         ,nEntryConnectionMode
    1624             :                                                                         ,aLoadArgs
    1625             :                                                                         ,aEmbeddedObjectDescriptor
    1626           0 :                                                                         ),UNO_QUERY);
    1627           0 :             if ( m_xEmbeddedObject.is() )
    1628             :             {
    1629           0 :                 if ( !m_pClientHelper )
    1630             :                 {
    1631           0 :                     m_pClientHelper = new OEmbeddedClientHelper(this);
    1632           0 :                     m_pClientHelper->acquire();
    1633             :                 }
    1634           0 :                 Reference<XEmbeddedClient> xClient = m_pClientHelper;
    1635           0 :                 m_xEmbeddedObject->setClientSite(xClient);
    1636           0 :                 m_xEmbeddedObject->changeState(EmbedStates::RUNNING);
    1637           0 :                 if ( bSetSize )
    1638             :                 {
    1639           0 :                     LockModifiable aLockModify( impl_getComponent_throw( false ) );
    1640             : 
    1641           0 :                     awt::Size aSize( DEFAULT_WIDTH, DEFAULT_HEIGHT );
    1642           0 :                     m_xEmbeddedObject->setVisualAreaSize(Aspects::MSOLE_CONTENT,aSize);
    1643           0 :                 }
    1644           0 :             }
    1645           0 :         }
    1646             :     }
    1647             :     else
    1648             :     {
    1649           0 :         sal_Int32 nCurrentState = m_xEmbeddedObject->getCurrentState();
    1650           0 :         if ( nCurrentState == EmbedStates::LOADED )
    1651             :         {
    1652           0 :             if ( !m_pClientHelper )
    1653             :             {
    1654           0 :                 m_pClientHelper = new OEmbeddedClientHelper(this);
    1655           0 :                 m_pClientHelper->acquire();
    1656             :             }
    1657           0 :             Reference<XEmbeddedClient> xClient = m_pClientHelper;
    1658           0 :             m_xEmbeddedObject->setClientSite(xClient);
    1659             : 
    1660           0 :             Sequence< PropertyValue > aEmbeddedObjectDescriptor;
    1661             :             Sequence< PropertyValue > aLoadArgs( fillLoadArgs(
    1662           0 :                 i_rConnection, _bSuppressMacros, _bReadOnly, i_rOpenCommandArguments, aEmbeddedObjectDescriptor ) );
    1663             : 
    1664           0 :             Reference<XCommonEmbedPersist> xCommon(m_xEmbeddedObject,UNO_QUERY);
    1665             :             OSL_ENSURE(xCommon.is(),"unsupported interface!");
    1666           0 :             if ( xCommon.is() )
    1667           0 :                 xCommon->reload( aLoadArgs, aEmbeddedObjectDescriptor );
    1668           0 :             m_xEmbeddedObject->changeState(EmbedStates::RUNNING);
    1669             :         }
    1670             :         else
    1671             :         {
    1672             :             OSL_ENSURE( ( nCurrentState == EmbedStates::RUNNING ) || ( nCurrentState == EmbedStates::ACTIVE ),
    1673             :                 "ODocumentDefinition::loadEmbeddedObject: unexpected state!" );
    1674             : 
    1675             :             // if the document was already loaded (which means the embedded object is in state RUNNING or ACTIVE),
    1676             :             // then just re-set some model parameters
    1677             :             try
    1678             :             {
    1679             :                 // ensure the media descriptor doesn't contain any values which are intended for the
    1680             :                 // EmbeddedObjectDescriptor only
    1681           0 :                 ::comphelper::NamedValueCollection aEmbeddedObjectDescriptor;
    1682           0 :                 ::comphelper::NamedValueCollection aNewMediaDesc;
    1683           0 :                 separateOpenCommandArguments( i_rOpenCommandArguments, aNewMediaDesc, aEmbeddedObjectDescriptor );
    1684             : 
    1685             :                 // merge the new media descriptor into the existing media descriptor
    1686           0 :                 const Reference< XModel > xModel( getComponent(), UNO_QUERY_THROW );
    1687           0 :                 const Sequence< PropertyValue > aArgs = xModel->getArgs();
    1688           0 :                 ::comphelper::NamedValueCollection aExistentMediaDesc( aArgs );
    1689           0 :                 aExistentMediaDesc.merge( aNewMediaDesc, false );
    1690             : 
    1691           0 :                 lcl_putLoadArgs( aExistentMediaDesc, optional_bool(), optional_bool() );
    1692             :                     // don't put _bSuppressMacros and _bReadOnly here - if the document was already
    1693             :                     // loaded, we should not tamper with its settings.
    1694             :                     // #i88977# #i86872#
    1695             : 
    1696           0 :                 xModel->attachResource( xModel->getURL(), aExistentMediaDesc.getPropertyValues() );
    1697             :             }
    1698           0 :             catch( const Exception& )
    1699             :             {
    1700             :                 DBG_UNHANDLED_EXCEPTION();
    1701             :             }
    1702             :         }
    1703             :     }
    1704             : 
    1705             :     // set the OfficeDatabaseDocument instance as parent of the embedded document
    1706             :     // #i40358#
    1707           0 :     Reference< XChild > xDepdendDocAsChild( getComponent(), UNO_QUERY );
    1708           0 :     if ( xDepdendDocAsChild.is() )
    1709             :     {
    1710             :         try
    1711             :         {
    1712           0 :             if ( !xDepdendDocAsChild->getParent().is() )
    1713             :             {   // first encounter
    1714           0 :                 xDepdendDocAsChild->setParent( getDataSource( m_xParentContainer ) );
    1715             :             }
    1716             :         }
    1717           0 :         catch( const Exception& )
    1718             :         {
    1719             :             DBG_UNHANDLED_EXCEPTION();
    1720             :         }
    1721             :     }
    1722             : 
    1723           0 :     if ( i_rConnection.is() )
    1724           0 :         m_xLastKnownConnection = i_rConnection;
    1725           0 : }
    1726             : 
    1727           0 : void ODocumentDefinition::onCommandPreview(Any& _rImage)
    1728             : {
    1729           0 :     loadEmbeddedObjectForPreview();
    1730           0 :     if ( m_xEmbeddedObject.is() )
    1731             :     {
    1732             :         try
    1733             :         {
    1734           0 :             Reference<XTransferable> xTransfer(getComponent(),UNO_QUERY);
    1735           0 :             if ( xTransfer.is() )
    1736             :             {
    1737           0 :                 DataFlavor aFlavor;
    1738           0 :                 aFlavor.MimeType = "image/png";
    1739           0 :                 aFlavor.HumanPresentableName = "Portable Network Graphics";
    1740           0 :                 aFlavor.DataType = cppu::UnoType<Sequence < sal_Int8 >>::get();
    1741             : 
    1742           0 :                 _rImage = xTransfer->getTransferData( aFlavor );
    1743           0 :             }
    1744             :         }
    1745           0 :         catch( const Exception& )
    1746             :         {
    1747             :         }
    1748             :     }
    1749           0 : }
    1750             : 
    1751           0 : void ODocumentDefinition::getPropertyDefaultByHandle( sal_Int32 /*_nHandle*/, Any& _rDefault ) const
    1752             : {
    1753           0 :     _rDefault.clear();
    1754           0 : }
    1755             : 
    1756           0 : void ODocumentDefinition::onCommandGetDocumentProperties( Any& _rProps )
    1757             : {
    1758           0 :     loadEmbeddedObjectForPreview();
    1759           0 :     if ( m_xEmbeddedObject.is() )
    1760             :     {
    1761             :         try
    1762             :         {
    1763             :             Reference<XDocumentPropertiesSupplier> xDocSup(
    1764           0 :                 getComponent(), UNO_QUERY );
    1765           0 :             if ( xDocSup.is() )
    1766           0 :                 _rProps <<= xDocSup->getDocumentProperties();
    1767             :         }
    1768           0 :         catch( const Exception& )
    1769             :         {
    1770             :             DBG_UNHANDLED_EXCEPTION();
    1771             :         }
    1772             :     }
    1773           0 : }
    1774             : 
    1775           0 : Reference< util::XCloseable > ODocumentDefinition::impl_getComponent_throw( const bool i_ForceCreate )
    1776             : {
    1777             :     OSL_ENSURE(m_xEmbeddedObject.is(),"Illegal call for embeddedObject");
    1778           0 :     Reference< util::XCloseable > xComp;
    1779           0 :     if ( m_xEmbeddedObject.is() )
    1780             :     {
    1781           0 :         int nState = m_xEmbeddedObject->getCurrentState();
    1782           0 :         if ( ( nState == EmbedStates::LOADED ) && i_ForceCreate )
    1783             :         {
    1784           0 :             m_xEmbeddedObject->changeState( EmbedStates::RUNNING );
    1785           0 :             nState = m_xEmbeddedObject->getCurrentState();
    1786             :             OSL_ENSURE( nState == EmbedStates::RUNNING, "ODocumentDefinition::impl_getComponent_throw: could not switch to RUNNING!" );
    1787             :         }
    1788             : 
    1789           0 :         if ( nState == EmbedStates::ACTIVE || nState == EmbedStates::RUNNING )
    1790             :         {
    1791           0 :             Reference<XComponentSupplier> xCompProv(m_xEmbeddedObject,UNO_QUERY);
    1792           0 :             if ( xCompProv.is() )
    1793             :             {
    1794           0 :                 xComp = xCompProv->getComponent();
    1795             :                 OSL_ENSURE(xComp.is(),"No valid component");
    1796           0 :             }
    1797             :         }
    1798             :     }
    1799           0 :     return xComp;
    1800             : }
    1801             : 
    1802           0 : Reference< util::XCloseable > ODocumentDefinition::getComponent() throw (RuntimeException, std::exception)
    1803             : {
    1804           0 :     ::osl::MutexGuard aGuard( m_aMutex );
    1805           0 :     return impl_getComponent_throw( true );
    1806             : }
    1807             : 
    1808             : namespace
    1809             : {
    1810           0 :     Reference< XDatabaseDocumentUI > lcl_getDatabaseDocumentUI( ODatabaseModelImpl& _rModelImpl )
    1811             :     {
    1812           0 :         Reference< XDatabaseDocumentUI > xUI;
    1813             : 
    1814           0 :         Reference< XModel > xModel( _rModelImpl.getModel_noCreate() );
    1815           0 :         if ( xModel.is() )
    1816           0 :             xUI.set( xModel->getCurrentController(), UNO_QUERY );
    1817           0 :         return xUI;
    1818             :     }
    1819             : }
    1820             : 
    1821           0 : Reference< XComponent > ODocumentDefinition::impl_openUI_nolck_throw( bool _bForEditing )
    1822             : {
    1823           0 :     ::osl::ClearableMutexGuard aGuard( m_aMutex );
    1824           0 :     if ( !m_pImpl || !m_pImpl->m_pDataSource )
    1825           0 :         throw DisposedException();
    1826             : 
    1827           0 :     Reference< XComponent > xComponent;
    1828             :     try
    1829             :     {
    1830           0 :         Reference< XDatabaseDocumentUI > xUI( lcl_getDatabaseDocumentUI( *m_pImpl->m_pDataSource ) );
    1831           0 :         if ( !xUI.is() )
    1832             :         {
    1833             :             // no XDatabaseDocumentUI -> just execute the respective command
    1834           0 :             m_bOpenInDesign = _bForEditing;
    1835           0 :             xComponent = Reference<XComponent>(onCommandOpenSomething(Any(), true, NULL), UNO_QUERY);
    1836             :             OSL_ENSURE( xComponent.is(), "ODocumentDefinition::impl_openUI_nolck_throw: opening the thingie failed." );
    1837           0 :             return xComponent;
    1838             :         }
    1839             : 
    1840             : 
    1841           0 :         OUString sName( impl_getHierarchicalName( false ) );
    1842           0 :         sal_Int32 nObjectType = m_bForm ? DatabaseObject::FORM : DatabaseObject::REPORT;
    1843           0 :         aGuard.clear();
    1844             : 
    1845           0 :         xComponent = xUI->loadComponent(
    1846             :             nObjectType, sName, _bForEditing
    1847           0 :         );
    1848             :     }
    1849           0 :     catch( const RuntimeException& ) { throw; }
    1850           0 :     catch( const Exception& )
    1851             :     {
    1852             :         throw WrappedTargetException(
    1853           0 :             OUString(), *this, ::cppu::getCaughtException() );
    1854             :     }
    1855             : 
    1856           0 :     return xComponent;
    1857             : }
    1858             : 
    1859           0 : void ODocumentDefinition::impl_store_throw()
    1860             : {
    1861           0 :     Reference<XEmbedPersist> xPersist( m_xEmbeddedObject, UNO_QUERY );
    1862           0 :     if ( xPersist.is() )
    1863             :     {
    1864           0 :         xPersist->storeOwn();
    1865           0 :         notifyDataSourceModified();
    1866           0 :     }
    1867           0 : }
    1868             : 
    1869           0 : bool ODocumentDefinition::impl_close_throw()
    1870             : {
    1871           0 :     bool bSuccess = prepareClose();
    1872           0 :     if ( bSuccess && m_xEmbeddedObject.is() )
    1873             :     {
    1874           0 :         m_xEmbeddedObject->changeState( EmbedStates::LOADED );
    1875           0 :         bSuccess = m_xEmbeddedObject->getCurrentState() == EmbedStates::LOADED;
    1876             :     }
    1877           0 :     return bSuccess;
    1878             : }
    1879             : 
    1880           0 : Reference< XComponent > SAL_CALL ODocumentDefinition::open(  ) throw (WrappedTargetException, RuntimeException, std::exception)
    1881             : {
    1882           0 :     return impl_openUI_nolck_throw( false );
    1883             : }
    1884             : 
    1885           0 : Reference< XComponent > SAL_CALL ODocumentDefinition::openDesign(  ) throw (WrappedTargetException, RuntimeException, std::exception)
    1886             : {
    1887           0 :     return impl_openUI_nolck_throw( true );
    1888             : }
    1889             : 
    1890           0 : void SAL_CALL ODocumentDefinition::store(  ) throw (WrappedTargetException, RuntimeException, std::exception)
    1891             : {
    1892           0 :     ::osl::MutexGuard aGuard( m_aMutex );
    1893             :     try
    1894             :     {
    1895           0 :         impl_store_throw();
    1896             :     }
    1897           0 :     catch( const RuntimeException& ) { throw; }
    1898           0 :     catch( const Exception& )
    1899             :     {
    1900             :         throw WrappedTargetException(
    1901           0 :             OUString(), *this, ::cppu::getCaughtException() );
    1902           0 :     }
    1903           0 : }
    1904             : 
    1905           0 : sal_Bool SAL_CALL ODocumentDefinition::close(  ) throw (WrappedTargetException, RuntimeException, std::exception)
    1906             : {
    1907           0 :     ::osl::MutexGuard aGuard( m_aMutex );
    1908             : 
    1909           0 :     bool bSuccess = false;
    1910             :     try
    1911             :     {
    1912           0 :         bSuccess = impl_close_throw();
    1913             :     }
    1914           0 :     catch( const RuntimeException& ) { throw; }
    1915           0 :     catch( const Exception& )
    1916             :     {
    1917             :         throw WrappedTargetException(
    1918           0 :             OUString(), *this, ::cppu::getCaughtException() );
    1919             :     }
    1920           0 :     return bSuccess;
    1921             : }
    1922             : 
    1923           0 : OUString SAL_CALL ODocumentDefinition::getHierarchicalName() throw (RuntimeException, std::exception)
    1924             : {
    1925           0 :     ::osl::MutexGuard aGuard( m_aMutex );
    1926           0 :     return impl_getHierarchicalName( false );
    1927             : }
    1928             : 
    1929           0 : OUString SAL_CALL ODocumentDefinition::composeHierarchicalName( const OUString& i_rRelativeName ) throw (IllegalArgumentException, NoSupportException, RuntimeException, std::exception)
    1930             : {
    1931           0 :     OUStringBuffer aBuffer;
    1932           0 :     aBuffer.append( getHierarchicalName() );
    1933           0 :     aBuffer.append( '/' );
    1934           0 :     aBuffer.append( i_rRelativeName );
    1935           0 :     return aBuffer.makeStringAndClear();
    1936             : }
    1937             : 
    1938           0 : void SAL_CALL ODocumentDefinition::rename( const OUString& _rNewName ) throw (SQLException, ElementExistException, RuntimeException, std::exception)
    1939             : {
    1940             :     try
    1941             :     {
    1942           0 :         ::osl::ResettableMutexGuard aGuard(m_aMutex);
    1943           0 :         if ( _rNewName.equals( m_pImpl->m_aProps.aTitle ) )
    1944           0 :             return;
    1945             : 
    1946             :         // document definitions are organized in a hierarchical way, so reject names
    1947             :         // which contain a /, as this is reserved for hierarchy level separation
    1948           0 :         if ( _rNewName.indexOf( '/' ) != -1 )
    1949           0 :             m_aErrorHelper.raiseException( ErrorCondition::DB_OBJECT_NAME_WITH_SLASHES, *this );
    1950             : 
    1951           0 :         NameChangeNotifier aNameChangeAndNotify( *this, _rNewName, aGuard );
    1952           0 :         m_pImpl->m_aProps.aTitle = _rNewName;
    1953             : 
    1954           0 :         if ( m_xEmbeddedObject.is() && m_xEmbeddedObject->getCurrentState() == EmbedStates::ACTIVE )
    1955           0 :             updateDocumentTitle();
    1956             :     }
    1957           0 :     catch(const PropertyVetoException&)
    1958             :     {
    1959           0 :         throw ElementExistException(_rNewName,*this);
    1960             :     }
    1961             : }
    1962             : 
    1963           0 : Reference< XStorage> ODocumentDefinition::getContainerStorage() const
    1964             : {
    1965           0 :     return  m_pImpl->m_pDataSource
    1966           0 :         ?   m_pImpl->m_pDataSource->getStorage( m_bForm ? ODatabaseModelImpl::E_FORM : ODatabaseModelImpl::E_REPORT )
    1967           0 :         :   Reference< XStorage>();
    1968             : }
    1969             : 
    1970           0 : bool ODocumentDefinition::isModified()
    1971             : {
    1972           0 :     osl::ClearableGuard< osl::Mutex > aGuard(m_aMutex);
    1973           0 :     bool bRet = false;
    1974           0 :     if ( m_xEmbeddedObject.is() )
    1975             :     {
    1976           0 :         Reference<XModifiable> xModel(getComponent(),UNO_QUERY);
    1977           0 :         bRet = xModel.is() && xModel->isModified();
    1978             :     }
    1979           0 :     return bRet;
    1980             : }
    1981             : 
    1982           0 : bool ODocumentDefinition::prepareClose()
    1983             : {
    1984           0 :     if ( !m_xEmbeddedObject.is() )
    1985           0 :         return true;
    1986             : 
    1987             :     try
    1988             :     {
    1989             :         // suspend the controller. Embedded objects are not allowed to raise
    1990             :         // own UI at their own discretion, instead, this has always to be triggered
    1991             :         // by the embedding component. Thus, we do the suspend call here.
    1992             :         // #i49370#
    1993             : 
    1994           0 :         Reference< util::XCloseable > xComponent( impl_getComponent_throw( false ) );
    1995           0 :         if ( !xComponent.is() )
    1996           0 :             return true;
    1997             : 
    1998           0 :         Reference< XModel > xModel( xComponent, UNO_QUERY );
    1999           0 :         Reference< XController > xController;
    2000           0 :         if ( xModel.is() )
    2001           0 :             xController = xModel->getCurrentController();
    2002             : 
    2003             :         OSL_ENSURE( xController.is() || ( m_xEmbeddedObject->getCurrentState() < EmbedStates::ACTIVE ),
    2004             :             "ODocumentDefinition::prepareClose: no controller!" );
    2005           0 :         if ( !xController.is() )
    2006             :             // document has not yet been activated, i.e. has no UI, yet
    2007           0 :             return true;
    2008             : 
    2009           0 :         bool bCouldSuspend = xController->suspend( sal_True );
    2010           0 :         if ( !bCouldSuspend )
    2011             :             // controller vetoed the closing
    2012           0 :             return false;
    2013             : 
    2014           0 :         if ( isModified() )
    2015             :         {
    2016           0 :             Reference< XFrame > xFrame( xController->getFrame() );
    2017           0 :             if ( xFrame.is() )
    2018             :             {
    2019           0 :                 Reference< XTopWindow > xTopWindow( xFrame->getContainerWindow(), UNO_QUERY_THROW );
    2020           0 :                 xTopWindow->toFront();
    2021             :             }
    2022           0 :             if ( !save( true ) )
    2023             :             {
    2024           0 :                 if ( bCouldSuspend )
    2025             :                     // revert suspension
    2026           0 :                     xController->suspend( sal_False );
    2027             :                 // saving failed or was cancelled
    2028           0 :                 return false;
    2029           0 :             }
    2030           0 :         }
    2031             :     }
    2032           0 :     catch( const Exception& )
    2033             :     {
    2034             :         DBG_UNHANDLED_EXCEPTION();
    2035             :     }
    2036             : 
    2037           0 :     return true;
    2038             : }
    2039             : 
    2040           0 : void ODocumentDefinition::fillReportData( const Reference< XComponentContext >& _rContext,
    2041             :                                                const Reference< util::XCloseable >& _rxComponent,
    2042             :                                                const Reference< XConnection >& _rxActiveConnection )
    2043             : {
    2044           0 :     Sequence< Any > aArgs(2);
    2045           0 :     PropertyValue aValue;
    2046           0 :     aValue.Name =  "TextDocument";
    2047           0 :     aValue.Value <<= _rxComponent;
    2048           0 :     aArgs[0] <<= aValue;
    2049           0 :     aValue.Name = "ActiveConnection";
    2050           0 :     aValue.Value <<= _rxActiveConnection;
    2051           0 :     aArgs[1] <<= aValue;
    2052             : 
    2053             :     try
    2054             :     {
    2055             :         Reference< XJobExecutor > xExecuteable(
    2056           0 :             _rContext->getServiceManager()->createInstanceWithArgumentsAndContext("com.sun.star.wizards.report.CallReportWizard", aArgs, _rContext), UNO_QUERY_THROW );
    2057           0 :         xExecuteable->trigger( "fill" );
    2058             :     }
    2059           0 :     catch( const Exception& )
    2060             :     {
    2061             :         DBG_UNHANDLED_EXCEPTION();
    2062           0 :     }
    2063           0 : }
    2064             : 
    2065           0 : void ODocumentDefinition::updateDocumentTitle()
    2066             : {
    2067           0 :     OUString sName = m_pImpl->m_aProps.aTitle;
    2068           0 :     if ( m_pImpl->m_pDataSource )
    2069             :     {
    2070           0 :         if ( sName.isEmpty() )
    2071             :         {
    2072           0 :             if ( m_bForm )
    2073           0 :                 sName = DBACORE_RESSTRING( RID_STR_FORM );
    2074             :             else
    2075           0 :                 sName = DBACORE_RESSTRING( RID_STR_REPORT );
    2076           0 :             Reference< XUntitledNumbers > xUntitledProvider(m_pImpl->m_pDataSource->getModel_noCreate(), UNO_QUERY      );
    2077           0 :             if ( xUntitledProvider.is() )
    2078           0 :                 sName += OUString::number( xUntitledProvider->leaseNumber(getComponent()) );
    2079             :         }
    2080             : 
    2081           0 :         Reference< XTitle > xDatabaseDocumentModel(m_pImpl->m_pDataSource->getModel_noCreate(),uno::UNO_QUERY);
    2082           0 :         if ( xDatabaseDocumentModel.is() )
    2083           0 :             sName = xDatabaseDocumentModel->getTitle() + " : " + sName;
    2084             :     }
    2085           0 :     Reference< XTitle> xTitle(getComponent(),UNO_QUERY);
    2086           0 :     if ( xTitle.is() )
    2087           0 :         xTitle->setTitle(sName);
    2088           0 : }
    2089             : 
    2090           0 : void SAL_CALL ODocumentDefinition::queryClosing( const lang::EventObject& Source, sal_Bool GetsOwnership ) throw (util::CloseVetoException, uno::RuntimeException, std::exception)
    2091             : {
    2092             :     (void) Source;
    2093             :     (void) GetsOwnership;
    2094             :     try
    2095             :     {
    2096           0 :         if ( !close() )
    2097           0 :             throw util::CloseVetoException();
    2098             :     }
    2099           0 :     catch(const lang::WrappedTargetException&)
    2100             :     {
    2101           0 :         throw util::CloseVetoException();
    2102             :     }
    2103           0 : }
    2104             : 
    2105           0 : void SAL_CALL ODocumentDefinition::notifyClosing( const lang::EventObject& /*Source*/ ) throw (uno::RuntimeException, std::exception)
    2106             : {
    2107           0 : }
    2108             : 
    2109           0 : void SAL_CALL ODocumentDefinition::disposing( const lang::EventObject& /*Source*/ ) throw (uno::RuntimeException, std::exception)
    2110             : {
    2111           0 : }
    2112             : 
    2113           0 : void ODocumentDefinition::firePropertyChange( sal_Int32 i_nHandle, const Any& i_rNewValue, const Any& i_rOldValue,
    2114             :         bool i_bVetoable, const NotifierAccess& )
    2115             : {
    2116           0 :     fire( &i_nHandle, &i_rNewValue, &i_rOldValue, 1, i_bVetoable );
    2117           0 : }
    2118             : 
    2119             : // NameChangeNotifier
    2120           0 : NameChangeNotifier::NameChangeNotifier( ODocumentDefinition& i_rDocumentDefinition, const OUString& i_rNewName,
    2121             :                                   ::osl::ResettableMutexGuard& i_rClearForNotify )
    2122             :     :m_rDocumentDefinition( i_rDocumentDefinition )
    2123           0 :     ,m_aOldValue( makeAny( i_rDocumentDefinition.getCurrentName() ) )
    2124             :     ,m_aNewValue( makeAny( i_rNewName ) )
    2125           0 :     ,m_rClearForNotify( i_rClearForNotify )
    2126             : {
    2127           0 :     impl_fireEvent_throw( true );
    2128           0 : }
    2129             : 
    2130           0 : NameChangeNotifier::~NameChangeNotifier()
    2131             : {
    2132           0 :     impl_fireEvent_throw( false );
    2133           0 : }
    2134             : 
    2135           0 : void NameChangeNotifier::impl_fireEvent_throw( const bool i_bVetoable )
    2136             : {
    2137           0 :     m_rClearForNotify.clear();
    2138             :     m_rDocumentDefinition.firePropertyChange(
    2139           0 :         PROPERTY_ID_NAME, m_aNewValue, m_aOldValue, i_bVetoable, ODocumentDefinition::NotifierAccess() );
    2140           0 :     m_rClearForNotify.reset();
    2141           0 : }
    2142             : 
    2143             : }   // namespace dbaccess
    2144             : 
    2145             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11