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::unique_ptr;
39 : using ::std::vector;
40 :
41 1098 : ScMyOLEFixer::ScMyOLEFixer(ScXMLImport& rTempImport)
42 : : rImport(rTempImport),
43 : aShapes(),
44 1098 : pCollection(NULL)
45 : {
46 1098 : }
47 :
48 1098 : ScMyOLEFixer::~ScMyOLEFixer()
49 : {
50 1098 : }
51 :
52 204 : bool ScMyOLEFixer::IsOLE(uno::Reference< drawing::XShape >& rShape)
53 : {
54 204 : return rShape->getShapeType() == "com.sun.star.drawing.OLE2Shape";
55 : }
56 :
57 68 : void ScMyOLEFixer::CreateChartListener(ScDocument* pDoc,
58 : const OUString& rName,
59 : const OUString& rRangeList)
60 : {
61 : // This is the minimum required.
62 68 : if (!pDoc)
63 0 : return;
64 :
65 68 : if (rRangeList.isEmpty())
66 : {
67 0 : pDoc->AddOLEObjectToCollection(rName);
68 0 : return;
69 : }
70 :
71 68 : OUString aRangeStr;
72 68 : ScRangeStringConverter::GetStringFromXMLRangeString(aRangeStr, rRangeList, pDoc);
73 68 : if (aRangeStr.isEmpty())
74 : {
75 0 : pDoc->AddOLEObjectToCollection(rName);
76 0 : return;
77 : }
78 :
79 68 : if (!pCollection)
80 42 : pCollection = pDoc->GetChartListenerCollection();
81 :
82 68 : if (!pCollection)
83 0 : return;
84 :
85 136 : unique_ptr< vector<ScTokenRef> > pRefTokens(new vector<ScTokenRef>);
86 68 : const sal_Unicode cSep = ScCompiler::GetNativeSymbolChar(ocSep);
87 : ScRefTokenHelper::compileRangeRepresentation(
88 68 : *pRefTokens, aRangeStr, pDoc, cSep, pDoc->GetGrammar());
89 68 : if (!pRefTokens->empty())
90 : {
91 68 : ScChartListener* pCL(new ScChartListener(rName, pDoc, pRefTokens.release()));
92 :
93 : //for loading binary files e.g.
94 : //if we have the flat filter we need to set the dirty flag thus the visible charts get repainted
95 : //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
96 68 : if( (rImport.getImportFlags() & IMPORT_ALL) == IMPORT_ALL )
97 2 : pCL->SetDirty( true );
98 : else
99 : {
100 : // #i104899# If a formula cell is already dirty, further changes aren't propagated.
101 : // This can happen easily now that row heights aren't updated for all sheets.
102 66 : pDoc->InterpretDirtyCells( *pCL->GetRangeList() );
103 : }
104 :
105 68 : pCollection->insert( pCL );
106 68 : pCL->StartListeningTo();
107 68 : }
108 : }
109 :
110 68 : void ScMyOLEFixer::AddOLE(uno::Reference <drawing::XShape>& rShape,
111 : const OUString &rRangeList)
112 : {
113 68 : ScMyToFixupOLE aShape;
114 68 : aShape.xShape.set(rShape);
115 68 : aShape.sRangeList = rRangeList;
116 68 : aShapes.push_back(aShape);
117 68 : }
118 :
119 322 : void ScMyOLEFixer::FixupOLEs()
120 : {
121 322 : if (!aShapes.empty() && rImport.GetModel().is())
122 : {
123 42 : OUString sPersistName ("PersistName");
124 42 : ScMyToFixupOLEs::iterator aItr(aShapes.begin());
125 42 : ScMyToFixupOLEs::iterator aEndItr(aShapes.end());
126 42 : ScDocument* pDoc(rImport.GetDocument());
127 :
128 84 : ScXMLImport::MutexGuard aGuard(rImport);
129 :
130 152 : while (aItr != aEndItr)
131 : {
132 : // #i78086# also call CreateChartListener for invalid position (anchored to sheet)
133 68 : if (!IsOLE(aItr->xShape))
134 : OSL_FAIL("Only OLEs should be in here now");
135 :
136 68 : if (IsOLE(aItr->xShape))
137 : {
138 68 : uno::Reference < beans::XPropertySet > xShapeProps ( aItr->xShape, uno::UNO_QUERY );
139 136 : uno::Reference < beans::XPropertySetInfo > xShapeInfo(xShapeProps->getPropertySetInfo());
140 :
141 136 : OUString sName;
142 272 : if (pDoc && xShapeProps.is() && xShapeInfo.is() && xShapeInfo->hasPropertyByName(sPersistName) &&
143 272 : (xShapeProps->getPropertyValue(sPersistName) >>= sName))
144 136 : CreateChartListener(pDoc, sName, aItr->sRangeList);
145 : }
146 68 : aItr = aShapes.erase(aItr);
147 42 : }
148 : }
149 550 : }
150 :
151 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|