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