Line data Source code
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 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>
31 :
32 : class SwTable;
33 : class SwTableLine;
34 : class SwTableBox;
35 : class SwNode;
36 : class AttributeOutputBase;
37 :
38 : namespace ww8
39 : {
40 : using namespace ::std;
41 :
42 : const unsigned int MAXTABLECELLS = 63;
43 :
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;
54 :
55 : class WW8TableNodeInfoInner
56 : {
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;
70 :
71 : public:
72 : typedef boost::shared_ptr<WW8TableNodeInfoInner> Pointer_t;
73 :
74 : WW8TableNodeInfoInner(WW8TableNodeInfo * pParent);
75 : ~WW8TableNodeInfoInner();
76 :
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);
89 :
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;
102 :
103 : const SwNode * getNode() const;
104 :
105 : TableBoxVectorPtr getTableBoxesOfRow();
106 : WidthsPtr getWidthsOfRow();
107 : GridColsPtr getGridColsOfRow(AttributeOutputBase & rBase);
108 : RowSpansPtr getRowSpansOfRow();
109 :
110 : #ifdef DBG_UTIL
111 : ::std::string toString() const;
112 : #endif
113 : };
114 :
115 : class CellInfo;
116 : typedef ::std::multiset<CellInfo, less<CellInfo> > CellInfoMultiSet;
117 : typedef boost::shared_ptr<CellInfoMultiSet> CellInfoMultiSetPtr;
118 :
119 : class WW8TableInfo;
120 : class WW8TableNodeInfo
121 : {
122 : public:
123 : typedef map<sal_uInt32, WW8TableNodeInfoInner::Pointer_t,
124 : greater<sal_uInt32> > Inners_t;
125 :
126 : private:
127 : WW8TableInfo * mpParent;
128 : sal_uInt32 mnDepth;
129 : const SwNode * mpNode;
130 : Inners_t mInners;
131 : WW8TableNodeInfo * mpNext;
132 : const SwNode * mpNextNode;
133 :
134 : public:
135 : typedef boost::shared_ptr<WW8TableNodeInfo> Pointer_t;
136 :
137 : WW8TableNodeInfo(WW8TableInfo * pParent, const SwNode * pTxtNode);
138 : virtual ~WW8TableNodeInfo();
139 :
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);
154 :
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;
165 :
166 : const Inners_t & getInners() const;
167 : const WW8TableNodeInfoInner::Pointer_t getFirstInner() const;
168 : const WW8TableNodeInfoInner::Pointer_t getInnerForDepth(sal_uInt32 nDepth) const;
169 :
170 : sal_uInt32 getCell() const;
171 : sal_uInt32 getRow() const;
172 :
173 : #ifdef DBG_UTIL
174 : ::std::string toString() const;
175 : #endif
176 :
177 : bool operator < (const WW8TableNodeInfo & rInfo) const;
178 : };
179 :
180 : struct hashNode
181 : {
182 962 : size_t operator()(const SwNode * pNode) const
183 962 : { return reinterpret_cast<size_t>(pNode); }
184 : };
185 :
186 : struct hashTable
187 : {
188 82 : size_t operator()(const SwTable * pTable) const
189 82 : { return reinterpret_cast<size_t>(pTable); }
190 : };
191 :
192 : class WW8TableCellGridRow
193 : {
194 : CellInfoMultiSetPtr m_pCellInfos;
195 : TableBoxVectorPtr m_pTableBoxVector;
196 : WidthsPtr m_pWidths;
197 : RowSpansPtr m_pRowSpans;
198 :
199 : public:
200 : typedef boost::shared_ptr<WW8TableCellGridRow> Pointer_t;
201 : WW8TableCellGridRow();
202 : ~WW8TableCellGridRow();
203 :
204 : void insert(const CellInfo & rCellInfo);
205 : CellInfoMultiSet::const_iterator begin() const;
206 : CellInfoMultiSet::const_iterator end() const;
207 :
208 : void setTableBoxVector(TableBoxVectorPtr pTableBoxVector);
209 : void setWidths(WidthsPtr pGridCols);
210 : void setRowSpans(RowSpansPtr pRowSpans);
211 :
212 : TableBoxVectorPtr getTableBoxVector() const;
213 : WidthsPtr getWidths() const;
214 : RowSpansPtr getRowSpans() const;
215 : };
216 :
217 : class WW8TableCellGrid
218 : {
219 : typedef ::std::set<long> RowTops_t;
220 : typedef ::std::map<long, WW8TableCellGridRow::Pointer_t> Rows_t;
221 :
222 : RowTops_t m_aRowTops;
223 : Rows_t m_aRows;
224 :
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);
230 :
231 : public:
232 : typedef ::boost::shared_ptr<WW8TableCellGrid> Pointer_t;
233 :
234 : WW8TableCellGrid();
235 : ~WW8TableCellGrid();
236 :
237 : void insert(const SwRect & rRect, WW8TableNodeInfo * pNodeInfo,
238 : unsigned long * pFmtFrmWidth = NULL);
239 : void addShadowCells();
240 : WW8TableNodeInfo * connectCells();
241 :
242 : #ifdef DBG_UTIL
243 : ::std::string toString();
244 : #endif
245 :
246 : TableBoxVectorPtr getTableBoxesOfRow(WW8TableNodeInfoInner * pNodeInfo);
247 : WidthsPtr getWidthsOfRow(WW8TableNodeInfoInner * pNodeInfo);
248 : RowSpansPtr getRowSpansOfRow(WW8TableNodeInfoInner * pNodeInfo);
249 : };
250 :
251 : class WW8TableInfo
252 : {
253 : friend class WW8TableNodeInfoInner;
254 : typedef boost::unordered_map<const SwNode *, WW8TableNodeInfo::Pointer_t, hashNode > Map_t;
255 : Map_t mMap;
256 :
257 : typedef boost::unordered_map<const SwTable *, WW8TableCellGrid::Pointer_t, hashTable > CellGridMap_t;
258 : CellGridMap_t mCellGridMap;
259 :
260 : typedef boost::unordered_map<const SwTable *, const SwNode *, hashTable > FirstInTableMap_t;
261 : FirstInTableMap_t mFirstInTableMap;
262 :
263 : WW8TableNodeInfo *
264 : processTableLine(const SwTable * pTable,
265 : const SwTableLine * pTableLine,
266 : sal_uInt32 nRow,
267 : sal_uInt32 nDepth, WW8TableNodeInfo * pPrev);
268 :
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);
275 :
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);
283 :
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);
292 :
293 : WW8TableCellGrid::Pointer_t getCellGridForTable(const SwTable * pTable,
294 : bool bCreate = true);
295 :
296 : public:
297 : typedef boost::shared_ptr<WW8TableInfo> Pointer_t;
298 :
299 : WW8TableInfo();
300 : virtual ~WW8TableInfo();
301 :
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;
307 :
308 : WW8TableNodeInfo * reorderByLayout(const SwTable * pTable);
309 : };
310 :
311 : class CellInfo
312 : {
313 : SwRect m_aRect;
314 : WW8TableNodeInfo * m_pNodeInfo;
315 : unsigned long m_nFmtFrmWidth;
316 :
317 : public:
318 : CellInfo(const SwRect & aRect, WW8TableNodeInfo * pNodeInfo);
319 :
320 0 : CellInfo(const CellInfo & aRectAndTableInfo)
321 : : m_aRect(aRectAndTableInfo.m_aRect),
322 : m_pNodeInfo(aRectAndTableInfo.m_pNodeInfo),
323 0 : m_nFmtFrmWidth(aRectAndTableInfo.m_nFmtFrmWidth)
324 : {
325 0 : }
326 :
327 0 : ~CellInfo() {}
328 :
329 : bool operator < (const CellInfo & aCellInfo) const;
330 :
331 0 : long top() const { return m_aRect.Top(); }
332 0 : long bottom() const { return m_aRect.Bottom(); }
333 0 : long left() const { return m_aRect.Left(); }
334 : long right() const { return m_aRect.Right(); }
335 0 : long width() const { return m_aRect.Width(); }
336 0 : long height() const { return m_aRect.Height(); }
337 0 : SwRect getRect() const { return m_aRect; }
338 0 : WW8TableNodeInfo * getTableNodeInfo() const
339 0 : { return m_pNodeInfo; }
340 0 : unsigned long getFmtFrmWidth() const
341 : {
342 0 : return m_nFmtFrmWidth;
343 : }
344 :
345 0 : void setFmtFrmWidth(unsigned long nFmtFrmWidth)
346 : {
347 0 : m_nFmtFrmWidth = nFmtFrmWidth;
348 0 : }
349 :
350 : #ifdef DBG_UTIL
351 : ::std::string toString() const;
352 : #endif
353 : };
354 :
355 : }
356 : #endif // WW8_TABLE_INFO_HXX
357 :
358 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|