Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*************************************************************************
3 : *
4 : * The Contents of this file are made available subject to the terms of
5 : * either of the following licenses
6 : *
7 : * - GNU Lesser General Public License Version 2.1
8 : * - Sun Industry Standards Source License Version 1.1
9 : *
10 : * Sun Microsystems Inc., October, 2000
11 : *
12 : * GNU Lesser General Public License Version 2.1
13 : * =============================================
14 : * Copyright 2000 by Sun Microsystems, Inc.
15 : * 901 San Antonio Road, Palo Alto, CA 94303, USA
16 : *
17 : * This library is free software; you can redistribute it and/or
18 : * modify it under the terms of the GNU Lesser General Public
19 : * License version 2.1, as published by the Free Software Foundation.
20 : *
21 : * This library is distributed in the hope that it will be useful,
22 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 : * Lesser General Public License for more details.
25 : *
26 : * You should have received a copy of the GNU Lesser General Public
27 : * License along with this library; if not, write to the Free Software
28 : * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 : * MA 02111-1307 USA
30 : *
31 : *
32 : * Sun Industry Standards Source License Version 1.1
33 : * =================================================
34 : * The contents of this file are subject to the Sun Industry Standards
35 : * Source License Version 1.1 (the "License"); You may not use this file
36 : * except in compliance with the License. You may obtain a copy of the
37 : * License at http://www.openoffice.org/license.html.
38 : *
39 : * Software provided under this License is provided on an "AS IS" basis,
40 : * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
41 : * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
42 : * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
43 : * See the License for the specific provisions governing your rights and
44 : * obligations concerning the Software.
45 : *
46 : * The Initial Developer of the Original Code is: IBM Corporation
47 : *
48 : * Copyright: 2008 by IBM Corporation
49 : *
50 : * All Rights Reserved.
51 : *
52 : * Contributor(s): _______________________________________
53 : *
54 : *
55 : ************************************************************************/
56 : /**
57 : * @file
58 : * For LWP filter architecture prototype - table layouts
59 : */
60 : /*************************************************************************
61 : * Change History
62 : Mar 2005 Created
63 : ************************************************************************/
64 : #include "lwpglobalmgr.hxx"
65 : #include "lwptablelayout.hxx"
66 : #include "lwpfoundry.hxx"
67 : #include "lwpobjfactory.hxx"
68 : #include "lwpholder.hxx"
69 : #include "lwptable.hxx"
70 : #include "lwptblcell.hxx"
71 : #include "lwpnumericfmt.hxx"
72 : #include "lwpdlvlist.hxx"
73 : #include "lwppara.hxx"
74 :
75 : #include "xfilter/xfstylemanager.hxx"
76 : #include "xfilter/xftablestyle.hxx"
77 : #include "xfilter/xftable.hxx"
78 : #include "xfilter/xfrow.hxx"
79 : #include "xfilter/xfrowstyle.hxx"
80 : #include "xfilter/xfcell.hxx"
81 : #include "xfilter/xfcellstyle.hxx"
82 : #include "xfilter/xfcolstyle.hxx"
83 : #include "xfilter/xfframestyle.hxx"
84 : #include "xfilter/xfframe.hxx"
85 : #include "xfilter/xffloatframe.hxx"
86 : #include "lwpframelayout.hxx"
87 : #include "xfilter/xfparastyle.hxx"
88 :
89 2 : LwpSuperTableLayout::LwpSuperTableLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
90 2 : : LwpPlacableLayout(objHdr, pStrm)
91 : {
92 2 : m_pFrame = new LwpFrame(this);
93 2 : }
94 :
95 6 : LwpSuperTableLayout::~LwpSuperTableLayout()
96 : {
97 2 : if(m_pFrame)
98 : {
99 2 : delete m_pFrame;
100 : }
101 4 : }
102 : /**
103 : * @short Read super table layout record
104 : */
105 2 : void LwpSuperTableLayout::Read()
106 : {
107 2 : LwpPlacableLayout::Read();
108 2 : m_pObjStrm->SkipExtra();
109 :
110 2 : }
111 : /**
112 : * @short Get child table layout
113 : * @return pointer to table layout
114 : */
115 2 : LwpTableLayout* LwpSuperTableLayout::GetTableLayout()
116 : {
117 2 : LwpObjectID *pID = GetChildTail();
118 :
119 4 : while(pID && !pID->IsNull())
120 : {
121 2 : LwpLayout* pLayout = dynamic_cast<LwpLayout*>(pID->obj());
122 2 : if (!pLayout)
123 : {
124 0 : break;
125 : }
126 2 : if (pLayout->GetLayoutType() == LWP_TABLE_LAYOUT)
127 : {
128 2 : return dynamic_cast<LwpTableLayout *>(pLayout);
129 : }
130 0 : pID = pLayout->GetPrevious();
131 : }
132 :
133 0 : return NULL;
134 : }
135 : /**
136 : * @short Get effective heading table layout, the one just before table layout is the only one which is effective
137 : * @return LwpTableHeadingLayout* - pointer to table heading layout
138 : */
139 1 : LwpTableHeadingLayout* LwpSuperTableLayout::GetTableHeadingLayout()
140 : {
141 1 : LwpObjectID *pID = GetChildTail();
142 :
143 3 : while(pID && !pID->IsNull())
144 : {
145 1 : LwpLayout * pLayout = dynamic_cast<LwpLayout *>(pID->obj());
146 1 : if (!pLayout)
147 : {
148 0 : break;
149 : }
150 :
151 1 : if (pLayout->GetLayoutType() == LWP_TABLE_HEADING_LAYOUT)
152 : {
153 0 : return dynamic_cast<LwpTableHeadingLayout *>(pLayout);
154 : }
155 1 : pID = pLayout->GetPrevious();
156 : }
157 :
158 1 : return NULL;
159 : }
160 : /**
161 : * @short Register super table layout style
162 : */
163 1 : void LwpSuperTableLayout::RegisterNewStyle()
164 : {
165 : // if this layout is style of real table entry
166 1 : LwpTableLayout* pTableLayout = GetTableLayout();
167 1 : if (pTableLayout != NULL)
168 : {
169 1 : pTableLayout->SetFoundry(m_pFoundry);
170 1 : pTableLayout->RegisterStyle();
171 : }
172 1 : }
173 : /**
174 : * @short Judge whether table size is according to content, borrowed from Word Pro code
175 : * @param
176 : * @return sal_Bool
177 : */
178 2 : sal_Bool LwpSuperTableLayout::IsSizeRightToContent()
179 : {
180 : /* Only "with paragraph above" tables can size right to content. */
181 2 : if (GetRelativeType() == LwpLayoutRelativityGuts::LAY_INLINE_NEWLINE)
182 2 : return LwpPlacableLayout::IsSizeRightToContent();
183 :
184 0 : return sal_False;
185 : }
186 : /**
187 : * @short Judge whether table is justifiable, borrowed from Word Pro code
188 : * @param
189 : * @return sal_Bool
190 : */
191 2 : sal_Bool LwpSuperTableLayout::IsJustifiable()
192 : {
193 2 : return (GetRelativeType() != LwpLayoutRelativityGuts::LAY_INLINE_NEWLINE || IsSizeRightToContent());
194 : }
195 : /**
196 : * @short Get width of frame outside table
197 : * @param pTableStyle - pointer of XFTableStyle
198 : * @return double - table width
199 : */
200 0 : double LwpSuperTableLayout::GetWidth()
201 : {
202 0 : double dWidth = GetTableWidth();
203 0 : double dLeft = GetMarginsValue(MARGIN_LEFT);
204 0 : double dRight = GetMarginsValue(MARGIN_RIGHT);
205 :
206 0 : return (dWidth + dLeft + dRight);
207 : }
208 : /**
209 : * @short Get width of table
210 : * @param pTableStyle - pointer of XFTableStyle
211 : * @return double - table width
212 : */
213 2 : double LwpSuperTableLayout::GetTableWidth()
214 : {
215 2 : sal_Int32 nWidth = 0;
216 2 : if(!IsJustifiable() || ((nWidth = LwpMiddleLayout::GetMinimumWidth()) <= 0))
217 : {
218 0 : LwpTableLayout* pTableLayout = GetTableLayout();
219 0 : if(!pTableLayout)
220 : {
221 : assert(sal_False);
222 0 : return 0;
223 : }
224 0 : LwpTable *pTable = pTableLayout->GetTable();
225 0 : if(!pTable)
226 : {
227 : assert(sal_False);
228 0 : return 0;
229 : }
230 0 : double dDefaultWidth = pTable->GetWidth();
231 0 : sal_uInt16 nCol = pTable->GetColumn();
232 :
233 0 : double dWidth = 0;
234 :
235 0 : for(sal_uInt16 i =0; i< nCol; i++)
236 : {
237 0 : LwpObjectID *pColumnID = pTableLayout->GetColumnLayoutHead();
238 0 : LwpColumnLayout * pColumnLayout = dynamic_cast<LwpColumnLayout *>(pColumnID->obj());
239 0 : double dColumnWidth = dDefaultWidth;
240 0 : while (pColumnLayout)
241 : {
242 0 : if(pColumnLayout->GetColumnID() == i)
243 : {
244 0 : dColumnWidth = pColumnLayout->GetWidth();
245 0 : break;
246 : }
247 0 : pColumnID = pColumnLayout->GetNext();
248 0 : pColumnLayout = dynamic_cast<LwpColumnLayout *>(pColumnID->obj());
249 : }
250 0 : dWidth += dColumnWidth;
251 : }
252 :
253 0 : return dWidth;
254 : }
255 :
256 2 : double dLeft = GetMarginsValue(MARGIN_LEFT);
257 2 : double dRight = GetMarginsValue(MARGIN_RIGHT);
258 2 : return LwpTools::ConvertFromUnitsToMetric(nWidth)-dLeft-dRight;
259 :
260 : }
261 : /**
262 : * @short Apply shadow to table
263 : * @param pTableStyle - pointer of XFTableStyle
264 : * @return
265 : */
266 1 : void LwpSuperTableLayout::ApplyShadow(XFTableStyle *pTableStyle)
267 : {
268 : // use shadow property of supertable
269 1 : XFShadow* pXFShadow = GetXFShadow();
270 1 : if(pXFShadow)
271 : {
272 0 : pTableStyle->SetShadow(pXFShadow->GetPosition(), pXFShadow->GetOffset(), pXFShadow->GetColor());
273 : }
274 1 : }
275 : /**
276 : * @short Apply pattern fill to table style
277 : * @param pTableStyle - pointer of XFTableStyle
278 : * @return
279 : */
280 0 : void LwpSuperTableLayout::ApplyPatternFill(XFTableStyle* pTableStyle)
281 : {
282 0 : XFBGImage* pXFBGImage = this->GetFillPattern();
283 0 : if (pXFBGImage)
284 : {
285 0 : pTableStyle->SetBackImage(pXFBGImage);
286 : }
287 0 : }
288 :
289 : /**
290 : * @short Apply background to table style
291 : * @param pTableStyle - pointer of XFTableStyle
292 : * @return
293 : */
294 1 : void LwpSuperTableLayout::ApplyBackGround(XFTableStyle* pTableStyle)
295 : {
296 1 : if (this->IsPatternFill())
297 : {
298 0 : ApplyPatternFill(pTableStyle);
299 : }
300 : else
301 : {
302 1 : ApplyBackColor(pTableStyle);
303 : }
304 1 : }
305 : /**
306 : * @short Apply back color to table
307 : * @param pTableStyle - pointer of XFTableStyle
308 : * @return
309 : */
310 1 : void LwpSuperTableLayout::ApplyBackColor(XFTableStyle *pTableStyle)
311 : {
312 1 : LwpColor* pColor = GetBackColor();
313 1 : if(pColor && pColor->IsValidColor())
314 : {
315 0 : XFColor aColor(pColor->To24Color());
316 0 : pTableStyle->SetBackColor(aColor);
317 : }
318 1 : }
319 : /**
320 : * @short Apply watermark to table
321 : * @param pTableStyle - pointer of XFTableStyle
322 : * @return
323 : */
324 1 : void LwpSuperTableLayout::ApplyWatermark(XFTableStyle *pTableStyle)
325 : {
326 1 : XFBGImage* pBGImage = GetXFBGImage();
327 1 : if(pBGImage)
328 : {
329 0 : pTableStyle->SetBackImage(pBGImage);
330 : }
331 1 : }
332 : /**
333 : * @short Apply alignment to table
334 : * @param pTableStyle - pointer of XFTableStyle
335 : * @return
336 : */
337 1 : void LwpSuperTableLayout::ApplyAlignment(XFTableStyle * pTableStyle)
338 : {
339 1 : LwpPoint aPoint;
340 1 : if (GetGeometry())
341 1 : aPoint = GetGeometry()->GetOrigin();
342 : //LwpPoint aPoint = GetOrigin();
343 1 : double dXOffset = LwpTools::ConvertFromUnitsToMetric(aPoint.GetX());
344 :
345 : // add left padding to alignment distance
346 1 : double dLeft = GetMarginsValue(MARGIN_LEFT);
347 :
348 1 : pTableStyle->SetAlign(enumXFAlignStart, dXOffset+ dLeft);
349 1 : }
350 : /**
351 : * @short Add table to container
352 : * @param pCont - pointer of container
353 : * @return pCont
354 : */
355 1 : void LwpSuperTableLayout::XFConvert(XFContentContainer* pCont)
356 : {
357 2 : if ( LwpLayoutRelativityGuts::LAY_INLINE_NEWLINE == GetRelativeType()
358 1 : && !GetContainerLayout()->IsCell())
359 : {
360 1 : LwpTableLayout * pTableLayout = GetTableLayout();
361 1 : if (pTableLayout)
362 : {
363 1 : pTableLayout->XFConvert(pCont);
364 : }
365 : }
366 0 : else if(IsRelativeAnchored())
367 : {
368 : //anchor to paragraph except "with paragraph above"
369 0 : XFConvertFrame(pCont);
370 : }
371 0 : else if(m_pFrame)
372 : {
373 : //anchor to page, frame, cell
374 0 : m_pFrame->XFConvert(pCont);
375 : }
376 1 : }
377 : /**
378 : * @short convert frame which anchor to page
379 : * @param
380 : * @return
381 : */
382 0 : void LwpSuperTableLayout::XFConvertFrame(XFContentContainer* pCont, sal_Int32 nStart , sal_Int32 nEnd , sal_Bool bAll)
383 : {
384 0 : if(m_pFrame)
385 : {
386 0 : XFFrame* pXFFrame = NULL;
387 0 : if(nEnd < nStart)
388 : {
389 0 : pXFFrame = new XFFrame();
390 : }
391 : else
392 : {
393 0 : pXFFrame = new XFFloatFrame(nStart, nEnd, bAll);
394 : }
395 :
396 0 : m_pFrame->Parse(pXFFrame, static_cast<sal_uInt16>(nStart));
397 : //parse table, and add table to frame
398 0 : LwpTableLayout * pTableLayout = GetTableLayout();
399 0 : if (pTableLayout)
400 : {
401 0 : pTableLayout->XFConvert(pXFFrame);
402 : }
403 : //add frame to the container
404 0 : pCont ->Add(pXFFrame);
405 : }
406 :
407 0 : }
408 : /**
409 : * @short register frame style
410 : * @param
411 : * @return
412 : */
413 0 : void LwpSuperTableLayout::RegisterFrameStyle()
414 : {
415 0 : XFFrameStyle* pFrameStyle = new XFFrameStyle();
416 0 : m_pFrame->RegisterStyle(pFrameStyle);
417 0 : }
418 :
419 2 : LwpTableLayout::LwpTableLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
420 2 : : LwpLayout(objHdr, pStrm), m_nRows(0), m_nCols(0), m_pXFTable(NULL)
421 : {
422 2 : m_CellsMap.clear();
423 2 : m_pColumns = NULL;
424 2 : }
425 :
426 5 : LwpTableLayout::~LwpTableLayout()
427 : {
428 2 : m_CellsMap.clear();
429 :
430 2 : if (m_pColumns)
431 : {
432 1 : delete [] m_pColumns;
433 1 : m_pColumns = NULL;
434 : }
435 3 : }
436 : /**
437 : * @short Get neighbour cell by specifying ROW+COL
438 : * @param nRow
439 : * @param nCol
440 : * @return LwpCellLayout *
441 : */
442 40 : LwpCellLayout * LwpTableLayout::GetCellByRowCol(sal_uInt16 nRow, sal_uInt16 nCol)
443 : {
444 40 : if (nRow >= m_nRows || nCol >= m_nCols)
445 9 : return NULL;
446 :
447 31 : return m_WordProCellsMap[nRow*m_nCols + nCol];
448 : }
449 : /**
450 : * @short traverse all table cells
451 : * @param
452 : * @param
453 : * @param
454 : */
455 1 : void LwpTableLayout::TraverseTable()
456 : {
457 1 : sal_uInt32 nCount = m_nRows*m_nCols;
458 :
459 : // new cell map nRow*nCOl and initialize
460 21 : for (sal_uInt32 iLoop = 0; iLoop < nCount; ++iLoop)
461 : {
462 20 : m_WordProCellsMap.push_back(GetDefaultCellLayout());
463 : }
464 :
465 : // set value
466 1 : LwpObjectID *pRowID = GetChildHead();
467 1 : LwpRowLayout * pRowLayout = dynamic_cast<LwpRowLayout *>(pRowID->obj());
468 7 : while (pRowLayout)
469 : {
470 5 : pRowLayout->SetRowMap();
471 :
472 : // for 's analysis job
473 5 : m_RowsMap[pRowLayout->GetRowID()] = pRowLayout;
474 5 : pRowLayout->CollectMergeInfo();
475 : // end for 's analysis
476 :
477 5 : pRowID = pRowLayout->GetNext();
478 5 : pRowLayout = dynamic_cast<LwpRowLayout *>(pRowID->obj());
479 : }
480 1 : }
481 :
482 : /**
483 : * @short search the cell map
484 : * @param nRow - row id (0 based)
485 : * @param nRow - row id (0 based)
486 : * @return LwpObjectID * - pointer to cell story object ID
487 : */
488 0 : LwpObjectID * LwpTableLayout::SearchCellStoryMap(sal_uInt16 nRow, sal_uInt16 nCol)
489 : {
490 0 : if (nRow >= m_nRows || nCol >= m_nCols )
491 : {
492 0 : return NULL;
493 : }
494 :
495 0 : LwpCellLayout * pCell = GetCellByRowCol(nRow, nCol);
496 0 : if (pCell)
497 : {
498 : // maybe connected cell layout
499 : // maybe default cell layout
500 0 : if (nRow != pCell->GetRowID() || nCol != pCell->GetColID())
501 : {
502 0 : return NULL;
503 : }
504 0 : return pCell->GetContent();
505 : }
506 :
507 0 : return NULL;
508 : }
509 :
510 : /**
511 : * @short Get parent super table layout of table layout
512 : * @return LwpSuperTableLayout * - pointer of parent super table layout
513 : */
514 23 : LwpSuperTableLayout * LwpTableLayout::GetSuperTableLayout()
515 : {
516 23 : return dynamic_cast<LwpSuperTableLayout *>(GetParent()->obj());
517 : }
518 : /**
519 : * @short Get table pointer
520 : * @return LwpTable * - content table pointer
521 : */
522 18 : LwpTable * LwpTableLayout::GetTable()
523 : {
524 18 : LwpTable *pTable = dynamic_cast<LwpTable *>(m_Content.obj());
525 18 : return pTable;
526 : }
527 : /**
528 : * @short Get column style name by column ID
529 : * @param sal_uInt16 -- col id(0 based)
530 : * @return OUString - name of column style
531 : */
532 0 : OUString LwpTableLayout::GetColumnWidth(sal_uInt16 nCol)
533 : {
534 0 : if (nCol >= m_nCols)
535 : {
536 : assert(sal_False);
537 0 : return m_DefaultColumnStyleName;
538 : }
539 :
540 0 : LwpColumnLayout * pCol = m_pColumns[nCol];
541 0 : if (pCol)
542 : {
543 0 : return pCol->GetStyleName();
544 : }
545 :
546 0 : return m_DefaultColumnStyleName;
547 : }
548 : /**
549 : * @short analyze all columns to get whole table width and width of all columns
550 : * @short and register all column styles
551 : * @param none
552 : */
553 1 : void LwpTableLayout::RegisterColumns()
554 : {
555 1 : LwpTable * pTable = GetTable();
556 1 : LwpSuperTableLayout * pSuper = GetSuperTableLayout();
557 :
558 1 : sal_uInt16 nCols = m_nCols;
559 :
560 1 : m_pColumns = new LwpColumnLayout *[nCols];
561 1 : sal_Bool * pWidthCalculated = new sal_Bool[nCols];
562 5 : for(sal_uInt16 i=0;i<nCols; i++)
563 : {
564 4 : pWidthCalculated[i] = sal_False;
565 4 : m_pColumns[i] = NULL;
566 : }
567 :
568 1 : double dDefaultColumn = pTable->GetWidth();
569 1 : sal_uInt16 nJustifiableColumn = nCols;
570 :
571 1 : double dTableWidth = pSuper->GetTableWidth();
572 :
573 : // Get total width of justifiable columns
574 : // NOTICE: all default columns are regarded as justifiable columns
575 1 : LwpObjectID *pColumnID = GetColumnLayoutHead();
576 1 : LwpColumnLayout * pColumnLayout = dynamic_cast<LwpColumnLayout *>(pColumnID->obj());
577 2 : while (pColumnLayout)
578 : {
579 0 : m_pColumns[pColumnLayout->GetColumnID()] = pColumnLayout;
580 0 : if (!pColumnLayout->IsJustifiable())
581 : {
582 0 : pWidthCalculated[pColumnLayout->GetColumnID()] = sal_True;
583 0 : dTableWidth -= pColumnLayout->GetWidth();
584 0 : nJustifiableColumn --;
585 : }
586 :
587 0 : pColumnID = pColumnLayout->GetNext();
588 0 : pColumnLayout = dynamic_cast<LwpColumnLayout *>(pColumnID->obj());
589 : }
590 :
591 : // if all columns are not justifiable, the rightmost column will be changed to justifiable
592 1 : if(nJustifiableColumn == 0)
593 : {
594 0 : nJustifiableColumn ++;
595 0 : if (m_pColumns[nCols - 1])
596 : {
597 0 : pWidthCalculated[nCols-1] = sal_False;
598 0 : dTableWidth += m_pColumns[nCols-1]->GetWidth();
599 : }
600 : else
601 : {
602 : // this can't happen
603 0 : dTableWidth = dDefaultColumn;
604 : assert(sal_False);
605 : }
606 : }
607 :
608 : // justifiable columns will share the remain width averagely
609 1 : dDefaultColumn = dTableWidth/nJustifiableColumn;
610 :
611 : // register default column style
612 1 : XFColStyle *pColStyle = new XFColStyle();
613 1 : pColStyle->SetWidth(static_cast<float>(dDefaultColumn));
614 :
615 1 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
616 1 : m_DefaultColumnStyleName = pXFStyleManager->AddStyle(pColStyle)->GetStyleName();
617 :
618 : // register existed column style
619 1 : sal_uInt16 i=0;
620 5 : for( i=0;i<nCols; i++)
621 : {
622 4 : if(m_pColumns[i])
623 : {
624 0 : m_pColumns[i]->SetFoundry(m_pFoundry);
625 0 : if(!pWidthCalculated[i])
626 : {
627 : // justifiable ----register style with calculated value
628 0 : m_pColumns[i]->SetStyleName(m_DefaultColumnStyleName);
629 : }
630 : else
631 : {
632 : // not justifiable ---- register style with original value
633 0 : m_pColumns[i]->RegisterStyle(m_pColumns[i]->GetWidth());
634 : }
635 : }
636 : }
637 1 : delete [] pWidthCalculated;
638 1 : }
639 : /**
640 : * @short register all row styles
641 : * @param none
642 : */
643 1 : void LwpTableLayout::RegisterRows()
644 : {
645 1 : LwpTable * pTable = GetTable();
646 1 : if (pTable == NULL)
647 : {
648 : assert(sal_False);
649 1 : return;
650 : }
651 :
652 : // register default row style
653 1 : XFRowStyle * pRowStyle = new XFRowStyle();
654 1 : if (m_nDirection & 0x0030)
655 : {
656 1 : pRowStyle->SetMinRowHeight((float)pTable->GetHeight());
657 : }
658 : else
659 : {
660 0 : pRowStyle->SetRowHeight((float)pTable->GetHeight());
661 : }
662 1 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
663 1 : m_DefaultRowStyleName = pXFStyleManager->AddStyle(pRowStyle)->GetStyleName();
664 :
665 : // register style of rows
666 1 : LwpObjectID * pRowID = GetChildHead();
667 1 : LwpRowLayout * pRowLayout = dynamic_cast<LwpRowLayout *>(pRowID->obj());
668 7 : while (pRowLayout)
669 : {
670 5 : pRowLayout->SetFoundry(m_pFoundry);
671 5 : pRowLayout->RegisterStyle();
672 :
673 5 : pRowID = pRowLayout->GetNext();
674 5 : pRowLayout = dynamic_cast<LwpRowLayout *>(pRowID->obj());
675 : }
676 : }
677 : /**
678 : * @short register table style, if needed, including frame style
679 : * @param none
680 : */
681 1 : void LwpTableLayout::RegisterStyle()
682 : {
683 : // get super table layout
684 1 : LwpSuperTableLayout * pSuper = GetSuperTableLayout();
685 1 : if(!pSuper)
686 : {
687 : assert(sal_False);
688 0 : return;
689 : }
690 :
691 : // get table
692 1 : LwpTable * pTable = GetTable();
693 1 : if (pTable == NULL)
694 : {
695 : assert(sal_False);
696 0 : return;
697 : }
698 :
699 : // get row/column number of this table
700 1 : m_nRows = pTable->GetRow();
701 1 : m_nCols = pTable->GetColumn();
702 :
703 : // get default cell layout of current table
704 1 : LwpObjectID * pID= pTable->GetDefaultCellStyle();
705 1 : if (pID)
706 : {
707 1 : m_pDefaultCellLayout = dynamic_cast<LwpCellLayout *>(pID->obj());
708 : }
709 :
710 : // register columns styles
711 1 : RegisterColumns();
712 :
713 : // register style of whole table
714 1 : XFTableStyle * pTableStyle = new XFTableStyle();
715 :
716 1 : sal_uInt8 nType = pSuper->GetRelativeType();
717 : // If the table is not "with paragraph above" placement, create an frame style
718 : // by supertable layout
719 2 : if ( LwpLayoutRelativityGuts::LAY_INLINE_NEWLINE == nType
720 1 : && !pSuper->GetContainerLayout()->IsCell())
721 : {
722 : //with para above
723 : // pSuper->ApplyBackColor(pTableStyle);
724 1 : pSuper->ApplyBackGround(pTableStyle);
725 1 : pSuper->ApplyWatermark(pTableStyle);
726 1 : pSuper->ApplyShadow(pTableStyle);
727 1 : pSuper->ApplyAlignment(pTableStyle);
728 1 : pTableStyle->SetWidth(pSuper->GetTableWidth());
729 : }
730 : else
731 : {
732 0 : pSuper->RegisterFrameStyle();
733 0 : pTableStyle->SetAlign(enumXFAlignCenter);
734 0 : pTableStyle->SetWidth(pSuper->GetTableWidth());
735 : }
736 1 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
737 1 : m_StyleName = pXFStyleManager->AddStyle(pTableStyle)->GetStyleName();
738 :
739 : //convert to OO table now and register row stle
740 : // traverse
741 1 : TraverseTable();
742 :
743 1 : SplitConflictCells();
744 :
745 : // Register rows layouts, it must be after SplitConflictCells
746 1 : RegisterRows();
747 :
748 : // Parse table
749 1 : ParseTable();
750 :
751 :
752 : //Comment:The old code doesn't check if the LwpFoundry pointer is NULL,
753 : // So the NULL pointer cause sodc frozee. Add code to check the
754 : // the pointer.
755 : //New Code
756 1 : if( GetFoundry() && GetTable() )
757 :
758 1 : PutCellVals( GetFoundry(),*GetTable()->GetObjectID() );
759 : }
760 : /**
761 : * @short read table layout
762 : * @param none
763 : */
764 1 : void LwpTableLayout::ParseTable()
765 : {
766 : // get super table layout
767 1 : LwpSuperTableLayout * pSuper = GetSuperTableLayout();
768 1 : if(!pSuper)
769 : {
770 : assert(sal_False);
771 1 : return;
772 : }
773 :
774 : // set name of object
775 1 : m_pXFTable = new XFTable;
776 1 : m_pXFTable->SetTableName(pSuper->GetName()->str());
777 : // set table style
778 1 : m_pXFTable->SetStyleName(m_StyleName);
779 :
780 1 : sal_uInt16 nRow = m_nRows;
781 1 : sal_uInt8 nCol = (sal_uInt8)m_nCols;
782 :
783 : //process header rows
784 : LwpTableHeadingLayout* pTableHeading;
785 1 : pTableHeading = pSuper->GetTableHeadingLayout();
786 : sal_uInt16 nStartHeadRow;
787 : sal_uInt16 nEndHeadRow;
788 : sal_uInt16 nContentRow;
789 1 : if (pTableHeading)
790 : {
791 0 : pTableHeading->GetStartEndRow(nStartHeadRow,nEndHeadRow);
792 0 : if (nStartHeadRow != 0)
793 0 : ConvertTable(m_pXFTable,0,nRow,0,nCol);
794 : else
795 : {
796 0 : nContentRow = ConvertHeadingRow(m_pXFTable,nStartHeadRow,nEndHeadRow+1);
797 0 : ConvertTable(m_pXFTable,nContentRow,nRow,0,nCol);
798 : }
799 : }
800 : else
801 1 : ConvertTable(m_pXFTable,0,nRow,0,nCol);
802 : }
803 :
804 : /**
805 : * @short read table layout
806 : * @param none
807 : */
808 2 : void LwpTableLayout::Read()
809 : {
810 2 : LwpLayout::Read();
811 :
812 : // before layout hierarchy rework!
813 2 : if(LwpFileHeader::m_nFileRevision < 0x000b)
814 : {
815 : assert(sal_False);
816 : }
817 2 : m_ColumnLayout.ReadIndexed(m_pObjStrm);
818 :
819 2 : m_pObjStrm->SkipExtra();
820 2 : }
821 :
822 : /**
823 : * @short Convert table
824 : * @param
825 : * @return pCont - container which will contain table
826 : */
827 1 : void LwpTableLayout::XFConvert(XFContentContainer* pCont)
828 : {
829 :
830 1 : pCont->Add(m_pXFTable);
831 1 : }
832 : /**
833 : * @short convert heading row
834 : * @param pXFTable - pointer of table
835 : * @param nStartRow - start heading row ID
836 : * @param nEndRow - end heading row ID
837 : */
838 0 : sal_uInt16 LwpTableLayout::ConvertHeadingRow(
839 : XFTable* pXFTable,sal_uInt16 nStartHeadRow,sal_uInt16 nEndHeadRow)
840 : {
841 : sal_uInt16 nContentRow;
842 0 : sal_uInt8 nCol = static_cast<sal_uInt8>(GetTable()->GetColumn());
843 0 : XFTable* pTmpTable = new XFTable;
844 : XFRow* pXFRow;
845 :
846 0 : ConvertTable(pTmpTable,nStartHeadRow,nEndHeadRow,0,nCol);
847 :
848 0 : sal_uInt16 nRowNum = static_cast<sal_uInt16>(pTmpTable->GetRowCount());
849 0 : sal_uInt8* CellMark = new sal_uInt8[nRowNum];
850 0 : sal_Bool bFindFlag = sal_False;
851 :
852 0 : if (nRowNum == 1)
853 : {
854 0 : pXFRow = pTmpTable->GetRow(1);
855 0 : pXFTable->AddHeaderRow(pXFRow);
856 0 : pTmpTable->RemoveRow(1);
857 0 : nContentRow = nEndHeadRow;
858 : }
859 : else
860 : {
861 0 : sal_uInt8 nFirstColSpann = 1;
862 0 : bFindFlag = FindSplitColMark(pTmpTable,CellMark,nFirstColSpann);
863 :
864 0 : if (bFindFlag)//split to 2 cells
865 : {
866 0 : SplitRowToCells(pTmpTable,pXFTable,nFirstColSpann,CellMark);
867 0 : nContentRow = nEndHeadRow;
868 : }
869 : else//can not split,the first row will be the heading row,the rest will be content row
870 : {
871 0 : pXFRow = pTmpTable->GetRow(1);
872 0 : pXFTable->AddHeaderRow(pXFRow);
873 0 : pTmpTable->RemoveRow(1);
874 0 : nContentRow = m_RowsMap[0]->GetCurMaxSpannedRows(0,nCol);
875 : }
876 : }
877 0 : delete pTmpTable;
878 0 : delete [] CellMark;
879 0 : return nContentRow;
880 : }
881 :
882 0 : void LwpTableLayout::SplitRowToCells(XFTable* pTmpTable,XFTable* pXFTable,
883 : sal_uInt8 nFirstColSpann,sal_uInt8* pCellMark)
884 : {
885 : sal_uInt16 i;
886 : sal_uInt8 j;
887 0 : sal_uInt16 nRowNum = static_cast<sal_uInt16>(pTmpTable->GetRowCount());
888 0 : sal_uInt8 nCol = static_cast<sal_uInt8>(GetTable()->GetColumn());
889 :
890 0 : XFRow* pXFRow = new XFRow;
891 :
892 : //register style for heading row
893 0 : double fHeight = 0;
894 0 : OUString styleName;
895 0 : XFRowStyle* pRowStyle = new XFRowStyle;
896 0 : styleName = pTmpTable->GetRow(1)->GetStyleName();
897 :
898 : // get settings of the row and assign them to new row style
899 0 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
900 0 : XFRowStyle *pTempRowStyle = static_cast<XFRowStyle*>(pXFStyleManager->FindStyle(styleName));
901 0 : if (pTempRowStyle)
902 0 : *pRowStyle = *pTempRowStyle;
903 :
904 0 : for (i=1;i<=nRowNum;i++)
905 : {
906 0 : styleName = pTmpTable->GetRow(i)->GetStyleName();
907 0 : fHeight+=static_cast<XFRowStyle*>(pXFStyleManager->FindStyle(styleName))->GetRowHeight();
908 : }
909 0 : if (m_nDirection & 0x0030)
910 : {
911 0 : pRowStyle->SetMinRowHeight((float)fHeight);
912 : }
913 : else
914 : {
915 0 : pRowStyle->SetRowHeight((float)fHeight);
916 : }
917 0 : pXFRow->SetStyleName(pXFStyleManager->AddStyle(pRowStyle)->GetStyleName());
918 :
919 : //construct headong row
920 0 : XFCell* pXFCell1 = new XFCell;
921 0 : XFCell* pXFCell2 = new XFCell;
922 0 : XFTable* pSubTable1 = new XFTable;
923 0 : XFTable* pSubTable2 = new XFTable;
924 : XFRow* pNewRow;
925 : XFRow* pOldRow;
926 : XFCell* pNewCell;
927 :
928 0 : for (i=1;i<=nRowNum;i++)
929 : {
930 0 : pOldRow = pTmpTable->GetRow(i);
931 0 : pNewRow = new XFRow;
932 0 : pNewRow->SetStyleName(pOldRow->GetStyleName());
933 0 : for (j=1;j<=pCellMark[i];j++)
934 : {
935 0 : pNewCell = pOldRow->GetCell(j);
936 0 : pNewRow->AddCell(pNewCell);
937 : }
938 0 : pSubTable1->AddRow(pNewRow);
939 : }
940 0 : ConvertColumn(pSubTable1,0,nFirstColSpann);//add column info
941 :
942 0 : pXFCell1->Add(pSubTable1);
943 0 : pXFCell1->SetColumnSpaned(nFirstColSpann);
944 0 : pXFRow->AddCell(pXFCell1);
945 :
946 0 : for (i=1;i<=nRowNum;i++)
947 : {
948 0 : pOldRow = pTmpTable->GetRow(i);
949 0 : pNewRow = new XFRow;
950 0 : pNewRow->SetStyleName(pOldRow->GetStyleName());
951 0 : for(j=pCellMark[i]+1;j<=pOldRow->GetCellCount();j++)
952 : {
953 0 : pNewCell = pOldRow->GetCell(j);
954 0 : pNewRow->AddCell(pNewCell);
955 : }
956 0 : pSubTable2->AddRow(pNewRow);
957 :
958 : }
959 0 : ConvertColumn(pSubTable2,nFirstColSpann,nCol);//add column info
960 0 : pXFCell2->Add(pSubTable2);
961 0 : pXFCell2->SetColumnSpaned(nCol-nFirstColSpann);
962 0 : pXFRow->AddCell(pXFCell2);
963 :
964 0 : pXFTable->AddHeaderRow(pXFRow);
965 :
966 : //remove tmp table
967 0 : for (i=1;i<=nRowNum;i++)
968 : {
969 0 : pOldRow = pTmpTable->GetRow(i);
970 0 : for(j=1;j<=pOldRow->GetCellCount();j++)
971 0 : pOldRow->RemoveCell(j);
972 0 : pTmpTable->RemoveRow(i);
973 0 : }
974 0 : }
975 :
976 : /**
977 : * @short find if the heading rows can be split to 2 cells
978 : * @param pXFTable - pointer of tmp XFtable
979 : * @param CellMark - pointer of cell mark array
980 : */
981 0 : sal_Bool LwpTableLayout::FindSplitColMark(XFTable* pXFTable,sal_uInt8* pCellMark,
982 : sal_uInt8& nMaxColSpan)
983 : {
984 0 : sal_uInt16 nRowNum = static_cast<sal_uInt16>(pXFTable->GetRowCount());
985 0 : sal_uInt8 nColNum = static_cast<sal_uInt8>(pXFTable->GetColumnCount());
986 0 : sal_uInt8 nCellMark=0;
987 : sal_uInt8 nCount;
988 : sal_uInt8 nColSpan;
989 0 : sal_Bool bFindFlag = sal_False;
990 : XFRow* pTmpRow;
991 :
992 0 : for(sal_uInt8 i=1;i<=nColNum;i++)
993 : {
994 : sal_uInt16 nRowLoop;
995 : sal_uInt8 nCellLoop;
996 :
997 : //find current max column span
998 0 : nMaxColSpan = 1;
999 0 : for (nRowLoop=1;nRowLoop<=nRowNum;nRowLoop++)
1000 : {
1001 0 : nColSpan = 0;
1002 0 : for(nCellLoop=1; nCellLoop<i+1; nCellLoop++)
1003 : {
1004 0 : pTmpRow = pXFTable->GetRow(nRowLoop);
1005 0 : XFCell* pCell = pTmpRow->GetCell(nCellLoop);
1006 0 : if (pCell)
1007 0 : nColSpan += static_cast<sal_uInt8>(pCell->GetColSpaned());
1008 : else
1009 0 : return sal_False;
1010 : }
1011 0 : if (nColSpan > nMaxColSpan)
1012 0 : nMaxColSpan = nColSpan;
1013 0 : pCellMark[nRowLoop] = 0;//reset all cell mark to zero
1014 : }
1015 :
1016 : //find if other row has the same colum
1017 0 : for (nRowLoop=1;nRowLoop<=nRowNum;nRowLoop++)
1018 : {
1019 0 : pTmpRow = pXFTable->GetRow(nRowLoop);
1020 0 : nCount = 0;
1021 0 : nCellMark = 0;
1022 0 : for (nCellLoop=1; nCellLoop<=pTmpRow->GetCellCount(); nCellLoop++)
1023 : {
1024 0 : if (nCount>nMaxColSpan)
1025 0 : break;
1026 0 : nCount+= static_cast<sal_uInt8>(pTmpRow->GetCell(nCellLoop)->GetColSpaned());
1027 0 : if (nCount == nMaxColSpan)
1028 : {
1029 0 : nCellMark = nCellLoop;
1030 0 : break;
1031 : }
1032 : }
1033 0 : if (nCellMark == 0)
1034 0 : break;
1035 : else
1036 0 : pCellMark[nRowLoop] = nCellMark;
1037 : }
1038 0 : for(nRowLoop=1;nRowLoop<=nRowNum;nRowLoop++)//check if all ==0,break
1039 : {
1040 0 : if (pCellMark[nRowLoop] == 0)
1041 0 : break;
1042 : }
1043 0 : if (nRowLoop == nRowNum+1)
1044 : {
1045 0 : bFindFlag = sal_True;
1046 0 : return bFindFlag;
1047 : }
1048 :
1049 : }
1050 0 : return bFindFlag;
1051 : }
1052 :
1053 : /**
1054 : * @short convert word pro table to SODC table
1055 : * @param pXFTable - pointer of table
1056 : * @param nStartRow - start row ID
1057 : * @param nEndRow - end row ID
1058 : * @param nStartCol - start column ID
1059 : * @param nEndCol - end column ID
1060 : */
1061 1 : void LwpTableLayout::ConvertTable(XFTable* pXFTable,sal_uInt16 nStartRow,
1062 : sal_uInt16 nEndRow,sal_uInt8 nStartCol,sal_uInt8 nEndCol)
1063 : {
1064 : //out put column info TO BE CHANGED
1065 1 : ConvertColumn(pXFTable,nStartCol,nEndCol);
1066 :
1067 1 : std::map<sal_uInt16,LwpRowLayout*>::iterator iter;
1068 :
1069 7 : for (sal_uInt16 i=nStartRow; i<nEndRow;)
1070 : {
1071 5 : iter = m_RowsMap.find(i);
1072 5 : if (iter == m_RowsMap.end())
1073 : {
1074 0 : ConvertDefaultRow(pXFTable,nStartCol,nEndCol,i);
1075 0 : i++;
1076 : }
1077 : else
1078 : {
1079 5 : LwpRowLayout* pRow = iter->second;
1080 5 : if (pRow->GetCurMaxSpannedRows(nStartCol,nEndCol) == 1)
1081 : {
1082 5 : pRow->ConvertCommonRow(pXFTable,nStartCol,nEndCol);
1083 5 : i++;
1084 : }
1085 : else
1086 : {
1087 0 : pRow->ConvertRow(pXFTable,nStartCol,nEndCol);
1088 0 : i += pRow->GetCurMaxSpannedRows(nStartCol,nEndCol);
1089 : }
1090 : }
1091 : }
1092 1 : }
1093 :
1094 : /**
1095 : * @short apply numeric value and formula to cell
1096 : * @param pFoundry - pointer of foundry
1097 : * @param aTableID - table ID
1098 : */
1099 1 : void LwpTableLayout::PutCellVals(LwpFoundry* pFoundry, LwpObjectID aTableID)
1100 : {
1101 :
1102 : //Comment:The old code doesn't check if the LwpFoundry pointer is NULL,
1103 : // So the NULL pointer cause sodc frozee. Add code to check the
1104 : // the pointer.
1105 : //New Code
1106 2 : if( !pFoundry ) return;
1107 :
1108 :
1109 : try{
1110 :
1111 1 : LwpDLVListHeadHolder* pHolder = (LwpDLVListHeadHolder*)pFoundry->GetNumberManager()->GetTableRangeID().obj();
1112 :
1113 1 : LwpTableRange* pTableRange = (LwpTableRange*)pHolder->GetHeadID()->obj();
1114 :
1115 : //Look up the table
1116 2 : while (NULL!=pTableRange)
1117 : {
1118 0 : LwpObjectID aID = pTableRange->GetTableID();
1119 0 : if (aID == aTableID)
1120 : {
1121 : break;
1122 : }
1123 0 : pTableRange = pTableRange->GetNext();
1124 : }
1125 :
1126 1 : if (pTableRange)
1127 : {
1128 0 : LwpCellRange* pRange = (LwpCellRange*)pTableRange->GetCellRangeID().obj();
1129 0 : LwpFolder* pFolder = (LwpFolder*)pRange->GetFolderID().obj();
1130 0 : LwpObjectID aRowListID = pFolder->GetChildHeadID();
1131 0 : LwpRowList* pRowList = (LwpRowList*)aRowListID.obj();
1132 :
1133 : //loop the rowlist
1134 0 : while( NULL!=pRowList)
1135 : {
1136 0 : sal_uInt16 nRowID = pRowList->GetRowID();
1137 : {
1138 0 : LwpCellList* pCellList = (LwpCellList*)pRowList->GetChildHeadID().obj();
1139 : //loop the celllist
1140 0 : while( NULL!=pCellList)
1141 : {
1142 : {//put cell
1143 0 : sal_uInt16 nColID = pCellList->GetColumnID();
1144 :
1145 0 : XFCell* pCell = GetCellsMap(nRowID,static_cast<sal_uInt8>(nColID));
1146 0 : if (pCell)
1147 : {
1148 0 : pCellList->Convert(pCell, this);
1149 :
1150 : //process paragraph
1151 0 : PostProcessParagraph(pCell, nRowID, nColID);
1152 : }
1153 : else
1154 : {
1155 : //Hidden cell would not be in cellsmap
1156 : assert(false);
1157 : }
1158 : }
1159 0 : pCellList = (LwpCellList*)pCellList->GetNextID().obj();
1160 : }
1161 : }
1162 0 : pRowList =(LwpRowList*)pRowList->GetNextID().obj();
1163 : }
1164 : }
1165 :
1166 0 : }catch (...) {
1167 : assert(false);
1168 : }
1169 : }
1170 :
1171 : /**
1172 : * @short 1. set number right alignment to right if number 2. remove tab added before if number
1173 : * @param pCell - cell which to be process
1174 : * @param nRowID - row number in Word Pro file
1175 : * @param nColID - column number in Word Pro file
1176 : */
1177 0 : void LwpTableLayout::PostProcessParagraph(XFCell *pCell, sal_uInt16 nRowID, sal_uInt16 nColID)
1178 : {
1179 : // if number right, set alignment to right
1180 0 : LwpCellLayout * pCellLayout = GetCellByRowCol(nRowID, nColID);
1181 0 : if(pCellLayout)
1182 : {
1183 0 : XFParagraph * pXFPara = NULL;
1184 0 : pXFPara = static_cast<XFParagraph*>(pCell->FindFirstContent(enumXFContentPara));
1185 0 : if (!pXFPara)
1186 0 : return;
1187 0 : XFColor aColor;
1188 0 : XFColor aNullColor = XFColor();
1189 :
1190 0 : if ( pXFPara)
1191 : {
1192 0 : OUString sNumfmt = pCellLayout->GetNumfmtName();
1193 0 : sal_Bool bColorMod = sal_False;
1194 0 : XFNumberStyle* pNumStyle = NULL;
1195 0 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
1196 0 : if (!sNumfmt.isEmpty())
1197 : {
1198 0 : pNumStyle = (XFNumberStyle*)pXFStyleManager->FindStyle( sNumfmt);
1199 0 : aColor = pNumStyle->GetColor();
1200 0 : if ( pNumStyle && aColor != aNullColor )
1201 0 : bColorMod = sal_True;//end
1202 : }
1203 :
1204 0 : XFParaStyle * pStyle = pXFStyleManager->FindParaStyle(pXFPara->GetStyleName());
1205 0 : if (pStyle->GetNumberRight() || bColorMod)
1206 : {
1207 0 : XFParaStyle* pOverStyle = new XFParaStyle;
1208 0 : *pOverStyle = *pStyle;
1209 :
1210 0 : if (pStyle->GetNumberRight())
1211 0 : pOverStyle->SetAlignType(enumXFAlignEnd);
1212 :
1213 0 : if (bColorMod)
1214 : {
1215 0 : XFFont* pFont = pOverStyle->GetFont();
1216 0 : aColor = pFont->GetColor();
1217 0 : if ( aColor == aNullColor )
1218 : {
1219 0 : XFFont* pNewFont = new XFFont;
1220 0 : aColor = pNumStyle->GetColor();
1221 0 : pNewFont->SetColor(aColor);
1222 0 : pOverStyle->SetFont(pNewFont);
1223 : }
1224 : }
1225 :
1226 0 : pOverStyle->SetStyleName(A2OUSTR(""));
1227 0 : OUString StyleName = pXFStyleManager->AddStyle(pOverStyle)->GetStyleName();
1228 :
1229 0 : pXFPara->SetStyleName(StyleName);
1230 0 : }
1231 : }
1232 : }
1233 : }
1234 :
1235 : /**
1236 : * @short Parse all cols of table
1237 : * @param pXFTable - pointer to created XFTable
1238 : */
1239 1 : void LwpTableLayout::ConvertColumn(XFTable *pXFTable,sal_uInt8 nStartCol,sal_uInt8 nEndCol)
1240 : {
1241 1 : LwpTable * pTable = GetTable();
1242 1 : if (!pTable)
1243 : {
1244 : assert(sal_False);
1245 1 : return;
1246 : }
1247 :
1248 5 : for (sal_uInt32 iLoop = 0; iLoop < static_cast<sal_uInt32>(nEndCol)-nStartCol; ++iLoop)
1249 : {
1250 : // add row to table
1251 4 : LwpObjectID *pColID = GetColumnLayoutHead();
1252 4 : LwpColumnLayout * pColumnLayout = dynamic_cast<LwpColumnLayout *>(pColID->obj());
1253 8 : while (pColumnLayout)
1254 : {
1255 0 : if (pColumnLayout->GetColumnID() == (iLoop+nStartCol))
1256 : {
1257 0 : pXFTable->SetColumnStyle(iLoop+1, pColumnLayout->GetStyleName());
1258 0 : break;
1259 : }
1260 0 : pColID = pColumnLayout->GetNext();
1261 0 : pColumnLayout = dynamic_cast<LwpColumnLayout *>(pColID->obj());
1262 : }
1263 4 : if (!pColumnLayout)
1264 : {
1265 4 : pXFTable->SetColumnStyle(iLoop+1, m_DefaultColumnStyleName);
1266 : }
1267 : }
1268 : }
1269 : /**
1270 : * @short split conflict merged cells
1271 : */
1272 1 : void LwpTableLayout::SplitConflictCells()
1273 : {
1274 1 : LwpTable * pTable = GetTable();
1275 1 : if (!pTable)
1276 1 : return;
1277 1 : sal_uInt16 nCol = pTable->GetColumn();
1278 1 : sal_uInt16 nRow = pTable->GetRow();
1279 :
1280 : sal_uInt16 nEffectRows;
1281 1 : std::map<sal_uInt16,LwpRowLayout*>::iterator iter1;
1282 1 : std::map<sal_uInt16,LwpRowLayout*>::iterator iter2;
1283 : LwpRowLayout* pRowLayout;
1284 : LwpRowLayout* pEffectRow;
1285 :
1286 7 : for (sal_uInt16 i=0; i<nRow; )
1287 : {
1288 5 : iter1 = m_RowsMap.find(i);
1289 5 : if (iter1 == m_RowsMap.end())//default rows
1290 : {
1291 0 : i++;
1292 0 : continue;
1293 : }
1294 5 : pRowLayout= iter1->second;
1295 5 : if (pRowLayout->GetMergeCellFlag() == sal_False)
1296 : {
1297 5 : i++;
1298 5 : continue;
1299 : }
1300 : else
1301 : {
1302 0 : nEffectRows = i + pRowLayout->GetCurMaxSpannedRows(0,(sal_uInt8)nCol);
1303 :
1304 0 : for (sal_uInt16 j = i+1; j<nEffectRows; j++)
1305 : {
1306 0 : iter2 = m_RowsMap.find(j);
1307 0 : if (iter2 == m_RowsMap.end())
1308 0 : continue;
1309 0 : pEffectRow = iter2->second;
1310 0 : if (pEffectRow->GetMergeCellFlag() == sal_False)
1311 0 : continue;
1312 : else
1313 0 : pEffectRow->SetCellSplit(nEffectRows);
1314 : }
1315 0 : i = nEffectRows;
1316 : }
1317 : }//end for
1318 :
1319 : }
1320 : /**
1321 : * @short add default row which are missing in the file
1322 : * @param pXFTable - pointer to new created table
1323 : * @param nStartCol - starting column
1324 : * @param nEndCol - end column
1325 : * @return pXFTable
1326 : */
1327 0 : void LwpTableLayout::ConvertDefaultRow(XFTable* pXFTable,sal_uInt8 nStartCol,
1328 : sal_uInt8 nEndCol,sal_uInt16 nRowID)
1329 : {
1330 : // current row doesn't exist in the file
1331 0 : XFRow * pRow = new XFRow();
1332 0 : pRow->SetStyleName(m_DefaultRowStyleName);
1333 :
1334 0 : for (sal_uInt16 j =0;j < nEndCol-nStartCol; j++)
1335 : {
1336 : // if table has default cell layout, use it to ConvertCell
1337 : // otherwise use blank cell
1338 0 : XFCell * pCell = NULL;
1339 0 : if (m_pDefaultCellLayout)
1340 : {
1341 : pCell = m_pDefaultCellLayout->ConvertCell(
1342 0 : *GetTable()->GetObjectID(),nRowID,j+nStartCol);
1343 : }
1344 : else
1345 : {
1346 0 : pCell = new XFCell();
1347 : }
1348 0 : pRow->AddCell(pCell);
1349 : }
1350 :
1351 0 : pXFTable->AddRow(pRow);
1352 0 : }
1353 : /**
1354 : * @short set cell map info
1355 : * @param pXFCell - pointer to xfcell
1356 : * @param nRow - row id
1357 : * @param nCol - column id
1358 : */
1359 20 : void LwpTableLayout::SetCellsMap(sal_uInt16 nRow,sal_uInt8 nCol,XFCell* pXFCell)
1360 : {
1361 20 : std::pair<std::pair<sal_uInt16,sal_uInt8>,XFCell*> cell;
1362 20 : std::pair<sal_uInt16,sal_uInt8> pos;
1363 20 : pos.first = nRow;
1364 20 : pos.second = nCol;
1365 20 : cell.first = pos;
1366 20 : cell.second = pXFCell;
1367 20 : m_CellsMap.insert(cell);
1368 20 : }
1369 :
1370 : /**
1371 : * @short get cell map info
1372 : * @param nRow - row id
1373 : * @param nCol - column id
1374 : * @return pXFCell
1375 : */
1376 0 : XFCell* LwpTableLayout::GetCellsMap(sal_uInt16 nRow,sal_uInt8 nCol)
1377 : {
1378 0 : std::pair<sal_uInt16,sal_uInt8> pos;
1379 0 : pos.first = nRow;
1380 0 : pos.second = nCol;
1381 0 : std::map<std::pair<sal_uInt16,sal_uInt8>,XFCell*>::iterator iter;
1382 0 : iter = m_CellsMap.find(pos);
1383 0 : if (iter == m_CellsMap.end())
1384 0 : return NULL;
1385 0 : return iter->second;
1386 : }
1387 : /**
1388 : * @descr Get row layout by row id
1389 : * @param nRow - row id
1390 : */
1391 0 : LwpRowLayout* LwpTableLayout::GetRowLayout(sal_uInt16 nRow)
1392 : {
1393 0 : LwpObjectID *pRowID = GetChildHead();
1394 0 : LwpRowLayout * pRowLayout = dynamic_cast<LwpRowLayout *>(pRowID->obj());
1395 0 : while (pRowLayout)
1396 : {
1397 0 : if(pRowLayout->GetRowID() == nRow)
1398 0 : return pRowLayout;
1399 :
1400 0 : pRowID = pRowLayout->GetNext();
1401 0 : pRowLayout = dynamic_cast<LwpRowLayout *>(pRowID->obj());
1402 : }
1403 0 : return NULL;
1404 : }
1405 :
1406 :
1407 : //add end by
1408 0 : LwpColumnLayout::LwpColumnLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
1409 0 : : LwpVirtualLayout(objHdr, pStrm)
1410 0 : {}
1411 :
1412 0 : LwpColumnLayout::~LwpColumnLayout()
1413 0 : {}
1414 0 : void LwpColumnLayout::Read()
1415 : {
1416 0 : LwpObjectStream* pStrm = m_pObjStrm;
1417 :
1418 0 : LwpVirtualLayout::Read();
1419 :
1420 : sal_uInt16 colid;
1421 :
1422 0 : colid = pStrm->QuickReaduInt16(); // forced to lushort
1423 0 : ccolid = (sal_uInt8)colid; // Phillip
1424 0 : cwidth = pStrm->QuickReadInt32();
1425 :
1426 0 : pStrm->SkipExtra();
1427 0 : }
1428 :
1429 0 : void LwpColumnLayout::RegisterStyle(double dCalculatedWidth)
1430 : {
1431 0 : XFColStyle * pColStyle = new XFColStyle();
1432 0 : pColStyle->SetWidth(static_cast<float>(dCalculatedWidth));
1433 0 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
1434 0 : m_StyleName = pXFStyleManager->AddStyle(pColStyle)->GetStyleName();
1435 0 : }
1436 :
1437 0 : LwpTableHeadingLayout::LwpTableHeadingLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
1438 0 : : LwpTableLayout(objHdr, pStrm)
1439 0 : {}
1440 :
1441 0 : LwpTableHeadingLayout::~LwpTableHeadingLayout()
1442 0 : {}
1443 : /**
1444 : * @short read table heading layout
1445 : * @param
1446 : * @return
1447 : */
1448 0 : void LwpTableHeadingLayout::Read()
1449 : {
1450 0 : LwpTableLayout::Read();
1451 :
1452 0 : cStartRow = m_pObjStrm->QuickReaduInt16();
1453 0 : cEndRow = m_pObjStrm->QuickReaduInt16();
1454 :
1455 0 : m_pObjStrm->SkipExtra();
1456 :
1457 0 : }
1458 : /**
1459 : * @short get start and end row number of table heading
1460 : * @param
1461 : * @return *pStartRow - starting row number
1462 : * @return *pEndRow - end row number
1463 : */
1464 0 : void LwpTableHeadingLayout::GetStartEndRow(sal_uInt16& nStartRow, sal_uInt16& nEndRow)
1465 : {
1466 0 : nStartRow = cStartRow;
1467 0 : nEndRow = cEndRow;
1468 0 : }
1469 : /**
1470 : * @short get first row heading layout of table heading
1471 : * @param
1472 : * @return LwpRowHeadingLayout * - pointer to first row heading layout of table heading
1473 : */
1474 0 : LwpRowHeadingLayout * LwpTableHeadingLayout::GetFirstRowHeadingLayout()
1475 : {
1476 0 : LwpObjectID *pID = GetChildHead();
1477 0 : if(pID && !pID->IsNull())
1478 : {
1479 0 : LwpRowHeadingLayout * pHeadingRow = dynamic_cast<LwpRowHeadingLayout *>(pID->obj());
1480 0 : return pHeadingRow;
1481 : }
1482 0 : return NULL;
1483 : }
1484 :
1485 0 : LwpSuperParallelColumnLayout::LwpSuperParallelColumnLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm):LwpSuperTableLayout(objHdr, pStrm)
1486 : {
1487 0 : }
1488 0 : LwpSuperParallelColumnLayout::~LwpSuperParallelColumnLayout()
1489 0 : {}
1490 :
1491 0 : void LwpSuperParallelColumnLayout::Read()
1492 : {
1493 0 : LwpSuperTableLayout::Read();
1494 0 : m_pObjStrm->SkipExtra();
1495 :
1496 0 : }
1497 :
1498 0 : LwpSuperGlossaryLayout::LwpSuperGlossaryLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm):LwpSuperTableLayout(objHdr, pStrm)
1499 : {
1500 0 : }
1501 :
1502 0 : LwpSuperGlossaryLayout::~LwpSuperGlossaryLayout()
1503 : {
1504 0 : }
1505 :
1506 0 : void LwpSuperGlossaryLayout::Read()
1507 : {
1508 0 : LwpSuperTableLayout::Read();
1509 0 : m_pObjStrm->SkipExtra();
1510 0 : }
1511 :
1512 :
1513 0 : LwpParallelColumnsLayout::LwpParallelColumnsLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm):LwpTableLayout(objHdr, pStrm)
1514 : {
1515 0 : }
1516 :
1517 0 : LwpParallelColumnsLayout::~LwpParallelColumnsLayout()
1518 : {
1519 0 : }
1520 :
1521 0 : void LwpParallelColumnsLayout::Read()
1522 : {
1523 0 : LwpTableLayout::Read();
1524 0 : m_pObjStrm->SkipExtra();
1525 0 : }
1526 :
1527 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|