LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/oox/source/ppt - pptgraphicshapecontext.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 11 66 16.7 %
Date: 2013-07-09 Functions: 4 5 80.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 <com/sun/star/xml/sax/FastToken.hpp>
      21             : #include <com/sun/star/drawing/LineStyle.hpp>
      22             : #include <com/sun/star/beans/XMultiPropertySet.hpp>
      23             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      24             : #include <com/sun/star/container/XNamed.hpp>
      25             : 
      26             : #include "oox/ppt/pptshape.hxx"
      27             : #include "oox/ppt/pptgraphicshapecontext.hxx"
      28             : #include "oox/ppt/pptshapepropertiescontext.hxx"
      29             : #include "oox/ppt/slidepersist.hxx"
      30             : #include "oox/drawingml/shapestylecontext.hxx"
      31             : #include "oox/token/namespaces.hxx"
      32             : #include "oox/drawingml/fillpropertiesgroupcontext.hxx"
      33             : #include "oox/drawingml/lineproperties.hxx"
      34             : #include "oox/drawingml/drawingmltypes.hxx"
      35             : #include "oox/drawingml/customshapegeometry.hxx"
      36             : #include "oox/drawingml/textbodycontext.hxx"
      37             : #include <oox/token/tokens.hxx>
      38             : 
      39             : using namespace oox::core;
      40             : using namespace ::com::sun::star;
      41             : using namespace ::com::sun::star::uno;
      42             : using namespace ::com::sun::star::drawing;
      43             : using namespace ::com::sun::star::beans;
      44             : using namespace ::com::sun::star::text;
      45             : using namespace ::com::sun::star::xml::sax;
      46             : 
      47             : namespace oox { namespace ppt {
      48             : 
      49             : // CT_Shape
      50           1 : PPTGraphicShapeContext::PPTGraphicShapeContext( ContextHandler2Helper& rParent, const SlidePersistPtr pSlidePersistPtr, oox::drawingml::ShapePtr pMasterShapePtr, oox::drawingml::ShapePtr pShapePtr )
      51             : : oox::drawingml::GraphicShapeContext( rParent, pMasterShapePtr, pShapePtr )
      52           1 : , mpSlidePersistPtr( pSlidePersistPtr )
      53             : {
      54           1 : }
      55             : 
      56             : // if nFirstPlaceholder can't be found, it will be searched for nSecondPlaceholder
      57           0 : static oox::drawingml::ShapePtr findPlaceholder( sal_Int32 nFirstPlaceholder, sal_Int32 nSecondPlaceholder, std::vector< oox::drawingml::ShapePtr >& rShapes )
      58             : {
      59           0 :     oox::drawingml::ShapePtr pPlaceholder = PPTShape::findPlaceholder( nFirstPlaceholder, rShapes );
      60           0 :     return !nSecondPlaceholder || pPlaceholder.get() ? pPlaceholder : PPTShape::findPlaceholder( nSecondPlaceholder, rShapes );
      61             : }
      62             : 
      63           6 : ContextHandlerRef PPTGraphicShapeContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
      64             : {
      65           6 :     switch( aElementToken )
      66             :     {
      67             :     // nvSpPr CT_ShapeNonVisual begin
      68             : //  case NMSP_PPT|XML_drElemPr:
      69             : //      break;
      70             :     case PPT_TOKEN(cNvPr):
      71           1 :         mpShapePtr->setId( rAttribs.getString( XML_id ).get() );
      72           1 :         mpShapePtr->setName( rAttribs.getString( XML_name ).get() );
      73           1 :         break;
      74             :     case PPT_TOKEN(ph):
      75             :     {
      76           0 :         sal_Int32 nSubType( rAttribs.getToken( XML_type, XML_obj ) );
      77           0 :         mpShapePtr->setSubType( nSubType );
      78           0 :         OUString sIdx( rAttribs.getString( XML_idx ).get() );
      79           0 :         sal_Bool bHasIdx = !sIdx.isEmpty();
      80           0 :         sal_Int32 nIdx = sIdx.toInt32();
      81           0 :         if( rAttribs.hasAttribute( XML_idx ) )
      82           0 :             mpShapePtr->setSubTypeIndex( nIdx );
      83             : 
      84           0 :         if ( nSubType || bHasIdx )
      85             :         {
      86           0 :             PPTShape* pPPTShapePtr = dynamic_cast< PPTShape* >( mpShapePtr.get() );
      87           0 :             if ( pPPTShapePtr )
      88             :             {
      89           0 :                 oox::ppt::ShapeLocation eShapeLocation = pPPTShapePtr->getShapeLocation();
      90           0 :                 oox::drawingml::ShapePtr pPlaceholder;
      91             : 
      92           0 :                 if ( bHasIdx && eShapeLocation == Slide )
      93             :                 {
      94             :                     // TODO: use id to shape map
      95           0 :                     SlidePersistPtr pMasterPersist( mpSlidePersistPtr->getMasterPersist() );
      96           0 :                     if ( pMasterPersist.get() && rAttribs.hasAttribute( XML_idx ) )
      97           0 :                         pPlaceholder = PPTShape::findPlaceholderByIndex( nIdx, pMasterPersist->getShapes()->getChildren() );
      98             :                 }
      99           0 :                 if ( !pPlaceholder.get() && ( ( eShapeLocation == Slide ) || ( eShapeLocation == Layout ) ) )
     100             :                 {
     101             :                     // inheriting properties from placeholder objects by cloning shape
     102             : 
     103           0 :                     sal_Int32 nFirstPlaceholder = 0;
     104           0 :                     sal_Int32 nSecondPlaceholder = 0;
     105           0 :                     switch( nSubType )
     106             :                     {
     107             :                         case XML_ctrTitle :     // slide/layout
     108           0 :                             nFirstPlaceholder = XML_ctrTitle;
     109           0 :                             nSecondPlaceholder = XML_title;
     110           0 :                             break;
     111             :                         case XML_subTitle :     // slide/layout
     112           0 :                             nFirstPlaceholder = XML_subTitle;
     113           0 :                             nSecondPlaceholder = XML_title;
     114           0 :                             break;
     115             :                         case XML_obj :          // slide/layout
     116           0 :                             nFirstPlaceholder = XML_body;
     117           0 :                             break;
     118             :                         case XML_dt :           // slide/layout/master/notes/notesmaster/handoutmaster
     119             :                         case XML_sldNum :       // slide/layout/master/notes/notesmaster/handoutmaster
     120             :                         case XML_ftr :          // slide/layout/master/notes/notesmaster/handoutmaster
     121             :                         case XML_hdr :          // notes/notesmaster/handoutmaster
     122             :                         case XML_body :         // slide/layout/master/notes/notesmaster
     123             :                         case XML_title :        // slide/layout/master/
     124             :                         case XML_chart :        // slide/layout
     125             :                         case XML_tbl :          // slide/layout
     126             :                         case XML_clipArt :      // slide/layout
     127             :                         case XML_dgm :          // slide/layout
     128             :                         case XML_media :        // slide/layout
     129             :                         case XML_sldImg :       // notes/notesmaster
     130             :                         case XML_pic :          // slide/layout
     131           0 :                             nFirstPlaceholder = nSubType;
     132             :                         default:
     133           0 :                             break;
     134             :                     }
     135           0 :                     if ( nFirstPlaceholder )
     136             :                     {
     137           0 :                         if ( eShapeLocation == Layout )     // for layout objects the referenced object can be found within the same shape tree
     138           0 :                             pPlaceholder = findPlaceholder( nFirstPlaceholder, nSecondPlaceholder, mpSlidePersistPtr->getShapes()->getChildren() );
     139           0 :                         else if ( eShapeLocation == Slide ) // normal slide shapes have to search within the corresponding master tree for referenced objects
     140             :                         {
     141           0 :                             SlidePersistPtr pMasterPersist( mpSlidePersistPtr->getMasterPersist() );
     142           0 :                             if ( pMasterPersist.get() )
     143           0 :                                 pPlaceholder = findPlaceholder( nFirstPlaceholder, nSecondPlaceholder, pMasterPersist->getShapes()->getChildren() );
     144             :                         }
     145             :                     }
     146             :                 }
     147           0 :                 if ( pPlaceholder.get() )
     148             :                 {
     149           0 :                     bool bUseText = true;
     150             :                     // TODO: Check if pPlaceholder->getSubType is none (i.e. none explicitly specified)
     151           0 :                     if( pPlaceholder->getSubType() == XML_obj )
     152           0 :                         bUseText = false;
     153           0 :                     mpShapePtr->applyShapeReference( *pPlaceholder.get(), bUseText );
     154           0 :                     PPTShape* pPPTShape = dynamic_cast< PPTShape* >( pPlaceholder.get() );
     155           0 :                     if ( pPPTShape )
     156           0 :                         pPPTShape->setReferenced( sal_True );
     157           0 :                     pPPTShapePtr->setPlaceholder( pPlaceholder );
     158           0 :                 }
     159             :             }
     160             :         }
     161           0 :         break;
     162             :     }
     163             :     // nvSpPr CT_ShapeNonVisual end
     164             : 
     165             :     case PPT_TOKEN(spPr):
     166           1 :         return new PPTShapePropertiesContext( *this, *mpShapePtr );
     167             : 
     168             :     case PPT_TOKEN(style):
     169           0 :         return new oox::drawingml::ShapeStyleContext( *this, *mpShapePtr );
     170             : 
     171             :     case PPT_TOKEN(txBody):
     172             :     {
     173           0 :         oox::drawingml::TextBodyPtr xTextBody( new oox::drawingml::TextBody );
     174           0 :         mpShapePtr->setTextBody( xTextBody );
     175           0 :         return new oox::drawingml::TextBodyContext( *this, *xTextBody );
     176             :     }
     177             :     }
     178             : 
     179           5 :     return GraphicShapeContext::onCreateContext( aElementToken, rAttribs );
     180             : }
     181             : 
     182             : 
     183         141 : } }
     184             : 
     185             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10