1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: WW8TableInfo.cxx,v $
10 * $Revision: 1.1.2.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
36 #include "WW8TableInfo.hxx"
37 #include "swtable.hxx"
40 #include "dbgoutsw.hxx"
45 // WW8TableNodeInfoInner
47 WW8TableNodeInfoInner::WW8TableNodeInfoInner(WW8TableNodeInfo
* pParent
)
58 WW8TableNodeInfoInner::~WW8TableNodeInfoInner()
62 void WW8TableNodeInfoInner::setDepth(sal_uInt32 nDepth
)
67 void WW8TableNodeInfoInner::setCell(sal_uInt32 nCell
)
72 void WW8TableNodeInfoInner::setRow(sal_uInt32 nRow
)
77 void WW8TableNodeInfoInner::setEndOfLine(bool bEndOfLine
)
79 mbEndOfLine
= bEndOfLine
;
82 void WW8TableNodeInfoInner::setEndOfCell(bool bEndOfCell
)
84 mbEndOfCell
= bEndOfCell
;
87 void WW8TableNodeInfoInner::setTableBox(const SwTableBox
* pTableBox
)
89 mpTableBox
= pTableBox
;
92 void WW8TableNodeInfoInner::setTable(const SwTable
* pTable
)
97 sal_uInt32
WW8TableNodeInfoInner::getDepth() const
102 sal_uInt32
WW8TableNodeInfoInner::getCell() const
107 sal_uInt32
WW8TableNodeInfoInner::getRow() const
112 bool WW8TableNodeInfoInner::isEndOfCell() const
117 bool WW8TableNodeInfoInner::isEndOfLine() const
122 const SwNode
* WW8TableNodeInfoInner::getNode() const
124 const SwNode
* pResult
= NULL
;
126 if (mpParent
!= NULL
)
127 pResult
= mpParent
->getNode();
132 const SwTableBox
* WW8TableNodeInfoInner::getTableBox() const
137 const SwTable
* WW8TableNodeInfoInner::getTable() const
142 string
WW8TableNodeInfoInner::toString() const
144 static char buffer
[256];
145 snprintf(buffer
, sizeof(buffer
),
146 "<tableinner depth=\"%" SAL_PRIxUINT32
"\""
147 " cell=\"%" SAL_PRIxUINT32
"\""
148 " row=\"%" SAL_PRIxUINT32
"\""
150 " endOfLine=\"%s\"/>",
151 mnDepth
, mnCell
, mnRow
,
152 mbEndOfCell
? "yes" : "no",
153 mbEndOfLine
? "yes" : "no");
155 return string(buffer
);
158 // WW8TableTextNodeInfo
160 WW8TableNodeInfo::WW8TableNodeInfo(const SwNode
* pNode
)
168 WW8TableNodeInfo::~WW8TableNodeInfo()
172 ::std::string
WW8TableNodeInfo::toString() const
174 static char buffer
[1024];
175 snprintf(buffer
, sizeof(buffer
),
176 "<tableNodeInfo depth=\"%" SAL_PRIxUINT32
"\">"
179 ::std::string
sResult(buffer
);
181 Inners_t::const_iterator
aIt(mInners
.begin());
182 Inners_t::const_iterator
aEnd(mInners
.end());
186 WW8TableNodeInfoInner::Pointer_t pInner
= aIt
->second
;
187 sResult
+= pInner
->toString();
193 //!! does not compile with debug=t -> unresolved external (dbg_out),
194 //!! sommeone who knows what he wants to get should fix this
195 // sResult += dbg_out(*mpNode);
198 sResult
+="</tableNodeInfo>";
203 void WW8TableNodeInfo::setDepth(sal_uInt32 nDepth
)
207 Inners_t::iterator aIt
= mInners
.find(mnDepth
);
209 if (aIt
== mInners
.end())
210 mInners
[mnDepth
] = WW8TableNodeInfoInner::Pointer_t(new WW8TableNodeInfoInner(this));
212 mInners
[mnDepth
]->setDepth(mnDepth
);
215 void WW8TableNodeInfo::setEndOfLine(bool bEndOfLine
)
217 WW8TableNodeInfoInner::Pointer_t pInner
= getInnerForDepth(mnDepth
);
218 pInner
->setEndOfLine(bEndOfLine
);
221 ::std::clog
<< "<endOfLine depth=\"" << mnDepth
<< "\">"
222 << toString() << "</endOfLine>" << ::std::endl
;
226 void WW8TableNodeInfo::setEndOfCell(bool bEndOfCell
)
228 WW8TableNodeInfoInner::Pointer_t pInner
= getInnerForDepth(mnDepth
);
229 pInner
->setEndOfCell(bEndOfCell
);
232 ::std::clog
<< "<endOfCell depth=\"" << mnDepth
<< "\">"
233 << toString() << "</endOfCell>" << ::std::endl
;
237 void WW8TableNodeInfo::setTableBox(const SwTableBox
* pTableBox
)
239 getInnerForDepth(mnDepth
)->setTableBox(pTableBox
);
242 void WW8TableNodeInfo::setTable(const SwTable
* pTable
)
244 getInnerForDepth(mnDepth
)->setTable(pTable
);
247 void WW8TableNodeInfo::setNext(WW8TableNodeInfo
* pNext
)
252 void WW8TableNodeInfo::setCell(sal_uInt32 nCell
)
254 getInnerForDepth(mnDepth
)->setCell(nCell
);
257 void WW8TableNodeInfo::setRow(sal_uInt32 nRow
)
259 getInnerForDepth(mnDepth
)->setRow(nRow
);
262 sal_uInt32
WW8TableNodeInfo::getDepth() const
264 if (mInners
.size() > 0)
265 return mInners
.begin()->second
->getDepth();
270 const SwNode
* WW8TableNodeInfo::getNode() const
275 const SwTableBox
* WW8TableNodeInfo::getTableBox() const
277 return getInnerForDepth(mnDepth
)->getTableBox();
280 const SwTable
* WW8TableNodeInfo::getTable() const
282 return getInnerForDepth(mnDepth
)->getTable();
285 WW8TableNodeInfo
* WW8TableNodeInfo::getNext() const
290 bool WW8TableNodeInfo::isEndOfLine() const
292 return getInnerForDepth(mnDepth
)->isEndOfLine();
295 bool WW8TableNodeInfo::isEndOfCell() const
297 return getInnerForDepth(mnDepth
)->isEndOfCell();
300 sal_uInt32
WW8TableNodeInfo::getCell() const
302 return getInnerForDepth(mnDepth
)->getCell();
305 sal_uInt32
WW8TableNodeInfo::getRow() const
307 return getInnerForDepth(mnDepth
)->getRow();
310 const ww8::WW8TableNodeInfo::Inners_t
& WW8TableNodeInfo::getInners() const
315 const WW8TableNodeInfoInner::Pointer_t
WW8TableNodeInfo::getFirstInner() const
317 WW8TableNodeInfoInner::Pointer_t pResult
;
319 if (mInners
.size() > 0)
320 pResult
= mInners
.begin()->second
;
325 const WW8TableNodeInfoInner::Pointer_t
WW8TableNodeInfo::getInnerForDepth(sal_uInt32 nDepth
) const
327 WW8TableNodeInfoInner::Pointer_t pResult
;
329 Inners_t::const_iterator aIt
= mInners
.find(nDepth
);
330 if (aIt
!= mInners
.end())
332 pResult
= aIt
->second
;
340 WW8TableInfo::WW8TableInfo()
344 WW8TableInfo::~WW8TableInfo()
348 void WW8TableInfo::processSwTable(const SwTable
* pTable
)
351 ::std::clog
<< "<processSwTable>" << ::std::endl
;
354 const SwTableLines
& rLines
= pTable
->GetTabLines();
356 WW8TableNodeInfo
* pPrev
= NULL
;
358 for (USHORT n
= 0; n
< rLines
.Count(); n
++)
360 const SwTableLine
* pLine
= rLines
[n
];
362 pPrev
= processTableLine(pTable
, pLine
, n
, 1, pPrev
);
366 ::std::clog
<< "</processSwTable>" << ::std::endl
;
371 WW8TableInfo::processTableLine(const SwTable
* pTable
,
372 const SwTableLine
* pTableLine
,
374 sal_uInt32 nDepth
, WW8TableNodeInfo
* pPrev
)
377 ::std::clog
<< "<processTableLine row=\"" << nRow
<< "\" depth=\""
378 << nDepth
<< "\">" << ::std::endl
;
381 const SwTableBoxes
& rBoxes
= pTableLine
->GetTabBoxes();
383 WW8TableNodeInfo::Pointer_t pTextNodeInfo
;
385 for (USHORT n
= 0; n
< rBoxes
.Count(); n
++)
387 const SwTableBox
* pBox
= rBoxes
[n
];
389 pPrev
= processTableBox(pTable
, pBox
, nRow
, n
, nDepth
, n
== rBoxes
.Count() - 1, pPrev
);
393 ::std::clog
<< "</processTableLine>" << ::std::endl
;
399 WW8TableNodeInfo::Pointer_t
400 WW8TableInfo::processTableBoxLines(const SwTableBox
* pBox
,
401 const SwTable
* pTable
,
402 const SwTableBox
* pBoxToSet
,
408 ::std::clog
<< "<processTableBoxLines depth=\"" << nDepth
409 << "\" row=\"" << nRow
<< "\" cell=\"" << nCell
<< "\">" << ::std::endl
;
412 const SwTableLines
& rLines
= pBox
->GetTabLines();
413 WW8TableNodeInfo::Pointer_t pNodeInfo
;
415 if (rLines
.Count() > 0)
417 for (sal_uInt32 n
= 0; n
< rLines
.Count(); n
++)
419 const SwTableLine
* pLine
= rLines
[n
];
420 const SwTableBoxes
& rBoxes
= pLine
->GetTabBoxes();
422 for (USHORT nBox
= 0; nBox
< rBoxes
.Count(); nBox
++)
423 pNodeInfo
= processTableBoxLines(rBoxes
[nBox
], pTable
, pBoxToSet
, nRow
, nCell
, nDepth
);
428 const SwStartNode
* pSttNd
= pBox
->GetSttNd();
429 const SwEndNode
* pEndNd
= pSttNd
->EndOfSectionNode();
430 SwPaM
aPaM(*pSttNd
, 0);
431 SwPaM
aEndPaM(*pEndNd
, 0);
436 SwNode
& rNode
= aPaM
.GetPoint()->nNode
.GetNode();
438 pNodeInfo
= insertTableNodeInfo(&rNode
, pTable
, pBoxToSet
, nRow
, nCell
, nDepth
);
440 if (aPaM
.GetPoint()->nNode
== aEndPaM
.GetPoint()->nNode
)
443 aPaM
.GetPoint()->nNode
++;
448 ::std::clog
<< "</processTableBoxLines>" << ::std::endl
;
456 WW8TableInfo::processTableBox(const SwTable
* pTable
,
457 const SwTableBox
* pBox
,
462 WW8TableNodeInfo
* pPrev
)
465 ::std::clog
<< "<processTableBox row=\"" << nRow
<< "\" cell=\"" << nCell
466 << "\" depth=\"" << nDepth
<< "\">" << ::std::endl
;
469 WW8TableNodeInfo::Pointer_t pNodeInfo
;
470 const SwTableLines
& rLines
= pBox
->GetTabLines();
471 const SwStartNode
* pSttNd
= pBox
->GetSttNd();
472 WW8TableNodeInfo::Pointer_t pEndOfCellInfo
;
474 if (rLines
.Count() > 0)
476 pNodeInfo
= processTableBoxLines(pBox
, pTable
, pBox
, nRow
, nCell
, nDepth
);
477 pNodeInfo
->setEndOfCell(true);
479 pNodeInfo
->setEndOfLine(true);
481 for (sal_uInt32 n
= 0; n
< rLines
.Count(); n
++)
483 const SwTableLine
* pLine
= rLines
[n
];
485 pPrev
= processTableLine(pTable
, pLine
, n
, 1, pPrev
);
490 SwPaM
aPaM(*pSttNd
, 0);
493 sal_uInt32 nDepthInsideCell
= 0;
497 SwNode
& rNode
= aPaM
.GetPoint()->nNode
.GetNode();
499 if (rNode
.IsStartNode())
501 if (nDepthInsideCell
> 0)
502 pEndOfCellInfo
.reset();
507 pNodeInfo
= insertTableNodeInfo(&rNode
, pTable
, pBox
, nRow
, nCell
, nDepth
);
510 pPrev
->setNext(pNodeInfo
.get());
512 pPrev
= pNodeInfo
.get();
514 if (nDepthInsideCell
== 1 && rNode
.IsTxtNode())
515 pEndOfCellInfo
= pNodeInfo
;
517 if (rNode
.IsEndNode())
521 if (nDepthInsideCell
== 0 && pEndOfCellInfo
.get() == NULL
)
522 pEndOfCellInfo
= pNodeInfo
;
524 SwEndNode
* pEndNode
= rNode
.GetEndNode( );
525 SwStartNode
* pTmpSttNd
= pEndNode
->StartOfSectionNode();
526 if (pTmpSttNd
== pSttNd
)
530 aPaM
.GetPoint()->nNode
++;
534 if (pEndOfCellInfo
.get() != NULL
)
536 pEndOfCellInfo
->setEndOfCell(true);
539 pEndOfCellInfo
->setEndOfLine(true);
544 ::std::clog
<< "</processTableBox>" << ::std::endl
;
550 WW8TableNodeInfo::Pointer_t
WW8TableInfo::insertTableNodeInfo
551 (const SwNode
* pNode
,
552 const SwTable
* pTable
,
553 const SwTableBox
* pTableBox
,
558 WW8TableNodeInfo::Pointer_t pNodeInfo
= getTableNodeInfo(pNode
);
560 if (pNodeInfo
.get() == NULL
)
562 pNodeInfo
= WW8TableNodeInfo::Pointer_t(new WW8TableNodeInfo(pNode
));
563 mMap
.insert(Map_t::value_type(pNode
, pNodeInfo
));
566 pNodeInfo
->setDepth(nDepth
+ pNodeInfo
->getDepth());
568 pNodeInfo
->setTable(pTable
);
569 pNodeInfo
->setTableBox(pTableBox
);
571 pNodeInfo
->setCell(nCell
);
572 pNodeInfo
->setRow(nRow
);
575 ::std::clog
<< pNodeInfo
->toString() << ::std::endl
;
581 WW8TableNodeInfo::Pointer_t
WW8TableInfo::getTableNodeInfo
582 (const SwNode
* pNode
)
584 WW8TableNodeInfo::Pointer_t pResult
;
585 Map_t::iterator aIt
= mMap
.find(pNode
);
587 if (aIt
!= mMap
.end())
588 pResult
= (*aIt
).second
;
593 const SwNode
* WW8TableInfo::getNextNode(const SwNode
* pNode
)
595 const SwNode
* pResult
= NULL
;
597 WW8TableNodeInfo::Pointer_t pNodeInfo
= getTableNodeInfo(pNode
);
599 if (pNodeInfo
.get() != NULL
)
601 WW8TableNodeInfo
* pNextInfo
= pNodeInfo
->getNext();
603 if (pNextInfo
!= NULL
)
604 pResult
= pNextInfo
->getNode();