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