LCOV - code coverage report
Current view: top level - sd/source/ui/unoidl - unopback.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 195 0.0 %
Date: 2014-04-14 Functions: 0 25 0.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           0 : const SvxItemPropertySet* ImplGetPageBackgroundPropertySet()
      42             : {
      43             :     static const SfxItemPropertyMapEntry aPageBackgroundPropertyMap_Impl[] =
      44             :     {
      45           0 :         FILL_PROPERTIES
      46             :         { OUString(), 0, css::uno::Type(), 0, 0 }
      47           0 :     };
      48             : 
      49           0 :     static SvxItemPropertySet aPageBackgroundPropertySet_Impl( aPageBackgroundPropertyMap_Impl, SdrObject::GetGlobalDrawObjectItemPool() );
      50           0 :     return &aPageBackgroundPropertySet_Impl;
      51             : }
      52             : 
      53           0 : UNO3_GETIMPLEMENTATION_IMPL( SdUnoPageBackground );
      54             : 
      55           0 : SdUnoPageBackground::SdUnoPageBackground(
      56             :     SdDrawDocument* pDoc /* = NULL */,
      57             :     const SfxItemSet* pSet /* = NULL */) throw()
      58           0 : :   mpPropSet(ImplGetPageBackgroundPropertySet()),
      59             :     mpSet(NULL),
      60           0 :     mpDoc(pDoc)
      61             : {
      62           0 :     if( pDoc )
      63             :     {
      64           0 :         StartListening( *pDoc );
      65           0 :         mpSet = new SfxItemSet( pDoc->GetPool(), XATTR_FILL_FIRST, XATTR_FILL_LAST );
      66             : 
      67           0 :         if( pSet )
      68           0 :             mpSet->Put(*pSet);
      69             :     }
      70           0 : }
      71             : 
      72           0 : SdUnoPageBackground::~SdUnoPageBackground() throw()
      73             : {
      74           0 :     if( mpDoc )
      75           0 :         EndListening( *mpDoc );
      76             : 
      77           0 :     if( mpSet )
      78           0 :         delete mpSet;
      79           0 : }
      80             : 
      81           0 : void SdUnoPageBackground::Notify( SfxBroadcaster&, const SfxHint& rHint )
      82             : {
      83           0 :     const SdrHint* pSdrHint = PTR_CAST( SdrHint, &rHint );
      84             : 
      85           0 :     if( pSdrHint )
      86             :     {
      87             :         // delete item set if document is dying because then the pool
      88             :         // will also die
      89           0 :         if( pSdrHint->GetKind() == HINT_MODELCLEARED )
      90             :         {
      91           0 :             delete mpSet;
      92           0 :             mpSet = NULL;
      93           0 :             mpDoc = NULL;
      94             :         }
      95             :     }
      96             : 
      97           0 : }
      98             : 
      99           0 : void SdUnoPageBackground::fillItemSet( SdDrawDocument* pDoc, SfxItemSet& rSet ) throw()
     100             : {
     101           0 :     rSet.ClearItem();
     102             : 
     103           0 :     if( mpSet == NULL )
     104             :     {
     105           0 :         StartListening( *pDoc );
     106           0 :         mpDoc = pDoc;
     107             : 
     108           0 :         mpSet = new SfxItemSet( *rSet.GetPool(), XATTR_FILL_FIRST, XATTR_FILL_LAST );
     109             : 
     110           0 :         if( mpPropSet->AreThereOwnUsrAnys() )
     111             :         {
     112             :             uno::Any* pAny;
     113           0 :             PropertyEntryVector_t aProperties = mpPropSet->getPropertyMap()->getPropertyEntries();
     114           0 :             PropertyEntryVector_t::const_iterator aIt = aProperties.begin();
     115             : 
     116           0 :             while( aIt != aProperties.end() )
     117             :             {
     118           0 :                 pAny = mpPropSet->GetUsrAnyForID( aIt->nWID );
     119           0 :                 if( pAny )
     120             :                 {
     121           0 :                     OUString aPropertyName( aIt->sName );
     122           0 :                     switch( aIt->nWID )
     123             :                     {
     124             :                         case XATTR_FILLFLOATTRANSPARENCE :
     125             :                         case XATTR_FILLGRADIENT :
     126             :                         {
     127           0 :                             if ( ( pAny->getValueType() == ::getCppuType((const ::com::sun::star::awt::Gradient*)0) )
     128           0 :                                 && ( aIt->nMemberId == MID_FILLGRADIENT ) )
     129             :                             {
     130           0 :                                 setPropertyValue( aPropertyName, *pAny );
     131             :                             }
     132           0 :                             else if ( ( pAny->getValueType() == ::getCppuType((const OUString*)0) ) &&
     133           0 :                                         ( aIt->nMemberId == MID_NAME ) )
     134             :                             {
     135           0 :                                 setPropertyValue( aPropertyName, *pAny );
     136             :                             }
     137             :                         }
     138           0 :                         break;
     139             :                         case XATTR_FILLHATCH :
     140             :                         {
     141           0 :                             if ( ( pAny->getValueType() == ::getCppuType((const ::com::sun::star::drawing::Hatch*)0) )
     142           0 :                                 && ( aIt->nMemberId == MID_FILLHATCH ) )
     143             :                             {
     144           0 :                                 setPropertyValue( aPropertyName, *pAny );
     145             :                             }
     146           0 :                             else if ( ( pAny->getValueType() == ::getCppuType((const OUString*)0) ) &&
     147           0 :                                         ( aIt->nMemberId == MID_NAME ) )
     148             :                             {
     149           0 :                                 setPropertyValue( aPropertyName, *pAny );
     150             :                             }
     151             :                         }
     152           0 :                         break;
     153             :                         case XATTR_FILLBITMAP :
     154             :                         {
     155           0 :                             if ( ( ( pAny->getValueType() == ::getCppuType((const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XBitmap >*)0) ) ||
     156           0 :                                     ( pAny->getValueType() == ::getCppuType((const ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic >*)0) ) ) &&
     157           0 :                                     ( aIt->nMemberId == MID_BITMAP ) )
     158             :                             {
     159           0 :                                 setPropertyValue( aPropertyName, *pAny );
     160             :                             }
     161           0 :                             else if ( ( pAny->getValueType() == ::getCppuType((const OUString*)0) ) &&
     162           0 :                                         ( ( aIt->nMemberId == MID_NAME ) || ( aIt->nMemberId == MID_GRAFURL ) ) )
     163             :                             {
     164           0 :                                 setPropertyValue( aPropertyName, *pAny );
     165             :                             }
     166             :                         }
     167           0 :                         break;
     168             : 
     169             :                         default:
     170           0 :                             setPropertyValue( aPropertyName, *pAny );
     171           0 :                     }
     172             :                 }
     173           0 :                 ++aIt;
     174           0 :             }
     175             :         }
     176             :     }
     177             : 
     178           0 :     rSet.Put( *mpSet );
     179           0 : }
     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           0 : uno::Reference< beans::XPropertySetInfo > SAL_CALL SdUnoPageBackground::getPropertySetInfo()
     208             :     throw(uno::RuntimeException, std::exception)
     209             : {
     210           0 :     return mpPropSet->getPropertySetInfo();
     211             : }
     212             : 
     213           0 : 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           0 :     SolarMutexGuard aGuard;
     217             : 
     218           0 :     const SfxItemPropertySimpleEntry* pEntry = getPropertyMapEntry( aPropertyName );
     219             : 
     220           0 :     if( pEntry == NULL )
     221             :     {
     222           0 :         throw beans::UnknownPropertyException();
     223             :     }
     224             :     else
     225             :     {
     226           0 :         if( mpSet )
     227             :         {
     228           0 :             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           0 :                     return;
     236             :                 }
     237           0 :                 throw lang::IllegalArgumentException();
     238             :             }
     239             : 
     240           0 :             SfxItemPool& rPool = *mpSet->GetPool();
     241           0 :             SfxItemSet aSet( rPool, pEntry->nWID, pEntry->nWID);
     242           0 :             aSet.Put( *mpSet );
     243             : 
     244           0 :             if( !aSet.Count() )
     245           0 :                 aSet.Put( rPool.GetDefaultItem( pEntry->nWID ) );
     246             : 
     247           0 :             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           0 :                 SvxItemPropertySet_setPropertyValue( *mpPropSet, pEntry, aValue, aSet );
     258             :             }
     259             : 
     260           0 :             mpSet->Put( aSet );
     261             :         }
     262             :         else
     263             :         {
     264           0 :             if(pEntry && pEntry->nWID)
     265           0 :                 mpPropSet->setPropertyValue( pEntry, aValue );
     266             :         }
     267           0 :     }
     268             : }
     269             : 
     270           0 : uno::Any SAL_CALL SdUnoPageBackground::getPropertyValue( const OUString& PropertyName )
     271             :     throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
     272             : {
     273           0 :     SolarMutexGuard aGuard;
     274             : 
     275           0 :     uno::Any aAny;
     276           0 :     const SfxItemPropertySimpleEntry* pEntry = getPropertyMapEntry(PropertyName);
     277             : 
     278           0 :     if( pEntry == NULL )
     279             :     {
     280           0 :         throw beans::UnknownPropertyException();
     281             :     }
     282             :     else
     283             :     {
     284           0 :         if( mpSet )
     285             :         {
     286           0 :             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           0 :                 SfxItemPool& rPool = *mpSet->GetPool();
     304           0 :                 SfxItemSet aSet( rPool, pEntry->nWID, pEntry->nWID);
     305           0 :                 aSet.Put( *mpSet );
     306             : 
     307           0 :                 if( !aSet.Count() )
     308           0 :                     aSet.Put( rPool.GetDefaultItem( pEntry->nWID ) );
     309             : 
     310             :                 // get value from ItemSet
     311           0 :                 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           0 :     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           0 : beans::PropertyState SAL_CALL SdUnoPageBackground::getPropertyState( const OUString& PropertyName )
     330             :     throw(beans::UnknownPropertyException, uno::RuntimeException, std::exception)
     331             : {
     332           0 :     SolarMutexGuard aGuard;
     333             : 
     334           0 :     const SfxItemPropertySimpleEntry* pEntry = getPropertyMapEntry(PropertyName);
     335             : 
     336           0 :     if( pEntry == NULL )
     337           0 :         throw beans::UnknownPropertyException();
     338             : 
     339           0 :     if( mpSet )
     340             :     {
     341           0 :         if( pEntry->nWID == OWN_ATTR_FILLBMP_MODE )
     342             :         {
     343           0 :             if( mpSet->GetItemState( XATTR_FILLBMP_STRETCH, false ) == SFX_ITEM_SET ||
     344           0 :                 mpSet->GetItemState( XATTR_FILLBMP_TILE, false ) == SFX_ITEM_SET )
     345             :             {
     346           0 :                 return beans::PropertyState_DIRECT_VALUE;
     347             :             }
     348             :             else
     349             :             {
     350           0 :                 return beans::PropertyState_AMBIGUOUS_VALUE;
     351             :             }
     352             :         }
     353             : 
     354           0 :         switch( mpSet->GetItemState( pEntry->nWID, false ) )
     355             :         {
     356             :         case SFX_ITEM_READONLY:
     357             :         case SFX_ITEM_SET:
     358           0 :             return beans::PropertyState_DIRECT_VALUE;
     359             :         case SFX_ITEM_DEFAULT:
     360           0 :             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           0 :     }
     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           0 : void SAL_CALL SdUnoPageBackground::setPropertyToDefault( const OUString& PropertyName )
     394             :     throw(beans::UnknownPropertyException, uno::RuntimeException, std::exception)
     395             : {
     396           0 :     SolarMutexGuard aGuard;
     397             : 
     398           0 :     const SfxItemPropertySimpleEntry* pEntry = getPropertyMapEntry(PropertyName);
     399             : 
     400           0 :     if( pEntry == NULL )
     401           0 :         throw beans::UnknownPropertyException();
     402             : 
     403           0 :     if( mpSet )
     404             :     {
     405           0 :         if( pEntry->nWID == OWN_ATTR_FILLBMP_MODE )
     406             :         {
     407           0 :             mpSet->ClearItem( XATTR_FILLBMP_STRETCH );
     408           0 :             mpSet->ClearItem( XATTR_FILLBMP_TILE );
     409             :         }
     410             :         else
     411             :         {
     412           0 :             mpSet->ClearItem( pEntry->nWID );
     413             :         }
     414           0 :     }
     415           0 : }
     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           0 : const SfxItemPropertySimpleEntry* SdUnoPageBackground::getPropertyMapEntry( const OUString& rPropertyName ) const throw()
     447             : {
     448           0 :     return mpPropSet->getPropertyMap()->getByName(rPropertyName);
     449             : }
     450             : 
     451             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10