23 #include <ooo/vba/excel/XlBordersIndex.hpp>
24 #include <ooo/vba/excel/XlBorderWeight.hpp>
25 #include <ooo/vba/excel/XlLineStyle.hpp>
26 #include <ooo/vba/excel/XlColorIndex.hpp>
27 #include <com/sun/star/beans/XPropertySet.hpp>
28 #include <com/sun/star/table/TableBorder.hpp>
29 #include <com/sun/star/table/XCellRange.hpp>
30 #include <com/sun/star/table/XColumnRowRange.hpp>
43 const sal_Int16
supportedIndexTable[] = { XlBordersIndex::xlEdgeLeft, XlBordersIndex::xlEdgeTop, XlBordersIndex::xlEdgeBottom, XlBordersIndex::xlEdgeRight, XlBordersIndex::xlDiagonalDown, XlBordersIndex::xlDiagonalUp, XlBordersIndex::xlInsideVertical, XlBordersIndex::xlInsideHorizontal };
58 uno::Reference< beans::XPropertySet >
m_xProps;
61 void setBorderLine(
const table::BorderLine& rBorderLine )
63 table::TableBorder aTableBorder;
64 m_xProps->getPropertyValue(
sTableBorder ) >>= aTableBorder;
68 case XlBordersIndex::xlEdgeLeft:
69 aTableBorder.IsLeftLineValid =
true;
70 aTableBorder.LeftLine= rBorderLine;
72 case XlBordersIndex::xlEdgeTop:
73 aTableBorder.IsTopLineValid =
true;
74 aTableBorder.TopLine = rBorderLine;
77 case XlBordersIndex::xlEdgeBottom:
78 aTableBorder.IsBottomLineValid =
true;
79 aTableBorder.BottomLine = rBorderLine;
81 case XlBordersIndex::xlEdgeRight:
82 aTableBorder.IsRightLineValid =
true;
83 aTableBorder.RightLine = rBorderLine;
85 case XlBordersIndex::xlInsideVertical:
86 aTableBorder.IsVerticalLineValid =
true;
87 aTableBorder.VerticalLine = rBorderLine;
89 case XlBordersIndex::xlInsideHorizontal:
90 aTableBorder.IsHorizontalLineValid =
true;
91 aTableBorder.HorizontalLine = rBorderLine;
93 case XlBordersIndex::xlDiagonalDown:
94 case XlBordersIndex::xlDiagonalUp:
101 m_xProps->setPropertyValue(
sTableBorder, uno::makeAny(aTableBorder) );
104 bool getBorderLine( table::BorderLine& rBorderLine )
106 table::TableBorder aTableBorder;
107 m_xProps->getPropertyValue(
sTableBorder ) >>= aTableBorder;
108 switch ( m_LineType )
110 case XlBordersIndex::xlEdgeLeft:
111 if ( aTableBorder.IsLeftLineValid )
112 rBorderLine = aTableBorder.LeftLine;
114 case XlBordersIndex::xlEdgeTop:
115 if ( aTableBorder.IsTopLineValid )
116 rBorderLine = aTableBorder.TopLine;
119 case XlBordersIndex::xlEdgeBottom:
120 if ( aTableBorder.IsBottomLineValid )
121 rBorderLine = aTableBorder.BottomLine;
123 case XlBordersIndex::xlEdgeRight:
124 if ( aTableBorder.IsRightLineValid )
125 rBorderLine = aTableBorder.RightLine;
127 case XlBordersIndex::xlInsideVertical:
128 if ( aTableBorder.IsVerticalLineValid )
129 rBorderLine = aTableBorder.VerticalLine;
131 case XlBordersIndex::xlInsideHorizontal:
132 if ( aTableBorder.IsHorizontalLineValid )
133 rBorderLine = aTableBorder.HorizontalLine;
136 case XlBordersIndex::xlDiagonalDown:
137 case XlBordersIndex::xlDiagonalUp:
150 return "ScVbaBorder";
156 "ooo.vba.excel.Border"
161 ScVbaBorder(
const uno::Reference< beans::XPropertySet > & xProps,
const uno::Reference< uno::XComponentContext >& xContext, sal_Int32 lineType,
const ScVbaPalette& rPalette) :
ScVbaBorder_Base( uno::Reference< XHelperInterface >( xProps, uno::UNO_QUERY ), xContext ), m_xProps( xProps ), m_LineType( lineType ), m_Palette( rPalette ) {}
164 uno::Any SAL_CALL getColor()
override
166 table::BorderLine aBorderLine;
167 if ( getBorderLine( aBorderLine ) )
169 throw uno::RuntimeException(
"No Implementation available" );
171 void SAL_CALL setColor(
const uno::Any& _color )
override
173 sal_Int32 nColor = 0;
175 table::BorderLine aBorderLine;
176 if ( !getBorderLine( aBorderLine ) )
177 throw uno::RuntimeException(
"No Implementation available" );
180 setBorderLine( aBorderLine );
184 uno::Any SAL_CALL getColorIndex()
override
186 sal_Int32 nColor = 0;
188 uno::Reference< container::XIndexAccess > xIndex = m_Palette.
getPalette();
189 sal_Int32 nElems = xIndex->getCount();
193 sal_Int32 nPaletteColor = 0;
194 xIndex->getByIndex(
count ) >>= nPaletteColor;
195 if ( nPaletteColor == nColor )
201 return uno::makeAny(nIndex);
204 void SAL_CALL setColorIndex(
const uno::Any& _colorindex )
override
206 sal_Int32 nColor = 0;
207 _colorindex >>= nColor;
208 if ( !nColor || nColor == XlColorIndex::xlColorIndexAutomatic )
212 uno::Any SAL_CALL getWeight()
override
214 table::BorderLine aBorderLine;
215 if ( getBorderLine( aBorderLine ) )
217 switch ( aBorderLine.OuterLineWidth )
221 return uno::makeAny( XlBorderWeight::xlThin );
223 return uno::makeAny( XlBorderWeight::xlMedium );
225 return uno::makeAny( XlBorderWeight::xlThick );
227 return uno::makeAny( XlBorderWeight::xlHairline );
232 throw uno::RuntimeException(
"Method failed" );
234 void SAL_CALL setWeight(
const uno::Any& _weight )
override
236 sal_Int32 nWeight = 0;
238 table::BorderLine aBorderLine;
239 if ( !getBorderLine( aBorderLine ) )
240 throw uno::RuntimeException(
"Method failed" );
244 case XlBorderWeight::xlThin:
247 case XlBorderWeight::xlMedium:
250 case XlBorderWeight::xlThick:
253 case XlBorderWeight::xlHairline:
257 throw uno::RuntimeException(
"Bad param" );
259 setBorderLine( aBorderLine );
263 void SAL_CALL setTintAndShade(
const uno::Any& )
override
267 uno::Any SAL_CALL getTintAndShade()
override
270 return uno::makeAny(static_cast<double>(0));
273 uno::Any SAL_CALL getLineStyle()
override
276 return uno::makeAny( XlLineStyle::xlContinuous );
278 void SAL_CALL setLineStyle(
const uno::Any& _linestyle )
override
282 sal_Int32 nLineStyle = 0;
283 _linestyle >>= nLineStyle;
284 table::BorderLine aBorderLine;
285 if ( !getBorderLine( aBorderLine ) )
286 throw uno::RuntimeException(
"Method failed" );
288 switch ( nLineStyle )
290 case XlLineStyle::xlContinuous:
291 case XlLineStyle::xlDash:
292 case XlLineStyle::xlDashDot:
293 case XlLineStyle::xlDashDotDot:
294 case XlLineStyle::xlDot:
295 case XlLineStyle::xlDouble:
296 case XlLineStyle::xlLineStyleNone:
297 case XlLineStyle::xlSlantDashDot:
300 throw uno::RuntimeException(
"Bad param" );
302 setBorderLine( aBorderLine );
310 uno::Reference< table::XCellRange > m_xRange;
311 uno::Reference< uno::XComponentContext >
m_xContext;
313 sal_Int32 getTableIndex( sal_Int32 nConst )
316 sal_Int32 nIndexes = getCount();
317 sal_Int32 realIndex = 0;
319 for ( ; realIndex < nIndexes; ++realIndex, ++pTableEntry )
321 if ( *pTableEntry == nConst )
327 RangeBorders(
const uno::Reference< table::XCellRange >& xRange,
const uno::Reference< uno::XComponentContext > & xContext,
const ScVbaPalette& rPalette ) : m_xRange( xRange ), m_xContext( xContext ), m_Palette( rPalette )
331 virtual ::sal_Int32 SAL_CALL getCount( )
override
335 virtual uno::Any SAL_CALL getByIndex( ::sal_Int32
Index )
override
338 sal_Int32
nIndex = getTableIndex( Index );
339 if ( nIndex >= 0 && nIndex < getCount() )
341 uno::Reference< beans::XPropertySet > xProps( m_xRange, uno::UNO_QUERY_THROW );
342 return uno::makeAny( uno::Reference< excel::XBorder >(
new ScVbaBorder( xProps, m_xContext,
supportedIndexTable[ nIndex ], m_Palette )) );
344 throw lang::IndexOutOfBoundsException();
346 virtual uno::Type SAL_CALL getElementType( )
override
350 virtual sal_Bool SAL_CALL hasElements( )
override
358 static uno::Reference< container::XIndexAccess >
361 return new RangeBorders( xRange, xContext, rPalette );
368 uno::Reference<container::XIndexAccess > m_xIndexAccess;
371 explicit RangeBorderEnumWrapper(
const uno::Reference< container::XIndexAccess >& xIndexAccess ) : m_xIndexAccess( xIndexAccess ), nIndex( 0 ) {}
372 virtual sal_Bool SAL_CALL hasMoreElements( )
override
374 return ( nIndex < m_xIndexAccess->getCount() );
377 virtual uno::Any SAL_CALL nextElement( )
override
379 if ( nIndex < m_xIndexAccess->getCount() )
380 return m_xIndexAccess->getByIndex( nIndex++ );
381 throw container::NoSuchElementException();
388 const uno::Reference< uno::XComponentContext > & xContext,
389 const uno::Reference< table::XCellRange >& xRange,
393 uno::Reference< table::XColumnRowRange > xColumnRowRange(xRange, uno::UNO_QUERY_THROW );
394 if ( xColumnRowRange->getRows()->getCount() == 1 && xColumnRowRange->getColumns()->getCount() == 1 )
396 m_xProps.set( xRange, uno::UNO_QUERY_THROW );
399 uno::Reference< container::XEnumeration >
402 return new RangeBorderEnumWrapper( m_xIndexAccess );
427 for( sal_Int32
i = 0;
i < count ;
i++ )
434 if( color != xBorder->getColor() )
435 return uno::makeAny( uno::Reference< uno::XInterface >() );
438 color = xBorder->getColor();
446 for( sal_Int32
i = 0;
i < count ;
i++ )
449 xBorder->setColor( _color );
456 for( sal_Int32
i = 0;
i < count ;
i++ )
463 if( nColorIndex != xBorder->getColorIndex() )
464 return uno::makeAny( uno::Reference< uno::XInterface >() );
467 nColorIndex = xBorder->getColorIndex();
475 for( sal_Int32
i = 0;
i < count ;
i++ )
478 xBorder->setColorIndex( _colorindex );
489 bRes = ((maTableBorder.TopLine.OuterLineWidth == maTableBorder.BottomLine.OuterLineWidth) &&
490 (maTableBorder.TopLine.OuterLineWidth == maTableBorder.LeftLine.OuterLineWidth) &&
491 (maTableBorder.TopLine.OuterLineWidth == maTableBorder.RightLine.OuterLineWidth));
495 bRes = ((maTableBorder.TopLine.OuterLineWidth == maTableBorder.BottomLine.OuterLineWidth) &&
496 (maTableBorder.TopLine.OuterLineWidth == maTableBorder.LeftLine.OuterLineWidth) &&
497 (maTableBorder.TopLine.OuterLineWidth == maTableBorder.HorizontalLine.OuterLineWidth) &&
498 (maTableBorder.TopLine.OuterLineWidth == maTableBorder.VerticalLine.OuterLineWidth) &&
499 (maTableBorder.TopLine.OuterLineWidth == maTableBorder.RightLine.OuterLineWidth));
506 table::TableBorder aTableBorder;
509 sal_Int32 aLinestyle = XlLineStyle::xlLineStyleNone;
513 if (aTableBorder.TopLine.LineDistance != 0)
515 aLinestyle = XlLineStyle::xlDouble;
517 else if ( aTableBorder.TopLine.OuterLineWidth != 0 )
519 aLinestyle = XlLineStyle::xlContinuous;
522 return uno::makeAny( aLinestyle );
527 for( sal_Int32
i = 0;
i < count ;
i++ )
530 xBorder->setLineStyle( _linestyle );
537 for( sal_Int32
i = 0;
i < count ;
i++ )
544 if( weight != xBorder->getWeight() )
545 return uno::makeAny( uno::Reference< uno::XInterface >() );
548 weight = xBorder->getWeight();
557 return uno::makeAny(static_cast<double>(0));
568 for( sal_Int32
i = 0;
i < count ;
i++ )
571 xBorder->setWeight( _weight );
578 return "ScVbaBorders";
581 uno::Sequence< OUString >
586 "ooo.vba.excel.Borders"
const sal_Int32 OOLineThin
const size_t count(pCandidateA->getBorderLines().size())
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
css::uno::Reference< css::beans::XPropertySet > m_xProps
virtual css::uno::Any SAL_CALL getColorIndex() override
const sal_Int32 OOLineMedium
virtual void SAL_CALL setWeight(const css::uno::Any &) override
Sequence< OUString > aServiceNames
virtual void SAL_CALL setColorIndex(const css::uno::Any &_colorindex) override
sal_Int32 XLRGBToOORGB(sal_Int32 nCol)
virtual OUString getServiceImplName()=0
const sal_Int32 OOLineHairline
::cppu::WeakImplHelper< css::container::XEnumeration > EnumerationHelper_BASE
ScVbaBorders(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::table::XCellRange > &xRange, const ScVbaPalette &rPalette)
virtual css::uno::Sequence< OUString > getServiceNames()=0
virtual css::uno::Type SAL_CALL getElementType() override
virtual css::uno::Any getItemByIntIndex(const sal_Int32 nIndex) override
virtual css::uno::Any SAL_CALL getLineStyle() override
static uno::Reference< container::XIndexAccess > rangeToBorderIndexAccess(const uno::Reference< table::XCellRange > &xRange, const uno::Reference< uno::XComponentContext > &xContext, const ScVbaPalette &rPalette)
virtual css::uno::Any SAL_CALL getWeight() override
#define SAL_N_ELEMENTS(arr)
virtual OUString getServiceImplName() override
virtual css::uno::Any createCollectionObject(const css::uno::Any &aSource) override
constexpr OUStringLiteral sTableBorder
virtual void SAL_CALL setTintAndShade(const css::uno::Any &) override
virtual css::uno::Any SAL_CALL getTintAndShade() override
sal_Int32 OORGBToXLRGB(sal_Int32 nCol)
static bool lcl_areAllLineWidthsSame(const table::TableBorder &maTableBorder, bool bIsCell)
css::uno::Type const & get()
const sal_Int16 supportedIndexTable[]
InheritedHelperInterfaceWeakImpl< excel::XBorder > ScVbaBorder_Base
virtual css::uno::Sequence< OUString > getServiceNames() override
virtual void SAL_CALL setLineStyle(const css::uno::Any &_linestyle) override
Reference< XComponentContext > m_xContext
::cppu::WeakImplHelper< container::XIndexAccess > RangeBorders_Base
virtual css::uno::Any SAL_CALL getColor() override
virtual void SAL_CALL setColor(const css::uno::Any &_color) override
const sal_Int32 OOLineThick
virtual ::sal_Int32 SAL_CALL getCount() override
css::uno::Reference< css::container::XIndexAccess > getPalette() const