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 <undlihdl.hxx> 31 #include <xmloff/xmltoken.hxx> 32 #include <xmloff/xmluconv.hxx> 33 #include <rtl/ustrbuf.hxx> 34 35 36 #include <com/sun/star/uno/Any.hxx> 37 #include <com/sun/star/awt/FontUnderline.hpp> 38 39 using ::rtl::OUString; 40 using ::rtl::OUStringBuffer; 41 42 using namespace ::com::sun::star; 43 using namespace ::com::sun::star::awt; 44 using namespace ::xmloff::token; 45 46 SvXMLEnumMapEntry __READONLY_DATA pXML_UnderlineType_Enum[] = 47 { 48 { XML_NONE, FontUnderline::NONE }, 49 { XML_SINGLE, FontUnderline::SINGLE }, 50 { XML_DOUBLE, FontUnderline::DOUBLE }, 51 { XML_SINGLE, FontUnderline::DOTTED }, 52 { XML_SINGLE, FontUnderline::DASH }, 53 { XML_SINGLE, FontUnderline::LONGDASH }, 54 { XML_SINGLE, FontUnderline::DASHDOT }, 55 { XML_SINGLE, FontUnderline::DASHDOTDOT }, 56 { XML_SINGLE, FontUnderline::WAVE }, 57 { XML_SINGLE, FontUnderline::BOLD }, 58 { XML_SINGLE, FontUnderline::BOLDDOTTED }, 59 { XML_SINGLE, FontUnderline::BOLDDASH }, 60 { XML_SINGLE, FontUnderline::BOLDLONGDASH }, 61 { XML_SINGLE, FontUnderline::BOLDDASHDOT }, 62 { XML_SINGLE, FontUnderline::BOLDDASHDOTDOT }, 63 { XML_SINGLE, FontUnderline::BOLDWAVE }, 64 { XML_DOUBLE, FontUnderline::DOUBLEWAVE }, 65 { XML_SINGLE, FontUnderline::SMALLWAVE }, 66 { XML_TOKEN_INVALID, 0 } 67 }; 68 69 SvXMLEnumMapEntry __READONLY_DATA pXML_UnderlineStyle_Enum[] = 70 { 71 { XML_NONE, FontUnderline::NONE }, 72 { XML_SOLID, FontUnderline::SINGLE }, 73 { XML_SOLID, FontUnderline::DOUBLE }, 74 { XML_DOTTED, FontUnderline::DOTTED }, 75 { XML_DASH, FontUnderline::DASH }, 76 { XML_LONG_DASH, FontUnderline::LONGDASH }, 77 { XML_DOT_DASH, FontUnderline::DASHDOT }, 78 { XML_DOT_DOT_DASH, FontUnderline::DASHDOTDOT }, 79 { XML_WAVE, FontUnderline::WAVE }, 80 { XML_SOLID, FontUnderline::BOLD }, 81 { XML_DOTTED, FontUnderline::BOLDDOTTED }, 82 { XML_DASH, FontUnderline::BOLDDASH }, 83 { XML_LONG_DASH, FontUnderline::BOLDLONGDASH }, 84 { XML_DOT_DASH, FontUnderline::BOLDDASHDOT }, 85 { XML_DOT_DOT_DASH, FontUnderline::BOLDDASHDOTDOT }, 86 { XML_WAVE, FontUnderline::BOLDWAVE }, 87 { XML_WAVE, FontUnderline::DOUBLEWAVE }, 88 { XML_SMALL_WAVE, FontUnderline::SMALLWAVE }, 89 { XML_TOKEN_INVALID, 0 } 90 }; 91 92 SvXMLEnumMapEntry __READONLY_DATA pXML_UnderlineWidth_Enum[] = 93 { 94 { XML_AUTO, FontUnderline::NONE }, 95 { XML_AUTO, FontUnderline::SINGLE }, 96 { XML_AUTO, FontUnderline::DOUBLE }, 97 { XML_AUTO, FontUnderline::DOTTED }, 98 { XML_AUTO, FontUnderline::DASH }, 99 { XML_AUTO, FontUnderline::LONGDASH }, 100 { XML_AUTO, FontUnderline::DASHDOT }, 101 { XML_AUTO, FontUnderline::DASHDOTDOT }, 102 { XML_AUTO, FontUnderline::WAVE }, 103 { XML_BOLD, FontUnderline::BOLD }, 104 { XML_BOLD, FontUnderline::BOLDDOTTED }, 105 { XML_BOLD, FontUnderline::BOLDDASH }, 106 { XML_BOLD, FontUnderline::BOLDLONGDASH }, 107 { XML_BOLD, FontUnderline::BOLDDASHDOT }, 108 { XML_BOLD, FontUnderline::BOLDDASHDOTDOT }, 109 { XML_BOLD, FontUnderline::BOLDWAVE }, 110 { XML_AUTO, FontUnderline::DOUBLEWAVE }, 111 { XML_THIN, FontUnderline::NONE }, 112 { XML_MEDIUM, FontUnderline::NONE }, 113 { XML_THICK, FontUnderline::BOLD}, 114 { XML_TOKEN_INVALID, 0 } 115 }; 116 117 118 119 /////////////////////////////////////////////////////////////////////////////// 120 // 121 // class XMLUnderlineTypePropHdl 122 // 123 124 XMLUnderlineTypePropHdl::~XMLUnderlineTypePropHdl() 125 { 126 // nothing to do 127 } 128 129 sal_Bool XMLUnderlineTypePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const 130 { 131 sal_uInt16 eNewUnderline; 132 sal_Bool bRet = SvXMLUnitConverter::convertEnum( 133 eNewUnderline, rStrImpValue, pXML_UnderlineType_Enum ); 134 if( bRet ) 135 { 136 // multi property: style and width might be set already. 137 // If the old value is NONE, the new is used unchanged. 138 sal_Int16 eUnderline = sal_Int16(); 139 if( (rValue >>= eUnderline) && FontUnderline::NONE!=eUnderline ) 140 { 141 switch( eNewUnderline ) 142 { 143 case FontUnderline::NONE: 144 case FontUnderline::SINGLE: 145 // keep existing line style 146 eNewUnderline = eUnderline; 147 break; 148 case FontUnderline::DOUBLE: 149 // A double line style has priority over a bold line style, 150 // but not over the line style itself. 151 switch( eUnderline ) 152 { 153 case FontUnderline::SINGLE: 154 case FontUnderline::BOLD: 155 break; 156 case FontUnderline::WAVE: 157 case FontUnderline::BOLDWAVE: 158 eNewUnderline = FontUnderline::DOUBLEWAVE; 159 break; 160 default: 161 // If a double line style is not supported for the existing 162 // value, keep the new one 163 eNewUnderline = eUnderline; 164 break; 165 } 166 break; 167 default: 168 OSL_ENSURE( bRet, "unexpected line type value" ); 169 break; 170 } 171 if( eNewUnderline != eUnderline ) 172 rValue <<= (sal_Int16)eNewUnderline; 173 } 174 else 175 { 176 rValue <<= (sal_Int16)eNewUnderline; 177 } 178 } 179 180 return bRet; 181 } 182 183 sal_Bool XMLUnderlineTypePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const 184 { 185 sal_Bool bRet = sal_False; 186 sal_Int16 nValue = sal_Int16(); 187 OUStringBuffer aOut; 188 189 if( (rValue >>= nValue) && 190 (FontUnderline::DOUBLE == nValue || 191 FontUnderline::DOUBLEWAVE == nValue) ) 192 { 193 bRet = SvXMLUnitConverter::convertEnum( 194 aOut, (sal_uInt16)nValue, pXML_UnderlineType_Enum ); 195 if( bRet ) 196 rStrExpValue = aOut.makeStringAndClear(); 197 } 198 199 return bRet; 200 } 201 202 /////////////////////////////////////////////////////////////////////////////// 203 // 204 // class XMLUnderlineStylePropHdl 205 // 206 207 XMLUnderlineStylePropHdl::~XMLUnderlineStylePropHdl() 208 { 209 // nothing to do 210 } 211 212 sal_Bool XMLUnderlineStylePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const 213 { 214 sal_uInt16 eNewUnderline; 215 sal_Bool bRet = SvXMLUnitConverter::convertEnum( 216 eNewUnderline, rStrImpValue, pXML_UnderlineStyle_Enum ); 217 if( bRet ) 218 { 219 // multi property: style and width might be set already. 220 // If the old value is NONE, the new is used unchanged. 221 sal_Int16 eUnderline = sal_Int16(); 222 if( (rValue >>= eUnderline) && FontUnderline::NONE!=eUnderline ) 223 { 224 switch( eNewUnderline ) 225 { 226 case FontUnderline::NONE: 227 case FontUnderline::SINGLE: 228 // keep double or bold line style 229 eNewUnderline = eUnderline; 230 case FontUnderline::DOTTED: 231 // The line style has priority over a double type. 232 if( FontUnderline::BOLD == eUnderline ) 233 eNewUnderline = FontUnderline::BOLDDOTTED; 234 break; 235 case FontUnderline::DASH: 236 if( FontUnderline::BOLD == eUnderline ) 237 eNewUnderline = FontUnderline::BOLDDASH; 238 break; 239 case FontUnderline::LONGDASH: 240 if( FontUnderline::BOLD == eUnderline ) 241 eNewUnderline = FontUnderline::BOLDLONGDASH; 242 break; 243 case FontUnderline::DASHDOT: 244 if( FontUnderline::BOLD == eUnderline ) 245 eNewUnderline = FontUnderline::BOLDDASHDOT; 246 break; 247 case FontUnderline::DASHDOTDOT: 248 if( FontUnderline::BOLD == eUnderline ) 249 eNewUnderline = FontUnderline::BOLDDASHDOTDOT; 250 break; 251 case FontUnderline::WAVE: 252 if( FontUnderline::BOLD == eUnderline ) 253 eNewUnderline = FontUnderline::BOLDWAVE; 254 break; 255 case FontUnderline::SMALLWAVE: 256 // SMALLWAVE is not used 257 default: 258 OSL_ENSURE( bRet, "unexpected line style value" ); 259 break; 260 } 261 if( eNewUnderline != eUnderline ) 262 rValue <<= (sal_Int16)eNewUnderline; 263 } 264 else 265 { 266 rValue <<= (sal_Int16)eNewUnderline; 267 } 268 } 269 270 return bRet; 271 } 272 273 sal_Bool XMLUnderlineStylePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const 274 { 275 sal_Bool bRet = sal_False; 276 sal_Int16 nValue = sal_Int16(); 277 OUStringBuffer aOut; 278 279 if( rValue >>= nValue ) 280 { 281 bRet = SvXMLUnitConverter::convertEnum( 282 aOut, (sal_uInt16)nValue, pXML_UnderlineStyle_Enum ); 283 if( bRet ) 284 rStrExpValue = aOut.makeStringAndClear(); 285 } 286 287 return bRet; 288 } 289 290 /////////////////////////////////////////////////////////////////////////////// 291 // 292 // class XMLUnderlineWidthPropHdl 293 // 294 295 XMLUnderlineWidthPropHdl::~XMLUnderlineWidthPropHdl() 296 { 297 // nothing to do 298 } 299 300 sal_Bool XMLUnderlineWidthPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const 301 { 302 sal_uInt16 eNewUnderline; 303 sal_Bool bRet = SvXMLUnitConverter::convertEnum( 304 eNewUnderline, rStrImpValue, pXML_UnderlineWidth_Enum ); 305 if( bRet ) 306 { 307 // multi property: style and width might be set already. 308 // If the old value is NONE, the new is used unchanged. 309 sal_Int16 eUnderline = sal_Int16(); 310 if( (rValue >>= eUnderline) && FontUnderline::NONE!=eUnderline ) 311 { 312 switch( eNewUnderline ) 313 { 314 case FontUnderline::NONE: 315 // keep existing line style 316 eNewUnderline = eUnderline; 317 break; 318 case FontUnderline::BOLD: 319 // A double line style has priority over a bold line style, 320 // but not over the line style itself. 321 switch( eUnderline ) 322 { 323 case FontUnderline::SINGLE: 324 break; 325 case FontUnderline::DOTTED: 326 eNewUnderline = FontUnderline::BOLDDOTTED; 327 break; 328 case FontUnderline::DASH: 329 eNewUnderline = FontUnderline::BOLDDASH; 330 break; 331 case FontUnderline::LONGDASH: 332 eNewUnderline = FontUnderline::BOLDLONGDASH; 333 break; 334 case FontUnderline::DASHDOT: 335 eNewUnderline = FontUnderline::BOLDDASHDOT; 336 break; 337 case FontUnderline::DASHDOTDOT: 338 eNewUnderline = FontUnderline::BOLDDASHDOTDOT; 339 break; 340 case FontUnderline::WAVE: 341 eNewUnderline = FontUnderline::BOLDWAVE; 342 break; 343 default: 344 // a doube line style overwrites a bold one 345 eNewUnderline = eUnderline; 346 break; 347 } 348 break; 349 default: 350 OSL_ENSURE( bRet, "unexpected line width value" ); 351 break; 352 } 353 if( eNewUnderline != eUnderline ) 354 rValue <<= (sal_Int16)eNewUnderline; 355 } 356 else 357 { 358 rValue <<= (sal_Int16)eNewUnderline; 359 } 360 } 361 362 return bRet; 363 } 364 365 sal_Bool XMLUnderlineWidthPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const 366 { 367 sal_Bool bRet = sal_False; 368 sal_Int16 nValue = sal_Int16(); 369 OUStringBuffer aOut; 370 371 if( (rValue >>= nValue) && (FontUnderline::NONE != nValue) ) 372 { 373 bRet = SvXMLUnitConverter::convertEnum( 374 aOut, (sal_uInt16)nValue, pXML_UnderlineWidth_Enum ); 375 if( bRet ) 376 rStrExpValue = aOut.makeStringAndClear(); 377 } 378 379 return bRet; 380 } 381 382