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 "XMLTableShapeImportHelper.hxx"
21 : #include "xmlimprt.hxx"
22 : #include "XMLConverter.hxx"
23 : #include "drwlayer.hxx"
24 : #include "xmlannoi.hxx"
25 : #include "rangeutl.hxx"
26 : #include "userdat.hxx"
27 : #include "docuno.hxx"
28 : #include "sheetdata.hxx"
29 : #include <xmloff/nmspmap.hxx>
30 : #include <xmloff/xmlnmspe.hxx>
31 : #include <xmloff/xmluconv.hxx>
32 : #include <xmloff/xmltoken.hxx>
33 : #include <svx/unoshape.hxx>
34 : #include <svx/svdobj.hxx>
35 : #include <com/sun/star/drawing/XShape.hpp>
36 : #include <com/sun/star/drawing/XShapes.hpp>
37 :
38 : #define SC_LAYERID "LayerID"
39 :
40 : using namespace ::com::sun::star;
41 : using namespace xmloff::token;
42 :
43 :
44 214 : XMLTableShapeImportHelper::XMLTableShapeImportHelper(
45 : ScXMLImport& rImp, SvXMLImportPropertyMapper *pImpMapper ) :
46 214 : XMLShapeImportHelper(rImp, rImp.GetModel(), pImpMapper ),
47 : pAnnotationContext(NULL),
48 214 : bOnTable(false)
49 : {
50 214 : }
51 :
52 428 : XMLTableShapeImportHelper::~XMLTableShapeImportHelper()
53 : {
54 428 : }
55 :
56 94 : void XMLTableShapeImportHelper::SetLayer(uno::Reference<drawing::XShape>& rShape, sal_Int16 nLayerID, const OUString& sType) const
57 : {
58 94 : if ( sType == "com.sun.star.drawing.ControlShape" )
59 21 : nLayerID = SC_LAYER_CONTROLS;
60 94 : if (nLayerID != -1)
61 : {
62 26 : uno::Reference< beans::XPropertySet > xShapeProp( rShape, uno::UNO_QUERY );
63 26 : if( xShapeProp.is() )
64 26 : xShapeProp->setPropertyValue(OUString( SC_LAYERID ), uno::makeAny(nLayerID) );
65 : }
66 94 : }
67 :
68 : // Attempt to find the topmost parent of the group, this is the one we apply
69 : // offsets to
70 10 : static uno::Reference< drawing::XShape > lcl_getTopLevelParent( const uno::Reference< drawing::XShape >& rShape )
71 : {
72 10 : uno::Reference< container::XChild > xChild( rShape, uno::UNO_QUERY );
73 20 : uno::Reference< drawing::XShape > xParent( xChild->getParent(), uno::UNO_QUERY );
74 10 : if ( xParent.is() )
75 0 : return lcl_getTopLevelParent( xParent );
76 20 : return rShape;
77 : }
78 :
79 109 : void XMLTableShapeImportHelper::finishShape(
80 : uno::Reference< drawing::XShape >& rShape,
81 : const uno::Reference< xml::sax::XAttributeList >& xAttrList,
82 : uno::Reference< drawing::XShapes >& rShapes )
83 : {
84 109 : bool bNote = false;
85 109 : XMLShapeImportHelper::finishShape( rShape, xAttrList, rShapes );
86 109 : static_cast<ScXMLImport&>(mrImporter).LockSolarMutex();
87 109 : ScMyTables& rTables = static_cast<ScXMLImport&>(mrImporter).GetTables();
88 109 : if (rShapes == rTables.GetCurrentXShapes())
89 : {
90 99 : if (!pAnnotationContext)
91 : {
92 84 : ScDrawObjData aAnchor;
93 84 : aAnchor.maStart = ScAddress(aStartCell.Column, aStartCell.Row, aStartCell.Sheet);
94 84 : awt::Point aStartPoint(rShape->getPosition());
95 84 : aAnchor.maStartOffset = Point(aStartPoint.X, aStartPoint.Y);
96 :
97 84 : sal_Int32 nEndX(-1);
98 84 : sal_Int32 nEndY(-1);
99 84 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
100 84 : table::CellAddress aEndCell;
101 84 : OUString* pRangeList(NULL);
102 84 : sal_Int16 nLayerID(-1);
103 988 : for( sal_Int16 i=0; i < nAttrCount; ++i )
104 : {
105 904 : const OUString& rAttrName(xAttrList->getNameByIndex( i ));
106 1808 : const OUString& rValue(xAttrList->getValueByIndex( i ));
107 :
108 1808 : OUString aLocalName;
109 : sal_uInt16 nPrefix(
110 904 : static_cast<ScXMLImport&>(mrImporter).GetNamespaceMap().GetKeyByAttrName( rAttrName,
111 904 : &aLocalName ));
112 904 : if(nPrefix == XML_NAMESPACE_TABLE)
113 : {
114 167 : if (IsXMLToken(aLocalName, XML_END_CELL_ADDRESS))
115 : {
116 54 : sal_Int32 nOffset(0);
117 54 : ScRangeStringConverter::GetAddressFromString(aEndCell, rValue, static_cast<ScXMLImport&>(mrImporter).GetDocument(), ::formula::FormulaGrammar::CONV_OOO, nOffset);
118 54 : aAnchor.maEnd = ScAddress(aEndCell.Column, aEndCell.Row, aEndCell.Sheet);
119 : }
120 113 : else if (IsXMLToken(aLocalName, XML_END_X))
121 : {
122 : static_cast<ScXMLImport&>(mrImporter).
123 54 : GetMM100UnitConverter().convertMeasureToCore(
124 54 : nEndX, rValue);
125 54 : aAnchor.maEndOffset.X() = nEndX;
126 : }
127 59 : else if (IsXMLToken(aLocalName, XML_END_Y))
128 : {
129 : static_cast<ScXMLImport&>(mrImporter).
130 54 : GetMM100UnitConverter().convertMeasureToCore(
131 54 : nEndY, rValue);
132 54 : aAnchor.maEndOffset.Y() = nEndY;
133 : }
134 5 : else if (IsXMLToken(aLocalName, XML_TABLE_BACKGROUND))
135 5 : if (IsXMLToken(rValue, XML_TRUE))
136 5 : nLayerID = SC_LAYER_BACK;
137 : }
138 737 : else if(nPrefix == XML_NAMESPACE_DRAW)
139 : {
140 295 : if (IsXMLToken(aLocalName, XML_NOTIFY_ON_UPDATE_OF_RANGES))
141 29 : pRangeList = new OUString(rValue);
142 : }
143 904 : }
144 84 : SetLayer(rShape, nLayerID, rShape->getShapeType());
145 :
146 84 : if (SvxShape* pShapeImp = SvxShape::getImplementation(rShape))
147 : {
148 84 : if (SdrObject *pSdrObj = pShapeImp->GetSdrObject())
149 : {
150 84 : if (!bOnTable)
151 54 : ScDrawLayer::SetCellAnchored(*pSdrObj, aAnchor);
152 : else
153 30 : ScDrawLayer::SetPageAnchored(*pSdrObj);
154 : }
155 : }
156 :
157 84 : if (pRangeList)
158 : {
159 : // #i78086# If there are notification ranges, the ChartListener must be created
160 : // also when anchored to the sheet
161 : // -> call AddOLE with invalid cell position (checked in ScMyShapeResizer::ResizeShapes)
162 :
163 29 : if (rTables.IsOLE(rShape))
164 29 : rTables.AddOLE(rShape, *pRangeList);
165 : }
166 :
167 84 : delete pRangeList;
168 : }
169 : else // shape is annotation
170 : {
171 : // get the style names for stream copying
172 15 : OUString aStyleName;
173 30 : OUString aTextStyle;
174 15 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
175 103 : for( sal_Int16 i=0; i < nAttrCount; ++i )
176 : {
177 88 : const OUString& rAttrName(xAttrList->getNameByIndex( i ));
178 176 : OUString aLocalName;
179 88 : sal_uInt16 nPrefix(static_cast<ScXMLImport&>(mrImporter).GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName ));
180 88 : if(nPrefix == XML_NAMESPACE_DRAW)
181 : {
182 40 : if (IsXMLToken(aLocalName, XML_STYLE_NAME))
183 10 : aStyleName = xAttrList->getValueByIndex( i );
184 30 : else if (IsXMLToken(aLocalName, XML_TEXT_STYLE_NAME))
185 10 : aTextStyle = xAttrList->getValueByIndex( i );
186 : }
187 88 : }
188 :
189 15 : pAnnotationContext->SetShape(rShape, rShapes, aStyleName, aTextStyle);
190 30 : bNote = true;
191 : }
192 : }
193 : else //this are grouped shapes which should also get the layerid
194 : {
195 10 : uno::Reference< drawing::XShapes > xGroup( rShape, uno::UNO_QUERY );
196 : // ignore the group ( within group ) object it it exists
197 10 : if ( !bOnTable && !xGroup.is() )
198 : {
199 : // For cell anchored grouped shape we need to set the start
200 : // position from the most top and left positioned shape(s) within
201 : // the group
202 10 : Point aStartPoint( rShape->getPosition().X,rShape->getPosition().Y );
203 10 : uno::Reference< drawing::XShape > xChild( rShapes, uno::UNO_QUERY );
204 10 : if (SvxShape* pGroupShapeImp = SvxShape::getImplementation( lcl_getTopLevelParent( xChild ) ))
205 : {
206 10 : if (SdrObject *pSdrObj = pGroupShapeImp->GetSdrObject())
207 : {
208 10 : if ( ScDrawObjData* pAnchor = ScDrawLayer::GetObjData( pSdrObj ) )
209 : {
210 10 : if ( pAnchor->maStartOffset.getX() == 0 && pAnchor->maStartOffset.getY() == 0 )
211 5 : pAnchor->maStartOffset = aStartPoint;
212 10 : if ( aStartPoint.getX() < pAnchor->maStartOffset.getX() )
213 0 : pAnchor->maStartOffset.setX( aStartPoint.getX() );
214 10 : if ( aStartPoint.getY() < pAnchor->maStartOffset.getY() )
215 0 : pAnchor->maStartOffset.setY( aStartPoint.getY() );
216 : }
217 : }
218 10 : }
219 : }
220 10 : sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
221 10 : sal_Int16 nLayerID(-1);
222 70 : for( sal_Int16 i=0; i < nAttrCount; ++i )
223 : {
224 60 : const OUString& rAttrName(xAttrList->getNameByIndex( i ));
225 120 : const OUString& rValue(xAttrList->getValueByIndex( i ));
226 :
227 120 : OUString aLocalName;
228 60 : sal_uInt16 nPrefix(static_cast<ScXMLImport&>(mrImporter).GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName ));
229 60 : if(nPrefix == XML_NAMESPACE_TABLE)
230 : {
231 0 : if (IsXMLToken(aLocalName, XML_TABLE_BACKGROUND))
232 0 : if (IsXMLToken(rValue, XML_TRUE))
233 0 : nLayerID = SC_LAYER_BACK;
234 : }
235 60 : }
236 10 : SetLayer(rShape, nLayerID, rShape->getShapeType());
237 : }
238 :
239 109 : if (!bNote)
240 : {
241 : // any shape other than a note prevents copying the sheet
242 94 : ScSheetSaveData* pSheetData = ScModelObj::getImplementation(mrImporter.GetModel())->GetSheetSaveData();
243 94 : pSheetData->BlockSheet( rTables.GetCurrentSheet() );
244 : }
245 :
246 109 : static_cast<ScXMLImport&>(mrImporter).UnlockSolarMutex();
247 109 : }
248 :
249 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|