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 "service.hxx"
23 #include "vbawrapformat.hxx"
24 #include <ooo/vba/word/WdWrapSideType.hpp>
25 #include <ooo/vba/word/WdWrapType.hpp>
26 #include <com/sun/star/beans/XPropertySet.hpp>
27 #include <com/sun/star/text/WrapTextMode.hpp>
28 #include <basic/sberrors.hxx>
29 #include <vbahelper/vbahelper.hxx>
30 #include <vbahelper/helperdecl.hxx>
31 
32 using namespace ooo::vba;
33 using namespace com::sun::star;
34 
35 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 )
36 {
37  m_xPropertySet.set( m_xShape, uno::UNO_QUERY_THROW );
38 }
39 
41 {
42  text::WrapTextMode eTextMode = text::WrapTextMode_NONE;
43  if( mnSide == word::WdWrapSideType::wdWrapLeft )
44  {
45  eTextMode = text::WrapTextMode_LEFT;
46  }
47  else if( mnSide == word::WdWrapSideType::wdWrapRight )
48  {
49  eTextMode = text::WrapTextMode_RIGHT;
50  }
51  else if( mnSide == word::WdWrapSideType::wdWrapBoth ||
52  mnSide == word::WdWrapSideType::wdWrapLargest )
53  {
54  switch( mnWrapFormatType )
55  {
56  case word::WdWrapType::wdWrapNone:
57  case word::WdWrapType::wdWrapThrough:
58  {
59  eTextMode = text::WrapTextMode_THROUGH;
60  break;
61  }
62  case word::WdWrapType::wdWrapInline:
63  case word::WdWrapType::wdWrapTopBottom:
64  {
65  eTextMode = text::WrapTextMode_NONE;
66  break;
67  }
68  case word::WdWrapType::wdWrapSquare:
69  {
70  eTextMode = text::WrapTextMode_PARALLEL;
71  m_xPropertySet->setPropertyValue("SurroundContour", uno::makeAny( false ) );
72  break;
73  }
74  case word::WdWrapType::wdWrapTight:
75  {
76  eTextMode = text::WrapTextMode_PARALLEL;
77  m_xPropertySet->setPropertyValue("SurroundContour", uno::makeAny( true ) );
78  break;
79  }
80  default:
81  {
82  DebugHelper::runtimeexception(ERRCODE_BASIC_BAD_ARGUMENT);
83  }
84  }
85  }
86  m_xPropertySet->setPropertyValue("TextWrap", uno::makeAny( eTextMode ) );
87 }
88 
89 ::sal_Int32 SAL_CALL SwVbaWrapFormat::getType()
90 {
91  sal_Int32 nType = word::WdWrapType::wdWrapSquare;
92  text::WrapTextMode eTextMode;
93  m_xPropertySet->getPropertyValue("TextWrap") >>= eTextMode;
94  switch( eTextMode )
95  {
96  case text::WrapTextMode_NONE:
97  {
98  nType = word::WdWrapType::wdWrapTopBottom;
99  break;
100  }
101  case text::WrapTextMode_THROUGH:
102  {
103  nType = word::WdWrapType::wdWrapNone;
104  break;
105  }
106  case text::WrapTextMode_PARALLEL:
107  {
108  bool bContour = false;
109  m_xPropertySet->getPropertyValue("SurroundContour") >>= bContour;
110  if( bContour )
111  nType = word::WdWrapType::wdWrapTight;
112  else
113  nType = word::WdWrapType::wdWrapSquare;
114  break;
115  }
116  case text::WrapTextMode_DYNAMIC:
117  case text::WrapTextMode_LEFT:
118  case text::WrapTextMode_RIGHT:
119  {
120  nType = word::WdWrapType::wdWrapThrough;
121  break;
122  }
123  default:
124  {
125  nType = word::WdWrapType::wdWrapSquare;
126  }
127  }
128  return nType;
129 }
130 
131 void SAL_CALL SwVbaWrapFormat::setType( ::sal_Int32 _type )
132 {
133  mnWrapFormatType = _type;
134  makeWrap();
135 }
136 
137 ::sal_Int32 SAL_CALL SwVbaWrapFormat::getSide()
138 {
139  sal_Int32 nSide = word::WdWrapSideType::wdWrapBoth;
140  text::WrapTextMode eTextMode;
141  m_xPropertySet->getPropertyValue("TextWrap") >>= eTextMode;
142  switch( eTextMode )
143  {
144  case text::WrapTextMode_LEFT:
145  {
146  nSide = word::WdWrapSideType::wdWrapLeft;
147  break;
148  }
149  case text::WrapTextMode_RIGHT:
150  {
151  nSide = word::WdWrapSideType::wdWrapRight;
152  break;
153  }
154  default:
155  {
156  nSide = word::WdWrapSideType::wdWrapBoth;
157  }
158  }
159  return nSide;
160 }
161 
162 void SAL_CALL SwVbaWrapFormat::setSide( ::sal_Int32 _side )
163 {
164  mnSide = _side;
165  makeWrap();
166 }
167 
168 float SwVbaWrapFormat::getDistance( const OUString& sName )
169 {
170  sal_Int32 nDistance = 0;
171  m_xPropertySet->getPropertyValue( sName ) >>= nDistance;
172  return static_cast< float >( Millimeter::getInPoints( nDistance ) );
173 }
174 
175 void SwVbaWrapFormat::setDistance( const OUString& sName, float _distance )
176 {
177  sal_Int32 nDistance = Millimeter::getInHundredthsOfOneMillimeter( _distance );
178  m_xPropertySet->setPropertyValue( sName, uno::makeAny( nDistance ) );
179 }
180 
182 {
183  return getDistance( "TopMargin" );
184 }
185 
186 void SAL_CALL SwVbaWrapFormat::setDistanceTop( float _distancetop )
187 {
188  setDistance( "TopMargin", _distancetop );
189 }
190 
192 {
193  return getDistance( "BottomMargin" );
194 }
195 
196 void SAL_CALL SwVbaWrapFormat::setDistanceBottom( float _distancebottom )
197 {
198  setDistance( "BottomMargin", _distancebottom );
199 }
200 
202 {
203  return getDistance( "LeftMargin" );
204 }
205 
206 void SAL_CALL SwVbaWrapFormat::setDistanceLeft( float _distanceleft )
207 {
208  setDistance( "LeftMargin", _distanceleft );
209 }
210 
212 {
213  return getDistance( "RightMargin" );
214 }
215 
216 void SAL_CALL SwVbaWrapFormat::setDistanceRight( float _distanceright )
217 {
218  setDistance( "RightMargin", _distanceright );
219 }
220 
221 OUString
223 {
224  return "SwVbaWrapFormat";
225 }
226 
227 uno::Sequence< OUString >
229 {
230  static uno::Sequence< OUString > const aServiceNames
231  {
232  "ooo.vba.word.WrapFormat"
233  };
234  return aServiceNames;
235 }
236 
237 namespace wrapformat
238 {
239 namespace sdecl = comphelper::service_decl;
242  serviceImpl,
243  "SwVbaWrapFormat",
244  "ooo.vba.word.WrapFormat" );
245 }
246 
247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define ERRCODE_BASIC_BAD_ARGUMENT
float getDistance(const OUString &sName)
virtual void SAL_CALL setDistanceTop(float _distancetop) override
virtual void SAL_CALL setDistanceBottom(float _distancebottom) override
css::uno::Reference< T > getXSomethingFromArgs(css::uno::Sequence< css::uno::Any > const &args, sal_Int32 nPos, bool bCanBeNull=true)
Sequence< OUString > aServiceNames
sal_Int32 mnWrapFormatType
virtual OUString getServiceImplName() override
virtual float SAL_CALL getDistanceLeft() override
virtual void SAL_CALL setType(::sal_Int32 _type) override
sdecl::vba_service_class_< SwVbaWrapFormat, sdecl::with_args< true > > const serviceImpl
css::uno::Reference< css::beans::XPropertySet > m_xPropertySet
virtual float SAL_CALL getDistanceRight() override
QPRO_FUNC_TYPE const nType
virtual ::sal_Int32 SAL_CALL getType() override
virtual ::sal_Int32 SAL_CALL getSide() override
virtual void SAL_CALL setDistanceRight(float _distanceright) override
SwVbaWrapFormat(css::uno::Sequence< css::uno::Any > const &aArgs, css::uno::Reference< css::uno::XComponentContext >const &xContext)
comphelper::service_decl::ServiceDecl const serviceDecl
css::uno::Reference< css::drawing::XShape > m_xShape
virtual float SAL_CALL getDistanceTop() override
virtual css::uno::Sequence< OUString > getServiceNames() override
virtual void SAL_CALL setDistanceLeft(float _distanceleft) override
void setDistance(const OUString &sName, float _distance)
virtual float SAL_CALL getDistanceBottom() override
virtual void SAL_CALL setSide(::sal_Int32 _side) override