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