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

Generated by: LCOV version 1.10