LibreOffice Module writerfilter (master) 1
TableData.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#pragma once
21
22#include <com/sun/star/text/XTextRange.hpp>
23
24#include "PropertyMap.hxx"
25
26#include <utility>
27#include <vector>
28
30{
31
35class CellData final : public virtual SvRefBase
36{
40 css::uno::Reference<css::text::XTextRange> mStart;
41
45 css::uno::Reference<css::text::XTextRange> mEnd;
46
51
52 bool mbOpen;
53
54 sal_uInt32 m_nGridSpan;
55
56public:
58
59 CellData(css::uno::Reference<css::text::XTextRange> const & start, TablePropertyMapPtr pProps)
60 : mStart(start), mEnd(start), mpProps(std::move(pProps)), mbOpen(true)
61 , m_nGridSpan(1)
62 {
63 }
64
70 void setEnd(css::uno::Reference<css::text::XTextRange> const & end) { mEnd = end; mbOpen = false; }
71
78 {
79 if( mpProps )
80 mpProps->InsertProps(pProps.get());
81 else
82 mpProps = pProps;
83 }
84
88 const css::uno::Reference<css::text::XTextRange>& getStart() const { return mStart; }
89
93 const css::uno::Reference<css::text::XTextRange>& getEnd() const { return mEnd; }
94
98 const TablePropertyMapPtr& getProperties() const { return mpProps; }
99
100 bool isOpen() const { return mbOpen; }
101
102 sal_uInt32 getGridSpan() const { return m_nGridSpan; }
103 void setGridSpan( sal_uInt32 nSpan ) { m_nGridSpan = nSpan; }
104};
105
109class RowData final : public virtual SvRefBase
110{
111 typedef ::std::vector<CellData::Pointer_t> Cells;
112
117
122
123 sal_uInt32 m_nGridBefore;
124 sal_uInt32 m_nGridAfter;
125
126public:
128
130 : m_nGridBefore(0)
131 , m_nGridAfter(0)
132 {
133 }
134
135 RowData(const RowData& rRowData)
136 : SvRefBase(), mCells(rRowData.mCells), mpProperties(rRowData.mpProperties)
137 , m_nGridBefore(rRowData.m_nGridBefore)
138 , m_nGridAfter(rRowData.m_nGridAfter)
139 {
140 }
141
150 void addCell(const css::uno::Reference<css::text::XTextRange>& start, TablePropertyMapPtr pProps, bool bAddBefore = false)
151 {
152 CellData::Pointer_t pCellData(new CellData(start, pProps));
153 if (bAddBefore)
154 {
155 mCells.insert(mCells.begin(), pCellData);
156 mCells[0]->setEnd(start);
157 }
158 else
159 mCells.push_back(pCellData);
160 }
161
162 void endCell(const css::uno::Reference<css::text::XTextRange>& end)
163 {
164 if (mCells.size() > 0)
165 mCells.back()->setEnd(end);
166 }
167
168 bool isCellOpen() const
169 {
170 return mCells.size() > 0 && mCells.back()->isOpen();
171 }
172
179 {
180 if( pProperties )
181 {
182 if( !mpProperties )
183 mpProperties = pProperties;
184 else
185 mpProperties->InsertProps(pProperties.get());
186 }
187 }
188
193 {
194 if (!mCells.empty())
195 mCells.back()->insertProperties(pProps);
196 }
197
201 unsigned int getCellCount() const
202 {
203 return mCells.size();
204 }
205
211 const css::uno::Reference<css::text::XTextRange>& getCellStart(unsigned int i) const
212 {
213 return mCells[i]->getStart();
214 }
215
221 const css::uno::Reference<css::text::XTextRange>& getCellEnd(unsigned int i) const
222 {
223 return mCells[i]->getEnd();
224 }
225
231 TablePropertyMapPtr const & getCellProperties(unsigned int i) const
232 {
233 return mCells[i]->getProperties();
234 }
235
240 {
241 return mpProperties;
242 }
243
244 sal_uInt32 getGridBefore() const { return m_nGridBefore; }
245 void setGridBefore(sal_uInt32 nSkipGrids) { m_nGridBefore = nSkipGrids; }
246 sal_uInt32 getGridAfter() const { return m_nGridAfter; }
247 void setGridAfter(sal_uInt32 nSkipGrids) { m_nGridAfter = nSkipGrids; }
248 sal_uInt32 getGridSpan(sal_uInt32 i) { return mCells[i]->getGridSpan(); }
249 std::vector< sal_uInt32 > getGridSpans()
250 {
251 std::vector< sal_uInt32 > nRet;
252 for (auto const& aCell: mCells)
253 nRet.push_back(aCell->getGridSpan());
254 return nRet;
255 }
256 void setCurrentGridSpan(sal_uInt32 nSpan, bool bFirstCell = false)
257 {
258 if ( mCells.size() )
259 {
260 if ( bFirstCell )
261 mCells.front()->setGridSpan(nSpan);
262 else
263 mCells.back()->setGridSpan(nSpan);
264 }
265 }
266};
267
271class TableData : public virtual SvRefBase
272{
274 typedef ::std::vector<RowPointer_t> Rows;
275
280
285
289 unsigned int mnDepth;
290
294 void newRow() { mpRow = RowPointer_t(new RowData()); }
295
296public:
298
299 explicit TableData(unsigned int nDepth) : mnDepth(nDepth) { newRow(); }
300
309 void endRow(TablePropertyMapPtr pProperties)
310 {
311 mpRow->insertProperties(pProperties);
312 mRows.push_back(mpRow);
313 newRow();
314 }
315
323 void addCell(const css::uno::Reference<css::text::XTextRange>& start, TablePropertyMapPtr pProps)
324 {
325 mpRow->addCell(start, pProps);
326 }
327
333 void endCell(const css::uno::Reference<css::text::XTextRange>& end)
334 {
335 mpRow->endCell(end);
336 }
337
341 bool isCellOpen() const
342 {
343 return mpRow->isCellOpen();
344 }
345
352 {
353 mpRow->insertCellProperties(pProps);
354 }
355
359 unsigned int getRowCount() const
360 {
361 return mRows.size();
362 }
363
367 unsigned int getDepth() const
368 {
369 return mnDepth;
370 }
371
377 RowPointer_t const & getRow(unsigned int i) const
378 {
379 return mRows[i];
380 }
381
383 {
384 return mpRow;
385 }
386};
387
388}
389
390
391/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
T * get() const
Class containing the data to describe a table cell.
Definition: TableData.hxx:36
TablePropertyMapPtr mpProps
Pointer to properties of cell.
Definition: TableData.hxx:50
void setEnd(css::uno::Reference< css::text::XTextRange > const &end)
Set the end handle of a cell.
Definition: TableData.hxx:70
sal_uInt32 m_nGridSpan
number of grid columns in the parent table's table grid which this cell defines
Definition: TableData.hxx:54
css::uno::Reference< css::text::XTextRange > mStart
Handle to start of cell.
Definition: TableData.hxx:40
CellData(css::uno::Reference< css::text::XTextRange > const &start, TablePropertyMapPtr pProps)
Definition: TableData.hxx:59
css::uno::Reference< css::text::XTextRange > mEnd
Handle to end of cell.
Definition: TableData.hxx:45
void insertProperties(TablePropertyMapPtr pProps)
Adds properties to the cell.
Definition: TableData.hxx:77
tools::SvRef< CellData > Pointer_t
Definition: TableData.hxx:57
const TablePropertyMapPtr & getProperties() const
Return properties of the cell.
Definition: TableData.hxx:98
const css::uno::Reference< css::text::XTextRange > & getEnd() const
Return end handle of the cell.
Definition: TableData.hxx:93
sal_uInt32 getGridSpan() const
Definition: TableData.hxx:102
void setGridSpan(sal_uInt32 nSpan)
Definition: TableData.hxx:103
const css::uno::Reference< css::text::XTextRange > & getStart() const
Return start handle of the cell.
Definition: TableData.hxx:88
Class to handle data of a table row.
Definition: TableData.hxx:110
sal_uInt32 getGridSpan(sal_uInt32 i)
Definition: TableData.hxx:248
void endCell(const css::uno::Reference< css::text::XTextRange > &end)
Definition: TableData.hxx:162
void insertProperties(TablePropertyMapPtr pProperties)
Add properties to the row.
Definition: TableData.hxx:178
const css::uno::Reference< css::text::XTextRange > & getCellStart(unsigned int i) const
Return start handle of a cell in the row.
Definition: TableData.hxx:211
void insertCellProperties(TablePropertyMapPtr pProps)
Add properties to the last cell of the row.
Definition: TableData.hxx:192
TablePropertyMapPtr const & getCellProperties(unsigned int i) const
Return the properties of a cell in the row.
Definition: TableData.hxx:231
sal_uInt32 m_nGridAfter
number of grid columns in the parent table's table grid which shall be left after the last cell in th...
Definition: TableData.hxx:124
void setCurrentGridSpan(sal_uInt32 nSpan, bool bFirstCell=false)
Definition: TableData.hxx:256
TablePropertyMapPtr mpProperties
the properties of the row
Definition: TableData.hxx:121
void addCell(const css::uno::Reference< css::text::XTextRange > &start, TablePropertyMapPtr pProps, bool bAddBefore=false)
Add a cell to the row.
Definition: TableData.hxx:150
std::vector< sal_uInt32 > getGridSpans()
Definition: TableData.hxx:249
::std::vector< CellData::Pointer_t > Cells
Definition: TableData.hxx:111
const css::uno::Reference< css::text::XTextRange > & getCellEnd(unsigned int i) const
Return end handle of a cell in the row.
Definition: TableData.hxx:221
sal_uInt32 getGridBefore() const
Definition: TableData.hxx:244
void setGridBefore(sal_uInt32 nSkipGrids)
Definition: TableData.hxx:245
void setGridAfter(sal_uInt32 nSkipGrids)
Definition: TableData.hxx:247
sal_uInt32 getGridAfter() const
Definition: TableData.hxx:246
Cells mCells
the cell data of the row
Definition: TableData.hxx:116
tools::SvRef< RowData > Pointer_t
Definition: TableData.hxx:127
RowData(const RowData &rRowData)
Definition: TableData.hxx:135
const TablePropertyMapPtr & getProperties() const
Return properties of the row.
Definition: TableData.hxx:239
sal_uInt32 m_nGridBefore
number of grid columns in the parent table's table grid which must be skipped before the contents of ...
Definition: TableData.hxx:123
unsigned int getCellCount() const
Return number of cells in the row.
Definition: TableData.hxx:201
Class that holds the data of a table.
Definition: TableData.hxx:272
bool isCellOpen() const
Return if the current cell of the current row is open.
Definition: TableData.hxx:341
RowPointer_t const & getRow(unsigned int i) const
Return row data of a certain row.
Definition: TableData.hxx:377
unsigned int mnDepth
depth of the current table in a hierarchy of tables
Definition: TableData.hxx:289
Rows mRows
the data of the rows of the table
Definition: TableData.hxx:279
unsigned int getDepth() const
Return depth of table in surrounding table hierarchy.
Definition: TableData.hxx:367
::std::vector< RowPointer_t > Rows
Definition: TableData.hxx:274
void endRow(TablePropertyMapPtr pProperties)
End the current row.
Definition: TableData.hxx:309
void addCell(const css::uno::Reference< css::text::XTextRange > &start, TablePropertyMapPtr pProps)
Add a cell to the current row.
Definition: TableData.hxx:323
unsigned int getRowCount() const
Return number of rows in the table.
Definition: TableData.hxx:359
RowData::Pointer_t RowPointer_t
Definition: TableData.hxx:273
void newRow()
initialize mpRow
Definition: TableData.hxx:294
void endCell(const css::uno::Reference< css::text::XTextRange > &end)
End the current cell of the current row.
Definition: TableData.hxx:333
const RowPointer_t & getCurrentRow() const
Definition: TableData.hxx:382
TableData(unsigned int nDepth)
Definition: TableData.hxx:299
tools::SvRef< TableData > Pointer_t
Definition: TableData.hxx:297
RowPointer_t mpRow
pointer to the data of the current row (while building up the table data).
Definition: TableData.hxx:284
void insertCellProperties(TablePropertyMapPtr pProps)
Insert properties to the current cell of the current row.
Definition: TableData.hxx:351
int i
end