LCOV - code coverage report
Current view: top level - svx/source/table - tablerow.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 95 165 57.6 %
Date: 2014-11-03 Functions: 11 18 61.1 %
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             : 
      20             : 
      21             : #include <com/sun/star/lang/DisposedException.hpp>
      22             : 
      23             : #include "cell.hxx"
      24             : #include "tablerow.hxx"
      25             : #include "tableundo.hxx"
      26             : #include "svx/svdmodel.hxx"
      27             : #include "svx/svdotable.hxx"
      28             : 
      29             : 
      30             : 
      31             : using namespace ::com::sun::star::uno;
      32             : using namespace ::com::sun::star::lang;
      33             : using namespace ::com::sun::star::container;
      34             : using namespace ::com::sun::star::table;
      35             : using namespace ::com::sun::star::beans;
      36             : 
      37             : 
      38             : 
      39             : namespace sdr { namespace table {
      40             : 
      41             : const sal_Int32 Property_Height = 0;
      42             : const sal_Int32 Property_OptimalHeight = 1;
      43             : const sal_Int32 Property_IsVisible = 2;
      44             : const sal_Int32 Property_IsStartOfNewPage = 3;
      45             : 
      46         210 : TableRow::TableRow( const TableModelRef& xTableModel, sal_Int32 nRow, sal_Int32 nColumns )
      47             : : TableRowBase( getStaticPropertySetInfo() )
      48             : , mxTableModel( xTableModel )
      49             : , mnRow( nRow )
      50             : , mnHeight( 0 )
      51             : , mbOptimalHeight( true )
      52             : , mbIsVisible( true )
      53         210 : , mbIsStartOfNewPage( false )
      54             : {
      55         210 :     if( nColumns < 20 )
      56         210 :         maCells.reserve( 20 );
      57             : 
      58         210 :     if( nColumns )
      59             :     {
      60         210 :         maCells.resize( nColumns );
      61         682 :         while( nColumns-- )
      62         262 :             maCells[ nColumns ] = mxTableModel->createCell();
      63             :     }
      64         210 : }
      65             : 
      66             : 
      67             : 
      68         420 : TableRow::~TableRow()
      69             : {
      70         420 : }
      71             : 
      72             : 
      73             : 
      74         210 : void TableRow::dispose()
      75             : {
      76         210 :     mxTableModel.clear();
      77         210 :     if( !maCells.empty() )
      78             :     {
      79         210 :         CellVector::iterator aIter( maCells.begin() );
      80        1342 :         while( aIter != maCells.end() )
      81         922 :             (*aIter++)->dispose();
      82         210 :         CellVector().swap(maCells);
      83             :     }
      84         210 : }
      85             : 
      86             : 
      87             : 
      88         156 : void TableRow::throwIfDisposed() const throw (::com::sun::star::uno::RuntimeException)
      89             : {
      90         156 :     if( !mxTableModel.is() )
      91           0 :         throw DisposedException();
      92         156 : }
      93             : 
      94             : 
      95             : 
      96           0 : TableRow& TableRow::operator=( const TableRow& r )
      97             : {
      98           0 :     mnHeight = r.mnHeight;
      99           0 :     mbOptimalHeight = r.mbOptimalHeight;
     100           0 :     mbIsVisible = r.mbIsVisible;
     101           0 :     mbIsStartOfNewPage = r.mbIsStartOfNewPage;
     102           0 :     maName = r.maName;
     103           0 :     mnRow = r.mnRow;
     104             : 
     105           0 :     return *this;
     106             : }
     107             : 
     108             : 
     109             : 
     110         156 : void TableRow::insertColumns( sal_Int32 nIndex, sal_Int32 nCount, CellVector::iterator* pIter /* = 0 */  )
     111             : {
     112         156 :     throwIfDisposed();
     113         156 :     if( nCount )
     114             :     {
     115         156 :         if( nIndex >= static_cast< sal_Int32 >( maCells.size() ) )
     116           4 :             nIndex = static_cast< sal_Int32 >( maCells.size() );
     117         156 :         if ( pIter )
     118           0 :             maCells.insert( maCells.begin() + nIndex, *pIter, (*pIter) + nCount );
     119             :         else
     120             :         {
     121         156 :             maCells.reserve( maCells.size() + nCount );
     122         816 :             for ( sal_Int32 i = 0; i < nCount; i++ )
     123         660 :                 maCells.insert( maCells.begin() + nIndex + i, mxTableModel->createCell() );
     124             :         }
     125             :     }
     126         156 : }
     127             : 
     128             : 
     129             : 
     130           0 : void TableRow::removeColumns( sal_Int32 nIndex, sal_Int32 nCount )
     131             : {
     132           0 :     throwIfDisposed();
     133           0 :     if( (nCount >= 0) && ( nIndex >= 0) )
     134             :     {
     135           0 :         if( (nIndex + nCount) < static_cast< sal_Int32 >( maCells.size() ) )
     136             :         {
     137           0 :             CellVector::iterator aBegin( maCells.begin() );
     138           0 :             while( nIndex-- && (aBegin != maCells.end()) )
     139           0 :                 ++aBegin;
     140             : 
     141           0 :             if( nCount > 1 )
     142             :             {
     143           0 :                 CellVector::iterator aEnd( aBegin );
     144           0 :                 while( nCount-- && (aEnd != maCells.end()) )
     145           0 :                     ++aEnd;
     146           0 :                 maCells.erase( aBegin, aEnd );
     147             :             }
     148             :             else
     149             :             {
     150           0 :                 maCells.erase( aBegin );
     151             :             }
     152             :         }
     153             :         else
     154             :         {
     155           0 :             maCells.resize( nIndex );
     156             :         }
     157             :     }
     158           0 : }
     159             : 
     160             : 
     161             : // XCellRange
     162             : 
     163             : 
     164           0 : Reference< XCell > SAL_CALL TableRow::getCellByPosition( sal_Int32 nColumn, sal_Int32 nRow ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     165             : {
     166           0 :     throwIfDisposed();
     167           0 :     if( nRow != 0 )
     168           0 :         throw IndexOutOfBoundsException();
     169             : 
     170           0 :     return mxTableModel->getCellByPosition( nColumn, mnRow );
     171             : }
     172             : 
     173             : 
     174             : 
     175           0 : Reference< XCellRange > SAL_CALL TableRow::getCellRangeByPosition( sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     176             : {
     177           0 :     throwIfDisposed();
     178           0 :     if( (nLeft >= 0 ) && (nTop == 0) && (nRight >= nLeft) && (nBottom == 0)  )
     179             :     {
     180           0 :         return mxTableModel->getCellRangeByPosition( nLeft, mnRow, nRight, mnRow );
     181             :     }
     182           0 :     throw IndexOutOfBoundsException();
     183             : }
     184             : 
     185             : 
     186             : 
     187           0 : Reference< XCellRange > SAL_CALL TableRow::getCellRangeByName( const OUString& /*aRange*/ ) throw (RuntimeException, std::exception)
     188             : {
     189           0 :     throwIfDisposed();
     190           0 :     return Reference< XCellRange >();
     191             : }
     192             : 
     193             : 
     194             : // XNamed
     195             : 
     196             : 
     197           0 : OUString SAL_CALL TableRow::getName() throw (RuntimeException, std::exception)
     198             : {
     199           0 :     return maName;
     200             : }
     201             : 
     202             : 
     203             : 
     204           0 : void SAL_CALL TableRow::setName( const OUString& aName ) throw (RuntimeException, std::exception)
     205             : {
     206           0 :     maName = aName;
     207           0 : }
     208             : 
     209             : 
     210             : // XFastPropertySet
     211             : 
     212             : 
     213         492 : void SAL_CALL TableRow::setFastPropertyValue( sal_Int32 nHandle, const Any& aValue ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, RuntimeException, std::exception)
     214             : {
     215         492 :     bool bOk = false;
     216         492 :     bool bChange = false;
     217             : 
     218         492 :     TableRowUndo* pUndo = 0;
     219             : 
     220         492 :     SdrModel* pModel = mxTableModel->getSdrTableObj()->GetModel();
     221             : 
     222         492 :     const bool bUndo = mxTableModel.is() && mxTableModel->getSdrTableObj() && mxTableModel->getSdrTableObj()->IsInserted() && pModel && pModel->IsUndoEnabled();
     223             : 
     224         492 :     if( bUndo )
     225             :     {
     226          74 :         TableRowRef xThis( this );
     227          74 :         pUndo = new TableRowUndo( xThis );
     228             :     }
     229             : 
     230         492 :     switch( nHandle )
     231             :     {
     232             :     case Property_Height:
     233             :         {
     234         492 :             sal_Int32 nHeight = mnHeight;
     235         492 :             bOk = aValue >>= nHeight;
     236         492 :             if( bOk && (mnHeight != nHeight) )
     237             :             {
     238         334 :                 mnHeight = nHeight;
     239         334 :                 mbOptimalHeight = mnHeight == 0;
     240         334 :                 bChange = true;
     241             :             }
     242         492 :             break;
     243             :         }
     244             : 
     245             :     case Property_OptimalHeight:
     246             :         {
     247           0 :             bool bOptimalHeight = mbOptimalHeight;
     248           0 :             bOk = aValue >>= bOptimalHeight;
     249           0 :             if( bOk && (mbOptimalHeight != bOptimalHeight) )
     250             :             {
     251           0 :                 mbOptimalHeight = bOptimalHeight;
     252           0 :                 if( bOptimalHeight )
     253           0 :                     mnHeight = 0;
     254           0 :                 bChange = true;
     255             :             }
     256           0 :             break;
     257             :         }
     258             :     case Property_IsVisible:
     259             :         {
     260           0 :             bool bIsVisible = mbIsVisible;
     261           0 :             bOk = aValue >>= bIsVisible;
     262           0 :             if( bOk && (mbIsVisible != bIsVisible) )
     263             :             {
     264           0 :                 mbIsVisible = bIsVisible;
     265           0 :                 bChange = true;
     266             :             }
     267           0 :             break;
     268             :         }
     269             : 
     270             :     case Property_IsStartOfNewPage:
     271             :         {
     272           0 :             bool bIsStartOfNewPage = mbIsStartOfNewPage;
     273           0 :             bOk = aValue >>= bIsStartOfNewPage;
     274           0 :             if( bOk && (mbIsStartOfNewPage != bIsStartOfNewPage) )
     275             :             {
     276           0 :                 mbIsStartOfNewPage = bIsStartOfNewPage;
     277           0 :                 bChange = true;
     278             :             }
     279           0 :             break;
     280             :         }
     281             :     default:
     282           0 :         delete pUndo;
     283           0 :         throw UnknownPropertyException();
     284             :     }
     285         492 :     if( !bOk )
     286             :     {
     287           0 :         delete pUndo;
     288           0 :         throw IllegalArgumentException();
     289             :     }
     290             : 
     291         492 :     if( bChange )
     292             :     {
     293         334 :         if( pUndo )
     294             :         {
     295          74 :             pModel->AddUndo( pUndo );
     296          74 :             pUndo = 0;
     297             :         }
     298         334 :         mxTableModel->setModified(sal_True);
     299             :     }
     300             : 
     301         492 :     delete pUndo;
     302         492 : }
     303             : 
     304             : 
     305             : 
     306        2894 : Any SAL_CALL TableRow::getFastPropertyValue( sal_Int32 nHandle ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
     307             : {
     308        2894 :     switch( nHandle )
     309             :     {
     310        1408 :     case Property_Height:           return Any( mnHeight );
     311        1486 :     case Property_OptimalHeight:    return Any( mbOptimalHeight );
     312           0 :     case Property_IsVisible:        return Any( mbIsVisible );
     313           0 :     case Property_IsStartOfNewPage: return Any( mbIsStartOfNewPage );
     314           0 :     default:                        throw UnknownPropertyException();
     315             :     }
     316             : }
     317             : 
     318             : 
     319             : 
     320         210 : rtl::Reference< FastPropertySetInfo > TableRow::getStaticPropertySetInfo()
     321             : {
     322         210 :     static rtl::Reference< FastPropertySetInfo > xInfo;
     323         210 :     if( !xInfo.is() )
     324             :     {
     325           6 :         ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
     326           6 :         if( !xInfo.is() )
     327             :         {
     328           6 :             PropertyVector aProperties(6);
     329             : 
     330           6 :             aProperties[0].Name = "Height";
     331           6 :             aProperties[0].Handle = Property_Height;
     332           6 :             aProperties[0].Type = ::cppu::UnoType<sal_Int32>::get();
     333           6 :             aProperties[0].Attributes = 0;
     334             : 
     335           6 :             aProperties[1].Name = "OptimalHeight";
     336           6 :             aProperties[1].Handle = Property_OptimalHeight;
     337           6 :             aProperties[1].Type = ::getBooleanCppuType();
     338           6 :             aProperties[1].Attributes = 0;
     339             : 
     340           6 :             aProperties[2].Name = "IsVisible";
     341           6 :             aProperties[2].Handle = Property_IsVisible;
     342           6 :             aProperties[2].Type = ::getBooleanCppuType();
     343           6 :             aProperties[2].Attributes = 0;
     344             : 
     345           6 :             aProperties[3].Name = "IsStartOfNewPage";
     346           6 :             aProperties[3].Handle = Property_IsStartOfNewPage;
     347           6 :             aProperties[3].Type = ::getBooleanCppuType();
     348           6 :             aProperties[3].Attributes = 0;
     349             : 
     350           6 :             aProperties[4].Name = "Size";
     351           6 :             aProperties[4].Handle = Property_Height;
     352           6 :             aProperties[4].Type = ::cppu::UnoType<sal_Int32>::get();
     353           6 :             aProperties[4].Attributes = 0;
     354             : 
     355           6 :             aProperties[5].Name = "OptimalSize";
     356           6 :             aProperties[5].Handle = Property_OptimalHeight;
     357           6 :             aProperties[5].Type = ::getBooleanCppuType();
     358           6 :             aProperties[5].Attributes = 0;
     359             : 
     360           6 :             xInfo.set( new FastPropertySetInfo(aProperties) );
     361           6 :         }
     362             :     }
     363             : 
     364         210 :     return xInfo;
     365             : }
     366             : 
     367             : 
     368             : 
     369             : 
     370         651 : } }
     371             : 
     372             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10