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

Generated by: LCOV version 1.11