LCOV - code coverage report
Current view: top level - xmloff/source/chart - XMLSymbolTypePropertyHdl.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 47 47 100.0 %
Date: 2014-11-03 Functions: 7 7 100.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 "XMLSymbolTypePropertyHdl.hxx"
      21             : #include <xmloff/xmluconv.hxx>
      22             : #include <com/sun/star/chart/ChartErrorIndicatorType.hpp>
      23             : #include <rtl/ustrbuf.hxx>
      24             : 
      25             : using namespace ::xmloff::token;
      26             : 
      27             : namespace
      28             : {
      29             : struct SvXMLSignedEnumMapEntry
      30             : {
      31             :     ::xmloff::token::XMLTokenEnum   eToken;
      32             :     sal_Int32                       nValue;
      33             : };
      34             : 
      35             : const SvXMLSignedEnumMapEntry aXMLChartSymbolTypeEnumMap[] =
      36             : {
      37             :     { XML_NONE,                -3 },
      38             :     { XML_AUTOMATIC,           -2 },
      39             :     { XML_IMAGE,               -1 },
      40             :     { XML_TOKEN_INVALID,        0 }
      41             : };
      42             : 
      43             : const SvXMLSignedEnumMapEntry aXMLChartSymbolNameMap[] =
      44             : {
      45             :     { XML_GRADIENTSTYLE_SQUARE, 0 },  // "square"
      46             :     { XML_DIAMOND,              1 },
      47             :     { XML_ARROW_DOWN,           2 },
      48             :     { XML_ARROW_UP,             3 },
      49             :     { XML_ARROW_RIGHT,          4 },
      50             :     { XML_ARROW_LEFT,           5 },
      51             :     { XML_BOW_TIE,              6 },
      52             :     { XML_HOURGLASS,            7 },
      53             :     { XML_CIRCLE,               8 },
      54             :     { XML_STAR,                 9 },
      55             :     { XML_X,                   10 },
      56             :     { XML_PLUS,                11 },
      57             :     { XML_ASTERISK,            12 },
      58             :     { XML_HORIZONTAL_BAR,      13 },
      59             :     { XML_VERTICAL_BAR,        14 },
      60             :     { XML_TOKEN_INVALID,        0 }
      61             : };
      62             : 
      63         632 : bool lcl_convertEnum(
      64             :     OUStringBuffer & rBuffer,
      65             :     sal_Int32 nValue,
      66             :     const SvXMLSignedEnumMapEntry *pMap )
      67             : {
      68         632 :     enum XMLTokenEnum eTok = XML_TOKEN_INVALID;
      69             : 
      70        6008 :     while( pMap->eToken != XML_TOKEN_INVALID )
      71             :     {
      72        5100 :         if( pMap->nValue == nValue )
      73             :         {
      74         356 :             eTok = pMap->eToken;
      75         356 :             break;
      76             :         }
      77        4744 :         pMap++;
      78             :     }
      79             : 
      80         632 :     if( eTok != XML_TOKEN_INVALID )
      81         356 :         rBuffer.append( GetXMLToken(eTok) );
      82             : 
      83         632 :     return (eTok != XML_TOKEN_INVALID);
      84             : }
      85             : 
      86         324 : bool lcl_convertEnum(
      87             :     sal_Int32 & rEnum,
      88             :     const OUString & rValue,
      89             :     const SvXMLSignedEnumMapEntry *pMap )
      90             : {
      91        1270 :     while( pMap->eToken != XML_TOKEN_INVALID )
      92             :     {
      93         852 :         if( IsXMLToken( rValue, pMap->eToken ) )
      94             :         {
      95         230 :             rEnum = pMap->nValue;
      96         230 :             return true;
      97             :         }
      98         622 :         pMap++;
      99             :     }
     100          94 :     return false;
     101             : }
     102             : 
     103             : } // anonymous namespace
     104             : 
     105             : using namespace com::sun::star;
     106             : 
     107        3776 : XMLSymbolTypePropertyHdl::XMLSymbolTypePropertyHdl( bool bIsNamedSymbol )
     108        3776 :         : m_bIsNamedSymbol( bIsNamedSymbol )
     109        3776 : {}
     110             : 
     111        7552 : XMLSymbolTypePropertyHdl::~XMLSymbolTypePropertyHdl()
     112        7552 : {}
     113             : 
     114         324 : bool XMLSymbolTypePropertyHdl::importXML( const OUString& rStrImpValue,
     115             :                                                   uno::Any& rValue, const SvXMLUnitConverter& /*rUnitConverter*/ ) const
     116             : {
     117         324 :     bool bResult = false;
     118             : 
     119         324 :     if( m_bIsNamedSymbol )
     120             :     {
     121          94 :         sal_Int32 nValue = -3; // NONE
     122          94 :         bResult = lcl_convertEnum( nValue, rStrImpValue, aXMLChartSymbolNameMap );
     123          94 :         rValue <<= nValue;
     124             :     }
     125             :     else
     126             :     {
     127         230 :         sal_Int32 nValue = -3; // NONE
     128         230 :         bResult = lcl_convertEnum( nValue, rStrImpValue, aXMLChartSymbolTypeEnumMap );
     129         230 :         rValue <<= nValue;
     130             :     }
     131             : 
     132         324 :     return bResult;
     133             : }
     134             : 
     135         712 : bool XMLSymbolTypePropertyHdl::exportXML( OUString& rStrExpValue,
     136             :                                               const uno::Any& rValue, const SvXMLUnitConverter& /*rUnitConverter*/ ) const
     137             : {
     138         712 :     bool bResult = false;
     139             : 
     140         712 :     sal_Int32 nType = -3; // NONE
     141         712 :     rValue >>= nType;
     142             : 
     143         712 :     if( m_bIsNamedSymbol )
     144             :     {
     145         356 :         OUStringBuffer aBuf;
     146         356 :         bResult = lcl_convertEnum( aBuf, nType, aXMLChartSymbolNameMap );
     147         356 :         rStrExpValue = aBuf.makeStringAndClear();
     148             :     }
     149             :     else
     150             :     {
     151         356 :         if( nType < 0 )
     152             :         {
     153         276 :             OUStringBuffer aBuf;
     154         276 :             bResult = lcl_convertEnum( aBuf, nType, aXMLChartSymbolTypeEnumMap );
     155         276 :             rStrExpValue = aBuf.makeStringAndClear();
     156             :         }
     157             :         else
     158             :         {
     159          80 :             bResult = true;
     160          80 :             rStrExpValue = GetXMLToken( XML_NAMED_SYMBOL );
     161             :         }
     162             :     }
     163             : 
     164         712 :     return bResult;
     165             : }
     166             : 
     167             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10