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

Generated by: LCOV version 1.10