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-17 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          35 : SvxUnoDrawPool::SvxUnoDrawPool( SdrModel* pModel, sal_Int32 nServiceId ) throw()
      47          35 : : PropertySetHelper( SvxPropertySetInfoPool::getOrCreate( nServiceId ) ), mpModel( pModel )
      48             : {
      49          35 :     init();
      50          35 : }
      51             : 
      52             : /* deprecated */
      53           6 : SvxUnoDrawPool::SvxUnoDrawPool( SdrModel* pModel ) throw()
      54           6 : : PropertySetHelper( SvxPropertySetInfoPool::getOrCreate( SVXUNO_SERVICEID_COM_SUN_STAR_DRAWING_DEFAULTS ) ), mpModel( pModel )
      55             : {
      56           6 :     init();
      57           6 : }
      58             : 
      59          46 : SvxUnoDrawPool::~SvxUnoDrawPool() throw()
      60             : {
      61          23 :     if (mpDefaultsPool)
      62             :     {
      63          23 :         SfxItemPool* pOutlPool = mpDefaultsPool->GetSecondaryPool();
      64          23 :         SfxItemPool::Free(mpDefaultsPool);
      65          23 :         SfxItemPool::Free(pOutlPool);
      66             :     }
      67          23 : }
      68             : 
      69          41 : void SvxUnoDrawPool::init()
      70             : {
      71          41 :     mpDefaultsPool = new SdrItemPool();
      72          41 :     SfxItemPool* pOutlPool=EditEngine::CreatePool();
      73          41 :     mpDefaultsPool->SetSecondaryPool(pOutlPool);
      74             : 
      75          41 :     SdrModel::SetTextDefaults( mpDefaultsPool, SdrEngineDefaults::GetFontHeight() );
      76          41 :     mpDefaultsPool->SetDefaultMetric((SfxMapUnit)SdrEngineDefaults::GetMapUnit());
      77          41 :     mpDefaultsPool->FreezeIdRanges();
      78          41 : }
      79             : 
      80           8 : SfxItemPool* SvxUnoDrawPool::getModelPool( sal_Bool bReadOnly ) throw()
      81             : {
      82           8 :     if( mpModel )
      83             :     {
      84           8 :         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         158 : void SvxUnoDrawPool::getAny( SfxItemPool* pPool, const comphelper::PropertyMapEntry* pEntry, uno::Any& rValue )
      96             :     throw(beans::UnknownPropertyException)
      97             : {
      98         158 :     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         158 :             const SfxMapUnit eMapUnit = pPool ? pPool->GetMetric((sal_uInt16)pEntry->mnHandle) : SFX_MAPUNIT_100TH_MM;
     121             : 
     122         158 :             sal_uInt8 nMemberId = pEntry->mnMemberId & (~SFX_METRIC_ITEM);
     123         158 :             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         158 :             pPool->GetDefaultItem( pPool->GetWhich( (sal_uInt16)pEntry->mnHandle ) ).QueryValue( rValue, nMemberId );
     130             :         }
     131             :     }
     132             : 
     133             : 
     134             :     // check for needed metric translation
     135         158 :     const SfxMapUnit eMapUnit = pPool->GetMetric((sal_uInt16)pEntry->mnHandle);
     136         158 :     if(pEntry->mnMemberId & SFX_METRIC_ITEM && eMapUnit != SFX_MAPUNIT_100TH_MM)
     137             :     {
     138           8 :         SvxUnoConvertToMM( eMapUnit, rValue );
     139             :     }
     140             :     // convert int32 to correct enum type if needed
     141         150 :     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         158 : }
     149             : 
     150        1147 : void SvxUnoDrawPool::putAny( SfxItemPool* pPool, const comphelper::PropertyMapEntry* pEntry, const uno::Any& rValue )
     151             :     throw(beans::UnknownPropertyException, lang::IllegalArgumentException)
     152             : {
     153        1147 :     uno::Any aValue( rValue );
     154             : 
     155        1147 :     const SfxMapUnit eMapUnit = pPool->GetMetric((sal_uInt16)pEntry->mnHandle);
     156        1147 :     if(pEntry->mnMemberId & SFX_METRIC_ITEM && eMapUnit != SFX_MAPUNIT_100TH_MM)
     157             :     {
     158          70 :         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        1147 :     const sal_uInt16 nWhich = pPool->GetWhich( (sal_uInt16)pEntry->mnHandle );
     165        1147 :     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        1147 :                 return;
     183             :             }
     184             :             while(0);
     185             : 
     186             :     default:
     187             :         {
     188        1147 :             ::std::auto_ptr<SfxPoolItem> pNewItem( pPool->GetDefaultItem( nWhich ).Clone() );
     189        1147 :             sal_uInt8 nMemberId = pEntry->mnMemberId & (~SFX_METRIC_ITEM);
     190        1147 :             if( !pPool || (pPool->GetMetric(nWhich) == SFX_MAPUNIT_100TH_MM) )
     191         196 :                 nMemberId &= (~CONVERT_TWIPS);
     192             : 
     193        1147 :             if( !pNewItem->PutValue( aValue, nMemberId ) )
     194           0 :                 throw lang::IllegalArgumentException();
     195             : 
     196        1147 :             pPool->SetPoolDefaultItem( *pNewItem );
     197             :         }
     198        1147 :     }
     199             : }
     200             : 
     201          82 : void SvxUnoDrawPool::_setPropertyValues( const comphelper::PropertyMapEntry** ppEntries, const uno::Any* pValues )
     202             :     throw(beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException )
     203             : {
     204          82 :     SolarMutexGuard aGuard;
     205             : 
     206          82 :     SfxItemPool* pPool = getModelPool( sal_False );
     207             : 
     208             :     DBG_ASSERT( pPool, "I need a SfxItemPool!" );
     209          82 :     if( NULL == pPool )
     210           0 :         throw beans::UnknownPropertyException();
     211             : 
     212        1311 :     while( *ppEntries )
     213        1229 :         putAny( pPool, *ppEntries++, *pValues++ );
     214          82 : }
     215             : 
     216         158 : void SvxUnoDrawPool::_getPropertyValues( const comphelper::PropertyMapEntry** ppEntries, uno::Any* pValue )
     217             :     throw(beans::UnknownPropertyException, lang::WrappedTargetException )
     218             : {
     219         158 :     SolarMutexGuard aGuard;
     220             : 
     221         158 :     SfxItemPool* pPool = getModelPool( sal_True );
     222             : 
     223             :     DBG_ASSERT( pPool, "I need a SfxItemPool!" );
     224         158 :     if( NULL == pPool )
     225           0 :         throw beans::UnknownPropertyException();
     226             : 
     227         474 :     while( *ppEntries )
     228         316 :         getAny( pPool, *ppEntries++, *pValue++ );
     229         158 : }
     230             : 
     231           4 : void SvxUnoDrawPool::_getPropertyStates( const comphelper::PropertyMapEntry** ppEntries, beans::PropertyState* pStates )
     232             :     throw(beans::UnknownPropertyException )
     233             : {
     234           4 :     SolarMutexGuard aGuard;
     235             : 
     236           4 :     SfxItemPool* pPool = getModelPool( sal_True );
     237             : 
     238           4 :     if( pPool && pPool != mpDefaultsPool )
     239             :     {
     240         560 :         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         552 :             const sal_uInt16 nWhich = pPool->GetWhich( ((sal_uInt16)(*ppEntries)->mnHandle) );
     246             : 
     247         552 :             switch( nWhich )
     248             :             {
     249             :             case OWN_ATTR_FILLBMP_MODE:
     250             :                 {
     251             :                     // use method <IsStaticDefaultItem(..)> instead of using
     252             :                     // probably incompatible item pool <mpDefaultPool>.
     253           4 :                     if ( IsStaticDefaultItem( &(pPool->GetDefaultItem( XATTR_FILLBMP_STRETCH )) ) ||
     254           0 :                          IsStaticDefaultItem( &(pPool->GetDefaultItem( XATTR_FILLBMP_TILE )) ) )
     255             :                     {
     256           4 :                         *pStates = beans::PropertyState_DEFAULT_VALUE;
     257             :                     }
     258             :                     else
     259             :                     {
     260           0 :                         *pStates = beans::PropertyState_DIRECT_VALUE;
     261             :                     }
     262             :                 }
     263           4 :                 break;
     264             :             default:
     265             :                 // OD 13.10.2003 #i18732# - correction:
     266             :                 // use method <IsStaticDefaultItem(..)> instead of using probably
     267             :                 // incompatible item pool <mpDefaultPool>.
     268         548 :                 const SfxPoolItem& r1 = pPool->GetDefaultItem( nWhich );
     269             :                 //const SfxPoolItem& r2 = mpDefaultPool->GetDefaultItem( nWhich );
     270             : 
     271         548 :                 if ( IsStaticDefaultItem( &r1 ) )
     272             :                 {
     273         390 :                     *pStates = beans::PropertyState_DEFAULT_VALUE;
     274             :                 }
     275             :                 else
     276             :                 {
     277         158 :                     *pStates = beans::PropertyState_DIRECT_VALUE;
     278             :                 }
     279             :             }
     280             : 
     281         552 :             pStates++;
     282         552 :             ppEntries++;
     283           4 :         }
     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           4 :         return;
     291           4 :     }
     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         143 : uno::Any SAL_CALL SvxUnoDrawPool::queryInterface( const uno::Type & rType )
     332             :     throw( uno::RuntimeException )
     333             : {
     334         143 :     return OWeakAggObject::queryInterface( rType );
     335             : }
     336             : 
     337         143 : uno::Any SAL_CALL SvxUnoDrawPool::queryAggregation( const uno::Type & rType )
     338             :     throw(uno::RuntimeException)
     339             : {
     340         143 :     uno::Any aAny;
     341             : 
     342         143 :     if( rType == ::getCppuType((const uno::Reference< lang::XServiceInfo >*)0) )
     343           0 :         aAny <<= uno::Reference< lang::XServiceInfo >(this);
     344         143 :     else if( rType == ::getCppuType((const uno::Reference< lang::XTypeProvider >*)0) )
     345           4 :         aAny <<= uno::Reference< lang::XTypeProvider >(this);
     346         139 :     else if( rType == ::getCppuType((const uno::Reference< beans::XPropertySet >*)0) )
     347          45 :         aAny <<= uno::Reference< beans::XPropertySet >(this);
     348          94 :     else if( rType == ::getCppuType((const uno::Reference< beans::XPropertyState >*)0) )
     349           4 :         aAny <<= uno::Reference< beans::XPropertyState >(this);
     350          90 :     else if( rType == ::getCppuType((const uno::Reference< beans::XMultiPropertySet >*)0) )
     351          45 :         aAny <<= uno::Reference< beans::XMultiPropertySet >(this);
     352             :     else
     353          45 :         aAny <<= OWeakAggObject::queryAggregation( rType );
     354             : 
     355         143 :     return aAny;
     356             : }
     357             : 
     358         398 : void SAL_CALL SvxUnoDrawPool::acquire() throw ( )
     359             : {
     360         398 :     OWeakAggObject::acquire();
     361         398 : }
     362             : 
     363         380 : void SAL_CALL SvxUnoDrawPool::release() throw ( )
     364             : {
     365         380 :     OWeakAggObject::release();
     366         380 : }
     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           4 : uno::Sequence< sal_Int8 > SAL_CALL SvxUnoDrawPool::getImplementationId()
     390             :     throw (uno::RuntimeException)
     391             : {
     392           4 :     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