xref: /trunk/main/sd/source/ui/unoidl/unopback.cxx (revision 79aad27f)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sd.hxx"
26 #include <com/sun/star/drawing/BitmapMode.hpp>
27 #include <vos/mutex.hxx>
28 #include <vcl/svapp.hxx>
29 #include <svl/itemset.hxx>
30 #include <svx/svdpool.hxx>
31 #include <comphelper/extract.hxx>
32 #include <rtl/uuid.h>
33 #include <rtl/memory.h>
34 #include <svx/xflbstit.hxx>
35 #include <svx/xflbmtit.hxx>
36 #include <svx/svdobj.hxx>
37 #include <svx/unoprov.hxx>
38 #include <svx/unoshape.hxx>
39 #include <comphelper/serviceinfohelper.hxx>
40 
41 #include "unopback.hxx"
42 #include "unohelp.hxx"
43 #include "drawdoc.hxx"
44 #include "unokywds.hxx"
45 
46 using namespace ::rtl;
47 using namespace ::vos;
48 using namespace ::com::sun::star;
49 
ImplGetPageBackgroundPropertySet()50 const SvxItemPropertySet* ImplGetPageBackgroundPropertySet()
51 {
52 	static const SfxItemPropertyMapEntry aPageBackgroundPropertyMap_Impl[] =
53 	{
54 		FILL_PROPERTIES
55 		{0,0,0,0,0,0}
56 	};
57 
58     static SvxItemPropertySet aPageBackgroundPropertySet_Impl( aPageBackgroundPropertyMap_Impl, SdrObject::GetGlobalDrawObjectItemPool() );
59 	return &aPageBackgroundPropertySet_Impl;
60 }
61 
62 UNO3_GETIMPLEMENTATION_IMPL( SdUnoPageBackground );
63 
SdUnoPageBackground(SdDrawDocument * pDoc,const SfxItemSet * pSet)64 SdUnoPageBackground::SdUnoPageBackground(
65     SdDrawDocument* pDoc /* = NULL */,
66     const SfxItemSet* pSet /* = NULL */) throw()
67 :   mpPropSet(ImplGetPageBackgroundPropertySet()),
68     mpSet(NULL),
69     mpDoc(pDoc)
70 {
71 	if( pDoc )
72 	{
73 		StartListening( *pDoc );
74 		mpSet = new SfxItemSet( pDoc->GetPool(), XATTR_FILL_FIRST, XATTR_FILL_LAST );
75 
76 		if( pSet )
77 			mpSet->Put(*pSet);
78 	}
79 }
80 
~SdUnoPageBackground()81 SdUnoPageBackground::~SdUnoPageBackground() throw()
82 {
83 	if( mpDoc )
84 		EndListening( *mpDoc );
85 
86 	if( mpSet )
87 		delete mpSet;
88 }
89 
Notify(SfxBroadcaster &,const SfxHint & rHint)90 void SdUnoPageBackground::Notify( SfxBroadcaster&, const SfxHint& rHint )
91 {
92 	const SdrHint* pSdrHint = PTR_CAST( SdrHint, &rHint );
93 
94 	if( pSdrHint )
95 	{
96 		// delete item set if document is dying because then the pool
97 		// will also die
98 		if( pSdrHint->GetKind() == HINT_MODELCLEARED )
99 		{
100 			delete mpSet;
101 			mpSet = NULL;
102 			mpDoc = NULL;
103 		}
104 	}
105 
106 }
107 
fillItemSet(SdDrawDocument * pDoc,SfxItemSet & rSet)108 void SdUnoPageBackground::fillItemSet( SdDrawDocument* pDoc, SfxItemSet& rSet ) throw()
109 {
110 	rSet.ClearItem();
111 
112 	if( mpSet == NULL )
113 	{
114 		StartListening( *pDoc );
115 		mpDoc = pDoc;
116 
117 		mpSet = new SfxItemSet( *rSet.GetPool(), XATTR_FILL_FIRST, XATTR_FILL_LAST );
118 
119 		if( mpPropSet->AreThereOwnUsrAnys() )
120 		{
121 			uno::Any* pAny;
122             PropertyEntryVector_t aProperties = mpPropSet->getPropertyMap()->getPropertyEntries();
123             PropertyEntryVector_t::const_iterator aIt = aProperties.begin();
124 
125 			while( aIt != aProperties.end() )
126 			{
127 				pAny = mpPropSet->GetUsrAnyForID( aIt->nWID );
128 				if( pAny )
129 				{
130 					OUString aPropertyName( aIt->sName );
131 					switch( aIt->nWID )
132 					{
133 						case XATTR_FILLFLOATTRANSPARENCE :
134 						case XATTR_FILLGRADIENT :
135 						{
136 							if ( ( pAny->getValueType() == ::getCppuType((const ::com::sun::star::awt::Gradient*)0) )
137 								&& ( aIt->nMemberId == MID_FILLGRADIENT ) )
138 							{
139 								setPropertyValue( aPropertyName, *pAny );
140 							}
141 							else if ( ( pAny->getValueType() == ::getCppuType((const ::rtl::OUString*)0) ) &&
142 										( aIt->nMemberId == MID_NAME ) )
143 							{
144 								setPropertyValue( aPropertyName, *pAny );
145 							}
146 						}
147 						break;
148 						case XATTR_FILLHATCH :
149 						{
150 							if ( ( pAny->getValueType() == ::getCppuType((const ::com::sun::star::drawing::Hatch*)0) )
151 								&& ( aIt->nMemberId == MID_FILLHATCH ) )
152 							{
153 								setPropertyValue( aPropertyName, *pAny );
154 							}
155 							else if ( ( pAny->getValueType() == ::getCppuType((const ::rtl::OUString*)0) ) &&
156 										( aIt->nMemberId == MID_NAME ) )
157 							{
158 								setPropertyValue( aPropertyName, *pAny );
159 							}
160 						}
161 						break;
162 						case XATTR_FILLBITMAP :
163 						{
164 							if ( ( ( pAny->getValueType() == ::getCppuType((const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XBitmap >*)0) ) ||
165 									( pAny->getValueType() == ::getCppuType((const ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic >*)0) ) ) &&
166 									( aIt->nMemberId == MID_BITMAP ) )
167 							{
168 								setPropertyValue( aPropertyName, *pAny );
169 							}
170 							else if ( ( pAny->getValueType() == ::getCppuType((const ::rtl::OUString*)0) ) &&
171 										( ( aIt->nMemberId == MID_NAME ) || ( aIt->nMemberId == MID_GRAFURL ) ) )
172 							{
173 								setPropertyValue( aPropertyName, *pAny );
174 							}
175 						}
176 						break;
177 
178 						default:
179 							setPropertyValue( aPropertyName, *pAny );
180 					}
181 			    }
182 				++aIt;
183 			}
184 		}
185 	}
186 
187 	rSet.Put( *mpSet );
188 }
189 
190 // XServiceInfo
getImplementationName()191 OUString SAL_CALL SdUnoPageBackground::getImplementationName()
192 	throw(uno::RuntimeException)
193 {
194 	return OUString::createFromAscii( sUNO_SdUnoPageBackground );
195 }
196 
supportsService(const OUString & ServiceName)197 sal_Bool SAL_CALL SdUnoPageBackground::supportsService( const OUString& ServiceName )
198 	throw(uno::RuntimeException)
199 {
200 	return comphelper::ServiceInfoHelper::supportsService( ServiceName, getSupportedServiceNames() );
201 }
202 
getSupportedServiceNames()203 uno::Sequence< OUString > SAL_CALL SdUnoPageBackground::getSupportedServiceNames()
204 	throw(uno::RuntimeException)
205 {
206 	uno::Sequence< OUString > aNameSequence( 2 );
207 	OUString* pStrings = aNameSequence.getArray();
208 
209 	*pStrings++ = OUString( RTL_CONSTASCII_USTRINGPARAM( sUNO_Service_PageBackground ) );
210 	*pStrings   = OUString( RTL_CONSTASCII_USTRINGPARAM( sUNO_Service_FillProperties ) );
211 
212 	return aNameSequence;
213 }
214 
215 // XPropertySet
getPropertySetInfo()216 uno::Reference< beans::XPropertySetInfo > SAL_CALL SdUnoPageBackground::getPropertySetInfo()
217 	throw(uno::RuntimeException)
218 {
219 	return mpPropSet->getPropertySetInfo();
220 }
221 
setPropertyValue(const OUString & aPropertyName,const uno::Any & aValue)222 void SAL_CALL SdUnoPageBackground::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue )
223 	throw(beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
224 {
225 	OGuard aGuard( Application::GetSolarMutex() );
226 
227 	const SfxItemPropertySimpleEntry* pEntry = getPropertyMapEntry( aPropertyName );
228 
229 	if( pEntry == NULL )
230 	{
231 		throw beans::UnknownPropertyException();
232 	}
233 	else
234 	{
235 		if( mpSet )
236 		{
237 			if( pEntry->nWID == OWN_ATTR_FILLBMP_MODE )
238 			{
239 				drawing::BitmapMode eMode;
240 				if( aValue >>= eMode )
241 				{
242 					mpSet->Put( XFillBmpStretchItem( eMode == drawing::BitmapMode_STRETCH ) );
243 					mpSet->Put( XFillBmpTileItem( eMode == drawing::BitmapMode_REPEAT ) );
244 					return;
245 				}
246 				throw lang::IllegalArgumentException();
247 			}
248 
249 			SfxItemPool& rPool = *mpSet->GetPool();
250 			SfxItemSet aSet( rPool,	pEntry->nWID, pEntry->nWID);
251 			aSet.Put( *mpSet );
252 
253 			if( !aSet.Count() )
254 				aSet.Put( rPool.GetDefaultItem( pEntry->nWID ) );
255 
256 			if( pEntry->nMemberId == MID_NAME && ( pEntry->nWID == XATTR_FILLBITMAP || pEntry->nWID == XATTR_FILLGRADIENT || pEntry->nWID == XATTR_FILLHATCH || pEntry->nWID == XATTR_FILLFLOATTRANSPARENCE ) )
257 			{
258 				OUString aName;
259 				if(!(aValue >>= aName ))
260 					throw lang::IllegalArgumentException();
261 
262 				SvxShape::SetFillAttribute( pEntry->nWID, aName, aSet );
263 			}
264 			else
265 			{
266 				SvxItemPropertySet_setPropertyValue( *mpPropSet, pEntry, aValue, aSet );
267 			}
268 
269 			mpSet->Put( aSet );
270 		}
271 		else
272 		{
273 			if(pEntry && pEntry->nWID)
274 				mpPropSet->setPropertyValue( pEntry, aValue );
275 		}
276 	}
277 }
278 
getPropertyValue(const OUString & PropertyName)279 uno::Any SAL_CALL SdUnoPageBackground::getPropertyValue( const OUString& PropertyName )
280 	throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
281 {
282 	OGuard aGuard( Application::GetSolarMutex() );
283 
284 	uno::Any aAny;
285 	const SfxItemPropertySimpleEntry* pEntry = getPropertyMapEntry(PropertyName);
286 
287 	if( pEntry == NULL )
288 	{
289 		throw beans::UnknownPropertyException();
290 	}
291 	else
292 	{
293 		if( mpSet )
294 		{
295 			if( pEntry->nWID == OWN_ATTR_FILLBMP_MODE )
296 			{
297 				XFillBmpStretchItem* pStretchItem = (XFillBmpStretchItem*)mpSet->GetItem(XATTR_FILLBMP_STRETCH);
298 				XFillBmpTileItem* pTileItem = (XFillBmpTileItem*)mpSet->GetItem(XATTR_FILLBMP_TILE);
299 
300 				if( pStretchItem && pTileItem )
301 				{
302 					if( pTileItem->GetValue() )
303 						aAny <<= drawing::BitmapMode_REPEAT;
304 					else if( pStretchItem->GetValue() )
305 						aAny <<= drawing::BitmapMode_STRETCH;
306 					else
307 						aAny <<= drawing::BitmapMode_NO_REPEAT;
308 				}
309 			}
310 			else
311 			{
312 				SfxItemPool& rPool = *mpSet->GetPool();
313 				SfxItemSet aSet( rPool,	pEntry->nWID, pEntry->nWID);
314 				aSet.Put( *mpSet );
315 
316 				if( !aSet.Count() )
317 					aSet.Put( rPool.GetDefaultItem( pEntry->nWID ) );
318 
319 				// Hole Wert aus ItemSet
320 				aAny = SvxItemPropertySet_getPropertyValue( *mpPropSet, pEntry, aSet );
321 			}
322 		}
323 		else
324 		{
325 			if(pEntry && pEntry->nWID)
326 				aAny = mpPropSet->getPropertyValue( pEntry );
327 		}
328 	}
329 	return aAny;
330 }
331 
addPropertyChangeListener(const OUString &,const uno::Reference<beans::XPropertyChangeListener> &)332 void SAL_CALL SdUnoPageBackground::addPropertyChangeListener( const OUString& , const uno::Reference< beans::XPropertyChangeListener >&  ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {}
removePropertyChangeListener(const OUString &,const uno::Reference<beans::XPropertyChangeListener> &)333 void SAL_CALL SdUnoPageBackground::removePropertyChangeListener( const OUString& , const uno::Reference< beans::XPropertyChangeListener >&  ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {}
addVetoableChangeListener(const OUString &,const uno::Reference<beans::XVetoableChangeListener> &)334 void SAL_CALL SdUnoPageBackground::addVetoableChangeListener( const OUString& , const uno::Reference< beans::XVetoableChangeListener >&  ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {}
removeVetoableChangeListener(const OUString &,const uno::Reference<beans::XVetoableChangeListener> &)335 void SAL_CALL SdUnoPageBackground::removeVetoableChangeListener( const OUString& , const uno::Reference< beans::XVetoableChangeListener >&  ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {}
336 
337 // XPropertyState
getPropertyState(const OUString & PropertyName)338 beans::PropertyState SAL_CALL SdUnoPageBackground::getPropertyState( const OUString& PropertyName )
339 	throw(beans::UnknownPropertyException, uno::RuntimeException)
340 {
341 	OGuard aGuard( Application::GetSolarMutex() );
342 
343 	const SfxItemPropertySimpleEntry* pEntry = getPropertyMapEntry(PropertyName);
344 
345 	if( pEntry == NULL )
346 		throw beans::UnknownPropertyException();
347 
348 	if( mpSet )
349 	{
350 		if( pEntry->nWID == OWN_ATTR_FILLBMP_MODE )
351 		{
352 			if( mpSet->GetItemState( XATTR_FILLBMP_STRETCH, false ) == SFX_ITEM_SET ||
353 				mpSet->GetItemState( XATTR_FILLBMP_TILE, false ) == SFX_ITEM_SET )
354 			{
355 				return beans::PropertyState_DIRECT_VALUE;
356 			}
357 			else
358 			{
359 				return beans::PropertyState_AMBIGUOUS_VALUE;
360 			}
361 		}
362 
363 		switch( mpSet->GetItemState( pEntry->nWID, sal_False ) )
364 		{
365 		case SFX_ITEM_READONLY:
366 		case SFX_ITEM_SET:
367 			return beans::PropertyState_DIRECT_VALUE;
368 		case SFX_ITEM_DEFAULT:
369 			return beans::PropertyState_DEFAULT_VALUE;
370 		default:
371 //		case SFX_ITEM_DONTCARE:
372 //		case SFX_ITEM_DISABLED:
373 			return beans::PropertyState_AMBIGUOUS_VALUE;
374 		}
375 	}
376 	else
377 	{
378 		if( NULL == mpPropSet->GetUsrAnyForID(pEntry->nWID) )
379 			return beans::PropertyState_DEFAULT_VALUE;
380 		else
381 			return beans::PropertyState_DIRECT_VALUE;
382 	}
383 }
384 
getPropertyStates(const uno::Sequence<OUString> & aPropertyName)385 uno::Sequence< beans::PropertyState > SAL_CALL SdUnoPageBackground::getPropertyStates( const uno::Sequence< OUString >& aPropertyName )
386 	throw(beans::UnknownPropertyException, uno::RuntimeException)
387 {
388 	OGuard aGuard( Application::GetSolarMutex() );
389 
390 	sal_Int32 nCount = aPropertyName.getLength();
391 	const OUString* pNames = aPropertyName.getConstArray();
392 
393 	uno::Sequence< beans::PropertyState > aPropertyStateSequence( nCount );
394 	beans::PropertyState* pState = aPropertyStateSequence.getArray();
395 
396 	while( nCount-- )
397 		*pState++ = getPropertyState( *pNames++ );
398 
399 	return aPropertyStateSequence;
400 }
401 
setPropertyToDefault(const OUString & PropertyName)402 void SAL_CALL SdUnoPageBackground::setPropertyToDefault( const OUString& PropertyName )
403 	throw(beans::UnknownPropertyException, uno::RuntimeException)
404 {
405 	OGuard aGuard( Application::GetSolarMutex() );
406 
407 	const SfxItemPropertySimpleEntry* pEntry = getPropertyMapEntry(PropertyName);
408 
409 	if( pEntry == NULL )
410 		throw beans::UnknownPropertyException();
411 
412 	if( mpSet )
413 	{
414 		if( pEntry->nWID == OWN_ATTR_FILLBMP_MODE )
415 		{
416 			mpSet->ClearItem( XATTR_FILLBMP_STRETCH );
417 			mpSet->ClearItem( XATTR_FILLBMP_TILE );
418 		}
419 		else
420 		{
421 			mpSet->ClearItem( pEntry->nWID );
422 		}
423 	}
424 }
425 
getPropertyDefault(const OUString & aPropertyName)426 uno::Any SAL_CALL SdUnoPageBackground::getPropertyDefault( const OUString& aPropertyName )
427 	throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
428 {
429 	OGuard aGuard( Application::GetSolarMutex() );
430 
431 	const SfxItemPropertySimpleEntry* pEntry = getPropertyMapEntry(aPropertyName);
432 	if( pEntry == NULL || mpSet == NULL )
433 		throw beans::UnknownPropertyException();
434 
435 	uno::Any aAny;
436 	if( mpSet )
437 	{
438 		if( pEntry->nWID == OWN_ATTR_FILLBMP_MODE )
439 		{
440 			aAny <<= drawing::BitmapMode_REPEAT;
441 		}
442 		else
443 		{
444 			SfxItemPool& rPool = *mpSet->GetPool();
445 			SfxItemSet aSet( rPool,	pEntry->nWID, pEntry->nWID);
446 			aSet.Put( rPool.GetDefaultItem( pEntry->nWID ) );
447 
448 			aAny = SvxItemPropertySet_getPropertyValue( *mpPropSet, pEntry, aSet );
449 		}
450 	}
451 	return aAny;
452 }
453 
454 /** this is used because our property map is not sorted yet */
getPropertyMapEntry(const OUString & rPropertyName) const455 const SfxItemPropertySimpleEntry* SdUnoPageBackground::getPropertyMapEntry( const OUString& rPropertyName ) const throw()
456 {
457 	return mpPropSet->getPropertyMap()->getByName(rPropertyName);
458 }
459 
460