LCOV - code coverage report
Current view: top level - svx/source/table - tablemodel.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 13 13 100.0 %
Date: 2014-11-03 Functions: 5 5 100.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             : #ifndef INCLUDED_SVX_SOURCE_TABLE_TABLEMODEL_HXX
      21             : #define INCLUDED_SVX_SOURCE_TABLE_TABLEMODEL_HXX
      22             : 
      23             : #include <sal/types.h>
      24             : #include <com/sun/star/util/XBroadcaster.hpp>
      25             : #include <com/sun/star/table/XTable.hpp>
      26             : #include <basegfx/range/b2irectangle.hxx>
      27             : #include <basegfx/tuple/b2ituple.hxx>
      28             : #include <cppuhelper/compbase2.hxx>
      29             : #include <comphelper/broadcasthelper.hxx>
      30             : #include <comphelper/listenernotification.hxx>
      31             : #include "celltypes.hxx"
      32             : 
      33             : 
      34             : 
      35             : namespace sdr { namespace table {
      36             : 
      37             : class SdrTableObj;
      38             : 
      39             : /** base class for each object implementing an XCellRange */
      40         110 : class ICellRange
      41             : {
      42             : public:
      43             :     virtual sal_Int32 getLeft() = 0;
      44             :     virtual sal_Int32 getTop() = 0;
      45             :     virtual sal_Int32 getRight() = 0;
      46             :     virtual sal_Int32 getBottom() = 0;
      47             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::table::XTable > getTable() = 0;
      48             : 
      49             : protected:
      50         110 :     ~ICellRange() {}
      51             : };
      52             : 
      53             : typedef ::cppu::WeakComponentImplHelper2< ::com::sun::star::table::XTable, ::com::sun::star::util::XBroadcaster > TableModelBase;
      54             : 
      55             : class TableModel : public TableModelBase,
      56             :                    public ::comphelper::OBaseMutex,
      57             :                    public ICellRange
      58             : {
      59             :     friend class InsertRowUndo;
      60             :     friend class RemoveRowUndo;
      61             :     friend class InsertColUndo;
      62             :     friend class RemoveColUndo;
      63             :     friend class TableColumnUndo;
      64             :     friend class TableRowUndo;
      65             :     friend class TableColumn;
      66             :     friend class TableRow;
      67             :     friend class TableRows;
      68             :     friend class TableColumns;
      69             :     friend class TableModelNotifyGuard;
      70             : 
      71             : public:
      72             :     TableModel( SdrTableObj* pTableObj );
      73             :     TableModel( SdrTableObj* pTableObj, const TableModelRef& xSourceTable );
      74             :     virtual ~TableModel();
      75             : 
      76             :     void init( sal_Int32 nColumns, sal_Int32 nRows );
      77             : 
      78       15220 :     SdrTableObj* getSdrTableObj() const { return mpTableObj; }
      79             : 
      80             :     /** deletes rows and columns that are completely merged. Must be called between BegUndo/EndUndo! */
      81             :     void optimize();
      82             : 
      83             :     /// merges the cell at the given position with the given span
      84             :     void merge( sal_Int32 nCol, sal_Int32 nRow, sal_Int32 nColSpan, sal_Int32 nRowSpan );
      85             : 
      86             :     // ICellRange
      87             :     virtual sal_Int32 getLeft() SAL_OVERRIDE;
      88             :     virtual sal_Int32 getTop() SAL_OVERRIDE;
      89             :     virtual sal_Int32 getRight() SAL_OVERRIDE;
      90             :     virtual sal_Int32 getBottom() SAL_OVERRIDE;
      91             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::table::XTable > getTable() SAL_OVERRIDE;
      92             : 
      93             :     // XTable
      94             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::table::XCellCursor > SAL_CALL createCursor(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      95             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::table::XCellCursor > SAL_CALL createCursorByRange( const ::com::sun::star::uno::Reference< ::com::sun::star::table::XCellRange >& rRange ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      96             :     virtual ::sal_Int32 SAL_CALL getRowCount() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      97             :     virtual ::sal_Int32 SAL_CALL getColumnCount() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      98             : 
      99             :     // XComponent
     100             :     virtual void SAL_CALL dispose(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     101             :     virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     102             :     virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     103             : 
     104             :     // XModifiable
     105             :     virtual sal_Bool SAL_CALL isModified(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     106             :     virtual void SAL_CALL setModified( sal_Bool bModified ) throw (::com::sun::star::beans::PropertyVetoException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     107             : 
     108             :     // XModifyBroadcaster
     109             :     virtual void SAL_CALL addModifyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     110             :     virtual void SAL_CALL removeModifyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     111             : 
     112             :     // XColumnRowRange
     113             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::table::XTableColumns > SAL_CALL getColumns() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     114             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::table::XTableRows > SAL_CALL getRows() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     115             : 
     116             :     // XCellRange
     117             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell > SAL_CALL getCellByPosition( ::sal_Int32 nColumn, ::sal_Int32 nRow ) throw ( ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     118             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::table::XCellRange > SAL_CALL getCellRangeByPosition( ::sal_Int32 nLeft, ::sal_Int32 nTop, ::sal_Int32 nRight, ::sal_Int32 nBottom ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     119             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::table::XCellRange > SAL_CALL getCellRangeByName( const OUString& aRange ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     120             : 
     121             :     // XPropertySet
     122             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     123             :     virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     124             :     virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     125             :     virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     126             :     virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& aListener ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     127             :     virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     128             :     virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     129             : 
     130             :     // XFastPropertySet
     131             :     virtual void SAL_CALL setFastPropertyValue( ::sal_Int32 nHandle, const ::com::sun::star::uno::Any& aValue ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     132             :     virtual ::com::sun::star::uno::Any SAL_CALL getFastPropertyValue( ::sal_Int32 nHandle ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     133             : 
     134             :     // XBroadcaster
     135             :     virtual void SAL_CALL lockBroadcasts() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     136             :     virtual void SAL_CALL unlockBroadcasts() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     137             : 
     138             : protected:
     139             :     void notifyModification();
     140             : 
     141             :     void insertColumns( sal_Int32 nIndex, sal_Int32 nCount );
     142             :     void removeColumns( sal_Int32 nIndex, sal_Int32 nCount );
     143             :     void insertRows( sal_Int32 nIndex, sal_Int32 nCount );
     144             :     void removeRows( sal_Int32 nIndex, sal_Int32 nCount );
     145             : 
     146             :     sal_Int32 getRowCountImpl() const;
     147             :     sal_Int32 getColumnCountImpl() const;
     148             : 
     149             :     CellRef createCell();
     150             :     CellRef getCell( ::sal_Int32 nCol, ::sal_Int32 nRow ) const;
     151             : 
     152             :     void UndoInsertRows( sal_Int32 nIndex, sal_Int32 nCount );
     153             :     void UndoRemoveRows( sal_Int32 nIndex, RowVector& aNewRows );
     154             : 
     155             :     void UndoInsertColumns( sal_Int32 nIndex, sal_Int32 nCount );
     156             :     void UndoRemoveColumns( sal_Int32 nIndex, ColumnVector& aNewCols, CellVector& aCells );
     157             : 
     158             : private:
     159             :     /** this function is called upon disposing the component
     160             :     */
     161             :     virtual void SAL_CALL disposing() SAL_OVERRIDE;
     162             : 
     163             :     TableRowRef getRow( sal_Int32 nRow ) const throw (::com::sun::star::lang::IndexOutOfBoundsException);
     164             :     TableColumnRef getColumn( sal_Int32 nColumn ) const throw (::com::sun::star::lang::IndexOutOfBoundsException);
     165             : 
     166             :     void updateRows();
     167             :     void updateColumns();
     168             : 
     169             :     RowVector       maRows;
     170             :     ColumnVector    maColumns;
     171             : 
     172             :     TableColumnsRef mxTableColumns;
     173             :     TableRowsRef mxTableRows;
     174             : 
     175             :     SdrTableObj* mpTableObj;
     176             : 
     177             :     bool mbModified;
     178             :     bool mbNotifyPending;
     179             : 
     180             :     sal_Int32 mnNotifyLock;
     181             : };
     182             : 
     183             : class TableModelNotifyGuard
     184             : {
     185             : public:
     186        1058 :     TableModelNotifyGuard( TableModel* pModel )
     187        1058 :     : mxBroadcaster( static_cast< ::com::sun::star::util::XBroadcaster* >( pModel ) )
     188             :     {
     189        1058 :         if( mxBroadcaster.is() )
     190        1058 :             mxBroadcaster->lockBroadcasts();
     191        1058 :     }
     192             : 
     193             :     TableModelNotifyGuard( ::com::sun::star::uno::XInterface* pInterface )
     194             :     : mxBroadcaster( pInterface, ::com::sun::star::uno::UNO_QUERY )
     195             :     {
     196             :         if( mxBroadcaster.is() )
     197             :             mxBroadcaster->lockBroadcasts();
     198             :     }
     199             : 
     200        1058 :     ~TableModelNotifyGuard()
     201        1058 :     {
     202        1058 :         if( mxBroadcaster.is() )
     203        1058 :             mxBroadcaster->unlockBroadcasts();
     204        1058 :     }
     205             : 
     206             : private:
     207             :     com::sun::star::uno::Reference< ::com::sun::star::util::XBroadcaster > mxBroadcaster;
     208             : };
     209             : 
     210             : } }
     211             : 
     212             : #endif
     213             : 
     214             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10