tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / svx / source / inc / tablemodel.hxx
bloba82163f7b874137ef4001a5a19f059d5fd32b1ae
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 <comphelper/compbase.hxx>
27 #include <comphelper/interfacecontainer4.hxx>
28 #include "celltypes.hxx"
29 #include <svx/svxdllapi.h>
31 struct _xmlTextWriter;
32 typedef struct _xmlTextWriter* xmlTextWriterPtr;
34 namespace sdr::table {
36 class SdrTableObj;
38 /** base class for each object implementing an XCellRange */
39 class SAL_LOPLUGIN_ANNOTATE("crosscast") ICellRange
41 public:
42 virtual sal_Int32 getLeft() = 0;
43 virtual sal_Int32 getTop() = 0;
44 virtual sal_Int32 getRight() = 0;
45 virtual sal_Int32 getBottom() = 0;
46 virtual css::uno::Reference< css::table::XTable > getTable() = 0;
48 protected:
49 ~ICellRange() {}
52 typedef ::comphelper::WeakComponentImplHelper< css::table::XTable, css::util::XBroadcaster > TableModelBase;
54 class SVXCORE_DLLPUBLIC TableModel final :
55 public TableModelBase,
56 public ICellRange
58 friend class InsertRowUndo;
59 friend class RemoveRowUndo;
60 friend class InsertColUndo;
61 friend class RemoveColUndo;
62 friend class TableColumnUndo;
63 friend class TableRowUndo;
64 friend class TableColumn;
65 friend class TableRow;
66 friend class TableRows;
67 friend class TableColumns;
68 friend class TableModelNotifyGuard;
70 public:
71 explicit TableModel( SdrTableObj* pTableObj );
72 TableModel( SdrTableObj* pTableObj, const TableModelRef& xSourceTable );
73 virtual ~TableModel() override;
75 void init( sal_Int32 nColumns, sal_Int32 nRows );
77 SdrTableObj* getSdrTableObj() const { return mpTableObj; }
79 /** deletes rows and columns that are completely merged. Must be called between BegUndo/EndUndo! */
80 void optimize();
82 /// merges the cell at the given position with the given span
83 void merge( sal_Int32 nCol, sal_Int32 nRow, sal_Int32 nColSpan, sal_Int32 nRowSpan );
84 /// Get the width of all columns in this table.
85 std::vector<sal_Int32> getColumnWidths();
87 void dumpAsXml(xmlTextWriterPtr pWriter) const;
89 // ICellRange
90 virtual sal_Int32 getLeft() override;
91 virtual sal_Int32 getTop() override;
92 virtual sal_Int32 getRight() override;
93 virtual sal_Int32 getBottom() override;
94 virtual css::uno::Reference< css::table::XTable > getTable() override;
96 // XTable
97 virtual css::uno::Reference< css::table::XCellCursor > SAL_CALL createCursor( ) override;
98 virtual css::uno::Reference< css::table::XCellCursor > SAL_CALL createCursorByRange( const css::uno::Reference< css::table::XCellRange >& rRange ) override;
99 virtual ::sal_Int32 SAL_CALL getRowCount() override;
100 virtual ::sal_Int32 SAL_CALL getColumnCount() override;
102 // XComponent
103 // virtual void disposing(std::unique_lock<std::mutex>& rGuard) override;
105 // XModifiable
106 virtual sal_Bool SAL_CALL isModified( ) override;
107 virtual void SAL_CALL setModified( sal_Bool bModified ) override;
109 // XModifyBroadcaster
110 virtual void SAL_CALL addModifyListener( const css::uno::Reference< css::util::XModifyListener >& aListener ) override;
111 virtual void SAL_CALL removeModifyListener( const css::uno::Reference< css::util::XModifyListener >& aListener ) override;
113 // XColumnRowRange
114 virtual css::uno::Reference< css::table::XTableColumns > SAL_CALL getColumns() override;
115 virtual css::uno::Reference< css::table::XTableRows > SAL_CALL getRows() override;
117 // XCellRange
118 virtual css::uno::Reference< css::table::XCell > SAL_CALL getCellByPosition( ::sal_Int32 nColumn, ::sal_Int32 nRow ) override;
119 virtual css::uno::Reference< css::table::XCellRange > SAL_CALL getCellRangeByPosition( ::sal_Int32 nLeft, ::sal_Int32 nTop, ::sal_Int32 nRight, ::sal_Int32 nBottom ) override;
120 virtual css::uno::Reference< css::table::XCellRange > SAL_CALL getCellRangeByName( const OUString& aRange ) override;
122 // XPropertySet
123 virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override;
124 virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue ) override;
125 virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override;
126 virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener ) override;
127 virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& aListener ) override;
128 virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
129 virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
131 // XFastPropertySet
132 virtual void SAL_CALL setFastPropertyValue( ::sal_Int32 nHandle, const css::uno::Any& aValue ) override;
133 virtual css::uno::Any SAL_CALL getFastPropertyValue( ::sal_Int32 nHandle ) override;
135 // XBroadcaster
136 virtual void SAL_CALL lockBroadcasts() override;
137 virtual void SAL_CALL unlockBroadcasts() override;
139 CellRef getCell( sal_Int32 nCol, sal_Int32 nRow ) const;
141 private:
142 void notifyModification();
144 void insertColumns( sal_Int32 nIndex, sal_Int32 nCount );
145 void removeColumns( sal_Int32 nIndex, sal_Int32 nCount );
146 void insertRows( sal_Int32 nIndex, sal_Int32 nCount );
147 void removeRows( sal_Int32 nIndex, sal_Int32 nCount );
149 sal_Int32 getRowCountImpl() const;
150 sal_Int32 getColumnCountImpl() const;
152 CellRef createCell();
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 disposing(std::unique_lock<std::mutex>& rGuard) 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;
186 comphelper::OInterfaceContainerHelper4<css::util::XModifyListener> maModifyListeners;
189 class TableModelNotifyGuard
191 public:
192 explicit TableModelNotifyGuard( TableModel* pModel )
193 : mxBroadcaster( static_cast< css::util::XBroadcaster* >( pModel ) )
195 if( mxBroadcaster.is() )
196 mxBroadcaster->lockBroadcasts();
199 ~TableModelNotifyGuard()
201 if( mxBroadcaster.is() )
202 mxBroadcaster->unlockBroadcasts();
205 private:
206 css::uno::Reference< css::util::XBroadcaster > mxBroadcaster;
211 #endif
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */