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

Generated by: LCOV version 1.10