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

Generated by: LCOV version 1.10