LCOV - code coverage report
Current view: top level - svx/source/unodraw - unopool.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 106 171 62.0 %
Date: 2014-11-03 Functions: 16 24 66.7 %
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/lang/XServiceInfo.hpp>
      21             : #include <com/sun/star/beans/PropertyState.hpp>
      22             : 
      23             : #include <comphelper/propertysetinfo.hxx>
      24             : #include <comphelper/servicehelper.hxx>
      25             : #include <cppuhelper/supportsservice.hxx>
      26             : #include <osl/mutex.hxx>
      27             : #include <vcl/svapp.hxx>
      28             : #include "svx/unopool.hxx"
      29             : #include <svx/svdmodel.hxx>
      30             : #include <svx/svdpool.hxx>
      31             : #include <svx/unoprov.hxx>
      32             : #include <svx/svdobj.hxx>
      33             : #include <svx/unoshprp.hxx>
      34             : #include <svx/xflbstit.hxx>
      35             : #include <svx/xflbmtit.hxx>
      36             : #include <svx/unopage.hxx>
      37             : #include <svx/svdetc.hxx>
      38             : #include <editeng/editeng.hxx>
      39             : 
      40             : #include "svx/unoapi.hxx"
      41             : #include <boost/scoped_ptr.hpp>
      42             : 
      43             : using namespace ::com::sun::star;
      44             : using namespace ::cppu;
      45             : 
      46         434 : SvxUnoDrawPool::SvxUnoDrawPool(SdrModel* pModel, sal_Int32 nServiceId)
      47         434 : : PropertySetHelper( SvxPropertySetInfoPool::getOrCreate( nServiceId ) ), mpModel( pModel )
      48             : {
      49         434 :     init();
      50         434 : }
      51             : 
      52             : /* deprecated */
      53         210 : SvxUnoDrawPool::SvxUnoDrawPool(SdrModel* pModel)
      54         210 : : PropertySetHelper( SvxPropertySetInfoPool::getOrCreate( SVXUNO_SERVICEID_COM_SUN_STAR_DRAWING_DEFAULTS ) ), mpModel( pModel )
      55             : {
      56         210 :     init();
      57         210 : }
      58             : 
      59        1284 : SvxUnoDrawPool::~SvxUnoDrawPool() throw()
      60             : {
      61         642 :     if (mpDefaultsPool)
      62             :     {
      63         642 :         SfxItemPool* pOutlPool = mpDefaultsPool->GetSecondaryPool();
      64         642 :         SfxItemPool::Free(mpDefaultsPool);
      65         642 :         SfxItemPool::Free(pOutlPool);
      66             :     }
      67         642 : }
      68             : 
      69         644 : void SvxUnoDrawPool::init()
      70             : {
      71         644 :     mpDefaultsPool = new SdrItemPool();
      72         644 :     SfxItemPool* pOutlPool=EditEngine::CreatePool();
      73         644 :     mpDefaultsPool->SetSecondaryPool(pOutlPool);
      74             : 
      75         644 :     SdrModel::SetTextDefaults( mpDefaultsPool, SdrEngineDefaults::GetFontHeight() );
      76         644 :     mpDefaultsPool->SetDefaultMetric((SfxMapUnit)SdrEngineDefaults::GetMapUnit());
      77         644 :     mpDefaultsPool->FreezeIdRanges();
      78         644 : }
      79             : 
      80         812 : SfxItemPool* SvxUnoDrawPool::getModelPool( bool bReadOnly ) throw()
      81             : {
      82         812 :     if( mpModel )
      83             :     {
      84         812 :         return &mpModel->GetItemPool();
      85             :     }
      86             :     else
      87             :     {
      88           0 :         if( bReadOnly )
      89           0 :             return mpDefaultsPool;
      90             :         else
      91           0 :             return NULL;
      92             :     }
      93             : }
      94             : 
      95        3460 : void SvxUnoDrawPool::getAny( SfxItemPool* pPool, const comphelper::PropertyMapEntry* pEntry, uno::Any& rValue )
      96             :     throw(beans::UnknownPropertyException)
      97             : {
      98        3460 :     switch( pEntry->mnHandle )
      99             :     {
     100             :     case OWN_ATTR_FILLBMP_MODE:
     101             :         {
     102           0 :             const XFillBmpStretchItem* pStretchItem = static_cast<const XFillBmpStretchItem*>(&pPool->GetDefaultItem(XATTR_FILLBMP_STRETCH));
     103           0 :             const XFillBmpTileItem* pTileItem = static_cast<const XFillBmpTileItem*>(&pPool->GetDefaultItem(XATTR_FILLBMP_TILE));
     104           0 :             if( pTileItem && pTileItem->GetValue() )
     105             :             {
     106           0 :                 rValue <<= drawing::BitmapMode_REPEAT;
     107             :             }
     108           0 :             else if( pStretchItem && pStretchItem->GetValue() )
     109             :             {
     110           0 :                 rValue <<= drawing::BitmapMode_STRETCH;
     111             :             }
     112             :             else
     113             :             {
     114           0 :                 rValue <<= drawing::BitmapMode_NO_REPEAT;
     115             :             }
     116           0 :             break;
     117             :         }
     118             :     default:
     119             :         {
     120        3460 :             const SfxMapUnit eMapUnit = pPool->GetMetric((sal_uInt16)pEntry->mnHandle);
     121             : 
     122        3460 :             sal_uInt8 nMemberId = pEntry->mnMemberId & (~SFX_METRIC_ITEM);
     123        3460 :             if( eMapUnit == SFX_MAPUNIT_100TH_MM )
     124        1118 :                 nMemberId &= (~CONVERT_TWIPS);
     125             : 
     126             :             // DVO, OD 10.10.2003 #i18732#
     127             :             // Assure, that ID is a Which-ID (it could be a Slot-ID.)
     128             :             // Thus, convert handle to Which-ID.
     129        3460 :             pPool->GetDefaultItem( pPool->GetWhich( (sal_uInt16)pEntry->mnHandle ) ).QueryValue( rValue, nMemberId );
     130             :         }
     131             :     }
     132             : 
     133             : 
     134             :     // check for needed metric translation
     135        3460 :     const SfxMapUnit eMapUnit = pPool->GetMetric((sal_uInt16)pEntry->mnHandle);
     136        3460 :     if(pEntry->mnMemberId & SFX_METRIC_ITEM && eMapUnit != SFX_MAPUNIT_100TH_MM)
     137             :     {
     138         120 :         SvxUnoConvertToMM( eMapUnit, rValue );
     139             :     }
     140             :     // convert int32 to correct enum type if needed
     141        3340 :     else if ( pEntry->maType.getTypeClass() == uno::TypeClass_ENUM && rValue.getValueType() == ::cppu::UnoType<sal_Int32>::get() )
     142             :     {
     143             :         sal_Int32 nEnum;
     144           0 :         rValue >>= nEnum;
     145             : 
     146           0 :         rValue.setValue( &nEnum, pEntry->maType );
     147             :     }
     148        3460 : }
     149             : 
     150       15310 : void SvxUnoDrawPool::putAny( SfxItemPool* pPool, const comphelper::PropertyMapEntry* pEntry, const uno::Any& rValue )
     151             :     throw(beans::UnknownPropertyException, lang::IllegalArgumentException, uno::RuntimeException)
     152             : {
     153       15310 :     uno::Any aValue( rValue );
     154             : 
     155       15310 :     const SfxMapUnit eMapUnit = pPool->GetMetric((sal_uInt16)pEntry->mnHandle);
     156       15310 :     if(pEntry->mnMemberId & SFX_METRIC_ITEM && eMapUnit != SFX_MAPUNIT_100TH_MM)
     157             :     {
     158         612 :         SvxUnoConvertFromMM( eMapUnit, aValue );
     159             :     }
     160             : 
     161             :     // DVO, OD 10.10.2003 #i18732#
     162             :     // Assure, that ID is a Which-ID (it could be a Slot-ID.)
     163             :     // Thus, convert handle to Which-ID.
     164       15310 :     const sal_uInt16 nWhich = pPool->GetWhich( (sal_uInt16)pEntry->mnHandle );
     165       15310 :     switch( nWhich )
     166             :     {
     167             :         case OWN_ATTR_FILLBMP_MODE:
     168             :             do
     169             :             {
     170             :                 drawing::BitmapMode eMode;
     171           0 :                 if(!(aValue >>= eMode) )
     172             :                 {
     173           0 :                     sal_Int32 nMode = 0;
     174           0 :                     if(!(aValue >>= nMode))
     175           0 :                         throw lang::IllegalArgumentException();
     176             : 
     177           0 :                     eMode = (drawing::BitmapMode)nMode;
     178             :                 }
     179             : 
     180           0 :                 pPool->SetPoolDefaultItem( XFillBmpStretchItem( eMode == drawing::BitmapMode_STRETCH ) );
     181           0 :                 pPool->SetPoolDefaultItem( XFillBmpTileItem( eMode == drawing::BitmapMode_REPEAT ) );
     182       15310 :                 return;
     183             :             }
     184             :             while(false);
     185             : 
     186             :     default:
     187             :         {
     188       15310 :             boost::scoped_ptr<SfxPoolItem> pNewItem( pPool->GetDefaultItem( nWhich ).Clone() );
     189       15310 :             sal_uInt8 nMemberId = pEntry->mnMemberId & (~SFX_METRIC_ITEM);
     190       15310 :             if( pPool->GetMetric(nWhich) == SFX_MAPUNIT_100TH_MM )
     191        3850 :                 nMemberId &= (~CONVERT_TWIPS);
     192             : 
     193       15310 :             if( !pNewItem->PutValue( aValue, nMemberId ) )
     194           0 :                 throw lang::IllegalArgumentException();
     195             : 
     196       15310 :             pPool->SetPoolDefaultItem( *pNewItem );
     197             :         }
     198       15310 :     }
     199             : }
     200             : 
     201        1160 : void SvxUnoDrawPool::_setPropertyValues( const comphelper::PropertyMapEntry** ppEntries, const uno::Any* pValues )
     202             :     throw(beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException )
     203             : {
     204        1160 :     SolarMutexGuard aGuard;
     205             : 
     206        1160 :     SfxItemPool* pPool = getModelPool( false );
     207             : 
     208             :     DBG_ASSERT( pPool, "I need a SfxItemPool!" );
     209        1160 :     if( NULL == pPool )
     210           0 :         throw beans::UnknownPropertyException();
     211             : 
     212       17630 :     while( *ppEntries )
     213       16470 :         putAny( pPool, *ppEntries++, *pValues++ );
     214        1160 : }
     215             : 
     216        3460 : void SvxUnoDrawPool::_getPropertyValues( const comphelper::PropertyMapEntry** ppEntries, uno::Any* pValue )
     217             :     throw(beans::UnknownPropertyException, lang::WrappedTargetException )
     218             : {
     219        3460 :     SolarMutexGuard aGuard;
     220             : 
     221        3460 :     SfxItemPool* pPool = getModelPool( true );
     222             : 
     223             :     DBG_ASSERT( pPool, "I need a SfxItemPool!" );
     224        3460 :     if( NULL == pPool )
     225           0 :         throw beans::UnknownPropertyException();
     226             : 
     227       10380 :     while( *ppEntries )
     228        6920 :         getAny( pPool, *ppEntries++, *pValue++ );
     229        3460 : }
     230             : 
     231          94 : void SvxUnoDrawPool::_getPropertyStates( const comphelper::PropertyMapEntry** ppEntries, beans::PropertyState* pStates )
     232             :     throw(beans::UnknownPropertyException )
     233             : {
     234          94 :     SolarMutexGuard aGuard;
     235             : 
     236          94 :     SfxItemPool* pPool = getModelPool( true );
     237             : 
     238          94 :     if( pPool && pPool != mpDefaultsPool )
     239             :     {
     240       13348 :         while( *ppEntries )
     241             :         {
     242             :             // OD 13.10.2003 #i18732#
     243             :             // Assure, that ID is a Which-ID (it could be a Slot-ID.)
     244             :             // Thus, convert handle to Which-ID.
     245       13160 :             const sal_uInt16 nWhich = pPool->GetWhich( ((sal_uInt16)(*ppEntries)->mnHandle) );
     246             : 
     247       13160 :             switch( nWhich )
     248             :             {
     249             :             case OWN_ATTR_FILLBMP_MODE:
     250             :                 {
     251             :                     // use method <IsStaticDefaultItem(..)> instead of using
     252             :                     // probably incompatible item pool <mpDefaultPool>.
     253          94 :                     if ( IsStaticDefaultItem( &(pPool->GetDefaultItem( XATTR_FILLBMP_STRETCH )) ) ||
     254           0 :                          IsStaticDefaultItem( &(pPool->GetDefaultItem( XATTR_FILLBMP_TILE )) ) )
     255             :                     {
     256          94 :                         *pStates = beans::PropertyState_DEFAULT_VALUE;
     257             :                     }
     258             :                     else
     259             :                     {
     260           0 :                         *pStates = beans::PropertyState_DIRECT_VALUE;
     261             :                     }
     262             :                 }
     263          94 :                 break;
     264             :             default:
     265             :                 // OD 13.10.2003 #i18732# - correction:
     266             :                 // use method <IsStaticDefaultItem(..)> instead of using probably
     267             :                 // incompatible item pool <mpDefaultPool>.
     268       13066 :                 const SfxPoolItem& r1 = pPool->GetDefaultItem( nWhich );
     269             :                 //const SfxPoolItem& r2 = mpDefaultPool->GetDefaultItem( nWhich );
     270             : 
     271       13066 :                 if ( IsStaticDefaultItem( &r1 ) )
     272             :                 {
     273        9952 :                     *pStates = beans::PropertyState_DEFAULT_VALUE;
     274             :                 }
     275             :                 else
     276             :                 {
     277        3114 :                     *pStates = beans::PropertyState_DIRECT_VALUE;
     278             :                 }
     279             :             }
     280             : 
     281       13160 :             pStates++;
     282       13160 :             ppEntries++;
     283          94 :         }
     284             :     }
     285             :     else
     286             :     {
     287             :         // as long as we have no model, all properties are default
     288           0 :         while( *ppEntries++ )
     289           0 :             *pStates++ = beans::PropertyState_DEFAULT_VALUE;
     290          94 :         return;
     291          94 :     }
     292             : }
     293             : 
     294           0 : void SvxUnoDrawPool::_setPropertyToDefault( const comphelper::PropertyMapEntry* pEntry )
     295             :     throw(beans::UnknownPropertyException )
     296             : {
     297           0 :     SolarMutexGuard aGuard;
     298             : 
     299           0 :     SfxItemPool* pPool = getModelPool( true );
     300             : 
     301             :     // OD 10.10.2003 #i18732#
     302             :     // Assure, that ID is a Which-ID (it could be a Slot-ID.)
     303             :     // Thus, convert handle to Which-ID.
     304           0 :     const sal_uInt16 nWhich = pPool->GetWhich( (sal_uInt16)pEntry->mnHandle );
     305           0 :     if ( pPool && pPool != mpDefaultsPool )
     306             :     {
     307             :         // OD 13.10.2003 #i18732# - use method <ResetPoolDefaultItem(..)>
     308             :         // instead of using probably incompatible item pool <mpDefaultsPool>.
     309           0 :         pPool->ResetPoolDefaultItem( nWhich );
     310           0 :     }
     311           0 : }
     312             : 
     313           0 : uno::Any SvxUnoDrawPool::_getPropertyDefault( const comphelper::PropertyMapEntry* pEntry )
     314             :     throw(beans::UnknownPropertyException, lang::WrappedTargetException )
     315             : {
     316           0 :     SolarMutexGuard aGuard;
     317             : 
     318             :     // OD 13.10.2003 #i18732# - use method <GetPoolDefaultItem(..)> instead of
     319             :     // using probably incompatible item pool <mpDefaultsPool>
     320           0 :     uno::Any aAny;
     321           0 :     SfxItemPool* pPool = getModelPool( true );
     322           0 :     const sal_uInt16 nWhich = pPool->GetWhich( (sal_uInt16)pEntry->mnHandle );
     323           0 :     const SfxPoolItem *pItem = pPool->GetPoolDefaultItem ( nWhich );
     324           0 :     pItem->QueryValue( aAny, pEntry->mnMemberId );
     325             : 
     326           0 :     return aAny;
     327             : }
     328             : 
     329             : // XInterface
     330             : 
     331        2140 : uno::Any SAL_CALL SvxUnoDrawPool::queryInterface( const uno::Type & rType )
     332             :     throw( uno::RuntimeException, std::exception )
     333             : {
     334        2140 :     return OWeakAggObject::queryInterface( rType );
     335             : }
     336             : 
     337        2140 : uno::Any SAL_CALL SvxUnoDrawPool::queryAggregation( const uno::Type & rType )
     338             :     throw(uno::RuntimeException, std::exception)
     339             : {
     340        2140 :     uno::Any aAny;
     341             : 
     342        2140 :     if( rType == cppu::UnoType<lang::XServiceInfo>::get())
     343           0 :         aAny <<= uno::Reference< lang::XServiceInfo >(this);
     344        2140 :     else if( rType == cppu::UnoType<lang::XTypeProvider>::get())
     345           0 :         aAny <<= uno::Reference< lang::XTypeProvider >(this);
     346        2140 :     else if( rType == cppu::UnoType<beans::XPropertySet>::get())
     347         700 :         aAny <<= uno::Reference< beans::XPropertySet >(this);
     348        1440 :     else if( rType == cppu::UnoType<beans::XPropertyState>::get())
     349          94 :         aAny <<= uno::Reference< beans::XPropertyState >(this);
     350        1346 :     else if( rType == cppu::UnoType<beans::XMultiPropertySet>::get())
     351         672 :         aAny <<= uno::Reference< beans::XMultiPropertySet >(this);
     352             :     else
     353         674 :         aAny <<= OWeakAggObject::queryAggregation( rType );
     354             : 
     355        2140 :     return aAny;
     356             : }
     357             : 
     358        5496 : void SAL_CALL SvxUnoDrawPool::acquire() throw ( )
     359             : {
     360        5496 :     OWeakAggObject::acquire();
     361        5496 : }
     362             : 
     363        5494 : void SAL_CALL SvxUnoDrawPool::release() throw ( )
     364             : {
     365        5494 :     OWeakAggObject::release();
     366        5494 : }
     367             : 
     368           0 : uno::Sequence< uno::Type > SAL_CALL SvxUnoDrawPool::getTypes()
     369             :     throw (uno::RuntimeException, std::exception)
     370             : {
     371           0 :     uno::Sequence< uno::Type > aTypes( 6 );
     372           0 :     uno::Type* pTypes = aTypes.getArray();
     373             : 
     374           0 :     *pTypes++ = cppu::UnoType<uno::XAggregation>::get();
     375           0 :     *pTypes++ = cppu::UnoType<lang::XServiceInfo>::get();
     376           0 :     *pTypes++ = cppu::UnoType<lang::XTypeProvider>::get();
     377           0 :     *pTypes++ = cppu::UnoType<beans::XPropertySet>::get();
     378           0 :     *pTypes++ = cppu::UnoType<beans::XPropertyState>::get();
     379           0 :     *pTypes++ = cppu::UnoType<beans::XMultiPropertySet>::get();
     380             : 
     381           0 :     return aTypes;
     382             : }
     383             : 
     384           0 : uno::Sequence< sal_Int8 > SAL_CALL SvxUnoDrawPool::getImplementationId()
     385             :     throw (uno::RuntimeException, std::exception)
     386             : {
     387           0 :     return css::uno::Sequence<sal_Int8>();
     388             : }
     389             : 
     390             : // XServiceInfo
     391           0 : sal_Bool SAL_CALL SvxUnoDrawPool::supportsService( const  OUString& ServiceName ) throw(uno::RuntimeException, std::exception)
     392             : {
     393           0 :     return cppu::supportsService(this, ServiceName);
     394             : }
     395             : 
     396           0 : OUString SAL_CALL SvxUnoDrawPool::getImplementationName() throw( uno::RuntimeException, std::exception )
     397             : {
     398           0 :     return OUString("SvxUnoDrawPool");
     399             : }
     400             : 
     401           0 : uno::Sequence< OUString > SAL_CALL SvxUnoDrawPool::getSupportedServiceNames(  )
     402             :     throw( uno::RuntimeException, std::exception )
     403             : {
     404           0 :     uno::Sequence< OUString > aSNS( 1 );
     405           0 :     aSNS.getArray()[0] = "com.sun.star.drawing.Defaults";
     406           0 :     return aSNS;
     407         594 : }
     408             : 
     409             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10