LibreOffice Module writerfilter (master) 1
TableManager.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 <memory>
23#include <stack>
24
25#include "PropertyMap.hxx"
26#include "TableData.hxx"
27
29
31{
32
33class DomainMapperTableHandler;
34
43class TableManager : public virtual SvRefBase
44{
46 {
51
56
61
65 std::stack<TablePropertyMapPtr> mTableProps;
66
71
76
81
82 public:
87 : mbRowEnd(false), mbInCell(false), mbCellEnd(false)
88 {
89 }
90
92 {
94 mTableProps.push(pProps);
95 }
96
97 void endLevel()
98 {
99 mTableProps.pop();
100 }
101
106 {
107 mbRowEnd = false;
108 mbInCell = false;
109 mbCellEnd = false;
110 }
111
113 {
114 // copy tblPrEx table exception properties, if they exist
115 if (getTableExceptionProps().is())
116 {
118 mpCellProps->InsertProps(getTableExceptionProps().get());
119 }
120 else
122 }
123
125 {
126 mpCellProps = pProps;
127 }
128
130 {
131 return mpCellProps;
132 }
133
135 {
136 // reset also table exception and
137 // its copy set by the previous resetCellProps()
141 }
142
144 {
145 mpRowProps = pProps;
146 }
147
149 {
150 return mpRowProps;
151 }
152
154 {
155 mpTableExceptionProps = pProps;
156 // set table exception properties of the first cell
158 }
159
161 {
163 }
164
166 {
167 if (mTableProps.size() > 0)
168 mTableProps.top().clear();
169 }
170
172 {
173 if (mTableProps.size() > 0)
174 mTableProps.top() = pProps;
175 }
176
178 {
179 TablePropertyMapPtr pResult;
180
181 if (mTableProps.size() > 0)
182 pResult = mTableProps.top();
183
184 return pResult;
185 }
186
187 void setInCell(bool bInCell)
188 {
189 mbInCell = bInCell;
190 }
191
192 bool isInCell() const
193 {
194 return mbInCell;
195 }
196
197 void setCellEnd(bool bCellEnd)
198 {
199 mbCellEnd = bCellEnd;
200 }
201
202 bool isCellEnd() const
203 {
204 return mbCellEnd;
205 }
206
207 void setRowEnd(bool bRowEnd)
208 {
209 mbRowEnd = bRowEnd;
210 }
211
212 bool isRowEnd() const
213 {
214 return mbRowEnd;
215 }
216 };
217
221 css::uno::Reference<css::text::XTextRange> mCurHandle;
222
224
225protected:
227 {
228 return mState.getCellProps();
229 }
230
231public:
233 {
234 return mState.getRowProps();
235 }
236
238 {
240 }
241
242protected:
243 void setInCell(bool bInCell)
244 {
245 mState.setInCell(bInCell);
246 }
247
248 bool isInCell() const
249 {
250 return mState.isInCell();
251 }
252
253 void setCellEnd(bool bCellEnd)
254 {
255 mState.setCellEnd(bCellEnd);
256 }
257
258 void setRowEnd(bool bRowEnd)
259 {
260 mState.setRowEnd(bRowEnd);
261 }
262
263 bool isRowEnd() const
264 {
265 return mState.isRowEnd();
266 }
267
269 {
270 return mState.getTableProps();
271 }
272
273 const css::uno::Reference<css::text::XTextRange>& getHandle() const
274 {
275 return mCurHandle;
276 }
277
278 void setHandle(const css::uno::Reference<css::text::XTextRange>& rHandle)
279 {
280 mCurHandle = rHandle;
281 }
282
283private:
285
289 sal_uInt32 mnTableDepthNew;
290
294 sal_uInt32 mnTableDepth;
295
301 std::stack<TableData::Pointer_t> mTableDataStack;
306
308
313
317 void inCell();
318
322 void endCell();
323
329 void cellDepth(sal_uInt32 nDepth);
330
334 void endRow();
335
339 void resolveCurrentTable();
340
345 void openCell(const css::uno::Reference<css::text::XTextRange>& rHandle, const TablePropertyMapPtr& pProps);
346
350 void closeCell(const css::uno::Reference<css::text::XTextRange>& rHandle);
351
355 void ensureOpenCell(const TablePropertyMapPtr& pProps);
356
357protected:
362
363 sal_uInt32 getTableDepth() const { return mnTableDepthNew; }
364
369 virtual void endOfCellAction();
370
375 virtual void endOfRowAction();
378 virtual void clearData();
379
383 void setKeepUnfinishedRow(bool bKeep)
384 {
385 mbKeepUnfinishedRow = bKeep;
386 }
387
388
389public:
390 TableManager();
392
398 void setHandler(const tools::SvRef<DomainMapperTableHandler>& pTableDataHandler);
399
405 void handle(const css::uno::Reference<css::text::XTextRange>& rHandle);
406
412 virtual void startLevel();
413
420 virtual void endLevel();
421
425 void endTable()
426 {
427 setRowEnd(false);
428 }
429
433 bool isInTable();
434
438 void startParagraphGroup();
439
443 void endParagraphGroup();
444
450 virtual bool sprm(Sprm & rSprm);
451
455 void handle0x7();
456
463 void text(const sal_uInt8 * data, size_t len);
464
471 void utext(const sal_uInt8 * data, size_t len);
472
478 virtual void cellProps(const TablePropertyMapPtr& pProps);
479
485 virtual void insertRowProps(const TablePropertyMapPtr& pProps);
486
492 virtual void tableExceptionProps(const TablePropertyMapPtr& pProps);
493
499 virtual void insertTableProps(const TablePropertyMapPtr& pProps);
500
507 bool isIgnore() const;
508
509 sal_uInt32 getGridBefore(sal_uInt32 nRow);
510 sal_uInt32 getCurrentGridBefore();
511 void setCurrentGridBefore( sal_uInt32 nSkipGrids );
512 sal_uInt32 getGridAfter(sal_uInt32 nRow);
513 void setCurrentGridAfter( sal_uInt32 nSkipGrids );
514 std::vector<sal_uInt32> getCurrentGridSpans();
515 void setCurrentGridSpan( sal_uInt32 nGridSpan, bool bFirstCell = false );
517 sal_uInt32 findColumn( const sal_uInt32 nRow, const sal_uInt32 nCell );
519 sal_uInt32 findColumnCell( const sal_uInt32 nRow, const sal_uInt32 nCol );
520
521 void setTableStartsAtCellStart(bool bTableStartsAtCellStart);
522 void setCellLastParaAfterAutospacing(bool bIsAfterAutospacing);
524};
525
526}
527
528
529
530/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
An SPRM: Section, Paragraph and Run Modifier.
const TablePropertyMapPtr & getTableExceptionProps() const
TablePropertyMapPtr mpRowProps
properties of the current row
TablePropertyMapPtr mpCellProps
properties of the current cell
std::stack< TablePropertyMapPtr > mTableProps
properties of the current table
bool mbCellEnd
true when at the end of a cell
TablePropertyMapPtr mpTableExceptionProps
table exception properties of the current row
const TablePropertyMapPtr & getCellProps() const
const TablePropertyMapPtr & getRowProps() const
void resetCellSpecifics()
Reset to initial state at beginning of row.
void setTableExceptionProps(TablePropertyMapPtr pProps)
sal_uInt32 getGridAfter(sal_uInt32 nRow)
void resolveCurrentTable()
Resolve the current table to the TableDataHandler.
void startParagraphGroup()
Handle the start of a paragraph group.
std::stack< TableData::Pointer_t > mTableDataStack
stack of table data
TablePropertyMapPtr const & getTableExceptionProps() const
const css::uno::Reference< css::text::XTextRange > & getHandle() const
void endParagraphGroup()
Handle the end of a paragraph group.
sal_uInt32 mnTableDepthNew
depth of the current cell
void text(const sal_uInt8 *data, size_t len)
Handle 8 bit text at current handle.
bool m_bTableStartsAtCellStart
If this is a nested table, does it start at cell start?
virtual bool sprm(Sprm &rSprm)
Handle an SPRM at current handle.
sal_Int32 getTableDepthDifference() const
Return the current table difference, i.e.
void closeCell(const css::uno::Reference< css::text::XTextRange > &rHandle)
Close a cell at current level.
void setHandle(const css::uno::Reference< css::text::XTextRange > &rHandle)
TablePropertyMapPtr getTableProps()
bool isInTable()
Tells whether a table has been started or not.
virtual void insertRowProps(const TablePropertyMapPtr &pProps)
Handle properties of the current row.
void utext(const sal_uInt8 *data, size_t len)
Handle 16 bit text at current handle.
void setCurrentGridBefore(sal_uInt32 nSkipGrids)
tools::SvRef< DomainMapperTableHandler > mpTableDataHandler
handler for resolveCurrentTable
virtual void startLevel()
Start a new table level.
void endTable()
Signal that the next paragraph definitely won't be part of any table.
void openCell(const css::uno::Reference< css::text::XTextRange > &rHandle, const TablePropertyMapPtr &pProps)
Open a cell at current level.
virtual void tableExceptionProps(const TablePropertyMapPtr &pProps)
Handle table exception properties of the current row.
virtual void clearData()
let the derived class clear their table related data
virtual void insertTableProps(const TablePropertyMapPtr &pProps)
Handle properties of the current table.
bool isIgnore() const
Return if table manager has detected paragraph to ignore.
void handle(const css::uno::Reference< css::text::XTextRange > &rHandle)
Set the current handle.
void endCell()
Set flag which indicate the current handle is at the end of a cell.
void handle0x7()
Handle occurrence of character 0x7.
virtual void endLevel()
End a table level.
TablePropertyMapPtr const & getCellProps() const
void inCell()
Set flag which indicates the current handle is in a cell.
void setCurrentGridAfter(sal_uInt32 nSkipGrids)
TablePropertyMapPtr const & getRowProps() const
void setCellLastParaAfterAutospacing(bool bIsAfterAutospacing)
virtual void endOfCellAction()
Action to be carried out at the end of the last paragraph of a cell.
void setTableStartsAtCellStart(bool bTableStartsAtCellStart)
css::uno::Reference< css::text::XTextRange > mCurHandle
handle for the current position in document
sal_uInt32 findColumn(const sal_uInt32 nRow, const sal_uInt32 nCell)
Given a zero-based row/cell, return the zero-based grid it belongs to, or SAL_MAX_UINT16 for invalid.
virtual void cellProps(const TablePropertyMapPtr &pProps)
Handle properties of the current cell.
sal_uInt32 findColumnCell(const sal_uInt32 nRow, const sal_uInt32 nCol)
Given a zero-based row/col, return the zero-based cell describing that grid, or SAL_MAX_UINT16 for in...
void setKeepUnfinishedRow(bool bKeep)
Should we keep the unfinished row in endLevel to initialize the table data in the following startLeve...
void setCurrentGridSpan(sal_uInt32 nGridSpan, bool bFirstCell=false)
virtual void endOfRowAction()
Action to be carried out at the end of the "table row" paragraph.
tools::SvRef< css::uno::Reference< css::text::XTextRange > > T_p
void setHandler(const tools::SvRef< DomainMapperTableHandler > &pTableDataHandler)
Set handler for resolveCurrentTable.
sal_uInt32 mnTableDepth
depth of the previous cell
void endRow()
Set flag indication the current handle is at the end of a row.
std::vector< sal_uInt32 > getCurrentGridSpans()
void ensureOpenCell(const TablePropertyMapPtr &pProps)
Ensure a cell is open at the current level.
sal_uInt32 getGridBefore(sal_uInt32 nRow)
void cellDepth(sal_uInt32 nDepth)
Set the table depth of the current cell.
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
The classes in this file define the interfaces for the resource model of the DocTokenizer:
unsigned char sal_uInt8