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

Generated by: LCOV version 1.10