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

Generated by: LCOV version 1.10