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