LCOV - code coverage report
Current view: top level - sw/source/core/unocore - SwXTextDefaults.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 53 130 40.8 %
Date: 2014-11-03 Functions: 10 19 52.6 %
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/beans/PropertyAttribute.hpp>
      21             : 
      22             : #include <osl/mutex.hxx>
      23             : #include <vcl/svapp.hxx>
      24             : 
      25             : #include <SwXTextDefaults.hxx>
      26             : #include <SwStyleNameMapper.hxx>
      27             : #include <fchrfmt.hxx>
      28             : #include <charfmt.hxx>
      29             : #include <cppuhelper/supportsservice.hxx>
      30             : #include <docstyle.hxx>
      31             : #include <doc.hxx>
      32             : #include <docsh.hxx>
      33             : #include <unomap.hxx>
      34             : #include <unomid.h>
      35             : #include <paratr.hxx>
      36             : #include <unoprnms.hxx>
      37             : #include <unocrsrhelper.hxx>
      38             : #include <hintids.hxx>
      39             : 
      40             : using namespace ::com::sun::star;
      41             : using namespace ::com::sun::star::uno;
      42             : using namespace ::com::sun::star::beans;
      43             : using namespace ::com::sun::star::lang;
      44             : 
      45        7606 : SwXTextDefaults::SwXTextDefaults ( SwDoc * pNewDoc ) :
      46        7606 :     m_pPropSet( aSwMapProvider.GetPropertySet( PROPERTY_MAP_TEXT_DEFAULT ) ),
      47       15212 :     m_pDoc   ( pNewDoc )
      48             : {
      49        7606 : }
      50             : 
      51       15212 : SwXTextDefaults::~SwXTextDefaults ()
      52             : {
      53       15212 : }
      54             : 
      55        1710 : uno::Reference< XPropertySetInfo > SAL_CALL SwXTextDefaults::getPropertySetInfo(  )
      56             :         throw(RuntimeException, std::exception)
      57             : {
      58        1710 :     static uno::Reference < XPropertySetInfo > xRef = m_pPropSet->getPropertySetInfo();
      59        1710 :     return xRef;
      60             : }
      61             : 
      62       46308 : void SAL_CALL SwXTextDefaults::setPropertyValue( const OUString& rPropertyName, const Any& aValue )
      63             :         throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException, std::exception)
      64             : {
      65       46308 :     SolarMutexGuard aGuard;
      66       46308 :     if (!m_pDoc)
      67           0 :         throw RuntimeException();
      68       46308 :     const SfxItemPropertySimpleEntry *pMap = m_pPropSet->getPropertyMap().getByName( rPropertyName );
      69       46308 :     if (!pMap)
      70           0 :         throw UnknownPropertyException( "Unknown property: " + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
      71       46308 :     if ( pMap->nFlags & PropertyAttribute::READONLY)
      72           0 :         throw PropertyVetoException ( "Property is read-only: " + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
      73             : 
      74       46308 :     const SfxPoolItem& rItem = m_pDoc->GetDefault(pMap->nWID);
      75       46308 :     if (RES_PAGEDESC == pMap->nWID && MID_PAGEDESC_PAGEDESCNAME == pMap->nMemberId)
      76             :     {
      77           0 :         SfxItemSet aSet( m_pDoc->GetAttrPool(), RES_PAGEDESC, RES_PAGEDESC );
      78           0 :         aSet.Put(rItem);
      79           0 :         SwUnoCursorHelper::SetPageDesc( aValue, *m_pDoc, aSet );
      80           0 :         m_pDoc->SetDefault(aSet.Get(RES_PAGEDESC));
      81             :     }
      82       92616 :     else if ((RES_PARATR_DROP == pMap->nWID && MID_DROPCAP_CHAR_STYLE_NAME == pMap->nMemberId) ||
      83       46308 :              (RES_TXTATR_CHARFMT == pMap->nWID))
      84             :     {
      85           0 :         OUString uStyle;
      86           0 :         if(aValue >>= uStyle)
      87             :         {
      88           0 :             OUString sStyle;
      89           0 :             SwStyleNameMapper::FillUIName(uStyle, sStyle, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, true );
      90             :             SwDocStyleSheet* pStyle =
      91           0 :                 (SwDocStyleSheet*)m_pDoc->GetDocShell()->GetStyleSheetPool()->Find(sStyle, SFX_STYLE_FAMILY_CHAR);
      92           0 :             SwFmtDrop* pDrop = 0;
      93           0 :             SwFmtCharFmt *pCharFmt = 0;
      94           0 :             if(pStyle)
      95             :             {
      96           0 :                 rtl::Reference< SwDocStyleSheet > xStyle( new SwDocStyleSheet( *(SwDocStyleSheet*)pStyle ) );
      97           0 :                 if (RES_PARATR_DROP == pMap->nWID)
      98             :                 {
      99           0 :                     pDrop = (SwFmtDrop*)rItem.Clone();   // because rItem is const...
     100           0 :                     pDrop->SetCharFmt(xStyle->GetCharFmt());
     101           0 :                     m_pDoc->SetDefault(*pDrop);
     102             :                 }
     103             :                 else // RES_TXTATR_CHARFMT == pMap->nWID
     104             :                 {
     105           0 :                     pCharFmt = (SwFmtCharFmt*)rItem.Clone();   // because rItem is const...
     106           0 :                     pCharFmt->SetCharFmt(xStyle->GetCharFmt());
     107           0 :                     m_pDoc->SetDefault(*pCharFmt);
     108           0 :                 }
     109             :             }
     110             :             else
     111           0 :                 throw lang::IllegalArgumentException();
     112           0 :             delete pDrop;
     113           0 :             delete pCharFmt;
     114             :         }
     115             :         else
     116           0 :             throw lang::IllegalArgumentException();
     117             :     }
     118             :     else
     119             :     {
     120       46308 :         SfxPoolItem * pNewItem = rItem.Clone();
     121       46308 :         pNewItem->PutValue( aValue, pMap->nMemberId);
     122       46308 :         m_pDoc->SetDefault(*pNewItem);
     123       46308 :         delete pNewItem;
     124       46308 :     }
     125       46308 : }
     126             : 
     127        2220 : Any SAL_CALL SwXTextDefaults::getPropertyValue( const OUString& rPropertyName )
     128             :         throw(UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
     129             : {
     130        2220 :     SolarMutexGuard aGuard;
     131        2220 :     if (!m_pDoc)
     132           0 :         throw RuntimeException();
     133        2220 :     const SfxItemPropertySimpleEntry *pMap = m_pPropSet->getPropertyMap().getByName( rPropertyName );
     134        2220 :     if (!pMap)
     135           0 :         throw UnknownPropertyException( "Unknown property: " + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
     136        2220 :     Any aRet;
     137        2220 :     const SfxPoolItem& rItem = m_pDoc->GetDefault(pMap->nWID);
     138        2220 :     rItem.QueryValue( aRet, pMap->nMemberId );
     139        2220 :     return aRet;
     140             : }
     141             : 
     142           0 : void SAL_CALL SwXTextDefaults::addPropertyChangeListener( const OUString& /*rPropertyName*/, const uno::Reference< XPropertyChangeListener >& /*xListener*/ )
     143             :         throw(UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
     144             : {
     145             :     OSL_FAIL ( "not implemented" );
     146           0 : }
     147             : 
     148           0 : void SAL_CALL SwXTextDefaults::removePropertyChangeListener( const OUString& /*rPropertyName*/, const uno::Reference< XPropertyChangeListener >& /*xListener*/ )
     149             :         throw(UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
     150             : {
     151             :     OSL_FAIL ( "not implemented" );
     152           0 : }
     153             : 
     154           0 : void SAL_CALL SwXTextDefaults::addVetoableChangeListener( const OUString& /*rPropertyName*/, const uno::Reference< XVetoableChangeListener >& /*xListener*/ )
     155             :         throw(UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
     156             : {
     157             :     OSL_FAIL ( "not implemented" );
     158           0 : }
     159             : 
     160           0 : void SAL_CALL SwXTextDefaults::removeVetoableChangeListener( const OUString& /*rPropertyName*/, const uno::Reference< XVetoableChangeListener >& /*xListener*/ )
     161             :         throw(UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
     162             : {
     163             :     OSL_FAIL ( "not implemented" );
     164           0 : }
     165             : 
     166             : // XPropertyState
     167        7800 : PropertyState SAL_CALL SwXTextDefaults::getPropertyState( const OUString& rPropertyName )
     168             :         throw(UnknownPropertyException, RuntimeException, std::exception)
     169             : {
     170        7800 :     SolarMutexGuard aGuard;
     171        7800 :     PropertyState eRet = PropertyState_DIRECT_VALUE;
     172        7800 :     if (!m_pDoc)
     173           0 :         throw RuntimeException();
     174        7800 :     const SfxItemPropertySimpleEntry *pMap = m_pPropSet->getPropertyMap().getByName( rPropertyName );
     175        7800 :     if (!pMap)
     176           0 :         throw UnknownPropertyException( "Unknown property: " + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
     177             : 
     178        7800 :     const SfxPoolItem& rItem = m_pDoc->GetDefault(pMap->nWID);
     179        7800 :     if (IsStaticDefaultItem ( &rItem ) )
     180        5776 :         eRet = PropertyState_DEFAULT_VALUE;
     181        7800 :     return eRet;
     182             : }
     183             : 
     184         240 : Sequence< PropertyState > SAL_CALL SwXTextDefaults::getPropertyStates( const Sequence< OUString >& rPropertyNames )
     185             :         throw(UnknownPropertyException, RuntimeException, std::exception)
     186             : {
     187         240 :     const sal_Int32 nCount = rPropertyNames.getLength();
     188         240 :     const OUString * pNames = rPropertyNames.getConstArray();
     189         240 :     Sequence < PropertyState > aRet ( nCount );
     190         240 :     PropertyState *pState = aRet.getArray();
     191             : 
     192        8040 :     for ( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++)
     193        7800 :         pState[nIndex] = getPropertyState( pNames[nIndex] );
     194             : 
     195         240 :     return aRet;
     196             : }
     197             : 
     198           0 : void SAL_CALL SwXTextDefaults::setPropertyToDefault( const OUString& rPropertyName )
     199             :         throw(UnknownPropertyException, RuntimeException, std::exception)
     200             : {
     201           0 :     if (!m_pDoc)
     202           0 :         throw RuntimeException();
     203           0 :     const SfxItemPropertySimpleEntry *pMap = m_pPropSet->getPropertyMap().getByName( rPropertyName );
     204           0 :     if (!pMap)
     205           0 :         throw UnknownPropertyException( "Unknown property: " + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
     206           0 :     if ( pMap->nFlags & PropertyAttribute::READONLY)
     207           0 :         throw RuntimeException( "setPropertyToDefault: property is read-only: " + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
     208           0 :     SfxItemPool& rSet (m_pDoc->GetAttrPool());
     209           0 :     rSet.ResetPoolDefaultItem ( pMap->nWID );
     210           0 : }
     211             : 
     212           0 : Any SAL_CALL SwXTextDefaults::getPropertyDefault( const OUString& rPropertyName )
     213             :         throw(UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
     214             : {
     215           0 :     if (!m_pDoc)
     216           0 :         throw RuntimeException();
     217           0 :     const SfxItemPropertySimpleEntry *pMap = m_pPropSet->getPropertyMap().getByName( rPropertyName );
     218           0 :     if (!pMap)
     219           0 :         throw UnknownPropertyException( "Unknown property: " + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
     220           0 :     Any aRet;
     221           0 :     SfxItemPool& rSet (m_pDoc->GetAttrPool());
     222           0 :     const SfxPoolItem *pItem = rSet.GetPoolDefaultItem ( pMap->nWID );
     223           0 :     pItem->QueryValue( aRet, pMap->nMemberId );
     224           0 :     return aRet;
     225             : }
     226             : 
     227           0 : OUString SAL_CALL SwXTextDefaults::getImplementationName(  )
     228             :     throw (RuntimeException, std::exception)
     229             : {
     230           0 :     return OUString("SwXTextDefaults");
     231             : }
     232             : 
     233           0 : sal_Bool SAL_CALL SwXTextDefaults::supportsService( const OUString& rServiceName )
     234             :     throw (RuntimeException, std::exception)
     235             : {
     236           0 :     return cppu::supportsService(this, rServiceName);
     237             : }
     238             : 
     239           0 : uno::Sequence< OUString > SAL_CALL SwXTextDefaults::getSupportedServiceNames(  )
     240             :     throw (RuntimeException, std::exception)
     241             : {
     242           0 :     uno::Sequence< OUString > aRet(7);
     243           0 :     OUString* pArr = aRet.getArray();
     244           0 :     *pArr++ = "com.sun.star.text.Defaults";
     245           0 :     *pArr++ = "com.sun.star.style.CharacterProperties";
     246           0 :     *pArr++ = "com.sun.star.style.CharacterPropertiesAsian";
     247           0 :     *pArr++ = "com.sun.star.style.CharacterPropertiesComplex";
     248           0 :     *pArr++ = "com.sun.star.style.ParagraphProperties";
     249           0 :     *pArr++ = "com.sun.star.style.ParagraphPropertiesAsian";
     250           0 :     *pArr++ = "com.sun.star.style.ParagraphPropertiesComplex";
     251           0 :     return aRet;
     252         270 : }
     253             : 
     254             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10