bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / filter / ww8 / WW8TableInfo.hxx
blob68a3c0d6a6376be6b3b71f1cf267641196cf0ffc
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 WW8_TABLE_INFO_HXX
21 #define WW8_TABLE_INFO_HXX
22 #include <boost/unordered_map.hpp>
23 #include <string>
24 #include <map>
25 #include <set>
26 #include <functional>
27 #include <boost/shared_ptr.hpp>
28 #include <vector>
29 #include <sal/types.h>
30 #include <swrect.hxx>
32 class SwTable;
33 class SwTableLine;
34 class SwTableBox;
35 class SwNode;
36 class AttributeOutputBase;
38 namespace ww8
40 using namespace ::std;
42 const unsigned int MAXTABLECELLS = 63;
44 class WW8TableNodeInfo;
45 typedef boost::shared_ptr<SwRect> SwRectPtr;
46 typedef ::std::vector<const SwTableBox *> TableBoxVector;
47 typedef boost::shared_ptr<TableBoxVector> TableBoxVectorPtr;
48 typedef ::std::vector<sal_uInt32> GridCols;
49 typedef boost::shared_ptr<GridCols> GridColsPtr;
50 typedef ::std::vector<sal_uInt32> RowSpans;
51 typedef boost::shared_ptr<RowSpans> RowSpansPtr;
52 typedef ::std::vector<sal_uInt32> Widths;
53 typedef boost::shared_ptr<Widths> WidthsPtr;
55 class WW8TableNodeInfoInner
57 WW8TableNodeInfo * mpParent;
58 sal_uInt32 mnDepth;
59 sal_uInt32 mnCell;
60 sal_uInt32 mnRow;
61 sal_uInt32 mnShadowsBefore;
62 sal_uInt32 mnShadowsAfter;
63 bool mbEndOfLine;
64 bool mbEndOfCell;
65 bool mbFirstInTable;
66 bool mbVertMerge;
67 const SwTableBox * mpTableBox;
68 const SwTable * mpTable;
69 SwRect maRect;
71 public:
72 typedef boost::shared_ptr<WW8TableNodeInfoInner> Pointer_t;
74 WW8TableNodeInfoInner(WW8TableNodeInfo * pParent);
75 ~WW8TableNodeInfoInner();
77 void setDepth(sal_uInt32 nDepth);
78 void setCell(sal_uInt32 nCell);
79 void setRow(sal_uInt32 nRow);
80 void setShadowsBefore(sal_uInt32 nShadowsBefore);
81 void setShadowsAfter(sal_uInt32 nShadowsAfter);
82 void setEndOfLine(bool bEndOfLine);
83 void setEndOfCell(bool bEndOfCell);
84 void setFirstInTable(bool bFirstInTable);
85 void setVertMerge(bool bVertMErge);
86 void setTableBox(const SwTableBox * pTableBox);
87 void setTable(const SwTable * pTable);
88 void setRect(const SwRect & rRect);
90 sal_uInt32 getDepth() const;
91 sal_uInt32 getCell() const;
92 sal_uInt32 getRow() const;
93 sal_uInt32 getShadowsBefore() const;
94 sal_uInt32 getShadowsAfter() const;
95 bool isEndOfCell() const;
96 bool isEndOfLine() const;
97 bool isFirstInTable() const;
98 bool isVertMerge() const;
99 const SwTableBox * getTableBox() const;
100 const SwTable * getTable() const;
101 const SwRect & getRect() const;
103 const SwNode * getNode() const;
105 TableBoxVectorPtr getTableBoxesOfRow();
106 WidthsPtr getWidthsOfRow();
107 GridColsPtr getGridColsOfRow(AttributeOutputBase & rBase);
108 RowSpansPtr getRowSpansOfRow();
110 #ifdef DBG_UTIL
111 ::std::string toString() const;
112 #endif
115 class CellInfo;
116 typedef ::std::multiset<CellInfo, less<CellInfo> > CellInfoMultiSet;
117 typedef boost::shared_ptr<CellInfoMultiSet> CellInfoMultiSetPtr;
119 class WW8TableInfo;
120 class WW8TableNodeInfo
122 public:
123 typedef map<sal_uInt32, WW8TableNodeInfoInner::Pointer_t,
124 greater<sal_uInt32> > Inners_t;
126 private:
127 WW8TableInfo * mpParent;
128 sal_uInt32 mnDepth;
129 const SwNode * mpNode;
130 Inners_t mInners;
131 WW8TableNodeInfo * mpNext;
132 const SwNode * mpNextNode;
134 public:
135 typedef boost::shared_ptr<WW8TableNodeInfo> Pointer_t;
137 WW8TableNodeInfo(WW8TableInfo * pParent, const SwNode * pTxtNode);
138 virtual ~WW8TableNodeInfo();
140 void setDepth(sal_uInt32 nDepth);
141 void setEndOfLine(bool bEndOfLine);
142 void setEndOfCell(bool bEndOfCell);
143 void setFirstInTable(bool bFirstInTable);
144 void setVertMerge(bool bVertMerge);
145 void setTableBox(const SwTableBox *pTableBox);
146 void setTable(const SwTable * pTable);
147 void setCell(sal_uInt32 nCell);
148 void setRow(sal_uInt32 nRow);
149 void setShadowsBefore(sal_uInt32 nShadowsBefore);
150 void setShadowsAfter(sal_uInt32 nShadowsAfter);
151 void setNext(WW8TableNodeInfo * pNext);
152 void setNextNode(const SwNode * pNode);
153 void setRect(const SwRect & rRect);
155 WW8TableInfo * getParent() const;
156 sal_uInt32 getDepth() const;
157 bool isEndOfLine() const;
158 bool isEndOfCell() const;
159 bool isFirstInTable() const;
160 const SwNode * getNode() const;
161 const SwTableBox * getTableBox() const;
162 WW8TableNodeInfo * getNext() const;
163 const SwNode * getNextNode() const;
164 const SwRect & getRect() const;
166 const Inners_t & getInners() const;
167 const WW8TableNodeInfoInner::Pointer_t getFirstInner() const;
168 const WW8TableNodeInfoInner::Pointer_t getInnerForDepth(sal_uInt32 nDepth) const;
170 sal_uInt32 getCell() const;
171 sal_uInt32 getRow() const;
173 #ifdef DBG_UTIL
174 ::std::string toString() const;
175 #endif
177 bool operator < (const WW8TableNodeInfo & rInfo) const;
180 struct hashNode
182 size_t operator()(const SwNode * pNode) const
183 { return reinterpret_cast<size_t>(pNode); }
186 struct hashTable
188 size_t operator()(const SwTable * pTable) const
189 { return reinterpret_cast<size_t>(pTable); }
192 class WW8TableCellGridRow
194 CellInfoMultiSetPtr m_pCellInfos;
195 TableBoxVectorPtr m_pTableBoxVector;
196 WidthsPtr m_pWidths;
197 RowSpansPtr m_pRowSpans;
199 public:
200 typedef boost::shared_ptr<WW8TableCellGridRow> Pointer_t;
201 WW8TableCellGridRow();
202 ~WW8TableCellGridRow();
204 void insert(const CellInfo & rCellInfo);
205 CellInfoMultiSet::const_iterator begin() const;
206 CellInfoMultiSet::const_iterator end() const;
208 void setTableBoxVector(TableBoxVectorPtr pTableBoxVector);
209 void setWidths(WidthsPtr pGridCols);
210 void setRowSpans(RowSpansPtr pRowSpans);
212 TableBoxVectorPtr getTableBoxVector() const;
213 WidthsPtr getWidths() const;
214 RowSpansPtr getRowSpans() const;
217 class WW8TableCellGrid
219 typedef ::std::set<long> RowTops_t;
220 typedef ::std::map<long, WW8TableCellGridRow::Pointer_t> Rows_t;
222 RowTops_t m_aRowTops;
223 Rows_t m_aRows;
225 WW8TableCellGridRow::Pointer_t getRow(long nTop, bool bCreate = true);
226 RowTops_t::const_iterator getRowTopsBegin() const;
227 RowTops_t::const_iterator getRowTopsEnd() const;
228 CellInfoMultiSet::const_iterator getCellsBegin(long nTop);
229 CellInfoMultiSet::const_iterator getCellsEnd(long nTop);
231 public:
232 typedef ::boost::shared_ptr<WW8TableCellGrid> Pointer_t;
234 WW8TableCellGrid();
235 ~WW8TableCellGrid();
237 void insert(const SwRect & rRect, WW8TableNodeInfo * pNodeInfo,
238 unsigned long * pFmtFrmWidth = NULL);
239 void addShadowCells();
240 WW8TableNodeInfo * connectCells();
242 #ifdef DBG_UTIL
243 ::std::string toString();
244 #endif
246 TableBoxVectorPtr getTableBoxesOfRow(WW8TableNodeInfoInner * pNodeInfo);
247 WidthsPtr getWidthsOfRow(WW8TableNodeInfoInner * pNodeInfo);
248 RowSpansPtr getRowSpansOfRow(WW8TableNodeInfoInner * pNodeInfo);
251 class WW8TableInfo
253 friend class WW8TableNodeInfoInner;
254 typedef boost::unordered_map<const SwNode *, WW8TableNodeInfo::Pointer_t, hashNode > Map_t;
255 Map_t mMap;
257 typedef boost::unordered_map<const SwTable *, WW8TableCellGrid::Pointer_t, hashTable > CellGridMap_t;
258 CellGridMap_t mCellGridMap;
260 typedef boost::unordered_map<const SwTable *, const SwNode *, hashTable > FirstInTableMap_t;
261 FirstInTableMap_t mFirstInTableMap;
263 WW8TableNodeInfo *
264 processTableLine(const SwTable * pTable,
265 const SwTableLine * pTableLine,
266 sal_uInt32 nRow,
267 sal_uInt32 nDepth, WW8TableNodeInfo * pPrev);
269 WW8TableNodeInfo *
270 processTableBox(const SwTable * pTable,
271 const SwTableBox * pTableBox,
272 sal_uInt32 nRow,
273 sal_uInt32 nCell,
274 sal_uInt32 nDepth, bool bEndOfLine, WW8TableNodeInfo * pPrev);
276 WW8TableNodeInfo::Pointer_t
277 processTableBoxLines(const SwTableBox * pBox,
278 const SwTable * pTable,
279 const SwTableBox * pBoxToSet,
280 sal_uInt32 nRow,
281 sal_uInt32 nCell,
282 sal_uInt32 nDepth);
284 WW8TableNodeInfo::Pointer_t
285 insertTableNodeInfo(const SwNode * pNode,
286 const SwTable * pTable,
287 const SwTableBox * pTableBox,
288 sal_uInt32 nRow,
289 sal_uInt32 nCell,
290 sal_uInt32 nDepth,
291 SwRect * pRect = NULL);
293 WW8TableCellGrid::Pointer_t getCellGridForTable(const SwTable * pTable,
294 bool bCreate = true);
296 public:
297 typedef boost::shared_ptr<WW8TableInfo> Pointer_t;
299 WW8TableInfo();
300 virtual ~WW8TableInfo();
302 void processSwTable(const SwTable * pTable);
303 WW8TableNodeInfo * processSwTableByLayout(const SwTable * pTable);
304 WW8TableNodeInfo::Pointer_t getTableNodeInfo(const SwNode * pNode);
305 const SwNode * getNextNode(const SwNode * pNode);
306 const WW8TableNodeInfo * getFirstTableNodeInfo() const;
308 WW8TableNodeInfo * reorderByLayout(const SwTable * pTable);
311 class CellInfo
313 SwRect m_aRect;
314 WW8TableNodeInfo * m_pNodeInfo;
315 unsigned long m_nFmtFrmWidth;
317 public:
318 CellInfo(const SwRect & aRect, WW8TableNodeInfo * pNodeInfo);
320 CellInfo(const CellInfo & aRectAndTableInfo)
321 : m_aRect(aRectAndTableInfo.m_aRect),
322 m_pNodeInfo(aRectAndTableInfo.m_pNodeInfo),
323 m_nFmtFrmWidth(aRectAndTableInfo.m_nFmtFrmWidth)
327 ~CellInfo() {}
329 bool operator < (const CellInfo & aCellInfo) const;
331 long top() const { return m_aRect.Top(); }
332 long bottom() const { return m_aRect.Bottom(); }
333 long left() const { return m_aRect.Left(); }
334 long right() const { return m_aRect.Right(); }
335 long width() const { return m_aRect.Width(); }
336 long height() const { return m_aRect.Height(); }
337 SwRect getRect() const { return m_aRect; }
338 WW8TableNodeInfo * getTableNodeInfo() const
339 { return m_pNodeInfo; }
340 unsigned long getFmtFrmWidth() const
342 return m_nFmtFrmWidth;
345 void setFmtFrmWidth(unsigned long nFmtFrmWidth)
347 m_nFmtFrmWidth = nFmtFrmWidth;
350 #ifdef DBG_UTIL
351 ::std::string toString() const;
352 #endif
356 #endif // WW8_TABLE_INFO_HXX
358 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */