LCOV - code coverage report
Current view: top level - lotuswordpro/source/filter - lwptablelayout.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 242 644 37.6 %
Date: 2014-11-03 Functions: 33 70 47.1 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10