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