xref: /AOO41X/main/sw/source/core/unocore/SwXTextDefaults.cxx (revision efeef26f81c84063fb0a91bde3856d4a51172d90)
1*efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*efeef26fSAndrew Rist  * distributed with this work for additional information
6*efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9*efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15*efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17*efeef26fSAndrew Rist  * specific language governing permissions and limitations
18*efeef26fSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*efeef26fSAndrew Rist  *************************************************************/
21*efeef26fSAndrew Rist 
22*efeef26fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <vos/mutex.hxx>
30cdf0e10cSrcweir #include <vcl/svapp.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <SwXTextDefaults.hxx>
33cdf0e10cSrcweir #include <SwStyleNameMapper.hxx>
34cdf0e10cSrcweir #include <fchrfmt.hxx>
35cdf0e10cSrcweir #include <charfmt.hxx>
36cdf0e10cSrcweir #include <docstyle.hxx>
37cdf0e10cSrcweir #include <doc.hxx>
38cdf0e10cSrcweir #include <docsh.hxx>
39cdf0e10cSrcweir #include <unomap.hxx>
40cdf0e10cSrcweir #include <unomid.h>
41cdf0e10cSrcweir #include <paratr.hxx>
42cdf0e10cSrcweir #include <unoprnms.hxx>
43cdf0e10cSrcweir #include <unocrsrhelper.hxx>
44cdf0e10cSrcweir #include <hintids.hxx>
45cdf0e10cSrcweir 
46cdf0e10cSrcweir #include <unomid.h>
47cdf0e10cSrcweir 
48cdf0e10cSrcweir 
49cdf0e10cSrcweir using rtl::OUString;
50cdf0e10cSrcweir using namespace rtl;
51cdf0e10cSrcweir using namespace ::com::sun::star;
52cdf0e10cSrcweir using namespace ::com::sun::star::uno;
53cdf0e10cSrcweir using namespace ::com::sun::star::beans;
54cdf0e10cSrcweir using namespace ::com::sun::star::lang;
55cdf0e10cSrcweir 
56cdf0e10cSrcweir 
SwXTextDefaults(SwDoc * pNewDoc)57cdf0e10cSrcweir SwXTextDefaults::SwXTextDefaults ( SwDoc * pNewDoc ) :
58cdf0e10cSrcweir     m_pPropSet( aSwMapProvider.GetPropertySet( PROPERTY_MAP_TEXT_DEFAULT ) ),
59cdf0e10cSrcweir     m_pDoc   ( pNewDoc )
60cdf0e10cSrcweir {
61cdf0e10cSrcweir }
62cdf0e10cSrcweir 
63cdf0e10cSrcweir 
~SwXTextDefaults()64cdf0e10cSrcweir SwXTextDefaults::~SwXTextDefaults ()
65cdf0e10cSrcweir {
66cdf0e10cSrcweir }
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 
getPropertySetInfo()69cdf0e10cSrcweir uno::Reference< XPropertySetInfo > SAL_CALL SwXTextDefaults::getPropertySetInfo(  )
70cdf0e10cSrcweir 		throw(RuntimeException)
71cdf0e10cSrcweir {
72cdf0e10cSrcweir     static uno::Reference < XPropertySetInfo > xRef = m_pPropSet->getPropertySetInfo();
73cdf0e10cSrcweir     return xRef;
74cdf0e10cSrcweir }
75cdf0e10cSrcweir 
76cdf0e10cSrcweir 
setPropertyValue(const OUString & rPropertyName,const Any & aValue)77cdf0e10cSrcweir void SAL_CALL SwXTextDefaults::setPropertyValue( const OUString& rPropertyName, const Any& aValue )
78cdf0e10cSrcweir 		throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
79cdf0e10cSrcweir {
80cdf0e10cSrcweir     vos::OGuard aGuard( Application::GetSolarMutex());
81cdf0e10cSrcweir     if (!m_pDoc)
82cdf0e10cSrcweir         throw RuntimeException();
83cdf0e10cSrcweir     const SfxItemPropertySimpleEntry *pMap = m_pPropSet->getPropertyMap()->getByName( rPropertyName );
84cdf0e10cSrcweir     if (!pMap)
85cdf0e10cSrcweir         throw UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
86cdf0e10cSrcweir     if ( pMap->nFlags & PropertyAttribute::READONLY)
87cdf0e10cSrcweir         throw PropertyVetoException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Property is read-only: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
88cdf0e10cSrcweir 
89cdf0e10cSrcweir     const SfxPoolItem& rItem = m_pDoc->GetDefault(pMap->nWID);
90cdf0e10cSrcweir     if (RES_PAGEDESC == pMap->nWID && MID_PAGEDESC_PAGEDESCNAME == pMap->nMemberId)
91cdf0e10cSrcweir     {
92cdf0e10cSrcweir         SfxItemSet aSet( m_pDoc->GetAttrPool(), RES_PAGEDESC, RES_PAGEDESC );
93cdf0e10cSrcweir         aSet.Put(rItem);
94cdf0e10cSrcweir         SwUnoCursorHelper::SetPageDesc( aValue, *m_pDoc, aSet );
95cdf0e10cSrcweir         m_pDoc->SetDefault(aSet.Get(RES_PAGEDESC));
96cdf0e10cSrcweir     }
97cdf0e10cSrcweir     else if ((RES_PARATR_DROP == pMap->nWID && MID_DROPCAP_CHAR_STYLE_NAME == pMap->nMemberId) ||
98cdf0e10cSrcweir              (RES_TXTATR_CHARFMT == pMap->nWID))
99cdf0e10cSrcweir     {
100cdf0e10cSrcweir         OUString uStyle;
101cdf0e10cSrcweir         if(aValue >>= uStyle)
102cdf0e10cSrcweir         {
103cdf0e10cSrcweir             String sStyle;
104cdf0e10cSrcweir             SwStyleNameMapper::FillUIName(uStyle, sStyle, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, sal_True );
105cdf0e10cSrcweir             SwDocStyleSheet* pStyle =
106cdf0e10cSrcweir                 (SwDocStyleSheet*)m_pDoc->GetDocShell()->GetStyleSheetPool()->Find(sStyle, SFX_STYLE_FAMILY_CHAR);
107cdf0e10cSrcweir             SwFmtDrop* pDrop = 0;
108cdf0e10cSrcweir             SwFmtCharFmt *pCharFmt = 0;
109cdf0e10cSrcweir             if(pStyle)
110cdf0e10cSrcweir             {
111cdf0e10cSrcweir 				rtl::Reference< SwDocStyleSheet > xStyle( new SwDocStyleSheet( *(SwDocStyleSheet*)pStyle ) );
112cdf0e10cSrcweir                 if (RES_PARATR_DROP == pMap->nWID)
113cdf0e10cSrcweir                 {
114cdf0e10cSrcweir                     pDrop = (SwFmtDrop*)rItem.Clone();   // because rItem ist const...
115cdf0e10cSrcweir                     pDrop->SetCharFmt(xStyle->GetCharFmt());
116cdf0e10cSrcweir                     m_pDoc->SetDefault(*pDrop);
117cdf0e10cSrcweir                 }
118cdf0e10cSrcweir                 else // RES_TXTATR_CHARFMT == pMap->nWID
119cdf0e10cSrcweir                 {
120cdf0e10cSrcweir                     pCharFmt = (SwFmtCharFmt*)rItem.Clone();   // because rItem ist const...
121cdf0e10cSrcweir                     pCharFmt->SetCharFmt(xStyle->GetCharFmt());
122cdf0e10cSrcweir                     m_pDoc->SetDefault(*pCharFmt);
123cdf0e10cSrcweir                 }
124cdf0e10cSrcweir             }
125cdf0e10cSrcweir             else
126cdf0e10cSrcweir                 throw lang::IllegalArgumentException();
127cdf0e10cSrcweir             delete pDrop;
128cdf0e10cSrcweir             delete pCharFmt;
129cdf0e10cSrcweir         }
130cdf0e10cSrcweir         else
131cdf0e10cSrcweir             throw lang::IllegalArgumentException();
132cdf0e10cSrcweir     }
133cdf0e10cSrcweir     else
134cdf0e10cSrcweir     {
135cdf0e10cSrcweir         SfxPoolItem * pNewItem = rItem.Clone();
136cdf0e10cSrcweir         pNewItem->PutValue( aValue, pMap->nMemberId);
137cdf0e10cSrcweir         m_pDoc->SetDefault(*pNewItem);
138cdf0e10cSrcweir         delete pNewItem;
139cdf0e10cSrcweir     }
140cdf0e10cSrcweir }
141cdf0e10cSrcweir 
142cdf0e10cSrcweir 
getPropertyValue(const OUString & rPropertyName)143cdf0e10cSrcweir Any SAL_CALL SwXTextDefaults::getPropertyValue( const OUString& rPropertyName )
144cdf0e10cSrcweir 		throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
145cdf0e10cSrcweir {
146cdf0e10cSrcweir     vos::OGuard aGuard( Application::GetSolarMutex());
147cdf0e10cSrcweir     if (!m_pDoc)
148cdf0e10cSrcweir         throw RuntimeException();
149cdf0e10cSrcweir     const SfxItemPropertySimpleEntry *pMap = m_pPropSet->getPropertyMap()->getByName( rPropertyName );
150cdf0e10cSrcweir     if (!pMap)
151cdf0e10cSrcweir         throw UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
152cdf0e10cSrcweir     Any aRet;
153cdf0e10cSrcweir     const SfxPoolItem& rItem = m_pDoc->GetDefault(pMap->nWID);
154cdf0e10cSrcweir 	rItem.QueryValue( aRet, pMap->nMemberId );
155cdf0e10cSrcweir     return aRet;
156cdf0e10cSrcweir }
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 
addPropertyChangeListener(const OUString &,const uno::Reference<XPropertyChangeListener> &)159cdf0e10cSrcweir void SAL_CALL SwXTextDefaults::addPropertyChangeListener( const OUString& /*rPropertyName*/, const uno::Reference< XPropertyChangeListener >& /*xListener*/ )
160cdf0e10cSrcweir 		throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
161cdf0e10cSrcweir {
162cdf0e10cSrcweir     DBG_WARNING ( "not implemented" );
163cdf0e10cSrcweir }
164cdf0e10cSrcweir 
165cdf0e10cSrcweir 
removePropertyChangeListener(const OUString &,const uno::Reference<XPropertyChangeListener> &)166cdf0e10cSrcweir void SAL_CALL SwXTextDefaults::removePropertyChangeListener( const OUString& /*rPropertyName*/, const uno::Reference< XPropertyChangeListener >& /*xListener*/ )
167cdf0e10cSrcweir 		throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
168cdf0e10cSrcweir {
169cdf0e10cSrcweir     DBG_WARNING ( "not implemented" );
170cdf0e10cSrcweir }
171cdf0e10cSrcweir 
172cdf0e10cSrcweir 
addVetoableChangeListener(const OUString &,const uno::Reference<XVetoableChangeListener> &)173cdf0e10cSrcweir void SAL_CALL SwXTextDefaults::addVetoableChangeListener( const OUString& /*rPropertyName*/, const uno::Reference< XVetoableChangeListener >& /*xListener*/ )
174cdf0e10cSrcweir 		throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
175cdf0e10cSrcweir {
176cdf0e10cSrcweir     DBG_WARNING ( "not implemented" );
177cdf0e10cSrcweir }
178cdf0e10cSrcweir 
179cdf0e10cSrcweir 
removeVetoableChangeListener(const OUString &,const uno::Reference<XVetoableChangeListener> &)180cdf0e10cSrcweir void SAL_CALL SwXTextDefaults::removeVetoableChangeListener( const OUString& /*rPropertyName*/, const uno::Reference< XVetoableChangeListener >& /*xListener*/ )
181cdf0e10cSrcweir 		throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
182cdf0e10cSrcweir {
183cdf0e10cSrcweir     DBG_WARNING ( "not implemented" );
184cdf0e10cSrcweir }
185cdf0e10cSrcweir 
186cdf0e10cSrcweir 
187cdf0e10cSrcweir // XPropertyState
getPropertyState(const OUString & rPropertyName)188cdf0e10cSrcweir PropertyState SAL_CALL SwXTextDefaults::getPropertyState( const OUString& rPropertyName )
189cdf0e10cSrcweir         throw(UnknownPropertyException, RuntimeException)
190cdf0e10cSrcweir {
191cdf0e10cSrcweir     vos::OGuard aGuard( Application::GetSolarMutex());
192cdf0e10cSrcweir     PropertyState eRet = PropertyState_DIRECT_VALUE;
193cdf0e10cSrcweir     if (!m_pDoc)
194cdf0e10cSrcweir         throw RuntimeException();
195cdf0e10cSrcweir     const SfxItemPropertySimpleEntry *pMap = m_pPropSet->getPropertyMap()->getByName( rPropertyName );
196cdf0e10cSrcweir     if (!pMap)
197cdf0e10cSrcweir         throw UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
198cdf0e10cSrcweir 
199cdf0e10cSrcweir     const SfxPoolItem& rItem = m_pDoc->GetDefault(pMap->nWID);
200cdf0e10cSrcweir     if (IsStaticDefaultItem ( &rItem ) )
201cdf0e10cSrcweir     	eRet = PropertyState_DEFAULT_VALUE;
202cdf0e10cSrcweir     return eRet;
203cdf0e10cSrcweir }
204cdf0e10cSrcweir 
205cdf0e10cSrcweir 
getPropertyStates(const Sequence<OUString> & rPropertyNames)206cdf0e10cSrcweir Sequence< PropertyState > SAL_CALL SwXTextDefaults::getPropertyStates( const Sequence< OUString >& rPropertyNames )
207cdf0e10cSrcweir         throw(UnknownPropertyException, RuntimeException)
208cdf0e10cSrcweir {
209cdf0e10cSrcweir     const sal_Int32 nCount = rPropertyNames.getLength();
210cdf0e10cSrcweir     const OUString * pNames = rPropertyNames.getConstArray();
211cdf0e10cSrcweir     Sequence < PropertyState > aRet ( nCount );
212cdf0e10cSrcweir     PropertyState *pState = aRet.getArray();
213cdf0e10cSrcweir 
214cdf0e10cSrcweir     for ( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++)
215cdf0e10cSrcweir         pState[nIndex] = getPropertyState( pNames[nIndex] );
216cdf0e10cSrcweir 
217cdf0e10cSrcweir     return aRet;
218cdf0e10cSrcweir }
219cdf0e10cSrcweir 
220cdf0e10cSrcweir 
setPropertyToDefault(const OUString & rPropertyName)221cdf0e10cSrcweir void SAL_CALL SwXTextDefaults::setPropertyToDefault( const OUString& rPropertyName )
222cdf0e10cSrcweir         throw(UnknownPropertyException, RuntimeException)
223cdf0e10cSrcweir {
224cdf0e10cSrcweir     if (!m_pDoc)
225cdf0e10cSrcweir         throw RuntimeException();
226cdf0e10cSrcweir     const SfxItemPropertySimpleEntry *pMap = m_pPropSet->getPropertyMap()->getByName( rPropertyName );
227cdf0e10cSrcweir     if (!pMap)
228cdf0e10cSrcweir         throw UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
229cdf0e10cSrcweir     if ( pMap->nFlags & PropertyAttribute::READONLY)
230cdf0e10cSrcweir         throw RuntimeException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "setPropertyToDefault: property is read-only: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
231cdf0e10cSrcweir     SfxItemPool& rSet (m_pDoc->GetAttrPool());
232cdf0e10cSrcweir     rSet.ResetPoolDefaultItem ( pMap->nWID );
233cdf0e10cSrcweir }
234cdf0e10cSrcweir 
235cdf0e10cSrcweir 
getPropertyDefault(const OUString & rPropertyName)236cdf0e10cSrcweir Any SAL_CALL SwXTextDefaults::getPropertyDefault( const OUString& rPropertyName )
237cdf0e10cSrcweir         throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
238cdf0e10cSrcweir {
239cdf0e10cSrcweir     if (!m_pDoc)
240cdf0e10cSrcweir         throw RuntimeException();
241cdf0e10cSrcweir     const SfxItemPropertySimpleEntry *pMap = m_pPropSet->getPropertyMap()->getByName( rPropertyName );
242cdf0e10cSrcweir     if (!pMap)
243cdf0e10cSrcweir         throw UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
244cdf0e10cSrcweir     Any aRet;
245cdf0e10cSrcweir     SfxItemPool& rSet (m_pDoc->GetAttrPool());
246cdf0e10cSrcweir     const SfxPoolItem *pItem = rSet.GetPoolDefaultItem ( pMap->nWID );
247cdf0e10cSrcweir     pItem->QueryValue( aRet, pMap->nMemberId );
248cdf0e10cSrcweir     return aRet;
249cdf0e10cSrcweir }
250cdf0e10cSrcweir 
251cdf0e10cSrcweir 
getImplementationName()252cdf0e10cSrcweir rtl::OUString SAL_CALL SwXTextDefaults::getImplementationName(  )
253cdf0e10cSrcweir     throw (RuntimeException)
254cdf0e10cSrcweir {
255cdf0e10cSrcweir     return C2U("SwXTextDefaults");
256cdf0e10cSrcweir }
257cdf0e10cSrcweir 
258cdf0e10cSrcweir 
supportsService(const::rtl::OUString & rServiceName)259cdf0e10cSrcweir sal_Bool SAL_CALL SwXTextDefaults::supportsService( const ::rtl::OUString& rServiceName )
260cdf0e10cSrcweir     throw (RuntimeException)
261cdf0e10cSrcweir {
262cdf0e10cSrcweir     return  rServiceName == C2U("com.sun.star.text.Defaults") ||
263cdf0e10cSrcweir             rServiceName == C2U("com.sun.star.style.CharacterProperties") ||
264cdf0e10cSrcweir             rServiceName == C2U("com.sun.star.style.CharacterPropertiesAsian") ||
265cdf0e10cSrcweir             rServiceName == C2U("com.sun.star.style.CharacterPropertiesComplex") ||
266cdf0e10cSrcweir             rServiceName == C2U("com.sun.star.style.ParagraphProperties") ||
267cdf0e10cSrcweir             rServiceName == C2U("com.sun.star.style.ParagraphPropertiesAsian") ||
268cdf0e10cSrcweir             rServiceName == C2U("com.sun.star.style.ParagraphPropertiesComplex");
269cdf0e10cSrcweir }
270cdf0e10cSrcweir 
271cdf0e10cSrcweir 
getSupportedServiceNames()272cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL SwXTextDefaults::getSupportedServiceNames(  )
273cdf0e10cSrcweir     throw (RuntimeException)
274cdf0e10cSrcweir {
275cdf0e10cSrcweir     uno::Sequence< OUString > aRet(7);
276cdf0e10cSrcweir 	OUString* pArr = aRet.getArray();
277cdf0e10cSrcweir     *pArr++ = C2U("com.sun.star.text.Defaults");
278cdf0e10cSrcweir     *pArr++ = C2U("com.sun.star.style.CharacterProperties");
279cdf0e10cSrcweir     *pArr++ = C2U("com.sun.star.style.CharacterPropertiesAsian");
280cdf0e10cSrcweir     *pArr++ = C2U("com.sun.star.style.CharacterPropertiesComplex");
281cdf0e10cSrcweir     *pArr++ = C2U("com.sun.star.style.ParagraphProperties");
282cdf0e10cSrcweir     *pArr++ = C2U("com.sun.star.style.ParagraphPropertiesAsian");
283cdf0e10cSrcweir     *pArr++ = C2U("com.sun.star.style.ParagraphPropertiesComplex");
284cdf0e10cSrcweir 	return aRet;
285cdf0e10cSrcweir }
286cdf0e10cSrcweir 
287cdf0e10cSrcweir 
288cdf0e10cSrcweir 
289