LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sd/source/ui/unoidl - unopback.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 92 196 46.9 %
Date: 2013-07-09 Functions: 17 26 65.4 %
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/drawing/BitmapMode.hpp>
      21             : #include <osl/mutex.hxx>
      22             : #include <vcl/svapp.hxx>
      23             : #include <svl/itemset.hxx>
      24             : #include <svx/svdpool.hxx>
      25             : #include <comphelper/extract.hxx>
      26             : #include <svx/xflbstit.hxx>
      27             : #include <svx/xflbmtit.hxx>
      28             : #include <svx/svdobj.hxx>
      29             : #include <svx/unoprov.hxx>
      30             : #include <svx/unoshape.hxx>
      31             : #include <comphelper/serviceinfohelper.hxx>
      32             : 
      33             : #include "unopback.hxx"
      34             : #include "unohelp.hxx"
      35             : #include "drawdoc.hxx"
      36             : #include "unokywds.hxx"
      37             : 
      38             : using namespace ::rtl;
      39             : using namespace ::com::sun::star;
      40             : 
      41          38 : const SvxItemPropertySet* ImplGetPageBackgroundPropertySet()
      42             : {
      43             :     static const SfxItemPropertyMapEntry aPageBackgroundPropertyMap_Impl[] =
      44             :     {
      45         130 :         FILL_PROPERTIES
      46             :         {0,0,0,0,0,0}
      47         168 :     };
      48             : 
      49          38 :     static SvxItemPropertySet aPageBackgroundPropertySet_Impl( aPageBackgroundPropertyMap_Impl, SdrObject::GetGlobalDrawObjectItemPool() );
      50          38 :     return &aPageBackgroundPropertySet_Impl;
      51             : }
      52             : 
      53          64 : UNO3_GETIMPLEMENTATION_IMPL( SdUnoPageBackground );
      54             : 
      55          26 : SdUnoPageBackground::SdUnoPageBackground(
      56             :     SdDrawDocument* pDoc /* = NULL */,
      57             :     const SfxItemSet* pSet /* = NULL */) throw()
      58          26 : :   mpPropSet(ImplGetPageBackgroundPropertySet()),
      59             :     mpSet(NULL),
      60          52 :     mpDoc(pDoc)
      61             : {
      62          26 :     if( pDoc )
      63             :     {
      64          26 :         StartListening( *pDoc );
      65          26 :         mpSet = new SfxItemSet( pDoc->GetPool(), XATTR_FILL_FIRST, XATTR_FILL_LAST );
      66             : 
      67          26 :         if( pSet )
      68           5 :             mpSet->Put(*pSet);
      69             :     }
      70          26 : }
      71             : 
      72          72 : SdUnoPageBackground::~SdUnoPageBackground() throw()
      73             : {
      74          24 :     if( mpDoc )
      75          23 :         EndListening( *mpDoc );
      76             : 
      77          24 :     if( mpSet )
      78          23 :         delete mpSet;
      79          48 : }
      80             : 
      81          50 : void SdUnoPageBackground::Notify( SfxBroadcaster&, const SfxHint& rHint )
      82             : {
      83          50 :     const SdrHint* pSdrHint = PTR_CAST( SdrHint, &rHint );
      84             : 
      85          50 :     if( pSdrHint )
      86             :     {
      87             :         // delete item set if document is dying because then the pool
      88             :         // will also die
      89          47 :         if( pSdrHint->GetKind() == HINT_MODELCLEARED )
      90             :         {
      91           6 :             delete mpSet;
      92           6 :             mpSet = NULL;
      93           6 :             mpDoc = NULL;
      94             :         }
      95             :     }
      96             : 
      97          50 : }
      98             : 
      99          16 : void SdUnoPageBackground::fillItemSet( SdDrawDocument* pDoc, SfxItemSet& rSet ) throw()
     100             : {
     101          16 :     rSet.ClearItem();
     102             : 
     103          16 :     if( mpSet == NULL )
     104             :     {
     105           0 :         StartListening( *pDoc );
     106           0 :         mpDoc = pDoc;
     107             : 
     108           0 :         mpSet = new SfxItemSet( *rSet.GetPool(), XATTR_FILL_FIRST, XATTR_FILL_LAST );
     109             : 
     110           0 :         if( mpPropSet->AreThereOwnUsrAnys() )
     111             :         {
     112             :             uno::Any* pAny;
     113           0 :             PropertyEntryVector_t aProperties = mpPropSet->getPropertyMap()->getPropertyEntries();
     114           0 :             PropertyEntryVector_t::const_iterator aIt = aProperties.begin();
     115             : 
     116           0 :             while( aIt != aProperties.end() )
     117             :             {
     118           0 :                 pAny = mpPropSet->GetUsrAnyForID( aIt->nWID );
     119           0 :                 if( pAny )
     120             :                 {
     121           0 :                     OUString aPropertyName( aIt->sName );
     122           0 :                     switch( aIt->nWID )
     123             :                     {
     124             :                         case XATTR_FILLFLOATTRANSPARENCE :
     125             :                         case XATTR_FILLGRADIENT :
     126             :                         {
     127           0 :                             if ( ( pAny->getValueType() == ::getCppuType((const ::com::sun::star::awt::Gradient*)0) )
     128           0 :                                 && ( aIt->nMemberId == MID_FILLGRADIENT ) )
     129             :                             {
     130           0 :                                 setPropertyValue( aPropertyName, *pAny );
     131             :                             }
     132           0 :                             else if ( ( pAny->getValueType() == ::getCppuType((const OUString*)0) ) &&
     133           0 :                                         ( aIt->nMemberId == MID_NAME ) )
     134             :                             {
     135           0 :                                 setPropertyValue( aPropertyName, *pAny );
     136             :                             }
     137             :                         }
     138           0 :                         break;
     139             :                         case XATTR_FILLHATCH :
     140             :                         {
     141           0 :                             if ( ( pAny->getValueType() == ::getCppuType((const ::com::sun::star::drawing::Hatch*)0) )
     142           0 :                                 && ( aIt->nMemberId == MID_FILLHATCH ) )
     143             :                             {
     144           0 :                                 setPropertyValue( aPropertyName, *pAny );
     145             :                             }
     146           0 :                             else if ( ( pAny->getValueType() == ::getCppuType((const OUString*)0) ) &&
     147           0 :                                         ( aIt->nMemberId == MID_NAME ) )
     148             :                             {
     149           0 :                                 setPropertyValue( aPropertyName, *pAny );
     150             :                             }
     151             :                         }
     152           0 :                         break;
     153             :                         case XATTR_FILLBITMAP :
     154             :                         {
     155           0 :                             if ( ( ( pAny->getValueType() == ::getCppuType((const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XBitmap >*)0) ) ||
     156           0 :                                     ( pAny->getValueType() == ::getCppuType((const ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic >*)0) ) ) &&
     157           0 :                                     ( aIt->nMemberId == MID_BITMAP ) )
     158             :                             {
     159           0 :                                 setPropertyValue( aPropertyName, *pAny );
     160             :                             }
     161           0 :                             else if ( ( pAny->getValueType() == ::getCppuType((const OUString*)0) ) &&
     162           0 :                                         ( ( aIt->nMemberId == MID_NAME ) || ( aIt->nMemberId == MID_GRAFURL ) ) )
     163             :                             {
     164           0 :                                 setPropertyValue( aPropertyName, *pAny );
     165             :                             }
     166             :                         }
     167           0 :                         break;
     168             : 
     169             :                         default:
     170           0 :                             setPropertyValue( aPropertyName, *pAny );
     171           0 :                     }
     172             :                 }
     173           0 :                 ++aIt;
     174           0 :             }
     175             :         }
     176             :     }
     177             : 
     178          16 :     rSet.Put( *mpSet );
     179          16 : }
     180             : 
     181             : // XServiceInfo
     182           0 : OUString SAL_CALL SdUnoPageBackground::getImplementationName()
     183             :     throw(uno::RuntimeException)
     184             : {
     185           0 :     return OUString::createFromAscii( sUNO_SdUnoPageBackground );
     186             : }
     187             : 
     188           0 : sal_Bool SAL_CALL SdUnoPageBackground::supportsService( const OUString& ServiceName )
     189             :     throw(uno::RuntimeException)
     190             : {
     191           0 :     return comphelper::ServiceInfoHelper::supportsService( ServiceName, getSupportedServiceNames() );
     192             : }
     193             : 
     194           0 : uno::Sequence< OUString > SAL_CALL SdUnoPageBackground::getSupportedServiceNames()
     195             :     throw(uno::RuntimeException)
     196             : {
     197           0 :     uno::Sequence< OUString > aNameSequence( 2 );
     198           0 :     OUString* pStrings = aNameSequence.getArray();
     199             : 
     200           0 :     *pStrings++ = OUString( sUNO_Service_PageBackground );
     201           0 :     *pStrings   = OUString( sUNO_Service_FillProperties );
     202             : 
     203           0 :     return aNameSequence;
     204             : }
     205             : 
     206             : // XPropertySet
     207          30 : uno::Reference< beans::XPropertySetInfo > SAL_CALL SdUnoPageBackground::getPropertySetInfo()
     208             :     throw(uno::RuntimeException)
     209             : {
     210          30 :     return mpPropSet->getPropertySetInfo();
     211             : }
     212             : 
     213           7 : void SAL_CALL SdUnoPageBackground::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue )
     214             :     throw(beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
     215             : {
     216           7 :     SolarMutexGuard aGuard;
     217             : 
     218           7 :     const SfxItemPropertySimpleEntry* pEntry = getPropertyMapEntry( aPropertyName );
     219             : 
     220           7 :     if( pEntry == NULL )
     221             :     {
     222           0 :         throw beans::UnknownPropertyException();
     223             :     }
     224             :     else
     225             :     {
     226           7 :         if( mpSet )
     227             :         {
     228           7 :             if( pEntry->nWID == OWN_ATTR_FILLBMP_MODE )
     229             :             {
     230             :                 drawing::BitmapMode eMode;
     231           0 :                 if( aValue >>= eMode )
     232             :                 {
     233           0 :                     mpSet->Put( XFillBmpStretchItem( eMode == drawing::BitmapMode_STRETCH ) );
     234           0 :                     mpSet->Put( XFillBmpTileItem( eMode == drawing::BitmapMode_REPEAT ) );
     235           7 :                     return;
     236             :                 }
     237           0 :                 throw lang::IllegalArgumentException();
     238             :             }
     239             : 
     240           7 :             SfxItemPool& rPool = *mpSet->GetPool();
     241           7 :             SfxItemSet aSet( rPool, pEntry->nWID, pEntry->nWID);
     242           7 :             aSet.Put( *mpSet );
     243             : 
     244           7 :             if( !aSet.Count() )
     245           7 :                 aSet.Put( rPool.GetDefaultItem( pEntry->nWID ) );
     246             : 
     247           7 :             if( pEntry->nMemberId == MID_NAME && ( pEntry->nWID == XATTR_FILLBITMAP || pEntry->nWID == XATTR_FILLGRADIENT || pEntry->nWID == XATTR_FILLHATCH || pEntry->nWID == XATTR_FILLFLOATTRANSPARENCE ) )
     248             :             {
     249           0 :                 OUString aName;
     250           0 :                 if(!(aValue >>= aName ))
     251           0 :                     throw lang::IllegalArgumentException();
     252             : 
     253           0 :                 SvxShape::SetFillAttribute( pEntry->nWID, aName, aSet );
     254             :             }
     255             :             else
     256             :             {
     257           7 :                 SvxItemPropertySet_setPropertyValue( *mpPropSet, pEntry, aValue, aSet );
     258             :             }
     259             : 
     260           7 :             mpSet->Put( aSet );
     261             :         }
     262             :         else
     263             :         {
     264           0 :             if(pEntry && pEntry->nWID)
     265           0 :                 mpPropSet->setPropertyValue( pEntry, aValue );
     266             :         }
     267           7 :     }
     268             : }
     269             : 
     270           9 : uno::Any SAL_CALL SdUnoPageBackground::getPropertyValue( const OUString& PropertyName )
     271             :     throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
     272             : {
     273           9 :     SolarMutexGuard aGuard;
     274             : 
     275           9 :     uno::Any aAny;
     276           9 :     const SfxItemPropertySimpleEntry* pEntry = getPropertyMapEntry(PropertyName);
     277             : 
     278           9 :     if( pEntry == NULL )
     279             :     {
     280           0 :         throw beans::UnknownPropertyException();
     281             :     }
     282             :     else
     283             :     {
     284           9 :         if( mpSet )
     285             :         {
     286           9 :             if( pEntry->nWID == OWN_ATTR_FILLBMP_MODE )
     287             :             {
     288           0 :                 XFillBmpStretchItem* pStretchItem = (XFillBmpStretchItem*)mpSet->GetItem(XATTR_FILLBMP_STRETCH);
     289           0 :                 XFillBmpTileItem* pTileItem = (XFillBmpTileItem*)mpSet->GetItem(XATTR_FILLBMP_TILE);
     290             : 
     291           0 :                 if( pStretchItem && pTileItem )
     292             :                 {
     293           0 :                     if( pTileItem->GetValue() )
     294           0 :                         aAny <<= drawing::BitmapMode_REPEAT;
     295           0 :                     else if( pStretchItem->GetValue() )
     296           0 :                         aAny <<= drawing::BitmapMode_STRETCH;
     297             :                     else
     298           0 :                         aAny <<= drawing::BitmapMode_NO_REPEAT;
     299             :                 }
     300             :             }
     301             :             else
     302             :             {
     303           9 :                 SfxItemPool& rPool = *mpSet->GetPool();
     304           9 :                 SfxItemSet aSet( rPool, pEntry->nWID, pEntry->nWID);
     305           9 :                 aSet.Put( *mpSet );
     306             : 
     307           9 :                 if( !aSet.Count() )
     308           0 :                     aSet.Put( rPool.GetDefaultItem( pEntry->nWID ) );
     309             : 
     310             :                 // get value from ItemSet
     311           9 :                 aAny = SvxItemPropertySet_getPropertyValue( *mpPropSet, pEntry, aSet );
     312             :             }
     313             :         }
     314             :         else
     315             :         {
     316           0 :             if(pEntry && pEntry->nWID)
     317           0 :                 aAny = mpPropSet->getPropertyValue( pEntry );
     318             :         }
     319             :     }
     320           9 :     return aAny;
     321             : }
     322             : 
     323           0 : void SAL_CALL SdUnoPageBackground::addPropertyChangeListener( const OUString& , const uno::Reference< beans::XPropertyChangeListener >&  ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {}
     324           0 : void SAL_CALL SdUnoPageBackground::removePropertyChangeListener( const OUString& , const uno::Reference< beans::XPropertyChangeListener >&  ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {}
     325           0 : void SAL_CALL SdUnoPageBackground::addVetoableChangeListener( const OUString& , const uno::Reference< beans::XVetoableChangeListener >&  ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {}
     326           0 : void SAL_CALL SdUnoPageBackground::removeVetoableChangeListener( const OUString& , const uno::Reference< beans::XVetoableChangeListener >&  ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {}
     327             : 
     328             : // XPropertyState
     329         198 : beans::PropertyState SAL_CALL SdUnoPageBackground::getPropertyState( const OUString& PropertyName )
     330             :     throw(beans::UnknownPropertyException, uno::RuntimeException)
     331             : {
     332         198 :     SolarMutexGuard aGuard;
     333             : 
     334         198 :     const SfxItemPropertySimpleEntry* pEntry = getPropertyMapEntry(PropertyName);
     335             : 
     336         198 :     if( pEntry == NULL )
     337           0 :         throw beans::UnknownPropertyException();
     338             : 
     339         198 :     if( mpSet )
     340             :     {
     341         198 :         if( pEntry->nWID == OWN_ATTR_FILLBMP_MODE )
     342             :         {
     343          18 :             if( mpSet->GetItemState( XATTR_FILLBMP_STRETCH, false ) == SFX_ITEM_SET ||
     344           9 :                 mpSet->GetItemState( XATTR_FILLBMP_TILE, false ) == SFX_ITEM_SET )
     345             :             {
     346           0 :                 return beans::PropertyState_DIRECT_VALUE;
     347             :             }
     348             :             else
     349             :             {
     350           9 :                 return beans::PropertyState_AMBIGUOUS_VALUE;
     351             :             }
     352             :         }
     353             : 
     354         189 :         switch( mpSet->GetItemState( pEntry->nWID, sal_False ) )
     355             :         {
     356             :         case SFX_ITEM_READONLY:
     357             :         case SFX_ITEM_SET:
     358           9 :             return beans::PropertyState_DIRECT_VALUE;
     359             :         case SFX_ITEM_DEFAULT:
     360         180 :             return beans::PropertyState_DEFAULT_VALUE;
     361             :         default:
     362             : //      case SFX_ITEM_DONTCARE:
     363             : //      case SFX_ITEM_DISABLED:
     364           0 :             return beans::PropertyState_AMBIGUOUS_VALUE;
     365             :         }
     366             :     }
     367             :     else
     368             :     {
     369           0 :         if( NULL == mpPropSet->GetUsrAnyForID(pEntry->nWID) )
     370           0 :             return beans::PropertyState_DEFAULT_VALUE;
     371             :         else
     372           0 :             return beans::PropertyState_DIRECT_VALUE;
     373         198 :     }
     374             : }
     375             : 
     376           0 : uno::Sequence< beans::PropertyState > SAL_CALL SdUnoPageBackground::getPropertyStates( const uno::Sequence< OUString >& aPropertyName )
     377             :     throw(beans::UnknownPropertyException, uno::RuntimeException)
     378             : {
     379           0 :     SolarMutexGuard aGuard;
     380             : 
     381           0 :     sal_Int32 nCount = aPropertyName.getLength();
     382           0 :     const OUString* pNames = aPropertyName.getConstArray();
     383             : 
     384           0 :     uno::Sequence< beans::PropertyState > aPropertyStateSequence( nCount );
     385           0 :     beans::PropertyState* pState = aPropertyStateSequence.getArray();
     386             : 
     387           0 :     while( nCount-- )
     388           0 :         *pState++ = getPropertyState( *pNames++ );
     389             : 
     390           0 :     return aPropertyStateSequence;
     391             : }
     392             : 
     393         125 : void SAL_CALL SdUnoPageBackground::setPropertyToDefault( const OUString& PropertyName )
     394             :     throw(beans::UnknownPropertyException, uno::RuntimeException)
     395             : {
     396         125 :     SolarMutexGuard aGuard;
     397             : 
     398         125 :     const SfxItemPropertySimpleEntry* pEntry = getPropertyMapEntry(PropertyName);
     399             : 
     400         125 :     if( pEntry == NULL )
     401           0 :         throw beans::UnknownPropertyException();
     402             : 
     403         125 :     if( mpSet )
     404             :     {
     405         125 :         if( pEntry->nWID == OWN_ATTR_FILLBMP_MODE )
     406             :         {
     407           5 :             mpSet->ClearItem( XATTR_FILLBMP_STRETCH );
     408           5 :             mpSet->ClearItem( XATTR_FILLBMP_TILE );
     409             :         }
     410             :         else
     411             :         {
     412         120 :             mpSet->ClearItem( pEntry->nWID );
     413             :         }
     414         125 :     }
     415         125 : }
     416             : 
     417           0 : uno::Any SAL_CALL SdUnoPageBackground::getPropertyDefault( const OUString& aPropertyName )
     418             :     throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
     419             : {
     420           0 :     SolarMutexGuard aGuard;
     421             : 
     422           0 :     const SfxItemPropertySimpleEntry* pEntry = getPropertyMapEntry(aPropertyName);
     423           0 :     if( pEntry == NULL || mpSet == NULL )
     424           0 :         throw beans::UnknownPropertyException();
     425             : 
     426           0 :     uno::Any aAny;
     427           0 :     if( mpSet )
     428             :     {
     429           0 :         if( pEntry->nWID == OWN_ATTR_FILLBMP_MODE )
     430             :         {
     431           0 :             aAny <<= drawing::BitmapMode_REPEAT;
     432             :         }
     433             :         else
     434             :         {
     435           0 :             SfxItemPool& rPool = *mpSet->GetPool();
     436           0 :             SfxItemSet aSet( rPool, pEntry->nWID, pEntry->nWID);
     437           0 :             aSet.Put( rPool.GetDefaultItem( pEntry->nWID ) );
     438             : 
     439           0 :             aAny = SvxItemPropertySet_getPropertyValue( *mpPropSet, pEntry, aSet );
     440             :         }
     441             :     }
     442           0 :     return aAny;
     443             : }
     444             : 
     445             : /** this is used because our property map is not sorted yet */
     446         339 : const SfxItemPropertySimpleEntry* SdUnoPageBackground::getPropertyMapEntry( const OUString& rPropertyName ) const throw()
     447             : {
     448         339 :     return mpPropSet->getPropertyMap()->getByName(rPropertyName);
     449          33 : }
     450             : 
     451             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10