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

Generated by: LCOV version 1.10