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& rID = GetChildTail();
118 :
119 4 : while(!rID.IsNull())
120 : {
121 1 : LwpLayout* pLayout = dynamic_cast<LwpLayout*>(rID.obj().get());
122 1 : if (!pLayout)
123 : {
124 0 : break;
125 : }
126 1 : if (pLayout->GetLayoutType() == LWP_TABLE_LAYOUT)
127 : {
128 1 : return dynamic_cast<LwpTableLayout *>(pLayout);
129 : }
130 0 : rID = pLayout->GetPrevious();
131 : }
132 :
133 1 : 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& rID = GetChildTail();
142 :
143 3 : while(!rID.IsNull())
144 : {
145 1 : LwpLayout * pLayout = dynamic_cast<LwpLayout *>(rID.obj().get());
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 : rID = 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 : 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 false;
185 : }
186 : /**
187 : * @short Judge whether table is justifiable, borrowed from Word Pro code
188 : * @param
189 : * @return sal_Bool
190 : */
191 2 : 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(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& rColumnID = pTableLayout->GetColumnLayoutHead();
238 0 : LwpColumnLayout * pColumnLayout = dynamic_cast<LwpColumnLayout *>(rColumnID.obj().get());
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 : rColumnID = pColumnLayout->GetNext();
248 0 : pColumnLayout = dynamic_cast<LwpColumnLayout *>(rColumnID.obj().get());
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 : boost::scoped_ptr<XFShadow> pXFShadow(GetXFShadow());
270 1 : if(pXFShadow)
271 : {
272 0 : pTableStyle->SetShadow(pXFShadow->GetPosition(), pXFShadow->GetOffset(), pXFShadow->GetColor());
273 1 : }
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 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 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, 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 : : LwpLayout(objHdr, pStrm)
421 : , m_nRows(0)
422 : , m_nCols(0)
423 : , m_pDefaultCellLayout(NULL)
424 : , m_pColumns(NULL)
425 2 : , m_pXFTable(NULL)
426 : {
427 2 : m_CellsMap.clear();
428 2 : }
429 :
430 5 : LwpTableLayout::~LwpTableLayout()
431 : {
432 2 : m_CellsMap.clear();
433 :
434 2 : if (m_pColumns)
435 : {
436 1 : delete [] m_pColumns;
437 1 : m_pColumns = NULL;
438 : }
439 3 : }
440 :
441 : /**
442 : * @short Get neighbour cell by specifying ROW+COL
443 : * @param nRow
444 : * @param nCol
445 : * @return LwpCellLayout *
446 : */
447 40 : LwpCellLayout * LwpTableLayout::GetCellByRowCol(sal_uInt16 nRow, sal_uInt16 nCol)
448 : {
449 40 : if (nRow >= m_nRows || nCol >= m_nCols)
450 9 : return NULL;
451 :
452 31 : return m_WordProCellsMap[static_cast<size_t>(nRow)*m_nCols + nCol];
453 : }
454 : /**
455 : * @short traverse all table cells
456 : * @param
457 : * @param
458 : * @param
459 : */
460 1 : void LwpTableLayout::TraverseTable()
461 : {
462 1 : sal_uInt32 nCount = m_nRows*m_nCols;
463 :
464 : // new cell map nRow*nCOl and initialize
465 21 : for (sal_uInt32 iLoop = 0; iLoop < nCount; ++iLoop)
466 : {
467 20 : m_WordProCellsMap.push_back(GetDefaultCellLayout());
468 : }
469 :
470 : // set value
471 1 : LwpObjectID& rRowID = GetChildHead();
472 1 : LwpRowLayout * pRowLayout = dynamic_cast<LwpRowLayout *>(rRowID.obj().get());
473 7 : while (pRowLayout)
474 : {
475 5 : pRowLayout->SetRowMap();
476 :
477 : // for 's analysis job
478 5 : m_RowsMap[pRowLayout->GetRowID()] = pRowLayout;
479 5 : pRowLayout->CollectMergeInfo();
480 : // end for 's analysis
481 :
482 5 : rRowID = pRowLayout->GetNext();
483 5 : pRowLayout = dynamic_cast<LwpRowLayout *>(rRowID.obj().get());
484 : }
485 1 : }
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 23 : LwpSuperTableLayout * LwpTableLayout::GetSuperTableLayout()
520 : {
521 23 : return dynamic_cast<LwpSuperTableLayout *>(GetParent().obj().get());
522 : }
523 : /**
524 : * @short Get table pointer
525 : * @return LwpTable * - content table pointer
526 : */
527 13 : LwpTable * LwpTableLayout::GetTable()
528 : {
529 13 : LwpTable *pTable = dynamic_cast<LwpTable *>(m_Content.obj().get());
530 13 : 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 1 : void LwpTableLayout::RegisterColumns()
559 : {
560 1 : LwpTable * pTable = GetTable();
561 1 : LwpSuperTableLayout * pSuper = GetSuperTableLayout();
562 :
563 1 : sal_uInt16 nCols = m_nCols;
564 :
565 1 : m_pColumns = new LwpColumnLayout *[nCols];
566 1 : sal_Bool * pWidthCalculated = new sal_Bool[nCols];
567 5 : for(sal_uInt16 i=0;i<nCols; i++)
568 : {
569 4 : pWidthCalculated[i] = sal_False;
570 4 : m_pColumns[i] = NULL;
571 : }
572 :
573 1 : double dDefaultColumn = pTable->GetWidth();
574 1 : sal_uInt16 nJustifiableColumn = nCols;
575 :
576 1 : double dTableWidth = pSuper->GetTableWidth();
577 :
578 : // Get total width of justifiable columns
579 : // NOTICE: all default columns are regarded as justifiable columns
580 1 : LwpObjectID& rColumnID = GetColumnLayoutHead();
581 1 : LwpColumnLayout * pColumnLayout = dynamic_cast<LwpColumnLayout *>(rColumnID.obj().get());
582 2 : 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 : rColumnID = pColumnLayout->GetNext();
593 0 : pColumnLayout = dynamic_cast<LwpColumnLayout *>(rColumnID.obj().get());
594 : }
595 :
596 : // if all columns are not justifiable, the rightmost column will be changed to justifiable
597 1 : 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 1 : dDefaultColumn = dTableWidth/nJustifiableColumn;
615 :
616 : // register default column style
617 1 : XFColStyle *pColStyle = new XFColStyle();
618 1 : pColStyle->SetWidth(static_cast<float>(dDefaultColumn));
619 :
620 1 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
621 1 : m_DefaultColumnStyleName = pXFStyleManager->AddStyle(pColStyle).m_pStyle->GetStyleName();
622 :
623 : // register existed column style
624 1 : sal_uInt16 i=0;
625 5 : for( i=0;i<nCols; i++)
626 : {
627 4 : 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 1 : delete [] pWidthCalculated;
643 1 : }
644 : /**
645 : * @short register all row styles
646 : * @param none
647 : */
648 1 : void LwpTableLayout::RegisterRows()
649 : {
650 1 : LwpTable * pTable = GetTable();
651 1 : if (pTable == NULL)
652 : {
653 : assert(false);
654 1 : return;
655 : }
656 :
657 : // register default row style
658 1 : XFRowStyle * pRowStyle = new XFRowStyle();
659 1 : if (m_nDirection & 0x0030)
660 : {
661 1 : pRowStyle->SetMinRowHeight((float)pTable->GetHeight());
662 : }
663 : else
664 : {
665 0 : pRowStyle->SetRowHeight((float)pTable->GetHeight());
666 : }
667 1 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
668 1 : m_DefaultRowStyleName = pXFStyleManager->AddStyle(pRowStyle).m_pStyle->GetStyleName();
669 :
670 : // register style of rows
671 1 : LwpObjectID& rRowID = GetChildHead();
672 1 : LwpRowLayout * pRowLayout = dynamic_cast<LwpRowLayout *>(rRowID.obj().get());
673 2 : while (pRowLayout)
674 : {
675 0 : pRowLayout->SetFoundry(m_pFoundry);
676 0 : pRowLayout->RegisterStyle();
677 :
678 0 : rRowID = pRowLayout->GetNext();
679 0 : pRowLayout = dynamic_cast<LwpRowLayout *>(rRowID.obj().get());
680 : }
681 : }
682 : /**
683 : * @short register table style, if needed, including frame style
684 : * @param none
685 : */
686 1 : void LwpTableLayout::RegisterStyle()
687 : {
688 : // get super table layout
689 1 : LwpSuperTableLayout * pSuper = GetSuperTableLayout();
690 1 : if(!pSuper)
691 : {
692 : assert(false);
693 0 : return;
694 : }
695 :
696 : // get table
697 1 : LwpTable * pTable = GetTable();
698 1 : if (pTable == NULL)
699 : {
700 : assert(false);
701 0 : return;
702 : }
703 :
704 : // get row/column number of this table
705 1 : m_nRows = pTable->GetRow();
706 1 : m_nCols = pTable->GetColumn();
707 :
708 : // get default cell layout of current table
709 1 : LwpObjectID& rID= pTable->GetDefaultCellStyle();
710 1 : m_pDefaultCellLayout = dynamic_cast<LwpCellLayout *>(rID.obj().get());
711 :
712 : // register columns styles
713 1 : RegisterColumns();
714 :
715 : // register style of whole table
716 1 : XFTableStyle * pTableStyle = new XFTableStyle();
717 :
718 1 : sal_uInt8 nType = pSuper->GetRelativeType();
719 : // If the table is not "with paragraph above" placement, create an frame style
720 : // by supertable layout
721 1 : if ( LwpLayoutRelativityGuts::LAY_INLINE_NEWLINE == nType
722 1 : && !pSuper->GetContainerLayout()->IsCell())
723 : {
724 : //with para above
725 : // pSuper->ApplyBackColor(pTableStyle);
726 1 : pSuper->ApplyBackGround(pTableStyle);
727 1 : pSuper->ApplyWatermark(pTableStyle);
728 1 : pSuper->ApplyShadow(pTableStyle);
729 1 : pSuper->ApplyAlignment(pTableStyle);
730 1 : pTableStyle->SetWidth(pSuper->GetTableWidth());
731 : }
732 : else
733 : {
734 0 : pSuper->RegisterFrameStyle();
735 0 : pTableStyle->SetAlign(enumXFAlignCenter);
736 0 : pTableStyle->SetWidth(pSuper->GetTableWidth());
737 : }
738 1 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
739 1 : m_StyleName = pXFStyleManager->AddStyle(pTableStyle).m_pStyle->GetStyleName();
740 :
741 : //convert to OO table now and register row stle
742 : // traverse
743 1 : TraverseTable();
744 :
745 1 : SplitConflictCells();
746 :
747 : // Register rows layouts, it must be after SplitConflictCells
748 1 : RegisterRows();
749 :
750 : // Parse table
751 1 : ParseTable();
752 :
753 : //Comment:The old code doesn't check if the LwpFoundry pointer is NULL,
754 : // So the NULL pointer cause sodc frozee. Add code to check the
755 : // the pointer.
756 : //New Code
757 1 : if( GetFoundry() && GetTable() )
758 :
759 1 : PutCellVals( GetFoundry(),GetTable()->GetObjectID() );
760 : }
761 : /**
762 : * @short read table layout
763 : * @param none
764 : */
765 1 : void LwpTableLayout::ParseTable()
766 : {
767 : // get super table layout
768 1 : LwpSuperTableLayout * pSuper = GetSuperTableLayout();
769 1 : if(!pSuper)
770 : {
771 : assert(false);
772 1 : return;
773 : }
774 :
775 : // set name of object
776 1 : m_pXFTable = new XFTable;
777 1 : m_pXFTable->SetTableName(pSuper->GetName().str());
778 : // set table style
779 1 : m_pXFTable->SetStyleName(m_StyleName);
780 :
781 1 : sal_uInt16 nRow = m_nRows;
782 1 : sal_uInt8 nCol = (sal_uInt8)m_nCols;
783 :
784 : //process header rows
785 : LwpTableHeadingLayout* pTableHeading;
786 1 : pTableHeading = pSuper->GetTableHeadingLayout();
787 : sal_uInt16 nStartHeadRow;
788 : sal_uInt16 nEndHeadRow;
789 : sal_uInt16 nContentRow;
790 1 : if (pTableHeading)
791 : {
792 0 : pTableHeading->GetStartEndRow(nStartHeadRow,nEndHeadRow);
793 0 : if (nStartHeadRow != 0)
794 0 : ConvertTable(m_pXFTable,0,nRow,0,nCol);
795 : else
796 : {
797 0 : nContentRow = ConvertHeadingRow(m_pXFTable,nStartHeadRow,nEndHeadRow+1);
798 0 : ConvertTable(m_pXFTable,nContentRow,nRow,0,nCol);
799 : }
800 : }
801 : else
802 1 : ConvertTable(m_pXFTable,0,nRow,0,nCol);
803 : }
804 :
805 : /**
806 : * @short read table layout
807 : * @param none
808 : */
809 2 : void LwpTableLayout::Read()
810 : {
811 2 : LwpLayout::Read();
812 :
813 : // before layout hierarchy rework!
814 2 : if(LwpFileHeader::m_nFileRevision < 0x000b)
815 : {
816 : assert(false);
817 : }
818 2 : m_ColumnLayout.ReadIndexed(m_pObjStrm);
819 :
820 2 : m_pObjStrm->SkipExtra();
821 2 : }
822 :
823 : /**
824 : * @short Convert table
825 : * @param
826 : * @return pCont - container which will contain table
827 : */
828 0 : void LwpTableLayout::XFConvert(XFContentContainer* pCont)
829 : {
830 :
831 0 : pCont->Add(m_pXFTable);
832 0 : }
833 : /**
834 : * @short convert heading row
835 : * @param pXFTable - pointer of table
836 : * @param nStartRow - start heading row ID
837 : * @param nEndRow - end heading row ID
838 : */
839 0 : sal_uInt16 LwpTableLayout::ConvertHeadingRow(
840 : XFTable* pXFTable,sal_uInt16 nStartHeadRow,sal_uInt16 nEndHeadRow)
841 : {
842 : sal_uInt16 nContentRow;
843 0 : sal_uInt8 nCol = static_cast<sal_uInt8>(GetTable()->GetColumn());
844 0 : XFTable* pTmpTable = new XFTable;
845 : XFRow* pXFRow;
846 :
847 0 : ConvertTable(pTmpTable,nStartHeadRow,nEndHeadRow,0,nCol);
848 :
849 0 : sal_uInt16 nRowNum = pTmpTable->GetRowCount();
850 0 : sal_uInt8* CellMark = new sal_uInt8[nRowNum];
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 : const bool 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 = 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).m_pStyle->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 : bool LwpTableLayout::FindSplitColMark(XFTable* pXFTable, sal_uInt8* pCellMark,
982 : sal_uInt8& nMaxColSpan)
983 : {
984 0 : sal_uInt16 nRowNum = 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 : bool bFindFlag = 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 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 column
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 = 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 : try{
1109 :
1110 1 : LwpDLVListHeadHolder* pHolder = static_cast<LwpDLVListHeadHolder*>(pFoundry->GetNumberManager().GetTableRangeID().obj().get());
1111 :
1112 1 : LwpTableRange* pTableRange = static_cast<LwpTableRange*>(pHolder->GetHeadID().obj().get());
1113 :
1114 : //Look up the table
1115 2 : while (NULL!=pTableRange)
1116 : {
1117 0 : LwpObjectID aID = pTableRange->GetTableID();
1118 0 : if (aID == aTableID)
1119 : {
1120 0 : break;
1121 : }
1122 0 : pTableRange = pTableRange->GetNext();
1123 : }
1124 :
1125 1 : if (pTableRange)
1126 : {
1127 0 : LwpCellRange* pRange = static_cast<LwpCellRange*>(pTableRange->GetCellRangeID().obj().get());
1128 0 : LwpFolder* pFolder = static_cast<LwpFolder*>(pRange->GetFolderID().obj().get());
1129 0 : LwpObjectID aRowListID = pFolder->GetChildHeadID();
1130 0 : LwpRowList* pRowList = static_cast<LwpRowList*>(aRowListID.obj().get());
1131 :
1132 : //loop the rowlist
1133 0 : while( NULL!=pRowList)
1134 : {
1135 0 : sal_uInt16 nRowID = pRowList->GetRowID();
1136 : {
1137 0 : LwpCellList* pCellList = static_cast<LwpCellList*>(pRowList->GetChildHeadID().obj().get());
1138 : //loop the celllist
1139 0 : while( NULL!=pCellList)
1140 : {
1141 : {//put cell
1142 0 : sal_uInt16 nColID = pCellList->GetColumnID();
1143 :
1144 0 : XFCell* pCell = GetCellsMap(nRowID,static_cast<sal_uInt8>(nColID));
1145 0 : if (pCell)
1146 : {
1147 0 : pCellList->Convert(pCell, this);
1148 :
1149 : //process paragraph
1150 0 : PostProcessParagraph(pCell, nRowID, nColID);
1151 : }
1152 : else
1153 : {
1154 : //Hidden cell would not be in cellsmap
1155 : assert(false);
1156 : }
1157 : }
1158 0 : pCellList = static_cast<LwpCellList*>(pCellList->GetNextID().obj().get());
1159 : }
1160 : }
1161 0 : pRowList = static_cast<LwpRowList*>(pRowList->GetNextID().obj().get());
1162 : }
1163 : }
1164 :
1165 0 : }catch (...) {
1166 : assert(false);
1167 : }
1168 : }
1169 :
1170 : /**
1171 : * @short 1. set number right alignment to right if number 2. remove tab added before if number
1172 : * @param pCell - cell which to be process
1173 : * @param nRowID - row number in Word Pro file
1174 : * @param nColID - column number in Word Pro file
1175 : */
1176 0 : void LwpTableLayout::PostProcessParagraph(XFCell *pCell, sal_uInt16 nRowID, sal_uInt16 nColID)
1177 : {
1178 : // if number right, set alignment to right
1179 0 : LwpCellLayout * pCellLayout = GetCellByRowCol(nRowID, nColID);
1180 0 : if(pCellLayout)
1181 : {
1182 : rtl::Reference<XFContent> first(
1183 0 : pCell->FindFirstContent(enumXFContentPara));
1184 0 : XFParagraph * pXFPara = static_cast<XFParagraph*>(first.get());
1185 0 : if (!pXFPara)
1186 0 : return;
1187 0 : XFColor aNullColor = XFColor();
1188 :
1189 0 : if ( pXFPara)
1190 : {
1191 0 : OUString sNumfmt = pCellLayout->GetNumfmtName();
1192 0 : bool bColorMod = false;
1193 0 : XFNumberStyle* pNumStyle = NULL;
1194 0 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
1195 0 : if (!sNumfmt.isEmpty())
1196 : {
1197 0 : pNumStyle = static_cast<XFNumberStyle*>(pXFStyleManager->FindStyle( sNumfmt));
1198 0 : XFColor aColor = pNumStyle->GetColor();
1199 0 : if ( aColor != aNullColor )
1200 0 : bColorMod = true;//end
1201 : }
1202 :
1203 0 : XFParaStyle * pStyle = pXFStyleManager->FindParaStyle(pXFPara->GetStyleName());
1204 0 : if ((pStyle && pStyle->GetNumberRight()) || bColorMod)
1205 : {
1206 0 : XFParaStyle* pOverStyle = new XFParaStyle;
1207 :
1208 0 : if (pStyle)
1209 : {
1210 0 : *pOverStyle = *pStyle;
1211 :
1212 0 : if (pStyle->GetNumberRight())
1213 0 : pOverStyle->SetAlignType(enumXFAlignEnd);
1214 : }
1215 :
1216 0 : if (bColorMod)
1217 : {
1218 0 : rtl::Reference<XFFont> pFont = pOverStyle->GetFont();
1219 0 : XFColor aColor = pFont->GetColor();
1220 0 : if ( aColor == aNullColor )
1221 : {
1222 0 : rtl::Reference<XFFont> pNewFont = new XFFont;
1223 0 : aColor = pNumStyle->GetColor();
1224 0 : pNewFont->SetColor(aColor);
1225 0 : pOverStyle->SetFont(pNewFont);
1226 0 : }
1227 : }
1228 :
1229 0 : pOverStyle->SetStyleName("");
1230 0 : OUString StyleName = pXFStyleManager->AddStyle(pOverStyle).m_pStyle->GetStyleName();
1231 :
1232 0 : pXFPara->SetStyleName(StyleName);
1233 0 : }
1234 0 : }
1235 : }
1236 : }
1237 :
1238 : /**
1239 : * @short Parse all cols of table
1240 : * @param pXFTable - pointer to created XFTable
1241 : */
1242 1 : void LwpTableLayout::ConvertColumn(XFTable *pXFTable,sal_uInt8 nStartCol,sal_uInt8 nEndCol)
1243 : {
1244 1 : LwpTable * pTable = GetTable();
1245 1 : if (!pTable)
1246 : {
1247 : assert(false);
1248 1 : return;
1249 : }
1250 :
1251 5 : for (sal_uInt32 iLoop = 0; iLoop < static_cast<sal_uInt32>(nEndCol)-nStartCol; ++iLoop)
1252 : {
1253 : // add row to table
1254 4 : LwpObjectID& rColID = GetColumnLayoutHead();
1255 4 : LwpColumnLayout * pColumnLayout = dynamic_cast<LwpColumnLayout *>(rColID.obj().get());
1256 8 : while (pColumnLayout)
1257 : {
1258 0 : if (pColumnLayout->GetColumnID() == (iLoop+nStartCol))
1259 : {
1260 0 : pXFTable->SetColumnStyle(iLoop+1, pColumnLayout->GetStyleName());
1261 0 : break;
1262 : }
1263 0 : rColID = pColumnLayout->GetNext();
1264 0 : pColumnLayout = dynamic_cast<LwpColumnLayout *>(rColID.obj().get());
1265 : }
1266 4 : if (!pColumnLayout)
1267 : {
1268 4 : pXFTable->SetColumnStyle(iLoop+1, m_DefaultColumnStyleName);
1269 : }
1270 : }
1271 : }
1272 : /**
1273 : * @short split conflict merged cells
1274 : */
1275 1 : void LwpTableLayout::SplitConflictCells()
1276 : {
1277 1 : LwpTable * pTable = GetTable();
1278 1 : if (!pTable)
1279 1 : return;
1280 1 : sal_uInt16 nCol = pTable->GetColumn();
1281 1 : sal_uInt16 nRow = pTable->GetRow();
1282 :
1283 : sal_uInt16 nEffectRows;
1284 1 : std::map<sal_uInt16,LwpRowLayout*>::iterator iter1;
1285 1 : std::map<sal_uInt16,LwpRowLayout*>::iterator iter2;
1286 : LwpRowLayout* pRowLayout;
1287 : LwpRowLayout* pEffectRow;
1288 :
1289 7 : for (sal_uInt16 i=0; i<nRow; )
1290 : {
1291 5 : iter1 = m_RowsMap.find(i);
1292 5 : if (iter1 == m_RowsMap.end())//default rows
1293 : {
1294 0 : i++;
1295 0 : continue;
1296 : }
1297 5 : pRowLayout= iter1->second;
1298 5 : if (!pRowLayout->GetMergeCellFlag())
1299 : {
1300 5 : i++;
1301 5 : continue;
1302 : }
1303 : else
1304 : {
1305 0 : nEffectRows = i + pRowLayout->GetCurMaxSpannedRows(0,(sal_uInt8)nCol);
1306 :
1307 0 : for (sal_uInt16 j = i+1; j<nEffectRows; j++)
1308 : {
1309 0 : iter2 = m_RowsMap.find(j);
1310 0 : if (iter2 == m_RowsMap.end())
1311 0 : continue;
1312 0 : pEffectRow = iter2->second;
1313 0 : if (!pEffectRow->GetMergeCellFlag())
1314 0 : continue;
1315 : else
1316 0 : pEffectRow->SetCellSplit(nEffectRows);
1317 : }
1318 0 : i = nEffectRows;
1319 : }
1320 : }//end for
1321 :
1322 : }
1323 : /**
1324 : * @short add default row which are missing in the file
1325 : * @param pXFTable - pointer to new created table
1326 : * @param nStartCol - starting column
1327 : * @param nEndCol - end column
1328 : * @return pXFTable
1329 : */
1330 0 : void LwpTableLayout::ConvertDefaultRow(XFTable* pXFTable,sal_uInt8 nStartCol,
1331 : sal_uInt8 nEndCol,sal_uInt16 nRowID)
1332 : {
1333 : // current row doesn't exist in the file
1334 0 : XFRow * pRow = new XFRow();
1335 0 : pRow->SetStyleName(m_DefaultRowStyleName);
1336 :
1337 0 : for (sal_uInt16 j =0;j < nEndCol-nStartCol; j++)
1338 : {
1339 : // if table has default cell layout, use it to ConvertCell
1340 : // otherwise use blank cell
1341 0 : XFCell * pCell = NULL;
1342 0 : if (m_pDefaultCellLayout)
1343 : {
1344 : pCell = m_pDefaultCellLayout->ConvertCell(
1345 0 : GetTable()->GetObjectID(),nRowID,j+nStartCol);
1346 : }
1347 : else
1348 : {
1349 0 : pCell = new XFCell();
1350 : }
1351 0 : pRow->AddCell(pCell);
1352 : }
1353 :
1354 0 : pXFTable->AddRow(pRow);
1355 0 : }
1356 : /**
1357 : * @short set cell map info
1358 : * @param pXFCell - pointer to xfcell
1359 : * @param nRow - row id
1360 : * @param nCol - column id
1361 : */
1362 20 : void LwpTableLayout::SetCellsMap(sal_uInt16 nRow,sal_uInt8 nCol,XFCell* pXFCell)
1363 : {
1364 20 : std::pair<std::pair<sal_uInt16,sal_uInt8>,XFCell*> cell;
1365 20 : std::pair<sal_uInt16,sal_uInt8> pos;
1366 20 : pos.first = nRow;
1367 20 : pos.second = nCol;
1368 20 : cell.first = pos;
1369 20 : cell.second = pXFCell;
1370 20 : m_CellsMap.insert(cell);
1371 20 : }
1372 :
1373 : /**
1374 : * @short get cell map info
1375 : * @param nRow - row id
1376 : * @param nCol - column id
1377 : * @return pXFCell
1378 : */
1379 0 : XFCell* LwpTableLayout::GetCellsMap(sal_uInt16 nRow,sal_uInt8 nCol)
1380 : {
1381 0 : std::pair<sal_uInt16,sal_uInt8> pos;
1382 0 : pos.first = nRow;
1383 0 : pos.second = nCol;
1384 0 : std::map<std::pair<sal_uInt16,sal_uInt8>,XFCell*>::iterator iter;
1385 0 : iter = m_CellsMap.find(pos);
1386 0 : if (iter == m_CellsMap.end())
1387 0 : return NULL;
1388 0 : return iter->second;
1389 : }
1390 : /**
1391 : * @descr Get row layout by row id
1392 : * @param nRow - row id
1393 : */
1394 0 : LwpRowLayout* LwpTableLayout::GetRowLayout(sal_uInt16 nRow)
1395 : {
1396 0 : LwpObjectID& rRowID = GetChildHead();
1397 0 : LwpRowLayout * pRowLayout = dynamic_cast<LwpRowLayout *>(rRowID.obj().get());
1398 0 : while (pRowLayout)
1399 : {
1400 0 : if(pRowLayout->GetRowID() == nRow)
1401 0 : return pRowLayout;
1402 :
1403 0 : rRowID = pRowLayout->GetNext();
1404 0 : pRowLayout = dynamic_cast<LwpRowLayout *>(rRowID.obj().get());
1405 : }
1406 0 : return NULL;
1407 : }
1408 :
1409 : //add end by
1410 0 : LwpColumnLayout::LwpColumnLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
1411 : : LwpVirtualLayout(objHdr, pStrm)
1412 : , ccolid(0)
1413 0 : , cwidth(0)
1414 0 : {}
1415 :
1416 0 : LwpColumnLayout::~LwpColumnLayout()
1417 0 : {}
1418 0 : void LwpColumnLayout::Read()
1419 : {
1420 0 : LwpObjectStream* pStrm = m_pObjStrm;
1421 :
1422 0 : LwpVirtualLayout::Read();
1423 :
1424 : sal_uInt16 colid;
1425 :
1426 0 : colid = pStrm->QuickReaduInt16(); // forced to lushort
1427 0 : ccolid = (sal_uInt8)colid; // Phillip
1428 0 : cwidth = pStrm->QuickReadInt32();
1429 :
1430 0 : pStrm->SkipExtra();
1431 0 : }
1432 :
1433 0 : void LwpColumnLayout::RegisterStyle(double dCalculatedWidth)
1434 : {
1435 0 : XFColStyle * pColStyle = new XFColStyle();
1436 0 : pColStyle->SetWidth(static_cast<float>(dCalculatedWidth));
1437 0 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
1438 0 : m_StyleName = pXFStyleManager->AddStyle(pColStyle).m_pStyle->GetStyleName();
1439 0 : }
1440 :
1441 0 : LwpTableHeadingLayout::LwpTableHeadingLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
1442 : : LwpTableLayout(objHdr, pStrm)
1443 : , cStartRow(0)
1444 0 : , cEndRow(0)
1445 0 : {}
1446 :
1447 0 : LwpTableHeadingLayout::~LwpTableHeadingLayout()
1448 0 : {}
1449 : /**
1450 : * @short read table heading layout
1451 : * @param
1452 : * @return
1453 : */
1454 0 : void LwpTableHeadingLayout::Read()
1455 : {
1456 0 : LwpTableLayout::Read();
1457 :
1458 0 : cStartRow = m_pObjStrm->QuickReaduInt16();
1459 0 : cEndRow = m_pObjStrm->QuickReaduInt16();
1460 :
1461 0 : m_pObjStrm->SkipExtra();
1462 :
1463 0 : }
1464 : /**
1465 : * @short get start and end row number of table heading
1466 : * @param
1467 : * @return *pStartRow - starting row number
1468 : * @return *pEndRow - end row number
1469 : */
1470 0 : void LwpTableHeadingLayout::GetStartEndRow(sal_uInt16& nStartRow, sal_uInt16& nEndRow)
1471 : {
1472 0 : nStartRow = cStartRow;
1473 0 : nEndRow = cEndRow;
1474 0 : }
1475 : /**
1476 : * @short get first row heading layout of table heading
1477 : * @param
1478 : * @return LwpRowHeadingLayout * - pointer to first row heading layout of table heading
1479 : */
1480 0 : LwpRowHeadingLayout * LwpTableHeadingLayout::GetFirstRowHeadingLayout()
1481 : {
1482 0 : LwpObjectID& rID = GetChildHead();
1483 0 : if(!rID.IsNull())
1484 : {
1485 0 : LwpRowHeadingLayout * pHeadingRow = dynamic_cast<LwpRowHeadingLayout *>(rID.obj().get());
1486 0 : return pHeadingRow;
1487 : }
1488 0 : return NULL;
1489 : }
1490 :
1491 0 : LwpSuperParallelColumnLayout::LwpSuperParallelColumnLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm):LwpSuperTableLayout(objHdr, pStrm)
1492 : {
1493 0 : }
1494 0 : LwpSuperParallelColumnLayout::~LwpSuperParallelColumnLayout()
1495 0 : {}
1496 :
1497 0 : void LwpSuperParallelColumnLayout::Read()
1498 : {
1499 0 : LwpSuperTableLayout::Read();
1500 0 : m_pObjStrm->SkipExtra();
1501 :
1502 0 : }
1503 :
1504 0 : LwpSuperGlossaryLayout::LwpSuperGlossaryLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm):LwpSuperTableLayout(objHdr, pStrm)
1505 : {
1506 0 : }
1507 :
1508 0 : LwpSuperGlossaryLayout::~LwpSuperGlossaryLayout()
1509 : {
1510 0 : }
1511 :
1512 0 : void LwpSuperGlossaryLayout::Read()
1513 : {
1514 0 : LwpSuperTableLayout::Read();
1515 0 : m_pObjStrm->SkipExtra();
1516 0 : }
1517 :
1518 0 : LwpParallelColumnsLayout::LwpParallelColumnsLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm):LwpTableLayout(objHdr, pStrm)
1519 : {
1520 0 : }
1521 :
1522 0 : LwpParallelColumnsLayout::~LwpParallelColumnsLayout()
1523 : {
1524 0 : }
1525 :
1526 0 : void LwpParallelColumnsLayout::Read()
1527 : {
1528 0 : LwpTableLayout::Read();
1529 0 : m_pObjStrm->SkipExtra();
1530 0 : }
1531 :
1532 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|