LCOV - code coverage report
Current view: top level - sc/source/filter/xml - xmlcoli.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 105 133 78.9 %
Date: 2014-11-03 Functions: 11 12 91.7 %
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        2322 : 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        2322 :     sVisibility(GetXMLToken(XML_VISIBLE))
      50             : {
      51        2322 :     nColCount = 1;
      52        2322 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
      53        2322 :     const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetTableColAttrTokenMap();
      54             : 
      55        5904 :     for( sal_Int16 i=0; i < nAttrCount; ++i )
      56             :     {
      57        3582 :         const OUString& sAttrName(xAttrList->getNameByIndex( i ));
      58        7164 :         OUString aLocalName;
      59        3582 :         sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
      60        3582 :                                             sAttrName, &aLocalName );
      61        7164 :         const OUString& sValue(xAttrList->getValueByIndex( i ));
      62             : 
      63        3582 :         switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
      64             :         {
      65             :             case XML_TOK_TABLE_COL_ATTR_REPEATED:
      66             :                 {
      67         356 :                     nColCount = std::max<sal_Int32>(sValue.toInt32(), 1);
      68         356 :                     nColCount = std::min<sal_Int32>(nColCount, MAXCOLCOUNT);
      69             :                 }
      70         356 :                 break;
      71             :             case XML_TOK_TABLE_COL_ATTR_STYLE_NAME:
      72             :                 {
      73        2322 :                     sStyleName = sValue;
      74             :                 }
      75        2322 :                 break;
      76             :             case XML_TOK_TABLE_COL_ATTR_VISIBILITY:
      77             :                 {
      78           6 :                     sVisibility = sValue;
      79             :                 }
      80           6 :                 break;
      81             :             case XML_TOK_TABLE_COL_ATTR_DEFAULT_CELL_STYLE_NAME:
      82             :                 {
      83         898 :                     sCellStyleName = sValue;
      84             :                 }
      85         898 :                 break;
      86             :         }
      87        3582 :     }
      88        2322 : }
      89             : 
      90        4644 : ScXMLTableColContext::~ScXMLTableColContext()
      91             : {
      92        4644 : }
      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        2322 : void ScXMLTableColContext::EndElement()
     108             : {
     109        2322 :     ScXMLImport& rXMLImport = GetScImport();
     110        2322 :     SCTAB nSheet = rXMLImport.GetTables().GetCurrentSheet();
     111        2322 :     sal_Int32 nCurrentColumn = rXMLImport.GetTables().GetCurrentColCount();
     112        2322 :     uno::Reference<sheet::XSpreadsheet> xSheet(rXMLImport.GetTables().GetCurrentXSheet());
     113        2322 :     if(xSheet.is())
     114             :     {
     115        2322 :         sal_Int32 nLastColumn(nCurrentColumn + nColCount - 1);
     116        2322 :         if (nLastColumn > MAXCOL)
     117           0 :             nLastColumn = MAXCOL;
     118        2322 :         if (nCurrentColumn > MAXCOL)
     119           0 :             nCurrentColumn = MAXCOL;
     120        2322 :         uno::Reference<table::XColumnRowRange> xColumnRowRange (xSheet->getCellRangeByPosition(nCurrentColumn, 0, nLastColumn, 0), uno::UNO_QUERY);
     121        2322 :         if (xColumnRowRange.is())
     122             :         {
     123        2322 :             uno::Reference <beans::XPropertySet> xColumnProperties(xColumnRowRange->getColumns(), uno::UNO_QUERY);
     124        2322 :             if (xColumnProperties.is())
     125             :             {
     126        2322 :                 if (!sStyleName.isEmpty())
     127             :                 {
     128        2322 :                     XMLTableStylesContext *pStyles = static_cast<XMLTableStylesContext *>(rXMLImport.GetAutoStyles());
     129        2322 :                     if ( pStyles )
     130             :                     {
     131             :                         XMLTableStyleContext* pStyle = const_cast<XMLTableStyleContext*>(static_cast<const XMLTableStyleContext *>(pStyles->FindStyleChildContext(
     132        2322 :                             XML_STYLE_FAMILY_TABLE_COLUMN, sStyleName, true)));
     133        2322 :                         if (pStyle)
     134             :                         {
     135        2322 :                             pStyle->FillPropertySet(xColumnProperties);
     136             : 
     137        2322 :                             if ( nSheet != pStyle->GetLastSheet() )
     138             :                             {
     139        2128 :                                 ScSheetSaveData* pSheetData = ScModelObj::getImplementation(rXMLImport.GetModel())->GetSheetSaveData();
     140        2128 :                                 pSheetData->AddColumnStyle( sStyleName, ScAddress( (SCCOL)nCurrentColumn, 0, nSheet ) );
     141        2128 :                                 pStyle->SetLastSheet(nSheet);
     142             :                             }
     143             :                         }
     144             :                     }
     145             :                 }
     146        2322 :                 OUString sVisible(SC_UNONAME_CELLVIS);
     147        2322 :                 bool bValue(true);
     148        2322 :                 if (!IsXMLToken(sVisibility, XML_VISIBLE))
     149           6 :                     bValue = false;
     150        2322 :                 xColumnProperties->setPropertyValue(sVisible, uno::makeAny(bValue));
     151        2322 :             }
     152        2322 :         }
     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        2322 :     if ( sCellStyleName.isEmpty() )
     158        1424 :         sCellStyleName = "Default";
     159             : 
     160        2322 :     GetScImport().GetTables().AddColStyle(nColCount, sCellStyleName);
     161        2322 : }
     162             : 
     163          16 : 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          16 :     bGroupDisplay(true)
     177             : {
     178             :     // don't have any attributes
     179          16 :     if (bHeader)
     180           0 :         nHeaderStartCol = rImport.GetTables().GetCurrentColCount();
     181          16 :     else if (bGroup)
     182             :     {
     183          16 :         nGroupStartCol = rImport.GetTables().GetCurrentColCount();
     184          16 :         sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
     185          18 :         for( sal_Int16 i=0; i < nAttrCount; ++i )
     186             :         {
     187           2 :             const OUString& sAttrName(xAttrList->getNameByIndex( i ));
     188           4 :             OUString aLocalName;
     189           2 :             sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
     190           2 :                                                 sAttrName, &aLocalName );
     191           4 :             const OUString& sValue(xAttrList->getValueByIndex( i ));
     192             : 
     193           2 :             if (nPrefix == XML_NAMESPACE_TABLE && IsXMLToken(aLocalName, XML_DISPLAY))
     194             :             {
     195           2 :                 if (IsXMLToken(sValue, XML_FALSE))
     196           2 :                     bGroupDisplay = false;
     197             :             }
     198           2 :         }
     199             :     }
     200          16 : }
     201             : 
     202          32 : ScXMLTableColsContext::~ScXMLTableColsContext()
     203             : {
     204          32 : }
     205             : 
     206          40 : 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          40 :     SvXMLImportContext *pContext = 0;
     212             : 
     213          40 :     const SvXMLTokenMap& rTokenMap = GetScImport().GetTableColsElemTokenMap();
     214          40 :     switch( rTokenMap.Get( nPrefix, rLName ) )
     215             :     {
     216             :     case XML_TOK_TABLE_COLS_COL_GROUP:
     217             :         pContext = new ScXMLTableColsContext( GetScImport(), nPrefix,
     218             :                                                    rLName, xAttrList,
     219          12 :                                                    false, true );
     220          12 :         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          28 :                                                       );
     236          28 :         break;
     237             :     }
     238             : 
     239          40 :     if( !pContext )
     240           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
     241             : 
     242          40 :     return pContext;
     243             : }
     244             : 
     245          16 : void ScXMLTableColsContext::EndElement()
     246             : {
     247          16 :     ScXMLImport& rXMLImport = GetScImport();
     248          16 :     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          16 :     else if (bGroup)
     275             :     {
     276          16 :         SCTAB nSheet = rXMLImport.GetTables().GetCurrentSheet();
     277          16 :         nGroupEndCol = rXMLImport.GetTables().GetCurrentColCount();
     278          16 :         nGroupEndCol--;
     279          16 :         if (nGroupStartCol <= nGroupEndCol)
     280             :         {
     281          16 :             ScDocument* pDoc = GetScImport().GetDocument();
     282          16 :             if (pDoc)
     283             :             {
     284          16 :                 ScXMLImport::MutexGuard aGuard(GetScImport());
     285          16 :                 ScOutlineTable* pOutlineTable = pDoc->GetOutlineTable(nSheet, true);
     286          16 :                 if (pOutlineTable)
     287             :                 {
     288          16 :                     ScOutlineArray& rColArray = pOutlineTable->GetColArray();
     289             :                     bool bResized;
     290          16 :                     rColArray.Insert(static_cast<SCCOL>(nGroupStartCol), static_cast<SCCOL>(nGroupEndCol), bResized, !bGroupDisplay, true);
     291          16 :                 }
     292             :             }
     293             :         }
     294             :     }
     295         244 : }
     296             : 
     297             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10