LCOV - code coverage report
Current view: top level - svx/source/table - tablerow.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 90 159 56.6 %
Date: 2012-08-25 Functions: 9 16 56.2 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 68 212 32.1 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include <com/sun/star/lang/DisposedException.hpp>
      31                 :            : 
      32                 :            : #include "cell.hxx"
      33                 :            : #include "tablerow.hxx"
      34                 :            : #include "tableundo.hxx"
      35                 :            : #include "svx/svdmodel.hxx"
      36                 :            : #include "svx/svdotable.hxx"
      37                 :            : 
      38                 :            : // -----------------------------------------------------------------------------
      39                 :            : 
      40                 :            : using ::rtl::OUString;
      41                 :            : using namespace ::com::sun::star::uno;
      42                 :            : using namespace ::com::sun::star::lang;
      43                 :            : using namespace ::com::sun::star::container;
      44                 :            : using namespace ::com::sun::star::table;
      45                 :            : using namespace ::com::sun::star::beans;
      46                 :            : 
      47                 :            : // -----------------------------------------------------------------------------
      48                 :            : 
      49                 :            : namespace sdr { namespace table {
      50                 :            : 
      51                 :            : const sal_Int32 Property_Height = 0;
      52                 :            : const sal_Int32 Property_OptimalHeight = 1;
      53                 :            : const sal_Int32 Property_IsVisible = 2;
      54                 :            : const sal_Int32 Property_IsStartOfNewPage = 3;
      55                 :            : 
      56                 :            : // -----------------------------------------------------------------------------
      57                 :            : // TableRow
      58                 :            : // -----------------------------------------------------------------------------
      59                 :            : 
      60                 :         30 : TableRow::TableRow( const TableModelRef& xTableModel, sal_Int32 nRow, sal_Int32 nColumns )
      61                 :            : : TableRowBase( getStaticPropertySetInfo() )
      62                 :            : , mxTableModel( xTableModel )
      63                 :            : , mnRow( nRow )
      64                 :            : , mnHeight( 0 )
      65                 :            : , mbOptimalHeight( sal_True )
      66                 :            : , mbIsVisible( sal_True )
      67 [ +  - ][ +  - ]:         30 : , mbIsStartOfNewPage( sal_False )
      68                 :            : {
      69         [ +  - ]:         30 :     if( nColumns < 20 )
      70         [ +  - ]:         30 :         maCells.reserve( 20 );
      71                 :            : 
      72         [ +  - ]:         30 :     if( nColumns )
      73                 :            :     {
      74         [ +  - ]:         30 :         maCells.resize( nColumns );
      75         [ +  + ]:         60 :         while( nColumns-- )
      76 [ +  - ][ +  - ]:         30 :             maCells[ nColumns ] = mxTableModel->createCell();
      77                 :            :     }
      78                 :         30 : }
      79                 :            : 
      80                 :            : // -----------------------------------------------------------------------------
      81                 :            : 
      82                 :         30 : TableRow::~TableRow()
      83                 :            : {
      84         [ -  + ]:         60 : }
      85                 :            : 
      86                 :            : // -----------------------------------------------------------------------------
      87                 :            : 
      88                 :         30 : void TableRow::dispose()
      89                 :            : {
      90                 :         30 :     mxTableModel.clear();
      91         [ +  - ]:         30 :     if( !maCells.empty() )
      92                 :            :     {
      93                 :         30 :         CellVector::iterator aIter( maCells.begin() );
      94 [ +  - ][ +  + ]:         78 :         while( aIter != maCells.end() )
      95 [ +  - ][ +  - ]:         48 :             (*aIter++)->dispose();
      96         [ +  - ]:         30 :         CellVector().swap(maCells);
      97                 :            :     }
      98                 :         30 : }
      99                 :            : 
     100                 :            : // -----------------------------------------------------------------------------
     101                 :            : 
     102                 :          3 : void TableRow::throwIfDisposed() const throw (::com::sun::star::uno::RuntimeException)
     103                 :            : {
     104         [ -  + ]:          3 :     if( !mxTableModel.is() )
     105         [ #  # ]:          0 :         throw DisposedException();
     106                 :          3 : }
     107                 :            : 
     108                 :            : // -----------------------------------------------------------------------------
     109                 :            : 
     110                 :          0 : TableRow& TableRow::operator=( const TableRow& r )
     111                 :            : {
     112                 :          0 :     mnHeight = r.mnHeight;
     113                 :          0 :     mbOptimalHeight = r.mbOptimalHeight;
     114                 :          0 :     mbIsVisible = r.mbIsVisible;
     115                 :          0 :     mbIsStartOfNewPage = r.mbIsStartOfNewPage;
     116                 :          0 :     maName = r.maName;
     117                 :          0 :     mnRow = r.mnRow;
     118                 :            : 
     119                 :          0 :     return *this;
     120                 :            : }
     121                 :            : 
     122                 :            : // -----------------------------------------------------------------------------
     123                 :            : 
     124                 :          3 : void TableRow::insertColumns( sal_Int32 nIndex, sal_Int32 nCount, CellVector::iterator* pIter /* = 0 */  )
     125                 :            : {
     126                 :          3 :     throwIfDisposed();
     127         [ +  - ]:          3 :     if( nCount )
     128                 :            :     {
     129         [ +  - ]:          3 :         if( nIndex >= static_cast< sal_Int32 >( maCells.size() ) )
     130                 :          3 :             nIndex = static_cast< sal_Int32 >( maCells.size() );
     131         [ -  + ]:          3 :         if ( pIter )
     132 [ #  # ][ #  # ]:          0 :             maCells.insert( maCells.begin() + nIndex, *pIter, (*pIter) + nCount );
                 [ #  # ]
     133                 :            :         else
     134                 :            :         {
     135                 :          3 :             maCells.reserve( maCells.size() + nCount );
     136         [ +  + ]:         21 :             for ( sal_Int32 i = 0; i < nCount; i++ )
     137 [ +  - ][ +  - ]:         18 :                 maCells.insert( maCells.begin() + nIndex + i, mxTableModel->createCell() );
                 [ +  - ]
     138                 :            :         }
     139                 :            :     }
     140                 :          3 : }
     141                 :            : 
     142                 :            : // -----------------------------------------------------------------------------
     143                 :            : 
     144                 :          0 : void TableRow::removeColumns( sal_Int32 nIndex, sal_Int32 nCount )
     145                 :            : {
     146                 :          0 :     throwIfDisposed();
     147 [ #  # ][ #  # ]:          0 :     if( (nCount >= 0) && ( nIndex >= 0) )
     148                 :            :     {
     149         [ #  # ]:          0 :         if( (nIndex + nCount) < static_cast< sal_Int32 >( maCells.size() ) )
     150                 :            :         {
     151                 :          0 :             CellVector::iterator aBegin( maCells.begin() );
     152 [ #  # ][ #  # ]:          0 :             while( nIndex-- && (aBegin != maCells.end()) )
         [ #  # ][ #  # ]
           [ #  #  #  # ]
     153         [ #  # ]:          0 :                 aBegin++;
     154                 :            : 
     155         [ #  # ]:          0 :             if( nCount > 1 )
     156                 :            :             {
     157                 :          0 :                 CellVector::iterator aEnd( aBegin );
     158 [ #  # ][ #  # ]:          0 :                 while( nCount-- && (aEnd != maCells.end()) )
         [ #  # ][ #  # ]
           [ #  #  #  # ]
     159         [ #  # ]:          0 :                     aEnd++;
     160         [ #  # ]:          0 :                 maCells.erase( aBegin, aEnd );
     161                 :            :             }
     162                 :            :             else
     163                 :            :             {
     164         [ #  # ]:          0 :                 maCells.erase( aBegin );
     165                 :            :             }
     166                 :            :         }
     167                 :            :         else
     168                 :            :         {
     169                 :          0 :             maCells.resize( nIndex );
     170                 :            :         }
     171                 :            :     }
     172                 :          0 : }
     173                 :            : 
     174                 :            : // -----------------------------------------------------------------------------
     175                 :            : // XCellRange
     176                 :            : // -----------------------------------------------------------------------------
     177                 :            : 
     178                 :          0 : Reference< XCell > SAL_CALL TableRow::getCellByPosition( sal_Int32 nColumn, sal_Int32 nRow ) throw (IndexOutOfBoundsException, RuntimeException)
     179                 :            : {
     180                 :          0 :     throwIfDisposed();
     181         [ #  # ]:          0 :     if( nRow != 0 )
     182         [ #  # ]:          0 :         throw IndexOutOfBoundsException();
     183                 :            : 
     184                 :          0 :     return mxTableModel->getCellByPosition( nColumn, mnRow );
     185                 :            : }
     186                 :            : 
     187                 :            : // -----------------------------------------------------------------------------
     188                 :            : 
     189                 :          0 : Reference< XCellRange > SAL_CALL TableRow::getCellRangeByPosition( sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom ) throw (IndexOutOfBoundsException, RuntimeException)
     190                 :            : {
     191                 :          0 :     throwIfDisposed();
     192 [ #  # ][ #  # ]:          0 :     if( (nLeft >= 0 ) && (nTop == 0) && (nRight >= nLeft) && (nBottom == 0)  )
         [ #  # ][ #  # ]
     193                 :            :     {
     194                 :          0 :         return mxTableModel->getCellRangeByPosition( nLeft, mnRow, nRight, mnRow );
     195                 :            :     }
     196         [ #  # ]:          0 :     throw IndexOutOfBoundsException();
     197                 :            : }
     198                 :            : 
     199                 :            : // -----------------------------------------------------------------------------
     200                 :            : 
     201                 :          0 : Reference< XCellRange > SAL_CALL TableRow::getCellRangeByName( const OUString& /*aRange*/ ) throw (RuntimeException)
     202                 :            : {
     203                 :          0 :     throwIfDisposed();
     204                 :          0 :     return Reference< XCellRange >();
     205                 :            : }
     206                 :            : 
     207                 :            : // -----------------------------------------------------------------------------
     208                 :            : // XNamed
     209                 :            : // -----------------------------------------------------------------------------
     210                 :            : 
     211                 :          0 : OUString SAL_CALL TableRow::getName() throw (RuntimeException)
     212                 :            : {
     213                 :          0 :     return maName;
     214                 :            : }
     215                 :            : 
     216                 :            : // -----------------------------------------------------------------------------
     217                 :            : 
     218                 :          0 : void SAL_CALL TableRow::setName( const OUString& aName ) throw (RuntimeException)
     219                 :            : {
     220                 :          0 :     maName = aName;
     221                 :          0 : }
     222                 :            : 
     223                 :            : // -----------------------------------------------------------------------------
     224                 :            : // XFastPropertySet
     225                 :            : // -----------------------------------------------------------------------------
     226                 :            : 
     227                 :         48 : void SAL_CALL TableRow::setFastPropertyValue( sal_Int32 nHandle, const Any& aValue ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, RuntimeException)
     228                 :            : {
     229                 :         48 :     bool bOk = false;
     230                 :         48 :     bool bChange = false;
     231                 :            : 
     232                 :         48 :     TableRowUndo* pUndo = 0;
     233                 :            : 
     234                 :         48 :     SdrModel* pModel = mxTableModel->getSdrTableObj()->GetModel();
     235                 :            : 
     236 [ +  - ][ +  + ]:         48 :     const bool bUndo = mxTableModel.is() && mxTableModel->getSdrTableObj() && mxTableModel->getSdrTableObj()->IsInserted() && pModel && pModel->IsUndoEnabled();
         [ +  - ][ -  + ]
                 [ +  - ]
     237                 :            : 
     238         [ -  + ]:         48 :     if( bUndo )
     239                 :            :     {
     240                 :          0 :         TableRowRef xThis( this );
     241 [ #  # ][ #  # ]:          0 :         pUndo = new TableRowUndo( xThis );
     242                 :            :     }
     243                 :            : 
     244   [ +  -  -  -  :         48 :     switch( nHandle )
                      - ]
     245                 :            :     {
     246                 :            :     case Property_Height:
     247                 :            :         {
     248                 :         48 :             sal_Int32 nHeight = mnHeight;
     249                 :         48 :             bOk = aValue >>= nHeight;
     250 [ +  + ][ +  - ]:         48 :             if( bOk && (mnHeight != nHeight) )
     251                 :            :             {
     252                 :         42 :                 mnHeight = nHeight;
     253                 :         42 :                 mbOptimalHeight = mnHeight == 0;
     254                 :         48 :                 bChange = true;
     255                 :            :             }
     256                 :            :             break;
     257                 :            :         }
     258                 :            : 
     259                 :            :     case Property_OptimalHeight:
     260                 :            :         {
     261                 :          0 :             sal_Bool bOptimalHeight = mbOptimalHeight;
     262                 :          0 :             bOk = aValue >>= bOptimalHeight;
     263 [ #  # ][ #  # ]:          0 :             if( bOk && (mbOptimalHeight != bOptimalHeight) )
     264                 :            :             {
     265                 :          0 :                 mbOptimalHeight = bOptimalHeight;
     266         [ #  # ]:          0 :                 if( bOptimalHeight )
     267                 :          0 :                     mnHeight = 0;
     268                 :          0 :                 bChange = true;
     269                 :            :             }
     270                 :            :             break;
     271                 :            :         }
     272                 :            :     case Property_IsVisible:
     273                 :            :         {
     274                 :          0 :             sal_Bool bIsVisible = mbIsVisible;
     275                 :          0 :             bOk = aValue >>= bIsVisible;
     276 [ #  # ][ #  # ]:          0 :             if( bOk && (mbIsVisible != bIsVisible) )
     277                 :            :             {
     278                 :          0 :                 mbIsVisible = bIsVisible;
     279                 :          0 :                 bChange = true;
     280                 :            :             }
     281                 :            :             break;
     282                 :            :         }
     283                 :            : 
     284                 :            :     case Property_IsStartOfNewPage:
     285                 :            :         {
     286                 :          0 :             sal_Bool bIsStartOfNewPage = mbIsStartOfNewPage;
     287                 :          0 :             bOk = aValue >>= bIsStartOfNewPage;
     288 [ #  # ][ #  # ]:          0 :             if( bOk && (mbIsStartOfNewPage != bIsStartOfNewPage) )
     289                 :            :             {
     290                 :          0 :                 mbIsStartOfNewPage = bIsStartOfNewPage;
     291                 :          0 :                 bChange = true;
     292                 :            :             }
     293                 :            :             break;
     294                 :            :         }
     295                 :            :     default:
     296         [ #  # ]:          0 :         throw UnknownPropertyException();
     297                 :            :     }
     298         [ -  + ]:         48 :     if( !bOk )
     299         [ #  # ]:          0 :         throw IllegalArgumentException();
     300                 :            : 
     301         [ +  + ]:         48 :     if( bChange )
     302                 :            :     {
     303         [ -  + ]:         42 :         if( pUndo )
     304                 :            :         {
     305                 :          0 :             pModel->AddUndo( pUndo );
     306                 :          0 :             pUndo = 0;
     307                 :            :         }
     308                 :         42 :         mxTableModel->setModified(sal_True);
     309                 :            :     }
     310                 :            : 
     311         [ -  + ]:         48 :     if( pUndo )
     312         [ #  # ]:          0 :         delete pUndo;
     313                 :         48 : }
     314                 :            : 
     315                 :            : // -----------------------------------------------------------------------------
     316                 :            : 
     317                 :        318 : Any SAL_CALL TableRow::getFastPropertyValue( sal_Int32 nHandle ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
     318                 :            : {
     319   [ +  +  -  -  :        318 :     switch( nHandle )
                      - ]
     320                 :            :     {
     321                 :        156 :     case Property_Height:           return Any( mnHeight );
     322                 :        162 :     case Property_OptimalHeight:    return Any( mbOptimalHeight );
     323                 :          0 :     case Property_IsVisible:        return Any( mbIsVisible );
     324                 :          0 :     case Property_IsStartOfNewPage: return Any( mbIsStartOfNewPage );
     325         [ #  # ]:        318 :     default:                        throw UnknownPropertyException();
     326                 :            :     }
     327                 :            : }
     328                 :            : 
     329                 :            : // -----------------------------------------------------------------------------
     330                 :            : 
     331                 :         30 : rtl::Reference< ::comphelper::FastPropertySetInfo > TableRow::getStaticPropertySetInfo()
     332                 :            : {
     333 [ +  + ][ +  - ]:         30 :     static rtl::Reference< ::comphelper::FastPropertySetInfo > xInfo;
     334         [ +  + ]:         30 :     if( !xInfo.is() )
     335                 :            :     {
     336 [ +  - ][ +  - ]:          3 :         ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
     337         [ +  - ]:          3 :         if( !xInfo.is() )
     338                 :            :         {
     339         [ +  - ]:          3 :             comphelper::PropertyVector aProperties(6);
     340                 :            : 
     341         [ +  - ]:          3 :             aProperties[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "Height" ) );
     342                 :          3 :             aProperties[0].Handle = Property_Height;
     343         [ +  - ]:          3 :             aProperties[0].Type = ::getCppuType((const sal_Int32*)0);
     344                 :          3 :             aProperties[0].Attributes = 0;
     345                 :            : 
     346         [ +  - ]:          3 :             aProperties[1].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "OptimalHeight" ) );
     347                 :          3 :             aProperties[1].Handle = Property_OptimalHeight;
     348         [ +  - ]:          3 :             aProperties[1].Type = ::getBooleanCppuType();
     349                 :          3 :             aProperties[1].Attributes = 0;
     350                 :            : 
     351         [ +  - ]:          3 :             aProperties[2].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "IsVisible" ) );
     352                 :          3 :             aProperties[2].Handle = Property_IsVisible;
     353         [ +  - ]:          3 :             aProperties[2].Type = ::getBooleanCppuType();
     354                 :          3 :             aProperties[2].Attributes = 0;
     355                 :            : 
     356         [ +  - ]:          3 :             aProperties[3].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "IsStartOfNewPage" ) );
     357                 :          3 :             aProperties[3].Handle = Property_IsStartOfNewPage;
     358         [ +  - ]:          3 :             aProperties[3].Type = ::getBooleanCppuType();
     359                 :          3 :             aProperties[3].Attributes = 0;
     360                 :            : 
     361         [ +  - ]:          3 :             aProperties[4].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "Size" ) );
     362                 :          3 :             aProperties[4].Handle = Property_Height;
     363         [ +  - ]:          3 :             aProperties[4].Type = ::getCppuType((const sal_Int32*)0);
     364                 :          3 :             aProperties[4].Attributes = 0;
     365                 :            : 
     366         [ +  - ]:          3 :             aProperties[5].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "OptimalSize" ) );
     367                 :          3 :             aProperties[5].Handle = Property_OptimalHeight;
     368         [ +  - ]:          3 :             aProperties[5].Type = ::getBooleanCppuType();
     369                 :          3 :             aProperties[5].Attributes = 0;
     370                 :            : 
     371         [ +  - ]:          3 :             xInfo.set( new ::comphelper::FastPropertySetInfo(aProperties) );
     372         [ +  - ]:          3 :         }
     373                 :            :     }
     374                 :            : 
     375                 :         30 :     return xInfo;
     376                 :            : }
     377                 :            : 
     378                 :            : // -----------------------------------------------------------------------------
     379                 :            : 
     380                 :            : 
     381                 :            : } }
     382                 :            : 
     383                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10