LCOV - code coverage report
Current view: top level - libreoffice/sw/source/ui/vba - vbarows.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 180 0.0 %
Date: 2012-12-27 Functions: 0 27 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 "vbarows.hxx"
      20             : #include "vbarow.hxx"
      21             : #include <com/sun/star/text/HoriOrientation.hpp>
      22             : #include <com/sun/star/table/XCellRange.hpp>
      23             : #include <ooo/vba/word/WdRowAlignment.hpp>
      24             : #include <ooo/vba/word/WdConstants.hpp>
      25             : #include <ooo/vba/word/WdRulerStyle.hpp>
      26             : #include "wordvbahelper.hxx"
      27             : #include "vbacolumns.hxx"
      28             : #include "vbatablehelper.hxx"
      29             : 
      30             : using namespace ::ooo::vba;
      31             : using namespace ::com::sun::star;
      32             : 
      33           0 : class RowsEnumWrapper : public EnumerationHelper_BASE
      34             : {
      35             :     uno::WeakReference< XHelperInterface > mxParent;
      36             :     uno::Reference< uno::XComponentContext > mxContext;
      37             :     uno::Reference< text::XTextTable > mxTextTable;
      38             :     uno::Reference< container::XIndexAccess > mxIndexAccess;
      39             :     sal_Int32 nIndex;
      40             : 
      41             : public:
      42           0 :     RowsEnumWrapper( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< text::XTextTable >& xTextTable ) : mxParent( xParent ), mxContext( xContext ), mxTextTable( xTextTable ), nIndex( 0 )
      43             :     {
      44           0 :         mxIndexAccess.set( mxTextTable->getRows(), uno::UNO_QUERY );
      45           0 :     }
      46           0 :     virtual ::sal_Bool SAL_CALL hasMoreElements(  ) throw (uno::RuntimeException)
      47             :     {
      48           0 :         return ( nIndex < mxIndexAccess->getCount() );
      49             :     }
      50             : 
      51           0 :     virtual uno::Any SAL_CALL nextElement(  ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
      52             :     {
      53           0 :         if( nIndex < mxIndexAccess->getCount() )
      54             :         {
      55           0 :             return uno::makeAny( uno::Reference< word::XRow > ( new SwVbaRow( mxParent, mxContext, mxTextTable, nIndex++ ) ) );
      56             :         }
      57           0 :         throw container::NoSuchElementException();
      58             :     }
      59             : };
      60             : 
      61           0 : SwVbaRows::SwVbaRows( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< text::XTextTable >& xTextTable, const uno::Reference< table::XTableRows >& xTableRows ) throw (uno::RuntimeException) : SwVbaRows_BASE( xParent, xContext, uno::Reference< container::XIndexAccess >( xTableRows, uno::UNO_QUERY_THROW ) ), mxTextTable( xTextTable ), mxTableRows( xTableRows )
      62             : {
      63           0 :     mnStartRowIndex = 0;
      64           0 :     mnEndRowIndex = m_xIndexAccess->getCount() - 1;
      65           0 : }
      66             : 
      67           0 : SwVbaRows::SwVbaRows( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< text::XTextTable >& xTextTable, const uno::Reference< table::XTableRows >& xTableRows, sal_Int32 nStarIndex, sal_Int32 nEndIndex ) throw (uno::RuntimeException) : SwVbaRows_BASE( xParent, xContext, uno::Reference< container::XIndexAccess >( xTableRows, uno::UNO_QUERY_THROW ) ), mxTextTable( xTextTable ), mxTableRows( xTableRows ), mnStartRowIndex( nStarIndex ), mnEndRowIndex( nEndIndex )
      68             : {
      69           0 :     if( mnEndRowIndex < mnStartRowIndex )
      70           0 :         throw uno::RuntimeException();
      71           0 : }
      72             : 
      73             : /**
      74             :  * get the alignment of the rows: SO format com.sun.star.text.HoriOrientation
      75             :  * is mapped to WdRowAlignment in Word
      76             :  * @return the alignment
      77             :  */
      78           0 : ::sal_Int32 SAL_CALL SwVbaRows::getAlignment() throw (uno::RuntimeException)
      79             : {
      80           0 :     sal_Int16 nAlignment = text::HoriOrientation::LEFT;
      81           0 :     uno::Reference< beans::XPropertySet > xTableProps( mxTextTable, uno::UNO_QUERY_THROW );
      82           0 :     xTableProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HoriOrient") ) ) >>= nAlignment;
      83           0 :     sal_Int32 nRet = 0;
      84           0 :     switch( nAlignment )
      85             :     {
      86             :         case text::HoriOrientation::CENTER:
      87             :         {
      88           0 :            nRet = word::WdRowAlignment::wdAlignRowCenter;
      89           0 :            break;
      90             :         }
      91             :         case text::HoriOrientation::RIGHT:
      92             :         {
      93           0 :             nRet = word::WdRowAlignment::wdAlignRowRight;
      94           0 :             break;
      95             :         }
      96             :         default:
      97             :         {
      98           0 :             nRet = word::WdRowAlignment::wdAlignRowLeft;
      99             :         }
     100             :     }
     101           0 :     return nRet;
     102             : }
     103             : 
     104           0 : void SAL_CALL SwVbaRows::setAlignment( ::sal_Int32 _alignment ) throw (uno::RuntimeException)
     105             : {
     106           0 :     sal_Int16 nAlignment = text::HoriOrientation::LEFT;
     107           0 :     switch( _alignment )
     108             :     {
     109             :         case word::WdRowAlignment::wdAlignRowCenter:
     110             :         {
     111           0 :             nAlignment = text::HoriOrientation::CENTER;
     112           0 :             break;
     113             :         }
     114             :         case word::WdRowAlignment::wdAlignRowRight:
     115             :         {
     116           0 :             nAlignment = text::HoriOrientation::RIGHT;
     117           0 :             break;
     118             :         }
     119             :         default:
     120             :         {
     121           0 :             nAlignment = text::HoriOrientation::LEFT;
     122             :         }
     123             :     }
     124           0 :     uno::Reference< beans::XPropertySet > xTableProps( mxTextTable, uno::UNO_QUERY_THROW );
     125           0 :     xTableProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HoriOrient") ), uno::makeAny( nAlignment ) );
     126           0 : }
     127             : 
     128           0 : uno::Any SAL_CALL SwVbaRows::getAllowBreakAcrossPages() throw (uno::RuntimeException)
     129             : {
     130           0 :     sal_Bool bAllowBreak = sal_False;
     131           0 :     uno::Reference< container::XIndexAccess > xRowsAccess( mxTableRows, uno::UNO_QUERY_THROW );
     132           0 :     for( sal_Int32 index = mnStartRowIndex; index <= mnEndRowIndex; ++index )
     133             :     {
     134           0 :         uno::Reference< beans::XPropertySet > xRowProps( xRowsAccess->getByIndex( index ), uno::UNO_QUERY_THROW );
     135           0 :         sal_Bool bSplit = sal_False;
     136           0 :         xRowProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("IsSplitAllowed") ) ) >>= bSplit;
     137           0 :         if( index == 0 )
     138             :         {
     139           0 :             bAllowBreak = bSplit;
     140             :         }
     141           0 :         if( bSplit != bAllowBreak )
     142             :         {
     143           0 :             sal_Int32 nRet = word::WdConstants::wdUndefined;
     144           0 :             return uno::makeAny( nRet );
     145             :         }
     146           0 :     }
     147           0 :     return uno::makeAny( bAllowBreak );
     148             : }
     149             : 
     150           0 : void SAL_CALL SwVbaRows::setAllowBreakAcrossPages( const uno::Any& _allowbreakacrosspages ) throw (uno::RuntimeException)
     151             : {
     152           0 :     sal_Bool bAllowBreak = sal_False;
     153           0 :     _allowbreakacrosspages >>= bAllowBreak;
     154           0 :     uno::Reference< container::XIndexAccess > xRowsAccess( mxTableRows, uno::UNO_QUERY_THROW );
     155           0 :     for( sal_Int32 index = mnStartRowIndex; index <= mnEndRowIndex; ++index )
     156             :     {
     157           0 :         uno::Reference< beans::XPropertySet > xRowProps( xRowsAccess->getByIndex( index ), uno::UNO_QUERY_THROW );
     158           0 :         xRowProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("IsSplitAllowed") ), uno::makeAny( bAllowBreak ) );
     159           0 :     }
     160           0 : }
     161             : 
     162           0 : float SAL_CALL SwVbaRows::getSpaceBetweenColumns() throw (uno::RuntimeException)
     163             : {
     164             :     // just get the first spacing of the first cell
     165           0 :     uno::Reference< table::XCellRange > xCellRange( mxTextTable, uno::UNO_QUERY_THROW );
     166           0 :     uno::Reference< beans::XPropertySet > xCellProps( xCellRange->getCellByPosition( 0, mnStartRowIndex ), uno::UNO_QUERY_THROW );
     167           0 :     sal_Int32 nLeftBorderDistance = 0;
     168           0 :     sal_Int32 nRightBorderDistance = 0;
     169           0 :     xCellProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("LeftBorderDistance") ) ) >>= nLeftBorderDistance;
     170           0 :     xCellProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightBorderDistance") ) ) >>= nRightBorderDistance;
     171           0 :     return static_cast< float >( Millimeter::getInPoints( nLeftBorderDistance + nRightBorderDistance ) );
     172             : }
     173             : 
     174           0 : void SAL_CALL SwVbaRows::setSpaceBetweenColumns( float _spacebetweencolumns ) throw (uno::RuntimeException)
     175             : {
     176           0 :     sal_Int32 nSpace = Millimeter::getInHundredthsOfOneMillimeter( _spacebetweencolumns ) / 2;
     177           0 :     uno::Reference< container::XIndexAccess > xColumnAccess( mxTextTable->getColumns(), uno::UNO_QUERY_THROW );
     178           0 :     uno::Reference< table::XCellRange > xCellRange( mxTextTable, uno::UNO_QUERY_THROW );
     179           0 :     SwVbaTableHelper aTableHelper( mxTextTable );
     180           0 :     for( sal_Int32 row = mnStartRowIndex; row <= mnEndRowIndex; ++row )
     181             :     {
     182           0 :         sal_Int32 nColumns = aTableHelper.getTabColumnsCount( row );
     183           0 :         for( sal_Int32 column = 0; column < nColumns; ++column )
     184             :         {
     185           0 :             uno::Reference< beans::XPropertySet > xCellProps( xCellRange->getCellByPosition( column, row ), uno::UNO_QUERY_THROW );
     186           0 :             xCellProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("LeftBorderDistance") ), uno::makeAny( nSpace ) );
     187           0 :             xCellProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightBorderDistance") ), uno::makeAny( nSpace ) );
     188           0 :         }
     189           0 :     }
     190           0 : }
     191             : 
     192           0 : void SAL_CALL SwVbaRows::Delete(  ) throw (uno::RuntimeException)
     193             : {
     194           0 :     mxTableRows->removeByIndex( mnStartRowIndex, getCount() );
     195           0 : }
     196             : 
     197           0 : void SAL_CALL SwVbaRows::SetLeftIndent( float LeftIndent, ::sal_Int32 RulerStyle ) throw (uno::RuntimeException)
     198             : {
     199           0 :     uno::Reference< word::XColumns > xColumns( new SwVbaColumns( getParent(), mxContext, mxTextTable, mxTextTable->getColumns() ) );
     200           0 :     sal_Int32 nIndent = (sal_Int32)( LeftIndent );
     201           0 :     switch( RulerStyle )
     202             :     {
     203             :         case word::WdRulerStyle::wdAdjustFirstColumn:
     204             :         {
     205           0 :             setIndentWithAdjustFirstColumn( xColumns, nIndent );
     206           0 :             break;
     207             :         }
     208             :         case word::WdRulerStyle::wdAdjustNone:
     209             :         {
     210           0 :             setIndentWithAdjustNone( nIndent );
     211           0 :             break;
     212             :         }
     213             :         case word::WdRulerStyle::wdAdjustProportional:
     214             :         {
     215           0 :             setIndentWithAdjustProportional( xColumns, nIndent );
     216           0 :             break;
     217             :         }
     218             :         case word::WdRulerStyle::wdAdjustSameWidth:
     219             :         {
     220           0 :             setIndentWithAdjustSameWidth( xColumns, nIndent );
     221           0 :             break;
     222             :         }
     223             :         default:
     224             :         {
     225           0 :             DebugHelper::exception(SbERR_BAD_ARGUMENT, rtl::OUString());
     226             :         }
     227           0 :     }
     228           0 : }
     229             : 
     230           0 : void SwVbaRows::setIndentWithAdjustNone( sal_Int32 indent ) throw (uno::RuntimeException)
     231             : {
     232           0 :     uno::Reference< beans::XPropertySet > xTableProps( mxTextTable, uno::UNO_QUERY_THROW );
     233           0 :     sal_Int32 nMargin = 0;
     234           0 :     xTableProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("LeftMargin") ) ) >>= nMargin;
     235           0 :     nMargin += indent;
     236           0 :     xTableProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("LeftMargin") ), uno::makeAny( nMargin ) );
     237           0 : }
     238             : 
     239           0 :  void SwVbaRows::setIndentWithAdjustFirstColumn( const uno::Reference< word::XColumns >& xColumns, sal_Int32 indent ) throw (uno::RuntimeException)
     240             :  {
     241           0 :     sal_Int32 nIndex = 1;
     242           0 :     uno::Reference< XCollection > xCol( xColumns, uno::UNO_QUERY_THROW );
     243           0 :     uno::Reference< word::XColumn > xColumn( xCol->Item( uno::makeAny( nIndex ), uno::Any() ), uno::UNO_QUERY_THROW );
     244           0 :     sal_Int32 nWidth = xColumn->getWidth();
     245           0 :     nWidth -= indent;
     246           0 :     xColumn->setWidth( nWidth );
     247           0 :     setIndentWithAdjustNone( indent );
     248           0 :  }
     249             : 
     250           0 :  void SwVbaRows::setIndentWithAdjustProportional(
     251             :     const uno::Reference< word::XColumns >& xColumns,
     252             :     sal_Int32 indent
     253             : ) throw (uno::RuntimeException)
     254             :  {
     255             :     // calculate the new width and get the proportion between old and new
     256           0 :     uno::Reference< beans::XPropertySet > xTableProps( mxTextTable, uno::UNO_QUERY_THROW );
     257           0 :     sal_Int32 nWidth = 0;
     258           0 :     xTableProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Width") ) ) >>= nWidth;
     259           0 :     sal_Int32 nNewWidth = nWidth - indent;
     260           0 :     if ((nNewWidth <= 0) || (nWidth <= 0))
     261             :     {
     262             :         throw uno::RuntimeException(
     263             :             ::rtl::OUString(
     264             :                 RTL_CONSTASCII_USTRINGPARAM(
     265             :                     "Pb with width, in SwVbaRows::setIndentWithAdjustProportional (nNewWidth <= 0) || (nWidth <= 0)"
     266             :                 )
     267             :             ),
     268             :             uno::Reference< uno::XInterface >()
     269           0 :         );
     270             :     }
     271           0 :     double propFactor = (double)nNewWidth/(double)nWidth;
     272             : 
     273             :     // get all columns, calculate and set the new width of the columns
     274           0 :     uno::Reference< XCollection > xCol( xColumns, uno::UNO_QUERY_THROW );
     275           0 :     sal_Int32 nColCount = xCol->getCount();
     276           0 :     for( sal_Int32 i = 0; i < nColCount; i++ )
     277             :     {
     278           0 :         uno::Reference< word::XColumn > xColumn( xCol->Item( uno::makeAny( i ), uno::Any() ), uno::UNO_QUERY_THROW );
     279           0 :         sal_Int32 nColWidth = xColumn->getWidth();
     280           0 :         sal_Int32 nNewColWidth = ( sal_Int32 )( propFactor * nColWidth );
     281           0 :         xColumn->setWidth( nNewColWidth );
     282           0 :     }
     283             : 
     284             :     // set the width and position of the table
     285           0 :     setIndentWithAdjustNone( indent );
     286           0 :     xTableProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Width") ), uno::makeAny( nNewWidth ) );
     287           0 :  }
     288             : 
     289           0 :  void SwVbaRows::setIndentWithAdjustSameWidth( const uno::Reference< word::XColumns >& xColumns, sal_Int32 indent ) throw (uno::RuntimeException)
     290             :  {
     291             :     // calculate the new width and get the width of all columns
     292           0 :     uno::Reference< beans::XPropertySet > xTableProps( mxTextTable, uno::UNO_QUERY_THROW );
     293           0 :     sal_Int32 nWidth = 0;
     294           0 :     xTableProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Width") ) ) >>= nWidth;
     295           0 :     sal_Int32 nNewWidth = nWidth - indent;
     296             : 
     297             :     // get all columns, calculate and set the new width of the columns
     298           0 :     uno::Reference< XCollection > xCol( xColumns, uno::UNO_QUERY_THROW );
     299           0 :     sal_Int32 nColCount = xCol->getCount();
     300           0 :     sal_Int32 nNewColWidth = (sal_Int32)( double( nNewWidth )/nColCount );
     301           0 :     for( sal_Int32 i = 0; i < nColCount; i++ )
     302             :     {
     303           0 :         uno::Reference< word::XColumn > xColumn( xCol->Item( uno::makeAny( i ), uno::Any() ), uno::UNO_QUERY_THROW );
     304           0 :         xColumn->setWidth( nNewColWidth );
     305           0 :     }
     306             : 
     307             :     // set the width and position of the table
     308           0 :     setIndentWithAdjustNone( indent );
     309           0 :     xTableProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Width") ), uno::makeAny( nNewWidth ) );
     310           0 :  }
     311             : 
     312           0 : void SAL_CALL SwVbaRows::Select(  ) throw (uno::RuntimeException)
     313             : {
     314           0 :     SwVbaRow::SelectRow( getCurrentWordDoc(mxContext), mxTextTable, mnStartRowIndex, mnEndRowIndex );
     315           0 : }
     316             : 
     317           0 : ::sal_Int32 SAL_CALL SwVbaRows::getCount() throw (uno::RuntimeException)
     318             : {
     319           0 :     return ( mnEndRowIndex - mnStartRowIndex + 1 );
     320             : }
     321             : 
     322           0 : uno::Any SAL_CALL SwVbaRows::Item( const uno::Any& Index1, const uno::Any& /*not processed in this base class*/ ) throw (uno::RuntimeException)
     323             : {
     324           0 :     sal_Int32 nIndex = 0;
     325           0 :     if( ( Index1 >>= nIndex ) == sal_True )
     326             :     {
     327           0 :         if( nIndex <= 0 || nIndex > getCount() )
     328             :         {
     329           0 :             throw  lang::IndexOutOfBoundsException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Index out of bounds") ), uno::Reference< uno::XInterface >() );
     330             :         }
     331           0 :         return uno::makeAny( uno::Reference< word::XRow >( new SwVbaRow( this, mxContext, mxTextTable, nIndex - 1 ) ) );
     332             :     }
     333           0 :     throw  uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Index out of bounds") ), uno::Reference< uno::XInterface >() );
     334             : }
     335             : 
     336             : // XEnumerationAccess
     337             : uno::Type
     338           0 : SwVbaRows::getElementType() throw (uno::RuntimeException)
     339             : {
     340           0 :     return word::XRow::static_type(0);
     341             : }
     342             : uno::Reference< container::XEnumeration >
     343           0 : SwVbaRows::createEnumeration() throw (uno::RuntimeException)
     344             : {
     345           0 :     return new RowsEnumWrapper( this, mxContext, mxTextTable );
     346             : }
     347             : 
     348             : uno::Any
     349           0 : SwVbaRows::createCollectionObject( const uno::Any& aSource )
     350             : {
     351           0 :     return aSource;
     352             : }
     353             : 
     354             : rtl::OUString
     355           0 : SwVbaRows::getServiceImplName()
     356             : {
     357           0 :     return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SwVbaRows"));
     358             : }
     359             : 
     360             : uno::Sequence<rtl::OUString>
     361           0 : SwVbaRows::getServiceNames()
     362             : {
     363           0 :     static uno::Sequence< rtl::OUString > sNames;
     364           0 :     if ( sNames.getLength() == 0 )
     365             :     {
     366           0 :         sNames.realloc( 1 );
     367           0 :         sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Rows") );
     368             :     }
     369           0 :     return sNames;
     370             : }
     371             : 
     372             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10