2001-03-21 13:51:13 +00:00
/*************************************************************************
*
2008-04-10 15:11:03 +00:00
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER .
2001-03-21 13:51:13 +00:00
*
2008-04-10 15:11:03 +00:00
* Copyright 2008 by Sun Microsystems , Inc .
2001-03-21 13:51:13 +00:00
*
2008-04-10 15:11:03 +00:00
* OpenOffice . org - a multi - platform office productivity suite
2001-03-21 13:51:13 +00:00
*
2008-04-10 15:11:03 +00:00
* $ RCSfile : SwXTextDefaults . cxx , v $
* $ Revision : 1.22 $
2001-03-21 13:51:13 +00:00
*
2008-04-10 15:11:03 +00:00
* This file is part of OpenOffice . org .
2001-03-21 13:51:13 +00:00
*
2008-04-10 15:11:03 +00:00
* OpenOffice . org is free software : you can redistribute it and / or modify
* it under the terms of the GNU Lesser General Public License version 3
* only , as published by the Free Software Foundation .
2001-03-21 13:51:13 +00:00
*
2008-04-10 15:11:03 +00:00
* OpenOffice . org is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU Lesser General Public License version 3 for more details
* ( a copy is included in the LICENSE file that accompanied this code ) .
2001-03-21 13:51:13 +00:00
*
2008-04-10 15:11:03 +00:00
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice . org . If not , see
* < http : //www.openoffice.org/license.html>
* for a copy of the LGPLv3 License .
2001-03-21 13:51:13 +00:00
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2006-09-16 20:54:36 +00:00
// MARKER(update_precomp.py): autogen include statement, do not remove
# include "precompiled_sw.hxx"
2002-10-16 07:56:04 +00:00
# include <vos/mutex.hxx>
# include <vcl/svapp.hxx>
# include <com/sun/star/beans/PropertyAttribute.hpp>
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>
# include <hintids.hxx>
2007-09-27 08:33:54 +00:00
# include <unomid.h>
2001-03-21 13:51:13 +00:00
2008-03-12 11:26:28 +00:00
using rtl : : OUString ;
2001-03-21 13:51:13 +00:00
using namespace rtl ;
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 ;
2001-03-21 13:51:13 +00:00
2002-10-16 05:55:14 +00:00
// declarations
void lcl_setPageDesc ( SwDoc * , const uno : : Any & , SfxItemSet & ) ; // from unoobj.cxx
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 )
{
vos : : OGuard aGuard ( Application : : GetSolarMutex ( ) ) ;
2009-06-03 11:26:39 +00:00
if ( ! m_pDoc )
2001-03-21 13:51:13 +00:00
throw RuntimeException ( ) ;
2009-06-03 11:26:39 +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 ) ;
2009-06-03 11:26:39 +00:00
lcl_setPageDesc ( m_pDoc , aValue , aSet ) ;
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 ;
2007-09-27 08:33:54 +00:00
SwStyleNameMapper : : FillUIName ( uStyle , sStyle , nsSwGetPoolIdFromName : : GET_POOLID_CHRFMT , sal_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 )
{
vos : : OGuard aGuard ( Application : : GetSolarMutex ( ) ) ;
2009-06-03 11:26:39 +00:00
if ( ! m_pDoc )
2001-03-21 13:51:13 +00:00
throw RuntimeException ( ) ;
2009-06-03 11:26:39 +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 )
{
DBG_WARNING ( " not implemented " ) ;
}
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 )
{
DBG_WARNING ( " not implemented " ) ;
}
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 )
{
DBG_WARNING ( " not implemented " ) ;
}
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 )
{
DBG_WARNING ( " not implemented " ) ;
}
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 )
{
vos : : OGuard aGuard ( Application : : GetSolarMutex ( ) ) ;
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 ( ) ;
2009-06-03 11:26:39 +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 ( ) ;
2009-06-03 11:26:39 +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 ( ) ;
2009-06-03 11:26:39 +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 )
{
return C2U ( " SwXTextDefaults " ) ;
}
sal_Bool SAL_CALL SwXTextDefaults : : supportsService ( const : : rtl : : OUString & rServiceName )
throw ( RuntimeException )
{
return rServiceName = = C2U ( " com.sun.star.text.Defaults " ) | |
rServiceName = = C2U ( " com.sun.star.style.CharacterProperties " ) | |
rServiceName = = C2U ( " com.sun.star.style.CharacterPropertiesAsian " ) | |
rServiceName = = C2U ( " com.sun.star.style.CharacterPropertiesComplex " ) | |
rServiceName = = C2U ( " com.sun.star.style.ParagraphProperties " ) | |
2002-09-26 06:18:30 +00:00
rServiceName = = C2U ( " com.sun.star.style.ParagraphPropertiesAsian " ) | |
2002-08-15 13:54:39 +00:00
rServiceName = = C2U ( " com.sun.star.style.ParagraphPropertiesComplex " ) ;
}
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 ( ) ;
* pArr + + = C2U ( " com.sun.star.text.Defaults " ) ;
* pArr + + = C2U ( " com.sun.star.style.CharacterProperties " ) ;
* pArr + + = C2U ( " com.sun.star.style.CharacterPropertiesAsian " ) ;
* pArr + + = C2U ( " com.sun.star.style.CharacterPropertiesComplex " ) ;
* pArr + + = C2U ( " com.sun.star.style.ParagraphProperties " ) ;
2002-09-26 06:18:30 +00:00
* pArr + + = C2U ( " com.sun.star.style.ParagraphPropertiesAsian " ) ;
* pArr + + = C2U ( " com.sun.star.style.ParagraphPropertiesComplex " ) ;
2002-08-15 13:54:39 +00:00
return aRet ;
}