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