1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26 #include "XMLSymbolTypePropertyHdl.hxx"
27 #include <xmloff/xmluconv.hxx>
28 #include <com/sun/star/chart/ChartErrorIndicatorType.hpp>
29 #include <rtl/ustrbuf.hxx>
30 
31 using namespace ::xmloff::token;
32 using ::rtl::OUString;
33 using ::rtl::OUStringBuffer;
34 
35 namespace
36 {
37 struct SvXMLSignedEnumMapEntry
38 {
39 	::xmloff::token::XMLTokenEnum   eToken;
40 	sal_Int32                       nValue;
41 };
42 
43 SvXMLSignedEnumMapEntry aXMLChartSymbolTypeEnumMap[] =
44 {
45     { XML_NONE,                -3 },
46     { XML_AUTOMATIC,           -2 },
47     { XML_IMAGE,               -1 },
48     { XML_TOKEN_INVALID,        0 }
49 };
50 
51 SvXMLSignedEnumMapEntry aXMLChartSymbolNameMap[] =
52 {
53     { XML_GRADIENTSTYLE_SQUARE, 0 },  // "square"
54     { XML_DIAMOND,              1 },
55     { XML_ARROW_DOWN,           2 },
56     { XML_ARROW_UP,             3 },
57     { XML_ARROW_RIGHT,          4 },
58     { XML_ARROW_LEFT,           5 },
59     { XML_BOW_TIE,              6 },
60     { XML_HOURGLASS,            7 },
61     { XML_CIRCLE,               8 },
62     { XML_STAR,                 9 },
63     { XML_X,                   10 },
64     { XML_PLUS,                11 },
65     { XML_ASTERISK,            12 },
66     { XML_HORIZONTAL_BAR,      13 },
67     { XML_VERTICAL_BAR,        14 },
68     { XML_TOKEN_INVALID,        0 }
69 };
70 
lcl_convertEnum(OUStringBuffer & rBuffer,sal_Int32 nValue,const SvXMLSignedEnumMapEntry * pMap)71 sal_Bool lcl_convertEnum(
72     OUStringBuffer & rBuffer,
73     sal_Int32 nValue,
74     const SvXMLSignedEnumMapEntry *pMap )
75 {
76     enum XMLTokenEnum eTok = XML_TOKEN_INVALID;
77 
78     while( pMap->eToken != XML_TOKEN_INVALID )
79     {
80         if( pMap->nValue == nValue )
81         {
82             eTok = pMap->eToken;
83             break;
84         }
85         pMap++;
86     }
87 
88     if( eTok != XML_TOKEN_INVALID )
89         rBuffer.append( GetXMLToken(eTok) );
90 
91     return (eTok != XML_TOKEN_INVALID);
92 }
93 
lcl_convertEnum(sal_Int32 & rEnum,const OUString & rValue,const SvXMLSignedEnumMapEntry * pMap)94 sal_Bool lcl_convertEnum(
95     sal_Int32 & rEnum,
96     const OUString & rValue,
97     const SvXMLSignedEnumMapEntry *pMap )
98 {
99     while( pMap->eToken != XML_TOKEN_INVALID )
100     {
101         if( IsXMLToken( rValue, pMap->eToken ) )
102         {
103             rEnum = pMap->nValue;
104             return sal_True;
105         }
106         pMap++;
107     }
108     return sal_False;
109 }
110 
111 } // anonymous namespace
112 
113 using namespace com::sun::star;
114 
XMLSymbolTypePropertyHdl(bool bIsNamedSymbol)115 XMLSymbolTypePropertyHdl::XMLSymbolTypePropertyHdl( bool bIsNamedSymbol )
116         : m_bIsNamedSymbol( bIsNamedSymbol )
117 {}
118 
~XMLSymbolTypePropertyHdl()119 XMLSymbolTypePropertyHdl::~XMLSymbolTypePropertyHdl()
120 {}
121 
importXML(const OUString & rStrImpValue,uno::Any & rValue,const SvXMLUnitConverter &) const122 sal_Bool XMLSymbolTypePropertyHdl::importXML( const OUString& rStrImpValue,
123 												  uno::Any& rValue, const SvXMLUnitConverter& /*rUnitConverter*/ ) const
124 {
125     sal_Bool bResult = sal_False;
126 
127     if( m_bIsNamedSymbol )
128     {
129         sal_Int32 nValue = -3; // NONE
130         bResult = lcl_convertEnum( nValue, rStrImpValue, aXMLChartSymbolNameMap );
131         rValue <<= nValue;
132     }
133     else
134     {
135         sal_Int32 nValue = -3; // NONE
136         bResult = lcl_convertEnum( nValue, rStrImpValue, aXMLChartSymbolTypeEnumMap );
137         rValue <<= nValue;
138     }
139 
140 	return bResult;
141 }
142 
exportXML(OUString & rStrExpValue,const uno::Any & rValue,const SvXMLUnitConverter &) const143 sal_Bool XMLSymbolTypePropertyHdl::exportXML( OUString& rStrExpValue,
144                                               const uno::Any& rValue, const SvXMLUnitConverter& /*rUnitConverter*/ ) const
145 {
146     sal_Bool bResult = sal_False;
147 
148     sal_Int32 nType = -3; // NONE
149     rValue >>= nType;
150 
151     if( m_bIsNamedSymbol )
152     {
153         OUStringBuffer aBuf;
154         bResult = lcl_convertEnum( aBuf, nType, aXMLChartSymbolNameMap );
155         rStrExpValue = aBuf.makeStringAndClear();
156     }
157     else
158     {
159         if( nType < 0 )
160         {
161             OUStringBuffer aBuf;
162             bResult = lcl_convertEnum( aBuf, nType, aXMLChartSymbolTypeEnumMap );
163             rStrExpValue = aBuf.makeStringAndClear();
164         }
165         else
166 		{
167 			bResult = true;
168             rStrExpValue = GetXMLToken( XML_NAMED_SYMBOL );
169 		}
170     }
171 
172 	return bResult;
173 }
174