lok: vcl: fix multiple floatwin removal case more robustly.
[LibreOffice.git] / writerfilter / source / dmapper / TableData.hxx
blob8381a989912561eed86c35fac5c3999e3890fedc
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_WRITERFILTER_SOURCE_DMAPPER_TABLEDATA_HXX
21 #define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_TABLEDATA_HXX
23 #include <dmapper/resourcemodel.hxx>
25 #include <vector>
26 #include <memory>
28 namespace writerfilter
30 namespace dmapper
33 /**
34 Class containing the data to describe a table cell.
36 class CellData final : public virtual SvRefBase
38 /**
39 Handle to start of cell.
41 css::uno::Reference<css::text::XTextRange> mStart;
43 /**
44 Handle to end of cell.
46 css::uno::Reference<css::text::XTextRange> mEnd;
48 /**
49 Pointer to properties of cell.
51 TablePropertyMapPtr mpProps;
53 bool mbOpen;
55 public:
56 typedef tools::SvRef<CellData> Pointer_t;
58 CellData(css::uno::Reference<css::text::XTextRange> const & start, TablePropertyMapPtr pProps)
59 : mStart(start), mEnd(start), mpProps(pProps), mbOpen(true)
63 /**
64 Set the end handle of a cell.
66 @param end the end handle of the cell
68 void setEnd(css::uno::Reference<css::text::XTextRange> const & end) { mEnd = end; mbOpen = false; }
70 /**
71 Adds properties to the cell.
73 @param pProps the properties to add
75 void insertProperties(TablePropertyMapPtr pProps)
77 if( mpProps.get() )
78 mpProps->InsertProps(pProps.get());
79 else
80 mpProps = pProps;
83 /**
84 Return start handle of the cell.
86 const css::uno::Reference<css::text::XTextRange>& getStart() { return mStart; }
88 /**
89 Return end handle of the cell.
91 const css::uno::Reference<css::text::XTextRange>& getEnd() { return mEnd; }
93 /**
94 Return properties of the cell.
96 const TablePropertyMapPtr& getProperties() { return mpProps; }
98 bool isOpen() const { return mbOpen; }
102 Class to handle data of a table row.
104 class RowData final : public virtual SvRefBase
106 typedef ::std::vector<CellData::Pointer_t> Cells;
109 the cell data of the row
111 Cells mCells;
114 the properties of the row
116 mutable TablePropertyMapPtr mpProperties;
118 public:
119 typedef tools::SvRef<RowData> Pointer_t;
121 RowData() {}
123 RowData(const RowData& rRowData)
124 : SvRefBase(), mCells(rRowData.mCells), mpProperties(rRowData.mpProperties)
129 Add a cell to the row.
131 @param start the start handle of the cell
132 @param end the end handle of the cell
133 @param pProps the properties of the cell
135 void addCell(const css::uno::Reference<css::text::XTextRange>& start, TablePropertyMapPtr pProps)
137 CellData::Pointer_t pCellData(new CellData(start, pProps));
138 mCells.push_back(pCellData);
141 void endCell(const css::uno::Reference<css::text::XTextRange>& end)
143 if (mCells.size() > 0)
144 mCells.back()->setEnd(end);
147 bool isCellOpen() const
149 return mCells.size() > 0 && mCells.back()->isOpen();
153 Add properties to the row.
155 @param pProperties the properties to set
157 void insertProperties(TablePropertyMapPtr pProperties)
159 if( pProperties.get() )
161 if( !mpProperties.get() )
162 mpProperties = pProperties;
163 else
164 mpProperties->InsertProps(pProperties.get());
169 Add properties to the last cell of the row.
171 void insertCellProperties(TablePropertyMapPtr pProps)
173 if (!mCells.empty())
174 mCells.back()->insertProperties(pProps);
178 Return number of cells in the row.
180 unsigned int getCellCount()
182 return mCells.size();
186 Return start handle of a cell in the row.
188 @param i index of the cell
190 const css::uno::Reference<css::text::XTextRange>& getCellStart(unsigned int i) const
192 return mCells[i]->getStart();
196 Return end handle of a cell in the row.
198 @param i index of the cell
200 const css::uno::Reference<css::text::XTextRange>& getCellEnd(unsigned int i) const
202 return mCells[i]->getEnd();
206 Return the properties of a cell in the row.
208 @param i index of the cell
210 TablePropertyMapPtr const & getCellProperties(unsigned int i) const
212 return mCells[i]->getProperties();
216 Return properties of the row.
218 const TablePropertyMapPtr& getProperties()
220 return mpProperties;
225 Class that holds the data of a table.
227 class TableData : public virtual SvRefBase
229 typedef RowData::Pointer_t RowPointer_t;
230 typedef ::std::vector<RowPointer_t> Rows;
233 the data of the rows of the table
235 Rows mRows;
238 pointer to the data of the current row (while building up the table data).
240 RowPointer_t mpRow;
243 depth of the current table in a hierarchy of tables
245 unsigned int const mnDepth;
248 initialize mpRow
250 void newRow() { mpRow = RowPointer_t(new RowData()); }
252 public:
253 typedef tools::SvRef<TableData> Pointer_t;
255 explicit TableData(unsigned int nDepth) : mnDepth(nDepth) { newRow(); }
258 End the current row.
260 Sets properties of the current row and pushes the row to the
261 back of the rows currently contained in the table.
263 @param pProperties properties of the row to be ended
265 void endRow(TablePropertyMapPtr pProperties)
267 mpRow->insertProperties(pProperties);
268 mRows.push_back(mpRow);
269 newRow();
273 Add a cell to the current row.
275 @param start start handle of the cell
276 @param end end handle of the cell
277 @param pProps properties of the cell
279 void addCell(const css::uno::Reference<css::text::XTextRange>& start, TablePropertyMapPtr pProps)
281 mpRow->addCell(start, pProps);
285 End the current cell of the current row.
287 @parm end end handle of the cell
289 void endCell(const css::uno::Reference<css::text::XTextRange>& end)
291 mpRow->endCell(end);
295 Return if the current cell of the current row is open.
297 bool isCellOpen() const
299 return mpRow->isCellOpen();
303 Insert properties to the current cell of the current row.
305 @param pProps the properties to add
307 void insertCellProperties(TablePropertyMapPtr pProps)
309 mpRow->insertCellProperties(pProps);
313 Return number of rows in the table.
315 unsigned int getRowCount()
317 return mRows.size();
321 Return depth of table in surrounding table hierarchy.
323 unsigned int getDepth()
325 return mnDepth;
329 Return row data of a certain row.
331 @param i index of the row
333 RowPointer_t const & getRow(unsigned int i) const
335 return mRows[i];
338 const RowPointer_t& getCurrentRow() const
340 return mpRow;
347 #endif // INCLUDED_WRITERFILTER_SOURCE_DMAPPER_RESOURCEMODEL_TABLEDATA_HXX
349 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */