Line data Source code
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 :
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>
33 :
34 :
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;
39 :
40 : using ::com::sun::star::beans::XPropertySet;
41 : using ::com::sun::star::xml::sax::XAttributeList;
42 : using ::com::sun::star::text::XLineNumberingProperties;
43 :
44 0 : TYPEINIT1( XMLLineNumberingImportContext, SvXMLStyleContext );
45 :
46 :
47 414 : 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 414 : , sNumFormat(GetXMLToken(XML_1))
65 414 : , 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 1242 : , bRestartNumbering(false)
74 : {
75 414 : }
76 :
77 828 : XMLLineNumberingImportContext::~XMLLineNumberingImportContext()
78 : {
79 828 : }
80 :
81 414 : void XMLLineNumberingImportContext::StartElement(
82 : const Reference<XAttributeList> & xAttrList)
83 : {
84 : static const SvXMLTokenMapEntry aLineNumberingTokenMap[] =
85 : {
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 },
107 :
108 : XML_TOKEN_MAP_END
109 : };
110 :
111 414 : SvXMLTokenMap aTokenMap(aLineNumberingTokenMap);
112 :
113 : // process attributes
114 414 : sal_Int16 nLength = xAttrList->getLength();
115 2486 : for(sal_Int16 i=0; i<nLength; i++)
116 : {
117 2072 : OUString sLocalName;
118 2072 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
119 4144 : GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName );
120 :
121 : ProcessAttribute(
122 2072 : (enum LineNumberingToken)aTokenMap.Get(nPrefix, sLocalName),
123 4144 : xAttrList->getValueByIndex(i));
124 2486 : }
125 414 : }
126 :
127 2072 : void XMLLineNumberingImportContext::ProcessAttribute(
128 : enum LineNumberingToken eToken,
129 : const OUString& sValue)
130 : {
131 2072 : bool bTmp(false);
132 : sal_Int32 nTmp;
133 :
134 2072 : switch (eToken)
135 : {
136 : case XML_TOK_LINENUMBERING_STYLE_NAME:
137 2 : sStyleName = sValue;
138 2 : break;
139 :
140 : case XML_TOK_LINENUMBERING_NUMBER_LINES:
141 414 : if (::sax::Converter::convertBool(bTmp, sValue))
142 : {
143 414 : bNumberLines = bTmp;
144 : }
145 414 : break;
146 :
147 : case XML_TOK_LINENUMBERING_COUNT_EMPTY_LINES:
148 0 : if (::sax::Converter::convertBool(bTmp, sValue))
149 : {
150 0 : bCountEmptyLines = bTmp;
151 : }
152 0 : break;
153 :
154 : case XML_TOK_LINENUMBERING_COUNT_IN_TEXT_BOXES:
155 0 : if (::sax::Converter::convertBool(bTmp, sValue))
156 : {
157 0 : bCountInFloatingFrames = bTmp;
158 : }
159 0 : break;
160 :
161 : case XML_TOK_LINENUMBERING_RESTART_NUMBERING:
162 0 : if (::sax::Converter::convertBool(bTmp, sValue))
163 : {
164 0 : bRestartNumbering = bTmp;
165 : }
166 0 : break;
167 :
168 : case XML_TOK_LINENUMBERING_OFFSET:
169 414 : if (GetImport().GetMM100UnitConverter().
170 : convertMeasureToCore(nTmp, sValue))
171 : {
172 414 : nOffset = nTmp;
173 : }
174 414 : break;
175 :
176 : case XML_TOK_LINENUMBERING_NUM_FORMAT:
177 414 : sNumFormat = sValue;
178 414 : break;
179 :
180 : case XML_TOK_LINENUMBERING_NUM_LETTER_SYNC:
181 0 : sNumLetterSync = sValue;
182 0 : break;
183 :
184 : case XML_TOK_LINENUMBERING_NUMBER_POSITION:
185 : {
186 : static const SvXMLEnumMapEntry aLineNumberPositionMap[] =
187 : {
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 }
193 : };
194 :
195 : sal_uInt16 nTmp16;
196 414 : if (SvXMLUnitConverter::convertEnum(nTmp16, sValue,
197 : aLineNumberPositionMap))
198 : {
199 414 : nNumberPosition = nTmp16;
200 : }
201 414 : break;
202 : }
203 :
204 : case XML_TOK_LINENUMBERING_INCREMENT:
205 414 : if (::sax::Converter::convertNumber(nTmp, sValue, 0))
206 : {
207 414 : nIncrement = (sal_Int16)nTmp;
208 : }
209 414 : break;
210 : }
211 2072 : }
212 :
213 312 : void XMLLineNumberingImportContext::CreateAndInsert(bool)
214 : {
215 : // insert and block mode is handled in insertStyleFamily
216 :
217 : // we'll try to get the LineNumberingProperties
218 312 : Reference<XLineNumberingProperties> xSupplier(GetImport().GetModel(),
219 312 : UNO_QUERY);
220 312 : if (xSupplier.is())
221 : {
222 : Reference<XPropertySet> xLineNumbering =
223 312 : xSupplier->getLineNumberingProperties();
224 :
225 312 : if (xLineNumbering.is())
226 : {
227 312 : Any aAny;
228 :
229 : // set style name (if it exists)
230 624 : if ( GetImport().GetStyles()->FindStyleChildContext(
231 624 : XML_STYLE_FAMILY_TEXT_TEXT, sStyleName ) != NULL )
232 : {
233 4 : aAny <<= GetImport().GetStyleDisplayName(
234 2 : XML_STYLE_FAMILY_TEXT_TEXT, sStyleName );
235 2 : xLineNumbering->setPropertyValue(sCharStyleName, aAny);
236 : }
237 :
238 312 : aAny <<= sSeparator;
239 312 : xLineNumbering->setPropertyValue(sSeparatorText, aAny);
240 :
241 312 : aAny <<= nOffset;
242 312 : xLineNumbering->setPropertyValue(sDistance, aAny);
243 :
244 312 : aAny <<= nNumberPosition;
245 312 : xLineNumbering->setPropertyValue(sNumberPosition, aAny);
246 :
247 312 : if (nIncrement >= 0)
248 : {
249 312 : aAny <<= nIncrement;
250 312 : xLineNumbering->setPropertyValue(sInterval, aAny);
251 : }
252 :
253 312 : if (nSeparatorIncrement >= 0)
254 : {
255 0 : aAny <<= nSeparatorIncrement;
256 0 : xLineNumbering->setPropertyValue(sSeparatorInterval, aAny);
257 : }
258 :
259 312 : aAny.setValue(&bNumberLines, ::getBooleanCppuType());
260 312 : xLineNumbering->setPropertyValue(sIsOn, aAny);
261 :
262 312 : aAny.setValue(&bCountEmptyLines, ::getBooleanCppuType());
263 312 : xLineNumbering->setPropertyValue(sCountEmptyLines, aAny);
264 :
265 312 : aAny.setValue(&bCountInFloatingFrames, ::getBooleanCppuType());
266 312 : xLineNumbering->setPropertyValue(sCountLinesInFrames, aAny);
267 :
268 312 : aAny.setValue(&bRestartNumbering, ::getBooleanCppuType());
269 312 : xLineNumbering->setPropertyValue(sRestartAtEachPage, aAny);
270 :
271 312 : sal_Int16 nNumType = NumberingType::ARABIC;
272 312 : GetImport().GetMM100UnitConverter().convertNumFormat( nNumType,
273 : sNumFormat,
274 624 : sNumLetterSync );
275 312 : aAny <<= nNumType;
276 312 : xLineNumbering->setPropertyValue(sNumberingType, aAny);
277 312 : }
278 312 : }
279 312 : }
280 :
281 0 : SvXMLImportContext* XMLLineNumberingImportContext::CreateChildContext(
282 : sal_uInt16 nPrefix,
283 : const OUString& rLocalName,
284 : const Reference<XAttributeList> & xAttrList )
285 : {
286 0 : if ( (nPrefix == XML_NAMESPACE_TEXT) &&
287 0 : IsXMLToken(rLocalName, XML_LINENUMBERING_SEPARATOR) )
288 : {
289 0 : return new XMLLineNumberingSeparatorImportContext(GetImport(),
290 : nPrefix, rLocalName,
291 0 : *this);
292 : }
293 : else
294 : {
295 : // unknown element: default context
296 : return SvXMLImportContext::CreateChildContext(nPrefix, rLocalName,
297 0 : xAttrList);
298 : }
299 : }
300 :
301 0 : void XMLLineNumberingImportContext::SetSeparatorText(
302 : const OUString& sText)
303 : {
304 0 : sSeparator = sText;
305 0 : }
306 :
307 0 : void XMLLineNumberingImportContext::SetSeparatorIncrement(
308 : sal_Int16 nIncr)
309 : {
310 0 : nSeparatorIncrement = nIncr;
311 0 : }
312 :
313 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|