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