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