LCOV - code coverage report
Current view: top level - libreoffice/oox/source/drawingml/table - tableproperties.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 79 1.3 %
Date: 2012-12-27 Functions: 2 9 22.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             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "oox/drawingml/table/tableproperties.hxx"
      21             : #include "oox/drawingml/drawingmltypes.hxx"
      22             : #include <com/sun/star/table/XTable.hpp>
      23             : #include <com/sun/star/container/XNameContainer.hpp>
      24             : #include <com/sun/star/beans/XMultiPropertySet.hpp>
      25             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      26             : #include <com/sun/star/table/XMergeableCellRange.hpp>
      27             : #include <com/sun/star/table/BorderLine2.hpp>
      28             : #include <rtl/instance.hxx>
      29             : #include "oox/core/xmlfilterbase.hxx"
      30             : #include "oox/helper/propertyset.hxx"
      31             : 
      32             : using namespace ::oox::core;
      33             : using namespace ::com::sun::star;
      34             : using namespace ::com::sun::star::uno;
      35             : using namespace ::com::sun::star::beans;
      36             : using namespace ::com::sun::star::table;
      37             : 
      38             : 
      39             : namespace oox { namespace drawingml { namespace table {
      40             : 
      41           0 : TableProperties::TableProperties()
      42             : : mbRtl( sal_False )
      43             : , mbFirstRow( sal_False )
      44             : , mbFirstCol( sal_False )
      45             : , mbLastRow( sal_False )
      46             : , mbLastCol( sal_False )
      47             : , mbBandRow( sal_False )
      48           0 : , mbBandCol( sal_False )
      49             : {
      50           0 : }
      51           0 : TableProperties::~TableProperties()
      52             : {
      53           0 : }
      54             : 
      55           0 : void CreateTableRows( uno::Reference< XTableRows > xTableRows, const std::vector< TableRow >& rvTableRows )
      56             : {
      57           0 :     if ( rvTableRows.size() > 1 )
      58           0 :         xTableRows->insertByIndex( 0, rvTableRows.size() - 1 );
      59           0 :     std::vector< TableRow >::const_iterator aTableRowIter( rvTableRows.begin() );
      60           0 :     uno::Reference< container::XIndexAccess > xIndexAccess( xTableRows, UNO_QUERY_THROW );
      61           0 :     const OUString sHeight("Height");
      62           0 :     for ( sal_Int32 n = 0; n < xIndexAccess->getCount(); n++ )
      63             :     {
      64           0 :         Reference< XPropertySet > xPropSet( xIndexAccess->getByIndex( n ), UNO_QUERY_THROW );
      65           0 :         xPropSet->setPropertyValue( sHeight, Any( static_cast< sal_Int32 >( aTableRowIter->getHeight() / 360 ) ) );
      66           0 :         ++aTableRowIter;
      67           0 :     }
      68           0 : }
      69             : 
      70           0 : void CreateTableColumns( Reference< XTableColumns > xTableColumns, const std::vector< sal_Int32 >& rvTableGrid )
      71             : {
      72           0 :     if ( rvTableGrid.size() > 1 )
      73           0 :         xTableColumns->insertByIndex( 0, rvTableGrid.size() - 1 );
      74           0 :     std::vector< sal_Int32 >::const_iterator aTableGridIter( rvTableGrid.begin() );
      75           0 :     uno::Reference< container::XIndexAccess > xIndexAccess( xTableColumns, UNO_QUERY_THROW );
      76           0 :     const OUString sWidth("Width");
      77           0 :     for ( sal_Int32 n = 0; n < xIndexAccess->getCount(); n++ )
      78             :     {
      79           0 :         Reference< XPropertySet > xPropSet( xIndexAccess->getByIndex( n ), UNO_QUERY_THROW );
      80           0 :         xPropSet->setPropertyValue( sWidth, Any( static_cast< sal_Int32 >( *aTableGridIter++ / 360 ) ) );
      81           0 :     }
      82           0 : }
      83             : 
      84           0 : void MergeCells( const uno::Reference< XTable >& xTable, sal_Int32 nCol, sal_Int32 nRow, sal_Int32 nColSpan, sal_Int32 nRowSpan )
      85             : {
      86           0 :    if( xTable.is() ) try
      87             :    {
      88           0 :        Reference< XMergeableCellRange > xRange( xTable->createCursorByRange( xTable->getCellRangeByPosition( nCol, nRow,nCol + nColSpan - 1, nRow + nRowSpan - 1 ) ), UNO_QUERY_THROW );
      89           0 :        if( xRange->isMergeable() )
      90           0 :                xRange->merge();
      91             :    }
      92           0 :    catch( Exception& )
      93             :    {
      94             :    }
      95           0 : }
      96             : 
      97             : namespace
      98             : {
      99             :     struct theDefaultTableStyle : public ::rtl::Static< TableStyle, theDefaultTableStyle > {};
     100             : }
     101             : 
     102           0 : const TableStyle& TableProperties::getUsedTableStyle( const ::oox::core::XmlFilterBase& rFilterBase )
     103             : {
     104           0 :     ::oox::core::XmlFilterBase& rBase( const_cast< ::oox::core::XmlFilterBase& >( rFilterBase ) );
     105             : 
     106           0 :     TableStyle* pTableStyle = NULL;
     107           0 :     if ( mpTableStyle )
     108           0 :         pTableStyle = &*mpTableStyle;
     109           0 :     else if ( rBase.getTableStyles() )
     110             :     {
     111           0 :         const std::vector< TableStyle >& rTableStyles( rBase.getTableStyles()->getTableStyles() );
     112           0 :         const OUString aStyleId( getStyleId().isEmpty() ? rBase.getTableStyles()->getDefaultStyleId() : getStyleId() );
     113           0 :         std::vector< TableStyle >::const_iterator aIter( rTableStyles.begin() );
     114           0 :         while( aIter != rTableStyles.end() )
     115             :         {
     116           0 :             if ( const_cast< TableStyle& >( *aIter ).getStyleId() == aStyleId )
     117             :             {
     118           0 :                 pTableStyle = &const_cast< TableStyle& >( *aIter );
     119           0 :                 break;  // we get the correct style
     120             :             }
     121           0 :             ++aIter;
     122           0 :         }
     123             :     }
     124             : 
     125           0 :     if ( !pTableStyle )
     126           0 :         return theDefaultTableStyle::get();
     127             : 
     128           0 :     return *pTableStyle;
     129             : }
     130             : 
     131           0 : void TableProperties::pushToPropSet( const ::oox::core::XmlFilterBase& rFilterBase,
     132             :     const Reference < XPropertySet >& xPropSet, TextListStylePtr pMasterTextListStyle )
     133             : {
     134             :     uno::Reference< XColumnRowRange > xColumnRowRange(
     135           0 :          xPropSet->getPropertyValue("Model"), uno::UNO_QUERY_THROW );
     136             : 
     137           0 :     CreateTableColumns( xColumnRowRange->getColumns(), mvTableGrid );
     138           0 :     CreateTableRows( xColumnRowRange->getRows(), mvTableRows );
     139             : 
     140           0 :     const TableStyle& rTableStyle( getUsedTableStyle( rFilterBase ) );
     141           0 :     sal_Int32 nRow = 0;
     142           0 :     std::vector< TableRow >::iterator aTableRowIter( mvTableRows.begin() );
     143           0 :     while( aTableRowIter != mvTableRows.end() )
     144             :     {
     145           0 :         sal_Int32 nColumn = 0;
     146           0 :         std::vector< TableCell >::iterator aTableCellIter( aTableRowIter->getTableCells().begin() );
     147           0 :         while( aTableCellIter != aTableRowIter->getTableCells().end() )
     148             :         {
     149           0 :             TableCell& rTableCell( *aTableCellIter );
     150           0 :             if ( !rTableCell.getvMerge() && !rTableCell.gethMerge() )
     151             :             {
     152           0 :                 uno::Reference< XTable > xTable( xColumnRowRange, uno::UNO_QUERY_THROW );
     153           0 :                 if ( ( rTableCell.getRowSpan() > 1 ) || ( rTableCell.getGridSpan() > 1 ) )
     154           0 :                     MergeCells( xTable, nColumn, nRow, rTableCell.getGridSpan(), rTableCell.getRowSpan() );
     155             : 
     156           0 :                 Reference< XCellRange > xCellRange( xTable, UNO_QUERY_THROW );
     157           0 :                 rTableCell.pushToXCell( rFilterBase, pMasterTextListStyle, xCellRange->getCellByPosition( nColumn, nRow ), *this, rTableStyle,
     158           0 :                     nColumn, aTableRowIter->getTableCells().size(), nRow, mvTableRows.size() );
     159             :             }
     160           0 :             nColumn++;
     161           0 :             aTableCellIter++;
     162             :         }
     163           0 :         nRow++;
     164           0 :         aTableRowIter++;
     165           0 :     }
     166           0 : }
     167             : 
     168          51 : } } }
     169             : 
     170             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10