bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / text / XMLLineNumberingImportContext.cxx
blob125e6606c5c59d3f174b8b59f565a008a39fd297
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 "XMLLineNumberingImportContext.hxx"
21 #include "XMLLineNumberingSeparatorImportContext.hxx"
22 #include <com/sun/star/beans/XPropertySet.hpp>
23 #include <com/sun/star/text/XLineNumberingProperties.hpp>
24 #include <com/sun/star/style/LineNumberPosition.hpp>
25 #include <com/sun/star/style/NumberingType.hpp>
26 #include <sax/tools/converter.hxx>
27 #include <xmloff/xmlimp.hxx>
28 #include <xmloff/xmluconv.hxx>
29 #include <xmloff/xmlnmspe.hxx>
30 #include <xmloff/nmspmap.hxx>
31 #include <xmloff/xmltoken.hxx>
32 #include <xmloff/xmlnumi.hxx>
35 using namespace ::com::sun::star;
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::style;
38 using namespace ::xmloff::token;
40 using ::com::sun::star::beans::XPropertySet;
41 using ::com::sun::star::xml::sax::XAttributeList;
42 using ::com::sun::star::text::XLineNumberingProperties;
44 TYPEINIT1( XMLLineNumberingImportContext, SvXMLStyleContext );
47 XMLLineNumberingImportContext::XMLLineNumberingImportContext(
48 SvXMLImport& rImport,
49 sal_uInt16 nPrfx,
50 const OUString& rLocalName,
51 const Reference<XAttributeList> & xAttrList)
52 : SvXMLStyleContext(rImport, nPrfx, rLocalName, xAttrList, XML_STYLE_FAMILY_TEXT_LINENUMBERINGCONFIG)
53 , sCharStyleName("CharStyleName")
54 , sCountEmptyLines("CountEmptyLines")
55 , sCountLinesInFrames("CountLinesInFrames")
56 , sDistance("Distance")
57 , sInterval("Interval")
58 , sSeparatorText("SeparatorText")
59 , sNumberPosition("NumberPosition")
60 , sNumberingType("NumberingType")
61 , sIsOn("IsOn")
62 , sRestartAtEachPage("RestartAtEachPage")
63 , sSeparatorInterval("SeparatorInterval")
64 , sNumFormat(GetXMLToken(XML_1))
65 , sNumLetterSync(GetXMLToken(XML_FALSE))
66 , nOffset(-1)
67 , nNumberPosition(style::LineNumberPosition::LEFT)
68 , nIncrement(-1)
69 , nSeparatorIncrement(-1)
70 , bNumberLines(true)
71 , bCountEmptyLines(true)
72 , bCountInFloatingFrames(false)
73 , bRestartNumbering(false)
77 XMLLineNumberingImportContext::~XMLLineNumberingImportContext()
81 void XMLLineNumberingImportContext::StartElement(
82 const Reference<XAttributeList> & xAttrList)
84 static const SvXMLTokenMapEntry aLineNumberingTokenMap[] =
86 { XML_NAMESPACE_TEXT, XML_STYLE_NAME, XML_TOK_LINENUMBERING_STYLE_NAME },
87 { XML_NAMESPACE_TEXT, XML_NUMBER_LINES,
88 XML_TOK_LINENUMBERING_NUMBER_LINES },
89 { XML_NAMESPACE_TEXT, XML_COUNT_EMPTY_LINES,
90 XML_TOK_LINENUMBERING_COUNT_EMPTY_LINES },
91 { XML_NAMESPACE_TEXT, XML_COUNT_IN_TEXT_BOXES,
92 XML_TOK_LINENUMBERING_COUNT_IN_TEXT_BOXES },
93 { XML_NAMESPACE_TEXT, XML_RESTART_ON_PAGE,
94 XML_TOK_LINENUMBERING_RESTART_NUMBERING },
95 { XML_NAMESPACE_TEXT, XML_OFFSET, XML_TOK_LINENUMBERING_OFFSET },
96 { XML_NAMESPACE_STYLE, XML_NUM_FORMAT, XML_TOK_LINENUMBERING_NUM_FORMAT },
97 { XML_NAMESPACE_STYLE, XML_NUM_LETTER_SYNC,
98 XML_TOK_LINENUMBERING_NUM_LETTER_SYNC },
99 { XML_NAMESPACE_TEXT, XML_NUMBER_POSITION,
100 XML_TOK_LINENUMBERING_NUMBER_POSITION },
101 { XML_NAMESPACE_TEXT, XML_INCREMENT, XML_TOK_LINENUMBERING_INCREMENT },
102 // { XML_NAMESPACE_TEXT, XML_LINENUMBERING_CONFIGURATION,
103 // XML_TOK_LINENUMBERING_LINENUMBERING_CONFIGURATION },
104 // { XML_NAMESPACE_TEXT, XML_INCREMENT, XML_TOK_LINENUMBERING_INCREMENT },
105 // { XML_NAMESPACE_TEXT, XML_LINENUMBERING_SEPARATOR,
106 // XML_TOK_LINENUMBERING_LINENUMBERING_SEPARATOR },
108 XML_TOKEN_MAP_END
111 SvXMLTokenMap aTokenMap(aLineNumberingTokenMap);
113 // process attributes
114 sal_Int16 nLength = xAttrList->getLength();
115 for(sal_Int16 i=0; i<nLength; i++)
117 OUString sLocalName;
118 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
119 GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName );
121 ProcessAttribute(
122 (enum LineNumberingToken)aTokenMap.Get(nPrefix, sLocalName),
123 xAttrList->getValueByIndex(i));
127 void XMLLineNumberingImportContext::ProcessAttribute(
128 enum LineNumberingToken eToken,
129 const OUString& sValue)
131 bool bTmp(false);
132 sal_Int32 nTmp;
134 switch (eToken)
136 case XML_TOK_LINENUMBERING_STYLE_NAME:
137 sStyleName = sValue;
138 break;
140 case XML_TOK_LINENUMBERING_NUMBER_LINES:
141 if (::sax::Converter::convertBool(bTmp, sValue))
143 bNumberLines = bTmp;
145 break;
147 case XML_TOK_LINENUMBERING_COUNT_EMPTY_LINES:
148 if (::sax::Converter::convertBool(bTmp, sValue))
150 bCountEmptyLines = bTmp;
152 break;
154 case XML_TOK_LINENUMBERING_COUNT_IN_TEXT_BOXES:
155 if (::sax::Converter::convertBool(bTmp, sValue))
157 bCountInFloatingFrames = bTmp;
159 break;
161 case XML_TOK_LINENUMBERING_RESTART_NUMBERING:
162 if (::sax::Converter::convertBool(bTmp, sValue))
164 bRestartNumbering = bTmp;
166 break;
168 case XML_TOK_LINENUMBERING_OFFSET:
169 if (GetImport().GetMM100UnitConverter().
170 convertMeasureToCore(nTmp, sValue))
172 nOffset = nTmp;
174 break;
176 case XML_TOK_LINENUMBERING_NUM_FORMAT:
177 sNumFormat = sValue;
178 break;
180 case XML_TOK_LINENUMBERING_NUM_LETTER_SYNC:
181 sNumLetterSync = sValue;
182 break;
184 case XML_TOK_LINENUMBERING_NUMBER_POSITION:
186 static const SvXMLEnumMapEntry aLineNumberPositionMap[] =
188 { XML_LEFT, style::LineNumberPosition::LEFT },
189 { XML_RIGHT, style::LineNumberPosition::RIGHT },
190 { XML_INSIDE, style::LineNumberPosition::INSIDE },
191 { XML_OUTSIDE, style::LineNumberPosition::OUTSIDE },
192 { XML_TOKEN_INVALID, 0 }
195 sal_uInt16 nTmp16;
196 if (SvXMLUnitConverter::convertEnum(nTmp16, sValue,
197 aLineNumberPositionMap))
199 nNumberPosition = nTmp16;
201 break;
204 case XML_TOK_LINENUMBERING_INCREMENT:
205 if (::sax::Converter::convertNumber(nTmp, sValue, 0))
207 nIncrement = (sal_Int16)nTmp;
209 break;
213 void XMLLineNumberingImportContext::CreateAndInsert(bool)
215 // insert and block mode is handled in insertStyleFamily
217 // we'll try to get the LineNumberingProperties
218 Reference<XLineNumberingProperties> xSupplier(GetImport().GetModel(),
219 UNO_QUERY);
220 if (xSupplier.is())
222 Reference<XPropertySet> xLineNumbering =
223 xSupplier->getLineNumberingProperties();
225 if (xLineNumbering.is())
227 Any aAny;
229 // set style name (if it exists)
230 if ( GetImport().GetStyles()->FindStyleChildContext(
231 XML_STYLE_FAMILY_TEXT_TEXT, sStyleName ) != NULL )
233 aAny <<= GetImport().GetStyleDisplayName(
234 XML_STYLE_FAMILY_TEXT_TEXT, sStyleName );
235 xLineNumbering->setPropertyValue(sCharStyleName, aAny);
238 aAny <<= sSeparator;
239 xLineNumbering->setPropertyValue(sSeparatorText, aAny);
241 aAny <<= nOffset;
242 xLineNumbering->setPropertyValue(sDistance, aAny);
244 aAny <<= nNumberPosition;
245 xLineNumbering->setPropertyValue(sNumberPosition, aAny);
247 if (nIncrement >= 0)
249 aAny <<= nIncrement;
250 xLineNumbering->setPropertyValue(sInterval, aAny);
253 if (nSeparatorIncrement >= 0)
255 aAny <<= nSeparatorIncrement;
256 xLineNumbering->setPropertyValue(sSeparatorInterval, aAny);
259 aAny.setValue(&bNumberLines, cppu::UnoType<bool>::get());
260 xLineNumbering->setPropertyValue(sIsOn, aAny);
262 aAny.setValue(&bCountEmptyLines, cppu::UnoType<bool>::get());
263 xLineNumbering->setPropertyValue(sCountEmptyLines, aAny);
265 aAny.setValue(&bCountInFloatingFrames, cppu::UnoType<bool>::get());
266 xLineNumbering->setPropertyValue(sCountLinesInFrames, aAny);
268 aAny.setValue(&bRestartNumbering, cppu::UnoType<bool>::get());
269 xLineNumbering->setPropertyValue(sRestartAtEachPage, aAny);
271 sal_Int16 nNumType = NumberingType::ARABIC;
272 GetImport().GetMM100UnitConverter().convertNumFormat( nNumType,
273 sNumFormat,
274 sNumLetterSync );
275 aAny <<= nNumType;
276 xLineNumbering->setPropertyValue(sNumberingType, aAny);
281 SvXMLImportContext* XMLLineNumberingImportContext::CreateChildContext(
282 sal_uInt16 nPrefix,
283 const OUString& rLocalName,
284 const Reference<XAttributeList> & xAttrList )
286 if ( (nPrefix == XML_NAMESPACE_TEXT) &&
287 IsXMLToken(rLocalName, XML_LINENUMBERING_SEPARATOR) )
289 return new XMLLineNumberingSeparatorImportContext(GetImport(),
290 nPrefix, rLocalName,
291 *this);
293 else
295 // unknown element: default context
296 return SvXMLImportContext::CreateChildContext(nPrefix, rLocalName,
297 xAttrList);
301 void XMLLineNumberingImportContext::SetSeparatorText(
302 const OUString& sText)
304 sSeparator = sText;
307 void XMLLineNumberingImportContext::SetSeparatorIncrement(
308 sal_Int16 nIncr)
310 nSeparatorIncrement = nIncr;
313 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */