1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_xmloff.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir #include <bordrhdl.hxx> 33*cdf0e10cSrcweir #include <xmloff/xmltoken.hxx> 34*cdf0e10cSrcweir #include <xmloff/xmluconv.hxx> 35*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 36*cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx> 37*cdf0e10cSrcweir #include <com/sun/star/table/BorderLine.hpp> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir using ::rtl::OUString; 40*cdf0e10cSrcweir using ::rtl::OUStringBuffer; 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir using namespace ::com::sun::star; 43*cdf0e10cSrcweir using namespace ::xmloff::token; 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir // copied from svx/boxitem.hxx 46*cdf0e10cSrcweir #define DEF_LINE_WIDTH_0 1 47*cdf0e10cSrcweir #define DEF_LINE_WIDTH_1 35 48*cdf0e10cSrcweir #define DEF_LINE_WIDTH_2 88 49*cdf0e10cSrcweir #define DEF_LINE_WIDTH_3 141 50*cdf0e10cSrcweir #define DEF_LINE_WIDTH_4 176 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir #define DEF_MAX_LINE_WIDHT DEF_LINE_WIDTH_4 53*cdf0e10cSrcweir #define DEF_MAX_LINE_DIST DEF_LINE_WIDTH_2 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir #define DEF_DOUBLE_LINE0_OUT DEF_LINE_WIDTH_0 56*cdf0e10cSrcweir #define DEF_DOUBLE_LINE0_IN DEF_LINE_WIDTH_0 57*cdf0e10cSrcweir #define DEF_DOUBLE_LINE0_DIST DEF_LINE_WIDTH_1 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir #define DEF_DOUBLE_LINE1_OUT DEF_LINE_WIDTH_1 60*cdf0e10cSrcweir #define DEF_DOUBLE_LINE1_IN DEF_LINE_WIDTH_1 61*cdf0e10cSrcweir #define DEF_DOUBLE_LINE1_DIST DEF_LINE_WIDTH_1 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir #define DEF_DOUBLE_LINE2_OUT DEF_LINE_WIDTH_2 64*cdf0e10cSrcweir #define DEF_DOUBLE_LINE2_IN DEF_LINE_WIDTH_2 65*cdf0e10cSrcweir #define DEF_DOUBLE_LINE2_DIST DEF_LINE_WIDTH_2 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir #define DEF_DOUBLE_LINE3_OUT DEF_LINE_WIDTH_2 68*cdf0e10cSrcweir #define DEF_DOUBLE_LINE3_IN DEF_LINE_WIDTH_1 69*cdf0e10cSrcweir #define DEF_DOUBLE_LINE3_DIST DEF_LINE_WIDTH_2 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir #define DEF_DOUBLE_LINE4_OUT DEF_LINE_WIDTH_1 72*cdf0e10cSrcweir #define DEF_DOUBLE_LINE4_IN DEF_LINE_WIDTH_2 73*cdf0e10cSrcweir #define DEF_DOUBLE_LINE4_DIST DEF_LINE_WIDTH_1 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir #define DEF_DOUBLE_LINE5_OUT DEF_LINE_WIDTH_3 76*cdf0e10cSrcweir #define DEF_DOUBLE_LINE5_IN DEF_LINE_WIDTH_2 77*cdf0e10cSrcweir #define DEF_DOUBLE_LINE5_DIST DEF_LINE_WIDTH_2 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir #define DEF_DOUBLE_LINE6_OUT DEF_LINE_WIDTH_2 80*cdf0e10cSrcweir #define DEF_DOUBLE_LINE6_IN DEF_LINE_WIDTH_3 81*cdf0e10cSrcweir #define DEF_DOUBLE_LINE6_DIST DEF_LINE_WIDTH_2 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir #define DEF_DOUBLE_LINE7_OUT DEF_LINE_WIDTH_0 84*cdf0e10cSrcweir #define DEF_DOUBLE_LINE7_IN DEF_LINE_WIDTH_0 85*cdf0e10cSrcweir #define DEF_DOUBLE_LINE7_DIST DEF_LINE_WIDTH_2 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir #define DEF_DOUBLE_LINE8_OUT DEF_LINE_WIDTH_1 88*cdf0e10cSrcweir #define DEF_DOUBLE_LINE8_IN DEF_LINE_WIDTH_0 89*cdf0e10cSrcweir #define DEF_DOUBLE_LINE8_DIST DEF_LINE_WIDTH_2 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir #define DEF_DOUBLE_LINE9_OUT DEF_LINE_WIDTH_2 92*cdf0e10cSrcweir #define DEF_DOUBLE_LINE9_IN DEF_LINE_WIDTH_0 93*cdf0e10cSrcweir #define DEF_DOUBLE_LINE9_DIST DEF_LINE_WIDTH_2 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir #define DEF_DOUBLE_LINE10_OUT DEF_LINE_WIDTH_3 96*cdf0e10cSrcweir #define DEF_DOUBLE_LINE10_IN DEF_LINE_WIDTH_0 97*cdf0e10cSrcweir #define DEF_DOUBLE_LINE10_DIST DEF_LINE_WIDTH_2 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir // finished copy 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir #define SVX_XML_BORDER_STYLE_NONE 0 102*cdf0e10cSrcweir #define SVX_XML_BORDER_STYLE_SOLID 1 103*cdf0e10cSrcweir #define SVX_XML_BORDER_STYLE_DOUBLE 2 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir #define SVX_XML_BORDER_WIDTH_THIN 0 106*cdf0e10cSrcweir #define SVX_XML_BORDER_WIDTH_MIDDLE 1 107*cdf0e10cSrcweir #define SVX_XML_BORDER_WIDTH_THICK 2 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir SvXMLEnumMapEntry pXML_BorderStyles[] = 110*cdf0e10cSrcweir { 111*cdf0e10cSrcweir { XML_NONE, SVX_XML_BORDER_STYLE_NONE }, 112*cdf0e10cSrcweir { XML_HIDDEN, SVX_XML_BORDER_STYLE_NONE }, 113*cdf0e10cSrcweir { XML_SOLID, SVX_XML_BORDER_STYLE_SOLID }, 114*cdf0e10cSrcweir { XML_DOUBLE, SVX_XML_BORDER_STYLE_DOUBLE }, 115*cdf0e10cSrcweir { XML_DOTTED, SVX_XML_BORDER_STYLE_SOLID }, 116*cdf0e10cSrcweir { XML_DASHED, SVX_XML_BORDER_STYLE_SOLID }, 117*cdf0e10cSrcweir { XML_GROOVE, SVX_XML_BORDER_STYLE_SOLID }, 118*cdf0e10cSrcweir { XML_RIDGE, SVX_XML_BORDER_STYLE_SOLID }, 119*cdf0e10cSrcweir { XML_INSET, SVX_XML_BORDER_STYLE_SOLID }, 120*cdf0e10cSrcweir { XML_OUTSET, SVX_XML_BORDER_STYLE_SOLID }, 121*cdf0e10cSrcweir { XML_TOKEN_INVALID, 0 } 122*cdf0e10cSrcweir }; 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir SvXMLEnumMapEntry pXML_NamedBorderWidths[] = 125*cdf0e10cSrcweir { 126*cdf0e10cSrcweir { XML_THIN, SVX_XML_BORDER_WIDTH_THIN }, 127*cdf0e10cSrcweir { XML_MIDDLE, SVX_XML_BORDER_WIDTH_MIDDLE }, 128*cdf0e10cSrcweir { XML_THICK, SVX_XML_BORDER_WIDTH_THICK }, 129*cdf0e10cSrcweir { XML_TOKEN_INVALID, 0 } 130*cdf0e10cSrcweir }; 131*cdf0e10cSrcweir // mapping tables to map external xml input to intarnal box line widths 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir // Ein Eintrag besteht aus vier USHORTs. Der erste ist die Gesamtbreite, 134*cdf0e10cSrcweir // die anderen sind die 3 Einzelbreiten 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir #define SBORDER_ENTRY( n ) \ 137*cdf0e10cSrcweir DEF_LINE_WIDTH_##n, DEF_LINE_WIDTH_##n, 0, 0 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir #define DBORDER_ENTRY( n ) \ 140*cdf0e10cSrcweir DEF_DOUBLE_LINE##n##_OUT + DEF_DOUBLE_LINE##n##_IN + \ 141*cdf0e10cSrcweir DEF_DOUBLE_LINE##n##_DIST, \ 142*cdf0e10cSrcweir DEF_DOUBLE_LINE##n##_OUT, \ 143*cdf0e10cSrcweir DEF_DOUBLE_LINE##n##_IN, \ 144*cdf0e10cSrcweir DEF_DOUBLE_LINE##n##_DIST 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir #define TDBORDER_ENTRY( n ) \ 147*cdf0e10cSrcweir DEF_DOUBLE_LINE##n##_OUT, \ 148*cdf0e10cSrcweir DEF_DOUBLE_LINE##n##_OUT, \ 149*cdf0e10cSrcweir DEF_DOUBLE_LINE##n##_IN, \ 150*cdf0e10cSrcweir DEF_DOUBLE_LINE##n##_DIST 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir static sal_uInt16 __READONLY_DATA aSBorderWidths[] = 154*cdf0e10cSrcweir { 155*cdf0e10cSrcweir SBORDER_ENTRY( 0 ), SBORDER_ENTRY( 1 ), SBORDER_ENTRY( 2 ), 156*cdf0e10cSrcweir SBORDER_ENTRY( 3 ), SBORDER_ENTRY( 4 ) 157*cdf0e10cSrcweir }; 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir static sal_uInt16 __READONLY_DATA aDBorderWidths[] = 160*cdf0e10cSrcweir { 161*cdf0e10cSrcweir DBORDER_ENTRY( 0 ), 162*cdf0e10cSrcweir DBORDER_ENTRY( 7 ), 163*cdf0e10cSrcweir DBORDER_ENTRY( 1 ), 164*cdf0e10cSrcweir DBORDER_ENTRY( 8 ), 165*cdf0e10cSrcweir DBORDER_ENTRY( 4 ), 166*cdf0e10cSrcweir DBORDER_ENTRY( 9 ), 167*cdf0e10cSrcweir DBORDER_ENTRY( 3 ), 168*cdf0e10cSrcweir DBORDER_ENTRY( 10 ), 169*cdf0e10cSrcweir DBORDER_ENTRY( 2 ), 170*cdf0e10cSrcweir DBORDER_ENTRY( 6 ), 171*cdf0e10cSrcweir DBORDER_ENTRY( 5 ) 172*cdf0e10cSrcweir }; 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir void lcl_frmitems_setXMLBorderWidth( table::BorderLine &rBorderLine, 175*cdf0e10cSrcweir sal_uInt16 nWidth, sal_Bool bDouble ) 176*cdf0e10cSrcweir { 177*cdf0e10cSrcweir #ifdef XML_CHECK_UI_CONTSTRAINS 178*cdf0e10cSrcweir const sal_uInt16 *aWidths; 179*cdf0e10cSrcweir sal_uInt16 nSize; 180*cdf0e10cSrcweir if( !bDouble ) 181*cdf0e10cSrcweir { 182*cdf0e10cSrcweir aWidths = aSBorderWidths; 183*cdf0e10cSrcweir nSize = sizeof( aSBorderWidths ); 184*cdf0e10cSrcweir } 185*cdf0e10cSrcweir else 186*cdf0e10cSrcweir { 187*cdf0e10cSrcweir aWidths = aDBorderWidths; 188*cdf0e10cSrcweir nSize = sizeof( aDBorderWidths ); 189*cdf0e10cSrcweir } 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir sal_uInt16 i = (nSize / sizeof(sal_uInt16)) - 4; 192*cdf0e10cSrcweir while( i>0 && 193*cdf0e10cSrcweir nWidth <= ((aWidths[i] + aWidths[i-4]) / 2) ) 194*cdf0e10cSrcweir { 195*cdf0e10cSrcweir i -= 4; 196*cdf0e10cSrcweir } 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir rBorderLine.OuterLineWidth = aWidths[i+1]; 199*cdf0e10cSrcweir rBorderLine.InnerLineWidth = aWidths[i+2]; 200*cdf0e10cSrcweir rBorderLine.LineDistance = aWidths[i+3]; 201*cdf0e10cSrcweir #else 202*cdf0e10cSrcweir if( bDouble ) 203*cdf0e10cSrcweir { 204*cdf0e10cSrcweir const sal_uInt16 *aWidths = aDBorderWidths; 205*cdf0e10cSrcweir sal_uInt16 nSize = sizeof( aDBorderWidths ); 206*cdf0e10cSrcweir sal_uInt16 i = (nSize / sizeof(sal_uInt16)) - 4; 207*cdf0e10cSrcweir while( i>0 && 208*cdf0e10cSrcweir nWidth <= ((aWidths[i] + aWidths[i-4]) / 2) ) 209*cdf0e10cSrcweir { 210*cdf0e10cSrcweir i -= 4; 211*cdf0e10cSrcweir } 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir rBorderLine.OuterLineWidth = aWidths[i+1]; 214*cdf0e10cSrcweir rBorderLine.InnerLineWidth = aWidths[i+2]; 215*cdf0e10cSrcweir rBorderLine.LineDistance = aWidths[i+3]; 216*cdf0e10cSrcweir } 217*cdf0e10cSrcweir else 218*cdf0e10cSrcweir { 219*cdf0e10cSrcweir rBorderLine.OuterLineWidth = 0 == nWidth ? DEF_LINE_WIDTH_0 : nWidth; 220*cdf0e10cSrcweir rBorderLine.InnerLineWidth = 0; 221*cdf0e10cSrcweir rBorderLine.LineDistance = 0; 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir } 224*cdf0e10cSrcweir #endif 225*cdf0e10cSrcweir } 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////////////// 229*cdf0e10cSrcweir // 230*cdf0e10cSrcweir // class XMLEscapementPropHdl 231*cdf0e10cSrcweir // 232*cdf0e10cSrcweir 233*cdf0e10cSrcweir XMLBorderWidthHdl::~XMLBorderWidthHdl() 234*cdf0e10cSrcweir { 235*cdf0e10cSrcweir // nothing to do 236*cdf0e10cSrcweir } 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir sal_Bool XMLBorderWidthHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const 239*cdf0e10cSrcweir { 240*cdf0e10cSrcweir SvXMLTokenEnumerator aTokenEnum( rStrImpValue ); 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir sal_Int32 nInWidth, nDistance, nOutWidth; 243*cdf0e10cSrcweir 244*cdf0e10cSrcweir OUString aToken; 245*cdf0e10cSrcweir if( !aTokenEnum.getNextToken( aToken ) ) 246*cdf0e10cSrcweir return sal_False; 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir if( !rUnitConverter.convertMeasure( nInWidth, aToken, 0, 500 ) ) 249*cdf0e10cSrcweir return sal_False; 250*cdf0e10cSrcweir 251*cdf0e10cSrcweir if( !aTokenEnum.getNextToken( aToken ) ) 252*cdf0e10cSrcweir return sal_False; 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir if( !rUnitConverter.convertMeasure( nDistance, aToken, 0, 500 ) ) 255*cdf0e10cSrcweir return sal_False; 256*cdf0e10cSrcweir 257*cdf0e10cSrcweir if( !aTokenEnum.getNextToken( aToken ) ) 258*cdf0e10cSrcweir return sal_False; 259*cdf0e10cSrcweir 260*cdf0e10cSrcweir if( !rUnitConverter.convertMeasure( nOutWidth, aToken, 0, 500 ) ) 261*cdf0e10cSrcweir return sal_False; 262*cdf0e10cSrcweir 263*cdf0e10cSrcweir #ifdef XML_CHECK_UI_CONSTRAINS 264*cdf0e10cSrcweir sal_uInt16 nSize = sizeof( aDBorderWidths ); 265*cdf0e10cSrcweir for( sal_uInt16 i=0; i < nSize; i += 4 ) 266*cdf0e10cSrcweir { 267*cdf0e10cSrcweir if( aDBorderWidths[i+1] == nOutWidth && 268*cdf0e10cSrcweir aDBorderWidths[i+2] == nInWidth && 269*cdf0e10cSrcweir aDBorderWidths[i+3] == nDistance ) 270*cdf0e10cSrcweir break; 271*cdf0e10cSrcweir } 272*cdf0e10cSrcweir 273*cdf0e10cSrcweir sal_uInt16 nWidth = i < nSize ? 0 : nOutWidth + nInWidth + nDistance; 274*cdf0e10cSrcweir #endif 275*cdf0e10cSrcweir 276*cdf0e10cSrcweir table::BorderLine aBorderLine; 277*cdf0e10cSrcweir if(!(rValue >>= aBorderLine)) 278*cdf0e10cSrcweir aBorderLine.Color = 0; 279*cdf0e10cSrcweir 280*cdf0e10cSrcweir aBorderLine.InnerLineWidth = sal::static_int_cast< sal_Int16 >(nInWidth); 281*cdf0e10cSrcweir aBorderLine.OuterLineWidth = sal::static_int_cast< sal_Int16 >(nOutWidth); 282*cdf0e10cSrcweir aBorderLine.LineDistance = sal::static_int_cast< sal_Int16 >(nDistance); 283*cdf0e10cSrcweir 284*cdf0e10cSrcweir rValue <<= aBorderLine; 285*cdf0e10cSrcweir return sal_True; 286*cdf0e10cSrcweir } 287*cdf0e10cSrcweir 288*cdf0e10cSrcweir sal_Bool XMLBorderWidthHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const 289*cdf0e10cSrcweir { 290*cdf0e10cSrcweir OUStringBuffer aOut; 291*cdf0e10cSrcweir 292*cdf0e10cSrcweir table::BorderLine aBorderLine; 293*cdf0e10cSrcweir if(!(rValue >>= aBorderLine)) 294*cdf0e10cSrcweir return sal_False; 295*cdf0e10cSrcweir 296*cdf0e10cSrcweir if( aBorderLine.LineDistance == 0 && aBorderLine.InnerLineWidth == 0) 297*cdf0e10cSrcweir return sal_False; 298*cdf0e10cSrcweir 299*cdf0e10cSrcweir rUnitConverter.convertMeasure( aOut, aBorderLine.InnerLineWidth ); 300*cdf0e10cSrcweir aOut.append( sal_Unicode( ' ' ) ); 301*cdf0e10cSrcweir rUnitConverter.convertMeasure( aOut, aBorderLine.LineDistance ); 302*cdf0e10cSrcweir aOut.append( sal_Unicode( ' ' ) ); 303*cdf0e10cSrcweir rUnitConverter.convertMeasure( aOut, aBorderLine.OuterLineWidth ); 304*cdf0e10cSrcweir 305*cdf0e10cSrcweir rStrExpValue = aOut.makeStringAndClear(); 306*cdf0e10cSrcweir return sal_True; 307*cdf0e10cSrcweir } 308*cdf0e10cSrcweir 309*cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////////////// 310*cdf0e10cSrcweir // 311*cdf0e10cSrcweir // class XMLEscapementHeightPropHdl 312*cdf0e10cSrcweir // 313*cdf0e10cSrcweir 314*cdf0e10cSrcweir XMLBorderHdl::~XMLBorderHdl() 315*cdf0e10cSrcweir { 316*cdf0e10cSrcweir // nothing to do 317*cdf0e10cSrcweir } 318*cdf0e10cSrcweir 319*cdf0e10cSrcweir sal_Bool XMLBorderHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const 320*cdf0e10cSrcweir { 321*cdf0e10cSrcweir OUString aToken; 322*cdf0e10cSrcweir SvXMLTokenEnumerator aTokens( rStrImpValue ); 323*cdf0e10cSrcweir 324*cdf0e10cSrcweir sal_Bool bHasStyle = sal_False; 325*cdf0e10cSrcweir sal_Bool bHasWidth = sal_False; 326*cdf0e10cSrcweir sal_Bool bHasColor = sal_False; 327*cdf0e10cSrcweir 328*cdf0e10cSrcweir sal_uInt16 nStyle = USHRT_MAX; 329*cdf0e10cSrcweir sal_uInt16 nWidth = 0; 330*cdf0e10cSrcweir sal_uInt16 nNamedWidth = USHRT_MAX; 331*cdf0e10cSrcweir Color aColor; 332*cdf0e10cSrcweir 333*cdf0e10cSrcweir sal_Int32 nTemp; 334*cdf0e10cSrcweir while( aTokens.getNextToken( aToken ) && aToken.getLength() != 0 ) 335*cdf0e10cSrcweir { 336*cdf0e10cSrcweir if( !bHasWidth && 337*cdf0e10cSrcweir rUnitConverter.convertEnum( nNamedWidth, aToken, 338*cdf0e10cSrcweir pXML_NamedBorderWidths ) ) 339*cdf0e10cSrcweir { 340*cdf0e10cSrcweir bHasWidth = sal_True; 341*cdf0e10cSrcweir } 342*cdf0e10cSrcweir else if( !bHasStyle && 343*cdf0e10cSrcweir rUnitConverter.convertEnum( nStyle, aToken, 344*cdf0e10cSrcweir pXML_BorderStyles ) ) 345*cdf0e10cSrcweir { 346*cdf0e10cSrcweir bHasStyle = sal_True; 347*cdf0e10cSrcweir } 348*cdf0e10cSrcweir else if( !bHasColor && rUnitConverter.convertColor( aColor, aToken ) ) 349*cdf0e10cSrcweir { 350*cdf0e10cSrcweir bHasColor = sal_True; 351*cdf0e10cSrcweir } 352*cdf0e10cSrcweir else if( !bHasWidth && 353*cdf0e10cSrcweir rUnitConverter.convertMeasure( nTemp, aToken, 0, 354*cdf0e10cSrcweir USHRT_MAX ) ) 355*cdf0e10cSrcweir { 356*cdf0e10cSrcweir nWidth = (sal_uInt16)nTemp; 357*cdf0e10cSrcweir bHasWidth = sal_True; 358*cdf0e10cSrcweir } 359*cdf0e10cSrcweir else 360*cdf0e10cSrcweir { 361*cdf0e10cSrcweir // missformed 362*cdf0e10cSrcweir return sal_False; 363*cdf0e10cSrcweir } 364*cdf0e10cSrcweir } 365*cdf0e10cSrcweir 366*cdf0e10cSrcweir // if there is no style or a different style than none but no width, 367*cdf0e10cSrcweir // then the declaration is not valid. 368*cdf0e10cSrcweir if( !bHasStyle || (SVX_XML_BORDER_STYLE_NONE != nStyle && !bHasWidth) ) 369*cdf0e10cSrcweir return sal_False; 370*cdf0e10cSrcweir 371*cdf0e10cSrcweir table::BorderLine aBorderLine; 372*cdf0e10cSrcweir if(!(rValue >>= aBorderLine)) 373*cdf0e10cSrcweir { 374*cdf0e10cSrcweir aBorderLine.Color = 0; 375*cdf0e10cSrcweir aBorderLine.InnerLineWidth = 0; 376*cdf0e10cSrcweir aBorderLine.OuterLineWidth = 0; 377*cdf0e10cSrcweir aBorderLine.LineDistance = 0; 378*cdf0e10cSrcweir } 379*cdf0e10cSrcweir 380*cdf0e10cSrcweir // first of all, delete an empty line 381*cdf0e10cSrcweir sal_Bool bDouble = SVX_XML_BORDER_STYLE_DOUBLE == nStyle; 382*cdf0e10cSrcweir if( (bHasStyle && SVX_XML_BORDER_STYLE_NONE == nStyle) || 383*cdf0e10cSrcweir (bHasWidth && USHRT_MAX == nNamedWidth && 0 == nWidth) ) 384*cdf0e10cSrcweir { 385*cdf0e10cSrcweir aBorderLine.InnerLineWidth = 0; 386*cdf0e10cSrcweir aBorderLine.OuterLineWidth = 0; 387*cdf0e10cSrcweir aBorderLine.LineDistance = 0; 388*cdf0e10cSrcweir } 389*cdf0e10cSrcweir else if( bHasWidth ) 390*cdf0e10cSrcweir { 391*cdf0e10cSrcweir if( USHRT_MAX != nNamedWidth ) 392*cdf0e10cSrcweir { 393*cdf0e10cSrcweir const sal_uInt16 *aWidths = bDouble ? aDBorderWidths 394*cdf0e10cSrcweir : aSBorderWidths; 395*cdf0e10cSrcweir sal_uInt16 nNWidth = nNamedWidth * 4; 396*cdf0e10cSrcweir aBorderLine.OuterLineWidth = aWidths[nNWidth+1]; 397*cdf0e10cSrcweir aBorderLine.InnerLineWidth = aWidths[nNWidth+2]; 398*cdf0e10cSrcweir aBorderLine.LineDistance = aWidths[nNWidth+3]; 399*cdf0e10cSrcweir } 400*cdf0e10cSrcweir else 401*cdf0e10cSrcweir { 402*cdf0e10cSrcweir lcl_frmitems_setXMLBorderWidth( aBorderLine, nWidth, bDouble ); 403*cdf0e10cSrcweir } 404*cdf0e10cSrcweir } 405*cdf0e10cSrcweir else 406*cdf0e10cSrcweir { 407*cdf0e10cSrcweir lcl_frmitems_setXMLBorderWidth( aBorderLine, 0, bDouble ); 408*cdf0e10cSrcweir } 409*cdf0e10cSrcweir 410*cdf0e10cSrcweir // set color 411*cdf0e10cSrcweir if( bHasColor ) 412*cdf0e10cSrcweir aBorderLine.Color = (sal_Int32)aColor.GetRGBColor(); 413*cdf0e10cSrcweir 414*cdf0e10cSrcweir rValue <<= aBorderLine; 415*cdf0e10cSrcweir return sal_True; 416*cdf0e10cSrcweir } 417*cdf0e10cSrcweir 418*cdf0e10cSrcweir sal_Bool XMLBorderHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const 419*cdf0e10cSrcweir { 420*cdf0e10cSrcweir OUStringBuffer aOut; 421*cdf0e10cSrcweir 422*cdf0e10cSrcweir table::BorderLine aBorderLine; 423*cdf0e10cSrcweir if(!(rValue >>= aBorderLine)) 424*cdf0e10cSrcweir return sal_False; 425*cdf0e10cSrcweir 426*cdf0e10cSrcweir sal_Int32 nWidth = aBorderLine.OuterLineWidth; 427*cdf0e10cSrcweir const sal_uInt16 nDistance = aBorderLine.LineDistance; 428*cdf0e10cSrcweir if( 0 != nDistance ) 429*cdf0e10cSrcweir { 430*cdf0e10cSrcweir nWidth += nDistance; 431*cdf0e10cSrcweir nWidth += aBorderLine.InnerLineWidth; 432*cdf0e10cSrcweir } 433*cdf0e10cSrcweir 434*cdf0e10cSrcweir if( nWidth == 0 ) 435*cdf0e10cSrcweir { 436*cdf0e10cSrcweir aOut.append( GetXMLToken( XML_NONE ) ); 437*cdf0e10cSrcweir } 438*cdf0e10cSrcweir else 439*cdf0e10cSrcweir { 440*cdf0e10cSrcweir rUnitConverter.convertMeasure( aOut, nWidth ); 441*cdf0e10cSrcweir 442*cdf0e10cSrcweir aOut.append( sal_Unicode( ' ' ) ); 443*cdf0e10cSrcweir 444*cdf0e10cSrcweir aOut.append( GetXMLToken((0 == nDistance) ? XML_SOLID : XML_DOUBLE) ); 445*cdf0e10cSrcweir 446*cdf0e10cSrcweir aOut.append( sal_Unicode( ' ' ) ); 447*cdf0e10cSrcweir 448*cdf0e10cSrcweir rUnitConverter.convertColor( aOut, aBorderLine.Color ); 449*cdf0e10cSrcweir } 450*cdf0e10cSrcweir 451*cdf0e10cSrcweir rStrExpValue = aOut.makeStringAndClear(); 452*cdf0e10cSrcweir 453*cdf0e10cSrcweir return sal_True; 454*cdf0e10cSrcweir } 455