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