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