LibreOffice Module svx (master) 1
tablemodel.hxx
Go to the documentation of this file.
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>
28#include "celltypes.hxx"
29
30struct _xmlTextWriter;
31typedef struct _xmlTextWriter* xmlTextWriterPtr;
32
33namespace sdr::table {
34
35class SdrTableObj;
36
38class SAL_LOPLUGIN_ANNOTATE("crosscast") ICellRange
39{
40public:
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;
46
47protected:
48 ~ICellRange() {}
49};
50
51typedef ::cppu::WeakComponentImplHelper< css::table::XTable, css::util::XBroadcaster > TableModelBase;
52
53class TableModel final : public ::cppu::BaseMutex,
54 public TableModelBase,
55 public ICellRange
56{
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;
68
69public:
70 explicit TableModel( SdrTableObj* pTableObj );
71 TableModel( SdrTableObj* pTableObj, const TableModelRef& xSourceTable );
72 virtual ~TableModel() override;
73
74 void init( sal_Int32 nColumns, sal_Int32 nRows );
75
77
79 void optimize();
80
82 void merge( sal_Int32 nCol, sal_Int32 nRow, sal_Int32 nColSpan, sal_Int32 nRowSpan );
84 std::vector<sal_Int32> getColumnWidths();
85
86 void dumpAsXml(xmlTextWriterPtr pWriter) const;
87
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;
94
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;
100
101 // XComponent
102 virtual void SAL_CALL dispose( ) override;
103
104 // XModifiable
105 virtual sal_Bool SAL_CALL isModified( ) override;
106 virtual void SAL_CALL setModified( sal_Bool bModified ) override;
107
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;
111
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;
115
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;
120
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;
129
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;
133
134 // XBroadcaster
135 virtual void SAL_CALL lockBroadcasts() override;
136 virtual void SAL_CALL unlockBroadcasts() override;
137
138private:
139 void notifyModification();
140
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 );
145
146 sal_Int32 getRowCountImpl() const;
147 sal_Int32 getColumnCountImpl() const;
148
150 CellRef getCell( ::sal_Int32 nCol, ::sal_Int32 nRow ) const;
151
152 void UndoInsertRows( sal_Int32 nIndex, sal_Int32 nCount );
153 void UndoRemoveRows( sal_Int32 nIndex, RowVector& aNewRows );
154
155 void UndoInsertColumns( sal_Int32 nIndex, sal_Int32 nCount );
156 void UndoRemoveColumns( sal_Int32 nIndex, ColumnVector& aNewCols, CellVector& aCells );
157
158private:
161 virtual void SAL_CALL disposing() override;
162
164 TableRowRef const & getRow( sal_Int32 nRow ) const;
166 TableColumnRef const & getColumn( sal_Int32 nColumn ) const;
167
168 void updateRows();
169 void updateColumns();
170
173
176
177 SdrTableObj* mpTableObj; // TTTT should be reference
178
181
182 sal_Int32 mnNotifyLock;
183};
184
186{
187public:
189 : mxBroadcaster( static_cast< css::util::XBroadcaster* >( pModel ) )
190 {
191 if( mxBroadcaster.is() )
192 mxBroadcaster->lockBroadcasts();
193 }
194
196 {
197 if( mxBroadcaster.is() )
198 mxBroadcaster->unlockBroadcasts();
199 }
200
201private:
202 css::uno::Reference< css::util::XBroadcaster > mxBroadcaster;
203};
204
205}
206
207#endif
208
209/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
TableModelNotifyGuard(TableModel *pModel)
Definition: tablemodel.hxx:188
css::uno::Reference< css::util::XBroadcaster > mxBroadcaster
Definition: tablemodel.hxx:202
SdrTableObj * getSdrTableObj() const
Definition: tablemodel.hxx:76
void insertRows(sal_Int32 nIndex, sal_Int32 nCount)
Definition: tablemodel.cxx:780
virtual void SAL_CALL removePropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &aListener) override
Definition: tablemodel.cxx:445
rtl::Reference< TableRows > mxTableRows
Definition: tablemodel.hxx:175
virtual css::uno::Reference< css::table::XTableColumns > SAL_CALL getColumns() override
Definition: tablemodel.cxx:364
virtual sal_Bool SAL_CALL isModified() override
Definition: tablemodel.cxx:328
void insertColumns(sal_Int32 nIndex, sal_Int32 nCount)
Definition: tablemodel.cxx:590
virtual void SAL_CALL lockBroadcasts() override
Definition: tablemodel.cxx:525
void removeRows(sal_Int32 nIndex, sal_Int32 nCount)
Definition: tablemodel.cxx:842
virtual ::sal_Int32 SAL_CALL getColumnCount() override
Definition: tablemodel.cxx:301
virtual css::uno::Reference< css::table::XCell > SAL_CALL getCellByPosition(::sal_Int32 nColumn, ::sal_Int32 nRow) override
Definition: tablemodel.cxx:387
sal_Int32 getRowCountImpl() const
Definition: tablemodel.cxx:478
virtual css::uno::Any SAL_CALL getFastPropertyValue(::sal_Int32 nHandle) override
Definition: tablemodel.cxx:468
virtual ~TableModel() override
Definition: tablemodel.cxx:142
void init(sal_Int32 nColumns, sal_Int32 nRows)
Definition: tablemodel.cxx:147
virtual sal_Int32 getRight() override
Definition: tablemodel.cxx:184
virtual void SAL_CALL addPropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
Definition: tablemodel.cxx:440
TableColumnRef const & getColumn(sal_Int32 nColumn) const
Definition: tablemodel.cxx:949
virtual void SAL_CALL setFastPropertyValue(::sal_Int32 nHandle, const css::uno::Any &aValue) override
Definition: tablemodel.cxx:463
virtual css::uno::Reference< css::table::XTable > getTable() override
Definition: tablemodel.cxx:196
CellRef getCell(::sal_Int32 nCol, ::sal_Int32 nRow) const
Definition: tablemodel.cxx:567
virtual void SAL_CALL setModified(sal_Bool bModified) override
Definition: tablemodel.cxx:335
virtual css::uno::Reference< css::table::XCellRange > SAL_CALL getCellRangeByPosition(::sal_Int32 nLeft, ::sal_Int32 nTop, ::sal_Int32 nRight, ::sal_Int32 nBottom) override
Definition: tablemodel.cxx:399
virtual css::uno::Reference< css::table::XCellCursor > SAL_CALL createCursorByRange(const css::uno::Reference< css::table::XCellRange > &rRange) override
Definition: tablemodel.cxx:282
SdrTableObj * mpTableObj
Definition: tablemodel.hxx:177
void merge(sal_Int32 nCol, sal_Int32 nRow, sal_Int32 nColSpan, sal_Int32 nRowSpan)
merges the cell at the given position with the given span
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
Definition: tablemodel.cxx:434
ColumnVector maColumns
Definition: tablemodel.hxx:172
virtual css::uno::Reference< css::table::XTableRows > SAL_CALL getRows() override
Definition: tablemodel.cxx:374
virtual void SAL_CALL unlockBroadcasts() override
Definition: tablemodel.cxx:532
virtual sal_Int32 getLeft() override
Definition: tablemodel.cxx:172
virtual css::uno::Reference< css::table::XCellRange > SAL_CALL getCellRangeByName(const OUString &aRange) override
Definition: tablemodel.cxx:413
void UndoInsertColumns(sal_Int32 nIndex, sal_Int32 nCount)
Definition: tablemodel.cxx:229
TableRowRef const & getRow(sal_Int32 nRow) const
Definition: tablemodel.cxx:940
std::vector< sal_Int32 > getColumnWidths()
Get the width of all columns in this table.
Definition: tablemodel.cxx:307
virtual sal_Int32 getBottom() override
Definition: tablemodel.cxx:190
virtual css::uno::Reference< css::table::XCellCursor > SAL_CALL createCursor() override
Definition: tablemodel.cxx:275
virtual void SAL_CALL addVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
Definition: tablemodel.cxx:450
virtual void SAL_CALL removeModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
Definition: tablemodel.cxx:355
virtual void SAL_CALL dispose() override
Definition: tablemodel.cxx:318
virtual sal_Int32 getTop() override
Definition: tablemodel.cxx:178
virtual void SAL_CALL disposing() override
this function is called upon disposing the component
Definition: tablemodel.cxx:490
void removeColumns(sal_Int32 nIndex, sal_Int32 nCount)
Definition: tablemodel.cxx:668
void optimize()
deletes rows and columns that are completely merged.
Definition: tablemodel.cxx:959
virtual void SAL_CALL setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
Definition: tablemodel.cxx:429
virtual void SAL_CALL addModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
Definition: tablemodel.cxx:349
rtl::Reference< TableColumns > mxTableColumns
Definition: tablemodel.hxx:174
TableModel(SdrTableObj *pTableObj)
Definition: tablemodel.cxx:97
void UndoInsertRows(sal_Int32 nIndex, sal_Int32 nCount)
Definition: tablemodel.cxx:202
sal_Int32 getColumnCountImpl() const
Definition: tablemodel.cxx:484
virtual void SAL_CALL removeVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
Definition: tablemodel.cxx:455
void UndoRemoveColumns(sal_Int32 nIndex, ColumnVector &aNewCols, CellVector &aCells)
Definition: tablemodel.cxx:244
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
Definition: tablemodel.cxx:422
virtual ::sal_Int32 SAL_CALL getRowCount() override
Definition: tablemodel.cxx:295
void dumpAsXml(xmlTextWriterPtr pWriter) const
void UndoRemoveRows(sal_Int32 nIndex, RowVector &aNewRows)
Definition: tablemodel.cxx:213
struct _xmlTextWriter * xmlTextWriterPtr
std::vector< CellRef > CellVector
Definition: celltypes.hxx:38
class SAL_LOPLUGIN_ANNOTATE("crosscast") ICellRange
base class for each object implementing an XCellRange
Definition: tablemodel.hxx:38
std::vector< TableColumnRef > ColumnVector
Definition: celltypes.hxx:40
std::vector< TableRowRef > RowVector
Definition: celltypes.hxx:39
::cppu::WeakComponentImplHelper< css::table::XTable, css::util::XBroadcaster > TableModelBase
Definition: tablemodel.hxx:49
struct _xmlTextWriter * xmlTextWriterPtr
Definition: tablemodel.hxx:31
unsigned char sal_Bool