LCOV - code coverage report
Current view: top level - sw/source/core/unocore - SwXTextDefaults.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 53 130 40.8 %
Date: 2015-06-13 12:38:46 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        4640 : SwXTextDefaults::SwXTextDefaults ( SwDoc * pNewDoc ) :
      46        4640 :     m_pPropSet( aSwMapProvider.GetPropertySet( PROPERTY_MAP_TEXT_DEFAULT ) ),
      47        9280 :     m_pDoc   ( pNewDoc )
      48             : {
      49        4640 : }
      50             : 
      51        9280 : SwXTextDefaults::~SwXTextDefaults ()
      52             : {
      53        9280 : }
      54             : 
      55        1562 : uno::Reference< XPropertySetInfo > SAL_CALL SwXTextDefaults::getPropertySetInfo(  )
      56             :         throw(RuntimeException, std::exception)
      57             : {
      58        1562 :     static uno::Reference < XPropertySetInfo > xRef = m_pPropSet->getPropertySetInfo();
      59        1562 :     return xRef;
      60             : }
      61             : 
      62       29192 : void SAL_CALL SwXTextDefaults::setPropertyValue( const OUString& rPropertyName, const Any& aValue )
      63             :         throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException, std::exception)
      64             : {
      65       29192 :     SolarMutexGuard aGuard;
      66       29192 :     if (!m_pDoc)
      67           0 :         throw RuntimeException();
      68       29192 :     const SfxItemPropertySimpleEntry *pMap = m_pPropSet->getPropertyMap().getByName( rPropertyName );
      69       29192 :     if (!pMap)
      70           0 :         throw UnknownPropertyException( "Unknown property: " + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
      71       29192 :     if ( pMap->nFlags & PropertyAttribute::READONLY)
      72           0 :         throw PropertyVetoException ( "Property is read-only: " + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
      73             : 
      74       29192 :     const SfxPoolItem& rItem = m_pDoc->GetDefault(pMap->nWID);
      75       29192 :     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       58384 :     else if ((RES_PARATR_DROP == pMap->nWID && MID_DROPCAP_CHAR_STYLE_NAME == pMap->nMemberId) ||
      83       29192 :              (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 :                 static_cast<SwDocStyleSheet*>(m_pDoc->GetDocShell()->GetStyleSheetPool()->Find(sStyle, SFX_STYLE_FAMILY_CHAR));
      92           0 :             SwFormatDrop* pDrop = 0;
      93           0 :             SwFormatCharFormat *pCharFormat = 0;
      94           0 :             if(pStyle)
      95             :             {
      96           0 :                 rtl::Reference< SwDocStyleSheet > xStyle( new SwDocStyleSheet( *pStyle ) );
      97           0 :                 if (RES_PARATR_DROP == pMap->nWID)
      98             :                 {
      99           0 :                     pDrop = static_cast<SwFormatDrop*>(rItem.Clone());   // because rItem is const...
     100           0 :                     pDrop->SetCharFormat(xStyle->GetCharFormat());
     101           0 :                     m_pDoc->SetDefault(*pDrop);
     102             :                 }
     103             :                 else // RES_TXTATR_CHARFMT == pMap->nWID
     104             :                 {
     105           0 :                     pCharFormat = static_cast<SwFormatCharFormat*>(rItem.Clone());   // because rItem is const...
     106           0 :                     pCharFormat->SetCharFormat(xStyle->GetCharFormat());
     107           0 :                     m_pDoc->SetDefault(*pCharFormat);
     108           0 :                 }
     109             :             }
     110             :             else
     111           0 :                 throw lang::IllegalArgumentException();
     112           0 :             delete pDrop;
     113           0 :             delete pCharFormat;
     114             :         }
     115             :         else
     116           0 :             throw lang::IllegalArgumentException();
     117             :     }
     118             :     else
     119             :     {
     120       29192 :         SfxPoolItem * pNewItem = rItem.Clone();
     121       29192 :         pNewItem->PutValue( aValue, pMap->nMemberId);
     122       29192 :         m_pDoc->SetDefault(*pNewItem);
     123       29192 :         delete pNewItem;
     124       29192 :     }
     125       29192 : }
     126             : 
     127        2634 : Any SAL_CALL SwXTextDefaults::getPropertyValue( const OUString& rPropertyName )
     128             :         throw(UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
     129             : {
     130        2634 :     SolarMutexGuard aGuard;
     131        2634 :     if (!m_pDoc)
     132           0 :         throw RuntimeException();
     133        2634 :     const SfxItemPropertySimpleEntry *pMap = m_pPropSet->getPropertyMap().getByName( rPropertyName );
     134        2634 :     if (!pMap)
     135           0 :         throw UnknownPropertyException( "Unknown property: " + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
     136        2634 :     Any aRet;
     137        2634 :     const SfxPoolItem& rItem = m_pDoc->GetDefault(pMap->nWID);
     138        2634 :     rItem.QueryValue( aRet, pMap->nMemberId );
     139        2634 :     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        9563 : PropertyState SAL_CALL SwXTextDefaults::getPropertyState( const OUString& rPropertyName )
     168             :         throw(UnknownPropertyException, RuntimeException, std::exception)
     169             : {
     170        9563 :     SolarMutexGuard aGuard;
     171        9563 :     PropertyState eRet = PropertyState_DIRECT_VALUE;
     172        9563 :     if (!m_pDoc)
     173           0 :         throw RuntimeException();
     174        9563 :     const SfxItemPropertySimpleEntry *pMap = m_pPropSet->getPropertyMap().getByName( rPropertyName );
     175        9563 :     if (!pMap)
     176           0 :         throw UnknownPropertyException( "Unknown property: " + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
     177             : 
     178        9563 :     const SfxPoolItem& rItem = m_pDoc->GetDefault(pMap->nWID);
     179        9563 :     if (IsStaticDefaultItem ( &rItem ) )
     180        7199 :         eRet = PropertyState_DEFAULT_VALUE;
     181        9563 :     return eRet;
     182             : }
     183             : 
     184         292 : Sequence< PropertyState > SAL_CALL SwXTextDefaults::getPropertyStates( const Sequence< OUString >& rPropertyNames )
     185             :         throw(UnknownPropertyException, RuntimeException, std::exception)
     186             : {
     187         292 :     const sal_Int32 nCount = rPropertyNames.getLength();
     188         292 :     const OUString * pNames = rPropertyNames.getConstArray();
     189         292 :     Sequence < PropertyState > aRet ( nCount );
     190         292 :     PropertyState *pState = aRet.getArray();
     191             : 
     192        9855 :     for ( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++)
     193        9563 :         pState[nIndex] = getPropertyState( pNames[nIndex] );
     194             : 
     195         292 :     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         177 : }
     253             : 
     254             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11