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

Generated by: LCOV version 1.10