1*63bba73cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*63bba73cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*63bba73cSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*63bba73cSAndrew Rist * distributed with this work for additional information
6*63bba73cSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*63bba73cSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*63bba73cSAndrew Rist * "License"); you may not use this file except in compliance
9*63bba73cSAndrew Rist * with the License. You may obtain a copy of the License at
10*63bba73cSAndrew Rist *
11*63bba73cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*63bba73cSAndrew Rist *
13*63bba73cSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*63bba73cSAndrew Rist * software distributed under the License is distributed on an
15*63bba73cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*63bba73cSAndrew Rist * KIND, either express or implied. See the License for the
17*63bba73cSAndrew Rist * specific language governing permissions and limitations
18*63bba73cSAndrew Rist * under the License.
19*63bba73cSAndrew Rist *
20*63bba73cSAndrew Rist *************************************************************/
21*63bba73cSAndrew Rist
22*63bba73cSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
26cdf0e10cSrcweir #include "XMLLineNumberingImportContext.hxx"
27cdf0e10cSrcweir #include "XMLLineNumberingSeparatorImportContext.hxx"
28cdf0e10cSrcweir #include "com/sun/star/beans/XPropertySet.hpp"
29cdf0e10cSrcweir #include "com/sun/star/text/XLineNumberingProperties.hpp"
30cdf0e10cSrcweir #include <com/sun/star/style/LineNumberPosition.hpp>
31cdf0e10cSrcweir #include <com/sun/star/style/NumberingType.hpp>
32cdf0e10cSrcweir #include <xmloff/xmlimp.hxx>
33cdf0e10cSrcweir #include <xmloff/xmluconv.hxx>
34cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
35cdf0e10cSrcweir #include <xmloff/nmspmap.hxx>
36cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
37cdf0e10cSrcweir #include <xmloff/xmlnumi.hxx>
38cdf0e10cSrcweir
39cdf0e10cSrcweir
40cdf0e10cSrcweir using namespace ::com::sun::star;
41cdf0e10cSrcweir using namespace ::com::sun::star::uno;
42cdf0e10cSrcweir using namespace ::com::sun::star::style;
43cdf0e10cSrcweir using namespace ::xmloff::token;
44cdf0e10cSrcweir
45cdf0e10cSrcweir using ::com::sun::star::beans::XPropertySet;
46cdf0e10cSrcweir using ::com::sun::star::xml::sax::XAttributeList;
47cdf0e10cSrcweir using ::com::sun::star::text::XLineNumberingProperties;
48cdf0e10cSrcweir using ::rtl::OUString;
49cdf0e10cSrcweir
50cdf0e10cSrcweir TYPEINIT1( XMLLineNumberingImportContext, SvXMLStyleContext );
51cdf0e10cSrcweir
52cdf0e10cSrcweir
XMLLineNumberingImportContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLocalName,const Reference<XAttributeList> & xAttrList)53cdf0e10cSrcweir XMLLineNumberingImportContext::XMLLineNumberingImportContext(
54cdf0e10cSrcweir SvXMLImport& rImport,
55cdf0e10cSrcweir sal_uInt16 nPrfx,
56cdf0e10cSrcweir const OUString& rLocalName,
57cdf0e10cSrcweir const Reference<XAttributeList> & xAttrList)
58cdf0e10cSrcweir : SvXMLStyleContext(rImport, nPrfx, rLocalName, xAttrList, XML_STYLE_FAMILY_TEXT_LINENUMBERINGCONFIG)
59cdf0e10cSrcweir , sCharStyleName(RTL_CONSTASCII_USTRINGPARAM("CharStyleName"))
60cdf0e10cSrcweir , sCountEmptyLines(RTL_CONSTASCII_USTRINGPARAM("CountEmptyLines"))
61cdf0e10cSrcweir , sCountLinesInFrames(RTL_CONSTASCII_USTRINGPARAM("CountLinesInFrames"))
62cdf0e10cSrcweir , sDistance(RTL_CONSTASCII_USTRINGPARAM("Distance"))
63cdf0e10cSrcweir , sInterval(RTL_CONSTASCII_USTRINGPARAM("Interval"))
64cdf0e10cSrcweir , sSeparatorText(RTL_CONSTASCII_USTRINGPARAM("SeparatorText"))
65cdf0e10cSrcweir , sNumberPosition(RTL_CONSTASCII_USTRINGPARAM("NumberPosition"))
66cdf0e10cSrcweir , sNumberingType(RTL_CONSTASCII_USTRINGPARAM("NumberingType"))
67cdf0e10cSrcweir , sIsOn(RTL_CONSTASCII_USTRINGPARAM("IsOn"))
68cdf0e10cSrcweir , sRestartAtEachPage(RTL_CONSTASCII_USTRINGPARAM("RestartAtEachPage"))
69cdf0e10cSrcweir , sSeparatorInterval(RTL_CONSTASCII_USTRINGPARAM("SeparatorInterval"))
70cdf0e10cSrcweir , sNumFormat(GetXMLToken(XML_1))
71cdf0e10cSrcweir , sNumLetterSync(GetXMLToken(XML_FALSE))
72cdf0e10cSrcweir , nOffset(-1)
73cdf0e10cSrcweir , nNumberPosition(style::LineNumberPosition::LEFT)
74cdf0e10cSrcweir , nIncrement(-1)
75cdf0e10cSrcweir , nSeparatorIncrement(-1)
76cdf0e10cSrcweir , bNumberLines(sal_True)
77cdf0e10cSrcweir , bCountEmptyLines(sal_True)
78cdf0e10cSrcweir , bCountInFloatingFrames(sal_False)
79cdf0e10cSrcweir , bRestartNumbering(sal_False)
80cdf0e10cSrcweir {
81cdf0e10cSrcweir }
82cdf0e10cSrcweir
~XMLLineNumberingImportContext()83cdf0e10cSrcweir XMLLineNumberingImportContext::~XMLLineNumberingImportContext()
84cdf0e10cSrcweir {
85cdf0e10cSrcweir }
86cdf0e10cSrcweir
StartElement(const Reference<XAttributeList> & xAttrList)87cdf0e10cSrcweir void XMLLineNumberingImportContext::StartElement(
88cdf0e10cSrcweir const Reference<XAttributeList> & xAttrList)
89cdf0e10cSrcweir {
90cdf0e10cSrcweir static SvXMLTokenMapEntry aLineNumberingTokenMap[] =
91cdf0e10cSrcweir {
92cdf0e10cSrcweir { XML_NAMESPACE_TEXT, XML_STYLE_NAME, XML_TOK_LINENUMBERING_STYLE_NAME },
93cdf0e10cSrcweir { XML_NAMESPACE_TEXT, XML_NUMBER_LINES,
94cdf0e10cSrcweir XML_TOK_LINENUMBERING_NUMBER_LINES },
95cdf0e10cSrcweir { XML_NAMESPACE_TEXT, XML_COUNT_EMPTY_LINES,
96cdf0e10cSrcweir XML_TOK_LINENUMBERING_COUNT_EMPTY_LINES },
97cdf0e10cSrcweir { XML_NAMESPACE_TEXT, XML_COUNT_IN_TEXT_BOXES,
98cdf0e10cSrcweir XML_TOK_LINENUMBERING_COUNT_IN_TEXT_BOXES },
99cdf0e10cSrcweir { XML_NAMESPACE_TEXT, XML_RESTART_ON_PAGE,
100cdf0e10cSrcweir XML_TOK_LINENUMBERING_RESTART_NUMBERING },
101cdf0e10cSrcweir { XML_NAMESPACE_TEXT, XML_OFFSET, XML_TOK_LINENUMBERING_OFFSET },
102cdf0e10cSrcweir { XML_NAMESPACE_STYLE, XML_NUM_FORMAT, XML_TOK_LINENUMBERING_NUM_FORMAT },
103cdf0e10cSrcweir { XML_NAMESPACE_STYLE, XML_NUM_LETTER_SYNC,
104cdf0e10cSrcweir XML_TOK_LINENUMBERING_NUM_LETTER_SYNC },
105cdf0e10cSrcweir { XML_NAMESPACE_TEXT, XML_NUMBER_POSITION,
106cdf0e10cSrcweir XML_TOK_LINENUMBERING_NUMBER_POSITION },
107cdf0e10cSrcweir { XML_NAMESPACE_TEXT, XML_INCREMENT, XML_TOK_LINENUMBERING_INCREMENT },
108cdf0e10cSrcweir // { XML_NAMESPACE_TEXT, XML_LINENUMBERING_CONFIGURATION,
109cdf0e10cSrcweir // XML_TOK_LINENUMBERING_LINENUMBERING_CONFIGURATION },
110cdf0e10cSrcweir // { XML_NAMESPACE_TEXT, XML_INCREMENT, XML_TOK_LINENUMBERING_INCREMENT },
111cdf0e10cSrcweir // { XML_NAMESPACE_TEXT, XML_LINENUMBERING_SEPARATOR,
112cdf0e10cSrcweir // XML_TOK_LINENUMBERING_LINENUMBERING_SEPARATOR },
113cdf0e10cSrcweir
114cdf0e10cSrcweir XML_TOKEN_MAP_END
115cdf0e10cSrcweir };
116cdf0e10cSrcweir
117cdf0e10cSrcweir SvXMLTokenMap aTokenMap(aLineNumberingTokenMap);
118cdf0e10cSrcweir
119cdf0e10cSrcweir // process attributes
120cdf0e10cSrcweir sal_Int16 nLength = xAttrList->getLength();
121cdf0e10cSrcweir for(sal_Int16 i=0; i<nLength; i++)
122cdf0e10cSrcweir {
123cdf0e10cSrcweir OUString sLocalName;
124cdf0e10cSrcweir sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
125cdf0e10cSrcweir GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName );
126cdf0e10cSrcweir
127cdf0e10cSrcweir ProcessAttribute(
128cdf0e10cSrcweir (enum LineNumberingToken)aTokenMap.Get(nPrefix, sLocalName),
129cdf0e10cSrcweir xAttrList->getValueByIndex(i));
130cdf0e10cSrcweir }
131cdf0e10cSrcweir }
132cdf0e10cSrcweir
ProcessAttribute(enum LineNumberingToken eToken,OUString sValue)133cdf0e10cSrcweir void XMLLineNumberingImportContext::ProcessAttribute(
134cdf0e10cSrcweir enum LineNumberingToken eToken,
135cdf0e10cSrcweir OUString sValue)
136cdf0e10cSrcweir {
137cdf0e10cSrcweir sal_Bool bTmp;
138cdf0e10cSrcweir sal_Int32 nTmp;
139cdf0e10cSrcweir
140cdf0e10cSrcweir switch (eToken)
141cdf0e10cSrcweir {
142cdf0e10cSrcweir case XML_TOK_LINENUMBERING_STYLE_NAME:
143cdf0e10cSrcweir sStyleName = sValue;
144cdf0e10cSrcweir break;
145cdf0e10cSrcweir
146cdf0e10cSrcweir case XML_TOK_LINENUMBERING_NUMBER_LINES:
147cdf0e10cSrcweir if (SvXMLUnitConverter::convertBool(bTmp, sValue))
148cdf0e10cSrcweir {
149cdf0e10cSrcweir bNumberLines = bTmp;
150cdf0e10cSrcweir }
151cdf0e10cSrcweir break;
152cdf0e10cSrcweir
153cdf0e10cSrcweir case XML_TOK_LINENUMBERING_COUNT_EMPTY_LINES:
154cdf0e10cSrcweir if (SvXMLUnitConverter::convertBool(bTmp, sValue))
155cdf0e10cSrcweir {
156cdf0e10cSrcweir bCountEmptyLines = bTmp;
157cdf0e10cSrcweir }
158cdf0e10cSrcweir break;
159cdf0e10cSrcweir
160cdf0e10cSrcweir case XML_TOK_LINENUMBERING_COUNT_IN_TEXT_BOXES:
161cdf0e10cSrcweir if (SvXMLUnitConverter::convertBool(bTmp, sValue))
162cdf0e10cSrcweir {
163cdf0e10cSrcweir bCountInFloatingFrames = bTmp;
164cdf0e10cSrcweir }
165cdf0e10cSrcweir break;
166cdf0e10cSrcweir
167cdf0e10cSrcweir case XML_TOK_LINENUMBERING_RESTART_NUMBERING:
168cdf0e10cSrcweir if (SvXMLUnitConverter::convertBool(bTmp, sValue))
169cdf0e10cSrcweir {
170cdf0e10cSrcweir bRestartNumbering = bTmp;
171cdf0e10cSrcweir }
172cdf0e10cSrcweir break;
173cdf0e10cSrcweir
174cdf0e10cSrcweir case XML_TOK_LINENUMBERING_OFFSET:
175cdf0e10cSrcweir if (GetImport().GetMM100UnitConverter().
176cdf0e10cSrcweir convertMeasure(nTmp, sValue))
177cdf0e10cSrcweir {
178cdf0e10cSrcweir nOffset = nTmp;
179cdf0e10cSrcweir }
180cdf0e10cSrcweir break;
181cdf0e10cSrcweir
182cdf0e10cSrcweir case XML_TOK_LINENUMBERING_NUM_FORMAT:
183cdf0e10cSrcweir sNumFormat = sValue;
184cdf0e10cSrcweir break;
185cdf0e10cSrcweir
186cdf0e10cSrcweir case XML_TOK_LINENUMBERING_NUM_LETTER_SYNC:
187cdf0e10cSrcweir sNumLetterSync = sValue;
188cdf0e10cSrcweir break;
189cdf0e10cSrcweir
190cdf0e10cSrcweir case XML_TOK_LINENUMBERING_NUMBER_POSITION:
191cdf0e10cSrcweir {
192cdf0e10cSrcweir static const SvXMLEnumMapEntry aLineNumberPositionMap[] =
193cdf0e10cSrcweir {
194cdf0e10cSrcweir { XML_LEFT, style::LineNumberPosition::LEFT },
195cdf0e10cSrcweir { XML_RIGHT, style::LineNumberPosition::RIGHT },
196cdf0e10cSrcweir { XML_INSIDE, style::LineNumberPosition::INSIDE },
197cdf0e10cSrcweir { XML_OUTSIDE, style::LineNumberPosition::OUTSIDE },
198cdf0e10cSrcweir { XML_TOKEN_INVALID, 0 }
199cdf0e10cSrcweir };
200cdf0e10cSrcweir
201cdf0e10cSrcweir sal_uInt16 nTmp16;
202cdf0e10cSrcweir if (SvXMLUnitConverter::convertEnum(nTmp16, sValue,
203cdf0e10cSrcweir aLineNumberPositionMap))
204cdf0e10cSrcweir {
205cdf0e10cSrcweir nNumberPosition = nTmp16;
206cdf0e10cSrcweir }
207cdf0e10cSrcweir break;
208cdf0e10cSrcweir }
209cdf0e10cSrcweir
210cdf0e10cSrcweir case XML_TOK_LINENUMBERING_INCREMENT:
211cdf0e10cSrcweir if (SvXMLUnitConverter::convertNumber(nTmp, sValue, 0))
212cdf0e10cSrcweir {
213cdf0e10cSrcweir nIncrement = (sal_Int16)nTmp;
214cdf0e10cSrcweir }
215cdf0e10cSrcweir break;
216cdf0e10cSrcweir }
217cdf0e10cSrcweir }
218cdf0e10cSrcweir
CreateAndInsert(sal_Bool)219cdf0e10cSrcweir void XMLLineNumberingImportContext::CreateAndInsert(sal_Bool)
220cdf0e10cSrcweir {
221cdf0e10cSrcweir // insert and block mode is handled in insertStyleFamily
222cdf0e10cSrcweir
223cdf0e10cSrcweir // we'll try to get the LineNumberingProperties
224cdf0e10cSrcweir Reference<XLineNumberingProperties> xSupplier(GetImport().GetModel(),
225cdf0e10cSrcweir UNO_QUERY);
226cdf0e10cSrcweir if (xSupplier.is())
227cdf0e10cSrcweir {
228cdf0e10cSrcweir Reference<XPropertySet> xLineNumbering =
229cdf0e10cSrcweir xSupplier->getLineNumberingProperties();
230cdf0e10cSrcweir
231cdf0e10cSrcweir if (xLineNumbering.is())
232cdf0e10cSrcweir {
233cdf0e10cSrcweir Any aAny;
234cdf0e10cSrcweir
235cdf0e10cSrcweir // set style name (if it exists)
236cdf0e10cSrcweir if ( GetImport().GetStyles()->FindStyleChildContext(
237cdf0e10cSrcweir XML_STYLE_FAMILY_TEXT_TEXT, sStyleName ) != NULL )
238cdf0e10cSrcweir {
239cdf0e10cSrcweir aAny <<= GetImport().GetStyleDisplayName(
240cdf0e10cSrcweir XML_STYLE_FAMILY_TEXT_TEXT, sStyleName );
241cdf0e10cSrcweir xLineNumbering->setPropertyValue(sCharStyleName, aAny);
242cdf0e10cSrcweir }
243cdf0e10cSrcweir
244cdf0e10cSrcweir aAny <<= sSeparator;
245cdf0e10cSrcweir xLineNumbering->setPropertyValue(sSeparatorText, aAny);
246cdf0e10cSrcweir
247cdf0e10cSrcweir aAny <<= nOffset;
248cdf0e10cSrcweir xLineNumbering->setPropertyValue(sDistance, aAny);
249cdf0e10cSrcweir
250cdf0e10cSrcweir aAny <<= nNumberPosition;
251cdf0e10cSrcweir xLineNumbering->setPropertyValue(sNumberPosition, aAny);
252cdf0e10cSrcweir
253cdf0e10cSrcweir if (nIncrement >= 0)
254cdf0e10cSrcweir {
255cdf0e10cSrcweir aAny <<= nIncrement;
256cdf0e10cSrcweir xLineNumbering->setPropertyValue(sInterval, aAny);
257cdf0e10cSrcweir }
258cdf0e10cSrcweir
259cdf0e10cSrcweir if (nSeparatorIncrement >= 0)
260cdf0e10cSrcweir {
261cdf0e10cSrcweir aAny <<= nSeparatorIncrement;
262cdf0e10cSrcweir xLineNumbering->setPropertyValue(sSeparatorInterval, aAny);
263cdf0e10cSrcweir }
264cdf0e10cSrcweir
265cdf0e10cSrcweir aAny.setValue(&bNumberLines, ::getBooleanCppuType());
266cdf0e10cSrcweir xLineNumbering->setPropertyValue(sIsOn, aAny);
267cdf0e10cSrcweir
268cdf0e10cSrcweir aAny.setValue(&bCountEmptyLines, ::getBooleanCppuType());
269cdf0e10cSrcweir xLineNumbering->setPropertyValue(sCountEmptyLines, aAny);
270cdf0e10cSrcweir
271cdf0e10cSrcweir aAny.setValue(&bCountInFloatingFrames, ::getBooleanCppuType());
272cdf0e10cSrcweir xLineNumbering->setPropertyValue(sCountLinesInFrames, aAny);
273cdf0e10cSrcweir
274cdf0e10cSrcweir aAny.setValue(&bRestartNumbering, ::getBooleanCppuType());
275cdf0e10cSrcweir xLineNumbering->setPropertyValue(sRestartAtEachPage, aAny);
276cdf0e10cSrcweir
277cdf0e10cSrcweir sal_Int16 nNumType = NumberingType::ARABIC;
278cdf0e10cSrcweir GetImport().GetMM100UnitConverter().convertNumFormat( nNumType,
279cdf0e10cSrcweir sNumFormat,
280cdf0e10cSrcweir sNumLetterSync );
281cdf0e10cSrcweir aAny <<= nNumType;
282cdf0e10cSrcweir xLineNumbering->setPropertyValue(sNumberingType, aAny);
283cdf0e10cSrcweir }
284cdf0e10cSrcweir }
285cdf0e10cSrcweir }
286cdf0e10cSrcweir
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const Reference<XAttributeList> & xAttrList)287cdf0e10cSrcweir SvXMLImportContext* XMLLineNumberingImportContext::CreateChildContext(
288cdf0e10cSrcweir sal_uInt16 nPrefix,
289cdf0e10cSrcweir const OUString& rLocalName,
290cdf0e10cSrcweir const Reference<XAttributeList> & xAttrList )
291cdf0e10cSrcweir {
292cdf0e10cSrcweir if ( (nPrefix == XML_NAMESPACE_TEXT) &&
293cdf0e10cSrcweir IsXMLToken(rLocalName, XML_LINENUMBERING_SEPARATOR) )
294cdf0e10cSrcweir {
295cdf0e10cSrcweir return new XMLLineNumberingSeparatorImportContext(GetImport(),
296cdf0e10cSrcweir nPrefix, rLocalName,
297cdf0e10cSrcweir *this);
298cdf0e10cSrcweir }
299cdf0e10cSrcweir else
300cdf0e10cSrcweir {
301cdf0e10cSrcweir // unknown element: default context
302cdf0e10cSrcweir return SvXMLImportContext::CreateChildContext(nPrefix, rLocalName,
303cdf0e10cSrcweir xAttrList);
304cdf0e10cSrcweir }
305cdf0e10cSrcweir }
306cdf0e10cSrcweir
SetSeparatorText(const OUString & sText)307cdf0e10cSrcweir void XMLLineNumberingImportContext::SetSeparatorText(
308cdf0e10cSrcweir const OUString& sText)
309cdf0e10cSrcweir {
310cdf0e10cSrcweir sSeparator = sText;
311cdf0e10cSrcweir }
312cdf0e10cSrcweir
SetSeparatorIncrement(sal_Int16 nIncr)313cdf0e10cSrcweir void XMLLineNumberingImportContext::SetSeparatorIncrement(
314cdf0e10cSrcweir sal_Int16 nIncr)
315cdf0e10cSrcweir {
316cdf0e10cSrcweir nSeparatorIncrement = nIncr;
317cdf0e10cSrcweir }
318cdf0e10cSrcweir
319