1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sw.hxx" 30 31 #include <com/sun/star/beans/PropertyAttribute.hpp> 32 33 #include <vos/mutex.hxx> 34 #include <vcl/svapp.hxx> 35 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 <unocrsrhelper.hxx> 48 #include <hintids.hxx> 49 50 #include <unomid.h> 51 52 53 using rtl::OUString; 54 using namespace rtl; 55 using namespace ::com::sun::star; 56 using namespace ::com::sun::star::uno; 57 using namespace ::com::sun::star::beans; 58 using namespace ::com::sun::star::lang; 59 60 61 SwXTextDefaults::SwXTextDefaults ( SwDoc * pNewDoc ) : 62 m_pPropSet( aSwMapProvider.GetPropertySet( PROPERTY_MAP_TEXT_DEFAULT ) ), 63 m_pDoc ( pNewDoc ) 64 { 65 } 66 67 68 SwXTextDefaults::~SwXTextDefaults () 69 { 70 } 71 72 73 uno::Reference< XPropertySetInfo > SAL_CALL SwXTextDefaults::getPropertySetInfo( ) 74 throw(RuntimeException) 75 { 76 static uno::Reference < XPropertySetInfo > xRef = m_pPropSet->getPropertySetInfo(); 77 return xRef; 78 } 79 80 81 void SAL_CALL SwXTextDefaults::setPropertyValue( const OUString& rPropertyName, const Any& aValue ) 82 throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException) 83 { 84 vos::OGuard aGuard( Application::GetSolarMutex()); 85 if (!m_pDoc) 86 throw RuntimeException(); 87 const SfxItemPropertySimpleEntry *pMap = m_pPropSet->getPropertyMap()->getByName( rPropertyName ); 88 if (!pMap) 89 throw UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) ); 90 if ( pMap->nFlags & PropertyAttribute::READONLY) 91 throw PropertyVetoException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Property is read-only: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) ); 92 93 const SfxPoolItem& rItem = m_pDoc->GetDefault(pMap->nWID); 94 if (RES_PAGEDESC == pMap->nWID && MID_PAGEDESC_PAGEDESCNAME == pMap->nMemberId) 95 { 96 SfxItemSet aSet( m_pDoc->GetAttrPool(), RES_PAGEDESC, RES_PAGEDESC ); 97 aSet.Put(rItem); 98 SwUnoCursorHelper::SetPageDesc( aValue, *m_pDoc, aSet ); 99 m_pDoc->SetDefault(aSet.Get(RES_PAGEDESC)); 100 } 101 else if ((RES_PARATR_DROP == pMap->nWID && MID_DROPCAP_CHAR_STYLE_NAME == pMap->nMemberId) || 102 (RES_TXTATR_CHARFMT == pMap->nWID)) 103 { 104 OUString uStyle; 105 if(aValue >>= uStyle) 106 { 107 String sStyle; 108 SwStyleNameMapper::FillUIName(uStyle, sStyle, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, sal_True ); 109 SwDocStyleSheet* pStyle = 110 (SwDocStyleSheet*)m_pDoc->GetDocShell()->GetStyleSheetPool()->Find(sStyle, SFX_STYLE_FAMILY_CHAR); 111 SwFmtDrop* pDrop = 0; 112 SwFmtCharFmt *pCharFmt = 0; 113 if(pStyle) 114 { 115 rtl::Reference< SwDocStyleSheet > xStyle( new SwDocStyleSheet( *(SwDocStyleSheet*)pStyle ) ); 116 if (RES_PARATR_DROP == pMap->nWID) 117 { 118 pDrop = (SwFmtDrop*)rItem.Clone(); // because rItem ist const... 119 pDrop->SetCharFmt(xStyle->GetCharFmt()); 120 m_pDoc->SetDefault(*pDrop); 121 } 122 else // RES_TXTATR_CHARFMT == pMap->nWID 123 { 124 pCharFmt = (SwFmtCharFmt*)rItem.Clone(); // because rItem ist const... 125 pCharFmt->SetCharFmt(xStyle->GetCharFmt()); 126 m_pDoc->SetDefault(*pCharFmt); 127 } 128 } 129 else 130 throw lang::IllegalArgumentException(); 131 delete pDrop; 132 delete pCharFmt; 133 } 134 else 135 throw lang::IllegalArgumentException(); 136 } 137 else 138 { 139 SfxPoolItem * pNewItem = rItem.Clone(); 140 pNewItem->PutValue( aValue, pMap->nMemberId); 141 m_pDoc->SetDefault(*pNewItem); 142 delete pNewItem; 143 } 144 } 145 146 147 Any SAL_CALL SwXTextDefaults::getPropertyValue( const OUString& rPropertyName ) 148 throw(UnknownPropertyException, WrappedTargetException, RuntimeException) 149 { 150 vos::OGuard aGuard( Application::GetSolarMutex()); 151 if (!m_pDoc) 152 throw RuntimeException(); 153 const SfxItemPropertySimpleEntry *pMap = m_pPropSet->getPropertyMap()->getByName( rPropertyName ); 154 if (!pMap) 155 throw UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) ); 156 Any aRet; 157 const SfxPoolItem& rItem = m_pDoc->GetDefault(pMap->nWID); 158 rItem.QueryValue( aRet, pMap->nMemberId ); 159 return aRet; 160 } 161 162 163 void SAL_CALL SwXTextDefaults::addPropertyChangeListener( const OUString& /*rPropertyName*/, const uno::Reference< XPropertyChangeListener >& /*xListener*/ ) 164 throw(UnknownPropertyException, WrappedTargetException, RuntimeException) 165 { 166 DBG_WARNING ( "not implemented" ); 167 } 168 169 170 void SAL_CALL SwXTextDefaults::removePropertyChangeListener( const OUString& /*rPropertyName*/, const uno::Reference< XPropertyChangeListener >& /*xListener*/ ) 171 throw(UnknownPropertyException, WrappedTargetException, RuntimeException) 172 { 173 DBG_WARNING ( "not implemented" ); 174 } 175 176 177 void SAL_CALL SwXTextDefaults::addVetoableChangeListener( const OUString& /*rPropertyName*/, const uno::Reference< XVetoableChangeListener >& /*xListener*/ ) 178 throw(UnknownPropertyException, WrappedTargetException, RuntimeException) 179 { 180 DBG_WARNING ( "not implemented" ); 181 } 182 183 184 void SAL_CALL SwXTextDefaults::removeVetoableChangeListener( const OUString& /*rPropertyName*/, const uno::Reference< XVetoableChangeListener >& /*xListener*/ ) 185 throw(UnknownPropertyException, WrappedTargetException, RuntimeException) 186 { 187 DBG_WARNING ( "not implemented" ); 188 } 189 190 191 // XPropertyState 192 PropertyState SAL_CALL SwXTextDefaults::getPropertyState( const OUString& rPropertyName ) 193 throw(UnknownPropertyException, RuntimeException) 194 { 195 vos::OGuard aGuard( Application::GetSolarMutex()); 196 PropertyState eRet = PropertyState_DIRECT_VALUE; 197 if (!m_pDoc) 198 throw RuntimeException(); 199 const SfxItemPropertySimpleEntry *pMap = m_pPropSet->getPropertyMap()->getByName( rPropertyName ); 200 if (!pMap) 201 throw UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) ); 202 203 const SfxPoolItem& rItem = m_pDoc->GetDefault(pMap->nWID); 204 if (IsStaticDefaultItem ( &rItem ) ) 205 eRet = PropertyState_DEFAULT_VALUE; 206 return eRet; 207 } 208 209 210 Sequence< PropertyState > SAL_CALL SwXTextDefaults::getPropertyStates( const Sequence< OUString >& rPropertyNames ) 211 throw(UnknownPropertyException, RuntimeException) 212 { 213 const sal_Int32 nCount = rPropertyNames.getLength(); 214 const OUString * pNames = rPropertyNames.getConstArray(); 215 Sequence < PropertyState > aRet ( nCount ); 216 PropertyState *pState = aRet.getArray(); 217 218 for ( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++) 219 pState[nIndex] = getPropertyState( pNames[nIndex] ); 220 221 return aRet; 222 } 223 224 225 void SAL_CALL SwXTextDefaults::setPropertyToDefault( const OUString& rPropertyName ) 226 throw(UnknownPropertyException, RuntimeException) 227 { 228 if (!m_pDoc) 229 throw RuntimeException(); 230 const SfxItemPropertySimpleEntry *pMap = m_pPropSet->getPropertyMap()->getByName( rPropertyName ); 231 if (!pMap) 232 throw UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) ); 233 if ( pMap->nFlags & PropertyAttribute::READONLY) 234 throw RuntimeException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "setPropertyToDefault: property is read-only: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) ); 235 SfxItemPool& rSet (m_pDoc->GetAttrPool()); 236 rSet.ResetPoolDefaultItem ( pMap->nWID ); 237 } 238 239 240 Any SAL_CALL SwXTextDefaults::getPropertyDefault( const OUString& rPropertyName ) 241 throw(UnknownPropertyException, WrappedTargetException, RuntimeException) 242 { 243 if (!m_pDoc) 244 throw RuntimeException(); 245 const SfxItemPropertySimpleEntry *pMap = m_pPropSet->getPropertyMap()->getByName( rPropertyName ); 246 if (!pMap) 247 throw UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) ); 248 Any aRet; 249 SfxItemPool& rSet (m_pDoc->GetAttrPool()); 250 const SfxPoolItem *pItem = rSet.GetPoolDefaultItem ( pMap->nWID ); 251 pItem->QueryValue( aRet, pMap->nMemberId ); 252 return aRet; 253 } 254 255 256 rtl::OUString SAL_CALL SwXTextDefaults::getImplementationName( ) 257 throw (RuntimeException) 258 { 259 return C2U("SwXTextDefaults"); 260 } 261 262 263 sal_Bool SAL_CALL SwXTextDefaults::supportsService( const ::rtl::OUString& rServiceName ) 264 throw (RuntimeException) 265 { 266 return rServiceName == C2U("com.sun.star.text.Defaults") || 267 rServiceName == C2U("com.sun.star.style.CharacterProperties") || 268 rServiceName == C2U("com.sun.star.style.CharacterPropertiesAsian") || 269 rServiceName == C2U("com.sun.star.style.CharacterPropertiesComplex") || 270 rServiceName == C2U("com.sun.star.style.ParagraphProperties") || 271 rServiceName == C2U("com.sun.star.style.ParagraphPropertiesAsian") || 272 rServiceName == C2U("com.sun.star.style.ParagraphPropertiesComplex"); 273 } 274 275 276 uno::Sequence< ::rtl::OUString > SAL_CALL SwXTextDefaults::getSupportedServiceNames( ) 277 throw (RuntimeException) 278 { 279 uno::Sequence< OUString > aRet(7); 280 OUString* pArr = aRet.getArray(); 281 *pArr++ = C2U("com.sun.star.text.Defaults"); 282 *pArr++ = C2U("com.sun.star.style.CharacterProperties"); 283 *pArr++ = C2U("com.sun.star.style.CharacterPropertiesAsian"); 284 *pArr++ = C2U("com.sun.star.style.CharacterPropertiesComplex"); 285 *pArr++ = C2U("com.sun.star.style.ParagraphProperties"); 286 *pArr++ = C2U("com.sun.star.style.ParagraphPropertiesAsian"); 287 *pArr++ = C2U("com.sun.star.style.ParagraphPropertiesComplex"); 288 return aRet; 289 } 290 291 292 293