Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <com/sun/star/style/TabAlign.hpp>
30 : : #include <rtl/ustrbuf.hxx>
31 : : #include <xmloff/xmltkmap.hxx>
32 : : #include <xmloff/nmspmap.hxx>
33 : : #include "xmloff/xmlnmspe.hxx"
34 : : #include <xmloff/xmlimp.hxx>
35 : : #include <com/sun/star/style/TabStop.hpp>
36 : : #include <xmloff/xmltoken.hxx>
37 : : #include "xmloff/i18nmap.hxx"
38 : : #include <xmloff/xmluconv.hxx>
39 : : #include "xmltabi.hxx"
40 : :
41 : : using ::rtl::OUString;
42 : : using ::rtl::OUStringBuffer;
43 : :
44 : : using namespace ::com::sun::star;
45 : : using namespace ::xmloff::token;
46 : :
47 : : enum SvXMLTokenMapAttrs
48 : : {
49 : : XML_TOK_TABSTOP_POSITION,
50 : : XML_TOK_TABSTOP_TYPE,
51 : : XML_TOK_TABSTOP_CHAR,
52 : : XML_TOK_TABSTOP_LEADER_STYLE,
53 : : XML_TOK_TABSTOP_LEADER_TEXT,
54 : : XML_TOK_TABSTOP_END=XML_TOK_UNKNOWN
55 : : };
56 : :
57 : : static SvXMLTokenMapEntry aTabsAttributesAttrTokenMap[] =
58 : : {
59 : : { XML_NAMESPACE_STYLE, XML_POSITION, XML_TOK_TABSTOP_POSITION },
60 : : { XML_NAMESPACE_STYLE, XML_TYPE, XML_TOK_TABSTOP_TYPE },
61 : : { XML_NAMESPACE_STYLE, XML_CHAR, XML_TOK_TABSTOP_CHAR },
62 : : { XML_NAMESPACE_STYLE, XML_LEADER_TEXT, XML_TOK_TABSTOP_LEADER_TEXT },
63 : : { XML_NAMESPACE_STYLE, XML_LEADER_STYLE, XML_TOK_TABSTOP_LEADER_STYLE },
64 : : XML_TOKEN_MAP_END
65 : : };
66 : :
67 : : // ---
68 : :
69 : : class SvxXMLTabStopContext_Impl : public SvXMLImportContext
70 : : {
71 : : private:
72 : : style::TabStop aTabStop;
73 : :
74 : : public:
75 : : TYPEINFO();
76 : :
77 : : SvxXMLTabStopContext_Impl( SvXMLImport& rImport, sal_uInt16 nPrfx,
78 : : const OUString& rLName,
79 : : const uno::Reference< xml::sax::XAttributeList > & xAttrList );
80 : :
81 : : virtual ~SvxXMLTabStopContext_Impl();
82 : :
83 : : virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
84 : : const OUString& rLocalName,
85 : : const uno::Reference< xml::sax::XAttributeList > & xAttrList );
86 : :
87 : 86 : const style::TabStop& getTabStop() const { return aTabStop; }
88 : : };
89 : :
90 [ # # ][ # # ]: 0 : TYPEINIT1( SvxXMLTabStopContext_Impl, SvXMLImportContext );
91 : :
92 : 43 : SvxXMLTabStopContext_Impl::SvxXMLTabStopContext_Impl(
93 : : SvXMLImport& rImport, sal_uInt16 nPrfx,
94 : : const OUString& rLName,
95 : : const uno::Reference< xml::sax::XAttributeList > & xAttrList )
96 : 43 : : SvXMLImportContext( rImport, nPrfx, rLName )
97 : : {
98 : 43 : aTabStop.Position = 0;
99 : 43 : aTabStop.Alignment = style::TabAlign_LEFT;
100 : 43 : aTabStop.DecimalChar = sal_Unicode( ',' );
101 : 43 : aTabStop.FillChar = sal_Unicode( ' ' );
102 : 43 : sal_Unicode cTextFillChar = 0;
103 : :
104 [ + - ]: 43 : SvXMLTokenMap aTokenMap( aTabsAttributesAttrTokenMap );
105 : :
106 [ + - ][ + - ]: 43 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
[ + - ]
107 [ + + ]: 141 : for( sal_Int16 i=0; i < nAttrCount; i++ )
108 : : {
109 [ + - ][ + - ]: 98 : const OUString& rAttrName = xAttrList->getNameByIndex( i );
110 : 98 : OUString aLocalName;
111 : : sal_uInt16 nPrefix =
112 : 98 : GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
113 [ + - ]: 98 : &aLocalName );
114 [ + - ][ + - ]: 98 : const OUString& rValue = xAttrList->getValueByIndex( i );
115 : :
116 : : sal_Int32 nVal;
117 [ + - ][ + + : 98 : switch( aTokenMap.Get( nPrefix, aLocalName ) )
- + + - ]
118 : : {
119 : : case XML_TOK_TABSTOP_POSITION:
120 [ + - ][ + - ]: 43 : if (GetImport().GetMM100UnitConverter().convertMeasureToCore(
121 : : nVal, rValue))
122 : : {
123 : 43 : aTabStop.Position = nVal;
124 : : }
125 : 43 : break;
126 : : case XML_TOK_TABSTOP_TYPE:
127 [ + - ][ - + ]: 37 : if( IsXMLToken( rValue, XML_LEFT ) )
128 : : {
129 : 0 : aTabStop.Alignment = style::TabAlign_LEFT;
130 : : }
131 [ + - ][ + + ]: 37 : else if( IsXMLToken( rValue, XML_RIGHT ) )
132 : : {
133 : 26 : aTabStop.Alignment = style::TabAlign_RIGHT;
134 : : }
135 [ + - ][ + - ]: 11 : else if( IsXMLToken( rValue, XML_CENTER ) )
136 : : {
137 : 11 : aTabStop.Alignment = style::TabAlign_CENTER;
138 : : }
139 [ # # ][ # # ]: 0 : else if( IsXMLToken( rValue, XML_CHAR ) )
140 : : {
141 : 0 : aTabStop.Alignment = style::TabAlign_DECIMAL;
142 : : }
143 [ # # ][ # # ]: 0 : else if( IsXMLToken( rValue, XML_DEFAULT ) )
144 : : {
145 : 0 : aTabStop.Alignment = style::TabAlign_DEFAULT;
146 : : }
147 : 37 : break;
148 : : case XML_TOK_TABSTOP_CHAR:
149 [ # # ]: 0 : if( !rValue.isEmpty() )
150 : 0 : aTabStop.DecimalChar = rValue[0];
151 : 0 : break;
152 : : case XML_TOK_TABSTOP_LEADER_STYLE:
153 [ + - ][ - + ]: 9 : if( IsXMLToken( rValue, XML_NONE ) )
154 : 0 : aTabStop.FillChar = ' ';
155 [ + - ][ + - ]: 9 : else if( IsXMLToken( rValue, XML_DOTTED ) )
156 : 9 : aTabStop.FillChar = '.';
157 : : else
158 : 0 : aTabStop.FillChar = '_';
159 : 9 : break;
160 : : case XML_TOK_TABSTOP_LEADER_TEXT:
161 [ + - ]: 9 : if( !rValue.isEmpty() )
162 : 9 : cTextFillChar = rValue[0];
163 : 9 : break;
164 : : }
165 : 98 : }
166 : :
167 [ + + ][ + - ]: 43 : if( cTextFillChar != 0 && aTabStop.FillChar != ' ' )
168 [ + - ]: 43 : aTabStop.FillChar = cTextFillChar;
169 : 43 : }
170 : :
171 : 43 : SvxXMLTabStopContext_Impl::~SvxXMLTabStopContext_Impl()
172 : : {
173 [ - + ]: 86 : }
174 : :
175 : 0 : SvXMLImportContext *SvxXMLTabStopContext_Impl::CreateChildContext(
176 : : sal_uInt16 nPrefix,
177 : : const OUString& rLocalName,
178 : : const uno::Reference< xml::sax::XAttributeList > & )
179 : : {
180 [ # # ]: 0 : return new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
181 : : }
182 : :
183 : :
184 : :
185 : :
186 : 52 : class SvxXMLTabStopArray_Impl : public std::vector<SvxXMLTabStopContext_Impl *> {};
187 : :
188 : :
189 : : // ---
190 : :
191 [ # # ][ # # ]: 0 : TYPEINIT1( SvxXMLTabStopImportContext, XMLElementPropertyContext );
192 : :
193 : 112 : SvxXMLTabStopImportContext::SvxXMLTabStopImportContext(
194 : : SvXMLImport& rImport, sal_uInt16 nPrfx,
195 : : const OUString& rLName,
196 : : const XMLPropertyState& rProp,
197 : : ::std::vector< XMLPropertyState > &rProps )
198 : : : XMLElementPropertyContext( rImport, nPrfx, rLName, rProp, rProps ),
199 : 112 : mpTabStops( NULL )
200 : : {
201 : 112 : }
202 : :
203 : 112 : SvxXMLTabStopImportContext::~SvxXMLTabStopImportContext()
204 : : {
205 [ + + ]: 112 : if( mpTabStops )
206 : : {
207 [ + + ]: 69 : while( !mpTabStops->empty() )
208 : : {
209 [ + - ]: 43 : SvxXMLTabStopContext_Impl *pTabStop = mpTabStops->back();
210 [ + - ]: 43 : mpTabStops->pop_back();
211 [ + - ]: 43 : pTabStop->ReleaseRef();
212 : : }
213 : : }
214 : :
215 [ + + ]: 112 : delete mpTabStops;
216 [ - + ]: 224 : }
217 : :
218 : 43 : SvXMLImportContext *SvxXMLTabStopImportContext::CreateChildContext(
219 : : sal_uInt16 nPrefix,
220 : : const OUString& rLocalName,
221 : : const uno::Reference< xml::sax::XAttributeList > & xAttrList )
222 : : {
223 : 43 : SvXMLImportContext *pContext = 0;
224 : :
225 [ + - ][ + - ]: 43 : if( XML_NAMESPACE_STYLE == nPrefix && IsXMLToken( rLocalName, XML_TAB_STOP ) )
[ + - ]
226 : : {
227 : : // create new tabstop import context
228 : : SvxXMLTabStopContext_Impl *pTabStopContext =
229 : 43 : new SvxXMLTabStopContext_Impl( GetImport(), nPrefix, rLocalName,
230 [ + - ][ + - ]: 43 : xAttrList );
231 : :
232 : : // add new tabstop to array of tabstops
233 [ + + ]: 43 : if( !mpTabStops )
234 [ + - ][ + - ]: 26 : mpTabStops = new SvxXMLTabStopArray_Impl;
235 : :
236 [ + - ]: 43 : mpTabStops->push_back( pTabStopContext );
237 : 43 : pTabStopContext->AddRef();
238 : :
239 : 43 : pContext = pTabStopContext;
240 : : }
241 : : else
242 : : {
243 [ # # ]: 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
244 : : }
245 : :
246 : 43 : return pContext;
247 : : }
248 : :
249 : 112 : void SvxXMLTabStopImportContext::EndElement( )
250 : : {
251 [ + + ]: 112 : sal_uInt16 nCount = mpTabStops ? mpTabStops->size() : 0;
252 [ + - ]: 112 : uno::Sequence< style::TabStop> aSeq( nCount );
253 : :
254 [ + + ]: 112 : if( mpTabStops )
255 : : {
256 : 26 : sal_uInt16 nNewCount = 0;
257 : :
258 [ + - ]: 26 : style::TabStop* pTabStops = aSeq.getArray();
259 [ + + ]: 69 : for( sal_uInt16 i=0; i < nCount; i++ )
260 : : {
261 : 43 : SvxXMLTabStopContext_Impl *pTabStopContext = (*mpTabStops)[i];
262 : 43 : const style::TabStop& rTabStop = pTabStopContext->getTabStop();
263 : 43 : sal_Bool bDflt = style::TabAlign_DEFAULT == rTabStop.Alignment;
264 [ # # ][ - + ]: 43 : if( !bDflt || 0==i )
265 : : {
266 : 43 : *pTabStops++ = pTabStopContext->getTabStop();
267 : 43 : nNewCount++;
268 : : }
269 [ - + ][ # # ]: 43 : if( bDflt && 0==i )
270 : 0 : break;
271 : : }
272 : :
273 [ - + ]: 26 : if( nCount != nNewCount )
274 [ # # ]: 0 : aSeq.realloc( nNewCount );
275 : : }
276 [ + - ]: 112 : aProp.maValue <<= aSeq;
277 : :
278 : 112 : SetInsert( sal_True );
279 [ + - ][ + - ]: 112 : XMLElementPropertyContext::EndElement();
280 : :
281 : 112 : }
282 : :
283 : :
284 : :
285 : :
286 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|