LCOV - code coverage report
Current view: top level - svx/source/unodraw - unopool.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 106 171 62.0 %
Date: 2015-06-13 12:38:46 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         360 : SvxUnoDrawPool::SvxUnoDrawPool(SdrModel* pModel, sal_Int32 nServiceId)
      47         360 : : PropertySetHelper( SvxPropertySetInfoPool::getOrCreate( nServiceId ) ), mpModel( pModel )
      48             : {
      49         360 :     init();
      50         360 : }
      51             : 
      52             : /* deprecated */
      53         158 : SvxUnoDrawPool::SvxUnoDrawPool(SdrModel* pModel)
      54         158 : : PropertySetHelper( SvxPropertySetInfoPool::getOrCreate( SVXUNO_SERVICEID_COM_SUN_STAR_DRAWING_DEFAULTS ) ), mpModel( pModel )
      55             : {
      56         158 :     init();
      57         158 : }
      58             : 
      59        1030 : SvxUnoDrawPool::~SvxUnoDrawPool() throw()
      60             : {
      61         515 :     if (mpDefaultsPool)
      62             :     {
      63         515 :         SfxItemPool* pOutlPool = mpDefaultsPool->GetSecondaryPool();
      64         515 :         SfxItemPool::Free(mpDefaultsPool);
      65         515 :         SfxItemPool::Free(pOutlPool);
      66             :     }
      67         515 : }
      68             : 
      69         518 : void SvxUnoDrawPool::init()
      70             : {
      71         518 :     mpDefaultsPool = new SdrItemPool();
      72         518 :     SfxItemPool* pOutlPool=EditEngine::CreatePool();
      73         518 :     mpDefaultsPool->SetSecondaryPool(pOutlPool);
      74             : 
      75         518 :     SdrModel::SetTextDefaults( mpDefaultsPool, SdrEngineDefaults::GetFontHeight() );
      76         518 :     mpDefaultsPool->SetDefaultMetric((SfxMapUnit)SdrEngineDefaults::GetMapUnit());
      77         518 :     mpDefaultsPool->FreezeIdRanges();
      78         518 : }
      79             : 
      80         590 : SfxItemPool* SvxUnoDrawPool::getModelPool( bool bReadOnly ) throw()
      81             : {
      82         590 :     if( mpModel )
      83             :     {
      84         590 :         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        3678 : void SvxUnoDrawPool::getAny( SfxItemPool* pPool, const comphelper::PropertyMapEntry* pEntry, uno::Any& rValue )
      96             :     throw(beans::UnknownPropertyException)
      97             : {
      98        3678 :     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        3678 :             const SfxMapUnit eMapUnit = pPool->GetMetric((sal_uInt16)pEntry->mnHandle);
     121             : 
     122        3678 :             sal_uInt8 nMemberId = pEntry->mnMemberId & (~SFX_METRIC_ITEM);
     123        3678 :             if( eMapUnit == SFX_MAPUNIT_100TH_MM )
     124         857 :                 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        3678 :             pPool->GetDefaultItem( pPool->GetWhich( (sal_uInt16)pEntry->mnHandle ) ).QueryValue( rValue, nMemberId );
     130             :         }
     131             :     }
     132             : 
     133             : 
     134             :     // check for needed metric translation
     135        3678 :     const SfxMapUnit eMapUnit = pPool->GetMetric((sal_uInt16)pEntry->mnHandle);
     136        3678 :     if(pEntry->mnMemberId & SFX_METRIC_ITEM && eMapUnit != SFX_MAPUNIT_100TH_MM)
     137             :     {
     138         146 :         SvxUnoConvertToMM( eMapUnit, rValue );
     139             :     }
     140             :     // convert int32 to correct enum type if needed
     141        3532 :     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        3678 : }
     149             : 
     150       15017 : void SvxUnoDrawPool::putAny( SfxItemPool* pPool, const comphelper::PropertyMapEntry* pEntry, const uno::Any& rValue )
     151             :     throw(beans::UnknownPropertyException, lang::IllegalArgumentException, uno::RuntimeException)
     152             : {
     153       15017 :     uno::Any aValue( rValue );
     154             : 
     155       15017 :     const SfxMapUnit eMapUnit = pPool->GetMetric((sal_uInt16)pEntry->mnHandle);
     156       15017 :     if(pEntry->mnMemberId & SFX_METRIC_ITEM && eMapUnit != SFX_MAPUNIT_100TH_MM)
     157             :     {
     158         570 :         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       15017 :     const sal_uInt16 nWhich = pPool->GetWhich( (sal_uInt16)pEntry->mnHandle );
     165       15017 :     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       15017 :                 return;
     183             :             }
     184             :             while(false);
     185             : 
     186             :     default:
     187             :         {
     188       15017 :             boost::scoped_ptr<SfxPoolItem> pNewItem( pPool->GetDefaultItem( nWhich ).Clone() );
     189       15017 :             sal_uInt8 nMemberId = pEntry->mnMemberId & (~SFX_METRIC_ITEM);
     190       15017 :             if( pPool->GetMetric(nWhich) == SFX_MAPUNIT_100TH_MM )
     191        3673 :                 nMemberId &= (~CONVERT_TWIPS);
     192             : 
     193       15017 :             if( !pNewItem->PutValue( aValue, nMemberId ) )
     194           0 :                 throw lang::IllegalArgumentException();
     195             : 
     196       15017 :             pPool->SetPoolDefaultItem( *pNewItem );
     197             :         }
     198       15017 :     }
     199             : }
     200             : 
     201         957 : void SvxUnoDrawPool::_setPropertyValues( const comphelper::PropertyMapEntry** ppEntries, const uno::Any* pValues )
     202             :     throw(beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException )
     203             : {
     204         957 :     SolarMutexGuard aGuard;
     205             : 
     206         957 :     SfxItemPool* pPool = getModelPool( false );
     207             : 
     208             :     DBG_ASSERT( pPool, "I need a SfxItemPool!" );
     209         957 :     if( NULL == pPool )
     210           0 :         throw beans::UnknownPropertyException();
     211             : 
     212       16931 :     while( *ppEntries )
     213       15974 :         putAny( pPool, *ppEntries++, *pValues++ );
     214         957 : }
     215             : 
     216        3678 : void SvxUnoDrawPool::_getPropertyValues( const comphelper::PropertyMapEntry** ppEntries, uno::Any* pValue )
     217             :     throw(beans::UnknownPropertyException, lang::WrappedTargetException )
     218             : {
     219        3678 :     SolarMutexGuard aGuard;
     220             : 
     221        3678 :     SfxItemPool* pPool = getModelPool( true );
     222             : 
     223             :     DBG_ASSERT( pPool, "I need a SfxItemPool!" );
     224        3678 :     if( NULL == pPool )
     225           0 :         throw beans::UnknownPropertyException();
     226             : 
     227       11034 :     while( *ppEntries )
     228        7356 :         getAny( pPool, *ppEntries++, *pValue++ );
     229        3678 : }
     230             : 
     231          99 : void SvxUnoDrawPool::_getPropertyStates( const comphelper::PropertyMapEntry** ppEntries, beans::PropertyState* pStates )
     232             :     throw(beans::UnknownPropertyException )
     233             : {
     234          99 :     SolarMutexGuard aGuard;
     235             : 
     236          99 :     SfxItemPool* pPool = getModelPool( true );
     237             : 
     238          99 :     if( pPool && pPool != mpDefaultsPool )
     239             :     {
     240       14157 :         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       13959 :             const sal_uInt16 nWhich = pPool->GetWhich( ((sal_uInt16)(*ppEntries)->mnHandle) );
     246             : 
     247       13959 :             switch( nWhich )
     248             :             {
     249             :             case OWN_ATTR_FILLBMP_MODE:
     250             :                 {
     251             :                     // use method <IsStaticDefaultItem(..)> instead of using
     252             :                     // probably incompatible item pool <mpDefaultPool>.
     253          99 :                     if ( IsStaticDefaultItem( &(pPool->GetDefaultItem( XATTR_FILLBMP_STRETCH )) ) ||
     254           0 :                          IsStaticDefaultItem( &(pPool->GetDefaultItem( XATTR_FILLBMP_TILE )) ) )
     255             :                     {
     256          99 :                         *pStates = beans::PropertyState_DEFAULT_VALUE;
     257             :                     }
     258             :                     else
     259             :                     {
     260           0 :                         *pStates = beans::PropertyState_DIRECT_VALUE;
     261             :                     }
     262             :                 }
     263          99 :                 break;
     264             :             default:
     265             :                 // OD 13.10.2003 #i18732# - correction:
     266             :                 // use method <IsStaticDefaultItem(..)> instead of using probably
     267             :                 // incompatible item pool <mpDefaultPool>.
     268       13860 :                 const SfxPoolItem& r1 = pPool->GetDefaultItem( nWhich );
     269             :                 //const SfxPoolItem& r2 = mpDefaultPool->GetDefaultItem( nWhich );
     270             : 
     271       13860 :                 if ( IsStaticDefaultItem( &r1 ) )
     272             :                 {
     273       10542 :                     *pStates = beans::PropertyState_DEFAULT_VALUE;
     274             :                 }
     275             :                 else
     276             :                 {
     277        3318 :                     *pStates = beans::PropertyState_DIRECT_VALUE;
     278             :                 }
     279             :             }
     280             : 
     281       13959 :             pStates++;
     282       13959 :             ppEntries++;
     283          99 :         }
     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          99 :         return;
     291          99 :     }
     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        1827 : uno::Any SAL_CALL SvxUnoDrawPool::queryInterface( const uno::Type & rType )
     332             :     throw( uno::RuntimeException, std::exception )
     333             : {
     334        1827 :     return OWeakAggObject::queryInterface( rType );
     335             : }
     336             : 
     337        1827 : uno::Any SAL_CALL SvxUnoDrawPool::queryAggregation( const uno::Type & rType )
     338             :     throw(uno::RuntimeException, std::exception)
     339             : {
     340        1827 :     uno::Any aAny;
     341             : 
     342        1827 :     if( rType == cppu::UnoType<lang::XServiceInfo>::get())
     343           0 :         aAny <<= uno::Reference< lang::XServiceInfo >(this);
     344        1827 :     else if( rType == cppu::UnoType<lang::XTypeProvider>::get())
     345           0 :         aAny <<= uno::Reference< lang::XTypeProvider >(this);
     346        1827 :     else if( rType == cppu::UnoType<beans::XPropertySet>::get())
     347         585 :         aAny <<= uno::Reference< beans::XPropertySet >(this);
     348        1242 :     else if( rType == cppu::UnoType<beans::XPropertyState>::get())
     349          99 :         aAny <<= uno::Reference< beans::XPropertyState >(this);
     350        1143 :     else if( rType == cppu::UnoType<beans::XMultiPropertySet>::get())
     351         571 :         aAny <<= uno::Reference< beans::XMultiPropertySet >(this);
     352             :     else
     353         572 :         aAny <<= OWeakAggObject::queryAggregation( rType );
     354             : 
     355        1827 :     return aAny;
     356             : }
     357             : 
     358        4272 : void SAL_CALL SvxUnoDrawPool::acquire() throw ( )
     359             : {
     360        4272 :     OWeakAggObject::acquire();
     361        4272 : }
     362             : 
     363        4269 : void SAL_CALL SvxUnoDrawPool::release() throw ( )
     364             : {
     365        4269 :     OWeakAggObject::release();
     366        4269 : }
     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         390 : }
     408             : 
     409             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11