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

Generated by: LCOV version 1.10