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

Generated by: LCOV version 1.11