Update ooo320-m1
[ooovba.git] / xmloff / source / chart / XMLSymbolTypePropertyHdl.cxx
blobcf2f6598fe2ff2a3dec5f00271bbb73cac3729b1
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLSymbolTypePropertyHdl.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include "XMLSymbolTypePropertyHdl.hxx"
34 #include <xmloff/xmluconv.hxx>
35 #include <com/sun/star/chart/ChartErrorIndicatorType.hpp>
36 #include <rtl/ustrbuf.hxx>
38 using namespace ::xmloff::token;
39 using ::rtl::OUString;
40 using ::rtl::OUStringBuffer;
42 namespace
44 struct SvXMLSignedEnumMapEntry
46 ::xmloff::token::XMLTokenEnum eToken;
47 sal_Int32 nValue;
50 SvXMLSignedEnumMapEntry aXMLChartSymbolTypeEnumMap[] =
52 { XML_NONE, -3 },
53 { XML_AUTOMATIC, -2 },
54 { XML_IMAGE, -1 },
55 { XML_TOKEN_INVALID, 0 }
58 SvXMLSignedEnumMapEntry aXMLChartSymbolNameMap[] =
60 { XML_GRADIENTSTYLE_SQUARE, 0 }, // "square"
61 { XML_DIAMOND, 1 },
62 { XML_ARROW_DOWN, 2 },
63 { XML_ARROW_UP, 3 },
64 { XML_ARROW_RIGHT, 4 },
65 { XML_ARROW_LEFT, 5 },
66 { XML_BOW_TIE, 6 },
67 { XML_HOURGLASS, 7 },
68 { XML_TOKEN_INVALID, 0 }
71 sal_Bool lcl_convertEnum(
72 OUStringBuffer & rBuffer,
73 sal_Int32 nValue,
74 const SvXMLSignedEnumMapEntry *pMap )
76 enum XMLTokenEnum eTok = XML_TOKEN_INVALID;
78 while( pMap->eToken != XML_TOKEN_INVALID )
80 if( pMap->nValue == nValue )
82 eTok = pMap->eToken;
83 break;
85 pMap++;
88 if( eTok != XML_TOKEN_INVALID )
89 rBuffer.append( GetXMLToken(eTok) );
91 return (eTok != XML_TOKEN_INVALID);
94 sal_Bool lcl_convertEnum(
95 sal_Int32 & rEnum,
96 const OUString & rValue,
97 const SvXMLSignedEnumMapEntry *pMap )
99 while( pMap->eToken != XML_TOKEN_INVALID )
101 if( IsXMLToken( rValue, pMap->eToken ) )
103 rEnum = pMap->nValue;
104 return sal_True;
106 pMap++;
108 return sal_False;
111 } // anonymous namespace
113 using namespace com::sun::star;
115 XMLSymbolTypePropertyHdl::XMLSymbolTypePropertyHdl( bool bIsNamedSymbol )
116 : m_bIsNamedSymbol( bIsNamedSymbol )
119 XMLSymbolTypePropertyHdl::~XMLSymbolTypePropertyHdl()
122 sal_Bool XMLSymbolTypePropertyHdl::importXML( const OUString& rStrImpValue,
123 uno::Any& rValue, const SvXMLUnitConverter& /*rUnitConverter*/ ) const
125 sal_Bool bResult = sal_False;
127 if( m_bIsNamedSymbol )
129 sal_Int32 nValue = -3; // NONE
130 bResult = lcl_convertEnum( nValue, rStrImpValue, aXMLChartSymbolNameMap );
131 rValue <<= nValue;
133 else
135 sal_Int32 nValue = -3; // NONE
136 bResult = lcl_convertEnum( nValue, rStrImpValue, aXMLChartSymbolTypeEnumMap );
137 rValue <<= nValue;
140 return bResult;
143 sal_Bool XMLSymbolTypePropertyHdl::exportXML( OUString& rStrExpValue,
144 const uno::Any& rValue, const SvXMLUnitConverter& /*rUnitConverter*/ ) const
146 sal_Bool bResult = sal_False;
148 sal_Int32 nType = -3; // NONE
149 rValue >>= nType;
151 if( m_bIsNamedSymbol )
153 OUStringBuffer aBuf;
154 bResult = lcl_convertEnum( aBuf, nType, aXMLChartSymbolNameMap );
155 rStrExpValue = aBuf.makeStringAndClear();
157 else
159 if( nType < 0 )
161 OUStringBuffer aBuf;
162 bResult = lcl_convertEnum( aBuf, nType, aXMLChartSymbolTypeEnumMap );
163 rStrExpValue = aBuf.makeStringAndClear();
165 else
167 bResult = true;
168 rStrExpValue = GetXMLToken( XML_NAMED_SYMBOL );
172 return bResult;