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