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

Generated by: LCOV version 1.10