/src/libreoffice/svx/source/inc/tablemodel.hxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | #ifndef INCLUDED_SVX_SOURCE_INC_TABLEMODEL_HXX |
21 | | #define INCLUDED_SVX_SOURCE_INC_TABLEMODEL_HXX |
22 | | |
23 | | #include <sal/types.h> |
24 | | #include <com/sun/star/util/XBroadcaster.hpp> |
25 | | #include <com/sun/star/table/XTable.hpp> |
26 | | #include <comphelper/compbase.hxx> |
27 | | #include <comphelper/interfacecontainer4.hxx> |
28 | | #include "celltypes.hxx" |
29 | | #include <svx/svxdllapi.h> |
30 | | |
31 | | struct _xmlTextWriter; |
32 | | typedef struct _xmlTextWriter* xmlTextWriterPtr; |
33 | | |
34 | | namespace sdr::table { |
35 | | |
36 | | class SdrTableObj; |
37 | | class TableRows; |
38 | | class TableColumns; |
39 | | |
40 | | /** base class for each object implementing an XCellRange */ |
41 | | class SAL_LOPLUGIN_ANNOTATE("crosscast") ICellRange |
42 | | { |
43 | | public: |
44 | | virtual sal_Int32 getLeft() = 0; |
45 | | virtual sal_Int32 getTop() = 0; |
46 | | virtual sal_Int32 getRight() = 0; |
47 | | virtual sal_Int32 getBottom() = 0; |
48 | | virtual css::uno::Reference< css::table::XTable > getTable() = 0; |
49 | | |
50 | | protected: |
51 | 9.28k | ~ICellRange() {} |
52 | | }; |
53 | | |
54 | | typedef ::comphelper::WeakComponentImplHelper< css::table::XTable, css::util::XBroadcaster > TableModelBase; |
55 | | |
56 | | class SVXCORE_DLLPUBLIC TableModel final : |
57 | | public TableModelBase, |
58 | | public ICellRange |
59 | | { |
60 | | friend class InsertRowUndo; |
61 | | friend class RemoveRowUndo; |
62 | | friend class InsertColUndo; |
63 | | friend class RemoveColUndo; |
64 | | friend class TableColumnUndo; |
65 | | friend class TableRowUndo; |
66 | | friend class TableColumn; |
67 | | friend class TableRow; |
68 | | friend class TableRows; |
69 | | friend class TableColumns; |
70 | | friend class TableModelNotifyGuard; |
71 | | |
72 | | public: |
73 | | explicit TableModel( SdrTableObj* pTableObj ); |
74 | | TableModel( SdrTableObj* pTableObj, const TableModelRef& xSourceTable ); |
75 | | virtual ~TableModel() override; |
76 | | |
77 | | void init( sal_Int32 nColumns, sal_Int32 nRows ); |
78 | | |
79 | 44.8k | SdrTableObj* getSdrTableObj() const { return mpTableObj; } |
80 | | |
81 | | /** deletes rows and columns that are completely merged. Must be called between BegUndo/EndUndo! */ |
82 | | void optimize(); |
83 | | |
84 | | /// merges the cell at the given position with the given span |
85 | | void merge( sal_Int32 nCol, sal_Int32 nRow, sal_Int32 nColSpan, sal_Int32 nRowSpan ); |
86 | | /// Get the width of all columns in this table. |
87 | | std::vector<sal_Int32> getColumnWidths(); |
88 | | |
89 | | void dumpAsXml(xmlTextWriterPtr pWriter) const; |
90 | | |
91 | | // ICellRange |
92 | | virtual sal_Int32 getLeft() override; |
93 | | virtual sal_Int32 getTop() override; |
94 | | virtual sal_Int32 getRight() override; |
95 | | virtual sal_Int32 getBottom() override; |
96 | | virtual css::uno::Reference< css::table::XTable > getTable() override; |
97 | | |
98 | | // XTable |
99 | | virtual css::uno::Reference< css::table::XCellCursor > SAL_CALL createCursor( ) override; |
100 | | virtual css::uno::Reference< css::table::XCellCursor > SAL_CALL createCursorByRange( const css::uno::Reference< css::table::XCellRange >& rRange ) override; |
101 | | virtual ::sal_Int32 SAL_CALL getRowCount() override; |
102 | | virtual ::sal_Int32 SAL_CALL getColumnCount() override; |
103 | | |
104 | | // XComponent |
105 | | // virtual void disposing(std::unique_lock<std::mutex>& rGuard) override; |
106 | | |
107 | | // XModifiable |
108 | | virtual sal_Bool SAL_CALL isModified( ) override; |
109 | | virtual void SAL_CALL setModified( sal_Bool bModified ) override; |
110 | | |
111 | | // XModifyBroadcaster |
112 | | virtual void SAL_CALL addModifyListener( const css::uno::Reference< css::util::XModifyListener >& aListener ) override; |
113 | | virtual void SAL_CALL removeModifyListener( const css::uno::Reference< css::util::XModifyListener >& aListener ) override; |
114 | | |
115 | | // XColumnRowRange |
116 | | virtual css::uno::Reference< css::table::XTableColumns > SAL_CALL getColumns() override; |
117 | | virtual css::uno::Reference< css::table::XTableRows > SAL_CALL getRows() override; |
118 | | |
119 | | // XCellRange |
120 | | virtual css::uno::Reference< css::table::XCell > SAL_CALL getCellByPosition( ::sal_Int32 nColumn, ::sal_Int32 nRow ) override; |
121 | | virtual css::uno::Reference< css::table::XCellRange > SAL_CALL getCellRangeByPosition( ::sal_Int32 nLeft, ::sal_Int32 nTop, ::sal_Int32 nRight, ::sal_Int32 nBottom ) override; |
122 | | virtual css::uno::Reference< css::table::XCellRange > SAL_CALL getCellRangeByName( const OUString& aRange ) override; |
123 | | |
124 | | // XPropertySet |
125 | | virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override; |
126 | | virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue ) override; |
127 | | virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override; |
128 | | virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener ) override; |
129 | | virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& aListener ) override; |
130 | | virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override; |
131 | | virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override; |
132 | | |
133 | | // XFastPropertySet |
134 | | virtual void SAL_CALL setFastPropertyValue( ::sal_Int32 nHandle, const css::uno::Any& aValue ) override; |
135 | | virtual css::uno::Any SAL_CALL getFastPropertyValue( ::sal_Int32 nHandle ) override; |
136 | | |
137 | | // XBroadcaster |
138 | | virtual void SAL_CALL lockBroadcasts() override; |
139 | | virtual void SAL_CALL unlockBroadcasts() override; |
140 | | |
141 | | CellRef getCell( sal_Int32 nCol, sal_Int32 nRow ) const; |
142 | | |
143 | | private: |
144 | | void notifyModification(); |
145 | | |
146 | | void insertColumns( sal_Int32 nIndex, sal_Int32 nCount ); |
147 | | void removeColumns( sal_Int32 nIndex, sal_Int32 nCount ); |
148 | | void insertRows( sal_Int32 nIndex, sal_Int32 nCount ); |
149 | | void removeRows( sal_Int32 nIndex, sal_Int32 nCount ); |
150 | | |
151 | | sal_Int32 getRowCountImpl() const; |
152 | | sal_Int32 getColumnCountImpl() const; |
153 | | |
154 | | CellRef createCell(); |
155 | | |
156 | | void UndoInsertRows( sal_Int32 nIndex, sal_Int32 nCount ); |
157 | | void UndoRemoveRows( sal_Int32 nIndex, RowVector& aNewRows ); |
158 | | |
159 | | void UndoInsertColumns( sal_Int32 nIndex, sal_Int32 nCount ); |
160 | | void UndoRemoveColumns( sal_Int32 nIndex, ColumnVector& aNewCols, CellVector& aCells ); |
161 | | |
162 | | private: |
163 | | /** this function is called upon disposing the component |
164 | | */ |
165 | | virtual void disposing(std::unique_lock<std::mutex>& rGuard) override; |
166 | | |
167 | | /// @throws css::lang::IndexOutOfBoundsException |
168 | | TableRowRef const & getRow( sal_Int32 nRow ) const; |
169 | | /// @throws css::lang::IndexOutOfBoundsException |
170 | | TableColumnRef const & getColumn( sal_Int32 nColumn ) const; |
171 | | |
172 | | void updateRows(); |
173 | | void updateColumns(); |
174 | | |
175 | | RowVector maRows; |
176 | | ColumnVector maColumns; |
177 | | |
178 | | rtl::Reference< TableColumns > mxTableColumns; |
179 | | rtl::Reference< TableRows > mxTableRows; |
180 | | |
181 | | SdrTableObj* mpTableObj; // TTTT should be reference |
182 | | |
183 | | bool mbModified; |
184 | | bool mbNotifyPending; |
185 | | |
186 | | sal_Int32 mnNotifyLock; |
187 | | |
188 | | comphelper::OInterfaceContainerHelper4<css::util::XModifyListener> maModifyListeners; |
189 | | }; |
190 | | |
191 | | class TableModelNotifyGuard |
192 | | { |
193 | | public: |
194 | | explicit TableModelNotifyGuard( TableModel* pModel ) |
195 | 9.81k | : mxBroadcaster( static_cast< css::util::XBroadcaster* >( pModel ) ) |
196 | 9.81k | { |
197 | 9.81k | if( mxBroadcaster.is() ) |
198 | 9.81k | mxBroadcaster->lockBroadcasts(); |
199 | 9.81k | } |
200 | | |
201 | | ~TableModelNotifyGuard() |
202 | 9.81k | { |
203 | 9.81k | if( mxBroadcaster.is() ) |
204 | 9.81k | mxBroadcaster->unlockBroadcasts(); |
205 | 9.81k | } |
206 | | |
207 | | private: |
208 | | css::uno::Reference< css::util::XBroadcaster > mxBroadcaster; |
209 | | }; |
210 | | |
211 | | } |
212 | | |
213 | | #endif |
214 | | |
215 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |