bump product version to 4.1.6.2
[LibreOffice.git] / svx / source / table / tablemodel.hxx
blob77768a635aa3145a37d069eca19ea049fb8a5dd9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 _SVX_TABLE_TABLEMODEL_HXX_
21 #define _SVX_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"
33 // -----------------------------------------------------------------------------
35 namespace sdr { namespace table {
37 class SdrTableObj;
39 // -----------------------------------------------------------------------------
40 // ICellRange
41 // -----------------------------------------------------------------------------
43 /** base class for each object implementing an XCellRange */
44 class ICellRange
46 public:
47 virtual sal_Int32 getLeft() = 0;
48 virtual sal_Int32 getTop() = 0;
49 virtual sal_Int32 getRight() = 0;
50 virtual sal_Int32 getBottom() = 0;
51 virtual ::com::sun::star::uno::Reference< ::com::sun::star::table::XTable > getTable() = 0;
53 protected:
54 ~ICellRange() {}
57 // -----------------------------------------------------------------------------
58 // TableModel
59 // -----------------------------------------------------------------------------
61 typedef ::cppu::WeakComponentImplHelper2< ::com::sun::star::table::XTable, ::com::sun::star::util::XBroadcaster > TableModelBase;
63 class TableModel : public TableModelBase,
64 public ::comphelper::OBaseMutex,
65 public ICellRange
67 friend class InsertRowUndo;
68 friend class RemoveRowUndo;
69 friend class InsertColUndo;
70 friend class RemoveColUndo;
71 friend class TableColumnUndo;
72 friend class TableRowUndo;
73 friend class TableColumn;
74 friend class TableRow;
75 friend class TableRows;
76 friend class TableColumns;
77 friend class TableModelNotifyGuard;
79 public:
80 TableModel( SdrTableObj* pTableObj );
81 TableModel( SdrTableObj* pTableObj, const TableModelRef& xSourceTable );
82 virtual ~TableModel();
84 void init( sal_Int32 nColumns, sal_Int32 nRows );
86 SdrTableObj* getSdrTableObj() const { return mpTableObj; }
88 /** deletes rows and columns that are completely merged. Must be called between BegUndo/EndUndo! */
89 void optimize();
91 /// merges the cell at the given position with the given span
92 void merge( sal_Int32 nCol, sal_Int32 nRow, sal_Int32 nColSpan, sal_Int32 nRowSpan );
94 // ICellRange
95 virtual sal_Int32 getLeft();
96 virtual sal_Int32 getTop();
97 virtual sal_Int32 getRight();
98 virtual sal_Int32 getBottom();
99 virtual ::com::sun::star::uno::Reference< ::com::sun::star::table::XTable > getTable();
101 // XTable
102 virtual ::com::sun::star::uno::Reference< ::com::sun::star::table::XCellCursor > SAL_CALL createCursor( ) throw (::com::sun::star::uno::RuntimeException);
103 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);
104 virtual ::sal_Int32 SAL_CALL getRowCount() throw (::com::sun::star::uno::RuntimeException);
105 virtual ::sal_Int32 SAL_CALL getColumnCount() throw (::com::sun::star::uno::RuntimeException);
107 // XComponent
108 virtual void SAL_CALL dispose( ) throw (::com::sun::star::uno::RuntimeException);
109 virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
110 virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
112 // XModifiable
113 virtual ::sal_Bool SAL_CALL isModified( ) throw (::com::sun::star::uno::RuntimeException);
114 virtual void SAL_CALL setModified( ::sal_Bool bModified ) throw (::com::sun::star::beans::PropertyVetoException, ::com::sun::star::uno::RuntimeException);
116 // XModifyBroadcaster
117 virtual void SAL_CALL addModifyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
118 virtual void SAL_CALL removeModifyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
120 // XColumnRowRange
121 virtual ::com::sun::star::uno::Reference< ::com::sun::star::table::XTableColumns > SAL_CALL getColumns() throw (::com::sun::star::uno::RuntimeException);
122 virtual ::com::sun::star::uno::Reference< ::com::sun::star::table::XTableRows > SAL_CALL getRows() throw (::com::sun::star::uno::RuntimeException);
124 // XCellRange
125 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);
126 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);
127 virtual ::com::sun::star::uno::Reference< ::com::sun::star::table::XCellRange > SAL_CALL getCellRangeByName( const OUString& aRange ) throw (::com::sun::star::uno::RuntimeException);
129 // XPropertySet
130 virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw (::com::sun::star::uno::RuntimeException);
131 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);
132 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);
133 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);
134 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);
135 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);
136 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);
138 // XFastPropertySet
139 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);
140 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);
142 // XBroadcaster
143 virtual void SAL_CALL lockBroadcasts() throw (::com::sun::star::uno::RuntimeException);
144 virtual void SAL_CALL unlockBroadcasts() throw (::com::sun::star::uno::RuntimeException);
146 protected:
147 void notifyModification();
149 void insertColumns( sal_Int32 nIndex, sal_Int32 nCount );
150 void removeColumns( sal_Int32 nIndex, sal_Int32 nCount );
151 void insertRows( sal_Int32 nIndex, sal_Int32 nCount );
152 void removeRows( sal_Int32 nIndex, sal_Int32 nCount );
154 sal_Int32 getRowCountImpl() const;
155 sal_Int32 getColumnCountImpl() const;
157 CellRef createCell();
158 CellRef getCell( ::sal_Int32 nCol, ::sal_Int32 nRow ) const;
160 void UndoInsertRows( sal_Int32 nIndex, sal_Int32 nCount );
161 void UndoRemoveRows( sal_Int32 nIndex, RowVector& aNewRows );
163 void UndoInsertColumns( sal_Int32 nIndex, sal_Int32 nCount );
164 void UndoRemoveColumns( sal_Int32 nIndex, ColumnVector& aNewCols, CellVector& aCells );
166 private:
167 /** this function is called upon disposing the component
169 virtual void SAL_CALL disposing();
171 TableRowRef getRow( sal_Int32 nRow ) const throw (::com::sun::star::lang::IndexOutOfBoundsException);
172 TableColumnRef getColumn( sal_Int32 nColumn ) const throw (::com::sun::star::lang::IndexOutOfBoundsException);
174 void updateRows();
175 void updateColumns();
177 RowVector maRows;
178 ColumnVector maColumns;
180 TableColumnsRef mxTableColumns;
181 TableRowsRef mxTableRows;
183 SdrTableObj* mpTableObj;
185 sal_Bool mbModified;
186 bool mbNotifyPending;
188 sal_Int32 mnNotifyLock;
191 class TableModelNotifyGuard
193 public:
194 TableModelNotifyGuard( TableModel* pModel )
195 : mxBroadcaster( static_cast< ::com::sun::star::util::XBroadcaster* >( pModel ) )
197 if( mxBroadcaster.is() )
198 mxBroadcaster->lockBroadcasts();
201 TableModelNotifyGuard( ::com::sun::star::uno::XInterface* pInterface )
202 : mxBroadcaster( pInterface, ::com::sun::star::uno::UNO_QUERY )
204 if( mxBroadcaster.is() )
205 mxBroadcaster->lockBroadcasts();
208 ~TableModelNotifyGuard()
210 if( mxBroadcaster.is() )
211 mxBroadcaster->unlockBroadcasts();
214 private:
215 com::sun::star::uno::Reference< ::com::sun::star::util::XBroadcaster > mxBroadcaster;
220 #endif
222 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */