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