LCOV - code coverage report
Current view: top level - xmloff/source/draw - shapeimport.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 301 407 74.0 %
Date: 2014-04-11 Functions: 39 49 79.6 %
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 <tools/debug.hxx>
      21             : 
      22             : #include <com/sun/star/text/PositionLayoutDir.hpp>
      23             : #include <com/sun/star/chart/XChartDocument.hpp>
      24             : 
      25             : #include <xmloff/unointerfacetouniqueidentifiermapper.hxx>
      26             : 
      27             : #include <list>
      28             : 
      29             : #include <xmloff/shapeimport.hxx>
      30             : #include <xmloff/xmltkmap.hxx>
      31             : #include <xmloff/xmlnmspe.hxx>
      32             : #include <xmloff/xmltoken.hxx>
      33             : #include "ximpstyl.hxx"
      34             : #include "ximpshap.hxx"
      35             : #include "sdpropls.hxx"
      36             : #include <xmloff/xmlprmap.hxx>
      37             : #include "ximp3dscene.hxx"
      38             : #include "ximp3dobject.hxx"
      39             : #include "ximpgrp.hxx"
      40             : #include "ximplink.hxx"
      41             : 
      42             : #include <map>
      43             : #include <vector>
      44             : 
      45             : using namespace ::std;
      46             : using namespace ::com::sun::star;
      47             : using namespace ::xmloff::token;
      48             : 
      49             : struct ltint32
      50             : {
      51         630 :   bool operator()(const sal_Int32 p, sal_Int32 q) const
      52             :   {
      53         630 :     return p < q;
      54             :   }
      55             : };
      56             : 
      57             : typedef std::map<sal_Int32,com::sun::star::uno::Reference< com::sun::star::drawing::XShape >,ltint32> IdShapeMap;
      58             : 
      59          10 : struct ConnectionHint
      60             : {
      61             :     com::sun::star::uno::Reference< com::sun::star::drawing::XShape > mxConnector;
      62             :     bool      bStart;
      63             :     OUString  aDestShapeId;
      64             :     sal_Int32 nDestGlueId;
      65             : };
      66             : 
      67             : struct XShapeCompareHelper
      68             : {
      69         860 :   bool operator()(com::sun::star::uno::Reference < com::sun::star::drawing::XShape > x1,
      70             :                   com::sun::star::uno::Reference < com::sun::star::drawing::XShape > x2 ) const
      71             :   {
      72         860 :     return x1.get() < x2.get();
      73             :   }
      74             : };
      75             : 
      76             : /** this map store all glue point id mappings for shapes that had user defined glue points. This
      77             :     is needed because on insertion the glue points will get a new and unique id */
      78             : typedef std::map<sal_Int32,sal_Int32,ltint32> GluePointIdMap;
      79             : typedef std::map< com::sun::star::uno::Reference < com::sun::star::drawing::XShape >, GluePointIdMap, XShapeCompareHelper > ShapeGluePointsMap;
      80             : 
      81             : /** this struct is created for each startPage() call and stores information that is needed during
      82             :     import of shapes for one page. Since pages could be nested ( notes pages inside impress ) there
      83             :     is a pointer so one can build up a stack of this structs */
      84         800 : struct XMLShapeImportPageContextImpl
      85             : {
      86             :     ShapeGluePointsMap      maShapeGluePointsMap;
      87             : 
      88             :     uno::Reference < drawing::XShapes > mxShapes;
      89             : 
      90             :     struct XMLShapeImportPageContextImpl* mpNext;
      91             : };
      92             : 
      93             : /** this class is to enable adding members to the XMLShapeImportHelper without getting incompatible */
      94        1310 : struct XMLShapeImportHelperImpl
      95             : {
      96             :     // context for sorting shapes
      97             :     ShapeSortContext*           mpSortContext;
      98             : 
      99             :     IdShapeMap                  maShapeIds;
     100             : 
     101             :     std::vector<ConnectionHint> maConnections;
     102             : 
     103             :     // #88546# possibility to swich progress bar handling on/off
     104             :     bool                        mbHandleProgressBar;
     105             : 
     106             :     // stores the capability of the current model to create presentation shapes
     107             :     bool                        mbIsPresentationShapesSupported;
     108             : };
     109             : 
     110         655 : XMLShapeImportHelper::XMLShapeImportHelper(
     111             :         SvXMLImport& rImporter,
     112             :         const uno::Reference< frame::XModel>& rModel,
     113             :         SvXMLImportPropertyMapper *pExtMapper )
     114             : :   mpPageContext(NULL),
     115             :     mxModel(rModel),
     116             : 
     117             :     mpPropertySetMapper(0L),
     118             :     mpPresPagePropsMapper(0L),
     119             :     mpStylesContext(0L),
     120             :     mpAutoStylesContext(0L),
     121             :     mpGroupShapeElemTokenMap(0L),
     122             :     mpFrameShapeElemTokenMap(0L),
     123             :     mp3DSceneShapeElemTokenMap(0L),
     124             :     mp3DObjectAttrTokenMap(0L),
     125             :     mp3DPolygonBasedAttrTokenMap(0L),
     126             :     mp3DCubeObjectAttrTokenMap(0L),
     127             :     mp3DSphereObjectAttrTokenMap(0L),
     128             :     mp3DSceneShapeAttrTokenMap(0L),
     129             :     mp3DLightAttrTokenMap(0L),
     130             :     mpPathShapeAttrTokenMap(0L),
     131             :     mpPolygonShapeAttrTokenMap(0L),
     132             :     msStartShape("StartShape"),
     133             :     msEndShape("EndShape"),
     134             :     msStartGluePointIndex("StartGluePointIndex"),
     135             :     msEndGluePointIndex("EndGluePointIndex"),
     136             : 
     137         655 :     mrImporter( rImporter )
     138             : {
     139         655 :     mpImpl = new XMLShapeImportHelperImpl();
     140         655 :     mpImpl->mpSortContext = 0;
     141             : 
     142             :     // #88546# init to sal_False
     143         655 :     mpImpl->mbHandleProgressBar = false;
     144             : 
     145         655 :     mpSdPropHdlFactory = new XMLSdPropHdlFactory( rModel, rImporter );
     146             : 
     147             :     // set lock to avoid deletion
     148         655 :     mpSdPropHdlFactory->acquire();
     149             : 
     150             :     // construct PropertySetMapper
     151         655 :     UniReference < XMLPropertySetMapper > xMapper = new XMLShapePropertySetMapper(mpSdPropHdlFactory, false);
     152         655 :     mpPropertySetMapper = new SvXMLImportPropertyMapper( xMapper, rImporter );
     153             :     // set lock to avoid deletion
     154         655 :     mpPropertySetMapper->acquire();
     155             : 
     156         655 :     if( pExtMapper )
     157             :     {
     158         264 :         UniReference < SvXMLImportPropertyMapper > xExtMapper( pExtMapper );
     159         264 :         mpPropertySetMapper->ChainImportMapper( xExtMapper );
     160             :     }
     161             : 
     162             :     // chain text attributes
     163         655 :     mpPropertySetMapper->ChainImportMapper(XMLTextImportHelper::CreateParaExtPropMapper(rImporter));
     164         655 :     mpPropertySetMapper->ChainImportMapper(XMLTextImportHelper::CreateParaDefaultExtPropMapper(rImporter));
     165             : 
     166             :     // construct PresPagePropsMapper
     167         655 :     xMapper = new XMLPropertySetMapper((XMLPropertyMapEntry*)aXMLSDPresPageProps, mpSdPropHdlFactory, false);
     168         655 :     mpPresPagePropsMapper = new SvXMLImportPropertyMapper( xMapper, rImporter );
     169         655 :     if(mpPresPagePropsMapper)
     170             :     {
     171             :         // set lock to avoid deletion
     172         655 :         mpPresPagePropsMapper->acquire();
     173             :     }
     174             : 
     175        1310 :     uno::Reference< lang::XServiceInfo > xInfo( rImporter.GetModel(), uno::UNO_QUERY );
     176        1310 :     const OUString aSName( "com.sun.star.presentation.PresentationDocument" );
     177        1310 :     mpImpl->mbIsPresentationShapesSupported = xInfo.is() && xInfo->supportsService( aSName );
     178         655 : }
     179             : 
     180        1487 : XMLShapeImportHelper::~XMLShapeImportHelper()
     181             : {
     182             :     DBG_ASSERT( mpImpl->maConnections.empty(), "XMLShapeImportHelper::restoreConnections() was not called!" );
     183             : 
     184             :     // cleanup factory, decrease refcount. Should lead to destruction.
     185         655 :     if(mpSdPropHdlFactory)
     186             :     {
     187         655 :         mpSdPropHdlFactory->release();
     188         655 :         mpSdPropHdlFactory = 0L;
     189             :     }
     190             : 
     191             :     // cleanup mapper, decrease refcount. Should lead to destruction.
     192         655 :     if(mpPropertySetMapper)
     193             :     {
     194         655 :         mpPropertySetMapper->release();
     195         655 :         mpPropertySetMapper = 0L;
     196             :     }
     197             : 
     198             :     // cleanup presPage mapper, decrease refcount. Should lead to destruction.
     199         655 :     if(mpPresPagePropsMapper)
     200             :     {
     201         655 :         mpPresPagePropsMapper->release();
     202         655 :         mpPresPagePropsMapper = 0L;
     203             :     }
     204             : 
     205         655 :     if(mpGroupShapeElemTokenMap) delete mpGroupShapeElemTokenMap;
     206         655 :     if(mpFrameShapeElemTokenMap) delete mpFrameShapeElemTokenMap;
     207             : 
     208         655 :     if(mpPolygonShapeAttrTokenMap) delete mpPolygonShapeAttrTokenMap;
     209         655 :     if(mpPathShapeAttrTokenMap) delete mpPathShapeAttrTokenMap;
     210         655 :     if(mp3DSceneShapeElemTokenMap) delete mp3DSceneShapeElemTokenMap;
     211         655 :     if(mp3DObjectAttrTokenMap) delete mp3DObjectAttrTokenMap;
     212         655 :     if(mp3DPolygonBasedAttrTokenMap) delete mp3DPolygonBasedAttrTokenMap;
     213         655 :     if(mp3DCubeObjectAttrTokenMap) delete mp3DCubeObjectAttrTokenMap;
     214         655 :     if(mp3DSphereObjectAttrTokenMap) delete mp3DSphereObjectAttrTokenMap;
     215         655 :     if(mp3DSceneShapeAttrTokenMap) delete mp3DSceneShapeAttrTokenMap;
     216         655 :     if(mp3DLightAttrTokenMap) delete mp3DLightAttrTokenMap;
     217             : 
     218             :     // Styles or AutoStyles context?
     219         655 :     if(mpStylesContext)
     220             :     {
     221          34 :         mpStylesContext->Clear();
     222          34 :         mpStylesContext->ReleaseRef();
     223             :     }
     224             : 
     225         655 :     if(mpAutoStylesContext)
     226             :     {
     227         623 :         mpAutoStylesContext->Clear();
     228         623 :         mpAutoStylesContext->ReleaseRef();
     229             :     }
     230             : 
     231         655 :     delete mpImpl;
     232         832 : }
     233             : 
     234         582 : const SvXMLTokenMap& XMLShapeImportHelper::GetGroupShapeElemTokenMap()
     235             : {
     236         582 :     if(!mpGroupShapeElemTokenMap)
     237             :     {
     238             :         static const SvXMLTokenMapEntry aGroupShapeElemTokenMap[] =
     239             : {
     240             :     { XML_NAMESPACE_DRAW,           XML_G,              XML_TOK_GROUP_GROUP         },
     241             :     { XML_NAMESPACE_DRAW,           XML_RECT,           XML_TOK_GROUP_RECT          },
     242             :     { XML_NAMESPACE_DRAW,           XML_LINE,           XML_TOK_GROUP_LINE          },
     243             :     { XML_NAMESPACE_DRAW,           XML_CIRCLE,         XML_TOK_GROUP_CIRCLE        },
     244             :     { XML_NAMESPACE_DRAW,           XML_ELLIPSE,        XML_TOK_GROUP_ELLIPSE       },
     245             :     { XML_NAMESPACE_DRAW,           XML_POLYGON,        XML_TOK_GROUP_POLYGON       },
     246             :     { XML_NAMESPACE_DRAW,           XML_POLYLINE,       XML_TOK_GROUP_POLYLINE      },
     247             :     { XML_NAMESPACE_DRAW,           XML_PATH,           XML_TOK_GROUP_PATH          },
     248             : 
     249             :     { XML_NAMESPACE_DRAW,           XML_CONTROL,        XML_TOK_GROUP_CONTROL       },
     250             :     { XML_NAMESPACE_DRAW,           XML_CONNECTOR,      XML_TOK_GROUP_CONNECTOR     },
     251             :     { XML_NAMESPACE_DRAW,           XML_MEASURE,        XML_TOK_GROUP_MEASURE       },
     252             :     { XML_NAMESPACE_DRAW,           XML_PAGE_THUMBNAIL, XML_TOK_GROUP_PAGE          },
     253             :     { XML_NAMESPACE_DRAW,           XML_CAPTION,        XML_TOK_GROUP_CAPTION       },
     254             : 
     255             :     { XML_NAMESPACE_CHART,          XML_CHART,          XML_TOK_GROUP_CHART         },
     256             :     { XML_NAMESPACE_DR3D,           XML_SCENE,          XML_TOK_GROUP_3DSCENE       },
     257             : 
     258             :     { XML_NAMESPACE_DRAW,           XML_FRAME,          XML_TOK_GROUP_FRAME         },
     259             :     { XML_NAMESPACE_DRAW,           XML_CUSTOM_SHAPE,   XML_TOK_GROUP_CUSTOM_SHAPE  },
     260             : 
     261             :     { XML_NAMESPACE_DRAW,           XML_CUSTOM_SHAPE,   XML_TOK_GROUP_CUSTOM_SHAPE  },
     262             :     { XML_NAMESPACE_OFFICE,         XML_ANNOTATION,     XML_TOK_GROUP_ANNOTATION    },
     263             :     { XML_NAMESPACE_DRAW,           XML_A,              XML_TOK_GROUP_A             },
     264             : 
     265             :     XML_TOKEN_MAP_END
     266             : };
     267             : 
     268         100 :         mpGroupShapeElemTokenMap = new SvXMLTokenMap(aGroupShapeElemTokenMap);
     269             :     } // if(!mpGroupShapeElemTokenMap)
     270             : 
     271         582 :     return *mpGroupShapeElemTokenMap;
     272             : }
     273             : 
     274         268 : const SvXMLTokenMap& XMLShapeImportHelper::GetFrameShapeElemTokenMap()
     275             : {
     276         268 :     if(!mpFrameShapeElemTokenMap)
     277             :     {
     278             :         static const SvXMLTokenMapEntry aFrameShapeElemTokenMap[] =
     279             : {
     280             :     { XML_NAMESPACE_DRAW,           XML_TEXT_BOX,       XML_TOK_FRAME_TEXT_BOX      },
     281             :     { XML_NAMESPACE_DRAW,           XML_IMAGE,          XML_TOK_FRAME_IMAGE         },
     282             :     { XML_NAMESPACE_DRAW,           XML_OBJECT,         XML_TOK_FRAME_OBJECT        },
     283             :     { XML_NAMESPACE_DRAW,           XML_OBJECT_OLE,     XML_TOK_FRAME_OBJECT_OLE    },
     284             :     { XML_NAMESPACE_DRAW,           XML_PLUGIN,         XML_TOK_FRAME_PLUGIN        },
     285             :     { XML_NAMESPACE_DRAW,           XML_FLOATING_FRAME, XML_TOK_FRAME_FLOATING_FRAME},
     286             :     { XML_NAMESPACE_DRAW,           XML_APPLET,         XML_TOK_FRAME_APPLET        },
     287             :     { XML_NAMESPACE_TABLE,          XML_TABLE,          XML_TOK_FRAME_TABLE         },
     288             :     XML_TOKEN_MAP_END
     289             : };
     290             : 
     291          53 :         mpFrameShapeElemTokenMap = new SvXMLTokenMap(aFrameShapeElemTokenMap);
     292             :     } // if(!mpFrameShapeElemTokenMap)
     293             : 
     294         268 :     return *mpFrameShapeElemTokenMap;
     295             : }
     296             : 
     297           0 : const SvXMLTokenMap& XMLShapeImportHelper::Get3DSceneShapeElemTokenMap()
     298             : {
     299           0 :     if(!mp3DSceneShapeElemTokenMap)
     300             :     {
     301             :         static const SvXMLTokenMapEntry a3DSceneShapeElemTokenMap[] =
     302             : {
     303             :     { XML_NAMESPACE_DR3D,           XML_SCENE,      XML_TOK_3DSCENE_3DSCENE     },
     304             :     { XML_NAMESPACE_DR3D,           XML_CUBE,       XML_TOK_3DSCENE_3DCUBE      },
     305             :     { XML_NAMESPACE_DR3D,           XML_SPHERE,     XML_TOK_3DSCENE_3DSPHERE    },
     306             :     { XML_NAMESPACE_DR3D,           XML_ROTATE,     XML_TOK_3DSCENE_3DLATHE     },
     307             :     { XML_NAMESPACE_DR3D,           XML_EXTRUDE,    XML_TOK_3DSCENE_3DEXTRUDE   },
     308             :     XML_TOKEN_MAP_END
     309             : };
     310             : 
     311           0 :         mp3DSceneShapeElemTokenMap = new SvXMLTokenMap(a3DSceneShapeElemTokenMap);
     312             :     } // if(!mp3DSceneShapeElemTokenMap)
     313             : 
     314           0 :     return *mp3DSceneShapeElemTokenMap;
     315             : }
     316             : 
     317           0 : const SvXMLTokenMap& XMLShapeImportHelper::Get3DObjectAttrTokenMap()
     318             : {
     319           0 :     if(!mp3DObjectAttrTokenMap)
     320             :     {
     321             :         static const SvXMLTokenMapEntry a3DObjectAttrTokenMap[] =
     322             : {
     323             :     { XML_NAMESPACE_DRAW,           XML_STYLE_NAME,         XML_TOK_3DOBJECT_DRAWSTYLE_NAME     },
     324             :     { XML_NAMESPACE_DR3D,           XML_TRANSFORM,          XML_TOK_3DOBJECT_TRANSFORM          },
     325             :     XML_TOKEN_MAP_END
     326             : };
     327             : 
     328           0 :         mp3DObjectAttrTokenMap = new SvXMLTokenMap(a3DObjectAttrTokenMap);
     329             :     } // if(!mp3DObjectAttrTokenMap)
     330             : 
     331           0 :     return *mp3DObjectAttrTokenMap;
     332             : }
     333             : 
     334           0 : const SvXMLTokenMap& XMLShapeImportHelper::Get3DPolygonBasedAttrTokenMap()
     335             : {
     336           0 :     if(!mp3DPolygonBasedAttrTokenMap)
     337             :     {
     338             :         static const SvXMLTokenMapEntry a3DPolygonBasedAttrTokenMap[] =
     339             : {
     340             :     { XML_NAMESPACE_SVG,            XML_VIEWBOX,            XML_TOK_3DPOLYGONBASED_VIEWBOX      },
     341             :     { XML_NAMESPACE_SVG,            XML_D,                  XML_TOK_3DPOLYGONBASED_D            },
     342             :     XML_TOKEN_MAP_END
     343             : };
     344             : 
     345           0 :         mp3DPolygonBasedAttrTokenMap = new SvXMLTokenMap(a3DPolygonBasedAttrTokenMap);
     346             :     } // if(!mp3DPolygonBasedAttrTokenMap)
     347             : 
     348           0 :     return *mp3DPolygonBasedAttrTokenMap;
     349             : }
     350             : 
     351           0 : const SvXMLTokenMap& XMLShapeImportHelper::Get3DCubeObjectAttrTokenMap()
     352             : {
     353           0 :     if(!mp3DCubeObjectAttrTokenMap)
     354             :     {
     355             :         static const SvXMLTokenMapEntry a3DCubeObjectAttrTokenMap[] =
     356             : {
     357             :     { XML_NAMESPACE_DR3D,           XML_MIN_EDGE,           XML_TOK_3DCUBEOBJ_MINEDGE   },
     358             :     { XML_NAMESPACE_DR3D,           XML_MAX_EDGE,           XML_TOK_3DCUBEOBJ_MAXEDGE   },
     359             :     XML_TOKEN_MAP_END
     360             : };
     361             : 
     362           0 :         mp3DCubeObjectAttrTokenMap = new SvXMLTokenMap(a3DCubeObjectAttrTokenMap);
     363             :     } // if(!mp3DCubeObjectAttrTokenMap)
     364             : 
     365           0 :     return *mp3DCubeObjectAttrTokenMap;
     366             : }
     367             : 
     368           0 : const SvXMLTokenMap& XMLShapeImportHelper::Get3DSphereObjectAttrTokenMap()
     369             : {
     370           0 :     if(!mp3DSphereObjectAttrTokenMap)
     371             :     {
     372             :         static const SvXMLTokenMapEntry a3DSphereObjectAttrTokenMap[] =
     373             : {
     374             :     { XML_NAMESPACE_DR3D,           XML_CENTER,             XML_TOK_3DSPHEREOBJ_CENTER  },
     375             :     { XML_NAMESPACE_DR3D,           XML_SIZE,               XML_TOK_3DSPHEREOBJ_SIZE    },
     376             :     XML_TOKEN_MAP_END
     377             : };
     378             : 
     379           0 :         mp3DSphereObjectAttrTokenMap = new SvXMLTokenMap(a3DSphereObjectAttrTokenMap);
     380             :     } // if(!mp3DSphereObjectAttrTokenMap)
     381             : 
     382           0 :     return *mp3DSphereObjectAttrTokenMap;
     383             : }
     384             : 
     385         864 : const SvXMLTokenMap& XMLShapeImportHelper::Get3DLightAttrTokenMap()
     386             : {
     387         864 :     if(!mp3DLightAttrTokenMap)
     388             :     {
     389             :         static const SvXMLTokenMapEntry a3DLightAttrTokenMap[] =
     390             : {
     391             :     { XML_NAMESPACE_DR3D,   XML_DIFFUSE_COLOR,      XML_TOK_3DLIGHT_DIFFUSE_COLOR       },
     392             :     { XML_NAMESPACE_DR3D,   XML_DIRECTION,          XML_TOK_3DLIGHT_DIRECTION           },
     393             :     { XML_NAMESPACE_DR3D,   XML_ENABLED,            XML_TOK_3DLIGHT_ENABLED             },
     394             :     { XML_NAMESPACE_DR3D,   XML_SPECULAR,           XML_TOK_3DLIGHT_SPECULAR            },
     395             :     XML_TOKEN_MAP_END
     396             : };
     397             : 
     398          27 :         mp3DLightAttrTokenMap = new SvXMLTokenMap(a3DLightAttrTokenMap);
     399             :     } // if(!mp3DLightAttrTokenMap)
     400             : 
     401         864 :     return *mp3DLightAttrTokenMap;
     402             : }
     403             : 
     404           0 : SvXMLShapeContext* XMLShapeImportHelper::Create3DSceneChildContext(
     405             :     SvXMLImport& rImport,
     406             :     sal_uInt16 p_nPrefix,
     407             :     const OUString& rLocalName,
     408             :     const uno::Reference< xml::sax::XAttributeList>& xAttrList,
     409             :     uno::Reference< drawing::XShapes >& rShapes)
     410             : {
     411           0 :     SdXMLShapeContext *pContext = 0L;
     412             : 
     413           0 :     if(rShapes.is())
     414             :     {
     415           0 :         const SvXMLTokenMap& rTokenMap = Get3DSceneShapeElemTokenMap();
     416           0 :         switch(rTokenMap.Get(p_nPrefix, rLocalName))
     417             :         {
     418             :             case XML_TOK_3DSCENE_3DSCENE:
     419             :             {
     420             :                 // dr3d:3dscene inside dr3d:3dscene context
     421           0 :                 pContext = new SdXML3DSceneShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, sal_False);
     422           0 :                 break;
     423             :             }
     424             :             case XML_TOK_3DSCENE_3DCUBE:
     425             :             {
     426             :                 // dr3d:3dcube inside dr3d:3dscene context
     427           0 :                 pContext = new SdXML3DCubeObjectShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, sal_False);
     428           0 :                 break;
     429             :             }
     430             :             case XML_TOK_3DSCENE_3DSPHERE:
     431             :             {
     432             :                 // dr3d:3dsphere inside dr3d:3dscene context
     433           0 :                 pContext = new SdXML3DSphereObjectShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, sal_False);
     434           0 :                 break;
     435             :             }
     436             :             case XML_TOK_3DSCENE_3DLATHE:
     437             :             {
     438             :                 // dr3d:3dlathe inside dr3d:3dscene context
     439           0 :                 pContext = new SdXML3DLatheObjectShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, sal_False);
     440           0 :                 break;
     441             :             }
     442             :             case XML_TOK_3DSCENE_3DEXTRUDE:
     443             :             {
     444             :                 // dr3d:3dextrude inside dr3d:3dscene context
     445           0 :                 pContext = new SdXML3DExtrudeObjectShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, sal_False);
     446           0 :                 break;
     447             :             }
     448             :         }
     449             :     }
     450             : 
     451             :     // now parse the attribute list and call the child context for each unknown attribute
     452           0 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
     453           0 :     for(sal_Int16 a(0); a < nAttrCount; a++)
     454             :     {
     455           0 :         const OUString& rAttrName = xAttrList->getNameByIndex(a);
     456           0 :         OUString aLocalName;
     457           0 :         sal_uInt16 nPrefix = rImport.GetNamespaceMap().GetKeyByAttrName(rAttrName, &aLocalName);
     458           0 :         const OUString aValue( xAttrList->getValueByIndex(a) );
     459             : 
     460           0 :         pContext->processAttribute( nPrefix, aLocalName, aValue );
     461           0 :     }
     462             : 
     463           0 :     return pContext;
     464             : }
     465             : 
     466          34 : void XMLShapeImportHelper::SetStylesContext(SvXMLStylesContext* pNew)
     467             : {
     468          34 :     mpStylesContext = pNew;
     469          34 :     if (mpStylesContext)
     470          34 :         mpStylesContext->AddRef();
     471          34 : }
     472             : 
     473         623 : void XMLShapeImportHelper::SetAutoStylesContext(SvXMLStylesContext* pNew)
     474             : {
     475         623 :     mpAutoStylesContext = pNew;
     476         623 :     if (mpAutoStylesContext)
     477         623 :         mpAutoStylesContext->AddRef();
     478         623 : }
     479             : 
     480         582 : SvXMLShapeContext* XMLShapeImportHelper::CreateGroupChildContext(
     481             :     SvXMLImport& rImport,
     482             :     sal_uInt16 p_nPrefix,
     483             :     const OUString& rLocalName,
     484             :     const uno::Reference< xml::sax::XAttributeList>& xAttrList,
     485             :     uno::Reference< drawing::XShapes >& rShapes,
     486             :     bool bTemporaryShape)
     487             : {
     488         582 :     SdXMLShapeContext *pContext = 0L;
     489             : 
     490         582 :     const SvXMLTokenMap& rTokenMap = GetGroupShapeElemTokenMap();
     491         582 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
     492             : 
     493         582 :     switch(rTokenMap.Get(p_nPrefix, rLocalName))
     494             :     {
     495             :         case XML_TOK_GROUP_GROUP:
     496             :         {
     497             :             // draw:g inside group context (RECURSIVE)
     498          11 :             pContext = new SdXMLGroupShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, bTemporaryShape);
     499          11 :             break;
     500             :         }
     501             :         case XML_TOK_GROUP_3DSCENE:
     502             :         {
     503             :             // dr3d:3dscene inside group context
     504           0 :             pContext = new SdXML3DSceneShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, bTemporaryShape);
     505           0 :             break;
     506             :         }
     507             :         case XML_TOK_GROUP_RECT:
     508             :         {
     509             :             // draw:rect inside group context
     510          27 :             pContext = new SdXMLRectShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, bTemporaryShape );
     511          27 :             break;
     512             :         }
     513             :         case XML_TOK_GROUP_LINE:
     514             :         {
     515             :             // draw:line inside group context
     516          21 :             pContext = new SdXMLLineShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, bTemporaryShape );
     517          21 :             break;
     518             :         }
     519             :         case XML_TOK_GROUP_CIRCLE:
     520             :         case XML_TOK_GROUP_ELLIPSE:
     521             :         {
     522             :             // draw:circle or draw:ellipse inside group context
     523          13 :             pContext = new SdXMLEllipseShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, bTemporaryShape );
     524          13 :             break;
     525             :         }
     526             :         case XML_TOK_GROUP_POLYGON:
     527             :         case XML_TOK_GROUP_POLYLINE:
     528             :         {
     529             :             // draw:polygon or draw:polyline inside group context
     530             :             pContext = new SdXMLPolygonShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes,
     531           5 :                 rTokenMap.Get(p_nPrefix, rLocalName) == XML_TOK_GROUP_POLYGON ? sal_True : sal_False, bTemporaryShape );
     532           5 :             break;
     533             :         }
     534             :         case XML_TOK_GROUP_PATH:
     535             :         {
     536             :             // draw:path inside group context
     537           9 :             pContext = new SdXMLPathShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, bTemporaryShape);
     538           9 :             break;
     539             :         }
     540             :         case XML_TOK_GROUP_FRAME:
     541             :         {
     542             :             // text:text-box inside group context
     543         264 :             pContext = new SdXMLFrameShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, bTemporaryShape );
     544         264 :             break;
     545             :         }
     546             :         case XML_TOK_GROUP_CONTROL:
     547             :         {
     548             :             // draw:control inside group context
     549          29 :             pContext = new SdXMLControlShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, bTemporaryShape );
     550          29 :             break;
     551             :         }
     552             :         case XML_TOK_GROUP_CONNECTOR:
     553             :         {
     554             :             // draw:connector inside group context
     555           1 :             pContext = new SdXMLConnectorShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, bTemporaryShape );
     556           1 :             break;
     557             :         }
     558             :         case XML_TOK_GROUP_MEASURE:
     559             :         {
     560             :             // draw:measure inside group context
     561           1 :             pContext = new SdXMLMeasureShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, bTemporaryShape );
     562           1 :             break;
     563             :         }
     564             :         case XML_TOK_GROUP_PAGE:
     565             :         {
     566             :             // draw:page inside group context
     567         107 :             pContext = new SdXMLPageShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, bTemporaryShape );
     568         107 :             break;
     569             :         }
     570             :         case XML_TOK_GROUP_CAPTION:
     571             :         case XML_TOK_GROUP_ANNOTATION:
     572             :         {
     573             :             // draw:caption inside group context
     574          15 :             pContext = new SdXMLCaptionShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, bTemporaryShape );
     575          15 :             break;
     576             :         }
     577             :         case XML_TOK_GROUP_CHART:
     578             :         {
     579             :             // chart:chart inside group context
     580           0 :             pContext = new SdXMLChartShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, bTemporaryShape );
     581           0 :             break;
     582             :         }
     583             :         case XML_TOK_GROUP_CUSTOM_SHAPE:
     584             :         {
     585             :             // draw:customshape
     586          69 :             pContext = new SdXMLCustomShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, sal_False );
     587          69 :             break;
     588             :         }
     589             :          case XML_TOK_GROUP_A:
     590             :          {
     591           0 :              return new SdXMLShapeLinkContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes );
     592             :          }
     593             :         // add other shapes here...
     594             :         default:
     595          10 :             return new SvXMLShapeContext( rImport, p_nPrefix, rLocalName, bTemporaryShape );
     596             :     }
     597             : 
     598             :     // now parse the attribute list and call the child context for each unknown attribute
     599        4754 :     for(sal_Int16 a(0); a < nAttrCount; a++)
     600             :     {
     601        4182 :         const OUString& rAttrName = xAttrList->getNameByIndex(a);
     602        8364 :         OUString aLocalName;
     603        4182 :         sal_uInt16 nPrefix = rImport.GetNamespaceMap().GetKeyByAttrName(rAttrName, &aLocalName);
     604        8364 :         const OUString aValue( xAttrList->getValueByIndex(a) );
     605             : 
     606        4182 :         pContext->processAttribute( nPrefix, aLocalName, aValue );
     607        4182 :     }
     608             : 
     609         572 :     return pContext;
     610             : }
     611             : 
     612             : // This method is called from SdXMLFrameContext to create children of drawe:frame
     613         268 : SvXMLShapeContext* XMLShapeImportHelper::CreateFrameChildContext(
     614             :     SvXMLImport& rImport,
     615             :     sal_uInt16 p_nPrefix,
     616             :     const OUString& rLocalName,
     617             :     const uno::Reference< xml::sax::XAttributeList>& rAttrList,
     618             :     uno::Reference< drawing::XShapes >& rShapes,
     619             :     const uno::Reference< xml::sax::XAttributeList>& rFrameAttrList)
     620             : {
     621         268 :     SdXMLShapeContext *pContext = 0L;
     622             : 
     623         268 :     const SvXMLTokenMap& rTokenMap = GetFrameShapeElemTokenMap();
     624             : 
     625         268 :     SvXMLAttributeList *pAttrList = new SvXMLAttributeList( rAttrList );
     626         268 :     if( rFrameAttrList.is() )
     627         268 :         pAttrList->AppendAttributeList( rFrameAttrList );
     628         268 :     uno::Reference < xml::sax::XAttributeList > xAttrList = pAttrList;
     629             : 
     630         268 :     switch(rTokenMap.Get(p_nPrefix, rLocalName))
     631             :     {
     632             :         case XML_TOK_FRAME_TEXT_BOX:
     633             :         {
     634             :             // text:text-box inside group context
     635         214 :             pContext = new SdXMLTextBoxShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, sal_False );
     636         214 :             break;
     637             :         }
     638             :         case XML_TOK_FRAME_IMAGE:
     639             :         {
     640             :             // office:image inside group context
     641          12 :             pContext = new SdXMLGraphicObjectShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, sal_False );
     642          12 :             break;
     643             :         }
     644             :         case XML_TOK_FRAME_OBJECT:
     645             :         case XML_TOK_FRAME_OBJECT_OLE:
     646             :         {
     647             :             // draw:object or draw:object_ole
     648          35 :             pContext = new SdXMLObjectShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, sal_False );
     649          35 :             break;
     650             :         }
     651             :         case XML_TOK_FRAME_TABLE:
     652             :         {
     653             :             // draw:object or draw:object_ole
     654           2 :             if( rImport.IsTableShapeSupported() )
     655           2 :                 pContext = new SdXMLTableShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes );
     656           2 :             break;
     657             : 
     658             :         }
     659             :         case XML_TOK_FRAME_PLUGIN:
     660             :         {
     661             :             // draw:plugin
     662           5 :             pContext = new SdXMLPluginShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, sal_False );
     663           5 :             break;
     664             :         }
     665             :         case XML_TOK_FRAME_FLOATING_FRAME:
     666             :         {
     667             :             // draw:floating-frame
     668           0 :             pContext = new SdXMLFloatingFrameShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, sal_False );
     669           0 :             break;
     670             :         }
     671             :         case XML_TOK_FRAME_APPLET:
     672             :         {
     673             :             // draw:applet
     674           0 :             pContext = new SdXMLAppletShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, sal_False );
     675           0 :             break;
     676             :         }
     677             :         // add other shapes here...
     678             :         default:
     679           0 :             break;
     680             :     }
     681             : 
     682         268 :     if( pContext )
     683             :     {
     684             :         // now parse the attribute list and call the child context for each unknown attribute
     685         268 :         sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
     686        2576 :         for(sal_Int16 a(0); a < nAttrCount; a++)
     687             :         {
     688        2308 :             const OUString& rAttrName = xAttrList->getNameByIndex(a);
     689        4616 :             OUString aLocalName;
     690        2308 :             sal_uInt16 nPrefix = rImport.GetNamespaceMap().GetKeyByAttrName(rAttrName, &aLocalName);
     691        4616 :             const OUString aValue( xAttrList->getValueByIndex(a) );
     692             : 
     693        2308 :             pContext->processAttribute( nPrefix, aLocalName, aValue );
     694        2308 :         }
     695             :     }
     696             : 
     697         268 :     return pContext;
     698             : }
     699             : 
     700           0 : SvXMLImportContext *XMLShapeImportHelper::CreateFrameChildContext(
     701             :     SvXMLImportContext *pThisContext,
     702             :     sal_uInt16 nPrefix,
     703             :     const OUString& rLocalName,
     704             :     const uno::Reference< xml::sax::XAttributeList>& xAttrList )
     705             : {
     706           0 :     SvXMLImportContext * pContext = NULL;
     707             : 
     708           0 :     SdXMLFrameShapeContext *pFrameContext = PTR_CAST( SdXMLFrameShapeContext, pThisContext );
     709           0 :     if( pFrameContext )
     710           0 :         pContext = pFrameContext->CreateChildContext( nPrefix, rLocalName, xAttrList );
     711             : 
     712           0 :     return pContext;
     713             : }
     714             : 
     715             : /** this function is called whenever the implementation classes like to add this new
     716             :     shape to the given XShapes.
     717             : */
     718         551 : void XMLShapeImportHelper::addShape( uno::Reference< drawing::XShape >& rShape,
     719             :                                      const uno::Reference< xml::sax::XAttributeList >&,
     720             :                                      uno::Reference< drawing::XShapes >& rShapes)
     721             : {
     722         551 :     if( rShape.is() && rShapes.is() )
     723             :     {
     724             :         // add new shape to parent
     725         551 :         rShapes->add( rShape );
     726             :     }
     727         551 : }
     728             : 
     729             : /** this function is called whenever the implementation classes have finished importing
     730             :     a shape to the given XShapes. The shape is already inserted into its XShapes and
     731             :     all properties and styles are set.
     732             : */
     733         576 : void XMLShapeImportHelper::finishShape(
     734             :         com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& rShape,
     735             :         const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >&,
     736             :         com::sun::star::uno::Reference< com::sun::star::drawing::XShapes >&)
     737             : {
     738             :     /* Set property <PositionLayoutDir>
     739             :        to <PositionInHoriL2R>, if it exists and the import states that
     740             :        the shape positioning attributes are in horizontal left-to-right
     741             :        layout. This is the case for the OpenOffice.org file format.
     742             :        This setting is done for Writer documents, because the property
     743             :        only exists at service com::sun::star::text::Shape - the Writer
     744             :        UNO service for shapes.
     745             :        The value indicates that the positioning attributes are given
     746             :        in horizontal left-to-right layout. The property is evaluated
     747             :        during the first positioning of the shape in order to convert
     748             :        the shape position given in the OpenOffice.org file format to
     749             :        the one for the OASIS Open Office file format. (#i28749#, #i36248#)
     750             :     */
     751         576 :     uno::Reference< beans::XPropertySet > xPropSet(rShape, uno::UNO_QUERY);
     752         576 :     if ( xPropSet.is() )
     753             :     {
     754        1734 :         if ( mrImporter.IsShapePositionInHoriL2R() &&
     755         585 :              xPropSet->getPropertySetInfo()->hasPropertyByName(
     756         582 :                 OUString("PositionLayoutDir")) )
     757             :         {
     758           3 :             uno::Any aPosLayoutDir;
     759           3 :             aPosLayoutDir <<= text::PositionLayoutDir::PositionInHoriL2R;
     760           3 :             xPropSet->setPropertyValue(
     761             :                 OUString("PositionLayoutDir"),
     762           3 :                 aPosLayoutDir );
     763             :         }
     764         576 :     }
     765         576 : }
     766             : 
     767             : // helper functions for z-order sorting
     768             : struct ZOrderHint
     769             : {
     770             :     sal_Int32 nIs;
     771             :     sal_Int32 nShould;
     772             : 
     773         167 :     bool operator<(const ZOrderHint& rComp) const { return nShould < rComp.nShould; }
     774             : };
     775             : 
     776         446 : class ShapeSortContext
     777             : {
     778             : public:
     779             :     uno::Reference< drawing::XShapes > mxShapes;
     780             :     list<ZOrderHint>              maZOrderList;
     781             :     list<ZOrderHint>              maUnsortedList;
     782             : 
     783             :     sal_Int32                     mnCurrentZ;
     784             :     ShapeSortContext*             mpParentContext;
     785             :     const OUString                msZOrder;
     786             : 
     787             :     ShapeSortContext( uno::Reference< drawing::XShapes >& rShapes, ShapeSortContext* pParentContext = NULL );
     788             : 
     789             :     void moveShape( sal_Int32 nSourcePos, sal_Int32 nDestPos );
     790             : };
     791             : 
     792         446 : ShapeSortContext::ShapeSortContext( uno::Reference< drawing::XShapes >& rShapes, ShapeSortContext* pParentContext )
     793             : :   mxShapes( rShapes ), mnCurrentZ( 0 ), mpParentContext( pParentContext ),
     794         446 :     msZOrder("ZOrder")
     795             : {
     796         446 : }
     797             : 
     798          22 : void ShapeSortContext::moveShape( sal_Int32 nSourcePos, sal_Int32 nDestPos )
     799             : {
     800          22 :     uno::Any aAny( mxShapes->getByIndex( nSourcePos ) );
     801          44 :     uno::Reference< beans::XPropertySet > xPropSet;
     802          22 :     aAny >>= xPropSet;
     803             : 
     804          22 :     if( xPropSet.is() && xPropSet->getPropertySetInfo()->hasPropertyByName( msZOrder ) )
     805             :     {
     806          22 :         aAny <<= nDestPos;
     807          22 :         xPropSet->setPropertyValue( msZOrder, aAny );
     808             : 
     809          22 :         list<ZOrderHint>::iterator aIter = maZOrderList.begin();
     810          22 :         list<ZOrderHint>::iterator aEnd = maZOrderList.end();
     811             : 
     812         148 :         while( aIter != aEnd )
     813             :         {
     814         104 :             if( (*aIter).nIs < nSourcePos )
     815             :             {
     816             :                 DBG_ASSERT( (*aIter).nIs >= nDestPos, "Shape sorting failed" );
     817          23 :                 (*aIter).nIs++;
     818             :             }
     819         104 :             ++aIter;
     820             :         }
     821             : 
     822          22 :         aIter = maUnsortedList.begin();
     823          22 :         aEnd = maUnsortedList.end();
     824             : 
     825          44 :         while( aIter != aEnd )
     826             :         {
     827           0 :             if( (*aIter).nIs < nSourcePos )
     828             :             {
     829             :                 DBG_ASSERT( (*aIter).nIs >= nDestPos, "shape sorting failed" );
     830           0 :                 (*aIter).nIs++;
     831             :             }
     832           0 :             ++aIter;
     833             :         }
     834          22 :     }
     835          22 : }
     836             : 
     837         446 : void XMLShapeImportHelper::pushGroupForSorting( uno::Reference< drawing::XShapes >& rShapes )
     838             : {
     839         446 :     mpImpl->mpSortContext = new ShapeSortContext( rShapes, mpImpl->mpSortContext );
     840         446 : }
     841             : 
     842         446 : void XMLShapeImportHelper::popGroupAndSort()
     843             : {
     844             :     DBG_ASSERT( mpImpl->mpSortContext, "No context to sort!" );
     845         446 :     if( mpImpl->mpSortContext == NULL )
     846         446 :         return;
     847             : 
     848             :     try
     849             :     {
     850         446 :         list<ZOrderHint>& rZList = mpImpl->mpSortContext->maZOrderList;
     851         446 :         list<ZOrderHint>& rUnsortedList = mpImpl->mpSortContext->maUnsortedList;
     852             : 
     853             :         // sort shapes
     854         446 :         if( !rZList.empty() )
     855             :         {
     856             :             // only do something if we have shapes to sort
     857             : 
     858             :             // check if there are more shapes than inserted with ::shapeWithZIndexAdded()
     859             :             // This can happen if there where already shapes on the page before import
     860             :             // Since the writer may delete some of this shapes during import, we need
     861             :             // to do this here and not in our c'tor anymore
     862             : 
     863             :             // check if we have more shapes than we know of
     864          87 :             sal_Int32 nCount = mpImpl->mpSortContext->mxShapes->getCount();
     865             : 
     866          87 :             nCount -= rZList.size();
     867          87 :             nCount -= rUnsortedList.size();
     868             : 
     869          87 :             if( nCount > 0 )
     870             :             {
     871             :                 // first update offsets of added shapes
     872           0 :                 list<ZOrderHint>::iterator aIter( rZList.begin() );
     873           0 :                 while( aIter != rZList.end() )
     874           0 :                     (*aIter++).nIs += nCount;
     875             : 
     876           0 :                 aIter = rUnsortedList.begin();
     877           0 :                 while( aIter != rUnsortedList.end() )
     878           0 :                     (*aIter++).nIs += nCount;
     879             : 
     880             :                 // second add the already existing shapes in the unsorted list
     881             :                 ZOrderHint aNewHint;
     882             : 
     883           0 :                 do
     884             :                 {
     885           0 :                     nCount--;
     886             : 
     887           0 :                     aNewHint.nIs = nCount;
     888           0 :                     aNewHint.nShould = -1;
     889             : 
     890           0 :                     rUnsortedList.insert(rUnsortedList.begin(), aNewHint);
     891             :                 }
     892             :                 while( nCount );
     893             :             }
     894             : 
     895             :             // sort z ordered shapes
     896          87 :             rZList.sort();
     897             : 
     898             :             // this is the current index, all shapes before that
     899             :             // index are finished
     900          87 :             sal_Int32 nIndex = 0;
     901         347 :             while( !rZList.empty() )
     902             :             {
     903         173 :                 list<ZOrderHint>::iterator aIter( rZList.begin() );
     904             : 
     905         346 :                 while( nIndex < (*aIter).nShould && !rUnsortedList.empty() )
     906             :                 {
     907           0 :                     ZOrderHint aGapHint( *rUnsortedList.begin() );
     908           0 :                     rUnsortedList.pop_front();
     909             : 
     910           0 :                     mpImpl->mpSortContext->moveShape( aGapHint.nIs, nIndex++ );
     911             :                 }
     912             : 
     913         173 :                 if( (*aIter).nIs != nIndex )
     914          22 :                     mpImpl->mpSortContext->moveShape( (*aIter).nIs, nIndex );
     915             : 
     916         173 :                 rZList.pop_front();
     917         173 :                 nIndex++;
     918             :             }
     919             :         }
     920             :     }
     921           0 :     catch( uno::Exception& )
     922             :     {
     923             :         OSL_FAIL("exception while sorting shapes, sorting failed!");
     924             :     }
     925             : 
     926             :     // put parent on top and delete current context, were done
     927         446 :     ShapeSortContext* pContext = mpImpl->mpSortContext;
     928         446 :     mpImpl->mpSortContext = pContext->mpParentContext;
     929         446 :     delete pContext;
     930             : }
     931             : 
     932         771 : void XMLShapeImportHelper::shapeWithZIndexAdded( com::sun::star::uno::Reference< com::sun::star::drawing::XShape >&, sal_Int32 nZIndex )
     933             : {
     934         771 :     if( mpImpl->mpSortContext)
     935             :     {
     936             :         ZOrderHint aNewHint;
     937         771 :         aNewHint.nIs = mpImpl->mpSortContext->mnCurrentZ++;
     938         771 :         aNewHint.nShould = nZIndex;
     939             : 
     940         771 :         if( nZIndex == -1 )
     941             :         {
     942             :             // don't care, so add to unsorted list
     943         598 :             mpImpl->mpSortContext->maUnsortedList.push_back(aNewHint);
     944             :         }
     945             :         else
     946             :         {
     947             :             // insert into sort list
     948         173 :             mpImpl->mpSortContext->maZOrderList.push_back(aNewHint);
     949             :         }
     950             :     }
     951         771 : }
     952             : 
     953           2 : void XMLShapeImportHelper::addShapeConnection( com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& rConnectorShape,
     954             :                          bool bStart,
     955             :                          const OUString& rDestShapeId,
     956             :                          sal_Int32 nDestGlueId )
     957             : {
     958           2 :     ConnectionHint aHint;
     959           2 :     aHint.mxConnector = rConnectorShape;
     960           2 :     aHint.bStart = bStart;
     961           2 :     aHint.aDestShapeId = rDestShapeId;
     962           2 :     aHint.nDestGlueId = nDestGlueId;
     963             : 
     964           2 :     mpImpl->maConnections.push_back( aHint );
     965           2 : }
     966             : 
     967         400 : void XMLShapeImportHelper::restoreConnections()
     968             : {
     969         400 :     if( !mpImpl->maConnections.empty() )
     970             :     {
     971           1 :         uno::Any aAny;
     972             : 
     973           1 :         const vector<ConnectionHint>::size_type nCount = mpImpl->maConnections.size();
     974           3 :         for( vector<ConnectionHint>::size_type i = 0; i < nCount; i++ )
     975             :         {
     976           2 :             ConnectionHint& rHint = mpImpl->maConnections[i];
     977           2 :             uno::Reference< beans::XPropertySet > xConnector( rHint.mxConnector, uno::UNO_QUERY );
     978           2 :             if( xConnector.is() )
     979             :             {
     980             :                 // #86637# remember line deltas
     981           2 :                 uno::Any aLine1Delta;
     982           4 :                 uno::Any aLine2Delta;
     983           4 :                 uno::Any aLine3Delta;
     984           4 :                 OUString aStr1("EdgeLine1Delta");
     985           4 :                 OUString aStr2("EdgeLine2Delta");
     986           4 :                 OUString aStr3("EdgeLine3Delta");
     987           2 :                 aLine1Delta = xConnector->getPropertyValue(aStr1);
     988           2 :                 aLine2Delta = xConnector->getPropertyValue(aStr2);
     989           2 :                 aLine3Delta = xConnector->getPropertyValue(aStr3);
     990             : 
     991             :                 // #86637# simply setting these values WILL force the connector to do
     992             :                 // an new layout promptly. So the line delta values have to be rescued
     993             :                 // and restored around connector changes.
     994             :                 uno::Reference< drawing::XShape > xShape(
     995           4 :                     mrImporter.getInterfaceToIdentifierMapper().getReference( rHint.aDestShapeId ), uno::UNO_QUERY );
     996           2 :                 if( xShape.is() )
     997             :                 {
     998           2 :                     aAny <<= xShape;
     999           2 :                     xConnector->setPropertyValue( rHint.bStart ? msStartShape : msEndShape, aAny );
    1000             : 
    1001           2 :                     sal_Int32 nGlueId = rHint.nDestGlueId < 4 ? rHint.nDestGlueId : getGluePointId( xShape, rHint.nDestGlueId );
    1002           2 :                     aAny <<= nGlueId;
    1003           2 :                     xConnector->setPropertyValue( rHint.bStart ? msStartGluePointIndex : msEndGluePointIndex, aAny );
    1004             :                 }
    1005             : 
    1006             :                 // #86637# restore line deltas
    1007           2 :                 xConnector->setPropertyValue(aStr1, aLine1Delta );
    1008           2 :                 xConnector->setPropertyValue(aStr2, aLine2Delta );
    1009           4 :                 xConnector->setPropertyValue(aStr3, aLine3Delta );
    1010             :             }
    1011           2 :         }
    1012           1 :         mpImpl->maConnections.clear();
    1013             :     }
    1014         400 : }
    1015             : 
    1016          83 : SvXMLImportPropertyMapper* XMLShapeImportHelper::CreateShapePropMapper( const uno::Reference< frame::XModel>& rModel, SvXMLImport& rImport )
    1017             : {
    1018          83 :     UniReference< XMLPropertyHandlerFactory > xFactory = new XMLSdPropHdlFactory( rModel, rImport );
    1019         166 :     UniReference < XMLPropertySetMapper > xMapper = new XMLShapePropertySetMapper( xFactory, false );
    1020          83 :     SvXMLImportPropertyMapper* pResult = new SvXMLImportPropertyMapper( xMapper, rImport );
    1021             : 
    1022             :     // chain text attributes
    1023          83 :     pResult->ChainImportMapper( XMLTextImportHelper::CreateParaExtPropMapper( rImport ) );
    1024         166 :     return pResult;
    1025             : }
    1026             : 
    1027             : /** adds a mapping for a glue point identifier from an xml file to the identifier created after inserting
    1028             :     the new glue point into the core. The saved mappings can be retrieved by getGluePointId() */
    1029         185 : void XMLShapeImportHelper::addGluePointMapping( com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape,
    1030             :                           sal_Int32 nSourceId, sal_Int32 nDestinnationId )
    1031             : {
    1032         185 :     if( mpPageContext )
    1033         185 :         mpPageContext->maShapeGluePointsMap[xShape][nSourceId] = nDestinnationId;
    1034         185 : }
    1035             : 
    1036             : /** find mapping for given DestinationID. This allows to extract the original draw:id imported with a draw:glue-point */
    1037           0 : sal_Int32 XMLShapeImportHelper::findGluePointMapping(
    1038             :     const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape,
    1039             :     sal_Int32 nDestinnationId ) const
    1040             : {
    1041           0 :     if( mpPageContext )
    1042             :     {
    1043           0 :         ShapeGluePointsMap::iterator aShapeIter( mpPageContext->maShapeGluePointsMap.find( xShape ) );
    1044             : 
    1045           0 :         if( aShapeIter != mpPageContext->maShapeGluePointsMap.end() )
    1046             :         {
    1047           0 :             GluePointIdMap::iterator aShapeIdIter = (*aShapeIter).second.begin();
    1048           0 :             GluePointIdMap::iterator aShapeIdEnd  = (*aShapeIter).second.end();
    1049             : 
    1050           0 :             while ( aShapeIdIter != aShapeIdEnd )
    1051             :             {
    1052           0 :                 if ( (*aShapeIdIter).second == nDestinnationId )
    1053             :                 {
    1054           0 :                     return (*aShapeIdIter).first;
    1055             :                 }
    1056             : 
    1057           0 :                 ++aShapeIdIter;
    1058             :             }
    1059             :         }
    1060             :     }
    1061             : 
    1062           0 :     return -1;
    1063             : }
    1064             : 
    1065             : /** moves all current DestinationId's by n */
    1066          35 : void XMLShapeImportHelper::moveGluePointMapping( const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape, const sal_Int32 n )
    1067             : {
    1068          35 :     if( mpPageContext )
    1069             :     {
    1070          35 :         ShapeGluePointsMap::iterator aShapeIter( mpPageContext->maShapeGluePointsMap.find( xShape ) );
    1071          35 :         if( aShapeIter != mpPageContext->maShapeGluePointsMap.end() )
    1072             :         {
    1073           0 :             GluePointIdMap::iterator aShapeIdIter = (*aShapeIter).second.begin();
    1074           0 :             GluePointIdMap::iterator aShapeIdEnd  = (*aShapeIter).second.end();
    1075           0 :             while ( aShapeIdIter != aShapeIdEnd )
    1076             :             {
    1077           0 :                 if ( (*aShapeIdIter).second != -1 )
    1078           0 :                     (*aShapeIdIter).second += n;
    1079           0 :                 ++aShapeIdIter;
    1080             :             }
    1081             :         }
    1082             :     }
    1083          35 : }
    1084             : 
    1085             : /** retrieves a mapping for a glue point identifier from the current xml file to the identifier created after
    1086             :     inserting the new glue point into the core. The mapping must be initialized first with addGluePointMapping() */
    1087           0 : sal_Int32 XMLShapeImportHelper::getGluePointId( const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape, sal_Int32 nSourceId )
    1088             : {
    1089           0 :     if( mpPageContext )
    1090             :     {
    1091           0 :         ShapeGluePointsMap::iterator aShapeIter( mpPageContext->maShapeGluePointsMap.find( xShape ) );
    1092           0 :         if( aShapeIter != mpPageContext->maShapeGluePointsMap.end() )
    1093             :         {
    1094           0 :             GluePointIdMap::iterator aIdIter = (*aShapeIter).second.find(nSourceId);
    1095           0 :             if( aIdIter != (*aShapeIter).second.end() )
    1096           0 :                 return (*aIdIter).second;
    1097             :         }
    1098             :     }
    1099             : 
    1100           0 :     return -1;
    1101             : }
    1102             : 
    1103             : /** this method must be calling before the first shape is imported for the given page */
    1104         400 : void XMLShapeImportHelper::startPage( com::sun::star::uno::Reference< com::sun::star::drawing::XShapes >& rShapes )
    1105             : {
    1106         400 :     XMLShapeImportPageContextImpl* pOldContext = mpPageContext;
    1107         400 :     mpPageContext = new XMLShapeImportPageContextImpl();
    1108         400 :     mpPageContext->mpNext = pOldContext;
    1109         400 :     mpPageContext->mxShapes = rShapes;
    1110         400 : }
    1111             : 
    1112             : /** this method must be calling after the last shape is imported for the given page */
    1113         400 : void XMLShapeImportHelper::endPage( com::sun::star::uno::Reference< com::sun::star::drawing::XShapes >&
    1114             : #ifdef DBG_UTIL
    1115             : rShapes
    1116             : #endif
    1117             : )
    1118             : {
    1119             :     DBG_ASSERT( mpPageContext && (mpPageContext->mxShapes == rShapes), "wrong call to endPage(), no startPage called or wrong page" );
    1120         400 :     if( NULL == mpPageContext )
    1121         400 :         return;
    1122             : 
    1123         400 :     restoreConnections();
    1124             : 
    1125         400 :     XMLShapeImportPageContextImpl* pNextContext = mpPageContext->mpNext;
    1126         400 :     delete mpPageContext;
    1127         400 :     mpPageContext = pNextContext;
    1128             : }
    1129             : 
    1130             : // #88546#
    1131             : /** defines if the import should increment the progress bar or not */
    1132          80 : void XMLShapeImportHelper::enableHandleProgressBar( bool bEnable )
    1133             : {
    1134          80 :     mpImpl->mbHandleProgressBar = bEnable;
    1135          80 : }
    1136             : 
    1137         576 : bool XMLShapeImportHelper::IsHandleProgressBarEnabled() const
    1138             : {
    1139         576 :     return mpImpl->mbHandleProgressBar;
    1140             : }
    1141             : 
    1142             : /** queries the capability of the current model to create presentation shapes */
    1143         426 : bool XMLShapeImportHelper::IsPresentationShapesSupported()
    1144             : {
    1145         426 :     return mpImpl->mbIsPresentationShapesSupported;
    1146             : }
    1147             : 
    1148         102 : const rtl::Reference< XMLTableImport >& XMLShapeImportHelper::GetShapeTableImport()
    1149             : {
    1150         102 :     if( !mxShapeTableImport.is() )
    1151             :     {
    1152          35 :         rtl::Reference< XMLPropertyHandlerFactory > xFactory( new XMLSdPropHdlFactory( mrImporter.GetModel(), mrImporter ) );
    1153          70 :         rtl::Reference< XMLPropertySetMapper > xPropertySetMapper( new XMLShapePropertySetMapper( xFactory.get(), false ) );
    1154          70 :         mxShapeTableImport = new XMLTableImport( mrImporter, xPropertySetMapper, xFactory );
    1155             :     }
    1156             : 
    1157         102 :     return mxShapeTableImport;
    1158             : }
    1159             : 
    1160           0 : void SvXMLShapeContext::setHyperlink( const OUString& rHyperlink )
    1161             : {
    1162           0 :     msHyperlink = rHyperlink;
    1163           0 : }
    1164             : 
    1165             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10