1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 #include "vbawrapformat.hxx" 28 #include <ooo/vba/word/WdWrapSideType.hpp> 29 #include <ooo/vba/word/WdWrapType.hpp> 30 #include <com/sun/star/text/WrapTextMode.hpp> 31 #include <vbahelper/vbahelper.hxx> 32 #include <vbahelper/helperdecl.hxx> 33 34 using namespace ooo::vba; 35 using namespace com::sun::star; 36 37 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 { 39 m_xPropertySet.set( m_xShape, uno::UNO_QUERY_THROW ); 40 } 41 42 void SwVbaWrapFormat::makeWrap() throw (uno::RuntimeException) 43 { 44 text::WrapTextMode eTextMode = text::WrapTextMode_NONE; 45 if( mnSide == word::WdWrapSideType::wdWrapLeft ) 46 { 47 eTextMode = text::WrapTextMode_LEFT; 48 } 49 else if( mnSide == word::WdWrapSideType::wdWrapRight ) 50 { 51 eTextMode = text::WrapTextMode_RIGHT; 52 } 53 else if( mnSide == word::WdWrapSideType::wdWrapBoth || 54 mnSide == word::WdWrapSideType::wdWrapLargest ) 55 { 56 switch( mnWrapFormatType ) 57 { 58 case word::WdWrapType::wdWrapNone: 59 case word::WdWrapType::wdWrapThrough: 60 { 61 eTextMode = text::WrapTextMode_THROUGHT; 62 break; 63 } 64 case word::WdWrapType::wdWrapInline: 65 case word::WdWrapType::wdWrapTopBottom: 66 { 67 eTextMode = text::WrapTextMode_NONE; 68 break; 69 } 70 case word::WdWrapType::wdWrapSquare: 71 { 72 eTextMode = text::WrapTextMode_PARALLEL; 73 m_xPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("SurroundContour") ), uno::makeAny( sal_False ) ); 74 break; 75 } 76 case word::WdWrapType::wdWrapTight: 77 { 78 eTextMode = text::WrapTextMode_PARALLEL; 79 m_xPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("SurroundContour") ), uno::makeAny( sal_True ) ); 80 break; 81 } 82 default: 83 { 84 DebugHelper::exception(SbERR_BAD_ARGUMENT, rtl::OUString()); 85 } 86 } 87 } 88 m_xPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TextWrap") ), uno::makeAny( eTextMode ) ); 89 } 90 91 ::sal_Int32 SAL_CALL SwVbaWrapFormat::getType() throw (uno::RuntimeException) 92 { 93 sal_Int32 nType = word::WdWrapType::wdWrapSquare; 94 text::WrapTextMode eTextMode; 95 m_xPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TextWrap") )) >>= eTextMode; 96 switch( eTextMode ) 97 { 98 case text::WrapTextMode_NONE: 99 { 100 nType = word::WdWrapType::wdWrapTopBottom; 101 break; 102 } 103 case text::WrapTextMode_THROUGHT: 104 { 105 nType = word::WdWrapType::wdWrapNone; 106 break; 107 } 108 case text::WrapTextMode_PARALLEL: 109 { 110 sal_Bool bContour = sal_False; 111 m_xPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("SurroundContour") )) >>= bContour; 112 if( bContour ) 113 nType = word::WdWrapType::wdWrapTight; 114 else 115 nType = word::WdWrapType::wdWrapSquare; 116 break; 117 } 118 case text::WrapTextMode_DYNAMIC: 119 case text::WrapTextMode_LEFT: 120 case text::WrapTextMode_RIGHT: 121 { 122 nType = word::WdWrapType::wdWrapThrough; 123 break; 124 } 125 default: 126 { 127 nType = word::WdWrapType::wdWrapSquare; 128 } 129 } 130 return nType; 131 } 132 133 void SAL_CALL SwVbaWrapFormat::setType( ::sal_Int32 _type ) throw (uno::RuntimeException) 134 { 135 mnWrapFormatType = _type; 136 makeWrap(); 137 } 138 139 ::sal_Int32 SAL_CALL SwVbaWrapFormat::getSide() throw (uno::RuntimeException) 140 { 141 sal_Int32 nSide = word::WdWrapSideType::wdWrapBoth; 142 text::WrapTextMode eTextMode; 143 m_xPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TextWrap") )) >>= eTextMode; 144 switch( eTextMode ) 145 { 146 case text::WrapTextMode_LEFT: 147 { 148 nSide = word::WdWrapSideType::wdWrapLeft; 149 break; 150 } 151 case text::WrapTextMode_RIGHT: 152 { 153 nSide = word::WdWrapSideType::wdWrapRight; 154 break; 155 } 156 default: 157 { 158 nSide = word::WdWrapSideType::wdWrapBoth; 159 } 160 } 161 return nSide; 162 } 163 164 void SAL_CALL SwVbaWrapFormat::setSide( ::sal_Int32 _side ) throw (uno::RuntimeException) 165 { 166 mnSide = _side; 167 makeWrap(); 168 } 169 170 float SwVbaWrapFormat::getDistance( const rtl::OUString& sName ) throw (uno::RuntimeException) 171 { 172 sal_Int32 nDistance = 0; 173 m_xPropertySet->getPropertyValue( sName ) >>= nDistance; 174 return static_cast< float >( Millimeter::getInPoints( nDistance ) ); 175 } 176 177 void SwVbaWrapFormat::setDistance( const rtl::OUString& sName, float _distance ) throw (uno::RuntimeException) 178 { 179 sal_Int32 nDistance = Millimeter::getInHundredthsOfOneMillimeter( _distance ); 180 m_xPropertySet->setPropertyValue( sName, uno::makeAny( nDistance ) ); 181 } 182 183 float SAL_CALL SwVbaWrapFormat::getDistanceTop() throw (uno::RuntimeException) 184 { 185 return getDistance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TopMargin") ) ); 186 } 187 188 void SAL_CALL SwVbaWrapFormat::setDistanceTop( float _distancetop ) throw (uno::RuntimeException) 189 { 190 setDistance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TopMargin") ), _distancetop ); 191 } 192 193 float SAL_CALL SwVbaWrapFormat::getDistanceBottom() throw (uno::RuntimeException) 194 { 195 return getDistance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("BottomMargin") ) ); 196 } 197 198 void SAL_CALL SwVbaWrapFormat::setDistanceBottom( float _distancebottom ) throw (uno::RuntimeException) 199 { 200 setDistance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("BottomMargin") ), _distancebottom ); 201 } 202 203 float SAL_CALL SwVbaWrapFormat::getDistanceLeft() throw (uno::RuntimeException) 204 { 205 return getDistance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("LeftMargin") ) ); 206 } 207 208 void SAL_CALL SwVbaWrapFormat::setDistanceLeft( float _distanceleft ) throw (uno::RuntimeException) 209 { 210 setDistance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("LeftMargin") ), _distanceleft ); 211 } 212 213 float SAL_CALL SwVbaWrapFormat::getDistanceRight() throw (uno::RuntimeException) 214 { 215 return getDistance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightMargin") ) ); 216 } 217 218 void SAL_CALL SwVbaWrapFormat::setDistanceRight( float _distanceright ) throw (uno::RuntimeException) 219 { 220 setDistance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightMargin") ), _distanceright ); 221 } 222 223 rtl::OUString& 224 SwVbaWrapFormat::getServiceImplName() 225 { 226 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaWrapFormat") ); 227 return sImplName; 228 } 229 230 uno::Sequence< rtl::OUString > 231 SwVbaWrapFormat::getServiceNames() 232 { 233 static uno::Sequence< rtl::OUString > aServiceNames; 234 if ( aServiceNames.getLength() == 0 ) 235 { 236 aServiceNames.realloc( 1 ); 237 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.WrapFormat" ) ); 238 } 239 return aServiceNames; 240 } 241 242 namespace wrapformat 243 { 244 namespace sdecl = comphelper::service_decl; 245 sdecl::vba_service_class_<SwVbaWrapFormat, sdecl::with_args<true> > serviceImpl; 246 extern sdecl::ServiceDecl const serviceDecl( 247 serviceImpl, 248 "SwVbaWrapFormat", 249 "ooo.vba.word.WrapFormat" ); 250 } 251 252 253