LCOV - code coverage report
Current view: top level - svtools/source/uno - unoimap.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 181 325 55.7 %
Date: 2014-11-03 Functions: 35 51 68.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 <com/sun/star/container/XNameContainer.hpp>
      21             : #include <com/sun/star/container/XIndexContainer.hpp>
      22             : #include <com/sun/star/lang/XServiceInfo.hpp>
      23             : #include <com/sun/star/document/XEventsSupplier.hpp>
      24             : #include <com/sun/star/lang/XUnoTunnel.hpp>
      25             : #include <com/sun/star/beans/XPropertySet.hpp>
      26             : #include <com/sun/star/awt/Rectangle.hpp>
      27             : #include <com/sun/star/awt/Point.hpp>
      28             : #include <com/sun/star/drawing/PointSequence.hpp>
      29             : #include <comphelper/servicehelper.hxx>
      30             : #include <comphelper/propertysethelper.hxx>
      31             : #include <comphelper/propertysetinfo.hxx>
      32             : #include <cppuhelper/weakagg.hxx>
      33             : #include <cppuhelper/implbase3.hxx>
      34             : #include <cppuhelper/supportsservice.hxx>
      35             : #include <list>
      36             : #include <osl/mutex.hxx>
      37             : #include <vcl/svapp.hxx>
      38             : #include <svtools/unoevent.hxx>
      39             : #include <svtools/unoimap.hxx>
      40             : #include <svtools/imap.hxx>
      41             : #include <svtools/imapcirc.hxx>
      42             : #include <svtools/imaprect.hxx>
      43             : #include <svtools/imappoly.hxx>
      44             : 
      45             : using namespace comphelper;
      46             : using namespace cppu;
      47             : using namespace com::sun::star;
      48             : using namespace com::sun::star::uno;
      49             : using namespace com::sun::star::lang;
      50             : using namespace com::sun::star::container;
      51             : using namespace com::sun::star::beans;
      52             : using namespace com::sun::star::document;
      53             : using namespace com::sun::star::drawing;
      54             : 
      55             : const sal_Int32 HANDLE_URL = 1;
      56             : const sal_Int32 HANDLE_DESCRIPTION = 2;
      57             : const sal_Int32 HANDLE_TARGET = 3;
      58             : const sal_Int32 HANDLE_NAME = 4;
      59             : const sal_Int32 HANDLE_ISACTIVE = 5;
      60             : const sal_Int32 HANDLE_POLYGON = 6;
      61             : const sal_Int32 HANDLE_CENTER = 7;
      62             : const sal_Int32 HANDLE_RADIUS = 8;
      63             : const sal_Int32 HANDLE_BOUNDARY = 9;
      64             : const sal_Int32 HANDLE_TITLE = 10;
      65             : 
      66             : class SvUnoImageMapObject : public OWeakAggObject,
      67             :                             public XEventsSupplier,
      68             :                             public XServiceInfo,
      69             :                             public PropertySetHelper,
      70             :                             public XTypeProvider,
      71             :                             public XUnoTunnel
      72             : {
      73             : public:
      74             :     SvUnoImageMapObject( sal_uInt16 nType, const SvEventDescription* pSupportedMacroItems );
      75             :     SvUnoImageMapObject( const IMapObject& rMapObject, const SvEventDescription* pSupportedMacroItems );
      76             :     virtual ~SvUnoImageMapObject() throw();
      77             : 
      78             :     UNO3_GETIMPLEMENTATION_DECL( SvUnoImageMapObject )
      79             : 
      80             :     IMapObject* createIMapObject() const;
      81             : 
      82             :     SvMacroTableEventDescriptor* mpEvents;
      83             : 
      84             :     // overiden helpers from PropertySetHelper
      85             :     virtual void _setPropertyValues( const PropertyMapEntry** ppEntries, const Any* pValues ) throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException ) SAL_OVERRIDE;
      86             :     virtual void _getPropertyValues( const PropertyMapEntry** ppEntries, Any* pValue ) throw(UnknownPropertyException, WrappedTargetException ) SAL_OVERRIDE;
      87             : 
      88             :     // XInterface
      89             :     virtual Any SAL_CALL queryAggregation( const Type & rType ) throw(RuntimeException, std::exception) SAL_OVERRIDE;
      90             :     virtual Any SAL_CALL queryInterface( const Type & rType ) throw(RuntimeException, std::exception) SAL_OVERRIDE;
      91             :     virtual void SAL_CALL acquire() throw() SAL_OVERRIDE;
      92             :     virtual void SAL_CALL release() throw() SAL_OVERRIDE;
      93             : 
      94             :     // XTypeProvider
      95             :     virtual Sequence< Type > SAL_CALL getTypes(  ) throw(RuntimeException, std::exception) SAL_OVERRIDE;
      96             :     virtual Sequence< sal_Int8 > SAL_CALL getImplementationId(  ) throw(RuntimeException, std::exception) SAL_OVERRIDE;
      97             : 
      98             :     // XEventsSupplier
      99             :     virtual Reference< ::com::sun::star::container::XNameReplace > SAL_CALL getEvents(  ) throw(RuntimeException, std::exception) SAL_OVERRIDE;
     100             : 
     101             :     // XServiceInfo
     102             :     virtual OUString SAL_CALL getImplementationName(  ) throw( RuntimeException, std::exception ) SAL_OVERRIDE;
     103             :     virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw( RuntimeException, std::exception ) SAL_OVERRIDE;
     104             :     virtual Sequence< OUString > SAL_CALL getSupportedServiceNames(  ) throw( RuntimeException, std::exception ) SAL_OVERRIDE;
     105             : 
     106             : private:
     107             :     static PropertySetInfo* createPropertySetInfo( sal_uInt16 nType );
     108             : 
     109             : 
     110             :     sal_uInt16 mnType;
     111             : 
     112             :     OUString maURL;
     113             :     OUString maAltText;
     114             :     OUString maDesc;
     115             :     OUString maTarget;
     116             :     OUString maName;
     117             :     bool mbIsActive;
     118             :     awt::Rectangle maBoundary;
     119             :     awt::Point maCenter;
     120             :     sal_Int32 mnRadius;
     121             :     PointSequence maPolygon;
     122             : };
     123             : 
     124          16 : UNO3_GETIMPLEMENTATION_IMPL( SvUnoImageMapObject );
     125             : 
     126          12 : PropertySetInfo * SvUnoImageMapObject::createPropertySetInfo( sal_uInt16 nType )
     127             : {
     128          12 :     switch( nType )
     129             :     {
     130             :     case IMAP_OBJ_POLYGON:
     131             :         {
     132             :             static PropertyMapEntry const aPolygonObj_Impl[] =
     133             :             {
     134           4 :                 { OUString("URL"),         HANDLE_URL,         cppu::UnoType<OUString>::get(),     0, 0 },
     135           4 :                 { OUString("Title"),       HANDLE_TITLE,       cppu::UnoType<OUString>::get(),     0, 0 },
     136           4 :                 { OUString("Description"), HANDLE_DESCRIPTION, cppu::UnoType<OUString>::get(),     0, 0 },
     137           4 :                 { OUString("Target"),      HANDLE_TARGET,      cppu::UnoType<OUString>::get(),     0, 0 },
     138           4 :                 { OUString("Name"),        HANDLE_NAME,        cppu::UnoType<OUString>::get(),     0, 0 },
     139           4 :                 { OUString("IsActive"),    HANDLE_ISACTIVE,    ::getBooleanCppuType(),                0, 0 },
     140           4 :                 { OUString("Polygon"),     HANDLE_POLYGON,     ::getCppuType((const PointSequence*)0),    0, 0 },
     141             :                 { OUString(), 0, css::uno::Type(), 0, 0 }
     142          36 :             };
     143             : 
     144           4 :             return new PropertySetInfo( aPolygonObj_Impl );
     145             :         }
     146             :     case IMAP_OBJ_CIRCLE:
     147             :         {
     148             :             static PropertyMapEntry const aCircleObj_Impl[] =
     149             :             {
     150           2 :                 { OUString("URL"),         HANDLE_URL,         cppu::UnoType<OUString>::get(),     0, 0 },
     151           2 :                 { OUString("Title"),       HANDLE_TITLE,       cppu::UnoType<OUString>::get(),     0, 0 },
     152           2 :                 { OUString("Description"), HANDLE_DESCRIPTION, cppu::UnoType<OUString>::get(),     0, 0 },
     153           2 :                 { OUString("Target"),      HANDLE_TARGET,      cppu::UnoType<OUString>::get(),     0, 0 },
     154           2 :                 { OUString("Name"),        HANDLE_NAME,        cppu::UnoType<OUString>::get(),     0, 0 },
     155           2 :                 { OUString("IsActive"),    HANDLE_ISACTIVE,    ::getBooleanCppuType(),                0, 0 },
     156           2 :                 { OUString("Center"),      HANDLE_CENTER,      cppu::UnoType<awt::Point>::get(),   0, 0 },
     157           2 :                 { OUString("Radius"),      HANDLE_RADIUS,      cppu::UnoType<sal_Int32>::get(),    0, 0 },
     158             :                 { OUString(), 0, css::uno::Type(), 0, 0 }
     159          20 :             };
     160             : 
     161           2 :             return new PropertySetInfo( aCircleObj_Impl );
     162             :         }
     163             :     case IMAP_OBJ_RECTANGLE:
     164             :     default:
     165             :         {
     166             :             static PropertyMapEntry const aRectangleObj_Impl[] =
     167             :             {
     168           4 :                 { OUString("URL"),         HANDLE_URL,         cppu::UnoType<OUString>::get(), 0, 0 },
     169           4 :                 { OUString("Title"),       HANDLE_TITLE,       cppu::UnoType<OUString>::get(),     0, 0 },
     170           4 :                 { OUString("Description"), HANDLE_DESCRIPTION, cppu::UnoType<OUString>::get(), 0, 0 },
     171           4 :                 { OUString("Target"),      HANDLE_TARGET,      cppu::UnoType<OUString>::get(), 0, 0 },
     172           4 :                 { OUString("Name"),        HANDLE_NAME,        cppu::UnoType<OUString>::get(), 0, 0 },
     173           4 :                 { OUString("IsActive"),    HANDLE_ISACTIVE,    ::getBooleanCppuType(),            0, 0 },
     174           4 :                 { OUString("Boundary"),    HANDLE_BOUNDARY,    cppu::UnoType<awt::Rectangle>::get(),   0, 0 },
     175             :                 { OUString(), 0, css::uno::Type(), 0, 0 }
     176          38 :             };
     177             : 
     178           6 :             return new PropertySetInfo( aRectangleObj_Impl );
     179             :         }
     180             :     }
     181             : }
     182             : 
     183          10 : SvUnoImageMapObject::SvUnoImageMapObject( sal_uInt16 nType, const SvEventDescription* pSupportedMacroItems )
     184             : :   PropertySetHelper( createPropertySetInfo( nType ) ),
     185             :     mnType( nType )
     186             : ,   mbIsActive( true )
     187          10 : ,   mnRadius( 0 )
     188             : {
     189          10 :     mpEvents = new SvMacroTableEventDescriptor( pSupportedMacroItems );
     190          10 :     mpEvents->acquire();
     191          10 : }
     192             : 
     193           2 : SvUnoImageMapObject::SvUnoImageMapObject( const IMapObject& rMapObject, const SvEventDescription* pSupportedMacroItems )
     194           2 : :   PropertySetHelper( createPropertySetInfo( rMapObject.GetType() ) ),
     195           2 :     mnType( rMapObject.GetType() )
     196             : ,   mbIsActive( true )
     197           6 : ,   mnRadius( 0 )
     198             : {
     199           2 :     maURL = rMapObject.GetURL();
     200           2 :     maAltText = rMapObject.GetAltText();
     201           2 :     maDesc = rMapObject.GetDesc();
     202           2 :     maTarget = rMapObject.GetTarget();
     203           2 :     maName = rMapObject.GetName();
     204           2 :     mbIsActive = rMapObject.IsActive();
     205             : 
     206           2 :     switch( mnType )
     207             :     {
     208             :     case IMAP_OBJ_RECTANGLE:
     209             :         {
     210           2 :             const Rectangle aRect( static_cast<const IMapRectangleObject*>(&rMapObject)->GetRectangle(false) );
     211           2 :             maBoundary.X = aRect.Left();
     212           2 :             maBoundary.Y = aRect.Top();
     213           2 :             maBoundary.Width = aRect.GetWidth();
     214           2 :             maBoundary.Height = aRect.GetHeight();
     215             :         }
     216           2 :         break;
     217             :     case IMAP_OBJ_CIRCLE:
     218             :         {
     219           0 :             mnRadius = (sal_Int32)static_cast<const IMapCircleObject*>(&rMapObject)->GetRadius(false);
     220           0 :             const Point aPoint( static_cast<const IMapCircleObject*>(&rMapObject)->GetCenter(false) );
     221             : 
     222           0 :             maCenter.X = aPoint.X();
     223           0 :             maCenter.Y = aPoint.Y();
     224             :         }
     225           0 :         break;
     226             :     case IMAP_OBJ_POLYGON:
     227             :     default:
     228             :         {
     229           0 :             const Polygon aPoly( static_cast<const IMapPolygonObject*>(&rMapObject)->GetPolygon(false) );
     230             : 
     231           0 :             const sal_uInt16 nCount = aPoly.GetSize();
     232           0 :             maPolygon.realloc( nCount );
     233           0 :             awt::Point* pPoints = maPolygon.getArray();
     234             : 
     235           0 :             for( sal_uInt16 nPoint = 0; nPoint < nCount; nPoint++ )
     236             :             {
     237           0 :                 const Point& rPoint = aPoly.GetPoint( nPoint );
     238           0 :                 pPoints->X = rPoint.X();
     239           0 :                 pPoints->Y = rPoint.Y();
     240             : 
     241           0 :                 pPoints++;
     242           0 :             }
     243             :         }
     244             :     }
     245             : 
     246           2 :     mpEvents = new SvMacroTableEventDescriptor( rMapObject.GetMacroTable(), pSupportedMacroItems );
     247           2 :     mpEvents->acquire();
     248           2 : }
     249             : 
     250          36 : SvUnoImageMapObject::~SvUnoImageMapObject() throw()
     251             : {
     252          12 :     mpEvents->release();
     253          24 : }
     254             : 
     255           4 : IMapObject* SvUnoImageMapObject::createIMapObject() const
     256             : {
     257           4 :     const OUString aURL( maURL );
     258           8 :     const OUString aAltText( maAltText );
     259           8 :     const OUString aDesc( maDesc );
     260           8 :     const OUString aTarget( maTarget );
     261           8 :     const OUString aName( maName );
     262             : 
     263             :     IMapObject* pNewIMapObject;
     264             : 
     265           4 :     switch( mnType )
     266             :     {
     267             :     case IMAP_OBJ_RECTANGLE:
     268             :         {
     269           2 :             const Rectangle aRect( maBoundary.X, maBoundary.Y, maBoundary.X + maBoundary.Width - 1, maBoundary.Y + maBoundary.Height - 1 );
     270           2 :             pNewIMapObject = new IMapRectangleObject( aRect, aURL, aAltText, aDesc, aTarget, aName, mbIsActive, false );
     271             :         }
     272           2 :         break;
     273             : 
     274             :     case IMAP_OBJ_CIRCLE:
     275             :         {
     276           0 :             const Point aCenter( maCenter.X, maCenter.Y );
     277           0 :             pNewIMapObject = new IMapCircleObject( aCenter, mnRadius, aURL, aAltText, aDesc, aTarget, aName, mbIsActive, false );
     278             :         }
     279           0 :         break;
     280             : 
     281             :     case IMAP_OBJ_POLYGON:
     282             :     default:
     283             :         {
     284           2 :             const sal_uInt16 nCount = (sal_uInt16)maPolygon.getLength();
     285             : 
     286           2 :             Polygon aPoly( nCount );
     287         194 :             for( sal_uInt16 nPoint = 0; nPoint < nCount; nPoint++ )
     288             :             {
     289         192 :                 Point aPoint( maPolygon[nPoint].X, maPolygon[nPoint].Y );
     290         192 :                 aPoly.SetPoint( aPoint, nPoint );
     291             :             }
     292             : 
     293           2 :             aPoly.Optimize( POLY_OPTIMIZE_CLOSE );
     294           2 :             pNewIMapObject = new IMapPolygonObject( aPoly, aURL, aAltText, aDesc, aTarget, aName, mbIsActive, false );
     295             :         }
     296           2 :         break;
     297             :     }
     298             : 
     299           4 :     SvxMacroTableDtor aMacroTable;
     300           4 :     mpEvents->copyMacrosIntoTable(aMacroTable);
     301           4 :     pNewIMapObject->SetMacroTable( aMacroTable );
     302             : 
     303           8 :     return pNewIMapObject;
     304             : }
     305             : 
     306             : // XInterface
     307             : 
     308          16 : Any SAL_CALL SvUnoImageMapObject::queryInterface( const Type & rType )
     309             :     throw( RuntimeException, std::exception )
     310             : {
     311          16 :     return OWeakAggObject::queryInterface( rType );
     312             : }
     313             : 
     314          16 : Any SAL_CALL SvUnoImageMapObject::queryAggregation( const Type & rType )
     315             :     throw(RuntimeException, std::exception)
     316             : {
     317          16 :     Any aAny;
     318             : 
     319          16 :     if( rType == cppu::UnoType<XServiceInfo>::get())
     320           0 :         aAny <<= Reference< XServiceInfo >(this);
     321          16 :     else if( rType == cppu::UnoType<XTypeProvider>::get())
     322           0 :         aAny <<= Reference< XTypeProvider >(this);
     323          16 :     else if( rType == cppu::UnoType<XPropertySet>::get())
     324           2 :         aAny <<= Reference< XPropertySet >(this);
     325          14 :     else if( rType == cppu::UnoType<XEventsSupplier>::get())
     326           0 :         aAny <<= Reference< XEventsSupplier >(this);
     327          14 :     else if( rType == cppu::UnoType<XMultiPropertySet>::get())
     328           0 :         aAny <<= Reference< XMultiPropertySet >(this);
     329          14 :     else if( rType == cppu::UnoType<XUnoTunnel>::get())
     330           4 :         aAny <<= Reference< XUnoTunnel >(this);
     331             :     else
     332          10 :         aAny <<= OWeakAggObject::queryAggregation( rType );
     333             : 
     334          16 :     return aAny;
     335             : }
     336             : 
     337          88 : void SAL_CALL SvUnoImageMapObject::acquire() throw()
     338             : {
     339          88 :     OWeakAggObject::acquire();
     340          88 : }
     341             : 
     342          88 : void SAL_CALL SvUnoImageMapObject::release() throw()
     343             : {
     344          88 :     OWeakAggObject::release();
     345          88 : }
     346             : 
     347           0 : uno::Sequence< uno::Type > SAL_CALL SvUnoImageMapObject::getTypes()
     348             :     throw (uno::RuntimeException, std::exception)
     349             : {
     350           0 :     uno::Sequence< uno::Type > aTypes( 7 );
     351           0 :     uno::Type* pTypes = aTypes.getArray();
     352             : 
     353           0 :     *pTypes++ = cppu::UnoType<XAggregation>::get();
     354           0 :     *pTypes++ = cppu::UnoType<XEventsSupplier>::get();
     355           0 :     *pTypes++ = cppu::UnoType<XServiceInfo>::get();
     356           0 :     *pTypes++ = cppu::UnoType<XPropertySet>::get();
     357           0 :     *pTypes++ = cppu::UnoType<XMultiPropertySet>::get();
     358           0 :     *pTypes++ = cppu::UnoType<XTypeProvider>::get();
     359           0 :     *pTypes++ = cppu::UnoType<XUnoTunnel>::get();
     360             : 
     361           0 :     return aTypes;
     362             : }
     363             : 
     364           0 : uno::Sequence< sal_Int8 > SAL_CALL SvUnoImageMapObject::getImplementationId()
     365             :     throw (uno::RuntimeException, std::exception)
     366             : {
     367           0 :     return css::uno::Sequence<sal_Int8>();
     368             : }
     369             : 
     370             : // XServiceInfo
     371           0 : sal_Bool SAL_CALL SvUnoImageMapObject::supportsService( const  OUString& ServiceName ) throw(RuntimeException, std::exception)
     372             : {
     373           0 :     return cppu::supportsService(this, ServiceName);
     374             : }
     375             : 
     376           0 : Sequence< OUString > SAL_CALL SvUnoImageMapObject::getSupportedServiceNames()
     377             :     throw(RuntimeException, std::exception)
     378             : {
     379           0 :     Sequence< OUString > aSNS( 2 );
     380           0 :     aSNS.getArray()[0] = "com.sun.star.image.ImageMapObject";
     381           0 :     switch( mnType )
     382             :     {
     383             :     case IMAP_OBJ_POLYGON:
     384             :     default:
     385           0 :         aSNS.getArray()[1] = "com.sun.star.image.ImageMapPolygonObject";
     386           0 :         break;
     387             :     case IMAP_OBJ_RECTANGLE:
     388           0 :         aSNS.getArray()[1] = "com.sun.star.image.ImageMapRectangleObject";
     389           0 :         break;
     390             :     case IMAP_OBJ_CIRCLE:
     391           0 :         aSNS.getArray()[1] = "com.sun.star.image.ImageMapCircleObject";
     392           0 :         break;
     393             :     }
     394           0 :     return aSNS;
     395             : }
     396             : 
     397           0 : OUString SAL_CALL SvUnoImageMapObject::getImplementationName() throw(RuntimeException, std::exception)
     398             : {
     399           0 :     switch( mnType )
     400             :     {
     401             :     case IMAP_OBJ_POLYGON:
     402             :     default:
     403           0 :         return OUString("org.openoffice.comp.svt.ImageMapPolygonObject");
     404             :     case IMAP_OBJ_CIRCLE:
     405           0 :         return OUString("org.openoffice.comp.svt.ImageMapCircleObject");
     406             :     case IMAP_OBJ_RECTANGLE:
     407           0 :         return OUString("org.openoffice.comp.svt.ImageMapRectangleObject");
     408             :     }
     409             : }
     410             : 
     411             : // overiden helpers from PropertySetHelper
     412          14 : void SvUnoImageMapObject::_setPropertyValues( const PropertyMapEntry** ppEntries, const Any* pValues )
     413             :     throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException )
     414             : {
     415          14 :     bool bOk = false;
     416             : 
     417          42 :     while( *ppEntries )
     418             :     {
     419          14 :         switch( (*ppEntries)->mnHandle )
     420             :         {
     421             :         case HANDLE_URL:
     422           2 :             bOk = *pValues >>= maURL;
     423           2 :             break;
     424             :         case HANDLE_TITLE:
     425           2 :             bOk = *pValues >>= maAltText;
     426           2 :             break;
     427             :         case HANDLE_DESCRIPTION:
     428           2 :             bOk = *pValues >>= maDesc;
     429           2 :             break;
     430             :         case HANDLE_TARGET:
     431           2 :             bOk = *pValues >>= maTarget;
     432           2 :             break;
     433             :         case HANDLE_NAME:
     434           2 :             bOk = *pValues >>= maName;
     435           2 :             break;
     436             :         case HANDLE_ISACTIVE:
     437           2 :             bOk = *pValues >>= mbIsActive;
     438           2 :             break;
     439             :         case HANDLE_BOUNDARY:
     440           0 :             bOk = *pValues >>= maBoundary;
     441           0 :             break;
     442             :         case HANDLE_CENTER:
     443           0 :             bOk = *pValues >>= maCenter;
     444           0 :             break;
     445             :         case HANDLE_RADIUS:
     446           0 :             bOk = *pValues >>= mnRadius;
     447           0 :             break;
     448             :         case HANDLE_POLYGON:
     449           2 :             bOk = *pValues >>= maPolygon;
     450           2 :             break;
     451             :         default:
     452             :             OSL_FAIL( "SvUnoImageMapObject::_setPropertyValues: unexpected property handle" );
     453           0 :             break;
     454             :         }
     455             : 
     456          14 :         if( !bOk )
     457           0 :             throw IllegalArgumentException();
     458             : 
     459          14 :         ppEntries++;
     460          14 :         pValues++;
     461             :     }
     462          14 : }
     463             : 
     464           0 : void SvUnoImageMapObject::_getPropertyValues( const PropertyMapEntry** ppEntries, Any* pValues )
     465             :     throw(UnknownPropertyException, WrappedTargetException )
     466             : {
     467           0 :     while( *ppEntries )
     468             :     {
     469           0 :         switch( (*ppEntries)->mnHandle )
     470             :         {
     471             :         case HANDLE_URL:
     472           0 :             *pValues <<= maURL;
     473           0 :             break;
     474             :         case HANDLE_TITLE:
     475           0 :             *pValues <<= maAltText;
     476           0 :             break;
     477             :         case HANDLE_DESCRIPTION:
     478           0 :             *pValues <<= maDesc;
     479           0 :             break;
     480             :         case HANDLE_TARGET:
     481           0 :             *pValues <<= maTarget;
     482           0 :             break;
     483             :         case HANDLE_NAME:
     484           0 :             *pValues <<= maName;
     485           0 :             break;
     486             :         case HANDLE_ISACTIVE:
     487           0 :             *pValues <<= mbIsActive;
     488           0 :             break;
     489             :         case HANDLE_BOUNDARY:
     490           0 :             *pValues <<= maBoundary;
     491           0 :             break;
     492             :         case HANDLE_CENTER:
     493           0 :             *pValues <<= maCenter;
     494           0 :             break;
     495             :         case HANDLE_RADIUS:
     496           0 :             *pValues <<= mnRadius;
     497           0 :             break;
     498             :         case HANDLE_POLYGON:
     499           0 :             *pValues <<= maPolygon;
     500           0 :             break;
     501             :         default:
     502             :             OSL_FAIL( "SvUnoImageMapObject::_getPropertyValues: unexpected property handle" );
     503           0 :             break;
     504             :         }
     505             : 
     506           0 :         ppEntries++;
     507           0 :         pValues++;
     508             :     }
     509           0 : }
     510             : 
     511             : 
     512           0 : Reference< XNameReplace > SAL_CALL SvUnoImageMapObject::getEvents()
     513             :     throw( RuntimeException, std::exception )
     514             : {
     515             :     // try weak reference first
     516           0 :     Reference< XNameReplace > xEvents( mpEvents );
     517           0 :     return xEvents;
     518             : }
     519             : 
     520             : 
     521             : 
     522             : class SvUnoImageMap : public WeakImplHelper3< XIndexContainer, XServiceInfo, XUnoTunnel >
     523             : {
     524             : public:
     525             :     SvUnoImageMap( const SvEventDescription* pSupportedMacroItems );
     526             :     SvUnoImageMap( const ImageMap& rMap, const SvEventDescription* pSupportedMacroItems );
     527             :     virtual ~SvUnoImageMap();
     528             : 
     529             :     bool fillImageMap( ImageMap& rMap ) const;
     530             :     SvUnoImageMapObject* getObject( const Any& aElement ) const throw( IllegalArgumentException );
     531             : 
     532             :     UNO3_GETIMPLEMENTATION_DECL( SvUnoImageMap )
     533             : 
     534             :     // XIndexContainer
     535             :     virtual void SAL_CALL insertByIndex( sal_Int32 Index, const Any& Element ) throw( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException, std::exception ) SAL_OVERRIDE;
     536             :     virtual void SAL_CALL removeByIndex( sal_Int32 Index ) throw( IndexOutOfBoundsException, WrappedTargetException, RuntimeException, std::exception ) SAL_OVERRIDE;
     537             : 
     538             :     // XIndexReplace
     539             :     virtual void SAL_CALL replaceByIndex( sal_Int32 Index, const Any& Element ) throw( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException, std::exception ) SAL_OVERRIDE;
     540             : 
     541             :     // XIndexAccess
     542             :     virtual sal_Int32 SAL_CALL getCount(  ) throw( RuntimeException, std::exception ) SAL_OVERRIDE;
     543             :     virtual Any SAL_CALL getByIndex( sal_Int32 Index ) throw( IndexOutOfBoundsException, WrappedTargetException, RuntimeException, std::exception ) SAL_OVERRIDE;
     544             : 
     545             :     // XElementAccess
     546             :     virtual Type SAL_CALL getElementType(  ) throw( RuntimeException, std::exception ) SAL_OVERRIDE;
     547             :     virtual sal_Bool SAL_CALL hasElements(  ) throw( RuntimeException, std::exception ) SAL_OVERRIDE;
     548             : 
     549             :     // XSerivceInfo
     550             :     virtual OUString SAL_CALL getImplementationName(  ) throw( RuntimeException, std::exception ) SAL_OVERRIDE;
     551             :     virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw( RuntimeException, std::exception ) SAL_OVERRIDE;
     552             :     virtual Sequence< OUString > SAL_CALL getSupportedServiceNames(  ) throw( RuntimeException, std::exception ) SAL_OVERRIDE;
     553             : 
     554             : private:
     555             :     OUString maName;
     556             : 
     557             :     std::list< SvUnoImageMapObject* > maObjectList;
     558             : };
     559             : 
     560          16 : UNO3_GETIMPLEMENTATION_IMPL( SvUnoImageMap );
     561             : 
     562           0 : SvUnoImageMap::SvUnoImageMap( const SvEventDescription* )
     563             : {
     564           0 : }
     565             : 
     566          64 : SvUnoImageMap::SvUnoImageMap( const ImageMap& rMap, const SvEventDescription* pSupportedMacroItems )
     567             : {
     568          64 :     maName = rMap.GetName();
     569             : 
     570          64 :     const std::size_t nCount = rMap.GetIMapObjectCount();
     571          66 :     for( std::size_t nPos = 0; nPos < nCount; nPos++ )
     572             :     {
     573           2 :         IMapObject* pMapObject = rMap.GetIMapObject( nPos );
     574           2 :         SvUnoImageMapObject* pUnoObj = new SvUnoImageMapObject( *pMapObject, pSupportedMacroItems );
     575           2 :         pUnoObj->acquire();
     576           2 :         maObjectList.push_back( pUnoObj );
     577             :     }
     578          64 : }
     579             : 
     580         192 : SvUnoImageMap::~SvUnoImageMap()
     581             : {
     582          64 :     std::list< SvUnoImageMapObject* >::iterator aIter = maObjectList.begin();
     583          64 :     const std::list< SvUnoImageMapObject* >::iterator aEnd = maObjectList.end();
     584         134 :     while( aIter != aEnd )
     585             :     {
     586           6 :         (*aIter++)->release();
     587             :     }
     588         128 : }
     589             : 
     590           4 : SvUnoImageMapObject* SvUnoImageMap::getObject( const Any& aElement ) const
     591             :     throw( IllegalArgumentException )
     592             : {
     593           4 :     Reference< XInterface > xObject;
     594           4 :     aElement >>= xObject;
     595             : 
     596           4 :     SvUnoImageMapObject* pObject = SvUnoImageMapObject::getImplementation( xObject );
     597           4 :     if( NULL == pObject )
     598           0 :         throw IllegalArgumentException();
     599             : 
     600           4 :     return pObject;
     601             : }
     602             : 
     603             : // XIndexContainer
     604           4 : void SAL_CALL SvUnoImageMap::insertByIndex( sal_Int32 Index, const Any& Element )
     605             :     throw( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException, std::exception )
     606             : {
     607           4 :     SvUnoImageMapObject* pObject = getObject( Element );
     608           4 :     const sal_Int32 nCount = maObjectList.size();
     609           4 :     if( NULL == pObject || Index > nCount )
     610           0 :         throw IndexOutOfBoundsException();
     611             : 
     612           4 :     pObject->acquire();
     613             : 
     614           4 :     if( Index == nCount )
     615           4 :         maObjectList.push_back( pObject );
     616             :     else
     617             :     {
     618           0 :         std::list< SvUnoImageMapObject* >::iterator aIter = maObjectList.begin();
     619           0 :         for( sal_Int32 n = 0; n < Index; n++ )
     620           0 :             ++aIter;
     621             : 
     622           0 :         maObjectList.insert( aIter, pObject );
     623             :     }
     624           4 : }
     625             : 
     626           0 : void SAL_CALL SvUnoImageMap::removeByIndex( sal_Int32 nIndex ) throw(IndexOutOfBoundsException, WrappedTargetException, RuntimeException, std::exception)
     627             : {
     628           0 :     const sal_Int32 nCount = maObjectList.size();
     629           0 :     if( nIndex >= nCount )
     630           0 :         throw IndexOutOfBoundsException();
     631             : 
     632           0 :     if( nCount - 1 == nIndex )
     633             :     {
     634           0 :         maObjectList.back()->release();
     635           0 :         maObjectList.pop_back();
     636             :     }
     637             :     else
     638             :     {
     639           0 :         std::list< SvUnoImageMapObject* >::iterator aIter = maObjectList.begin();
     640           0 :         std::advance(aIter, nIndex);
     641             : 
     642           0 :         (*aIter)->release();
     643           0 :         maObjectList.erase( aIter );
     644             :     }
     645           0 : }
     646             : 
     647             : // XIndexReplace
     648           0 : void SAL_CALL SvUnoImageMap::replaceByIndex( sal_Int32 Index, const Any& Element ) throw(IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException, std::exception)
     649             : {
     650           0 :     SvUnoImageMapObject* pObject = getObject( Element );
     651           0 :     const sal_Int32 nCount = maObjectList.size();
     652           0 :     if( NULL == pObject || Index >= nCount )
     653           0 :         throw IndexOutOfBoundsException();
     654             : 
     655           0 :     std::list< SvUnoImageMapObject* >::iterator aIter = maObjectList.begin();
     656           0 :     for( sal_Int32 n = 0; n < Index; n++ )
     657           0 :         ++aIter;
     658             : 
     659           0 :     (*aIter)->release();
     660           0 :     *aIter = pObject;
     661           0 :     pObject->acquire();
     662           0 : }
     663             : 
     664             : // XIndexAccess
     665           6 : sal_Int32 SAL_CALL SvUnoImageMap::getCount(  ) throw(RuntimeException, std::exception)
     666             : {
     667           6 :     return maObjectList.size();
     668             : }
     669             : 
     670           0 : Any SAL_CALL SvUnoImageMap::getByIndex( sal_Int32 Index ) throw(IndexOutOfBoundsException, WrappedTargetException, RuntimeException, std::exception)
     671             : {
     672           0 :     const sal_Int32 nCount = maObjectList.size();
     673           0 :     if( Index >= nCount )
     674           0 :         throw IndexOutOfBoundsException();
     675             : 
     676           0 :     std::list< SvUnoImageMapObject* >::iterator aIter = maObjectList.begin();
     677           0 :     for( sal_Int32 n = 0; n < Index; n++ )
     678           0 :         ++aIter;
     679             : 
     680           0 :     Reference< XPropertySet > xObj( *aIter );
     681           0 :     return makeAny( xObj );
     682             : }
     683             : 
     684             : // XElementAccess
     685           0 : Type SAL_CALL SvUnoImageMap::getElementType(  ) throw(RuntimeException, std::exception)
     686             : {
     687           0 :     return cppu::UnoType<XPropertySet>::get();
     688             : }
     689             : 
     690          58 : sal_Bool SAL_CALL SvUnoImageMap::hasElements(  ) throw(RuntimeException, std::exception)
     691             : {
     692          58 :     return (!maObjectList.empty());
     693             : }
     694             : 
     695             : // XSerivceInfo
     696           0 : OUString SAL_CALL SvUnoImageMap::getImplementationName(  )
     697             :     throw(RuntimeException, std::exception)
     698             : {
     699           0 :     return OUString( "org.openoffice.comp.svt.SvUnoImageMap" );
     700             : }
     701             : 
     702           0 : sal_Bool SAL_CALL SvUnoImageMap::supportsService( const OUString& ServiceName )
     703             :     throw(RuntimeException, std::exception)
     704             : {
     705           0 :     return cppu::supportsService(this, ServiceName);
     706             : }
     707             : 
     708           0 : Sequence< OUString > SAL_CALL SvUnoImageMap::getSupportedServiceNames(  )
     709             :     throw(RuntimeException, std::exception)
     710             : {
     711           0 :     const OUString aSN( "com.sun.star.image.ImageMap" );
     712           0 :     return Sequence< OUString >( &aSN, 1 );
     713             : }
     714             : 
     715           4 : bool SvUnoImageMap::fillImageMap( ImageMap& rMap ) const
     716             : {
     717           4 :     rMap.ClearImageMap();
     718             : 
     719           4 :     rMap.SetName( maName );
     720             : 
     721           4 :     std::list< SvUnoImageMapObject* >::const_iterator aIter = maObjectList.begin();
     722           4 :     const std::list< SvUnoImageMapObject* >::const_iterator aEnd = maObjectList.end();
     723          12 :     while( aIter != aEnd )
     724             :     {
     725           4 :         IMapObject* pNewMapObject = (*aIter)->createIMapObject();
     726           4 :         rMap.InsertIMapObject( *pNewMapObject );
     727           4 :         delete pNewMapObject;
     728             : 
     729           4 :         ++aIter;
     730             :     }
     731             : 
     732           4 :     return true;
     733             : }
     734             : 
     735             : 
     736             : // factory helper methods
     737             : 
     738             : 
     739           4 : Reference< XInterface > SvUnoImageMapRectangleObject_createInstance( const SvEventDescription* pSupportedMacroItems )
     740             : {
     741           4 :     return (XWeak*)new SvUnoImageMapObject( IMAP_OBJ_RECTANGLE, pSupportedMacroItems );
     742             : }
     743             : 
     744           2 : Reference< XInterface > SvUnoImageMapCircleObject_createInstance( const SvEventDescription* pSupportedMacroItems )
     745             : {
     746           2 :     return (XWeak*)new SvUnoImageMapObject( IMAP_OBJ_CIRCLE, pSupportedMacroItems );
     747             : }
     748             : 
     749           4 : Reference< XInterface > SvUnoImageMapPolygonObject_createInstance( const SvEventDescription* pSupportedMacroItems )
     750             : {
     751           4 :     return (XWeak*)new SvUnoImageMapObject( IMAP_OBJ_POLYGON, pSupportedMacroItems );
     752             : }
     753             : 
     754           0 : Reference< XInterface > SvUnoImageMap_createInstance( const SvEventDescription* pSupportedMacroItems )
     755             : {
     756           0 :     return (XWeak*)new SvUnoImageMap( pSupportedMacroItems );
     757             : }
     758             : 
     759          64 : Reference< XInterface > SvUnoImageMap_createInstance( const ImageMap& rMap, const SvEventDescription* pSupportedMacroItems )
     760             : {
     761          64 :     return (XWeak*)new SvUnoImageMap( rMap, pSupportedMacroItems );
     762             : }
     763             : 
     764           4 : bool SvUnoImageMap_fillImageMap( Reference< XInterface > xImageMap, ImageMap& rMap )
     765             : {
     766           4 :     SvUnoImageMap* pUnoImageMap = SvUnoImageMap::getImplementation( xImageMap );
     767           4 :     if( NULL == pUnoImageMap )
     768           0 :         return false;
     769             : 
     770           4 :     return pUnoImageMap->fillImageMap( rMap );
     771        1227 : }
     772             : 
     773             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10