LibreOffice Module sc (master)  1
XMLTableShapeResizer.cxx
Go to the documentation of this file.
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 <document.hxx>
22 #include "xmlimprt.hxx"
23 #include <chartlis.hxx>
24 #include <rangeutl.hxx>
25 #include <compiler.hxx>
26 #include <reftokenhelper.hxx>
27 
28 #include <osl/diagnose.h>
29 
30 #include <com/sun/star/beans/XPropertySet.hpp>
31 #include <com/sun/star/drawing/XShape.hpp>
32 
33 #include <memory>
34 #include <vector>
35 
36 using namespace ::com::sun::star;
37 using ::std::unique_ptr;
38 using ::std::vector;
39 
41  : rImport(rTempImport),
42  aShapes(),
43  pCollection(nullptr)
44 {
45 }
46 
48 {
49 }
50 
51 bool ScMyOLEFixer::IsOLE(const uno::Reference< drawing::XShape >& rShape)
52 {
53  return rShape->getShapeType() == "com.sun.star.drawing.OLE2Shape";
54 }
55 
57  const OUString& rName,
58  const OUString& rRangeList)
59 {
60  if (rRangeList.isEmpty())
61  {
62  rDoc.AddOLEObjectToCollection(rName);
63  return;
64  }
65 
66  OUString aRangeStr;
67  ScRangeStringConverter::GetStringFromXMLRangeString(aRangeStr, rRangeList, rDoc);
68  if (aRangeStr.isEmpty())
69  {
70  rDoc.AddOLEObjectToCollection(rName);
71  return;
72  }
73 
74  if (!pCollection)
76 
77  if (!pCollection)
78  return;
79 
80  unique_ptr< vector<ScTokenRef> > pRefTokens(new vector<ScTokenRef>);
83  *pRefTokens, aRangeStr, rDoc, cSep, rDoc.GetGrammar());
84  if (pRefTokens->empty())
85  return;
86 
87  ScChartListener* pCL(new ScChartListener(rName, rDoc, std::move(pRefTokens)));
88 
89  //for loading binary files e.g.
90  //if we have the flat filter we need to set the dirty flag thus the visible charts get repainted
91  //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
92  if( (rImport.getImportFlags() & SvXMLImportFlags::ALL) == SvXMLImportFlags::ALL )
93  pCL->SetDirty( true );
94  else
95  {
96  // #i104899# If a formula cell is already dirty, further changes aren't propagated.
97  // This can happen easily now that row heights aren't updated for all sheets.
98  rDoc.InterpretDirtyCells( *pCL->GetRangeList() );
99  }
100 
101  pCollection->insert( pCL );
102  pCL->StartListeningTo();
103 }
104 
105 void ScMyOLEFixer::AddOLE(const uno::Reference <drawing::XShape>& rShape,
106  const OUString &rRangeList)
107 {
108  ScMyToFixupOLE aShape;
109  aShape.xShape.set(rShape);
110  aShape.sRangeList = rRangeList;
111  aShapes.push_back(aShape);
112 }
113 
115 {
116  if (aShapes.empty() || !rImport.GetModel().is())
117  return;
118 
119  OUString sPersistName ("PersistName");
120  ScDocument* pDoc(rImport.GetDocument());
121 
123 
124  for (auto const& shape : aShapes)
125  {
126  // #i78086# also call CreateChartListener for invalid position (anchored to sheet)
127  if (!IsOLE(shape.xShape))
128  OSL_FAIL("Only OLEs should be in here now");
129 
130  if (IsOLE(shape.xShape))
131  {
132  uno::Reference < beans::XPropertySet > xShapeProps ( shape.xShape, uno::UNO_QUERY );
133  uno::Reference < beans::XPropertySetInfo > xShapeInfo(xShapeProps->getPropertySetInfo());
134 
135  OUString sName;
136  if (pDoc && xShapeProps.is() && xShapeInfo.is() && xShapeInfo->hasPropertyByName(sPersistName) &&
137  (xShapeProps->getPropertyValue(sPersistName) >>= sName))
138  CreateChartListener(*pDoc, sName, shape.sRangeList);
139  }
140  }
141  aShapes.clear();
142 }
143 
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void compileRangeRepresentation(::std::vector< ScTokenRef > &rRefTokens, const OUString &rRangeStr, ScDocument &rDoc, const sal_Unicode cSep,::formula::FormulaGrammar::Grammar eGrammar, bool bOnly3DRef=false)
Compile an array of reference tokens from a data source range string.
css::uno::Reference< css::drawing::XShape > xShape
ScDocument * GetDocument()
Definition: xmlimprt.hxx:296
ScRangeListRef GetRangeList() const
Definition: chartlis.cxx:186
void CreateChartListener(ScDocument &rDoc, const OUString &rName, const OUString &rRangeList)
SC_DLLPUBLIC formula::FormulaGrammar::Grammar GetGrammar() const
Definition: document.hxx:985
sal_uInt16 sal_Unicode
ScMyOLEFixer(ScXMLImport &rImport)
void StartListeningTo()
Definition: chartlis.cxx:264
static sal_Unicode GetNativeSymbolChar(OpCode eOp)
const char * sName
ocSep
void AddOLEObjectToCollection(const OUString &rName)
Definition: documen5.cxx:645
ScChartListenerCollection * pCollection
void AddOLE(const css::uno::Reference< css::drawing::XShape > &rShape, const OUString &rRangeList)
Use this class to manage solar mutex locking instead of calling LockSolarMutex() and UnlockSolarMutex...
Definition: xmlimprt.hxx:392
std::vector< ScMyToFixupOLE > aShapes
void insert(ScChartListener *pListener)
Definition: chartlis.cxx:387
ScXMLImport & rImport
SvXMLImportFlags getImportFlags() const
void InterpretDirtyCells(const ScRangeList &rRanges)
Definition: document.cxx:3888
const css::uno::Reference< css::frame::XModel > & GetModel() const
SC_DLLPUBLIC ScChartListenerCollection * GetChartListenerCollection() const
Definition: document.hxx:2143
void SetDirty(bool bFlg)
Definition: chartlis.hxx:103
static bool IsOLE(const css::uno::Reference< css::drawing::XShape > &rShape)
static void GetStringFromXMLRangeString(OUString &rString, const OUString &rXMLRange, const ScDocument &rDoc)
XML Range to Calc Range.
Definition: rangeutl.cxx:780