LCOV - code coverage report
Current view: top level - xmloff/source/draw - ximpbody.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 121 152 79.6 %
Date: 2014-04-11 Functions: 9 9 100.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 "ximpbody.hxx"
      21             : #include <xmloff/prstylei.hxx>
      22             : #include "ximpnote.hxx"
      23             : #include <com/sun/star/drawing/XDrawPage.hpp>
      24             : #include <com/sun/star/drawing/XDrawPages.hpp>
      25             : #include <com/sun/star/container/XNamed.hpp>
      26             : #include <com/sun/star/presentation/XPresentationPage.hpp>
      27             : #include "ximpstyl.hxx"
      28             : #include <com/sun/star/drawing/XMasterPageTarget.hpp>
      29             : #include <com/sun/star/beans/XPropertySet.hpp>
      30             : #include <com/sun/star/animations/XAnimationNodeSupplier.hpp>
      31             : 
      32             : #include <xmloff/unointerfacetouniqueidentifiermapper.hxx>
      33             : #include <xmloff/xmluconv.hxx>
      34             : #include <xmloff/xmlprmap.hxx>
      35             : #include <xmloff/families.hxx>
      36             : #include "ximpshow.hxx"
      37             : #include "PropertySetMerger.hxx"
      38             : #include "animationimport.hxx"
      39             : 
      40             : using namespace ::com::sun::star;
      41             : 
      42          40 : SdXMLDrawPageContext::SdXMLDrawPageContext( SdXMLImport& rImport,
      43             :     sal_uInt16 nPrfx, const OUString& rLocalName,
      44             :     const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
      45             :     uno::Reference< drawing::XShapes >& rShapes)
      46             : :   SdXMLGenericPageContext( rImport, nPrfx, rLocalName, xAttrList, rShapes )
      47          40 : ,   mbHadSMILNodes( false )
      48             : {
      49          40 :     bool bHaveXmlId( false );
      50          40 :     OUString sXmlId;
      51             : 
      52          40 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
      53             : 
      54         177 :     for(sal_Int16 i=0; i < nAttrCount; i++)
      55             :     {
      56         137 :         OUString sAttrName = xAttrList->getNameByIndex( i );
      57         274 :         OUString aLocalName;
      58         137 :         sal_uInt16 nPrefix = GetSdImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
      59         274 :         OUString sValue = xAttrList->getValueByIndex( i );
      60         137 :         const SvXMLTokenMap& rAttrTokenMap = GetSdImport().GetDrawPageAttrTokenMap();
      61             : 
      62         137 :         switch(rAttrTokenMap.Get(nPrefix, aLocalName))
      63             :         {
      64             :             case XML_TOK_DRAWPAGE_NAME:
      65             :             {
      66          40 :                 maName = sValue;
      67          40 :                 break;
      68             :             }
      69             :             case XML_TOK_DRAWPAGE_STYLE_NAME:
      70             :             {
      71          40 :                 maStyleName = sValue;
      72          40 :                 break;
      73             :             }
      74             :             case XML_TOK_DRAWPAGE_MASTER_PAGE_NAME:
      75             :             {
      76          40 :                 maMasterPageName = sValue;
      77          40 :                 break;
      78             :             }
      79             :             case XML_TOK_DRAWPAGE_PAGE_LAYOUT_NAME:
      80             :             {
      81          17 :                 maPageLayoutName =  sValue;
      82          17 :                 break;
      83             :             }
      84             :             case XML_TOK_DRAWPAGE_USE_HEADER_NAME:
      85             :             {
      86           0 :                 maUseHeaderDeclName =  sValue;
      87           0 :                 break;
      88             :             }
      89             :             case XML_TOK_DRAWPAGE_USE_FOOTER_NAME:
      90             :             {
      91           0 :                 maUseFooterDeclName =  sValue;
      92           0 :                 break;
      93             :             }
      94             :             case XML_TOK_DRAWPAGE_USE_DATE_TIME_NAME:
      95             :             {
      96           0 :                 maUseDateTimeDeclName =  sValue;
      97           0 :                 break;
      98             :             }
      99             :             case XML_TOK_DRAWPAGE_DRAWID:
     100             :             {
     101           0 :                 if (!bHaveXmlId) { sXmlId = sValue; }
     102             :             }
     103           0 :             break;
     104             :             case XML_TOK_DRAWPAGE_XMLID:
     105             :             {
     106           0 :                 sXmlId = sValue;
     107           0 :                 bHaveXmlId = true;
     108             :             }
     109           0 :             break;
     110             :             case XML_TOK_DRAWPAGE_HREF:
     111             :             {
     112           0 :                 maHREF = sValue;
     113           0 :                 break;
     114             :             }
     115             :         }
     116         137 :     }
     117             : 
     118          40 :     if (!sXmlId.isEmpty())
     119             :     {
     120           0 :         uno::Reference< uno::XInterface > const xRef( rShapes.get() );
     121           0 :         GetImport().getInterfaceToIdentifierMapper().registerReference(
     122           0 :             sXmlId, xRef );
     123             :     }
     124          40 :     GetImport().GetShapeImport()->startPage( rShapes );
     125             : 
     126          40 :     uno::Reference< drawing::XDrawPage > xShapeDrawPage(rShapes, uno::UNO_QUERY);
     127             : 
     128             :     // set PageName?
     129          40 :     if(!maName.isEmpty())
     130             :     {
     131          40 :         if(xShapeDrawPage.is())
     132             :         {
     133          40 :             uno::Reference < container::XNamed > xNamed(xShapeDrawPage, uno::UNO_QUERY);
     134          40 :             if(xNamed.is())
     135          40 :                 xNamed->setName(maName);
     136             :         }
     137             :     }
     138             : 
     139             :     // set MasterPage?
     140          40 :     if(!maMasterPageName.isEmpty())
     141             :     {
     142             :         // #85906# Code for setting masterpage needs complete rework
     143             :         // since GetSdImport().GetMasterStylesContext() gives always ZERO
     144             :         // because of content/style file split. Now the nechanism is to
     145             :         // compare the wanted masterpage-name with the existing masterpages
     146             :         // which were loaded and created in the styles section loading.
     147          40 :         uno::Reference< drawing::XDrawPages > xMasterPages(GetSdImport().GetLocalMasterPages(), uno::UNO_QUERY);
     148          80 :         uno::Reference < drawing::XMasterPageTarget > xDrawPage(rShapes, uno::UNO_QUERY);
     149          80 :         uno::Reference< drawing::XDrawPage > xMasterPage;
     150             : 
     151          40 :         if(xDrawPage.is() && xMasterPages.is())
     152             :         {
     153          40 :             sal_Bool bDone(sal_False);
     154             :             OUString sDisplayName( rImport.GetStyleDisplayName(
     155          40 :                             XML_STYLE_FAMILY_MASTER_PAGE, maMasterPageName ) );
     156             : 
     157          80 :             for(sal_Int32 a = 0; !bDone && a < xMasterPages->getCount(); a++)
     158             :             {
     159          40 :                 uno::Any aAny(xMasterPages->getByIndex(a));
     160          40 :                 aAny >>= xMasterPage;
     161             : 
     162          40 :                 if(xMasterPage.is())
     163             :                 {
     164          40 :                     uno::Reference < container::XNamed > xMasterNamed(xMasterPage, uno::UNO_QUERY);
     165          40 :                     if(xMasterNamed.is())
     166             :                     {
     167          40 :                         OUString sMasterPageName = xMasterNamed->getName();
     168             : 
     169          40 :                         if(!sMasterPageName.isEmpty() && sMasterPageName.equals(sDisplayName))
     170             :                         {
     171          40 :                             xDrawPage->setMasterPage(xMasterPage);
     172          40 :                             bDone = sal_True;
     173          40 :                         }
     174          40 :                     }
     175             :                 }
     176          40 :             }
     177             : 
     178          40 :             DBG_ASSERT( bDone, "xmloff::SdXMLDrawPageContext::SdXMLDrawPageContext(), could not find a slide master!" );
     179          40 :         }
     180             :     }
     181             : 
     182          40 :     SetStyle( maStyleName );
     183             : 
     184          40 :     if( !maHREF.isEmpty() )
     185             :     {
     186           0 :         uno::Reference< beans::XPropertySet > xProps( xShapeDrawPage, uno::UNO_QUERY );
     187           0 :         if( xProps.is() )
     188             :         {
     189           0 :             sal_Int32 nIndex = maHREF.lastIndexOf( (sal_Unicode)'#' );
     190           0 :             if( nIndex != -1 )
     191             :             {
     192           0 :                 OUString aFileName( maHREF.copy( 0, nIndex ) );
     193           0 :                 OUString aBookmarkName( maHREF.copy( nIndex+1 ) );
     194             : 
     195           0 :                 maHREF = GetImport().GetAbsoluteReference( aFileName );
     196           0 :                 maHREF += OUString(static_cast<sal_Unicode>('#'));
     197           0 :                 maHREF += aBookmarkName;
     198             :             }
     199             : 
     200           0 :             xProps->setPropertyValue("BookmarkURL", uno::makeAny( maHREF ) );
     201           0 :         }
     202             :     }
     203             : 
     204          40 :     SetLayout();
     205             : 
     206          40 :     DeleteAllShapes();
     207          40 : }
     208             : 
     209          80 : SdXMLDrawPageContext::~SdXMLDrawPageContext()
     210             : {
     211          80 : }
     212             : 
     213         150 : SvXMLImportContext *SdXMLDrawPageContext::CreateChildContext( sal_uInt16 nPrefix,
     214             :     const OUString& rLocalName,
     215             :     const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList )
     216             : {
     217         150 :     SvXMLImportContext *pContext = 0L;
     218         150 :     const SvXMLTokenMap& rTokenMap = GetSdImport().GetDrawPageElemTokenMap();
     219             : 
     220             :     // some special objects inside draw:page context
     221         150 :     switch(rTokenMap.Get(nPrefix, rLocalName))
     222             :     {
     223             :         case XML_TOK_DRAWPAGE_NOTES:
     224             :         {
     225          23 :             if( GetSdImport().IsImpress() )
     226             :             {
     227             :                 // get notes page
     228          23 :                 uno::Reference< presentation::XPresentationPage > xPresPage(GetLocalShapesContext(), uno::UNO_QUERY);
     229          23 :                 if(xPresPage.is())
     230             :                 {
     231          23 :                     uno::Reference< drawing::XDrawPage > xNotesDrawPage(xPresPage->getNotesPage(), uno::UNO_QUERY);
     232          23 :                     if(xNotesDrawPage.is())
     233             :                     {
     234          23 :                         uno::Reference< drawing::XShapes > xNewShapes(xNotesDrawPage, uno::UNO_QUERY);
     235          23 :                         if(xNewShapes.is())
     236             :                         {
     237             :                             // presentation:notes inside draw:page context
     238          23 :                             pContext = new SdXMLNotesContext( GetSdImport(), nPrefix, rLocalName, xAttrList, xNewShapes);
     239          23 :                         }
     240          23 :                     }
     241          23 :                 }
     242             :             }
     243          23 :             break;
     244             :         }
     245             :         case XML_TOK_DRAWPAGE_PAR:
     246             :         case XML_TOK_DRAWPAGE_SEQ:
     247             :         {
     248           1 :             if( GetSdImport().IsImpress() )
     249             :             {
     250           1 :                 uno::Reference< animations::XAnimationNodeSupplier > xNodeSupplier(GetLocalShapesContext(), uno::UNO_QUERY);
     251           1 :                 if(xNodeSupplier.is())
     252             :                 {
     253           1 :                     pContext = new xmloff::AnimationNodeContext( xNodeSupplier->getAnimationNode(), GetSdImport(), nPrefix, rLocalName, xAttrList );
     254           1 :                     mbHadSMILNodes = true;
     255           1 :                 }
     256             :             }
     257           1 :             break;
     258             :         }
     259             :     }
     260             : 
     261             :     // call parent when no own context was created
     262         150 :     if(!pContext)
     263         126 :         pContext = SdXMLGenericPageContext::CreateChildContext(nPrefix, rLocalName, xAttrList);
     264             : 
     265         150 :     return pContext;
     266             : }
     267             : 
     268          40 : void SdXMLDrawPageContext::EndElement()
     269             : {
     270          40 :     SdXMLGenericPageContext::EndElement();
     271          40 :     GetImport().GetShapeImport()->endPage(GetLocalShapesContext());
     272             : 
     273          40 :     if( mbHadSMILNodes )
     274             :     {
     275           1 :         uno::Reference< animations::XAnimationNodeSupplier > xNodeSupplier(GetLocalShapesContext(), uno::UNO_QUERY);
     276           2 :         uno::Reference< beans::XPropertySet > xPageProps( GetLocalShapesContext(), uno::UNO_QUERY );
     277           1 :         if(xNodeSupplier.is())
     278           2 :             xmloff::AnimationNodeContext::postProcessRootNode( GetSdImport(), xNodeSupplier->getAnimationNode(), xPageProps );
     279             :     }
     280          40 : }
     281             : 
     282          34 : SdXMLBodyContext::SdXMLBodyContext( SdXMLImport& rImport,
     283             :     sal_uInt16 nPrfx, const OUString& rLocalName )
     284          34 : :   SvXMLImportContext( rImport, nPrfx, rLocalName )
     285             : {
     286          34 : }
     287             : 
     288          68 : SdXMLBodyContext::~SdXMLBodyContext()
     289             : {
     290          68 : }
     291             : 
     292          52 : SvXMLImportContext *SdXMLBodyContext::CreateChildContext(
     293             :     sal_uInt16 nPrefix,
     294             :     const OUString& rLocalName,
     295             :     const uno::Reference< xml::sax::XAttributeList>& xAttrList )
     296             : {
     297          52 :     SvXMLImportContext *pContext = 0L;
     298          52 :     const SvXMLTokenMap& rTokenMap = GetSdImport().GetBodyElemTokenMap();
     299             : 
     300          52 :     switch(rTokenMap.Get(nPrefix, rLocalName))
     301             :     {
     302             :         case XML_TOK_BODY_HEADER_DECL:
     303             :         case XML_TOK_BODY_FOOTER_DECL:
     304             :         case XML_TOK_BODY_DATE_TIME_DECL:
     305             :         {
     306           0 :             pContext = new SdXMLHeaderFooterDeclContext( GetImport(), nPrefix, rLocalName, xAttrList );
     307           0 :             break;
     308             :         }
     309             :         case XML_TOK_BODY_PAGE:
     310             :         {
     311             :             // only read the first page in preview mode
     312          40 :             if( (GetSdImport().GetNewPageCount() == 0) || !GetSdImport().IsPreview() )
     313             :             {
     314             :                 // import this page
     315          40 :                 uno::Reference< drawing::XDrawPage > xNewDrawPage;
     316          80 :                 uno::Reference< drawing::XDrawPages > xDrawPages(GetSdImport().GetLocalDrawPages(), uno::UNO_QUERY);
     317             : 
     318          40 :                 if( !xDrawPages.is() )
     319           0 :                     break;
     320             : 
     321          40 :                 if(GetSdImport().GetNewPageCount() + 1 > xDrawPages->getCount())
     322             :                 {
     323             :                     // new page, create and insert
     324           7 :                     xNewDrawPage = xDrawPages->insertNewByIndex(xDrawPages->getCount());
     325             :                 }
     326             :                 else
     327             :                 {
     328             :                     // existing page, use it
     329          33 :                     uno::Any aAny(xDrawPages->getByIndex(GetSdImport().GetNewPageCount()));
     330          33 :                     aAny >>= xNewDrawPage;
     331             :                 }
     332             : 
     333             :                 // increment global import page counter
     334          40 :                 GetSdImport().IncrementNewPageCount();
     335             : 
     336          40 :                 if(xNewDrawPage.is())
     337             :                 {
     338          40 :                     uno::Reference< drawing::XShapes > xNewShapes(xNewDrawPage, uno::UNO_QUERY);
     339          40 :                     if(xNewShapes.is())
     340             :                     {
     341             :                         // draw:page inside office:body context
     342             :                         pContext = new SdXMLDrawPageContext(GetSdImport(), nPrefix, rLocalName, xAttrList,
     343          40 :                             xNewShapes);
     344          40 :                     }
     345          40 :                 }
     346             :             }
     347          40 :             break;
     348             :         }
     349             :         case XML_TOK_BODY_SETTINGS:
     350             :         {
     351          12 :             pContext = new SdXMLShowsContext( GetSdImport(), nPrefix, rLocalName, xAttrList );
     352             :         }
     353             :     }
     354             : 
     355             :     // call parent when no own context was created
     356          52 :     if(!pContext)
     357           0 :         pContext = SvXMLImportContext::CreateChildContext(nPrefix, rLocalName, xAttrList);
     358             : 
     359          52 :     return pContext;
     360             : }
     361             : 
     362             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10