android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / ui / vba / vbawrapformat.cxx
blob2aef0523b4329a8c7c542817234610201e7833b9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
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>
30 using namespace ooo::vba;
31 using namespace com::sun::star;
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 )
35 m_xPropertySet.set( m_xShape, uno::UNO_QUERY_THROW );
38 void SwVbaWrapFormat::makeWrap()
40 text::WrapTextMode eTextMode = text::WrapTextMode_NONE;
41 if( mnSide == word::WdWrapSideType::wdWrapLeft )
43 eTextMode = text::WrapTextMode_LEFT;
45 else if( mnSide == word::WdWrapSideType::wdWrapRight )
47 eTextMode = text::WrapTextMode_RIGHT;
49 else if( mnSide == word::WdWrapSideType::wdWrapBoth ||
50 mnSide == word::WdWrapSideType::wdWrapLargest )
52 switch( mnWrapFormatType )
54 case word::WdWrapType::wdWrapNone:
55 case word::WdWrapType::wdWrapThrough:
57 eTextMode = text::WrapTextMode_THROUGH;
58 break;
60 case word::WdWrapType::wdWrapInline:
61 case word::WdWrapType::wdWrapTopBottom:
63 eTextMode = text::WrapTextMode_NONE;
64 break;
66 case word::WdWrapType::wdWrapSquare:
68 eTextMode = text::WrapTextMode_PARALLEL;
69 m_xPropertySet->setPropertyValue("SurroundContour", uno::Any( false ) );
70 break;
72 case word::WdWrapType::wdWrapTight:
74 eTextMode = text::WrapTextMode_PARALLEL;
75 m_xPropertySet->setPropertyValue("SurroundContour", uno::Any( true ) );
76 break;
78 default:
80 DebugHelper::runtimeexception(ERRCODE_BASIC_BAD_ARGUMENT);
84 m_xPropertySet->setPropertyValue("TextWrap", uno::Any( eTextMode ) );
87 ::sal_Int32 SAL_CALL SwVbaWrapFormat::getType()
89 sal_Int32 nType = word::WdWrapType::wdWrapSquare;
90 text::WrapTextMode eTextMode;
91 m_xPropertySet->getPropertyValue("TextWrap") >>= eTextMode;
92 switch( eTextMode )
94 case text::WrapTextMode_NONE:
96 nType = word::WdWrapType::wdWrapTopBottom;
97 break;
99 case text::WrapTextMode_THROUGH:
101 nType = word::WdWrapType::wdWrapNone;
102 break;
104 case text::WrapTextMode_PARALLEL:
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;
114 case text::WrapTextMode_DYNAMIC:
115 case text::WrapTextMode_LEFT:
116 case text::WrapTextMode_RIGHT:
118 nType = word::WdWrapType::wdWrapThrough;
119 break;
121 default:
123 nType = word::WdWrapType::wdWrapSquare;
126 return nType;
129 void SAL_CALL SwVbaWrapFormat::setType( ::sal_Int32 _type )
131 mnWrapFormatType = _type;
132 makeWrap();
135 ::sal_Int32 SAL_CALL SwVbaWrapFormat::getSide()
137 sal_Int32 nSide = word::WdWrapSideType::wdWrapBoth;
138 text::WrapTextMode eTextMode;
139 m_xPropertySet->getPropertyValue("TextWrap") >>= eTextMode;
140 switch( eTextMode )
142 case text::WrapTextMode_LEFT:
144 nSide = word::WdWrapSideType::wdWrapLeft;
145 break;
147 case text::WrapTextMode_RIGHT:
149 nSide = word::WdWrapSideType::wdWrapRight;
150 break;
152 default:
154 nSide = word::WdWrapSideType::wdWrapBoth;
157 return nSide;
160 void SAL_CALL SwVbaWrapFormat::setSide( ::sal_Int32 _side )
162 mnSide = _side;
163 makeWrap();
166 float SwVbaWrapFormat::getDistance( const OUString& sName )
168 sal_Int32 nDistance = 0;
169 m_xPropertySet->getPropertyValue( sName ) >>= nDistance;
170 return static_cast< float >( Millimeter::getInPoints( nDistance ) );
173 void SwVbaWrapFormat::setDistance( const OUString& sName, float _distance )
175 sal_Int32 nDistance = Millimeter::getInHundredthsOfOneMillimeter( _distance );
176 m_xPropertySet->setPropertyValue( sName, uno::Any( nDistance ) );
179 float SAL_CALL SwVbaWrapFormat::getDistanceTop()
181 return getDistance( "TopMargin" );
184 void SAL_CALL SwVbaWrapFormat::setDistanceTop( float _distancetop )
186 setDistance( "TopMargin", _distancetop );
189 float SAL_CALL SwVbaWrapFormat::getDistanceBottom()
191 return getDistance( "BottomMargin" );
194 void SAL_CALL SwVbaWrapFormat::setDistanceBottom( float _distancebottom )
196 setDistance( "BottomMargin", _distancebottom );
199 float SAL_CALL SwVbaWrapFormat::getDistanceLeft()
201 return getDistance( "LeftMargin" );
204 void SAL_CALL SwVbaWrapFormat::setDistanceLeft( float _distanceleft )
206 setDistance( "LeftMargin", _distanceleft );
209 float SAL_CALL SwVbaWrapFormat::getDistanceRight()
211 return getDistance( "RightMargin" );
214 void SAL_CALL SwVbaWrapFormat::setDistanceRight( float _distanceright )
216 setDistance( "RightMargin", _distanceright );
219 OUString
220 SwVbaWrapFormat::getServiceImplName()
222 return "SwVbaWrapFormat";
225 uno::Sequence< OUString >
226 SwVbaWrapFormat::getServiceNames()
228 static uno::Sequence< OUString > const aServiceNames
230 "ooo.vba.word.WrapFormat"
232 return aServiceNames;
235 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
236 Writer_SwVbaWrapFormat_get_implementation(
237 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& args)
239 return cppu::acquire(new SwVbaWrapFormat(args, context));
243 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */