LCOV - code coverage report
Current view: top level - sd/source/ui/unoidl - unopback.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 128 195 65.6 %
Date: 2014-04-11 Functions: 16 25 64.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/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 <cppuhelper/supportsservice.hxx>
      27             : #include <svx/xflbstit.hxx>
      28             : #include <svx/xflbmtit.hxx>
      29             : #include <svx/svdobj.hxx>
      30             : #include <svx/unoprov.hxx>
      31             : #include <svx/unoshape.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         118 : const SvxItemPropertySet* ImplGetPageBackgroundPropertySet()
      42             : {
      43             :     static const SfxItemPropertyMapEntry aPageBackgroundPropertyMap_Impl[] =
      44             :     {
      45         243 :         FILL_PROPERTIES
      46             :         { OUString(), 0, css::uno::Type(), 0, 0 }
      47         370 :     };
      48             : 
      49         118 :     static SvxItemPropertySet aPageBackgroundPropertySet_Impl( aPageBackgroundPropertyMap_Impl, SdrObject::GetGlobalDrawObjectItemPool() );
      50         118 :     return &aPageBackgroundPropertySet_Impl;
      51             : }
      52             : 
      53         225 : UNO3_GETIMPLEMENTATION_IMPL( SdUnoPageBackground );
      54             : 
      55          80 : SdUnoPageBackground::SdUnoPageBackground(
      56             :     SdDrawDocument* pDoc /* = NULL */,
      57             :     const SfxItemSet* pSet /* = NULL */) throw()
      58          80 : :   mpPropSet(ImplGetPageBackgroundPropertySet()),
      59             :     mpSet(NULL),
      60         160 :     mpDoc(pDoc)
      61             : {
      62          80 :     if( pDoc )
      63             :     {
      64          79 :         StartListening( *pDoc );
      65          79 :         mpSet = new SfxItemSet( pDoc->GetPool(), XATTR_FILL_FIRST, XATTR_FILL_LAST );
      66             : 
      67          79 :         if( pSet )
      68           6 :             mpSet->Put(*pSet);
      69             :     }
      70          80 : }
      71             : 
      72         234 : SdUnoPageBackground::~SdUnoPageBackground() throw()
      73             : {
      74          78 :     if( mpDoc )
      75          77 :         EndListening( *mpDoc );
      76             : 
      77          78 :     if( mpSet )
      78          77 :         delete mpSet;
      79         156 : }
      80             : 
      81          89 : void SdUnoPageBackground::Notify( SfxBroadcaster&, const SfxHint& rHint )
      82             : {
      83          89 :     const SdrHint* pSdrHint = PTR_CAST( SdrHint, &rHint );
      84             : 
      85          89 :     if( pSdrHint )
      86             :     {
      87             :         // delete item set if document is dying because then the pool
      88             :         // will also die
      89          88 :         if( pSdrHint->GetKind() == HINT_MODELCLEARED )
      90             :         {
      91           2 :             delete mpSet;
      92           2 :             mpSet = NULL;
      93           2 :             mpDoc = NULL;
      94             :         }
      95             :     }
      96             : 
      97          89 : }
      98             : 
      99          57 : void SdUnoPageBackground::fillItemSet( SdDrawDocument* pDoc, SfxItemSet& rSet ) throw()
     100             : {
     101          57 :     rSet.ClearItem();
     102             : 
     103          57 :     if( mpSet == NULL )
     104             :     {
     105           1 :         StartListening( *pDoc );
     106           1 :         mpDoc = pDoc;
     107             : 
     108           1 :         mpSet = new SfxItemSet( *rSet.GetPool(), XATTR_FILL_FIRST, XATTR_FILL_LAST );
     109             : 
     110           1 :         if( mpPropSet->AreThereOwnUsrAnys() )
     111             :         {
     112             :             uno::Any* pAny;
     113           1 :             PropertyEntryVector_t aProperties = mpPropSet->getPropertyMap()->getPropertyEntries();
     114           1 :             PropertyEntryVector_t::const_iterator aIt = aProperties.begin();
     115             : 
     116          29 :             while( aIt != aProperties.end() )
     117             :             {
     118          27 :                 pAny = mpPropSet->GetUsrAnyForID( aIt->nWID );
     119          27 :                 if( pAny )
     120             :                 {
     121           6 :                     OUString aPropertyName( aIt->sName );
     122           6 :                     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           9 :                             if ( ( ( pAny->getValueType() == ::getCppuType((const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XBitmap >*)0) ) ||
     156           3 :                                     ( 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           8 :                             else if ( ( pAny->getValueType() == ::getCppuType((const OUString*)0) ) &&
     162           5 :                                         ( ( aIt->nMemberId == MID_NAME ) || ( aIt->nMemberId == MID_GRAFURL ) ) )
     163             :                             {
     164           2 :                                 setPropertyValue( aPropertyName, *pAny );
     165             :                             }
     166             :                         }
     167           3 :                         break;
     168             : 
     169             :                         default:
     170           3 :                             setPropertyValue( aPropertyName, *pAny );
     171           6 :                     }
     172             :                 }
     173          27 :                 ++aIt;
     174           1 :             }
     175             :         }
     176             :     }
     177             : 
     178          57 :     rSet.Put( *mpSet );
     179          57 : }
     180             : 
     181             : // XServiceInfo
     182           0 : OUString SAL_CALL SdUnoPageBackground::getImplementationName()
     183             :     throw(uno::RuntimeException, std::exception)
     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, std::exception)
     190             : {
     191           0 :     return cppu::supportsService( this, ServiceName );
     192             : }
     193             : 
     194           0 : uno::Sequence< OUString > SAL_CALL SdUnoPageBackground::getSupportedServiceNames()
     195             :     throw(uno::RuntimeException, std::exception)
     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          95 : uno::Reference< beans::XPropertySetInfo > SAL_CALL SdUnoPageBackground::getPropertySetInfo()
     208             :     throw(uno::RuntimeException, std::exception)
     209             : {
     210          95 :     return mpPropSet->getPropertySetInfo();
     211             : }
     212             : 
     213          68 : void SAL_CALL SdUnoPageBackground::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue )
     214             :     throw(beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
     215             : {
     216          68 :     SolarMutexGuard aGuard;
     217             : 
     218          68 :     const SfxItemPropertySimpleEntry* pEntry = getPropertyMapEntry( aPropertyName );
     219             : 
     220          68 :     if( pEntry == NULL )
     221             :     {
     222           0 :         throw beans::UnknownPropertyException();
     223             :     }
     224             :     else
     225             :     {
     226          68 :         if( mpSet )
     227             :         {
     228          64 :             if( pEntry->nWID == OWN_ATTR_FILLBMP_MODE )
     229             :             {
     230             :                 drawing::BitmapMode eMode;
     231           2 :                 if( aValue >>= eMode )
     232             :                 {
     233           2 :                     mpSet->Put( XFillBmpStretchItem( eMode == drawing::BitmapMode_STRETCH ) );
     234           2 :                     mpSet->Put( XFillBmpTileItem( eMode == drawing::BitmapMode_REPEAT ) );
     235          70 :                     return;
     236             :                 }
     237           0 :                 throw lang::IllegalArgumentException();
     238             :             }
     239             : 
     240          62 :             SfxItemPool& rPool = *mpSet->GetPool();
     241          62 :             SfxItemSet aSet( rPool, pEntry->nWID, pEntry->nWID);
     242          62 :             aSet.Put( *mpSet );
     243             : 
     244          62 :             if( !aSet.Count() )
     245          61 :                 aSet.Put( rPool.GetDefaultItem( pEntry->nWID ) );
     246             : 
     247          62 :             if( pEntry->nMemberId == MID_NAME && ( pEntry->nWID == XATTR_FILLBITMAP || pEntry->nWID == XATTR_FILLGRADIENT || pEntry->nWID == XATTR_FILLHATCH || pEntry->nWID == XATTR_FILLFLOATTRANSPARENCE ) )
     248             :             {
     249           2 :                 OUString aName;
     250           2 :                 if(!(aValue >>= aName ))
     251           0 :                     throw lang::IllegalArgumentException();
     252             : 
     253           2 :                 SvxShape::SetFillAttribute( pEntry->nWID, aName, aSet );
     254             :             }
     255             :             else
     256             :             {
     257          60 :                 SvxItemPropertySet_setPropertyValue( *mpPropSet, pEntry, aValue, aSet );
     258             :             }
     259             : 
     260          62 :             mpSet->Put( aSet );
     261             :         }
     262             :         else
     263             :         {
     264           4 :             if(pEntry && pEntry->nWID)
     265           4 :                 mpPropSet->setPropertyValue( pEntry, aValue );
     266             :         }
     267          66 :     }
     268             : }
     269             : 
     270          26 : uno::Any SAL_CALL SdUnoPageBackground::getPropertyValue( const OUString& PropertyName )
     271             :     throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
     272             : {
     273          26 :     SolarMutexGuard aGuard;
     274             : 
     275          26 :     uno::Any aAny;
     276          26 :     const SfxItemPropertySimpleEntry* pEntry = getPropertyMapEntry(PropertyName);
     277             : 
     278          26 :     if( pEntry == NULL )
     279             :     {
     280           0 :         throw beans::UnknownPropertyException();
     281             :     }
     282             :     else
     283             :     {
     284          26 :         if( mpSet )
     285             :         {
     286          26 :             if( pEntry->nWID == OWN_ATTR_FILLBMP_MODE )
     287             :             {
     288           1 :                 XFillBmpStretchItem* pStretchItem = (XFillBmpStretchItem*)mpSet->GetItem(XATTR_FILLBMP_STRETCH);
     289           1 :                 XFillBmpTileItem* pTileItem = (XFillBmpTileItem*)mpSet->GetItem(XATTR_FILLBMP_TILE);
     290             : 
     291           1 :                 if( pStretchItem && pTileItem )
     292             :                 {
     293           1 :                     if( pTileItem->GetValue() )
     294           0 :                         aAny <<= drawing::BitmapMode_REPEAT;
     295           1 :                     else if( pStretchItem->GetValue() )
     296           1 :                         aAny <<= drawing::BitmapMode_STRETCH;
     297             :                     else
     298           0 :                         aAny <<= drawing::BitmapMode_NO_REPEAT;
     299             :                 }
     300             :             }
     301             :             else
     302             :             {
     303          25 :                 SfxItemPool& rPool = *mpSet->GetPool();
     304          25 :                 SfxItemSet aSet( rPool, pEntry->nWID, pEntry->nWID);
     305          25 :                 aSet.Put( *mpSet );
     306             : 
     307          25 :                 if( !aSet.Count() )
     308           0 :                     aSet.Put( rPool.GetDefaultItem( pEntry->nWID ) );
     309             : 
     310             :                 // get value from ItemSet
     311          25 :                 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          26 :     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, std::exception) {}
     324           0 : void SAL_CALL SdUnoPageBackground::removePropertyChangeListener( const OUString& , const uno::Reference< beans::XPropertyChangeListener >&  ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception) {}
     325           0 : void SAL_CALL SdUnoPageBackground::addVetoableChangeListener( const OUString& , const uno::Reference< beans::XVetoableChangeListener >&  ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception) {}
     326           0 : void SAL_CALL SdUnoPageBackground::removeVetoableChangeListener( const OUString& , const uno::Reference< beans::XVetoableChangeListener >&  ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception) {}
     327             : 
     328             : // XPropertyState
     329         527 : beans::PropertyState SAL_CALL SdUnoPageBackground::getPropertyState( const OUString& PropertyName )
     330             :     throw(beans::UnknownPropertyException, uno::RuntimeException, std::exception)
     331             : {
     332         527 :     SolarMutexGuard aGuard;
     333             : 
     334         527 :     const SfxItemPropertySimpleEntry* pEntry = getPropertyMapEntry(PropertyName);
     335             : 
     336         527 :     if( pEntry == NULL )
     337           0 :         throw beans::UnknownPropertyException();
     338             : 
     339         527 :     if( mpSet )
     340             :     {
     341         527 :         if( pEntry->nWID == OWN_ATTR_FILLBMP_MODE )
     342             :         {
     343          41 :             if( mpSet->GetItemState( XATTR_FILLBMP_STRETCH, false ) == SFX_ITEM_SET ||
     344          20 :                 mpSet->GetItemState( XATTR_FILLBMP_TILE, false ) == SFX_ITEM_SET )
     345             :             {
     346           1 :                 return beans::PropertyState_DIRECT_VALUE;
     347             :             }
     348             :             else
     349             :             {
     350          20 :                 return beans::PropertyState_AMBIGUOUS_VALUE;
     351             :             }
     352             :         }
     353             : 
     354         506 :         switch( mpSet->GetItemState( pEntry->nWID, false ) )
     355             :         {
     356             :         case SFX_ITEM_READONLY:
     357             :         case SFX_ITEM_SET:
     358          24 :             return beans::PropertyState_DIRECT_VALUE;
     359             :         case SFX_ITEM_DEFAULT:
     360         465 :             return beans::PropertyState_DEFAULT_VALUE;
     361             :         default:
     362             : //      case SFX_ITEM_DONTCARE:
     363             : //      case SFX_ITEM_DISABLED:
     364          17 :             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         527 :     }
     374             : }
     375             : 
     376           0 : uno::Sequence< beans::PropertyState > SAL_CALL SdUnoPageBackground::getPropertyStates( const uno::Sequence< OUString >& aPropertyName )
     377             :     throw(beans::UnknownPropertyException, uno::RuntimeException, std::exception)
     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         440 : void SAL_CALL SdUnoPageBackground::setPropertyToDefault( const OUString& PropertyName )
     394             :     throw(beans::UnknownPropertyException, uno::RuntimeException, std::exception)
     395             : {
     396         440 :     SolarMutexGuard aGuard;
     397             : 
     398         440 :     const SfxItemPropertySimpleEntry* pEntry = getPropertyMapEntry(PropertyName);
     399             : 
     400         440 :     if( pEntry == NULL )
     401           0 :         throw beans::UnknownPropertyException();
     402             : 
     403         440 :     if( mpSet )
     404             :     {
     405         440 :         if( pEntry->nWID == OWN_ATTR_FILLBMP_MODE )
     406             :         {
     407          17 :             mpSet->ClearItem( XATTR_FILLBMP_STRETCH );
     408          17 :             mpSet->ClearItem( XATTR_FILLBMP_TILE );
     409             :         }
     410             :         else
     411             :         {
     412         423 :             mpSet->ClearItem( pEntry->nWID );
     413             :         }
     414         440 :     }
     415         440 : }
     416             : 
     417           0 : uno::Any SAL_CALL SdUnoPageBackground::getPropertyDefault( const OUString& aPropertyName )
     418             :     throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
     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        1061 : const SfxItemPropertySimpleEntry* SdUnoPageBackground::getPropertyMapEntry( const OUString& rPropertyName ) const throw()
     447             : {
     448        1061 :     return mpPropSet->getPropertyMap()->getByName(rPropertyName);
     449             : }
     450             : 
     451             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10