LCOV - code coverage report
Current view: top level - libreoffice/sw/source/ui/vba - vbatabstops.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 106 0.0 %
Date: 2012-12-17 Functions: 0 23 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 "vbatabstops.hxx"
      20             : #include "vbatabstop.hxx"
      21             : #include <com/sun/star/style/TabAlign.hpp>
      22             : #include <ooo/vba/word/WdTabLeader.hpp>
      23             : #include <ooo/vba/word/WdTabAlignment.hpp>
      24             : 
      25             : using namespace ::ooo::vba;
      26             : using namespace ::com::sun::star;
      27             : 
      28           0 : static uno::Sequence< style::TabStop > lcl_getTabStops( const uno::Reference< beans::XPropertySet >& xParaProps ) throw (uno::RuntimeException)
      29             : {
      30           0 :     uno::Sequence< style::TabStop > aSeq;
      31           0 :     xParaProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaTabStops") ) ) >>= aSeq;
      32           0 :     return aSeq;
      33             : }
      34             : 
      35           0 : static void lcl_setTabStops( const uno::Reference< beans::XPropertySet >& xParaProps, const uno::Sequence< style::TabStop >& aSeq ) throw (uno::RuntimeException)
      36             : {
      37           0 :     xParaProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaTabStops") ), uno::makeAny( aSeq ) );
      38           0 : }
      39             : 
      40             : typedef ::cppu::WeakImplHelper2< container::XIndexAccess, container::XEnumerationAccess > TabStopCollectionHelper_Base;
      41             : 
      42           0 : class TabStopsEnumWrapper : public EnumerationHelper_BASE
      43             : {
      44             :     uno::Reference< container::XIndexAccess > mxIndexAccess;
      45             :     sal_Int32 nIndex;
      46             : 
      47             : public:
      48           0 :     TabStopsEnumWrapper( const uno::Reference< container::XIndexAccess >& xIndexAccess ) : mxIndexAccess( xIndexAccess ), nIndex( 0 )
      49             :     {
      50           0 :     }
      51           0 :     virtual ::sal_Bool SAL_CALL hasMoreElements(  ) throw (uno::RuntimeException)
      52             :     {
      53           0 :         return ( nIndex < mxIndexAccess->getCount() );
      54             :     }
      55             : 
      56           0 :     virtual uno::Any SAL_CALL nextElement(  ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
      57             :     {
      58           0 :         if( nIndex < mxIndexAccess->getCount() )
      59             :         {
      60           0 :             return mxIndexAccess->getByIndex( nIndex++ );
      61             :         }
      62           0 :         throw container::NoSuchElementException();
      63             :     }
      64             : };
      65             : 
      66             : class TabStopCollectionHelper : public TabStopCollectionHelper_Base
      67             : {
      68             : private:
      69             :     uno::Reference< XHelperInterface > mxParent;
      70             :     uno::Reference< uno::XComponentContext > mxContext;
      71             :     uno::Reference< beans::XPropertySet > mxParaProps;
      72             :     uno::Sequence< style::TabStop > maTabStops;
      73             : 
      74             : public:
      75           0 :     TabStopCollectionHelper( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::beans::XPropertySet >& xParaProps ) throw ( css::uno::RuntimeException ): mxParent( xParent ), mxContext( xContext ), mxParaProps( xParaProps )
      76             :     {
      77           0 :         maTabStops = lcl_getTabStops( xParaProps );
      78           0 :     }
      79             : 
      80           0 :     virtual ~TabStopCollectionHelper() {}
      81             : 
      82           0 :     virtual sal_Int32 SAL_CALL getCount(  ) throw (uno::RuntimeException)
      83             :     {
      84           0 :         return maTabStops.getLength();
      85             :     }
      86           0 :     virtual uno::Any SAL_CALL getByIndex( sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
      87             :     {
      88           0 :         if ( Index < 0 || Index >= getCount() )
      89           0 :             throw css::lang::IndexOutOfBoundsException();
      90             : 
      91           0 :         const style::TabStop* pTabs = maTabStops.getConstArray();
      92           0 :         return uno::makeAny( uno::Reference< word::XTabStop >( new SwVbaTabStop( mxParent, mxContext, mxParaProps, pTabs[ Index ] ) ) );
      93             :     }
      94           0 :     virtual uno::Type SAL_CALL getElementType(  ) throw (uno::RuntimeException)
      95             :     {
      96           0 :         return word::XTabStop::static_type(0);
      97             :     }
      98           0 :     virtual sal_Bool SAL_CALL hasElements(  ) throw (uno::RuntimeException)
      99             :     {
     100           0 :         return sal_True;
     101             :     }
     102             :     // XEnumerationAccess
     103           0 :     virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration(  ) throw (uno::RuntimeException)
     104             :     {
     105           0 :         return new TabStopsEnumWrapper( this );
     106             :     }
     107             : };
     108             : 
     109           0 : SwVbaTabStops::SwVbaTabStops( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< beans::XPropertySet >& xParaProps ) throw (uno::RuntimeException) : SwVbaTabStops_BASE( xParent, xContext, uno::Reference< container::XIndexAccess >( new TabStopCollectionHelper( xParent, xContext, xParaProps ) ) ), mxParaProps( xParaProps )
     110             : {
     111           0 : }
     112             : 
     113           0 : uno::Reference< word::XTabStop > SAL_CALL SwVbaTabStops::Add( float Position, const uno::Any& Alignment, const uno::Any& Leader ) throw (uno::RuntimeException)
     114             : {
     115           0 :     sal_Int32 nPosition = Millimeter::getInHundredthsOfOneMillimeter( Position );
     116             : 
     117           0 :     style::TabAlign nAlign = style::TabAlign_LEFT;
     118           0 :     if( Alignment.hasValue() )
     119             :     {
     120           0 :         sal_Int32 wdAlign = word::WdTabAlignment::wdAlignTabLeft;
     121           0 :         Alignment >>= wdAlign;
     122           0 :         switch( wdAlign )
     123             :         {
     124             :             case word::WdTabAlignment::wdAlignTabLeft:
     125             :             {
     126           0 :                 nAlign = style::TabAlign_LEFT;
     127           0 :                 break;
     128             :             }
     129             :             case word::WdTabAlignment::wdAlignTabRight:
     130             :             {
     131           0 :                 nAlign = style::TabAlign_RIGHT;
     132           0 :                 break;
     133             :             }
     134             :             case word::WdTabAlignment::wdAlignTabCenter:
     135             :             {
     136           0 :                 nAlign = style::TabAlign_CENTER;
     137           0 :                 break;
     138             :             }
     139             :             case word::WdTabAlignment::wdAlignTabDecimal:
     140             :             {
     141           0 :                 nAlign = style::TabAlign_DECIMAL;
     142           0 :                 break;
     143             :             }
     144             :             case word::WdTabAlignment::wdAlignTabBar:
     145             :             case word::WdTabAlignment::wdAlignTabList:
     146             :             {
     147           0 :                 DebugHelper::exception( SbERR_NOT_IMPLEMENTED, rtl::OUString() );
     148           0 :                 break;
     149             :             }
     150             :             default:
     151             :             {
     152             :                 //left
     153             :             }
     154             :         }
     155             :     }
     156             : 
     157           0 :     sal_Unicode cLeader = ' '; // default is space
     158           0 :     if( Leader.hasValue() )
     159             :     {
     160           0 :         sal_Int32 wdLeader = word::WdTabLeader::wdTabLeaderSpaces;
     161           0 :         Leader >>= wdLeader;
     162           0 :         switch( wdLeader )
     163             :         {
     164             :             case word::WdTabLeader::wdTabLeaderSpaces:
     165             :             {
     166           0 :                 cLeader = ' ';
     167           0 :                 break;
     168             :             }
     169             :             case word::WdTabLeader::wdTabLeaderMiddleDot:
     170             :             {
     171           0 :                 cLeader = 183; // U+00B7 MIDDLE DOT
     172           0 :                 break;
     173             :             }
     174             :             case word::WdTabLeader::wdTabLeaderDots:
     175             :             {
     176           0 :                 cLeader = '.';
     177           0 :                 break;
     178             :             }
     179             :             case word::WdTabLeader::wdTabLeaderDashes:
     180             :             case word::WdTabLeader::wdTabLeaderHeavy:
     181             :             case word::WdTabLeader::wdTabLeaderLines:
     182             :             {
     183           0 :                 cLeader = '_';
     184           0 :                 break;
     185             :             }
     186             :             default:
     187             :             {
     188             :                 //left
     189             :             }
     190             :         }
     191             :     }
     192             : 
     193           0 :     sal_Char cDecimal = '.'; // default value
     194             : 
     195           0 :     style::TabStop aTab;
     196           0 :     aTab.Position = nPosition;
     197           0 :     aTab.Alignment = nAlign;
     198           0 :     aTab.DecimalChar = cDecimal;
     199           0 :     aTab.FillChar = cLeader;
     200             : 
     201           0 :     uno::Sequence< style::TabStop > aOldTabs = lcl_getTabStops( mxParaProps );
     202           0 :     sal_Bool bOverWriter = sal_False;
     203             : 
     204           0 :     sal_Int32 nTabs = aOldTabs.getLength();
     205           0 :     uno::Sequence< style::TabStop > aNewTabs( nTabs + 1 );
     206             : 
     207           0 :     style::TabStop* pOldTab = aOldTabs.getArray();
     208           0 :     style::TabStop* pNewTab = aNewTabs.getArray();
     209           0 :     pNewTab[0] = aTab;
     210           0 :     for( sal_Int32 nIndex = 0; nIndex < nTabs && !bOverWriter; nIndex++ )
     211             :     {
     212           0 :         if( pOldTab[nIndex].Position == nPosition )
     213             :         {
     214           0 :             bOverWriter = sal_True;
     215           0 :             pOldTab[nIndex] = aTab;
     216           0 :             break;
     217             :         }
     218           0 :         pNewTab[ nIndex+1 ] = pOldTab[ nIndex ];
     219             :     }
     220           0 :     if( bOverWriter )
     221           0 :         lcl_setTabStops( mxParaProps, aOldTabs );
     222             :     else
     223           0 :         lcl_setTabStops( mxParaProps, aNewTabs );
     224             : 
     225           0 :     return uno::Reference< word::XTabStop >( new SwVbaTabStop( this, mxContext, mxParaProps, aTab ) );
     226             : }
     227             : 
     228           0 : void SAL_CALL SwVbaTabStops::ClearAll() throw (uno::RuntimeException)
     229             : {
     230           0 :     uno::Sequence< style::TabStop > aSeq;
     231           0 :     lcl_setTabStops( mxParaProps, aSeq );
     232           0 : }
     233             : 
     234             : // XEnumerationAccess
     235             : uno::Type
     236           0 : SwVbaTabStops::getElementType() throw (uno::RuntimeException)
     237             : {
     238           0 :     return word::XTabStop::static_type(0);
     239             : }
     240             : uno::Reference< container::XEnumeration >
     241           0 : SwVbaTabStops::createEnumeration() throw (uno::RuntimeException)
     242             : {
     243           0 :     return new TabStopsEnumWrapper( m_xIndexAccess );
     244             : }
     245             : 
     246             : uno::Any
     247           0 : SwVbaTabStops::createCollectionObject( const css::uno::Any& aSource )
     248             : {
     249           0 :     return aSource;
     250             : }
     251             : 
     252             : rtl::OUString
     253           0 : SwVbaTabStops::getServiceImplName()
     254             : {
     255           0 :     return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SwVbaTabStops"));
     256             : }
     257             : 
     258             : css::uno::Sequence<rtl::OUString>
     259           0 : SwVbaTabStops::getServiceNames()
     260             : {
     261           0 :     static uno::Sequence< rtl::OUString > sNames;
     262           0 :     if ( sNames.getLength() == 0 )
     263             :     {
     264           0 :         sNames.realloc( 1 );
     265           0 :         sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.TabStops") );
     266             :     }
     267           0 :     return sNames;
     268             : }
     269             : 
     270             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10