1*b1cdbd2cSJim Jagielski /************************************************************** 2*b1cdbd2cSJim Jagielski * 3*b1cdbd2cSJim Jagielski * Licensed to the Apache Software Foundation (ASF) under one 4*b1cdbd2cSJim Jagielski * or more contributor license agreements. See the NOTICE file 5*b1cdbd2cSJim Jagielski * distributed with this work for additional information 6*b1cdbd2cSJim Jagielski * regarding copyright ownership. The ASF licenses this file 7*b1cdbd2cSJim Jagielski * to you under the Apache License, Version 2.0 (the 8*b1cdbd2cSJim Jagielski * "License"); you may not use this file except in compliance 9*b1cdbd2cSJim Jagielski * with the License. You may obtain a copy of the License at 10*b1cdbd2cSJim Jagielski * 11*b1cdbd2cSJim Jagielski * http://www.apache.org/licenses/LICENSE-2.0 12*b1cdbd2cSJim Jagielski * 13*b1cdbd2cSJim Jagielski * Unless required by applicable law or agreed to in writing, 14*b1cdbd2cSJim Jagielski * software distributed under the License is distributed on an 15*b1cdbd2cSJim Jagielski * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*b1cdbd2cSJim Jagielski * KIND, either express or implied. See the License for the 17*b1cdbd2cSJim Jagielski * specific language governing permissions and limitations 18*b1cdbd2cSJim Jagielski * under the License. 19*b1cdbd2cSJim Jagielski * 20*b1cdbd2cSJim Jagielski *************************************************************/ 21*b1cdbd2cSJim Jagielski 22*b1cdbd2cSJim Jagielski 23*b1cdbd2cSJim Jagielski 24*b1cdbd2cSJim Jagielski #ifndef _SVX_TABLE_TABLEMODEL_HXX_ 25*b1cdbd2cSJim Jagielski #define _SVX_TABLE_TABLEMODEL_HXX_ 26*b1cdbd2cSJim Jagielski 27*b1cdbd2cSJim Jagielski #include <com/sun/star/util/XBroadcaster.hpp> 28*b1cdbd2cSJim Jagielski #include <com/sun/star/table/XTable.hpp> 29*b1cdbd2cSJim Jagielski #include <basegfx/range/b2irectangle.hxx> 30*b1cdbd2cSJim Jagielski #include <basegfx/tuple/b2ituple.hxx> 31*b1cdbd2cSJim Jagielski #include <cppuhelper/compbase2.hxx> 32*b1cdbd2cSJim Jagielski #include <comphelper/broadcasthelper.hxx> 33*b1cdbd2cSJim Jagielski #include <comphelper/listenernotification.hxx> 34*b1cdbd2cSJim Jagielski #include <tools/gen.hxx> 35*b1cdbd2cSJim Jagielski #include "celltypes.hxx" 36*b1cdbd2cSJim Jagielski 37*b1cdbd2cSJim Jagielski // ----------------------------------------------------------------------------- 38*b1cdbd2cSJim Jagielski 39*b1cdbd2cSJim Jagielski namespace sdr { namespace table { 40*b1cdbd2cSJim Jagielski 41*b1cdbd2cSJim Jagielski class SdrTableObj; 42*b1cdbd2cSJim Jagielski 43*b1cdbd2cSJim Jagielski // ----------------------------------------------------------------------------- 44*b1cdbd2cSJim Jagielski // ICellRange 45*b1cdbd2cSJim Jagielski // ----------------------------------------------------------------------------- 46*b1cdbd2cSJim Jagielski 47*b1cdbd2cSJim Jagielski /** base class for each object implementing an XCellRange */ 48*b1cdbd2cSJim Jagielski class ICellRange 49*b1cdbd2cSJim Jagielski { 50*b1cdbd2cSJim Jagielski public: 51*b1cdbd2cSJim Jagielski virtual sal_Int32 getLeft() = 0; 52*b1cdbd2cSJim Jagielski virtual sal_Int32 getTop() = 0; 53*b1cdbd2cSJim Jagielski virtual sal_Int32 getRight() = 0; 54*b1cdbd2cSJim Jagielski virtual sal_Int32 getBottom() = 0; 55*b1cdbd2cSJim Jagielski virtual ::com::sun::star::uno::Reference< ::com::sun::star::table::XTable > getTable() = 0; 56*b1cdbd2cSJim Jagielski }; 57*b1cdbd2cSJim Jagielski 58*b1cdbd2cSJim Jagielski // ----------------------------------------------------------------------------- 59*b1cdbd2cSJim Jagielski // TableModel 60*b1cdbd2cSJim Jagielski // ----------------------------------------------------------------------------- 61*b1cdbd2cSJim Jagielski 62*b1cdbd2cSJim Jagielski typedef ::cppu::WeakComponentImplHelper2< ::com::sun::star::table::XTable, ::com::sun::star::util::XBroadcaster > TableModelBase; 63*b1cdbd2cSJim Jagielski 64*b1cdbd2cSJim Jagielski class TableModel : public TableModelBase, 65*b1cdbd2cSJim Jagielski public ::comphelper::OBaseMutex, 66*b1cdbd2cSJim Jagielski public ICellRange 67*b1cdbd2cSJim Jagielski { 68*b1cdbd2cSJim Jagielski friend class InsertRowUndo; 69*b1cdbd2cSJim Jagielski friend class RemoveRowUndo; 70*b1cdbd2cSJim Jagielski friend class InsertColUndo; 71*b1cdbd2cSJim Jagielski friend class RemoveColUndo; 72*b1cdbd2cSJim Jagielski friend class TableColumnUndo; 73*b1cdbd2cSJim Jagielski friend class TableRowUndo; 74*b1cdbd2cSJim Jagielski friend class TableColumn; 75*b1cdbd2cSJim Jagielski friend class TableRow; 76*b1cdbd2cSJim Jagielski friend class TableRows; 77*b1cdbd2cSJim Jagielski friend class TableColumns; 78*b1cdbd2cSJim Jagielski friend class TableModelNotifyGuard; 79*b1cdbd2cSJim Jagielski 80*b1cdbd2cSJim Jagielski public: 81*b1cdbd2cSJim Jagielski TableModel( SdrTableObj* pTableObj ); 82*b1cdbd2cSJim Jagielski TableModel( SdrTableObj* pTableObj, const TableModelRef& xSourceTable ); 83*b1cdbd2cSJim Jagielski virtual ~TableModel(); 84*b1cdbd2cSJim Jagielski 85*b1cdbd2cSJim Jagielski void init( sal_Int32 nColumns, sal_Int32 nRows ); 86*b1cdbd2cSJim Jagielski getSdrTableObj() const87*b1cdbd2cSJim Jagielski SdrTableObj* getSdrTableObj() const { return mpTableObj; } 88*b1cdbd2cSJim Jagielski 89*b1cdbd2cSJim Jagielski /** deletes rows and columns that are completly merged. Must be called between BegUndo/EndUndo! */ 90*b1cdbd2cSJim Jagielski void optimize(); 91*b1cdbd2cSJim Jagielski 92*b1cdbd2cSJim Jagielski /// merges the cell at the given position with the given span 93*b1cdbd2cSJim Jagielski void merge( sal_Int32 nCol, sal_Int32 nRow, sal_Int32 nColSpan, sal_Int32 nRowSpan ); 94*b1cdbd2cSJim Jagielski 95*b1cdbd2cSJim Jagielski // ICellRange 96*b1cdbd2cSJim Jagielski virtual sal_Int32 getLeft(); 97*b1cdbd2cSJim Jagielski virtual sal_Int32 getTop(); 98*b1cdbd2cSJim Jagielski virtual sal_Int32 getRight(); 99*b1cdbd2cSJim Jagielski virtual sal_Int32 getBottom(); 100*b1cdbd2cSJim Jagielski virtual ::com::sun::star::uno::Reference< ::com::sun::star::table::XTable > getTable(); 101*b1cdbd2cSJim Jagielski 102*b1cdbd2cSJim Jagielski // XTable 103*b1cdbd2cSJim Jagielski virtual ::com::sun::star::uno::Reference< ::com::sun::star::table::XCellCursor > SAL_CALL createCursor( ) throw (::com::sun::star::uno::RuntimeException); 104*b1cdbd2cSJim Jagielski 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 >& Range ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); 105*b1cdbd2cSJim Jagielski virtual ::sal_Int32 SAL_CALL getRowCount() throw (::com::sun::star::uno::RuntimeException); 106*b1cdbd2cSJim Jagielski virtual ::sal_Int32 SAL_CALL getColumnCount() throw (::com::sun::star::uno::RuntimeException); 107*b1cdbd2cSJim Jagielski 108*b1cdbd2cSJim Jagielski // XComponent 109*b1cdbd2cSJim Jagielski virtual void SAL_CALL dispose( ) throw (::com::sun::star::uno::RuntimeException); 110*b1cdbd2cSJim Jagielski virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); 111*b1cdbd2cSJim Jagielski virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException); 112*b1cdbd2cSJim Jagielski 113*b1cdbd2cSJim Jagielski // XModifiable 114*b1cdbd2cSJim Jagielski virtual ::sal_Bool SAL_CALL isModified( ) throw (::com::sun::star::uno::RuntimeException); 115*b1cdbd2cSJim Jagielski virtual void SAL_CALL setModified( ::sal_Bool bModified ) throw (::com::sun::star::beans::PropertyVetoException, ::com::sun::star::uno::RuntimeException); 116*b1cdbd2cSJim Jagielski 117*b1cdbd2cSJim Jagielski // XModifyBroadcaster 118*b1cdbd2cSJim Jagielski virtual void SAL_CALL addModifyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener ) throw (::com::sun::star::uno::RuntimeException); 119*b1cdbd2cSJim Jagielski virtual void SAL_CALL removeModifyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener ) throw (::com::sun::star::uno::RuntimeException); 120*b1cdbd2cSJim Jagielski 121*b1cdbd2cSJim Jagielski // XColumnRowRange 122*b1cdbd2cSJim Jagielski virtual ::com::sun::star::uno::Reference< ::com::sun::star::table::XTableColumns > SAL_CALL getColumns() throw (::com::sun::star::uno::RuntimeException); 123*b1cdbd2cSJim Jagielski virtual ::com::sun::star::uno::Reference< ::com::sun::star::table::XTableRows > SAL_CALL getRows() throw (::com::sun::star::uno::RuntimeException); 124*b1cdbd2cSJim Jagielski 125*b1cdbd2cSJim Jagielski // XCellRange 126*b1cdbd2cSJim Jagielski 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); 127*b1cdbd2cSJim Jagielski 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); 128*b1cdbd2cSJim Jagielski virtual ::com::sun::star::uno::Reference< ::com::sun::star::table::XCellRange > SAL_CALL getCellRangeByName( const ::rtl::OUString& aRange ) throw (::com::sun::star::uno::RuntimeException); 129*b1cdbd2cSJim Jagielski 130*b1cdbd2cSJim Jagielski // XPropertySet 131*b1cdbd2cSJim Jagielski virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw (::com::sun::star::uno::RuntimeException); 132*b1cdbd2cSJim Jagielski virtual void SAL_CALL setPropertyValue( const ::rtl::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); 133*b1cdbd2cSJim Jagielski virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& PropertyName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 134*b1cdbd2cSJim Jagielski virtual void SAL_CALL addPropertyChangeListener( const ::rtl::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); 135*b1cdbd2cSJim Jagielski virtual void SAL_CALL removePropertyChangeListener( const ::rtl::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); 136*b1cdbd2cSJim Jagielski virtual void SAL_CALL addVetoableChangeListener( const ::rtl::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*b1cdbd2cSJim Jagielski virtual void SAL_CALL removeVetoableChangeListener( const ::rtl::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); 138*b1cdbd2cSJim Jagielski 139*b1cdbd2cSJim Jagielski // XFastPropertySet 140*b1cdbd2cSJim Jagielski 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); 141*b1cdbd2cSJim Jagielski 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); 142*b1cdbd2cSJim Jagielski 143*b1cdbd2cSJim Jagielski // XBroadcaster 144*b1cdbd2cSJim Jagielski virtual void SAL_CALL lockBroadcasts() throw (::com::sun::star::uno::RuntimeException); 145*b1cdbd2cSJim Jagielski virtual void SAL_CALL unlockBroadcasts() throw (::com::sun::star::uno::RuntimeException); 146*b1cdbd2cSJim Jagielski 147*b1cdbd2cSJim Jagielski protected: 148*b1cdbd2cSJim Jagielski void notifyModification(); 149*b1cdbd2cSJim Jagielski 150*b1cdbd2cSJim Jagielski void insertColumns( sal_Int32 nIndex, sal_Int32 nCount ); 151*b1cdbd2cSJim Jagielski void removeColumns( sal_Int32 nIndex, sal_Int32 nCount ); 152*b1cdbd2cSJim Jagielski void insertRows( sal_Int32 nIndex, sal_Int32 nCount ); 153*b1cdbd2cSJim Jagielski void removeRows( sal_Int32 nIndex, sal_Int32 nCount ); 154*b1cdbd2cSJim Jagielski 155*b1cdbd2cSJim Jagielski sal_Int32 getRowCountImpl() const; 156*b1cdbd2cSJim Jagielski sal_Int32 getColumnCountImpl() const; 157*b1cdbd2cSJim Jagielski 158*b1cdbd2cSJim Jagielski CellRef createCell(); 159*b1cdbd2cSJim Jagielski CellRef getCell( ::sal_Int32 nCol, ::sal_Int32 nRow ) const; 160*b1cdbd2cSJim Jagielski 161*b1cdbd2cSJim Jagielski void UndoInsertRows( sal_Int32 nIndex, sal_Int32 nCount ); 162*b1cdbd2cSJim Jagielski void UndoRemoveRows( sal_Int32 nIndex, RowVector& aNewRows ); 163*b1cdbd2cSJim Jagielski 164*b1cdbd2cSJim Jagielski void UndoInsertColumns( sal_Int32 nIndex, sal_Int32 nCount ); 165*b1cdbd2cSJim Jagielski void UndoRemoveColumns( sal_Int32 nIndex, ColumnVector& aNewCols, CellVector& aCells ); 166*b1cdbd2cSJim Jagielski 167*b1cdbd2cSJim Jagielski private: 168*b1cdbd2cSJim Jagielski /** this function is called upon disposing the component 169*b1cdbd2cSJim Jagielski */ 170*b1cdbd2cSJim Jagielski virtual void SAL_CALL disposing(); 171*b1cdbd2cSJim Jagielski 172*b1cdbd2cSJim Jagielski TableRowRef getRow( sal_Int32 nRow ) const throw (::com::sun::star::lang::IndexOutOfBoundsException); 173*b1cdbd2cSJim Jagielski TableColumnRef getColumn( sal_Int32 nColumn ) const throw (::com::sun::star::lang::IndexOutOfBoundsException); 174*b1cdbd2cSJim Jagielski 175*b1cdbd2cSJim Jagielski void updateRows(); 176*b1cdbd2cSJim Jagielski void updateColumns(); 177*b1cdbd2cSJim Jagielski 178*b1cdbd2cSJim Jagielski RowVector maRows; 179*b1cdbd2cSJim Jagielski ColumnVector maColumns; 180*b1cdbd2cSJim Jagielski 181*b1cdbd2cSJim Jagielski TableColumnsRef mxTableColumns; 182*b1cdbd2cSJim Jagielski TableRowsRef mxTableRows; 183*b1cdbd2cSJim Jagielski 184*b1cdbd2cSJim Jagielski SdrTableObj* mpTableObj; 185*b1cdbd2cSJim Jagielski 186*b1cdbd2cSJim Jagielski sal_Bool mbModified; 187*b1cdbd2cSJim Jagielski bool mbNotifyPending; 188*b1cdbd2cSJim Jagielski 189*b1cdbd2cSJim Jagielski sal_Int32 mnNotifyLock; 190*b1cdbd2cSJim Jagielski }; 191*b1cdbd2cSJim Jagielski 192*b1cdbd2cSJim Jagielski class TableModelNotifyGuard 193*b1cdbd2cSJim Jagielski { 194*b1cdbd2cSJim Jagielski public: TableModelNotifyGuard(TableModel * pModel)195*b1cdbd2cSJim Jagielski TableModelNotifyGuard( TableModel* pModel ) 196*b1cdbd2cSJim Jagielski : mxBroadcaster( static_cast< ::com::sun::star::util::XBroadcaster* >( pModel ) ) 197*b1cdbd2cSJim Jagielski { 198*b1cdbd2cSJim Jagielski if( mxBroadcaster.is() ) 199*b1cdbd2cSJim Jagielski mxBroadcaster->lockBroadcasts(); 200*b1cdbd2cSJim Jagielski } 201*b1cdbd2cSJim Jagielski TableModelNotifyGuard(::com::sun::star::uno::XInterface * pInterface)202*b1cdbd2cSJim Jagielski TableModelNotifyGuard( ::com::sun::star::uno::XInterface* pInterface ) 203*b1cdbd2cSJim Jagielski : mxBroadcaster( pInterface, ::com::sun::star::uno::UNO_QUERY ) 204*b1cdbd2cSJim Jagielski { 205*b1cdbd2cSJim Jagielski if( mxBroadcaster.is() ) 206*b1cdbd2cSJim Jagielski mxBroadcaster->lockBroadcasts(); 207*b1cdbd2cSJim Jagielski } 208*b1cdbd2cSJim Jagielski ~TableModelNotifyGuard()209*b1cdbd2cSJim Jagielski ~TableModelNotifyGuard() 210*b1cdbd2cSJim Jagielski { 211*b1cdbd2cSJim Jagielski if( mxBroadcaster.is() ) 212*b1cdbd2cSJim Jagielski mxBroadcaster->unlockBroadcasts(); 213*b1cdbd2cSJim Jagielski } 214*b1cdbd2cSJim Jagielski 215*b1cdbd2cSJim Jagielski private: 216*b1cdbd2cSJim Jagielski com::sun::star::uno::Reference< ::com::sun::star::util::XBroadcaster > mxBroadcaster; 217*b1cdbd2cSJim Jagielski }; 218*b1cdbd2cSJim Jagielski 219*b1cdbd2cSJim Jagielski } } 220*b1cdbd2cSJim Jagielski 221*b1cdbd2cSJim Jagielski #endif 222