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