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