LCOV - code coverage report
Current view: top level - sw/source/ui/vba - vbaborders.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 144 0.7 %
Date: 2014-11-03 Functions: 2 34 5.9 %
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             : #include <ooo/vba/word/XBorder.hpp>
      21             : #include <ooo/vba/word/WdBorderType.hpp>
      22             : #include <ooo/vba/word/WdLineStyle.hpp>
      23             : #include <sal/macros.h>
      24             : #include <cppuhelper/implbase3.hxx>
      25             : #include <com/sun/star/beans/XPropertySet.hpp>
      26             : #include <com/sun/star/table/TableBorder.hpp>
      27             : #include <com/sun/star/table/ShadowFormat.hpp>
      28             : #include <com/sun/star/table/ShadowLocation.hpp>
      29             : #include "vbapalette.hxx"
      30             : 
      31             : using namespace ::com::sun::star;
      32             : using namespace ::ooo::vba;
      33             : 
      34             : typedef ::cppu::WeakImplHelper1<container::XIndexAccess > RangeBorders_Base;
      35             : typedef InheritedHelperInterfaceImpl1<word::XBorder > SwVbaBorder_Base;
      36             : 
      37             : // #TODO sort these indexes to match the order in which Word iterates over the
      38             : // borders, the enumeration will match the order in this list
      39             : static const sal_Int16 supportedIndexTable[] = { word::WdBorderType::wdBorderBottom, word::WdBorderType::wdBorderDiagonalDown, word::WdBorderType::wdBorderDiagonalUp, word::WdBorderType::wdBorderHorizontal, word::WdBorderType::wdBorderLeft, word::WdBorderType::wdBorderRight, word::WdBorderType::wdBorderTop, word::WdBorderType::wdBorderVertical };
      40             : 
      41             : //  Equiv widths in in 1/100 mm
      42             : const static sal_Int32 OOLineHairline = 2;
      43             : 
      44           0 : class SwVbaBorder : public SwVbaBorder_Base
      45             : {
      46             : private:
      47             :     uno::Reference< beans::XPropertySet > m_xProps;
      48             :     sal_Int32 m_LineType;
      49             :     VbaPalette m_Palette;
      50           0 :     bool setBorderLine( table::BorderLine& rBorderLine )
      51             :     {
      52           0 :         table::TableBorder aTableBorder;
      53           0 :         m_xProps->getPropertyValue( "TableBorder" ) >>= aTableBorder;
      54             : 
      55           0 :         switch ( m_LineType )
      56             :         {
      57             :             case word::WdBorderType::wdBorderLeft:
      58           0 :                 aTableBorder.IsLeftLineValid = sal_True;
      59           0 :                 aTableBorder.LeftLine= rBorderLine;
      60           0 :                 break;
      61             :             case word::WdBorderType::wdBorderTop:
      62           0 :                 aTableBorder.IsTopLineValid = sal_True;
      63           0 :                 aTableBorder.TopLine = rBorderLine;
      64           0 :                 break;
      65             : 
      66             :             case word::WdBorderType::wdBorderBottom:
      67           0 :                 aTableBorder.IsBottomLineValid = sal_True;
      68           0 :                 aTableBorder.BottomLine = rBorderLine;
      69           0 :                 break;
      70             :             case word::WdBorderType::wdBorderRight:
      71           0 :                 aTableBorder.IsRightLineValid = sal_True;
      72           0 :                 aTableBorder.RightLine = rBorderLine;
      73           0 :                 break;
      74             :             case word::WdBorderType::wdBorderVertical:
      75           0 :                 aTableBorder.IsVerticalLineValid = sal_True;
      76           0 :                 aTableBorder.VerticalLine = rBorderLine;
      77           0 :                 break;
      78             :             case word::WdBorderType::wdBorderHorizontal:
      79           0 :                 aTableBorder.IsHorizontalLineValid = sal_True;
      80           0 :                 aTableBorder.HorizontalLine = rBorderLine;
      81           0 :                 break;
      82             :             case word::WdBorderType::wdBorderDiagonalDown:
      83             :             case word::WdBorderType::wdBorderDiagonalUp:
      84             :                 // #TODO have to ignore at the momement, would be
      85             :                 // nice to investigate what we can do here
      86           0 :                 break;
      87             :             default:
      88           0 :                     return false;
      89             :         }
      90           0 :         m_xProps->setPropertyValue( "TableBorder", uno::makeAny(aTableBorder) );
      91           0 :         return true;
      92             :     }
      93             : 
      94           0 :     bool getBorderLine( table::BorderLine& rBorderLine )
      95             :     {
      96           0 :         table::TableBorder aTableBorder;
      97           0 :         m_xProps->getPropertyValue( "TableBorder" ) >>= aTableBorder;
      98           0 :         switch ( m_LineType )
      99             :         {
     100             :             case word::WdBorderType::wdBorderLeft:
     101           0 :                 if ( aTableBorder.IsLeftLineValid )
     102           0 :                     rBorderLine = aTableBorder.LeftLine;
     103           0 :                 break;
     104             :             case word::WdBorderType::wdBorderTop:
     105           0 :                 if ( aTableBorder.IsTopLineValid )
     106           0 :                     rBorderLine = aTableBorder.TopLine;
     107           0 :                 break;
     108             :             case word::WdBorderType::wdBorderBottom:
     109           0 :                 if ( aTableBorder.IsBottomLineValid )
     110           0 :                     rBorderLine = aTableBorder.BottomLine;
     111           0 :                 break;
     112             :             case word::WdBorderType::wdBorderRight:
     113           0 :                 if ( aTableBorder.IsRightLineValid )
     114           0 :                     rBorderLine = aTableBorder.RightLine;
     115           0 :                 break;
     116             :             case word::WdBorderType::wdBorderVertical:
     117           0 :                 if ( aTableBorder.IsVerticalLineValid )
     118           0 :                     rBorderLine = aTableBorder.VerticalLine;
     119           0 :                 break;
     120             :             case word::WdBorderType::wdBorderHorizontal:
     121           0 :                 if ( aTableBorder.IsHorizontalLineValid )
     122           0 :                     rBorderLine = aTableBorder.HorizontalLine;
     123           0 :                 break;
     124             : 
     125             :             case word::WdBorderType::wdBorderDiagonalDown:
     126             :             case word::WdBorderType::wdBorderDiagonalUp:
     127             :                 // #TODO have to ignore at the momement, would be
     128             :                 // nice to investigate what we can do here
     129           0 :                 break;
     130             :             default:
     131           0 :                     return false;
     132             :         }
     133           0 :         return true;
     134             :     }
     135             : 
     136             : protected:
     137           0 :     virtual OUString getServiceImplName() SAL_OVERRIDE
     138             :     {
     139           0 :         return OUString("SwVbaBorder");
     140             :     }
     141             : 
     142           0 :     virtual css::uno::Sequence<OUString> getServiceNames() SAL_OVERRIDE
     143             :     {
     144           0 :         static uno::Sequence< OUString > aServiceNames;
     145           0 :         if ( aServiceNames.getLength() == 0 )
     146             :         {
     147           0 :             aServiceNames.realloc( 1 );
     148           0 :             aServiceNames[ 0 ] = "ooo.vba.word.Border";
     149             :         }
     150           0 :         return aServiceNames;
     151             :     }
     152             : public:
     153           0 :     SwVbaBorder( const uno::Reference< beans::XPropertySet > & xProps, const uno::Reference< uno::XComponentContext >& xContext, sal_Int32 lineType, VbaPalette& rPalette) : SwVbaBorder_Base( uno::Reference< XHelperInterface >( xProps, uno::UNO_QUERY ), xContext ), m_xProps( xProps ), m_LineType( lineType ), m_Palette( rPalette ) {}
     154             : 
     155           0 :     uno::Any SAL_CALL getLineStyle() throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
     156             :     {
     157           0 :         sal_Int32 nLineStyle = word::WdLineStyle::wdLineStyleNone;
     158           0 :         table::BorderLine aBorderLine;
     159           0 :         if ( getBorderLine( aBorderLine ) )
     160             :         {
     161           0 :             if( aBorderLine.InnerLineWidth !=0 && aBorderLine.OuterLineWidth !=0 )
     162             :             {
     163           0 :                 nLineStyle = word::WdLineStyle::wdLineStyleDouble;
     164             :             }
     165           0 :             else if( aBorderLine.InnerLineWidth !=0 || aBorderLine.OuterLineWidth !=0 )
     166             :             {
     167           0 :                 nLineStyle = word::WdLineStyle::wdLineStyleSingle;
     168             :             }
     169             :             else
     170             :             {
     171           0 :                 nLineStyle = word::WdLineStyle::wdLineStyleNone;
     172             :             }
     173             :         }
     174           0 :         return uno::makeAny( nLineStyle );
     175             :     }
     176           0 :     void SAL_CALL setLineStyle( const uno::Any& _linestyle ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
     177             :     {
     178             :         // Urk no choice but to silently ignore we don't support this attribute
     179             :         // #TODO would be nice to support the word line styles
     180           0 :         sal_Int32 nLineStyle = 0;
     181           0 :         _linestyle >>= nLineStyle;
     182           0 :         table::BorderLine aBorderLine;
     183           0 :         if ( getBorderLine( aBorderLine ) )
     184             :         {
     185           0 :             switch ( nLineStyle )
     186             :             {
     187             :                 case word::WdLineStyle::wdLineStyleNone:
     188             :                 {
     189           0 :                     aBorderLine.InnerLineWidth = 0;
     190           0 :                     aBorderLine.OuterLineWidth = 0;
     191           0 :                     break;
     192             :                 }
     193             :                 case word::WdLineStyle::wdLineStyleDashDot:
     194             :                 case word::WdLineStyle::wdLineStyleDashDotDot:
     195             :                 case word::WdLineStyle::wdLineStyleDashDotStroked:
     196             :                 case word::WdLineStyle::wdLineStyleDashLargeGap:
     197             :                 case word::WdLineStyle::wdLineStyleDashSmallGap:
     198             :                 case word::WdLineStyle::wdLineStyleDot:
     199             :                 case word::WdLineStyle::wdLineStyleDouble:
     200             :                 case word::WdLineStyle::wdLineStyleDoubleWavy:
     201             :                 case word::WdLineStyle::wdLineStyleEmboss3D:
     202             :                 case word::WdLineStyle::wdLineStyleEngrave3D:
     203             :                 case word::WdLineStyle::wdLineStyleInset:
     204             :                 case word::WdLineStyle::wdLineStyleOutset:
     205             :                 case word::WdLineStyle::wdLineStyleSingle:
     206             :                 case word::WdLineStyle::wdLineStyleSingleWavy:
     207             :                 case word::WdLineStyle::wdLineStyleThickThinLargeGap:
     208             :                 case word::WdLineStyle::wdLineStyleThickThinMedGap:
     209             :                 case word::WdLineStyle::wdLineStyleThickThinSmallGap:
     210             :                 case word::WdLineStyle::wdLineStyleThinThickLargeGap:
     211             :                 case word::WdLineStyle::wdLineStyleThinThickMedGap:
     212             :                 case word::WdLineStyle::wdLineStyleThinThickSmallGap:
     213             :                 case word::WdLineStyle::wdLineStyleThinThickThinLargeGap:
     214             :                 case word::WdLineStyle::wdLineStyleThinThickThinMedGap:
     215             :                 case word::WdLineStyle::wdLineStyleThinThickThinSmallGap:
     216             :                 case word::WdLineStyle::wdLineStyleTriple:
     217             :                 {
     218           0 :                     aBorderLine.InnerLineWidth = 0;
     219           0 :                     aBorderLine.OuterLineWidth = OOLineHairline;
     220           0 :                     break;
     221             :                 }
     222             :                 default:
     223           0 :                     throw uno::RuntimeException("Bad param" );
     224             :             }
     225           0 :             setBorderLine( aBorderLine );
     226             :         }
     227             :         else
     228           0 :             throw uno::RuntimeException("Method failed" );
     229           0 :     }
     230             : };
     231             : 
     232           0 : class RangeBorders : public RangeBorders_Base
     233             : {
     234             : private:
     235             :     uno::Reference< table::XCellRange > m_xRange;
     236             :     uno::Reference< uno::XComponentContext > m_xContext;
     237             :     VbaPalette m_Palette;
     238           0 :     sal_Int32 getTableIndex( sal_Int32 nConst )
     239             :     {
     240             :         // hokay return position of the index in the table
     241           0 :         sal_Int32 nIndexes = getCount();
     242           0 :         sal_Int32 realIndex = 0;
     243           0 :         const sal_Int16* pTableEntry = supportedIndexTable;
     244           0 :         for ( ; realIndex < nIndexes; ++realIndex, ++pTableEntry )
     245             :         {
     246           0 :             if ( *pTableEntry == nConst )
     247           0 :                 return realIndex;
     248             :         }
     249           0 :         return getCount(); // error condition
     250             :     }
     251             : public:
     252           0 :     RangeBorders(  const uno::Reference< table::XCellRange >& xRange,  const uno::Reference< uno::XComponentContext > & xContext, VbaPalette& rPalette ) : m_xRange( xRange ), m_xContext( xContext ), m_Palette( rPalette )
     253             :     {
     254           0 :     }
     255             :     // XIndexAccess
     256           0 :     virtual ::sal_Int32 SAL_CALL getCount(  ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
     257             :     {
     258           0 :         return SAL_N_ELEMENTS( supportedIndexTable );
     259             :     }
     260           0 :     virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException, std::exception) SAL_OVERRIDE
     261             :     {
     262             : 
     263           0 :         sal_Int32 nIndex = getTableIndex( Index );
     264           0 :         if ( nIndex >= 0 && nIndex < getCount() )
     265             :         {
     266           0 :             uno::Reference< beans::XPropertySet > xProps( m_xRange, uno::UNO_QUERY_THROW );
     267           0 :             return uno::makeAny( uno::Reference< word::XBorder >( new SwVbaBorder( xProps, m_xContext, supportedIndexTable[ nIndex ], m_Palette )) );
     268             :         }
     269           0 :         throw lang::IndexOutOfBoundsException();
     270             :     }
     271           0 :     virtual uno::Type SAL_CALL getElementType(  ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
     272             :     {
     273           0 :         return  cppu::UnoType<word::XBorder>::get();
     274             :     }
     275           0 :     virtual sal_Bool SAL_CALL hasElements(  ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
     276             :     {
     277           0 :         return sal_True;
     278             :     }
     279             : };
     280             : 
     281             : uno::Reference< container::XIndexAccess >
     282           0 : rangeToBorderIndexAccess( const uno::Reference< table::XCellRange >& xRange,  const uno::Reference< uno::XComponentContext > & xContext, VbaPalette& rPalette )
     283             : {
     284           0 :     return new RangeBorders( xRange, xContext, rPalette );
     285             : }
     286             : 
     287           0 : class RangeBorderEnumWrapper : public EnumerationHelper_BASE
     288             : {
     289             :     uno::Reference<container::XIndexAccess > m_xIndexAccess;
     290             :     sal_Int32 nIndex;
     291             : public:
     292           0 :     RangeBorderEnumWrapper( const uno::Reference< container::XIndexAccess >& xIndexAccess ) : m_xIndexAccess( xIndexAccess ), nIndex( 0 ) {}
     293           0 :     virtual sal_Bool SAL_CALL hasMoreElements(  ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
     294             :     {
     295           0 :         return ( nIndex < m_xIndexAccess->getCount() );
     296             :     }
     297             : 
     298           0 :     virtual uno::Any SAL_CALL nextElement(  ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception) SAL_OVERRIDE
     299             :     {
     300           0 :         if ( nIndex < m_xIndexAccess->getCount() )
     301           0 :             return m_xIndexAccess->getByIndex( nIndex++ );
     302           0 :         throw container::NoSuchElementException();
     303             :     }
     304             : };
     305             : 
     306             : // for Table borders
     307           0 : SwVbaBorders::SwVbaBorders( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< table::XCellRange >& xRange, VbaPalette& rPalette  ):  SwVbaBorders_BASE( xParent, xContext, rangeToBorderIndexAccess( xRange ,xContext, rPalette ) )
     308             : {
     309           0 :     m_xProps.set( xRange, uno::UNO_QUERY_THROW );
     310           0 : }
     311             : 
     312             : uno::Reference< container::XEnumeration >
     313           0 : SwVbaBorders::createEnumeration() throw (uno::RuntimeException)
     314             : {
     315           0 :     return new RangeBorderEnumWrapper( m_xIndexAccess );
     316             : }
     317             : 
     318             : uno::Any
     319           0 : SwVbaBorders::createCollectionObject( const css::uno::Any& aSource )
     320             : {
     321           0 :     return aSource; // its already a Border object
     322             : }
     323             : 
     324             : uno::Type
     325           0 : SwVbaBorders::getElementType() throw (uno::RuntimeException)
     326             : {
     327           0 :     return cppu::UnoType<word::XBorders>::get();
     328             : }
     329             : 
     330             : uno::Any
     331           0 : SwVbaBorders::getItemByIntIndex( const sal_Int32 nIndex )  throw (uno::RuntimeException)
     332             : {
     333           0 :     return createCollectionObject( m_xIndexAccess->getByIndex( nIndex ) );
     334             : }
     335             : 
     336           0 : sal_Bool SAL_CALL SwVbaBorders::getShadow() throw (uno::RuntimeException, std::exception)
     337             : {
     338             :     // always return False for table border in MS Word
     339           0 :     return sal_False;
     340             : }
     341             : 
     342           0 : void SAL_CALL SwVbaBorders::setShadow( sal_Bool /*_shadow*/ ) throw (uno::RuntimeException, std::exception)
     343             : {
     344             :     // not support in Table border in Word
     345             :     // TODO:
     346           0 : }
     347             : 
     348             : OUString
     349           0 : SwVbaBorders::getServiceImplName()
     350             : {
     351           0 :     return OUString("SwVbaBorders");
     352             : }
     353             : 
     354             : uno::Sequence< OUString >
     355           0 : SwVbaBorders::getServiceNames()
     356             : {
     357           0 :     static uno::Sequence< OUString > aServiceNames;
     358           0 :     if ( aServiceNames.getLength() == 0 )
     359             :     {
     360           0 :         aServiceNames.realloc( 1 );
     361           0 :         aServiceNames[ 0 ] = "ooo.vba.word.Borders";
     362             :     }
     363           0 :     return aServiceNames;
     364           6 : }
     365             : 
     366             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10