LCOV - code coverage report
Current view: top level - sc/source/filter/xml - xmlcoli.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 104 133 78.2 %
Date: 2014-04-11 Functions: 9 10 90.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 "xmlcoli.hxx"
      21             : #include "xmlimprt.hxx"
      22             : #include "global.hxx"
      23             : #include "xmlstyli.hxx"
      24             : #include "document.hxx"
      25             : #include "docuno.hxx"
      26             : #include "olinetab.hxx"
      27             : #include "sheetdata.hxx"
      28             : #include "unonames.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             : using namespace com::sun::star;
      41             : using namespace xmloff::token;
      42             : 
      43         380 : ScXMLTableColContext::ScXMLTableColContext( ScXMLImport& rImport,
      44             :                                       sal_uInt16 nPrfx,
      45             :                                       const OUString& rLName,
      46             :                                       const ::com::sun::star::uno::Reference<
      47             :                                       ::com::sun::star::xml::sax::XAttributeList>& xAttrList ) :
      48             :     SvXMLImportContext( rImport, nPrfx, rLName ),
      49         380 :     sVisibility(GetXMLToken(XML_VISIBLE))
      50             : {
      51         380 :     nColCount = 1;
      52         380 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
      53         380 :     const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetTableColAttrTokenMap();
      54             : 
      55        1294 :     for( sal_Int16 i=0; i < nAttrCount; ++i )
      56             :     {
      57         914 :         const OUString& sAttrName(xAttrList->getNameByIndex( i ));
      58        1828 :         OUString aLocalName;
      59         914 :         sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
      60         914 :                                             sAttrName, &aLocalName );
      61        1828 :         const OUString& sValue(xAttrList->getValueByIndex( i ));
      62             : 
      63         914 :         switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
      64             :         {
      65             :             case XML_TOK_TABLE_COL_ATTR_REPEATED:
      66             :                 {
      67         151 :                     nColCount = std::max<sal_Int32>(sValue.toInt32(), 1);
      68         151 :                     nColCount = std::min<sal_Int32>(nColCount, MAXCOLCOUNT);
      69             :                 }
      70         151 :                 break;
      71             :             case XML_TOK_TABLE_COL_ATTR_STYLE_NAME:
      72             :                 {
      73         380 :                     sStyleName = sValue;
      74             :                 }
      75         380 :                 break;
      76             :             case XML_TOK_TABLE_COL_ATTR_VISIBILITY:
      77             :                 {
      78           3 :                     sVisibility = sValue;
      79             :                 }
      80           3 :                 break;
      81             :             case XML_TOK_TABLE_COL_ATTR_DEFAULT_CELL_STYLE_NAME:
      82             :                 {
      83         380 :                     sCellStyleName = sValue;
      84             :                 }
      85         380 :                 break;
      86             :         }
      87         914 :     }
      88         380 : }
      89             : 
      90         760 : ScXMLTableColContext::~ScXMLTableColContext()
      91             : {
      92         760 : }
      93             : 
      94           0 : SvXMLImportContext *ScXMLTableColContext::CreateChildContext( sal_uInt16 nPrefix,
      95             :                                             const OUString& rLName,
      96             :                                             const ::com::sun::star::uno::Reference<
      97             :                                         ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
      98             : {
      99           0 :     SvXMLImportContext *pContext = 0;
     100             : 
     101           0 :     if( !pContext )
     102           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
     103             : 
     104           0 :     return pContext;
     105             : }
     106             : 
     107         380 : void ScXMLTableColContext::EndElement()
     108             : {
     109         380 :     ScXMLImport& rXMLImport = GetScImport();
     110         380 :     SCTAB nSheet = rXMLImport.GetTables().GetCurrentSheet();
     111         380 :     sal_Int32 nCurrentColumn = rXMLImport.GetTables().GetCurrentColCount();
     112         380 :     uno::Reference<sheet::XSpreadsheet> xSheet(rXMLImport.GetTables().GetCurrentXSheet());
     113         380 :     if(xSheet.is())
     114             :     {
     115         380 :         sal_Int32 nLastColumn(nCurrentColumn + nColCount - 1);
     116         380 :         if (nLastColumn > MAXCOL)
     117           0 :             nLastColumn = MAXCOL;
     118         380 :         if (nCurrentColumn > MAXCOL)
     119           0 :             nCurrentColumn = MAXCOL;
     120         380 :         uno::Reference<table::XColumnRowRange> xColumnRowRange (xSheet->getCellRangeByPosition(nCurrentColumn, 0, nLastColumn, 0), uno::UNO_QUERY);
     121         380 :         if (xColumnRowRange.is())
     122             :         {
     123         380 :             uno::Reference <beans::XPropertySet> xColumnProperties(xColumnRowRange->getColumns(), uno::UNO_QUERY);
     124         380 :             if (xColumnProperties.is())
     125             :             {
     126         380 :                 if (!sStyleName.isEmpty())
     127             :                 {
     128         380 :                     XMLTableStylesContext *pStyles = (XMLTableStylesContext *)rXMLImport.GetAutoStyles();
     129         380 :                     if ( pStyles )
     130             :                     {
     131             :                         XMLTableStyleContext* pStyle = (XMLTableStyleContext *)pStyles->FindStyleChildContext(
     132         380 :                             XML_STYLE_FAMILY_TABLE_COLUMN, sStyleName, true);
     133         380 :                         if (pStyle)
     134             :                         {
     135         380 :                             pStyle->FillPropertySet(xColumnProperties);
     136             : 
     137         380 :                             if ( nSheet != pStyle->GetLastSheet() )
     138             :                             {
     139         296 :                                 ScSheetSaveData* pSheetData = ScModelObj::getImplementation(rXMLImport.GetModel())->GetSheetSaveData();
     140         296 :                                 pSheetData->AddColumnStyle( sStyleName, ScAddress( (SCCOL)nCurrentColumn, 0, nSheet ) );
     141         296 :                                 pStyle->SetLastSheet(nSheet);
     142             :                             }
     143             :                         }
     144             :                     }
     145             :                 }
     146         380 :                 OUString sVisible(SC_UNONAME_CELLVIS);
     147         380 :                 bool bValue(true);
     148         380 :                 if (!IsXMLToken(sVisibility, XML_VISIBLE))
     149           3 :                     bValue = false;
     150         380 :                 xColumnProperties->setPropertyValue(sVisible, uno::makeAny(bValue));
     151         380 :             }
     152         380 :         }
     153             :     }
     154             : 
     155             :     // #i57915# ScXMLImport::SetStyleToRange can't handle empty style names.
     156             :     // The default for a column if there is no attribute is the style "Default" (programmatic API name).
     157         380 :     if ( sCellStyleName.isEmpty() )
     158           0 :         sCellStyleName = "Default";
     159             : 
     160         380 :     GetScImport().GetTables().AddColStyle(nColCount, sCellStyleName);
     161         380 : }
     162             : 
     163           8 : ScXMLTableColsContext::ScXMLTableColsContext( ScXMLImport& rImport,
     164             :                                       sal_uInt16 nPrfx,
     165             :                                       const OUString& rLName,
     166             :                                       const ::com::sun::star::uno::Reference<
     167             :                                       ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
     168             :                                       const bool bTempHeader, const bool bTempGroup) :
     169             :     SvXMLImportContext( rImport, nPrfx, rLName ),
     170             :     nHeaderStartCol(0),
     171             :     nHeaderEndCol(0),
     172             :     nGroupStartCol(0),
     173             :     nGroupEndCol(0),
     174             :     bHeader(bTempHeader),
     175             :     bGroup(bTempGroup),
     176           8 :     bGroupDisplay(true)
     177             : {
     178             :     // don't have any attributes
     179           8 :     if (bHeader)
     180           0 :         nHeaderStartCol = rImport.GetTables().GetCurrentColCount();
     181           8 :     else if (bGroup)
     182             :     {
     183           8 :         nGroupStartCol = rImport.GetTables().GetCurrentColCount();
     184           8 :         sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
     185           9 :         for( sal_Int16 i=0; i < nAttrCount; ++i )
     186             :         {
     187           1 :             const OUString& sAttrName(xAttrList->getNameByIndex( i ));
     188           2 :             OUString aLocalName;
     189           1 :             sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
     190           1 :                                                 sAttrName, &aLocalName );
     191           2 :             const OUString& sValue(xAttrList->getValueByIndex( i ));
     192             : 
     193           1 :             if (nPrefix == XML_NAMESPACE_TABLE && IsXMLToken(aLocalName, XML_DISPLAY))
     194             :             {
     195           1 :                 if (IsXMLToken(sValue, XML_FALSE))
     196           1 :                     bGroupDisplay = false;
     197             :             }
     198           1 :         }
     199             :     }
     200           8 : }
     201             : 
     202          16 : ScXMLTableColsContext::~ScXMLTableColsContext()
     203             : {
     204          16 : }
     205             : 
     206          20 : SvXMLImportContext *ScXMLTableColsContext::CreateChildContext( sal_uInt16 nPrefix,
     207             :                                             const OUString& rLName,
     208             :                                             const ::com::sun::star::uno::Reference<
     209             :                                           ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
     210             : {
     211          20 :     SvXMLImportContext *pContext = 0;
     212             : 
     213          20 :     const SvXMLTokenMap& rTokenMap = GetScImport().GetTableColsElemTokenMap();
     214          20 :     switch( rTokenMap.Get( nPrefix, rLName ) )
     215             :     {
     216             :     case XML_TOK_TABLE_COLS_COL_GROUP:
     217             :         pContext = new ScXMLTableColsContext( GetScImport(), nPrefix,
     218             :                                                    rLName, xAttrList,
     219           6 :                                                    false, true );
     220           6 :         break;
     221             :     case XML_TOK_TABLE_COLS_HEADER_COLS:
     222             :         pContext = new ScXMLTableColsContext( GetScImport(), nPrefix,
     223             :                                                    rLName, xAttrList,
     224           0 :                                                    true, false );
     225           0 :         break;
     226             :     case XML_TOK_TABLE_COLS_COLS:
     227             :         pContext = new ScXMLTableColsContext( GetScImport(), nPrefix,
     228             :                                                    rLName, xAttrList,
     229           0 :                                                    false, false );
     230           0 :         break;
     231             :     case XML_TOK_TABLE_COLS_COL:
     232             :             pContext = new ScXMLTableColContext( GetScImport(), nPrefix,
     233             :                                                       rLName, xAttrList//,
     234             :                                                       //this
     235          14 :                                                       );
     236          14 :         break;
     237             :     }
     238             : 
     239          20 :     if( !pContext )
     240           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
     241             : 
     242          20 :     return pContext;
     243             : }
     244             : 
     245           8 : void ScXMLTableColsContext::EndElement()
     246             : {
     247           8 :     ScXMLImport& rXMLImport = GetScImport();
     248           8 :     if (bHeader)
     249             :     {
     250           0 :         nHeaderEndCol = rXMLImport.GetTables().GetCurrentColCount();
     251           0 :         nHeaderEndCol--;
     252           0 :         if (nHeaderStartCol <= nHeaderEndCol)
     253             :         {
     254           0 :             uno::Reference <sheet::XPrintAreas> xPrintAreas (rXMLImport.GetTables().GetCurrentXSheet(), uno::UNO_QUERY);
     255           0 :             if (xPrintAreas.is())
     256             :             {
     257           0 :                 if (!xPrintAreas->getPrintTitleColumns())
     258             :                 {
     259           0 :                     xPrintAreas->setPrintTitleColumns(true);
     260           0 :                     table::CellRangeAddress aColumnHeaderRange;
     261           0 :                     aColumnHeaderRange.StartColumn = nHeaderStartCol;
     262           0 :                     aColumnHeaderRange.EndColumn = nHeaderEndCol;
     263           0 :                     xPrintAreas->setTitleColumns(aColumnHeaderRange);
     264             :                 }
     265             :                 else
     266             :                 {
     267           0 :                     table::CellRangeAddress aColumnHeaderRange(xPrintAreas->getTitleColumns());
     268           0 :                     aColumnHeaderRange.EndColumn = nHeaderEndCol;
     269           0 :                     xPrintAreas->setTitleColumns(aColumnHeaderRange);
     270             :                 }
     271           0 :             }
     272             :         }
     273             :     }
     274           8 :     else if (bGroup)
     275             :     {
     276           8 :         SCTAB nSheet = rXMLImport.GetTables().GetCurrentSheet();
     277           8 :         nGroupEndCol = rXMLImport.GetTables().GetCurrentColCount();
     278           8 :         nGroupEndCol--;
     279           8 :         if (nGroupStartCol <= nGroupEndCol)
     280             :         {
     281           8 :             ScDocument* pDoc = GetScImport().GetDocument();
     282           8 :             if (pDoc)
     283             :             {
     284           8 :                 ScXMLImport::MutexGuard aGuard(GetScImport());
     285           8 :                 ScOutlineTable* pOutlineTable = pDoc->GetOutlineTable(nSheet, true);
     286           8 :                 ScOutlineArray* pColArray = pOutlineTable ? pOutlineTable->GetColArray() : NULL;
     287           8 :                 if (pColArray)
     288             :                 {
     289             :                     bool bResized;
     290           8 :                     pColArray->Insert(static_cast<SCCOL>(nGroupStartCol), static_cast<SCCOL>(nGroupEndCol), bResized, !bGroupDisplay, true);
     291           8 :                 }
     292             :             }
     293             :         }
     294             :     }
     295           8 : }
     296             : 
     297             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10