1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
24 #include "WW8TableInfo.hxx"
25 #include "fmtfsize.hxx"
26 #include "attributeoutputbase.hxx"
27 #include "swtable.hxx"
31 #include "dbgoutsw.hxx"
36 // WW8TableNodeInfoInner
38 WW8TableNodeInfoInner::WW8TableNodeInfoInner(WW8TableNodeInfo
* pParent
)
46 , mbFirstInTable(false)
53 WW8TableNodeInfoInner::~WW8TableNodeInfoInner()
57 void WW8TableNodeInfoInner::setDepth(sal_uInt32 nDepth
)
62 void WW8TableNodeInfoInner::setCell(sal_uInt32 nCell
)
67 void WW8TableNodeInfoInner::setRow(sal_uInt32 nRow
)
72 void WW8TableNodeInfoInner::setShadowsBefore(sal_uInt32 nShadowsBefore
)
74 mnShadowsBefore
= nShadowsBefore
;
77 void WW8TableNodeInfoInner::setShadowsAfter(sal_uInt32 nShadowsAfter
)
79 mnShadowsAfter
= nShadowsAfter
;
82 void WW8TableNodeInfoInner::setEndOfLine(bool bEndOfLine
)
84 mbEndOfLine
= bEndOfLine
;
87 void WW8TableNodeInfoInner::setEndOfCell(bool bEndOfCell
)
89 mbEndOfCell
= bEndOfCell
;
92 void WW8TableNodeInfoInner::setFirstInTable(bool bFirstInTable
)
94 mbFirstInTable
= bFirstInTable
;
97 void WW8TableNodeInfoInner::setVertMerge(bool bVertMerge
)
100 mbVertMerge
= bVertMerge
;
103 void WW8TableNodeInfoInner::setTableBox(const SwTableBox
* pTableBox
)
105 mpTableBox
= pTableBox
;
108 void WW8TableNodeInfoInner::setTable(const SwTable
* pTable
)
113 void WW8TableNodeInfoInner::setRect(const SwRect
& rRect
)
118 sal_uInt32
WW8TableNodeInfoInner::getDepth() const
123 sal_uInt32
WW8TableNodeInfoInner::getCell() const
128 sal_uInt32
WW8TableNodeInfoInner::getRow() const
133 sal_uInt32
WW8TableNodeInfoInner::getShadowsBefore() const
135 return mnShadowsBefore
;
138 sal_uInt32
WW8TableNodeInfoInner::getShadowsAfter() const
140 return mnShadowsAfter
;
143 bool WW8TableNodeInfoInner::isEndOfCell() const
148 bool WW8TableNodeInfoInner::isEndOfLine() const
153 bool WW8TableNodeInfoInner::isFirstInTable() const
155 return mbFirstInTable
;
158 const SwNode
* WW8TableNodeInfoInner::getNode() const
160 const SwNode
* pResult
= NULL
;
162 if (mpParent
!= NULL
)
163 pResult
= mpParent
->getNode();
168 TableBoxVectorPtr
WW8TableNodeInfoInner::getTableBoxesOfRow()
170 TableBoxVectorPtr
pResult(new TableBoxVector
);
172 WW8TableCellGrid::Pointer_t pCellGrid
=
173 mpParent
->getParent()->getCellGridForTable(getTable(), false);
175 if (pCellGrid
.get() == NULL
)
177 const SwTableLine
* pTabLine
= getTableBox()->GetUpper();
178 const SwTableBoxes
& rTblBoxes
= pTabLine
->GetTabBoxes();
180 sal_uInt8 nBoxes
= rTblBoxes
.size();
181 for ( sal_uInt8 n
= 0; n
< nBoxes
; n
++ )
183 pResult
->push_back(rTblBoxes
[n
]);
187 pResult
= pCellGrid
->getTableBoxesOfRow(this);
192 GridColsPtr
WW8TableNodeInfoInner::getGridColsOfRow(AttributeOutputBase
& rBase
)
194 GridColsPtr
pResult(new GridCols
);
195 WidthsPtr
pWidths(getWidthsOfRow());
197 const SwFrmFmt
*pFmt
= getTable()->GetFrmFmt();
198 OSL_ENSURE(pFmt
,"Impossible");
202 const SwFmtFrmSize
&rSize
= pFmt
->GetFrmSize();
203 unsigned long nTblSz
= static_cast<unsigned long>(rSize
.GetWidth());
205 sal_uInt32 nPageSize
= 0;
206 bool bRelBoxSize
= false;
208 rBase
.GetTablePageSize
209 ( this, nPageSize
, bRelBoxSize
);
212 Widths::const_iterator aWidthsEnd
= pWidths
->end();
213 for ( Widths::const_iterator aIt
= pWidths
->begin();
220 nCalc
= ( nCalc
* nPageSize
) / nTblSz
;
222 pResult
->push_back( nCalc
);
228 WidthsPtr
WW8TableNodeInfoInner::getWidthsOfRow()
232 WW8TableCellGrid::Pointer_t pCellGrid
=
233 mpParent
->getParent()->getCellGridForTable(getTable(), false);
235 if (pCellGrid
.get() == NULL
)
237 const SwTableBox
* pTabBox
= getTableBox();
238 const SwTableLine
* pTabLine
= pTabBox
->GetUpper();
239 const SwTableBoxes
& rTabBoxes
= pTabLine
->GetTabBoxes();
241 pWidths
= WidthsPtr(new Widths
);
242 // number of cell written
243 sal_uInt32 nBoxes
= rTabBoxes
.size();
244 if ( nBoxes
> MAXTABLECELLS
)
245 nBoxes
= MAXTABLECELLS
;
247 for (sal_uInt32 n
= 0; n
< nBoxes
; n
++)
249 const SwFrmFmt
* pBoxFmt
= rTabBoxes
[ n
]->GetFrmFmt();
250 const SwFmtFrmSize
& rLSz
= pBoxFmt
->GetFrmSize();
252 pWidths
->push_back(rLSz
.GetWidth());
256 pWidths
= pCellGrid
->getWidthsOfRow(this);
261 RowSpansPtr
WW8TableNodeInfoInner::getRowSpansOfRow()
263 RowSpansPtr
pResult(new RowSpans
);
265 WW8TableCellGrid::Pointer_t pCellGrid
=
266 mpParent
->getParent()->getCellGridForTable(getTable(), false);
268 if (pCellGrid
.get() == NULL
)
270 const SwTableBox
* pTabBox
= getTableBox();
271 const SwTableLine
* pTabLine
= pTabBox
->GetUpper();
272 const SwTableBoxes
& rTabBoxes
= pTabLine
->GetTabBoxes();
274 sal_uInt32 nBoxes
= rTabBoxes
.size();
275 if (nBoxes
> MAXTABLECELLS
)
276 nBoxes
= MAXTABLECELLS
;
278 for (sal_uInt32 n
= 0; n
< nBoxes
; ++n
)
280 pResult
->push_back(rTabBoxes
[n
]->getRowSpan());
284 pResult
= pCellGrid
->getRowSpansOfRow(this);
289 const SwTableBox
* WW8TableNodeInfoInner::getTableBox() const
294 const SwTable
* WW8TableNodeInfoInner::getTable() const
299 const SwRect
& WW8TableNodeInfoInner::getRect() const
305 ::std::string
WW8TableNodeInfoInner::toString() const
307 static char buffer
[256];
308 snprintf(buffer
, sizeof(buffer
),
309 "<tableinner depth=\"%" SAL_PRIuUINT32
"\""
310 " cell=\"%" SAL_PRIuUINT32
"\""
311 " row=\"%" SAL_PRIuUINT32
"\""
314 " shadowsBefore=\"%" SAL_PRIuUINT32
"\""
315 " shadowsAfter=\"%" SAL_PRIuUINT32
"\""
316 " vertMerge=\"%s\"/>",
317 mnDepth
, mnCell
, mnRow
,
318 mbEndOfCell
? "yes" : "no",
319 mbEndOfLine
? "yes" : "no",
322 mbVertMerge
? "yes" : "no");
324 return string(buffer
);
328 WW8TableNodeInfo::WW8TableNodeInfo(WW8TableInfo
* pParent
,
329 const SwNode
* pNode
)
338 WW8TableNodeInfo::~WW8TableNodeInfo()
343 ::std::string
WW8TableNodeInfo::toString() const
345 static char buffer
[1024];
346 snprintf(buffer
, sizeof(buffer
),
347 "<tableNodeInfo p=\"%p\" depth=\"%" SAL_PRIuUINT32
"\">"
350 ::std::string
sResult(buffer
);
352 Inners_t::const_iterator
aIt(mInners
.begin());
353 Inners_t::const_iterator
aEnd(mInners
.end());
357 WW8TableNodeInfoInner::Pointer_t pInner
= aIt
->second
;
358 sResult
+= pInner
->toString();
362 sResult
+= dbg_out(*mpNode
);
363 sResult
+= "</tableNodeInfo>";
369 void WW8TableNodeInfo::setDepth(sal_uInt32 nDepth
)
373 Inners_t::iterator aIt
= mInners
.find(mnDepth
);
375 if (aIt
== mInners
.end())
376 mInners
[mnDepth
] = WW8TableNodeInfoInner::Pointer_t(new WW8TableNodeInfoInner(this));
378 mInners
[mnDepth
]->setDepth(mnDepth
);
381 void WW8TableNodeInfo::setEndOfLine(bool bEndOfLine
)
383 WW8TableNodeInfoInner::Pointer_t pInner
= getInnerForDepth(mnDepth
);
384 pInner
->setEndOfLine(bEndOfLine
);
387 SAL_INFO( "sw.ww8", "<endOfLine depth=\"" << mnDepth
<< "\">" << toString() << "</endOfLine>" );
391 void WW8TableNodeInfo::setEndOfCell(bool bEndOfCell
)
393 WW8TableNodeInfoInner::Pointer_t pInner
= getInnerForDepth(mnDepth
);
394 pInner
->setEndOfCell(bEndOfCell
);
397 SAL_INFO( "sw.ww8", "<endOfCell depth=\"" << mnDepth
<< "\">" << toString() << "</endOfCell>" );
401 void WW8TableNodeInfo::setFirstInTable(bool bFirstInTable
)
403 WW8TableNodeInfoInner::Pointer_t pInner
= getInnerForDepth(mnDepth
);
405 pInner
->setFirstInTable(bFirstInTable
);
408 SAL_INFO( "sw.ww8", "<firstInTable depth=\"" << mnDepth
<< "\">" << toString() << "</firstInTable>" );
412 void WW8TableNodeInfo::setVertMerge(bool bVertMerge
)
414 WW8TableNodeInfoInner::Pointer_t pInner
= getInnerForDepth(mnDepth
);
416 pInner
->setVertMerge(bVertMerge
);
419 SAL_INFO( "sw.ww8", "<vertMerge depth=\"" << mnDepth
<< "\">" << toString() << "</vertMerge>" );
423 void WW8TableNodeInfo::setTableBox(const SwTableBox
* pTableBox
)
425 getInnerForDepth(mnDepth
)->setTableBox(pTableBox
);
428 void WW8TableNodeInfo::setTable(const SwTable
* pTable
)
430 getInnerForDepth(mnDepth
)->setTable(pTable
);
433 void WW8TableNodeInfo::setNext(WW8TableNodeInfo
* pNext
)
438 SAL_INFO( "sw.ww8", "<setnext><from>" << toString() << "</from><to>" << pNext
->toString() << "</to></setnext>" );
442 void WW8TableNodeInfo::setNextNode(const SwNode
* pNode
)
447 void WW8TableNodeInfo::setRect(const SwRect
& rRect
)
449 getInnerForDepth(mnDepth
)->setRect(rRect
);
452 void WW8TableNodeInfo::setCell(sal_uInt32 nCell
)
454 getInnerForDepth(mnDepth
)->setCell(nCell
);
457 void WW8TableNodeInfo::setRow(sal_uInt32 nRow
)
459 getInnerForDepth(mnDepth
)->setRow(nRow
);
462 void WW8TableNodeInfo::setShadowsBefore(sal_uInt32 nShadowsBefore
)
464 getInnerForDepth(mnDepth
)->setShadowsBefore(nShadowsBefore
);
467 void WW8TableNodeInfo::setShadowsAfter(sal_uInt32 nShadowsAfter
)
469 getInnerForDepth(mnDepth
)->setShadowsAfter(nShadowsAfter
);
472 WW8TableInfo
* WW8TableNodeInfo::getParent() const
477 sal_uInt32
WW8TableNodeInfo::getDepth() const
479 if (!mInners
.empty())
480 return mInners
.begin()->second
->getDepth();
485 const SwNode
* WW8TableNodeInfo::getNode() const
490 const SwTableBox
* WW8TableNodeInfo::getTableBox() const
492 return getInnerForDepth(mnDepth
)->getTableBox();
495 WW8TableNodeInfo
* WW8TableNodeInfo::getNext() const
500 const SwNode
* WW8TableNodeInfo::getNextNode() const
505 sal_uInt32
WW8TableNodeInfo::getCell() const
507 return getInnerForDepth(mnDepth
)->getCell();
510 sal_uInt32
WW8TableNodeInfo::getRow() const
512 return getInnerForDepth(mnDepth
)->getRow();
515 const ww8::WW8TableNodeInfo::Inners_t
& WW8TableNodeInfo::getInners() const
520 const WW8TableNodeInfoInner::Pointer_t
WW8TableNodeInfo::getFirstInner() const
522 WW8TableNodeInfoInner::Pointer_t pResult
;
524 if (!mInners
.empty())
525 pResult
= mInners
.begin()->second
;
530 const WW8TableNodeInfoInner::Pointer_t
WW8TableNodeInfo::getInnerForDepth(sal_uInt32 nDepth
) const
532 WW8TableNodeInfoInner::Pointer_t pResult
;
534 Inners_t::const_iterator aIt
= mInners
.find(nDepth
);
535 if (aIt
!= mInners
.end())
537 pResult
= aIt
->second
;
545 WW8TableInfo::WW8TableInfo()
549 WW8TableInfo::~WW8TableInfo()
554 WW8TableInfo::processSwTableByLayout(const SwTable
* pTable
)
556 SwTableCellInfo
aTableCellInfo(pTable
);
557 WW8TableNodeInfo
* pPrev
= NULL
;
559 while (aTableCellInfo
.getNext())
561 SwRect aRect
= aTableCellInfo
.getRect();
563 SAL_INFO( "sw.ww8", "<CellFrm>" );
564 SAL_INFO( "sw.ww8", "<rect top=\"" << aRect
.Top() << "\" bottom=\"" << aRect
.Bottom()
565 << "\" left=\"" << aRect
.Left() << "\" right=\"" << aRect
.Right() << "\"/>" );
566 const SwTableBox
* pTableBox
= aTableCellInfo
.getTableBox();
567 const SwStartNode
* pSttNd
= pTableBox
->GetSttNd();
571 SwPaM
aPam(*pSttNd
, 0);
576 SwNode
& rNode
= aPam
.GetPoint()->nNode
.GetNode();
578 insertTableNodeInfo(&rNode
, pTable
, pTableBox
, 0, 0, 1, & aRect
);
580 if (rNode
.IsEndNode())
582 SwEndNode
* pEndNode
= rNode
.GetEndNode();
583 SwStartNode
* pTmpSttNd
= pEndNode
->StartOfSectionNode();
585 if (pTmpSttNd
== pSttNd
)
589 aPam
.GetPoint()->nNode
++;
594 SAL_INFO( "sw.ww8", "</CellFrm>" );
597 pPrev
= reorderByLayout(pTable
);
602 void WW8TableInfo::processSwTable(const SwTable
* pTable
)
604 SAL_INFO( "sw.ww8", "<processSwTable>" );
606 WW8TableNodeInfo
* pPrev
= NULL
;
608 if (pTable
->IsTblComplex() && pTable
->HasLayout())
610 pPrev
= processSwTableByLayout(pTable
);
613 SAL_INFO( "sw.ww8", getCellGridForTable(pTable
)->toString());
618 const SwTableLines
& rLines
= pTable
->GetTabLines();
620 for (sal_uInt16 n
= 0; n
< rLines
.size(); n
++)
622 const SwTableLine
* pLine
= rLines
[n
];
624 pPrev
= processTableLine(pTable
, pLine
, n
, 1, pPrev
);
631 SwTableNode
* pTableNode
= pTable
->GetTableNode();
632 SwEndNode
* pEndNode
= pTableNode
->EndOfSectionNode();
634 pPrev
->setNextNode(pEndNode
);
636 SAL_INFO( "sw.ww8", "</processSwTable>" );
640 WW8TableInfo::processTableLine(const SwTable
* pTable
,
641 const SwTableLine
* pTableLine
,
643 sal_uInt32 nDepth
, WW8TableNodeInfo
* pPrev
)
645 SAL_INFO( "sw.ww8", "<processTableLine row=\"" << nRow
<< "\" depth=\"" << nDepth
<< "\">" );
647 const SwTableBoxes
& rBoxes
= pTableLine
->GetTabBoxes();
649 WW8TableNodeInfo::Pointer_t pTextNodeInfo
;
651 for (sal_uInt16 n
= 0; n
< rBoxes
.size(); n
++)
653 const SwTableBox
* pBox
= rBoxes
[n
];
655 pPrev
= processTableBox(pTable
, pBox
, nRow
, n
, nDepth
, n
== rBoxes
.size() - 1, pPrev
);
658 SAL_INFO( "sw.ww8", "</processTableLine>" );
663 WW8TableNodeInfo::Pointer_t
664 WW8TableInfo::processTableBoxLines(const SwTableBox
* pBox
,
665 const SwTable
* pTable
,
666 const SwTableBox
* pBoxToSet
,
671 SAL_INFO( "sw.ww8", "<processTableBoxLines depth=\"" << nDepth
<< "\" row=\"" << nRow
672 << "\" cell=\"" << nCell
<< "\">" );
674 const SwTableLines
& rLines
= pBox
->GetTabLines();
675 WW8TableNodeInfo::Pointer_t pNodeInfo
;
679 for (sal_uInt32 n
= 0; n
< rLines
.size(); n
++)
681 const SwTableLine
* pLine
= rLines
[n
];
682 const SwTableBoxes
& rBoxes
= pLine
->GetTabBoxes();
684 for (sal_uInt16 nBox
= 0; nBox
< rBoxes
.size(); nBox
++)
685 pNodeInfo
= processTableBoxLines(rBoxes
[nBox
], pTable
, pBoxToSet
, nRow
, nCell
, nDepth
);
690 const SwStartNode
* pSttNd
= pBox
->GetSttNd();
691 const SwEndNode
* pEndNd
= pSttNd
->EndOfSectionNode();
692 SwPaM
aPaM(*pSttNd
, 0);
693 SwPaM
aEndPaM(*pEndNd
, 0);
698 SwNode
& rNode
= aPaM
.GetPoint()->nNode
.GetNode();
700 pNodeInfo
= insertTableNodeInfo(&rNode
, pTable
, pBoxToSet
, nRow
, nCell
, nDepth
);
702 if (aPaM
.GetPoint()->nNode
== aEndPaM
.GetPoint()->nNode
)
705 aPaM
.GetPoint()->nNode
++;
709 SAL_INFO( "sw.ww8", "</processTableBoxLines>" );
715 WW8TableInfo::processTableBox(const SwTable
* pTable
,
716 const SwTableBox
* pBox
,
721 WW8TableNodeInfo
* pPrev
)
723 SAL_INFO( "sw.ww8", "<processTableBox row=\"" << nRow
<< "\" cell=\"" << nCell
724 << "\" depth=\"" << nDepth
<< "\">" );
726 WW8TableNodeInfo::Pointer_t pNodeInfo
;
727 const SwTableLines
& rLines
= pBox
->GetTabLines();
728 const SwStartNode
* pSttNd
= pBox
->GetSttNd();
729 WW8TableNodeInfo::Pointer_t pEndOfCellInfo
;
733 pNodeInfo
= processTableBoxLines(pBox
, pTable
, pBox
, nRow
, nCell
, nDepth
);
734 pNodeInfo
->setEndOfCell(true);
736 pNodeInfo
->setEndOfLine(true);
738 for (sal_uInt32 n
= 0; n
< rLines
.size(); n
++)
740 const SwTableLine
* pLine
= rLines
[n
];
742 pPrev
= processTableLine(pTable
, pLine
, n
, 1, pPrev
);
747 SwPaM
aPaM(*pSttNd
, 0);
750 sal_uInt32 nDepthInsideCell
= 0;
754 SwNode
& rNode
= aPaM
.GetPoint()->nNode
.GetNode();
756 if (rNode
.IsStartNode())
758 if (nDepthInsideCell
> 0)
759 pEndOfCellInfo
.reset();
764 pNodeInfo
= insertTableNodeInfo(&rNode
, pTable
, pBox
, nRow
, nCell
, nDepth
);
767 pPrev
->setNext(pNodeInfo
.get());
769 pPrev
= pNodeInfo
.get();
771 if (nDepthInsideCell
== 1 && rNode
.IsTxtNode())
772 pEndOfCellInfo
= pNodeInfo
;
774 if (rNode
.IsEndNode())
778 if (nDepthInsideCell
== 0 && pEndOfCellInfo
.get() == NULL
)
779 pEndOfCellInfo
= pNodeInfo
;
781 SwEndNode
* pEndNode
= rNode
.GetEndNode( );
782 SwStartNode
* pTmpSttNd
= pEndNode
->StartOfSectionNode();
783 if (pTmpSttNd
== pSttNd
)
787 aPaM
.GetPoint()->nNode
++;
791 if (pEndOfCellInfo
.get() != NULL
)
793 pEndOfCellInfo
->setEndOfCell(true);
796 pEndOfCellInfo
->setEndOfLine(true);
800 SAL_INFO( "sw.ww8", "</processTableBox>" );
805 WW8TableNodeInfo::Pointer_t
WW8TableInfo::insertTableNodeInfo
806 (const SwNode
* pNode
,
807 const SwTable
* pTable
,
808 const SwTableBox
* pTableBox
,
814 WW8TableNodeInfo::Pointer_t pNodeInfo
= getTableNodeInfo(pNode
);
816 if (pNodeInfo
.get() == NULL
)
819 WW8TableNodeInfo::Pointer_t(new WW8TableNodeInfo(this, pNode
));
820 mMap
.insert(Map_t::value_type(pNode
, pNodeInfo
));
823 pNodeInfo
->setDepth(nDepth
+ pNodeInfo
->getDepth());
825 pNodeInfo
->setTable(pTable
);
826 pNodeInfo
->setTableBox(pTableBox
);
828 pNodeInfo
->setCell(nCell
);
829 pNodeInfo
->setRow(nRow
);
831 if (pNode
->IsTxtNode())
833 FirstInTableMap_t::const_iterator aIt
= mFirstInTableMap
.find(pTable
);
834 if (aIt
== mFirstInTableMap
.end())
836 mFirstInTableMap
[pTable
] = pNode
;
837 pNodeInfo
->setFirstInTable(true);
843 WW8TableCellGrid::Pointer_t pCellGrid
= getCellGridForTable(pTable
);
845 pCellGrid
->insert(*pRect
, pNodeInfo
.get());
846 pNodeInfo
->setRect(*pRect
);
850 SAL_INFO( "sw.ww8", pNodeInfo
->toString());
855 WW8TableCellGrid::Pointer_t
WW8TableInfo::getCellGridForTable
856 (const SwTable
* pTable
, bool bCreate
)
858 WW8TableCellGrid::Pointer_t pResult
;
859 CellGridMap_t::iterator aIt
= mCellGridMap
.find(pTable
);
861 if (aIt
== mCellGridMap
.end())
865 pResult
= WW8TableCellGrid::Pointer_t(new WW8TableCellGrid
);
866 mCellGridMap
[pTable
] = pResult
;
870 pResult
= mCellGridMap
[pTable
];
875 WW8TableNodeInfo::Pointer_t
WW8TableInfo::getTableNodeInfo
876 (const SwNode
* pNode
)
878 WW8TableNodeInfo::Pointer_t pResult
;
879 Map_t::iterator aIt
= mMap
.find(pNode
);
881 if (aIt
!= mMap
.end())
882 pResult
= (*aIt
).second
;
887 const SwNode
* WW8TableInfo::getNextNode(const SwNode
* pNode
)
889 const SwNode
* pResult
= NULL
;
891 WW8TableNodeInfo::Pointer_t pNodeInfo
= getTableNodeInfo(pNode
);
893 if (pNodeInfo
.get() != NULL
)
895 WW8TableNodeInfo
* pNextInfo
= pNodeInfo
->getNext();
897 if (pNextInfo
!= NULL
)
898 pResult
= pNextInfo
->getNode();
901 const SwNode
* pNextNode
= pNodeInfo
->getNextNode();
903 if (pNextNode
!= NULL
)
911 bool WW8TableNodeInfo::operator < (const WW8TableNodeInfo
& rInfo
) const
915 if (rInfo
.mpNode
!= NULL
)
923 if (mpNode
->GetIndex() < rInfo
.mpNode
->GetIndex())
931 bool CellInfo::operator < (const CellInfo
& aCellInfo
) const
935 if (top() < aCellInfo
.top())
937 else if (top() == aCellInfo
.top())
939 if (left() < aCellInfo
.left())
941 else if (left() == aCellInfo
.left())
943 if (width() < aCellInfo
.width())
945 else if (width() == aCellInfo
.width())
947 if (height() < aCellInfo
.height())
949 else if (height() == aCellInfo
.height())
951 if (aCellInfo
.getTableNodeInfo() != NULL
)
953 if (m_pNodeInfo
== NULL
)
957 aRet
= *m_pNodeInfo
< *aCellInfo
.getTableNodeInfo();
969 ::std::string
CellInfo::toString() const
971 static char sBuffer
[256];
973 snprintf(sBuffer
, sizeof(sBuffer
),
974 "<cellinfo left=\"%ld\""
989 WW8TableNodeInfo
* WW8TableInfo::reorderByLayout(const SwTable
* pTable
)
991 WW8TableNodeInfo
* pPrev
= NULL
;
992 WW8TableCellGrid::Pointer_t pCellGrid
= getCellGridForTable(pTable
);
995 SAL_INFO( "sw.ww8", pCellGrid
->toString());
998 pCellGrid
->addShadowCells();
999 pPrev
= pCellGrid
->connectCells();
1004 WW8TableCellGrid::WW8TableCellGrid()
1008 WW8TableCellGrid::~WW8TableCellGrid()
1012 WW8TableCellGridRow::Pointer_t
WW8TableCellGrid::getRow(long nTop
, bool bCreate
)
1014 WW8TableCellGridRow::Pointer_t pResult
;
1016 RowTops_t::iterator aIt
= m_aRowTops
.find(nTop
);
1018 if (aIt
== m_aRowTops
.end())
1022 pResult
= WW8TableCellGridRow::Pointer_t(new WW8TableCellGridRow
);
1023 m_aRows
[nTop
] = pResult
;
1024 m_aRowTops
.insert(nTop
);
1028 pResult
= m_aRows
[nTop
];
1033 WW8TableCellGrid::RowTops_t::const_iterator
WW8TableCellGrid::getRowTopsBegin() const
1035 return m_aRowTops
.begin();
1038 WW8TableCellGrid::RowTops_t::const_iterator
WW8TableCellGrid::getRowTopsEnd() const
1040 return m_aRowTops
.end();
1043 CellInfoMultiSet::const_iterator
WW8TableCellGrid::getCellsBegin(long nTop
)
1045 return getRow(nTop
)->begin();
1048 CellInfoMultiSet::const_iterator
WW8TableCellGrid::getCellsEnd(long nTop
)
1050 return getRow(nTop
)->end();
1053 void WW8TableCellGrid::insert(const SwRect
& rRect
,
1054 WW8TableNodeInfo
* pNodeInfo
,
1055 unsigned long * pFmtFrmWidth
)
1057 CellInfo
aCellInfo(rRect
, pNodeInfo
);
1059 if (pFmtFrmWidth
!= NULL
)
1060 aCellInfo
.setFmtFrmWidth(*pFmtFrmWidth
);
1062 WW8TableCellGridRow::Pointer_t pRow
= getRow(rRect
.Top());
1063 pRow
->insert(aCellInfo
);
1066 void WW8TableCellGrid::addShadowCells()
1068 SAL_INFO( "sw.ww8", "<addShadowCells>" );
1070 RowTops_t::const_iterator aTopsIt
= getRowTopsBegin();
1072 while (aTopsIt
!= getRowTopsEnd())
1075 long nTop
= *aTopsIt
;
1078 CellInfoMultiSet::const_iterator aCellIt
= getCellsBegin(*aTopsIt
);
1079 CellInfoMultiSet::const_iterator aCellEndIt
= getCellsEnd(*aTopsIt
);
1081 RowSpansPtr
pRowSpans(new RowSpans
);
1083 bool bBeginningOfCell
= true;
1084 bool bVertMerge
= false;
1085 SwRect aRect
= aCellIt
->getRect();
1087 while (aCellIt
!= aCellEndIt
)
1089 WW8TableNodeInfo
* pNodeInfo
= aCellIt
->getTableNodeInfo();
1091 if (bBeginningOfCell
)
1093 RowTops_t::const_iterator
aRowSpanIt(aTopsIt
);
1096 if (aRowSpanIt
!= getRowTopsEnd() &&
1097 *aRowSpanIt
< aCellIt
->bottom())
1099 aRect
.Top(*aRowSpanIt
);
1100 unsigned long nFmtFrmWidth
= aCellIt
->getFmtFrmWidth();
1101 insert(aRect
, NULL
, &nFmtFrmWidth
);
1109 while (aRowSpanIt
!= getRowTopsEnd() &&
1110 *aRowSpanIt
< aCellIt
->bottom())
1116 if (pNodeInfo
!= NULL
)
1117 pRowSpans
->push_back(nRowSpan
);
1119 pRowSpans
->push_back(-nRowSpan
);
1122 if (pNodeInfo
!= NULL
)
1124 pNodeInfo
->setVertMerge(bVertMerge
);
1128 if (aCellIt
!= aCellEndIt
)
1130 bBeginningOfCell
= (aRect
.Left() != aCellIt
->left());
1131 aRect
= aCellIt
->getRect();
1135 WW8TableCellGridRow::Pointer_t pRow
= getRow(*aTopsIt
);
1136 if (pRow
.get() != NULL
)
1137 pRow
->setRowSpans(pRowSpans
);
1141 SAL_INFO( "sw.ww8", "</addShadowCells>" );
1144 WW8TableNodeInfo
* WW8TableCellGrid::connectCells()
1146 RowTops_t::const_iterator aTopsIt
= getRowTopsBegin();
1147 sal_uInt32 nRow
= 0;
1148 WW8TableNodeInfo
* pLastNodeInfo
= NULL
;
1150 while (aTopsIt
!= getRowTopsEnd())
1152 CellInfoMultiSet::const_iterator aCellIt
= getCellsBegin(*aTopsIt
);
1153 CellInfoMultiSet::const_iterator aCellEndIt
= getCellsEnd(*aTopsIt
);
1154 GridColsPtr
pWidths(new Widths
);
1155 TableBoxVectorPtr
pTableBoxes(new TableBoxVector
);
1157 sal_uInt32 nShadows
= 0;
1158 sal_uInt32 nCell
= 0;
1159 bool bBeginningOfCell
= true;
1160 WW8TableNodeInfo
* pEndOfCellInfo
= NULL
;
1161 sal_uInt32 nDepthInCell
= 0;
1162 while (aCellIt
!= aCellEndIt
)
1164 long nCellX
= aCellIt
->left();
1165 WW8TableNodeInfo
* pNodeInfo
= aCellIt
->getTableNodeInfo();
1166 if (pNodeInfo
!= NULL
)
1168 const SwNode
* pNode
= pNodeInfo
->getNode();
1170 if (pNode
->IsStartNode())
1173 pEndOfCellInfo
= NULL
;
1176 if (nDepthInCell
== 1 && pNode
->IsTxtNode())
1177 pEndOfCellInfo
= pNodeInfo
;
1179 pNodeInfo
->setShadowsBefore(nShadows
);
1180 pNodeInfo
->setCell(nCell
);
1181 pNodeInfo
->setRow(nRow
);
1182 if (pLastNodeInfo
!= NULL
)
1184 pLastNodeInfo
->setNext(pNodeInfo
);
1185 pLastNodeInfo
->setNextNode(pNode
);
1187 pLastNodeInfo
= pNodeInfo
;
1190 if (pNode
->IsEndNode())
1194 if (nDepthInCell
== 0 && pEndOfCellInfo
== NULL
)
1195 pEndOfCellInfo
= pNodeInfo
;
1203 if (bBeginningOfCell
)
1205 pWidths
->push_back(aCellIt
->getFmtFrmWidth());
1207 if (pNodeInfo
!= NULL
)
1208 pTableBoxes
->push_back(pNodeInfo
->getTableBox());
1210 pTableBoxes
->push_back(NULL
);
1214 bBeginningOfCell
= false;
1216 if (aCellIt
!= aCellEndIt
&& aCellIt
->left() != nCellX
)
1219 bBeginningOfCell
= true;
1221 if (pEndOfCellInfo
!= NULL
)
1223 pEndOfCellInfo
->setEndOfCell(true);
1226 pEndOfCellInfo
= NULL
;
1230 pLastNodeInfo
->setShadowsAfter(nShadows
);
1232 if (pEndOfCellInfo
== NULL
)
1234 pEndOfCellInfo
= pLastNodeInfo
;
1237 pEndOfCellInfo
->setEndOfCell(true);
1238 pLastNodeInfo
->setEndOfLine(true);
1240 WW8TableCellGridRow::Pointer_t
pRow(getRow(*aTopsIt
));
1241 pRow
->setTableBoxVector(pTableBoxes
);
1242 pRow
->setWidths(pWidths
);
1250 return pLastNodeInfo
;
1254 ::std::string
WW8TableCellGrid::toString()
1256 string sResult
= "<WW8TableCellGrid>";
1258 RowTops_t::const_iterator aTopsIt
= getRowTopsBegin();
1259 static char sBuffer
[1024];
1260 while (aTopsIt
!= getRowTopsEnd())
1262 sprintf(sBuffer
, "<row y=\"%ld\">", *aTopsIt
);
1265 CellInfoMultiSet::const_iterator aCellIt
= getCellsBegin(*aTopsIt
);
1266 CellInfoMultiSet::const_iterator aCellsEnd
= getCellsEnd(*aTopsIt
);
1268 while (aCellIt
!= aCellsEnd
)
1270 snprintf(sBuffer
, sizeof(sBuffer
), "<cellInfo top=\"%ld\" bottom=\"%ld\" left=\"%ld\" right=\"%ld\">",
1271 aCellIt
->top(), aCellIt
->bottom(), aCellIt
->left(), aCellIt
->right());
1274 WW8TableNodeInfo
* pInfo
= aCellIt
->getTableNodeInfo();
1276 sResult
+= pInfo
->toString();
1278 sResult
+= "<shadow/>\n";
1280 sResult
+= "</cellInfo>\n";
1284 WW8TableCellGridRow::Pointer_t pRow
= getRow(*aTopsIt
);
1285 WidthsPtr pWidths
= pRow
->getWidths();
1286 if (pWidths
!= NULL
)
1288 sResult
+= "<widths>";
1290 Widths::const_iterator aItEnd
= pWidths
->end();
1291 for (Widths::const_iterator aIt
= pWidths
->begin();
1295 if (aIt
!= pWidths
->begin())
1298 snprintf(sBuffer
, sizeof(sBuffer
), "%" SAL_PRIxUINT32
"", *aIt
);
1302 sResult
+= "</widths>";
1305 RowSpansPtr pRowSpans
= pRow
->getRowSpans();
1306 if (pRowSpans
.get() != NULL
)
1308 sResult
+= "<rowspans>";
1310 RowSpans::const_iterator aItEnd
= pRowSpans
->end();
1311 for (RowSpans::const_iterator aIt
= pRowSpans
->begin();
1315 if (aIt
!= pRowSpans
->begin())
1318 snprintf(sBuffer
, sizeof(sBuffer
), "%" SAL_PRIxUINT32
"", *aIt
);
1322 sResult
+= "</rowspans>";
1325 sResult
+= "</row>\n";
1329 sResult
+= "</WW8TableCellGrid>\n";
1335 TableBoxVectorPtr
WW8TableCellGrid::getTableBoxesOfRow
1336 (WW8TableNodeInfoInner
* pNodeInfoInner
)
1338 TableBoxVectorPtr pResult
;
1339 WW8TableCellGridRow::Pointer_t pRow
=
1340 getRow(pNodeInfoInner
->getRect().Top(), false);
1342 if (pRow
.get() != NULL
)
1344 pResult
= pRow
->getTableBoxVector();
1350 WidthsPtr
WW8TableCellGrid::getWidthsOfRow
1351 (WW8TableNodeInfoInner
* pNodeInfoInner
)
1353 GridColsPtr pResult
;
1355 WW8TableCellGridRow::Pointer_t pRow
=
1356 getRow(pNodeInfoInner
->getRect().Top(), false);
1358 if (pRow
.get() != NULL
)
1360 pResult
= pRow
->getWidths();
1366 RowSpansPtr
WW8TableCellGrid::getRowSpansOfRow
1367 (WW8TableNodeInfoInner
* pNodeInfoInner
)
1369 RowSpansPtr pResult
;
1371 WW8TableCellGridRow::Pointer_t pRow
=
1372 getRow(pNodeInfoInner
->getRect().Top(), false);
1374 if (pRow
.get() != NULL
)
1376 pResult
= pRow
->getRowSpans();
1382 WW8TableCellGridRow::WW8TableCellGridRow()
1383 : m_pCellInfos(new CellInfoMultiSet
)
1387 WW8TableCellGridRow::~WW8TableCellGridRow()
1391 void WW8TableCellGridRow::insert(const CellInfo
& rCellInfo
)
1393 m_pCellInfos
->insert(rCellInfo
);
1396 SAL_INFO( "sw.ww8", "<gridRowInsert>" << rCellInfo
.toString() << "</gridRowInsert>" );
1400 CellInfoMultiSet::const_iterator
WW8TableCellGridRow::begin() const
1402 return m_pCellInfos
->begin();
1405 CellInfoMultiSet::const_iterator
WW8TableCellGridRow::end() const
1407 return m_pCellInfos
->end();
1410 void WW8TableCellGridRow::setTableBoxVector(TableBoxVectorPtr pTableBoxVector
)
1412 m_pTableBoxVector
= pTableBoxVector
;
1415 void WW8TableCellGridRow::setWidths(WidthsPtr pWidths
)
1417 m_pWidths
= pWidths
;
1420 void WW8TableCellGridRow::setRowSpans(RowSpansPtr pRowSpans
)
1422 m_pRowSpans
= pRowSpans
;
1425 TableBoxVectorPtr
WW8TableCellGridRow::getTableBoxVector() const
1427 return m_pTableBoxVector
;
1430 WidthsPtr
WW8TableCellGridRow::getWidths() const
1435 RowSpansPtr
WW8TableCellGridRow::getRowSpans() const
1440 CellInfo::CellInfo(const SwRect
& aRect
, WW8TableNodeInfo
* pNodeInfo
)
1441 : m_aRect(aRect
), m_pNodeInfo(pNodeInfo
), m_nFmtFrmWidth(0)
1443 if (pNodeInfo
!= NULL
)
1445 const SwTableBox
* pBox
= pNodeInfo
->getTableBox();
1446 const SwFrmFmt
* pFrmFmt
= pBox
->GetFrmFmt();
1447 const SwFmtFrmSize
& rSize
= pFrmFmt
->GetFrmSize();
1449 m_nFmtFrmWidth
= rSize
.GetWidth();
1455 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */