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