LCOV - code coverage report
Current view: top level - sw/source/core/doc - docxforms.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 43 0.0 %
Date: 2014-04-14 Functions: 0 4 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 <doc.hxx>
      21             : #include <docsh.hxx>
      22             : #include <com/sun/star/uno/Reference.hxx>
      23             : #include <com/sun/star/container/XNameContainer.hpp>
      24             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      25             : #include <com/sun/star/frame/XModule.hpp>
      26             : #include <com/sun/star/xforms/Model.hpp>
      27             : #include <com/sun/star/xforms/XModel2.hpp>
      28             : #include <com/sun/star/xforms/XFormsUIHelper1.hpp>
      29             : #include <com/sun/star/xforms/XForms.hpp>
      30             : #include <comphelper/processfactory.hxx>
      31             : #include <tools/diagnose_ex.h>
      32             : #include <com/sun/star/container/XIndexAccess.hpp>
      33             : 
      34             : using namespace ::com::sun::star;
      35             : 
      36             : using uno::Reference;
      37             : using uno::XInterface;
      38             : using uno::UNO_QUERY;
      39             : using uno::makeAny;
      40             : using uno::Exception;
      41             : using container::XNameContainer;
      42             : using xforms::XModel2;
      43             : using frame::XModule;
      44             : using xforms::XFormsUIHelper1;
      45             : using com::sun::star::container::XIndexAccess;
      46             : 
      47           0 : Reference<XNameContainer> SwDoc::getXForms() const
      48             : {
      49           0 :     return mxXForms;
      50             : }
      51             : 
      52           0 : bool SwDoc::isXForms() const
      53             : {
      54           0 :     return mxXForms.is();
      55             : }
      56             : 
      57           0 : void SwDoc::initXForms( bool bCreateDefaultModel )
      58             : {
      59             :     OSL_ENSURE( ! isXForms(), "please initialize only once" );
      60             : 
      61             :     try
      62             :     {
      63             :         // create XForms components
      64           0 :         mxXForms = xforms::XForms::create( comphelper::getProcessComponentContext() );
      65             : 
      66             :         // change our module identifier, to be able to have a dedicated UI
      67           0 :         Reference< XModule > xModule;
      68           0 :         SwDocShell* pShell( GetDocShell() );
      69           0 :         if ( pShell )
      70           0 :             xModule = xModule.query( pShell->GetModel() );
      71             :         OSL_ENSURE( xModule.is(), "SwDoc::initXForms: no XModule at the document!" );
      72           0 :         if ( xModule.is() )
      73           0 :             xModule->setIdentifier( OUString( "com.sun.star.xforms.XMLFormDocument" ) );
      74             : 
      75             :         // create default model
      76           0 :         if( bCreateDefaultModel && mxXForms.is() )
      77             :         {
      78           0 :             OUString sName("Model 1");
      79           0 :             Reference<XModel2> xModel = xforms::Model::create( comphelper::getProcessComponentContext() );
      80           0 :             xModel->setID( sName );
      81           0 :             Reference<XFormsUIHelper1>( xModel, uno::UNO_QUERY_THROW )->newInstance(
      82             :                 OUString("Instance 1"),
      83           0 :                 OUString(), sal_True );
      84           0 :             xModel->initialize();
      85           0 :             mxXForms->insertByName( sName, makeAny( xModel ) );
      86           0 :             OSL_ENSURE( mxXForms->hasElements(), "can't create XForms model" );
      87             :         }
      88             : 
      89           0 :         OSL_ENSURE( isXForms(), "initialization failed" );
      90             :     }
      91           0 :     catch( const Exception& )
      92             :     {
      93             :     }
      94           0 : }
      95             : 
      96             : // #i113606#, to release the cyclic reference between XFormModel and bindings/submissions.
      97           0 : void SwDoc::disposeXForms( )
      98             : {
      99             :     // get XForms models
     100           0 :     if( mxXForms.is() )
     101             :     {
     102             :         // iterate over all models
     103           0 :         uno::Sequence<OUString> aNames = mxXForms->getElementNames();
     104           0 :         const OUString* pNames = aNames.getConstArray();
     105           0 :         sal_Int32 nNames = aNames.getLength();
     106           0 :         for( sal_Int32 n = 0; (n < nNames); n++ )
     107             :         {
     108             :             Reference< xforms::XModel > xModel(
     109           0 :                 mxXForms->getByName( pNames[n] ), UNO_QUERY );
     110             : 
     111           0 :             if( xModel.is() )
     112             :             {
     113             :                 // ask model for bindings
     114             :                 Reference< XIndexAccess > xBindings(
     115           0 :                          xModel->getBindings(), UNO_QUERY );
     116             : 
     117             :                 // Then release them one by one
     118           0 :                 int nCount = xBindings->getCount();
     119           0 :                 for( int i = nCount-1; i >= 0; i-- )
     120             :                 {
     121           0 :                     xModel->getBindings()->remove(xBindings->getByIndex( i ));
     122             :                 }
     123             : 
     124             :                 // ask model for Submissions
     125             :                 Reference< XIndexAccess > xSubmissions(
     126           0 :                          xModel->getSubmissions(), UNO_QUERY );
     127             : 
     128             :                 // Then release them one by one
     129           0 :                 nCount = xSubmissions->getCount();
     130           0 :                 for( int i = nCount-1; i >= 0; i-- )
     131             :                 {
     132           0 :                     xModel->getSubmissions()->remove(xSubmissions->getByIndex( i ));
     133           0 :                 }
     134             :             }
     135           0 :         }
     136             :     }
     137           0 : }
     138             : 
     139             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10