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 338 : 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 338 : , sNumFormat(GetXMLToken(XML_1))
65 338 : , 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 1014 : , bRestartNumbering(false)
74 : {
75 338 : }
76 :
77 676 : XMLLineNumberingImportContext::~XMLLineNumberingImportContext()
78 : {
79 676 : }
80 :
81 338 : 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 338 : SvXMLTokenMap aTokenMap(aLineNumberingTokenMap);
112 :
113 : // process attributes
114 338 : sal_Int16 nLength = xAttrList->getLength();
115 2029 : for(sal_Int16 i=0; i<nLength; i++)
116 : {
117 1691 : OUString sLocalName;
118 1691 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
119 3382 : GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName );
120 :
121 : ProcessAttribute(
122 1691 : (enum LineNumberingToken)aTokenMap.Get(nPrefix, sLocalName),
123 3382 : xAttrList->getValueByIndex(i));
124 2029 : }
125 338 : }
126 :
127 1691 : void XMLLineNumberingImportContext::ProcessAttribute(
128 : enum LineNumberingToken eToken,
129 : const OUString& sValue)
130 : {
131 1691 : bool bTmp(false);
132 : sal_Int32 nTmp;
133 :
134 1691 : 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 337 : if (::sax::Converter::convertBool(bTmp, sValue))
142 : {
143 337 : bNumberLines = bTmp;
144 : }
145 337 : 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 338 : if (GetImport().GetMM100UnitConverter().
170 : convertMeasureToCore(nTmp, sValue))
171 : {
172 338 : nOffset = nTmp;
173 : }
174 338 : break;
175 :
176 : case XML_TOK_LINENUMBERING_NUM_FORMAT:
177 338 : sNumFormat = sValue;
178 338 : 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 338 : if (SvXMLUnitConverter::convertEnum(nTmp16, sValue,
197 : aLineNumberPositionMap))
198 : {
199 338 : nNumberPosition = nTmp16;
200 : }
201 338 : break;
202 : }
203 :
204 : case XML_TOK_LINENUMBERING_INCREMENT:
205 338 : if (::sax::Converter::convertNumber(nTmp, sValue, 0))
206 : {
207 338 : nIncrement = (sal_Int16)nTmp;
208 : }
209 338 : break;
210 : }
211 1691 : }
212 :
213 285 : void XMLLineNumberingImportContext::CreateAndInsert(bool)
214 : {
215 : // insert and block mode is handled in insertStyleFamily
216 :
217 : // we'll try to get the LineNumberingProperties
218 285 : Reference<XLineNumberingProperties> xSupplier(GetImport().GetModel(),
219 285 : UNO_QUERY);
220 285 : if (xSupplier.is())
221 : {
222 : Reference<XPropertySet> xLineNumbering =
223 285 : xSupplier->getLineNumberingProperties();
224 :
225 285 : if (xLineNumbering.is())
226 : {
227 285 : Any aAny;
228 :
229 : // set style name (if it exists)
230 570 : if ( GetImport().GetStyles()->FindStyleChildContext(
231 570 : 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 285 : aAny <<= sSeparator;
239 285 : xLineNumbering->setPropertyValue(sSeparatorText, aAny);
240 :
241 285 : aAny <<= nOffset;
242 285 : xLineNumbering->setPropertyValue(sDistance, aAny);
243 :
244 285 : aAny <<= nNumberPosition;
245 285 : xLineNumbering->setPropertyValue(sNumberPosition, aAny);
246 :
247 285 : if (nIncrement >= 0)
248 : {
249 285 : aAny <<= nIncrement;
250 285 : xLineNumbering->setPropertyValue(sInterval, aAny);
251 : }
252 :
253 285 : if (nSeparatorIncrement >= 0)
254 : {
255 0 : aAny <<= nSeparatorIncrement;
256 0 : xLineNumbering->setPropertyValue(sSeparatorInterval, aAny);
257 : }
258 :
259 285 : aAny.setValue(&bNumberLines, cppu::UnoType<bool>::get());
260 285 : xLineNumbering->setPropertyValue(sIsOn, aAny);
261 :
262 285 : aAny.setValue(&bCountEmptyLines, cppu::UnoType<bool>::get());
263 285 : xLineNumbering->setPropertyValue(sCountEmptyLines, aAny);
264 :
265 285 : aAny.setValue(&bCountInFloatingFrames, cppu::UnoType<bool>::get());
266 285 : xLineNumbering->setPropertyValue(sCountLinesInFrames, aAny);
267 :
268 285 : aAny.setValue(&bRestartNumbering, cppu::UnoType<bool>::get());
269 285 : xLineNumbering->setPropertyValue(sRestartAtEachPage, aAny);
270 :
271 285 : sal_Int16 nNumType = NumberingType::ARABIC;
272 285 : GetImport().GetMM100UnitConverter().convertNumFormat( nNumType,
273 : sNumFormat,
274 570 : sNumLetterSync );
275 285 : aAny <<= nNumType;
276 285 : xLineNumbering->setPropertyValue(sNumberingType, aAny);
277 285 : }
278 285 : }
279 285 : }
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: */
|