LCOV - code coverage report
Current view: top level - libreoffice/svx/source/unodraw - unopool.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 107 175 61.1 %
Date: 2012-12-27 Functions: 15 22 68.2 %
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 <osl/mutex.hxx>
      26             : #include <vcl/svapp.hxx>
      27             : #include "svx/unopool.hxx"
      28             : #include <svx/svdmodel.hxx>
      29             : #include <svx/svdpool.hxx>
      30             : #include <svx/unoprov.hxx>
      31             : #include <svx/svdobj.hxx>
      32             : #include <svx/unoshprp.hxx>
      33             : #include <svx/xflbstit.hxx>
      34             : #include <svx/xflbmtit.hxx>
      35             : #include <svx/unopage.hxx>
      36             : #include <svx/svdetc.hxx>
      37             : #include <editeng/editeng.hxx>
      38             : 
      39             : #include "svx/unoapi.hxx"
      40             : #include <memory>
      41             : 
      42             : using namespace ::com::sun::star;
      43             : using namespace ::rtl;
      44             : using namespace ::cppu;
      45             : 
      46          17 : SvxUnoDrawPool::SvxUnoDrawPool( SdrModel* pModel, sal_Int32 nServiceId ) throw()
      47          17 : : PropertySetHelper( SvxPropertySetInfoPool::getOrCreate( nServiceId ) ), mpModel( pModel )
      48             : {
      49          17 :     init();
      50          17 : }
      51             : 
      52             : /* deprecated */
      53           3 : SvxUnoDrawPool::SvxUnoDrawPool( SdrModel* pModel ) throw()
      54           3 : : PropertySetHelper( SvxPropertySetInfoPool::getOrCreate( SVXUNO_SERVICEID_COM_SUN_STAR_DRAWING_DEFAULTS ) ), mpModel( pModel )
      55             : {
      56           3 :     init();
      57           3 : }
      58             : 
      59          32 : SvxUnoDrawPool::~SvxUnoDrawPool() throw()
      60             : {
      61          16 :     if (mpDefaultsPool)
      62             :     {
      63          16 :         SfxItemPool* pOutlPool = mpDefaultsPool->GetSecondaryPool();
      64          16 :         SfxItemPool::Free(mpDefaultsPool);
      65          16 :         SfxItemPool::Free(pOutlPool);
      66             :     }
      67          16 : }
      68             : 
      69          20 : void SvxUnoDrawPool::init()
      70             : {
      71          20 :     mpDefaultsPool = new SdrItemPool();
      72          20 :     SfxItemPool* pOutlPool=EditEngine::CreatePool();
      73          20 :     mpDefaultsPool->SetSecondaryPool(pOutlPool);
      74             : 
      75          20 :     SdrModel::SetTextDefaults( mpDefaultsPool, SdrEngineDefaults::GetFontHeight() );
      76          20 :     mpDefaultsPool->SetDefaultMetric((SfxMapUnit)SdrEngineDefaults::GetMapUnit());
      77          20 :     mpDefaultsPool->FreezeIdRanges();
      78          20 : }
      79             : 
      80           4 : SfxItemPool* SvxUnoDrawPool::getModelPool( sal_Bool bReadOnly ) throw()
      81             : {
      82           4 :     if( mpModel )
      83             :     {
      84           4 :         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          79 : void SvxUnoDrawPool::getAny( SfxItemPool* pPool, const comphelper::PropertyMapEntry* pEntry, uno::Any& rValue )
      96             :     throw(beans::UnknownPropertyException)
      97             : {
      98          79 :     switch( pEntry->mnHandle )
      99             :     {
     100             :     case OWN_ATTR_FILLBMP_MODE:
     101             :         {
     102           0 :             XFillBmpStretchItem* pStretchItem = (XFillBmpStretchItem*)&pPool->GetDefaultItem(XATTR_FILLBMP_STRETCH);
     103           0 :             XFillBmpTileItem* pTileItem = (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          79 :             const SfxMapUnit eMapUnit = pPool ? pPool->GetMetric((sal_uInt16)pEntry->mnHandle) : SFX_MAPUNIT_100TH_MM;
     121             : 
     122          79 :             sal_uInt8 nMemberId = pEntry->mnMemberId & (~SFX_METRIC_ITEM);
     123          79 :             if( eMapUnit == SFX_MAPUNIT_100TH_MM )
     124           0 :                 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          79 :             pPool->GetDefaultItem( pPool->GetWhich( (sal_uInt16)pEntry->mnHandle ) ).QueryValue( rValue, nMemberId );
     130             :         }
     131             :     }
     132             : 
     133             : 
     134             :     // check for needed metric translation
     135          79 :     const SfxMapUnit eMapUnit = pPool->GetMetric((sal_uInt16)pEntry->mnHandle);
     136          79 :     if(pEntry->mnMemberId & SFX_METRIC_ITEM && eMapUnit != SFX_MAPUNIT_100TH_MM)
     137             :     {
     138           4 :         SvxUnoConvertToMM( eMapUnit, rValue );
     139             :     }
     140             :     // convert int32 to correct enum type if needed
     141          75 :     else if ( pEntry->mpType->getTypeClass() == uno::TypeClass_ENUM && rValue.getValueType() == ::getCppuType((const sal_Int32*)0) )
     142             :     {
     143             :         sal_Int32 nEnum;
     144           0 :         rValue >>= nEnum;
     145             : 
     146           0 :         rValue.setValue( &nEnum, *pEntry->mpType );
     147             :     }
     148          79 : }
     149             : 
     150         561 : void SvxUnoDrawPool::putAny( SfxItemPool* pPool, const comphelper::PropertyMapEntry* pEntry, const uno::Any& rValue )
     151             :     throw(beans::UnknownPropertyException, lang::IllegalArgumentException)
     152             : {
     153         561 :     uno::Any aValue( rValue );
     154             : 
     155         561 :     const SfxMapUnit eMapUnit = pPool->GetMetric((sal_uInt16)pEntry->mnHandle);
     156         561 :     if(pEntry->mnMemberId & SFX_METRIC_ITEM && eMapUnit != SFX_MAPUNIT_100TH_MM)
     157             :     {
     158          34 :         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         561 :     const sal_uInt16 nWhich = pPool->GetWhich( (sal_uInt16)pEntry->mnHandle );
     165         561 :     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         561 :                 return;
     183             :             }
     184             :             while(0);
     185             : 
     186             :     default:
     187             :         {
     188         561 :             ::std::auto_ptr<SfxPoolItem> pNewItem( pPool->GetDefaultItem( nWhich ).Clone() );
     189         561 :             sal_uInt8 nMemberId = pEntry->mnMemberId & (~SFX_METRIC_ITEM);
     190         561 :             if( !pPool || (pPool->GetMetric(nWhich) == SFX_MAPUNIT_100TH_MM) )
     191          98 :                 nMemberId &= (~CONVERT_TWIPS);
     192             : 
     193         561 :             if( !pNewItem->PutValue( aValue, nMemberId ) )
     194           0 :                 throw lang::IllegalArgumentException();
     195             : 
     196         561 :             pPool->SetPoolDefaultItem( *pNewItem );
     197             :         }
     198         561 :     }
     199             : }
     200             : 
     201          40 : void SvxUnoDrawPool::_setPropertyValues( const comphelper::PropertyMapEntry** ppEntries, const uno::Any* pValues )
     202             :     throw(beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException )
     203             : {
     204          40 :     SolarMutexGuard aGuard;
     205             : 
     206          40 :     SfxItemPool* pPool = getModelPool( sal_False );
     207             : 
     208             :     DBG_ASSERT( pPool, "I need a SfxItemPool!" );
     209          40 :     if( NULL == pPool )
     210           0 :         throw beans::UnknownPropertyException();
     211             : 
     212         641 :     while( *ppEntries )
     213         601 :         putAny( pPool, *ppEntries++, *pValues++ );
     214          40 : }
     215             : 
     216          79 : void SvxUnoDrawPool::_getPropertyValues( const comphelper::PropertyMapEntry** ppEntries, uno::Any* pValue )
     217             :     throw(beans::UnknownPropertyException, lang::WrappedTargetException )
     218             : {
     219          79 :     SolarMutexGuard aGuard;
     220             : 
     221          79 :     SfxItemPool* pPool = getModelPool( sal_True );
     222             : 
     223             :     DBG_ASSERT( pPool, "I need a SfxItemPool!" );
     224          79 :     if( NULL == pPool )
     225           0 :         throw beans::UnknownPropertyException();
     226             : 
     227         237 :     while( *ppEntries )
     228         158 :         getAny( pPool, *ppEntries++, *pValue++ );
     229          79 : }
     230             : 
     231           2 : void SvxUnoDrawPool::_getPropertyStates( const comphelper::PropertyMapEntry** ppEntries, beans::PropertyState* pStates )
     232             :     throw(beans::UnknownPropertyException )
     233             : {
     234           2 :     SolarMutexGuard aGuard;
     235             : 
     236           2 :     SfxItemPool* pPool = getModelPool( sal_True );
     237             : 
     238           2 :     if( pPool && pPool != mpDefaultsPool )
     239             :     {
     240         280 :         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         276 :             const sal_uInt16 nWhich = pPool->GetWhich( ((sal_uInt16)(*ppEntries)->mnHandle) );
     246             : 
     247         276 :             switch( nWhich )
     248             :             {
     249             :             case OWN_ATTR_FILLBMP_MODE:
     250             :                 {
     251             :                     // use method <IsStaticDefaultItem(..)> instead of using
     252             :                     // probably incompatible item pool <mpDefaultPool>.
     253           2 :                     if ( IsStaticDefaultItem( &(pPool->GetDefaultItem( XATTR_FILLBMP_STRETCH )) ) ||
     254           0 :                          IsStaticDefaultItem( &(pPool->GetDefaultItem( XATTR_FILLBMP_TILE )) ) )
     255             :                     {
     256           2 :                         *pStates = beans::PropertyState_DEFAULT_VALUE;
     257             :                     }
     258             :                     else
     259             :                     {
     260           0 :                         *pStates = beans::PropertyState_DIRECT_VALUE;
     261             :                     }
     262             :                 }
     263           2 :                 break;
     264             :             default:
     265             :                 // OD 13.10.2003 #i18732# - correction:
     266             :                 // use method <IsStaticDefaultItem(..)> instead of using probably
     267             :                 // incompatible item pool <mpDefaultPool>.
     268         274 :                 const SfxPoolItem& r1 = pPool->GetDefaultItem( nWhich );
     269             :                 //const SfxPoolItem& r2 = mpDefaultPool->GetDefaultItem( nWhich );
     270             : 
     271         274 :                 if ( IsStaticDefaultItem( &r1 ) )
     272             :                 {
     273         195 :                     *pStates = beans::PropertyState_DEFAULT_VALUE;
     274             :                 }
     275             :                 else
     276             :                 {
     277          79 :                     *pStates = beans::PropertyState_DIRECT_VALUE;
     278             :                 }
     279             :             }
     280             : 
     281         276 :             pStates++;
     282         276 :             ppEntries++;
     283           2 :         }
     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           2 :         return;
     291           2 :     }
     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( sal_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( sal_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          70 : uno::Any SAL_CALL SvxUnoDrawPool::queryInterface( const uno::Type & rType )
     332             :     throw( uno::RuntimeException )
     333             : {
     334          70 :     return OWeakAggObject::queryInterface( rType );
     335             : }
     336             : 
     337          70 : uno::Any SAL_CALL SvxUnoDrawPool::queryAggregation( const uno::Type & rType )
     338             :     throw(uno::RuntimeException)
     339             : {
     340          70 :     uno::Any aAny;
     341             : 
     342          70 :     if( rType == ::getCppuType((const uno::Reference< lang::XServiceInfo >*)0) )
     343           0 :         aAny <<= uno::Reference< lang::XServiceInfo >(this);
     344          70 :     else if( rType == ::getCppuType((const uno::Reference< lang::XTypeProvider >*)0) )
     345           2 :         aAny <<= uno::Reference< lang::XTypeProvider >(this);
     346          68 :     else if( rType == ::getCppuType((const uno::Reference< beans::XPropertySet >*)0) )
     347          22 :         aAny <<= uno::Reference< beans::XPropertySet >(this);
     348          46 :     else if( rType == ::getCppuType((const uno::Reference< beans::XPropertyState >*)0) )
     349           2 :         aAny <<= uno::Reference< beans::XPropertyState >(this);
     350          44 :     else if( rType == ::getCppuType((const uno::Reference< beans::XMultiPropertySet >*)0) )
     351          22 :         aAny <<= uno::Reference< beans::XMultiPropertySet >(this);
     352             :     else
     353          22 :         aAny <<= OWeakAggObject::queryAggregation( rType );
     354             : 
     355          70 :     return aAny;
     356             : }
     357             : 
     358         195 : void SAL_CALL SvxUnoDrawPool::acquire() throw ( )
     359             : {
     360         195 :     OWeakAggObject::acquire();
     361         195 : }
     362             : 
     363         191 : void SAL_CALL SvxUnoDrawPool::release() throw ( )
     364             : {
     365         191 :     OWeakAggObject::release();
     366         191 : }
     367             : 
     368           0 : uno::Sequence< uno::Type > SAL_CALL SvxUnoDrawPool::getTypes()
     369             :     throw (uno::RuntimeException)
     370             : {
     371           0 :     uno::Sequence< uno::Type > aTypes( 6 );
     372           0 :     uno::Type* pTypes = aTypes.getArray();
     373             : 
     374           0 :     *pTypes++ = ::getCppuType((const uno::Reference< uno::XAggregation>*)0);
     375           0 :     *pTypes++ = ::getCppuType((const uno::Reference< lang::XServiceInfo>*)0);
     376           0 :     *pTypes++ = ::getCppuType((const uno::Reference< lang::XTypeProvider>*)0);
     377           0 :     *pTypes++ = ::getCppuType((const uno::Reference< beans::XPropertySet>*)0);
     378           0 :     *pTypes++ = ::getCppuType((const uno::Reference< beans::XPropertyState>*)0);
     379           0 :     *pTypes++ = ::getCppuType((const uno::Reference< beans::XMultiPropertySet>*)0);
     380             : 
     381           0 :     return aTypes;
     382             : }
     383             : 
     384             : namespace
     385             : {
     386             :     class theSvxUnoDrawPoolImplementationId : public rtl::Static< UnoTunnelIdInit, theSvxUnoDrawPoolImplementationId > {};
     387             : }
     388             : 
     389           2 : uno::Sequence< sal_Int8 > SAL_CALL SvxUnoDrawPool::getImplementationId()
     390             :     throw (uno::RuntimeException)
     391             : {
     392           2 :     return theSvxUnoDrawPoolImplementationId::get().getSeq();
     393             : }
     394             : 
     395             : // XServiceInfo
     396             : 
     397           0 : sal_Bool SAL_CALL SvxUnoDrawPool::supportsService( const  OUString& ServiceName ) throw(uno::RuntimeException)
     398             : {
     399           0 :     uno::Sequence< OUString > aSNL( getSupportedServiceNames() );
     400           0 :     const OUString * pArray = aSNL.getConstArray();
     401             : 
     402           0 :     for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
     403           0 :         if( pArray[i] == ServiceName )
     404           0 :             return sal_True;
     405             : 
     406           0 :     return sal_False;
     407             : }
     408             : 
     409           0 : OUString SAL_CALL SvxUnoDrawPool::getImplementationName() throw( uno::RuntimeException )
     410             : {
     411           0 :     return OUString( RTL_CONSTASCII_USTRINGPARAM("SvxUnoDrawPool") );
     412             : }
     413             : 
     414           0 : uno::Sequence< OUString > SAL_CALL SvxUnoDrawPool::getSupportedServiceNames(  )
     415             :     throw( uno::RuntimeException )
     416             : {
     417           0 :     uno::Sequence< OUString > aSNS( 1 );
     418           0 :     aSNS.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.Defaults" ));
     419           0 :     return aSNS;
     420             : }
     421             : 
     422             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10