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

Generated by: LCOV version 1.10