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