1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20 #include <sal/config.h>
21
22 #include "vbawrapformat.hxx"
23 #include <ooo/vba/word/WdWrapSideType.hpp>
24 #include <ooo/vba/word/WdWrapType.hpp>
25 #include <com/sun/star/beans/XPropertySet.hpp>
26 #include <com/sun/star/text/WrapTextMode.hpp>
27 #include <basic/sberrors.hxx>
28 #include <vbahelper/vbahelper.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()
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_THROUGH;
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("SurroundContour", uno::makeAny( false ) );
70 break;
71 }
72 case word::WdWrapType::wdWrapTight:
73 {
74 eTextMode = text::WrapTextMode_PARALLEL;
75 m_xPropertySet->setPropertyValue("SurroundContour", uno::makeAny( true ) );
76 break;
77 }
78 default:
79 {
80 DebugHelper::runtimeexception(ERRCODE_BASIC_BAD_ARGUMENT);
81 }
82 }
83 }
84 m_xPropertySet->setPropertyValue("TextWrap", uno::makeAny( eTextMode ) );
85 }
86
getType()87 ::sal_Int32 SAL_CALL SwVbaWrapFormat::getType()
88 {
89 sal_Int32 nType = word::WdWrapType::wdWrapSquare;
90 text::WrapTextMode eTextMode;
91 m_xPropertySet->getPropertyValue("TextWrap") >>= eTextMode;
92 switch( eTextMode )
93 {
94 case text::WrapTextMode_NONE:
95 {
96 nType = word::WdWrapType::wdWrapTopBottom;
97 break;
98 }
99 case text::WrapTextMode_THROUGH:
100 {
101 nType = word::WdWrapType::wdWrapNone;
102 break;
103 }
104 case text::WrapTextMode_PARALLEL:
105 {
106 bool bContour = false;
107 m_xPropertySet->getPropertyValue("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 )
130 {
131 mnWrapFormatType = _type;
132 makeWrap();
133 }
134
getSide()135 ::sal_Int32 SAL_CALL SwVbaWrapFormat::getSide()
136 {
137 sal_Int32 nSide = word::WdWrapSideType::wdWrapBoth;
138 text::WrapTextMode eTextMode;
139 m_xPropertySet->getPropertyValue("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 )
161 {
162 mnSide = _side;
163 makeWrap();
164 }
165
getDistance(const OUString & sName)166 float SwVbaWrapFormat::getDistance( const OUString& sName )
167 {
168 sal_Int32 nDistance = 0;
169 m_xPropertySet->getPropertyValue( sName ) >>= nDistance;
170 return static_cast< float >( Millimeter::getInPoints( nDistance ) );
171 }
172
setDistance(const OUString & sName,float _distance)173 void SwVbaWrapFormat::setDistance( const OUString& sName, float _distance )
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()
180 {
181 return getDistance( "TopMargin" );
182 }
183
setDistanceTop(float _distancetop)184 void SAL_CALL SwVbaWrapFormat::setDistanceTop( float _distancetop )
185 {
186 setDistance( "TopMargin", _distancetop );
187 }
188
getDistanceBottom()189 float SAL_CALL SwVbaWrapFormat::getDistanceBottom()
190 {
191 return getDistance( "BottomMargin" );
192 }
193
setDistanceBottom(float _distancebottom)194 void SAL_CALL SwVbaWrapFormat::setDistanceBottom( float _distancebottom )
195 {
196 setDistance( "BottomMargin", _distancebottom );
197 }
198
getDistanceLeft()199 float SAL_CALL SwVbaWrapFormat::getDistanceLeft()
200 {
201 return getDistance( "LeftMargin" );
202 }
203
setDistanceLeft(float _distanceleft)204 void SAL_CALL SwVbaWrapFormat::setDistanceLeft( float _distanceleft )
205 {
206 setDistance( "LeftMargin", _distanceleft );
207 }
208
getDistanceRight()209 float SAL_CALL SwVbaWrapFormat::getDistanceRight()
210 {
211 return getDistance( "RightMargin" );
212 }
213
setDistanceRight(float _distanceright)214 void SAL_CALL SwVbaWrapFormat::setDistanceRight( float _distanceright )
215 {
216 setDistance( "RightMargin", _distanceright );
217 }
218
219 OUString
getServiceImplName()220 SwVbaWrapFormat::getServiceImplName()
221 {
222 return "SwVbaWrapFormat";
223 }
224
225 uno::Sequence< OUString >
getServiceNames()226 SwVbaWrapFormat::getServiceNames()
227 {
228 static uno::Sequence< OUString > const aServiceNames
229 {
230 "ooo.vba.word.WrapFormat"
231 };
232 return aServiceNames;
233 }
234
235 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
Writer_SwVbaWrapFormat_get_implementation(css::uno::XComponentContext * context,css::uno::Sequence<css::uno::Any> const & args)236 Writer_SwVbaWrapFormat_get_implementation(
237 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& args)
238 {
239 return cppu::acquire(new SwVbaWrapFormat(args, context));
240 }
241
242
243 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
244