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 : #include <iostream>
21 : #include <set>
22 : #include <stdio.h>
23 : #include "WW8TableInfo.hxx"
24 : #include "fmtfsize.hxx"
25 : #include "attributeoutputbase.hxx"
26 : #include "swtable.hxx"
27 : #include "frmfmt.hxx"
28 : #include "pam.hxx"
29 : #include "ndtxt.hxx"
30 : #include "dbgoutsw.hxx"
31 :
32 : namespace ww8
33 : {
34 :
35 13518 : WW8TableNodeInfoInner::WW8TableNodeInfoInner(WW8TableNodeInfo * pParent)
36 : : mpParent(pParent)
37 : , mnDepth(0)
38 : , mnCell(0)
39 : , mnRow(0)
40 : , mnShadowsBefore(0)
41 : , mnShadowsAfter(0)
42 : , mbEndOfLine(false)
43 : , mbEndOfCell(false)
44 : , mbFirstInTable(false)
45 : , mbVertMerge(false)
46 : , mpTableBox(NULL)
47 13518 : , mpTable(NULL)
48 : {
49 13518 : }
50 :
51 13518 : WW8TableNodeInfoInner::~WW8TableNodeInfoInner()
52 : {
53 13518 : }
54 :
55 13518 : void WW8TableNodeInfoInner::setDepth(sal_uInt32 nDepth)
56 : {
57 13518 : mnDepth = nDepth;
58 13518 : }
59 :
60 13912 : void WW8TableNodeInfoInner::setCell(sal_uInt32 nCell)
61 : {
62 13912 : mnCell = nCell;
63 13912 : }
64 :
65 13518 : void WW8TableNodeInfoInner::setRow(sal_uInt32 nRow)
66 : {
67 13518 : mnRow = nRow;
68 13518 : }
69 :
70 0 : void WW8TableNodeInfoInner::setShadowsBefore(sal_uInt32 nShadowsBefore)
71 : {
72 0 : mnShadowsBefore = nShadowsBefore;
73 0 : }
74 :
75 0 : void WW8TableNodeInfoInner::setShadowsAfter(sal_uInt32 nShadowsAfter)
76 : {
77 0 : mnShadowsAfter = nShadowsAfter;
78 0 : }
79 :
80 1446 : void WW8TableNodeInfoInner::setEndOfLine(bool bEndOfLine)
81 : {
82 1446 : mbEndOfLine = bEndOfLine;
83 1446 : }
84 :
85 3602 : void WW8TableNodeInfoInner::setEndOfCell(bool bEndOfCell)
86 : {
87 3602 : mbEndOfCell = bEndOfCell;
88 3602 : }
89 :
90 320 : void WW8TableNodeInfoInner::setFirstInTable(bool bFirstInTable)
91 : {
92 320 : mbFirstInTable = bFirstInTable;
93 320 : }
94 :
95 0 : void WW8TableNodeInfoInner::setVertMerge(bool bVertMerge)
96 :
97 : {
98 0 : mbVertMerge = bVertMerge;
99 0 : }
100 :
101 13518 : void WW8TableNodeInfoInner::setTableBox(const SwTableBox * pTableBox)
102 : {
103 13518 : mpTableBox = pTableBox;
104 13518 : }
105 :
106 13518 : void WW8TableNodeInfoInner::setTable(const SwTable * pTable)
107 : {
108 13518 : mpTable = pTable;
109 13518 : }
110 :
111 0 : void WW8TableNodeInfoInner::setRect(const SwRect & rRect)
112 : {
113 0 : maRect = rRect;
114 0 : }
115 :
116 :
117 :
118 :
119 :
120 :
121 :
122 :
123 :
124 5690 : const SwNode * WW8TableNodeInfoInner::getNode() const
125 : {
126 5690 : const SwNode * pResult = NULL;
127 :
128 5690 : if (mpParent != NULL)
129 5690 : pResult = mpParent->getNode();
130 :
131 5690 : return pResult;
132 : }
133 :
134 72 : TableBoxVectorPtr WW8TableNodeInfoInner::getTableBoxesOfRow()
135 : {
136 72 : TableBoxVectorPtr pResult(new TableBoxVector);
137 :
138 : WW8TableCellGrid::Pointer_t pCellGrid =
139 144 : mpParent->getParent()->getCellGridForTable(getTable(), false);
140 :
141 72 : if (pCellGrid.get() == NULL)
142 : {
143 72 : const SwTableLine * pTabLine = getTableBox()->GetUpper();
144 72 : const SwTableBoxes & rTblBoxes = pTabLine->GetTabBoxes();
145 :
146 72 : sal_uInt8 nBoxes = rTblBoxes.size();
147 340 : for ( sal_uInt8 n = 0; n < nBoxes; n++ )
148 : {
149 268 : pResult->push_back(rTblBoxes[n]);
150 : }
151 : }
152 : else
153 0 : pResult = pCellGrid->getTableBoxesOfRow(this);
154 :
155 144 : return pResult;
156 : }
157 :
158 5058 : GridColsPtr WW8TableNodeInfoInner::getGridColsOfRow(AttributeOutputBase & rBase, bool calculateColumnsFromAllRows)
159 : {
160 5058 : GridColsPtr pResult(new GridCols);
161 10116 : WidthsPtr pWidths;
162 :
163 : // Check which columns should be checked - only the current row,
164 : // or all the rows together
165 5058 : if (calculateColumnsFromAllRows)
166 : {
167 : // Calculate the width of all the columns based on ALL the rows.
168 : // The difference is that this kind of draws vertical lines,
169 : // so that if the rows look like this:
170 : //
171 : // ------------------------
172 : // | | |
173 : // ------------------------
174 : // | | |
175 : // ------------------------
176 : // | | |
177 : // ------------------------
178 :
179 : // then the actual column widths will be broken down like this:
180 : //
181 : // ------------------------
182 : // | | | | |
183 : // ------------------------
184 :
185 : // See the example at
186 : // http://officeopenxml.com/WPtableGrid.php
187 : // Under "Word 2007 Example"
188 264 : pWidths = getColumnWidthsBasedOnAllRows();
189 : }
190 : else
191 : {
192 : // Calculate the width of all the columns based on the current row
193 4794 : pWidths = getWidthsOfRow();
194 : }
195 :
196 5058 : const SwFrmFmt *pFmt = getTable()->GetFrmFmt();
197 : OSL_ENSURE(pFmt,"Impossible");
198 5058 : if (!pFmt)
199 0 : return pResult;
200 :
201 5058 : const SwFmtFrmSize &rSize = pFmt->GetFrmSize();
202 5058 : unsigned long nTblSz = static_cast<unsigned long>(rSize.GetWidth());
203 :
204 5058 : sal_uInt32 nPageSize = 0;
205 5058 : bool bRelBoxSize = false;
206 :
207 : rBase.GetTablePageSize
208 5058 : ( this, nPageSize, bRelBoxSize );
209 :
210 5058 : SwTwips nSz = 0;
211 5058 : Widths::const_iterator aWidthsEnd = pWidths->end();
212 20834 : for ( Widths::const_iterator aIt = pWidths->begin();
213 : aIt != aWidthsEnd;
214 : ++aIt)
215 : {
216 15776 : nSz += *aIt;
217 15776 : SwTwips nCalc = nSz;
218 15776 : if ( bRelBoxSize )
219 2844 : nCalc = ( nCalc * nPageSize ) / nTblSz;
220 :
221 15776 : pResult->push_back( nCalc );
222 : }
223 :
224 5058 : return pResult;
225 : }
226 :
227 264 : WidthsPtr WW8TableNodeInfoInner::getColumnWidthsBasedOnAllRows()
228 : {
229 264 : WidthsPtr pWidths;
230 :
231 : WW8TableCellGrid::Pointer_t pCellGrid =
232 528 : mpParent->getParent()->getCellGridForTable(getTable(), false);
233 :
234 264 : if (pCellGrid.get() == NULL)
235 : {
236 264 : const SwTable * pTable = getTable();
237 264 : const SwTableLines& rTableLines = pTable->GetTabLines();
238 264 : sal_uInt16 nNumOfLines = rTableLines.size();
239 :
240 : // Go over all the rows - and for each row - calculate where
241 : // there is a separator between columns
242 264 : WidthsPtr pSeparators(new Widths);
243 1546 : for ( sal_uInt32 nLineIndex = 0; nLineIndex < nNumOfLines; nLineIndex++)
244 : {
245 1282 : const SwTableLine *pCurrentLine = rTableLines[nLineIndex];
246 1282 : const SwTableBoxes & rTabBoxes = pCurrentLine->GetTabBoxes();
247 1282 : sal_uInt32 nBoxes = rTabBoxes.size();
248 1282 : if ( nBoxes > MAXTABLECELLS )
249 0 : nBoxes = MAXTABLECELLS;
250 :
251 1282 : sal_uInt32 nSeparatorPosition = 0;
252 4284 : for (sal_uInt32 nBoxIndex = 0; nBoxIndex < nBoxes; nBoxIndex++)
253 : {
254 3002 : const SwFrmFmt* pBoxFmt = rTabBoxes[ nBoxIndex ]->GetFrmFmt();
255 3002 : const SwFmtFrmSize& rLSz = pBoxFmt->GetFrmSize();
256 3002 : nSeparatorPosition += rLSz.GetWidth();
257 3002 : pSeparators->push_back(nSeparatorPosition);
258 : }
259 : }
260 :
261 : // Sort the separator positions and remove any duplicates
262 264 : std::sort(pSeparators->begin(), pSeparators->end());
263 264 : std::vector<sal_uInt32>::iterator it = std::unique(pSeparators->begin(), pSeparators->end());
264 264 : pSeparators->erase(it, pSeparators->end());
265 :
266 : // Calculate the widths based on the position of the unique & sorted
267 : // column separators
268 264 : pWidths = WidthsPtr(new Widths);
269 264 : sal_uInt32 nPreviousWidth = 0;
270 264 : Widths::const_iterator aItEnd2 = pSeparators->end();
271 898 : for (Widths::const_iterator aIt2 = pSeparators->begin(); aIt2 != aItEnd2; ++aIt2)
272 : {
273 634 : sal_uInt32 nCurrentWidth = *aIt2;
274 634 : pWidths->push_back(nCurrentWidth - nPreviousWidth);
275 634 : nPreviousWidth = nCurrentWidth;
276 264 : }
277 : }
278 : else
279 : {
280 0 : pWidths = pCellGrid->getWidthsOfRow(this);
281 : }
282 :
283 528 : return pWidths;
284 : }
285 :
286 4794 : WidthsPtr WW8TableNodeInfoInner::getWidthsOfRow()
287 : {
288 4794 : WidthsPtr pWidths;
289 :
290 : WW8TableCellGrid::Pointer_t pCellGrid =
291 9588 : mpParent->getParent()->getCellGridForTable(getTable(), false);
292 :
293 4794 : if (pCellGrid.get() == NULL)
294 : {
295 4794 : const SwTableBox * pTabBox = getTableBox();
296 4794 : const SwTableLine * pTabLine = pTabBox->GetUpper();
297 4794 : const SwTableBoxes & rTabBoxes = pTabLine->GetTabBoxes();
298 :
299 4794 : pWidths = WidthsPtr(new Widths);
300 : // number of cell written
301 4794 : sal_uInt32 nBoxes = rTabBoxes.size();
302 4794 : if ( nBoxes > MAXTABLECELLS )
303 0 : nBoxes = MAXTABLECELLS;
304 :
305 19936 : for (sal_uInt32 n = 0; n < nBoxes; n++)
306 : {
307 15142 : const SwFrmFmt* pBoxFmt = rTabBoxes[ n ]->GetFrmFmt();
308 15142 : const SwFmtFrmSize& rLSz = pBoxFmt->GetFrmSize();
309 :
310 15142 : pWidths->push_back(rLSz.GetWidth());
311 : }
312 : }
313 : else
314 0 : pWidths = pCellGrid->getWidthsOfRow(this);
315 :
316 9588 : return pWidths;
317 : }
318 :
319 72 : RowSpansPtr WW8TableNodeInfoInner::getRowSpansOfRow()
320 : {
321 72 : RowSpansPtr pResult(new RowSpans);
322 :
323 : WW8TableCellGrid::Pointer_t pCellGrid =
324 144 : mpParent->getParent()->getCellGridForTable(getTable(), false);
325 :
326 72 : if (pCellGrid.get() == NULL)
327 : {
328 72 : const SwTableBox * pTabBox = getTableBox();
329 72 : const SwTableLine * pTabLine = pTabBox->GetUpper();
330 72 : const SwTableBoxes & rTabBoxes = pTabLine->GetTabBoxes();
331 :
332 72 : sal_uInt32 nBoxes = rTabBoxes.size();
333 72 : if (nBoxes > MAXTABLECELLS)
334 0 : nBoxes = MAXTABLECELLS;
335 :
336 340 : for (sal_uInt32 n = 0; n < nBoxes; ++n)
337 : {
338 268 : pResult->push_back(rTabBoxes[n]->getRowSpan());
339 : }
340 : }
341 : else
342 0 : pResult = pCellGrid->getRowSpansOfRow(this);
343 :
344 144 : return pResult;
345 : }
346 :
347 :
348 :
349 :
350 : #ifdef DBG_UTIL
351 : ::std::string WW8TableNodeInfoInner::toString() const
352 : {
353 : static char buffer[256];
354 : snprintf(buffer, sizeof(buffer),
355 : "<tableinner depth=\"%" SAL_PRIuUINT32 "\""
356 : " cell=\"%" SAL_PRIuUINT32 "\""
357 : " row=\"%" SAL_PRIuUINT32 "\""
358 : " endOfCell=\"%s\""
359 : " endOfLine=\"%s\""
360 : " shadowsBefore=\"%" SAL_PRIuUINT32 "\""
361 : " shadowsAfter=\"%" SAL_PRIuUINT32 "\""
362 : " vertMerge=\"%s\"/>",
363 : mnDepth, mnCell, mnRow,
364 : mbEndOfCell ? "yes" : "no",
365 : mbEndOfLine ? "yes" : "no",
366 : mnShadowsBefore,
367 : mnShadowsAfter,
368 : mbVertMerge ? "yes" : "no");
369 :
370 : return ::std::string(buffer);
371 : }
372 : #endif
373 :
374 11478 : WW8TableNodeInfo::WW8TableNodeInfo(WW8TableInfo * pParent,
375 : const SwNode * pNode)
376 : : mpParent(pParent),
377 : mnDepth(0),
378 : mpNode(pNode),
379 : mpNext(NULL),
380 11478 : mpNextNode(NULL)
381 : {
382 11478 : }
383 :
384 22956 : WW8TableNodeInfo::~WW8TableNodeInfo()
385 : {
386 22956 : }
387 :
388 : #ifdef DBG_UTIL
389 : ::std::string WW8TableNodeInfo::toString() const
390 : {
391 : static char buffer[1024];
392 : snprintf(buffer, sizeof(buffer),
393 : "<tableNodeInfo p=\"%p\" depth=\"%" SAL_PRIuUINT32 "\">"
394 : ,this, getDepth());
395 :
396 : ::std::string sResult(buffer);
397 :
398 : Inners_t::const_iterator aIt(mInners.begin());
399 : Inners_t::const_iterator aEnd(mInners.end());
400 :
401 : while (aIt != aEnd)
402 : {
403 : WW8TableNodeInfoInner::Pointer_t pInner = aIt->second;
404 : sResult += pInner->toString();
405 :
406 : ++aIt;
407 : }
408 : sResult += dbg_out(*mpNode);
409 : sResult += "</tableNodeInfo>";
410 :
411 : return sResult;
412 : }
413 : #endif
414 :
415 13518 : void WW8TableNodeInfo::setDepth(sal_uInt32 nDepth)
416 : {
417 13518 : mnDepth = nDepth;
418 :
419 13518 : Inners_t::iterator aIt = mInners.find(mnDepth);
420 :
421 13518 : if (aIt == mInners.end())
422 13518 : mInners[mnDepth] = WW8TableNodeInfoInner::Pointer_t(new WW8TableNodeInfoInner(this));
423 :
424 13518 : mInners[mnDepth]->setDepth(mnDepth);
425 13518 : }
426 :
427 1446 : void WW8TableNodeInfo::setEndOfLine(bool bEndOfLine)
428 : {
429 1446 : WW8TableNodeInfoInner::Pointer_t pInner = getInnerForDepth(mnDepth);
430 1446 : pInner->setEndOfLine(bEndOfLine);
431 :
432 : #ifdef DBG_UTIL
433 : SAL_INFO( "sw.ww8", "<endOfLine depth=\"" << mnDepth << "\">" << toString() << "</endOfLine>" );
434 : #endif
435 1446 : }
436 :
437 3602 : void WW8TableNodeInfo::setEndOfCell(bool bEndOfCell)
438 : {
439 3602 : WW8TableNodeInfoInner::Pointer_t pInner = getInnerForDepth(mnDepth);
440 3602 : pInner->setEndOfCell(bEndOfCell);
441 :
442 : #ifdef DBG_UTIL
443 : SAL_INFO( "sw.ww8", "<endOfCell depth=\"" << mnDepth << "\">" << toString() << "</endOfCell>" );
444 : #endif
445 3602 : }
446 :
447 320 : void WW8TableNodeInfo::setFirstInTable(bool bFirstInTable)
448 : {
449 320 : WW8TableNodeInfoInner::Pointer_t pInner = getInnerForDepth(mnDepth);
450 :
451 320 : pInner->setFirstInTable(bFirstInTable);
452 :
453 : #ifdef DBG_UTIL
454 : SAL_INFO( "sw.ww8", "<firstInTable depth=\"" << mnDepth << "\">" << toString() << "</firstInTable>" );
455 : #endif
456 320 : }
457 :
458 0 : void WW8TableNodeInfo::setVertMerge(bool bVertMerge)
459 : {
460 0 : WW8TableNodeInfoInner::Pointer_t pInner = getInnerForDepth(mnDepth);
461 :
462 0 : pInner->setVertMerge(bVertMerge);
463 :
464 : #ifdef DBG_UTIL
465 : SAL_INFO( "sw.ww8", "<vertMerge depth=\"" << mnDepth << "\">" << toString() << "</vertMerge>" );
466 : #endif
467 0 : }
468 :
469 13518 : void WW8TableNodeInfo::setTableBox(const SwTableBox * pTableBox)
470 : {
471 13518 : getInnerForDepth(mnDepth)->setTableBox(pTableBox);
472 13518 : }
473 :
474 13518 : void WW8TableNodeInfo::setTable(const SwTable * pTable)
475 : {
476 13518 : getInnerForDepth(mnDepth)->setTable(pTable);
477 13518 : }
478 :
479 13198 : void WW8TableNodeInfo::setNext(WW8TableNodeInfo * pNext)
480 : {
481 13198 : mpNext = pNext;
482 :
483 : #ifdef DBG_UTIL
484 : SAL_INFO( "sw.ww8", "<setnext><from>" << toString() << "</from><to>" << pNext->toString() << "</to></setnext>" );
485 : #endif
486 13198 : }
487 :
488 320 : void WW8TableNodeInfo::setNextNode(const SwNode * pNode)
489 : {
490 320 : mpNextNode = pNode;
491 320 : }
492 :
493 0 : void WW8TableNodeInfo::setRect(const SwRect & rRect)
494 : {
495 0 : getInnerForDepth(mnDepth)->setRect(rRect);
496 0 : }
497 :
498 13518 : void WW8TableNodeInfo::setCell(sal_uInt32 nCell)
499 : {
500 13518 : getInnerForDepth(mnDepth)->setCell(nCell);
501 13518 : }
502 :
503 13518 : void WW8TableNodeInfo::setRow(sal_uInt32 nRow)
504 : {
505 13518 : getInnerForDepth(mnDepth)->setRow(nRow);
506 13518 : }
507 :
508 0 : void WW8TableNodeInfo::setShadowsBefore(sal_uInt32 nShadowsBefore)
509 : {
510 0 : getInnerForDepth(mnDepth)->setShadowsBefore(nShadowsBefore);
511 0 : }
512 :
513 0 : void WW8TableNodeInfo::setShadowsAfter(sal_uInt32 nShadowsAfter)
514 : {
515 0 : getInnerForDepth(mnDepth)->setShadowsAfter(nShadowsAfter);
516 0 : }
517 :
518 :
519 14730 : sal_uInt32 WW8TableNodeInfo::getDepth() const
520 : {
521 14730 : if (!mInners.empty())
522 3252 : return mInners.begin()->second->getDepth();
523 :
524 11478 : return mnDepth;
525 : }
526 :
527 :
528 0 : const SwTableBox * WW8TableNodeInfo::getTableBox() const
529 : {
530 0 : return getInnerForDepth(mnDepth)->getTableBox();
531 : }
532 :
533 :
534 :
535 3740 : sal_uInt32 WW8TableNodeInfo::getCell() const
536 : {
537 3740 : return getInnerForDepth(mnDepth)->getCell();
538 : }
539 :
540 3740 : sal_uInt32 WW8TableNodeInfo::getRow() const
541 : {
542 3740 : return getInnerForDepth(mnDepth)->getRow();
543 : }
544 :
545 :
546 4226 : const WW8TableNodeInfoInner::Pointer_t WW8TableNodeInfo::getFirstInner() const
547 : {
548 4226 : WW8TableNodeInfoInner::Pointer_t pResult;
549 :
550 4226 : if (!mInners.empty())
551 4226 : pResult = mInners.begin()->second;
552 :
553 4226 : return pResult;
554 : }
555 :
556 70254 : const WW8TableNodeInfoInner::Pointer_t WW8TableNodeInfo::getInnerForDepth(sal_uInt32 nDepth) const
557 : {
558 70254 : WW8TableNodeInfoInner::Pointer_t pResult;
559 :
560 70254 : Inners_t::const_iterator aIt = mInners.find(nDepth);
561 70254 : if (aIt != mInners.end())
562 : {
563 70254 : pResult = aIt->second;
564 : }
565 :
566 70254 : return pResult;
567 : }
568 :
569 2554 : WW8TableInfo::WW8TableInfo()
570 : {
571 2554 : }
572 :
573 5108 : WW8TableInfo::~WW8TableInfo()
574 : {
575 5108 : }
576 :
577 : WW8TableNodeInfo *
578 0 : WW8TableInfo::processSwTableByLayout(const SwTable * pTable)
579 : {
580 0 : SwTableCellInfo aTableCellInfo(pTable);
581 0 : WW8TableNodeInfo * pPrev = NULL;
582 :
583 0 : while (aTableCellInfo.getNext())
584 : {
585 0 : SwRect aRect = aTableCellInfo.getRect();
586 :
587 : SAL_INFO( "sw.ww8", "<CellFrm>" );
588 : SAL_INFO( "sw.ww8", "<rect top=\"" << aRect.Top() << "\" bottom=\"" << aRect.Bottom()
589 : << "\" left=\"" << aRect.Left() << "\" right=\"" << aRect.Right() << "\"/>" );
590 0 : const SwTableBox * pTableBox = aTableCellInfo.getTableBox();
591 0 : const SwStartNode * pSttNd = pTableBox->GetSttNd();
592 :
593 0 : if (pSttNd != NULL)
594 : {
595 0 : SwPaM aPam(*pSttNd, 0);
596 :
597 0 : bool bDone = false;
598 0 : do
599 : {
600 0 : SwNode & rNode = aPam.GetPoint()->nNode.GetNode();
601 :
602 0 : insertTableNodeInfo(&rNode, pTable, pTableBox, 0, 0, 1, & aRect);
603 :
604 0 : if (rNode.IsEndNode())
605 : {
606 0 : SwEndNode * pEndNode = rNode.GetEndNode();
607 0 : SwStartNode * pTmpSttNd = pEndNode->StartOfSectionNode();
608 :
609 0 : if (pTmpSttNd == pSttNd)
610 0 : bDone = true;
611 : }
612 :
613 0 : aPam.GetPoint()->nNode++;
614 : }
615 0 : while (!bDone);
616 : }
617 :
618 : SAL_INFO( "sw.ww8", "</CellFrm>" );
619 : }
620 :
621 0 : pPrev = reorderByLayout(pTable);
622 :
623 0 : return pPrev;
624 : }
625 :
626 320 : void WW8TableInfo::processSwTable(const SwTable * pTable)
627 : {
628 : SAL_INFO( "sw.ww8", "<processSwTable>" );
629 :
630 320 : WW8TableNodeInfo * pPrev = NULL;
631 :
632 320 : if (pTable->IsTblComplex() && pTable->HasLayout())
633 : {
634 0 : pPrev = processSwTableByLayout(pTable);
635 :
636 : #ifdef DBG_UTIL
637 : SAL_INFO( "sw.ww8", getCellGridForTable(pTable)->toString());
638 : #endif
639 : }
640 : else
641 : {
642 320 : const SwTableLines & rLines = pTable->GetTabLines();
643 :
644 1766 : for (sal_uInt16 n = 0; n < rLines.size(); n++)
645 : {
646 1446 : const SwTableLine * pLine = rLines[n];
647 :
648 1446 : pPrev = processTableLine(pTable, pLine, n, 1, pPrev);
649 : }
650 :
651 : }
652 :
653 320 : if (pPrev != NULL)
654 : {
655 320 : SwTableNode * pTableNode = pTable->GetTableNode();
656 320 : SwEndNode * pEndNode = pTableNode->EndOfSectionNode();
657 :
658 320 : pPrev->setNextNode(pEndNode);
659 : }
660 : SAL_INFO( "sw.ww8", "</processSwTable>" );
661 320 : }
662 :
663 : WW8TableNodeInfo *
664 1446 : WW8TableInfo::processTableLine(const SwTable * pTable,
665 : const SwTableLine * pTableLine,
666 : sal_uInt32 nRow,
667 : sal_uInt32 nDepth, WW8TableNodeInfo * pPrev)
668 : {
669 : SAL_INFO( "sw.ww8", "<processTableLine row=\"" << nRow << "\" depth=\"" << nDepth << "\">" );
670 :
671 1446 : const SwTableBoxes & rBoxes = pTableLine->GetTabBoxes();
672 :
673 1446 : WW8TableNodeInfo::Pointer_t pTextNodeInfo;
674 :
675 5048 : for (sal_uInt16 n = 0; n < rBoxes.size(); n++)
676 : {
677 3602 : const SwTableBox * pBox = rBoxes[n];
678 :
679 3602 : pPrev = processTableBox(pTable, pBox, nRow, n, nDepth, n == rBoxes.size() - 1, pPrev);
680 : }
681 :
682 : SAL_INFO( "sw.ww8", "</processTableLine>" );
683 :
684 1446 : return pPrev;
685 : }
686 :
687 : WW8TableNodeInfo::Pointer_t
688 0 : WW8TableInfo::processTableBoxLines(const SwTableBox * pBox,
689 : const SwTable * pTable,
690 : const SwTableBox * pBoxToSet,
691 : sal_uInt32 nRow,
692 : sal_uInt32 nCell,
693 : sal_uInt32 nDepth)
694 : {
695 : SAL_INFO( "sw.ww8", "<processTableBoxLines depth=\"" << nDepth << "\" row=\"" << nRow
696 : << "\" cell=\"" << nCell << "\">" );
697 :
698 0 : const SwTableLines & rLines = pBox->GetTabLines();
699 0 : WW8TableNodeInfo::Pointer_t pNodeInfo;
700 :
701 0 : if (!rLines.empty())
702 : {
703 0 : for (sal_uInt32 n = 0; n < rLines.size(); n++)
704 : {
705 0 : const SwTableLine * pLine = rLines[n];
706 0 : const SwTableBoxes & rBoxes = pLine->GetTabBoxes();
707 :
708 0 : for (sal_uInt16 nBox = 0; nBox < rBoxes.size(); nBox++)
709 0 : pNodeInfo = processTableBoxLines(rBoxes[nBox], pTable, pBoxToSet, nRow, nCell, nDepth);
710 : }
711 : }
712 : else
713 : {
714 0 : const SwStartNode * pSttNd = pBox->GetSttNd();
715 0 : const SwEndNode * pEndNd = pSttNd->EndOfSectionNode();
716 0 : SwPaM aPaM(*pSttNd, 0);
717 0 : SwPaM aEndPaM(*pEndNd, 0);
718 :
719 0 : bool bDone = false;
720 0 : while (!bDone)
721 : {
722 0 : SwNode & rNode = aPaM.GetPoint()->nNode.GetNode();
723 :
724 0 : pNodeInfo = insertTableNodeInfo(&rNode, pTable, pBoxToSet, nRow, nCell, nDepth);
725 :
726 0 : if (aPaM.GetPoint()->nNode == aEndPaM.GetPoint()->nNode)
727 0 : bDone = true;
728 : else
729 0 : aPaM.GetPoint()->nNode++;
730 0 : }
731 : }
732 :
733 : SAL_INFO( "sw.ww8", "</processTableBoxLines>" );
734 :
735 0 : return pNodeInfo;
736 : }
737 :
738 : WW8TableNodeInfo *
739 3602 : WW8TableInfo::processTableBox(const SwTable * pTable,
740 : const SwTableBox * pBox,
741 : sal_uInt32 nRow,
742 : sal_uInt32 nCell,
743 : sal_uInt32 nDepth,
744 : bool bEndOfLine,
745 : WW8TableNodeInfo * pPrev)
746 : {
747 : SAL_INFO( "sw.ww8", "<processTableBox row=\"" << nRow << "\" cell=\"" << nCell
748 : << "\" depth=\"" << nDepth << "\">" );
749 :
750 3602 : WW8TableNodeInfo::Pointer_t pNodeInfo;
751 3602 : const SwTableLines & rLines = pBox->GetTabLines();
752 3602 : const SwStartNode * pSttNd = pBox->GetSttNd();
753 7204 : WW8TableNodeInfo::Pointer_t pEndOfCellInfo;
754 :
755 3602 : if (!rLines.empty())
756 : {
757 0 : pNodeInfo = processTableBoxLines(pBox, pTable, pBox, nRow, nCell, nDepth);
758 0 : pNodeInfo->setEndOfCell(true);
759 0 : if (bEndOfLine)
760 0 : pNodeInfo->setEndOfLine(true);
761 :
762 0 : for (sal_uInt32 n = 0; n < rLines.size(); n++)
763 : {
764 0 : const SwTableLine * pLine = rLines[n];
765 :
766 0 : pPrev = processTableLine(pTable, pLine, n, 1, pPrev);
767 : }
768 : }
769 : else
770 : {
771 3602 : SwPaM aPaM(*pSttNd, 0);
772 :
773 3602 : bool bDone = false;
774 3602 : sal_uInt32 nDepthInsideCell = 0;
775 :
776 13518 : do
777 : {
778 13518 : SwNode & rNode = aPaM.GetPoint()->nNode.GetNode();
779 :
780 13518 : if (rNode.IsStartNode())
781 : {
782 4302 : if (nDepthInsideCell > 0)
783 700 : pEndOfCellInfo.reset();
784 :
785 4302 : nDepthInsideCell++;
786 : }
787 :
788 13518 : pNodeInfo = insertTableNodeInfo(&rNode, pTable, pBox, nRow, nCell, nDepth);
789 :
790 13518 : if (pPrev != NULL)
791 13198 : pPrev->setNext(pNodeInfo.get());
792 :
793 13518 : pPrev = pNodeInfo.get();
794 :
795 13518 : if (nDepthInsideCell == 1 && rNode.IsTxtNode())
796 4226 : pEndOfCellInfo = pNodeInfo;
797 :
798 13518 : if (rNode.IsEndNode())
799 : {
800 4302 : nDepthInsideCell--;
801 :
802 4302 : if (nDepthInsideCell == 0 && pEndOfCellInfo.get() == NULL)
803 0 : pEndOfCellInfo = pNodeInfo;
804 :
805 4302 : SwEndNode * pEndNode = rNode.GetEndNode( );
806 4302 : SwStartNode * pTmpSttNd = pEndNode->StartOfSectionNode();
807 4302 : if (pTmpSttNd == pSttNd)
808 3602 : bDone = true;
809 : }
810 :
811 13518 : aPaM.GetPoint()->nNode++;
812 : }
813 13518 : while (!bDone);
814 :
815 3602 : if (pEndOfCellInfo.get() != NULL)
816 : {
817 3602 : pEndOfCellInfo->setEndOfCell(true);
818 :
819 3602 : if (bEndOfLine)
820 1446 : pEndOfCellInfo->setEndOfLine(true);
821 3602 : }
822 : }
823 :
824 : SAL_INFO( "sw.ww8", "</processTableBox>" );
825 :
826 7204 : return pPrev;
827 : }
828 :
829 13518 : WW8TableNodeInfo::Pointer_t WW8TableInfo::insertTableNodeInfo
830 : (const SwNode * pNode,
831 : const SwTable * pTable,
832 : const SwTableBox * pTableBox,
833 : sal_uInt32 nRow,
834 : sal_uInt32 nCell,
835 : sal_uInt32 nDepth,
836 : SwRect * pRect)
837 : {
838 13518 : WW8TableNodeInfo::Pointer_t pNodeInfo = getTableNodeInfo(pNode);
839 :
840 13518 : if (pNodeInfo.get() == NULL)
841 : {
842 34434 : pNodeInfo =
843 22956 : WW8TableNodeInfo::Pointer_t(new WW8TableNodeInfo(this, pNode));
844 11478 : mMap.insert(Map_t::value_type(pNode, pNodeInfo));
845 : }
846 :
847 13518 : pNodeInfo->setDepth(nDepth + pNodeInfo->getDepth());
848 :
849 13518 : pNodeInfo->setTable(pTable);
850 13518 : pNodeInfo->setTableBox(pTableBox);
851 :
852 13518 : pNodeInfo->setCell(nCell);
853 13518 : pNodeInfo->setRow(nRow);
854 :
855 13518 : if (pNode->IsTxtNode())
856 : {
857 4914 : FirstInTableMap_t::const_iterator aIt = mFirstInTableMap.find(pTable);
858 4914 : if (aIt == mFirstInTableMap.end())
859 : {
860 320 : mFirstInTableMap[pTable] = pNode;
861 320 : pNodeInfo->setFirstInTable(true);
862 : }
863 : }
864 :
865 13518 : if (pRect)
866 : {
867 0 : WW8TableCellGrid::Pointer_t pCellGrid = getCellGridForTable(pTable);
868 :
869 0 : pCellGrid->insert(*pRect, pNodeInfo.get());
870 0 : pNodeInfo->setRect(*pRect);
871 : }
872 :
873 : #ifdef DBG_UTIL
874 : SAL_INFO( "sw.ww8", pNodeInfo->toString());
875 : #endif
876 13518 : return pNodeInfo;
877 : }
878 :
879 5202 : WW8TableCellGrid::Pointer_t WW8TableInfo::getCellGridForTable
880 : (const SwTable * pTable, bool bCreate)
881 : {
882 5202 : WW8TableCellGrid::Pointer_t pResult;
883 5202 : CellGridMap_t::iterator aIt = mCellGridMap.find(pTable);
884 :
885 5202 : if (aIt == mCellGridMap.end())
886 : {
887 5202 : if (bCreate)
888 : {
889 0 : pResult = WW8TableCellGrid::Pointer_t(new WW8TableCellGrid);
890 0 : mCellGridMap[pTable] = pResult;
891 : }
892 : }
893 : else
894 0 : pResult = mCellGridMap[pTable];
895 :
896 5202 : return pResult;
897 : }
898 :
899 60976 : WW8TableNodeInfo::Pointer_t WW8TableInfo::getTableNodeInfo
900 : (const SwNode * pNode)
901 : {
902 60976 : WW8TableNodeInfo::Pointer_t pResult;
903 60976 : Map_t::iterator aIt = mMap.find(pNode);
904 :
905 60976 : if (aIt != mMap.end())
906 24900 : pResult = (*aIt).second;
907 :
908 60976 : return pResult;
909 : }
910 :
911 23330 : const SwNode * WW8TableInfo::getNextNode(const SwNode * pNode)
912 : {
913 23330 : const SwNode * pResult = NULL;
914 :
915 23330 : WW8TableNodeInfo::Pointer_t pNodeInfo = getTableNodeInfo(pNode);
916 :
917 23330 : if (pNodeInfo.get() != NULL)
918 : {
919 11434 : WW8TableNodeInfo * pNextInfo = pNodeInfo->getNext();
920 :
921 11434 : if (pNextInfo != NULL)
922 11182 : pResult = pNextInfo->getNode();
923 : else
924 : {
925 252 : const SwNode * pNextNode = pNodeInfo->getNextNode();
926 :
927 252 : if (pNextNode != NULL)
928 252 : pResult = pNextNode;
929 : }
930 : }
931 :
932 23330 : return pResult;
933 : }
934 :
935 0 : bool WW8TableNodeInfo::operator < (const WW8TableNodeInfo & rInfo) const
936 : {
937 0 : bool bRet = false;
938 :
939 0 : if (rInfo.mpNode != NULL)
940 : {
941 0 : if (mpNode == NULL)
942 : {
943 0 : bRet = true;
944 : }
945 : else
946 : {
947 0 : if (mpNode->GetIndex() < rInfo.mpNode->GetIndex())
948 0 : bRet = true;
949 : }
950 : }
951 :
952 0 : return bRet;
953 : }
954 :
955 0 : bool CellInfo::operator < (const CellInfo & aCellInfo) const
956 : {
957 0 : bool aRet = false;
958 :
959 0 : if (top() < aCellInfo.top())
960 0 : aRet = true;
961 0 : else if (top() == aCellInfo.top())
962 : {
963 0 : if (left() < aCellInfo.left())
964 0 : aRet = true;
965 0 : else if (left() == aCellInfo.left())
966 : {
967 0 : if (width() < aCellInfo.width())
968 0 : aRet = true;
969 0 : else if (width() == aCellInfo.width())
970 : {
971 0 : if (height() < aCellInfo.height())
972 0 : aRet = true;
973 0 : else if (height() == aCellInfo.height())
974 : {
975 0 : if (aCellInfo.getTableNodeInfo() != NULL)
976 : {
977 0 : if (m_pNodeInfo == NULL)
978 0 : aRet = true;
979 : else
980 : {
981 0 : aRet = *m_pNodeInfo < *aCellInfo.getTableNodeInfo();
982 : }
983 : }
984 : }
985 : }
986 : }
987 : }
988 :
989 0 : return aRet;
990 : }
991 :
992 : #ifdef DBG_UTIL
993 : ::std::string CellInfo::toString() const
994 : {
995 : static char sBuffer[256];
996 :
997 : snprintf(sBuffer, sizeof(sBuffer),
998 : "<cellinfo left=\"%ld\""
999 : " right=\"%ld\""
1000 : " top=\"%ld\""
1001 : " bottom=\"%ld\""
1002 : " node=\"%p\"/>",
1003 : left(),
1004 : right(),
1005 : top(),
1006 : bottom(),
1007 : m_pNodeInfo);
1008 :
1009 : return sBuffer;
1010 : }
1011 : #endif
1012 :
1013 0 : WW8TableNodeInfo * WW8TableInfo::reorderByLayout(const SwTable * pTable)
1014 : {
1015 0 : WW8TableNodeInfo * pPrev = NULL;
1016 0 : WW8TableCellGrid::Pointer_t pCellGrid = getCellGridForTable(pTable);
1017 :
1018 : #ifdef DBG_UTIL
1019 : SAL_INFO( "sw.ww8", pCellGrid->toString());
1020 : #endif
1021 :
1022 0 : pCellGrid->addShadowCells();
1023 0 : pPrev = pCellGrid->connectCells();
1024 :
1025 0 : return pPrev;
1026 : }
1027 :
1028 0 : WW8TableCellGrid::WW8TableCellGrid()
1029 : {
1030 0 : }
1031 :
1032 0 : WW8TableCellGrid::~WW8TableCellGrid()
1033 : {
1034 0 : }
1035 :
1036 0 : WW8TableCellGridRow::Pointer_t WW8TableCellGrid::getRow(long nTop, bool bCreate)
1037 : {
1038 0 : WW8TableCellGridRow::Pointer_t pResult;
1039 :
1040 0 : RowTops_t::iterator aIt = m_aRowTops.find(nTop);
1041 :
1042 0 : if (aIt == m_aRowTops.end())
1043 : {
1044 0 : if (bCreate)
1045 : {
1046 0 : pResult = WW8TableCellGridRow::Pointer_t(new WW8TableCellGridRow);
1047 0 : m_aRows[nTop] = pResult;
1048 0 : m_aRowTops.insert(nTop);
1049 : }
1050 : }
1051 : else
1052 0 : pResult = m_aRows[nTop];
1053 :
1054 0 : return pResult;
1055 : }
1056 :
1057 0 : WW8TableCellGrid::RowTops_t::const_iterator WW8TableCellGrid::getRowTopsBegin() const
1058 : {
1059 0 : return m_aRowTops.begin();
1060 : }
1061 :
1062 0 : WW8TableCellGrid::RowTops_t::const_iterator WW8TableCellGrid::getRowTopsEnd() const
1063 : {
1064 0 : return m_aRowTops.end();
1065 : }
1066 :
1067 0 : CellInfoMultiSet::const_iterator WW8TableCellGrid::getCellsBegin(long nTop)
1068 : {
1069 0 : return getRow(nTop)->begin();
1070 : }
1071 :
1072 0 : CellInfoMultiSet::const_iterator WW8TableCellGrid::getCellsEnd(long nTop)
1073 : {
1074 0 : return getRow(nTop)->end();
1075 : }
1076 :
1077 0 : void WW8TableCellGrid::insert(const SwRect & rRect,
1078 : WW8TableNodeInfo * pNodeInfo,
1079 : unsigned long * pFmtFrmWidth)
1080 : {
1081 0 : CellInfo aCellInfo(rRect, pNodeInfo);
1082 :
1083 0 : if (pFmtFrmWidth != NULL)
1084 0 : aCellInfo.setFmtFrmWidth(*pFmtFrmWidth);
1085 :
1086 0 : WW8TableCellGridRow::Pointer_t pRow = getRow(rRect.Top());
1087 0 : pRow->insert(aCellInfo);
1088 0 : }
1089 :
1090 0 : void WW8TableCellGrid::addShadowCells()
1091 : {
1092 : SAL_INFO( "sw.ww8", "<addShadowCells>" );
1093 :
1094 0 : RowTops_t::const_iterator aTopsIt = getRowTopsBegin();
1095 :
1096 0 : while (aTopsIt != getRowTopsEnd())
1097 : {
1098 : #ifdef DBG_UTIL
1099 : long nTop = *aTopsIt;
1100 : (void) nTop;
1101 : #endif
1102 0 : CellInfoMultiSet::const_iterator aCellIt = getCellsBegin(*aTopsIt);
1103 0 : CellInfoMultiSet::const_iterator aCellEndIt = getCellsEnd(*aTopsIt);
1104 :
1105 0 : RowSpansPtr pRowSpans(new RowSpans);
1106 :
1107 0 : bool bBeginningOfCell = true;
1108 0 : bool bVertMerge = false;
1109 0 : SwRect aRect = aCellIt->getRect();
1110 0 : long nRowSpan = 1;
1111 0 : while (aCellIt != aCellEndIt)
1112 : {
1113 0 : WW8TableNodeInfo * pNodeInfo = aCellIt->getTableNodeInfo();
1114 :
1115 0 : if (bBeginningOfCell)
1116 : {
1117 0 : RowTops_t::const_iterator aRowSpanIt(aTopsIt);
1118 0 : ++aRowSpanIt;
1119 :
1120 0 : if (aRowSpanIt != getRowTopsEnd() &&
1121 0 : *aRowSpanIt < aCellIt->bottom())
1122 : {
1123 0 : aRect.Top(*aRowSpanIt);
1124 0 : unsigned long nFmtFrmWidth = aCellIt->getFmtFrmWidth();
1125 0 : insert(aRect, NULL, &nFmtFrmWidth);
1126 :
1127 0 : bVertMerge = true;
1128 : }
1129 : else
1130 0 : bVertMerge = false;
1131 :
1132 0 : nRowSpan = 1;
1133 0 : while (aRowSpanIt != getRowTopsEnd() &&
1134 0 : *aRowSpanIt < aCellIt->bottom())
1135 : {
1136 0 : ++aRowSpanIt;
1137 0 : nRowSpan++;
1138 : }
1139 :
1140 0 : if (pNodeInfo != NULL)
1141 0 : pRowSpans->push_back(nRowSpan);
1142 : else
1143 0 : pRowSpans->push_back(-nRowSpan);
1144 : }
1145 :
1146 0 : if (pNodeInfo != NULL)
1147 : {
1148 0 : pNodeInfo->setVertMerge(bVertMerge);
1149 : }
1150 :
1151 0 : ++aCellIt;
1152 0 : if (aCellIt != aCellEndIt)
1153 : {
1154 0 : bBeginningOfCell = (aRect.Left() != aCellIt->left());
1155 0 : aRect = aCellIt->getRect();
1156 : }
1157 : }
1158 :
1159 0 : WW8TableCellGridRow::Pointer_t pRow = getRow(*aTopsIt);
1160 0 : if (pRow.get() != NULL)
1161 0 : pRow->setRowSpans(pRowSpans);
1162 :
1163 0 : ++aTopsIt;
1164 0 : }
1165 : SAL_INFO( "sw.ww8", "</addShadowCells>" );
1166 0 : }
1167 :
1168 0 : WW8TableNodeInfo * WW8TableCellGrid::connectCells()
1169 : {
1170 0 : RowTops_t::const_iterator aTopsIt = getRowTopsBegin();
1171 0 : sal_uInt32 nRow = 0;
1172 0 : WW8TableNodeInfo * pLastNodeInfo = NULL;
1173 :
1174 0 : while (aTopsIt != getRowTopsEnd())
1175 : {
1176 0 : CellInfoMultiSet::const_iterator aCellIt = getCellsBegin(*aTopsIt);
1177 0 : CellInfoMultiSet::const_iterator aCellEndIt = getCellsEnd(*aTopsIt);
1178 0 : GridColsPtr pWidths(new Widths);
1179 0 : TableBoxVectorPtr pTableBoxes(new TableBoxVector);
1180 :
1181 0 : sal_uInt32 nShadows = 0;
1182 0 : sal_uInt32 nCell = 0;
1183 0 : bool bBeginningOfCell = true;
1184 0 : WW8TableNodeInfo * pEndOfCellInfo = NULL;
1185 0 : sal_uInt32 nDepthInCell = 0;
1186 0 : while (aCellIt != aCellEndIt)
1187 : {
1188 0 : long nCellX = aCellIt->left();
1189 0 : WW8TableNodeInfo * pNodeInfo = aCellIt->getTableNodeInfo();
1190 0 : if (pNodeInfo != NULL)
1191 : {
1192 0 : const SwNode * pNode = pNodeInfo->getNode();
1193 :
1194 0 : if (pNode->IsStartNode())
1195 : {
1196 0 : nDepthInCell++;
1197 0 : pEndOfCellInfo = NULL;
1198 : }
1199 :
1200 0 : if (nDepthInCell == 1 && pNode->IsTxtNode())
1201 0 : pEndOfCellInfo = pNodeInfo;
1202 :
1203 0 : pNodeInfo->setShadowsBefore(nShadows);
1204 0 : pNodeInfo->setCell(nCell);
1205 0 : pNodeInfo->setRow(nRow);
1206 0 : if (pLastNodeInfo != NULL)
1207 : {
1208 0 : pLastNodeInfo->setNext(pNodeInfo);
1209 0 : pLastNodeInfo->setNextNode(pNode);
1210 : }
1211 0 : pLastNodeInfo = pNodeInfo;
1212 0 : nShadows = 0;
1213 :
1214 0 : if (pNode->IsEndNode())
1215 : {
1216 0 : nDepthInCell--;
1217 :
1218 0 : if (nDepthInCell == 0 && pEndOfCellInfo == NULL)
1219 0 : pEndOfCellInfo = pNodeInfo;
1220 : }
1221 : }
1222 : else
1223 : {
1224 0 : nShadows++;
1225 : }
1226 :
1227 0 : if (bBeginningOfCell)
1228 : {
1229 0 : pWidths->push_back(aCellIt->getFmtFrmWidth());
1230 :
1231 0 : if (pNodeInfo != NULL)
1232 0 : pTableBoxes->push_back(pNodeInfo->getTableBox());
1233 : else
1234 0 : pTableBoxes->push_back(NULL);
1235 : }
1236 :
1237 0 : ++aCellIt;
1238 0 : bBeginningOfCell = false;
1239 :
1240 0 : if (aCellIt != aCellEndIt && aCellIt->left() != nCellX)
1241 : {
1242 0 : nCell++;
1243 0 : bBeginningOfCell = true;
1244 :
1245 0 : if (pEndOfCellInfo != NULL)
1246 : {
1247 0 : pEndOfCellInfo->setEndOfCell(true);
1248 : }
1249 :
1250 0 : pEndOfCellInfo = NULL;
1251 : }
1252 : }
1253 :
1254 0 : pLastNodeInfo->setShadowsAfter(nShadows);
1255 :
1256 0 : if (pEndOfCellInfo == NULL)
1257 : {
1258 0 : pEndOfCellInfo = pLastNodeInfo;
1259 : }
1260 :
1261 0 : pEndOfCellInfo->setEndOfCell(true);
1262 0 : pLastNodeInfo->setEndOfLine(true);
1263 :
1264 0 : WW8TableCellGridRow::Pointer_t pRow(getRow(*aTopsIt));
1265 0 : pRow->setTableBoxVector(pTableBoxes);
1266 0 : pRow->setWidths(pWidths);
1267 :
1268 0 : nShadows = 0;
1269 :
1270 0 : ++aTopsIt;
1271 0 : nRow++;
1272 0 : }
1273 :
1274 0 : return pLastNodeInfo;
1275 : }
1276 :
1277 : #ifdef DBG_UTIL
1278 : ::std::string WW8TableCellGrid::toString()
1279 : {
1280 : ::std::string sResult = "<WW8TableCellGrid>";
1281 :
1282 : RowTops_t::const_iterator aTopsIt = getRowTopsBegin();
1283 : static char sBuffer[1024];
1284 : while (aTopsIt != getRowTopsEnd())
1285 : {
1286 : sprintf(sBuffer, "<row y=\"%ld\">", *aTopsIt);
1287 : sResult += sBuffer;
1288 :
1289 : CellInfoMultiSet::const_iterator aCellIt = getCellsBegin(*aTopsIt);
1290 : CellInfoMultiSet::const_iterator aCellsEnd = getCellsEnd(*aTopsIt);
1291 :
1292 : while (aCellIt != aCellsEnd)
1293 : {
1294 : snprintf(sBuffer, sizeof(sBuffer), "<cellInfo top=\"%ld\" bottom=\"%ld\" left=\"%ld\" right=\"%ld\">",
1295 : aCellIt->top(), aCellIt->bottom(), aCellIt->left(), aCellIt->right());
1296 : sResult += sBuffer;
1297 :
1298 : WW8TableNodeInfo * pInfo = aCellIt->getTableNodeInfo();
1299 : if (pInfo != NULL)
1300 : sResult += pInfo->toString();
1301 : else
1302 : sResult += "<shadow/>\n";
1303 :
1304 : sResult += "</cellInfo>\n";
1305 : ++aCellIt;
1306 : }
1307 :
1308 : WW8TableCellGridRow::Pointer_t pRow = getRow(*aTopsIt);
1309 : WidthsPtr pWidths = pRow->getWidths();
1310 : if (pWidths != 0)
1311 : {
1312 : sResult += "<widths>";
1313 :
1314 : Widths::const_iterator aItEnd = pWidths->end();
1315 : for (Widths::const_iterator aIt = pWidths->begin();
1316 : aIt != aItEnd;
1317 : ++aIt)
1318 : {
1319 : if (aIt != pWidths->begin())
1320 : sResult += ", ";
1321 :
1322 : snprintf(sBuffer, sizeof(sBuffer), "%" SAL_PRIxUINT32 "", *aIt);
1323 : sResult += sBuffer;
1324 : }
1325 :
1326 : sResult += "</widths>";
1327 : }
1328 :
1329 : RowSpansPtr pRowSpans = pRow->getRowSpans();
1330 : if (pRowSpans.get() != NULL)
1331 : {
1332 : sResult += "<rowspans>";
1333 :
1334 : RowSpans::const_iterator aItEnd = pRowSpans->end();
1335 : for (RowSpans::const_iterator aIt = pRowSpans->begin();
1336 : aIt != aItEnd;
1337 : ++aIt)
1338 : {
1339 : if (aIt != pRowSpans->begin())
1340 : sResult += ", ";
1341 :
1342 : snprintf(sBuffer, sizeof(sBuffer), "%" SAL_PRIxUINT32 "", *aIt);
1343 : sResult += sBuffer;
1344 : }
1345 :
1346 : sResult += "</rowspans>";
1347 : }
1348 :
1349 : sResult += "</row>\n";
1350 : ++aTopsIt;
1351 : }
1352 :
1353 : sResult += "</WW8TableCellGrid>\n";
1354 :
1355 : return sResult;
1356 : }
1357 : #endif
1358 :
1359 0 : TableBoxVectorPtr WW8TableCellGrid::getTableBoxesOfRow
1360 : (WW8TableNodeInfoInner * pNodeInfoInner)
1361 : {
1362 0 : TableBoxVectorPtr pResult;
1363 : WW8TableCellGridRow::Pointer_t pRow =
1364 0 : getRow(pNodeInfoInner->getRect().Top(), false);
1365 :
1366 0 : if (pRow.get() != NULL)
1367 : {
1368 0 : pResult = pRow->getTableBoxVector();
1369 : }
1370 :
1371 0 : return pResult;
1372 : }
1373 :
1374 0 : WidthsPtr WW8TableCellGrid::getWidthsOfRow
1375 : (WW8TableNodeInfoInner * pNodeInfoInner)
1376 : {
1377 0 : GridColsPtr pResult;
1378 :
1379 : WW8TableCellGridRow::Pointer_t pRow =
1380 0 : getRow(pNodeInfoInner->getRect().Top(), false);
1381 :
1382 0 : if (pRow.get() != NULL)
1383 : {
1384 0 : pResult = pRow->getWidths();
1385 : }
1386 :
1387 0 : return pResult;
1388 : }
1389 :
1390 0 : RowSpansPtr WW8TableCellGrid::getRowSpansOfRow
1391 : (WW8TableNodeInfoInner * pNodeInfoInner)
1392 : {
1393 0 : RowSpansPtr pResult;
1394 :
1395 : WW8TableCellGridRow::Pointer_t pRow =
1396 0 : getRow(pNodeInfoInner->getRect().Top(), false);
1397 :
1398 0 : if (pRow.get() != NULL)
1399 : {
1400 0 : pResult = pRow->getRowSpans();
1401 : }
1402 :
1403 0 : return pResult;
1404 : }
1405 :
1406 0 : WW8TableCellGridRow::WW8TableCellGridRow()
1407 0 : : m_pCellInfos(new CellInfoMultiSet)
1408 : {
1409 0 : }
1410 :
1411 0 : WW8TableCellGridRow::~WW8TableCellGridRow()
1412 : {
1413 0 : }
1414 :
1415 0 : void WW8TableCellGridRow::insert(const CellInfo & rCellInfo)
1416 : {
1417 0 : m_pCellInfos->insert(rCellInfo);
1418 :
1419 : #ifdef DBG_UTIL
1420 : SAL_INFO( "sw.ww8", "<gridRowInsert>" << rCellInfo.toString() << "</gridRowInsert>" );
1421 : #endif
1422 0 : }
1423 :
1424 0 : CellInfoMultiSet::const_iterator WW8TableCellGridRow::begin() const
1425 : {
1426 0 : return m_pCellInfos->begin();
1427 : }
1428 :
1429 0 : CellInfoMultiSet::const_iterator WW8TableCellGridRow::end() const
1430 : {
1431 0 : return m_pCellInfos->end();
1432 : }
1433 :
1434 0 : void WW8TableCellGridRow::setTableBoxVector(TableBoxVectorPtr pTableBoxVector)
1435 : {
1436 0 : m_pTableBoxVector = pTableBoxVector;
1437 0 : }
1438 :
1439 0 : void WW8TableCellGridRow::setWidths(WidthsPtr pWidths)
1440 : {
1441 0 : m_pWidths = pWidths;
1442 0 : }
1443 :
1444 0 : void WW8TableCellGridRow::setRowSpans(RowSpansPtr pRowSpans)
1445 : {
1446 0 : m_pRowSpans = pRowSpans;
1447 0 : }
1448 :
1449 :
1450 :
1451 :
1452 0 : CellInfo::CellInfo(const SwRect & aRect, WW8TableNodeInfo * pNodeInfo)
1453 0 : : m_aRect(aRect), m_pNodeInfo(pNodeInfo), m_nFmtFrmWidth(0)
1454 : {
1455 0 : if (pNodeInfo != NULL)
1456 : {
1457 0 : const SwTableBox * pBox = pNodeInfo->getTableBox();
1458 0 : const SwFrmFmt * pFrmFmt = pBox->GetFrmFmt();
1459 0 : const SwFmtFrmSize & rSize = pFrmFmt->GetFrmSize();
1460 :
1461 0 : m_nFmtFrmWidth = rSize.GetWidth();
1462 : }
1463 0 : }
1464 :
1465 102 : }
1466 :
1467 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|