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

Generated by: LCOV version 1.10