LCOV - code coverage report
Current view: top level - sc/source/filter/xml - XMLTableShapeImportHelper.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 114 120 95.0 %
Date: 2014-11-03 Functions: 8 8 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10