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

Generated by: LCOV version 1.11