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

Generated by: LCOV version 1.10