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