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