LCOV - code coverage report
Current view: top level - lotuswordpro/source/filter - lwprowlayout.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 63 192 32.8 %
Date: 2014-11-03 Functions: 10 19 52.6 %
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 - row layouts
      59             :  */
      60             : /*************************************************************************
      61             :  * Change History
      62             :  April 2005         Created
      63             :  ************************************************************************/
      64             : #include "lwprowlayout.hxx"
      65             : #include "lwptable.hxx"
      66             : #include "lwpglobalmgr.hxx"
      67             : #include "xfilter/xfstylemanager.hxx"
      68             : #include "xfilter/xfrow.hxx"
      69             : #include "xfilter/xfrowstyle.hxx"
      70             : #include "xfilter/xftablestyle.hxx"
      71             : #include "xfilter/xftable.hxx"
      72             : #include "xfilter/xfcell.hxx"
      73             : #include "xfilter/xfcellstyle.hxx"
      74             : 
      75          12 : LwpRowLayout::LwpRowLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
      76             :     : LwpVirtualLayout(objHdr, pStrm)
      77             :     , crowid(0)
      78             :     , cheight(0)
      79             :     , cLeaderDotCount(0)
      80             :     , cLeaderDotY(0)
      81          12 :     , cRowFlags(0)
      82             : {
      83          12 :     m_ConnCellList.clear();
      84          12 : }
      85             : 
      86          22 : LwpRowLayout::~LwpRowLayout()
      87          22 : {}
      88             : 
      89             : /**
      90             :  * @short   register row style
      91             :  * @param
      92             :  * @param
      93             :  * @param
      94             :  * @return
      95             :  */
      96          10 : void LwpRowLayout::SetRowMap(void)
      97             : {
      98          10 :     LwpObjectID& rCellID= GetChildHead();
      99          10 :     LwpCellLayout * pCellLayout = dynamic_cast<LwpCellLayout *>(rCellID.obj().get());
     100             : 
     101          26 :     while(pCellLayout)
     102             :     {
     103           6 :         pCellLayout->SetCellMap();
     104             : 
     105           6 :         rCellID = pCellLayout->GetNext();
     106           6 :         pCellLayout = dynamic_cast<LwpCellLayout *>(rCellID.obj().get());
     107             :     }
     108          10 : }
     109             : /**
     110             :  * @short   register row style
     111             :  * @param
     112             :  * @param
     113             :  * @param
     114             :  * @return
     115             :  */
     116           0 : void LwpRowLayout::RegisterStyle()
     117             : {
     118             :     // register row style
     119           0 :     XFRowStyle *pRowStyle = new XFRowStyle();
     120             : 
     121           0 :     if (m_nDirection & 0x0030)
     122             :     {
     123           0 :         pRowStyle->SetMinRowHeight((float)LwpTools::ConvertFromUnitsToMetric(cheight));
     124             :     }
     125             :     else
     126             :     {
     127           0 :         pRowStyle->SetRowHeight((float)LwpTools::ConvertFromUnitsToMetric(cheight));
     128             :     }
     129           0 :     XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
     130           0 :     m_StyleName = pXFStyleManager->AddStyle(pRowStyle)->GetStyleName();
     131             : 
     132           0 :     LwpTableLayout* pTableLayout = GetParentTableLayout();
     133           0 :     if (pTableLayout)
     134             :     {
     135           0 :         pTableLayout->GetTable();
     136             :     }
     137             :     // register cells' style
     138           0 :     LwpObjectID& rCellID= GetChildHead();
     139           0 :     LwpCellLayout * pCellLayout = dynamic_cast<LwpCellLayout *>(rCellID.obj().get());
     140             : 
     141           0 :     while(pCellLayout)
     142             :     {
     143           0 :         pCellLayout->SetFoundry(m_pFoundry);
     144           0 :         pCellLayout->RegisterStyle();
     145           0 :         rCellID = pCellLayout->GetNext();
     146           0 :         pCellLayout = dynamic_cast<LwpCellLayout *>(rCellID.obj().get());
     147             :     }
     148             : 
     149           0 : }
     150             : /**
     151             :  * @short   register row style
     152             :  * @param
     153             :  * @param
     154             :  * @param
     155             :  * @return
     156             :  */
     157          12 : void LwpRowLayout::Read()
     158             : {
     159             :     #define MAXUNIT (0x7fffffffL)               // Highest positive UNIT value
     160          12 :     LwpObjectStream* pStrm = m_pObjStrm;
     161             : 
     162          12 :     LwpVirtualLayout::Read();
     163             : 
     164             :     //skip CLiteLayout data;
     165          12 :     LwpAtomHolder ContentClass;
     166          12 :     ContentClass.Read(pStrm);
     167          12 :     pStrm->SkipExtra();
     168             : 
     169             :     // Row layout content
     170          12 :     crowid = pStrm->QuickReaduInt16();
     171          12 :     cheight = pStrm->QuickReadInt32();
     172          12 :     cLeaderDotCount = (sal_uInt8)pStrm->QuickReaduInt16();  // was written as lushort.
     173          12 :     cLeaderDotY = MAXUNIT;  // Sentinel meaning "not calculated yet"
     174          12 :     cRowFlags = (sal_uInt8)pStrm->QuickReaduInt16();    // was written as lushort.
     175             : 
     176          12 :     pStrm->SkipExtra();
     177          12 : }
     178             : 
     179             : /**
     180             :  * @short   Parse rows with connect cell
     181             :  * @param  pXFTable - pointer to created XFTable
     182             :  */
     183           0 : void LwpRowLayout::ConvertRow(XFTable* pXFTable,sal_uInt8 nStartCol,sal_uInt8 nEndCol)
     184             : {
     185           0 :     LwpTableLayout* pTableLayout = GetParentTableLayout();
     186           0 :     LwpTable* pTable = pTableLayout->GetTable();
     187             : 
     188             :     //calculate the connected cell position
     189           0 :     sal_Int32 nMarkConnCell = FindMarkConnCell(nStartCol,nEndCol);
     190             : 
     191             :     //if there is no connected cell
     192           0 :     if (nMarkConnCell == -1)
     193             :     {
     194           0 :         ConvertCommonRow(pXFTable,nStartCol,nEndCol);
     195           0 :         return;
     196             :     }
     197             : 
     198             :     //register connect row style
     199           0 :     sal_uInt16 nRowMark = crowid + GetCurMaxSpannedRows(nStartCol,nEndCol);
     200           0 :     XFRow* pXFRow = new XFRow;
     201           0 :     RegisterCurRowStyle(pXFRow,nRowMark);
     202             : 
     203             :     //if there is connected cell
     204           0 :     for (sal_uInt8 i=nStartCol; i<nEndCol; )
     205             :     {
     206             :         XFCell* pXFCell;
     207             :         sal_uInt8 nColMark;
     208             : 
     209           0 :         if (nMarkConnCell == -1)
     210           0 :             nColMark = nEndCol;
     211             :         else
     212           0 :             nColMark = m_ConnCellList[nMarkConnCell]->GetColID();
     213             : 
     214           0 :         if (nColMark > i)//create subtable
     215             :         {
     216           0 :             pXFCell = new XFCell;
     217           0 :             pXFCell->SetColumnSpaned(nColMark-i);
     218           0 :             XFTable* pSubTable = new XFTable;
     219           0 :             pTableLayout->ConvertTable(pSubTable,crowid,nRowMark,i,nColMark);
     220           0 :             pXFCell->Add(pSubTable);
     221           0 :             i = nColMark;
     222             :         }
     223             :         else
     224             :         {
     225           0 :             sal_uInt8 nColID = m_ConnCellList[nMarkConnCell]->GetColID()
     226           0 :                     +m_ConnCellList[nMarkConnCell]->GetNumcols()-1;
     227           0 :             pXFCell = m_ConnCellList[nMarkConnCell]->ConvertCell(
     228           0 :                 pTable->GetObjectID(),
     229           0 :                 crowid+m_ConnCellList[nMarkConnCell]->GetNumrows()-1,
     230           0 :                 m_ConnCellList[nMarkConnCell]->GetColID());
     231             : 
     232             :             //set all cell in this merge cell to cellsmap
     233           0 :             for (sal_uInt16 nRowLoop = crowid;nRowLoop<nRowMark ;nRowLoop++)
     234           0 :                 for (sal_uInt8 nColLoop = i;nColLoop<nColID+1;nColLoop++)
     235           0 :                     pTableLayout->SetCellsMap(nRowLoop,nColLoop,pXFCell);
     236             : 
     237           0 :             i += m_ConnCellList[nMarkConnCell]->GetNumcols();
     238           0 :             nMarkConnCell = FindNextMarkConnCell(static_cast<sal_uInt16>(nMarkConnCell),nEndCol);
     239             :         }
     240             : 
     241           0 :         if (pXFCell)
     242           0 :             pXFRow->AddCell(pXFCell);
     243             :     }
     244           0 :     pXFTable->AddRow(pXFRow);
     245             : }
     246             : 
     247             : /**
     248             :  * @short   register row style in SODC table
     249             :  * @param   pXFRow - pointer of row
     250             :  * @param   nRowMark - spanned row number
     251             :  */
     252           0 : void LwpRowLayout::RegisterCurRowStyle(XFRow* pXFRow,sal_uInt16 nRowMark)
     253             : {
     254           0 :     XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
     255           0 :     XFRowStyle* pRowStyle = static_cast<XFRowStyle*>(pXFStyleManager->FindStyle(m_StyleName));
     256           0 :     if (!pRowStyle)
     257           0 :         return;
     258           0 :     double fHeight = pRowStyle->GetRowHeight();
     259             : 
     260           0 :     XFRowStyle* pNewStyle = new XFRowStyle;
     261           0 :     *pNewStyle = *pRowStyle;
     262           0 :     LwpTableLayout* pTableLayout = GetParentTableLayout();
     263           0 :     if (!pTableLayout)
     264             :     {
     265           0 :         delete pNewStyle;
     266           0 :         return;
     267             :     }
     268           0 :     std::map<sal_uInt16,LwpRowLayout*> RowsMap = pTableLayout->GetRowsMap();
     269             : 
     270           0 :     for (sal_uInt16 i=crowid+1; i<nRowMark;i++)
     271             :     {
     272           0 :         std::map<sal_uInt16,LwpRowLayout*>::iterator iter = RowsMap.find(i);
     273           0 :         if (iter == RowsMap.end())
     274             :         {
     275             :             pRowStyle = static_cast<XFRowStyle*>(
     276           0 :                 pXFStyleManager->FindStyle(pTableLayout->GetDefaultRowStyleName()));
     277           0 :             fHeight += pRowStyle->GetRowHeight();
     278             :         }
     279             :         else
     280             :         {
     281             :             pRowStyle = static_cast<XFRowStyle*>(
     282           0 :                 pXFStyleManager->FindStyle(iter->second->GetStyleName()));
     283           0 :             fHeight+=pRowStyle->GetRowHeight();
     284             :         }
     285             :     }
     286             : 
     287           0 :     if (m_nDirection & 0x0030)
     288             :     {
     289           0 :         pNewStyle->SetMinRowHeight((float)fHeight);
     290             :     }
     291             :     else
     292             :     {
     293           0 :         pNewStyle->SetRowHeight((float)fHeight);
     294             :     }
     295             : 
     296           0 :     pXFRow->SetStyleName(pXFStyleManager->AddStyle(pNewStyle)->GetStyleName());
     297             : }
     298             : 
     299             : /**
     300             :  * @short   find max merge cell in a given column range
     301             :  * @param   nStartCol - start column ID
     302             :  * @param   nEndCol - end column ID
     303             :  */
     304          10 : sal_Int32 LwpRowLayout::FindMarkConnCell(sal_uInt8 nStartCol,sal_uInt8 nEndCol)
     305             : {
     306          10 :     if (m_ConnCellList.empty())
     307          10 :         return -1;
     308             : 
     309           0 :     sal_uInt16 nSpannRows = 1;
     310           0 :     sal_Int32 nMarkConnCell = -1;
     311             : 
     312           0 :     for (sal_uInt16 i=0;i<m_ConnCellList.size();i++)
     313             :     {
     314           0 :         if (m_ConnCellList[i]->GetColID()>=nEndCol)
     315           0 :             break;
     316           0 :         if (m_ConnCellList[i]->GetColID()>=nStartCol)
     317             :         {
     318           0 :             if (m_ConnCellList[i]->GetNumrows()>nSpannRows)
     319             :             {
     320           0 :                 nSpannRows = m_ConnCellList[i]->GetNumrows();
     321           0 :                 nMarkConnCell = i;
     322             :             }
     323             :         }
     324             :     }
     325           0 :     return nMarkConnCell;
     326             : }
     327             : 
     328             : /**
     329             :  * @short   find next merge cell with the same spanned row number with current merge cell
     330             :  * @param   nStartCol - start column ID
     331             :  * @param   nEndCol - end column ID
     332             :  */
     333           0 : sal_Int32 LwpRowLayout::FindNextMarkConnCell(sal_uInt16 nMarkConnCell,sal_uInt8 nEndCol)
     334             : {
     335           0 :     sal_uInt16 nMaxRows = m_ConnCellList[nMarkConnCell]->GetNumrows();
     336             : 
     337           0 :     for (sal_uInt16 i=nMarkConnCell+1;i<m_ConnCellList.size();i++)
     338             :     {
     339           0 :         if (m_ConnCellList[i]->GetColID()>=nEndCol)
     340           0 :             break;
     341           0 :         if (m_ConnCellList[i]->GetNumrows() == nMaxRows)
     342             :         {
     343           0 :             return i;
     344             :         }
     345             :     }
     346           0 :     return -1;
     347             : }
     348             : /**
     349             :  * @short   get max spanned row numbers in a given column range
     350             :  * @param   nStartCol - start column ID
     351             :  * @param   nEndCol - end column ID
     352             :  */
     353          10 : sal_uInt16 LwpRowLayout::GetCurMaxSpannedRows(sal_uInt8 nStartCol,sal_uInt8 nEndCol)
     354             : {
     355          10 :     sal_Int32 nMarkConnCell = FindMarkConnCell(nStartCol,nEndCol);
     356          10 :     if (nMarkConnCell == -1)
     357          10 :         return 1;
     358             :     else
     359           0 :         return m_ConnCellList[nMarkConnCell]->GetNumrows();
     360             : }
     361             : /**
     362             :  * @short   convert row with rowlayout,but no merge cells
     363             :  * @param   pXFTable - pointer of table
     364             :  * @param   nStartCol - start column ID
     365             :  * @param   nEndCol - end column ID
     366             :  */
     367          10 : void LwpRowLayout::ConvertCommonRow(XFTable* pXFTable,sal_uInt8 nStartCol,sal_uInt8 nEndCol)
     368             : {
     369          10 :     XFRow* pRow = new XFRow;
     370          10 :     pRow->SetStyleName(m_StyleName);
     371             : 
     372          10 :     XFCell * pCell = NULL;
     373          10 :     LwpTableLayout* pTableLayout = GetParentTableLayout();
     374          10 :     LwpTable* pTable = pTableLayout->GetTable();
     375             :     sal_uInt8 nCellStartCol,nCellEndCol;
     376             : 
     377          50 :     for (sal_uInt8 i = nStartCol; i < nEndCol ; i++)
     378             :     {
     379             :         // add row to table
     380          40 :         LwpObjectID& rCellID= GetChildHead();
     381          40 :         LwpCellLayout * pCellLayout = dynamic_cast<LwpCellLayout *>(rCellID.obj().get());
     382          40 :         nCellStartCol = i;//mark the begin position of cell
     383          40 :         nCellEndCol = i;//mark the end position of cell
     384          80 :         while(pCellLayout)
     385             :         {
     386           0 :             if (pCellLayout->GetColID() == i)
     387             :             {
     388           0 :                 if (pCellLayout->GetLayoutType() == LWP_CONNECTED_CELL_LAYOUT)
     389             :                 {
     390           0 :                     LwpConnectedCellLayout* pConnCell = static_cast<LwpConnectedCellLayout*>(pCellLayout);
     391           0 :                     nCellEndCol = i+pConnCell->GetNumcols()-1;
     392           0 :                     i = nCellEndCol;
     393             :                 }
     394           0 :                 pCell = pCellLayout->ConvertCell(pTable->GetObjectID(),crowid,i);
     395           0 :                 break;
     396             :             }
     397           0 :             rCellID = pCellLayout->GetNext();
     398           0 :             pCellLayout = dynamic_cast<LwpCellLayout *>(rCellID.obj().get());
     399             :         }
     400          40 :         if (!pCellLayout)
     401             :         {
     402             :             // if table has default cell layout, use it to ConvertCell
     403             :             // otherwise use blank cell
     404          40 :             LwpCellLayout * pDefaultCell = pTableLayout->GetDefaultCellLayout();
     405          40 :             if (pDefaultCell)
     406             :             {
     407             :                 pCell = pDefaultCell->ConvertCell(
     408          40 :                     pTable->GetObjectID(),crowid, i);
     409             :             }
     410             :             else
     411             :             {
     412           0 :                 pCell = new XFCell;
     413             :             }
     414             :         }
     415          40 :         pRow->AddCell(pCell);
     416             : 
     417          80 :         for (sal_uInt8 j=nCellStartCol;j<=nCellEndCol;j++)
     418          40 :             pTableLayout->SetCellsMap(crowid,j,pCell);//set to cellsmap
     419             :     }
     420             : 
     421          10 :     pXFTable->AddRow(pRow);
     422          10 : }
     423             : /**
     424             :  * @short   collect merge cell info when register row styles
     425             :  */
     426          10 : void LwpRowLayout::CollectMergeInfo()
     427             : {
     428          10 :     LwpObjectID& rCellID= GetChildHead();
     429          10 :     LwpCellLayout * pCellLayout = dynamic_cast<LwpCellLayout *>(rCellID.obj().get());
     430             : 
     431          20 :     while(pCellLayout)
     432             :     {
     433           0 :         if (pCellLayout->GetLayoutType() == LWP_CONNECTED_CELL_LAYOUT)
     434             :         {
     435           0 :             LwpConnectedCellLayout* pConnCell = static_cast<LwpConnectedCellLayout*>(pCellLayout);
     436           0 :             m_ConnCellList.push_back(pConnCell);
     437             :         }
     438           0 :         rCellID = pCellLayout->GetNext();
     439           0 :         pCellLayout = dynamic_cast<LwpCellLayout *>(rCellID.obj().get());
     440             :     }
     441          10 : }
     442             : /**
     443             :  * @short   split merge cells in this row
     444             :  * @param   nEffectRows - max spanned number of prevoius row
     445             :  */
     446           0 : void LwpRowLayout::SetCellSplit(sal_uInt16 nEffectRows)
     447             : {
     448             :     LwpConnectedCellLayout* pConnCell;
     449           0 :     for (sal_uInt32 i=0; i<m_ConnCellList.size(); i++)
     450             :     {
     451           0 :         pConnCell = m_ConnCellList[i];
     452           0 :         sal_uInt16 nRowSpan = pConnCell->GetRowID()+pConnCell->GetNumrows();
     453           0 :         if ( nRowSpan > nEffectRows )
     454             :         {
     455           0 :             pConnCell->SetNumrows(nEffectRows - pConnCell->GetRowID());
     456             :         }
     457             :     }
     458           0 : }
     459             : /**
     460             :  * @short   check if the row has merge cell
     461             :  */
     462          10 : bool LwpRowLayout::GetMergeCellFlag()
     463             : {
     464          10 :     if (m_ConnCellList.empty())
     465          10 :         return false;
     466             :     else
     467           0 :         return true;
     468             : }
     469             : 
     470           0 : LwpRowHeadingLayout::LwpRowHeadingLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
     471           0 :     : LwpRowLayout(objHdr, pStrm)
     472           0 : {}
     473             : 
     474           0 : LwpRowHeadingLayout::~LwpRowHeadingLayout()
     475           0 : {}
     476           0 : void LwpRowHeadingLayout::Read()
     477             : {
     478           0 :     LwpRowLayout::Read();
     479             : 
     480           0 :     cRowLayout.ReadIndexed(m_pObjStrm);
     481           0 :     m_pObjStrm->SkipExtra();
     482           0 : }
     483             : 
     484             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10