LCOV - code coverage report
Current view: top level - sc/source/ui/vba - vbaborders.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 276 0.0 %
Date: 2014-04-14 Functions: 0 47 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10