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 #include <tools/debug.hxx> 31*cdf0e10cSrcweir #include <backhdl.hxx> 32*cdf0e10cSrcweir #include <xmloff/xmltoken.hxx> 33*cdf0e10cSrcweir #include <xmloff/xmluconv.hxx> 34*cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx> 35*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir using ::rtl::OUString; 38*cdf0e10cSrcweir using ::rtl::OUStringBuffer; 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir using namespace ::com::sun::star; 41*cdf0e10cSrcweir using namespace ::xmloff::token; 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir SvXMLEnumMapEntry pXML_BrushHorizontalPos[] = 44*cdf0e10cSrcweir { 45*cdf0e10cSrcweir { XML_LEFT, style::GraphicLocation_LEFT_MIDDLE }, 46*cdf0e10cSrcweir { XML_RIGHT, style::GraphicLocation_RIGHT_MIDDLE }, 47*cdf0e10cSrcweir { XML_TOKEN_INVALID, 0 } 48*cdf0e10cSrcweir }; 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir SvXMLEnumMapEntry pXML_BrushVerticalPos[] = 51*cdf0e10cSrcweir { 52*cdf0e10cSrcweir { XML_TOP, style::GraphicLocation_MIDDLE_TOP }, 53*cdf0e10cSrcweir { XML_BOTTOM, style::GraphicLocation_MIDDLE_BOTTOM }, 54*cdf0e10cSrcweir { XML_TOKEN_INVALID, 0 } 55*cdf0e10cSrcweir }; 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////////////// 58*cdf0e10cSrcweir // 59*cdf0e10cSrcweir // class XMLBackGraphicPositionPropHdl 60*cdf0e10cSrcweir // 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir XMLBackGraphicPositionPropHdl::~XMLBackGraphicPositionPropHdl() 63*cdf0e10cSrcweir { 64*cdf0e10cSrcweir // Nothing to do 65*cdf0e10cSrcweir } 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir sal_Bool XMLBackGraphicPositionPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const 68*cdf0e10cSrcweir { 69*cdf0e10cSrcweir sal_Bool bRet = sal_True; 70*cdf0e10cSrcweir style::GraphicLocation ePos = style::GraphicLocation_NONE, eTmp; 71*cdf0e10cSrcweir sal_uInt16 nTmp; 72*cdf0e10cSrcweir SvXMLTokenEnumerator aTokenEnum( rStrImpValue ); 73*cdf0e10cSrcweir OUString aToken; 74*cdf0e10cSrcweir sal_Bool bHori = sal_False, bVert = sal_False; 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir while( bRet && aTokenEnum.getNextToken( aToken ) ) 77*cdf0e10cSrcweir { 78*cdf0e10cSrcweir if( bHori && bVert ) 79*cdf0e10cSrcweir { 80*cdf0e10cSrcweir bRet = sal_False; 81*cdf0e10cSrcweir } 82*cdf0e10cSrcweir else if( -1 != aToken.indexOf( sal_Unicode('%') ) ) 83*cdf0e10cSrcweir { 84*cdf0e10cSrcweir sal_Int32 nPrc = 50; 85*cdf0e10cSrcweir if( SvXMLUnitConverter::convertPercent( nPrc, aToken ) ) 86*cdf0e10cSrcweir { 87*cdf0e10cSrcweir if( !bHori ) 88*cdf0e10cSrcweir { 89*cdf0e10cSrcweir ePos = nPrc < 25 ? style::GraphicLocation_LEFT_TOP : 90*cdf0e10cSrcweir (nPrc < 75 ? style::GraphicLocation_MIDDLE_MIDDLE : 91*cdf0e10cSrcweir style::GraphicLocation_RIGHT_BOTTOM); 92*cdf0e10cSrcweir bHori = sal_True; 93*cdf0e10cSrcweir } 94*cdf0e10cSrcweir else 95*cdf0e10cSrcweir { 96*cdf0e10cSrcweir eTmp = nPrc < 25 ? style::GraphicLocation_LEFT_TOP: 97*cdf0e10cSrcweir (nPrc < 75 ? style::GraphicLocation_LEFT_MIDDLE : 98*cdf0e10cSrcweir style::GraphicLocation_LEFT_BOTTOM); 99*cdf0e10cSrcweir MergeXMLVertPos( ePos, eTmp ); 100*cdf0e10cSrcweir bVert = sal_True; 101*cdf0e10cSrcweir } 102*cdf0e10cSrcweir } 103*cdf0e10cSrcweir else 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir // wrong percentage 106*cdf0e10cSrcweir bRet = sal_False; 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir else if( IsXMLToken( aToken, XML_CENTER ) ) 110*cdf0e10cSrcweir { 111*cdf0e10cSrcweir if( bHori ) 112*cdf0e10cSrcweir MergeXMLVertPos( ePos, style::GraphicLocation_MIDDLE_MIDDLE ); 113*cdf0e10cSrcweir else if ( bVert ) 114*cdf0e10cSrcweir MergeXMLHoriPos( ePos, style::GraphicLocation_MIDDLE_MIDDLE ); 115*cdf0e10cSrcweir else 116*cdf0e10cSrcweir ePos = style::GraphicLocation_MIDDLE_MIDDLE; 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir else if( SvXMLUnitConverter::convertEnum( nTmp, aToken, pXML_BrushHorizontalPos ) ) 119*cdf0e10cSrcweir { 120*cdf0e10cSrcweir if( bVert ) 121*cdf0e10cSrcweir MergeXMLHoriPos( ePos, (style::GraphicLocation)nTmp ); 122*cdf0e10cSrcweir else if( !bHori ) 123*cdf0e10cSrcweir ePos = (style::GraphicLocation)nTmp; 124*cdf0e10cSrcweir else 125*cdf0e10cSrcweir bRet = sal_False; 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir bHori = sal_True; 128*cdf0e10cSrcweir } 129*cdf0e10cSrcweir else if( SvXMLUnitConverter::convertEnum( nTmp, aToken, pXML_BrushVerticalPos ) ) 130*cdf0e10cSrcweir { 131*cdf0e10cSrcweir if( bHori ) 132*cdf0e10cSrcweir MergeXMLVertPos( ePos, (style::GraphicLocation)nTmp ); 133*cdf0e10cSrcweir else if( !bVert ) 134*cdf0e10cSrcweir ePos = (style::GraphicLocation)nTmp; 135*cdf0e10cSrcweir else 136*cdf0e10cSrcweir bRet = sal_False; 137*cdf0e10cSrcweir bVert = sal_True; 138*cdf0e10cSrcweir } 139*cdf0e10cSrcweir else 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir bRet = sal_False; 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir bRet &= style::GraphicLocation_NONE != ePos; 146*cdf0e10cSrcweir if( bRet ) 147*cdf0e10cSrcweir rValue <<= (style::GraphicLocation)(sal_uInt16)ePos; 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir return bRet; 150*cdf0e10cSrcweir } 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir sal_Bool XMLBackGraphicPositionPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const 153*cdf0e10cSrcweir { 154*cdf0e10cSrcweir sal_Bool bRet = sal_True; 155*cdf0e10cSrcweir OUStringBuffer aOut; 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir style::GraphicLocation eLocation; 158*cdf0e10cSrcweir if( !( rValue >>= eLocation ) ) 159*cdf0e10cSrcweir { 160*cdf0e10cSrcweir sal_Int32 nValue = 0; 161*cdf0e10cSrcweir if( rValue >>= nValue ) 162*cdf0e10cSrcweir eLocation = (style::GraphicLocation)nValue; 163*cdf0e10cSrcweir else 164*cdf0e10cSrcweir bRet = sal_False; 165*cdf0e10cSrcweir } 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir if( bRet ) 168*cdf0e10cSrcweir { 169*cdf0e10cSrcweir bRet = sal_False; 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir switch( eLocation ) 172*cdf0e10cSrcweir { 173*cdf0e10cSrcweir case style::GraphicLocation_LEFT_TOP: 174*cdf0e10cSrcweir case style::GraphicLocation_MIDDLE_TOP: 175*cdf0e10cSrcweir case style::GraphicLocation_RIGHT_TOP: 176*cdf0e10cSrcweir aOut.append( GetXMLToken(XML_TOP) ); 177*cdf0e10cSrcweir bRet = sal_True; 178*cdf0e10cSrcweir break; 179*cdf0e10cSrcweir case style::GraphicLocation_LEFT_MIDDLE: 180*cdf0e10cSrcweir case style::GraphicLocation_MIDDLE_MIDDLE: 181*cdf0e10cSrcweir case style::GraphicLocation_RIGHT_MIDDLE: 182*cdf0e10cSrcweir aOut.append( GetXMLToken(XML_CENTER) ); 183*cdf0e10cSrcweir bRet = sal_True; 184*cdf0e10cSrcweir break; 185*cdf0e10cSrcweir case style::GraphicLocation_LEFT_BOTTOM: 186*cdf0e10cSrcweir case style::GraphicLocation_MIDDLE_BOTTOM: 187*cdf0e10cSrcweir case style::GraphicLocation_RIGHT_BOTTOM: 188*cdf0e10cSrcweir aOut.append( GetXMLToken(XML_BOTTOM) ); 189*cdf0e10cSrcweir bRet = sal_True; 190*cdf0e10cSrcweir break; 191*cdf0e10cSrcweir default: 192*cdf0e10cSrcweir break; 193*cdf0e10cSrcweir } 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir if( bRet ) 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir aOut.append( sal_Unicode( ' ' ) ); 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir switch( eLocation ) 200*cdf0e10cSrcweir { 201*cdf0e10cSrcweir case style::GraphicLocation_LEFT_TOP: 202*cdf0e10cSrcweir case style::GraphicLocation_LEFT_BOTTOM: 203*cdf0e10cSrcweir case style::GraphicLocation_LEFT_MIDDLE: 204*cdf0e10cSrcweir aOut.append( GetXMLToken(XML_LEFT) ); 205*cdf0e10cSrcweir break; 206*cdf0e10cSrcweir case style::GraphicLocation_MIDDLE_TOP: 207*cdf0e10cSrcweir case style::GraphicLocation_MIDDLE_MIDDLE: 208*cdf0e10cSrcweir case style::GraphicLocation_MIDDLE_BOTTOM: 209*cdf0e10cSrcweir aOut.append( GetXMLToken(XML_CENTER) ); 210*cdf0e10cSrcweir break; 211*cdf0e10cSrcweir case style::GraphicLocation_RIGHT_MIDDLE: 212*cdf0e10cSrcweir case style::GraphicLocation_RIGHT_TOP: 213*cdf0e10cSrcweir case style::GraphicLocation_RIGHT_BOTTOM: 214*cdf0e10cSrcweir aOut.append( GetXMLToken(XML_RIGHT) ); 215*cdf0e10cSrcweir break; 216*cdf0e10cSrcweir default: 217*cdf0e10cSrcweir break; 218*cdf0e10cSrcweir } 219*cdf0e10cSrcweir } 220*cdf0e10cSrcweir } 221*cdf0e10cSrcweir 222*cdf0e10cSrcweir rStrExpValue = aOut.makeStringAndClear(); 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir return bRet; 225*cdf0e10cSrcweir } 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir void XMLBackGraphicPositionPropHdl::MergeXMLVertPos( style::GraphicLocation& ePos, style::GraphicLocation eVert ) const 228*cdf0e10cSrcweir { 229*cdf0e10cSrcweir switch( ePos ) 230*cdf0e10cSrcweir { 231*cdf0e10cSrcweir case style::GraphicLocation_LEFT_TOP: 232*cdf0e10cSrcweir case style::GraphicLocation_LEFT_MIDDLE: 233*cdf0e10cSrcweir case style::GraphicLocation_LEFT_BOTTOM: 234*cdf0e10cSrcweir ePos = style::GraphicLocation_MIDDLE_TOP==eVert ? 235*cdf0e10cSrcweir style::GraphicLocation_LEFT_TOP : 236*cdf0e10cSrcweir (style::GraphicLocation_MIDDLE_MIDDLE==eVert ? 237*cdf0e10cSrcweir style::GraphicLocation_LEFT_MIDDLE : 238*cdf0e10cSrcweir style::GraphicLocation_LEFT_BOTTOM); 239*cdf0e10cSrcweir ePos = eVert; 240*cdf0e10cSrcweir break; 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir case style::GraphicLocation_MIDDLE_TOP: 243*cdf0e10cSrcweir case style::GraphicLocation_MIDDLE_MIDDLE: 244*cdf0e10cSrcweir case style::GraphicLocation_MIDDLE_BOTTOM: 245*cdf0e10cSrcweir ePos = eVert; 246*cdf0e10cSrcweir break; 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir case style::GraphicLocation_RIGHT_TOP: 249*cdf0e10cSrcweir case style::GraphicLocation_RIGHT_MIDDLE: 250*cdf0e10cSrcweir case style::GraphicLocation_RIGHT_BOTTOM: 251*cdf0e10cSrcweir ePos = style::GraphicLocation_MIDDLE_TOP==eVert ? 252*cdf0e10cSrcweir style::GraphicLocation_RIGHT_TOP : 253*cdf0e10cSrcweir (style::GraphicLocation_MIDDLE_MIDDLE==eVert ? 254*cdf0e10cSrcweir style::GraphicLocation_RIGHT_MIDDLE : 255*cdf0e10cSrcweir style::GraphicLocation_RIGHT_BOTTOM); 256*cdf0e10cSrcweir break; 257*cdf0e10cSrcweir default: 258*cdf0e10cSrcweir break; 259*cdf0e10cSrcweir } 260*cdf0e10cSrcweir } 261*cdf0e10cSrcweir 262*cdf0e10cSrcweir void XMLBackGraphicPositionPropHdl::MergeXMLHoriPos( style::GraphicLocation& ePos, style::GraphicLocation eHori ) const 263*cdf0e10cSrcweir { 264*cdf0e10cSrcweir DBG_ASSERT( style::GraphicLocation_LEFT_MIDDLE==eHori || style::GraphicLocation_MIDDLE_MIDDLE==eHori || style::GraphicLocation_RIGHT_MIDDLE==eHori, 265*cdf0e10cSrcweir "lcl_frmitems_MergeXMLHoriPos: vertical pos must be middle" ); 266*cdf0e10cSrcweir 267*cdf0e10cSrcweir switch( ePos ) 268*cdf0e10cSrcweir { 269*cdf0e10cSrcweir case style::GraphicLocation_LEFT_TOP: 270*cdf0e10cSrcweir case style::GraphicLocation_MIDDLE_TOP: 271*cdf0e10cSrcweir case style::GraphicLocation_RIGHT_TOP: 272*cdf0e10cSrcweir ePos = style::GraphicLocation_LEFT_MIDDLE==eHori ? 273*cdf0e10cSrcweir style::GraphicLocation_LEFT_TOP : 274*cdf0e10cSrcweir (style::GraphicLocation_MIDDLE_MIDDLE==eHori ? 275*cdf0e10cSrcweir style::GraphicLocation_MIDDLE_TOP : 276*cdf0e10cSrcweir style::GraphicLocation_RIGHT_TOP); 277*cdf0e10cSrcweir break; 278*cdf0e10cSrcweir 279*cdf0e10cSrcweir case style::GraphicLocation_LEFT_MIDDLE: 280*cdf0e10cSrcweir case style::GraphicLocation_MIDDLE_MIDDLE: 281*cdf0e10cSrcweir case style::GraphicLocation_RIGHT_MIDDLE: 282*cdf0e10cSrcweir ePos = eHori; 283*cdf0e10cSrcweir break; 284*cdf0e10cSrcweir 285*cdf0e10cSrcweir case style::GraphicLocation_LEFT_BOTTOM: 286*cdf0e10cSrcweir case style::GraphicLocation_MIDDLE_BOTTOM: 287*cdf0e10cSrcweir case style::GraphicLocation_RIGHT_BOTTOM: 288*cdf0e10cSrcweir ePos = style::GraphicLocation_LEFT_MIDDLE==eHori ? 289*cdf0e10cSrcweir style::GraphicLocation_LEFT_BOTTOM : 290*cdf0e10cSrcweir (style::GraphicLocation_MIDDLE_MIDDLE==eHori ? 291*cdf0e10cSrcweir style::GraphicLocation_MIDDLE_BOTTOM : 292*cdf0e10cSrcweir style::GraphicLocation_RIGHT_BOTTOM); 293*cdf0e10cSrcweir break; 294*cdf0e10cSrcweir default: 295*cdf0e10cSrcweir break; 296*cdf0e10cSrcweir } 297*cdf0e10cSrcweir } 298*cdf0e10cSrcweir 299