bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / text / XMLIndexTabStopEntryContext.cxx
blobf1ad3f007fba83b2843bd6e293512cbaa1af05ba
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 .
21 #include "XMLIndexTabStopEntryContext.hxx"
23 #include <sax/tools/converter.hxx>
25 #include "XMLIndexTemplateContext.hxx"
26 #include <xmloff/xmlictxt.hxx>
27 #include <xmloff/xmlimp.hxx>
28 #include <xmloff/txtimp.hxx>
29 #include <xmloff/nmspmap.hxx>
30 #include <xmloff/xmlnmspe.hxx>
31 #include <xmloff/xmltoken.hxx>
32 #include <xmloff/xmluconv.hxx>
33 #include <rtl/ustring.hxx>
34 #include <tools/debug.hxx>
36 using namespace ::xmloff::token;
38 using ::com::sun::star::uno::Sequence;
39 using ::com::sun::star::uno::Reference;
40 using ::com::sun::star::uno::Any;
41 using ::com::sun::star::beans::PropertyValue;
42 using ::com::sun::star::xml::sax::XAttributeList;
45 TYPEINIT1( XMLIndexTabStopEntryContext, XMLIndexSimpleEntryContext );
47 XMLIndexTabStopEntryContext::XMLIndexTabStopEntryContext(
48 SvXMLImport& rImport,
49 XMLIndexTemplateContext& rTemplate,
50 sal_uInt16 nPrfx,
51 const OUString& rLocalName ) :
52 XMLIndexSimpleEntryContext(rImport, rTemplate.sTokenTabStop,
53 rTemplate, nPrfx, rLocalName),
54 sLeaderChar(),
55 nTabPosition(0),
56 bTabPositionOK(false),
57 bTabRightAligned(false),
58 bLeaderCharOK(false),
59 bWithTab(true) // #i21237#
63 XMLIndexTabStopEntryContext::~XMLIndexTabStopEntryContext()
67 void XMLIndexTabStopEntryContext::StartElement(
68 const Reference<XAttributeList> & xAttrList)
70 // process three attributes: type, position, leader char
71 sal_Int16 nLength = xAttrList->getLength();
72 for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
74 OUString sLocalName;
75 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
76 GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
77 &sLocalName );
78 OUString sAttr = xAttrList->getValueByIndex(nAttr);
79 if (XML_NAMESPACE_STYLE == nPrefix)
81 if ( IsXMLToken( sLocalName, XML_TYPE ) )
83 // if it's neither left nor right, value is
84 // ignored. Since left is default, we only need to
85 // check for right
86 bTabRightAligned = IsXMLToken( sAttr, XML_RIGHT );
88 else if ( IsXMLToken( sLocalName, XML_POSITION ) )
90 sal_Int32 nTmp;
91 if (GetImport().GetMM100UnitConverter().
92 convertMeasureToCore(nTmp, sAttr))
94 nTabPosition = nTmp;
95 bTabPositionOK = true;
98 else if ( IsXMLToken( sLocalName, XML_LEADER_CHAR ) )
100 sLeaderChar = sAttr;
101 // valid only, if we have a char!
102 bLeaderCharOK = !sAttr.isEmpty();
104 // #i21237#
105 else if ( IsXMLToken( sLocalName, XML_WITH_TAB ) )
107 bool bTmp(false);
108 if (::sax::Converter::convertBool(bTmp, sAttr))
109 bWithTab = bTmp;
111 // else: unknown style: attribute -> ignore
113 // else: no style attribute -> ignore
116 // how many entries? #i21237#
117 nValues += 2 + (bTabPositionOK ? 1 : 0) + (bLeaderCharOK ? 1 : 0);
119 // now try parent class (for character style)
120 XMLIndexSimpleEntryContext::StartElement( xAttrList );
123 void XMLIndexTabStopEntryContext::FillPropertyValues(
124 Sequence<PropertyValue> & rValues)
126 // fill vlues from parent class (type + style name)
127 XMLIndexSimpleEntryContext::FillPropertyValues(rValues);
129 // get values array and next entry to be written;
130 sal_Int32 nNextEntry = bCharStyleNameOK ? 2 : 1;
131 PropertyValue* pValues = rValues.getArray();
133 // right aligned?
134 pValues[nNextEntry].Name = rTemplateContext.sTabStopRightAligned;
135 pValues[nNextEntry].Value.setValue( &bTabRightAligned,
136 cppu::UnoType<bool>::get());
137 nNextEntry++;
139 // position
140 if (bTabPositionOK)
142 pValues[nNextEntry].Name = rTemplateContext.sTabStopPosition;
143 pValues[nNextEntry].Value <<= nTabPosition;
144 nNextEntry++;
147 // leader char
148 if (bLeaderCharOK)
150 pValues[nNextEntry].Name = rTemplateContext.sTabStopFillCharacter;
151 pValues[nNextEntry].Value <<= sLeaderChar;
152 nNextEntry++;
155 // tab character #i21237#
156 pValues[nNextEntry].Name = "WithTab";
157 pValues[nNextEntry].Value.setValue( &bWithTab,
158 cppu::UnoType<bool>::get());
159 nNextEntry++;
161 // check whether we really filled all elements of the sequence
162 DBG_ASSERT( nNextEntry == rValues.getLength(),
163 "length incorrectly precumputed!" );
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */