LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/lotuswordpro/source/filter - lwpcelllayout.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 193 341 56.6 %
Date: 2013-07-09 Functions: 22 43 51.2 %
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 - cell layouts
      59             :  */
      60             : 
      61             : #include <tools/string.hxx>
      62             : 
      63             : #include "lwpcelllayout.hxx"
      64             : #include "lwpfoundry.hxx"
      65             : #include "lwpobjfactory.hxx"
      66             : #include "lwptblcell.hxx"
      67             : #include "lwptblformula.hxx"
      68             : #include "lwpholder.hxx"
      69             : #include "lwpnumericfmt.hxx"
      70             : #include "lwptable.hxx"
      71             : #include "lwpglobalmgr.hxx"
      72             : 
      73             : #include "xfilter/xfstylemanager.hxx"
      74             : #include "xfilter/xfcell.hxx"
      75             : #include "xfilter/xfcellstyle.hxx"
      76             : #include "xfilter/xfcolstyle.hxx"
      77             : 
      78          23 : LwpCellLayout::LwpCellLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
      79             :     : LwpMiddleLayout(objHdr, pStrm)
      80          23 :     , cType(LDT_NONE)
      81          23 : {}
      82             : 
      83          44 : LwpCellLayout::~LwpCellLayout()
      84          44 : {}
      85             : 
      86             : /**
      87             :  * @short   Get table layout pointer, if default cell layout, return NULL
      88             :  * @param LwpTableLayout *
      89             :  * @return
      90             :  */
      91           7 : LwpTableLayout * LwpCellLayout::GetTableLayout()
      92             : {
      93           7 :     LwpRowLayout * pRow = dynamic_cast<LwpRowLayout *>(GetParent()->obj());
      94           7 :     if(!pRow)
      95             :     {
      96           0 :         return NULL;
      97             :     }
      98           7 :     LwpTableLayout * pTableLayout = pRow->GetParentTableLayout();
      99           7 :     return pTableLayout;
     100             : }
     101             : /**
     102             :  * @short   Get table pointer, if default cell layout, return NULL
     103             :  * @param LwpTable *
     104             :  * @return
     105             :  */
     106           1 : LwpTable * LwpCellLayout::GetTable()
     107             : {
     108           1 :     LwpTableLayout * pTableLayout = GetTableLayout();
     109           1 :     if(!pTableLayout)
     110             :     {
     111           0 :         return NULL;
     112             :     }
     113           1 :     LwpTable *pTable = pTableLayout->GetTable();
     114           1 :     return pTable;
     115             : }
     116             : /**
     117             :  * @short   Set current cell layout to cell layout map
     118             :  * @param
     119             :  * @return
     120             :  */
     121           3 : void LwpCellLayout::SetCellMap()
     122             : {
     123             :     // this function is called from LwpTableLayout, so it can't be NULL
     124           3 :     GetTableLayout()->SetWordProCellMap(crowid, ccolid, this);
     125           3 : }
     126             : /**
     127             :  * @short  Get actual width of this cell layout
     128             :  * @param
     129             :  * @return width (cm)
     130             :  */
     131           0 : double LwpCellLayout::GetActualWidth()
     132             : {
     133             :     //Get table layout
     134           0 :     LwpTableLayout * pTableLayout = GetTableLayout();
     135             : 
     136           0 :     if (pTableLayout == NULL)
     137             :     {
     138           0 :         return GetGeometryWidth();
     139             :     }
     140             : 
     141           0 :     OUString strColStyle = pTableLayout->GetColumnWidth(ccolid);
     142             : 
     143           0 :     XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
     144           0 :     XFColStyle *pStyle = static_cast<XFColStyle *>(pXFStyleManager->FindStyle(strColStyle));
     145           0 :     if(pStyle)
     146             :     {
     147           0 :         return pStyle->GetWidth();
     148             :     }
     149             : 
     150           0 :     return GetGeometryWidth();
     151             : }
     152             : 
     153             : /**
     154             :  * @short   Apply padding to cell style
     155             :  * @param pCellStyle - pointer of XFCellStyle
     156             :  * @return
     157             :  */
     158          75 : void LwpCellLayout::ApplyPadding(XFCellStyle *pCellStyle)
     159             : {
     160          75 :     double fLeft = GetMarginsValue(MARGIN_LEFT);
     161          75 :     double fRight = GetMarginsValue(MARGIN_RIGHT);
     162          75 :     double fTop = GetMarginsValue(MARGIN_TOP);
     163          75 :     double fBottom = GetMarginsValue(MARGIN_BOTTOM);
     164          75 :     pCellStyle->SetPadding((float)fLeft,(float)fRight,(float)fTop,(float)fBottom);
     165          75 : }
     166             : /**
     167             :  * @short   Apply border to cell style according to cell position, default cell layout won't use this function
     168             :  * @param
     169             :  * @return pCellStyle - pointer of XFCellStyle
     170             :  */
     171           3 : void LwpCellLayout::ApplyBorders(XFCellStyle *pCellStyle)
     172             : {
     173             :     // judge cell border type
     174           3 :     LwpCellBorderType eType = GetCellBorderType(crowid, ccolid, GetTableLayout());
     175             : 
     176             :     // get left cell and judge if neighbour border is different
     177           3 :     XFBorders * pBorders = GetXFBorders();
     178           3 :     if(!pBorders)
     179             :     {
     180           3 :         return;
     181             :     }
     182             : 
     183           3 :     switch (eType)
     184             :     {
     185             :     case enumNoBottomBorder:
     186           1 :         pBorders->SetWidth(enumXFBorderBottom, 0);
     187           1 :         break;
     188             :     case enumNoLeftBorder:
     189           1 :         pBorders->SetWidth(enumXFBorderLeft, 0);
     190           1 :         break;
     191             :     case enumNoLeftNoBottomBorder:
     192           1 :         pBorders->SetWidth(enumXFBorderBottom, 0);
     193           1 :         pBorders->SetWidth(enumXFBorderLeft, 0);
     194           1 :         break;
     195             :     case enumWholeBorder:
     196           0 :         break;
     197             :     default:
     198             :         assert(sal_False);
     199             :     }
     200           3 :     pCellStyle->SetBorders(pBorders);
     201             : }
     202             : /**
     203             :  * @short   Apply watermark to cell style
     204             :  * @param pCellStyle - pointer of XFCellStyle
     205             :  * @return
     206             :  */
     207          75 : void LwpCellLayout::ApplyWatermark(XFCellStyle *pCellStyle)
     208             : {
     209          75 :     XFBGImage* pBGImage = GetXFBGImage();
     210          75 :     if(pBGImage)
     211             :     {
     212           0 :         pCellStyle->SetBackImage(pBGImage);
     213             :     }
     214          75 : }
     215             : 
     216             : /**
     217             :  * @short   Apply pattern fill to cell style
     218             :  * @param pCellStyle - pointer of XFCellStyle
     219             :  * @return
     220             :  */
     221           0 : void LwpCellLayout::ApplyPatternFill(XFCellStyle* pCellStyle)
     222             : {
     223           0 :     XFBGImage* pXFBGImage = this->GetFillPattern();
     224           0 :     if (pXFBGImage)
     225             :     {
     226           0 :         pCellStyle->SetBackImage(pXFBGImage);
     227             :     }
     228           0 : }
     229             : 
     230             : /**
     231             :  * @short   Apply background to cell style
     232             :  * @param pCellStyle - pointer of XFCellStyle
     233             :  * @return
     234             :  */
     235           3 : void LwpCellLayout::ApplyBackGround(XFCellStyle* pCellStyle)
     236             : {
     237           3 :     if (this->IsPatternFill())
     238             :     {
     239           0 :         ApplyPatternFill(pCellStyle);
     240             :     }
     241             :     else
     242             :     {
     243           3 :         ApplyBackColor(pCellStyle);
     244             :     }
     245           3 : }
     246             : /**
     247             :  * @short   Apply back color to cell style
     248             :  * @param pCellStyle - pointer of XFCellStyle
     249             :  * @return
     250             :  */
     251          75 : void LwpCellLayout::ApplyBackColor(XFCellStyle *pCellStyle)
     252             : {
     253          75 :     LwpColor* pColor = GetBackColor();
     254          75 :     if(pColor && pColor->IsValidColor())
     255             :     {
     256           0 :         XFColor aXFColor(pColor->To24Color());
     257           0 :         pCellStyle->SetBackColor(aXFColor);
     258             :     }
     259          75 : }
     260             : /**
     261             :  * @short   register style of cell layout
     262             :  * @param pCellStyle The style of the cell, which would be applied to the cell.
     263             :  * @return
     264             :  */
     265          75 : void LwpCellLayout::ApplyFmtStyle(XFCellStyle *pCellStyle)
     266             : {
     267          75 :     LwpLayoutNumerics* pLayoutNumerics = dynamic_cast<LwpLayoutNumerics*>(cLayNumerics.obj());
     268          75 :     if (!pLayoutNumerics)
     269             :     {
     270             :         // if current layout doesn't have format, go to based on layout
     271          51 :         LwpCellLayout* pCellLayout = dynamic_cast<LwpCellLayout*>(m_BasedOnStyle.obj());
     272          51 :         if (pCellLayout)
     273             :         {
     274           3 :             pLayoutNumerics = dynamic_cast<LwpLayoutNumerics*>(pCellLayout->GetNumericsObject()->obj());
     275             :         }
     276             :     }
     277             : 
     278             :     // apply format style
     279          75 :     if (pLayoutNumerics)
     280             :     {
     281          27 :         XFStyle* pStyle = pLayoutNumerics->Convert();
     282          27 :         if (pStyle)
     283             :         {
     284          27 :             XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
     285          27 :             m_NumfmtName = pXFStyleManager->AddStyle(pStyle)->GetStyleName();
     286          27 :             pCellStyle->SetDataStyle(m_NumfmtName);
     287             :         }
     288             :     }
     289             : 
     290          75 :     return;
     291             : }
     292             : /**
     293             :  * @short   get style name according to cell position, only table default cells use this function
     294             :  * @param   nRow - default cell position row number
     295             :  * @param   nCol - default cell position col number
     296             :  * @return  OUString - registered cell style name
     297             :  */
     298          17 : OUString LwpCellLayout::GetCellStyleName(sal_uInt16 nRow, sal_uInt16 nCol, LwpTableLayout * pTableLayout)
     299             : {
     300             :     // judge cell border type
     301          17 :     LwpCellBorderType eType = GetCellBorderType(nRow, nCol, pTableLayout);
     302          17 :     return m_CellStyleNames[eType];
     303             : }
     304             : /**
     305             : *   Make the XFCell
     306             : *   @date   03/26/2005
     307             : *   @param  aTableID - ID of the table which this cell belongs to
     308             : *   @param  bIsTopRow - whether current cell is top row
     309             : *   @param  bIsRightCol - whether current cell is the rightest column
     310             : *   @return XFCell*
     311             : */
     312          20 : XFCell* LwpCellLayout::ConvertCell(LwpObjectID aTableID, sal_uInt16 nRow, sal_uInt16 nCol)
     313             : {
     314             :     // if cell layout is aTableID's default cell layout
     315             :     // it can't have any content, bypass these code
     316          20 :     LwpTable * pTable = dynamic_cast<LwpTable *>(aTableID.obj());
     317          20 :     if (!pTable)
     318             :     {
     319             :         assert(sal_False);
     320           0 :         return NULL;
     321             :     }
     322          20 :     XFCell * pXFCell = new XFCell();
     323          20 :     OUString aStyleName = m_StyleName;
     324             : 
     325             :     // if cell layout is aTableID's default cell layout
     326             :     // we should judt its style by current positon
     327          20 :     if (*pTable->GetDefaultCellStyle() == *GetObjectID())
     328             :     {
     329          17 :         aStyleName = GetCellStyleName(nRow, nCol, pTable->GetTableLayout());
     330             :     }
     331             : 
     332             :     // content of cell
     333          20 :     LwpStory* pStory = dynamic_cast<LwpStory*>(m_Content.obj());
     334          20 :     if (pStory)
     335             :     {
     336           3 :         pStory->XFConvert(pXFCell);
     337             :     }
     338             : 
     339          20 :     ApplyProtect(pXFCell, aTableID);
     340          20 :     pXFCell->SetStyleName(aStyleName);
     341          20 :     return pXFCell;
     342             : }
     343             : 
     344           1 : LwpPara* LwpCellLayout::GetLastParaOfPreviousStory()
     345             : {
     346           1 :     LwpObjectID* pPreStoryID = this->GetPreviousCellStory();
     347           1 :     if (pPreStoryID && !(pPreStoryID->IsNull()))
     348             :     {
     349           0 :         LwpStory* pPreStory = dynamic_cast<LwpStory*>(pPreStoryID->obj(VO_STORY));
     350           0 :         return dynamic_cast<LwpPara*>(pPreStory->GetLastPara()->obj(VO_PARA));
     351             :     }
     352             :     else
     353             :     {
     354           1 :         return NULL;
     355             :     }
     356             : }
     357             : 
     358             : /**
     359             :  * @short    Get previous cell which used for bullet inside cell
     360             :  * @param
     361             :  * @return   LwpObjectID * - object ID of cell content story
     362             :  */
     363           1 : LwpObjectID * LwpCellLayout::GetPreviousCellStory()
     364             : {
     365           1 :     LwpTable *pTable = GetTable();
     366           1 :     if (!pTable)
     367             :     {
     368             :         assert(sal_False);
     369           0 :         return NULL;
     370             :     }
     371           1 :     sal_uInt16 nRow = crowid;
     372           1 :     sal_uInt16 nCol = ccolid;
     373             : 
     374             :     // if table is reset paragraph in columns, get cell on the top side of current cell
     375           1 :     if (pTable->IsNumberDown())
     376             :     {
     377           0 :         if (nRow == 0)
     378             :         {
     379           0 :             return NULL;
     380             :         }
     381           0 :         nRow -=1;
     382             :     }
     383             :     else
     384             :     {
     385             :         // if not, get cell on the left side of current cell
     386           1 :         if (nCol == 0)
     387             :         {
     388           1 :             if (nRow == 0)
     389             :             {
     390           1 :                 return NULL;
     391             :             }
     392             :             else
     393             :             {
     394           0 :                 nRow--;
     395           0 :                 nCol = pTable->GetColumn() - 1;
     396             :             }
     397             :         }
     398             :         else
     399             :         {
     400           0 :             nCol -=1;
     401             :         }
     402             :     }
     403             : 
     404             :     // get the object id pointer of previous cell story
     405           0 :     LwpTableLayout * pTableLayout = GetTableLayout();
     406           0 :     if (!pTableLayout)
     407             :     {
     408             :         assert(sal_False);
     409           0 :         return NULL;
     410             :     }
     411           0 :     return pTableLayout->SearchCellStoryMap(nRow, nCol);
     412             : }
     413             : 
     414             : /**
     415             :  * @short   judge border type by cell neighbour
     416             :  * @param nRow
     417             :  * @param nCol
     418             :  * @param pTableLayout
     419             :  * @return   LwpCellBorderType
     420             :  */
     421          20 : LwpCellBorderType LwpCellLayout::GetCellBorderType(sal_uInt16 nRow, sal_uInt16 nCol, LwpTableLayout * pTableLayout)
     422             : {
     423          20 :     if (!pTableLayout)
     424             :     {
     425             :         assert(sal_False);
     426           0 :         return enumWholeBorder;
     427             :     }
     428             : 
     429             :     // get left cell and judge if neighbour border is different
     430          20 :     XFBorders * pBorders = GetXFBorders();
     431          20 :     if(!pBorders)
     432             :     {
     433           0 :         return enumWholeBorder;
     434             :     }
     435          20 :     XFBorder *pLeftBorder = pBorders->GetLeft();
     436          20 :     XFBorder *pBottomBorder = pBorders->GetBottom();
     437          20 :     sal_Bool bNoLeftBorder = sal_False;
     438          20 :     sal_Bool bNoBottomBorder = sal_False;
     439             : 
     440          20 :     LwpCellLayout * pLeftNeighbour = GetCellByRowCol(nRow, GetLeftColID(nCol), pTableLayout);
     441          20 :     if (pLeftNeighbour)
     442             :     {
     443          15 :         XFBorders * pNeighbourBorders = pLeftNeighbour->GetXFBorders();
     444          15 :         if (pNeighbourBorders)
     445             :         {
     446          15 :             XFBorder * pRightBorder = pNeighbourBorders->GetRight();
     447          15 :             if (*pLeftBorder == *pRightBorder)
     448             :             {
     449             :                 // for these 2 types cell, left border should be ignored for sake of avoiding duplication border
     450             :                 // but if left border is different with right border of left cell
     451             :                 // we should not ignored it
     452          15 :                 bNoLeftBorder = sal_True;
     453             :             }
     454          15 :             delete pNeighbourBorders;
     455             :         }
     456             : 
     457             :     }
     458             : 
     459          20 :     LwpCellLayout * pBelowNeighbour = GetCellByRowCol(GetBelowRowID(nRow), nCol, pTableLayout);
     460          20 :     if (pBelowNeighbour) //&& (eType == enumRightNotLastCellBorder || eType ==  enumLeftNotLastCellBorder) )
     461             :     {
     462          16 :         XFBorders * pBelowBorders = pBelowNeighbour->GetXFBorders();
     463          16 :         if (pBelowBorders)
     464             :         {
     465          16 :             XFBorder * pTopBorder = pBelowBorders->GetTop();
     466          16 :             if (*pTopBorder == *pBottomBorder)
     467             :             {
     468             :                 // for these 2 types cell, bottom border should be ignored for sake of avoiding duplication border
     469             :                 // but if bottom border is different with right border of left cell
     470             :                 // we should not ignored it
     471          16 :                 bNoBottomBorder = sal_True;
     472             :             }
     473          16 :             delete pBelowBorders;
     474             :         }
     475             :     }
     476             : 
     477          20 :     delete pBorders;
     478             : 
     479          20 :     if (bNoBottomBorder)
     480             :     {
     481          16 :         if (bNoLeftBorder)
     482             :         {
     483          12 :             return enumNoLeftNoBottomBorder;
     484             :         }
     485           4 :         return enumNoBottomBorder;
     486             :     }
     487           4 :     if (bNoLeftBorder)
     488             :     {
     489           3 :         return enumNoLeftBorder;
     490             :     }
     491           1 :     return enumWholeBorder;
     492             : }
     493             : 
     494             : /**
     495             :  * @short   Get neighbour cell by specifying ROW+COL
     496             :  * @param   nRow
     497             :  * @param   nCol
     498             :  * @return   LwpCellLayout *
     499             :  */
     500          40 : LwpCellLayout * LwpCellLayout::GetCellByRowCol(sal_uInt16 nRow, sal_uInt16 nCol, LwpTableLayout * pTableLayout)
     501             : {
     502          40 :     return pTableLayout->GetCellByRowCol(nRow, nCol);
     503             : }
     504             : /**
     505             :  * @short   Register table's default cell layout
     506             :  * @param
     507             :  * @return
     508             :  */
     509          18 : void LwpCellLayout::RegisterDefaultCell()
     510             : {
     511          18 :     XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
     512          90 :     for (sal_uInt16 eLoop = enumWholeBorder; eLoop < enumCellBorderTopLimit; eLoop++)
     513             :     {
     514             :         // register cell style
     515          72 :         XFCellStyle *pCellStyle = new XFCellStyle();
     516             : 
     517          72 :         ApplyPadding(pCellStyle);
     518          72 :         ApplyBackColor(pCellStyle);
     519          72 :         ApplyWatermark(pCellStyle);
     520          72 :         ApplyFmtStyle(pCellStyle);
     521          72 :         pCellStyle->SetAlignType(enumXFAlignNone, GetVerticalAlignmentType());
     522             : 
     523          72 :         XFBorders * pBorders = GetXFBorders();
     524          72 :         if (pBorders)
     525             :         {
     526          16 :             switch(eLoop)
     527             :             {
     528             :             case enumNoBottomBorder:
     529             :                 // _
     530             :                 //| |
     531             :                 //
     532             :                 // remove bottom line
     533           4 :                 pBorders->SetWidth(enumXFBorderBottom, 0);
     534           4 :                 break;
     535             :             case enumNoLeftNoBottomBorder:
     536             :                 // _
     537             :                 //  |
     538             :                 //
     539             :                 // remove left and bottom
     540           4 :                 pBorders->SetWidth(enumXFBorderLeft, 0);
     541           4 :                 pBorders->SetWidth(enumXFBorderBottom, 0);
     542           4 :                 break;
     543             :             case enumWholeBorder:
     544             :                 //--
     545             :                 //||
     546             :                 //--
     547             :                 // nothing to remove
     548           4 :                 break;
     549             :             case enumNoLeftBorder:
     550             :                 //
     551             :                 //| |
     552             :                 //--
     553             :                 // remove left line
     554           4 :                 pBorders->SetWidth(enumXFBorderLeft, 0);
     555           4 :                 break;
     556             :             default:
     557             :                 assert(sal_False);
     558             :             }
     559          16 :             pCellStyle->SetBorders(pBorders);
     560             :         }
     561          72 :         m_CellStyleNames[eLoop] = pXFStyleManager->AddStyle(pCellStyle)->GetStyleName();
     562             :     }
     563          18 : }
     564             : /**
     565             :  * @short    Register 4 types of cell style and register content styles
     566             :  * @param
     567             :  * @param
     568             :  * @param
     569             :  * @return
     570             :  */
     571          21 : void LwpCellLayout::RegisterStyle()
     572             : {
     573          21 :     LwpVirtualLayout * pParent = dynamic_cast<LwpVirtualLayout *>(GetParent()->obj());
     574          21 :     if (!pParent || pParent->GetLayoutType() != LWP_ROW_LAYOUT)
     575             :     {
     576             :         // default cell layout, we must register 4 styles for it
     577          18 :         RegisterDefaultCell();
     578          39 :         return;
     579             :     }
     580             : 
     581             :     // register cell style
     582           3 :     XFCellStyle *pCellStyle = new XFCellStyle();
     583             : 
     584           3 :     ApplyPadding(pCellStyle);
     585             : //  ApplyBackColor(pCellStyle);
     586           3 :     ApplyBackGround(pCellStyle);
     587           3 :     ApplyWatermark(pCellStyle);
     588           3 :     ApplyFmtStyle(pCellStyle);
     589           3 :     ApplyBorders(pCellStyle);
     590             : 
     591           3 :     pCellStyle->SetAlignType(enumXFAlignNone, GetVerticalAlignmentType());
     592             : 
     593           3 :     XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
     594           3 :     m_StyleName = pXFStyleManager->AddStyle(pCellStyle)->GetStyleName();
     595             : 
     596             :     // content object register styles
     597           3 :     LwpObject * pObj = m_Content.obj();
     598           3 :     if (pObj)
     599             :     {
     600           3 :         pObj->SetFoundry(m_pFoundry);
     601           3 :         pObj->RegisterStyle();
     602             :     }
     603             : 
     604             :     //register child layout style
     605           3 :     RegisterChildStyle();
     606             : }
     607             : /**
     608             :  * @short   Read cell layout
     609             :  * @param
     610             :  * @return
     611             :  */
     612          23 : void LwpCellLayout::Read()
     613             : {
     614          23 :     LwpObjectStream* pStrm = m_pObjStrm;
     615             : 
     616          23 :     LwpMiddleLayout::Read();
     617             : 
     618             :     // before the layout hierarchy rework
     619          23 :     if (LwpFileHeader::m_nFileRevision  < 0x000b)
     620             :     {
     621             :         assert(sal_False);
     622             :     }
     623             :     else
     624             :     {
     625          23 :         crowid = pStrm->QuickReaduInt16();
     626          23 :         ccolid = (sal_uInt8) pStrm->QuickReaduInt16();  // written as a lushort
     627             : 
     628             :         sal_uInt16 type;
     629             : 
     630          23 :         type = pStrm->QuickReaduInt16();
     631          23 :         pStrm->SkipExtra();
     632          23 :         cType = (LeaderDotType)type;
     633             : 
     634          23 :         cLayNumerics.ReadIndexed(pStrm);
     635          23 :         cLayDiagonalLine.ReadIndexed(pStrm);
     636             : 
     637          23 :         pStrm->SkipExtra();
     638             :     }
     639          23 : }
     640             : 
     641             : /**
     642             : *   Apply protect attribute to cell of table
     643             : *   @date   04/04/2005
     644             : *   @param  aTableID - ID of the table which the cell belongs to
     645             : *   @param
     646             : *   @return XFCell*
     647             : */
     648          20 : void LwpCellLayout::ApplyProtect(XFCell * pCell, LwpObjectID aTableID)
     649             : {
     650          20 :     sal_Bool bProtected = sal_False;
     651             :     // judge current cell
     652          20 :     if (IsProtected())
     653             :     {
     654           0 :         bProtected = sal_True;
     655             :     }
     656             :     else
     657             :     {
     658             :         // judge base on
     659          20 :         LwpCellLayout * pBase = dynamic_cast<LwpCellLayout *>(m_BasedOnStyle.obj());
     660          20 :         if (pBase && pBase->IsProtected())
     661             :         {
     662           0 :             bProtected = sal_True;
     663             :         }
     664             :         else
     665             :         {
     666             :             // judge whole table
     667          20 :             LwpTable * pTable = dynamic_cast<LwpTable *>(aTableID.obj());
     668          20 :             LwpTableLayout * pTableLayout = static_cast<LwpTableLayout *>(pTable->GetTableLayout());
     669          20 :             LwpSuperTableLayout * pSuper = pTableLayout->GetSuperTableLayout();
     670          20 :             if (pSuper && pSuper->IsProtected())
     671             :             {
     672           0 :                 bProtected = sal_True;
     673             :             }
     674             :         }
     675             :     }
     676             : 
     677          20 :     pCell->SetProtect(bProtected);
     678          20 : }
     679             : 
     680             : 
     681           0 : LwpConnectedCellLayout::LwpConnectedCellLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
     682           0 :     : LwpCellLayout(objHdr, pStrm)
     683           0 : {}
     684             : 
     685           0 : LwpConnectedCellLayout::~LwpConnectedCellLayout()
     686           0 : {}
     687             : /**
     688             :  * @short   Set current connected cell layout to cell layout map
     689             :  * @param pCellLayoutMap - cell layout map reference
     690             :  * @return
     691             :  */
     692           0 : void LwpConnectedCellLayout::SetCellMap()
     693             : {
     694             :     // this function is called from LwpTableLayout, so it can't be NULL
     695           0 :     LwpTableLayout * pTableLayout = GetTableLayout();
     696           0 :     sal_uInt16 nRowSpan = m_nRealrowspan;
     697             : 
     698           0 :     for (sal_uInt16 iLoop = 0; iLoop < nRowSpan; iLoop ++)
     699             :     {
     700           0 :         for (sal_uInt16 jLoop = 0; jLoop < cnumcols; jLoop ++)
     701           0 :             pTableLayout->SetWordProCellMap(iLoop + crowid, jLoop + ccolid, this);
     702             :     }
     703           0 : }
     704             : 
     705             : /**
     706             :  * @short   judge border type by cell neighbour
     707             :  * @param nRow
     708             :  * @param nCol
     709             :  * @param pTableLayout
     710             :  * @return   LwpCellBorderType
     711             :  */
     712           0 : LwpCellBorderType LwpConnectedCellLayout::GetCellBorderType(sal_uInt16 nRow, sal_uInt16 nCol, LwpTableLayout * pTableLayout)
     713             : {
     714           0 :     if (!pTableLayout)
     715             :     {
     716             :         assert(sal_False);
     717           0 :         return enumWholeBorder;
     718             :     }
     719             : 
     720           0 :     sal_uInt16 nRowSpan = m_nRealrowspan;
     721             : 
     722             :     // get left cell and judge if neighbour border is different
     723           0 :     XFBorders * pBorders = GetXFBorders();
     724           0 :     if(!pBorders)
     725             :     {
     726           0 :         return enumWholeBorder;
     727             :     }
     728           0 :     XFBorder *pLeftBorder = pBorders->GetLeft();
     729           0 :     XFBorder *pBottomBorder = pBorders->GetBottom();
     730           0 :     sal_Bool bNoLeftBorder = sal_True;
     731           0 :     sal_Bool bNoBottomBorder = sal_True;
     732             : 
     733           0 :     if (nCol == 0)
     734             :     {
     735           0 :         bNoLeftBorder = sal_False;
     736             :     }
     737             :     else
     738             :     {
     739           0 :         for (sal_uInt16 iLoop=0; iLoop < nRowSpan; iLoop++)
     740             :         {
     741           0 :             LwpCellLayout * pLeftNeighbour = GetCellByRowCol(nRow+iLoop, GetLeftColID(nCol), pTableLayout);
     742           0 :             if (pLeftNeighbour)
     743             :             {
     744           0 :                 boost::scoped_ptr<XFBorders> pNeighbourBorders(pLeftNeighbour->GetXFBorders());
     745           0 :                 if (pNeighbourBorders)
     746             :                 {
     747           0 :                     XFBorder * pRightBorder = pNeighbourBorders->GetRight();
     748           0 :                     if (*pLeftBorder != *pRightBorder)
     749             :                     {
     750             :                         // if left border is different with right border of left cell
     751             :                         // we should not ignored it
     752           0 :                         bNoLeftBorder = sal_False;
     753           0 :                         break;
     754             :                     }
     755           0 :                 }
     756             :             }
     757             :         }
     758             :     }
     759             : 
     760           0 :     if ( (nRow + nRowSpan) == pTableLayout->GetTable()->GetRow() )
     761             :     {
     762           0 :         bNoBottomBorder = sal_False;
     763             :     }
     764             :     else
     765             :     {
     766           0 :         for (sal_uInt16 iLoop = 0; iLoop < cnumcols; iLoop ++)
     767             :         {
     768           0 :             LwpCellLayout * pBelowNeighbour = GetCellByRowCol(nRow + nRowSpan, nCol+iLoop, pTableLayout);
     769           0 :             if (pBelowNeighbour)
     770             :             {
     771           0 :                 boost::scoped_ptr<XFBorders> pBelowBorders(pBelowNeighbour->GetXFBorders());
     772           0 :                 if (pBelowBorders)
     773             :                 {
     774           0 :                     XFBorder * pTopBorder = pBelowBorders->GetTop();
     775           0 :                     if (*pTopBorder != *pBottomBorder)
     776             :                     {
     777             :                         // if bottom border is different with right border of left cell
     778             :                         // we should not ignored it
     779           0 :                         bNoBottomBorder = sal_False;
     780           0 :                         break;
     781             :                     }
     782           0 :                 }
     783             :             }
     784             :         }
     785             :     }
     786           0 :     delete pBorders;
     787             : 
     788           0 :     if (bNoBottomBorder)
     789             :     {
     790           0 :         if (bNoLeftBorder)
     791             :         {
     792           0 :             return enumNoLeftNoBottomBorder;
     793             :         }
     794           0 :         return enumNoBottomBorder;
     795             :     }
     796           0 :     if (bNoLeftBorder)
     797             :     {
     798           0 :         return enumNoLeftBorder;
     799             :     }
     800           0 :     return enumWholeBorder;
     801             : }
     802             : /**
     803             :  * @short   Read connected cell layout
     804             :  * @param
     805             :  * @return
     806             :  */
     807           0 : void LwpConnectedCellLayout::Read()
     808             : {
     809           0 :     LwpCellLayout::Read();
     810             :     sal_uInt16 numcols;
     811             : 
     812           0 :     cnumrows = m_pObjStrm->QuickReaduInt16();
     813           0 :     numcols = m_pObjStrm->QuickReaduInt16();        // written as a lushort
     814           0 :     cnumcols = (sal_uInt8)numcols;
     815             : 
     816           0 :     m_nRealrowspan = cnumrows;
     817           0 :     m_nRealcolspan = cnumcols;
     818             : 
     819           0 :     m_pObjStrm->SkipExtra();
     820           0 : }
     821           0 : XFCell* LwpConnectedCellLayout::ConvertCell(LwpObjectID aTableID, sal_uInt16 nRow, sal_uInt16 nCol)
     822             : {
     823           0 :     XFCell * pXFCell = LwpCellLayout::ConvertCell(aTableID, nRow, nCol);
     824           0 :     pXFCell->SetColumnSpaned(cnumcols);
     825             : //  if(!m_bSplitFlag)
     826             : //  {
     827             : //  }
     828           0 :     return pXFCell;
     829             : }
     830             : /**
     831             :  * @short   parse connected cell layout
     832             :  * @param pOutputStream - output stream
     833             :  * @return
     834             :  */
     835           0 :  void  LwpConnectedCellLayout::Parse(IXFStream* /*pOutputStream*/)
     836             : {
     837           0 : }
     838             : 
     839           0 : LwpHiddenCellLayout::LwpHiddenCellLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
     840           0 :     : LwpCellLayout(objHdr, pStrm)
     841           0 : {}
     842             : 
     843           0 : LwpHiddenCellLayout::~LwpHiddenCellLayout()
     844           0 : {}
     845             : /**
     846             :  * @short   Set current hidden cell layout to cell layout map
     847             :  * @param
     848             :  * @return
     849             :  */
     850           0 : void LwpHiddenCellLayout::SetCellMap()
     851             : {
     852           0 :     return;
     853             : }
     854             : /**
     855             :  * @short   Read hidden cell layout
     856             :  * @param
     857             :  * @return
     858             :  */
     859           0 : void LwpHiddenCellLayout::Read()
     860             : {
     861           0 :     LwpCellLayout::Read();
     862             : 
     863           0 :     cconnectedlayout.ReadIndexed(m_pObjStrm);
     864           0 :     m_pObjStrm->SkipExtra();
     865             : 
     866           0 : }
     867             : /**
     868             :  * @short   Convert hidden cell layout
     869             :  * @param aTableID - Object ID of table
     870             :  * @return XFCell * - pointer to converted cell
     871             :  */
     872             : 
     873           0 : XFCell* LwpHiddenCellLayout::ConvertCell(LwpObjectID aTableID, sal_uInt16 nRow, sal_uInt16 nCol)
     874             : {
     875           0 :     if (!cconnectedlayout.obj())
     876           0 :         return NULL;
     877           0 :     LwpConnectedCellLayout* pConnCell = dynamic_cast<LwpConnectedCellLayout* >(cconnectedlayout.obj());
     878             : 
     879           0 :     if (nRow < (pConnCell->GetNumrows()+pConnCell->GetRowID()))
     880           0 :         return NULL;
     881             :     // if the hidden cell should be displayed for limit of SODC
     882             :     // use the default cell layout
     883           0 :     XFCell* pXFCell = NULL;
     884           0 :     LwpTable *pTable = dynamic_cast<LwpTable *>(aTableID.obj());
     885           0 :     if (pTable)
     886             :     {
     887           0 :         LwpCellLayout *pDefault = dynamic_cast<LwpCellLayout *>(pTable->GetDefaultCellStyle()->obj());
     888           0 :         if (pDefault)
     889             :         {
     890           0 :             pXFCell = pDefault->ConvertCell(aTableID, nRow, nCol);
     891             :         }
     892             :         else
     893             :         {
     894           0 :             pXFCell = pConnCell->ConvertCell(aTableID, nRow, nCol);
     895             :         }
     896           0 :         pXFCell->SetColumnSpaned(pConnCell->GetNumcols());
     897             :     }
     898             :     else
     899             :     {
     900             :         assert(sal_False);
     901             :     }
     902           0 :     return pXFCell;
     903             : }
     904             : /**
     905             :  * @short   parse hidden cell layout
     906             :  * @param pOutputStream - output stream
     907             :  * @return
     908             :  */
     909           0 :  void  LwpHiddenCellLayout::Parse(IXFStream* /*pOutputStream*/)
     910             : {
     911           0 : }
     912             : 
     913             : 
     914           0 : LwpParallelColumnsBlock::LwpParallelColumnsBlock(LwpObjectHeader &objHdr, LwpSvStream* pStrm):LwpCellLayout(objHdr, pStrm)
     915           0 : {}
     916             : 
     917           0 : LwpParallelColumnsBlock::~LwpParallelColumnsBlock()
     918           0 : {}
     919             : 
     920           0 : void LwpParallelColumnsBlock::Read()
     921             : {
     922           0 :     LwpCellLayout::Read();
     923           0 :     m_pObjStrm->SkipExtra();
     924           0 : }
     925             : 
     926             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10