update dev300-m58
[ooovba.git] / sw / source / ui / vba / vbawrapformat.cxx
bloba169e9530a9dee0920cee833ba76283449dc1a8a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vbawrapformat.cxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #include "vbawrapformat.hxx"
31 #include <ooo/vba/word/WdWrapSideType.hpp>
32 #include <ooo/vba/word/WdWrapType.hpp>
33 #include <com/sun/star/text/WrapTextMode.hpp>
34 #include <vbahelper/vbahelper.hxx>
35 #include <vbahelper/helperdecl.hxx>
37 using namespace ooo::vba;
38 using namespace com::sun::star;
40 SwVbaWrapFormat::SwVbaWrapFormat( const uno::Reference< ov::XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< drawing::XShape > xShape ) : SwVbaWrapFormat_BASE( xParent, xContext ), m_xShape( xShape ), mnWrapFormatType( 0 ), mnSide( word::WdWrapSideType::wdWrapBoth )
42 m_xPropertySet.set( xShape, uno::UNO_QUERY_THROW );
45 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 )
47 m_xPropertySet.set( m_xShape, uno::UNO_QUERY_THROW );
50 void SwVbaWrapFormat::makeWrap() throw (uno::RuntimeException)
52 text::WrapTextMode eTextMode = text::WrapTextMode_NONE;
53 if( mnSide == word::WdWrapSideType::wdWrapLeft )
55 eTextMode = text::WrapTextMode_LEFT;
57 else if( mnSide == word::WdWrapSideType::wdWrapRight )
59 eTextMode = text::WrapTextMode_RIGHT;
61 else if( mnSide == word::WdWrapSideType::wdWrapBoth ||
62 mnSide == word::WdWrapSideType::wdWrapLargest )
64 switch( mnWrapFormatType )
66 case word::WdWrapType::wdWrapNone:
67 case word::WdWrapType::wdWrapThrough:
69 eTextMode = text::WrapTextMode_THROUGHT;
70 break;
72 case word::WdWrapType::wdWrapInline:
73 case word::WdWrapType::wdWrapTopBottom:
75 eTextMode = text::WrapTextMode_NONE;
76 break;
78 case word::WdWrapType::wdWrapSquare:
80 eTextMode = text::WrapTextMode_PARALLEL;
81 m_xPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("SurroundContour") ), uno::makeAny( sal_False ) );
82 break;
84 case word::WdWrapType::wdWrapTight:
86 eTextMode = text::WrapTextMode_PARALLEL;
87 m_xPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("SurroundContour") ), uno::makeAny( sal_True ) );
88 break;
90 default:
92 DebugHelper::exception(SbERR_BAD_ARGUMENT, rtl::OUString());
96 m_xPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TextWrap") ), uno::makeAny( eTextMode ) );
99 ::sal_Int32 SAL_CALL SwVbaWrapFormat::getType() throw (uno::RuntimeException)
101 sal_Int32 nType = word::WdWrapType::wdWrapSquare;
102 text::WrapTextMode eTextMode;
103 m_xPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TextWrap") )) >>= eTextMode;
104 switch( eTextMode )
106 case text::WrapTextMode_NONE:
108 nType = word::WdWrapType::wdWrapTopBottom;
109 break;
111 case text::WrapTextMode_THROUGHT:
113 nType = word::WdWrapType::wdWrapNone;
114 break;
116 case text::WrapTextMode_PARALLEL:
118 sal_Bool bContour = sal_False;
119 m_xPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("SurroundContour") )) >>= bContour;
120 if( bContour )
121 nType = word::WdWrapType::wdWrapTight;
122 else
123 nType = word::WdWrapType::wdWrapSquare;
124 break;
126 case text::WrapTextMode_DYNAMIC:
127 case text::WrapTextMode_LEFT:
128 case text::WrapTextMode_RIGHT:
130 nType = word::WdWrapType::wdWrapThrough;
131 break;
133 default:
135 nType = word::WdWrapType::wdWrapSquare;
138 return nType;
141 void SAL_CALL SwVbaWrapFormat::setType( ::sal_Int32 _type ) throw (uno::RuntimeException)
143 mnWrapFormatType = _type;
144 makeWrap();
147 ::sal_Int32 SAL_CALL SwVbaWrapFormat::getSide() throw (uno::RuntimeException)
149 sal_Int32 nSide = word::WdWrapSideType::wdWrapBoth;
150 text::WrapTextMode eTextMode;
151 m_xPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TextWrap") )) >>= eTextMode;
152 switch( eTextMode )
154 case text::WrapTextMode_LEFT:
156 nSide = word::WdWrapSideType::wdWrapLeft;
157 break;
159 case text::WrapTextMode_RIGHT:
161 nSide = word::WdWrapSideType::wdWrapRight;
162 break;
164 default:
166 nSide = word::WdWrapSideType::wdWrapBoth;
169 return nSide;
172 void SAL_CALL SwVbaWrapFormat::setSide( ::sal_Int32 _side ) throw (uno::RuntimeException)
174 mnSide = _side;
175 makeWrap();
178 float SwVbaWrapFormat::getDistance( const rtl::OUString& sName ) throw (uno::RuntimeException)
180 sal_Int32 nDistance = 0;
181 m_xPropertySet->getPropertyValue( sName ) >>= nDistance;
182 return static_cast< float >( Millimeter::getInPoints( nDistance ) );
185 void SwVbaWrapFormat::setDistance( const rtl::OUString& sName, float _distance ) throw (uno::RuntimeException)
187 sal_Int32 nDistance = Millimeter::getInHundredthsOfOneMillimeter( _distance );
188 m_xPropertySet->setPropertyValue( sName, uno::makeAny( nDistance ) );
191 float SAL_CALL SwVbaWrapFormat::getDistanceTop() throw (uno::RuntimeException)
193 return getDistance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TopMargin") ) );
196 void SAL_CALL SwVbaWrapFormat::setDistanceTop( float _distancetop ) throw (uno::RuntimeException)
198 setDistance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TopMargin") ), _distancetop );
201 float SAL_CALL SwVbaWrapFormat::getDistanceBottom() throw (uno::RuntimeException)
203 return getDistance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("BottomMargin") ) );
206 void SAL_CALL SwVbaWrapFormat::setDistanceBottom( float _distancebottom ) throw (uno::RuntimeException)
208 setDistance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("BottomMargin") ), _distancebottom );
211 float SAL_CALL SwVbaWrapFormat::getDistanceLeft() throw (uno::RuntimeException)
213 return getDistance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("LeftMargin") ) );
216 void SAL_CALL SwVbaWrapFormat::setDistanceLeft( float _distanceleft ) throw (uno::RuntimeException)
218 setDistance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("LeftMargin") ), _distanceleft );
221 float SAL_CALL SwVbaWrapFormat::getDistanceRight() throw (uno::RuntimeException)
223 return getDistance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightMargin") ) );
226 void SAL_CALL SwVbaWrapFormat::setDistanceRight( float _distanceright ) throw (uno::RuntimeException)
228 setDistance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightMargin") ), _distanceright );
231 rtl::OUString&
232 SwVbaWrapFormat::getServiceImplName()
234 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaWrapFormat") );
235 return sImplName;
238 uno::Sequence< rtl::OUString >
239 SwVbaWrapFormat::getServiceNames()
241 static uno::Sequence< rtl::OUString > aServiceNames;
242 if ( aServiceNames.getLength() == 0 )
244 aServiceNames.realloc( 1 );
245 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.WrapFormat" ) );
247 return aServiceNames;
250 namespace wrapformat
252 namespace sdecl = comphelper::service_decl;
253 sdecl::vba_service_class_<SwVbaWrapFormat, sdecl::with_args<true> > serviceImpl;
254 extern sdecl::ServiceDecl const serviceDecl(
255 serviceImpl,
256 "SwVbaWrapFormat",
257 "ooo.vba.word.WrapFormat" );