Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / xmloff / source / chart / XMLSymbolTypePropertyHdl.cxx
blobff956bc59f2ff99a56167c4666669485e1a42d8b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "XMLSymbolTypePropertyHdl.hxx"
21 #include <xmloff/xmluconv.hxx>
22 #include <com/sun/star/chart/ChartErrorIndicatorType.hpp>
23 #include <rtl/ustrbuf.hxx>
25 using namespace ::xmloff::token;
27 namespace
29 struct SvXMLSignedEnumMapEntry
31 ::xmloff::token::XMLTokenEnum eToken;
32 sal_Int32 nValue;
35 const SvXMLSignedEnumMapEntry aXMLChartSymbolTypeEnumMap[] =
37 { XML_NONE, -3 },
38 { XML_AUTOMATIC, -2 },
39 { XML_IMAGE, -1 },
40 { XML_TOKEN_INVALID, 0 }
43 const SvXMLSignedEnumMapEntry aXMLChartSymbolNameMap[] =
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 }
63 bool lcl_convertEnum(
64 OUStringBuffer & rBuffer,
65 sal_Int32 nValue,
66 const SvXMLSignedEnumMapEntry *pMap )
68 enum XMLTokenEnum eTok = XML_TOKEN_INVALID;
70 while( pMap->eToken != XML_TOKEN_INVALID )
72 if( pMap->nValue == nValue )
74 eTok = pMap->eToken;
75 break;
77 pMap++;
80 if( eTok != XML_TOKEN_INVALID )
81 rBuffer.append( GetXMLToken(eTok) );
83 return (eTok != XML_TOKEN_INVALID);
86 bool lcl_convertEnum(
87 sal_Int32 & rEnum,
88 const OUString & rValue,
89 const SvXMLSignedEnumMapEntry *pMap )
91 while( pMap->eToken != XML_TOKEN_INVALID )
93 if( IsXMLToken( rValue, pMap->eToken ) )
95 rEnum = pMap->nValue;
96 return true;
98 pMap++;
100 return false;
103 } // anonymous namespace
105 using namespace com::sun::star;
107 XMLSymbolTypePropertyHdl::XMLSymbolTypePropertyHdl( bool bIsNamedSymbol )
108 : m_bIsNamedSymbol( bIsNamedSymbol )
111 XMLSymbolTypePropertyHdl::~XMLSymbolTypePropertyHdl()
114 bool XMLSymbolTypePropertyHdl::importXML( const OUString& rStrImpValue,
115 uno::Any& rValue, const SvXMLUnitConverter& /*rUnitConverter*/ ) const
117 bool bResult = false;
119 if( m_bIsNamedSymbol )
121 sal_Int32 nValue = -3; // NONE
122 bResult = lcl_convertEnum( nValue, rStrImpValue, aXMLChartSymbolNameMap );
123 rValue <<= nValue;
125 else
127 sal_Int32 nValue = -3; // NONE
128 bResult = lcl_convertEnum( nValue, rStrImpValue, aXMLChartSymbolTypeEnumMap );
129 rValue <<= nValue;
132 return bResult;
135 bool XMLSymbolTypePropertyHdl::exportXML( OUString& rStrExpValue,
136 const uno::Any& rValue, const SvXMLUnitConverter& /*rUnitConverter*/ ) const
138 bool bResult = false;
140 sal_Int32 nType = -3; // NONE
141 rValue >>= nType;
143 if( m_bIsNamedSymbol )
145 OUStringBuffer aBuf;
146 bResult = lcl_convertEnum( aBuf, nType, aXMLChartSymbolNameMap );
147 rStrExpValue = aBuf.makeStringAndClear();
149 else
151 if( nType < 0 )
153 OUStringBuffer aBuf;
154 bResult = lcl_convertEnum( aBuf, nType, aXMLChartSymbolTypeEnumMap );
155 rStrExpValue = aBuf.makeStringAndClear();
157 else
159 bResult = true;
160 rStrExpValue = GetXMLToken( XML_NAMED_SYMBOL );
164 return bResult;
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */