LCOV - code coverage report
Current view: top level - sc/source/filter/xml - XMLTableShapeResizer.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 51 58 87.9 %
Date: 2015-06-13 12:38:46 Functions: 8 8 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 "XMLTableShapeResizer.hxx"
      21             : #include "unonames.hxx"
      22             : #include "document.hxx"
      23             : #include "xmlimprt.hxx"
      24             : #include "chartlis.hxx"
      25             : #include "XMLConverter.hxx"
      26             : #include "rangeutl.hxx"
      27             : #include "compiler.hxx"
      28             : #include "reftokenhelper.hxx"
      29             : 
      30             : #include <osl/diagnose.h>
      31             : 
      32             : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
      33             : #include <com/sun/star/table/XColumnRowRange.hpp>
      34             : #include <com/sun/star/beans/XPropertySet.hpp>
      35             : 
      36             : #include <memory>
      37             : #include <vector>
      38             : 
      39             : using namespace ::com::sun::star;
      40             : using ::std::unique_ptr;
      41             : using ::std::vector;
      42             : 
      43         683 : ScMyOLEFixer::ScMyOLEFixer(ScXMLImport& rTempImport)
      44             :     : rImport(rTempImport),
      45             :     aShapes(),
      46         683 :     pCollection(NULL)
      47             : {
      48         683 : }
      49             : 
      50         683 : ScMyOLEFixer::~ScMyOLEFixer()
      51             : {
      52         683 : }
      53             : 
      54          90 : bool ScMyOLEFixer::IsOLE(uno::Reference< drawing::XShape >& rShape)
      55             : {
      56          90 :     return rShape->getShapeType() == "com.sun.star.drawing.OLE2Shape";
      57             : }
      58             : 
      59          30 : void ScMyOLEFixer::CreateChartListener(ScDocument* pDoc,
      60             :     const OUString& rName,
      61             :     const OUString& rRangeList)
      62             : {
      63             :     // This is the minimum required.
      64          30 :     if (!pDoc)
      65           0 :         return;
      66             : 
      67          30 :     if (rRangeList.isEmpty())
      68             :     {
      69           0 :         pDoc->AddOLEObjectToCollection(rName);
      70           0 :         return;
      71             :     }
      72             : 
      73          30 :     OUString aRangeStr;
      74          30 :     ScRangeStringConverter::GetStringFromXMLRangeString(aRangeStr, rRangeList, pDoc);
      75          30 :     if (aRangeStr.isEmpty())
      76             :     {
      77           0 :         pDoc->AddOLEObjectToCollection(rName);
      78           0 :         return;
      79             :     }
      80             : 
      81          30 :     if (!pCollection)
      82          17 :         pCollection = pDoc->GetChartListenerCollection();
      83             : 
      84          30 :     if (!pCollection)
      85           0 :         return;
      86             : 
      87          60 :     unique_ptr< vector<ScTokenRef> > pRefTokens(new vector<ScTokenRef>);
      88          30 :         const sal_Unicode cSep = ScCompiler::GetNativeSymbolChar(ocSep);
      89             :     ScRefTokenHelper::compileRangeRepresentation(
      90          30 :         *pRefTokens, aRangeStr, pDoc, cSep, pDoc->GetGrammar());
      91          30 :     if (!pRefTokens->empty())
      92             :     {
      93          30 :         ScChartListener* pCL(new ScChartListener(rName, pDoc, pRefTokens.release()));
      94             : 
      95             :         //for loading binary files e.g.
      96             :         //if we have the flat filter we need to set the dirty flag thus the visible charts get repainted
      97             :         //otherwise the charts keep their first visual representation which was created at a moment where the calc itself was not loaded completely and is therefore incorrect
      98          30 :         if( rImport.getImportFlags() & SvXMLImportFlags::ALL )
      99          30 :             pCL->SetDirty( true );
     100             :         else
     101             :         {
     102             :             // #i104899# If a formula cell is already dirty, further changes aren't propagated.
     103             :             // This can happen easily now that row heights aren't updated for all sheets.
     104           0 :             pDoc->InterpretDirtyCells( *pCL->GetRangeList() );
     105             :         }
     106             : 
     107          30 :         pCollection->insert( pCL );
     108          30 :         pCL->StartListeningTo();
     109          30 :     }
     110             : }
     111             : 
     112          30 : void ScMyOLEFixer::AddOLE(uno::Reference <drawing::XShape>& rShape,
     113             :        const OUString &rRangeList)
     114             : {
     115          30 :     ScMyToFixupOLE aShape;
     116          30 :     aShape.xShape.set(rShape);
     117          30 :     aShape.sRangeList = rRangeList;
     118          30 :     aShapes.push_back(aShape);
     119          30 : }
     120             : 
     121         197 : void ScMyOLEFixer::FixupOLEs()
     122             : {
     123         197 :     if (!aShapes.empty() && rImport.GetModel().is())
     124             :     {
     125          17 :         OUString sPersistName ("PersistName");
     126          17 :         ScMyToFixupOLEs::iterator aItr(aShapes.begin());
     127          17 :         ScMyToFixupOLEs::iterator aEndItr(aShapes.end());
     128          17 :         ScDocument* pDoc(rImport.GetDocument());
     129             : 
     130          34 :         ScXMLImport::MutexGuard aGuard(rImport);
     131             : 
     132          64 :         while (aItr != aEndItr)
     133             :         {
     134             :             // #i78086# also call CreateChartListener for invalid position (anchored to sheet)
     135          30 :             if (!IsOLE(aItr->xShape))
     136             :                 OSL_FAIL("Only OLEs should be in here now");
     137             : 
     138          30 :             if (IsOLE(aItr->xShape))
     139             :             {
     140          30 :                 uno::Reference < beans::XPropertySet > xShapeProps ( aItr->xShape, uno::UNO_QUERY );
     141          60 :                 uno::Reference < beans::XPropertySetInfo > xShapeInfo(xShapeProps->getPropertySetInfo());
     142             : 
     143          60 :                 OUString sName;
     144         120 :                 if (pDoc && xShapeProps.is() && xShapeInfo.is() && xShapeInfo->hasPropertyByName(sPersistName) &&
     145         120 :                     (xShapeProps->getPropertyValue(sPersistName) >>= sName))
     146          60 :                     CreateChartListener(pDoc, sName, aItr->sRangeList);
     147             :             }
     148          30 :             aItr = aShapes.erase(aItr);
     149          17 :         }
     150             :     }
     151         353 : }
     152             : 
     153             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11