LCOV - code coverage report
Current view: top level - sc/source/filter/xml - XMLTableShapeResizer.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 51 58 87.9 %
Date: 2014-04-11 Functions: 6 6 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 <com/sun/star/sheet/XSpreadsheetDocument.hpp>
      31             : #include <com/sun/star/table/XColumnRowRange.hpp>
      32             : #include <com/sun/star/beans/XPropertySet.hpp>
      33             : 
      34             : #include <memory>
      35             : #include <vector>
      36             : 
      37             : using namespace ::com::sun::star;
      38             : using ::std::auto_ptr;
      39             : using ::std::vector;
      40             : 
      41         422 : ScMyOLEFixer::ScMyOLEFixer(ScXMLImport& rTempImport)
      42             :     : rImport(rTempImport),
      43             :     aShapes(),
      44         422 :     pCollection(NULL)
      45             : {
      46         422 : }
      47             : 
      48         422 : ScMyOLEFixer::~ScMyOLEFixer()
      49             : {
      50         422 : }
      51             : 
      52          87 : bool ScMyOLEFixer::IsOLE(uno::Reference< drawing::XShape >& rShape)
      53             : {
      54          87 :     return rShape->getShapeType() == "com.sun.star.drawing.OLE2Shape";
      55             : }
      56             : 
      57          29 : void ScMyOLEFixer::CreateChartListener(ScDocument* pDoc,
      58             :     const OUString& rName,
      59             :     const OUString& rRangeList)
      60             : {
      61             :     // This is the minimum required.
      62          29 :     if (!pDoc)
      63           0 :         return;
      64             : 
      65          29 :     if (rRangeList.isEmpty())
      66             :     {
      67           0 :         pDoc->AddOLEObjectToCollection(rName);
      68           0 :         return;
      69             :     }
      70             : 
      71          29 :     OUString aRangeStr;
      72          29 :     ScRangeStringConverter::GetStringFromXMLRangeString(aRangeStr, rRangeList, pDoc);
      73          29 :     if (aRangeStr.isEmpty())
      74             :     {
      75           0 :         pDoc->AddOLEObjectToCollection(rName);
      76           0 :         return;
      77             :     }
      78             : 
      79          29 :     if (!pCollection)
      80          16 :         pCollection = pDoc->GetChartListenerCollection();
      81             : 
      82          29 :     if (!pCollection)
      83           0 :         return;
      84             : 
      85             :     SAL_WNODEPRECATED_DECLARATIONS_PUSH
      86          58 :     auto_ptr< vector<ScTokenRef> > pRefTokens(new vector<ScTokenRef>);
      87             :     SAL_WNODEPRECATED_DECLARATIONS_POP
      88          29 :         const sal_Unicode cSep = ScCompiler::GetNativeSymbolChar(ocSep);
      89             :     ScRefTokenHelper::compileRangeRepresentation(
      90          29 :         *pRefTokens, aRangeStr, pDoc, cSep, pDoc->GetGrammar());
      91          29 :     if (!pRefTokens->empty())
      92             :     {
      93          29 :         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 incorect therefor
      98          29 :         if( (rImport.getImportFlags() & IMPORT_ALL) == IMPORT_ALL )
      99           0 :             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          29 :             pDoc->InterpretDirtyCells( *pCL->GetRangeList() );
     105             :         }
     106             : 
     107          29 :         pCollection->insert( pCL );
     108          29 :         pCL->StartListeningTo();
     109          29 :     }
     110             : }
     111             : 
     112          29 : void ScMyOLEFixer::AddOLE(uno::Reference <drawing::XShape>& rShape,
     113             :        const OUString &rRangeList)
     114             : {
     115          29 :     ScMyToFixupOLE aShape;
     116          29 :     aShape.xShape.set(rShape);
     117          29 :     aShape.sRangeList = rRangeList;
     118          29 :     aShapes.push_back(aShape);
     119          29 : }
     120             : 
     121         107 : void ScMyOLEFixer::FixupOLEs()
     122             : {
     123         107 :     if (!aShapes.empty() && rImport.GetModel().is())
     124             :     {
     125          16 :         OUString sPersistName ("PersistName");
     126          16 :         ScMyToFixupOLEs::iterator aItr(aShapes.begin());
     127          16 :         ScMyToFixupOLEs::iterator aEndItr(aShapes.end());
     128          16 :         ScDocument* pDoc(rImport.GetDocument());
     129             : 
     130          32 :         ScXMLImport::MutexGuard aGuard(rImport);
     131             : 
     132          61 :         while (aItr != aEndItr)
     133             :         {
     134             :             // #i78086# also call CreateChartListener for invalid position (anchored to sheet)
     135          29 :             if (!IsOLE(aItr->xShape))
     136             :                 OSL_FAIL("Only OLEs should be in here now");
     137             : 
     138          29 :             if (IsOLE(aItr->xShape))
     139             :             {
     140          29 :                 uno::Reference < beans::XPropertySet > xShapeProps ( aItr->xShape, uno::UNO_QUERY );
     141          58 :                 uno::Reference < beans::XPropertySetInfo > xShapeInfo(xShapeProps->getPropertySetInfo());
     142             : 
     143          58 :                 OUString sName;
     144         116 :                 if (pDoc && xShapeProps.is() && xShapeInfo.is() && xShapeInfo->hasPropertyByName(sPersistName) &&
     145         116 :                     (xShapeProps->getPropertyValue(sPersistName) >>= sName))
     146          58 :                     CreateChartListener(pDoc, sName, aItr->sRangeList);
     147             :             }
     148          29 :             aItr = aShapes.erase(aItr);
     149          16 :         }
     150             :     }
     151         107 : }
     152             : 
     153             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10