LCOV - code coverage report
Current view: top level - libreoffice/sc/source/filter/xml - xmlsubti.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 116 128 90.6 %
Date: 2012-12-17 Functions: 17 18 94.4 %
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 <svx/svdpage.hxx>
      35             : 
      36             : #include <sax/tools/converter.hxx>
      37             : #include <xmloff/xmltkmap.hxx>
      38             : #include <xmloff/nmspmap.hxx>
      39             : #include <xmloff/xmlerror.hxx>
      40             : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
      41             : #include <com/sun/star/sheet/XSheetCellRange.hpp>
      42             : #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
      43             : #include <com/sun/star/sheet/CellInsertMode.hpp>
      44             : #include <com/sun/star/sheet/XCellRangeMovement.hpp>
      45             : #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
      46             : #include <com/sun/star/container/XNamed.hpp>
      47             : #include <com/sun/star/util/XProtectable.hpp>
      48             : #include <com/sun/star/sheet/XArrayFormulaRange.hpp>
      49             : 
      50             : #include <memory>
      51             : 
      52             : using ::std::auto_ptr;
      53             : using namespace com::sun::star;
      54             : 
      55             : 
      56         422 : ScXMLTabProtectionData::ScXMLTabProtectionData() :
      57             :     meHash1(PASSHASH_SHA1),
      58             :     meHash2(PASSHASH_UNSPECIFIED),
      59             :     mbProtected(false),
      60             :     mbSelectProtectedCells(true),
      61         422 :     mbSelectUnprotectedCells(true)
      62             : {
      63         422 : }
      64             : 
      65         264 : ScMyTables::ScMyTables(ScXMLImport& rTempImport)
      66             :     : rImport(rTempImport),
      67             :     aFixupOLEs(rTempImport),
      68             :     maCurrentCellPos(ScAddress::INITIALIZE_INVALID),
      69             :     nCurrentColCount(0),
      70             :     nCurrentDrawPage( -1 ),
      71         264 :     nCurrentXShapes( -1 )
      72             : {
      73         264 : }
      74             : 
      75         264 : ScMyTables::~ScMyTables()
      76             : {
      77         264 : }
      78             : 
      79             : namespace {
      80             : 
      81         158 : uno::Reference<sheet::XSpreadsheet> getCurrentSheet(const uno::Reference<frame::XModel>& xModel, SCTAB nSheet)
      82             : {
      83         158 :     uno::Reference<sheet::XSpreadsheet> xSheet;
      84         158 :     uno::Reference<sheet::XSpreadsheetDocument> xSpreadDoc(xModel, uno::UNO_QUERY);
      85         158 :     if (!xSpreadDoc.is())
      86             :         return xSheet;
      87             : 
      88         158 :     uno::Reference <sheet::XSpreadsheets> xSheets(xSpreadDoc->getSheets());
      89         158 :     if (!xSheets.is())
      90             :         return xSheet;
      91             : 
      92         158 :     uno::Reference <container::XIndexAccess> xIndex(xSheets, uno::UNO_QUERY);
      93         158 :     if (!xIndex.is())
      94             :         return xSheet;
      95             : 
      96         158 :     xSheet.set(xIndex->getByIndex(nSheet), uno::UNO_QUERY);
      97         158 :     return xSheet;
      98             : }
      99             : 
     100             : }
     101             : 
     102         158 : void ScMyTables::NewSheet(const rtl::OUString& sTableName, const rtl::OUString& sStyleName,
     103             :                           const ScXMLTabProtectionData& rProtectData)
     104             : {
     105         158 :     if (rImport.GetModel().is())
     106             :     {
     107         158 :         nCurrentColCount = 0;
     108         158 :         sCurrentSheetName = sTableName;
     109             :         //reset cols and rows for new sheet, but increment tab
     110         158 :         maCurrentCellPos.SetCol(-1);
     111         158 :         maCurrentCellPos.SetRow(-1);
     112         158 :         maCurrentCellPos.SetTab(maCurrentCellPos.Tab() + 1);
     113             : 
     114         158 :         maProtectionData = rProtectData;
     115         158 :         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         158 :         if (maCurrentCellPos.Tab() > 0)
     120          92 :             pDoc->AppendTabOnLoad(sTableName);
     121             :         else
     122          66 :             pDoc->SetTabNameOnLoad(maCurrentCellPos.Tab(), sTableName);
     123             : 
     124         158 :         rImport.SetTableStyle(sStyleName);
     125         158 :         xCurrentSheet = getCurrentSheet(rImport.GetModel(), maCurrentCellPos.Tab());
     126         158 :         if (xCurrentSheet.is())
     127             :         {
     128             :             // We need to set the current cell range here regardless of
     129             :             // presence of style name.
     130         158 :             xCurrentCellRange.set(xCurrentSheet, uno::UNO_QUERY);
     131         158 :             SetTableStyle(sStyleName);
     132             :         }
     133             :     }
     134         158 : }
     135             : 
     136         158 : void ScMyTables::SetTableStyle(const rtl::OUString& sStyleName)
     137             : {
     138             :     //these uno calls are a bit difficult to remove, XMLTableStyleContext::FillPropertySet uses
     139             :     //SvXMLImportPropertyMapper::FillPropertySet
     140         158 :     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         158 :         if ( xCurrentSheet.is() )
     151             :         {
     152         158 :             xCurrentCellRange.set(xCurrentSheet, uno::UNO_QUERY);
     153         158 :             uno::Reference <beans::XPropertySet> xProperties(xCurrentSheet, uno::UNO_QUERY);
     154         158 :             if ( xProperties.is() )
     155             :             {
     156         158 :                 XMLTableStylesContext *pStyles = (XMLTableStylesContext *)rImport.GetAutoStyles();
     157         158 :                 if ( pStyles )
     158             :                 {
     159             :                     XMLTableStyleContext* pStyle = (XMLTableStyleContext *)pStyles->FindStyleChildContext(
     160         158 :                             XML_STYLE_FAMILY_TABLE_TABLE, sStyleName, true);
     161         158 :                     if ( pStyle )
     162             :                     {
     163         158 :                         pStyle->FillPropertySet(xProperties);
     164             : 
     165         158 :                         ScSheetSaveData* pSheetData = ScModelObj::getImplementation(rImport.GetModel())->GetSheetSaveData();
     166         158 :                         pSheetData->AddTableStyle( sStyleName, ScAddress( 0, 0, maCurrentCellPos.Tab() ) );
     167             :                     }
     168             :                 }
     169         158 :             }
     170             :         }
     171             :     }
     172         158 : }
     173             : 
     174    12586030 : void ScMyTables::AddRow()
     175             : {
     176    12586030 :     maCurrentCellPos.SetRow(maCurrentCellPos.Row() + 1);
     177    12586030 :     maCurrentCellPos.SetCol(-1); //reset columns for new row
     178    12586030 : }
     179             : 
     180        3020 : void ScMyTables::SetRowStyle(const rtl::OUString& rCellStyleName)
     181             : {
     182        3020 :     rImport.GetStylesImportHelper()->SetRowStyle(rCellStyleName);
     183        3020 : }
     184             : 
     185    12597646 : void ScMyTables::AddColumn(bool bIsCovered)
     186             : {
     187    12597646 :     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    12597646 :     if(maCurrentCellPos.Row() == 0 && !bIsCovered)
     191        1668 :         rImport.GetStylesImportHelper()->InsertCol(maCurrentCellPos.Col(), maCurrentCellPos.Tab(), rImport.GetDocument());
     192    12597646 : }
     193             : 
     194         158 : void ScMyTables::DeleteTable()
     195             : {
     196         158 :     ScXMLImport::MutexGuard aGuard(rImport);
     197             : 
     198         158 :     rImport.GetStylesImportHelper()->SetStylesToRanges();
     199         158 :     rImport.SetStylesToRangesFinished();
     200             : 
     201         158 :     maMatrixRangeList.RemoveAll();
     202             : 
     203         158 :     if (rImport.GetDocument() && maProtectionData.mbProtected)
     204             :     {
     205           0 :         uno::Sequence<sal_Int8> aHash;
     206           0 :         ::sax::Converter::decodeBase64(aHash, maProtectionData.maPassword);
     207             : 
     208             :         SAL_WNODEPRECATED_DECLARATIONS_PUSH
     209           0 :         auto_ptr<ScTableProtection> pProtect(new ScTableProtection);
     210             :         SAL_WNODEPRECATED_DECLARATIONS_POP
     211           0 :         pProtect->setProtected(maProtectionData.mbProtected);
     212           0 :         pProtect->setPasswordHash(aHash, maProtectionData.meHash1, maProtectionData.meHash2);
     213           0 :         pProtect->setOption(ScTableProtection::SELECT_LOCKED_CELLS,   maProtectionData.mbSelectProtectedCells);
     214           0 :         pProtect->setOption(ScTableProtection::SELECT_UNLOCKED_CELLS, maProtectionData.mbSelectUnprotectedCells);
     215           0 :         rImport.GetDocument()->SetTabProtection(maCurrentCellPos.Tab(), pProtect.get());
     216         158 :     }
     217         158 : }
     218             : 
     219         244 : void ScMyTables::AddColStyle(const sal_Int32 nRepeat, const rtl::OUString& rCellStyleName)
     220             : {
     221         244 :     rImport.GetStylesImportHelper()->AddColumnStyle(rCellStyleName, nCurrentColCount, nRepeat);
     222         244 :     nCurrentColCount += nRepeat;
     223         244 : }
     224             : 
     225          26 : uno::Reference< drawing::XDrawPage > ScMyTables::GetCurrentXDrawPage()
     226             : {
     227          26 :     if( (maCurrentCellPos.Tab() != nCurrentDrawPage) || !xDrawPage.is() )
     228             :     {
     229          26 :         uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier( xCurrentSheet, uno::UNO_QUERY );
     230          26 :         if( xDrawPageSupplier.is() )
     231          26 :             xDrawPage.set(xDrawPageSupplier->getDrawPage());
     232          26 :         nCurrentDrawPage = sal::static_int_cast<sal_Int16>(maCurrentCellPos.Tab());
     233             :     }
     234          26 :     return xDrawPage;
     235             : }
     236             : 
     237          18 : uno::Reference< drawing::XShapes > ScMyTables::GetCurrentXShapes()
     238             : {
     239          18 :     if( (maCurrentCellPos.Tab() != nCurrentXShapes) || !xShapes.is() )
     240             :     {
     241           4 :         xShapes.set(GetCurrentXDrawPage(), uno::UNO_QUERY);
     242           4 :         rImport.GetShapeImport()->startPage(xShapes);
     243           4 :         rImport.GetShapeImport()->pushGroupForSorting ( xShapes );
     244           4 :         nCurrentXShapes = sal::static_int_cast<sal_Int16>(maCurrentCellPos.Tab());
     245           4 :         return xShapes;
     246             :     }
     247             :     else
     248          14 :         return xShapes;
     249             : }
     250             : 
     251         158 : bool ScMyTables::HasDrawPage()
     252             : {
     253         158 :     return !((maCurrentCellPos.Tab() != nCurrentDrawPage) || !xDrawPage.is());
     254             : }
     255             : 
     256          26 : bool ScMyTables::HasXShapes()
     257             : {
     258          26 :     return !((maCurrentCellPos.Tab() != nCurrentXShapes) || !xShapes.is());
     259             : }
     260             : 
     261           0 : void ScMyTables::AddOLE(uno::Reference <drawing::XShape>& rShape,
     262             :       const rtl::OUString &rRangeList)
     263             : {
     264           0 :       aFixupOLEs.AddOLE(rShape, rRangeList);
     265           0 : }
     266             : 
     267          50 : void ScMyTables::AddMatrixRange(
     268             :         const SCCOL nStartColumn, const SCROW nStartRow, const SCCOL nEndColumn, const SCROW nEndRow,
     269             :         const rtl::OUString& rFormula, const rtl::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          50 :         nStartColumn, nStartRow, maCurrentCellPos.Tab(),
     275          50 :         nEndColumn, nEndRow, maCurrentCellPos.Tab()
     276         100 :     );
     277             : 
     278          50 :     maMatrixRangeList.Append(aScRange);
     279             : 
     280          50 :     ScDocument* pDoc = rImport.GetDocument();
     281          50 :     ScMarkData aMark;
     282          50 :     aMark.SetMarkArea( aScRange );
     283          50 :     aMark.SelectTable( aScRange.aStart.Tab(), sal_True );
     284          50 :     ScTokenArray* pCode = new ScTokenArray;
     285          50 :     pCode->AddStringXML( rFormula );
     286          50 :     if( (eGrammar == formula::FormulaGrammar::GRAM_EXTERNAL) && !rFormulaNmsp.isEmpty() )
     287           0 :         pCode->AddStringXML( rFormulaNmsp );
     288             :     pDoc->InsertMatrixFormula(
     289          50 :         aScRange.aStart.Col(), aScRange.aStart.Row(),
     290          50 :         aScRange.aEnd.Col(), aScRange.aEnd.Row(),
     291         150 :         aMark, EMPTY_STRING, pCode, eGrammar, false );
     292          50 :     delete pCode;
     293          50 :     pDoc->IncXMLImportedFormulaCount( rFormula.getLength() );
     294          50 : }
     295             : 
     296        3718 : bool ScMyTables::IsPartOfMatrix(const ScAddress& rScAddress) const
     297             : {
     298        3718 :     if (!maMatrixRangeList.empty())
     299        2246 :         return maMatrixRangeList.In(rScAddress);
     300        1472 :     return false;
     301             : }
     302             : 
     303             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10