1*63bba73cSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*63bba73cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*63bba73cSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*63bba73cSAndrew Rist * distributed with this work for additional information 6*63bba73cSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*63bba73cSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*63bba73cSAndrew Rist * "License"); you may not use this file except in compliance 9*63bba73cSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*63bba73cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*63bba73cSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*63bba73cSAndrew Rist * software distributed under the License is distributed on an 15*63bba73cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*63bba73cSAndrew Rist * KIND, either express or implied. See the License for the 17*63bba73cSAndrew Rist * specific language governing permissions and limitations 18*63bba73cSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*63bba73cSAndrew Rist *************************************************************/ 21*63bba73cSAndrew Rist 22*63bba73cSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_xmloff.hxx" 26cdf0e10cSrcweir #include <tools/debug.hxx> 27cdf0e10cSrcweir #include <backhdl.hxx> 28cdf0e10cSrcweir #include <xmloff/xmltoken.hxx> 29cdf0e10cSrcweir #include <xmloff/xmluconv.hxx> 30cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx> 31cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 32cdf0e10cSrcweir 33cdf0e10cSrcweir using ::rtl::OUString; 34cdf0e10cSrcweir using ::rtl::OUStringBuffer; 35cdf0e10cSrcweir 36cdf0e10cSrcweir using namespace ::com::sun::star; 37cdf0e10cSrcweir using namespace ::xmloff::token; 38cdf0e10cSrcweir 39cdf0e10cSrcweir SvXMLEnumMapEntry pXML_BrushHorizontalPos[] = 40cdf0e10cSrcweir { 41cdf0e10cSrcweir { XML_LEFT, style::GraphicLocation_LEFT_MIDDLE }, 42cdf0e10cSrcweir { XML_RIGHT, style::GraphicLocation_RIGHT_MIDDLE }, 43cdf0e10cSrcweir { XML_TOKEN_INVALID, 0 } 44cdf0e10cSrcweir }; 45cdf0e10cSrcweir 46cdf0e10cSrcweir SvXMLEnumMapEntry pXML_BrushVerticalPos[] = 47cdf0e10cSrcweir { 48cdf0e10cSrcweir { XML_TOP, style::GraphicLocation_MIDDLE_TOP }, 49cdf0e10cSrcweir { XML_BOTTOM, style::GraphicLocation_MIDDLE_BOTTOM }, 50cdf0e10cSrcweir { XML_TOKEN_INVALID, 0 } 51cdf0e10cSrcweir }; 52cdf0e10cSrcweir 53cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////////////// 54cdf0e10cSrcweir // 55cdf0e10cSrcweir // class XMLBackGraphicPositionPropHdl 56cdf0e10cSrcweir // 57cdf0e10cSrcweir 58cdf0e10cSrcweir XMLBackGraphicPositionPropHdl::~XMLBackGraphicPositionPropHdl() 59cdf0e10cSrcweir { 60cdf0e10cSrcweir // Nothing to do 61cdf0e10cSrcweir } 62cdf0e10cSrcweir 63cdf0e10cSrcweir sal_Bool XMLBackGraphicPositionPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const 64cdf0e10cSrcweir { 65cdf0e10cSrcweir sal_Bool bRet = sal_True; 66cdf0e10cSrcweir style::GraphicLocation ePos = style::GraphicLocation_NONE, eTmp; 67cdf0e10cSrcweir sal_uInt16 nTmp; 68cdf0e10cSrcweir SvXMLTokenEnumerator aTokenEnum( rStrImpValue ); 69cdf0e10cSrcweir OUString aToken; 70cdf0e10cSrcweir sal_Bool bHori = sal_False, bVert = sal_False; 71cdf0e10cSrcweir 72cdf0e10cSrcweir while( bRet && aTokenEnum.getNextToken( aToken ) ) 73cdf0e10cSrcweir { 74cdf0e10cSrcweir if( bHori && bVert ) 75cdf0e10cSrcweir { 76cdf0e10cSrcweir bRet = sal_False; 77cdf0e10cSrcweir } 78cdf0e10cSrcweir else if( -1 != aToken.indexOf( sal_Unicode('%') ) ) 79cdf0e10cSrcweir { 80cdf0e10cSrcweir sal_Int32 nPrc = 50; 81cdf0e10cSrcweir if( SvXMLUnitConverter::convertPercent( nPrc, aToken ) ) 82cdf0e10cSrcweir { 83cdf0e10cSrcweir if( !bHori ) 84cdf0e10cSrcweir { 85cdf0e10cSrcweir ePos = nPrc < 25 ? style::GraphicLocation_LEFT_TOP : 86cdf0e10cSrcweir (nPrc < 75 ? style::GraphicLocation_MIDDLE_MIDDLE : 87cdf0e10cSrcweir style::GraphicLocation_RIGHT_BOTTOM); 88cdf0e10cSrcweir bHori = sal_True; 89cdf0e10cSrcweir } 90cdf0e10cSrcweir else 91cdf0e10cSrcweir { 92cdf0e10cSrcweir eTmp = nPrc < 25 ? style::GraphicLocation_LEFT_TOP: 93cdf0e10cSrcweir (nPrc < 75 ? style::GraphicLocation_LEFT_MIDDLE : 94cdf0e10cSrcweir style::GraphicLocation_LEFT_BOTTOM); 95cdf0e10cSrcweir MergeXMLVertPos( ePos, eTmp ); 96cdf0e10cSrcweir bVert = sal_True; 97cdf0e10cSrcweir } 98cdf0e10cSrcweir } 99cdf0e10cSrcweir else 100cdf0e10cSrcweir { 101cdf0e10cSrcweir // wrong percentage 102cdf0e10cSrcweir bRet = sal_False; 103cdf0e10cSrcweir } 104cdf0e10cSrcweir } 105cdf0e10cSrcweir else if( IsXMLToken( aToken, XML_CENTER ) ) 106cdf0e10cSrcweir { 107cdf0e10cSrcweir if( bHori ) 108cdf0e10cSrcweir MergeXMLVertPos( ePos, style::GraphicLocation_MIDDLE_MIDDLE ); 109cdf0e10cSrcweir else if ( bVert ) 110cdf0e10cSrcweir MergeXMLHoriPos( ePos, style::GraphicLocation_MIDDLE_MIDDLE ); 111cdf0e10cSrcweir else 112cdf0e10cSrcweir ePos = style::GraphicLocation_MIDDLE_MIDDLE; 113cdf0e10cSrcweir } 114cdf0e10cSrcweir else if( SvXMLUnitConverter::convertEnum( nTmp, aToken, pXML_BrushHorizontalPos ) ) 115cdf0e10cSrcweir { 116cdf0e10cSrcweir if( bVert ) 117cdf0e10cSrcweir MergeXMLHoriPos( ePos, (style::GraphicLocation)nTmp ); 118cdf0e10cSrcweir else if( !bHori ) 119cdf0e10cSrcweir ePos = (style::GraphicLocation)nTmp; 120cdf0e10cSrcweir else 121cdf0e10cSrcweir bRet = sal_False; 122cdf0e10cSrcweir 123cdf0e10cSrcweir bHori = sal_True; 124cdf0e10cSrcweir } 125cdf0e10cSrcweir else if( SvXMLUnitConverter::convertEnum( nTmp, aToken, pXML_BrushVerticalPos ) ) 126cdf0e10cSrcweir { 127cdf0e10cSrcweir if( bHori ) 128cdf0e10cSrcweir MergeXMLVertPos( ePos, (style::GraphicLocation)nTmp ); 129cdf0e10cSrcweir else if( !bVert ) 130cdf0e10cSrcweir ePos = (style::GraphicLocation)nTmp; 131cdf0e10cSrcweir else 132cdf0e10cSrcweir bRet = sal_False; 133cdf0e10cSrcweir bVert = sal_True; 134cdf0e10cSrcweir } 135cdf0e10cSrcweir else 136cdf0e10cSrcweir { 137cdf0e10cSrcweir bRet = sal_False; 138cdf0e10cSrcweir } 139cdf0e10cSrcweir } 140cdf0e10cSrcweir 141cdf0e10cSrcweir bRet &= style::GraphicLocation_NONE != ePos; 142cdf0e10cSrcweir if( bRet ) 143cdf0e10cSrcweir rValue <<= (style::GraphicLocation)(sal_uInt16)ePos; 144cdf0e10cSrcweir 145cdf0e10cSrcweir return bRet; 146cdf0e10cSrcweir } 147cdf0e10cSrcweir 148cdf0e10cSrcweir sal_Bool XMLBackGraphicPositionPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const 149cdf0e10cSrcweir { 150cdf0e10cSrcweir sal_Bool bRet = sal_True; 151cdf0e10cSrcweir OUStringBuffer aOut; 152cdf0e10cSrcweir 153cdf0e10cSrcweir style::GraphicLocation eLocation; 154cdf0e10cSrcweir if( !( rValue >>= eLocation ) ) 155cdf0e10cSrcweir { 156cdf0e10cSrcweir sal_Int32 nValue = 0; 157cdf0e10cSrcweir if( rValue >>= nValue ) 158cdf0e10cSrcweir eLocation = (style::GraphicLocation)nValue; 159cdf0e10cSrcweir else 160cdf0e10cSrcweir bRet = sal_False; 161cdf0e10cSrcweir } 162cdf0e10cSrcweir 163cdf0e10cSrcweir if( bRet ) 164cdf0e10cSrcweir { 165cdf0e10cSrcweir bRet = sal_False; 166cdf0e10cSrcweir 167cdf0e10cSrcweir switch( eLocation ) 168cdf0e10cSrcweir { 169cdf0e10cSrcweir case style::GraphicLocation_LEFT_TOP: 170cdf0e10cSrcweir case style::GraphicLocation_MIDDLE_TOP: 171cdf0e10cSrcweir case style::GraphicLocation_RIGHT_TOP: 172cdf0e10cSrcweir aOut.append( GetXMLToken(XML_TOP) ); 173cdf0e10cSrcweir bRet = sal_True; 174cdf0e10cSrcweir break; 175cdf0e10cSrcweir case style::GraphicLocation_LEFT_MIDDLE: 176cdf0e10cSrcweir case style::GraphicLocation_MIDDLE_MIDDLE: 177cdf0e10cSrcweir case style::GraphicLocation_RIGHT_MIDDLE: 178cdf0e10cSrcweir aOut.append( GetXMLToken(XML_CENTER) ); 179cdf0e10cSrcweir bRet = sal_True; 180cdf0e10cSrcweir break; 181cdf0e10cSrcweir case style::GraphicLocation_LEFT_BOTTOM: 182cdf0e10cSrcweir case style::GraphicLocation_MIDDLE_BOTTOM: 183cdf0e10cSrcweir case style::GraphicLocation_RIGHT_BOTTOM: 184cdf0e10cSrcweir aOut.append( GetXMLToken(XML_BOTTOM) ); 185cdf0e10cSrcweir bRet = sal_True; 186cdf0e10cSrcweir break; 187cdf0e10cSrcweir default: 188cdf0e10cSrcweir break; 189cdf0e10cSrcweir } 190cdf0e10cSrcweir 191cdf0e10cSrcweir if( bRet ) 192cdf0e10cSrcweir { 193cdf0e10cSrcweir aOut.append( sal_Unicode( ' ' ) ); 194cdf0e10cSrcweir 195cdf0e10cSrcweir switch( eLocation ) 196cdf0e10cSrcweir { 197cdf0e10cSrcweir case style::GraphicLocation_LEFT_TOP: 198cdf0e10cSrcweir case style::GraphicLocation_LEFT_BOTTOM: 199cdf0e10cSrcweir case style::GraphicLocation_LEFT_MIDDLE: 200cdf0e10cSrcweir aOut.append( GetXMLToken(XML_LEFT) ); 201cdf0e10cSrcweir break; 202cdf0e10cSrcweir case style::GraphicLocation_MIDDLE_TOP: 203cdf0e10cSrcweir case style::GraphicLocation_MIDDLE_MIDDLE: 204cdf0e10cSrcweir case style::GraphicLocation_MIDDLE_BOTTOM: 205cdf0e10cSrcweir aOut.append( GetXMLToken(XML_CENTER) ); 206cdf0e10cSrcweir break; 207cdf0e10cSrcweir case style::GraphicLocation_RIGHT_MIDDLE: 208cdf0e10cSrcweir case style::GraphicLocation_RIGHT_TOP: 209cdf0e10cSrcweir case style::GraphicLocation_RIGHT_BOTTOM: 210cdf0e10cSrcweir aOut.append( GetXMLToken(XML_RIGHT) ); 211cdf0e10cSrcweir break; 212cdf0e10cSrcweir default: 213cdf0e10cSrcweir break; 214cdf0e10cSrcweir } 215cdf0e10cSrcweir } 216cdf0e10cSrcweir } 217cdf0e10cSrcweir 218cdf0e10cSrcweir rStrExpValue = aOut.makeStringAndClear(); 219cdf0e10cSrcweir 220cdf0e10cSrcweir return bRet; 221cdf0e10cSrcweir } 222cdf0e10cSrcweir 223cdf0e10cSrcweir void XMLBackGraphicPositionPropHdl::MergeXMLVertPos( style::GraphicLocation& ePos, style::GraphicLocation eVert ) const 224cdf0e10cSrcweir { 225cdf0e10cSrcweir switch( ePos ) 226cdf0e10cSrcweir { 227cdf0e10cSrcweir case style::GraphicLocation_LEFT_TOP: 228cdf0e10cSrcweir case style::GraphicLocation_LEFT_MIDDLE: 229cdf0e10cSrcweir case style::GraphicLocation_LEFT_BOTTOM: 230cdf0e10cSrcweir ePos = style::GraphicLocation_MIDDLE_TOP==eVert ? 231cdf0e10cSrcweir style::GraphicLocation_LEFT_TOP : 232cdf0e10cSrcweir (style::GraphicLocation_MIDDLE_MIDDLE==eVert ? 233cdf0e10cSrcweir style::GraphicLocation_LEFT_MIDDLE : 234cdf0e10cSrcweir style::GraphicLocation_LEFT_BOTTOM); 235cdf0e10cSrcweir ePos = eVert; 236cdf0e10cSrcweir break; 237cdf0e10cSrcweir 238cdf0e10cSrcweir case style::GraphicLocation_MIDDLE_TOP: 239cdf0e10cSrcweir case style::GraphicLocation_MIDDLE_MIDDLE: 240cdf0e10cSrcweir case style::GraphicLocation_MIDDLE_BOTTOM: 241cdf0e10cSrcweir ePos = eVert; 242cdf0e10cSrcweir break; 243cdf0e10cSrcweir 244cdf0e10cSrcweir case style::GraphicLocation_RIGHT_TOP: 245cdf0e10cSrcweir case style::GraphicLocation_RIGHT_MIDDLE: 246cdf0e10cSrcweir case style::GraphicLocation_RIGHT_BOTTOM: 247cdf0e10cSrcweir ePos = style::GraphicLocation_MIDDLE_TOP==eVert ? 248cdf0e10cSrcweir style::GraphicLocation_RIGHT_TOP : 249cdf0e10cSrcweir (style::GraphicLocation_MIDDLE_MIDDLE==eVert ? 250cdf0e10cSrcweir style::GraphicLocation_RIGHT_MIDDLE : 251cdf0e10cSrcweir style::GraphicLocation_RIGHT_BOTTOM); 252cdf0e10cSrcweir break; 253cdf0e10cSrcweir default: 254cdf0e10cSrcweir break; 255cdf0e10cSrcweir } 256cdf0e10cSrcweir } 257cdf0e10cSrcweir 258cdf0e10cSrcweir void XMLBackGraphicPositionPropHdl::MergeXMLHoriPos( style::GraphicLocation& ePos, style::GraphicLocation eHori ) const 259cdf0e10cSrcweir { 260cdf0e10cSrcweir DBG_ASSERT( style::GraphicLocation_LEFT_MIDDLE==eHori || style::GraphicLocation_MIDDLE_MIDDLE==eHori || style::GraphicLocation_RIGHT_MIDDLE==eHori, 261cdf0e10cSrcweir "lcl_frmitems_MergeXMLHoriPos: vertical pos must be middle" ); 262cdf0e10cSrcweir 263cdf0e10cSrcweir switch( ePos ) 264cdf0e10cSrcweir { 265cdf0e10cSrcweir case style::GraphicLocation_LEFT_TOP: 266cdf0e10cSrcweir case style::GraphicLocation_MIDDLE_TOP: 267cdf0e10cSrcweir case style::GraphicLocation_RIGHT_TOP: 268cdf0e10cSrcweir ePos = style::GraphicLocation_LEFT_MIDDLE==eHori ? 269cdf0e10cSrcweir style::GraphicLocation_LEFT_TOP : 270cdf0e10cSrcweir (style::GraphicLocation_MIDDLE_MIDDLE==eHori ? 271cdf0e10cSrcweir style::GraphicLocation_MIDDLE_TOP : 272cdf0e10cSrcweir style::GraphicLocation_RIGHT_TOP); 273cdf0e10cSrcweir break; 274cdf0e10cSrcweir 275cdf0e10cSrcweir case style::GraphicLocation_LEFT_MIDDLE: 276cdf0e10cSrcweir case style::GraphicLocation_MIDDLE_MIDDLE: 277cdf0e10cSrcweir case style::GraphicLocation_RIGHT_MIDDLE: 278cdf0e10cSrcweir ePos = eHori; 279cdf0e10cSrcweir break; 280cdf0e10cSrcweir 281cdf0e10cSrcweir case style::GraphicLocation_LEFT_BOTTOM: 282cdf0e10cSrcweir case style::GraphicLocation_MIDDLE_BOTTOM: 283cdf0e10cSrcweir case style::GraphicLocation_RIGHT_BOTTOM: 284cdf0e10cSrcweir ePos = style::GraphicLocation_LEFT_MIDDLE==eHori ? 285cdf0e10cSrcweir style::GraphicLocation_LEFT_BOTTOM : 286cdf0e10cSrcweir (style::GraphicLocation_MIDDLE_MIDDLE==eHori ? 287cdf0e10cSrcweir style::GraphicLocation_MIDDLE_BOTTOM : 288cdf0e10cSrcweir style::GraphicLocation_RIGHT_BOTTOM); 289cdf0e10cSrcweir break; 290cdf0e10cSrcweir default: 291cdf0e10cSrcweir break; 292cdf0e10cSrcweir } 293cdf0e10cSrcweir } 294cdf0e10cSrcweir 295