xref: /aoo42x/main/sw/source/ui/vba/vbawrapformat.cxx (revision efeef26f)
1*efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*efeef26fSAndrew Rist  * distributed with this work for additional information
6*efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9*efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*efeef26fSAndrew Rist  *
11*efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*efeef26fSAndrew Rist  *
13*efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15*efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17*efeef26fSAndrew Rist  * specific language governing permissions and limitations
18*efeef26fSAndrew Rist  * under the License.
19*efeef26fSAndrew Rist  *
20*efeef26fSAndrew Rist  *************************************************************/
21*efeef26fSAndrew Rist 
22*efeef26fSAndrew Rist 
23cdf0e10cSrcweir #include "vbawrapformat.hxx"
24cdf0e10cSrcweir #include <ooo/vba/word/WdWrapSideType.hpp>
25cdf0e10cSrcweir #include <ooo/vba/word/WdWrapType.hpp>
26cdf0e10cSrcweir #include <com/sun/star/text/WrapTextMode.hpp>
27cdf0e10cSrcweir #include <vbahelper/vbahelper.hxx>
28cdf0e10cSrcweir #include <vbahelper/helperdecl.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir using namespace ooo::vba;
31cdf0e10cSrcweir using namespace com::sun::star;
32cdf0e10cSrcweir 
SwVbaWrapFormat(uno::Sequence<uno::Any> const & aArgs,uno::Reference<uno::XComponentContext> const & xContext)33cdf0e10cSrcweir 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 )
34cdf0e10cSrcweir {
35cdf0e10cSrcweir     m_xPropertySet.set( m_xShape, uno::UNO_QUERY_THROW );
36cdf0e10cSrcweir }
37cdf0e10cSrcweir 
makeWrap()38cdf0e10cSrcweir void SwVbaWrapFormat::makeWrap() throw (uno::RuntimeException)
39cdf0e10cSrcweir {
40cdf0e10cSrcweir     text::WrapTextMode eTextMode = text::WrapTextMode_NONE;
41cdf0e10cSrcweir     if( mnSide == word::WdWrapSideType::wdWrapLeft )
42cdf0e10cSrcweir     {
43cdf0e10cSrcweir         eTextMode = text::WrapTextMode_LEFT;
44cdf0e10cSrcweir     }
45cdf0e10cSrcweir     else if(  mnSide == word::WdWrapSideType::wdWrapRight )
46cdf0e10cSrcweir     {
47cdf0e10cSrcweir         eTextMode = text::WrapTextMode_RIGHT;
48cdf0e10cSrcweir     }
49cdf0e10cSrcweir     else if( mnSide == word::WdWrapSideType::wdWrapBoth ||
50cdf0e10cSrcweir             mnSide == word::WdWrapSideType::wdWrapLargest )
51cdf0e10cSrcweir     {
52cdf0e10cSrcweir         switch( mnWrapFormatType )
53cdf0e10cSrcweir         {
54cdf0e10cSrcweir             case word::WdWrapType::wdWrapNone:
55cdf0e10cSrcweir             case word::WdWrapType::wdWrapThrough:
56cdf0e10cSrcweir             {
57cdf0e10cSrcweir                 eTextMode = text::WrapTextMode_THROUGHT;
58cdf0e10cSrcweir                 break;
59cdf0e10cSrcweir             }
60cdf0e10cSrcweir             case word::WdWrapType::wdWrapInline:
61cdf0e10cSrcweir             case word::WdWrapType::wdWrapTopBottom:
62cdf0e10cSrcweir             {
63cdf0e10cSrcweir                 eTextMode = text::WrapTextMode_NONE;
64cdf0e10cSrcweir                 break;
65cdf0e10cSrcweir             }
66cdf0e10cSrcweir             case word::WdWrapType::wdWrapSquare:
67cdf0e10cSrcweir             {
68cdf0e10cSrcweir                 eTextMode = text::WrapTextMode_PARALLEL;
69cdf0e10cSrcweir                 m_xPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("SurroundContour") ), uno::makeAny( sal_False ) );
70cdf0e10cSrcweir                 break;
71cdf0e10cSrcweir             }
72cdf0e10cSrcweir             case word::WdWrapType::wdWrapTight:
73cdf0e10cSrcweir             {
74cdf0e10cSrcweir                 eTextMode = text::WrapTextMode_PARALLEL;
75cdf0e10cSrcweir                 m_xPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("SurroundContour") ), uno::makeAny( sal_True ) );
76cdf0e10cSrcweir                 break;
77cdf0e10cSrcweir             }
78cdf0e10cSrcweir             default:
79cdf0e10cSrcweir             {
80cdf0e10cSrcweir                 DebugHelper::exception(SbERR_BAD_ARGUMENT, rtl::OUString());
81cdf0e10cSrcweir             }
82cdf0e10cSrcweir         }
83cdf0e10cSrcweir     }
84cdf0e10cSrcweir     m_xPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TextWrap") ), uno::makeAny( eTextMode ) );
85cdf0e10cSrcweir }
86cdf0e10cSrcweir 
getType()87cdf0e10cSrcweir ::sal_Int32 SAL_CALL SwVbaWrapFormat::getType() throw (uno::RuntimeException)
88cdf0e10cSrcweir {
89cdf0e10cSrcweir     sal_Int32 nType = word::WdWrapType::wdWrapSquare;
90cdf0e10cSrcweir     text::WrapTextMode eTextMode;
91cdf0e10cSrcweir     m_xPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TextWrap") )) >>= eTextMode;
92cdf0e10cSrcweir     switch( eTextMode )
93cdf0e10cSrcweir     {
94cdf0e10cSrcweir         case text::WrapTextMode_NONE:
95cdf0e10cSrcweir         {
96cdf0e10cSrcweir             nType = word::WdWrapType::wdWrapTopBottom;
97cdf0e10cSrcweir             break;
98cdf0e10cSrcweir         }
99cdf0e10cSrcweir         case text::WrapTextMode_THROUGHT:
100cdf0e10cSrcweir         {
101cdf0e10cSrcweir             nType = word::WdWrapType::wdWrapNone;
102cdf0e10cSrcweir             break;
103cdf0e10cSrcweir         }
104cdf0e10cSrcweir         case text::WrapTextMode_PARALLEL:
105cdf0e10cSrcweir         {
106cdf0e10cSrcweir             sal_Bool bContour = sal_False;
107cdf0e10cSrcweir             m_xPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("SurroundContour") )) >>= bContour;
108cdf0e10cSrcweir             if( bContour )
109cdf0e10cSrcweir                 nType = word::WdWrapType::wdWrapTight;
110cdf0e10cSrcweir             else
111cdf0e10cSrcweir                 nType = word::WdWrapType::wdWrapSquare;
112cdf0e10cSrcweir             break;
113cdf0e10cSrcweir         }
114cdf0e10cSrcweir         case text::WrapTextMode_DYNAMIC:
115cdf0e10cSrcweir         case text::WrapTextMode_LEFT:
116cdf0e10cSrcweir         case text::WrapTextMode_RIGHT:
117cdf0e10cSrcweir         {
118cdf0e10cSrcweir             nType = word::WdWrapType::wdWrapThrough;
119cdf0e10cSrcweir             break;
120cdf0e10cSrcweir         }
121cdf0e10cSrcweir         default:
122cdf0e10cSrcweir         {
123cdf0e10cSrcweir             nType = word::WdWrapType::wdWrapSquare;
124cdf0e10cSrcweir         }
125cdf0e10cSrcweir     }
126cdf0e10cSrcweir     return nType;
127cdf0e10cSrcweir }
128cdf0e10cSrcweir 
setType(::sal_Int32 _type)129cdf0e10cSrcweir void SAL_CALL SwVbaWrapFormat::setType( ::sal_Int32 _type ) throw (uno::RuntimeException)
130cdf0e10cSrcweir {
131cdf0e10cSrcweir     mnWrapFormatType = _type;
132cdf0e10cSrcweir     makeWrap();
133cdf0e10cSrcweir }
134cdf0e10cSrcweir 
getSide()135cdf0e10cSrcweir ::sal_Int32 SAL_CALL SwVbaWrapFormat::getSide() throw (uno::RuntimeException)
136cdf0e10cSrcweir {
137cdf0e10cSrcweir     sal_Int32 nSide = word::WdWrapSideType::wdWrapBoth;
138cdf0e10cSrcweir     text::WrapTextMode eTextMode;
139cdf0e10cSrcweir     m_xPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TextWrap") )) >>= eTextMode;
140cdf0e10cSrcweir     switch( eTextMode )
141cdf0e10cSrcweir     {
142cdf0e10cSrcweir         case text::WrapTextMode_LEFT:
143cdf0e10cSrcweir         {
144cdf0e10cSrcweir             nSide = word::WdWrapSideType::wdWrapLeft;
145cdf0e10cSrcweir             break;
146cdf0e10cSrcweir         }
147cdf0e10cSrcweir         case text::WrapTextMode_RIGHT:
148cdf0e10cSrcweir         {
149cdf0e10cSrcweir             nSide = word::WdWrapSideType::wdWrapRight;
150cdf0e10cSrcweir             break;
151cdf0e10cSrcweir         }
152cdf0e10cSrcweir         default:
153cdf0e10cSrcweir         {
154cdf0e10cSrcweir             nSide = word::WdWrapSideType::wdWrapBoth;
155cdf0e10cSrcweir         }
156cdf0e10cSrcweir     }
157cdf0e10cSrcweir     return nSide;
158cdf0e10cSrcweir }
159cdf0e10cSrcweir 
setSide(::sal_Int32 _side)160cdf0e10cSrcweir void SAL_CALL SwVbaWrapFormat::setSide( ::sal_Int32 _side ) throw (uno::RuntimeException)
161cdf0e10cSrcweir {
162cdf0e10cSrcweir     mnSide = _side;
163cdf0e10cSrcweir     makeWrap();
164cdf0e10cSrcweir }
165cdf0e10cSrcweir 
getDistance(const rtl::OUString & sName)166cdf0e10cSrcweir float SwVbaWrapFormat::getDistance( const rtl::OUString& sName ) throw (uno::RuntimeException)
167cdf0e10cSrcweir {
168cdf0e10cSrcweir     sal_Int32 nDistance = 0;
169cdf0e10cSrcweir     m_xPropertySet->getPropertyValue( sName ) >>= nDistance;
170cdf0e10cSrcweir     return static_cast< float >( Millimeter::getInPoints( nDistance ) );
171cdf0e10cSrcweir }
172cdf0e10cSrcweir 
setDistance(const rtl::OUString & sName,float _distance)173cdf0e10cSrcweir void SwVbaWrapFormat::setDistance( const rtl::OUString& sName, float _distance ) throw (uno::RuntimeException)
174cdf0e10cSrcweir {
175cdf0e10cSrcweir     sal_Int32 nDistance = Millimeter::getInHundredthsOfOneMillimeter( _distance );
176cdf0e10cSrcweir     m_xPropertySet->setPropertyValue( sName, uno::makeAny( nDistance ) );
177cdf0e10cSrcweir }
178cdf0e10cSrcweir 
getDistanceTop()179cdf0e10cSrcweir float SAL_CALL SwVbaWrapFormat::getDistanceTop() throw (uno::RuntimeException)
180cdf0e10cSrcweir {
181cdf0e10cSrcweir     return getDistance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TopMargin") ) );
182cdf0e10cSrcweir }
183cdf0e10cSrcweir 
setDistanceTop(float _distancetop)184cdf0e10cSrcweir void SAL_CALL SwVbaWrapFormat::setDistanceTop( float _distancetop ) throw (uno::RuntimeException)
185cdf0e10cSrcweir {
186cdf0e10cSrcweir     setDistance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TopMargin") ), _distancetop );
187cdf0e10cSrcweir }
188cdf0e10cSrcweir 
getDistanceBottom()189cdf0e10cSrcweir float SAL_CALL SwVbaWrapFormat::getDistanceBottom() throw (uno::RuntimeException)
190cdf0e10cSrcweir {
191cdf0e10cSrcweir     return getDistance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("BottomMargin") ) );
192cdf0e10cSrcweir }
193cdf0e10cSrcweir 
setDistanceBottom(float _distancebottom)194cdf0e10cSrcweir void SAL_CALL SwVbaWrapFormat::setDistanceBottom( float _distancebottom ) throw (uno::RuntimeException)
195cdf0e10cSrcweir {
196cdf0e10cSrcweir     setDistance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("BottomMargin") ), _distancebottom );
197cdf0e10cSrcweir }
198cdf0e10cSrcweir 
getDistanceLeft()199cdf0e10cSrcweir float SAL_CALL SwVbaWrapFormat::getDistanceLeft() throw (uno::RuntimeException)
200cdf0e10cSrcweir {
201cdf0e10cSrcweir     return getDistance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("LeftMargin") ) );
202cdf0e10cSrcweir }
203cdf0e10cSrcweir 
setDistanceLeft(float _distanceleft)204cdf0e10cSrcweir void SAL_CALL SwVbaWrapFormat::setDistanceLeft( float _distanceleft ) throw (uno::RuntimeException)
205cdf0e10cSrcweir {
206cdf0e10cSrcweir     setDistance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("LeftMargin") ), _distanceleft );
207cdf0e10cSrcweir }
208cdf0e10cSrcweir 
getDistanceRight()209cdf0e10cSrcweir float SAL_CALL SwVbaWrapFormat::getDistanceRight() throw (uno::RuntimeException)
210cdf0e10cSrcweir {
211cdf0e10cSrcweir     return getDistance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightMargin") ) );
212cdf0e10cSrcweir }
213cdf0e10cSrcweir 
setDistanceRight(float _distanceright)214cdf0e10cSrcweir void SAL_CALL SwVbaWrapFormat::setDistanceRight( float _distanceright ) throw (uno::RuntimeException)
215cdf0e10cSrcweir {
216cdf0e10cSrcweir     setDistance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightMargin") ), _distanceright );
217cdf0e10cSrcweir }
218cdf0e10cSrcweir 
219cdf0e10cSrcweir rtl::OUString&
getServiceImplName()220cdf0e10cSrcweir SwVbaWrapFormat::getServiceImplName()
221cdf0e10cSrcweir {
222cdf0e10cSrcweir 	static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaWrapFormat") );
223cdf0e10cSrcweir 	return sImplName;
224cdf0e10cSrcweir }
225cdf0e10cSrcweir 
226cdf0e10cSrcweir uno::Sequence< rtl::OUString >
getServiceNames()227cdf0e10cSrcweir SwVbaWrapFormat::getServiceNames()
228cdf0e10cSrcweir {
229cdf0e10cSrcweir 	static uno::Sequence< rtl::OUString > aServiceNames;
230cdf0e10cSrcweir 	if ( aServiceNames.getLength() == 0 )
231cdf0e10cSrcweir 	{
232cdf0e10cSrcweir 		aServiceNames.realloc( 1 );
233cdf0e10cSrcweir 		aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.WrapFormat" ) );
234cdf0e10cSrcweir 	}
235cdf0e10cSrcweir 	return aServiceNames;
236cdf0e10cSrcweir }
237cdf0e10cSrcweir 
238cdf0e10cSrcweir namespace wrapformat
239cdf0e10cSrcweir {
240cdf0e10cSrcweir namespace sdecl = comphelper::service_decl;
241cdf0e10cSrcweir sdecl::vba_service_class_<SwVbaWrapFormat, sdecl::with_args<true> > serviceImpl;
242cdf0e10cSrcweir extern sdecl::ServiceDecl const serviceDecl(
243cdf0e10cSrcweir     serviceImpl,
244cdf0e10cSrcweir     "SwVbaWrapFormat",
245cdf0e10cSrcweir     "ooo.vba.word.WrapFormat" );
246cdf0e10cSrcweir }
247cdf0e10cSrcweir 
248cdf0e10cSrcweir 
249