1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_SVX_SOURCE_TABLE_TABLEMODEL_HXX
21 #define INCLUDED_SVX_SOURCE_TABLE_TABLEMODEL_HXX
23 #include <sal/types.h>
24 #include <com/sun/star/util/XBroadcaster.hpp>
25 #include <com/sun/star/table/XTable.hpp>
26 #include <basegfx/range/b2irectangle.hxx>
27 #include <basegfx/tuple/b2ituple.hxx>
28 #include <cppuhelper/compbase2.hxx>
29 #include <comphelper/broadcasthelper.hxx>
30 #include <comphelper/listenernotification.hxx>
31 #include "celltypes.hxx"
35 namespace sdr
{ namespace table
{
39 /** base class for each object implementing an XCellRange */
43 virtual sal_Int32
getLeft() = 0;
44 virtual sal_Int32
getTop() = 0;
45 virtual sal_Int32
getRight() = 0;
46 virtual sal_Int32
getBottom() = 0;
47 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::table::XTable
> getTable() = 0;
53 typedef ::cppu::WeakComponentImplHelper2
< ::com::sun::star::table::XTable
, ::com::sun::star::util::XBroadcaster
> TableModelBase
;
55 class TableModel
: public ::comphelper::OBaseMutex
,
56 public TableModelBase
,
59 friend class InsertRowUndo
;
60 friend class RemoveRowUndo
;
61 friend class InsertColUndo
;
62 friend class RemoveColUndo
;
63 friend class TableColumnUndo
;
64 friend class TableRowUndo
;
65 friend class TableColumn
;
66 friend class TableRow
;
67 friend class TableRows
;
68 friend class TableColumns
;
69 friend class TableModelNotifyGuard
;
72 TableModel( SdrTableObj
* pTableObj
);
73 TableModel( SdrTableObj
* pTableObj
, const TableModelRef
& xSourceTable
);
74 virtual ~TableModel();
76 void init( sal_Int32 nColumns
, sal_Int32 nRows
);
78 SdrTableObj
* getSdrTableObj() const { return mpTableObj
; }
80 /** deletes rows and columns that are completely merged. Must be called between BegUndo/EndUndo! */
83 /// merges the cell at the given position with the given span
84 void merge( sal_Int32 nCol
, sal_Int32 nRow
, sal_Int32 nColSpan
, sal_Int32 nRowSpan
);
87 virtual sal_Int32
getLeft() SAL_OVERRIDE
;
88 virtual sal_Int32
getTop() SAL_OVERRIDE
;
89 virtual sal_Int32
getRight() SAL_OVERRIDE
;
90 virtual sal_Int32
getBottom() SAL_OVERRIDE
;
91 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::table::XTable
> getTable() SAL_OVERRIDE
;
94 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::table::XCellCursor
> SAL_CALL
createCursor( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
95 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
>& rRange
) throw (::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
96 virtual ::sal_Int32 SAL_CALL
getRowCount() throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
97 virtual ::sal_Int32 SAL_CALL
getColumnCount() throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
100 virtual void SAL_CALL
dispose( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
101 virtual void SAL_CALL
addEventListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XEventListener
>& xListener
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
102 virtual void SAL_CALL
removeEventListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XEventListener
>& aListener
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
105 virtual sal_Bool SAL_CALL
isModified( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
106 virtual void SAL_CALL
setModified( sal_Bool bModified
) throw (::com::sun::star::beans::PropertyVetoException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
108 // XModifyBroadcaster
109 virtual void SAL_CALL
addModifyListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::util::XModifyListener
>& aListener
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
110 virtual void SAL_CALL
removeModifyListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::util::XModifyListener
>& aListener
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
113 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::table::XTableColumns
> SAL_CALL
getColumns() throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
114 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::table::XTableRows
> SAL_CALL
getRows() throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
117 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
, std::exception
) SAL_OVERRIDE
;
118 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
, std::exception
) SAL_OVERRIDE
;
119 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::table::XCellRange
> SAL_CALL
getCellRangeByName( const OUString
& aRange
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
122 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
123 virtual void SAL_CALL
setPropertyValue( const 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
, std::exception
) SAL_OVERRIDE
;
124 virtual ::com::sun::star::uno::Any SAL_CALL
getPropertyValue( const OUString
& PropertyName
) throw (::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
125 virtual void SAL_CALL
addPropertyChangeListener( const 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
, std::exception
) SAL_OVERRIDE
;
126 virtual void SAL_CALL
removePropertyChangeListener( const 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
, std::exception
) SAL_OVERRIDE
;
127 virtual void SAL_CALL
addVetoableChangeListener( const 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
, std::exception
) SAL_OVERRIDE
;
128 virtual void SAL_CALL
removeVetoableChangeListener( const 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
, std::exception
) SAL_OVERRIDE
;
131 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
, std::exception
) SAL_OVERRIDE
;
132 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
, std::exception
) SAL_OVERRIDE
;
135 virtual void SAL_CALL
lockBroadcasts() throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
136 virtual void SAL_CALL
unlockBroadcasts() throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
139 void notifyModification();
141 void insertColumns( sal_Int32 nIndex
, sal_Int32 nCount
);
142 void removeColumns( sal_Int32 nIndex
, sal_Int32 nCount
);
143 void insertRows( sal_Int32 nIndex
, sal_Int32 nCount
);
144 void removeRows( sal_Int32 nIndex
, sal_Int32 nCount
);
146 sal_Int32
getRowCountImpl() const;
147 sal_Int32
getColumnCountImpl() const;
149 CellRef
createCell();
150 CellRef
getCell( ::sal_Int32 nCol
, ::sal_Int32 nRow
) const;
152 void UndoInsertRows( sal_Int32 nIndex
, sal_Int32 nCount
);
153 void UndoRemoveRows( sal_Int32 nIndex
, RowVector
& aNewRows
);
155 void UndoInsertColumns( sal_Int32 nIndex
, sal_Int32 nCount
);
156 void UndoRemoveColumns( sal_Int32 nIndex
, ColumnVector
& aNewCols
, CellVector
& aCells
);
159 /** this function is called upon disposing the component
161 virtual void SAL_CALL
disposing() SAL_OVERRIDE
;
163 TableRowRef
getRow( sal_Int32 nRow
) const throw (::com::sun::star::lang::IndexOutOfBoundsException
);
164 TableColumnRef
getColumn( sal_Int32 nColumn
) const throw (::com::sun::star::lang::IndexOutOfBoundsException
);
167 void updateColumns();
170 ColumnVector maColumns
;
172 TableColumnsRef mxTableColumns
;
173 TableRowsRef mxTableRows
;
175 SdrTableObj
* mpTableObj
;
178 bool mbNotifyPending
;
180 sal_Int32 mnNotifyLock
;
183 class TableModelNotifyGuard
186 TableModelNotifyGuard( TableModel
* pModel
)
187 : mxBroadcaster( static_cast< ::com::sun::star::util::XBroadcaster
* >( pModel
) )
189 if( mxBroadcaster
.is() )
190 mxBroadcaster
->lockBroadcasts();
193 TableModelNotifyGuard( ::com::sun::star::uno::XInterface
* pInterface
)
194 : mxBroadcaster( pInterface
, ::com::sun::star::uno::UNO_QUERY
)
196 if( mxBroadcaster
.is() )
197 mxBroadcaster
->lockBroadcasts();
200 ~TableModelNotifyGuard()
202 if( mxBroadcaster
.is() )
203 mxBroadcaster
->unlockBroadcasts();
207 com::sun::star::uno::Reference
< ::com::sun::star::util::XBroadcaster
> mxBroadcaster
;
214 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */