LCOV - code coverage report
Current view: top level - xmloff/source/draw - shapeimport.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 318 407 78.1 %
Date: 2014-11-03 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        1512 :   bool operator()(const sal_Int32 p, sal_Int32 q) const
      52             :   {
      53        1512 :     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          20 : 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        1860 :   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        1860 :     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        2320 : 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        3648 : 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 switch 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        1824 : 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        1824 :     mrImporter( rImporter )
     138             : {
     139        1824 :     mpImpl = new XMLShapeImportHelperImpl();
     140        1824 :     mpImpl->mpSortContext = 0;
     141             : 
     142             :     // #88546# init to sal_False
     143        1824 :     mpImpl->mbHandleProgressBar = false;
     144             : 
     145        1824 :     mpSdPropHdlFactory = new XMLSdPropHdlFactory( rModel, rImporter );
     146             : 
     147             :     // set lock to avoid deletion
     148        1824 :     mpSdPropHdlFactory->acquire();
     149             : 
     150             :     // construct PropertySetMapper
     151        1824 :     rtl::Reference < XMLPropertySetMapper > xMapper = new XMLShapePropertySetMapper(mpSdPropHdlFactory, false);
     152        1824 :     mpPropertySetMapper = new SvXMLImportPropertyMapper( xMapper, rImporter );
     153             :     // set lock to avoid deletion
     154        1824 :     mpPropertySetMapper->acquire();
     155             : 
     156        1824 :     if( pExtMapper )
     157             :     {
     158         730 :         rtl::Reference < SvXMLImportPropertyMapper > xExtMapper( pExtMapper );
     159         730 :         mpPropertySetMapper->ChainImportMapper( xExtMapper );
     160             :     }
     161             : 
     162             :     // chain text attributes
     163        1824 :     mpPropertySetMapper->ChainImportMapper(XMLTextImportHelper::CreateParaExtPropMapper(rImporter));
     164        1824 :     mpPropertySetMapper->ChainImportMapper(XMLTextImportHelper::CreateParaDefaultExtPropMapper(rImporter));
     165             : 
     166             :     // construct PresPagePropsMapper
     167        1824 :     xMapper = new XMLPropertySetMapper((XMLPropertyMapEntry*)aXMLSDPresPageProps, mpSdPropHdlFactory, false);
     168        1824 :     mpPresPagePropsMapper = new SvXMLImportPropertyMapper( xMapper, rImporter );
     169        1824 :     if(mpPresPagePropsMapper)
     170             :     {
     171             :         // set lock to avoid deletion
     172        1824 :         mpPresPagePropsMapper->acquire();
     173             :     }
     174             : 
     175        3648 :     uno::Reference< lang::XServiceInfo > xInfo( rImporter.GetModel(), uno::UNO_QUERY );
     176        3648 :     const OUString aSName( "com.sun.star.presentation.PresentationDocument" );
     177        3648 :     mpImpl->mbIsPresentationShapesSupported = xInfo.is() && xInfo->supportsService( aSName );
     178        1824 : }
     179             : 
     180        4156 : 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        1824 :     if(mpSdPropHdlFactory)
     186             :     {
     187        1824 :         mpSdPropHdlFactory->release();
     188        1824 :         mpSdPropHdlFactory = 0L;
     189             :     }
     190             : 
     191             :     // cleanup mapper, decrease refcount. Should lead to destruction.
     192        1824 :     if(mpPropertySetMapper)
     193             :     {
     194        1824 :         mpPropertySetMapper->release();
     195        1824 :         mpPropertySetMapper = 0L;
     196             :     }
     197             : 
     198             :     // cleanup presPage mapper, decrease refcount. Should lead to destruction.
     199        1824 :     if(mpPresPagePropsMapper)
     200             :     {
     201        1824 :         mpPresPagePropsMapper->release();
     202        1824 :         mpPresPagePropsMapper = 0L;
     203             :     }
     204             : 
     205        1824 :     if(mpGroupShapeElemTokenMap) delete mpGroupShapeElemTokenMap;
     206        1824 :     if(mpFrameShapeElemTokenMap) delete mpFrameShapeElemTokenMap;
     207             : 
     208        1824 :     if(mpPolygonShapeAttrTokenMap) delete mpPolygonShapeAttrTokenMap;
     209        1824 :     if(mpPathShapeAttrTokenMap) delete mpPathShapeAttrTokenMap;
     210        1824 :     if(mp3DSceneShapeElemTokenMap) delete mp3DSceneShapeElemTokenMap;
     211        1824 :     if(mp3DObjectAttrTokenMap) delete mp3DObjectAttrTokenMap;
     212        1824 :     if(mp3DPolygonBasedAttrTokenMap) delete mp3DPolygonBasedAttrTokenMap;
     213        1824 :     if(mp3DCubeObjectAttrTokenMap) delete mp3DCubeObjectAttrTokenMap;
     214        1824 :     if(mp3DSphereObjectAttrTokenMap) delete mp3DSphereObjectAttrTokenMap;
     215        1824 :     if(mp3DSceneShapeAttrTokenMap) delete mp3DSceneShapeAttrTokenMap;
     216        1824 :     if(mp3DLightAttrTokenMap) delete mp3DLightAttrTokenMap;
     217             : 
     218             :     // Styles or AutoStyles context?
     219        1824 :     if(mpStylesContext)
     220             :     {
     221         114 :         mpStylesContext->Clear();
     222         114 :         mpStylesContext->ReleaseRef();
     223             :     }
     224             : 
     225        1824 :     if(mpAutoStylesContext)
     226             :     {
     227        1744 :         mpAutoStylesContext->Clear();
     228        1744 :         mpAutoStylesContext->ReleaseRef();
     229             :     }
     230             : 
     231        1824 :     delete mpImpl;
     232        2332 : }
     233             : 
     234        4392 : const SvXMLTokenMap& XMLShapeImportHelper::GetGroupShapeElemTokenMap()
     235             : {
     236        4392 :     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         308 :         mpGroupShapeElemTokenMap = new SvXMLTokenMap(aGroupShapeElemTokenMap);
     269             :     } // if(!mpGroupShapeElemTokenMap)
     270             : 
     271        4392 :     return *mpGroupShapeElemTokenMap;
     272             : }
     273             : 
     274        1504 : const SvXMLTokenMap& XMLShapeImportHelper::GetFrameShapeElemTokenMap()
     275             : {
     276        1504 :     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         186 :         mpFrameShapeElemTokenMap = new SvXMLTokenMap(aFrameShapeElemTokenMap);
     292             :     } // if(!mpFrameShapeElemTokenMap)
     293             : 
     294        1504 :     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        2048 : const SvXMLTokenMap& XMLShapeImportHelper::Get3DLightAttrTokenMap()
     386             : {
     387        2048 :     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          64 :         mp3DLightAttrTokenMap = new SvXMLTokenMap(a3DLightAttrTokenMap);
     399             :     } // if(!mp3DLightAttrTokenMap)
     400             : 
     401        2048 :     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, 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, 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, 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, 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, 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         114 : void XMLShapeImportHelper::SetStylesContext(SvXMLStylesContext* pNew)
     467             : {
     468         114 :     mpStylesContext = pNew;
     469         114 :     if (mpStylesContext)
     470         114 :         mpStylesContext->AddFirstRef();
     471         114 : }
     472             : 
     473        1744 : void XMLShapeImportHelper::SetAutoStylesContext(SvXMLStylesContext* pNew)
     474             : {
     475        1744 :     mpAutoStylesContext = pNew;
     476        1744 :     if (mpAutoStylesContext)
     477        1744 :         mpAutoStylesContext->AddFirstRef();
     478        1744 : }
     479             : 
     480        4392 : 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        4392 :     SdXMLShapeContext *pContext = 0L;
     489             : 
     490        4392 :     const SvXMLTokenMap& rTokenMap = GetGroupShapeElemTokenMap();
     491        4392 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
     492             : 
     493        4392 :     switch(rTokenMap.Get(p_nPrefix, rLocalName))
     494             :     {
     495             :         case XML_TOK_GROUP_GROUP:
     496             :         {
     497             :             // draw:g inside group context (RECURSIVE)
     498         680 :             pContext = new SdXMLGroupShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, bTemporaryShape);
     499         680 :             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          96 :             pContext = new SdXMLRectShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, bTemporaryShape );
     511          96 :             break;
     512             :         }
     513             :         case XML_TOK_GROUP_LINE:
     514             :         {
     515             :             // draw:line inside group context
     516         124 :             pContext = new SdXMLLineShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, bTemporaryShape );
     517         124 :             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          40 :             pContext = new SdXMLEllipseShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, bTemporaryShape );
     524          40 :             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          10 :                 rTokenMap.Get(p_nPrefix, rLocalName) == XML_TOK_GROUP_POLYGON ? sal_True : sal_False, bTemporaryShape );
     532          10 :             break;
     533             :         }
     534             :         case XML_TOK_GROUP_PATH:
     535             :         {
     536             :             // draw:path inside group context
     537        1380 :             pContext = new SdXMLPathShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, bTemporaryShape);
     538        1380 :             break;
     539             :         }
     540             :         case XML_TOK_GROUP_FRAME:
     541             :         {
     542             :             // text:text-box inside group context
     543        1494 :             pContext = new SdXMLFrameShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, bTemporaryShape );
     544        1494 :             break;
     545             :         }
     546             :         case XML_TOK_GROUP_CONTROL:
     547             :         {
     548             :             // draw:control inside group context
     549          58 :             pContext = new SdXMLControlShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, bTemporaryShape );
     550          58 :             break;
     551             :         }
     552             :         case XML_TOK_GROUP_CONNECTOR:
     553             :         {
     554             :             // draw:connector inside group context
     555           2 :             pContext = new SdXMLConnectorShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, bTemporaryShape );
     556           2 :             break;
     557             :         }
     558             :         case XML_TOK_GROUP_MEASURE:
     559             :         {
     560             :             // draw:measure inside group context
     561           2 :             pContext = new SdXMLMeasureShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, bTemporaryShape );
     562           2 :             break;
     563             :         }
     564             :         case XML_TOK_GROUP_PAGE:
     565             :         {
     566             :             // draw:page inside group context
     567         292 :             pContext = new SdXMLPageShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, bTemporaryShape );
     568         292 :             break;
     569             :         }
     570             :         case XML_TOK_GROUP_CAPTION:
     571             :         case XML_TOK_GROUP_ANNOTATION:
     572             :         {
     573             :             // draw:caption inside group context
     574          32 :             pContext = new SdXMLCaptionShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, bTemporaryShape );
     575          32 :             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         164 :             pContext = new SdXMLCustomShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, false );
     587         164 :             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          18 :             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       34870 :     for(sal_Int16 a(0); a < nAttrCount; a++)
     600             :     {
     601       30496 :         const OUString& rAttrName = xAttrList->getNameByIndex(a);
     602       60992 :         OUString aLocalName;
     603       30496 :         sal_uInt16 nPrefix = rImport.GetNamespaceMap().GetKeyByAttrName(rAttrName, &aLocalName);
     604       60992 :         const OUString aValue( xAttrList->getValueByIndex(a) );
     605             : 
     606       30496 :         pContext->processAttribute( nPrefix, aLocalName, aValue );
     607       30496 :     }
     608             : 
     609        4374 :     return pContext;
     610             : }
     611             : 
     612             : // This method is called from SdXMLFrameShapeContext to create children of drawe:frame
     613        1504 : 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        1504 :     SdXMLShapeContext *pContext = 0L;
     622             : 
     623        1504 :     const SvXMLTokenMap& rTokenMap = GetFrameShapeElemTokenMap();
     624             : 
     625        1504 :     SvXMLAttributeList *pAttrList = new SvXMLAttributeList( rAttrList );
     626        1504 :     if( rFrameAttrList.is() )
     627        1504 :         pAttrList->AppendAttributeList( rFrameAttrList );
     628        1504 :     uno::Reference < xml::sax::XAttributeList > xAttrList = pAttrList;
     629             : 
     630        1504 :     switch(rTokenMap.Get(p_nPrefix, rLocalName))
     631             :     {
     632             :         case XML_TOK_FRAME_TEXT_BOX:
     633             :         {
     634             :             // text:text-box inside group context
     635        1348 :             pContext = new SdXMLTextBoxShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, false );
     636        1348 :             break;
     637             :         }
     638             :         case XML_TOK_FRAME_IMAGE:
     639             :         {
     640             :             // office:image inside group context
     641          56 :             pContext = new SdXMLGraphicObjectShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, false );
     642          56 :             break;
     643             :         }
     644             :         case XML_TOK_FRAME_OBJECT:
     645             :         case XML_TOK_FRAME_OBJECT_OLE:
     646             :         {
     647             :             // draw:object or draw:object_ole
     648          82 :             pContext = new SdXMLObjectShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, false );
     649          82 :             break;
     650             :         }
     651             :         case XML_TOK_FRAME_TABLE:
     652             :         {
     653             :             // draw:object or draw:object_ole
     654           6 :             if( rImport.IsTableShapeSupported() )
     655           6 :                 pContext = new SdXMLTableShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes );
     656           6 :             break;
     657             : 
     658             :         }
     659             :         case XML_TOK_FRAME_PLUGIN:
     660             :         {
     661             :             // draw:plugin
     662          10 :             pContext = new SdXMLPluginShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, false );
     663          10 :             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, 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, false );
     675           0 :             break;
     676             :         }
     677             :         // add other shapes here...
     678             :         default:
     679           2 :             break;
     680             :     }
     681             : 
     682        1504 :     if( pContext )
     683             :     {
     684             :         // now parse the attribute list and call the child context for each unknown attribute
     685        1502 :         sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
     686       15698 :         for(sal_Int16 a(0); a < nAttrCount; a++)
     687             :         {
     688       14196 :             const OUString& rAttrName = xAttrList->getNameByIndex(a);
     689       28392 :             OUString aLocalName;
     690       14196 :             sal_uInt16 nPrefix = rImport.GetNamespaceMap().GetKeyByAttrName(rAttrName, &aLocalName);
     691       28392 :             const OUString aValue( xAttrList->getValueByIndex(a) );
     692             : 
     693       14196 :             pContext->processAttribute( nPrefix, aLocalName, aValue );
     694       14196 :         }
     695             :     }
     696             : 
     697        1504 :     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        4238 : void XMLShapeImportHelper::addShape( uno::Reference< drawing::XShape >& rShape,
     719             :                                      const uno::Reference< xml::sax::XAttributeList >&,
     720             :                                      uno::Reference< drawing::XShapes >& rShapes)
     721             : {
     722        4238 :     if( rShape.is() && rShapes.is() )
     723             :     {
     724             :         // add new shape to parent
     725        4238 :         rShapes->add( rShape );
     726             :     }
     727        4238 : }
     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        4382 : 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        4382 :     uno::Reference< beans::XPropertySet > xPropSet(rShape, uno::UNO_QUERY);
     752        4382 :     if ( xPropSet.is() )
     753             :     {
     754       13158 :         if ( mrImporter.IsShapePositionInHoriL2R() &&
     755        4400 :              xPropSet->getPropertySetInfo()->hasPropertyByName(
     756        4394 :                 OUString("PositionLayoutDir")) )
     757             :         {
     758           6 :             uno::Any aPosLayoutDir;
     759           6 :             aPosLayoutDir <<= text::PositionLayoutDir::PositionInHoriL2R;
     760           6 :             xPropSet->setPropertyValue(
     761             :                 OUString("PositionLayoutDir"),
     762           6 :                 aPosLayoutDir );
     763             :         }
     764        4382 :     }
     765        4382 : }
     766             : 
     767             : // helper functions for z-order sorting
     768             : struct ZOrderHint
     769             : {
     770             :     sal_Int32 nIs;
     771             :     sal_Int32 nShould;
     772             : 
     773         534 :     bool operator<(const ZOrderHint& rComp) const { return nShould < rComp.nShould; }
     774             : };
     775             : 
     776        1940 : 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        1940 : ShapeSortContext::ShapeSortContext( uno::Reference< drawing::XShapes >& rShapes, ShapeSortContext* pParentContext )
     793             : :   mxShapes( rShapes ), mnCurrentZ( 0 ), mpParentContext( pParentContext ),
     794        1940 :     msZOrder("ZOrder")
     795             : {
     796        1940 : }
     797             : 
     798         130 : void ShapeSortContext::moveShape( sal_Int32 nSourcePos, sal_Int32 nDestPos )
     799             : {
     800         130 :     uno::Any aAny( mxShapes->getByIndex( nSourcePos ) );
     801         260 :     uno::Reference< beans::XPropertySet > xPropSet;
     802         130 :     aAny >>= xPropSet;
     803             : 
     804         130 :     if( xPropSet.is() && xPropSet->getPropertySetInfo()->hasPropertyByName( msZOrder ) )
     805             :     {
     806         130 :         aAny <<= nDestPos;
     807         130 :         xPropSet->setPropertyValue( msZOrder, aAny );
     808             : 
     809         130 :         list<ZOrderHint>::iterator aIter = maZOrderList.begin();
     810         130 :         list<ZOrderHint>::iterator aEnd = maZOrderList.end();
     811             : 
     812         998 :         while( aIter != aEnd )
     813             :         {
     814         738 :             if( (*aIter).nIs < nSourcePos )
     815             :             {
     816             :                 DBG_ASSERT( (*aIter).nIs >= nDestPos, "Shape sorting failed" );
     817         278 :                 (*aIter).nIs++;
     818             :             }
     819         738 :             ++aIter;
     820             :         }
     821             : 
     822         130 :         aIter = maUnsortedList.begin();
     823         130 :         aEnd = maUnsortedList.end();
     824             : 
     825         282 :         while( aIter != aEnd )
     826             :         {
     827          22 :             if( (*aIter).nIs < nSourcePos )
     828             :             {
     829             :                 DBG_ASSERT( (*aIter).nIs >= nDestPos, "shape sorting failed" );
     830          20 :                 (*aIter).nIs++;
     831             :             }
     832          22 :             ++aIter;
     833             :         }
     834         130 :     }
     835         130 : }
     836             : 
     837        1940 : void XMLShapeImportHelper::pushGroupForSorting( uno::Reference< drawing::XShapes >& rShapes )
     838             : {
     839        1940 :     mpImpl->mpSortContext = new ShapeSortContext( rShapes, mpImpl->mpSortContext );
     840        1940 : }
     841             : 
     842        1940 : void XMLShapeImportHelper::popGroupAndSort()
     843             : {
     844             :     DBG_ASSERT( mpImpl->mpSortContext, "No context to sort!" );
     845        1940 :     if( mpImpl->mpSortContext == NULL )
     846        1940 :         return;
     847             : 
     848             :     try
     849             :     {
     850        1940 :         list<ZOrderHint>& rZList = mpImpl->mpSortContext->maZOrderList;
     851        1940 :         list<ZOrderHint>& rUnsortedList = mpImpl->mpSortContext->maUnsortedList;
     852             : 
     853             :         // sort shapes
     854        1940 :         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         236 :             sal_Int32 nCount = mpImpl->mpSortContext->mxShapes->getCount();
     865             : 
     866         236 :             nCount -= rZList.size();
     867         236 :             nCount -= rUnsortedList.size();
     868             : 
     869         236 :             if( nCount > 0 )
     870             :             {
     871             :                 // first update offsets of added shapes
     872          18 :                 list<ZOrderHint>::iterator aIter( rZList.begin() );
     873          56 :                 while( aIter != rZList.end() )
     874          20 :                     (*aIter++).nIs += nCount;
     875             : 
     876          18 :                 aIter = rUnsortedList.begin();
     877          36 :                 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          20 :                 do
     884             :                 {
     885          20 :                     nCount--;
     886             : 
     887          20 :                     aNewHint.nIs = nCount;
     888          20 :                     aNewHint.nShould = -1;
     889             : 
     890          20 :                     rUnsortedList.insert(rUnsortedList.begin(), aNewHint);
     891             :                 }
     892             :                 while( nCount );
     893             :             }
     894             : 
     895             :             // sort z ordered shapes
     896         236 :             rZList.sort();
     897             : 
     898             :             // this is the current index, all shapes before that
     899             :             // index are finished
     900         236 :             sal_Int32 nIndex = 0;
     901         954 :             while( !rZList.empty() )
     902             :             {
     903         482 :                 list<ZOrderHint>::iterator aIter( rZList.begin() );
     904             : 
     905         966 :                 while( nIndex < (*aIter).nShould && !rUnsortedList.empty() )
     906             :                 {
     907           2 :                     ZOrderHint aGapHint( *rUnsortedList.begin() );
     908           2 :                     rUnsortedList.pop_front();
     909             : 
     910           2 :                     mpImpl->mpSortContext->moveShape( aGapHint.nIs, nIndex++ );
     911             :                 }
     912             : 
     913         482 :                 if( (*aIter).nIs != nIndex )
     914         128 :                     mpImpl->mpSortContext->moveShape( (*aIter).nIs, nIndex );
     915             : 
     916         482 :                 rZList.pop_front();
     917         482 :                 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        1940 :     ShapeSortContext* pContext = mpImpl->mpSortContext;
     928        1940 :     mpImpl->mpSortContext = pContext->mpParentContext;
     929        1940 :     delete pContext;
     930             : }
     931             : 
     932        4836 : void XMLShapeImportHelper::shapeWithZIndexAdded( com::sun::star::uno::Reference< com::sun::star::drawing::XShape >&, sal_Int32 nZIndex )
     933             : {
     934        4836 :     if( mpImpl->mpSortContext)
     935             :     {
     936             :         ZOrderHint aNewHint;
     937        4836 :         aNewHint.nIs = mpImpl->mpSortContext->mnCurrentZ++;
     938        4836 :         aNewHint.nShould = nZIndex;
     939             : 
     940        4836 :         if( nZIndex == -1 )
     941             :         {
     942             :             // don't care, so add to unsorted list
     943        4354 :             mpImpl->mpSortContext->maUnsortedList.push_back(aNewHint);
     944             :         }
     945             :         else
     946             :         {
     947             :             // insert into sort list
     948         482 :             mpImpl->mpSortContext->maZOrderList.push_back(aNewHint);
     949             :         }
     950             :     }
     951        4836 : }
     952             : 
     953           4 : 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           4 :     ConnectionHint aHint;
     959           4 :     aHint.mxConnector = rConnectorShape;
     960           4 :     aHint.bStart = bStart;
     961           4 :     aHint.aDestShapeId = rDestShapeId;
     962           4 :     aHint.nDestGlueId = nDestGlueId;
     963             : 
     964           4 :     mpImpl->maConnections.push_back( aHint );
     965           4 : }
     966             : 
     967        1160 : void XMLShapeImportHelper::restoreConnections()
     968             : {
     969        1160 :     if( !mpImpl->maConnections.empty() )
     970             :     {
     971           2 :         uno::Any aAny;
     972             : 
     973           2 :         const vector<ConnectionHint>::size_type nCount = mpImpl->maConnections.size();
     974           6 :         for( vector<ConnectionHint>::size_type i = 0; i < nCount; i++ )
     975             :         {
     976           4 :             ConnectionHint& rHint = mpImpl->maConnections[i];
     977           4 :             uno::Reference< beans::XPropertySet > xConnector( rHint.mxConnector, uno::UNO_QUERY );
     978           4 :             if( xConnector.is() )
     979             :             {
     980             :                 // #86637# remember line deltas
     981           4 :                 uno::Any aLine1Delta;
     982           8 :                 uno::Any aLine2Delta;
     983           8 :                 uno::Any aLine3Delta;
     984           8 :                 OUString aStr1("EdgeLine1Delta");
     985           8 :                 OUString aStr2("EdgeLine2Delta");
     986           8 :                 OUString aStr3("EdgeLine3Delta");
     987           4 :                 aLine1Delta = xConnector->getPropertyValue(aStr1);
     988           4 :                 aLine2Delta = xConnector->getPropertyValue(aStr2);
     989           4 :                 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           8 :                     mrImporter.getInterfaceToIdentifierMapper().getReference( rHint.aDestShapeId ), uno::UNO_QUERY );
     996           4 :                 if( xShape.is() )
     997             :                 {
     998           4 :                     aAny <<= xShape;
     999           4 :                     xConnector->setPropertyValue( rHint.bStart ? msStartShape : msEndShape, aAny );
    1000             : 
    1001           4 :                     sal_Int32 nGlueId = rHint.nDestGlueId < 4 ? rHint.nDestGlueId : getGluePointId( xShape, rHint.nDestGlueId );
    1002           4 :                     aAny <<= nGlueId;
    1003           4 :                     xConnector->setPropertyValue( rHint.bStart ? msStartGluePointIndex : msEndGluePointIndex, aAny );
    1004             :                 }
    1005             : 
    1006             :                 // #86637# restore line deltas
    1007           4 :                 xConnector->setPropertyValue(aStr1, aLine1Delta );
    1008           4 :                 xConnector->setPropertyValue(aStr2, aLine2Delta );
    1009           8 :                 xConnector->setPropertyValue(aStr3, aLine3Delta );
    1010             :             }
    1011           4 :         }
    1012           2 :         mpImpl->maConnections.clear();
    1013             :     }
    1014        1160 : }
    1015             : 
    1016         244 : SvXMLImportPropertyMapper* XMLShapeImportHelper::CreateShapePropMapper( const uno::Reference< frame::XModel>& rModel, SvXMLImport& rImport )
    1017             : {
    1018         244 :     rtl::Reference< XMLPropertyHandlerFactory > xFactory = new XMLSdPropHdlFactory( rModel, rImport );
    1019         488 :     rtl::Reference < XMLPropertySetMapper > xMapper = new XMLShapePropertySetMapper( xFactory, false );
    1020         244 :     SvXMLImportPropertyMapper* pResult = new SvXMLImportPropertyMapper( xMapper, rImport );
    1021             : 
    1022             :     // chain text attributes
    1023         244 :     pResult->ChainImportMapper( XMLTextImportHelper::CreateParaExtPropMapper( rImport ) );
    1024         488 :     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         442 : void XMLShapeImportHelper::addGluePointMapping( com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape,
    1030             :                           sal_Int32 nSourceId, sal_Int32 nDestinnationId )
    1031             : {
    1032         442 :     if( mpPageContext )
    1033         442 :         mpPageContext->maShapeGluePointsMap[xShape][nSourceId] = nDestinnationId;
    1034         442 : }
    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          82 : void XMLShapeImportHelper::moveGluePointMapping( const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape, const sal_Int32 n )
    1067             : {
    1068          82 :     if( mpPageContext )
    1069             :     {
    1070          82 :         ShapeGluePointsMap::iterator aShapeIter( mpPageContext->maShapeGluePointsMap.find( xShape ) );
    1071          82 :         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          82 : }
    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        1160 : void XMLShapeImportHelper::startPage( com::sun::star::uno::Reference< com::sun::star::drawing::XShapes >& rShapes )
    1105             : {
    1106        1160 :     XMLShapeImportPageContextImpl* pOldContext = mpPageContext;
    1107        1160 :     mpPageContext = new XMLShapeImportPageContextImpl();
    1108        1160 :     mpPageContext->mpNext = pOldContext;
    1109        1160 :     mpPageContext->mxShapes = rShapes;
    1110        1160 : }
    1111             : 
    1112             : /** this method must be calling after the last shape is imported for the given page */
    1113        1160 : 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        1160 :     if( NULL == mpPageContext )
    1121        1160 :         return;
    1122             : 
    1123        1160 :     restoreConnections();
    1124             : 
    1125        1160 :     XMLShapeImportPageContextImpl* pNextContext = mpPageContext->mpNext;
    1126        1160 :     delete mpPageContext;
    1127        1160 :     mpPageContext = pNextContext;
    1128             : }
    1129             : 
    1130             : // #88546#
    1131             : /** defines if the import should increment the progress bar or not */
    1132         230 : void XMLShapeImportHelper::enableHandleProgressBar( bool bEnable )
    1133             : {
    1134         230 :     mpImpl->mbHandleProgressBar = bEnable;
    1135         230 : }
    1136             : 
    1137        4382 : bool XMLShapeImportHelper::IsHandleProgressBarEnabled() const
    1138             : {
    1139        4382 :     return mpImpl->mbHandleProgressBar;
    1140             : }
    1141             : 
    1142             : /** queries the capability of the current model to create presentation shapes */
    1143        1230 : bool XMLShapeImportHelper::IsPresentationShapesSupported()
    1144             : {
    1145        1230 :     return mpImpl->mbIsPresentationShapesSupported;
    1146             : }
    1147             : 
    1148         350 : const rtl::Reference< XMLTableImport >& XMLShapeImportHelper::GetShapeTableImport()
    1149             : {
    1150         350 :     if( !mxShapeTableImport.is() )
    1151             :     {
    1152         118 :         rtl::Reference< XMLPropertyHandlerFactory > xFactory( new XMLSdPropHdlFactory( mrImporter.GetModel(), mrImporter ) );
    1153         236 :         rtl::Reference< XMLPropertySetMapper > xPropertySetMapper( new XMLShapePropertySetMapper( xFactory.get(), false ) );
    1154         236 :         mxShapeTableImport = new XMLTableImport( mrImporter, xPropertySetMapper, xFactory );
    1155             :     }
    1156             : 
    1157         350 :     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