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>
44const sal_Int16
supportedIndexTable[] = { XlBordersIndex::xlEdgeLeft, XlBordersIndex::xlEdgeTop, XlBordersIndex::xlEdgeBottom, XlBordersIndex::xlEdgeRight, XlBordersIndex::xlDiagonalDown, XlBordersIndex::xlDiagonalUp, XlBordersIndex::xlInsideVertical, XlBordersIndex::xlInsideHorizontal };
59 uno::Reference< beans::XPropertySet >
m_xProps;
62 void setBorderLine(
const table::BorderLine& rBorderLine )
64 table::TableBorder aTableBorder;
69 case XlBordersIndex::xlEdgeLeft:
70 aTableBorder.IsLeftLineValid =
true;
71 aTableBorder.LeftLine= rBorderLine;
73 case XlBordersIndex::xlEdgeTop:
74 aTableBorder.IsTopLineValid =
true;
75 aTableBorder.TopLine = rBorderLine;
78 case XlBordersIndex::xlEdgeBottom:
79 aTableBorder.IsBottomLineValid =
true;
80 aTableBorder.BottomLine = rBorderLine;
82 case XlBordersIndex::xlEdgeRight:
83 aTableBorder.IsRightLineValid =
true;
84 aTableBorder.RightLine = rBorderLine;
86 case XlBordersIndex::xlInsideVertical:
87 aTableBorder.IsVerticalLineValid =
true;
88 aTableBorder.VerticalLine = rBorderLine;
90 case XlBordersIndex::xlInsideHorizontal:
91 aTableBorder.IsHorizontalLineValid =
true;
92 aTableBorder.HorizontalLine = rBorderLine;
94 case XlBordersIndex::xlDiagonalDown:
95 case XlBordersIndex::xlDiagonalUp:
105 bool getBorderLine( table::BorderLine& rBorderLine )
107 table::TableBorder aTableBorder;
109 switch ( m_LineType )
111 case XlBordersIndex::xlEdgeLeft:
112 if ( aTableBorder.IsLeftLineValid )
113 rBorderLine = aTableBorder.LeftLine;
115 case XlBordersIndex::xlEdgeTop:
116 if ( aTableBorder.IsTopLineValid )
117 rBorderLine = aTableBorder.TopLine;
120 case XlBordersIndex::xlEdgeBottom:
121 if ( aTableBorder.IsBottomLineValid )
122 rBorderLine = aTableBorder.BottomLine;
124 case XlBordersIndex::xlEdgeRight:
125 if ( aTableBorder.IsRightLineValid )
126 rBorderLine = aTableBorder.RightLine;
128 case XlBordersIndex::xlInsideVertical:
129 if ( aTableBorder.IsVerticalLineValid )
130 rBorderLine = aTableBorder.VerticalLine;
132 case XlBordersIndex::xlInsideHorizontal:
133 if ( aTableBorder.IsHorizontalLineValid )
134 rBorderLine = aTableBorder.HorizontalLine;
137 case XlBordersIndex::xlDiagonalDown:
138 case XlBordersIndex::xlDiagonalUp:
151 return "ScVbaBorder";
157 "ooo.vba.excel.Border"
162 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 ) {}
165 uno::Any SAL_CALL getColor()
override
167 table::BorderLine aBorderLine;
168 if ( getBorderLine( aBorderLine ) )
170 throw uno::RuntimeException(
"No Implementation available" );
172 void SAL_CALL setColor(
const uno::Any& _color )
override
174 sal_Int32 nColor = 0;
176 table::BorderLine aBorderLine;
177 if ( !getBorderLine( aBorderLine ) )
178 throw uno::RuntimeException(
"No Implementation available" );
181 setBorderLine( aBorderLine );
185 uno::Any SAL_CALL getColorIndex()
override
187 sal_Int32 nColor = 0;
189 uno::Reference< container::XIndexAccess > xIndex = m_Palette.
getPalette();
190 sal_Int32 nElems = xIndex->getCount();
194 sal_Int32 nPaletteColor = 0;
195 xIndex->getByIndex(
count ) >>= nPaletteColor;
196 if ( nPaletteColor == nColor )
205 void SAL_CALL setColorIndex(
const uno::Any& _colorindex )
override
207 sal_Int32 nColor = 0;
208 _colorindex >>= nColor;
209 if ( !nColor || nColor == XlColorIndex::xlColorIndexAutomatic )
213 uno::Any SAL_CALL getWeight()
override
215 table::BorderLine aBorderLine;
216 if ( getBorderLine( aBorderLine ) )
218 switch ( aBorderLine.OuterLineWidth )
222 return uno::Any( XlBorderWeight::xlThin );
224 return uno::Any( XlBorderWeight::xlMedium );
226 return uno::Any( XlBorderWeight::xlThick );
228 return uno::Any( XlBorderWeight::xlHairline );
233 throw uno::RuntimeException(
"Method failed" );
235 void SAL_CALL setWeight(
const uno::Any& _weight )
override
237 sal_Int32 nWeight = 0;
239 table::BorderLine aBorderLine;
240 if ( !getBorderLine( aBorderLine ) )
241 throw uno::RuntimeException(
"Method failed" );
245 case XlBorderWeight::xlThin:
248 case XlBorderWeight::xlMedium:
251 case XlBorderWeight::xlThick:
254 case XlBorderWeight::xlHairline:
258 throw uno::RuntimeException(
"Bad param" );
260 setBorderLine( aBorderLine );
264 void SAL_CALL setTintAndShade(
const uno::Any& )
override
268 uno::Any SAL_CALL getTintAndShade()
override
271 return uno::Any(
static_cast<double>(0));
274 uno::Any SAL_CALL getLineStyle()
override
277 return uno::Any( XlLineStyle::xlContinuous );
279 void SAL_CALL setLineStyle(
const uno::Any& _linestyle )
override
283 sal_Int32 nLineStyle = 0;
284 _linestyle >>= nLineStyle;
285 table::BorderLine aBorderLine;
286 if ( !getBorderLine( aBorderLine ) )
287 throw uno::RuntimeException(
"Method failed" );
289 switch ( nLineStyle )
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:
301 throw uno::RuntimeException(
"Bad param" );
303 setBorderLine( aBorderLine );
311 uno::Reference< table::XCellRange > m_xRange;
312 uno::Reference< uno::XComponentContext >
m_xContext;
314 sal_Int32 getTableIndex( sal_Int32 nConst )
317 sal_Int32 nIndexes = getCount();
318 sal_Int32 realIndex = 0;
320 for ( ; realIndex < nIndexes; ++realIndex, ++pTableEntry )
322 if ( *pTableEntry == nConst )
328 RangeBorders( uno::Reference< table::XCellRange > xRange, uno::Reference< uno::XComponentContext > xContext,
const ScVbaPalette& rPalette ) : m_xRange(std::move( xRange )),
m_xContext(std::move( xContext )), m_Palette( rPalette )
332 virtual ::sal_Int32 SAL_CALL getCount( )
override
336 virtual uno::Any SAL_CALL getByIndex( ::sal_Int32
Index )
override
342 uno::Reference< beans::XPropertySet > xProps( m_xRange, uno::UNO_QUERY_THROW );
345 throw lang::IndexOutOfBoundsException();
347 virtual uno::Type SAL_CALL getElementType( )
override
351 virtual sal_Bool SAL_CALL hasElements( )
override
359static uno::Reference< container::XIndexAccess >
362 return new RangeBorders( xRange, xContext, rPalette );
369 uno::Reference<container::XIndexAccess > m_xIndexAccess;
372 explicit RangeBorderEnumWrapper( uno::Reference< container::XIndexAccess > xIndexAccess ) : m_xIndexAccess(
std::move( xIndexAccess )), m_nIndex( 0 ) {}
373 virtual sal_Bool SAL_CALL hasMoreElements( )
override
375 return ( m_nIndex < m_xIndexAccess->getCount() );
378 virtual uno::Any SAL_CALL nextElement( )
override
380 if ( m_nIndex < m_xIndexAccess->getCount() )
381 return m_xIndexAccess->getByIndex( m_nIndex++ );
382 throw container::NoSuchElementException();
389 const uno::Reference< uno::XComponentContext > & xContext,
390 const uno::Reference< table::XCellRange >& xRange,
394 uno::Reference< table::XColumnRowRange > xColumnRowRange(xRange, uno::UNO_QUERY_THROW );
395 if ( xColumnRowRange->getRows()->getCount() == 1 && xColumnRowRange->getColumns()->getCount() == 1 )
397 m_xProps.set( xRange, uno::UNO_QUERY_THROW );
400uno::Reference< container::XEnumeration >
428 for( sal_Int32
i = 0;
i <
count ;
i++ )
433 if(
color.hasValue() )
435 if(
color != xBorder->getColor() )
436 return uno::Any( uno::Reference< uno::XInterface >() );
439 color = xBorder->getColor();
447 for( sal_Int32
i = 0;
i <
count ;
i++ )
450 xBorder->setColor( _color );
457 for( sal_Int32
i = 0;
i <
count ;
i++ )
464 if( nColorIndex != xBorder->getColorIndex() )
465 return uno::Any( uno::Reference< uno::XInterface >() );
468 nColorIndex = xBorder->getColorIndex();
476 for( sal_Int32
i = 0;
i <
count ;
i++ )
479 xBorder->setColorIndex( _colorindex );
490 bRes = ((maTableBorder.TopLine.OuterLineWidth == maTableBorder.BottomLine.OuterLineWidth) &&
491(maTableBorder.TopLine.OuterLineWidth == maTableBorder.LeftLine.OuterLineWidth) &&
492(maTableBorder.TopLine.OuterLineWidth == maTableBorder.RightLine.OuterLineWidth));
496 bRes = ((maTableBorder.TopLine.OuterLineWidth == maTableBorder.BottomLine.OuterLineWidth) &&
497(maTableBorder.TopLine.OuterLineWidth == maTableBorder.LeftLine.OuterLineWidth) &&
498(maTableBorder.TopLine.OuterLineWidth == maTableBorder.HorizontalLine.OuterLineWidth) &&
499(maTableBorder.TopLine.OuterLineWidth == maTableBorder.VerticalLine.OuterLineWidth) &&
500(maTableBorder.TopLine.OuterLineWidth == maTableBorder.RightLine.OuterLineWidth));
507 table::TableBorder aTableBorder;
510 sal_Int32 aLinestyle = XlLineStyle::xlLineStyleNone;
514 if (aTableBorder.TopLine.LineDistance != 0)
516 aLinestyle = XlLineStyle::xlDouble;
518 else if ( aTableBorder.TopLine.OuterLineWidth != 0 )
520 aLinestyle = XlLineStyle::xlContinuous;
528 for( sal_Int32
i = 0;
i <
count ;
i++ )
531 xBorder->setLineStyle( _linestyle );
538 for( sal_Int32
i = 0;
i <
count ;
i++ )
545 if( weight != xBorder->getWeight() )
546 return uno::Any( uno::Reference< uno::XInterface >() );
549 weight = xBorder->getWeight();
558 return uno::Any(
static_cast<double>(0));
569 for( sal_Int32
i = 0;
i <
count ;
i++ )
572 xBorder->setWeight( _weight );
579 return "ScVbaBorders";
582uno::Sequence< OUString >
587 "ooo.vba.excel.Borders"
Reference< XComponentContext > m_xContext
virtual OUString getServiceImplName()=0
virtual css::uno::Sequence< OUString > getServiceNames()=0
virtual css::uno::Any SAL_CALL getColorIndex() override
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
virtual css::uno::Any getItemByIntIndex(const sal_Int32 nIndex) override
virtual css::uno::Any SAL_CALL getLineStyle() override
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::Any SAL_CALL getWeight() override
virtual OUString getServiceImplName() override
virtual css::uno::Any SAL_CALL getTintAndShade() override
virtual css::uno::Type SAL_CALL getElementType() override
virtual void SAL_CALL setTintAndShade(const css::uno::Any &) override
css::uno::Reference< css::beans::XPropertySet > m_xProps
virtual css::uno::Any createCollectionObject(const css::uno::Any &aSource) override
virtual css::uno::Sequence< OUString > getServiceNames() override
virtual void SAL_CALL setWeight(const css::uno::Any &) override
virtual css::uno::Any SAL_CALL getColor() override
virtual void SAL_CALL setColor(const css::uno::Any &_color) override
virtual void SAL_CALL setLineStyle(const css::uno::Any &_linestyle) override
virtual void SAL_CALL setColorIndex(const css::uno::Any &_colorindex) override
css::uno::Reference< css::container::XIndexAccess > m_xIndexAccess
virtual ::sal_Int32 SAL_CALL getCount() override
css::uno::Reference< css::container::XIndexAccess > getPalette() const
css::uno::Type const & get()
Sequence< OUString > aServiceNames
#define SAL_N_ELEMENTS(arr)
sal_Int32 XLRGBToOORGB(sal_Int32 nCol)
sal_Int32 OORGBToXLRGB(sal_Int32 nCol)
constexpr OUStringLiteral sTableBorder
const sal_Int32 OOLineMedium
const sal_Int32 OOLineThin
::cppu::WeakImplHelper< container::XIndexAccess > RangeBorders_Base
static bool lcl_areAllLineWidthsSame(const table::TableBorder &maTableBorder, bool bIsCell)
const sal_Int32 OOLineHairline
const sal_Int16 supportedIndexTable[]
static uno::Reference< container::XIndexAccess > rangeToBorderIndexAccess(const uno::Reference< table::XCellRange > &xRange, const uno::Reference< uno::XComponentContext > &xContext, const ScVbaPalette &rPalette)
InheritedHelperInterfaceWeakImpl< excel::XBorder > ScVbaBorder_Base
const sal_Int32 OOLineThick
::cppu::WeakImplHelper< css::container::XEnumeration > EnumerationHelper_BASE