Update ooo320-m1
[ooovba.git] / xmloff / source / style / xmltabi.cxx
blobe365ca3aacc5c312d46d02784f1fdfe1ae73c64c
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: xmltabi.cxx,v $
10 * $Revision: 1.17 $
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"
33 #include <com/sun/star/style/TabAlign.hpp>
34 #include <rtl/ustrbuf.hxx>
35 #include <xmloff/xmltkmap.hxx>
36 #include <xmloff/nmspmap.hxx>
37 #include "xmlnmspe.hxx"
38 #include <xmloff/xmlimp.hxx>
39 #include <com/sun/star/style/TabStop.hpp>
40 #include <xmloff/xmltoken.hxx>
41 #include "i18nmap.hxx"
42 #include <xmloff/xmluconv.hxx>
44 #include "xmltabi.hxx"
46 #define _SVSTDARR_USHORTS
47 #include <svtools/svstdarr.hxx>
49 using ::rtl::OUString;
50 using ::rtl::OUStringBuffer;
52 using namespace ::com::sun::star;
53 using namespace ::xmloff::token;
55 // ---
57 enum SvXMLTokenMapAttrs
59 XML_TOK_TABSTOP_POSITION,
60 XML_TOK_TABSTOP_TYPE,
61 XML_TOK_TABSTOP_CHAR,
62 XML_TOK_TABSTOP_LEADER_STYLE,
63 XML_TOK_TABSTOP_LEADER_TEXT,
64 XML_TOK_TABSTOP_END=XML_TOK_UNKNOWN
67 static __FAR_DATA SvXMLTokenMapEntry aTabsAttributesAttrTokenMap[] =
69 { XML_NAMESPACE_STYLE, XML_POSITION, XML_TOK_TABSTOP_POSITION },
70 { XML_NAMESPACE_STYLE, XML_TYPE, XML_TOK_TABSTOP_TYPE },
71 { XML_NAMESPACE_STYLE, XML_CHAR, XML_TOK_TABSTOP_CHAR },
72 { XML_NAMESPACE_STYLE, XML_LEADER_TEXT, XML_TOK_TABSTOP_LEADER_TEXT },
73 { XML_NAMESPACE_STYLE, XML_LEADER_STYLE, XML_TOK_TABSTOP_LEADER_STYLE },
74 XML_TOKEN_MAP_END
77 // ---
79 class SvxXMLTabStopContext_Impl : public SvXMLImportContext
81 private:
82 style::TabStop aTabStop;
84 public:
85 TYPEINFO();
87 SvxXMLTabStopContext_Impl( SvXMLImport& rImport, sal_uInt16 nPrfx,
88 const OUString& rLName,
89 const uno::Reference< xml::sax::XAttributeList > & xAttrList );
91 virtual ~SvxXMLTabStopContext_Impl();
93 virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
94 const OUString& rLocalName,
95 const uno::Reference< xml::sax::XAttributeList > & xAttrList );
97 const style::TabStop& getTabStop() const { return aTabStop; }
100 TYPEINIT1( SvxXMLTabStopContext_Impl, SvXMLImportContext );
102 SvxXMLTabStopContext_Impl::SvxXMLTabStopContext_Impl(
103 SvXMLImport& rImport, sal_uInt16 nPrfx,
104 const OUString& rLName,
105 const uno::Reference< xml::sax::XAttributeList > & xAttrList )
106 : SvXMLImportContext( rImport, nPrfx, rLName )
108 aTabStop.Position = 0;
109 aTabStop.Alignment = style::TabAlign_LEFT;
110 aTabStop.DecimalChar = sal_Unicode( ',' );
111 aTabStop.FillChar = sal_Unicode( ' ' );
112 sal_Unicode cTextFillChar = 0;
114 SvXMLTokenMap aTokenMap( aTabsAttributesAttrTokenMap );
116 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
117 for( sal_Int16 i=0; i < nAttrCount; i++ )
119 const OUString& rAttrName = xAttrList->getNameByIndex( i );
120 OUString aLocalName;
121 sal_uInt16 nPrefix =
122 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
123 &aLocalName );
124 const OUString& rValue = xAttrList->getValueByIndex( i );
126 sal_Int32 nVal;
127 switch( aTokenMap.Get( nPrefix, aLocalName ) )
129 case XML_TOK_TABSTOP_POSITION:
130 if( GetImport().GetMM100UnitConverter().convertMeasure( nVal,
131 rValue ) )
132 aTabStop.Position = nVal;
133 break;
134 case XML_TOK_TABSTOP_TYPE:
135 if( IsXMLToken( rValue, XML_LEFT ) )
137 aTabStop.Alignment = style::TabAlign_LEFT;
139 else if( IsXMLToken( rValue, XML_RIGHT ) )
141 aTabStop.Alignment = style::TabAlign_RIGHT;
143 else if( IsXMLToken( rValue, XML_CENTER ) )
145 aTabStop.Alignment = style::TabAlign_CENTER;
147 else if( IsXMLToken( rValue, XML_CHAR ) )
149 aTabStop.Alignment = style::TabAlign_DECIMAL;
151 else if( IsXMLToken( rValue, XML_DEFAULT ) )
153 aTabStop.Alignment = style::TabAlign_DEFAULT;
155 break;
156 case XML_TOK_TABSTOP_CHAR:
157 if( 0 != rValue.getLength() )
158 aTabStop.DecimalChar = rValue[0];
159 break;
160 case XML_TOK_TABSTOP_LEADER_STYLE:
161 if( IsXMLToken( rValue, XML_NONE ) )
162 aTabStop.FillChar = ' ';
163 else if( IsXMLToken( rValue, XML_DOTTED ) )
164 aTabStop.FillChar = '.';
165 else
166 aTabStop.FillChar = '_';
167 break;
168 case XML_TOK_TABSTOP_LEADER_TEXT:
169 if( 0 != rValue.getLength() )
170 cTextFillChar = rValue[0];
171 break;
175 if( cTextFillChar != 0 && aTabStop.FillChar != ' ' )
176 aTabStop.FillChar = cTextFillChar;
179 SvxXMLTabStopContext_Impl::~SvxXMLTabStopContext_Impl()
183 SvXMLImportContext *SvxXMLTabStopContext_Impl::CreateChildContext(
184 sal_uInt16 nPrefix,
185 const OUString& rLocalName,
186 const uno::Reference< xml::sax::XAttributeList > & )
188 return new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
194 typedef SvxXMLTabStopContext_Impl *SvxXMLTabStopContext_Impl_ImplPtr;
195 SV_DECL_PTRARR( SvxXMLTabStopArray_Impl, SvxXMLTabStopContext_Impl_ImplPtr, 20, 5 )
198 // ---
200 TYPEINIT1( SvxXMLTabStopImportContext, XMLElementPropertyContext );
202 SvxXMLTabStopImportContext::SvxXMLTabStopImportContext(
203 SvXMLImport& rImport, sal_uInt16 nPrfx,
204 const OUString& rLName,
205 const XMLPropertyState& rProp,
206 ::std::vector< XMLPropertyState > &rProps )
207 : XMLElementPropertyContext( rImport, nPrfx, rLName, rProp, rProps ),
208 mpTabStops( NULL )
212 SvxXMLTabStopImportContext::~SvxXMLTabStopImportContext()
214 if( mpTabStops )
216 sal_uInt16 nCount = mpTabStops->Count();
217 while( nCount )
219 nCount--;
220 SvxXMLTabStopContext_Impl *pTabStop = (*mpTabStops)[nCount];
221 mpTabStops->Remove( nCount, 1 );
222 pTabStop->ReleaseRef();
226 delete mpTabStops;
229 SvXMLImportContext *SvxXMLTabStopImportContext::CreateChildContext(
230 sal_uInt16 nPrefix,
231 const OUString& rLocalName,
232 const uno::Reference< xml::sax::XAttributeList > & xAttrList )
234 SvXMLImportContext *pContext = 0;
236 if( XML_NAMESPACE_STYLE == nPrefix && IsXMLToken( rLocalName, XML_TAB_STOP ) )
238 // create new tabstop import context
239 SvxXMLTabStopContext_Impl *pTabStopContext =
240 new SvxXMLTabStopContext_Impl( GetImport(), nPrefix, rLocalName,
241 xAttrList );
243 // add new tabstop to array of tabstops
244 if( !mpTabStops )
245 mpTabStops = new SvxXMLTabStopArray_Impl;
247 mpTabStops->Insert( pTabStopContext, mpTabStops->Count() );
248 pTabStopContext->AddRef();
250 pContext = pTabStopContext;
252 else
254 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
257 return pContext;
260 void SvxXMLTabStopImportContext::EndElement( )
262 sal_uInt16 nCount = mpTabStops ? mpTabStops->Count() : 0;
263 uno::Sequence< style::TabStop> aSeq( nCount );
265 if( mpTabStops )
267 sal_uInt16 nNewCount = 0;
269 style::TabStop* pTabStops = aSeq.getArray();
270 for( sal_uInt16 i=0; i < nCount; i++ )
272 SvxXMLTabStopContext_Impl *pTabStopContext = (*mpTabStops)[i];
273 const style::TabStop& rTabStop = pTabStopContext->getTabStop();
274 sal_Bool bDflt = style::TabAlign_DEFAULT == rTabStop.Alignment;
275 if( !bDflt || 0==i )
277 *pTabStops++ = pTabStopContext->getTabStop();
278 nNewCount++;
280 if( bDflt && 0==i )
281 break;
284 if( nCount != nNewCount )
285 aSeq.realloc( nNewCount );
287 aProp.maValue <<= aSeq;
289 SetInsert( sal_True );
290 XMLElementPropertyContext::EndElement();