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

Generated by: LCOV version 1.10