LibreOffice Module vbahelper (master) 1
vbalineformat.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#include <ooo/vba/office/MsoArrowheadStyle.hpp>
20#include <ooo/vba/office/MsoLineDashStyle.hpp>
21#include <com/sun/star/drawing/LineStyle.hpp>
22#include <com/sun/star/drawing/LineDash.hpp>
23#include "vbalineformat.hxx"
24#include "vbacolorformat.hxx"
25
26using namespace ooo::vba;
27using namespace com::sun::star;
28
29ScVbaLineFormat::ScVbaLineFormat( const uno::Reference< ov::XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< drawing::XShape >& xShape ) : ScVbaLineFormat_BASE( xParent, xContext ), m_xShape( xShape )
30{
31 m_xPropertySet.set( xShape, uno::UNO_QUERY_THROW );
32 m_nLineDashStyle = office::MsoLineDashStyle::msoLineSolid;
33 m_nLineWeight = 1;
34}
35
36sal_Int32
38{
39 sal_Int32 nLineType = office::MsoArrowheadStyle::msoArrowheadNone;
40 if ( sLineName == u"Small Arrow" || sLineName == u"Arrow" || sLineName == u"msArrowEnd" || sLineName == u"Double Arrow")
41 {
42 // msoArrowheadTriangle
43 nLineType = office::MsoArrowheadStyle::msoArrowheadTriangle;
44 }
45 else if ( sLineName == u"Square 45" || sLineName == u"Square" || sLineName == u"msArrowDiamondEnd")
46 {
47 // msoArrowheadDiamond
48 nLineType = office::MsoArrowheadStyle::msoArrowheadDiamond;
49 }
50 else if (sLineName == u"Circle" || sLineName == u"msArrowOvalEnd" || sLineName == u"Dimension Lines" )
51 {
52 // msoArrowheadOval
53 nLineType = office::MsoArrowheadStyle::msoArrowheadOval;
54 }
55 else if ( sLineName == u"Arrow concave" || sLineName == u"msArrowStealthEnd" )
56 {
57 // msoArrowheadStealth
58 nLineType = office::MsoArrowheadStyle::msoArrowheadStealth;
59 }
60 else if ( sLineName == u"Rounded short Arrow" || sLineName == u"Rounded large Arrow" || sLineName == u"Symmetric Arrow"
61 || sLineName == u"msArrowOpenEnd" || sLineName == u"Line Arrow" )
62 {
63 // msoArrowheadOpen
64 nLineType = office::MsoArrowheadStyle::msoArrowheadOpen;
65 }
66 else
67 {
68 // msoArrowheadNone
69 nLineType = office::MsoArrowheadStyle::msoArrowheadNone;
70 }
71 return nLineType;
72}
73
74OUString
76{
77 switch( nArrowheadStyle )
78 {
79 case office::MsoArrowheadStyle::msoArrowheadNone:
80 return OUString();
81 case office::MsoArrowheadStyle::msoArrowheadStealth:
82 return "Arrow concave";
83 case office::MsoArrowheadStyle::msoArrowheadOpen:
84 return "Line Arrow";
85 case office::MsoArrowheadStyle::msoArrowheadOval:
86 return "Circle";
87 case office::MsoArrowheadStyle::msoArrowheadDiamond:
88 return "Square 45";
89 case office::MsoArrowheadStyle::msoArrowheadTriangle:
90 return "Arrow";
91 default:
92 throw uno::RuntimeException( "Invalid Arrow Style!" );
93 }
94}
95
96// Attributes
97sal_Int32 SAL_CALL
99{
100 sal_Int32 nLineType = office::MsoArrowheadStyle::msoArrowheadNone;
101 OUString sLineName;
102 m_xPropertySet->getPropertyValue( "LineStartName" ) >>= sLineName;
103 if( ( sLineName.getLength() > 7 ) && ( sLineName.indexOf( "msArray" ) ) != -1 )
104 {
105 sal_Int32 nIndex = sLineName.indexOf( ' ' );
106 OUString sName = sLineName.copy( 0, nIndex );
107 //sal_Int32 nSize = o3tl::toInt32(sLineName.subView( nIndex + 1 ));
109 }
110 else
111 {
112 nLineType = convertLineStartEndNameToArrowheadStyle( sLineName );
113 }
114 return nLineType;
115}
116
117void SAL_CALL
118ScVbaLineFormat::setBeginArrowheadStyle( sal_Int32 _beginarrowheadstyle )
119{
120 OUString sArrayName = convertArrowheadStyleToLineStartEndName( _beginarrowheadstyle );
121 m_xPropertySet->setPropertyValue( "LineStartName" , uno::Any( sArrayName ) );
122}
123
124sal_Int32 SAL_CALL
126{
127 // #STUB
128 // force error
129 throw uno::RuntimeException( "Property 'EndArrowheadWidth' is not supported." );
130}
131
132void SAL_CALL
133ScVbaLineFormat::setBeginArrowheadLength( sal_Int32 /*_beginarrowheadlength*/ )
134{
135 // #STUB
136 // force error
137 throw uno::RuntimeException( "Property 'EndArrowheadWidth' is not supported." );
138}
139
140sal_Int32 SAL_CALL
142{
143 // #STUB
144 // force error
145 throw uno::RuntimeException( "Property 'EndArrowheadWidth' is not supported." );
146}
147
148void SAL_CALL
149ScVbaLineFormat::setBeginArrowheadWidth( sal_Int32 /*_beginarrowheadwidth*/ )
150{
151 // #STUB
152 // force error
153 throw uno::RuntimeException( "Property 'EndArrowheadWidth' is not supported." );
154}
155
156sal_Int32 SAL_CALL
158{
159 // #STUB
160 return 0;
161}
162
163void SAL_CALL
164ScVbaLineFormat::setEndArrowheadStylel( sal_Int32 /*_endarrowheadstylel*/ )
165{
166 // #STUB
167}
168
169sal_Int32 SAL_CALL
171{
172 // #STUB
173 // force error
174 throw uno::RuntimeException( "Property 'EndArrowheadWidth' is not supported." );
175}
176
177void SAL_CALL
178ScVbaLineFormat::setEndArrowheadLength( sal_Int32 /*_endarrowheadlength*/ )
179{
180 // #STUB
181 throw uno::RuntimeException( "Property 'EndArrowheadWidth' is not supported." );
182}
183
184sal_Int32 SAL_CALL
186{
187 // #STUB
188 throw uno::RuntimeException( "Property 'EndArrowheadWidth' is not supported." );
189}
190
191void SAL_CALL
192ScVbaLineFormat::setEndArrowheadWidth( sal_Int32 /*_endarrowheadwidth*/ )
193{
194 // #STUB
195 throw uno::RuntimeException( "Property 'EndArrowheadWidth' is not supported." );
196}
197
198double SAL_CALL
200{
201 sal_Int32 nLineWidth=0;
202 m_xPropertySet->getPropertyValue( "LineWidth" ) >>= nLineWidth;
203 double dLineWidth = Millimeter::getInPoints( nLineWidth );
204 return dLineWidth;
205}
206
207void SAL_CALL
209{
210 if( _weight < 0 )
211 throw uno::RuntimeException( "Parameter: Must be positive." );
212 if( _weight == 0 )
213 _weight = 0.5;
214 m_nLineWeight = _weight;
215 Millimeter aMillimeter;
216 aMillimeter.setInPoints( _weight );
217
218 sal_Int32 nLineWidth = static_cast<sal_Int32>( aMillimeter.getInHundredthsOfOneMillimeter() );
219 m_xPropertySet->setPropertyValue( "LineWidth" , uno::Any( nLineWidth ) );
221}
222
223sal_Bool SAL_CALL
225{
226 drawing::LineStyle aLineStyle;
227 m_xPropertySet->getPropertyValue( "LineStyle" ) >>= aLineStyle;
228 if( aLineStyle == drawing::LineStyle_NONE )
229 {
230 return false;
231 }
232 return true;
233}
234
235void SAL_CALL
237{
238 drawing::LineStyle aLineStyle;
239 m_xPropertySet->getPropertyValue( "LineStyle" ) >>= aLineStyle;
240 if( !_visible )
241 {
242 aLineStyle = drawing::LineStyle_NONE;
243 m_xPropertySet->setPropertyValue( "LineStyle" , uno::Any( aLineStyle ) );
244 }
245 else
246 {
247 if( aLineStyle == drawing::LineStyle_NONE )
248 {
250 }
251 }
252}
253
254double SAL_CALL
256{
257 sal_Int16 nTransparency = 0;
258 m_xPropertySet->getPropertyValue( "LineTransparence" ) >>= nTransparency;
259 double fTransparency = static_cast<double>( nTransparency );
260 return fTransparency / 100;
261}
262
263void SAL_CALL
264ScVbaLineFormat::setTransparency( double _transparency )
265{
266 sal_Int16 nTransparency = static_cast<sal_Int16>( _transparency * 100 );
267 m_xPropertySet->setPropertyValue( "LineTransparence" , uno::Any( nTransparency ) );
268}
269
270sal_Int16 SAL_CALL
272{
273 //OpenOffice.org only supports one LineStyle (other than the DashStyles)
274 //Therefore we can only return the SingleLine
275 return 1;
276}
277
278void SAL_CALL
279ScVbaLineFormat::setStyle( sal_Int16 /*_style */)
280{
281 //OpenOffice.org only supports one LineStyle (other than the DashStyles)
282 //Therefore we do not set the LineStyle, because it maybe is already set
283 //to Dashed or Single Line. Setting the 'Visible' or 'DashStyle' properties
284 //will be done with the according methods.
285
286 // #STUB
287}
288
289sal_Int32 SAL_CALL
291{
292 drawing::LineStyle eLineStyle;
293 //LineStyle integer in Xray
294 m_xPropertySet->getPropertyValue( "LineStyle" ) >>= eLineStyle;
295 if( eLineStyle == drawing::LineStyle_SOLID )
296 m_nLineDashStyle = office::MsoLineDashStyle::msoLineSolid;
297 else
298 {
299 drawing::LineDash aLineDash;
300 m_xPropertySet->getPropertyValue( "LineDash" ) >>= aLineDash;
301 if( aLineDash.Dots == 0 )
302 {
303 //LineDash
304 //LineLongDash
305 m_nLineDashStyle = office::MsoLineDashStyle::msoLineDash;
306 if( aLineDash.Distance > 0 && ( aLineDash.DashLen / aLineDash.Distance > 1 ) )
307 {
308 m_nLineDashStyle = office::MsoLineDashStyle::msoLineLongDash;
309 }
310 }
311 else if( aLineDash.Dots == 1 )
312 {
313 // LineDashDot
314 // LineLongDashDot
315 // LineSquareDot
316 // LineRoundDot ! not supported
317 m_nLineDashStyle = office::MsoLineDashStyle::msoLineDashDot;
318 if( aLineDash.Dashes == 0 )
319 {
320 m_nLineDashStyle = office::MsoLineDashStyle::msoLineSquareDot;
321 }
322 else
323 {
324 if( aLineDash.Distance > 0 && ( aLineDash.DashLen / aLineDash.Distance > 1 ) )
325 {
326 m_nLineDashStyle = office::MsoLineDashStyle::msoLineLongDashDot;
327 }
328 }
329 }
330 else if( aLineDash.Dots == 2 )
331 {
332 // LineDashDotDot
333 m_nLineDashStyle = office::MsoLineDashStyle::msoLineDashDotDot;
334 }
335 }
336
337 return m_nLineDashStyle;
338}
339
340void SAL_CALL
341ScVbaLineFormat::setDashStyle( sal_Int32 _dashstyle )
342{
343 m_nLineDashStyle = _dashstyle;
344 if( _dashstyle == office::MsoLineDashStyle::msoLineSolid )
345 {
346 m_xPropertySet->setPropertyValue( "LineStyle" , uno::Any( drawing::LineStyle_SOLID ));
347 }
348 else
349 {
350 m_xPropertySet->setPropertyValue( "LineStyle" , uno::Any( drawing::LineStyle_DASH ) );
351 drawing::LineDash aLineDash;
352 Millimeter aMillimeter( m_nLineWeight );
353 sal_Int32 nPixel = static_cast< sal_Int32 >( aMillimeter.getInHundredthsOfOneMillimeter() );
354 switch( _dashstyle )
355 {
356 case office::MsoLineDashStyle::msoLineDashDot:
357 aLineDash.Dots = 1;
358 aLineDash.DotLen = nPixel;
359 aLineDash.Dashes = 1;
360 aLineDash.DashLen = 5 * nPixel;
361 aLineDash.Distance = 4 * nPixel;
362 break;
363 case office::MsoLineDashStyle::msoLineLongDashDot:
364 aLineDash.Dots = 1;
365 aLineDash.DotLen = nPixel;
366 aLineDash.Dashes = 1;
367 aLineDash.DashLen = 10 * nPixel;
368 aLineDash.Distance = 4 * nPixel;
369 break;
370 case office::MsoLineDashStyle::msoLineDash:
371 aLineDash.Dots = 0;
372 aLineDash.DotLen = 0;
373 aLineDash.Dashes = 1;
374 aLineDash.DashLen = 6 * nPixel;
375 aLineDash.Distance = 4 * nPixel;
376 break;
377 case office::MsoLineDashStyle::msoLineDashDotDot:
378 aLineDash.Dots = 2;
379 aLineDash.DotLen = nPixel;
380 aLineDash.Dashes = 1;
381 aLineDash.DashLen = 10 * nPixel;
382 aLineDash.Distance = 3 * nPixel;
383 break;
384 case office::MsoLineDashStyle::msoLineLongDash:
385 aLineDash.Dots = 0;
386 aLineDash.DotLen = 0;
387 aLineDash.Dashes = 1;
388 aLineDash.DashLen = 10 * nPixel;
389 aLineDash.Distance = 4 * nPixel;
390 break;
391 case office::MsoLineDashStyle::msoLineSquareDot:
392 aLineDash.Dots = 1;
393 aLineDash.DotLen = nPixel;
394 aLineDash.Dashes = 0;
395 aLineDash.DashLen = 0;
396 aLineDash.Distance = nPixel;
397 break;
398 case office::MsoLineDashStyle::msoLineRoundDot:
399 aLineDash.Dots = 1;
400 aLineDash.DotLen = nPixel;
401 aLineDash.Dashes = 0;
402 aLineDash.DashLen = 0;
403 aLineDash.Distance = nPixel;
404 break;
405 default:
406 throw uno::RuntimeException( "this MsoLineDashStyle is not supported." );
407 }
408 m_xPropertySet->setPropertyValue( "LineDash" , uno::Any( aLineDash ) );
409 }
410}
411
412// Methods
413uno::Reference< msforms::XColorFormat > SAL_CALL
415{
416 return uno::Reference< msforms::XColorFormat >( new ScVbaColorFormat( getParent(), mxContext, this, m_xShape, ::ColorFormatType::LINEFORMAT_BACKCOLOR ) );
417}
418
419uno::Reference< msforms::XColorFormat > SAL_CALL
421{
422 return uno::Reference< msforms::XColorFormat >( new ScVbaColorFormat( getParent(), mxContext, this, m_xShape, ::ColorFormatType::LINEFORMAT_FORECOLOR ) );
423}
424
425OUString
427{
428 return "ScVbaLineFormat";
429}
430
431uno::Sequence< OUString >
433{
434 static uno::Sequence< OUString > const aServiceNames
435 {
436 "ooo.vba.msform.LineFormat"
437 };
438 return aServiceNames;
439}
440
441
442/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 nLineWidth
static const sal_Int16 LINEFORMAT_FORECOLOR
static const sal_Int16 LINEFORMAT_BACKCOLOR
css::uno::Reference< css::uno::XComponentContext > mxContext
virtual css::uno::Reference< ov::XHelperInterface > SAL_CALL getParent() override
virtual void SAL_CALL setVisible(sal_Bool _visible) override
virtual sal_Int32 SAL_CALL getEndArrowheadWidth() override
virtual void SAL_CALL setDashStyle(sal_Int32 _dashstyle) override
virtual void SAL_CALL setStyle(sal_Int16 _style) override
virtual sal_Int32 SAL_CALL getBeginArrowheadLength() override
virtual OUString getServiceImplName() override
virtual void SAL_CALL setBeginArrowheadStyle(sal_Int32 _beginarrowheadstyle) override
virtual void SAL_CALL setBeginArrowheadLength(sal_Int32 _beginarrowheadlength) override
static sal_Int32 convertLineStartEndNameToArrowheadStyle(std::u16string_view sLineName)
css::uno::Reference< css::beans::XPropertySet > m_xPropertySet
virtual void SAL_CALL setTransparency(double _transparency) override
virtual void SAL_CALL setEndArrowheadWidth(sal_Int32 _endarrowheadwidth) override
virtual css::uno::Reference< ov::msforms::XColorFormat > SAL_CALL ForeColor() override
virtual double SAL_CALL getWeight() override
virtual sal_Int32 SAL_CALL getEndArrowheadStylel() override
virtual sal_Bool SAL_CALL getVisible() override
virtual sal_Int32 SAL_CALL getBeginArrowheadWidth() override
virtual sal_Int32 SAL_CALL getDashStyle() override
ScVbaLineFormat(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::drawing::XShape > &xShape)
virtual void SAL_CALL setEndArrowheadLength(sal_Int32 _endarrowheadlength) override
static OUString convertArrowheadStyleToLineStartEndName(sal_Int32 nArrowheadStyle)
virtual void SAL_CALL setEndArrowheadStylel(sal_Int32 _endarrowheadstylel) override
virtual double SAL_CALL getTransparency() override
virtual sal_Int32 SAL_CALL getBeginArrowheadStyle() override
virtual void SAL_CALL setWeight(double _weight) override
virtual css::uno::Reference< ov::msforms::XColorFormat > SAL_CALL BackColor() override
virtual css::uno::Sequence< OUString > getServiceNames() override
css::uno::Reference< css::drawing::XShape > m_xShape
virtual sal_Int16 SAL_CALL getStyle() override
sal_Int32 m_nLineDashStyle
virtual sal_Int32 SAL_CALL getEndArrowheadLength() override
virtual void SAL_CALL setBeginArrowheadWidth(sal_Int32 _beginarrowheadwidth) override
double getInHundredthsOfOneMillimeter() const
Definition: vbahelper.cxx:1058
void setInPoints(double points)
Definition: vbahelper.cxx:1053
float u
Sequence< OUString > aServiceNames
OUString sName
sal_Int32 nIndex
#define nPixel
unsigned char sal_Bool