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