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