1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_xmloff.hxx" 30 #include "PageMasterPropHdl.hxx" 31 #include <xmloff/xmltoken.hxx> 32 #include <xmloff/xmluconv.hxx> 33 #include <xmloff/xmlnumi.hxx> 34 #include <xmloff/xmlnume.hxx> 35 #include <rtl/ustrbuf.hxx> 36 #include <com/sun/star/uno/Any.hxx> 37 #include <com/sun/star/style/PageStyleLayout.hpp> 38 #include <comphelper/types.hxx> 39 #include <comphelper/extract.hxx> 40 41 using ::rtl::OUString; 42 using ::rtl::OUStringBuffer; 43 44 using namespace ::com::sun::star; 45 using namespace ::com::sun::star::uno; 46 using namespace ::com::sun::star::style; 47 using namespace ::comphelper; 48 using namespace ::xmloff::token; 49 50 51 //______________________________________________________________________________ 52 53 #define DEFAULT_PAPERTRAY (sal_Int32(-1)) 54 55 56 //______________________________________________________________________________ 57 // property handler for style:page-usage (style::PageStyleLayout) 58 59 XMLPMPropHdl_PageStyleLayout::~XMLPMPropHdl_PageStyleLayout() 60 { 61 } 62 63 bool XMLPMPropHdl_PageStyleLayout::equals( const Any& rAny1, const Any& rAny2 ) const 64 { 65 style::PageStyleLayout eLayout1, eLayout2; 66 return ((rAny1 >>= eLayout1) && (rAny2 >>= eLayout2)) ? (eLayout1 == eLayout2) : sal_False; 67 } 68 69 sal_Bool XMLPMPropHdl_PageStyleLayout::importXML( 70 const OUString& rStrImpValue, 71 Any& rValue, 72 const SvXMLUnitConverter& ) const 73 { 74 sal_Bool bRet = sal_True; 75 76 if( IsXMLToken( rStrImpValue, XML_ALL ) ) 77 rValue <<= PageStyleLayout_ALL; 78 else if( IsXMLToken( rStrImpValue, XML_LEFT ) ) 79 rValue <<= PageStyleLayout_LEFT; 80 else if( IsXMLToken( rStrImpValue, XML_RIGHT ) ) 81 rValue <<= PageStyleLayout_RIGHT; 82 else if( IsXMLToken( rStrImpValue, XML_MIRRORED ) ) 83 rValue <<= PageStyleLayout_MIRRORED; 84 else 85 bRet = sal_False; 86 87 return bRet; 88 } 89 90 sal_Bool XMLPMPropHdl_PageStyleLayout::exportXML( 91 OUString& rStrExpValue, 92 const Any& rValue, 93 const SvXMLUnitConverter& ) const 94 { 95 sal_Bool bRet = sal_False; 96 PageStyleLayout eLayout; 97 98 if( rValue >>= eLayout ) 99 { 100 bRet = sal_True; 101 switch( eLayout ) 102 { 103 case PageStyleLayout_ALL: 104 rStrExpValue = GetXMLToken( XML_ALL ); 105 break; 106 case PageStyleLayout_LEFT: 107 rStrExpValue = GetXMLToken( XML_LEFT ); 108 break; 109 case PageStyleLayout_RIGHT: 110 rStrExpValue = GetXMLToken( XML_RIGHT ); 111 break; 112 case PageStyleLayout_MIRRORED: 113 rStrExpValue = GetXMLToken( XML_MIRRORED ); 114 break; 115 default: 116 bRet = sal_False; 117 } 118 } 119 120 return bRet; 121 } 122 123 124 //______________________________________________________________________________ 125 // property handler for style:num-format (style::NumberingType) 126 127 XMLPMPropHdl_NumFormat::~XMLPMPropHdl_NumFormat() 128 { 129 } 130 131 sal_Bool XMLPMPropHdl_NumFormat::importXML( 132 const OUString& rStrImpValue, 133 Any& rValue, 134 const SvXMLUnitConverter& rUnitConverter ) const 135 { 136 sal_Int16 nSync = sal_Int16(); 137 sal_Int16 nNumType = NumberingType::NUMBER_NONE; 138 rUnitConverter.convertNumFormat( nNumType, rStrImpValue, OUString(), 139 sal_True ); 140 141 if( !(rValue >>= nSync) ) 142 nSync = NumberingType::NUMBER_NONE; 143 144 // if num-letter-sync appears before num-format, the function 145 // XMLPMPropHdl_NumLetterSync::importXML() sets the value 146 // NumberingType::CHARS_LOWER_LETTER_N 147 if( nSync == NumberingType::CHARS_LOWER_LETTER_N ) 148 { 149 switch( nNumType ) 150 { 151 case NumberingType::CHARS_LOWER_LETTER: 152 nNumType = NumberingType::CHARS_LOWER_LETTER_N; 153 break; 154 case NumberingType::CHARS_UPPER_LETTER: 155 nNumType = NumberingType::CHARS_UPPER_LETTER_N; 156 break; 157 } 158 } 159 rValue <<= nNumType; 160 161 return sal_True; 162 } 163 164 sal_Bool XMLPMPropHdl_NumFormat::exportXML( 165 OUString& rStrExpValue, 166 const Any& rValue, 167 const SvXMLUnitConverter& rUnitConverter ) const 168 { 169 sal_Bool bRet = sal_False; 170 sal_Int16 nNumType = sal_Int16(); 171 172 if( rValue >>= nNumType ) 173 { 174 OUStringBuffer aBuffer( 10 ); 175 rUnitConverter.convertNumFormat( aBuffer, nNumType ); 176 rStrExpValue = aBuffer.makeStringAndClear(); 177 bRet = sal_True; 178 } 179 return bRet; 180 } 181 182 183 //______________________________________________________________________________ 184 // property handler for style:num-letter-sync (style::NumberingType) 185 186 XMLPMPropHdl_NumLetterSync::~XMLPMPropHdl_NumLetterSync() 187 { 188 } 189 190 sal_Bool XMLPMPropHdl_NumLetterSync::importXML( 191 const OUString& rStrImpValue, 192 Any& rValue, 193 const SvXMLUnitConverter& rUnitConverter ) const 194 { 195 sal_Int16 nNumType; 196 sal_Int16 nSync = NumberingType::NUMBER_NONE; 197 rUnitConverter.convertNumFormat( nSync, rStrImpValue, 198 GetXMLToken( XML_A ), sal_True ); 199 200 if( !(rValue >>= nNumType) ) 201 nNumType = NumberingType::NUMBER_NONE; 202 203 if( nSync == NumberingType::CHARS_LOWER_LETTER_N ) 204 { 205 switch( nNumType ) 206 { 207 case NumberingType::CHARS_LOWER_LETTER: 208 nNumType = NumberingType::CHARS_LOWER_LETTER_N; 209 break; 210 case NumberingType::CHARS_UPPER_LETTER: 211 nNumType = NumberingType::CHARS_UPPER_LETTER_N; 212 break; 213 } 214 } 215 rValue <<= nNumType; 216 217 return sal_True; 218 } 219 220 sal_Bool XMLPMPropHdl_NumLetterSync::exportXML( 221 OUString& rStrExpValue, 222 const Any& rValue, 223 const SvXMLUnitConverter& rUnitConverter ) const 224 { 225 sal_Bool bRet = sal_False; 226 sal_Int16 nNumType = sal_Int16(); 227 228 if( rValue >>= nNumType ) 229 { 230 OUStringBuffer aBuffer( 5 ); 231 rUnitConverter.convertNumLetterSync( aBuffer, nNumType ); 232 rStrExpValue = aBuffer.makeStringAndClear(); 233 bRet = rStrExpValue.getLength() > 0; 234 } 235 return bRet; 236 } 237 238 239 //______________________________________________________________________________ 240 // property handler for style:paper-tray-number 241 242 XMLPMPropHdl_PaperTrayNumber::~XMLPMPropHdl_PaperTrayNumber() 243 { 244 } 245 246 sal_Bool XMLPMPropHdl_PaperTrayNumber::importXML( 247 const OUString& rStrImpValue, 248 Any& rValue, 249 const SvXMLUnitConverter& ) const 250 { 251 sal_Bool bRet = sal_False; 252 253 if( IsXMLToken( rStrImpValue, XML_DEFAULT ) ) 254 { 255 rValue <<= DEFAULT_PAPERTRAY; 256 bRet = sal_True; 257 } 258 else 259 { 260 sal_Int32 nPaperTray; 261 if( SvXMLUnitConverter::convertNumber( nPaperTray, rStrImpValue, 0 ) ) 262 { 263 rValue <<= nPaperTray; 264 bRet = sal_True; 265 } 266 } 267 268 return bRet; 269 } 270 271 sal_Bool XMLPMPropHdl_PaperTrayNumber::exportXML( 272 OUString& rStrExpValue, 273 const Any& rValue, 274 const SvXMLUnitConverter& ) const 275 { 276 sal_Bool bRet = sal_False; 277 sal_Int32 nPaperTray = 0; 278 279 if( rValue >>= nPaperTray ) 280 { 281 if( nPaperTray == DEFAULT_PAPERTRAY ) 282 rStrExpValue = GetXMLToken( XML_DEFAULT ); 283 else 284 { 285 OUStringBuffer aBuffer; 286 SvXMLUnitConverter::convertNumber( aBuffer, nPaperTray ); 287 rStrExpValue = aBuffer.makeStringAndClear(); 288 } 289 bRet = sal_True; 290 } 291 return bRet; 292 } 293 294 295 //______________________________________________________________________________ 296 // property handler for style:print 297 298 XMLPMPropHdl_Print::XMLPMPropHdl_Print( enum XMLTokenEnum eValue ) : 299 sAttrValue( GetXMLToken( eValue ) ) 300 { 301 } 302 303 XMLPMPropHdl_Print::~XMLPMPropHdl_Print() 304 { 305 } 306 307 sal_Bool XMLPMPropHdl_Print::importXML( 308 const OUString& rStrImpValue, 309 Any& rValue, 310 const SvXMLUnitConverter& ) const 311 { 312 sal_Unicode cToken = ' '; 313 sal_Int32 nTokenIndex = 0; 314 sal_Bool bFound = sal_False; 315 316 do 317 { 318 bFound = (sAttrValue == rStrImpValue.getToken( 0, cToken, nTokenIndex )); 319 } 320 while ( (nTokenIndex >= 0) && !bFound ); 321 322 setBOOL( rValue, bFound ); 323 return sal_True; 324 } 325 326 sal_Bool XMLPMPropHdl_Print::exportXML( 327 OUString& rStrExpValue, 328 const Any& rValue, 329 const SvXMLUnitConverter& ) const 330 { 331 if( getBOOL( rValue ) ) 332 { 333 if( rStrExpValue.getLength() ) 334 rStrExpValue += OUString( RTL_CONSTASCII_USTRINGPARAM( " " ) ); 335 rStrExpValue += sAttrValue; 336 } 337 338 return sal_True; 339 } 340 341 //______________________________________________________________________________ 342 // property handler for style:table-centering 343 344 XMLPMPropHdl_CenterHorizontal::~XMLPMPropHdl_CenterHorizontal() 345 { 346 } 347 348 sal_Bool XMLPMPropHdl_CenterHorizontal::importXML( 349 const OUString& rStrImpValue, 350 Any& rValue, 351 const SvXMLUnitConverter& ) const 352 { 353 sal_Bool bRet = sal_False; 354 355 if (rStrImpValue.getLength()) 356 if (IsXMLToken( rStrImpValue, XML_BOTH) || 357 IsXMLToken( rStrImpValue, XML_HORIZONTAL)) 358 { 359 rValue = ::cppu::bool2any(sal_True); 360 bRet = sal_True; 361 } 362 363 364 return bRet; 365 } 366 367 sal_Bool XMLPMPropHdl_CenterHorizontal::exportXML( 368 OUString& rStrExpValue, 369 const Any& rValue, 370 const SvXMLUnitConverter& ) const 371 { 372 sal_Bool bRet = sal_False; 373 374 if ( ::cppu::any2bool( rValue ) ) 375 { 376 bRet = sal_True; 377 if (rStrExpValue.getLength()) 378 rStrExpValue = GetXMLToken(XML_BOTH); 379 else 380 rStrExpValue = GetXMLToken(XML_HORIZONTAL); 381 } 382 383 return bRet; 384 } 385 386 XMLPMPropHdl_CenterVertical::~XMLPMPropHdl_CenterVertical() 387 { 388 } 389 390 sal_Bool XMLPMPropHdl_CenterVertical::importXML( 391 const OUString& rStrImpValue, 392 Any& rValue, 393 const SvXMLUnitConverter& ) const 394 { 395 sal_Bool bRet = sal_False; 396 397 if (rStrImpValue.getLength()) 398 if (IsXMLToken(rStrImpValue, XML_BOTH) || 399 IsXMLToken(rStrImpValue, XML_VERTICAL) ) 400 { 401 rValue = ::cppu::bool2any(sal_True); 402 bRet = sal_True; 403 } 404 405 return bRet; 406 } 407 408 sal_Bool XMLPMPropHdl_CenterVertical::exportXML( 409 OUString& rStrExpValue, 410 const Any& rValue, 411 const SvXMLUnitConverter& ) const 412 { 413 sal_Bool bRet = sal_False; 414 415 if ( ::cppu::any2bool( rValue ) ) 416 { 417 bRet = sal_True; 418 if (rStrExpValue.getLength()) 419 rStrExpValue = GetXMLToken(XML_BOTH); 420 else 421 rStrExpValue = GetXMLToken(XML_VERTICAL); 422 } 423 424 return bRet; 425 } 426 427