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  pCollection(nullptr)
43 {
44 }
45 
47 {
48 }
49 
50 bool ScMyOLEFixer::IsOLE(const uno::Reference< drawing::XShape >& rShape)
51 {
52  return rShape->getShapeType() == "com.sun.star.drawing.OLE2Shape";
53 }
54 
56  const OUString& rName,
57  const OUString& rRangeList)
58 {
59  if (rRangeList.isEmpty())
60  {
61  rDoc.AddOLEObjectToCollection(rName);
62  return;
63  }
64 
65  OUString aRangeStr;
66  ScRangeStringConverter::GetStringFromXMLRangeString(aRangeStr, rRangeList, rDoc);
67  if (aRangeStr.isEmpty())
68  {
69  rDoc.AddOLEObjectToCollection(rName);
70  return;
71  }
72 
73  if (!pCollection)
75 
76  if (!pCollection)
77  return;
78 
79  unique_ptr< vector<ScTokenRef> > pRefTokens(new vector<ScTokenRef>);
82  *pRefTokens, aRangeStr, rDoc, cSep, rDoc.GetGrammar());
83  if (pRefTokens->empty())
84  return;
85 
86  OUString sName = !rName.isEmpty() ? rName : pCollection->getUniqueName(u"OLEFixer ");
87  ScChartListener* pCL(new ScChartListener(sName, 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  bool bSuccess = pCollection->insert(pCL);
102  assert(bSuccess && "failed to insert listener"); (void)bSuccess;
103  pCL->StartListeningTo();
104 }
105 
106 void ScMyOLEFixer::AddOLE(const uno::Reference <drawing::XShape>& rShape,
107  const OUString &rRangeList)
108 {
109  ScMyToFixupOLE aShape;
110  aShape.xShape.set(rShape);
111  aShape.sRangeList = rRangeList;
112  aShapes.push_back(aShape);
113 }
114 
116 {
117  if (aShapes.empty() || !rImport.GetModel().is())
118  return;
119 
120  OUString sPersistName ("PersistName");
121  ScDocument* pDoc(rImport.GetDocument());
122 
124 
125  for (auto const& shape : aShapes)
126  {
127  // #i78086# also call CreateChartListener for invalid position (anchored to sheet)
128  if (!IsOLE(shape.xShape))
129  OSL_FAIL("Only OLEs should be in here now");
130 
131  if (IsOLE(shape.xShape))
132  {
133  uno::Reference < beans::XPropertySet > xShapeProps ( shape.xShape, uno::UNO_QUERY );
134  uno::Reference < beans::XPropertySetInfo > xShapeInfo(xShapeProps->getPropertySetInfo());
135 
136  OUString sName;
137  if (pDoc && xShapeProps.is() && xShapeInfo.is() && xShapeInfo->hasPropertyByName(sPersistName) &&
138  (xShapeProps->getPropertyValue(sPersistName) >>= sName))
139  CreateChartListener(*pDoc, sName, shape.sRangeList);
140  }
141  }
142  aShapes.clear();
143 }
144 
145 /* 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:205
bool insert(ScChartListener *pListener)
Definition: chartlis.cxx:386
ScRangeListRef GetRangeList() const
Definition: chartlis.cxx:184
void CreateChartListener(ScDocument &rDoc, const OUString &rName, const OUString &rRangeList)
SC_DLLPUBLIC formula::FormulaGrammar::Grammar GetGrammar() const
Definition: document.hxx:984
OUString getUniqueName(std::u16string_view rPrefix) const
Create a unique name that's not taken by any existing chart listener objects.
Definition: chartlis.cxx:418
sal_uInt16 sal_Unicode
ScMyOLEFixer(ScXMLImport &rImport)
void StartListeningTo()
Definition: chartlis.cxx:262
static sal_Unicode GetNativeSymbolChar(OpCode eOp)
const char * sName
ocSep
void AddOLEObjectToCollection(const OUString &rName)
Definition: documen5.cxx:643
ScChartListenerCollection * pCollection
void AddOLE(const css::uno::Reference< css::drawing::XShape > &rShape, const OUString &rRangeList)
float u
Use this class to manage solar mutex locking instead of calling LockSolarMutex() and UnlockSolarMutex...
Definition: xmlimprt.hxx:288
std::vector< ScMyToFixupOLE > aShapes
ScXMLImport & rImport
SvXMLImportFlags getImportFlags() const
void InterpretDirtyCells(const ScRangeList &rRanges)
Definition: document.cxx:3919
const css::uno::Reference< css::frame::XModel > & GetModel() const
SC_DLLPUBLIC ScChartListenerCollection * GetChartListenerCollection() const
Definition: document.hxx:2156
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:806
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo