LCOV - code coverage report
Current view: top level - libreoffice/oox/source/drawingml/diagram - layoutnodecontext.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 148 0.7 %
Date: 2012-12-27 Functions: 2 26 7.7 %
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 "layoutnodecontext.hxx"
      21             : 
      22             : #include "oox/helper/attributelist.hxx"
      23             : #include "oox/drawingml/diagram/diagram.hxx"
      24             : #include "oox/drawingml/shapecontext.hxx"
      25             : #include "oox/drawingml/customshapeproperties.hxx"
      26             : #include "diagramdefinitioncontext.hxx"
      27             : #include "constraintlistcontext.hxx"
      28             : 
      29             : using namespace ::oox::core;
      30             : using namespace ::com::sun::star::uno;
      31             : using namespace ::com::sun::star::xml::sax;
      32             : 
      33             : namespace oox { namespace drawingml {
      34             : 
      35           0 : class IfContext
      36             :     : public LayoutNodeContext
      37             : {
      38             : public:
      39           0 :     IfContext( ContextHandler& rParent,
      40             :                const Reference< XFastAttributeList >& xAttribs,
      41             :                const ConditionAtomPtr& pAtom )
      42           0 :         : LayoutNodeContext( rParent, xAttribs, pAtom )
      43           0 :     {}
      44             : };
      45             : 
      46             : 
      47             : 
      48           0 : class AlgorithmContext
      49             :     : public ContextHandler
      50             : {
      51             : public:
      52           0 :     AlgorithmContext( ContextHandler& rParent, const Reference< XFastAttributeList >& xAttribs, const AlgAtomPtr & pNode )
      53             :         : ContextHandler( rParent )
      54             :         , mnRevision( 0 )
      55           0 :         , mpNode( pNode )
      56             :         {
      57           0 :             AttributeList aAttribs( xAttribs );
      58           0 :             mnRevision = aAttribs.getInteger( XML_rev, 0 );
      59           0 :             pNode->setType(xAttribs->getOptionalValueToken(XML_type, 0));
      60           0 :         }
      61             : 
      62             :     virtual Reference< XFastContextHandler > SAL_CALL
      63           0 :     createFastChildContext( ::sal_Int32 aElement,
      64             :                             const Reference< XFastAttributeList >& xAttribs )
      65             :         throw (SAXException, RuntimeException)
      66             :         {
      67           0 :             Reference< XFastContextHandler > xRet;
      68             : 
      69           0 :             switch( aElement )
      70             :             {
      71             :                 case DGM_TOKEN( param ):
      72             :                 {
      73           0 :                     AttributeList aAttribs( xAttribs );
      74           0 :                     const sal_Int32 nValTok=aAttribs.getToken( XML_val, 0 );
      75             :                     mpNode->addParam(
      76             :                         aAttribs.getToken( XML_type, 0 ),
      77           0 :                         nValTok>0 ? nValTok : aAttribs.getInteger( XML_val, 0 ) );
      78           0 :                     break;
      79             :                 }
      80             :                 default:
      81           0 :                     break;
      82             :             }
      83             : 
      84           0 :             if( !xRet.is() )
      85           0 :                 xRet.set(this);
      86             : 
      87           0 :             return xRet;
      88             :         }
      89             : 
      90             : private:
      91             :     sal_Int32  mnRevision;
      92             :     AlgAtomPtr mpNode;
      93             : };
      94             : 
      95             : 
      96           0 : class ChooseContext
      97             :     : public ContextHandler
      98             : {
      99             : public:
     100           0 :     ChooseContext( ContextHandler& rParent, const Reference< XFastAttributeList >& xAttribs, const LayoutAtomPtr & pNode )
     101             :         : ContextHandler( rParent )
     102           0 :         , mpNode( pNode )
     103             :         {
     104           0 :             msName = xAttribs->getOptionalValue( XML_name );
     105           0 :         }
     106             : 
     107             :     virtual Reference< XFastContextHandler > SAL_CALL
     108           0 :     createFastChildContext( ::sal_Int32 aElement,
     109             :                             const Reference< XFastAttributeList >& xAttribs )
     110             :         throw (SAXException, RuntimeException)
     111             :         {
     112           0 :             Reference< XFastContextHandler > xRet;
     113             : 
     114           0 :             switch( aElement )
     115             :             {
     116             :             case DGM_TOKEN( if ):
     117             :             {
     118             :                 // CT_When
     119           0 :                 mpConditionNode.reset( new ConditionAtom(xAttribs) );
     120           0 :                 mpNode->addChild( mpConditionNode );
     121           0 :                 xRet.set( new IfContext( *this, xAttribs, mpConditionNode ) );
     122           0 :                 break;
     123             :             }
     124             :             case DGM_TOKEN( else ):
     125             :                 // CT_Otherwise
     126           0 :                 if( mpConditionNode )
     127             :                 {
     128           0 :                     mpConditionNode->readElseBranch();
     129           0 :                     xRet.set( new IfContext( *this, xAttribs, mpConditionNode ) );
     130           0 :                     mpConditionNode.reset();
     131             :                 }
     132             :                 else
     133             :                 {
     134             :                     OSL_TRACE( "ignoring second else clause" );
     135             :                 }
     136           0 :                 break;
     137             :             default:
     138           0 :                 break;
     139             :             }
     140             : 
     141           0 :             if( !xRet.is() )
     142           0 :                 xRet.set(this);
     143             : 
     144           0 :             return xRet;
     145             :         }
     146             : private:
     147             :     OUString msName;
     148             :     LayoutAtomPtr mpNode;
     149             :     ConditionAtomPtr mpConditionNode;
     150             : };
     151             : 
     152             : 
     153             : 
     154             : 
     155           0 : class ForEachContext
     156             :     : public LayoutNodeContext
     157             : {
     158             : public:
     159           0 :     ForEachContext( ContextHandler& rParent, const Reference< XFastAttributeList >& xAttribs, const ForEachAtomPtr& pAtom )
     160           0 :         : LayoutNodeContext( rParent, xAttribs, pAtom )
     161             :         {
     162           0 :             xAttribs->getOptionalValue( XML_ref );
     163           0 :             pAtom->iterator().loadFromXAttr( xAttribs );
     164           0 :         }
     165             : };
     166             : 
     167             : 
     168             : // CT_LayoutVariablePropertySet
     169             : class LayoutVariablePropertySetContext
     170             :     : public ContextHandler
     171             : {
     172             : public:
     173           0 :     LayoutVariablePropertySetContext( ContextHandler& rParent, LayoutNode::VarMap & aVar )
     174             :         : ContextHandler( rParent )
     175           0 :         , mVariables( aVar )
     176             :         {
     177           0 :         }
     178             : 
     179           0 :     virtual ~LayoutVariablePropertySetContext()
     180           0 :         {
     181           0 :         }
     182             : 
     183           0 :     virtual Reference< XFastContextHandler > SAL_CALL createFastChildContext( ::sal_Int32 aElement, const Reference< XFastAttributeList >& xAttribs )
     184             :         throw (SAXException, RuntimeException)
     185             :         {
     186           0 :             Reference< XFastContextHandler > xRet;
     187             : 
     188           0 :             sal_Int32 nIdx =  LayoutNodeContext::tagToVarIdx( getBaseToken( aElement ) );
     189           0 :             if( nIdx != -1 )
     190             :             {
     191           0 :                 mVariables[ nIdx ] = makeAny( xAttribs->getOptionalValue( XML_val ) );
     192             :             }
     193           0 :             if( !xRet.is() )
     194           0 :                 xRet.set(this);
     195             : 
     196           0 :             return xRet;
     197             :         }
     198             : private:
     199             :     LayoutNode::VarMap & mVariables;
     200             : };
     201             : 
     202             : 
     203             : // CT_LayoutNode
     204           0 : LayoutNodeContext::LayoutNodeContext( ContextHandler& rParent,
     205             :                                       const Reference< XFastAttributeList >& xAttribs,
     206             :                                       const LayoutAtomPtr& pAtom )
     207             :     : ContextHandler( rParent )
     208           0 :     , mpNode( pAtom )
     209             : {
     210             :     OSL_ENSURE( pAtom, "Node must NOT be NULL" );
     211           0 :     mpNode->setName( xAttribs->getOptionalValue( XML_name ) );
     212           0 : }
     213             : 
     214             : 
     215           0 : LayoutNodeContext::~LayoutNodeContext()
     216             : {
     217           0 : }
     218             : 
     219           0 : void SAL_CALL LayoutNodeContext::endFastElement( ::sal_Int32 )
     220             :     throw (SAXException, RuntimeException)
     221             : {
     222             : 
     223           0 : }
     224             : 
     225             : /** convert the XML tag to a variable index in the array
     226             :  * @param aTag the tag, without namespace
     227             :  * @return the variable index. -1 is an error
     228             :  */
     229           0 : sal_Int32 LayoutNodeContext::tagToVarIdx( sal_Int32 aTag )
     230             : {
     231           0 :     sal_Int32 nIdx = -1;
     232           0 :     switch( aTag )
     233             :     {
     234             :     case DGM_TOKEN( animLvl ):
     235           0 :         nIdx = LayoutNode::VAR_animLvl;
     236           0 :         break;
     237             :     case DGM_TOKEN( animOne ):
     238           0 :         nIdx = LayoutNode::VAR_animOne;
     239           0 :         break;
     240             :     case DGM_TOKEN( bulletEnabled ):
     241           0 :         nIdx = LayoutNode::VAR_bulletEnabled;
     242           0 :         break;
     243             :     case DGM_TOKEN( chMax ):
     244           0 :         nIdx = LayoutNode::VAR_chMax;
     245           0 :         break;
     246             :     case DGM_TOKEN( chPref ):
     247           0 :         nIdx = LayoutNode::VAR_chPref;
     248           0 :         break;
     249             :     case DGM_TOKEN( dir ):
     250           0 :         nIdx = LayoutNode::VAR_dir;
     251           0 :         break;
     252             :     case DGM_TOKEN( hierBranch ):
     253           0 :         nIdx = LayoutNode::VAR_hierBranch;
     254           0 :         break;
     255             :     case DGM_TOKEN( orgChart ):
     256           0 :         nIdx = LayoutNode::VAR_orgChart;
     257           0 :         break;
     258             :     case DGM_TOKEN( resizeHandles ):
     259           0 :         nIdx = LayoutNode::VAR_resizeHandles;
     260           0 :         break;
     261             :     default:
     262           0 :         break;
     263             :     }
     264           0 :     return nIdx;
     265             : }
     266             : 
     267             : 
     268             : Reference< XFastContextHandler > SAL_CALL
     269           0 : LayoutNodeContext::createFastChildContext( ::sal_Int32 aElement,
     270             :                                                   const Reference< XFastAttributeList >& xAttribs )
     271             :     throw (SAXException, RuntimeException)
     272             : {
     273           0 :     Reference< XFastContextHandler > xRet;
     274             : 
     275           0 :     switch( aElement )
     276             :     {
     277             :     case DGM_TOKEN( layoutNode ):
     278             :     {
     279           0 :         LayoutNodePtr pNode( new LayoutNode() );
     280           0 :         mpNode->addChild( pNode );
     281           0 :         pNode->setChildOrder( xAttribs->getOptionalValueToken( XML_chOrder, XML_b ) );
     282           0 :         pNode->setMoveWith( xAttribs->getOptionalValue( XML_moveWith ) );
     283           0 :         pNode->setStyleLabel( xAttribs->getOptionalValue( XML_styleLbl ) );
     284           0 :         xRet.set( new LayoutNodeContext( *this, xAttribs, pNode ) );
     285           0 :         break;
     286             :     }
     287             :     case DGM_TOKEN( shape ):
     288             :     {
     289           0 :         LayoutNodePtr pNode( boost::dynamic_pointer_cast< LayoutNode >( mpNode ) );
     290           0 :         if( pNode )
     291             :         {
     292           0 :             ShapePtr pShape;
     293             : 
     294           0 :             if( xAttribs->hasAttribute( XML_type ) )
     295             :             {
     296           0 :                 pShape.reset( new Shape("com.sun.star.drawing.CustomShape") );
     297           0 :                 const sal_Int32 nType(xAttribs->getOptionalValueToken( XML_type, XML_obj ));
     298           0 :                 pShape->setSubType( nType );
     299           0 :                 pShape->getCustomShapeProperties()->setShapePresetType( nType );
     300             :             }
     301             :             else
     302             :             {
     303           0 :                 pShape.reset( new Shape("com.sun.star.drawing.GroupShape") );
     304             :             }
     305             : 
     306           0 :             pNode->setShape( pShape );
     307           0 :             xRet.set( new ShapeContext( *this, ShapePtr(), pShape ) );
     308             :         }
     309             :         else
     310             :         {
     311             :             OSL_TRACE( "OOX: encountered a shape in a non layoutNode context" );
     312             :         }
     313           0 :         break;
     314             :     }
     315             :     case DGM_TOKEN( extLst ):
     316           0 :         return xRet;
     317             :     case DGM_TOKEN( alg ):
     318             :     {
     319             :         // CT_Algorithm
     320           0 :         AlgAtomPtr pAtom( new AlgAtom );
     321           0 :         mpNode->addChild( pAtom );
     322           0 :         xRet.set( new AlgorithmContext( *this, xAttribs, pAtom ) );
     323           0 :         break;
     324             :     }
     325             :     case DGM_TOKEN( choose ):
     326             :     {
     327             :         // CT_Choose
     328           0 :         LayoutAtomPtr pAtom( new ChooseAtom );
     329           0 :         mpNode->addChild( pAtom );
     330           0 :         xRet.set( new ChooseContext( *this, xAttribs, pAtom ) );
     331           0 :          break;
     332             :     }
     333             :     case DGM_TOKEN( forEach ):
     334             :     {
     335             :         // CT_ForEach
     336           0 :         ForEachAtomPtr pAtom( new ForEachAtom(xAttribs) );
     337           0 :         mpNode->addChild( pAtom );
     338           0 :         xRet.set( new ForEachContext( *this, xAttribs, pAtom ) );
     339           0 :         break;
     340             :     }
     341             :     case DGM_TOKEN( constrLst ):
     342             :         // CT_Constraints
     343           0 :         xRet.set( new ConstraintListContext( *this, xAttribs, mpNode ) );
     344           0 :         break;
     345             :     case DGM_TOKEN( presOf ):
     346             :     {
     347             :         // CT_PresentationOf
     348             :         // TODO
     349           0 :         xAttribs->getOptionalValue( XML_axis );
     350           0 :         xAttribs->getOptionalValue( XML_cnt );
     351           0 :         xAttribs->getOptionalValue( XML_hideLastTrans );
     352           0 :         xAttribs->getOptionalValue( XML_ptType );
     353           0 :         xAttribs->getOptionalValue( XML_st );
     354           0 :         xAttribs->getOptionalValue( XML_step );
     355           0 :         break;
     356             :     }
     357             :     case DGM_TOKEN( ruleLst ):
     358             :         // CT_Rules
     359             :         // TODO
     360           0 :         break;
     361             :     case DGM_TOKEN( varLst ):
     362             :     {
     363           0 :         LayoutNodePtr pNode( boost::dynamic_pointer_cast< LayoutNode >( mpNode ) );
     364           0 :         if( pNode )
     365             :         {
     366           0 :             xRet.set( new LayoutVariablePropertySetContext( *this, pNode->variables() ) );
     367             :         }
     368             :         else
     369             :         {
     370             :             OSL_TRACE( "OOX: encountered a varLst in a non layoutNode context" );
     371             :         }
     372           0 :         break;
     373             :     }
     374             :     default:
     375           0 :         break;
     376             :     }
     377           0 :     if( !xRet.is() )
     378           0 :         xRet.set(this);
     379             : 
     380           0 :     return xRet;
     381             : }
     382             : 
     383             : 
     384          51 : } }
     385             : 
     386             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10