Update ooo320-m1
[ooovba.git] / xmloff / source / text / XMLIndexTabStopEntryContext.cxx
blob681b2c4256702a80dce984d392049ae03e960687
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLIndexTabStopEntryContext.cxx,v $
10 * $Revision: 1.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
35 #include "XMLIndexTabStopEntryContext.hxx"
36 #include "XMLIndexTemplateContext.hxx"
37 #include <xmloff/xmlictxt.hxx>
38 #include <xmloff/xmlimp.hxx>
39 #include <xmloff/txtimp.hxx>
40 #include <xmloff/nmspmap.hxx>
41 #include "xmlnmspe.hxx"
42 #include <xmloff/xmltoken.hxx>
43 #include <xmloff/xmluconv.hxx>
44 #include <rtl/ustring.hxx>
45 #include <tools/debug.hxx>
47 using namespace ::xmloff::token;
49 using ::rtl::OUString;
50 using ::com::sun::star::uno::Sequence;
51 using ::com::sun::star::uno::Reference;
52 using ::com::sun::star::uno::Any;
53 using ::com::sun::star::beans::PropertyValue;
54 using ::com::sun::star::xml::sax::XAttributeList;
57 TYPEINIT1( XMLIndexTabStopEntryContext, XMLIndexSimpleEntryContext );
59 XMLIndexTabStopEntryContext::XMLIndexTabStopEntryContext(
60 SvXMLImport& rImport,
61 XMLIndexTemplateContext& rTemplate,
62 sal_uInt16 nPrfx,
63 const OUString& rLocalName ) :
64 XMLIndexSimpleEntryContext(rImport, rTemplate.sTokenTabStop,
65 rTemplate, nPrfx, rLocalName),
66 sLeaderChar(),
67 nTabPosition(0),
68 bTabPositionOK(sal_False),
69 bTabRightAligned(sal_False),
70 bLeaderCharOK(sal_False),
71 bWithTab(sal_True) // #i21237#
75 XMLIndexTabStopEntryContext::~XMLIndexTabStopEntryContext()
79 void XMLIndexTabStopEntryContext::StartElement(
80 const Reference<XAttributeList> & xAttrList)
82 // process three attributes: type, position, leader char
83 sal_Int16 nLength = xAttrList->getLength();
84 for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
86 OUString sLocalName;
87 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
88 GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
89 &sLocalName );
90 OUString sAttr = xAttrList->getValueByIndex(nAttr);
91 if (XML_NAMESPACE_STYLE == nPrefix)
93 if ( IsXMLToken( sLocalName, XML_TYPE ) )
95 // if it's neither left nor right, value is
96 // ignored. Since left is default, we only need to
97 // check for right
98 bTabRightAligned = IsXMLToken( sAttr, XML_RIGHT );
100 else if ( IsXMLToken( sLocalName, XML_POSITION ) )
102 sal_Int32 nTmp;
103 if (GetImport().GetMM100UnitConverter().
104 convertMeasure(nTmp, sAttr))
106 nTabPosition = nTmp;
107 bTabPositionOK = sal_True;
110 else if ( IsXMLToken( sLocalName, XML_LEADER_CHAR ) )
112 sLeaderChar = sAttr;
113 // valid only, if we have a char!
114 bLeaderCharOK = (sAttr.getLength() > 0);
116 // #i21237#
117 else if ( IsXMLToken( sLocalName, XML_WITH_TAB ) )
119 sal_Bool bTmp;
120 if (SvXMLUnitConverter::convertBool(bTmp, sAttr))
121 bWithTab = bTmp;
123 // else: unknown style: attribute -> ignore
125 // else: no style attribute -> ignore
128 // how many entries? #i21237#
129 nValues += 2 + (bTabPositionOK ? 1 : 0) + (bLeaderCharOK ? 1 : 0);
131 // now try parent class (for character style)
132 XMLIndexSimpleEntryContext::StartElement( xAttrList );
135 void XMLIndexTabStopEntryContext::FillPropertyValues(
136 Sequence<PropertyValue> & rValues)
138 // fill vlues from parent class (type + style name)
139 XMLIndexSimpleEntryContext::FillPropertyValues(rValues);
141 // get values array and next entry to be written;
142 sal_Int32 nNextEntry = bCharStyleNameOK ? 2 : 1;
143 PropertyValue* pValues = rValues.getArray();
145 // right aligned?
146 pValues[nNextEntry].Name = rTemplateContext.sTabStopRightAligned;
147 pValues[nNextEntry].Value.setValue( &bTabRightAligned,
148 ::getBooleanCppuType());
149 nNextEntry++;
151 // position
152 if (bTabPositionOK)
154 pValues[nNextEntry].Name = rTemplateContext.sTabStopPosition;
155 pValues[nNextEntry].Value <<= nTabPosition;
156 nNextEntry++;
159 // leader char
160 if (bLeaderCharOK)
162 pValues[nNextEntry].Name = rTemplateContext.sTabStopFillCharacter;
163 pValues[nNextEntry].Value <<= sLeaderChar;
164 nNextEntry++;
167 // tab character #i21237#
168 pValues[nNextEntry].Name =
169 OUString( RTL_CONSTASCII_USTRINGPARAM("WithTab") );
170 pValues[nNextEntry].Value.setValue( &bWithTab,
171 ::getBooleanCppuType());
172 nNextEntry++;
174 // check whether we really filled all elements of the sequence
175 DBG_ASSERT( nNextEntry == rValues.getLength(),
176 "length incorrectly precumputed!" );