1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef _SVX_TABLE_TABLEMODEL_HXX_ 29 #define _SVX_TABLE_TABLEMODEL_HXX_ 30 31 #include <com/sun/star/util/XBroadcaster.hpp> 32 #include <com/sun/star/table/XTable.hpp> 33 #include <basegfx/range/b2irectangle.hxx> 34 #include <basegfx/tuple/b2ituple.hxx> 35 #include <cppuhelper/compbase2.hxx> 36 #include <comphelper/broadcasthelper.hxx> 37 #include <comphelper/listenernotification.hxx> 38 #include <tools/gen.hxx> 39 #include "celltypes.hxx" 40 41 // ----------------------------------------------------------------------------- 42 43 namespace sdr { namespace table { 44 45 class SdrTableObj; 46 47 // ----------------------------------------------------------------------------- 48 // ICellRange 49 // ----------------------------------------------------------------------------- 50 51 /** base class for each object implementing an XCellRange */ 52 class ICellRange 53 { 54 public: 55 virtual sal_Int32 getLeft() = 0; 56 virtual sal_Int32 getTop() = 0; 57 virtual sal_Int32 getRight() = 0; 58 virtual sal_Int32 getBottom() = 0; 59 virtual ::com::sun::star::uno::Reference< ::com::sun::star::table::XTable > getTable() = 0; 60 }; 61 62 // ----------------------------------------------------------------------------- 63 // TableModel 64 // ----------------------------------------------------------------------------- 65 66 typedef ::cppu::WeakComponentImplHelper2< ::com::sun::star::table::XTable, ::com::sun::star::util::XBroadcaster > TableModelBase; 67 68 class TableModel : public TableModelBase, 69 public ::comphelper::OBaseMutex, 70 public ICellRange 71 { 72 friend class InsertRowUndo; 73 friend class RemoveRowUndo; 74 friend class InsertColUndo; 75 friend class RemoveColUndo; 76 friend class TableColumnUndo; 77 friend class TableRowUndo; 78 friend class TableColumn; 79 friend class TableRow; 80 friend class TableRows; 81 friend class TableColumns; 82 friend class TableModelNotifyGuard; 83 84 public: 85 TableModel( SdrTableObj* pTableObj ); 86 TableModel( SdrTableObj* pTableObj, const TableModelRef& xSourceTable ); 87 virtual ~TableModel(); 88 89 void init( sal_Int32 nColumns, sal_Int32 nRows ); 90 91 SdrTableObj* getSdrTableObj() const { return mpTableObj; } 92 93 /** deletes rows and columns that are completly merged. Must be called between BegUndo/EndUndo! */ 94 void optimize(); 95 96 /// merges the cell at the given position with the given span 97 void merge( sal_Int32 nCol, sal_Int32 nRow, sal_Int32 nColSpan, sal_Int32 nRowSpan ); 98 99 // ICellRange 100 virtual sal_Int32 getLeft(); 101 virtual sal_Int32 getTop(); 102 virtual sal_Int32 getRight(); 103 virtual sal_Int32 getBottom(); 104 virtual ::com::sun::star::uno::Reference< ::com::sun::star::table::XTable > getTable(); 105 106 // XTable 107 virtual ::com::sun::star::uno::Reference< ::com::sun::star::table::XCellCursor > SAL_CALL createCursor( ) throw (::com::sun::star::uno::RuntimeException); 108 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); 109 virtual ::sal_Int32 SAL_CALL getRowCount() throw (::com::sun::star::uno::RuntimeException); 110 virtual ::sal_Int32 SAL_CALL getColumnCount() throw (::com::sun::star::uno::RuntimeException); 111 112 // XComponent 113 virtual void SAL_CALL dispose( ) throw (::com::sun::star::uno::RuntimeException); 114 virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); 115 virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException); 116 117 // XModifiable 118 virtual ::sal_Bool SAL_CALL isModified( ) throw (::com::sun::star::uno::RuntimeException); 119 virtual void SAL_CALL setModified( ::sal_Bool bModified ) throw (::com::sun::star::beans::PropertyVetoException, ::com::sun::star::uno::RuntimeException); 120 121 // XModifyBroadcaster 122 virtual void SAL_CALL addModifyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener ) throw (::com::sun::star::uno::RuntimeException); 123 virtual void SAL_CALL removeModifyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener ) throw (::com::sun::star::uno::RuntimeException); 124 125 // XColumnRowRange 126 virtual ::com::sun::star::uno::Reference< ::com::sun::star::table::XTableColumns > SAL_CALL getColumns() throw (::com::sun::star::uno::RuntimeException); 127 virtual ::com::sun::star::uno::Reference< ::com::sun::star::table::XTableRows > SAL_CALL getRows() throw (::com::sun::star::uno::RuntimeException); 128 129 // XCellRange 130 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); 131 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); 132 virtual ::com::sun::star::uno::Reference< ::com::sun::star::table::XCellRange > SAL_CALL getCellRangeByName( const ::rtl::OUString& aRange ) throw (::com::sun::star::uno::RuntimeException); 133 134 // XPropertySet 135 virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw (::com::sun::star::uno::RuntimeException); 136 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); 137 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); 138 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); 139 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); 140 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); 141 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); 142 143 // XFastPropertySet 144 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); 145 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); 146 147 // XBroadcaster 148 virtual void SAL_CALL lockBroadcasts() throw (::com::sun::star::uno::RuntimeException); 149 virtual void SAL_CALL unlockBroadcasts() throw (::com::sun::star::uno::RuntimeException); 150 151 protected: 152 void notifyModification(); 153 154 void insertColumns( sal_Int32 nIndex, sal_Int32 nCount ); 155 void removeColumns( sal_Int32 nIndex, sal_Int32 nCount ); 156 void insertRows( sal_Int32 nIndex, sal_Int32 nCount ); 157 void removeRows( sal_Int32 nIndex, sal_Int32 nCount ); 158 159 sal_Int32 getRowCountImpl() const; 160 sal_Int32 getColumnCountImpl() const; 161 162 CellRef createCell(); 163 CellRef getCell( ::sal_Int32 nCol, ::sal_Int32 nRow ) const; 164 165 void UndoInsertRows( sal_Int32 nIndex, sal_Int32 nCount ); 166 void UndoRemoveRows( sal_Int32 nIndex, RowVector& aNewRows ); 167 168 void UndoInsertColumns( sal_Int32 nIndex, sal_Int32 nCount ); 169 void UndoRemoveColumns( sal_Int32 nIndex, ColumnVector& aNewCols, CellVector& aCells ); 170 171 private: 172 /** this function is called upon disposing the component 173 */ 174 virtual void SAL_CALL disposing(); 175 176 TableRowRef getRow( sal_Int32 nRow ) const throw (::com::sun::star::lang::IndexOutOfBoundsException); 177 TableColumnRef getColumn( sal_Int32 nColumn ) const throw (::com::sun::star::lang::IndexOutOfBoundsException); 178 179 void updateRows(); 180 void updateColumns(); 181 182 RowVector maRows; 183 ColumnVector maColumns; 184 185 TableColumnsRef mxTableColumns; 186 TableRowsRef mxTableRows; 187 188 SdrTableObj* mpTableObj; 189 190 sal_Bool mbModified; 191 bool mbNotifyPending; 192 193 sal_Int32 mnNotifyLock; 194 }; 195 196 class TableModelNotifyGuard 197 { 198 public: 199 TableModelNotifyGuard( TableModel* pModel ) 200 : mxBroadcaster( static_cast< ::com::sun::star::util::XBroadcaster* >( pModel ) ) 201 { 202 if( mxBroadcaster.is() ) 203 mxBroadcaster->lockBroadcasts(); 204 } 205 206 TableModelNotifyGuard( ::com::sun::star::uno::XInterface* pInterface ) 207 : mxBroadcaster( pInterface, ::com::sun::star::uno::UNO_QUERY ) 208 { 209 if( mxBroadcaster.is() ) 210 mxBroadcaster->lockBroadcasts(); 211 } 212 213 ~TableModelNotifyGuard() 214 { 215 if( mxBroadcaster.is() ) 216 mxBroadcaster->unlockBroadcasts(); 217 } 218 219 private: 220 com::sun::star::uno::Reference< ::com::sun::star::util::XBroadcaster > mxBroadcaster; 221 }; 222 223 } } 224 225 #endif 226