xref: /aoo42x/main/sc/source/ui/vba/vbaborders.cxx (revision b3f79822)
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 "vbaborders.hxx"
24 
25 #include <cppuhelper/implbase3.hxx>
26 #include <ooo/vba/excel/XlBordersIndex.hpp>
27 #include <ooo/vba/excel/XlBorderWeight.hpp>
28 #include <ooo/vba/excel/XlLineStyle.hpp>
29 #include <ooo/vba/excel/XlColorIndex.hpp>
30 #include <com/sun/star/beans/XPropertySet.hpp>
31 #include <com/sun/star/table/TableBorder.hpp>
32 #include <com/sun/star/table/XColumnRowRange.hpp>
33 
34 #include "vbapalette.hxx"
35 
36 using namespace ::com::sun::star;
37 using namespace ::ooo::vba;
38 using namespace ::ooo::vba::excel;
39 
40 
41 typedef ::cppu::WeakImplHelper1<container::XIndexAccess > RangeBorders_Base;
42 typedef InheritedHelperInterfaceImpl1<excel::XBorder > ScVbaBorder_Base;
43 
44 // #TODO sort these indexes to match the order in which Excel iterates over the
45 // borders, the enumeration will match the order in this list
46 static const sal_Int16 supportedIndexTable[] = {  XlBordersIndex::xlEdgeLeft, XlBordersIndex::xlEdgeTop, XlBordersIndex::xlEdgeBottom, XlBordersIndex::xlEdgeRight, XlBordersIndex::xlDiagonalDown, XlBordersIndex::xlDiagonalUp, XlBordersIndex::xlInsideVertical, XlBordersIndex::xlInsideHorizontal };
47 
48 const static rtl::OUString sTableBorder( RTL_CONSTASCII_USTRINGPARAM("TableBorder") );
49 
50 //  Equiv widths in in 1/100 mm
51 const static sal_Int32 OOLineThin = 35;
52 const static sal_Int32 OOLineMedium = 88;
53 const static sal_Int32 OOLineThick = 141;
54 const static sal_Int32 OOLineHairline = 2;
55 
56 class ScVbaBorder : public ScVbaBorder_Base
57 {
58 private:
59 	uno::Reference< beans::XPropertySet > m_xProps;
60 	sal_Int32 m_LineType;
61 	ScVbaPalette m_Palette;
setBorderLine(table::BorderLine & rBorderLine)62 	bool setBorderLine( table::BorderLine& rBorderLine )
63 	{
64 		table::TableBorder aTableBorder;
65 		m_xProps->getPropertyValue( sTableBorder ) >>= aTableBorder;
66 
67 		switch ( m_LineType )
68 		{
69 			case XlBordersIndex::xlEdgeLeft:
70 				aTableBorder.IsLeftLineValid = sal_True;
71 				aTableBorder.LeftLine= rBorderLine;
72 				break;
73 			case XlBordersIndex::xlEdgeTop:
74 				aTableBorder.IsTopLineValid = sal_True;
75 				aTableBorder.TopLine = rBorderLine;
76 				break;
77 
78 			case XlBordersIndex::xlEdgeBottom:
79 				aTableBorder.IsBottomLineValid = sal_True;
80 				aTableBorder.BottomLine = rBorderLine;
81 				break;
82 			case XlBordersIndex::xlEdgeRight:
83 				aTableBorder.IsRightLineValid = sal_True;
84 				aTableBorder.RightLine = rBorderLine;
85 				break;
86 			case XlBordersIndex::xlInsideVertical:
87 				aTableBorder.IsVerticalLineValid = sal_True;
88 				aTableBorder.VerticalLine = rBorderLine;
89 				break;
90 			case XlBordersIndex::xlInsideHorizontal:
91 				aTableBorder.IsHorizontalLineValid = sal_True;
92 				aTableBorder.HorizontalLine = rBorderLine;
93 				break;
94 			case XlBordersIndex::xlDiagonalDown:
95 			case XlBordersIndex::xlDiagonalUp:
96 				// #TODO have to ignore at the momement, would be
97 				// nice to investigate what we can do here
98 				break;
99 			default:
100 					return false;
101 		}
102 		m_xProps->setPropertyValue( sTableBorder, uno::makeAny(aTableBorder) );
103 		return true;
104 	}
105 
getBorderLine(table::BorderLine & rBorderLine)106 	bool getBorderLine( table::BorderLine& rBorderLine )
107 	{
108 		table::TableBorder aTableBorder;
109 		m_xProps->getPropertyValue( sTableBorder ) >>= aTableBorder;
110 		switch ( m_LineType )
111 		{
112 			case XlBordersIndex::xlEdgeLeft:
113 				if ( aTableBorder.IsLeftLineValid )
114 					rBorderLine = aTableBorder.LeftLine;
115 				break;
116 			case XlBordersIndex::xlEdgeTop:
117 				if ( aTableBorder.IsTopLineValid )
118 					rBorderLine = aTableBorder.TopLine;
119 				break;
120 
121 			case XlBordersIndex::xlEdgeBottom:
122 				if ( aTableBorder.IsBottomLineValid )
123 					rBorderLine = aTableBorder.BottomLine;
124 				break;
125 			case XlBordersIndex::xlEdgeRight:
126 				if ( aTableBorder.IsRightLineValid )
127 					rBorderLine = aTableBorder.RightLine;
128 				break;
129 			case XlBordersIndex::xlInsideVertical:
130                 if ( aTableBorder.IsVerticalLineValid )
131                     rBorderLine = aTableBorder.VerticalLine;
132 				break;
133 			case XlBordersIndex::xlInsideHorizontal:
134                 if ( aTableBorder.IsHorizontalLineValid )
135                     rBorderLine = aTableBorder.HorizontalLine;
136 				break;
137 
138 			case XlBordersIndex::xlDiagonalDown:
139 			case XlBordersIndex::xlDiagonalUp:
140 				// #TODO have to ignore at the momement, would be
141 				// nice to investigate what we can do here
142 				break;
143 			default:
144 					return false;
145 		}
146 		return true;
147 	}
148 	ScVbaBorder(); // no impl
149 protected:
getServiceImplName()150 	virtual rtl::OUString& getServiceImplName()
151 	{
152 		static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaBorder") );
153 	return sImplName;
154 	}
getServiceNames()155 	virtual css::uno::Sequence<rtl::OUString> getServiceNames()
156 	{
157 		static uno::Sequence< rtl::OUString > aServiceNames;
158 		if ( aServiceNames.getLength() == 0 )
159 		{
160 			aServiceNames.realloc( 1 );
161 			aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Border" ) );
162 		}
163 		return aServiceNames;
164 	}
165 public:
ScVbaBorder(const uno::Reference<beans::XPropertySet> & xProps,const uno::Reference<uno::XComponentContext> & xContext,sal_Int32 lineType,ScVbaPalette & rPalette)166 	ScVbaBorder( const uno::Reference< beans::XPropertySet > & xProps, const uno::Reference< uno::XComponentContext >& xContext, sal_Int32 lineType, ScVbaPalette& rPalette) : ScVbaBorder_Base( uno::Reference< XHelperInterface >( xProps, uno::UNO_QUERY ), xContext ), m_xProps( xProps ), m_LineType( lineType ), m_Palette( rPalette ) {}
167 
168 	// XBorder
getColor()169 	uno::Any SAL_CALL getColor() throw (uno::RuntimeException)
170 	{
171 		table::BorderLine aBorderLine;
172 		if ( getBorderLine( aBorderLine ) )
173 			return uno::makeAny( OORGBToXLRGB( aBorderLine.Color ) );
174 		throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "No Implementation available" ) ), uno::Reference< uno::XInterface >() );
175 	}
setColor(const uno::Any & _color)176 	void SAL_CALL setColor( const uno::Any& _color ) throw (uno::RuntimeException)
177 	{
178 		sal_Int32 nColor = 0;
179 		_color >>= nColor;
180 		table::BorderLine aBorderLine;
181 		if ( getBorderLine( aBorderLine ) )
182 		{
183 			aBorderLine.Color = XLRGBToOORGB( nColor );
184 			setBorderLine( aBorderLine );
185 		}
186 		else
187 			throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "No Implementation available" ) ), uno::Reference< uno::XInterface >() );
188 	}
189 
getColorIndex()190 	uno::Any SAL_CALL getColorIndex() throw (uno::RuntimeException)
191 	{
192 		sal_Int32 nColor = 0;
193 		XLRGBToOORGB( getColor() ) >>= nColor;
194 		uno::Reference< container::XIndexAccess > xIndex = m_Palette.getPalette();
195 		sal_Int32 nElems = xIndex->getCount();
196 		sal_Int32 nIndex = -1;
197 		for ( sal_Int32 count=0; count<nElems; ++count )
198 		{
199 			sal_Int32 nPaletteColor = 0;
200 			xIndex->getByIndex( count ) >>= nPaletteColor;
201 			if ( nPaletteColor == nColor )
202 			{
203 				nIndex = count + 1;
204 				break;
205 			}
206 		}
207 		return uno::makeAny(nIndex);
208 	}
209 
setColorIndex(const uno::Any & _colorindex)210 	void SAL_CALL setColorIndex( const uno::Any& _colorindex ) throw (uno::RuntimeException)
211 	{
212 		sal_Int32 nColor = 0;
213 		_colorindex >>= nColor;
214 		if ( !nColor || nColor == XlColorIndex::xlColorIndexAutomatic )
215 			nColor = 1;
216 		setColor( OORGBToXLRGB( m_Palette.getPalette()->getByIndex( --nColor )  ) );
217 	}
getWeight()218 	uno::Any SAL_CALL getWeight() throw (uno::RuntimeException)
219 	{
220 		table::BorderLine aBorderLine;
221 		if ( getBorderLine( aBorderLine ) )
222 		{
223 			switch ( aBorderLine.OuterLineWidth )
224 			{
225 				case 0:	// Thin = default OO thickness
226 				case OOLineThin:
227 					return uno::makeAny( XlBorderWeight::xlThin );
228 				case OOLineMedium:
229 					return uno::makeAny( XlBorderWeight::xlMedium );
230 				case OOLineThick:
231 					return uno::makeAny( XlBorderWeight::xlThick );
232 				case OOLineHairline:
233 					return uno::makeAny( XlBorderWeight::xlHairline );
234 				default:
235 					break;
236 			}
237 		}
238 		throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Method failed" ) ), uno::Reference< uno::XInterface >() );
239 	}
setWeight(const uno::Any & _weight)240 	void SAL_CALL setWeight( const uno::Any& _weight ) throw (uno::RuntimeException)
241 	{
242 		sal_Int32 nWeight = 0;
243 		_weight >>= nWeight;
244 		table::BorderLine aBorderLine;
245 		if ( getBorderLine( aBorderLine ) )
246 		{
247 			switch ( nWeight )
248 			{
249 				case XlBorderWeight::xlThin:
250 					aBorderLine.OuterLineWidth = OOLineThin;
251 					break;
252 				case XlBorderWeight::xlMedium:
253 					aBorderLine.OuterLineWidth = OOLineMedium;
254 					break;
255 				case XlBorderWeight::xlThick:
256 					aBorderLine.OuterLineWidth = OOLineThick;
257 					break;
258 				case XlBorderWeight::xlHairline:
259 					aBorderLine.OuterLineWidth = OOLineHairline;
260 					break;
261 				default:
262 					throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Bad param" ) ), uno::Reference< uno::XInterface >() );
263 			}
264 			setBorderLine( aBorderLine );
265 		}
266 		else
267 					throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Method failed" ) ), uno::Reference< uno::XInterface >() );
268 	}
269 
getLineStyle()270 	uno::Any SAL_CALL getLineStyle() throw (uno::RuntimeException)
271 	{
272 		// always return xlContinuous;
273 		return uno::makeAny( XlLineStyle::xlContinuous );
274 	}
setLineStyle(const uno::Any & _linestyle)275 	void SAL_CALL setLineStyle( const uno::Any& _linestyle ) throw (uno::RuntimeException)
276 	{
277 		// Urk no choice but to silently ignore we don't support this attribute
278 		// #TODO would be nice to support the excel line styles
279         sal_Int32 nLineStyle = 0;
280         _linestyle >>= nLineStyle;
281         table::BorderLine aBorderLine;
282 		if ( getBorderLine( aBorderLine ) )
283 		{
284 			switch ( nLineStyle )
285 			{
286                 case XlLineStyle::xlContinuous:
287                 case XlLineStyle::xlDash:
288                 case XlLineStyle::xlDashDot:
289                 case XlLineStyle::xlDashDotDot:
290                 case XlLineStyle::xlDot:
291                 case XlLineStyle::xlDouble:
292                 case XlLineStyle::xlLineStyleNone:
293                 case XlLineStyle::xlSlantDashDot:
294                     break;
295                 default:
296                     throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Bad param" ) ), uno::Reference< uno::XInterface >() );
297             }
298 			setBorderLine( aBorderLine );
299         }
300 		else
301             throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Method failed" ) ), uno::Reference< uno::XInterface >() );
302 	}
303 };
304 
305 class RangeBorders : public RangeBorders_Base
306 {
307 private:
308 	uno::Reference< table::XCellRange > m_xRange;
309 	uno::Reference< uno::XComponentContext > m_xContext;
310 	ScVbaPalette m_Palette;
getTableIndex(sal_Int32 nConst)311 	sal_Int32 getTableIndex( sal_Int32 nConst )
312 	{
313 		// hokay return position of the index in the table
314 		sal_Int32 nIndexes = getCount();
315 		sal_Int32 realIndex = 0;
316 		const sal_Int16* pTableEntry = supportedIndexTable;
317 		for ( ; realIndex < nIndexes; ++realIndex, ++pTableEntry )
318 		{
319 			if ( *pTableEntry == nConst )
320 				return realIndex;
321 		}
322 		return getCount(); // error condition
323 	}
324 public:
RangeBorders(const uno::Reference<table::XCellRange> & xRange,const uno::Reference<uno::XComponentContext> & xContext,ScVbaPalette & rPalette)325 	RangeBorders(  const uno::Reference< table::XCellRange >& xRange,  const uno::Reference< uno::XComponentContext > & xContext, ScVbaPalette& rPalette ) : m_xRange( xRange ), m_xContext( xContext ), m_Palette( rPalette )
326 	{
327 	}
328 	// XIndexAccess
getCount()329 	virtual ::sal_Int32 SAL_CALL getCount(  ) throw (uno::RuntimeException)
330 	{
331 		return sizeof( supportedIndexTable ) / sizeof( supportedIndexTable[0] );
332 	}
getByIndex(::sal_Int32 Index)333 	virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
334 	{
335 
336 		sal_Int32 nIndex = getTableIndex( Index );
337 		if ( nIndex >= 0 && nIndex < getCount() )
338 		{
339 			uno::Reference< beans::XPropertySet > xProps( m_xRange, uno::UNO_QUERY_THROW );
340 			return uno::makeAny( uno::Reference< excel::XBorder >( new ScVbaBorder( xProps, m_xContext, supportedIndexTable[ nIndex ], m_Palette )) );
341 		}
342 		throw lang::IndexOutOfBoundsException();
343 	}
getElementType()344 	virtual uno::Type SAL_CALL getElementType(  ) throw (uno::RuntimeException)
345 	{
346 		return  excel::XBorder::static_type(0);
347 	}
hasElements()348 	virtual ::sal_Bool SAL_CALL hasElements(  ) throw (uno::RuntimeException)
349 	{
350 		return sal_True;
351 	}
352 };
353 
354 uno::Reference< container::XIndexAccess >
rangeToBorderIndexAccess(const uno::Reference<table::XCellRange> & xRange,const uno::Reference<uno::XComponentContext> & xContext,ScVbaPalette & rPalette)355 rangeToBorderIndexAccess( const uno::Reference< table::XCellRange >& xRange,  const uno::Reference< uno::XComponentContext > & xContext, ScVbaPalette& rPalette )
356 {
357 	return new RangeBorders( xRange, xContext, rPalette );
358 }
359 
360 class RangeBorderEnumWrapper : public EnumerationHelper_BASE
361 {
362 	uno::Reference<container::XIndexAccess > m_xIndexAccess;
363 	sal_Int32 nIndex;
364 public:
RangeBorderEnumWrapper(const uno::Reference<container::XIndexAccess> & xIndexAccess)365 	RangeBorderEnumWrapper( const uno::Reference< container::XIndexAccess >& xIndexAccess ) : m_xIndexAccess( xIndexAccess ), nIndex( 0 ) {}
hasMoreElements()366 	virtual ::sal_Bool SAL_CALL hasMoreElements(  ) throw (uno::RuntimeException)
367 	{
368 		return ( nIndex < m_xIndexAccess->getCount() );
369 	}
370 
nextElement()371 	virtual uno::Any SAL_CALL nextElement(  ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
372 	{
373 		if ( nIndex < m_xIndexAccess->getCount() )
374 			return m_xIndexAccess->getByIndex( nIndex++ );
375 		throw container::NoSuchElementException();
376 	}
377 };
378 
ScVbaBorders(const uno::Reference<XHelperInterface> & xParent,const uno::Reference<uno::XComponentContext> & xContext,const uno::Reference<table::XCellRange> & xRange,ScVbaPalette & rPalette)379 ScVbaBorders::ScVbaBorders( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< table::XCellRange >& xRange, ScVbaPalette& rPalette  ):  ScVbaBorders_BASE( xParent, xContext, rangeToBorderIndexAccess( xRange ,xContext, rPalette ) ), bRangeIsSingleCell( false )
380 {
381 	uno::Reference< table::XColumnRowRange > xColumnRowRange(xRange, uno::UNO_QUERY_THROW );
382 	if ( xColumnRowRange->getRows()->getCount() == 1 && xColumnRowRange->getColumns()->getCount() == 1 )
383 		bRangeIsSingleCell = true;
384 	m_xProps.set( xRange, uno::UNO_QUERY_THROW );
385 }
386 
387 uno::Reference< container::XEnumeration >
createEnumeration()388 ScVbaBorders::createEnumeration() throw (uno::RuntimeException)
389 {
390 	return new RangeBorderEnumWrapper( m_xIndexAccess );
391 }
392 
393 uno::Any
createCollectionObject(const css::uno::Any & aSource)394 ScVbaBorders::createCollectionObject( const css::uno::Any& aSource )
395 {
396 	return aSource; // its already a Border object
397 }
398 
399 uno::Type
getElementType()400 ScVbaBorders::getElementType() throw (uno::RuntimeException)
401 {
402 	return excel::XBorders::static_type(0);
403 }
404 
405 uno::Any
getItemByIntIndex(const sal_Int32 nIndex)406 ScVbaBorders::getItemByIntIndex( const sal_Int32 nIndex )  throw (uno::RuntimeException)
407 {
408 	return createCollectionObject( m_xIndexAccess->getByIndex( nIndex ) );
409 }
410 
411 
getColor()412 uno::Any SAL_CALL ScVbaBorders::getColor() throw (uno::RuntimeException)
413 {
414     sal_Int32 count = getCount();
415     uno::Any color;
416     for( sal_Int32 i = 0; i < count ; i++ )
417     {
418         if( XlBordersIndex::xlDiagonalDown != supportedIndexTable[i] && XlBordersIndex::xlDiagonalUp != supportedIndexTable[i] )
419         {
420             uno::Reference< XBorder > xBorder( getItemByIntIndex( supportedIndexTable[i] ), uno::UNO_QUERY_THROW );
421             if( color.hasValue() )
422             {
423                 if( color != xBorder->getColor() )
424                     return uno::makeAny( uno::Reference< uno::XInterface >() );
425             }
426             else
427                 color = xBorder->getColor();
428         }
429     }
430     return  color;
431 }
setColor(const uno::Any & _color)432 void SAL_CALL ScVbaBorders::setColor( const uno::Any& _color ) throw (uno::RuntimeException)
433 {
434     sal_Int32 count = getCount();
435     for( sal_Int32 i = 0; i < count ; i++ )
436     {
437         uno::Reference< XBorder > xBorder( getItemByIntIndex( supportedIndexTable[i] ), uno::UNO_QUERY_THROW );
438         xBorder->setColor( _color );
439     }
440 }
getColorIndex()441 uno::Any SAL_CALL ScVbaBorders::getColorIndex() throw (uno::RuntimeException)
442 {
443     sal_Int32 count = getCount();
444     uno::Any nColorIndex;
445     for( sal_Int32 i = 0; i < count ; i++ )
446     {
447         if( XlBordersIndex::xlDiagonalDown != supportedIndexTable[i] && XlBordersIndex::xlDiagonalUp != supportedIndexTable[i] )
448         {
449             uno::Reference< XBorder > xBorder( getItemByIntIndex( supportedIndexTable[i] ), uno::UNO_QUERY_THROW );
450             if( nColorIndex.hasValue() )
451             {
452                 if( nColorIndex != xBorder->getColorIndex() )
453                     return uno::makeAny( uno::Reference< uno::XInterface >() );
454             }
455             else
456                 nColorIndex = xBorder->getColorIndex();
457         }
458     }
459     return  nColorIndex;
460 }
setColorIndex(const uno::Any & _colorindex)461 void SAL_CALL ScVbaBorders::setColorIndex( const uno::Any& _colorindex ) throw (uno::RuntimeException)
462 {
463     sal_Int32 count = getCount();
464     for( sal_Int32 i = 0; i < count ; i++ )
465     {
466         uno::Reference< XBorder > xBorder( getItemByIntIndex( supportedIndexTable[i] ), uno::UNO_QUERY_THROW );
467         xBorder->setColorIndex( _colorindex );
468     }
469 }
470 
471 bool
lcl_areAllLineWidthsSame(const table::TableBorder & maTableBorder,bool bIsCell)472 lcl_areAllLineWidthsSame( const table::TableBorder& maTableBorder, bool bIsCell )
473 {
474 
475 	bool bRes = false;
476 	if (bIsCell)
477 	{
478 		bRes = ((maTableBorder.TopLine.OuterLineWidth == maTableBorder.BottomLine.OuterLineWidth) &&
479 (maTableBorder.TopLine.OuterLineWidth == maTableBorder.LeftLine.OuterLineWidth) &&
480 (maTableBorder.TopLine.OuterLineWidth == maTableBorder.RightLine.OuterLineWidth));
481 	}
482 	else
483 	{
484 		bRes = ((maTableBorder.TopLine.OuterLineWidth == maTableBorder.BottomLine.OuterLineWidth) &&
485 (maTableBorder.TopLine.OuterLineWidth == maTableBorder.LeftLine.OuterLineWidth) &&
486 (maTableBorder.TopLine.OuterLineWidth == maTableBorder.HorizontalLine.OuterLineWidth) &&
487 (maTableBorder.TopLine.OuterLineWidth == maTableBorder.VerticalLine.OuterLineWidth) &&
488 (maTableBorder.TopLine.OuterLineWidth == maTableBorder.RightLine.OuterLineWidth));
489 	}
490 	return bRes;
491 }
492 
getLineStyle()493 uno::Any SAL_CALL ScVbaBorders::getLineStyle() throw (uno::RuntimeException)
494 {
495 	table::TableBorder maTableBorder;
496 	m_xProps->getPropertyValue( sTableBorder ) >>= maTableBorder;
497 
498 	sal_Int32 aLinestyle =  XlLineStyle::xlLineStyleNone;
499 
500 	if ( lcl_areAllLineWidthsSame( maTableBorder, bRangeIsSingleCell ))
501 	{
502 		if (maTableBorder.TopLine.LineDistance != 0)
503 		{
504 			aLinestyle = XlLineStyle::xlDouble;
505 		}
506 		else if ( maTableBorder.TopLine.OuterLineWidth != 0 )
507 		{
508 			aLinestyle = XlLineStyle::xlContinuous;
509 		}
510 	}
511 	return uno::makeAny( aLinestyle );
512 }
setLineStyle(const uno::Any & _linestyle)513 void SAL_CALL ScVbaBorders::setLineStyle( const uno::Any& _linestyle ) throw (uno::RuntimeException)
514 {
515     sal_Int32 count = getCount();
516     for( sal_Int32 i = 0; i < count ; i++ )
517     {
518         uno::Reference< XBorder > xBorder( getItemByIntIndex( supportedIndexTable[i] ), uno::UNO_QUERY_THROW );
519         xBorder->setLineStyle( _linestyle );
520     }
521 }
getWeight()522 uno::Any SAL_CALL ScVbaBorders::getWeight() throw (uno::RuntimeException)
523 {
524     sal_Int32 count = getCount();
525     uno::Any weight;
526     for( sal_Int32 i = 0; i < count ; i++ )
527     {
528         if( XlBordersIndex::xlDiagonalDown != supportedIndexTable[i] && XlBordersIndex::xlDiagonalUp != supportedIndexTable[i] )
529         {
530             uno::Reference< XBorder > xBorder( getItemByIntIndex( supportedIndexTable[i] ), uno::UNO_QUERY_THROW );
531             if( weight.hasValue() )
532             {
533                 if( weight != xBorder->getWeight() )
534                     return uno::makeAny( uno::Reference< uno::XInterface >() );
535             }
536             else
537                 weight = xBorder->getWeight();
538         }
539     }
540     return  weight;
541 }
setWeight(const uno::Any & _weight)542 void SAL_CALL ScVbaBorders::setWeight( const uno::Any& _weight ) throw (uno::RuntimeException)
543 {
544     sal_Int32 count = getCount();
545     for( sal_Int32 i = 0; i < count ; i++ )
546     {
547         uno::Reference< XBorder > xBorder( getItemByIntIndex( supportedIndexTable[i] ), uno::UNO_QUERY_THROW );
548         xBorder->setWeight( _weight );
549     }
550 }
551 
552 
553 rtl::OUString&
getServiceImplName()554 ScVbaBorders::getServiceImplName()
555 {
556 	static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaBorders") );
557 	return sImplName;
558 }
559 
560 uno::Sequence< rtl::OUString >
getServiceNames()561 ScVbaBorders::getServiceNames()
562 {
563 	static uno::Sequence< rtl::OUString > aServiceNames;
564 	if ( aServiceNames.getLength() == 0 )
565 	{
566 		aServiceNames.realloc( 1 );
567 		aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Borders" ) );
568 	}
569 	return aServiceNames;
570 }
571