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
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
36using namespace ::com::sun::star;
37using ::std::vector;
38
40 : rImport(rTempImport),
41 pCollection(nullptr)
42{
43}
44
46{
47}
48
49bool ScMyOLEFixer::IsOLE(const uno::Reference< drawing::XShape >& rShape)
50{
51 return rShape->getShapeType() == "com.sun.star.drawing.OLE2Shape";
52}
53
55 const OUString& rName,
56 std::u16string_view rRangeList)
57{
58 if (rRangeList.empty())
59 {
60 rDoc.AddOLEObjectToCollection(rName);
61 return;
62 }
63
64 OUString aRangeStr;
65 ScRangeStringConverter::GetStringFromXMLRangeString(aRangeStr, rRangeList, rDoc);
66 if (aRangeStr.isEmpty())
67 {
68 rDoc.AddOLEObjectToCollection(rName);
69 return;
70 }
71
72 if (!pCollection)
74
75 if (!pCollection)
76 return;
77
78 vector<ScTokenRef> aRefTokens;
81 aRefTokens, aRangeStr, rDoc, cSep, rDoc.GetGrammar());
82 if (aRefTokens.empty())
83 return;
84
85 OUString sName = !rName.isEmpty() ? rName : pCollection->getUniqueName(u"OLEFixer ");
86 ScChartListener* pCL(new ScChartListener(sName, rDoc, std::move(aRefTokens)));
87
88 //for loading binary files e.g.
89 //if we have the flat filter we need to set the dirty flag thus the visible charts get repainted
90 //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
91 if( (rImport.getImportFlags() & SvXMLImportFlags::ALL) == SvXMLImportFlags::ALL )
92 pCL->SetDirty( true );
93 else
94 {
95 // #i104899# If a formula cell is already dirty, further changes aren't propagated.
96 // This can happen easily now that row heights aren't updated for all sheets.
97 rDoc.InterpretDirtyCells( *pCL->GetRangeList() );
98 }
99
100 bool bSuccess = pCollection->insert(pCL);
101 assert(bSuccess && "failed to insert listener"); (void)bSuccess;
102 pCL->StartListeningTo();
103}
104
105void 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");
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: */
bool insert(ScChartListener *pListener)
Definition: chartlis.cxx:388
OUString getUniqueName(std::u16string_view rPrefix) const
Create a unique name that's not taken by any existing chart listener objects.
Definition: chartlis.cxx:420
void StartListeningTo()
Definition: chartlis.cxx:264
void SetDirty(bool bFlg)
Definition: chartlis.hxx:103
ScRangeListRef GetRangeList() const
Definition: chartlis.cxx:186
void AddOLEObjectToCollection(const OUString &rName)
Definition: documen5.cxx:646
SC_DLLPUBLIC ScChartListenerCollection * GetChartListenerCollection() const
Definition: document.hxx:2233
SC_DLLPUBLIC formula::FormulaGrammar::Grammar GetGrammar() const
Definition: document.hxx:1010
void InterpretDirtyCells(const ScRangeList &rRanges)
Definition: document.cxx:3872
ScXMLImport & rImport
void AddOLE(const css::uno::Reference< css::drawing::XShape > &rShape, const OUString &rRangeList)
void CreateChartListener(ScDocument &rDoc, const OUString &rName, std::u16string_view rRangeList)
ScMyOLEFixer(ScXMLImport &rImport)
ScChartListenerCollection * pCollection
static bool IsOLE(const css::uno::Reference< css::drawing::XShape > &rShape)
std::vector< ScMyToFixupOLE > aShapes
static void GetStringFromXMLRangeString(OUString &rString, std::u16string_view rXMLRange, const ScDocument &rDoc)
XML Range to Calc Range.
Definition: rangeutl.cxx:806
Use this class to manage solar mutex locking instead of calling LockSolarMutex() and UnlockSolarMutex...
Definition: xmlimprt.hxx:289
ScDocument * GetDocument()
Definition: xmlimprt.hxx:205
static sal_Unicode GetNativeSymbolChar(OpCode eOp)
float u
OUString sName
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.
ocSep
css::uno::Reference< css::drawing::XShape > xShape
sal_uInt16 sal_Unicode