LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sc/source/filter/xml - xmlrowi.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 137 152 90.1 %
Date: 2013-07-09 Functions: 12 12 100.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             :  * 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 "xmlrowi.hxx"
      21             : #include "xmlimprt.hxx"
      22             : #include "xmlcelli.hxx"
      23             : #include "global.hxx"
      24             : #include "xmlstyli.hxx"
      25             : #include "document.hxx"
      26             : #include "docuno.hxx"
      27             : #include "olinetab.hxx"
      28             : #include "sheetdata.hxx"
      29             : 
      30             : #include <xmloff/xmltkmap.hxx>
      31             : #include <xmloff/nmspmap.hxx>
      32             : #include <xmloff/xmlnmspe.hxx>
      33             : #include <xmloff/families.hxx>
      34             : #include <xmloff/xmltoken.hxx>
      35             : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
      36             : #include <com/sun/star/sheet/XSpreadsheet.hpp>
      37             : #include <com/sun/star/table/XColumnRowRange.hpp>
      38             : #include <com/sun/star/sheet/XPrintAreas.hpp>
      39             : 
      40             : #include <com/sun/star/table/CellAddress.hpp>
      41             : 
      42             : #define SC_ISVISIBLE "IsVisible"
      43             : #define SC_ISFILTERED "IsFiltered"
      44             : 
      45             : using namespace com::sun::star;
      46             : using namespace xmloff::token;
      47             : 
      48             : //------------------------------------------------------------------
      49             : 
      50        1994 : ScXMLTableRowContext::ScXMLTableRowContext( ScXMLImport& rImport,
      51             :                                       sal_uInt16 nPrfx,
      52             :                                       const OUString& rLName,
      53             :                                       const ::com::sun::star::uno::Reference<
      54             :                                       ::com::sun::star::xml::sax::XAttributeList>& xAttrList ) :
      55             :     SvXMLImportContext( rImport, nPrfx, rLName ),
      56        1994 :     sVisibility(GetXMLToken(XML_VISIBLE)),
      57             :     nRepeatedRows(1),
      58        3988 :     bHasCell(false)
      59             : {
      60        1994 :     OUString sCellStyleName;
      61        1994 :     sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
      62        1994 :     const SvXMLTokenMap& rAttrTokenMap(GetScImport().GetTableRowAttrTokenMap());
      63        4113 :     for( sal_Int16 i=0; i < nAttrCount; ++i )
      64             :     {
      65        2119 :         const OUString& sAttrName(xAttrList->getNameByIndex( i ));
      66        4238 :         OUString aLocalName;
      67        2119 :         sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
      68        2119 :                                             sAttrName, &aLocalName ));
      69        4238 :         const OUString& sValue(xAttrList->getValueByIndex( i ));
      70             : 
      71        2119 :         switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
      72             :         {
      73             :             case XML_TOK_TABLE_ROW_ATTR_STYLE_NAME:
      74             :             {
      75        1994 :                 sStyleName = sValue;
      76             :             }
      77        1994 :             break;
      78             :             case XML_TOK_TABLE_ROW_ATTR_VISIBILITY:
      79             :             {
      80          17 :                 sVisibility = sValue;
      81             :             }
      82          17 :             break;
      83             :             case XML_TOK_TABLE_ROW_ATTR_REPEATED:
      84             :             {
      85         108 :                 nRepeatedRows = std::max( sValue.toInt32(), (sal_Int32) 1 );
      86         108 :                 nRepeatedRows = std::min( nRepeatedRows, MAXROWCOUNT );
      87             :             }
      88         108 :             break;
      89             :             case XML_TOK_TABLE_ROW_ATTR_DEFAULT_CELL_STYLE_NAME:
      90             :             {
      91           0 :                 sCellStyleName = sValue;
      92             :             }
      93           0 :             break;
      94             :             /*case XML_TOK_TABLE_ROW_ATTR_USE_OPTIMAL_HEIGHT:
      95             :             {
      96             :                 sOptimalHeight = sValue;
      97             :             }
      98             :             break;*/
      99             :         }
     100        2119 :     }
     101        1994 :     GetScImport().GetTables().AddRow();
     102        1994 :     GetScImport().GetTables().SetRowStyle(sCellStyleName);
     103        1994 : }
     104             : 
     105        3988 : ScXMLTableRowContext::~ScXMLTableRowContext()
     106             : {
     107        3988 : }
     108             : 
     109        5652 : SvXMLImportContext *ScXMLTableRowContext::CreateChildContext( sal_uInt16 nPrefix,
     110             :                                             const OUString& rLName,
     111             :                                             const ::com::sun::star::uno::Reference<
     112             :                                           ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
     113             : {
     114        5652 :     SvXMLImportContext *pContext(0);
     115             : 
     116        5652 :     const SvXMLTokenMap& rTokenMap(GetScImport().GetTableRowElemTokenMap());
     117        5652 :     switch( rTokenMap.Get( nPrefix, rLName ) )
     118             :     {
     119             :     case XML_TOK_TABLE_ROW_CELL:
     120             : //      if( IsInsertCellPossible() )
     121             :         {
     122        5605 :             bHasCell = true;
     123             :             pContext = new ScXMLTableRowCellContext( GetScImport(), nPrefix,
     124             :                                                       rLName, xAttrList, false, static_cast<SCROW>(nRepeatedRows)
     125             :                                                       //this
     126        5605 :                                                       );
     127             :         }
     128        5605 :         break;
     129             :     case XML_TOK_TABLE_ROW_COVERED_CELL:
     130             : //      if( IsInsertCellPossible() )
     131             :         {
     132          47 :             bHasCell = true;
     133             :             pContext = new ScXMLTableRowCellContext( GetScImport(), nPrefix,
     134             :                                                       rLName, xAttrList, true, static_cast<SCROW>(nRepeatedRows)
     135             :                                                       //this
     136          47 :                                                       );
     137             :         }
     138          47 :         break;
     139             :     }
     140             : 
     141        5652 :     if( !pContext )
     142           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
     143             : 
     144        5652 :     return pContext;
     145             : }
     146             : 
     147        1994 : void ScXMLTableRowContext::EndElement()
     148             : {
     149        1994 :     ScXMLImport& rXMLImport(GetScImport());
     150        1994 :     if (!bHasCell && nRepeatedRows > 1)
     151             :     {
     152           0 :         for (sal_Int32 i = 0; i < nRepeatedRows - 1; ++i) //one row is always added
     153           0 :             GetScImport().GetTables().AddRow();
     154             :         OSL_FAIL("it seems here is a nonvalid file; possible missing of table:table-cell element");
     155             :     }
     156        1994 :     SCTAB nSheet = rXMLImport.GetTables().GetCurrentSheet();
     157        1994 :     sal_Int32 nCurrentRow(rXMLImport.GetTables().GetCurrentRow());
     158        1994 :     uno::Reference<sheet::XSpreadsheet> xSheet(rXMLImport.GetTables().GetCurrentXSheet());
     159        1994 :     if(xSheet.is())
     160             :     {
     161        1994 :         sal_Int32 nFirstRow(nCurrentRow - nRepeatedRows + 1);
     162        1994 :         if (nFirstRow > MAXROW)
     163           0 :             nFirstRow = MAXROW;
     164        1994 :         if (nCurrentRow > MAXROW)
     165           0 :             nCurrentRow = MAXROW;
     166        1994 :         uno::Reference <table::XCellRange> xCellRange(xSheet->getCellRangeByPosition(0, nFirstRow, 0, nCurrentRow));
     167        1994 :         if (xCellRange.is())
     168             :         {
     169        1994 :             uno::Reference<table::XColumnRowRange> xColumnRowRange (xCellRange, uno::UNO_QUERY);
     170        1994 :             if (xColumnRowRange.is())
     171             :             {
     172        1994 :                 uno::Reference <beans::XPropertySet> xRowProperties(xColumnRowRange->getRows(), uno::UNO_QUERY);
     173        1994 :                 if (xRowProperties.is())
     174             :                 {
     175        1994 :                     if (!sStyleName.isEmpty())
     176             :                     {
     177        1994 :                         XMLTableStylesContext *pStyles((XMLTableStylesContext *)rXMLImport.GetAutoStyles());
     178        1994 :                         if ( pStyles )
     179             :                         {
     180             :                             XMLTableStyleContext* pStyle((XMLTableStyleContext *)pStyles->FindStyleChildContext(
     181        1994 :                                 XML_STYLE_FAMILY_TABLE_ROW, sStyleName, true));
     182        1994 :                             if (pStyle)
     183             :                             {
     184        1994 :                                 pStyle->FillPropertySet(xRowProperties);
     185             : 
     186        1994 :                                 if ( nSheet != pStyle->GetLastSheet() )
     187             :                                 {
     188         226 :                                     ScSheetSaveData* pSheetData = ScModelObj::getImplementation(rXMLImport.GetModel())->GetSheetSaveData();
     189         226 :                                     pSheetData->AddRowStyle( sStyleName, ScAddress( 0, (SCROW)nFirstRow, nSheet ) );
     190         226 :                                     pStyle->SetLastSheet(nSheet);
     191             :                                 }
     192             :                             }
     193             :                         }
     194             :                     }
     195        1994 :                     bool bVisible (true);
     196        1994 :                     bool bFiltered (false);
     197        1994 :                     if (IsXMLToken(sVisibility, XML_COLLAPSE))
     198             :                     {
     199           3 :                         bVisible = false;
     200             :                     }
     201        1991 :                     else if (IsXMLToken(sVisibility, XML_FILTER))
     202             :                     {
     203          14 :                         bVisible = false;
     204          14 :                         bFiltered = true;
     205             :                     }
     206        1994 :                     if (!bVisible)
     207          17 :                         xRowProperties->setPropertyValue(OUString(SC_ISVISIBLE), uno::makeAny(bVisible));
     208        1994 :                     if (bFiltered)
     209          14 :                         xRowProperties->setPropertyValue(OUString(SC_ISFILTERED), uno::makeAny(bFiltered));
     210        1994 :                 }
     211        1994 :             }
     212        1994 :         }
     213        1994 :     }
     214        1994 : }
     215             : 
     216          10 : ScXMLTableRowsContext::ScXMLTableRowsContext( ScXMLImport& rImport,
     217             :                                       sal_uInt16 nPrfx,
     218             :                                       const OUString& rLName,
     219             :                                       const ::com::sun::star::uno::Reference<
     220             :                                       ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
     221             :                                       const bool bTempHeader, const bool bTempGroup ) :
     222             :     SvXMLImportContext( rImport, nPrfx, rLName ),
     223             :     nHeaderStartRow(0),
     224             :     nGroupStartRow(0),
     225             :     bHeader(bTempHeader),
     226             :     bGroup(bTempGroup),
     227          10 :     bGroupDisplay(true)
     228             : {
     229             :     // don't have any attributes
     230          10 :     if (bHeader)
     231             :     {
     232           2 :         ScAddress aAddr = rImport.GetTables().GetCurrentCellPos();
     233           2 :         nHeaderStartRow = aAddr.Row();
     234           2 :         ++nHeaderStartRow;
     235             :     }
     236           8 :     else if (bGroup)
     237             :     {
     238           8 :         nGroupStartRow = rImport.GetTables().GetCurrentRow();
     239           8 :         ++nGroupStartRow;
     240           8 :         sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
     241           9 :         for( sal_Int16 i=0; i < nAttrCount; ++i )
     242             :         {
     243           1 :             const OUString& sAttrName(xAttrList->getNameByIndex( i ));
     244           2 :             OUString aLocalName;
     245           1 :             sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
     246           1 :                                                 sAttrName, &aLocalName ));
     247           2 :             const OUString& sValue(xAttrList->getValueByIndex( i ));
     248             : 
     249           1 :             if ((nPrefix == XML_NAMESPACE_TABLE) && IsXMLToken(aLocalName, XML_DISPLAY))
     250           1 :                 bGroupDisplay = IsXMLToken(sValue, XML_TRUE);
     251           1 :         }
     252             :     }
     253          10 : }
     254             : 
     255          20 : ScXMLTableRowsContext::~ScXMLTableRowsContext()
     256             : {
     257          20 : }
     258             : 
     259          26 : SvXMLImportContext *ScXMLTableRowsContext::CreateChildContext( sal_uInt16 nPrefix,
     260             :                                             const OUString& rLName,
     261             :                                             const ::com::sun::star::uno::Reference<
     262             :                                           ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
     263             : {
     264          26 :     SvXMLImportContext *pContext(0);
     265             : 
     266          26 :     const SvXMLTokenMap& rTokenMap(GetScImport().GetTableRowsElemTokenMap());
     267          26 :     switch( rTokenMap.Get( nPrefix, rLName ) )
     268             :     {
     269             :     case XML_TOK_TABLE_ROWS_ROW_GROUP:
     270             :         pContext = new ScXMLTableRowsContext( GetScImport(), nPrefix,
     271             :                                                    rLName, xAttrList,
     272           6 :                                                    false, true );
     273           6 :         break;
     274             :     case XML_TOK_TABLE_ROWS_HEADER_ROWS:
     275             :         pContext = new ScXMLTableRowsContext( GetScImport(), nPrefix,
     276             :                                                    rLName, xAttrList,
     277           0 :                                                    true, false );
     278           0 :         break;
     279             :     case XML_TOK_TABLE_ROWS_ROWS:
     280             :         pContext = new ScXMLTableRowsContext( GetScImport(), nPrefix,
     281             :                                                    rLName, xAttrList,
     282           0 :                                                    false, false );
     283           0 :         break;
     284             :     case XML_TOK_TABLE_ROWS_ROW:
     285             :             pContext = new ScXMLTableRowContext( GetScImport(), nPrefix,
     286             :                                                       rLName, xAttrList//,
     287             :                                                       //this
     288          20 :                                                       );
     289          20 :         break;
     290             :     }
     291             : 
     292          26 :     if( !pContext )
     293           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
     294             : 
     295          26 :     return pContext;
     296             : }
     297             : 
     298          10 : void ScXMLTableRowsContext::EndElement()
     299             : {
     300          10 :     ScXMLImport& rXMLImport(GetScImport());
     301          10 :     if (bHeader)
     302             :     {
     303           2 :         SCROW nHeaderEndRow = rXMLImport.GetTables().GetCurrentRow();
     304           2 :         if (nHeaderStartRow <= nHeaderEndRow)
     305             :         {
     306           2 :             uno::Reference <sheet::XPrintAreas> xPrintAreas (rXMLImport.GetTables().GetCurrentXSheet(), uno::UNO_QUERY);
     307           2 :             if (xPrintAreas.is())
     308             :             {
     309           2 :                 if (!xPrintAreas->getPrintTitleRows())
     310             :                 {
     311           2 :                     xPrintAreas->setPrintTitleRows(true);
     312           2 :                     table::CellRangeAddress aRowHeaderRange;
     313           2 :                     aRowHeaderRange.StartRow = nHeaderStartRow;
     314           2 :                     aRowHeaderRange.EndRow = nHeaderEndRow;
     315           2 :                     xPrintAreas->setTitleRows(aRowHeaderRange);
     316             :                 }
     317             :                 else
     318             :                 {
     319           0 :                     table::CellRangeAddress aRowHeaderRange(xPrintAreas->getTitleRows());
     320           0 :                     aRowHeaderRange.EndRow = nHeaderEndRow;
     321           0 :                     xPrintAreas->setTitleRows(aRowHeaderRange);
     322             :                 }
     323           2 :             }
     324             :         }
     325             :     }
     326           8 :     else if (bGroup)
     327             :     {
     328           8 :         SCROW nGroupEndRow = rXMLImport.GetTables().GetCurrentRow();
     329           8 :         SCTAB nSheet(rXMLImport.GetTables().GetCurrentSheet());
     330           8 :         if (nGroupStartRow <= nGroupEndRow)
     331             :         {
     332           8 :             ScDocument* pDoc(GetScImport().GetDocument());
     333           8 :             if (pDoc)
     334             :             {
     335           8 :                 ScXMLImport::MutexGuard aGuard(GetScImport());
     336           8 :                 ScOutlineTable* pOutlineTable(pDoc->GetOutlineTable(nSheet, true));
     337           8 :                 ScOutlineArray* pRowArray(pOutlineTable->GetRowArray());
     338             :                 bool bResized;
     339           8 :                 pRowArray->Insert(static_cast<SCROW>(nGroupStartRow), static_cast<SCROW>(nGroupEndRow), bResized, !bGroupDisplay, true);
     340             :             }
     341             :         }
     342             :     }
     343         103 : }
     344             : 
     345             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10