2010-10-14 08:30:41 +02:00
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2011-03-31 10:05:04 +02:00
/*
* This file is part of the LibreOffice project .
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License , v . 2.0 . If a copy of the MPL was not distributed with this
* file , You can obtain one at http : //mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice :
*
* Licensed to the Apache Software Foundation ( ASF ) under one or more
* contributor license agreements . See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership . The ASF licenses this file to you under the Apache
* License , Version 2.0 ( the " License " ) ; you may not use this file
* except in compliance with the License . You may obtain a copy of
* the License at http : //www.apache.org/licenses/LICENSE-2.0 .
*/
2006-09-16 20:54:36 +00:00
2010-01-08 17:13:54 +01:00
# include <com/sun/star/beans/PropertyAttribute.hpp>
2010-10-16 03:22:02 -05:00
# include <osl/mutex.hxx>
2002-10-16 07:56:04 +00:00
# include <vcl/svapp.hxx>
2012-06-25 18:18:43 +02:00
# include <comphelper/stlunosequence.hxx>
2010-01-08 17:13:54 +01:00
2001-03-21 13:51:13 +00:00
# include <SwXTextDefaults.hxx>
2002-10-16 07:56:04 +00:00
# include <SwStyleNameMapper.hxx>
2002-10-16 10:21:25 +00:00
# include <fchrfmt.hxx>
# include <charfmt.hxx>
2002-10-16 07:56:04 +00:00
# include <docstyle.hxx>
2006-08-14 15:52:45 +00:00
# include <doc.hxx>
2002-10-16 07:56:04 +00:00
# include <docsh.hxx>
2001-03-21 13:51:13 +00:00
# include <unomap.hxx>
2002-10-16 05:55:14 +00:00
# include <unomid.h>
2002-10-16 07:56:04 +00:00
# include <paratr.hxx>
2001-03-21 13:51:13 +00:00
# include <unoprnms.hxx>
2010-01-08 17:13:54 +01:00
# include <unocrsrhelper.hxx>
2001-03-21 13:51:13 +00:00
# include <hintids.hxx>
2007-09-27 08:33:54 +00:00
using namespace : : com : : sun : : star ;
using namespace : : com : : sun : : star : : uno ;
using namespace : : com : : sun : : star : : beans ;
using namespace : : com : : sun : : star : : lang ;
2011-03-02 22:32:49 +01:00
using rtl : : OUString ;
2001-03-21 13:51:13 +00:00
2002-08-15 13:54:39 +00:00
2007-09-27 08:33:54 +00:00
SwXTextDefaults : : SwXTextDefaults ( SwDoc * pNewDoc ) :
2009-06-03 11:26:39 +00:00
m_pPropSet ( aSwMapProvider . GetPropertySet ( PROPERTY_MAP_TEXT_DEFAULT ) ) ,
m_pDoc ( pNewDoc )
2001-03-21 13:51:13 +00:00
{
}
2002-08-15 13:54:39 +00:00
2001-03-21 13:51:13 +00:00
SwXTextDefaults : : ~ SwXTextDefaults ( )
{
}
2002-08-15 13:54:39 +00:00
2008-03-12 11:26:28 +00:00
uno : : Reference < XPropertySetInfo > SAL_CALL SwXTextDefaults : : getPropertySetInfo ( )
2001-03-21 13:51:13 +00:00
throw ( RuntimeException )
{
2009-06-03 11:26:39 +00:00
static uno : : Reference < XPropertySetInfo > xRef = m_pPropSet - > getPropertySetInfo ( ) ;
2001-03-21 13:51:13 +00:00
return xRef ;
}
2002-08-15 13:54:39 +00:00
2001-03-21 13:51:13 +00:00
void SAL_CALL SwXTextDefaults : : setPropertyValue ( const OUString & rPropertyName , const Any & aValue )
throw ( UnknownPropertyException , PropertyVetoException , IllegalArgumentException , WrappedTargetException , RuntimeException )
{
2010-10-13 01:44:10 -05:00
SolarMutexGuard aGuard ;
2009-06-03 11:26:39 +00:00
if ( ! m_pDoc )
2001-03-21 13:51:13 +00:00
throw RuntimeException ( ) ;
2012-01-05 21:30:06 +00:00
const SfxItemPropertySimpleEntry * pMap = m_pPropSet - > getPropertyMap ( ) . getByName ( rPropertyName ) ;
2001-03-21 13:51:13 +00:00
if ( ! pMap )
2001-11-28 19:01:17 +00:00
throw UnknownPropertyException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( " Unknown property: " ) ) + rPropertyName , static_cast < cppu : : OWeakObject * > ( this ) ) ;
2001-03-21 13:51:13 +00:00
if ( pMap - > nFlags & PropertyAttribute : : READONLY )
2002-08-14 09:10:46 +00:00
throw PropertyVetoException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( " Property is read-only: " ) ) + rPropertyName , static_cast < cppu : : OWeakObject * > ( this ) ) ;
2002-10-16 05:55:14 +00:00
2009-06-03 11:26:39 +00:00
const SfxPoolItem & rItem = m_pDoc - > GetDefault ( pMap - > nWID ) ;
2002-10-16 05:55:14 +00:00
if ( RES_PAGEDESC = = pMap - > nWID & & MID_PAGEDESC_PAGEDESCNAME = = pMap - > nMemberId )
{
2009-06-03 11:26:39 +00:00
SfxItemSet aSet ( m_pDoc - > GetAttrPool ( ) , RES_PAGEDESC , RES_PAGEDESC ) ;
2002-10-16 05:55:14 +00:00
aSet . Put ( rItem ) ;
2010-01-08 17:13:54 +01:00
SwUnoCursorHelper : : SetPageDesc ( aValue , * m_pDoc , aSet ) ;
2009-06-03 11:26:39 +00:00
m_pDoc - > SetDefault ( aSet . Get ( RES_PAGEDESC ) ) ;
2002-10-16 05:55:14 +00:00
}
2002-10-16 10:21:25 +00:00
else if ( ( RES_PARATR_DROP = = pMap - > nWID & & MID_DROPCAP_CHAR_STYLE_NAME = = pMap - > nMemberId ) | |
( RES_TXTATR_CHARFMT = = pMap - > nWID ) )
2002-10-16 07:56:04 +00:00
{
OUString uStyle ;
if ( aValue > > = uStyle )
{
String sStyle ;
2012-10-10 07:34:19 +09:00
SwStyleNameMapper : : FillUIName ( uStyle , sStyle , nsSwGetPoolIdFromName : : GET_POOLID_CHRFMT , true ) ;
2002-10-16 07:56:04 +00:00
SwDocStyleSheet * pStyle =
2009-06-03 11:26:39 +00:00
( SwDocStyleSheet * ) m_pDoc - > GetDocShell ( ) - > GetStyleSheetPool ( ) - > Find ( sStyle , SFX_STYLE_FAMILY_CHAR ) ;
2002-10-16 07:56:04 +00:00
SwFmtDrop * pDrop = 0 ;
2002-10-16 10:21:25 +00:00
SwFmtCharFmt * pCharFmt = 0 ;
2002-10-16 07:56:04 +00:00
if ( pStyle )
{
2008-03-12 11:26:28 +00:00
rtl : : Reference < SwDocStyleSheet > xStyle ( new SwDocStyleSheet ( * ( SwDocStyleSheet * ) pStyle ) ) ;
2002-10-16 10:21:25 +00:00
if ( RES_PARATR_DROP = = pMap - > nWID )
{
pDrop = ( SwFmtDrop * ) rItem . Clone ( ) ; // because rItem ist const...
2008-03-12 11:26:28 +00:00
pDrop - > SetCharFmt ( xStyle - > GetCharFmt ( ) ) ;
2009-06-03 11:26:39 +00:00
m_pDoc - > SetDefault ( * pDrop ) ;
2002-10-16 10:21:25 +00:00
}
else // RES_TXTATR_CHARFMT == pMap->nWID
{
pCharFmt = ( SwFmtCharFmt * ) rItem . Clone ( ) ; // because rItem ist const...
2008-03-12 11:26:28 +00:00
pCharFmt - > SetCharFmt ( xStyle - > GetCharFmt ( ) ) ;
2009-06-03 11:26:39 +00:00
m_pDoc - > SetDefault ( * pCharFmt ) ;
2002-10-16 10:21:25 +00:00
}
2002-10-16 07:56:04 +00:00
}
else
throw lang : : IllegalArgumentException ( ) ;
delete pDrop ;
2002-10-16 10:21:25 +00:00
delete pCharFmt ;
2002-10-16 07:56:04 +00:00
}
else
throw lang : : IllegalArgumentException ( ) ;
}
2002-10-16 05:55:14 +00:00
else
{
SfxPoolItem * pNewItem = rItem . Clone ( ) ;
pNewItem - > PutValue ( aValue , pMap - > nMemberId ) ;
2009-06-03 11:26:39 +00:00
m_pDoc - > SetDefault ( * pNewItem ) ;
2002-10-16 05:55:14 +00:00
delete pNewItem ;
}
2001-03-21 13:51:13 +00:00
}
2002-08-15 13:54:39 +00:00
2001-03-21 13:51:13 +00:00
Any SAL_CALL SwXTextDefaults : : getPropertyValue ( const OUString & rPropertyName )
throw ( UnknownPropertyException , WrappedTargetException , RuntimeException )
{
2010-10-13 01:44:10 -05:00
SolarMutexGuard aGuard ;
2009-06-03 11:26:39 +00:00
if ( ! m_pDoc )
2001-03-21 13:51:13 +00:00
throw RuntimeException ( ) ;
2012-01-05 21:30:06 +00:00
const SfxItemPropertySimpleEntry * pMap = m_pPropSet - > getPropertyMap ( ) . getByName ( rPropertyName ) ;
2001-03-21 13:51:13 +00:00
if ( ! pMap )
2001-11-28 19:01:17 +00:00
throw UnknownPropertyException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( " Unknown property: " ) ) + rPropertyName , static_cast < cppu : : OWeakObject * > ( this ) ) ;
2001-03-21 13:51:13 +00:00
Any aRet ;
2009-06-03 11:26:39 +00:00
const SfxPoolItem & rItem = m_pDoc - > GetDefault ( pMap - > nWID ) ;
2001-06-07 13:54:02 +00:00
rItem . QueryValue ( aRet , pMap - > nMemberId ) ;
2001-03-21 13:51:13 +00:00
return aRet ;
}
2002-08-15 13:54:39 +00:00
2008-03-12 11:26:28 +00:00
void SAL_CALL SwXTextDefaults : : addPropertyChangeListener ( const OUString & /*rPropertyName*/ , const uno : : Reference < XPropertyChangeListener > & /*xListener*/ )
2001-03-21 13:51:13 +00:00
throw ( UnknownPropertyException , WrappedTargetException , RuntimeException )
{
2011-05-08 22:14:45 +02:00
OSL_FAIL ( " not implemented " ) ;
2001-03-21 13:51:13 +00:00
}
2002-08-15 13:54:39 +00:00
2008-03-12 11:26:28 +00:00
void SAL_CALL SwXTextDefaults : : removePropertyChangeListener ( const OUString & /*rPropertyName*/ , const uno : : Reference < XPropertyChangeListener > & /*xListener*/ )
2001-03-21 13:51:13 +00:00
throw ( UnknownPropertyException , WrappedTargetException , RuntimeException )
{
2011-05-08 22:14:45 +02:00
OSL_FAIL ( " not implemented " ) ;
2001-03-21 13:51:13 +00:00
}
2002-08-15 13:54:39 +00:00
2008-03-12 11:26:28 +00:00
void SAL_CALL SwXTextDefaults : : addVetoableChangeListener ( const OUString & /*rPropertyName*/ , const uno : : Reference < XVetoableChangeListener > & /*xListener*/ )
2001-03-21 13:51:13 +00:00
throw ( UnknownPropertyException , WrappedTargetException , RuntimeException )
{
2011-05-08 22:14:45 +02:00
OSL_FAIL ( " not implemented " ) ;
2001-03-21 13:51:13 +00:00
}
2002-08-15 13:54:39 +00:00
2008-03-12 11:26:28 +00:00
void SAL_CALL SwXTextDefaults : : removeVetoableChangeListener ( const OUString & /*rPropertyName*/ , const uno : : Reference < XVetoableChangeListener > & /*xListener*/ )
2001-03-21 13:51:13 +00:00
throw ( UnknownPropertyException , WrappedTargetException , RuntimeException )
{
2011-05-08 22:14:45 +02:00
OSL_FAIL ( " not implemented " ) ;
2001-03-21 13:51:13 +00:00
}
2002-08-15 13:54:39 +00:00
// XPropertyState
2001-03-21 13:51:13 +00:00
PropertyState SAL_CALL SwXTextDefaults : : getPropertyState ( const OUString & rPropertyName )
throw ( UnknownPropertyException , RuntimeException )
{
2010-10-13 01:44:10 -05:00
SolarMutexGuard aGuard ;
2001-03-21 13:51:13 +00:00
PropertyState eRet = PropertyState_DIRECT_VALUE ;
2009-06-03 11:26:39 +00:00
if ( ! m_pDoc )
2001-03-21 13:51:13 +00:00
throw RuntimeException ( ) ;
2012-01-05 21:30:06 +00:00
const SfxItemPropertySimpleEntry * pMap = m_pPropSet - > getPropertyMap ( ) . getByName ( rPropertyName ) ;
2001-03-21 13:51:13 +00:00
if ( ! pMap )
2001-11-28 19:01:17 +00:00
throw UnknownPropertyException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( " Unknown property: " ) ) + rPropertyName , static_cast < cppu : : OWeakObject * > ( this ) ) ;
2001-06-07 13:54:02 +00:00
2009-06-03 11:26:39 +00:00
const SfxPoolItem & rItem = m_pDoc - > GetDefault ( pMap - > nWID ) ;
2001-06-07 13:54:02 +00:00
if ( IsStaticDefaultItem ( & rItem ) )
eRet = PropertyState_DEFAULT_VALUE ;
2001-03-21 13:51:13 +00:00
return eRet ;
}
2002-08-15 13:54:39 +00:00
2001-03-21 13:51:13 +00:00
Sequence < PropertyState > SAL_CALL SwXTextDefaults : : getPropertyStates ( const Sequence < OUString > & rPropertyNames )
throw ( UnknownPropertyException , RuntimeException )
{
const sal_Int32 nCount = rPropertyNames . getLength ( ) ;
const OUString * pNames = rPropertyNames . getConstArray ( ) ;
Sequence < PropertyState > aRet ( nCount ) ;
PropertyState * pState = aRet . getArray ( ) ;
for ( sal_Int32 nIndex = 0 ; nIndex < nCount ; nIndex + + )
pState [ nIndex ] = getPropertyState ( pNames [ nIndex ] ) ;
return aRet ;
}
2002-08-15 13:54:39 +00:00
2001-03-21 13:51:13 +00:00
void SAL_CALL SwXTextDefaults : : setPropertyToDefault ( const OUString & rPropertyName )
throw ( UnknownPropertyException , RuntimeException )
{
2009-06-03 11:26:39 +00:00
if ( ! m_pDoc )
2001-03-21 13:51:13 +00:00
throw RuntimeException ( ) ;
2012-01-05 21:30:06 +00:00
const SfxItemPropertySimpleEntry * pMap = m_pPropSet - > getPropertyMap ( ) . getByName ( rPropertyName ) ;
2001-03-21 13:51:13 +00:00
if ( ! pMap )
2001-11-28 19:01:17 +00:00
throw UnknownPropertyException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( " Unknown property: " ) ) + rPropertyName , static_cast < cppu : : OWeakObject * > ( this ) ) ;
2001-03-21 13:51:13 +00:00
if ( pMap - > nFlags & PropertyAttribute : : READONLY )
2004-08-11 14:41:27 +00:00
throw RuntimeException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( " setPropertyToDefault: property is read-only: " ) ) + rPropertyName , static_cast < cppu : : OWeakObject * > ( this ) ) ;
2009-06-03 11:26:39 +00:00
SfxItemPool & rSet ( m_pDoc - > GetAttrPool ( ) ) ;
2004-08-11 14:41:27 +00:00
rSet . ResetPoolDefaultItem ( pMap - > nWID ) ;
2001-03-21 13:51:13 +00:00
}
2002-08-15 13:54:39 +00:00
2001-03-21 13:51:13 +00:00
Any SAL_CALL SwXTextDefaults : : getPropertyDefault ( const OUString & rPropertyName )
throw ( UnknownPropertyException , WrappedTargetException , RuntimeException )
{
2009-06-03 11:26:39 +00:00
if ( ! m_pDoc )
2001-03-21 13:51:13 +00:00
throw RuntimeException ( ) ;
2012-01-05 21:30:06 +00:00
const SfxItemPropertySimpleEntry * pMap = m_pPropSet - > getPropertyMap ( ) . getByName ( rPropertyName ) ;
2001-03-21 13:51:13 +00:00
if ( ! pMap )
2001-11-28 19:01:17 +00:00
throw UnknownPropertyException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( " Unknown property: " ) ) + rPropertyName , static_cast < cppu : : OWeakObject * > ( this ) ) ;
2001-03-21 13:51:13 +00:00
Any aRet ;
2009-06-03 11:26:39 +00:00
SfxItemPool & rSet ( m_pDoc - > GetAttrPool ( ) ) ;
2001-03-21 13:51:13 +00:00
const SfxPoolItem * pItem = rSet . GetPoolDefaultItem ( pMap - > nWID ) ;
pItem - > QueryValue ( aRet , pMap - > nMemberId ) ;
return aRet ;
}
2002-08-15 13:54:39 +00:00
rtl : : OUString SAL_CALL SwXTextDefaults : : getImplementationName ( )
throw ( RuntimeException )
{
2012-06-23 15:03:59 +02:00
return OUString ( " SwXTextDefaults " ) ;
2002-08-15 13:54:39 +00:00
}
sal_Bool SAL_CALL SwXTextDefaults : : supportsService ( const : : rtl : : OUString & rServiceName )
throw ( RuntimeException )
{
2012-06-25 18:18:43 +02:00
uno : : Sequence < : : rtl : : OUString > aSeq ( getSupportedServiceNames ( ) ) ;
return std : : find ( comphelper : : stl_begin ( aSeq ) , comphelper : : stl_end ( aSeq ) , rServiceName ) ! = comphelper : : stl_end ( aSeq ) ;
2002-08-15 13:54:39 +00:00
}
uno : : Sequence < : : rtl : : OUString > SAL_CALL SwXTextDefaults : : getSupportedServiceNames ( )
throw ( RuntimeException )
{
2002-09-26 06:18:30 +00:00
uno : : Sequence < OUString > aRet ( 7 ) ;
2002-08-15 13:54:39 +00:00
OUString * pArr = aRet . getArray ( ) ;
2012-06-23 15:03:59 +02:00
* pArr + + = " com.sun.star.text.Defaults " ;
* pArr + + = " com.sun.star.style.CharacterProperties " ;
* pArr + + = " com.sun.star.style.CharacterPropertiesAsian " ;
* pArr + + = " com.sun.star.style.CharacterPropertiesComplex " ;
* pArr + + = " com.sun.star.style.ParagraphProperties " ;
* pArr + + = " com.sun.star.style.ParagraphPropertiesAsian " ;
* pArr + + = " com.sun.star.style.ParagraphPropertiesComplex " ;
2002-08-15 13:54:39 +00:00
return aRet ;
}
2010-10-14 08:30:41 +02:00
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */