1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tablemodel.hxx,v $
10 * $Revision: 1.3.264.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _SVX_TABLE_TABLEMODEL_HXX_
32 #define _SVX_TABLE_TABLEMODEL_HXX_
34 #include <com/sun/star/util/XBroadcaster.hpp>
35 #include <com/sun/star/table/XTable.hpp>
36 #include <basegfx/range/b2irectangle.hxx>
37 #include <basegfx/tuple/b2ituple.hxx>
38 #include <cppuhelper/compbase2.hxx>
39 #include <comphelper/broadcasthelper.hxx>
40 #include <comphelper/listenernotification.hxx>
41 #include <tools/gen.hxx>
42 #include "celltypes.hxx"
44 // -----------------------------------------------------------------------------
46 namespace sdr
{ namespace table
{
50 // -----------------------------------------------------------------------------
52 // -----------------------------------------------------------------------------
54 /** base class for each object implementing an XCellRange */
58 virtual sal_Int32
getLeft() = 0;
59 virtual sal_Int32
getTop() = 0;
60 virtual sal_Int32
getRight() = 0;
61 virtual sal_Int32
getBottom() = 0;
62 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::table::XTable
> getTable() = 0;
65 // -----------------------------------------------------------------------------
67 // -----------------------------------------------------------------------------
69 typedef ::cppu::WeakComponentImplHelper2
< ::com::sun::star::table::XTable
, ::com::sun::star::util::XBroadcaster
> TableModelBase
;
71 class TableModel
: public TableModelBase
,
72 public ::comphelper::OBaseMutex
,
75 friend class InsertRowUndo
;
76 friend class RemoveRowUndo
;
77 friend class InsertColUndo
;
78 friend class RemoveColUndo
;
79 friend class TableColumnUndo
;
80 friend class TableRowUndo
;
81 friend class TableColumn
;
82 friend class TableRow
;
83 friend class TableRows
;
84 friend class TableColumns
;
85 friend class TableModelNotifyGuard
;
88 TableModel( SdrTableObj
* pTableObj
);
89 TableModel( SdrTableObj
* pTableObj
, const TableModelRef
& xSourceTable
);
90 virtual ~TableModel();
92 void init( sal_Int32 nColumns
, sal_Int32 nRows
);
94 SdrTableObj
* getSdrTableObj() const { return mpTableObj
; }
96 /** deletes rows and columns that are completly merged. Must be called between BegUndo/EndUndo! */
99 /// merges the cell at the given position with the given span
100 void merge( sal_Int32 nCol
, sal_Int32 nRow
, sal_Int32 nColSpan
, sal_Int32 nRowSpan
);
103 virtual sal_Int32
getLeft();
104 virtual sal_Int32
getTop();
105 virtual sal_Int32
getRight();
106 virtual sal_Int32
getBottom();
107 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::table::XTable
> getTable();
110 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::table::XCellCursor
> SAL_CALL
createCursor( ) throw (::com::sun::star::uno::RuntimeException
);
111 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
);
112 virtual ::sal_Int32 SAL_CALL
getRowCount() throw (::com::sun::star::uno::RuntimeException
);
113 virtual ::sal_Int32 SAL_CALL
getColumnCount() throw (::com::sun::star::uno::RuntimeException
);
116 virtual void SAL_CALL
dispose( ) throw (::com::sun::star::uno::RuntimeException
);
117 virtual void SAL_CALL
addEventListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XEventListener
>& xListener
) throw (::com::sun::star::uno::RuntimeException
);
118 virtual void SAL_CALL
removeEventListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XEventListener
>& aListener
) throw (::com::sun::star::uno::RuntimeException
);
121 virtual ::sal_Bool SAL_CALL
isModified( ) throw (::com::sun::star::uno::RuntimeException
);
122 virtual void SAL_CALL
setModified( ::sal_Bool bModified
) throw (::com::sun::star::beans::PropertyVetoException
, ::com::sun::star::uno::RuntimeException
);
124 // XModifyBroadcaster
125 virtual void SAL_CALL
addModifyListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::util::XModifyListener
>& aListener
) throw (::com::sun::star::uno::RuntimeException
);
126 virtual void SAL_CALL
removeModifyListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::util::XModifyListener
>& aListener
) throw (::com::sun::star::uno::RuntimeException
);
129 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::table::XTableColumns
> SAL_CALL
getColumns() throw (::com::sun::star::uno::RuntimeException
);
130 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::table::XTableRows
> SAL_CALL
getRows() throw (::com::sun::star::uno::RuntimeException
);
133 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
);
134 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
);
135 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::table::XCellRange
> SAL_CALL
getCellRangeByName( const ::rtl::OUString
& aRange
) throw (::com::sun::star::uno::RuntimeException
);
138 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo( ) throw (::com::sun::star::uno::RuntimeException
);
139 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
);
140 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
);
141 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
);
142 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
);
143 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
);
144 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
);
147 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
);
148 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
);
151 virtual void SAL_CALL
lockBroadcasts() throw (::com::sun::star::uno::RuntimeException
);
152 virtual void SAL_CALL
unlockBroadcasts() throw (::com::sun::star::uno::RuntimeException
);
155 void notifyModification();
157 void insertColumns( sal_Int32 nIndex
, sal_Int32 nCount
);
158 void removeColumns( sal_Int32 nIndex
, sal_Int32 nCount
);
159 void insertRows( sal_Int32 nIndex
, sal_Int32 nCount
);
160 void removeRows( sal_Int32 nIndex
, sal_Int32 nCount
);
162 sal_Int32
getRowCountImpl() const;
163 sal_Int32
getColumnCountImpl() const;
165 CellRef
createCell();
166 CellRef
getCell( ::sal_Int32 nCol
, ::sal_Int32 nRow
) const;
168 void UndoInsertRows( sal_Int32 nIndex
, sal_Int32 nCount
);
169 void UndoRemoveRows( sal_Int32 nIndex
, RowVector
& aNewRows
);
171 void UndoInsertColumns( sal_Int32 nIndex
, sal_Int32 nCount
);
172 void UndoRemoveColumns( sal_Int32 nIndex
, ColumnVector
& aNewCols
, CellVector
& aCells
);
175 /** this function is called upon disposing the component
177 virtual void SAL_CALL
disposing();
179 TableRowRef
getRow( sal_Int32 nRow
) const throw (::com::sun::star::lang::IndexOutOfBoundsException
);
180 TableColumnRef
getColumn( sal_Int32 nColumn
) const throw (::com::sun::star::lang::IndexOutOfBoundsException
);
183 void updateColumns();
186 ColumnVector maColumns
;
188 TableColumnsRef mxTableColumns
;
189 TableRowsRef mxTableRows
;
191 SdrTableObj
* mpTableObj
;
194 bool mbNotifyPending
;
196 sal_Int32 mnNotifyLock
;
199 class TableModelNotifyGuard
202 TableModelNotifyGuard( TableModel
* pModel
)
203 : mxBroadcaster( static_cast< ::com::sun::star::util::XBroadcaster
* >( pModel
) )
205 if( mxBroadcaster
.is() )
206 mxBroadcaster
->lockBroadcasts();
209 TableModelNotifyGuard( ::com::sun::star::uno::XInterface
* pInterface
)
210 : mxBroadcaster( pInterface
, ::com::sun::star::uno::UNO_QUERY
)
212 if( mxBroadcaster
.is() )
213 mxBroadcaster
->lockBroadcasts();
216 ~TableModelNotifyGuard()
218 if( mxBroadcaster
.is() )
219 mxBroadcaster
->unlockBroadcasts();
223 com::sun::star::uno::Reference
< ::com::sun::star::util::XBroadcaster
> mxBroadcaster
;