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>
26 #include <cppuhelper/compbase.hxx>
27 #include <cppuhelper/basemutex.hxx>
28 #include "celltypes.hxx"
29 
30 struct _xmlTextWriter;
31 typedef struct _xmlTextWriter* xmlTextWriterPtr;
32 
33 namespace sdr { namespace table {
34 
35 class SdrTableObj;
36 
39 {
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;
46 
47 protected:
49 };
50 
51 typedef ::cppu::WeakComponentImplHelper< css::table::XTable, css::util::XBroadcaster > TableModelBase;
52 
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;
67  friend class TableModelNotifyGuard;
68 
69 public:
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 
76  SdrTableObj* getSdrTableObj() const { return mpTableObj; }
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 
138 protected:
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 
158 private:
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 {
187 public:
188  explicit TableModelNotifyGuard( TableModel* pModel )
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 
201 private:
202  css::uno::Reference< css::util::XBroadcaster > mxBroadcaster;
203 };
204 
205 } }
206 
207 #endif
208 
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::vector< TableRowRef > RowVector
Definition: celltypes.hxx:39
struct _xmlTextWriter * xmlTextWriterPtr
void removeRows(sal_Int32 nIndex, sal_Int32 nCount)
Definition: tablemodel.cxx:842
void UndoRemoveRows(sal_Int32 nIndex, RowVector &aNewRows)
Definition: tablemodel.cxx:218
void UndoInsertColumns(sal_Int32 nIndex, sal_Int32 nCount)
Definition: tablemodel.cxx:234
TableModelNotifyGuard(TableModel *pModel)
Definition: tablemodel.hxx:188
void optimize()
deletes rows and columns that are completely merged.
Definition: tablemodel.cxx:955
virtual css::uno::Reference< css::table::XCellCursor > SAL_CALL createCursorByRange(const css::uno::Reference< css::table::XCellRange > &rRange) override
Definition: tablemodel.cxx:287
virtual void SAL_CALL setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
Definition: tablemodel.cxx:434
void UndoRemoveColumns(sal_Int32 nIndex, ColumnVector &aNewCols, CellVector &aCells)
Definition: tablemodel.cxx:249
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::Reference< css::table::XTable > getTable()=0
virtual ::sal_Int32 SAL_CALL getColumnCount() override
Definition: tablemodel.cxx:306
virtual ~TableModel() override
Definition: tablemodel.cxx:147
virtual sal_Int32 getTop() override
Definition: tablemodel.cxx:183
virtual sal_Bool SAL_CALL isModified() override
Definition: tablemodel.cxx:333
sal_Int32 getColumnCountImpl() const
Definition: tablemodel.cxx:489
virtual void SAL_CALL setModified(sal_Bool bModified) override
Definition: tablemodel.cxx:340
virtual void SAL_CALL unlockBroadcasts() override
Definition: tablemodel.cxx:537
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
Definition: tablemodel.cxx:439
void removeColumns(sal_Int32 nIndex, sal_Int32 nCount)
Definition: tablemodel.cxx:673
css::uno::Reference< css::util::XBroadcaster > mxBroadcaster
Definition: tablemodel.hxx:202
std::vector< TableColumnRef > ColumnVector
Definition: celltypes.hxx:40
virtual css::uno::Reference< css::table::XTableColumns > SAL_CALL getColumns() override
Definition: tablemodel.cxx:369
sal_Int32 getRowCountImpl() const
Definition: tablemodel.cxx:483
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:404
std::vector< sal_Int32 > getColumnWidths()
Get the width of all columns in this table.
Definition: tablemodel.cxx:312
CellRef getCell(::sal_Int32 nCol,::sal_Int32 nRow) const
Definition: tablemodel.cxx:572
void UndoInsertRows(sal_Int32 nIndex, sal_Int32 nCount)
Definition: tablemodel.cxx:207
rtl::Reference< TableColumns > mxTableColumns
Definition: tablemodel.hxx:174
TableColumnRef const & getColumn(sal_Int32 nColumn) const
Definition: tablemodel.cxx:945
std::vector< CellRef > CellVector
Definition: celltypes.hxx:38
unsigned char sal_Bool
virtual sal_Int32 getLeft() override
Definition: tablemodel.cxx:177
TableRowRef const & getRow(sal_Int32 nRow) const
Definition: tablemodel.cxx:936
virtual void SAL_CALL addVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
Definition: tablemodel.cxx:455
TableModel(SdrTableObj *pTableObj)
Definition: tablemodel.cxx:102
rtl::Reference< TableRows > mxTableRows
Definition: tablemodel.hxx:175
void init(sal_Int32 nColumns, sal_Int32 nRows)
Definition: tablemodel.cxx:152
void insertColumns(sal_Int32 nIndex, sal_Int32 nCount)
Definition: tablemodel.cxx:595
virtual sal_Int32 getRight()=0
virtual sal_Int32 getRight() override
Definition: tablemodel.cxx:189
virtual css::uno::Any SAL_CALL getFastPropertyValue(::sal_Int32 nHandle) override
Definition: tablemodel.cxx:473
virtual sal_Int32 getBottom() override
Definition: tablemodel.cxx:195
virtual void SAL_CALL dispose() override
Definition: tablemodel.cxx:323
ColumnVector maColumns
Definition: tablemodel.hxx:172
virtual ::sal_Int32 SAL_CALL getRowCount() override
Definition: tablemodel.cxx:300
void insertRows(sal_Int32 nIndex, sal_Int32 nCount)
Definition: tablemodel.cxx:780
virtual void SAL_CALL lockBroadcasts() override
Definition: tablemodel.cxx:530
virtual void SAL_CALL removePropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &aListener) override
Definition: tablemodel.cxx:450
virtual void SAL_CALL removeModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
Definition: tablemodel.cxx:360
virtual void SAL_CALL addModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
Definition: tablemodel.cxx:354
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
Definition: tablemodel.cxx:427
virtual css::uno::Reference< css::table::XTableRows > SAL_CALL getRows() override
Definition: tablemodel.cxx:379
virtual css::uno::Reference< css::table::XTable > getTable() override
Definition: tablemodel.cxx:201
::cppu::WeakComponentImplHelper< css::table::XTable, css::util::XBroadcaster > TableModelBase
Definition: tablemodel.hxx:51
virtual void SAL_CALL removeVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
Definition: tablemodel.cxx:460
virtual css::uno::Reference< css::table::XCellRange > SAL_CALL getCellRangeByName(const OUString &aRange) override
Definition: tablemodel.cxx:418
SdrTableObj * getSdrTableObj() const
Definition: tablemodel.hxx:76
virtual sal_Int32 getLeft()=0
virtual void SAL_CALL disposing() override
this function is called upon disposing the component
Definition: tablemodel.cxx:495
virtual sal_Int32 getBottom()=0
SdrTableObj * mpTableObj
Definition: tablemodel.hxx:177
virtual void SAL_CALL setFastPropertyValue(::sal_Int32 nHandle, const css::uno::Any &aValue) override
Definition: tablemodel.cxx:468
virtual css::uno::Reference< css::table::XCellCursor > SAL_CALL createCursor() override
Definition: tablemodel.cxx:280
virtual void SAL_CALL addPropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
Definition: tablemodel.cxx:445
base class for each object implementing an XCellRange
Definition: tablemodel.hxx:38
virtual sal_Int32 getTop()=0
void dumpAsXml(xmlTextWriterPtr pWriter) const
virtual css::uno::Reference< css::table::XCell > SAL_CALL getCellByPosition(::sal_Int32 nColumn,::sal_Int32 nRow) override
Definition: tablemodel.cxx:392
struct _xmlTextWriter * xmlTextWriterPtr
Definition: tablemodel.hxx:31