LibreOffice Module xmloff (master) 1
XMLSymbolTypePropertyHdl.cxx
Go to the documentation of this file.
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
21#include <xmloff/xmluconv.hxx>
22#include <rtl/ustrbuf.hxx>
23
24using namespace ::xmloff::token;
25
26namespace
27{
28struct SvXMLSignedEnumMapEntry
29{
31 sal_Int32 nValue;
32};
33
34const SvXMLSignedEnumMapEntry aXMLChartSymbolTypeEnumMap[] =
35{
36 { XML_NONE, -3 },
37 { XML_AUTOMATIC, -2 },
38 { XML_IMAGE, -1 },
40};
41
42const SvXMLSignedEnumMapEntry aXMLChartSymbolNameMap[] =
43{
44 { XML_GRADIENTSTYLE_SQUARE, 0 }, // "square"
45 { XML_DIAMOND, 1 },
46 { XML_ARROW_DOWN, 2 },
47 { XML_ARROW_UP, 3 },
48 { XML_ARROW_RIGHT, 4 },
49 { XML_ARROW_LEFT, 5 },
50 { XML_BOW_TIE, 6 },
51 { XML_HOURGLASS, 7 },
52 { XML_CIRCLE, 8 },
53 { XML_STAR, 9 },
54 { XML_X, 10 },
55 { XML_PLUS, 11 },
56 { XML_ASTERISK, 12 },
57 { XML_HORIZONTAL_BAR, 13 },
58 { XML_VERTICAL_BAR, 14 },
60};
61
62bool lcl_convertEnum(
63 OUStringBuffer & rBuffer,
64 sal_Int32 nValue,
65 const SvXMLSignedEnumMapEntry *pMap )
66{
68
69 while( pMap->eToken != XML_TOKEN_INVALID )
70 {
71 if( pMap->nValue == nValue )
72 {
73 eTok = pMap->eToken;
74 break;
75 }
76 pMap++;
77 }
78
79 if( eTok != XML_TOKEN_INVALID )
80 rBuffer.append( GetXMLToken(eTok) );
81
82 return (eTok != XML_TOKEN_INVALID);
83}
84
85bool lcl_convertEnum(
86 sal_Int32 & rEnum,
87 std::u16string_view rValue,
88 const SvXMLSignedEnumMapEntry *pMap )
89{
90 while( pMap->eToken != XML_TOKEN_INVALID )
91 {
92 if( IsXMLToken( rValue, pMap->eToken ) )
93 {
94 rEnum = pMap->nValue;
95 return true;
96 }
97 pMap++;
98 }
99 return false;
100}
101
102} // anonymous namespace
103
104using namespace com::sun::star;
105
107 : m_bIsNamedSymbol( bIsNamedSymbol )
108{}
109
111{}
112
113bool XMLSymbolTypePropertyHdl::importXML( const OUString& rStrImpValue,
114 uno::Any& rValue, const SvXMLUnitConverter& /*rUnitConverter*/ ) const
115{
116 bool bResult = false;
117
118 if( m_bIsNamedSymbol )
119 {
120 sal_Int32 nValue = -3; // NONE
121 bResult = lcl_convertEnum( nValue, rStrImpValue, aXMLChartSymbolNameMap );
122 rValue <<= nValue;
123 }
124 else
125 {
126 sal_Int32 nValue = -3; // NONE
127 bResult = lcl_convertEnum( nValue, rStrImpValue, aXMLChartSymbolTypeEnumMap );
128 rValue <<= nValue;
129 }
130
131 return bResult;
132}
133
134bool XMLSymbolTypePropertyHdl::exportXML( OUString& rStrExpValue,
135 const uno::Any& rValue, const SvXMLUnitConverter& /*rUnitConverter*/ ) const
136{
137 bool bResult = false;
138
139 sal_Int32 nType = -3; // NONE
140 rValue >>= nType;
141
142 if( m_bIsNamedSymbol )
143 {
144 OUStringBuffer aBuf;
145 bResult = lcl_convertEnum( aBuf, nType, aXMLChartSymbolNameMap );
146 rStrExpValue = aBuf.makeStringAndClear();
147 }
148 else
149 {
150 if( nType < 0 )
151 {
152 OUStringBuffer aBuf;
153 bResult = lcl_convertEnum( aBuf, nType, aXMLChartSymbolTypeEnumMap );
154 rStrExpValue = aBuf.makeStringAndClear();
155 }
156 else
157 {
158 bResult = true;
159 rStrExpValue = GetXMLToken( XML_NAMED_SYMBOL );
160 }
161 }
162
163 return bResult;
164}
165
166/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
the SvXMLTypeConverter converts values of various types from their internal representation to the tex...
Definition: xmluconv.hxx:83
XMLSymbolTypePropertyHdl(bool bIsNamedSymbol)
virtual bool exportXML(OUString &rStrExpValue, const css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Exports the given value according to the XML-data-type corresponding to the derived class.
virtual bool importXML(const OUString &rStrImpValue, css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Imports the given value according to the XML-data-type corresponding to the derived class.
virtual ~XMLSymbolTypePropertyHdl() override
sal_Int16 nValue
aBuf
Handling of tokens in XML:
XMLTokenEnum
The enumeration of all XML tokens.
Definition: xmltoken.hxx:50
@ XML_GRADIENTSTYLE_SQUARE
Definition: xmltoken.hxx:988
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3597
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
Definition: xmltoken.cxx:3541
QPRO_FUNC_TYPE nType
XMLTokenEnum eToken
Definition: xmltoken.cxx:40