LCOV - code coverage report
Current view: top level - svx/source/table - tablecolumn.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 77 126 61.1 %
Date: 2015-06-13 12:38:46 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         222 : TableColumn::TableColumn( const TableModelRef& xTableModel, sal_Int32 nColumn )
      50             : : TableColumnBase( getStaticPropertySetInfo() )
      51             : , mxTableModel( xTableModel )
      52             : , mnColumn( nColumn )
      53             : , mnWidth( 0 )
      54             : , mbOptimalWidth( true )
      55             : , mbIsVisible( true )
      56         222 : , mbIsStartOfNewPage( false )
      57             : {
      58         222 : }
      59             : 
      60             : 
      61             : 
      62         438 : TableColumn::~TableColumn()
      63             : {
      64         438 : }
      65             : 
      66             : 
      67             : 
      68         219 : void TableColumn::dispose()
      69             : {
      70         219 :     mxTableModel.clear();
      71         219 : }
      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, std::exception)
     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, std::exception)
     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, std::exception)
     123             : {
     124           0 :     return Reference< XCellRange >();
     125             : }
     126             : 
     127             : 
     128             : // XNamed
     129             : 
     130             : 
     131           0 : OUString SAL_CALL TableColumn::getName() throw (RuntimeException, std::exception)
     132             : {
     133           0 :     return maName;
     134             : }
     135             : 
     136             : 
     137             : 
     138           0 : void SAL_CALL TableColumn::setName( const OUString& aName ) throw (RuntimeException, std::exception)
     139             : {
     140           0 :     maName = aName;
     141           0 : }
     142             : 
     143             : 
     144             : // XFastPropertySet
     145             : 
     146             : 
     147         524 : void SAL_CALL TableColumn::setFastPropertyValue( sal_Int32 nHandle, const Any& aValue ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, RuntimeException, std::exception)
     148             : {
     149         524 :     bool bOk = false;
     150         524 :     bool bChange = false;
     151             : 
     152         524 :     SdrModel* pModel = mxTableModel->getSdrTableObj()->GetModel();
     153             : 
     154         524 :     TableColumnUndo* pUndo = 0;
     155         524 :     if( mxTableModel.is() && mxTableModel->getSdrTableObj() && mxTableModel->getSdrTableObj()->IsInserted() && pModel && pModel->IsUndoEnabled() )
     156             :     {
     157          66 :         TableColumnRef xThis( this );
     158          66 :         pUndo = new TableColumnUndo( xThis );
     159             :     }
     160             : 
     161         524 :     switch( nHandle )
     162             :     {
     163             :     case Property_Width:
     164             :         {
     165         510 :             sal_Int32 nWidth = mnWidth;
     166         510 :             bOk = aValue >>= nWidth;
     167         510 :             if( bOk && (nWidth != mnWidth) )
     168             :             {
     169         280 :                 mnWidth = nWidth;
     170         280 :                 mbOptimalWidth = mnWidth == 0;
     171         280 :                 bChange = true;
     172             :             }
     173         510 :             break;
     174             :         }
     175             :     case Property_OptimalWidth:
     176             :         {
     177          14 :             bool bOptimalWidth = mbOptimalWidth;
     178          14 :             bOk = aValue >>= bOptimalWidth;
     179          14 :             if( bOk && (mbOptimalWidth != bOptimalWidth) )
     180             :             {
     181           9 :                 mbOptimalWidth = bOptimalWidth;
     182           9 :                 if( bOptimalWidth )
     183           0 :                     mnWidth = 0;
     184           9 :                 bChange = true;
     185             :             }
     186          14 :             break;
     187             :         }
     188             :     case Property_IsVisible:
     189             :         {
     190           0 :             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 :             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 :         delete pUndo;
     213           0 :         throw UnknownPropertyException();
     214             :     }
     215         524 :     if( !bOk )
     216             :     {
     217           0 :         delete pUndo;
     218           0 :         throw IllegalArgumentException();
     219             :     }
     220             : 
     221         524 :     if( bChange )
     222             :     {
     223         289 :         if( pUndo )
     224             :         {
     225          36 :             pModel->AddUndo( pUndo );
     226          36 :             pUndo = 0;
     227             :         }
     228         289 :         mxTableModel->setModified(sal_True);
     229             :     }
     230             : 
     231         524 :     delete pUndo;
     232         524 : }
     233             : 
     234             : 
     235             : 
     236        2748 : Any SAL_CALL TableColumn::getFastPropertyValue( sal_Int32 nHandle ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
     237             : {
     238        2748 :     switch( nHandle )
     239             :     {
     240        1345 :     case Property_Width:            return Any( mnWidth );
     241        1403 :     case Property_OptimalWidth:     return Any( mbOptimalWidth );
     242           0 :     case Property_IsVisible:        return Any( mbIsVisible );
     243           0 :     case Property_IsStartOfNewPage: return Any( mbIsStartOfNewPage );
     244           0 :     default:                        throw UnknownPropertyException();
     245             :     }
     246             : }
     247             : 
     248             : 
     249             : 
     250         222 : rtl::Reference< FastPropertySetInfo > TableColumn::getStaticPropertySetInfo()
     251             : {
     252         222 :     static rtl::Reference< FastPropertySetInfo > xInfo;
     253         222 :     if( !xInfo.is() )
     254             :     {
     255           5 :         ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
     256           5 :         if( !xInfo.is() )
     257             :         {
     258           5 :             PropertyVector aProperties(6);
     259             : 
     260           5 :             aProperties[0].Name = "Width";
     261           5 :             aProperties[0].Handle = Property_Width;
     262           5 :             aProperties[0].Type = ::cppu::UnoType<sal_Int32>::get();
     263           5 :             aProperties[0].Attributes = 0;
     264             : 
     265           5 :             aProperties[1].Name = "OptimalWidth";
     266           5 :             aProperties[1].Handle = Property_OptimalWidth;
     267           5 :             aProperties[1].Type = cppu::UnoType<bool>::get();
     268           5 :             aProperties[1].Attributes = 0;
     269             : 
     270           5 :             aProperties[2].Name = "IsVisible";
     271           5 :             aProperties[2].Handle = Property_IsVisible;
     272           5 :             aProperties[2].Type = cppu::UnoType<bool>::get();
     273           5 :             aProperties[2].Attributes = 0;
     274             : 
     275           5 :             aProperties[3].Name = "IsStartOfNewPage";
     276           5 :             aProperties[3].Handle = Property_IsStartOfNewPage;
     277           5 :             aProperties[3].Type = cppu::UnoType<bool>::get();
     278           5 :             aProperties[3].Attributes = 0;
     279             : 
     280           5 :             aProperties[4].Name = "Size";
     281           5 :             aProperties[4].Handle = Property_Width;
     282           5 :             aProperties[4].Type = ::cppu::UnoType<sal_Int32>::get();
     283           5 :             aProperties[4].Attributes = 0;
     284             : 
     285           5 :             aProperties[5].Name = "OptimalSize";
     286           5 :             aProperties[5].Handle = Property_OptimalWidth;
     287           5 :             aProperties[5].Type = cppu::UnoType<bool>::get();
     288           5 :             aProperties[5].Attributes = 0;
     289             : 
     290           5 :             xInfo.set( new FastPropertySetInfo(aProperties) );
     291           5 :         }
     292             :     }
     293             : 
     294         222 :     return xInfo;
     295             : }
     296             : 
     297             : 
     298             : 
     299         435 : } }
     300             : 
     301             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11