LCOV - code coverage report
Current view: top level - sd/source/ui/unoidl - unopback.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 132 197 67.0 %
Date: 2015-06-13 12:38:46 Functions: 18 27 66.7 %
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 ::com::sun::star;
      39             : 
      40         350 : const SvxItemPropertySet* ImplGetPageBackgroundPropertySet()
      41             : {
      42             :     static const SfxItemPropertyMapEntry aPageBackgroundPropertyMap_Impl[] =
      43             :     {
      44         351 :         FILL_PROPERTIES
      45             :         { OUString(), 0, css::uno::Type(), 0, 0 }
      46         714 :     };
      47             : 
      48         350 :     static SvxItemPropertySet aPageBackgroundPropertySet_Impl( aPageBackgroundPropertyMap_Impl, SdrObject::GetGlobalDrawObjectItemPool() );
      49         350 :     return &aPageBackgroundPropertySet_Impl;
      50             : }
      51             : 
      52         666 : UNO3_GETIMPLEMENTATION_IMPL( SdUnoPageBackground );
      53             : 
      54         230 : SdUnoPageBackground::SdUnoPageBackground(
      55             :     SdDrawDocument* pDoc /* = NULL */,
      56             :     const SfxItemSet* pSet /* = NULL */) throw()
      57         230 : :   mpPropSet(ImplGetPageBackgroundPropertySet()),
      58             :     mpSet(NULL),
      59         460 :     mpDoc(pDoc)
      60             : {
      61         230 :     if( pDoc )
      62             :     {
      63         224 :         StartListening( *pDoc );
      64         224 :         mpSet = new SfxItemSet( pDoc->GetPool(), XATTR_FILL_FIRST, XATTR_FILL_LAST );
      65             : 
      66         224 :         if( pSet )
      67          10 :             mpSet->Put(*pSet);
      68             :     }
      69         230 : }
      70             : 
      71         684 : SdUnoPageBackground::~SdUnoPageBackground() throw()
      72             : {
      73         228 :     SolarMutexGuard g;
      74             : 
      75         228 :     if( mpDoc )
      76         227 :         EndListening( *mpDoc );
      77             : 
      78         228 :     if( mpSet )
      79         227 :         delete mpSet;
      80         456 : }
      81             : 
      82         289 : void SdUnoPageBackground::Notify( SfxBroadcaster&, const SfxHint& rHint )
      83             : {
      84         289 :     const SdrHint* pSdrHint = dynamic_cast<const SdrHint*>( &rHint );
      85             : 
      86         289 :     if( pSdrHint )
      87             :     {
      88             :         // delete item set if document is dying because then the pool
      89             :         // will also die
      90         286 :         if( pSdrHint->GetKind() == HINT_MODELCLEARED )
      91             :         {
      92           6 :             delete mpSet;
      93           6 :             mpSet = NULL;
      94           6 :             mpDoc = NULL;
      95             :         }
      96             :     }
      97             : 
      98         289 : }
      99             : 
     100         171 : void SdUnoPageBackground::fillItemSet( SdDrawDocument* pDoc, SfxItemSet& rSet ) throw()
     101             : {
     102         171 :     rSet.ClearItem();
     103             : 
     104         171 :     if( mpSet == NULL )
     105             :     {
     106           6 :         StartListening( *pDoc );
     107           6 :         mpDoc = pDoc;
     108             : 
     109           6 :         mpSet = new SfxItemSet( *rSet.GetPool(), XATTR_FILL_FIRST, XATTR_FILL_LAST );
     110             : 
     111           6 :         if( mpPropSet->AreThereOwnUsrAnys() )
     112             :         {
     113           6 :             PropertyEntryVector_t aProperties = mpPropSet->getPropertyMap().getPropertyEntries();
     114           6 :             PropertyEntryVector_t::const_iterator aIt = aProperties.begin();
     115             : 
     116         174 :             while( aIt != aProperties.end() )
     117             :             {
     118         162 :                 uno::Any* pAny = mpPropSet->GetUsrAnyForID( aIt->nWID );
     119         162 :                 if( pAny )
     120             :                 {
     121          37 :                     OUString aPropertyName( aIt->sName );
     122          37 :                     switch( aIt->nWID )
     123             :                     {
     124             :                         case XATTR_FILLFLOATTRANSPARENCE :
     125             :                         case XATTR_FILLGRADIENT :
     126             :                         {
     127           0 :                             if ( ( pAny->getValueType() == ::cppu::UnoType< ::com::sun::star::awt::Gradient>::get() )
     128           0 :                                 && ( aIt->nMemberId == MID_FILLGRADIENT ) )
     129             :                             {
     130           0 :                                 setPropertyValue( aPropertyName, *pAny );
     131             :                             }
     132           0 :                             else if ( ( pAny->getValueType() == ::cppu::UnoType<OUString>::get() ) &&
     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() == ::cppu::UnoType< ::com::sun::star::drawing::Hatch>::get() )
     142           0 :                                 && ( aIt->nMemberId == MID_FILLHATCH ) )
     143             :                             {
     144           0 :                                 setPropertyValue( aPropertyName, *pAny );
     145             :                             }
     146           0 :                             else if ( ( pAny->getValueType() == ::cppu::UnoType<OUString>::get() ) &&
     147           0 :                                         ( aIt->nMemberId == MID_NAME ) )
     148             :                             {
     149           0 :                                 setPropertyValue( aPropertyName, *pAny );
     150             :                             }
     151             :                         }
     152           0 :                         break;
     153             :                         case XATTR_FILLBITMAP :
     154             :                         {
     155          54 :                             if ( ( ( pAny->getValueType() == cppu::UnoType<com::sun::star::awt::XBitmap>::get()) ||
     156          18 :                                     ( pAny->getValueType() == cppu::UnoType<com::sun::star::graphic::XGraphic>::get()) ) &&
     157           0 :                                     ( aIt->nMemberId == MID_BITMAP ) )
     158             :                             {
     159           0 :                                 setPropertyValue( aPropertyName, *pAny );
     160             :                             }
     161          48 :                             else if ( ( pAny->getValueType() == ::cppu::UnoType<OUString>::get() ) &&
     162          30 :                                         ( ( aIt->nMemberId == MID_NAME ) || ( aIt->nMemberId == MID_GRAFURL ) ) )
     163             :                             {
     164          12 :                                 setPropertyValue( aPropertyName, *pAny );
     165             :                             }
     166             :                         }
     167          18 :                         break;
     168             : 
     169             :                         default:
     170          19 :                             setPropertyValue( aPropertyName, *pAny );
     171          37 :                     }
     172             :                 }
     173         162 :                 ++aIt;
     174           6 :             }
     175             :         }
     176             :     }
     177             : 
     178         171 :     rSet.Put( *mpSet );
     179         171 : }
     180             : 
     181             : // XServiceInfo
     182           0 : OUString SAL_CALL SdUnoPageBackground::getImplementationName()
     183             :     throw(uno::RuntimeException, std::exception)
     184             : {
     185           0 :     return OUString("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++ = sUNO_Service_PageBackground;
     201           0 :     *pStrings   = sUNO_Service_FillProperties;
     202             : 
     203           0 :     return aNameSequence;
     204             : }
     205             : 
     206             : // XPropertySet
     207         273 : uno::Reference< beans::XPropertySetInfo > SAL_CALL SdUnoPageBackground::getPropertySetInfo()
     208             :     throw(uno::RuntimeException, std::exception)
     209             : {
     210         273 :     return mpPropSet->getPropertySetInfo();
     211             : }
     212             : 
     213         209 : 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         209 :     SolarMutexGuard aGuard;
     217             : 
     218         209 :     const SfxItemPropertySimpleEntry* pEntry = getPropertyMapEntry( aPropertyName );
     219             : 
     220         209 :     if( pEntry == NULL )
     221             :     {
     222           0 :         throw beans::UnknownPropertyException();
     223             :     }
     224             :     else
     225             :     {
     226         209 :         if( mpSet )
     227             :         {
     228         187 :             if( pEntry->nWID == OWN_ATTR_FILLBMP_MODE )
     229             :             {
     230             :                 drawing::BitmapMode eMode;
     231           7 :                 if( aValue >>= eMode )
     232             :                 {
     233           7 :                     mpSet->Put( XFillBmpStretchItem( eMode == drawing::BitmapMode_STRETCH ) );
     234           7 :                     mpSet->Put( XFillBmpTileItem( eMode == drawing::BitmapMode_REPEAT ) );
     235         216 :                     return;
     236             :                 }
     237           0 :                 throw lang::IllegalArgumentException();
     238             :             }
     239             : 
     240         180 :             SfxItemPool& rPool = *mpSet->GetPool();
     241         180 :             SfxItemSet aSet( rPool, pEntry->nWID, pEntry->nWID);
     242         180 :             aSet.Put( *mpSet );
     243             : 
     244         180 :             if( !aSet.Count() )
     245         174 :                 aSet.Put( rPool.GetDefaultItem( pEntry->nWID ) );
     246             : 
     247         180 :             if( pEntry->nMemberId == MID_NAME && ( pEntry->nWID == XATTR_FILLBITMAP || pEntry->nWID == XATTR_FILLGRADIENT || pEntry->nWID == XATTR_FILLHATCH || pEntry->nWID == XATTR_FILLFLOATTRANSPARENCE ) )
     248             :             {
     249           7 :                 OUString aName;
     250           7 :                 if(!(aValue >>= aName ))
     251           0 :                     throw lang::IllegalArgumentException();
     252             : 
     253           7 :                 SvxShape::SetFillAttribute( pEntry->nWID, aName, aSet );
     254             :             }
     255             :             else
     256             :             {
     257         173 :                 SvxItemPropertySet_setPropertyValue( pEntry, aValue, aSet );
     258             :             }
     259             : 
     260         180 :             mpSet->Put( aSet );
     261             :         }
     262             :         else
     263             :         {
     264          22 :             if(pEntry && pEntry->nWID)
     265          22 :                 mpPropSet->setPropertyValue( pEntry, aValue );
     266             :         }
     267         202 :     }
     268             : }
     269             : 
     270          68 : uno::Any SAL_CALL SdUnoPageBackground::getPropertyValue( const OUString& PropertyName )
     271             :     throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
     272             : {
     273          68 :     SolarMutexGuard aGuard;
     274             : 
     275          68 :     uno::Any aAny;
     276          68 :     const SfxItemPropertySimpleEntry* pEntry = getPropertyMapEntry(PropertyName);
     277             : 
     278          68 :     if( pEntry == NULL )
     279             :     {
     280           1 :         throw beans::UnknownPropertyException();
     281             :     }
     282             :     else
     283             :     {
     284          67 :         if( mpSet )
     285             :         {
     286          67 :             if( pEntry->nWID == OWN_ATTR_FILLBMP_MODE )
     287             :             {
     288           1 :                 const XFillBmpStretchItem* pStretchItem = static_cast<const XFillBmpStretchItem*>(mpSet->GetItem(XATTR_FILLBMP_STRETCH));
     289           1 :                 const XFillBmpTileItem* pTileItem = static_cast<const 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          66 :                 SfxItemPool& rPool = *mpSet->GetPool();
     304          66 :                 SfxItemSet aSet( rPool, pEntry->nWID, pEntry->nWID);
     305          66 :                 aSet.Put( *mpSet );
     306             : 
     307          66 :                 if( !aSet.Count() )
     308           3 :                     aSet.Put( rPool.GetDefaultItem( pEntry->nWID ) );
     309             : 
     310             :                 // get value from ItemSet
     311          66 :                 aAny = SvxItemPropertySet_getPropertyValue( pEntry, aSet );
     312             :             }
     313             :         }
     314             :         else
     315             :         {
     316           0 :             if(pEntry && pEntry->nWID)
     317           0 :                 aAny = mpPropSet->getPropertyValue( pEntry );
     318             :         }
     319             :     }
     320          68 :     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        1391 : beans::PropertyState SAL_CALL SdUnoPageBackground::getPropertyState( const OUString& PropertyName )
     330             :     throw(beans::UnknownPropertyException, uno::RuntimeException, std::exception)
     331             : {
     332        1391 :     SolarMutexGuard aGuard;
     333             : 
     334        1391 :     const SfxItemPropertySimpleEntry* pEntry = getPropertyMapEntry(PropertyName);
     335             : 
     336        1391 :     if( pEntry == NULL )
     337           0 :         throw beans::UnknownPropertyException();
     338             : 
     339        1391 :     if( mpSet )
     340             :     {
     341        1391 :         if( pEntry->nWID == OWN_ATTR_FILLBMP_MODE )
     342             :         {
     343         105 :             if( mpSet->GetItemState( XATTR_FILLBMP_STRETCH, false ) == SfxItemState::SET ||
     344          52 :                 mpSet->GetItemState( XATTR_FILLBMP_TILE, false ) == SfxItemState::SET )
     345             :             {
     346           1 :                 return beans::PropertyState_DIRECT_VALUE;
     347             :             }
     348             :             else
     349             :             {
     350          52 :                 return beans::PropertyState_AMBIGUOUS_VALUE;
     351             :             }
     352             :         }
     353             : 
     354        1338 :         switch( mpSet->GetItemState( pEntry->nWID, false ) )
     355             :         {
     356             :         case SfxItemState::READONLY:
     357             :         case SfxItemState::SET:
     358          58 :             return beans::PropertyState_DIRECT_VALUE;
     359             :         case SfxItemState::DEFAULT:
     360        1231 :             return beans::PropertyState_DEFAULT_VALUE;
     361             :         default:
     362             : //      case SfxItemState::DONTCARE:
     363             : //      case SfxItemState::DISABLED:
     364          49 :             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        1391 :     }
     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        1270 : void SAL_CALL SdUnoPageBackground::setPropertyToDefault( const OUString& PropertyName )
     394             :     throw(beans::UnknownPropertyException, uno::RuntimeException, std::exception)
     395             : {
     396        1270 :     SolarMutexGuard aGuard;
     397             : 
     398        1270 :     const SfxItemPropertySimpleEntry* pEntry = getPropertyMapEntry(PropertyName);
     399             : 
     400        1270 :     if( pEntry == NULL )
     401           0 :         throw beans::UnknownPropertyException();
     402             : 
     403        1270 :     if( mpSet )
     404             :     {
     405        1270 :         if( pEntry->nWID == OWN_ATTR_FILLBMP_MODE )
     406             :         {
     407          49 :             mpSet->ClearItem( XATTR_FILLBMP_STRETCH );
     408          49 :             mpSet->ClearItem( XATTR_FILLBMP_TILE );
     409             :         }
     410             :         else
     411             :         {
     412        1221 :             mpSet->ClearItem( pEntry->nWID );
     413             :         }
     414        1270 :     }
     415        1270 : }
     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( pEntry, aSet );
     440             :         }
     441             :     }
     442           0 :     return aAny;
     443             : }
     444             : 
     445             : /** this is used because our property map is not sorted yet */
     446        2938 : const SfxItemPropertySimpleEntry* SdUnoPageBackground::getPropertyMapEntry( const OUString& rPropertyName ) const throw()
     447             : {
     448        2938 :     return mpPropSet->getPropertyMap().getByName(rPropertyName);
     449          66 : }
     450             : 
     451             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11