LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/xmloff/source/draw - ximpshow.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 47 124 37.9 %
Date: 2013-07-09 Functions: 5 11 45.5 %
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             : 
      21             : #include <com/sun/star/util/Duration.hpp>
      22             : #include <com/sun/star/xml/sax/XAttributeList.hpp>
      23             : #include <com/sun/star/lang/XSingleServiceFactory.hpp>
      24             : #include <com/sun/star/container/XNameContainer.hpp>
      25             : #include <com/sun/star/presentation/XCustomPresentationSupplier.hpp>
      26             : #include <com/sun/star/presentation/XPresentationSupplier.hpp>
      27             : #include <com/sun/star/container/XIndexContainer.hpp>
      28             : #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
      29             : #include <sax/tools/converter.hxx>
      30             : #include <xmloff/xmltoken.hxx>
      31             : #include <comphelper/extract.hxx>
      32             : #include "xmloff/xmlnmspe.hxx"
      33             : #include <xmloff/nmspmap.hxx>
      34             : #include <xmloff/xmluconv.hxx>
      35             : #include "ximpshow.hxx"
      36             : 
      37             : 
      38             : using namespace ::std;
      39             : using namespace ::cppu;
      40             : using namespace ::com::sun::star;
      41             : using namespace ::com::sun::star::xml;
      42             : using namespace ::com::sun::star::xml::sax;
      43             : using namespace ::com::sun::star::uno;
      44             : using namespace ::com::sun::star::drawing;
      45             : using namespace ::com::sun::star::beans;
      46             : using namespace ::com::sun::star::lang;
      47             : using namespace ::com::sun::star::util;
      48             : using namespace ::com::sun::star::container;
      49             : using namespace ::com::sun::star::presentation;
      50             : using namespace ::xmloff::token;
      51             : 
      52             : ///////////////////////////////////////////////////////////////////////
      53             : 
      54           4 : class ShowsImpImpl
      55             : {
      56             : public:
      57             :     Reference< XSingleServiceFactory > mxShowFactory;
      58             :     Reference< XNameContainer > mxShows;
      59             :     Reference< XPropertySet > mxPresProps;
      60             :     Reference< XNameAccess > mxPages;
      61             :     OUString maCustomShowName;
      62             :     SdXMLImport& mrImport;
      63             : 
      64           4 :     ShowsImpImpl( SdXMLImport& rImport )
      65           4 :     :   mrImport( rImport )
      66           4 :     {}
      67             : };
      68             : 
      69             : ///////////////////////////////////////////////////////////////////////
      70             : 
      71           0 : TYPEINIT1( SdXMLShowsContext, SvXMLImportContext );
      72             : 
      73           4 : SdXMLShowsContext::SdXMLShowsContext( SdXMLImport& rImport,  sal_uInt16 nPrfx, const OUString& rLocalName,  const Reference< XAttributeList >& xAttrList )
      74           4 : :   SvXMLImportContext(rImport, nPrfx, rLocalName)
      75             : {
      76           4 :     mpImpl = new ShowsImpImpl( rImport );
      77             : 
      78           4 :     Reference< XCustomPresentationSupplier > xShowsSupplier( rImport.GetModel(), UNO_QUERY );
      79           4 :     if( xShowsSupplier.is() )
      80             :     {
      81           4 :         mpImpl->mxShows = xShowsSupplier->getCustomPresentations();
      82           4 :         mpImpl->mxShowFactory = Reference< XSingleServiceFactory >::query( mpImpl->mxShows );
      83             :     }
      84             : 
      85           8 :     Reference< XDrawPagesSupplier > xDrawPagesSupplier( rImport.GetModel(), UNO_QUERY );
      86           4 :     if( xDrawPagesSupplier.is() )
      87           4 :         mpImpl->mxPages = Reference< XNameAccess >::query( xDrawPagesSupplier->getDrawPages() );
      88             : 
      89           8 :     Reference< XPresentationSupplier > xPresentationSupplier( rImport.GetModel(), UNO_QUERY );
      90           4 :     if( xPresentationSupplier.is() )
      91           4 :         mpImpl->mxPresProps = Reference< XPropertySet >::query( xPresentationSupplier->getPresentation() );
      92             : 
      93             : 
      94           4 :     if( mpImpl->mxPresProps.is() )
      95             :     {
      96           4 :         sal_Bool bAll = sal_True;
      97           4 :         uno::Any aAny;
      98             : 
      99             :         // read attributes
     100           4 :         const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
     101           8 :         for(sal_Int16 i=0; i < nAttrCount; i++)
     102             :         {
     103           4 :             OUString sAttrName = xAttrList->getNameByIndex( i );
     104           8 :             OUString aLocalName;
     105           4 :             sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
     106           8 :             OUString sValue = xAttrList->getValueByIndex( i );
     107             : 
     108           4 :             switch( nPrefix )
     109             :             {
     110             :             case XML_NAMESPACE_PRESENTATION:
     111           4 :                 if( IsXMLToken( aLocalName, XML_START_PAGE ) )
     112             :                 {
     113           0 :                     aAny <<= sValue;
     114           0 :                     mpImpl->mxPresProps->setPropertyValue("FirstPage", aAny );
     115           0 :                     bAll = sal_False;
     116             :                 }
     117           4 :                 else if( IsXMLToken( aLocalName, XML_SHOW ) )
     118             :                 {
     119           0 :                     mpImpl->maCustomShowName = sValue;
     120           0 :                     bAll = sal_False;
     121             :                 }
     122           4 :                 else if( IsXMLToken( aLocalName, XML_PAUSE ) )
     123             :                 {
     124           0 :                     Duration aDuration;
     125           0 :                     if (!::sax::Converter::convertDuration(aDuration,  sValue))
     126           0 :                         continue;
     127             : 
     128           0 :                     const sal_Int32 nMS = (aDuration.Hours * 60 +
     129           0 :                             aDuration.Minutes) * 60 + aDuration.Seconds;
     130           0 :                     aAny <<= nMS;
     131           0 :                     mpImpl->mxPresProps->setPropertyValue("Pause", aAny );
     132             :                 }
     133           4 :                 else if( IsXMLToken( aLocalName, XML_ANIMATIONS ) )
     134             :                 {
     135           0 :                     aAny = bool2any( IsXMLToken( sValue, XML_ENABLED ) );
     136           0 :                     mpImpl->mxPresProps->setPropertyValue("AllowAnimations", aAny );
     137             :                 }
     138           4 :                 else if( IsXMLToken( aLocalName, XML_STAY_ON_TOP ) )
     139             :                 {
     140           0 :                     aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
     141           0 :                     mpImpl->mxPresProps->setPropertyValue("IsAlwaysOnTop", aAny );
     142             :                 }
     143           4 :                 else if( IsXMLToken( aLocalName, XML_FORCE_MANUAL ) )
     144             :                 {
     145           0 :                     aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
     146           0 :                     mpImpl->mxPresProps->setPropertyValue("IsAutomatic", aAny );
     147             :                 }
     148           4 :                 else if( IsXMLToken( aLocalName, XML_ENDLESS ) )
     149             :                 {
     150           0 :                     aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
     151           0 :                     mpImpl->mxPresProps->setPropertyValue("IsEndless", aAny );
     152             :                 }
     153           4 :                 else if( IsXMLToken( aLocalName, XML_FULL_SCREEN ) )
     154             :                 {
     155           0 :                     aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
     156           0 :                     mpImpl->mxPresProps->setPropertyValue("IsFullScreen", aAny );
     157             :                 }
     158           4 :                 else if( IsXMLToken( aLocalName, XML_MOUSE_VISIBLE ) )
     159             :                 {
     160           4 :                     aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
     161           4 :                     mpImpl->mxPresProps->setPropertyValue("IsMouseVisible", aAny );
     162             :                 }
     163           0 :                 else if( IsXMLToken( aLocalName, XML_START_WITH_NAVIGATOR ) )
     164             :                 {
     165           0 :                     aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
     166           0 :                     mpImpl->mxPresProps->setPropertyValue("StartWithNavigator", aAny );
     167             :                 }
     168           0 :                 else if( IsXMLToken( aLocalName, XML_MOUSE_AS_PEN ) )
     169             :                 {
     170           0 :                     aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
     171           0 :                     mpImpl->mxPresProps->setPropertyValue("UsePen", aAny );
     172             :                 }
     173           0 :                 else if( IsXMLToken( aLocalName, XML_TRANSITION_ON_CLICK ) )
     174             :                 {
     175           0 :                     aAny = bool2any( IsXMLToken( sValue, XML_ENABLED ) );
     176           0 :                     mpImpl->mxPresProps->setPropertyValue("IsTransitionOnClick", aAny );
     177             :                 }
     178           0 :                 else if( IsXMLToken( aLocalName, XML_SHOW_LOGO ) )
     179             :                 {
     180           0 :                     aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
     181           0 :                     mpImpl->mxPresProps->setPropertyValue("IsShowLogo", aAny );
     182             :                 }
     183             :             }
     184           4 :         }
     185           4 :         aAny = bool2any( bAll );
     186           4 :         mpImpl->mxPresProps->setPropertyValue("IsShowAll", aAny );
     187           4 :     }
     188           4 : }
     189             : 
     190          12 : SdXMLShowsContext::~SdXMLShowsContext()
     191             : {
     192           4 :     if( mpImpl && !mpImpl->maCustomShowName.isEmpty() )
     193             :     {
     194           0 :         uno::Any aAny;
     195           0 :         aAny <<= mpImpl->maCustomShowName;
     196           0 :         mpImpl->mxPresProps->setPropertyValue("CustomShow", aAny );
     197             :     }
     198             : 
     199           4 :     delete mpImpl;
     200           8 : }
     201             : 
     202           0 : SvXMLImportContext * SdXMLShowsContext::CreateChildContext( sal_uInt16 p_nPrefix, const OUString& rLocalName, const Reference< XAttributeList>& xAttrList )
     203             : {
     204           0 :     if( mpImpl && p_nPrefix == XML_NAMESPACE_PRESENTATION && IsXMLToken( rLocalName, XML_SHOW ) )
     205             :     {
     206           0 :         OUString aName;
     207           0 :         OUString aPages;
     208             : 
     209             :         // read attributes
     210           0 :         const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
     211           0 :         for(sal_Int16 i=0; i < nAttrCount; i++)
     212             :         {
     213           0 :             OUString sAttrName = xAttrList->getNameByIndex( i );
     214           0 :             OUString aLocalName;
     215           0 :             sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
     216           0 :             OUString sValue = xAttrList->getValueByIndex( i );
     217             : 
     218           0 :             switch( nPrefix )
     219             :             {
     220             :             case XML_NAMESPACE_PRESENTATION:
     221           0 :                 if( IsXMLToken( aLocalName, XML_NAME ) )
     222             :                 {
     223           0 :                     aName = sValue;
     224             :                 }
     225           0 :                 else if( IsXMLToken( aLocalName, XML_PAGES ) )
     226             :                 {
     227           0 :                     aPages = sValue;
     228             :                 }
     229             :             }
     230           0 :         }
     231             : 
     232           0 :         if( !aName.isEmpty() && !aPages.isEmpty() )
     233             :         {
     234           0 :             Reference< XIndexContainer > xShow( mpImpl->mxShowFactory->createInstance(), UNO_QUERY );
     235           0 :             if( xShow.is() )
     236             :             {
     237           0 :                 SvXMLTokenEnumerator aPageNames( aPages, sal_Unicode(',') );
     238           0 :                 OUString sPageName;
     239           0 :                 Any aAny;
     240             : 
     241           0 :                 while( aPageNames.getNextToken( sPageName ) )
     242             :                 {
     243           0 :                     if( !mpImpl->mxPages->hasByName( sPageName ) )
     244           0 :                         continue;
     245             : 
     246           0 :                     Reference< XDrawPage > xPage;
     247           0 :                     mpImpl->mxPages->getByName( sPageName ) >>= xPage;
     248           0 :                     if( xPage.is() )
     249             :                     {
     250           0 :                         aAny <<= xPage;
     251           0 :                         xShow->insertByIndex( xShow->getCount(), aAny );
     252             :                     }
     253           0 :                 }
     254             : 
     255           0 :                 aAny <<= xShow;
     256             : 
     257           0 :                 if( mpImpl->mxShows->hasByName( aName ) )
     258             :                 {
     259           0 :                     mpImpl->mxShows->replaceByName( aName, aAny );
     260             :                 }
     261             :                 else
     262             :                 {
     263           0 :                     mpImpl->mxShows->insertByName( aName, aAny );
     264           0 :                 }
     265           0 :             }
     266           0 :         }
     267             :     }
     268             : 
     269           0 :     return new SvXMLImportContext( GetImport(), p_nPrefix, rLocalName );
     270             : }
     271             : 
     272             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10