LCOV - code coverage report
Current view: top level - libreoffice/oox/source/drawingml/diagram - diagramfragmenthandler.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 15 84 17.9 %
Date: 2012-12-27 Functions: 7 21 33.3 %
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 <osl/diagnose.h>
      21             : 
      22             : #include "diagramdefinitioncontext.hxx"
      23             : #include "diagramfragmenthandler.hxx"
      24             : #include "datamodelcontext.hxx"
      25             : #include "oox/drawingml/colorchoicecontext.hxx"
      26             : 
      27             : using namespace ::oox::core;
      28             : using namespace ::com::sun::star::xml::sax;
      29             : using namespace ::com::sun::star::uno;
      30             : 
      31             : namespace oox { namespace drawingml {
      32             : 
      33           1 : DiagramDataFragmentHandler::DiagramDataFragmentHandler( XmlFilterBase& rFilter,
      34             :                                                         const OUString& rFragmentPath,
      35             :                                                         const DiagramDataPtr pDataPtr )
      36             :     throw( )
      37             :     : FragmentHandler( rFilter, rFragmentPath )
      38           1 :     , mpDataPtr( pDataPtr )
      39             : {
      40           1 : }
      41             : 
      42           2 : DiagramDataFragmentHandler::~DiagramDataFragmentHandler( ) throw ()
      43             : {
      44             : 
      45           2 : }
      46             : 
      47           1 : void SAL_CALL DiagramDataFragmentHandler::endDocument()
      48             :     throw (SAXException, RuntimeException)
      49             : {
      50             : 
      51           1 : }
      52             : 
      53             : 
      54             : Reference< XFastContextHandler > SAL_CALL
      55           1 : DiagramDataFragmentHandler::createFastChildContext( ::sal_Int32 aElement,
      56             :                                                     const Reference< XFastAttributeList >& )
      57             :     throw ( SAXException, RuntimeException)
      58             : {
      59           1 :     Reference< XFastContextHandler > xRet;
      60             : 
      61           1 :     switch( aElement )
      62             :     {
      63             :     case DGM_TOKEN( dataModel ):
      64           1 :         xRet.set( new DataModelContext( *this, mpDataPtr ) );
      65           1 :         break;
      66             :     default:
      67           0 :         break;
      68             :     }
      69             : 
      70           1 :     if( !xRet.is() )
      71           0 :         xRet = getFastContextHandler();
      72             : 
      73           1 :     return xRet;
      74             : }
      75             : 
      76             : ///////////////////
      77             : 
      78           0 : DiagramLayoutFragmentHandler::DiagramLayoutFragmentHandler( XmlFilterBase& rFilter,
      79             :                                                         const OUString& rFragmentPath,
      80             :                                                         const DiagramLayoutPtr pDataPtr )
      81             :     throw( )
      82             :     : FragmentHandler( rFilter, rFragmentPath )
      83           0 :     , mpDataPtr( pDataPtr )
      84             : {
      85           0 : }
      86             : 
      87           0 : DiagramLayoutFragmentHandler::~DiagramLayoutFragmentHandler( ) throw ()
      88             : {
      89             : 
      90           0 : }
      91             : 
      92           0 : void SAL_CALL DiagramLayoutFragmentHandler::endDocument()
      93             :     throw (SAXException, RuntimeException)
      94             : {
      95             : 
      96           0 : }
      97             : 
      98             : 
      99             : Reference< XFastContextHandler > SAL_CALL
     100           0 : DiagramLayoutFragmentHandler::createFastChildContext( ::sal_Int32 aElement,
     101             :                                                       const Reference< XFastAttributeList >& xAttribs )
     102             :     throw ( SAXException, RuntimeException)
     103             : {
     104           0 :     Reference< XFastContextHandler > xRet;
     105             : 
     106           0 :     switch( aElement )
     107             :     {
     108             :     case DGM_TOKEN( layoutDef ):
     109           0 :         xRet.set( new DiagramDefinitionContext( *this, xAttribs, mpDataPtr ) );
     110           0 :         break;
     111             :     default:
     112           0 :         break;
     113             :     }
     114             : 
     115           0 :     if( !xRet.is() )
     116           0 :         xRet = getFastContextHandler();
     117             : 
     118           0 :     return xRet;
     119             : }
     120             : 
     121             : ///////////////////////
     122             : 
     123           0 : DiagramQStylesFragmentHandler::DiagramQStylesFragmentHandler( XmlFilterBase& rFilter,
     124             :                                                               const OUString& rFragmentPath,
     125             :                                                               DiagramQStyleMap& rStylesMap ) :
     126             :     FragmentHandler2( rFilter, rFragmentPath ),
     127             :     maStyleName(),
     128             :     maStyleEntry(),
     129           0 :     mrStylesMap( rStylesMap )
     130           0 : {}
     131             : 
     132           0 : ::oox::core::ContextHandlerRef DiagramQStylesFragmentHandler::createStyleMatrixContext(
     133             :     sal_Int32 nElement,
     134             :     const AttributeList& rAttribs,
     135             :     ShapeStyleRef& o_rStyle )
     136             : {
     137             :     o_rStyle.mnThemedIdx = (nElement == DGM_TOKEN(fontRef)) ?
     138           0 :         rAttribs.getToken( XML_idx, XML_none ) : rAttribs.getInteger( XML_idx, 0 );
     139           0 :     return new ColorContext( *this, o_rStyle.maPhClr );
     140             : }
     141             : 
     142           0 : ::oox::core::ContextHandlerRef DiagramQStylesFragmentHandler::onCreateContext( sal_Int32 nElement,
     143             :                                                                                const AttributeList& rAttribs )
     144             : {
     145             :     // state-table like way of navigating the color fragment. we
     146             :     // currently ignore everything except styleLbl in the colorsDef
     147             :     // element
     148           0 :     switch( getCurrentElement() )
     149             :     {
     150             :         case XML_ROOT_CONTEXT:
     151           0 :             return nElement == DGM_TOKEN(styleDef) ? this : NULL;
     152             :         case DGM_TOKEN(styleDef):
     153           0 :             return nElement == DGM_TOKEN(styleLbl) ? this : NULL;
     154             :         case DGM_TOKEN(styleLbl):
     155           0 :             return nElement == DGM_TOKEN(style) ? this : NULL;
     156             :         case DGM_TOKEN(style):
     157             :         {
     158           0 :             switch( nElement )
     159             :             {
     160             :                 case DGM_TOKEN(lnRef) :     // CT_StyleMatrixReference
     161             :                     return createStyleMatrixContext(nElement,rAttribs,
     162           0 :                                                     maStyleEntry.maLineStyle);
     163             :                 case DGM_TOKEN(fillRef) :   // CT_StyleMatrixReference
     164             :                     return createStyleMatrixContext(nElement,rAttribs,
     165           0 :                                                     maStyleEntry.maFillStyle);
     166             :                 case DGM_TOKEN(effectRef) : // CT_StyleMatrixReference
     167             :                     return createStyleMatrixContext(nElement,rAttribs,
     168           0 :                                                     maStyleEntry.maEffectStyle);
     169             :                 case DGM_TOKEN(fontRef) :   // CT_FontRe    ference
     170             :                     return createStyleMatrixContext(nElement,rAttribs,
     171           0 :                                                     maStyleEntry.maTextStyle);
     172             :             }
     173           0 :             return 0;
     174             :         }
     175             :     }
     176             : 
     177           0 :     return 0;
     178             : }
     179             : 
     180             : 
     181           0 : void DiagramQStylesFragmentHandler::onStartElement( const AttributeList& rAttribs )
     182             : {
     183           0 :     if( getCurrentElement() == DGM_TOKEN( styleDef ) )
     184             :     {
     185           0 :         maStyleName = rAttribs.getString( XML_name, OUString() );
     186           0 :         maStyleEntry = mrStylesMap[maStyleName];
     187             :     }
     188           0 : }
     189             : 
     190             : /////////////////////
     191             : 
     192           0 : void DiagramQStylesFragmentHandler::onEndElement( )
     193             : {
     194           0 :     if( getCurrentElement() == DGM_TOKEN(styleLbl) )
     195           0 :         mrStylesMap[maStyleName] = maStyleEntry;
     196           0 : }
     197             : 
     198           0 : ColorFragmentHandler::ColorFragmentHandler( ::oox::core::XmlFilterBase& rFilter,
     199             :                                             const OUString& rFragmentPath,
     200             :                                             DiagramColorMap& rColorsMap ) :
     201             :     FragmentHandler2(rFilter,rFragmentPath),
     202             :     maColorName(),
     203             :     maColorEntry(),
     204           0 :     mrColorsMap(rColorsMap)
     205           0 : {}
     206             : 
     207           0 : ::oox::core::ContextHandlerRef ColorFragmentHandler::onCreateContext( sal_Int32 nElement,
     208             :                                                                       const AttributeList& /*rAttribs*/ )
     209             : {
     210             :     // state-table like way of navigating the color fragment. we
     211             :     // currently ignore everything except styleLbl in the colorsDef
     212             :     // element
     213           0 :     switch( getCurrentElement() )
     214             :     {
     215             :         case XML_ROOT_CONTEXT:
     216           0 :             return nElement == DGM_TOKEN(colorsDef) ? this : NULL;
     217             :         case DGM_TOKEN(colorsDef):
     218           0 :             return nElement == DGM_TOKEN(styleLbl) ? this : NULL;
     219             :         case DGM_TOKEN(styleLbl):
     220             :             return ((nElement == DGM_TOKEN(fillClrLst)) ||
     221             :                     (nElement == DGM_TOKEN(linClrLst)) ||
     222             :                     (nElement == DGM_TOKEN(effectClrLst)) ||
     223             :                     (nElement == DGM_TOKEN(txLinClrLst)) ||
     224             :                     (nElement == DGM_TOKEN(txFillClrLst)) ||
     225           0 :                     (nElement == DGM_TOKEN(txEffectClrLst))) ? this : NULL;
     226             : 
     227             :         // the actual colors - defer to color fragment handlers.
     228             : 
     229             :         // TODO(F1): well, actually, there might be *several* color
     230             :         // definitions in it, after all it's called list. but
     231             :         // apparently colorChoiceContext doesn't handle that anyway...
     232             :         case DGM_TOKEN(fillClrLst):
     233           0 :             return new ColorContext( *this, maColorEntry.maFillColor );
     234             :         case DGM_TOKEN(linClrLst):
     235           0 :             return new ColorContext( *this, maColorEntry.maLineColor );
     236             :         case DGM_TOKEN(effectClrLst):
     237           0 :             return new ColorContext( *this, maColorEntry.maEffectColor );
     238             :         case DGM_TOKEN(txFillClrLst):
     239           0 :             return new ColorContext( *this, maColorEntry.maTextFillColor );
     240             :         case DGM_TOKEN(txLinClrLst):
     241           0 :             return new ColorContext( *this, maColorEntry.maTextLineColor );
     242             :         case DGM_TOKEN(txEffectClrLst):
     243           0 :             return new ColorContext( *this, maColorEntry.maTextEffectColor );
     244             :     }
     245             : 
     246           0 :     return 0;
     247             : }
     248             : 
     249             : 
     250           0 : void ColorFragmentHandler::onStartElement( const AttributeList& rAttribs )
     251             : {
     252           0 :     if( getCurrentElement() == DGM_TOKEN(styleLbl) )
     253             :     {
     254           0 :         maColorName = rAttribs.getString( XML_name, OUString() );
     255           0 :         maColorEntry = mrColorsMap[maColorName];
     256             :     }
     257           0 : }
     258             : 
     259           0 : void ColorFragmentHandler::onEndElement( )
     260             : {
     261           0 :     if( getCurrentElement() == DGM_TOKEN(styleLbl) )
     262           0 :         mrColorsMap[maColorName] = maColorEntry;
     263           0 : }
     264             : 
     265             : 
     266          51 : } }
     267             : 
     268             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10