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