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  OUString sName = !rName.isEmpty() ? rName : pCollection->getUniqueName(u"OLEFixer ");
88  ScChartListener* pCL(new ScChartListener(sName, rDoc, std::move(pRefTokens)));
89 
90  //for loading binary files e.g.
91  //if we have the flat filter we need to set the dirty flag thus the visible charts get repainted
92  //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
93  if( (rImport.getImportFlags() & SvXMLImportFlags::ALL) == SvXMLImportFlags::ALL )
94  pCL->SetDirty( true );
95  else
96  {
97  // #i104899# If a formula cell is already dirty, further changes aren't propagated.
98  // This can happen easily now that row heights aren't updated for all sheets.
99  rDoc.InterpretDirtyCells( *pCL->GetRangeList() );
100  }
101 
102  bool bSuccess = pCollection->insert(pCL);
103  assert(bSuccess && "failed to insert listener"); (void)bSuccess;
104  pCL->StartListeningTo();
105 }
106 
107 void ScMyOLEFixer::AddOLE(const uno::Reference <drawing::XShape>& rShape,
108  const OUString &rRangeList)
109 {
110  ScMyToFixupOLE aShape;
111  aShape.xShape.set(rShape);
112  aShape.sRangeList = rRangeList;
113  aShapes.push_back(aShape);
114 }
115 
117 {
118  if (aShapes.empty() || !rImport.GetModel().is())
119  return;
120 
121  OUString sPersistName ("PersistName");
122  ScDocument* pDoc(rImport.GetDocument());
123 
125 
126  for (auto const& shape : aShapes)
127  {
128  // #i78086# also call CreateChartListener for invalid position (anchored to sheet)
129  if (!IsOLE(shape.xShape))
130  OSL_FAIL("Only OLEs should be in here now");
131 
132  if (IsOLE(shape.xShape))
133  {
134  uno::Reference < beans::XPropertySet > xShapeProps ( shape.xShape, uno::UNO_QUERY );
135  uno::Reference < beans::XPropertySetInfo > xShapeInfo(xShapeProps->getPropertySetInfo());
136 
137  OUString sName;
138  if (pDoc && xShapeProps.is() && xShapeInfo.is() && xShapeInfo->hasPropertyByName(sPersistName) &&
139  (xShapeProps->getPropertyValue(sPersistName) >>= sName))
140  CreateChartListener(*pDoc, sName, shape.sRangeList);
141  }
142  }
143  aShapes.clear();
144 }
145 
146 /* 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:387
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:983
OUString getUniqueName(std::u16string_view rPrefix) const
Create a unique name that's not taken by any existing chart listener objects.
Definition: chartlis.cxx:419
sal_uInt16 sal_Unicode
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
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)
float u
Use this class to manage solar mutex locking instead of calling LockSolarMutex() and UnlockSolarMutex...
Definition: xmlimprt.hxx:293
std::vector< ScMyToFixupOLE > aShapes
ScXMLImport & rImport
SvXMLImportFlags getImportFlags() const
void InterpretDirtyCells(const ScRangeList &rRanges)
Definition: document.cxx:3880
const css::uno::Reference< css::frame::XModel > & GetModel() const
SC_DLLPUBLIC ScChartListenerCollection * GetChartListenerCollection() const
Definition: document.hxx:2146
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:798
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo