Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include "PageMasterPropHdl.hxx"
22 :
23 : #include <sax/tools/converter.hxx>
24 :
25 : #include <xmloff/xmltoken.hxx>
26 : #include <xmloff/xmluconv.hxx>
27 : #include <xmloff/xmlnumi.hxx>
28 : #include <xmloff/xmlnume.hxx>
29 : #include <rtl/ustrbuf.hxx>
30 : #include <com/sun/star/uno/Any.hxx>
31 : #include <com/sun/star/style/PageStyleLayout.hpp>
32 : #include <comphelper/types.hxx>
33 : #include <comphelper/extract.hxx>
34 :
35 :
36 : using namespace ::com::sun::star;
37 : using namespace ::com::sun::star::uno;
38 : using namespace ::com::sun::star::style;
39 : using namespace ::comphelper;
40 : using namespace ::xmloff::token;
41 :
42 :
43 : //______________________________________________________________________________
44 :
45 : #define DEFAULT_PAPERTRAY (sal_Int32(-1))
46 :
47 :
48 : //______________________________________________________________________________
49 : // property handler for style:page-usage (style::PageStyleLayout)
50 :
51 332 : XMLPMPropHdl_PageStyleLayout::~XMLPMPropHdl_PageStyleLayout()
52 : {
53 332 : }
54 :
55 6 : bool XMLPMPropHdl_PageStyleLayout::equals( const Any& rAny1, const Any& rAny2 ) const
56 : {
57 : style::PageStyleLayout eLayout1, eLayout2;
58 6 : return ((rAny1 >>= eLayout1) && (rAny2 >>= eLayout2)) ? (eLayout1 == eLayout2) : sal_False;
59 : }
60 :
61 24 : sal_Bool XMLPMPropHdl_PageStyleLayout::importXML(
62 : const OUString& rStrImpValue,
63 : Any& rValue,
64 : const SvXMLUnitConverter& ) const
65 : {
66 24 : sal_Bool bRet = sal_True;
67 :
68 24 : if( IsXMLToken( rStrImpValue, XML_ALL ) )
69 0 : rValue <<= PageStyleLayout_ALL;
70 24 : else if( IsXMLToken( rStrImpValue, XML_LEFT ) )
71 1 : rValue <<= PageStyleLayout_LEFT;
72 23 : else if( IsXMLToken( rStrImpValue, XML_RIGHT ) )
73 1 : rValue <<= PageStyleLayout_RIGHT;
74 22 : else if( IsXMLToken( rStrImpValue, XML_MIRRORED ) )
75 22 : rValue <<= PageStyleLayout_MIRRORED;
76 : else
77 0 : bRet = sal_False;
78 :
79 24 : return bRet;
80 : }
81 :
82 20 : sal_Bool XMLPMPropHdl_PageStyleLayout::exportXML(
83 : OUString& rStrExpValue,
84 : const Any& rValue,
85 : const SvXMLUnitConverter& ) const
86 : {
87 20 : sal_Bool bRet = sal_False;
88 : PageStyleLayout eLayout;
89 :
90 20 : if( rValue >>= eLayout )
91 : {
92 20 : bRet = sal_True;
93 20 : switch( eLayout )
94 : {
95 : case PageStyleLayout_ALL:
96 16 : rStrExpValue = GetXMLToken( XML_ALL );
97 16 : break;
98 : case PageStyleLayout_LEFT:
99 0 : rStrExpValue = GetXMLToken( XML_LEFT );
100 0 : break;
101 : case PageStyleLayout_RIGHT:
102 0 : rStrExpValue = GetXMLToken( XML_RIGHT );
103 0 : break;
104 : case PageStyleLayout_MIRRORED:
105 4 : rStrExpValue = GetXMLToken( XML_MIRRORED );
106 4 : break;
107 : default:
108 0 : bRet = sal_False;
109 : }
110 : }
111 :
112 20 : return bRet;
113 : }
114 :
115 :
116 : //______________________________________________________________________________
117 : // property handler for style:num-format (style::NumberingType)
118 :
119 308 : XMLPMPropHdl_NumFormat::~XMLPMPropHdl_NumFormat()
120 : {
121 308 : }
122 :
123 75 : sal_Bool XMLPMPropHdl_NumFormat::importXML(
124 : const OUString& rStrImpValue,
125 : Any& rValue,
126 : const SvXMLUnitConverter& rUnitConverter ) const
127 : {
128 75 : sal_Int16 nSync = sal_Int16();
129 75 : sal_Int16 nNumType = NumberingType::NUMBER_NONE;
130 : rUnitConverter.convertNumFormat( nNumType, rStrImpValue, OUString(),
131 75 : sal_True );
132 :
133 75 : if( !(rValue >>= nSync) )
134 75 : nSync = NumberingType::NUMBER_NONE;
135 :
136 : // if num-letter-sync appears before num-format, the function
137 : // XMLPMPropHdl_NumLetterSync::importXML() sets the value
138 : // NumberingType::CHARS_LOWER_LETTER_N
139 75 : if( nSync == NumberingType::CHARS_LOWER_LETTER_N )
140 : {
141 0 : switch( nNumType )
142 : {
143 : case NumberingType::CHARS_LOWER_LETTER:
144 0 : nNumType = NumberingType::CHARS_LOWER_LETTER_N;
145 0 : break;
146 : case NumberingType::CHARS_UPPER_LETTER:
147 0 : nNumType = NumberingType::CHARS_UPPER_LETTER_N;
148 0 : break;
149 : }
150 : }
151 75 : rValue <<= nNumType;
152 :
153 75 : return sal_True;
154 : }
155 :
156 20 : sal_Bool XMLPMPropHdl_NumFormat::exportXML(
157 : OUString& rStrExpValue,
158 : const Any& rValue,
159 : const SvXMLUnitConverter& rUnitConverter ) const
160 : {
161 20 : sal_Bool bRet = sal_False;
162 20 : sal_Int16 nNumType = sal_Int16();
163 :
164 20 : if( rValue >>= nNumType )
165 : {
166 20 : OUStringBuffer aBuffer( 10 );
167 20 : rUnitConverter.convertNumFormat( aBuffer, nNumType );
168 20 : rStrExpValue = aBuffer.makeStringAndClear();
169 20 : bRet = sal_True;
170 : }
171 20 : return bRet;
172 : }
173 :
174 :
175 : //______________________________________________________________________________
176 : // property handler for style:num-letter-sync (style::NumberingType)
177 :
178 308 : XMLPMPropHdl_NumLetterSync::~XMLPMPropHdl_NumLetterSync()
179 : {
180 308 : }
181 :
182 0 : sal_Bool XMLPMPropHdl_NumLetterSync::importXML(
183 : const OUString& rStrImpValue,
184 : Any& rValue,
185 : const SvXMLUnitConverter& rUnitConverter ) const
186 : {
187 : sal_Int16 nNumType;
188 0 : sal_Int16 nSync = NumberingType::NUMBER_NONE;
189 : rUnitConverter.convertNumFormat( nSync, rStrImpValue,
190 0 : GetXMLToken( XML_A ), sal_True );
191 :
192 0 : if( !(rValue >>= nNumType) )
193 0 : nNumType = NumberingType::NUMBER_NONE;
194 :
195 0 : if( nSync == NumberingType::CHARS_LOWER_LETTER_N )
196 : {
197 0 : switch( nNumType )
198 : {
199 : case NumberingType::CHARS_LOWER_LETTER:
200 0 : nNumType = NumberingType::CHARS_LOWER_LETTER_N;
201 0 : break;
202 : case NumberingType::CHARS_UPPER_LETTER:
203 0 : nNumType = NumberingType::CHARS_UPPER_LETTER_N;
204 0 : break;
205 : }
206 : }
207 0 : rValue <<= nNumType;
208 :
209 0 : return sal_True;
210 : }
211 :
212 20 : sal_Bool XMLPMPropHdl_NumLetterSync::exportXML(
213 : OUString& rStrExpValue,
214 : const Any& rValue,
215 : const SvXMLUnitConverter& rUnitConverter ) const
216 : {
217 20 : sal_Bool bRet = sal_False;
218 20 : sal_Int16 nNumType = sal_Int16();
219 :
220 20 : if( rValue >>= nNumType )
221 : {
222 20 : OUStringBuffer aBuffer( 5 );
223 20 : rUnitConverter.convertNumLetterSync( aBuffer, nNumType );
224 20 : rStrExpValue = aBuffer.makeStringAndClear();
225 20 : bRet = !rStrExpValue.isEmpty();
226 : }
227 20 : return bRet;
228 : }
229 :
230 :
231 : //______________________________________________________________________________
232 : // property handler for style:paper-tray-number
233 :
234 0 : XMLPMPropHdl_PaperTrayNumber::~XMLPMPropHdl_PaperTrayNumber()
235 : {
236 0 : }
237 :
238 0 : sal_Bool XMLPMPropHdl_PaperTrayNumber::importXML(
239 : const OUString& rStrImpValue,
240 : Any& rValue,
241 : const SvXMLUnitConverter& ) const
242 : {
243 0 : sal_Bool bRet = sal_False;
244 :
245 0 : if( IsXMLToken( rStrImpValue, XML_DEFAULT ) )
246 : {
247 0 : rValue <<= DEFAULT_PAPERTRAY;
248 0 : bRet = sal_True;
249 : }
250 : else
251 : {
252 : sal_Int32 nPaperTray;
253 0 : if (::sax::Converter::convertNumber( nPaperTray, rStrImpValue, 0 ))
254 : {
255 0 : rValue <<= nPaperTray;
256 0 : bRet = sal_True;
257 : }
258 : }
259 :
260 0 : return bRet;
261 : }
262 :
263 0 : sal_Bool XMLPMPropHdl_PaperTrayNumber::exportXML(
264 : OUString& rStrExpValue,
265 : const Any& rValue,
266 : const SvXMLUnitConverter& ) const
267 : {
268 0 : sal_Bool bRet = sal_False;
269 0 : sal_Int32 nPaperTray = 0;
270 :
271 0 : if( rValue >>= nPaperTray )
272 : {
273 0 : if( nPaperTray == DEFAULT_PAPERTRAY )
274 0 : rStrExpValue = GetXMLToken( XML_DEFAULT );
275 : else
276 : {
277 0 : OUStringBuffer aBuffer;
278 0 : ::sax::Converter::convertNumber( aBuffer, nPaperTray );
279 0 : rStrExpValue = aBuffer.makeStringAndClear();
280 : }
281 0 : bRet = sal_True;
282 : }
283 0 : return bRet;
284 : }
285 :
286 :
287 : //______________________________________________________________________________
288 : // property handler for style:print
289 :
290 1232 : XMLPMPropHdl_Print::XMLPMPropHdl_Print( enum XMLTokenEnum eValue ) :
291 1232 : sAttrValue( GetXMLToken( eValue ) )
292 : {
293 1232 : }
294 :
295 2464 : XMLPMPropHdl_Print::~XMLPMPropHdl_Print()
296 : {
297 2464 : }
298 :
299 64 : sal_Bool XMLPMPropHdl_Print::importXML(
300 : const OUString& rStrImpValue,
301 : Any& rValue,
302 : const SvXMLUnitConverter& ) const
303 : {
304 64 : sal_Unicode cToken = ' ';
305 64 : sal_Int32 nTokenIndex = 0;
306 64 : sal_Bool bFound = sal_False;
307 :
308 228 : do
309 : {
310 228 : bFound = (sAttrValue == rStrImpValue.getToken( 0, cToken, nTokenIndex ));
311 : }
312 421 : while ( (nTokenIndex >= 0) && !bFound );
313 :
314 64 : setBOOL( rValue, bFound );
315 64 : return sal_True;
316 : }
317 :
318 4 : sal_Bool XMLPMPropHdl_Print::exportXML(
319 : OUString& rStrExpValue,
320 : const Any& rValue,
321 : const SvXMLUnitConverter& ) const
322 : {
323 4 : if( getBOOL( rValue ) )
324 : {
325 4 : if( !rStrExpValue.isEmpty() )
326 3 : rStrExpValue += " ";
327 4 : rStrExpValue += sAttrValue;
328 : }
329 :
330 4 : return sal_True;
331 : }
332 :
333 : //______________________________________________________________________________
334 : // property handler for style:table-centering
335 :
336 308 : XMLPMPropHdl_CenterHorizontal::~XMLPMPropHdl_CenterHorizontal()
337 : {
338 308 : }
339 :
340 0 : sal_Bool XMLPMPropHdl_CenterHorizontal::importXML(
341 : const OUString& rStrImpValue,
342 : Any& rValue,
343 : const SvXMLUnitConverter& ) const
344 : {
345 0 : sal_Bool bRet = sal_False;
346 :
347 0 : if (!rStrImpValue.isEmpty())
348 0 : if (IsXMLToken( rStrImpValue, XML_BOTH) ||
349 0 : IsXMLToken( rStrImpValue, XML_HORIZONTAL))
350 : {
351 0 : rValue = ::cppu::bool2any(sal_True);
352 0 : bRet = sal_True;
353 : }
354 :
355 :
356 0 : return bRet;
357 : }
358 :
359 0 : sal_Bool XMLPMPropHdl_CenterHorizontal::exportXML(
360 : OUString& rStrExpValue,
361 : const Any& rValue,
362 : const SvXMLUnitConverter& ) const
363 : {
364 0 : sal_Bool bRet = sal_False;
365 :
366 0 : if ( ::cppu::any2bool( rValue ) )
367 : {
368 0 : bRet = sal_True;
369 0 : if (!rStrExpValue.isEmpty())
370 0 : rStrExpValue = GetXMLToken(XML_BOTH);
371 : else
372 0 : rStrExpValue = GetXMLToken(XML_HORIZONTAL);
373 : }
374 :
375 0 : return bRet;
376 : }
377 :
378 308 : XMLPMPropHdl_CenterVertical::~XMLPMPropHdl_CenterVertical()
379 : {
380 308 : }
381 :
382 0 : sal_Bool XMLPMPropHdl_CenterVertical::importXML(
383 : const OUString& rStrImpValue,
384 : Any& rValue,
385 : const SvXMLUnitConverter& ) const
386 : {
387 0 : sal_Bool bRet = sal_False;
388 :
389 0 : if (!rStrImpValue.isEmpty())
390 0 : if (IsXMLToken(rStrImpValue, XML_BOTH) ||
391 0 : IsXMLToken(rStrImpValue, XML_VERTICAL) )
392 : {
393 0 : rValue = ::cppu::bool2any(sal_True);
394 0 : bRet = sal_True;
395 : }
396 :
397 0 : return bRet;
398 : }
399 :
400 0 : sal_Bool XMLPMPropHdl_CenterVertical::exportXML(
401 : OUString& rStrExpValue,
402 : const Any& rValue,
403 : const SvXMLUnitConverter& ) const
404 : {
405 0 : sal_Bool bRet = sal_False;
406 :
407 0 : if ( ::cppu::any2bool( rValue ) )
408 : {
409 0 : bRet = sal_True;
410 0 : if (!rStrExpValue.isEmpty())
411 0 : rStrExpValue = GetXMLToken(XML_BOTH);
412 : else
413 0 : rStrExpValue = GetXMLToken(XML_VERTICAL);
414 : }
415 :
416 0 : return bRet;
417 : }
418 :
419 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|