LibreOffice Module sw (master)  1
WW8TableInfo.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_SW_SOURCE_FILTER_WW8_WW8TABLEINFO_HXX
21 #define INCLUDED_SW_SOURCE_FILTER_WW8_WW8TABLEINFO_HXX
22 #include <string>
23 #include <map>
24 #include <memory>
25 #include <set>
26 #include <functional>
27 #include <unordered_map>
28 #include <vector>
29 #include <sal/types.h>
30 #include <swrect.hxx>
31 
32 class SwTable;
33 class SwTableLine;
34 class SwTableBox;
35 class SwNode;
37 
38 namespace ww8
39 {
40 const unsigned int MAXTABLECELLS = 63;
41 
43 typedef std::vector<const SwTableBox *> TableBoxVector;
44 typedef std::shared_ptr<TableBoxVector> TableBoxVectorPtr;
45 typedef std::vector<sal_uInt32> GridCols;
46 typedef std::shared_ptr<GridCols> GridColsPtr;
47 typedef std::vector<sal_Int32> RowSpans;
48 typedef std::shared_ptr<RowSpans> RowSpansPtr;
49 typedef std::vector<sal_uInt32> Widths;
50 typedef std::shared_ptr<Widths> WidthsPtr;
51 
53 {
55  sal_uInt32 mnDepth;
56  sal_uInt32 mnCell;
57  sal_uInt32 mnRow;
58  sal_uInt32 mnShadowsBefore;
59  sal_uInt32 mnShadowsAfter;
66  const SwTable * mpTable;
68 
69 public:
70  typedef std::shared_ptr<WW8TableNodeInfoInner> Pointer_t;
71 
72  explicit WW8TableNodeInfoInner(WW8TableNodeInfo * pParent);
73 
74  void setDepth(sal_uInt32 nDepth);
75  void setCell(sal_uInt32 nCell);
76  void setRow(sal_uInt32 nRow);
77  void setShadowsBefore(sal_uInt32 nShadowsBefore);
78  void setShadowsAfter(sal_uInt32 nShadowsAfter);
79  void setEndOfLine(bool bEndOfLine);
80  void setFinalEndOfLine(bool bEndOfLine);
81  void setEndOfCell(bool bEndOfCell);
82  void setFirstInTable(bool bFirstInTable);
83  void setVertMerge(bool bVertMerge);
84  void setTableBox(const SwTableBox *pTableBox);
85  void setTable(const SwTable * pTable);
86  void setRect(const SwRect & rRect);
87 
88  sal_uInt32 getDepth() const { return mnDepth;}
89  sal_uInt32 getCell() const { return mnCell;}
90  sal_uInt32 getRow() const { return mnRow;}
91  sal_uInt32 getShadowsBefore() const { return mnShadowsBefore;}
92  sal_uInt32 getShadowsAfter() const { return mnShadowsAfter;}
93  bool isEndOfCell() const { return mbEndOfCell;}
94  bool isEndOfLine() const { return mbEndOfLine;}
95  bool isFinalEndOfLine() const { return mbFinalEndOfLine;}
96  bool isFirstInTable() const { return mbFirstInTable;}
97  const SwTableBox * getTableBox() const { return mpTableBox;}
98  const SwTable * getTable() const { return mpTable;}
99  const SwRect & getRect() const { return maRect;}
100 
101  const SwNode * getNode() const;
102 
103  TableBoxVectorPtr getTableBoxesOfRow() const;
104  WidthsPtr getWidthsOfRow() const;
105  WidthsPtr getColumnWidthsBasedOnAllRows() const;
106  GridColsPtr getGridColsOfRow(AttributeOutputBase & rBase, bool calculateColumnsFromAllRows = false);
107  RowSpansPtr getRowSpansOfRow() const;
108 
109 #ifdef DBG_UTIL
110  std::string toString() const;
111 #endif
112 };
113 
114 class CellInfo
115 {
119 
120 public:
121  CellInfo(const SwRect & aRect, WW8TableNodeInfo * pNodeInfo);
122 
123  CellInfo(const CellInfo & aRectAndTableInfo)
124  : m_aRect(aRectAndTableInfo.m_aRect),
125  m_pNodeInfo(aRectAndTableInfo.m_pNodeInfo),
126  m_nFormatFrameWidth(aRectAndTableInfo.m_nFormatFrameWidth)
127  {
128  }
129 
130  bool operator < (const CellInfo & aCellInfo) const;
131 
132  tools::Long top() const { return m_aRect.Top(); }
133  tools::Long bottom() const { return m_aRect.Bottom(); }
134  tools::Long left() const { return m_aRect.Left(); }
135  tools::Long right() const { return m_aRect.Right(); }
136  tools::Long width() const { return m_aRect.Width(); }
137  tools::Long height() const { return m_aRect.Height(); }
138  const SwRect& getRect() const { return m_aRect; }
140  { return m_pNodeInfo; }
142  {
143  return m_nFormatFrameWidth;
144  }
145 
146  void setFormatFrameWidth(tools::ULong nFormatFrameWidth)
147  {
148  m_nFormatFrameWidth = nFormatFrameWidth;
149  }
150 
151 #ifdef DBG_UTIL
152  std::string toString() const;
153 #endif
154 };
155 
156 typedef std::multiset<CellInfo> CellInfoMultiSet;
157 typedef std::map<sal_uInt32, WW8TableNodeInfoInner*,
158  std::greater<sal_uInt32> > RowEndInners_t;
159 
160 
161 class WW8TableInfo;
162 class WW8TableNodeInfo final
163 {
164 public:
165  typedef std::map<sal_uInt32, WW8TableNodeInfoInner::Pointer_t,
166  std::greater<sal_uInt32> > Inners_t;
167 
168 private:
170  sal_uInt32 mnDepth;
171  const SwNode * mpNode;
172  Inners_t mInners;
175 
176 public:
177  typedef std::shared_ptr<WW8TableNodeInfo> Pointer_t;
178 
179  WW8TableNodeInfo(WW8TableInfo * pParent, const SwNode * pTextNode);
181 
182  void setDepth(sal_uInt32 nDepth);
183  void setEndOfLine(bool bEndOfLine);
184  void setEndOfCell(bool bEndOfCell);
185  void setFirstInTable(bool bFirstInTable);
186  void setVertMerge(bool bVertMerge);
187  void setTableBox(const SwTableBox *pTableBox);
188  void setTable(const SwTable * pTable);
189  void setCell(sal_uInt32 nCell);
190  void setRow(sal_uInt32 nRow);
191  void setShadowsBefore(sal_uInt32 nShadowsBefore);
192  void setShadowsAfter(sal_uInt32 nShadowsAfter);
193  void setNext(WW8TableNodeInfo * pNext);
194  void setNextNode(const SwNode * pNode);
195  void setRect(const SwRect & rRect);
196 
197  WW8TableInfo * getParent() const { return mpParent;}
198  sal_uInt32 getDepth() const;
199  const SwNode * getNode() const { return mpNode;}
200  const SwTableBox * getTableBox() const;
201  WW8TableNodeInfo * getNext() const { return mpNext;}
202  const SwNode * getNextNode() const { return mpNextNode;}
203 
204  const Inners_t & getInners() const { return mInners;}
205  WW8TableNodeInfoInner::Pointer_t getFirstInner() const;
206  WW8TableNodeInfoInner::Pointer_t getInnerForDepth(sal_uInt32 nDepth) const;
207 
208  sal_uInt32 getCell() const;
209  sal_uInt32 getRow() const;
210 
211 #ifdef DBG_UTIL
212  std::string toString() const;
213 #endif
214 
215  bool operator < (const WW8TableNodeInfo & rInfo) const;
216 };
217 
218 struct hashNode
219 {
220  size_t operator()(const SwNode * pNode) const
221  { return reinterpret_cast<size_t>(pNode); }
222 };
223 
224 struct hashTable
225 {
226  size_t operator()(const SwTable * pTable) const
227  { return reinterpret_cast<size_t>(pTable); }
228 };
229 
231 {
232  std::shared_ptr<CellInfoMultiSet> m_pCellInfos;
233  TableBoxVectorPtr m_pTableBoxVector;
234  WidthsPtr m_pWidths;
235  RowSpansPtr m_pRowSpans;
236 
237 public:
238  typedef std::shared_ptr<WW8TableCellGridRow> Pointer_t;
241 
242  void insert(const CellInfo & rCellInfo);
243  CellInfoMultiSet::const_iterator begin() const;
244  CellInfoMultiSet::const_iterator end() const;
245 
246  void setTableBoxVector(TableBoxVectorPtr const & pTableBoxVector);
247  void setWidths(WidthsPtr const & pGridCols);
248  void setRowSpans(RowSpansPtr const & pRowSpans);
249 
250  const TableBoxVectorPtr& getTableBoxVector() const { return m_pTableBoxVector;}
251  const WidthsPtr& getWidths() const { return m_pWidths;}
252  const RowSpansPtr& getRowSpans() const { return m_pRowSpans;}
253 };
254 
256 {
257  typedef std::set<tools::Long> RowTops_t;
258  typedef std::map<tools::Long, WW8TableCellGridRow::Pointer_t> Rows_t;
259 
260  RowTops_t m_aRowTops;
261  Rows_t m_aRows;
262 
263  WW8TableCellGridRow::Pointer_t getRow(tools::Long nTop, bool bCreate = true);
264  RowTops_t::const_iterator getRowTopsBegin() const;
265  RowTops_t::const_iterator getRowTopsEnd() const;
266  CellInfoMultiSet::const_iterator getCellsBegin(tools::Long nTop);
267  CellInfoMultiSet::const_iterator getCellsEnd(tools::Long nTop);
268 
269 public:
270  typedef std::shared_ptr<WW8TableCellGrid> Pointer_t;
271 
274 
275  void insert(const SwRect & rRect, WW8TableNodeInfo * pNodeInfo,
276  tools::ULong const * pFormatFrameWidth = nullptr);
277  void addShadowCells();
278  WW8TableNodeInfo *connectCells(RowEndInners_t &rLastRowEnds);
279 
280 #ifdef DBG_UTIL
281  std::string toString();
282 #endif
283 
284  TableBoxVectorPtr getTableBoxesOfRow(WW8TableNodeInfoInner const * pNodeInfo);
285  WidthsPtr getWidthsOfRow(WW8TableNodeInfoInner const * pNodeInfo);
286  RowSpansPtr getRowSpansOfRow(WW8TableNodeInfoInner const * pNodeInfo);
287 };
288 
289 class WW8TableInfo final
290 {
291  friend class WW8TableNodeInfoInner;
292  typedef std::unordered_map<const SwNode *, WW8TableNodeInfo::Pointer_t, hashNode > Map_t;
293  Map_t mMap;
294 
295  typedef std::unordered_map<const SwTable *, WW8TableCellGrid::Pointer_t, hashTable > CellGridMap_t;
296  CellGridMap_t mCellGridMap;
297 
298  typedef std::unordered_map<const SwTable *, const SwNode *, hashTable > FirstInTableMap_t;
299  FirstInTableMap_t mFirstInTableMap;
300 
302  processTableLine(const SwTable * pTable,
303  const SwTableLine * pTableLine,
304  sal_uInt32 nRow,
305  sal_uInt32 nDepth, WW8TableNodeInfo * pPrev, RowEndInners_t &rLastRowEnds);
306 
308  processTableBox(const SwTable * pTable,
309  const SwTableBox * pTableBox,
310  sal_uInt32 nRow,
311  sal_uInt32 nCell,
312  sal_uInt32 nDepth, bool bEndOfLine,
313  WW8TableNodeInfo * pPrev, RowEndInners_t &rLastRowEnds);
314 
316  processTableBoxLines(const SwTableBox * pBox,
317  const SwTable * pTable,
318  const SwTableBox * pBoxToSet,
319  sal_uInt32 nRow,
320  sal_uInt32 nCell,
321  sal_uInt32 nDepth);
322 
324  insertTableNodeInfo(const SwNode * pNode,
325  const SwTable * pTable,
326  const SwTableBox * pTableBox,
327  sal_uInt32 nRow,
328  sal_uInt32 nCell,
329  sal_uInt32 nDepth,
330  SwRect const * pRect = nullptr);
331 
333  bool bCreate = true);
334 
335 public:
336  typedef std::shared_ptr<WW8TableInfo> Pointer_t;
337 
338  WW8TableInfo();
339  ~WW8TableInfo();
340 
341  void processSwTable(const SwTable * pTable);
342  WW8TableNodeInfo * processSwTableByLayout(const SwTable * pTable, RowEndInners_t &rLastRowEnds);
344  const SwNode * getNextNode(const SwNode * pNode);
345 
346  WW8TableNodeInfo * reorderByLayout(const SwTable * pTable, RowEndInners_t &rLastRowEnds);
347 };
348 
349 }
350 #endif // INCLUDED_SW_SOURCE_FILTER_WW8_WW8TABLEINFO_HXX
351 
352 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void setNext(WW8TableNodeInfo *pNext)
WW8TableNodeInfo::Pointer_t processTableBoxLines(const SwTableBox *pBox, const SwTable *pTable, const SwTableBox *pBoxToSet, sal_uInt32 nRow, sal_uInt32 nCell, sal_uInt32 nDepth)
void setTableBox(const SwTableBox *pTableBox)
const RowSpansPtr & getRowSpans() const
std::map< sal_uInt32, WW8TableNodeInfoInner *, std::greater< sal_uInt32 > > RowEndInners_t
void Right(const tools::Long nRight)
Definition: swrect.hxx:202
std::vector< const SwTableBox * > TableBoxVector
sal_uInt32 getDepth() const
void setEndOfLine(bool bEndOfLine)
const SwNode * getNode() const
WW8TableNodeInfo * connectCells(RowEndInners_t &rLastRowEnds)
void setRect(const SwRect &rRect)
void Left(const tools::Long nLeft)
Definition: swrect.hxx:197
void setEndOfCell(bool bEndOfCell)
bool operator<(const WW8TableNodeInfo &rInfo) const
const SwNode * mpNode
long Long
sal_uInt32 getDepth() const
std::vector< sal_Int32 > RowSpans
tools::Long right() const
std::set< tools::Long > RowTops_t
void setCell(sal_uInt32 nCell)
std::unordered_map< const SwTable *, const SwNode *, hashTable > FirstInTableMap_t
void setRect(const SwRect &rRect)
tools::Long bottom() const
TableBoxVectorPtr getTableBoxesOfRow() const
SwTableLine is one table row in the document model.
Definition: swtable.hxx:357
TableBoxVectorPtr getTableBoxesOfRow(WW8TableNodeInfoInner const *pNodeInfo)
void setTable(const SwTable *pTable)
WW8TableInfo * mpParent
sal_uInt32 getCell() const
Of course Writer needs its own rectangles.
Definition: swrect.hxx:34
WW8TableNodeInfo(WW8TableInfo *pParent, const SwNode *pTextNode)
sal_uInt32 getShadowsAfter() const
std::unordered_map< const SwTable *, WW8TableCellGrid::Pointer_t, hashTable > CellGridMap_t
std::shared_ptr< Widths > WidthsPtr
std::string toString() const
std::map< tools::Long, WW8TableCellGridRow::Pointer_t > Rows_t
WW8TableNodeInfo::Pointer_t insertTableNodeInfo(const SwNode *pNode, const SwTable *pTable, const SwTableBox *pTableBox, sal_uInt32 nRow, sal_uInt32 nCell, sal_uInt32 nDepth, SwRect const *pRect=nullptr)
size_t operator()(const SwNode *pNode) const
unsigned long ULong
const SwRect & getRect() const
const SwTableBox * mpTableBox
tools::Long width() const
void Width(tools::Long nNew)
Definition: swrect.hxx:189
const SwNode * getNextNode(const SwNode *pNode)
void setTableBoxVector(TableBoxVectorPtr const &pTableBoxVector)
WW8TableNodeInfo * processTableLine(const SwTable *pTable, const SwTableLine *pTableLine, sal_uInt32 nRow, sal_uInt32 nDepth, WW8TableNodeInfo *pPrev, RowEndInners_t &rLastRowEnds)
sal_uInt32 getShadowsBefore() const
void setShadowsAfter(sal_uInt32 nShadowsAfter)
CellInfo(const CellInfo &aRectAndTableInfo)
CellInfoMultiSet::const_iterator getCellsEnd(tools::Long nTop)
void setFirstInTable(bool bFirstInTable)
std::vector< sal_uInt32 > GridCols
tools::Long height() const
void setRow(sal_uInt32 nRow)
WW8TableNodeInfo * reorderByLayout(const SwTable *pTable, RowEndInners_t &rLastRowEnds)
void setWidths(WidthsPtr const &pGridCols)
const Inners_t & getInners() const
WW8TableNodeInfoInner(WW8TableNodeInfo *pParent)
void setRowSpans(RowSpansPtr const &pRowSpans)
const SwTableBox * getTableBox() const
std::shared_ptr< WW8TableInfo > Pointer_t
tools::ULong getFormatFrameWidth() const
WW8TableNodeInfo * processSwTableByLayout(const SwTable *pTable, RowEndInners_t &rLastRowEnds)
std::vector< sal_uInt32 > Widths
WW8TableInfo * getParent() const
const SwTableBox * getTableBox() const
WW8TableNodeInfoInner::Pointer_t getFirstInner() const
std::shared_ptr< TableBoxVector > TableBoxVectorPtr
void setEndOfCell(bool bEndOfCell)
const SwNode * getNode() const
size_t operator()(const SwTable *pTable) const
WW8TableNodeInfo * mpNext
CellInfoMultiSet::const_iterator begin() const
RowSpansPtr getRowSpansOfRow(WW8TableNodeInfoInner const *pNodeInfo)
WW8TableNodeInfo * getNext() const
std::multiset< CellInfo > CellInfoMultiSet
void setFirstInTable(bool bFirstInTable)
tools::ULong m_nFormatFrameWidth
std::shared_ptr< GridCols > GridColsPtr
void insert(const SwRect &rRect, WW8TableNodeInfo *pNodeInfo, tools::ULong const *pFormatFrameWidth=nullptr)
WW8TableNodeInfo * processTableBox(const SwTable *pTable, const SwTableBox *pTableBox, sal_uInt32 nRow, sal_uInt32 nCell, sal_uInt32 nDepth, bool bEndOfLine, WW8TableNodeInfo *pPrev, RowEndInners_t &rLastRowEnds)
void processSwTable(const SwTable *pTable)
WW8TableNodeInfoInner::Pointer_t getInnerForDepth(sal_uInt32 nDepth) const
const TableBoxVectorPtr & getTableBoxVector() const
const SwNode * mpNextNode
std::string toString() const
CellInfo(const SwRect &aRect, WW8TableNodeInfo *pNodeInfo)
WW8TableNodeInfo * m_pNodeInfo
void setShadowsAfter(sal_uInt32 nShadowsAfter)
void setFinalEndOfLine(bool bEndOfLine)
void insert(const CellInfo &rCellInfo)
RowTops_t::const_iterator getRowTopsBegin() const
void setNextNode(const SwNode *pNode)
RowTops_t::const_iterator getRowTopsEnd() const
SwTable is one table in the document model, containing rows (which contain cells).
Definition: swtable.hxx:112
void setDepth(sal_uInt32 nDepth)
GridColsPtr getGridColsOfRow(AttributeOutputBase &rBase, bool calculateColumnsFromAllRows=false)
tools::Long left() const
void setCell(sal_uInt32 nCell)
WidthsPtr getColumnWidthsBasedOnAllRows() const
CellInfoMultiSet::const_iterator end() const
void setDepth(sal_uInt32 nDepth)
void Bottom(const tools::Long nBottom)
Definition: swrect.hxx:211
RowSpansPtr getRowSpansOfRow() const
std::unordered_map< const SwNode *, WW8TableNodeInfo::Pointer_t, hashNode > Map_t
WidthsPtr getWidthsOfRow() const
WW8TableCellGridRow::Pointer_t getRow(tools::Long nTop, bool bCreate=true)
WW8TableNodeInfo * getTableNodeInfo() const
std::string toString() const
void setVertMerge(bool bVertMerge)
WW8TableCellGrid::Pointer_t getCellGridForTable(const SwTable *pTable, bool bCreate=true)
CellInfoMultiSet::const_iterator getCellsBegin(tools::Long nTop)
std::shared_ptr< WW8TableCellGrid > Pointer_t
void setShadowsBefore(sal_uInt32 nShadowsBefore)
bool isFinalEndOfLine() const
void setRow(sal_uInt32 nRow)
WW8TableNodeInfo::Pointer_t getTableNodeInfo(const SwNode *pNode)
void setEndOfLine(bool bEndOfLine)
void Top(const tools::Long nTop)
Definition: swrect.hxx:206
SwTableBox is one table cell in the document model.
Definition: swtable.hxx:418
void setShadowsBefore(sal_uInt32 nShadowsBefore)
FirstInTableMap_t mFirstInTableMap
std::shared_ptr< WW8TableNodeInfoInner > Pointer_t
sal_uInt32 getRow() const
const SwTable * getTable() const
void setFormatFrameWidth(tools::ULong nFormatFrameWidth)
const WidthsPtr & getWidths() const
WW8TableNodeInfo * mpParent
std::shared_ptr< CellInfoMultiSet > m_pCellInfos
TableBoxVectorPtr m_pTableBoxVector
std::map< sal_uInt32, WW8TableNodeInfoInner::Pointer_t, std::greater< sal_uInt32 > > Inners_t
std::shared_ptr< WW8TableCellGridRow > Pointer_t
sal_uInt32 getCell() const
tools::Long top() const
std::shared_ptr< RowSpans > RowSpansPtr
void setTableBox(const SwTableBox *pTableBox)
CellGridMap_t mCellGridMap
const SwRect & getRect() const
void Height(tools::Long nNew)
Definition: swrect.hxx:193
std::shared_ptr< WW8TableNodeInfo > Pointer_t
const SwNode * getNextNode() const
void setTable(const SwTable *pTable)
WidthsPtr getWidthsOfRow(WW8TableNodeInfoInner const *pNodeInfo)
sal_uInt32 getRow() const
bool operator<(const CellInfo &aCellInfo) const
void setVertMerge(bool bVertMerge)
const unsigned int MAXTABLECELLS
Base class of the Writer document model elements.
Definition: node.hxx:81