tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / xmloff / source / style / PageMasterPropHdl.cxx
blobc1fb9010b70fd2d7b53b2fc3813df194ba8e4b74
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "PageMasterPropHdl.hxx"
22 #include <sax/tools/converter.hxx>
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>
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;
40 #define DEFAULT_PAPERTRAY (sal_Int32(-1))
42 // property handler for style:page-usage (style::PageStyleLayout)
44 XMLPMPropHdl_PageStyleLayout::~XMLPMPropHdl_PageStyleLayout()
48 bool XMLPMPropHdl_PageStyleLayout::equals( const Any& rAny1, const Any& rAny2 ) const
50 style::PageStyleLayout eLayout1, eLayout2;
51 return (rAny1 >>= eLayout1) && (rAny2 >>= eLayout2) && (eLayout1 == eLayout2);
54 bool XMLPMPropHdl_PageStyleLayout::importXML(
55 const OUString& rStrImpValue,
56 Any& rValue,
57 const SvXMLUnitConverter& ) const
59 bool bRet = true;
61 if( IsXMLToken( rStrImpValue, XML_ALL ) )
62 rValue <<= PageStyleLayout_ALL;
63 else if( IsXMLToken( rStrImpValue, XML_LEFT ) )
64 rValue <<= PageStyleLayout_LEFT;
65 else if( IsXMLToken( rStrImpValue, XML_RIGHT ) )
66 rValue <<= PageStyleLayout_RIGHT;
67 else if( IsXMLToken( rStrImpValue, XML_MIRRORED ) )
68 rValue <<= PageStyleLayout_MIRRORED;
69 else
70 bRet = false;
72 return bRet;
75 bool XMLPMPropHdl_PageStyleLayout::exportXML(
76 OUString& rStrExpValue,
77 const Any& rValue,
78 const SvXMLUnitConverter& ) const
80 bool bRet = false;
81 PageStyleLayout eLayout;
83 if( rValue >>= eLayout )
85 bRet = true;
86 switch( eLayout )
88 case PageStyleLayout_ALL:
89 rStrExpValue = GetXMLToken( XML_ALL );
90 break;
91 case PageStyleLayout_LEFT:
92 rStrExpValue = GetXMLToken( XML_LEFT );
93 break;
94 case PageStyleLayout_RIGHT:
95 rStrExpValue = GetXMLToken( XML_RIGHT );
96 break;
97 case PageStyleLayout_MIRRORED:
98 rStrExpValue = GetXMLToken( XML_MIRRORED );
99 break;
100 default:
101 bRet = false;
105 return bRet;
108 // property handler for style:num-format (style::NumberingType)
110 XMLPMPropHdl_NumFormat::~XMLPMPropHdl_NumFormat()
114 bool XMLPMPropHdl_NumFormat::importXML(
115 const OUString& rStrImpValue,
116 Any& rValue,
117 const SvXMLUnitConverter& rUnitConverter ) const
119 sal_Int16 nSync = sal_Int16();
120 sal_Int16 nNumType = NumberingType::NUMBER_NONE;
121 rUnitConverter.convertNumFormat( nNumType, rStrImpValue, u"", true );
123 if( !(rValue >>= nSync) )
124 nSync = NumberingType::NUMBER_NONE;
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 if( nSync == NumberingType::CHARS_LOWER_LETTER_N )
131 switch( nNumType )
133 case NumberingType::CHARS_LOWER_LETTER:
134 nNumType = NumberingType::CHARS_LOWER_LETTER_N;
135 break;
136 case NumberingType::CHARS_UPPER_LETTER:
137 nNumType = NumberingType::CHARS_UPPER_LETTER_N;
138 break;
141 rValue <<= nNumType;
143 return true;
146 bool XMLPMPropHdl_NumFormat::exportXML(
147 OUString& rStrExpValue,
148 const Any& rValue,
149 const SvXMLUnitConverter& rUnitConverter ) const
151 bool bRet = false;
152 sal_Int16 nNumType = sal_Int16();
154 if( rValue >>= nNumType )
156 OUStringBuffer aBuffer( 10 );
157 rUnitConverter.convertNumFormat( aBuffer, nNumType );
158 rStrExpValue = aBuffer.makeStringAndClear();
159 bRet = true;
161 return bRet;
164 // property handler for style:num-letter-sync (style::NumberingType)
166 XMLPMPropHdl_NumLetterSync::~XMLPMPropHdl_NumLetterSync()
170 bool XMLPMPropHdl_NumLetterSync::importXML(
171 const OUString& rStrImpValue,
172 Any& rValue,
173 const SvXMLUnitConverter& rUnitConverter ) const
175 sal_Int16 nNumType;
176 sal_Int16 nSync = NumberingType::NUMBER_NONE;
177 rUnitConverter.convertNumFormat( nSync, rStrImpValue,
178 GetXMLToken( XML_A ), true );
180 if( !(rValue >>= nNumType) )
181 nNumType = NumberingType::NUMBER_NONE;
183 if( nSync == NumberingType::CHARS_LOWER_LETTER_N )
185 switch( nNumType )
187 case NumberingType::CHARS_LOWER_LETTER:
188 nNumType = NumberingType::CHARS_LOWER_LETTER_N;
189 break;
190 case NumberingType::CHARS_UPPER_LETTER:
191 nNumType = NumberingType::CHARS_UPPER_LETTER_N;
192 break;
195 rValue <<= nNumType;
197 return true;
200 bool XMLPMPropHdl_NumLetterSync::exportXML(
201 OUString& rStrExpValue,
202 const Any& rValue,
203 const SvXMLUnitConverter& /*rUnitConverter*/ ) const
205 bool bRet = false;
206 sal_Int16 nNumType = sal_Int16();
208 if( rValue >>= nNumType )
210 OUStringBuffer aBuffer( 5 );
211 SvXMLUnitConverter::convertNumLetterSync( aBuffer, nNumType );
212 rStrExpValue = aBuffer.makeStringAndClear();
213 bRet = !rStrExpValue.isEmpty();
215 return bRet;
218 // property handler for style:paper-tray-number
220 XMLPMPropHdl_PaperTrayNumber::~XMLPMPropHdl_PaperTrayNumber()
224 bool XMLPMPropHdl_PaperTrayNumber::importXML(
225 const OUString& rStrImpValue,
226 Any& rValue,
227 const SvXMLUnitConverter& ) const
229 bool bRet = false;
231 if( IsXMLToken( rStrImpValue, XML_DEFAULT ) )
233 rValue <<= DEFAULT_PAPERTRAY;
234 bRet = true;
236 else
238 sal_Int32 nPaperTray;
239 if (::sax::Converter::convertNumber( nPaperTray, rStrImpValue, 0 ))
241 rValue <<= nPaperTray;
242 bRet = true;
246 return bRet;
249 bool XMLPMPropHdl_PaperTrayNumber::exportXML(
250 OUString& rStrExpValue,
251 const Any& rValue,
252 const SvXMLUnitConverter& ) const
254 bool bRet = false;
255 sal_Int32 nPaperTray = 0;
257 if( rValue >>= nPaperTray )
259 if( nPaperTray == DEFAULT_PAPERTRAY )
260 rStrExpValue = GetXMLToken( XML_DEFAULT );
261 else
263 rStrExpValue = OUString::number( nPaperTray );
265 bRet = true;
267 return bRet;
270 // property handler for style:print
272 XMLPMPropHdl_Print::XMLPMPropHdl_Print( enum XMLTokenEnum eValue ) :
273 sAttrValue( GetXMLToken( eValue ) )
277 XMLPMPropHdl_Print::~XMLPMPropHdl_Print()
281 bool XMLPMPropHdl_Print::importXML(
282 const OUString& rStrImpValue,
283 Any& rValue,
284 const SvXMLUnitConverter& ) const
286 sal_Int32 nTokenIndex = 0;
287 bool bFound = false;
291 bFound = (sAttrValue == o3tl::getToken(rStrImpValue, 0, ' ', nTokenIndex ));
293 while ( (nTokenIndex >= 0) && !bFound );
295 rValue <<= bFound;
296 return true;
299 bool XMLPMPropHdl_Print::exportXML(
300 OUString& rStrExpValue,
301 const Any& rValue,
302 const SvXMLUnitConverter& ) const
304 if( getBOOL( rValue ) )
306 if( !rStrExpValue.isEmpty() )
307 rStrExpValue += " ";
308 rStrExpValue += sAttrValue;
311 return true;
314 // property handler for style:table-centering
316 XMLPMPropHdl_CenterHorizontal::~XMLPMPropHdl_CenterHorizontal()
320 bool XMLPMPropHdl_CenterHorizontal::importXML(
321 const OUString& rStrImpValue,
322 Any& rValue,
323 const SvXMLUnitConverter& ) const
325 bool bRet = false;
327 if (!rStrImpValue.isEmpty())
328 if (IsXMLToken( rStrImpValue, XML_BOTH) ||
329 IsXMLToken( rStrImpValue, XML_HORIZONTAL))
331 rValue <<= true;
332 bRet = true;
335 return bRet;
338 bool XMLPMPropHdl_CenterHorizontal::exportXML(
339 OUString& rStrExpValue,
340 const Any& rValue,
341 const SvXMLUnitConverter& ) const
343 bool bRet = false;
345 if ( ::cppu::any2bool( rValue ) )
347 bRet = true;
348 if (!rStrExpValue.isEmpty())
349 rStrExpValue = GetXMLToken(XML_BOTH);
350 else
351 rStrExpValue = GetXMLToken(XML_HORIZONTAL);
354 return bRet;
357 XMLPMPropHdl_CenterVertical::~XMLPMPropHdl_CenterVertical()
361 bool XMLPMPropHdl_CenterVertical::importXML(
362 const OUString& rStrImpValue,
363 Any& rValue,
364 const SvXMLUnitConverter& ) const
366 bool bRet = false;
368 if (!rStrImpValue.isEmpty())
369 if (IsXMLToken(rStrImpValue, XML_BOTH) ||
370 IsXMLToken(rStrImpValue, XML_VERTICAL) )
372 rValue <<= true;
373 bRet = true;
376 return bRet;
379 bool XMLPMPropHdl_CenterVertical::exportXML(
380 OUString& rStrExpValue,
381 const Any& rValue,
382 const SvXMLUnitConverter& ) const
384 bool bRet = false;
386 if ( ::cppu::any2bool( rValue ) )
388 bRet = true;
389 if (!rStrExpValue.isEmpty())
390 rStrExpValue = GetXMLToken(XML_BOTH);
391 else
392 rStrExpValue = GetXMLToken(XML_VERTICAL);
395 return bRet;
398 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */