LCOV - code coverage report
Current view: top level - libreoffice/lotuswordpro/source/filter/xfilter - xfcell.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 34 107 31.8 %
Date: 2012-12-27 Functions: 5 10 50.0 %
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             :  * Table cell.
      59             :  ************************************************************************/
      60             : #include    "xfcell.hxx"
      61             : #include    "xfparagraph.hxx"
      62             : #include    "xftable.hxx"
      63             : #include    "xfrow.hxx"
      64             : 
      65          20 : XFCell::XFCell()
      66             : {
      67          20 :     m_pSubTable = NULL;
      68          20 :     m_pOwnerRow = NULL;
      69          20 :     m_nCol = 0;
      70          20 :     m_nColSpaned = 1;
      71          20 :     m_nRepeated = 0;
      72          20 :     m_eValueType = enumXFValueTypeNone;
      73          20 :     m_bProtect = sal_False;
      74          20 : }
      75             : 
      76           0 : XFCell::XFCell(const XFCell& other) : XFContentContainer(other)
      77             : {
      78           0 :     if( other.m_pSubTable )
      79           0 :         m_pSubTable = new XFTable(*other.m_pSubTable);
      80             :     else
      81           0 :         m_pSubTable = NULL;
      82           0 :     m_pOwnerRow = NULL;
      83           0 :     m_nCol = other.m_nCol;
      84           0 :     m_nColSpaned = other.m_nColSpaned;
      85           0 :     m_nRepeated = other.m_nRepeated;
      86           0 :     m_eValueType = other.m_eValueType;
      87           0 :     m_bProtect = other.m_bProtect;
      88           0 :     m_strValue = other.m_strValue;
      89           0 :     m_strDisplay = other.m_strDisplay;
      90           0 :     m_strFormula = other.m_strFormula;
      91           0 : }
      92             : 
      93           0 : XFCell& XFCell::operator=(const XFCell& other)
      94             : {
      95           0 :     if( this == &other )
      96           0 :         return *this;
      97             : 
      98           0 :     if( m_pSubTable )
      99           0 :         delete m_pSubTable;
     100             : 
     101           0 :     if( other.m_pSubTable )
     102           0 :         m_pSubTable = new XFTable(*other.m_pSubTable);
     103             :     else
     104           0 :         m_pSubTable = NULL;
     105           0 :     m_pOwnerRow = NULL;
     106           0 :     m_nCol = other.m_nCol;
     107           0 :     m_nColSpaned = other.m_nColSpaned;
     108           0 :     m_nRepeated = other.m_nRepeated;
     109           0 :     m_eValueType = other.m_eValueType;
     110           0 :     m_bProtect = other.m_bProtect;
     111           0 :     m_strValue = other.m_strValue;
     112           0 :     m_strDisplay = other.m_strDisplay;
     113           0 :     m_strFormula = other.m_strFormula;
     114             : 
     115           0 :     return *this;
     116             : }
     117             : 
     118          60 : XFCell::~XFCell()
     119             : {
     120          20 :     if( m_pSubTable )
     121           0 :         delete m_pSubTable;
     122          40 : }
     123             : 
     124           3 : void    XFCell::Add(IXFContent *pContent)
     125             : {
     126           3 :     if( m_eValueType != enumXFValueTypeNone )
     127             :     {
     128           0 :         Reset();
     129           0 :         m_eValueType = enumXFValueTypeNone;
     130             :     }
     131           3 :     if( m_pSubTable )
     132             :     {
     133             :         assert(false);
     134           0 :         return;
     135             :     }
     136           3 :     if( pContent->GetContentType() == enumXFContentTable )
     137             :     {
     138           0 :         XFTable *pTable = static_cast<XFTable*>(pContent);
     139           0 :         if( !pTable )
     140           0 :             return;
     141             :         //the sub table will fill all the cell, there can't be other contents.
     142           0 :         pTable->SetOwnerCell(this);
     143           0 :         m_pSubTable = pTable;
     144             :     }
     145           3 :     else if( pContent->GetContentType() == enumXFContentText )
     146             :     {
     147           0 :         XFParagraph *pPara = new XFParagraph();
     148           0 :         pPara->Add(pContent);
     149           0 :         XFContentContainer::Add(pPara);
     150             :     }
     151           3 :     else if( pContent->GetContentType() == enumXFContentFrame )
     152             :     {
     153           0 :         XFParagraph *pPara = new XFParagraph();
     154           0 :         pPara->Add(pContent);
     155           0 :         XFContentContainer::Add(pPara);
     156             :     }
     157             :     else
     158             :     {
     159           3 :         XFContentContainer::Add(pContent);
     160             :     }
     161             : }
     162             : 
     163             : 
     164           0 : void    XFCell::SetValue(double value)
     165             : {
     166           0 :     SetValue(DoubleToOUString(value,18));
     167           0 : }
     168             : 
     169           0 : void    XFCell::SetValue(rtl::OUString value)
     170             : {
     171           0 :     m_eValueType = enumXFValueTypeFloat;
     172           0 :     m_strValue = value;
     173           0 : }
     174             : 
     175           0 : rtl::OUString   XFCell::GetCellName()
     176             : {
     177           0 :     XFRow *pRow = m_pOwnerRow;
     178             : 
     179           0 :     if( !pRow )
     180           0 :         return A2OUSTR("");
     181             : 
     182           0 :     XFTable *pTable = pRow->GetOwnerTable();
     183             : 
     184           0 :     if( !pTable )
     185           0 :         return A2OUSTR("");
     186             : 
     187           0 :     rtl::OUString name;
     188           0 :     if( pTable->IsSubTable() )
     189             :     {
     190           0 :         name = pTable->GetTableName() + A2OUSTR(".") + Int32ToOUString(m_nCol) + A2OUSTR(".") + Int32ToOUString(pRow->GetRow());
     191             :     }
     192             :     else
     193             :     {
     194           0 :         name = GetTableColName(m_nCol) + Int32ToOUString(pRow->GetRow());
     195             :     }
     196           0 :     return name;
     197             : }
     198             : 
     199          20 : void    XFCell::ToXml(IXFStream *pStrm)
     200             : {
     201          20 :     IXFAttrList *pAttrList = pStrm->GetAttrList();
     202             : 
     203          20 :     pAttrList->Clear();
     204          20 :     if( !GetStyleName().isEmpty() )
     205          20 :         pAttrList->AddAttribute( A2OUSTR("table:style-name"), GetStyleName() );
     206          20 :     if( m_nColSpaned>1 )
     207           0 :         pAttrList->AddAttribute( A2OUSTR("table:number-columns-spanned"), Int32ToOUString(m_nColSpaned) );
     208          20 :     if( m_nRepeated )
     209           0 :         pAttrList->AddAttribute( A2OUSTR("table:number-columns-repeated"), Int32ToOUString(m_nRepeated) );
     210          20 :     if( m_eValueType != enumXFValueTypeNone )
     211             :     {
     212           0 :         pAttrList->AddAttribute( A2OUSTR("table:value-type"), GetValueType(m_eValueType) );
     213           0 :         pAttrList->AddAttribute( A2OUSTR("table:value"), m_strValue );
     214             :     }
     215          20 :     if( !m_strFormula.isEmpty() )
     216           0 :         pAttrList->AddAttribute( A2OUSTR("table:formula"), m_strFormula );
     217             : 
     218          20 :     if( m_bProtect )
     219           0 :         pAttrList->AddAttribute( A2OUSTR("table:protected"), A2OUSTR("true") );
     220             : 
     221             :     //for test only.
     222             : //  pAttrList->AddAttribute( A2OUSTR("table:cell-name"), GetCellName() );
     223             : 
     224          20 :     pStrm->StartElement( A2OUSTR("table:table-cell") );
     225             : 
     226          20 :     if( m_pSubTable )
     227           0 :         m_pSubTable->ToXml(pStrm);
     228             :     else
     229             :     {
     230          20 :         XFContentContainer::ToXml(pStrm);
     231             :     }
     232             : 
     233          20 :     pStrm->EndElement( A2OUSTR("table:table-cell") );
     234          20 : }
     235             : 
     236             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10