LCOV - code coverage report
Current view: top level - libreoffice/sd/source/ui/unoidl - unopback.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 87 195 44.6 %
Date: 2012-12-27 Functions: 15 24 62.5 %
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          16 : const SvxItemPropertySet* ImplGetPageBackgroundPropertySet()
      42             : {
      43             :     static const SfxItemPropertyMapEntry aPageBackgroundPropertyMap_Impl[] =
      44             :     {
      45          52 :         FILL_PROPERTIES
      46             :         {0,0,0,0,0,0}
      47          68 :     };
      48             : 
      49          16 :     static SvxItemPropertySet aPageBackgroundPropertySet_Impl( aPageBackgroundPropertyMap_Impl, SdrObject::GetGlobalDrawObjectItemPool() );
      50          16 :     return &aPageBackgroundPropertySet_Impl;
      51             : }
      52             : 
      53          36 : UNO3_GETIMPLEMENTATION_IMPL( SdUnoPageBackground );
      54             : 
      55          11 : SdUnoPageBackground::SdUnoPageBackground(
      56             :     SdDrawDocument* pDoc /* = NULL */,
      57             :     const SfxItemSet* pSet /* = NULL */) throw()
      58          11 : :   mpPropSet(ImplGetPageBackgroundPropertySet()),
      59             :     mpSet(NULL),
      60          22 :     mpDoc(pDoc)
      61             : {
      62          11 :     if( pDoc )
      63             :     {
      64          11 :         StartListening( *pDoc );
      65          11 :         mpSet = new SfxItemSet( pDoc->GetPool(), XATTR_FILL_FIRST, XATTR_FILL_LAST );
      66             : 
      67          11 :         if( pSet )
      68           0 :             mpSet->Put(*pSet);
      69             :     }
      70          11 : }
      71             : 
      72          33 : SdUnoPageBackground::~SdUnoPageBackground() throw()
      73             : {
      74          11 :     if( mpDoc )
      75          11 :         EndListening( *mpDoc );
      76             : 
      77          11 :     if( mpSet )
      78          11 :         delete mpSet;
      79          22 : }
      80             : 
      81          11 : void SdUnoPageBackground::Notify( SfxBroadcaster&, const SfxHint& rHint )
      82             : {
      83          11 :     const SdrHint* pSdrHint = PTR_CAST( SdrHint, &rHint );
      84             : 
      85          11 :     if( pSdrHint )
      86             :     {
      87             :         // delete item set if document is dying because then the pool
      88             :         // will also die
      89          11 :         if( pSdrHint->GetKind() == HINT_MODELCLEARED )
      90             :         {
      91           0 :             delete mpSet;
      92           0 :             mpSet = NULL;
      93           0 :             mpDoc = NULL;
      94             :         }
      95             :     }
      96             : 
      97          11 : }
      98             : 
      99           9 : void SdUnoPageBackground::fillItemSet( SdDrawDocument* pDoc, SfxItemSet& rSet ) throw()
     100             : {
     101           9 :     rSet.ClearItem();
     102             : 
     103           9 :     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 ::rtl::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 ::rtl::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 ::rtl::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           9 :     rSet.Put( *mpSet );
     179           9 : }
     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          13 : uno::Reference< beans::XPropertySetInfo > SAL_CALL SdUnoPageBackground::getPropertySetInfo()
     208             :     throw(uno::RuntimeException)
     209             : {
     210          13 :     return mpPropSet->getPropertySetInfo();
     211             : }
     212             : 
     213           2 : 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           2 :     SolarMutexGuard aGuard;
     217             : 
     218           2 :     const SfxItemPropertySimpleEntry* pEntry = getPropertyMapEntry( aPropertyName );
     219             : 
     220           2 :     if( pEntry == NULL )
     221             :     {
     222           0 :         throw beans::UnknownPropertyException();
     223             :     }
     224             :     else
     225             :     {
     226           2 :         if( mpSet )
     227             :         {
     228           2 :             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           2 :                     return;
     236             :                 }
     237           0 :                 throw lang::IllegalArgumentException();
     238             :             }
     239             : 
     240           2 :             SfxItemPool& rPool = *mpSet->GetPool();
     241           2 :             SfxItemSet aSet( rPool, pEntry->nWID, pEntry->nWID);
     242           2 :             aSet.Put( *mpSet );
     243             : 
     244           2 :             if( !aSet.Count() )
     245           2 :                 aSet.Put( rPool.GetDefaultItem( pEntry->nWID ) );
     246             : 
     247           2 :             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           2 :                 SvxItemPropertySet_setPropertyValue( *mpPropSet, pEntry, aValue, aSet );
     258             :             }
     259             : 
     260           2 :             mpSet->Put( aSet );
     261             :         }
     262             :         else
     263             :         {
     264           0 :             if(pEntry && pEntry->nWID)
     265           0 :                 mpPropSet->setPropertyValue( pEntry, aValue );
     266             :         }
     267           2 :     }
     268             : }
     269             : 
     270           2 : uno::Any SAL_CALL SdUnoPageBackground::getPropertyValue( const OUString& PropertyName )
     271             :     throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
     272             : {
     273           2 :     SolarMutexGuard aGuard;
     274             : 
     275           2 :     uno::Any aAny;
     276           2 :     const SfxItemPropertySimpleEntry* pEntry = getPropertyMapEntry(PropertyName);
     277             : 
     278           2 :     if( pEntry == NULL )
     279             :     {
     280           0 :         throw beans::UnknownPropertyException();
     281             :     }
     282             :     else
     283             :     {
     284           2 :         if( mpSet )
     285             :         {
     286           2 :             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           2 :                 SfxItemPool& rPool = *mpSet->GetPool();
     304           2 :                 SfxItemSet aSet( rPool, pEntry->nWID, pEntry->nWID);
     305           2 :                 aSet.Put( *mpSet );
     306             : 
     307           2 :                 if( !aSet.Count() )
     308           0 :                     aSet.Put( rPool.GetDefaultItem( pEntry->nWID ) );
     309             : 
     310             :                 // Hole Wert aus ItemSet
     311           2 :                 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           2 :     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          52 : beans::PropertyState SAL_CALL SdUnoPageBackground::getPropertyState( const OUString& PropertyName )
     330             :     throw(beans::UnknownPropertyException, uno::RuntimeException)
     331             : {
     332          52 :     SolarMutexGuard aGuard;
     333             : 
     334          52 :     const SfxItemPropertySimpleEntry* pEntry = getPropertyMapEntry(PropertyName);
     335             : 
     336          52 :     if( pEntry == NULL )
     337           0 :         throw beans::UnknownPropertyException();
     338             : 
     339          52 :     if( mpSet )
     340             :     {
     341          52 :         if( pEntry->nWID == OWN_ATTR_FILLBMP_MODE )
     342             :         {
     343           4 :             if( mpSet->GetItemState( XATTR_FILLBMP_STRETCH, false ) == SFX_ITEM_SET ||
     344           2 :                 mpSet->GetItemState( XATTR_FILLBMP_TILE, false ) == SFX_ITEM_SET )
     345             :             {
     346           0 :                 return beans::PropertyState_DIRECT_VALUE;
     347             :             }
     348             :             else
     349             :             {
     350           2 :                 return beans::PropertyState_AMBIGUOUS_VALUE;
     351             :             }
     352             :         }
     353             : 
     354          50 :         switch( mpSet->GetItemState( pEntry->nWID, sal_False ) )
     355             :         {
     356             :         case SFX_ITEM_READONLY:
     357             :         case SFX_ITEM_SET:
     358           2 :             return beans::PropertyState_DIRECT_VALUE;
     359             :         case SFX_ITEM_DEFAULT:
     360          48 :             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          52 :     }
     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          50 : void SAL_CALL SdUnoPageBackground::setPropertyToDefault( const OUString& PropertyName )
     394             :     throw(beans::UnknownPropertyException, uno::RuntimeException)
     395             : {
     396          50 :     SolarMutexGuard aGuard;
     397             : 
     398          50 :     const SfxItemPropertySimpleEntry* pEntry = getPropertyMapEntry(PropertyName);
     399             : 
     400          50 :     if( pEntry == NULL )
     401           0 :         throw beans::UnknownPropertyException();
     402             : 
     403          50 :     if( mpSet )
     404             :     {
     405          50 :         if( pEntry->nWID == OWN_ATTR_FILLBMP_MODE )
     406             :         {
     407           2 :             mpSet->ClearItem( XATTR_FILLBMP_STRETCH );
     408           2 :             mpSet->ClearItem( XATTR_FILLBMP_TILE );
     409             :         }
     410             :         else
     411             :         {
     412          48 :             mpSet->ClearItem( pEntry->nWID );
     413             :         }
     414          50 :     }
     415          50 : }
     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         106 : const SfxItemPropertySimpleEntry* SdUnoPageBackground::getPropertyMapEntry( const OUString& rPropertyName ) const throw()
     447             : {
     448         106 :     return mpPropSet->getPropertyMap()->getByName(rPropertyName);
     449             : }
     450             : 
     451             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10