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 #include "vbawrapformat.hxx" 28*cdf0e10cSrcweir #include <ooo/vba/word/WdWrapSideType.hpp> 29*cdf0e10cSrcweir #include <ooo/vba/word/WdWrapType.hpp> 30*cdf0e10cSrcweir #include <com/sun/star/text/WrapTextMode.hpp> 31*cdf0e10cSrcweir #include <vbahelper/vbahelper.hxx> 32*cdf0e10cSrcweir #include <vbahelper/helperdecl.hxx> 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir using namespace ooo::vba; 35*cdf0e10cSrcweir using namespace com::sun::star; 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir SwVbaWrapFormat::SwVbaWrapFormat( uno::Sequence< uno::Any > const& aArgs, uno::Reference< uno::XComponentContext >const& xContext ) : SwVbaWrapFormat_BASE( getXSomethingFromArgs< XHelperInterface >( aArgs, 0 ), xContext ), m_xShape( getXSomethingFromArgs< drawing::XShape >( aArgs, 1, false ) ), mnWrapFormatType( 0 ), mnSide( word::WdWrapSideType::wdWrapBoth ) 38*cdf0e10cSrcweir { 39*cdf0e10cSrcweir m_xPropertySet.set( m_xShape, uno::UNO_QUERY_THROW ); 40*cdf0e10cSrcweir } 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir void SwVbaWrapFormat::makeWrap() throw (uno::RuntimeException) 43*cdf0e10cSrcweir { 44*cdf0e10cSrcweir text::WrapTextMode eTextMode = text::WrapTextMode_NONE; 45*cdf0e10cSrcweir if( mnSide == word::WdWrapSideType::wdWrapLeft ) 46*cdf0e10cSrcweir { 47*cdf0e10cSrcweir eTextMode = text::WrapTextMode_LEFT; 48*cdf0e10cSrcweir } 49*cdf0e10cSrcweir else if( mnSide == word::WdWrapSideType::wdWrapRight ) 50*cdf0e10cSrcweir { 51*cdf0e10cSrcweir eTextMode = text::WrapTextMode_RIGHT; 52*cdf0e10cSrcweir } 53*cdf0e10cSrcweir else if( mnSide == word::WdWrapSideType::wdWrapBoth || 54*cdf0e10cSrcweir mnSide == word::WdWrapSideType::wdWrapLargest ) 55*cdf0e10cSrcweir { 56*cdf0e10cSrcweir switch( mnWrapFormatType ) 57*cdf0e10cSrcweir { 58*cdf0e10cSrcweir case word::WdWrapType::wdWrapNone: 59*cdf0e10cSrcweir case word::WdWrapType::wdWrapThrough: 60*cdf0e10cSrcweir { 61*cdf0e10cSrcweir eTextMode = text::WrapTextMode_THROUGHT; 62*cdf0e10cSrcweir break; 63*cdf0e10cSrcweir } 64*cdf0e10cSrcweir case word::WdWrapType::wdWrapInline: 65*cdf0e10cSrcweir case word::WdWrapType::wdWrapTopBottom: 66*cdf0e10cSrcweir { 67*cdf0e10cSrcweir eTextMode = text::WrapTextMode_NONE; 68*cdf0e10cSrcweir break; 69*cdf0e10cSrcweir } 70*cdf0e10cSrcweir case word::WdWrapType::wdWrapSquare: 71*cdf0e10cSrcweir { 72*cdf0e10cSrcweir eTextMode = text::WrapTextMode_PARALLEL; 73*cdf0e10cSrcweir m_xPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("SurroundContour") ), uno::makeAny( sal_False ) ); 74*cdf0e10cSrcweir break; 75*cdf0e10cSrcweir } 76*cdf0e10cSrcweir case word::WdWrapType::wdWrapTight: 77*cdf0e10cSrcweir { 78*cdf0e10cSrcweir eTextMode = text::WrapTextMode_PARALLEL; 79*cdf0e10cSrcweir m_xPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("SurroundContour") ), uno::makeAny( sal_True ) ); 80*cdf0e10cSrcweir break; 81*cdf0e10cSrcweir } 82*cdf0e10cSrcweir default: 83*cdf0e10cSrcweir { 84*cdf0e10cSrcweir DebugHelper::exception(SbERR_BAD_ARGUMENT, rtl::OUString()); 85*cdf0e10cSrcweir } 86*cdf0e10cSrcweir } 87*cdf0e10cSrcweir } 88*cdf0e10cSrcweir m_xPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TextWrap") ), uno::makeAny( eTextMode ) ); 89*cdf0e10cSrcweir } 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir ::sal_Int32 SAL_CALL SwVbaWrapFormat::getType() throw (uno::RuntimeException) 92*cdf0e10cSrcweir { 93*cdf0e10cSrcweir sal_Int32 nType = word::WdWrapType::wdWrapSquare; 94*cdf0e10cSrcweir text::WrapTextMode eTextMode; 95*cdf0e10cSrcweir m_xPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TextWrap") )) >>= eTextMode; 96*cdf0e10cSrcweir switch( eTextMode ) 97*cdf0e10cSrcweir { 98*cdf0e10cSrcweir case text::WrapTextMode_NONE: 99*cdf0e10cSrcweir { 100*cdf0e10cSrcweir nType = word::WdWrapType::wdWrapTopBottom; 101*cdf0e10cSrcweir break; 102*cdf0e10cSrcweir } 103*cdf0e10cSrcweir case text::WrapTextMode_THROUGHT: 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir nType = word::WdWrapType::wdWrapNone; 106*cdf0e10cSrcweir break; 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir case text::WrapTextMode_PARALLEL: 109*cdf0e10cSrcweir { 110*cdf0e10cSrcweir sal_Bool bContour = sal_False; 111*cdf0e10cSrcweir m_xPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("SurroundContour") )) >>= bContour; 112*cdf0e10cSrcweir if( bContour ) 113*cdf0e10cSrcweir nType = word::WdWrapType::wdWrapTight; 114*cdf0e10cSrcweir else 115*cdf0e10cSrcweir nType = word::WdWrapType::wdWrapSquare; 116*cdf0e10cSrcweir break; 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir case text::WrapTextMode_DYNAMIC: 119*cdf0e10cSrcweir case text::WrapTextMode_LEFT: 120*cdf0e10cSrcweir case text::WrapTextMode_RIGHT: 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir nType = word::WdWrapType::wdWrapThrough; 123*cdf0e10cSrcweir break; 124*cdf0e10cSrcweir } 125*cdf0e10cSrcweir default: 126*cdf0e10cSrcweir { 127*cdf0e10cSrcweir nType = word::WdWrapType::wdWrapSquare; 128*cdf0e10cSrcweir } 129*cdf0e10cSrcweir } 130*cdf0e10cSrcweir return nType; 131*cdf0e10cSrcweir } 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir void SAL_CALL SwVbaWrapFormat::setType( ::sal_Int32 _type ) throw (uno::RuntimeException) 134*cdf0e10cSrcweir { 135*cdf0e10cSrcweir mnWrapFormatType = _type; 136*cdf0e10cSrcweir makeWrap(); 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir ::sal_Int32 SAL_CALL SwVbaWrapFormat::getSide() throw (uno::RuntimeException) 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir sal_Int32 nSide = word::WdWrapSideType::wdWrapBoth; 142*cdf0e10cSrcweir text::WrapTextMode eTextMode; 143*cdf0e10cSrcweir m_xPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TextWrap") )) >>= eTextMode; 144*cdf0e10cSrcweir switch( eTextMode ) 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir case text::WrapTextMode_LEFT: 147*cdf0e10cSrcweir { 148*cdf0e10cSrcweir nSide = word::WdWrapSideType::wdWrapLeft; 149*cdf0e10cSrcweir break; 150*cdf0e10cSrcweir } 151*cdf0e10cSrcweir case text::WrapTextMode_RIGHT: 152*cdf0e10cSrcweir { 153*cdf0e10cSrcweir nSide = word::WdWrapSideType::wdWrapRight; 154*cdf0e10cSrcweir break; 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir default: 157*cdf0e10cSrcweir { 158*cdf0e10cSrcweir nSide = word::WdWrapSideType::wdWrapBoth; 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir return nSide; 162*cdf0e10cSrcweir } 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir void SAL_CALL SwVbaWrapFormat::setSide( ::sal_Int32 _side ) throw (uno::RuntimeException) 165*cdf0e10cSrcweir { 166*cdf0e10cSrcweir mnSide = _side; 167*cdf0e10cSrcweir makeWrap(); 168*cdf0e10cSrcweir } 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir float SwVbaWrapFormat::getDistance( const rtl::OUString& sName ) throw (uno::RuntimeException) 171*cdf0e10cSrcweir { 172*cdf0e10cSrcweir sal_Int32 nDistance = 0; 173*cdf0e10cSrcweir m_xPropertySet->getPropertyValue( sName ) >>= nDistance; 174*cdf0e10cSrcweir return static_cast< float >( Millimeter::getInPoints( nDistance ) ); 175*cdf0e10cSrcweir } 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir void SwVbaWrapFormat::setDistance( const rtl::OUString& sName, float _distance ) throw (uno::RuntimeException) 178*cdf0e10cSrcweir { 179*cdf0e10cSrcweir sal_Int32 nDistance = Millimeter::getInHundredthsOfOneMillimeter( _distance ); 180*cdf0e10cSrcweir m_xPropertySet->setPropertyValue( sName, uno::makeAny( nDistance ) ); 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir float SAL_CALL SwVbaWrapFormat::getDistanceTop() throw (uno::RuntimeException) 184*cdf0e10cSrcweir { 185*cdf0e10cSrcweir return getDistance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TopMargin") ) ); 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir void SAL_CALL SwVbaWrapFormat::setDistanceTop( float _distancetop ) throw (uno::RuntimeException) 189*cdf0e10cSrcweir { 190*cdf0e10cSrcweir setDistance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TopMargin") ), _distancetop ); 191*cdf0e10cSrcweir } 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir float SAL_CALL SwVbaWrapFormat::getDistanceBottom() throw (uno::RuntimeException) 194*cdf0e10cSrcweir { 195*cdf0e10cSrcweir return getDistance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("BottomMargin") ) ); 196*cdf0e10cSrcweir } 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir void SAL_CALL SwVbaWrapFormat::setDistanceBottom( float _distancebottom ) throw (uno::RuntimeException) 199*cdf0e10cSrcweir { 200*cdf0e10cSrcweir setDistance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("BottomMargin") ), _distancebottom ); 201*cdf0e10cSrcweir } 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir float SAL_CALL SwVbaWrapFormat::getDistanceLeft() throw (uno::RuntimeException) 204*cdf0e10cSrcweir { 205*cdf0e10cSrcweir return getDistance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("LeftMargin") ) ); 206*cdf0e10cSrcweir } 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir void SAL_CALL SwVbaWrapFormat::setDistanceLeft( float _distanceleft ) throw (uno::RuntimeException) 209*cdf0e10cSrcweir { 210*cdf0e10cSrcweir setDistance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("LeftMargin") ), _distanceleft ); 211*cdf0e10cSrcweir } 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir float SAL_CALL SwVbaWrapFormat::getDistanceRight() throw (uno::RuntimeException) 214*cdf0e10cSrcweir { 215*cdf0e10cSrcweir return getDistance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightMargin") ) ); 216*cdf0e10cSrcweir } 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir void SAL_CALL SwVbaWrapFormat::setDistanceRight( float _distanceright ) throw (uno::RuntimeException) 219*cdf0e10cSrcweir { 220*cdf0e10cSrcweir setDistance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightMargin") ), _distanceright ); 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir rtl::OUString& 224*cdf0e10cSrcweir SwVbaWrapFormat::getServiceImplName() 225*cdf0e10cSrcweir { 226*cdf0e10cSrcweir static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaWrapFormat") ); 227*cdf0e10cSrcweir return sImplName; 228*cdf0e10cSrcweir } 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir uno::Sequence< rtl::OUString > 231*cdf0e10cSrcweir SwVbaWrapFormat::getServiceNames() 232*cdf0e10cSrcweir { 233*cdf0e10cSrcweir static uno::Sequence< rtl::OUString > aServiceNames; 234*cdf0e10cSrcweir if ( aServiceNames.getLength() == 0 ) 235*cdf0e10cSrcweir { 236*cdf0e10cSrcweir aServiceNames.realloc( 1 ); 237*cdf0e10cSrcweir aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.WrapFormat" ) ); 238*cdf0e10cSrcweir } 239*cdf0e10cSrcweir return aServiceNames; 240*cdf0e10cSrcweir } 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir namespace wrapformat 243*cdf0e10cSrcweir { 244*cdf0e10cSrcweir namespace sdecl = comphelper::service_decl; 245*cdf0e10cSrcweir sdecl::vba_service_class_<SwVbaWrapFormat, sdecl::with_args<true> > serviceImpl; 246*cdf0e10cSrcweir extern sdecl::ServiceDecl const serviceDecl( 247*cdf0e10cSrcweir serviceImpl, 248*cdf0e10cSrcweir "SwVbaWrapFormat", 249*cdf0e10cSrcweir "ooo.vba.word.WrapFormat" ); 250*cdf0e10cSrcweir } 251*cdf0e10cSrcweir 252*cdf0e10cSrcweir 253