LCOV - code coverage report
Current view: top level - svx/source/table - tablerow.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 95 165 57.6 %
Date: 2015-06-13 12:38:46 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         131 : 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         131 : , mbIsStartOfNewPage( false )
      54             : {
      55         131 :     if( nColumns < 20 )
      56         131 :         maCells.reserve( 20 );
      57             : 
      58         131 :     if( nColumns )
      59             :     {
      60         131 :         maCells.resize( nColumns );
      61         428 :         while( nColumns-- )
      62         166 :             maCells[ nColumns ] = mxTableModel->createCell();
      63             :     }
      64         131 : }
      65             : 
      66             : 
      67             : 
      68         254 : TableRow::~TableRow()
      69             : {
      70         254 : }
      71             : 
      72             : 
      73             : 
      74         127 : void TableRow::dispose()
      75             : {
      76         127 :     mxTableModel.clear();
      77         127 :     if( !maCells.empty() )
      78             :     {
      79         127 :         CellVector::iterator aIter( maCells.begin() );
      80         759 :         while( aIter != maCells.end() )
      81         505 :             (*aIter++)->dispose();
      82         127 :         CellVector().swap(maCells);
      83             :     }
      84         127 : }
      85             : 
      86             : 
      87             : 
      88          92 : void TableRow::throwIfDisposed() const throw (::com::sun::star::uno::RuntimeException)
      89             : {
      90          92 :     if( !mxTableModel.is() )
      91           0 :         throw DisposedException();
      92          92 : }
      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          92 : void TableRow::insertColumns( sal_Int32 nIndex, sal_Int32 nCount, CellVector::iterator* pIter /* = 0 */  )
     111             : {
     112          92 :     throwIfDisposed();
     113          92 :     if( nCount )
     114             :     {
     115          92 :         if( nIndex >= static_cast< sal_Int32 >( maCells.size() ) )
     116           8 :             nIndex = static_cast< sal_Int32 >( maCells.size() );
     117          92 :         if ( pIter )
     118           0 :             maCells.insert( maCells.begin() + nIndex, *pIter, (*pIter) + nCount );
     119             :         else
     120             :         {
     121          92 :             maCells.reserve( maCells.size() + nCount );
     122         436 :             for ( sal_Int32 i = 0; i < nCount; i++ )
     123         344 :                 maCells.insert( maCells.begin() + nIndex + i, mxTableModel->createCell() );
     124             :         }
     125             :     }
     126          92 : }
     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         335 : 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         335 :     bool bOk = false;
     216         335 :     bool bChange = false;
     217             : 
     218         335 :     TableRowUndo* pUndo = 0;
     219             : 
     220         335 :     SdrModel* pModel = mxTableModel->getSdrTableObj()->GetModel();
     221             : 
     222         335 :     const bool bUndo = mxTableModel.is() && mxTableModel->getSdrTableObj() && mxTableModel->getSdrTableObj()->IsInserted() && pModel && pModel->IsUndoEnabled();
     223             : 
     224         335 :     if( bUndo )
     225             :     {
     226          78 :         TableRowRef xThis( this );
     227          78 :         pUndo = new TableRowUndo( xThis );
     228             :     }
     229             : 
     230         335 :     switch( nHandle )
     231             :     {
     232             :     case Property_Height:
     233             :         {
     234         335 :             sal_Int32 nHeight = mnHeight;
     235         335 :             bOk = aValue >>= nHeight;
     236         335 :             if( bOk && (mnHeight != nHeight) )
     237             :             {
     238         144 :                 mnHeight = nHeight;
     239         144 :                 mbOptimalHeight = mnHeight == 0;
     240         144 :                 bChange = true;
     241             :             }
     242         335 :             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         335 :     if( !bOk )
     286             :     {
     287           0 :         delete pUndo;
     288           0 :         throw IllegalArgumentException();
     289             :     }
     290             : 
     291         335 :     if( bChange )
     292             :     {
     293         144 :         if( pUndo )
     294             :         {
     295          40 :             pModel->AddUndo( pUndo );
     296          40 :             pUndo = 0;
     297             :         }
     298         144 :         mxTableModel->setModified(sal_True);
     299             :     }
     300             : 
     301         335 :     delete pUndo;
     302         335 : }
     303             : 
     304             : 
     305             : 
     306        1825 : Any SAL_CALL TableRow::getFastPropertyValue( sal_Int32 nHandle ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
     307             : {
     308        1825 :     switch( nHandle )
     309             :     {
     310         807 :     case Property_Height:           return Any( mnHeight );
     311        1018 :     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         131 : rtl::Reference< FastPropertySetInfo > TableRow::getStaticPropertySetInfo()
     321             : {
     322         131 :     static rtl::Reference< FastPropertySetInfo > xInfo;
     323         131 :     if( !xInfo.is() )
     324             :     {
     325           5 :         ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
     326           5 :         if( !xInfo.is() )
     327             :         {
     328           5 :             PropertyVector aProperties(6);
     329             : 
     330           5 :             aProperties[0].Name = "Height";
     331           5 :             aProperties[0].Handle = Property_Height;
     332           5 :             aProperties[0].Type = ::cppu::UnoType<sal_Int32>::get();
     333           5 :             aProperties[0].Attributes = 0;
     334             : 
     335           5 :             aProperties[1].Name = "OptimalHeight";
     336           5 :             aProperties[1].Handle = Property_OptimalHeight;
     337           5 :             aProperties[1].Type = cppu::UnoType<bool>::get();
     338           5 :             aProperties[1].Attributes = 0;
     339             : 
     340           5 :             aProperties[2].Name = "IsVisible";
     341           5 :             aProperties[2].Handle = Property_IsVisible;
     342           5 :             aProperties[2].Type = cppu::UnoType<bool>::get();
     343           5 :             aProperties[2].Attributes = 0;
     344             : 
     345           5 :             aProperties[3].Name = "IsStartOfNewPage";
     346           5 :             aProperties[3].Handle = Property_IsStartOfNewPage;
     347           5 :             aProperties[3].Type = cppu::UnoType<bool>::get();
     348           5 :             aProperties[3].Attributes = 0;
     349             : 
     350           5 :             aProperties[4].Name = "Size";
     351           5 :             aProperties[4].Handle = Property_Height;
     352           5 :             aProperties[4].Type = ::cppu::UnoType<sal_Int32>::get();
     353           5 :             aProperties[4].Attributes = 0;
     354             : 
     355           5 :             aProperties[5].Name = "OptimalSize";
     356           5 :             aProperties[5].Handle = Property_OptimalHeight;
     357           5 :             aProperties[5].Type = cppu::UnoType<bool>::get();
     358           5 :             aProperties[5].Attributes = 0;
     359             : 
     360           5 :             xInfo.set( new FastPropertySetInfo(aProperties) );
     361           5 :         }
     362             :     }
     363             : 
     364         131 :     return xInfo;
     365             : }
     366             : 
     367             : 
     368             : 
     369             : 
     370         435 : } }
     371             : 
     372             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11