LCOV - code coverage report
Current view: top level - oox/source/drawingml/diagram - datamodelcontext.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 125 144 86.8 %
Date: 2014-04-11 Functions: 29 30 96.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 "datamodelcontext.hxx"
      21             : #include "oox/helper/attributelist.hxx"
      22             : #include "oox/drawingml/fillpropertiesgroupcontext.hxx"
      23             : #include "oox/drawingml/shapepropertiescontext.hxx"
      24             : #include "oox/drawingml/textbodycontext.hxx"
      25             : 
      26             : using namespace ::oox::core;
      27             : using namespace ::com::sun::star::xml::sax;
      28             : using namespace ::com::sun::star::uno;
      29             : 
      30             : namespace oox { namespace drawingml {
      31             : 
      32             : // CT_CxnList
      33          40 : class CxnListContext
      34             :     : public ContextHandler2
      35             : {
      36             : public:
      37          20 :     CxnListContext( ContextHandler2Helper& rParent,
      38             :                     dgm::Connections & aConnections )
      39             :         : ContextHandler2( rParent )
      40          20 :         , mrConnection( aConnections )
      41             :         {
      42          20 :         }
      43             : 
      44             :     virtual ContextHandlerRef
      45        1098 :     onCreateContext( sal_Int32 aElementToken,
      46             :                      const AttributeList& rAttribs ) SAL_OVERRIDE
      47             :         {
      48        1098 :             switch( aElementToken )
      49             :             {
      50             :                 case DGM_TOKEN( cxn ):
      51             :                 {
      52        1098 :                     mrConnection.push_back( dgm::Connection() );
      53        1098 :                     dgm::Connection& rConnection=mrConnection.back();
      54             : 
      55        1098 :                     const sal_Int32 nType = rAttribs.getToken( XML_type, XML_parOf );
      56        1098 :                     rConnection.mnType = nType;
      57        1098 :                     rConnection.msModelId = rAttribs.getString( XML_modelId ).get();
      58        1098 :                     rConnection.msSourceId = rAttribs.getString( XML_srcId ).get();
      59        1098 :                     rConnection.msDestId  = rAttribs.getString( XML_destId ).get();
      60        1098 :                     rConnection.msPresId  = rAttribs.getString( XML_presId ).get();
      61        1098 :                     rConnection.msSibTransId  = rAttribs.getString( XML_sibTransId ).get();
      62        1098 :                     rConnection.msParTransId  = rAttribs.getString( XML_parTransId ).get();
      63        1098 :                     rConnection.mnSourceOrder = rAttribs.getInteger( XML_srcOrd, 0 );
      64        1098 :                     rConnection.mnDestOrder = rAttribs.getInteger( XML_destOrd, 0 );
      65             : 
      66             :                     // skip CT_extLst
      67        1098 :                     return 0;
      68             :                 }
      69             :                 default:
      70           0 :                     break;
      71             :             }
      72             : 
      73           0 :             return this;
      74             :         }
      75             : private:
      76             :     dgm::Connections& mrConnection;
      77             : };
      78             : 
      79             : 
      80             : // CT_presLayoutVars
      81         416 : class PresLayoutVarsContext
      82             :     : public ContextHandler2
      83             : {
      84             : public:
      85         208 :     PresLayoutVarsContext( ContextHandler2Helper& rParent,
      86             :                            dgm::Point & rPoint ) :
      87             :         ContextHandler2( rParent ),
      88         208 :         mrPoint( rPoint )
      89             :     {
      90         208 :     }
      91             :     virtual ContextHandlerRef
      92         273 :     onCreateContext( sal_Int32 aElementToken,
      93             :                      const AttributeList& rAttribs ) SAL_OVERRIDE
      94             :     {
      95         273 :         switch( aElementToken )
      96             :         {
      97             :             // TODO
      98             :             case DGM_TOKEN( animLvl ):
      99             :             case DGM_TOKEN( animOne ):
     100          11 :                 break;
     101             :             case DGM_TOKEN( bulletEnabled ):
     102          70 :                 mrPoint.mbBulletEnabled = rAttribs.getBool( XML_val, false );
     103          70 :                 break;
     104             :             case DGM_TOKEN( chMax ):
     105          24 :                 mrPoint.mnMaxChildren = rAttribs.getInteger( XML_val, -1 );
     106          24 :                 break;
     107             :             case DGM_TOKEN( chPref ):
     108          75 :                 mrPoint.mnPreferredChildren = rAttribs.getInteger( XML_val, -1 );
     109          75 :                 break;
     110             :             case DGM_TOKEN( dir ):
     111          20 :                 mrPoint.mnDirection = rAttribs.getToken( XML_val, XML_norm );
     112          20 :                 break;
     113             :             case DGM_TOKEN( hierBranch ):
     114          56 :                 mrPoint.mnHierarchyBranch = rAttribs.getToken( XML_val, XML_std );
     115          56 :                 break;
     116             :             case DGM_TOKEN( orgChart ):
     117           1 :                 mrPoint.mbOrgChartEnabled = rAttribs.getBool( XML_val, false );
     118           1 :                 break;
     119             :             case DGM_TOKEN( resizeHandles ):
     120          16 :                 mrPoint.mnResizeHandles = rAttribs.getToken( XML_val, XML_rel );
     121          16 :                 break;
     122             :             default:
     123           0 :                 break;
     124             :         }
     125             : 
     126         273 :         return this;
     127             :     }
     128             : 
     129             : private:
     130             :     dgm::Point& mrPoint;
     131             : };
     132             : 
     133             : 
     134             : // CT_prSet
     135        2282 : class PropertiesContext
     136             :     : public ContextHandler2
     137             : {
     138             : public:
     139        1141 :     PropertiesContext( ContextHandler2Helper& rParent,
     140             :                        dgm::Point & rPoint,
     141             :                        const AttributeList& rAttribs ) :
     142             :         ContextHandler2( rParent ),
     143        1141 :         mrPoint( rPoint )
     144             :     {
     145        1141 :         OUString aEmptyStr;
     146             : 
     147        1141 :         mrPoint.msColorTransformCategoryId = rAttribs.getString( XML_csCatId, aEmptyStr );
     148        1141 :         mrPoint.msColorTransformTypeId = rAttribs.getString( XML_csTypeId, aEmptyStr );
     149        1141 :         mrPoint.msLayoutCategoryId = rAttribs.getString( XML_loCatId, aEmptyStr );
     150        1141 :         mrPoint.msLayoutTypeId = rAttribs.getString( XML_loTypeId, aEmptyStr );
     151        1141 :         mrPoint.msPlaceholderText = rAttribs.getString( XML_phldrT, aEmptyStr );
     152        1141 :         mrPoint.msPresentationAssociationId = rAttribs.getString( XML_presAssocID, aEmptyStr );
     153        1141 :         mrPoint.msPresentationLayoutName = rAttribs.getString( XML_presName, aEmptyStr );
     154        1141 :         mrPoint.msPresentationLayoutStyleLabel = rAttribs.getString( XML_presStyleLbl, aEmptyStr );
     155        1141 :         mrPoint.msQuickStyleCategoryId = rAttribs.getString( XML_qsCatId, aEmptyStr );
     156        1141 :         mrPoint.msQuickStyleTypeId = rAttribs.getString( XML_qsTypeId, aEmptyStr );
     157             : 
     158        1141 :         mrPoint.mnCustomAngle = rAttribs.getInteger( XML_custAng, -1 );
     159        1141 :         mrPoint.mnPercentageNeighbourWidth = rAttribs.getInteger( XML_custLinFactNeighborX, -1 );
     160        1141 :         mrPoint.mnPercentageNeighbourHeight = rAttribs.getInteger( XML_custLinFactNeighborY, -1 );
     161        1141 :         mrPoint.mnPercentageOwnWidth = rAttribs.getInteger( XML_custLinFactX, -1 );
     162        1141 :         mrPoint.mnPercentageOwnHeight = rAttribs.getInteger( XML_custLinFactY, -1 );
     163        1141 :         mrPoint.mnIncludeAngleScale = rAttribs.getInteger( XML_custRadScaleInc, -1 );
     164        1141 :         mrPoint.mnRadiusScale = rAttribs.getInteger( XML_custRadScaleRad, -1 );
     165        1141 :         mrPoint.mnWidthScale = rAttribs.getInteger( XML_custScaleX, -1 );
     166        1141 :         mrPoint.mnHeightScale = rAttribs.getInteger( XML_custScaleY, -1 );
     167        1141 :         mrPoint.mnWidthOverride = rAttribs.getInteger( XML_custSzX, -1 );
     168        1141 :         mrPoint.mnHeightOverride = rAttribs.getInteger( XML_custSzY, -1 );
     169        1141 :         mrPoint.mnLayoutStyleCount = rAttribs.getInteger( XML_presStyleCnt, -1 );
     170        1141 :         mrPoint.mnLayoutStyleIndex = rAttribs.getInteger( XML_presStyleIdx, -1 );
     171             : 
     172        1141 :         mrPoint.mbCoherent3DOffset = rAttribs.getBool( XML_coherent3DOff, false );
     173        1141 :         mrPoint.mbCustomHorizontalFlip = rAttribs.getBool( XML_custFlipHor, false );
     174        1141 :         mrPoint.mbCustomVerticalFlip = rAttribs.getBool( XML_custFlipVert, false );
     175        1141 :         mrPoint.mbCustomText = rAttribs.getBool( XML_custT, false );
     176        1141 :         mrPoint.mbIsPlaceholder = rAttribs.getBool( XML_phldr, false );
     177        1141 :     }
     178             : 
     179             :     virtual ContextHandlerRef
     180         208 :     onCreateContext( sal_Int32 aElementToken,
     181             :                      const AttributeList& ) SAL_OVERRIDE
     182             :         {
     183         208 :             switch( aElementToken )
     184             :             {
     185             :             case DGM_TOKEN( presLayoutVars ):
     186         208 :                 return new PresLayoutVarsContext( *this, mrPoint );
     187             :             case DGM_TOKEN( style ):
     188             :                 // skip CT_shapeStyle
     189           0 :                 return 0;
     190             :             default:
     191           0 :                 break;
     192             :             }
     193           0 :             return this;
     194             :         }
     195             : 
     196             : private:
     197             :     dgm::Point& mrPoint;
     198             : };
     199             : 
     200             : 
     201             : // CL_Pt
     202        2282 : class PtContext
     203             :     : public ContextHandler2
     204             : {
     205             : public:
     206        1141 :     PtContext( ContextHandler2Helper& rParent,
     207             :                const AttributeList& rAttribs,
     208             :                dgm::Point & rPoint):
     209             :         ContextHandler2( rParent ),
     210        1141 :         mrPoint( rPoint )
     211             :     {
     212        1141 :         mrPoint.msModelId = rAttribs.getString( XML_modelId ).get();
     213             : 
     214             :         // the default type is XML_node
     215        1141 :         const sal_Int32 nType  = rAttribs.getToken( XML_type, XML_node );
     216        1141 :         mrPoint.mnType = nType;
     217             : 
     218             :         // ignore the cxnId unless it is this type. See 5.15.3.1.3 in Primer
     219        1141 :         if( ( nType == XML_parTrans ) || ( nType == XML_sibTrans ) )
     220         310 :             mrPoint.msCnxId = rAttribs.getString( XML_cxnId ).get();
     221        1141 :     }
     222             : 
     223             : 
     224             :     virtual ContextHandlerRef
     225        3181 :     onCreateContext( sal_Int32 aElementToken,
     226             :                      const AttributeList& rAttribs ) SAL_OVERRIDE
     227             :         {
     228        3181 :             switch( aElementToken )
     229             :             {
     230             :             case DGM_TOKEN( extLst ):
     231           0 :                 return 0;
     232             :             case DGM_TOKEN( prSet ):
     233             :                 OSL_TRACE( "diagram property set for point");
     234        1141 :                 return new PropertiesContext( *this, mrPoint, rAttribs );
     235             :             case DGM_TOKEN( spPr ):
     236             :                 OSL_TRACE( "shape props for point");
     237        1141 :                 if( !mrPoint.mpShape )
     238        1141 :                     mrPoint.mpShape.reset( new Shape() );
     239        1141 :                 return new ShapePropertiesContext( *this, *(mrPoint.mpShape) );
     240             :             case DGM_TOKEN( t ):
     241             :             {
     242             :                 OSL_TRACE( "shape text body for point");
     243         899 :                 TextBodyPtr xTextBody( new TextBody );
     244         899 :                 if( !mrPoint.mpShape )
     245           0 :                     mrPoint.mpShape.reset( new Shape() );
     246         899 :                 mrPoint.mpShape->setTextBody( xTextBody );
     247         899 :                 return new TextBodyContext( *this, *xTextBody );
     248             :             }
     249             :             default:
     250           0 :                 break;
     251             :             }
     252           0 :             return this;
     253             :         }
     254             : 
     255             : private:
     256             :     dgm::Point& mrPoint;
     257             : };
     258             : 
     259             : 
     260             : 
     261             : // CT_PtList
     262          40 : class PtListContext
     263             :     : public ContextHandler2
     264             : {
     265             : public:
     266          20 :     PtListContext( ContextHandler2Helper& rParent,  dgm::Points& rPoints) :
     267             :         ContextHandler2( rParent ),
     268          20 :         mrPoints( rPoints )
     269          20 :     {}
     270             :     virtual ContextHandlerRef
     271        1141 :     onCreateContext( sal_Int32 aElementToken,
     272             :                      const AttributeList& rAttribs ) SAL_OVERRIDE
     273             :         {
     274        1141 :             switch( aElementToken )
     275             :             {
     276             :             case DGM_TOKEN( pt ):
     277             :             {
     278             :                 // CT_Pt
     279        1141 :                 mrPoints.push_back( dgm::Point() );
     280        1141 :                 return new PtContext( *this, rAttribs, mrPoints.back() );
     281             :             }
     282             :             default:
     283           0 :                 break;
     284             :             }
     285           0 :             return this;
     286             :         }
     287             : 
     288             : private:
     289             :     dgm::Points& mrPoints;
     290             : };
     291             : 
     292             : // CT_BackgroundFormatting
     293          40 : class BackgroundFormattingContext
     294             :     : public ContextHandler2
     295             : {
     296             : public:
     297          20 :     BackgroundFormattingContext( ContextHandler2Helper& rParent, DiagramDataPtr & pModel )
     298             :         : ContextHandler2( rParent )
     299          20 :         , mpDataModel( pModel )
     300             :         {
     301             :             OSL_ENSURE( pModel, "the data model MUST NOT be NULL" );
     302          20 :         }
     303             : 
     304             :     virtual ContextHandlerRef
     305           0 :     onCreateContext( sal_Int32 aElementToken,
     306             :                      const AttributeList& rAttribs ) SAL_OVERRIDE
     307             :         {
     308           0 :             switch( aElementToken )
     309             :             {
     310             :             case A_TOKEN( blipFill ):
     311             :             case A_TOKEN( gradFill ):
     312             :             case A_TOKEN( grpFill ):
     313             :             case A_TOKEN( noFill ):
     314             :             case A_TOKEN( pattFill ):
     315             :             case A_TOKEN( solidFill ):
     316             :                 // EG_FillProperties
     317             :                 return FillPropertiesContext::createFillContext(
     318           0 :                     *this, aElementToken, rAttribs, *mpDataModel->getFillProperties() );
     319             :             case A_TOKEN( effectDag ):
     320             :             case A_TOKEN( effectLst ):
     321             :                 // TODO
     322             :                 // EG_EffectProperties
     323           0 :                 break;
     324             :             default:
     325           0 :                 break;
     326             :             }
     327           0 :             return this;
     328             :         }
     329             : private:
     330             :     DiagramDataPtr mpDataModel;
     331             : };
     332             : 
     333             : 
     334             : 
     335          20 : DataModelContext::DataModelContext( ContextHandler2Helper& rParent,
     336             :                                     const DiagramDataPtr & pDataModel )
     337             :     : ContextHandler2( rParent )
     338          20 :     , mpDataModel( pDataModel )
     339             : {
     340             :     OSL_ENSURE( pDataModel, "Data Model must not be NULL" );
     341          20 : }
     342             : 
     343             : 
     344          60 : DataModelContext::~DataModelContext()
     345             : {
     346             :     // some debug
     347          20 :     mpDataModel->dump();
     348          40 : }
     349             : 
     350             : ContextHandlerRef
     351         140 : DataModelContext::onCreateContext( ::sal_Int32 aElement,
     352             :                                    const AttributeList& rAttribs )
     353             : {
     354         140 :     switch( aElement )
     355             :     {
     356             :     case DGM_TOKEN( cxnLst ):
     357             :         // CT_CxnList
     358          20 :         return new CxnListContext( *this, mpDataModel->getConnections() );
     359             :     case DGM_TOKEN( ptLst ):
     360             :         // CT_PtList
     361          20 :         return new PtListContext( *this, mpDataModel->getPoints() );
     362             :     case DGM_TOKEN( bg ):
     363             :         // CT_BackgroundFormatting
     364          20 :         return new BackgroundFormattingContext( *this, mpDataModel );
     365             :     case DGM_TOKEN( whole ):
     366             :         // CT_WholeE2oFormatting
     367             :         // TODO
     368          20 :         return 0;
     369             :     case DGM_TOKEN( extLst ):
     370             :     case A_TOKEN( ext ):
     371          40 :         break;
     372             :     case DSP_TOKEN( dataModelExt ):
     373          20 :         mpDataModel->getExtDrawings().push_back( rAttribs.getString( XML_relId ).get() );
     374          20 :         break;
     375             :     default:
     376           0 :         break;
     377             :     }
     378             : 
     379          60 :     return this;
     380             : }
     381             : 
     382         177 : } }
     383             : 
     384             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10