Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / inc / tablemodel.hxx
blob7a2cf4851c7e57c90f320bea9075ec59ca74af8c
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 INCLUDED_SVX_SOURCE_INC_TABLEMODEL_HXX
21 #define INCLUDED_SVX_SOURCE_INC_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 <cppuhelper/compbase.hxx>
27 #include <cppuhelper/basemutex.hxx>
28 #include "celltypes.hxx"
30 struct _xmlTextWriter;
31 typedef struct _xmlTextWriter* xmlTextWriterPtr;
33 namespace sdr::table {
35 class SdrTableObj;
37 /** base class for each object implementing an XCellRange */
38 class SAL_LOPLUGIN_ANNOTATE("crosscast") ICellRange
40 public:
41 virtual sal_Int32 getLeft() = 0;
42 virtual sal_Int32 getTop() = 0;
43 virtual sal_Int32 getRight() = 0;
44 virtual sal_Int32 getBottom() = 0;
45 virtual css::uno::Reference< css::table::XTable > getTable() = 0;
47 protected:
48 ~ICellRange() {}
51 typedef ::cppu::WeakComponentImplHelper< css::table::XTable, css::util::XBroadcaster > TableModelBase;
53 class TableModel final : public ::cppu::BaseMutex,
54 public TableModelBase,
55 public ICellRange
57 friend class InsertRowUndo;
58 friend class RemoveRowUndo;
59 friend class InsertColUndo;
60 friend class RemoveColUndo;
61 friend class TableColumnUndo;
62 friend class TableRowUndo;
63 friend class TableColumn;
64 friend class TableRow;
65 friend class TableRows;
66 friend class TableColumns;
67 friend class TableModelNotifyGuard;
69 public:
70 explicit TableModel( SdrTableObj* pTableObj );
71 TableModel( SdrTableObj* pTableObj, const TableModelRef& xSourceTable );
72 virtual ~TableModel() override;
74 void init( sal_Int32 nColumns, sal_Int32 nRows );
76 SdrTableObj* getSdrTableObj() const { return mpTableObj; }
78 /** deletes rows and columns that are completely merged. Must be called between BegUndo/EndUndo! */
79 void optimize();
81 /// merges the cell at the given position with the given span
82 void merge( sal_Int32 nCol, sal_Int32 nRow, sal_Int32 nColSpan, sal_Int32 nRowSpan );
83 /// Get the width of all columns in this table.
84 std::vector<sal_Int32> getColumnWidths();
86 void dumpAsXml(xmlTextWriterPtr pWriter) const;
88 // ICellRange
89 virtual sal_Int32 getLeft() override;
90 virtual sal_Int32 getTop() override;
91 virtual sal_Int32 getRight() override;
92 virtual sal_Int32 getBottom() override;
93 virtual css::uno::Reference< css::table::XTable > getTable() override;
95 // XTable
96 virtual css::uno::Reference< css::table::XCellCursor > SAL_CALL createCursor( ) override;
97 virtual css::uno::Reference< css::table::XCellCursor > SAL_CALL createCursorByRange( const css::uno::Reference< css::table::XCellRange >& rRange ) override;
98 virtual ::sal_Int32 SAL_CALL getRowCount() override;
99 virtual ::sal_Int32 SAL_CALL getColumnCount() override;
101 // XComponent
102 virtual void SAL_CALL dispose( ) override;
104 // XModifiable
105 virtual sal_Bool SAL_CALL isModified( ) override;
106 virtual void SAL_CALL setModified( sal_Bool bModified ) override;
108 // XModifyBroadcaster
109 virtual void SAL_CALL addModifyListener( const css::uno::Reference< css::util::XModifyListener >& aListener ) override;
110 virtual void SAL_CALL removeModifyListener( const css::uno::Reference< css::util::XModifyListener >& aListener ) override;
112 // XColumnRowRange
113 virtual css::uno::Reference< css::table::XTableColumns > SAL_CALL getColumns() override;
114 virtual css::uno::Reference< css::table::XTableRows > SAL_CALL getRows() override;
116 // XCellRange
117 virtual css::uno::Reference< css::table::XCell > SAL_CALL getCellByPosition( ::sal_Int32 nColumn, ::sal_Int32 nRow ) override;
118 virtual css::uno::Reference< css::table::XCellRange > SAL_CALL getCellRangeByPosition( ::sal_Int32 nLeft, ::sal_Int32 nTop, ::sal_Int32 nRight, ::sal_Int32 nBottom ) override;
119 virtual css::uno::Reference< css::table::XCellRange > SAL_CALL getCellRangeByName( const OUString& aRange ) override;
121 // XPropertySet
122 virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override;
123 virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue ) override;
124 virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override;
125 virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener ) override;
126 virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& aListener ) override;
127 virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
128 virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
130 // XFastPropertySet
131 virtual void SAL_CALL setFastPropertyValue( ::sal_Int32 nHandle, const css::uno::Any& aValue ) override;
132 virtual css::uno::Any SAL_CALL getFastPropertyValue( ::sal_Int32 nHandle ) override;
134 // XBroadcaster
135 virtual void SAL_CALL lockBroadcasts() override;
136 virtual void SAL_CALL unlockBroadcasts() override;
138 private:
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 );
158 private:
159 /** this function is called upon disposing the component
161 virtual void SAL_CALL disposing() override;
163 /// @throws css::lang::IndexOutOfBoundsException
164 TableRowRef const & getRow( sal_Int32 nRow ) const;
165 /// @throws css::lang::IndexOutOfBoundsException
166 TableColumnRef const & getColumn( sal_Int32 nColumn ) const;
168 void updateRows();
169 void updateColumns();
171 RowVector maRows;
172 ColumnVector maColumns;
174 rtl::Reference< TableColumns > mxTableColumns;
175 rtl::Reference< TableRows > mxTableRows;
177 SdrTableObj* mpTableObj; // TTTT should be reference
179 bool mbModified;
180 bool mbNotifyPending;
182 sal_Int32 mnNotifyLock;
185 class TableModelNotifyGuard
187 public:
188 explicit TableModelNotifyGuard( TableModel* pModel )
189 : mxBroadcaster( static_cast< css::util::XBroadcaster* >( pModel ) )
191 if( mxBroadcaster.is() )
192 mxBroadcaster->lockBroadcasts();
195 ~TableModelNotifyGuard()
197 if( mxBroadcaster.is() )
198 mxBroadcaster->unlockBroadcasts();
201 private:
202 css::uno::Reference< css::util::XBroadcaster > mxBroadcaster;
207 #endif
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */