LCOV - code coverage report
Current view: top level - lotuswordpro/source/filter/xfilter - xftable.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 17 104 16.3 %
Date: 2015-06-13 12:38:46 Functions: 3 12 25.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 object.
      59             :  ************************************************************************/
      60             : #include "xftable.hxx"
      61             : #include "xfrow.hxx"
      62             : #include "xfcolstyle.hxx"
      63             : #include "xfstylemanager.hxx"
      64             : #include <cassert>
      65             : 
      66           1 : XFTable::XFTable()
      67             : {
      68           1 :     m_strName = XFGlobal::GenTableName();
      69           1 :     m_bSubTable = false;
      70           1 :     m_pOwnerCell = NULL;
      71           1 : }
      72             : 
      73           0 : XFTable::~XFTable()
      74             : {
      75           0 :     std::map<sal_uInt16, XFRow*>::iterator it;
      76           0 :     for( it=m_aRows.begin(); it!=m_aRows.end(); ++it )
      77             :     {
      78           0 :         XFRow *pRow = (*it).second;
      79           0 :         delete pRow;
      80             :     }
      81           0 :     m_aRows.clear();
      82           0 :     m_aColumns.clear();
      83           0 : }
      84             : 
      85           4 : void    XFTable::SetColumnStyle(sal_Int32 col, const OUString& style)
      86             : {
      87           4 :     m_aColumns[col] = style;
      88           4 : }
      89             : 
      90           5 : void XFTable::AddRow(XFRow *pRow)
      91             : {
      92             :     assert(pRow);
      93             : 
      94           5 :     int row = pRow->GetRow();
      95             : 
      96           5 :     if( row<1 )
      97           5 :         pRow->SetRow(m_aRows.size()+1);
      98             : 
      99           5 :     row = pRow->GetRow();
     100           5 :     if( m_aRows.find(row) != m_aRows.end() )
     101           0 :         delete m_aRows[row];
     102             : 
     103           5 :     pRow->SetOwnerTable(this);
     104           5 :     m_aRows[row] = pRow;
     105           5 : }
     106             : 
     107           0 : void    XFTable::AddHeaderRow(XFRow *pRow)
     108             : {
     109           0 :     if( !pRow )
     110           0 :         return;
     111           0 :     m_aHeaderRows.Add(pRow);
     112             : }
     113             : 
     114           0 : OUString XFTable::GetTableName()
     115             : {
     116           0 :     if( m_bSubTable )
     117             :     {
     118           0 :         return m_pOwnerCell->GetCellName();
     119             :     }
     120             :     else
     121           0 :         return m_strName;
     122             : }
     123             : 
     124           0 : sal_uInt16 XFTable::GetRowCount()
     125             : {
     126           0 :     sal_uInt16 rowMax = 0;
     127           0 :     std::map<sal_uInt16, XFRow*>::iterator it;
     128           0 :     for( it=m_aRows.begin(); it!=m_aRows.end(); ++it )
     129             :     {
     130           0 :         if (it->first > rowMax)
     131           0 :             rowMax = it->first;
     132             :     }
     133             : 
     134           0 :     return rowMax;
     135             : }
     136             : 
     137           0 : XFRow*  XFTable::GetRow(sal_Int32 row)
     138             : {
     139           0 :     return m_aRows[row];
     140             : }
     141             : 
     142           0 : sal_Int32   XFTable::GetColumnCount()
     143             : {
     144           0 :     int     colMax = -1;
     145           0 :     std::map<sal_Int32,OUString>::iterator it;
     146           0 :     for( it=m_aColumns.begin(); it!=m_aColumns.end(); ++it )
     147             :     {
     148           0 :         if( it->first>colMax )
     149           0 :             colMax = it->first;
     150             :     }
     151           0 :     return colMax;
     152             : }
     153             : 
     154           0 : enumXFContent XFTable::GetContentType()
     155             : {
     156           0 :     return enumXFContentTable;
     157             : }
     158             : 
     159           0 : void    XFTable::ToXml(IXFStream *pStrm)
     160             : {
     161           0 :     IXFAttrList *pAttrList = pStrm->GetAttrList();
     162             : 
     163           0 :     pAttrList->Clear();
     164             :     //sub table shouldn't use table name.
     165           0 :     if( !m_bSubTable )
     166           0 :         pAttrList->AddAttribute( "table:name", m_strName);
     167             : 
     168           0 :     if( !GetStyleName().isEmpty() )
     169           0 :         pAttrList->AddAttribute( "table:style-name", GetStyleName() );
     170             : 
     171           0 :     if( m_bSubTable )
     172           0 :         pStrm->StartElement( "table:sub-table" );
     173             :     else
     174           0 :         pStrm->StartElement( "table:table" );
     175             : 
     176             :     //output columns:
     177             :     {
     178           0 :         int lastCol = 0;
     179           0 :         std::map<sal_Int32,OUString>::iterator it;
     180           0 :         for( it=m_aColumns.begin(); it!=m_aColumns.end(); ++it )
     181             :         {
     182           0 :             sal_Int32   col = (*it).first;
     183           0 :             OUString   style = m_aColumns[col];
     184             : 
     185             :             //default col repeated:
     186           0 :             if( col >lastCol+1 )
     187             :             {
     188           0 :                 if( col > lastCol + 2 )
     189             :                 {
     190           0 :                     if( !m_strDefColStyle.isEmpty() )
     191             :                     {
     192           0 :                         pAttrList->AddAttribute( "table:style-name", m_strDefColStyle );
     193             :                     }
     194           0 :                     pAttrList->AddAttribute( "table:number-columns-repeated", OUString::number(col-lastCol-1) );
     195             :                 }
     196           0 :                 pStrm->StartElement( "table:table-column" );
     197           0 :                 pStrm->EndElement( "table:table-column" );
     198             :             }
     199             : 
     200           0 :             if( !style.isEmpty() )
     201             :             {
     202           0 :                 pAttrList->AddAttribute( "table:style-name", style );
     203             :             }
     204           0 :             pStrm->StartElement( "table:table-column" );
     205           0 :             pStrm->EndElement( "table:table-column" );
     206           0 :             lastCol = col;
     207           0 :         }
     208             :     }
     209             : 
     210           0 :     if( m_aHeaderRows.GetCount()>0 )
     211             :     {
     212           0 :         pStrm->StartElement( "table:table-header-rows" );
     213           0 :         m_aHeaderRows.ToXml(pStrm);
     214           0 :         pStrm->EndElement( "table:table-header-rows" );
     215             :     }
     216             :     //output rows:
     217             :     {
     218           0 :         int     lastRow = 0;
     219             : 
     220           0 :         std::map<sal_uInt16, XFRow* >::iterator it = m_aRows.begin();
     221           0 :         for( ; it!=m_aRows.end(); ++it )
     222             :         {
     223           0 :             int row = (*it).first;
     224           0 :             XFRow *pRow = (*it).second;
     225             : 
     226             :             //null row repeated:
     227           0 :             if( row>lastRow+1 )
     228             :             {
     229           0 :                 XFRow *pNullRow = new XFRow();
     230           0 :                 pNullRow->SetStyleName(m_strDefRowStyle);
     231           0 :                 if( row>lastRow+2)
     232           0 :                     pNullRow->SetRepeated(row-lastRow-1);
     233           0 :                 XFCell *pCell = new XFCell();
     234           0 :                 pCell->SetStyleName(m_strDefCellStyle);
     235           0 :                 pNullRow->AddCell(pCell);
     236           0 :                 pNullRow->ToXml(pStrm);
     237             :             }
     238           0 :             pRow->ToXml(pStrm);
     239           0 :             lastRow = row;
     240             :         }
     241             :     }
     242             : 
     243           0 :     if( m_bSubTable )
     244           0 :         pStrm->EndElement( "table:sub-table" );
     245             :     else
     246           0 :         pStrm->EndElement( "table:table" );
     247           0 : }
     248             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11