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