LCOV - code coverage report
Current view: top level - xmloff/source/draw - ximpbody.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 110 151 72.8 %
Date: 2012-08-25 Functions: 9 9 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 108 260 41.5 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "ximpbody.hxx"
      30                 :            : #include <xmloff/prstylei.hxx>
      31                 :            : #include "ximpnote.hxx"
      32                 :            : #include <com/sun/star/drawing/XDrawPage.hpp>
      33                 :            : #include <com/sun/star/drawing/XDrawPages.hpp>
      34                 :            : #include <com/sun/star/container/XNamed.hpp>
      35                 :            : #include <com/sun/star/presentation/XPresentationPage.hpp>
      36                 :            : #include "ximpstyl.hxx"
      37                 :            : #include <com/sun/star/drawing/XMasterPageTarget.hpp>
      38                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      39                 :            : #include <com/sun/star/animations/XAnimationNodeSupplier.hpp>
      40                 :            : 
      41                 :            : #include <xmloff/unointerfacetouniqueidentifiermapper.hxx>
      42                 :            : #include <xmloff/xmluconv.hxx>
      43                 :            : #include <xmloff/xmlprmap.hxx>
      44                 :            : #include <xmloff/families.hxx>
      45                 :            : #include "ximpshow.hxx"
      46                 :            : #include "PropertySetMerger.hxx"
      47                 :            : #include "animationimport.hxx"
      48                 :            : 
      49                 :            : using ::rtl::OUString;
      50                 :            : using ::rtl::OUStringBuffer;
      51                 :            : 
      52                 :            : using namespace ::com::sun::star;
      53                 :            : 
      54                 :            : //////////////////////////////////////////////////////////////////////////////
      55                 :            : 
      56                 :         32 : SdXMLDrawPageContext::SdXMLDrawPageContext( SdXMLImport& rImport,
      57                 :            :     sal_uInt16 nPrfx, const OUString& rLocalName,
      58                 :            :     const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
      59                 :            :     uno::Reference< drawing::XShapes >& rShapes)
      60                 :            : :   SdXMLGenericPageContext( rImport, nPrfx, rLocalName, xAttrList, rShapes )
      61                 :         32 : ,   mbHadSMILNodes( false )
      62                 :            : {
      63                 :         32 :     bool bHaveXmlId( false );
      64                 :         32 :     OUString sXmlId;
      65                 :            : 
      66 [ +  - ][ +  - ]:         32 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
                 [ +  - ]
      67                 :            : 
      68         [ +  + ]:        156 :     for(sal_Int16 i=0; i < nAttrCount; i++)
      69                 :            :     {
      70 [ +  - ][ +  - ]:        124 :         OUString sAttrName = xAttrList->getNameByIndex( i );
      71                 :        124 :         OUString aLocalName;
      72         [ +  - ]:        124 :         sal_uInt16 nPrefix = GetSdImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
      73 [ +  - ][ +  - ]:        124 :         OUString sValue = xAttrList->getValueByIndex( i );
      74         [ +  - ]:        124 :         const SvXMLTokenMap& rAttrTokenMap = GetSdImport().GetDrawPageAttrTokenMap();
      75                 :            : 
      76 [ +  - ][ +  +  :        124 :         switch(rAttrTokenMap.Get(nPrefix, aLocalName))
          +  +  -  -  -  
             -  -  -  - ]
      77                 :            :         {
      78                 :            :             case XML_TOK_DRAWPAGE_NAME:
      79                 :            :             {
      80                 :         32 :                 maName = sValue;
      81                 :         32 :                 break;
      82                 :            :             }
      83                 :            :             case XML_TOK_DRAWPAGE_STYLE_NAME:
      84                 :            :             {
      85                 :         32 :                 maStyleName = sValue;
      86                 :         32 :                 break;
      87                 :            :             }
      88                 :            :             case XML_TOK_DRAWPAGE_MASTER_PAGE_NAME:
      89                 :            :             {
      90                 :         32 :                 maMasterPageName = sValue;
      91                 :         32 :                 break;
      92                 :            :             }
      93                 :            :             case XML_TOK_DRAWPAGE_PAGE_LAYOUT_NAME:
      94                 :            :             {
      95                 :         28 :                 maPageLayoutName =  sValue;
      96                 :         28 :                 break;
      97                 :            :             }
      98                 :            :             case XML_TOK_DRAWPAGE_USE_HEADER_NAME:
      99                 :            :             {
     100                 :          0 :                 maUseHeaderDeclName =  sValue;
     101                 :          0 :                 break;
     102                 :            :             }
     103                 :            :             case XML_TOK_DRAWPAGE_USE_FOOTER_NAME:
     104                 :            :             {
     105                 :          0 :                 maUseFooterDeclName =  sValue;
     106                 :          0 :                 break;
     107                 :            :             }
     108                 :            :             case XML_TOK_DRAWPAGE_USE_DATE_TIME_NAME:
     109                 :            :             {
     110                 :          0 :                 maUseDateTimeDeclName =  sValue;
     111                 :          0 :                 break;
     112                 :            :             }
     113                 :            :             case XML_TOK_DRAWPAGE_DRAWID:
     114                 :            :             {
     115         [ #  # ]:          0 :                 if (!bHaveXmlId) { sXmlId = sValue; }
     116                 :            :             }
     117                 :          0 :             break;
     118                 :            :             case XML_TOK_DRAWPAGE_XMLID:
     119                 :            :             {
     120                 :          0 :                 sXmlId = sValue;
     121                 :          0 :                 bHaveXmlId = true;
     122                 :            :             }
     123                 :          0 :             break;
     124                 :            :             case XML_TOK_DRAWPAGE_HREF:
     125                 :            :             {
     126                 :          0 :                 maHREF = sValue;
     127                 :          0 :                 break;
     128                 :            :             }
     129                 :            :         }
     130                 :        124 :     }
     131                 :            : 
     132         [ -  + ]:         32 :     if (!sXmlId.isEmpty())
     133                 :            :     {
     134 [ #  # ][ #  # ]:          0 :         uno::Reference< uno::XInterface > const xRef( rShapes.get() );
     135         [ #  # ]:          0 :         GetImport().getInterfaceToIdentifierMapper().registerReference(
     136         [ #  # ]:          0 :             sXmlId, xRef );
     137                 :            :     }
     138 [ +  - ][ +  - ]:         32 :     GetImport().GetShapeImport()->startPage( rShapes );
         [ +  - ][ +  - ]
     139                 :            : 
     140         [ +  - ]:         32 :     uno::Reference< drawing::XDrawPage > xShapeDrawPage(rShapes, uno::UNO_QUERY);
     141                 :            : 
     142                 :            :     // set PageName?
     143         [ +  - ]:         32 :     if(!maName.isEmpty())
     144                 :            :     {
     145         [ +  - ]:         32 :         if(xShapeDrawPage.is())
     146                 :            :         {
     147         [ +  - ]:         32 :             uno::Reference < container::XNamed > xNamed(xShapeDrawPage, uno::UNO_QUERY);
     148         [ +  - ]:         32 :             if(xNamed.is())
     149 [ +  - ][ +  - ]:         32 :                 xNamed->setName(maName);
     150                 :            :         }
     151                 :            :     }
     152                 :            : 
     153                 :            :     // set MasterPage?
     154         [ +  - ]:         32 :     if(!maMasterPageName.isEmpty())
     155                 :            :     {
     156                 :            :         // #85906# Code for setting masterpage needs complete rework
     157                 :            :         // since GetSdImport().GetMasterStylesContext() gives always ZERO
     158                 :            :         // because of content/style file split. Now the nechanism is to
     159                 :            :         // compare the wanted masterpage-name with the existing masterpages
     160                 :            :         // which were loaded and created in the styles section loading.
     161         [ +  - ]:         32 :         uno::Reference< drawing::XDrawPages > xMasterPages(GetSdImport().GetLocalMasterPages(), uno::UNO_QUERY);
     162         [ +  - ]:         32 :         uno::Reference < drawing::XMasterPageTarget > xDrawPage(rShapes, uno::UNO_QUERY);
     163                 :         32 :         uno::Reference< drawing::XDrawPage > xMasterPage;
     164                 :            : 
     165 [ +  - ][ +  - ]:         32 :         if(xDrawPage.is() && xMasterPages.is())
                 [ +  - ]
     166                 :            :         {
     167                 :         32 :             sal_Bool bDone(sal_False);
     168                 :            :             OUString sDisplayName( rImport.GetStyleDisplayName(
     169         [ +  - ]:         32 :                             XML_STYLE_FAMILY_MASTER_PAGE, maMasterPageName ) );
     170                 :            : 
     171 [ +  + ][ +  - ]:         64 :             for(sal_Int32 a = 0; !bDone && a < xMasterPages->getCount(); a++)
         [ +  - ][ +  - ]
                 [ +  + ]
     172                 :            :             {
     173 [ +  - ][ +  - ]:         32 :                 uno::Any aAny(xMasterPages->getByIndex(a));
     174         [ +  - ]:         32 :                 aAny >>= xMasterPage;
     175                 :            : 
     176         [ +  - ]:         32 :                 if(xMasterPage.is())
     177                 :            :                 {
     178         [ +  - ]:         32 :                     uno::Reference < container::XNamed > xMasterNamed(xMasterPage, uno::UNO_QUERY);
     179         [ +  - ]:         32 :                     if(xMasterNamed.is())
     180                 :            :                     {
     181 [ +  - ][ +  - ]:         32 :                         OUString sMasterPageName = xMasterNamed->getName();
     182                 :            : 
     183 [ +  - ][ +  - ]:         32 :                         if(!sMasterPageName.isEmpty() && sMasterPageName.equals(sDisplayName))
                 [ +  - ]
     184                 :            :                         {
     185 [ +  - ][ +  - ]:         32 :                             xDrawPage->setMasterPage(xMasterPage);
     186                 :         32 :                             bDone = sal_True;
     187                 :         32 :                         }
     188                 :         32 :                     }
     189                 :            :                 }
     190                 :         32 :             }
     191                 :            : 
     192                 :         32 :             DBG_ASSERT( bDone, "xmloff::SdXMLDrawPageContext::SdXMLDrawPageContext(), could not find a slide master!" );
     193                 :         32 :         }
     194                 :            :     }
     195                 :            : 
     196         [ +  - ]:         32 :     SetStyle( maStyleName );
     197                 :            : 
     198         [ -  + ]:         32 :     if( !maHREF.isEmpty() )
     199                 :            :     {
     200         [ #  # ]:          0 :         uno::Reference< beans::XPropertySet > xProps( xShapeDrawPage, uno::UNO_QUERY );
     201         [ #  # ]:          0 :         if( xProps.is() )
     202                 :            :         {
     203                 :          0 :             sal_Int32 nIndex = maHREF.lastIndexOf( (sal_Unicode)'#' );
     204         [ #  # ]:          0 :             if( nIndex != -1 )
     205                 :            :             {
     206                 :          0 :                 OUString aFileName( maHREF.copy( 0, nIndex ) );
     207                 :          0 :                 OUString aBookmarkName( maHREF.copy( nIndex+1 ) );
     208                 :            : 
     209         [ #  # ]:          0 :                 maHREF = GetImport().GetAbsoluteReference( aFileName );
     210                 :          0 :                 maHREF += OUString(static_cast<sal_Unicode>('#'));
     211                 :          0 :                 maHREF += aBookmarkName;
     212                 :            :             }
     213                 :            : 
     214 [ #  # ][ #  # ]:          0 :             xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "BookmarkURL" ) ), uno::makeAny( maHREF ) );
         [ #  # ][ #  # ]
     215                 :          0 :         }
     216                 :            :     }
     217                 :            : 
     218         [ +  - ]:         32 :     SetLayout();
     219                 :            : 
     220         [ +  - ]:         32 :     DeleteAllShapes();
     221                 :         32 : }
     222                 :            : 
     223                 :            : //////////////////////////////////////////////////////////////////////////////
     224                 :            : 
     225                 :         32 : SdXMLDrawPageContext::~SdXMLDrawPageContext()
     226                 :            : {
     227         [ -  + ]:         64 : }
     228                 :            : 
     229                 :            : //////////////////////////////////////////////////////////////////////////////
     230                 :            : 
     231                 :        261 : SvXMLImportContext *SdXMLDrawPageContext::CreateChildContext( sal_uInt16 nPrefix,
     232                 :            :     const OUString& rLocalName,
     233                 :            :     const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList )
     234                 :            : {
     235                 :        261 :     SvXMLImportContext *pContext = 0L;
     236                 :        261 :     const SvXMLTokenMap& rTokenMap = GetSdImport().GetDrawPageElemTokenMap();
     237                 :            : 
     238                 :            :     // some special objects inside draw:page context
     239      [ +  -  + ]:        261 :     switch(rTokenMap.Get(nPrefix, rLocalName))
     240                 :            :     {
     241                 :            :         case XML_TOK_DRAWPAGE_NOTES:
     242                 :            :         {
     243         [ +  - ]:         28 :             if( GetSdImport().IsImpress() )
     244                 :            :             {
     245                 :            :                 // get notes page
     246         [ +  - ]:         28 :                 uno::Reference< presentation::XPresentationPage > xPresPage(GetLocalShapesContext(), uno::UNO_QUERY);
     247         [ +  - ]:         28 :                 if(xPresPage.is())
     248                 :            :                 {
     249 [ +  - ][ +  - ]:         28 :                     uno::Reference< drawing::XDrawPage > xNotesDrawPage(xPresPage->getNotesPage(), uno::UNO_QUERY);
                 [ +  - ]
     250         [ +  - ]:         28 :                     if(xNotesDrawPage.is())
     251                 :            :                     {
     252         [ +  - ]:         28 :                         uno::Reference< drawing::XShapes > xNewShapes(xNotesDrawPage, uno::UNO_QUERY);
     253         [ +  - ]:         28 :                         if(xNewShapes.is())
     254                 :            :                         {
     255                 :            :                             // presentation:notes inside draw:page context
     256 [ +  - ][ +  - ]:         28 :                             pContext = new SdXMLNotesContext( GetSdImport(), nPrefix, rLocalName, xAttrList, xNewShapes);
     257                 :         28 :                         }
     258                 :         28 :                     }
     259                 :         28 :                 }
     260                 :            :             }
     261                 :         28 :             break;
     262                 :            :         }
     263                 :            :         case XML_TOK_DRAWPAGE_PAR:
     264                 :            :         case XML_TOK_DRAWPAGE_SEQ:
     265                 :            :         {
     266         [ #  # ]:          0 :             if( GetSdImport().IsImpress() )
     267                 :            :             {
     268         [ #  # ]:          0 :                 uno::Reference< animations::XAnimationNodeSupplier > xNodeSupplier(GetLocalShapesContext(), uno::UNO_QUERY);
     269         [ #  # ]:          0 :                 if(xNodeSupplier.is())
     270                 :            :                 {
     271 [ #  # ][ #  # ]:          0 :                     pContext = new xmloff::AnimationNodeContext( xNodeSupplier->getAnimationNode(), GetSdImport(), nPrefix, rLocalName, xAttrList );
         [ #  # ][ #  # ]
     272                 :          0 :                     mbHadSMILNodes = true;
     273                 :          0 :                 }
     274                 :            :             }
     275                 :          0 :             break;
     276                 :            :         }
     277                 :            :     }
     278                 :            : 
     279                 :            :     // call parent when no own context was created
     280         [ +  + ]:        261 :     if(!pContext)
     281                 :        233 :         pContext = SdXMLGenericPageContext::CreateChildContext(nPrefix, rLocalName, xAttrList);
     282                 :            : 
     283                 :        261 :     return pContext;
     284                 :            : }
     285                 :            : 
     286                 :         32 : void SdXMLDrawPageContext::EndElement()
     287                 :            : {
     288                 :         32 :     SdXMLGenericPageContext::EndElement();
     289 [ +  - ][ +  - ]:         32 :     GetImport().GetShapeImport()->endPage(GetLocalShapesContext());
     290                 :            : 
     291         [ -  + ]:         32 :     if( mbHadSMILNodes )
     292                 :            :     {
     293         [ #  # ]:          0 :         uno::Reference< animations::XAnimationNodeSupplier > xNodeSupplier(GetLocalShapesContext(), uno::UNO_QUERY);
     294         [ #  # ]:          0 :         uno::Reference< beans::XPropertySet > xPageProps( GetLocalShapesContext(), uno::UNO_QUERY );
     295         [ #  # ]:          0 :         if(xNodeSupplier.is())
     296 [ #  # ][ #  # ]:          0 :             xmloff::AnimationNodeContext::postProcessRootNode( GetSdImport(), xNodeSupplier->getAnimationNode(), xPageProps );
                 [ #  # ]
     297                 :            :     }
     298                 :         32 : }
     299                 :            : 
     300                 :            : //////////////////////////////////////////////////////////////////////////////
     301                 :            : //////////////////////////////////////////////////////////////////////////////
     302                 :            : 
     303                 :         11 : SdXMLBodyContext::SdXMLBodyContext( SdXMLImport& rImport,
     304                 :            :     sal_uInt16 nPrfx, const OUString& rLocalName )
     305                 :         11 : :   SvXMLImportContext( rImport, nPrfx, rLocalName )
     306                 :            : {
     307                 :         11 : }
     308                 :            : 
     309                 :            : //////////////////////////////////////////////////////////////////////////////
     310                 :            : 
     311                 :         11 : SdXMLBodyContext::~SdXMLBodyContext()
     312                 :            : {
     313         [ -  + ]:         22 : }
     314                 :            : 
     315                 :            : //////////////////////////////////////////////////////////////////////////////
     316                 :            : 
     317                 :         39 : SvXMLImportContext *SdXMLBodyContext::CreateChildContext(
     318                 :            :     sal_uInt16 nPrefix,
     319                 :            :     const OUString& rLocalName,
     320                 :            :     const uno::Reference< xml::sax::XAttributeList>& xAttrList )
     321                 :            : {
     322                 :         39 :     SvXMLImportContext *pContext = 0L;
     323                 :         39 :     const SvXMLTokenMap& rTokenMap = GetSdImport().GetBodyElemTokenMap();
     324                 :            : 
     325   [ -  +  +  - ]:         39 :     switch(rTokenMap.Get(nPrefix, rLocalName))
     326                 :            :     {
     327                 :            :         case XML_TOK_BODY_HEADER_DECL:
     328                 :            :         case XML_TOK_BODY_FOOTER_DECL:
     329                 :            :         case XML_TOK_BODY_DATE_TIME_DECL:
     330                 :            :         {
     331         [ #  # ]:          0 :             pContext = new SdXMLHeaderFooterDeclContext( GetImport(), nPrefix, rLocalName, xAttrList );
     332                 :          0 :             break;
     333                 :            :         }
     334                 :            :         case XML_TOK_BODY_PAGE:
     335                 :            :         {
     336                 :            :             // only read the first page in preview mode
     337 [ +  + ][ +  - ]:         32 :             if( (GetSdImport().GetNewPageCount() == 0) || !GetSdImport().IsPreview() )
                 [ +  - ]
     338                 :            :             {
     339                 :            :                 // import this page
     340                 :         32 :                 uno::Reference< drawing::XDrawPage > xNewDrawPage;
     341         [ +  - ]:         32 :                 uno::Reference< drawing::XDrawPages > xDrawPages(GetSdImport().GetLocalDrawPages(), uno::UNO_QUERY);
     342                 :            : 
     343         [ -  + ]:         32 :                 if( !xDrawPages.is() )
     344                 :            :                     break;
     345                 :            : 
     346 [ +  - ][ +  - ]:         32 :                 if(GetSdImport().GetNewPageCount() + 1 > xDrawPages->getCount())
                 [ +  + ]
     347                 :            :                 {
     348                 :            :                     // new page, create and insert
     349 [ +  - ][ +  - ]:         21 :                     xNewDrawPage = xDrawPages->insertNewByIndex(xDrawPages->getCount());
         [ +  - ][ +  - ]
                 [ +  - ]
     350                 :            :                 }
     351                 :            :                 else
     352                 :            :                 {
     353                 :            :                     // existing page, use it
     354 [ +  - ][ +  - ]:         11 :                     uno::Any aAny(xDrawPages->getByIndex(GetSdImport().GetNewPageCount()));
     355         [ +  - ]:         11 :                     aAny >>= xNewDrawPage;
     356                 :            :                 }
     357                 :            : 
     358                 :            :                 // increment global import page counter
     359                 :         32 :                 GetSdImport().IncrementNewPageCount();
     360                 :            : 
     361         [ +  - ]:         32 :                 if(xNewDrawPage.is())
     362                 :            :                 {
     363         [ +  - ]:         32 :                     uno::Reference< drawing::XShapes > xNewShapes(xNewDrawPage, uno::UNO_QUERY);
     364         [ +  - ]:         32 :                     if(xNewShapes.is())
     365                 :            :                     {
     366                 :            :                         // draw:page inside office:body context
     367                 :            :                         pContext = new SdXMLDrawPageContext(GetSdImport(), nPrefix, rLocalName, xAttrList,
     368 [ +  - ][ +  - ]:         32 :                             xNewShapes);
     369                 :         32 :                     }
     370 [ -  + ][ +  - ]:         32 :                 }
     371                 :            :             }
     372                 :         32 :             break;
     373                 :            :         }
     374                 :            :         case XML_TOK_BODY_SETTINGS:
     375                 :            :         {
     376         [ +  - ]:          7 :             pContext = new SdXMLShowsContext( GetSdImport(), nPrefix, rLocalName, xAttrList );
     377                 :            :         }
     378                 :            :     }
     379                 :            : 
     380                 :            :     // call parent when no own context was created
     381         [ -  + ]:         39 :     if(!pContext)
     382                 :          0 :         pContext = SvXMLImportContext::CreateChildContext(nPrefix, rLocalName, xAttrList);
     383                 :            : 
     384                 :         39 :     return pContext;
     385                 :            : }
     386                 :            : 
     387                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10