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

Generated by: LCOV version 1.10