LibreOffice Module xmloff (master)  1
PageMasterPropHdl.cxx
Go to the documentation of this file.
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 
33 using namespace ::com::sun::star;
34 using namespace ::com::sun::star::uno;
35 using namespace ::com::sun::star::style;
36 using namespace ::comphelper;
37 using namespace ::xmloff::token;
38 
39 #define DEFAULT_PAPERTRAY (sal_Int32(-1))
40 
41 // property handler for style:page-usage (style::PageStyleLayout)
42 
44 {
45 }
46 
47 bool XMLPMPropHdl_PageStyleLayout::equals( const Any& rAny1, const Any& rAny2 ) const
48 {
49  style::PageStyleLayout eLayout1, eLayout2;
50  return (rAny1 >>= eLayout1) && (rAny2 >>= eLayout2) && (eLayout1 == eLayout2);
51 }
52 
54  const OUString& rStrImpValue,
55  Any& rValue,
56  const SvXMLUnitConverter& ) const
57 {
58  bool bRet = true;
59 
60  if( IsXMLToken( rStrImpValue, XML_ALL ) )
61  rValue <<= PageStyleLayout_ALL;
62  else if( IsXMLToken( rStrImpValue, XML_LEFT ) )
63  rValue <<= PageStyleLayout_LEFT;
64  else if( IsXMLToken( rStrImpValue, XML_RIGHT ) )
65  rValue <<= PageStyleLayout_RIGHT;
66  else if( IsXMLToken( rStrImpValue, XML_MIRRORED ) )
67  rValue <<= PageStyleLayout_MIRRORED;
68  else
69  bRet = false;
70 
71  return bRet;
72 }
73 
75  OUString& rStrExpValue,
76  const Any& rValue,
77  const SvXMLUnitConverter& ) const
78 {
79  bool bRet = false;
80  PageStyleLayout eLayout;
81 
82  if( rValue >>= eLayout )
83  {
84  bRet = true;
85  switch( eLayout )
86  {
87  case PageStyleLayout_ALL:
88  rStrExpValue = GetXMLToken( XML_ALL );
89  break;
90  case PageStyleLayout_LEFT:
91  rStrExpValue = GetXMLToken( XML_LEFT );
92  break;
93  case PageStyleLayout_RIGHT:
94  rStrExpValue = GetXMLToken( XML_RIGHT );
95  break;
96  case PageStyleLayout_MIRRORED:
97  rStrExpValue = GetXMLToken( XML_MIRRORED );
98  break;
99  default:
100  bRet = false;
101  }
102  }
103 
104  return bRet;
105 }
106 
107 // property handler for style:num-format (style::NumberingType)
108 
110 {
111 }
112 
114  const OUString& rStrImpValue,
115  Any& rValue,
116  const SvXMLUnitConverter& rUnitConverter ) const
117 {
118  sal_Int16 nSync = sal_Int16();
119  sal_Int16 nNumType = NumberingType::NUMBER_NONE;
120  rUnitConverter.convertNumFormat( nNumType, rStrImpValue, OUString(), true );
121 
122  if( !(rValue >>= nSync) )
123  nSync = NumberingType::NUMBER_NONE;
124 
125  // if num-letter-sync appears before num-format, the function
126  // XMLPMPropHdl_NumLetterSync::importXML() sets the value
127  // NumberingType::CHARS_LOWER_LETTER_N
128  if( nSync == NumberingType::CHARS_LOWER_LETTER_N )
129  {
130  switch( nNumType )
131  {
132  case NumberingType::CHARS_LOWER_LETTER:
133  nNumType = NumberingType::CHARS_LOWER_LETTER_N;
134  break;
135  case NumberingType::CHARS_UPPER_LETTER:
136  nNumType = NumberingType::CHARS_UPPER_LETTER_N;
137  break;
138  }
139  }
140  rValue <<= nNumType;
141 
142  return true;
143 }
144 
146  OUString& rStrExpValue,
147  const Any& rValue,
148  const SvXMLUnitConverter& rUnitConverter ) const
149 {
150  bool bRet = false;
151  sal_Int16 nNumType = sal_Int16();
152 
153  if( rValue >>= nNumType )
154  {
155  OUStringBuffer aBuffer( 10 );
156  rUnitConverter.convertNumFormat( aBuffer, nNumType );
157  rStrExpValue = aBuffer.makeStringAndClear();
158  bRet = true;
159  }
160  return bRet;
161 }
162 
163 // property handler for style:num-letter-sync (style::NumberingType)
164 
166 {
167 }
168 
170  const OUString& rStrImpValue,
171  Any& rValue,
172  const SvXMLUnitConverter& rUnitConverter ) const
173 {
174  sal_Int16 nNumType;
175  sal_Int16 nSync = NumberingType::NUMBER_NONE;
176  rUnitConverter.convertNumFormat( nSync, rStrImpValue,
177  GetXMLToken( XML_A ), true );
178 
179  if( !(rValue >>= nNumType) )
180  nNumType = NumberingType::NUMBER_NONE;
181 
182  if( nSync == NumberingType::CHARS_LOWER_LETTER_N )
183  {
184  switch( nNumType )
185  {
186  case NumberingType::CHARS_LOWER_LETTER:
187  nNumType = NumberingType::CHARS_LOWER_LETTER_N;
188  break;
189  case NumberingType::CHARS_UPPER_LETTER:
190  nNumType = NumberingType::CHARS_UPPER_LETTER_N;
191  break;
192  }
193  }
194  rValue <<= nNumType;
195 
196  return true;
197 }
198 
200  OUString& rStrExpValue,
201  const Any& rValue,
202  const SvXMLUnitConverter& /*rUnitConverter*/ ) const
203 {
204  bool bRet = false;
205  sal_Int16 nNumType = sal_Int16();
206 
207  if( rValue >>= nNumType )
208  {
209  OUStringBuffer aBuffer( 5 );
210  SvXMLUnitConverter::convertNumLetterSync( aBuffer, nNumType );
211  rStrExpValue = aBuffer.makeStringAndClear();
212  bRet = !rStrExpValue.isEmpty();
213  }
214  return bRet;
215 }
216 
217 // property handler for style:paper-tray-number
218 
220 {
221 }
222 
224  const OUString& rStrImpValue,
225  Any& rValue,
226  const SvXMLUnitConverter& ) const
227 {
228  bool bRet = false;
229 
230  if( IsXMLToken( rStrImpValue, XML_DEFAULT ) )
231  {
232  rValue <<= DEFAULT_PAPERTRAY;
233  bRet = true;
234  }
235  else
236  {
237  sal_Int32 nPaperTray;
238  if (::sax::Converter::convertNumber( nPaperTray, rStrImpValue, 0 ))
239  {
240  rValue <<= nPaperTray;
241  bRet = true;
242  }
243  }
244 
245  return bRet;
246 }
247 
249  OUString& rStrExpValue,
250  const Any& rValue,
251  const SvXMLUnitConverter& ) const
252 {
253  bool bRet = false;
254  sal_Int32 nPaperTray = 0;
255 
256  if( rValue >>= nPaperTray )
257  {
258  if( nPaperTray == DEFAULT_PAPERTRAY )
259  rStrExpValue = GetXMLToken( XML_DEFAULT );
260  else
261  {
262  rStrExpValue = OUString::number( nPaperTray );
263  }
264  bRet = true;
265  }
266  return bRet;
267 }
268 
269 // property handler for style:print
270 
272  sAttrValue( GetXMLToken( eValue ) )
273 {
274 }
275 
277 {
278 }
279 
281  const OUString& rStrImpValue,
282  Any& rValue,
283  const SvXMLUnitConverter& ) const
284 {
285  sal_Int32 nTokenIndex = 0;
286  bool bFound = false;
287 
288  do
289  {
290  bFound = (sAttrValue == rStrImpValue.getToken( 0, ' ', nTokenIndex ));
291  }
292  while ( (nTokenIndex >= 0) && !bFound );
293 
294  rValue <<= bFound;
295  return true;
296 }
297 
299  OUString& rStrExpValue,
300  const Any& rValue,
301  const SvXMLUnitConverter& ) const
302 {
303  if( getBOOL( rValue ) )
304  {
305  if( !rStrExpValue.isEmpty() )
306  rStrExpValue += " ";
307  rStrExpValue += sAttrValue;
308  }
309 
310  return true;
311 }
312 
313 // property handler for style:table-centering
314 
316 {
317 }
318 
320  const OUString& rStrImpValue,
321  Any& rValue,
322  const SvXMLUnitConverter& ) const
323 {
324  bool bRet = false;
325 
326  if (!rStrImpValue.isEmpty())
327  if (IsXMLToken( rStrImpValue, XML_BOTH) ||
328  IsXMLToken( rStrImpValue, XML_HORIZONTAL))
329  {
330  rValue <<= true;
331  bRet = true;
332  }
333 
334  return bRet;
335 }
336 
338  OUString& rStrExpValue,
339  const Any& rValue,
340  const SvXMLUnitConverter& ) const
341 {
342  bool bRet = false;
343 
344  if ( ::cppu::any2bool( rValue ) )
345  {
346  bRet = true;
347  if (!rStrExpValue.isEmpty())
348  rStrExpValue = GetXMLToken(XML_BOTH);
349  else
350  rStrExpValue = GetXMLToken(XML_HORIZONTAL);
351  }
352 
353  return bRet;
354 }
355 
357 {
358 }
359 
361  const OUString& rStrImpValue,
362  Any& rValue,
363  const SvXMLUnitConverter& ) const
364 {
365  bool bRet = false;
366 
367  if (!rStrImpValue.isEmpty())
368  if (IsXMLToken(rStrImpValue, XML_BOTH) ||
369  IsXMLToken(rStrImpValue, XML_VERTICAL) )
370  {
371  rValue <<= true;
372  bRet = true;
373  }
374 
375  return bRet;
376 }
377 
379  OUString& rStrExpValue,
380  const Any& rValue,
381  const SvXMLUnitConverter& ) const
382 {
383  bool bRet = false;
384 
385  if ( ::cppu::any2bool( rValue ) )
386  {
387  bRet = true;
388  if (!rStrExpValue.isEmpty())
389  rStrExpValue = GetXMLToken(XML_BOTH);
390  else
391  rStrExpValue = GetXMLToken(XML_VERTICAL);
392  }
393 
394  return bRet;
395 }
396 
397 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual ~XMLPMPropHdl_Print() override
bool IsXMLToken(const OUString &rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3434
virtual bool importXML(const OUString &rStrImpValue, css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Imports the given value according to the XML-data-type corresponding to the derived class...
virtual ~XMLPMPropHdl_CenterVertical() override
bool convertNumFormat(sal_Int16 &rType, const OUString &rNumFormat, const OUString &rNumLetterSync, bool bNumberNone=false) const
convert num-format and num-letter-sync values to NumberingType
Definition: xmluconv.cxx:574
the SvXMLTypeConverter converts values of various types from their internal representation to the tex...
Definition: xmluconv.hxx:77
virtual bool importXML(const OUString &rStrImpValue, css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Imports the given value according to the XML-data-type corresponding to the derived class...
bool getBOOL(const Any &_rAny)
virtual bool importXML(const OUString &rStrImpValue, css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Imports the given value according to the XML-data-type corresponding to the derived class...
virtual ~XMLPMPropHdl_CenterHorizontal() override
virtual bool exportXML(OUString &rStrExpValue, const css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Exports the given value according to the XML-data-type corresponding to the derived class...
virtual bool importXML(const OUString &rStrImpValue, css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Imports the given value according to the XML-data-type corresponding to the derived class...
virtual bool equals(const css::uno::Any &rAny1, const css::uno::Any &rAny2) const override
Compares two Any's in case of the given XML-data-type.
css::uno::Any const & rValue
Definition: ImageStyle.hxx:38
XMLPMPropHdl_Print(enum::xmloff::token::XMLTokenEnum eValue)
virtual bool exportXML(OUString &rStrExpValue, const css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Exports the given value according to the XML-data-type corresponding to the derived class...
virtual ~XMLPMPropHdl_PageStyleLayout() override
virtual bool exportXML(OUString &rStrExpValue, const css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Exports the given value according to the XML-data-type corresponding to the derived class...
virtual bool importXML(const OUString &rStrImpValue, css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Imports the given value according to the XML-data-type corresponding to the derived class...
virtual ~XMLPMPropHdl_NumLetterSync() override
sal_Int16 nNumType
XMLTokenEnum
The enumeration of all XML tokens.
Definition: xmltoken.hxx:49
virtual bool exportXML(OUString &rStrExpValue, const css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Exports the given value according to the XML-data-type corresponding to the derived class...
virtual ~XMLPMPropHdl_NumFormat() override
virtual ~XMLPMPropHdl_PaperTrayNumber() override
virtual bool exportXML(OUString &rStrExpValue, const css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Exports the given value according to the XML-data-type corresponding to the derived class...
virtual bool exportXML(OUString &rStrExpValue, const css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Exports the given value according to the XML-data-type corresponding to the derived class...
virtual bool importXML(const OUString &rStrImpValue, css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Imports the given value according to the XML-data-type corresponding to the derived class...
virtual bool exportXML(OUString &rStrExpValue, const css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Exports the given value according to the XML-data-type corresponding to the derived class...
#define DEFAULT_PAPERTRAY
static void convertNumLetterSync(OUStringBuffer &rBuffer, sal_Int16 nType)
Definition: xmluconv.cxx:671
std::unique_ptr< char[]> aBuffer
virtual bool importXML(const OUString &rStrImpValue, css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Imports the given value according to the XML-data-type corresponding to the derived class...
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
Definition: xmltoken.cxx:3378
Handling of tokens in XML:
bool any2bool(const css::uno::Any &rAny)
static bool convertNumber(sal_Int32 &rValue, std::u16string_view aString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32)