Bump version to 6.4-15
[LibreOffice.git] / svx / source / inc / tablemodel.hxx
blob78aabc51f692a1c14dfbd4cc43d75f8aca747c1d
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 <basegfx/range/b2irectangle.hxx>
27 #include <basegfx/tuple/b2ituple.hxx>
28 #include <cppuhelper/compbase.hxx>
29 #include <cppuhelper/basemutex.hxx>
30 #include "celltypes.hxx"
32 struct _xmlTextWriter;
33 typedef struct _xmlTextWriter* xmlTextWriterPtr;
35 namespace sdr { namespace table {
37 class SdrTableObj;
39 /** base class for each object implementing an XCellRange */
40 class ICellRange
42 public:
43 virtual sal_Int32 getLeft() = 0;
44 virtual sal_Int32 getTop() = 0;
45 virtual sal_Int32 getRight() = 0;
46 virtual sal_Int32 getBottom() = 0;
47 virtual css::uno::Reference< css::table::XTable > getTable() = 0;
49 protected:
50 ~ICellRange() {}
53 typedef ::cppu::WeakComponentImplHelper< css::table::XTable, css::util::XBroadcaster > TableModelBase;
55 class TableModel : public ::cppu::BaseMutex,
56 public TableModelBase,
57 public ICellRange
59 friend class InsertRowUndo;
60 friend class RemoveRowUndo;
61 friend class InsertColUndo;
62 friend class RemoveColUndo;
63 friend class TableColumnUndo;
64 friend class TableRowUndo;
65 friend class TableColumn;
66 friend class TableRow;
67 friend class TableRows;
68 friend class TableColumns;
69 friend class TableModelNotifyGuard;
71 public:
72 explicit TableModel( SdrTableObj* pTableObj );
73 TableModel( SdrTableObj* pTableObj, const TableModelRef& xSourceTable );
74 virtual ~TableModel() override;
76 void init( sal_Int32 nColumns, sal_Int32 nRows );
78 SdrTableObj* getSdrTableObj() const { return mpTableObj; }
80 /** deletes rows and columns that are completely merged. Must be called between BegUndo/EndUndo! */
81 void optimize();
83 /// merges the cell at the given position with the given span
84 void merge( sal_Int32 nCol, sal_Int32 nRow, sal_Int32 nColSpan, sal_Int32 nRowSpan );
85 /// Get the width of all columns in this table.
86 std::vector<sal_Int32> getColumnWidths();
88 void dumpAsXml(xmlTextWriterPtr pWriter) const;
90 // ICellRange
91 virtual sal_Int32 getLeft() override;
92 virtual sal_Int32 getTop() override;
93 virtual sal_Int32 getRight() override;
94 virtual sal_Int32 getBottom() override;
95 virtual css::uno::Reference< css::table::XTable > getTable() override;
97 // XTable
98 virtual css::uno::Reference< css::table::XCellCursor > SAL_CALL createCursor( ) override;
99 virtual css::uno::Reference< css::table::XCellCursor > SAL_CALL createCursorByRange( const css::uno::Reference< css::table::XCellRange >& rRange ) override;
100 virtual ::sal_Int32 SAL_CALL getRowCount() override;
101 virtual ::sal_Int32 SAL_CALL getColumnCount() override;
103 // XComponent
104 virtual void SAL_CALL dispose( ) override;
106 // XModifiable
107 virtual sal_Bool SAL_CALL isModified( ) override;
108 virtual void SAL_CALL setModified( sal_Bool bModified ) override;
110 // XModifyBroadcaster
111 virtual void SAL_CALL addModifyListener( const css::uno::Reference< css::util::XModifyListener >& aListener ) override;
112 virtual void SAL_CALL removeModifyListener( const css::uno::Reference< css::util::XModifyListener >& aListener ) override;
114 // XColumnRowRange
115 virtual css::uno::Reference< css::table::XTableColumns > SAL_CALL getColumns() override;
116 virtual css::uno::Reference< css::table::XTableRows > SAL_CALL getRows() override;
118 // XCellRange
119 virtual css::uno::Reference< css::table::XCell > SAL_CALL getCellByPosition( ::sal_Int32 nColumn, ::sal_Int32 nRow ) override;
120 virtual css::uno::Reference< css::table::XCellRange > SAL_CALL getCellRangeByPosition( ::sal_Int32 nLeft, ::sal_Int32 nTop, ::sal_Int32 nRight, ::sal_Int32 nBottom ) override;
121 virtual css::uno::Reference< css::table::XCellRange > SAL_CALL getCellRangeByName( const OUString& aRange ) override;
123 // XPropertySet
124 virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override;
125 virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue ) override;
126 virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override;
127 virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener ) override;
128 virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& aListener ) override;
129 virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
130 virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
132 // XFastPropertySet
133 virtual void SAL_CALL setFastPropertyValue( ::sal_Int32 nHandle, const css::uno::Any& aValue ) override;
134 virtual css::uno::Any SAL_CALL getFastPropertyValue( ::sal_Int32 nHandle ) override;
136 // XBroadcaster
137 virtual void SAL_CALL lockBroadcasts() override;
138 virtual void SAL_CALL unlockBroadcasts() override;
140 protected:
141 void notifyModification();
143 void insertColumns( sal_Int32 nIndex, sal_Int32 nCount );
144 void removeColumns( sal_Int32 nIndex, sal_Int32 nCount );
145 void insertRows( sal_Int32 nIndex, sal_Int32 nCount );
146 void removeRows( sal_Int32 nIndex, sal_Int32 nCount );
148 sal_Int32 getRowCountImpl() const;
149 sal_Int32 getColumnCountImpl() const;
151 CellRef createCell();
152 CellRef getCell( ::sal_Int32 nCol, ::sal_Int32 nRow ) const;
154 void UndoInsertRows( sal_Int32 nIndex, sal_Int32 nCount );
155 void UndoRemoveRows( sal_Int32 nIndex, RowVector& aNewRows );
157 void UndoInsertColumns( sal_Int32 nIndex, sal_Int32 nCount );
158 void UndoRemoveColumns( sal_Int32 nIndex, ColumnVector& aNewCols, CellVector& aCells );
160 private:
161 /** this function is called upon disposing the component
163 virtual void SAL_CALL disposing() override;
165 /// @throws css::lang::IndexOutOfBoundsException
166 TableRowRef const & getRow( sal_Int32 nRow ) const;
167 /// @throws css::lang::IndexOutOfBoundsException
168 TableColumnRef const & getColumn( sal_Int32 nColumn ) const;
170 void updateRows();
171 void updateColumns();
173 RowVector maRows;
174 ColumnVector maColumns;
176 rtl::Reference< TableColumns > mxTableColumns;
177 rtl::Reference< TableRows > mxTableRows;
179 SdrTableObj* mpTableObj; // TTTT should be reference
181 bool mbModified;
182 bool mbNotifyPending;
184 sal_Int32 mnNotifyLock;
187 class TableModelNotifyGuard
189 public:
190 explicit TableModelNotifyGuard( TableModel* pModel )
191 : mxBroadcaster( static_cast< css::util::XBroadcaster* >( pModel ) )
193 if( mxBroadcaster.is() )
194 mxBroadcaster->lockBroadcasts();
197 ~TableModelNotifyGuard()
199 if( mxBroadcaster.is() )
200 mxBroadcaster->unlockBroadcasts();
203 private:
204 css::uno::Reference< css::util::XBroadcaster > mxBroadcaster;
209 #endif
211 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */