update dev300-m58
[ooovba.git] / sw / source / core / unocore / SwXTextDefaults.cxx
blob22181294430da834fbdd688969c9c3a999da4d91
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SwXTextDefaults.cxx,v $
10 * $Revision: 1.22 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
33 #include <vos/mutex.hxx>
34 #include <vcl/svapp.hxx>
35 #include <com/sun/star/beans/PropertyAttribute.hpp>
36 #include <SwXTextDefaults.hxx>
37 #include <SwStyleNameMapper.hxx>
38 #include <fchrfmt.hxx>
39 #include <charfmt.hxx>
40 #include <docstyle.hxx>
41 #include <doc.hxx>
42 #include <docsh.hxx>
43 #include <unomap.hxx>
44 #include <unomid.h>
45 #include <paratr.hxx>
46 #include <unoprnms.hxx>
47 #include <hintids.hxx>
49 #include <unomid.h>
52 using rtl::OUString;
53 using namespace rtl;
54 using namespace ::com::sun::star;
55 using namespace ::com::sun::star::uno;
56 using namespace ::com::sun::star::beans;
57 using namespace ::com::sun::star::lang;
59 // declarations
60 void lcl_setPageDesc(SwDoc*, const uno::Any&, SfxItemSet& ); // from unoobj.cxx
63 SwXTextDefaults::SwXTextDefaults ( SwDoc * pNewDoc ) :
64 m_pPropSet( aSwMapProvider.GetPropertySet( PROPERTY_MAP_TEXT_DEFAULT ) ),
65 m_pDoc ( pNewDoc )
70 SwXTextDefaults::~SwXTextDefaults ()
75 uno::Reference< XPropertySetInfo > SAL_CALL SwXTextDefaults::getPropertySetInfo( )
76 throw(RuntimeException)
78 static uno::Reference < XPropertySetInfo > xRef = m_pPropSet->getPropertySetInfo();
79 return xRef;
83 void SAL_CALL SwXTextDefaults::setPropertyValue( const OUString& rPropertyName, const Any& aValue )
84 throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
86 vos::OGuard aGuard( Application::GetSolarMutex());
87 if (!m_pDoc)
88 throw RuntimeException();
89 const SfxItemPropertySimpleEntry *pMap = m_pPropSet->getPropertyMap()->getByName( rPropertyName );
90 if (!pMap)
91 throw UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
92 if ( pMap->nFlags & PropertyAttribute::READONLY)
93 throw PropertyVetoException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Property is read-only: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
95 const SfxPoolItem& rItem = m_pDoc->GetDefault(pMap->nWID);
96 if (RES_PAGEDESC == pMap->nWID && MID_PAGEDESC_PAGEDESCNAME == pMap->nMemberId)
98 SfxItemSet aSet( m_pDoc->GetAttrPool(), RES_PAGEDESC, RES_PAGEDESC );
99 aSet.Put(rItem);
100 lcl_setPageDesc( m_pDoc, aValue, aSet );
101 m_pDoc->SetDefault(aSet.Get(RES_PAGEDESC));
103 else if ((RES_PARATR_DROP == pMap->nWID && MID_DROPCAP_CHAR_STYLE_NAME == pMap->nMemberId) ||
104 (RES_TXTATR_CHARFMT == pMap->nWID))
106 OUString uStyle;
107 if(aValue >>= uStyle)
109 String sStyle;
110 SwStyleNameMapper::FillUIName(uStyle, sStyle, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, sal_True );
111 SwDocStyleSheet* pStyle =
112 (SwDocStyleSheet*)m_pDoc->GetDocShell()->GetStyleSheetPool()->Find(sStyle, SFX_STYLE_FAMILY_CHAR);
113 SwFmtDrop* pDrop = 0;
114 SwFmtCharFmt *pCharFmt = 0;
115 if(pStyle)
117 rtl::Reference< SwDocStyleSheet > xStyle( new SwDocStyleSheet( *(SwDocStyleSheet*)pStyle ) );
118 if (RES_PARATR_DROP == pMap->nWID)
120 pDrop = (SwFmtDrop*)rItem.Clone(); // because rItem ist const...
121 pDrop->SetCharFmt(xStyle->GetCharFmt());
122 m_pDoc->SetDefault(*pDrop);
124 else // RES_TXTATR_CHARFMT == pMap->nWID
126 pCharFmt = (SwFmtCharFmt*)rItem.Clone(); // because rItem ist const...
127 pCharFmt->SetCharFmt(xStyle->GetCharFmt());
128 m_pDoc->SetDefault(*pCharFmt);
131 else
132 throw lang::IllegalArgumentException();
133 delete pDrop;
134 delete pCharFmt;
136 else
137 throw lang::IllegalArgumentException();
139 else
141 SfxPoolItem * pNewItem = rItem.Clone();
142 pNewItem->PutValue( aValue, pMap->nMemberId);
143 m_pDoc->SetDefault(*pNewItem);
144 delete pNewItem;
149 Any SAL_CALL SwXTextDefaults::getPropertyValue( const OUString& rPropertyName )
150 throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
152 vos::OGuard aGuard( Application::GetSolarMutex());
153 if (!m_pDoc)
154 throw RuntimeException();
155 const SfxItemPropertySimpleEntry *pMap = m_pPropSet->getPropertyMap()->getByName( rPropertyName );
156 if (!pMap)
157 throw UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
158 Any aRet;
159 const SfxPoolItem& rItem = m_pDoc->GetDefault(pMap->nWID);
160 rItem.QueryValue( aRet, pMap->nMemberId );
161 return aRet;
165 void SAL_CALL SwXTextDefaults::addPropertyChangeListener( const OUString& /*rPropertyName*/, const uno::Reference< XPropertyChangeListener >& /*xListener*/ )
166 throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
168 DBG_WARNING ( "not implemented" );
172 void SAL_CALL SwXTextDefaults::removePropertyChangeListener( const OUString& /*rPropertyName*/, const uno::Reference< XPropertyChangeListener >& /*xListener*/ )
173 throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
175 DBG_WARNING ( "not implemented" );
179 void SAL_CALL SwXTextDefaults::addVetoableChangeListener( const OUString& /*rPropertyName*/, const uno::Reference< XVetoableChangeListener >& /*xListener*/ )
180 throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
182 DBG_WARNING ( "not implemented" );
186 void SAL_CALL SwXTextDefaults::removeVetoableChangeListener( const OUString& /*rPropertyName*/, const uno::Reference< XVetoableChangeListener >& /*xListener*/ )
187 throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
189 DBG_WARNING ( "not implemented" );
193 // XPropertyState
194 PropertyState SAL_CALL SwXTextDefaults::getPropertyState( const OUString& rPropertyName )
195 throw(UnknownPropertyException, RuntimeException)
197 vos::OGuard aGuard( Application::GetSolarMutex());
198 PropertyState eRet = PropertyState_DIRECT_VALUE;
199 if (!m_pDoc)
200 throw RuntimeException();
201 const SfxItemPropertySimpleEntry *pMap = m_pPropSet->getPropertyMap()->getByName( rPropertyName );
202 if (!pMap)
203 throw UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
205 const SfxPoolItem& rItem = m_pDoc->GetDefault(pMap->nWID);
206 if (IsStaticDefaultItem ( &rItem ) )
207 eRet = PropertyState_DEFAULT_VALUE;
208 return eRet;
212 Sequence< PropertyState > SAL_CALL SwXTextDefaults::getPropertyStates( const Sequence< OUString >& rPropertyNames )
213 throw(UnknownPropertyException, RuntimeException)
215 const sal_Int32 nCount = rPropertyNames.getLength();
216 const OUString * pNames = rPropertyNames.getConstArray();
217 Sequence < PropertyState > aRet ( nCount );
218 PropertyState *pState = aRet.getArray();
220 for ( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++)
221 pState[nIndex] = getPropertyState( pNames[nIndex] );
223 return aRet;
227 void SAL_CALL SwXTextDefaults::setPropertyToDefault( const OUString& rPropertyName )
228 throw(UnknownPropertyException, RuntimeException)
230 if (!m_pDoc)
231 throw RuntimeException();
232 const SfxItemPropertySimpleEntry *pMap = m_pPropSet->getPropertyMap()->getByName( rPropertyName );
233 if (!pMap)
234 throw UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
235 if ( pMap->nFlags & PropertyAttribute::READONLY)
236 throw RuntimeException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "setPropertyToDefault: property is read-only: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
237 SfxItemPool& rSet (m_pDoc->GetAttrPool());
238 rSet.ResetPoolDefaultItem ( pMap->nWID );
242 Any SAL_CALL SwXTextDefaults::getPropertyDefault( const OUString& rPropertyName )
243 throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
245 if (!m_pDoc)
246 throw RuntimeException();
247 const SfxItemPropertySimpleEntry *pMap = m_pPropSet->getPropertyMap()->getByName( rPropertyName );
248 if (!pMap)
249 throw UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
250 Any aRet;
251 SfxItemPool& rSet (m_pDoc->GetAttrPool());
252 const SfxPoolItem *pItem = rSet.GetPoolDefaultItem ( pMap->nWID );
253 pItem->QueryValue( aRet, pMap->nMemberId );
254 return aRet;
258 rtl::OUString SAL_CALL SwXTextDefaults::getImplementationName( )
259 throw (RuntimeException)
261 return C2U("SwXTextDefaults");
265 sal_Bool SAL_CALL SwXTextDefaults::supportsService( const ::rtl::OUString& rServiceName )
266 throw (RuntimeException)
268 return rServiceName == C2U("com.sun.star.text.Defaults") ||
269 rServiceName == C2U("com.sun.star.style.CharacterProperties") ||
270 rServiceName == C2U("com.sun.star.style.CharacterPropertiesAsian") ||
271 rServiceName == C2U("com.sun.star.style.CharacterPropertiesComplex") ||
272 rServiceName == C2U("com.sun.star.style.ParagraphProperties") ||
273 rServiceName == C2U("com.sun.star.style.ParagraphPropertiesAsian") ||
274 rServiceName == C2U("com.sun.star.style.ParagraphPropertiesComplex");
278 uno::Sequence< ::rtl::OUString > SAL_CALL SwXTextDefaults::getSupportedServiceNames( )
279 throw (RuntimeException)
281 uno::Sequence< OUString > aRet(7);
282 OUString* pArr = aRet.getArray();
283 *pArr++ = C2U("com.sun.star.text.Defaults");
284 *pArr++ = C2U("com.sun.star.style.CharacterProperties");
285 *pArr++ = C2U("com.sun.star.style.CharacterPropertiesAsian");
286 *pArr++ = C2U("com.sun.star.style.CharacterPropertiesComplex");
287 *pArr++ = C2U("com.sun.star.style.ParagraphProperties");
288 *pArr++ = C2U("com.sun.star.style.ParagraphPropertiesAsian");
289 *pArr++ = C2U("com.sun.star.style.ParagraphPropertiesComplex");
290 return aRet;