LCOV - code coverage report
Current view: top level - svx/source/unodraw - unopool.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 105 170 61.8 %
Date: 2014-04-11 Functions: 14 22 63.6 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <com/sun/star/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 ::rtl;
      45             : using namespace ::cppu;
      46             : 
      47         120 : SvxUnoDrawPool::SvxUnoDrawPool( SdrModel* pModel, sal_Int32 nServiceId ) throw()
      48         120 : : PropertySetHelper( SvxPropertySetInfoPool::getOrCreate( nServiceId ) ), mpModel( pModel )
      49             : {
      50         120 :     init();
      51         120 : }
      52             : 
      53             : /* deprecated */
      54          72 : SvxUnoDrawPool::SvxUnoDrawPool( SdrModel* pModel ) throw()
      55          72 : : PropertySetHelper( SvxPropertySetInfoPool::getOrCreate( SVXUNO_SERVICEID_COM_SUN_STAR_DRAWING_DEFAULTS ) ), mpModel( pModel )
      56             : {
      57          72 :     init();
      58          72 : }
      59             : 
      60         380 : SvxUnoDrawPool::~SvxUnoDrawPool() throw()
      61             : {
      62         190 :     if (mpDefaultsPool)
      63             :     {
      64         190 :         SfxItemPool* pOutlPool = mpDefaultsPool->GetSecondaryPool();
      65         190 :         SfxItemPool::Free(mpDefaultsPool);
      66         190 :         SfxItemPool::Free(pOutlPool);
      67             :     }
      68         190 : }
      69             : 
      70         192 : void SvxUnoDrawPool::init()
      71             : {
      72         192 :     mpDefaultsPool = new SdrItemPool();
      73         192 :     SfxItemPool* pOutlPool=EditEngine::CreatePool();
      74         192 :     mpDefaultsPool->SetSecondaryPool(pOutlPool);
      75             : 
      76         192 :     SdrModel::SetTextDefaults( mpDefaultsPool, SdrEngineDefaults::GetFontHeight() );
      77         192 :     mpDefaultsPool->SetDefaultMetric((SfxMapUnit)SdrEngineDefaults::GetMapUnit());
      78         192 :     mpDefaultsPool->FreezeIdRanges();
      79         192 : }
      80             : 
      81         741 : SfxItemPool* SvxUnoDrawPool::getModelPool( bool bReadOnly ) throw()
      82             : {
      83         741 :     if( mpModel )
      84             :     {
      85         741 :         return &mpModel->GetItemPool();
      86             :     }
      87             :     else
      88             :     {
      89           0 :         if( bReadOnly )
      90           0 :             return mpDefaultsPool;
      91             :         else
      92           0 :             return NULL;
      93             :     }
      94             : }
      95             : 
      96        1680 : void SvxUnoDrawPool::getAny( SfxItemPool* pPool, const comphelper::PropertyMapEntry* pEntry, uno::Any& rValue )
      97             :     throw(beans::UnknownPropertyException)
      98             : {
      99        1680 :     switch( pEntry->mnHandle )
     100             :     {
     101             :     case OWN_ATTR_FILLBMP_MODE:
     102             :         {
     103           0 :             XFillBmpStretchItem* pStretchItem = (XFillBmpStretchItem*)&pPool->GetDefaultItem(XATTR_FILLBMP_STRETCH);
     104           0 :             XFillBmpTileItem* pTileItem = (XFillBmpTileItem*)&pPool->GetDefaultItem(XATTR_FILLBMP_TILE);
     105           0 :             if( pTileItem && pTileItem->GetValue() )
     106             :             {
     107           0 :                 rValue <<= drawing::BitmapMode_REPEAT;
     108             :             }
     109           0 :             else if( pStretchItem && pStretchItem->GetValue() )
     110             :             {
     111           0 :                 rValue <<= drawing::BitmapMode_STRETCH;
     112             :             }
     113             :             else
     114             :             {
     115           0 :                 rValue <<= drawing::BitmapMode_NO_REPEAT;
     116             :             }
     117           0 :             break;
     118             :         }
     119             :     default:
     120             :         {
     121        1680 :             const SfxMapUnit eMapUnit = pPool->GetMetric((sal_uInt16)pEntry->mnHandle);
     122             : 
     123        1680 :             sal_uInt8 nMemberId = pEntry->mnMemberId & (~SFX_METRIC_ITEM);
     124        1680 :             if( eMapUnit == SFX_MAPUNIT_100TH_MM )
     125         857 :                 nMemberId &= (~CONVERT_TWIPS);
     126             : 
     127             :             // DVO, OD 10.10.2003 #i18732#
     128             :             // Assure, that ID is a Which-ID (it could be a Slot-ID.)
     129             :             // Thus, convert handle to Which-ID.
     130        1680 :             pPool->GetDefaultItem( pPool->GetWhich( (sal_uInt16)pEntry->mnHandle ) ).QueryValue( rValue, nMemberId );
     131             :         }
     132             :     }
     133             : 
     134             : 
     135             :     // check for needed metric translation
     136        1680 :     const SfxMapUnit eMapUnit = pPool->GetMetric((sal_uInt16)pEntry->mnHandle);
     137        1680 :     if(pEntry->mnMemberId & SFX_METRIC_ITEM && eMapUnit != SFX_MAPUNIT_100TH_MM)
     138             :     {
     139          42 :         SvxUnoConvertToMM( eMapUnit, rValue );
     140             :     }
     141             :     // convert int32 to correct enum type if needed
     142        1638 :     else if ( pEntry->maType.getTypeClass() == uno::TypeClass_ENUM && rValue.getValueType() == ::getCppuType((const sal_Int32*)0) )
     143             :     {
     144             :         sal_Int32 nEnum;
     145           0 :         rValue >>= nEnum;
     146             : 
     147           0 :         rValue.setValue( &nEnum, pEntry->maType );
     148             :     }
     149        1680 : }
     150             : 
     151        5372 : void SvxUnoDrawPool::putAny( SfxItemPool* pPool, const comphelper::PropertyMapEntry* pEntry, const uno::Any& rValue )
     152             :     throw(beans::UnknownPropertyException, lang::IllegalArgumentException)
     153             : {
     154        5372 :     uno::Any aValue( rValue );
     155             : 
     156        5372 :     const SfxMapUnit eMapUnit = pPool->GetMetric((sal_uInt16)pEntry->mnHandle);
     157        5372 :     if(pEntry->mnMemberId & SFX_METRIC_ITEM && eMapUnit != SFX_MAPUNIT_100TH_MM)
     158             :     {
     159         224 :         SvxUnoConvertFromMM( eMapUnit, aValue );
     160             :     }
     161             : 
     162             :     // DVO, OD 10.10.2003 #i18732#
     163             :     // Assure, that ID is a Which-ID (it could be a Slot-ID.)
     164             :     // Thus, convert handle to Which-ID.
     165        5372 :     const sal_uInt16 nWhich = pPool->GetWhich( (sal_uInt16)pEntry->mnHandle );
     166        5372 :     switch( nWhich )
     167             :     {
     168             :         case OWN_ATTR_FILLBMP_MODE:
     169             :             do
     170             :             {
     171             :                 drawing::BitmapMode eMode;
     172           0 :                 if(!(aValue >>= eMode) )
     173             :                 {
     174           0 :                     sal_Int32 nMode = 0;
     175           0 :                     if(!(aValue >>= nMode))
     176           0 :                         throw lang::IllegalArgumentException();
     177             : 
     178           0 :                     eMode = (drawing::BitmapMode)nMode;
     179             :                 }
     180             : 
     181           0 :                 pPool->SetPoolDefaultItem( XFillBmpStretchItem( eMode == drawing::BitmapMode_STRETCH ) );
     182           0 :                 pPool->SetPoolDefaultItem( XFillBmpTileItem( eMode == drawing::BitmapMode_REPEAT ) );
     183        5372 :                 return;
     184             :             }
     185             :             while(false);
     186             : 
     187             :     default:
     188             :         {
     189        5372 :             boost::scoped_ptr<SfxPoolItem> pNewItem( pPool->GetDefaultItem( nWhich ).Clone() );
     190        5372 :             sal_uInt8 nMemberId = pEntry->mnMemberId & (~SFX_METRIC_ITEM);
     191        5372 :             if( pPool->GetMetric(nWhich) == SFX_MAPUNIT_100TH_MM )
     192        1413 :                 nMemberId &= (~CONVERT_TWIPS);
     193             : 
     194        5372 :             if( !pNewItem->PutValue( aValue, nMemberId ) )
     195           0 :                 throw lang::IllegalArgumentException();
     196             : 
     197        5372 :             pPool->SetPoolDefaultItem( *pNewItem );
     198             :         }
     199        5372 :     }
     200             : }
     201             : 
     202         361 : void SvxUnoDrawPool::_setPropertyValues( const comphelper::PropertyMapEntry** ppEntries, const uno::Any* pValues )
     203             :     throw(beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException )
     204             : {
     205         361 :     SolarMutexGuard aGuard;
     206             : 
     207         361 :     SfxItemPool* pPool = getModelPool( false );
     208             : 
     209             :     DBG_ASSERT( pPool, "I need a SfxItemPool!" );
     210         361 :     if( NULL == pPool )
     211           0 :         throw beans::UnknownPropertyException();
     212             : 
     213        6094 :     while( *ppEntries )
     214        5733 :         putAny( pPool, *ppEntries++, *pValues++ );
     215         361 : }
     216             : 
     217        1680 : void SvxUnoDrawPool::_getPropertyValues( const comphelper::PropertyMapEntry** ppEntries, uno::Any* pValue )
     218             :     throw(beans::UnknownPropertyException, lang::WrappedTargetException )
     219             : {
     220        1680 :     SolarMutexGuard aGuard;
     221             : 
     222        1680 :     SfxItemPool* pPool = getModelPool( true );
     223             : 
     224             :     DBG_ASSERT( pPool, "I need a SfxItemPool!" );
     225        1680 :     if( NULL == pPool )
     226           0 :         throw beans::UnknownPropertyException();
     227             : 
     228        5040 :     while( *ppEntries )
     229        3360 :         getAny( pPool, *ppEntries++, *pValue++ );
     230        1680 : }
     231             : 
     232          48 : void SvxUnoDrawPool::_getPropertyStates( const comphelper::PropertyMapEntry** ppEntries, beans::PropertyState* pStates )
     233             :     throw(beans::UnknownPropertyException )
     234             : {
     235          48 :     SolarMutexGuard aGuard;
     236             : 
     237          48 :     SfxItemPool* pPool = getModelPool( true );
     238             : 
     239          48 :     if( pPool && pPool != mpDefaultsPool )
     240             :     {
     241        6768 :         while( *ppEntries )
     242             :         {
     243             :             // OD 13.10.2003 #i18732#
     244             :             // Assure, that ID is a Which-ID (it could be a Slot-ID.)
     245             :             // Thus, convert handle to Which-ID.
     246        6672 :             const sal_uInt16 nWhich = pPool->GetWhich( ((sal_uInt16)(*ppEntries)->mnHandle) );
     247             : 
     248        6672 :             switch( nWhich )
     249             :             {
     250             :             case OWN_ATTR_FILLBMP_MODE:
     251             :                 {
     252             :                     // use method <IsStaticDefaultItem(..)> instead of using
     253             :                     // probably incompatible item pool <mpDefaultPool>.
     254          48 :                     if ( IsStaticDefaultItem( &(pPool->GetDefaultItem( XATTR_FILLBMP_STRETCH )) ) ||
     255           0 :                          IsStaticDefaultItem( &(pPool->GetDefaultItem( XATTR_FILLBMP_TILE )) ) )
     256             :                     {
     257          48 :                         *pStates = beans::PropertyState_DEFAULT_VALUE;
     258             :                     }
     259             :                     else
     260             :                     {
     261           0 :                         *pStates = beans::PropertyState_DIRECT_VALUE;
     262             :                     }
     263             :                 }
     264          48 :                 break;
     265             :             default:
     266             :                 // OD 13.10.2003 #i18732# - correction:
     267             :                 // use method <IsStaticDefaultItem(..)> instead of using probably
     268             :                 // incompatible item pool <mpDefaultPool>.
     269        6624 :                 const SfxPoolItem& r1 = pPool->GetDefaultItem( nWhich );
     270             :                 //const SfxPoolItem& r2 = mpDefaultPool->GetDefaultItem( nWhich );
     271             : 
     272        6624 :                 if ( IsStaticDefaultItem( &r1 ) )
     273             :                 {
     274        5174 :                     *pStates = beans::PropertyState_DEFAULT_VALUE;
     275             :                 }
     276             :                 else
     277             :                 {
     278        1450 :                     *pStates = beans::PropertyState_DIRECT_VALUE;
     279             :                 }
     280             :             }
     281             : 
     282        6672 :             pStates++;
     283        6672 :             ppEntries++;
     284          48 :         }
     285             :     }
     286             :     else
     287             :     {
     288             :         // as long as we have no model, all properties are default
     289           0 :         while( *ppEntries++ )
     290           0 :             *pStates++ = beans::PropertyState_DEFAULT_VALUE;
     291          48 :         return;
     292          48 :     }
     293             : }
     294             : 
     295           0 : void SvxUnoDrawPool::_setPropertyToDefault( const comphelper::PropertyMapEntry* pEntry )
     296             :     throw(beans::UnknownPropertyException )
     297             : {
     298           0 :     SolarMutexGuard aGuard;
     299             : 
     300           0 :     SfxItemPool* pPool = getModelPool( true );
     301             : 
     302             :     // OD 10.10.2003 #i18732#
     303             :     // Assure, that ID is a Which-ID (it could be a Slot-ID.)
     304             :     // Thus, convert handle to Which-ID.
     305           0 :     const sal_uInt16 nWhich = pPool->GetWhich( (sal_uInt16)pEntry->mnHandle );
     306           0 :     if ( pPool && pPool != mpDefaultsPool )
     307             :     {
     308             :         // OD 13.10.2003 #i18732# - use method <ResetPoolDefaultItem(..)>
     309             :         // instead of using probably incompatible item pool <mpDefaultsPool>.
     310           0 :         pPool->ResetPoolDefaultItem( nWhich );
     311           0 :     }
     312           0 : }
     313             : 
     314           0 : uno::Any SvxUnoDrawPool::_getPropertyDefault( const comphelper::PropertyMapEntry* pEntry )
     315             :     throw(beans::UnknownPropertyException, lang::WrappedTargetException )
     316             : {
     317           0 :     SolarMutexGuard aGuard;
     318             : 
     319             :     // OD 13.10.2003 #i18732# - use method <GetPoolDefaultItem(..)> instead of
     320             :     // using probably incompatible item pool <mpDefaultsPool>
     321           0 :     uno::Any aAny;
     322           0 :     SfxItemPool* pPool = getModelPool( true );
     323           0 :     const sal_uInt16 nWhich = pPool->GetWhich( (sal_uInt16)pEntry->mnHandle );
     324           0 :     const SfxPoolItem *pItem = pPool->GetPoolDefaultItem ( nWhich );
     325           0 :     pItem->QueryValue( aAny, pEntry->mnMemberId );
     326             : 
     327           0 :     return aAny;
     328             : }
     329             : 
     330             : // XInterface
     331             : 
     332         668 : uno::Any SAL_CALL SvxUnoDrawPool::queryInterface( const uno::Type & rType )
     333             :     throw( uno::RuntimeException, std::exception )
     334             : {
     335         668 :     return OWeakAggObject::queryInterface( rType );
     336             : }
     337             : 
     338         668 : uno::Any SAL_CALL SvxUnoDrawPool::queryAggregation( const uno::Type & rType )
     339             :     throw(uno::RuntimeException, std::exception)
     340             : {
     341         668 :     uno::Any aAny;
     342             : 
     343         668 :     if( rType == ::getCppuType((const uno::Reference< lang::XServiceInfo >*)0) )
     344           0 :         aAny <<= uno::Reference< lang::XServiceInfo >(this);
     345         668 :     else if( rType == ::getCppuType((const uno::Reference< lang::XTypeProvider >*)0) )
     346           0 :         aAny <<= uno::Reference< lang::XTypeProvider >(this);
     347         668 :     else if( rType == ::getCppuType((const uno::Reference< beans::XPropertySet >*)0) )
     348         209 :         aAny <<= uno::Reference< beans::XPropertySet >(this);
     349         459 :     else if( rType == ::getCppuType((const uno::Reference< beans::XPropertyState >*)0) )
     350          48 :         aAny <<= uno::Reference< beans::XPropertyState >(this);
     351         411 :     else if( rType == ::getCppuType((const uno::Reference< beans::XMultiPropertySet >*)0) )
     352         205 :         aAny <<= uno::Reference< beans::XMultiPropertySet >(this);
     353             :     else
     354         206 :         aAny <<= OWeakAggObject::queryAggregation( rType );
     355             : 
     356         668 :     return aAny;
     357             : }
     358             : 
     359        1908 : void SAL_CALL SvxUnoDrawPool::acquire() throw ( )
     360             : {
     361        1908 :     OWeakAggObject::acquire();
     362        1908 : }
     363             : 
     364        1906 : void SAL_CALL SvxUnoDrawPool::release() throw ( )
     365             : {
     366        1906 :     OWeakAggObject::release();
     367        1906 : }
     368             : 
     369           0 : uno::Sequence< uno::Type > SAL_CALL SvxUnoDrawPool::getTypes()
     370             :     throw (uno::RuntimeException, std::exception)
     371             : {
     372           0 :     uno::Sequence< uno::Type > aTypes( 6 );
     373           0 :     uno::Type* pTypes = aTypes.getArray();
     374             : 
     375           0 :     *pTypes++ = ::getCppuType((const uno::Reference< uno::XAggregation>*)0);
     376           0 :     *pTypes++ = ::getCppuType((const uno::Reference< lang::XServiceInfo>*)0);
     377           0 :     *pTypes++ = ::getCppuType((const uno::Reference< lang::XTypeProvider>*)0);
     378           0 :     *pTypes++ = ::getCppuType((const uno::Reference< beans::XPropertySet>*)0);
     379           0 :     *pTypes++ = ::getCppuType((const uno::Reference< beans::XPropertyState>*)0);
     380           0 :     *pTypes++ = ::getCppuType((const uno::Reference< beans::XMultiPropertySet>*)0);
     381             : 
     382           0 :     return aTypes;
     383             : }
     384             : 
     385           0 : uno::Sequence< sal_Int8 > SAL_CALL SvxUnoDrawPool::getImplementationId()
     386             :     throw (uno::RuntimeException, std::exception)
     387             : {
     388           0 :     return css::uno::Sequence<sal_Int8>();
     389             : }
     390             : 
     391             : // XServiceInfo
     392           0 : sal_Bool SAL_CALL SvxUnoDrawPool::supportsService( const  OUString& ServiceName ) throw(uno::RuntimeException, std::exception)
     393             : {
     394           0 :     return cppu::supportsService(this, ServiceName);
     395             : }
     396             : 
     397           0 : OUString SAL_CALL SvxUnoDrawPool::getImplementationName() throw( uno::RuntimeException, std::exception )
     398             : {
     399           0 :     return OUString("SvxUnoDrawPool");
     400             : }
     401             : 
     402           0 : uno::Sequence< OUString > SAL_CALL SvxUnoDrawPool::getSupportedServiceNames(  )
     403             :     throw( uno::RuntimeException, std::exception )
     404             : {
     405           0 :     uno::Sequence< OUString > aSNS( 1 );
     406           0 :     aSNS.getArray()[0] = "com.sun.star.drawing.Defaults";
     407           0 :     return aSNS;
     408             : }
     409             : 
     410             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10