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 : : #include <com/sun/star/lang/XServiceInfo.hpp>
30 : : #include <com/sun/star/beans/PropertyState.hpp>
31 : :
32 : : #include <comphelper/propertysetinfo.hxx>
33 : : #include <comphelper/servicehelper.hxx>
34 : : #include <osl/mutex.hxx>
35 : : #include <vcl/svapp.hxx>
36 : : #include "svx/unopool.hxx"
37 : : #include <svx/svdmodel.hxx>
38 : : #include <svx/svdpool.hxx>
39 : : #include <svx/unoprov.hxx>
40 : : #include <svx/svdobj.hxx>
41 : : #include <svx/unoshprp.hxx>
42 : : #include <svx/xflbstit.hxx>
43 : : #include <svx/xflbmtit.hxx>
44 : : #include <svx/unopage.hxx>
45 : : #include <svx/svdetc.hxx>
46 : : #include <editeng/editeng.hxx>
47 : :
48 : : #include "svx/unoapi.hxx"
49 : : #include <memory>
50 : :
51 : : using namespace ::com::sun::star;
52 : : using namespace ::rtl;
53 : : using namespace ::cppu;
54 : :
55 : 73 : SvxUnoDrawPool::SvxUnoDrawPool( SdrModel* pModel, sal_Int32 nServiceId ) throw()
56 : 73 : : PropertySetHelper( SvxPropertySetInfoPool::getOrCreate( nServiceId ) ), mpModel( pModel )
57 : : {
58 [ + - ]: 73 : init();
59 : 73 : }
60 : :
61 : : /* deprecated */
62 : 27 : SvxUnoDrawPool::SvxUnoDrawPool( SdrModel* pModel ) throw()
63 : 27 : : PropertySetHelper( SvxPropertySetInfoPool::getOrCreate( SVXUNO_SERVICEID_COM_SUN_STAR_DRAWING_DEFAULTS ) ), mpModel( pModel )
64 : : {
65 [ + - ]: 27 : init();
66 : 27 : }
67 : :
68 : 88 : SvxUnoDrawPool::~SvxUnoDrawPool() throw()
69 : : {
70 [ + - ]: 88 : if (mpDefaultsPool)
71 : : {
72 [ + - ]: 88 : SfxItemPool* pOutlPool = mpDefaultsPool->GetSecondaryPool();
73 [ + - ]: 88 : SfxItemPool::Free(mpDefaultsPool);
74 [ + - ]: 88 : SfxItemPool::Free(pOutlPool);
75 : : }
76 [ - + ]: 88 : }
77 : :
78 : 100 : void SvxUnoDrawPool::init()
79 : : {
80 [ + - ]: 100 : mpDefaultsPool = new SdrItemPool();
81 : 100 : SfxItemPool* pOutlPool=EditEngine::CreatePool();
82 : 100 : mpDefaultsPool->SetSecondaryPool(pOutlPool);
83 : :
84 : 100 : SdrModel::SetTextDefaults( mpDefaultsPool, SdrEngineDefaults::GetFontHeight() );
85 : 100 : mpDefaultsPool->SetDefaultMetric((SfxMapUnit)SdrEngineDefaults::GetMapUnit());
86 : 100 : mpDefaultsPool->FreezeIdRanges();
87 : 100 : }
88 : :
89 : 406 : SfxItemPool* SvxUnoDrawPool::getModelPool( sal_Bool bReadOnly ) throw()
90 : : {
91 [ + - ]: 406 : if( mpModel )
92 : : {
93 : 406 : return &mpModel->GetItemPool();
94 : : }
95 : : else
96 : : {
97 [ # # ]: 0 : if( bReadOnly )
98 : 0 : return mpDefaultsPool;
99 : : else
100 : 406 : return NULL;
101 : : }
102 : : }
103 : :
104 : 1170 : void SvxUnoDrawPool::getAny( SfxItemPool* pPool, const comphelper::PropertyMapEntry* pEntry, uno::Any& rValue )
105 : : throw(beans::UnknownPropertyException)
106 : : {
107 [ - + ]: 1170 : switch( pEntry->mnHandle )
108 : : {
109 : : case OWN_ATTR_FILLBMP_MODE:
110 : : {
111 : 0 : XFillBmpStretchItem* pStretchItem = (XFillBmpStretchItem*)&pPool->GetDefaultItem(XATTR_FILLBMP_STRETCH);
112 : 0 : XFillBmpTileItem* pTileItem = (XFillBmpTileItem*)&pPool->GetDefaultItem(XATTR_FILLBMP_TILE);
113 [ # # ][ # # ]: 0 : if( pTileItem && pTileItem->GetValue() )
[ # # ]
114 : : {
115 [ # # ]: 0 : rValue <<= drawing::BitmapMode_REPEAT;
116 : : }
117 [ # # ][ # # ]: 0 : else if( pStretchItem && pStretchItem->GetValue() )
[ # # ]
118 : : {
119 [ # # ]: 0 : rValue <<= drawing::BitmapMode_STRETCH;
120 : : }
121 : : else
122 : : {
123 [ # # ]: 0 : rValue <<= drawing::BitmapMode_NO_REPEAT;
124 : : }
125 : 0 : break;
126 : : }
127 : : default:
128 : : {
129 [ + - ]: 1170 : const SfxMapUnit eMapUnit = pPool ? pPool->GetMetric((sal_uInt16)pEntry->mnHandle) : SFX_MAPUNIT_100TH_MM;
130 : :
131 : 1170 : sal_uInt8 nMemberId = pEntry->mnMemberId & (~SFX_METRIC_ITEM);
132 [ + + ]: 1170 : if( eMapUnit == SFX_MAPUNIT_100TH_MM )
133 : 372 : nMemberId &= (~CONVERT_TWIPS);
134 : :
135 : : // DVO, OD 10.10.2003 #i18732#
136 : : // Assure, that ID is a Which-ID (it could be a Slot-ID.)
137 : : // Thus, convert handle to Which-ID.
138 : 1170 : pPool->GetDefaultItem( pPool->GetWhich( (sal_uInt16)pEntry->mnHandle ) ).QueryValue( rValue, nMemberId );
139 : : }
140 : : }
141 : :
142 : :
143 : : // check for needed metric translation
144 : 1170 : const SfxMapUnit eMapUnit = pPool->GetMetric((sal_uInt16)pEntry->mnHandle);
145 [ + - ][ + + ]: 1170 : if(pEntry->mnMemberId & SFX_METRIC_ITEM && eMapUnit != SFX_MAPUNIT_100TH_MM)
146 : : {
147 : 42 : SvxUnoConvertToMM( eMapUnit, rValue );
148 : : }
149 : : // convert int32 to correct enum type if needed
150 [ + + ][ - + ]: 1128 : else if ( pEntry->mpType->getTypeClass() == uno::TypeClass_ENUM && rValue.getValueType() == ::getCppuType((const sal_Int32*)0) )
[ - + ]
151 : : {
152 : : sal_Int32 nEnum;
153 : 0 : rValue >>= nEnum;
154 : :
155 : 0 : rValue.setValue( &nEnum, *pEntry->mpType );
156 : : }
157 : 1170 : }
158 : :
159 : 2319 : void SvxUnoDrawPool::putAny( SfxItemPool* pPool, const comphelper::PropertyMapEntry* pEntry, const uno::Any& rValue )
160 : : throw(beans::UnknownPropertyException, lang::IllegalArgumentException)
161 : : {
162 : 2319 : uno::Any aValue( rValue );
163 : :
164 [ + - ]: 2319 : const SfxMapUnit eMapUnit = pPool->GetMetric((sal_uInt16)pEntry->mnHandle);
165 [ + + ][ + + ]: 2319 : if(pEntry->mnMemberId & SFX_METRIC_ITEM && eMapUnit != SFX_MAPUNIT_100TH_MM)
166 : : {
167 : 126 : SvxUnoConvertFromMM( eMapUnit, aValue );
168 : : }
169 : :
170 : : // DVO, OD 10.10.2003 #i18732#
171 : : // Assure, that ID is a Which-ID (it could be a Slot-ID.)
172 : : // Thus, convert handle to Which-ID.
173 [ + - ]: 2319 : const sal_uInt16 nWhich = pPool->GetWhich( (sal_uInt16)pEntry->mnHandle );
174 [ - + ]: 2319 : switch( nWhich )
175 : : {
176 : : case OWN_ATTR_FILLBMP_MODE:
177 : : do
178 : : {
179 : : drawing::BitmapMode eMode;
180 [ # # ][ # # ]: 0 : if(!(aValue >>= eMode) )
181 : : {
182 : 0 : sal_Int32 nMode = 0;
183 [ # # ]: 0 : if(!(aValue >>= nMode))
184 [ # # ]: 0 : throw lang::IllegalArgumentException();
185 : :
186 : 0 : eMode = (drawing::BitmapMode)nMode;
187 : : }
188 : :
189 [ # # ][ # # ]: 0 : pPool->SetPoolDefaultItem( XFillBmpStretchItem( eMode == drawing::BitmapMode_STRETCH ) );
[ # # ]
190 [ # # ][ # # ]: 0 : pPool->SetPoolDefaultItem( XFillBmpTileItem( eMode == drawing::BitmapMode_REPEAT ) );
[ # # ]
191 : 2319 : return;
192 : : }
193 : : while(0);
194 : :
195 : : default:
196 : : {
197 [ + - ][ + - ]: 2319 : ::std::auto_ptr<SfxPoolItem> pNewItem( pPool->GetDefaultItem( nWhich ).Clone() );
198 : 2319 : sal_uInt8 nMemberId = pEntry->mnMemberId & (~SFX_METRIC_ITEM);
199 [ + - ][ + + ]: 2319 : if( !pPool || (pPool->GetMetric(nWhich) == SFX_MAPUNIT_100TH_MM) )
[ + + ][ + - ]
200 : 651 : nMemberId &= (~CONVERT_TWIPS);
201 : :
202 [ + - ][ - + ]: 2319 : if( !pNewItem->PutValue( aValue, nMemberId ) )
203 [ # # ]: 0 : throw lang::IllegalArgumentException();
204 : :
205 [ + - ][ + - ]: 2319 : pPool->SetPoolDefaultItem( *pNewItem );
206 : : }
207 [ + - ]: 2319 : }
208 : : }
209 : :
210 : 166 : void SvxUnoDrawPool::_setPropertyValues( const comphelper::PropertyMapEntry** ppEntries, const uno::Any* pValues )
211 : : throw(beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException )
212 : : {
213 [ + - ]: 166 : SolarMutexGuard aGuard;
214 : :
215 : 166 : SfxItemPool* pPool = getModelPool( sal_False );
216 : :
217 : : DBG_ASSERT( pPool, "I need a SfxItemPool!" );
218 [ - + ]: 166 : if( NULL == pPool )
219 [ # # ]: 0 : throw beans::UnknownPropertyException();
220 : :
221 [ + + ]: 2485 : while( *ppEntries )
222 [ + - ][ + - ]: 2485 : putAny( pPool, *ppEntries++, *pValues++ );
223 : 166 : }
224 : :
225 : 1170 : void SvxUnoDrawPool::_getPropertyValues( const comphelper::PropertyMapEntry** ppEntries, uno::Any* pValue )
226 : : throw(beans::UnknownPropertyException, lang::WrappedTargetException )
227 : : {
228 [ + - ]: 1170 : SolarMutexGuard aGuard;
229 : :
230 : 1170 : SfxItemPool* pPool = getModelPool( sal_True );
231 : :
232 : : DBG_ASSERT( pPool, "I need a SfxItemPool!" );
233 [ - + ]: 1170 : if( NULL == pPool )
234 [ # # ]: 0 : throw beans::UnknownPropertyException();
235 : :
236 [ + + ]: 2340 : while( *ppEntries )
237 [ + - ][ + - ]: 2340 : getAny( pPool, *ppEntries++, *pValue++ );
238 : 1170 : }
239 : :
240 : 33 : void SvxUnoDrawPool::_getPropertyStates( const comphelper::PropertyMapEntry** ppEntries, beans::PropertyState* pStates )
241 : : throw(beans::UnknownPropertyException )
242 : : {
243 [ + - ]: 33 : SolarMutexGuard aGuard;
244 : :
245 : 33 : SfxItemPool* pPool = getModelPool( sal_True );
246 : :
247 [ + - ][ + - ]: 33 : if( pPool && pPool != mpDefaultsPool )
248 : : {
249 [ + + ]: 4554 : while( *ppEntries )
250 : : {
251 : : // OD 13.10.2003 #i18732#
252 : : // Assure, that ID is a Which-ID (it could be a Slot-ID.)
253 : : // Thus, convert handle to Which-ID.
254 [ + - ]: 4521 : const sal_uInt16 nWhich = pPool->GetWhich( ((sal_uInt16)(*ppEntries)->mnHandle) );
255 : :
256 [ + + ]: 4521 : switch( nWhich )
257 : : {
258 : : case OWN_ATTR_FILLBMP_MODE:
259 : : {
260 : : // use method <IsStaticDefaultItem(..)> instead of using
261 : : // probably incompatible item pool <mpDefaultPool>.
262 [ + - ]: 33 : if ( IsStaticDefaultItem( &(pPool->GetDefaultItem( XATTR_FILLBMP_STRETCH )) ) ||
[ - + # # ]
[ + - ]
263 [ # # ]: 0 : IsStaticDefaultItem( &(pPool->GetDefaultItem( XATTR_FILLBMP_TILE )) ) )
264 : : {
265 : 33 : *pStates = beans::PropertyState_DEFAULT_VALUE;
266 : : }
267 : : else
268 : : {
269 : 0 : *pStates = beans::PropertyState_DIRECT_VALUE;
270 : : }
271 : : }
272 : 33 : break;
273 : : default:
274 : : // OD 13.10.2003 #i18732# - correction:
275 : : // use method <IsStaticDefaultItem(..)> instead of using probably
276 : : // incompatible item pool <mpDefaultPool>.
277 [ + - ]: 4488 : const SfxPoolItem& r1 = pPool->GetDefaultItem( nWhich );
278 : : //const SfxPoolItem& r2 = mpDefaultPool->GetDefaultItem( nWhich );
279 : :
280 [ + + ]: 4488 : if ( IsStaticDefaultItem( &r1 ) )
281 : : {
282 : 3438 : *pStates = beans::PropertyState_DEFAULT_VALUE;
283 : : }
284 : : else
285 : : {
286 : 1050 : *pStates = beans::PropertyState_DIRECT_VALUE;
287 : : }
288 : : }
289 : :
290 : 4521 : pStates++;
291 : 4521 : ppEntries++;
292 : 33 : }
293 : : }
294 : : else
295 : : {
296 : : // as long as we have no model, all properties are default
297 [ # # ]: 33 : while( *ppEntries++ )
298 : 0 : *pStates++ = beans::PropertyState_DEFAULT_VALUE;
299 : 33 : return;
300 [ + - ][ + - ]: 33 : }
301 : : }
302 : :
303 : 0 : void SvxUnoDrawPool::_setPropertyToDefault( const comphelper::PropertyMapEntry* pEntry )
304 : : throw(beans::UnknownPropertyException )
305 : : {
306 [ # # ]: 0 : SolarMutexGuard aGuard;
307 : :
308 : 0 : SfxItemPool* pPool = getModelPool( sal_True );
309 : :
310 : : // OD 10.10.2003 #i18732#
311 : : // Assure, that ID is a Which-ID (it could be a Slot-ID.)
312 : : // Thus, convert handle to Which-ID.
313 [ # # ]: 0 : const sal_uInt16 nWhich = pPool->GetWhich( (sal_uInt16)pEntry->mnHandle );
314 [ # # ][ # # ]: 0 : if ( pPool && pPool != mpDefaultsPool )
315 : : {
316 : : // OD 13.10.2003 #i18732# - use method <ResetPoolDefaultItem(..)>
317 : : // instead of using probably incompatible item pool <mpDefaultsPool>.
318 [ # # ]: 0 : pPool->ResetPoolDefaultItem( nWhich );
319 [ # # ]: 0 : }
320 : 0 : }
321 : :
322 : 0 : uno::Any SvxUnoDrawPool::_getPropertyDefault( const comphelper::PropertyMapEntry* pEntry )
323 : : throw(beans::UnknownPropertyException, lang::WrappedTargetException )
324 : : {
325 [ # # ]: 0 : SolarMutexGuard aGuard;
326 : :
327 : : // OD 13.10.2003 #i18732# - use method <GetPoolDefaultItem(..)> instead of
328 : : // using probably incompatible item pool <mpDefaultsPool>
329 : 0 : uno::Any aAny;
330 : 0 : SfxItemPool* pPool = getModelPool( sal_True );
331 [ # # ]: 0 : const sal_uInt16 nWhich = pPool->GetWhich( (sal_uInt16)pEntry->mnHandle );
332 [ # # ]: 0 : const SfxPoolItem *pItem = pPool->GetPoolDefaultItem ( nWhich );
333 [ # # ]: 0 : pItem->QueryValue( aAny, pEntry->mnMemberId );
334 : :
335 [ # # ]: 0 : return aAny;
336 : : }
337 : :
338 : : // XInterface
339 : :
340 : 382 : uno::Any SAL_CALL SvxUnoDrawPool::queryInterface( const uno::Type & rType )
341 : : throw( uno::RuntimeException )
342 : : {
343 : 382 : return OWeakAggObject::queryInterface( rType );
344 : : }
345 : :
346 : 382 : uno::Any SAL_CALL SvxUnoDrawPool::queryAggregation( const uno::Type & rType )
347 : : throw(uno::RuntimeException)
348 : : {
349 : 382 : uno::Any aAny;
350 : :
351 [ - + ][ + - ]: 382 : if( rType == ::getCppuType((const uno::Reference< lang::XServiceInfo >*)0) )
352 [ # # ][ # # ]: 0 : aAny <<= uno::Reference< lang::XServiceInfo >(this);
353 [ + - ][ - + ]: 382 : else if( rType == ::getCppuType((const uno::Reference< lang::XTypeProvider >*)0) )
354 [ # # ][ # # ]: 0 : aAny <<= uno::Reference< lang::XTypeProvider >(this);
355 [ + - ][ + + ]: 382 : else if( rType == ::getCppuType((const uno::Reference< beans::XPropertySet >*)0) )
356 [ + - ][ + - ]: 116 : aAny <<= uno::Reference< beans::XPropertySet >(this);
357 [ + - ][ + + ]: 266 : else if( rType == ::getCppuType((const uno::Reference< beans::XPropertyState >*)0) )
358 [ + - ][ + - ]: 33 : aAny <<= uno::Reference< beans::XPropertyState >(this);
359 [ + - ][ + + ]: 233 : else if( rType == ::getCppuType((const uno::Reference< beans::XMultiPropertySet >*)0) )
360 [ + - ][ + - ]: 116 : aAny <<= uno::Reference< beans::XMultiPropertySet >(this);
361 : : else
362 [ + - ][ + - ]: 117 : aAny <<= OWeakAggObject::queryAggregation( rType );
363 : :
364 : 382 : return aAny;
365 : : }
366 : :
367 : 1199 : void SAL_CALL SvxUnoDrawPool::acquire() throw ( )
368 : : {
369 : 1199 : OWeakAggObject::acquire();
370 : 1199 : }
371 : :
372 : 1187 : void SAL_CALL SvxUnoDrawPool::release() throw ( )
373 : : {
374 : 1187 : OWeakAggObject::release();
375 : 1187 : }
376 : :
377 : 0 : uno::Sequence< uno::Type > SAL_CALL SvxUnoDrawPool::getTypes()
378 : : throw (uno::RuntimeException)
379 : : {
380 : 0 : uno::Sequence< uno::Type > aTypes( 6 );
381 [ # # ]: 0 : uno::Type* pTypes = aTypes.getArray();
382 : :
383 [ # # ]: 0 : *pTypes++ = ::getCppuType((const uno::Reference< uno::XAggregation>*)0);
384 [ # # ]: 0 : *pTypes++ = ::getCppuType((const uno::Reference< lang::XServiceInfo>*)0);
385 [ # # ]: 0 : *pTypes++ = ::getCppuType((const uno::Reference< lang::XTypeProvider>*)0);
386 [ # # ]: 0 : *pTypes++ = ::getCppuType((const uno::Reference< beans::XPropertySet>*)0);
387 [ # # ]: 0 : *pTypes++ = ::getCppuType((const uno::Reference< beans::XPropertyState>*)0);
388 [ # # ]: 0 : *pTypes++ = ::getCppuType((const uno::Reference< beans::XMultiPropertySet>*)0);
389 : :
390 : 0 : return aTypes;
391 : : }
392 : :
393 : : namespace
394 : : {
395 : : class theSvxUnoDrawPoolImplementationId : public rtl::Static< UnoTunnelIdInit, theSvxUnoDrawPoolImplementationId > {};
396 : : }
397 : :
398 : 0 : uno::Sequence< sal_Int8 > SAL_CALL SvxUnoDrawPool::getImplementationId()
399 : : throw (uno::RuntimeException)
400 : : {
401 : 0 : return theSvxUnoDrawPoolImplementationId::get().getSeq();
402 : : }
403 : :
404 : : // XServiceInfo
405 : :
406 : 0 : sal_Bool SAL_CALL SvxUnoDrawPool::supportsService( const OUString& ServiceName ) throw(uno::RuntimeException)
407 : : {
408 [ # # ]: 0 : uno::Sequence< OUString > aSNL( getSupportedServiceNames() );
409 : 0 : const OUString * pArray = aSNL.getConstArray();
410 : :
411 [ # # ]: 0 : for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
412 [ # # ]: 0 : if( pArray[i] == ServiceName )
413 : 0 : return sal_True;
414 : :
415 [ # # ]: 0 : return sal_False;
416 : : }
417 : :
418 : 0 : OUString SAL_CALL SvxUnoDrawPool::getImplementationName() throw( uno::RuntimeException )
419 : : {
420 : 0 : return OUString( RTL_CONSTASCII_USTRINGPARAM("SvxUnoDrawPool") );
421 : : }
422 : :
423 : 0 : uno::Sequence< OUString > SAL_CALL SvxUnoDrawPool::getSupportedServiceNames( )
424 : : throw( uno::RuntimeException )
425 : : {
426 : 0 : uno::Sequence< OUString > aSNS( 1 );
427 [ # # ][ # # ]: 0 : aSNS.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.Defaults" ));
428 : 0 : return aSNS;
429 : : }
430 : :
431 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|