LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/svx/source/table - tablecolumn.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 73 124 58.9 %
Date: 2013-07-09 Functions: 9 16 56.2 %
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 "tablecolumn.hxx"
      24             : #include "tableundo.hxx"
      25             : #include "svx/svdmodel.hxx"
      26             : #include "svx/svdotable.hxx"
      27             : 
      28             : // -----------------------------------------------------------------------------
      29             : 
      30             : using namespace ::com::sun::star::uno;
      31             : using namespace ::com::sun::star::lang;
      32             : using namespace ::com::sun::star::container;
      33             : using namespace ::com::sun::star::table;
      34             : using namespace ::com::sun::star::beans;
      35             : 
      36             : // -----------------------------------------------------------------------------
      37             : 
      38             : namespace sdr { namespace table {
      39             : 
      40             : const sal_Int32 Property_Width = 0;
      41             : const sal_Int32 Property_OptimalWidth = 1;
      42             : const sal_Int32 Property_IsVisible = 2;
      43             : const sal_Int32 Property_IsStartOfNewPage = 3;
      44             : 
      45             : // -----------------------------------------------------------------------------
      46             : // TableRow
      47             : // -----------------------------------------------------------------------------
      48             : 
      49         183 : TableColumn::TableColumn( const TableModelRef& xTableModel, sal_Int32 nColumn )
      50             : : TableColumnBase( getStaticPropertySetInfo() )
      51             : , mxTableModel( xTableModel )
      52             : , mnColumn( nColumn )
      53             : , mnWidth( 0 )
      54             : , mbOptimalWidth( sal_True )
      55             : , mbIsVisible( sal_True )
      56         183 : , mbIsStartOfNewPage( sal_False )
      57             : {
      58         183 : }
      59             : 
      60             : // -----------------------------------------------------------------------------
      61             : 
      62         366 : TableColumn::~TableColumn()
      63             : {
      64         366 : }
      65             : 
      66             : // -----------------------------------------------------------------------------
      67             : 
      68         183 : void TableColumn::dispose()
      69             : {
      70         183 :     mxTableModel.clear();
      71         183 : }
      72             : 
      73             : // -----------------------------------------------------------------------------
      74             : 
      75           0 : void TableColumn::throwIfDisposed() const throw (::com::sun::star::uno::RuntimeException)
      76             : {
      77           0 :     if( !mxTableModel.is() )
      78           0 :         throw DisposedException();
      79           0 : }
      80             : 
      81             : // -----------------------------------------------------------------------------
      82             : 
      83           0 : TableColumn& TableColumn::operator=( const TableColumn& r )
      84             : {
      85           0 :     mnWidth = r.mnWidth;
      86           0 :     mbOptimalWidth = r.mbOptimalWidth;
      87           0 :     mbIsVisible = r.mbIsVisible;
      88           0 :     mbIsStartOfNewPage = r.mbIsStartOfNewPage;
      89           0 :     maName = r.maName;
      90           0 :     mnColumn = r.mnColumn;
      91             : 
      92           0 :     return *this;
      93             : }
      94             : 
      95             : // -----------------------------------------------------------------------------
      96             : // XCellRange
      97             : // -----------------------------------------------------------------------------
      98             : 
      99           0 : Reference< XCell > SAL_CALL TableColumn::getCellByPosition( sal_Int32 nColumn, sal_Int32 nRow ) throw (IndexOutOfBoundsException, RuntimeException)
     100             : {
     101           0 :     throwIfDisposed();
     102           0 :     if( nColumn != 0 )
     103           0 :         throw IndexOutOfBoundsException();
     104             : 
     105           0 :     return mxTableModel->getCellByPosition( mnColumn, nRow );
     106             : }
     107             : 
     108             : // -----------------------------------------------------------------------------
     109             : 
     110           0 : Reference< XCellRange > SAL_CALL TableColumn::getCellRangeByPosition( sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom ) throw (IndexOutOfBoundsException, RuntimeException)
     111             : {
     112           0 :     throwIfDisposed();
     113           0 :     if( (nTop >= 0 ) && (nLeft == 0) && (nBottom >= nTop) && (nRight == 0)  )
     114             :     {
     115           0 :         return mxTableModel->getCellRangeByPosition( mnColumn, nTop, mnColumn, nBottom );
     116             :     }
     117           0 :     throw IndexOutOfBoundsException();
     118             : }
     119             : 
     120             : // -----------------------------------------------------------------------------
     121             : 
     122           0 : Reference< XCellRange > SAL_CALL TableColumn::getCellRangeByName( const OUString& /*aRange*/ ) throw (RuntimeException)
     123             : {
     124           0 :     return Reference< XCellRange >();
     125             : }
     126             : 
     127             : // -----------------------------------------------------------------------------
     128             : // XNamed
     129             : // -----------------------------------------------------------------------------
     130             : 
     131           0 : OUString SAL_CALL TableColumn::getName() throw (RuntimeException)
     132             : {
     133           0 :     return maName;
     134             : }
     135             : 
     136             : // -----------------------------------------------------------------------------
     137             : 
     138           0 : void SAL_CALL TableColumn::setName( const OUString& aName ) throw (RuntimeException)
     139             : {
     140           0 :     maName = aName;
     141           0 : }
     142             : 
     143             : // -----------------------------------------------------------------------------
     144             : // XFastPropertySet
     145             : // -----------------------------------------------------------------------------
     146             : 
     147         405 : void SAL_CALL TableColumn::setFastPropertyValue( sal_Int32 nHandle, const Any& aValue ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, RuntimeException)
     148             : {
     149         405 :     bool bOk = false;
     150         405 :     bool bChange = false;
     151             : 
     152         405 :     SdrModel* pModel = mxTableModel->getSdrTableObj()->GetModel();
     153             : 
     154         405 :     TableColumnUndo* pUndo = 0;
     155         405 :     if( mxTableModel.is() && mxTableModel->getSdrTableObj() && mxTableModel->getSdrTableObj()->IsInserted() && pModel && pModel->IsUndoEnabled() )
     156             :     {
     157           0 :         TableColumnRef xThis( this );
     158           0 :         pUndo = new TableColumnUndo( xThis );
     159             :     }
     160             : 
     161         405 :     switch( nHandle )
     162             :     {
     163             :     case Property_Width:
     164             :         {
     165         397 :             sal_Int32 nWidth = mnWidth;
     166         397 :             bOk = aValue >>= nWidth;
     167         397 :             if( bOk && (nWidth != mnWidth) )
     168             :             {
     169         218 :                 mnWidth = nWidth;
     170         218 :                 mbOptimalWidth = mnWidth == 0;
     171         218 :                 bChange = true;
     172             :             }
     173         397 :             break;
     174             :         }
     175             :     case Property_OptimalWidth:
     176             :         {
     177           8 :             sal_Bool bOptimalWidth = mbOptimalWidth;
     178           8 :             bOk = aValue >>= bOptimalWidth;
     179           8 :             if( bOk && (mbOptimalWidth != bOptimalWidth) )
     180             :             {
     181           6 :                 mbOptimalWidth = bOptimalWidth;
     182           6 :                 if( bOptimalWidth )
     183           0 :                     mnWidth = 0;
     184           6 :                 bChange = true;
     185             :             }
     186           8 :             break;
     187             :         }
     188             :     case Property_IsVisible:
     189             :         {
     190           0 :             sal_Bool bIsVisible = mbIsVisible;
     191           0 :             bOk = aValue >>= bIsVisible;
     192           0 :             if( bOk && (mbIsVisible != bIsVisible) )
     193             :             {
     194           0 :                 mbIsVisible = bIsVisible;
     195           0 :                 bChange = true;
     196             :             }
     197           0 :             break;
     198             :         }
     199             : 
     200             :     case Property_IsStartOfNewPage:
     201             :         {
     202           0 :             sal_Bool bIsStartOfNewPage = mbIsStartOfNewPage;
     203           0 :             bOk = aValue >>= bIsStartOfNewPage;
     204           0 :             if( bOk && (mbIsStartOfNewPage != bIsStartOfNewPage) )
     205             :             {
     206           0 :                 mbIsStartOfNewPage = bIsStartOfNewPage;
     207           0 :                 bChange = true;
     208             :             }
     209           0 :             break;
     210             :         }
     211             :     default:
     212           0 :         throw UnknownPropertyException();
     213             :     }
     214         405 :     if( !bOk )
     215           0 :         throw IllegalArgumentException();
     216             : 
     217         405 :     if( bChange )
     218             :     {
     219         224 :         if( pUndo )
     220             :         {
     221           0 :             pModel->AddUndo( pUndo );
     222           0 :             pUndo = 0;
     223             :         }
     224         224 :         mxTableModel->setModified(sal_True);
     225             :     }
     226             : 
     227         405 :     delete pUndo;
     228         405 : }
     229             : 
     230             : // -----------------------------------------------------------------------------
     231             : 
     232       54279 : Any SAL_CALL TableColumn::getFastPropertyValue( sal_Int32 nHandle ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
     233             : {
     234       54279 :     switch( nHandle )
     235             :     {
     236       27122 :     case Property_Width:            return Any( mnWidth );
     237       27157 :     case Property_OptimalWidth:     return Any( mbOptimalWidth );
     238           0 :     case Property_IsVisible:        return Any( mbIsVisible );
     239           0 :     case Property_IsStartOfNewPage: return Any( mbIsStartOfNewPage );
     240           0 :     default:                        throw UnknownPropertyException();
     241             :     }
     242             : }
     243             : 
     244             : // -----------------------------------------------------------------------------
     245             : 
     246         183 : rtl::Reference< FastPropertySetInfo > TableColumn::getStaticPropertySetInfo()
     247             : {
     248         183 :     static rtl::Reference< FastPropertySetInfo > xInfo;
     249         183 :     if( !xInfo.is() )
     250             :     {
     251           2 :         ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
     252           2 :         if( !xInfo.is() )
     253             :         {
     254           2 :             PropertyVector aProperties(6);
     255             : 
     256           2 :             aProperties[0].Name = OUString( "Width" );
     257           2 :             aProperties[0].Handle = Property_Width;
     258           2 :             aProperties[0].Type = ::getCppuType((const sal_Int32*)0);
     259           2 :             aProperties[0].Attributes = 0;
     260             : 
     261           2 :             aProperties[1].Name = OUString( "OptimalWidth" );
     262           2 :             aProperties[1].Handle = Property_OptimalWidth;
     263           2 :             aProperties[1].Type = ::getBooleanCppuType();
     264           2 :             aProperties[1].Attributes = 0;
     265             : 
     266           2 :             aProperties[2].Name = OUString( "IsVisible" );
     267           2 :             aProperties[2].Handle = Property_IsVisible;
     268           2 :             aProperties[2].Type = ::getBooleanCppuType();
     269           2 :             aProperties[2].Attributes = 0;
     270             : 
     271           2 :             aProperties[3].Name = OUString( "IsStartOfNewPage" );
     272           2 :             aProperties[3].Handle = Property_IsStartOfNewPage;
     273           2 :             aProperties[3].Type = ::getBooleanCppuType();
     274           2 :             aProperties[3].Attributes = 0;
     275             : 
     276           2 :             aProperties[4].Name = OUString( "Size" );
     277           2 :             aProperties[4].Handle = Property_Width;
     278           2 :             aProperties[4].Type = ::getCppuType((const sal_Int32*)0);
     279           2 :             aProperties[4].Attributes = 0;
     280             : 
     281           2 :             aProperties[5].Name = OUString( "OptimalSize" );
     282           2 :             aProperties[5].Handle = Property_OptimalWidth;
     283           2 :             aProperties[5].Type = ::getBooleanCppuType();
     284           2 :             aProperties[5].Attributes = 0;
     285             : 
     286           2 :             xInfo.set( new FastPropertySetInfo(aProperties) );
     287           2 :         }
     288             :     }
     289             : 
     290         183 :     return xInfo;
     291             : }
     292             : 
     293             : // -----------------------------------------------------------------------------
     294             : 
     295         258 : } }
     296             : 
     297             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10