LibreOffice Module sw (master) 1
vbawrapformat.cxx
Go to the documentation of this file.
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>
29
30using namespace ooo::vba;
31using namespace com::sun::star;
32
33SwVbaWrapFormat::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
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::Any( false ) );
70 break;
71 }
72 case word::WdWrapType::wdWrapTight:
73 {
74 eTextMode = text::WrapTextMode_PARALLEL;
75 m_xPropertySet->setPropertyValue("SurroundContour", uno::Any( true ) );
76 break;
77 }
78 default:
79 {
80 DebugHelper::runtimeexception(ERRCODE_BASIC_BAD_ARGUMENT);
81 }
82 }
83 }
84 m_xPropertySet->setPropertyValue("TextWrap", uno::Any( eTextMode ) );
85}
86
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
129void SAL_CALL SwVbaWrapFormat::setType( ::sal_Int32 _type )
130{
131 mnWrapFormatType = _type;
132 makeWrap();
133}
134
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
160void SAL_CALL SwVbaWrapFormat::setSide( ::sal_Int32 _side )
161{
162 mnSide = _side;
163 makeWrap();
164}
165
166float 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
173void SwVbaWrapFormat::setDistance( const OUString& sName, float _distance )
174{
175 sal_Int32 nDistance = Millimeter::getInHundredthsOfOneMillimeter( _distance );
176 m_xPropertySet->setPropertyValue( sName, uno::Any( nDistance ) );
177}
178
180{
181 return getDistance( "TopMargin" );
182}
183
184void SAL_CALL SwVbaWrapFormat::setDistanceTop( float _distancetop )
185{
186 setDistance( "TopMargin", _distancetop );
187}
188
190{
191 return getDistance( "BottomMargin" );
192}
193
194void SAL_CALL SwVbaWrapFormat::setDistanceBottom( float _distancebottom )
195{
196 setDistance( "BottomMargin", _distancebottom );
197}
198
200{
201 return getDistance( "LeftMargin" );
202}
203
204void SAL_CALL SwVbaWrapFormat::setDistanceLeft( float _distanceleft )
205{
206 setDistance( "LeftMargin", _distanceleft );
207}
208
210{
211 return getDistance( "RightMargin" );
212}
213
214void SAL_CALL SwVbaWrapFormat::setDistanceRight( float _distanceright )
215{
216 setDistance( "RightMargin", _distanceright );
217}
218
219OUString
221{
222 return "SwVbaWrapFormat";
223}
224
225uno::Sequence< OUString >
227{
228 static uno::Sequence< OUString > const aServiceNames
229 {
230 "ooo.vba.word.WrapFormat"
231 };
232 return aServiceNames;
233}
234
235extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
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: */
SwVbaWrapFormat(css::uno::Sequence< css::uno::Any > const &aArgs, css::uno::Reference< css::uno::XComponentContext >const &xContext)
sal_Int32 mnWrapFormatType
virtual void SAL_CALL setSide(::sal_Int32 _side) override
virtual float SAL_CALL getDistanceTop() override
virtual void SAL_CALL setDistanceRight(float _distanceright) override
virtual void SAL_CALL setDistanceTop(float _distancetop) override
virtual float SAL_CALL getDistanceBottom() override
virtual void SAL_CALL setDistanceBottom(float _distancebottom) override
virtual ::sal_Int32 SAL_CALL getSide() override
css::uno::Reference< css::drawing::XShape > m_xShape
virtual void SAL_CALL setType(::sal_Int32 _type) override
virtual ::sal_Int32 SAL_CALL getType() override
float getDistance(const OUString &sName)
virtual float SAL_CALL getDistanceRight() override
css::uno::Reference< css::beans::XPropertySet > m_xPropertySet
virtual void SAL_CALL setDistanceLeft(float _distanceleft) override
virtual float SAL_CALL getDistanceLeft() override
void setDistance(const OUString &sName, float _distance)
virtual OUString getServiceImplName() override
virtual css::uno::Sequence< OUString > getServiceNames() override
Sequence< OUString > aServiceNames
OUString sName
css::uno::Reference< T > getXSomethingFromArgs(css::uno::Sequence< css::uno::Any > const &args, sal_Int32 nPos, bool bCanBeNull=true)
args
QPRO_FUNC_TYPE nType
#define ERRCODE_BASIC_BAD_ARGUMENT
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * Writer_SwVbaWrapFormat_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &args)