LCOV - code coverage report
Current view: top level - sc/source/filter/xml - xmlsubti.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 114 126 90.5 %
Date: 2014-04-11 Functions: 18 18 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 "xmlsubti.hxx"
      21             : #include "global.hxx"
      22             : #include "xmlstyli.hxx"
      23             : #include "xmlimprt.hxx"
      24             : #include "document.hxx"
      25             : #include "markdata.hxx"
      26             : #include "XMLConverter.hxx"
      27             : #include "docuno.hxx"
      28             : #include "cellsuno.hxx"
      29             : #include "XMLStylesImportHelper.hxx"
      30             : #include "sheetdata.hxx"
      31             : #include "tabprotection.hxx"
      32             : #include "tokenarray.hxx"
      33             : #include "convuno.hxx"
      34             : #include "documentimport.hxx"
      35             : 
      36             : #include <svx/svdpage.hxx>
      37             : 
      38             : #include <sax/tools/converter.hxx>
      39             : #include <xmloff/xmltkmap.hxx>
      40             : #include <xmloff/nmspmap.hxx>
      41             : #include <xmloff/xmlerror.hxx>
      42             : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
      43             : #include <com/sun/star/sheet/XSheetCellRange.hpp>
      44             : #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
      45             : #include <com/sun/star/sheet/CellInsertMode.hpp>
      46             : #include <com/sun/star/sheet/XCellRangeMovement.hpp>
      47             : #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
      48             : #include <com/sun/star/container/XNamed.hpp>
      49             : #include <com/sun/star/util/XProtectable.hpp>
      50             : #include <com/sun/star/sheet/XArrayFormulaRange.hpp>
      51             : 
      52             : #include <boost/scoped_ptr.hpp>
      53             : 
      54             : using namespace com::sun::star;
      55             : 
      56             : 
      57         644 : ScXMLTabProtectionData::ScXMLTabProtectionData() :
      58             :     meHash1(PASSHASH_SHA1),
      59             :     meHash2(PASSHASH_UNSPECIFIED),
      60             :     mbProtected(false),
      61             :     mbSelectProtectedCells(true),
      62         644 :     mbSelectUnprotectedCells(true)
      63             : {
      64         644 : }
      65             : 
      66         422 : ScMyTables::ScMyTables(ScXMLImport& rTempImport)
      67             :     : rImport(rTempImport),
      68             :     aFixupOLEs(rTempImport),
      69             :     maCurrentCellPos(ScAddress::INITIALIZE_INVALID),
      70             :     nCurrentColCount(0),
      71             :     nCurrentDrawPage( -1 ),
      72         422 :     nCurrentXShapes( -1 )
      73             : {
      74         422 : }
      75             : 
      76         422 : ScMyTables::~ScMyTables()
      77             : {
      78         422 : }
      79             : 
      80             : namespace {
      81             : 
      82         221 : uno::Reference<sheet::XSpreadsheet> getCurrentSheet(const uno::Reference<frame::XModel>& xModel, SCTAB nSheet)
      83             : {
      84         221 :     uno::Reference<sheet::XSpreadsheet> xSheet;
      85         442 :     uno::Reference<sheet::XSpreadsheetDocument> xSpreadDoc(xModel, uno::UNO_QUERY);
      86         221 :     if (!xSpreadDoc.is())
      87           0 :         return xSheet;
      88             : 
      89         442 :     uno::Reference <sheet::XSpreadsheets> xSheets(xSpreadDoc->getSheets());
      90         221 :     if (!xSheets.is())
      91           0 :         return xSheet;
      92             : 
      93         442 :     uno::Reference <container::XIndexAccess> xIndex(xSheets, uno::UNO_QUERY);
      94         221 :     if (!xIndex.is())
      95           0 :         return xSheet;
      96             : 
      97         221 :     xSheet.set(xIndex->getByIndex(nSheet), uno::UNO_QUERY);
      98         221 :     return xSheet;
      99             : }
     100             : 
     101             : }
     102             : 
     103         221 : void ScMyTables::NewSheet(const OUString& sTableName, const OUString& sStyleName,
     104             :                           const ScXMLTabProtectionData& rProtectData)
     105             : {
     106         221 :     if (rImport.GetModel().is())
     107             :     {
     108         221 :         nCurrentColCount = 0;
     109         221 :         sCurrentSheetName = sTableName;
     110             :         //reset cols and rows for new sheet, but increment tab
     111         221 :         maCurrentCellPos.SetCol(-1);
     112         221 :         maCurrentCellPos.SetRow(-1);
     113         221 :         maCurrentCellPos.SetTab(maCurrentCellPos.Tab() + 1);
     114             : 
     115         221 :         maProtectionData = rProtectData;
     116         221 :         ScDocument *pDoc = ScXMLConverter::GetScDocument(rImport.GetModel());
     117             : 
     118             :         // The document contains one sheet when created. So for the first
     119             :         // sheet, we only need to set its name.
     120         221 :         if (maCurrentCellPos.Tab() > 0)
     121         114 :             pDoc->AppendTabOnLoad(sTableName);
     122             :         else
     123         107 :             pDoc->SetTabNameOnLoad(maCurrentCellPos.Tab(), sTableName);
     124             : 
     125         221 :         rImport.SetTableStyle(sStyleName);
     126         221 :         xCurrentSheet = getCurrentSheet(rImport.GetModel(), maCurrentCellPos.Tab());
     127         221 :         if (xCurrentSheet.is())
     128             :         {
     129             :             // We need to set the current cell range here regardless of
     130             :             // presence of style name.
     131         221 :             xCurrentCellRange.set(xCurrentSheet, uno::UNO_QUERY);
     132         221 :             SetTableStyle(sStyleName);
     133             :         }
     134             :     }
     135         221 : }
     136             : 
     137         221 : void ScMyTables::SetTableStyle(const OUString& sStyleName)
     138             : {
     139             :     //these uno calls are a bit difficult to remove, XMLTableStyleContext::FillPropertySet uses
     140             :     //SvXMLImportPropertyMapper::FillPropertySet
     141         221 :     if ( !sStyleName.isEmpty() )
     142             :     {
     143             :         // #i57869# All table style properties for all sheets are now applied here,
     144             :         // before importing the contents.
     145             :         // This is needed for the background color.
     146             :         // Sheet visibility has special handling in ScDocFunc::SetTableVisible to
     147             :         // allow hiding the first sheet.
     148             :         // RTL layout is only remembered, not actually applied, so the shapes can
     149             :         // be loaded before mirroring.
     150             : 
     151         221 :         if ( xCurrentSheet.is() )
     152             :         {
     153         221 :             xCurrentCellRange.set(xCurrentSheet, uno::UNO_QUERY);
     154         221 :             uno::Reference <beans::XPropertySet> xProperties(xCurrentSheet, uno::UNO_QUERY);
     155         221 :             if ( xProperties.is() )
     156             :             {
     157         221 :                 XMLTableStylesContext *pStyles = (XMLTableStylesContext *)rImport.GetAutoStyles();
     158         221 :                 if ( pStyles )
     159             :                 {
     160             :                     XMLTableStyleContext* pStyle = (XMLTableStyleContext *)pStyles->FindStyleChildContext(
     161         221 :                             XML_STYLE_FAMILY_TABLE_TABLE, sStyleName, true);
     162         221 :                     if ( pStyle )
     163             :                     {
     164         221 :                         pStyle->FillPropertySet(xProperties);
     165             : 
     166         221 :                         ScSheetSaveData* pSheetData = ScModelObj::getImplementation(rImport.GetModel())->GetSheetSaveData();
     167         221 :                         pSheetData->AddTableStyle( sStyleName, ScAddress( 0, 0, maCurrentCellPos.Tab() ) );
     168             :                     }
     169             :                 }
     170         221 :             }
     171             :         }
     172             :     }
     173         221 : }
     174             : 
     175    33556093 : void ScMyTables::AddRow()
     176             : {
     177    33556093 :     maCurrentCellPos.SetRow(maCurrentCellPos.Row() + 1);
     178    33556093 :     maCurrentCellPos.SetCol(-1); //reset columns for new row
     179    33556093 : }
     180             : 
     181        2719 : void ScMyTables::SetRowStyle(const OUString& rCellStyleName)
     182             : {
     183        2719 :     rImport.GetStylesImportHelper()->SetRowStyle(rCellStyleName);
     184        2719 : }
     185             : 
     186    33812286 : void ScMyTables::AddColumn(bool bIsCovered)
     187             : {
     188    33812286 :     maCurrentCellPos.SetCol( maCurrentCellPos.Col() + 1 );
     189             :     //here only need to set column style if this is the first row and
     190             :     //the cell is not covered.
     191    33812286 :     if(maCurrentCellPos.Row() == 0 && !bIsCovered)
     192        6820 :         rImport.GetStylesImportHelper()->InsertCol(maCurrentCellPos.Col(), maCurrentCellPos.Tab(), rImport.GetDocument());
     193    33812286 : }
     194             : 
     195         222 : void ScMyTables::DeleteTable()
     196             : {
     197         222 :     ScXMLImport::MutexGuard aGuard(rImport);
     198             : 
     199         222 :     rImport.GetStylesImportHelper()->SetStylesToRanges();
     200         222 :     rImport.SetStylesToRangesFinished();
     201             : 
     202         222 :     maMatrixRangeList.RemoveAll();
     203             : 
     204         222 :     if (rImport.GetDocument() && maProtectionData.mbProtected)
     205             :     {
     206           0 :         uno::Sequence<sal_Int8> aHash;
     207           0 :         ::sax::Converter::decodeBase64(aHash, maProtectionData.maPassword);
     208             : 
     209           0 :         boost::scoped_ptr<ScTableProtection> pProtect(new ScTableProtection);
     210           0 :         pProtect->setProtected(maProtectionData.mbProtected);
     211           0 :         pProtect->setPasswordHash(aHash, maProtectionData.meHash1, maProtectionData.meHash2);
     212           0 :         pProtect->setOption(ScTableProtection::SELECT_LOCKED_CELLS,   maProtectionData.mbSelectProtectedCells);
     213           0 :         pProtect->setOption(ScTableProtection::SELECT_UNLOCKED_CELLS, maProtectionData.mbSelectUnprotectedCells);
     214           0 :         rImport.GetDocument()->SetTabProtection(maCurrentCellPos.Tab(), pProtect.get());
     215         222 :     }
     216         222 : }
     217             : 
     218         380 : void ScMyTables::AddColStyle(const sal_Int32 nRepeat, const OUString& rCellStyleName)
     219             : {
     220         380 :     rImport.GetStylesImportHelper()->AddColumnStyle(rCellStyleName, nCurrentColCount, nRepeat);
     221         380 :     nCurrentColCount += nRepeat;
     222             :     SAL_WARN_IF(nCurrentColCount > MAXCOLCOUNT, "sc", "more columns than fit into SCCOL");
     223         380 :     nCurrentColCount = std::min<sal_Int32>( nCurrentColCount, MAXCOLCOUNT );
     224         380 : }
     225             : 
     226          75 : uno::Reference< drawing::XDrawPage > ScMyTables::GetCurrentXDrawPage()
     227             : {
     228          75 :     if( (maCurrentCellPos.Tab() != nCurrentDrawPage) || !xDrawPage.is() )
     229             :     {
     230          68 :         uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier( xCurrentSheet, uno::UNO_QUERY );
     231          68 :         if( xDrawPageSupplier.is() )
     232          68 :             xDrawPage.set(xDrawPageSupplier->getDrawPage());
     233          68 :         nCurrentDrawPage = sal::static_int_cast<sal_Int16>(maCurrentCellPos.Tab());
     234             :     }
     235          75 :     return xDrawPage;
     236             : }
     237             : 
     238         274 : uno::Reference< drawing::XShapes > ScMyTables::GetCurrentXShapes()
     239             : {
     240         274 :     if( (maCurrentCellPos.Tab() != nCurrentXShapes) || !xShapes.is() )
     241             :     {
     242          51 :         xShapes.set(GetCurrentXDrawPage(), uno::UNO_QUERY);
     243          51 :         rImport.GetShapeImport()->startPage(xShapes);
     244          51 :         rImport.GetShapeImport()->pushGroupForSorting ( xShapes );
     245          51 :         nCurrentXShapes = sal::static_int_cast<sal_Int16>(maCurrentCellPos.Tab());
     246          51 :         return xShapes;
     247             :     }
     248             :     else
     249         223 :         return xShapes;
     250             : }
     251             : 
     252         222 : bool ScMyTables::HasDrawPage()
     253             : {
     254         222 :     return !((maCurrentCellPos.Tab() != nCurrentDrawPage) || !xDrawPage.is());
     255             : }
     256             : 
     257          68 : bool ScMyTables::HasXShapes()
     258             : {
     259          68 :     return !((maCurrentCellPos.Tab() != nCurrentXShapes) || !xShapes.is());
     260             : }
     261             : 
     262          29 : void ScMyTables::AddOLE(uno::Reference <drawing::XShape>& rShape,
     263             :       const OUString &rRangeList)
     264             : {
     265          29 :       aFixupOLEs.AddOLE(rShape, rRangeList);
     266          29 : }
     267             : 
     268          31 : void ScMyTables::AddMatrixRange(
     269             :         const SCCOL nStartColumn, const SCROW nStartRow, const SCCOL nEndColumn, const SCROW nEndRow,
     270             :         const OUString& rFormula, const OUString& rFormulaNmsp, const formula::FormulaGrammar::Grammar eGrammar)
     271             : {
     272             :     OSL_ENSURE(nEndRow >= nStartRow, "wrong row order");
     273             :     OSL_ENSURE(nEndColumn >= nStartColumn, "wrong column order");
     274             :     ScRange aScRange(
     275          31 :         nStartColumn, nStartRow, maCurrentCellPos.Tab(),
     276          31 :         nEndColumn, nEndRow, maCurrentCellPos.Tab()
     277          62 :     );
     278             : 
     279          31 :     maMatrixRangeList.Append(aScRange);
     280             : 
     281          31 :     ScDocumentImport& rDoc = rImport.GetDoc();
     282          31 :     boost::scoped_ptr<ScTokenArray> pCode(new ScTokenArray);
     283          31 :     pCode->AddStringXML( rFormula );
     284          31 :     if( (eGrammar == formula::FormulaGrammar::GRAM_EXTERNAL) && !rFormulaNmsp.isEmpty() )
     285           0 :         pCode->AddStringXML( rFormulaNmsp );
     286          31 :     rDoc.setMatrixCells(aScRange, *pCode, eGrammar);
     287          31 :     rDoc.getDoc().IncXMLImportedFormulaCount( rFormula.getLength() );
     288          31 : }
     289             : 
     290        4883 : bool ScMyTables::IsPartOfMatrix(const ScAddress& rScAddress) const
     291             : {
     292        4883 :     if (!maMatrixRangeList.empty())
     293        1121 :         return maMatrixRangeList.In(rScAddress);
     294        3762 :     return false;
     295             : }
     296             : 
     297             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10