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

Generated by: LCOV version 1.10