Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "XMLTableShapeResizer.hxx"
30 : : #include "unonames.hxx"
31 : : #include "document.hxx"
32 : : #include "xmlimprt.hxx"
33 : : #include "chartlis.hxx"
34 : : #include "XMLConverter.hxx"
35 : : #include "rangeutl.hxx"
36 : : #include "compiler.hxx"
37 : : #include "reftokenhelper.hxx"
38 : :
39 : : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
40 : : #include <com/sun/star/table/XColumnRowRange.hpp>
41 : : #include <com/sun/star/beans/XPropertySet.hpp>
42 : :
43 : : #include <memory>
44 : : #include <vector>
45 : :
46 : : using namespace ::com::sun::star;
47 : : using ::std::auto_ptr;
48 : : using ::std::vector;
49 : : using ::rtl::OUString;
50 : :
51 : 378 : ScMyOLEFixer::ScMyOLEFixer(ScXMLImport& rTempImport)
52 : : : rImport(rTempImport),
53 : : aShapes(),
54 : 378 : pCollection(NULL)
55 : : {
56 : 378 : }
57 : :
58 : 378 : ScMyOLEFixer::~ScMyOLEFixer()
59 : : {
60 : 378 : }
61 : :
62 : 0 : sal_Bool ScMyOLEFixer::IsOLE(uno::Reference< drawing::XShape >& rShape)
63 : : {
64 : 0 : return rShape->getShapeType() == "com.sun.star.drawing.OLE2Shape";
65 : : }
66 : :
67 : 0 : void ScMyOLEFixer::CreateChartListener(ScDocument* pDoc,
68 : : const rtl::OUString& rName,
69 : : const rtl::OUString& rRangeList)
70 : : {
71 : : // This is the minimum required.
72 [ # # ]: 0 : if (!pDoc)
73 : : return;
74 : :
75 [ # # ]: 0 : if (rRangeList.isEmpty())
76 : : {
77 [ # # ]: 0 : pDoc->AddOLEObjectToCollection(rName);
78 : : return;
79 : : }
80 : :
81 : 0 : OUString aRangeStr;
82 [ # # ]: 0 : ScRangeStringConverter::GetStringFromXMLRangeString(aRangeStr, rRangeList, pDoc);
83 [ # # ]: 0 : if (aRangeStr.isEmpty())
84 : : {
85 [ # # ]: 0 : pDoc->AddOLEObjectToCollection(rName);
86 : : return;
87 : : }
88 : :
89 [ # # ]: 0 : if (!pCollection)
90 [ # # ]: 0 : pCollection = pDoc->GetChartListenerCollection();
91 : :
92 [ # # ]: 0 : if (!pCollection)
93 : : return;
94 : :
95 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
96 [ # # ][ # # ]: 0 : auto_ptr< vector<ScTokenRef> > pRefTokens(new vector<ScTokenRef>);
97 : : SAL_WNODEPRECATED_DECLARATIONS_POP
98 [ # # ]: 0 : const sal_Unicode cSep = ScCompiler::GetNativeSymbol(ocSep).GetChar(0);
99 : : ScRefTokenHelper::compileRangeRepresentation(
100 [ # # ][ # # ]: 0 : *pRefTokens, aRangeStr, pDoc, cSep, pDoc->GetGrammar());
101 [ # # ]: 0 : if (!pRefTokens->empty())
102 : : {
103 [ # # ][ # # ]: 0 : ScChartListener* pCL(new ScChartListener(rName, pDoc, pRefTokens.release()));
104 : :
105 : : //for loading binary files e.g.
106 : : //if we have the flat filter we need to set the dirty flag thus the visible charts get repainted
107 : : //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
108 [ # # ]: 0 : if( (rImport.getImportFlags() & IMPORT_ALL) == IMPORT_ALL )
109 : 0 : pCL->SetDirty( sal_True );
110 : : else
111 : : {
112 : : // #i104899# If a formula cell is already dirty, further changes aren't propagated.
113 : : // This can happen easily now that row heights aren't updated for all sheets.
114 [ # # ][ # # ]: 0 : pDoc->InterpretDirtyCells( *pCL->GetRangeList() );
[ # # ]
115 : : }
116 : :
117 [ # # ]: 0 : pCollection->insert( pCL );
118 [ # # ]: 0 : pCL->StartListeningTo();
119 [ # # ]: 0 : }
120 : : }
121 : :
122 : 0 : void ScMyOLEFixer::AddOLE(uno::Reference <drawing::XShape>& rShape,
123 : : const rtl::OUString &rRangeList)
124 : : {
125 [ # # ]: 0 : ScMyToFixupOLE aShape;
126 [ # # ]: 0 : aShape.xShape.set(rShape);
127 : 0 : aShape.sRangeList = rRangeList;
128 [ # # ][ # # ]: 0 : aShapes.push_back(aShape);
129 : 0 : }
130 : :
131 : 93 : void ScMyOLEFixer::FixupOLEs()
132 : : {
133 [ - + ][ # # ]: 93 : if (!aShapes.empty() && rImport.GetModel().is())
[ - + ]
134 : : {
135 [ # # ]: 0 : rtl::OUString sPersistName (RTL_CONSTASCII_USTRINGPARAM("PersistName"));
136 : 0 : ScMyToFixupOLEs::iterator aItr(aShapes.begin());
137 : 0 : ScMyToFixupOLEs::iterator aEndItr(aShapes.end());
138 : 0 : ScDocument* pDoc(rImport.GetDocument());
139 : :
140 [ # # ]: 0 : ScXMLImport::MutexGuard aGuard(rImport);
141 : :
142 [ # # ]: 0 : while (aItr != aEndItr)
143 : : {
144 : : // #i78086# also call CreateChartListener for invalid position (anchored to sheet)
145 [ # # ]: 0 : if (!IsOLE(aItr->xShape))
146 : : OSL_FAIL("Only OLEs should be in here now");
147 : :
148 [ # # ][ # # ]: 0 : if (IsOLE(aItr->xShape))
149 : : {
150 [ # # ]: 0 : uno::Reference < beans::XPropertySet > xShapeProps ( aItr->xShape, uno::UNO_QUERY );
151 [ # # ][ # # ]: 0 : uno::Reference < beans::XPropertySetInfo > xShapeInfo(xShapeProps->getPropertySetInfo());
152 : :
153 : 0 : rtl::OUString sName;
154 [ # # ][ # # ]: 0 : if (pDoc && xShapeProps.is() && xShapeInfo.is() && xShapeInfo->hasPropertyByName(sPersistName) &&
[ # # ][ # # ]
[ # # # # ]
[ # # ][ # # ]
155 [ # # ][ # # ]: 0 : (xShapeProps->getPropertyValue(sPersistName) >>= sName))
[ # # ][ # # ]
156 [ # # ]: 0 : CreateChartListener(pDoc, sName, aItr->sRangeList);
157 : : }
158 [ # # ]: 0 : aItr = aShapes.erase(aItr);
159 [ # # ]: 0 : }
160 : : }
161 : 93 : }
162 : :
163 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|