xref: /aoo42x/main/svx/source/unodraw/unoshap4.cxx (revision a5258243)
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_svx.hxx"
30 #include <com/sun/star/util/XModifiable.hpp>
31 #include <com/sun/star/embed/XLinkageSupport.hpp>
32 #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
33 #include <com/sun/star/task/XInteractionHandler.hpp>
34 
35 #define _SVX_USE_UNOGLOBALS_
36 
37 #include <vcl/virdev.hxx>
38 #include <svx/svdoole2.hxx>
39 #include <svx/svdomedia.hxx>
40 #include <svx/svdpool.hxx>
41 #ifndef SVX_LIGHT
42 #ifndef _SOT_CLSIDS_HXX
43 #include <sot/clsids.hxx>
44 #endif
45 #include <sfx2/frmdescr.hxx>
46 #endif
47 #include <vcl/svapp.hxx>
48 #include <vos/mutex.hxx>
49 
50 #include <toolkit/helper/vclunohelper.hxx>
51 #include <sfx2/objsh.hxx>
52 #include <sfx2/docfile.hxx>
53 
54 #include <sot/storage.hxx>
55 #include <sot/exchange.hxx>
56 #include <svtools/FilterConfigItem.hxx>
57 
58 #include <svx/svdmodel.hxx>
59 #include "shapeimpl.hxx"
60 
61 #include <svx/unoshprp.hxx>
62 
63 #include "svx/unoapi.hxx"
64 #include "svx/svdpagv.hxx"
65 #include "svx/svdview.hxx"
66 #include "svx/svdglob.hxx"
67 #include "svx/svdstr.hrc"
68 
69 ///////////////////////////////////////////////////////////////////////
70 
71 extern sal_Bool ConvertGDIMetaFileToWMF( const GDIMetaFile & rMTF, SvStream & rTargetStream, FilterConfigItem* pFilterConfigItem = NULL, sal_Bool bPlaceable = sal_True );
72 
73 ///////////////////////////////////////////////////////////////////////
74 
75 using namespace ::osl;
76 using namespace ::vos;
77 using namespace ::rtl;
78 using namespace ::cppu;
79 using namespace ::com::sun::star;
80 using namespace ::com::sun::star::uno;
81 using namespace ::com::sun::star::lang;
82 using namespace ::com::sun::star::container;
83 using namespace ::com::sun::star::beans;
84 
85 ///////////////////////////////////////////////////////////////////////
86 SvxOle2Shape::SvxOle2Shape( SdrObject* pObject ) throw()
87 : SvxShapeText( pObject, aSvxMapProvider.GetMap(SVXMAP_OLE2), aSvxMapProvider.GetPropertySet(SVXMAP_OLE2, SdrObject::GetGlobalDrawObjectItemPool())  )
88 {
89 }
90 
91 SvxOle2Shape::SvxOle2Shape( SdrObject* pObject, const SfxItemPropertyMapEntry* pPropertyMap, const SvxItemPropertySet* pPropertySet ) throw ()
92 : SvxShapeText( pObject, pPropertyMap, pPropertySet  )
93 {
94 }
95 
96 SvxOle2Shape::~SvxOle2Shape() throw()
97 {
98 }
99 
100 ::com::sun::star::uno::Any SAL_CALL SvxOle2Shape::queryAggregation( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException)
101 {
102 	return SvxShapeText::queryAggregation( rType );
103 }
104 
105 //XPropertySet
106 bool SvxOle2Shape::setPropertyValueImpl( const ::rtl::OUString& rName, const SfxItemPropertySimpleEntry* pProperty, const ::com::sun::star::uno::Any& rValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
107 {
108 	switch( pProperty->nWID )
109 	{
110 /*
111 	case OWN_ATTR_CLSID:
112 	{
113 		OUString aCLSID;
114 		if( rValue >>= aCLSID )
115 		{
116             // init an ole object with a global name
117 			SdrOle2Obj* pOle2 = dynamic_cast< SdrOle2Obj* >( mpObj.get() );
118 			if( pOle2 )
119 			{
120                 uno::Reference < embed::XEmbeddedObject > xObj = pOle2->GetObjRef();
121                 if ( !xObj.is() )
122                 {
123 					SvGlobalName aClassName;
124 					if( aClassName.MakeId( aCLSID ) )
125 					{
126                         SfxObjectShell* pPersist = mpModel->GetPersist();
127                         ::rtl::OUString aPersistName;
128                         Any aAny( getPropertyValue( OUString::createFromAscii( UNO_NAME_OLE2_PERSISTNAME ) ) );
129                         aAny >>= aPersistName;
130 
131                         //TODO/LATER: how to cope with creation failure?!
132                         xObj = pPersist->GetEmbeddedObjectContainer().CreateEmbeddedObject( aClassName.GetByteSequence(), aPersistName );
133                         if( xObj.is() )
134                         {
135                             aAny <<= aPersistName;
136                             setPropertyValue( OUString::createFromAscii( UNO_NAME_OLE2_PERSISTNAME ), aAny );
137                             pOle2->SetObjRef( xObj );
138 
139                             Rectangle aRect = pOle2->GetLogicRect();
140                             awt::Size aSz;
141                             Size aSize( pOle2->GetLogicRect().GetSize() );
142                             aSz.Width = aSize.Width();
143                             aSz.Height = aSize.Height();
144                             xObj->setVisualAreaSize( pOle2->GetAspect(), aSz );
145 						}
146 					}
147                 }
148 			}
149 			return true;
150 		}
151 		break;
152 	}
153 */
154 	case OWN_ATTR_OLE_VISAREA:
155 	{
156 		// TODO/LATER: seems to make no sence for iconified object
157 
158 		awt::Rectangle aVisArea;
159 		if( (rValue >>= aVisArea) && mpObj->ISA(SdrOle2Obj))
160 		{
161 			Size aTmp( aVisArea.X + aVisArea.Width, aVisArea.Y + aVisArea.Height );
162             uno::Reference < embed::XEmbeddedObject > xObj = ((SdrOle2Obj*)mpObj.get())->GetObjRef();
163             if( xObj.is() )
164 			{
165 				try
166 				{
167 					MapUnit aMapUnit( MAP_100TH_MM ); // the API handles with MAP_100TH_MM map mode
168 					MapUnit aObjUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( embed::Aspects::MSOLE_CONTENT ) );
169 					aTmp = OutputDevice::LogicToLogic( aTmp, aMapUnit, aObjUnit );
170 					xObj->setVisualAreaSize( embed::Aspects::MSOLE_CONTENT, awt::Size( aTmp.Width(), aTmp.Height() ) );
171 				}
172 				catch( uno::Exception& )
173 				{
174 					OSL_ENSURE( sal_False, "Couldn't set the visual area for the object!\n" );
175 				}
176 			}
177 
178 			return true;
179 		}
180 		break;
181 	}
182 	case OWN_ATTR_OLE_ASPECT:
183 	{
184 		sal_Int64 nAspect = 0;
185 		if( rValue >>= nAspect )
186 		{
187 			static_cast<SdrOle2Obj*>(mpObj.get())->SetAspect( nAspect );
188 			return true;
189 		}
190 		break;
191 	}
192 	case OWN_ATTR_CLSID:
193 	{
194 		OUString aCLSID;
195 		if( rValue >>= aCLSID )
196 		{
197 			// init a ole object with a global name
198 			SvGlobalName aClassName;
199 			if( aClassName.MakeId( aCLSID ) )
200 			{
201 				if( createObject( aClassName ) )
202 					return true;
203 			}
204 		}
205 		break;
206 	}
207 	case OWN_ATTR_THUMBNAIL:
208 	{
209 		OUString aURL;
210 		if( rValue >>= aURL )
211 		{
212 			GraphicObject aGrafObj( GraphicObject::CreateGraphicObjectFromURL( aURL ) );
213 			static_cast<SdrOle2Obj*>(mpObj.get())->SetGraphic( &aGrafObj.GetGraphic() );
214 			return true;
215 		}
216 		break;
217 	}
218 	case OWN_ATTR_VALUE_GRAPHIC:
219 	{
220 		uno::Reference< graphic::XGraphic > xGraphic( rValue, uno::UNO_QUERY );
221 		if( xGraphic.is() )
222 		{
223 			SdrOle2Obj* pOle = dynamic_cast< SdrOle2Obj* >( mpObj.get() );
224 			if( pOle )
225 			{
226 				GraphicObject aGrafObj( xGraphic );
227 				const Graphic aGraphic( aGrafObj.GetGraphic() );
228 				pOle->SetGraphicToObj( aGraphic, rtl::OUString() );
229 			}
230 			return true;
231 		}
232 		break;
233 	}
234 	case OWN_ATTR_PERSISTNAME:
235     {
236 		OUString aPersistName;
237         if( rValue >>= aPersistName )
238 		{
239 			static_cast<SdrOle2Obj*>(mpObj.get())->SetPersistName( aPersistName );
240             return true;
241 		}
242 		break;
243     }
244 	case OWN_ATTR_OLE_LINKURL:
245 	{
246 		OUString aLinkURL;
247 		if( rValue >>= aLinkURL )
248 		{
249 			createLink( aLinkURL );
250 			return true;
251 		}
252 		break;
253 	}
254 	default:
255         return SvxShapeText::setPropertyValueImpl( rName, pProperty, rValue );
256 	}
257 
258 	throw IllegalArgumentException();
259 }
260 
261 bool SvxOle2Shape::getPropertyValueImpl( const ::rtl::OUString& rName, const SfxItemPropertySimpleEntry* pProperty, ::com::sun::star::uno::Any& rValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
262 {
263 	switch( pProperty->nWID )
264 	{
265 	case OWN_ATTR_CLSID:
266 	{
267 		OUString aCLSID;
268 		SvGlobalName aClassName = GetClassName_Impl(aCLSID);
269 		rValue <<= aCLSID;
270 		break;
271 	}
272 
273 	case OWN_ATTR_INTERNAL_OLE:
274 	{
275 		rtl::OUString sCLSID;
276 		rValue <<= SotExchange::IsInternal( GetClassName_Impl(sCLSID) );
277 		break;
278 	}
279 
280 	case OWN_ATTR_METAFILE:
281 	{
282 		SdrOle2Obj* pObj = dynamic_cast<SdrOle2Obj*>(mpObj.get());
283 		if( pObj )
284 		{
285 			Graphic* pGraphic = pObj->GetGraphic();
286 			if( pGraphic )
287 			{
288 				sal_Bool bIsWMF = sal_False;
289 				if ( pGraphic->IsLink() )
290 				{
291 					GfxLink aLnk = pGraphic->GetLink();
292 					if ( aLnk.GetType() == GFX_LINK_TYPE_NATIVE_WMF )
293 					{
294 						bIsWMF = sal_True;
295 						uno::Sequence<sal_Int8> aSeq((sal_Int8*)aLnk.GetData(), (sal_Int32) aLnk.GetDataSize());
296 						rValue <<= aSeq;
297 					}
298 				}
299 				if ( !bIsWMF )
300 				{
301 					GDIMetaFile aMtf;
302 					if ( pGraphic->GetType() != GRAPHIC_BITMAP )
303 						aMtf = pObj->GetGraphic()->GetGDIMetaFile();
304 					else
305 					{
306 						VirtualDevice aVirDev;
307 						aMtf.Record( &aVirDev );
308 						pGraphic->Draw( &aVirDev, Point(),  pGraphic->GetPrefSize() );
309 						aMtf.Stop();
310 						aMtf.SetPrefSize( pGraphic->GetPrefSize() );
311 						aMtf.SetPrefMapMode( pGraphic->GetPrefMapMode() );
312 					}
313 					SvMemoryStream aDestStrm( 65535, 65535 );
314 					ConvertGDIMetaFileToWMF( aMtf, aDestStrm, NULL, sal_False );
315                     const uno::Sequence<sal_Int8> aSeq(
316                         static_cast< const sal_Int8* >(aDestStrm.GetData()),
317                         aDestStrm.GetEndOfData());
318 					rValue <<= aSeq;
319 				}
320 			}
321 		}
322 		else
323 		{
324 			rValue = GetBitmap( sal_True );
325 		}
326 		break;
327 	}
328 
329 	case OWN_ATTR_OLE_VISAREA:
330 	{
331 		awt::Rectangle aVisArea;
332 		if( mpObj->ISA(SdrOle2Obj))
333 		{
334 			MapMode aMapMode( MAP_100TH_MM ); // the API uses this map mode
335 			Size aTmp = ((SdrOle2Obj*)mpObj.get())->GetOrigObjSize( &aMapMode ); // get the size in the requested map mode
336 			aVisArea = awt::Rectangle( 0, 0, aTmp.Width(), aTmp.Height() );
337 		}
338 
339 		rValue <<= aVisArea;
340 		break;
341 	}
342 
343 	case OWN_ATTR_OLESIZE:
344 	{
345 		Size aTmp( static_cast<SdrOle2Obj*>(mpObj.get())->GetOrigObjSize() );
346 		rValue <<= awt::Size( aTmp.Width(), aTmp.Height() );
347 		break;
348 	}
349 
350 	case OWN_ATTR_OLE_ASPECT:
351 	{
352 		rValue <<= static_cast<SdrOle2Obj*>(mpObj.get())->GetAspect();
353 		break;
354 	}
355 
356 	case OWN_ATTR_OLEMODEL:
357 	case OWN_ATTR_OLE_EMBEDDED_OBJECT:
358 	case OWN_ATTR_OLE_EMBEDDED_OBJECT_NONEWCLIENT:
359 	{
360 		SdrOle2Obj* pObj = dynamic_cast<SdrOle2Obj*>( mpObj.get() );
361 		if( pObj )
362 		{
363             uno::Reference < embed::XEmbeddedObject > xObj( pObj->GetObjRef() );
364             if ( xObj.is()
365 			  && ( pProperty->nWID == OWN_ATTR_OLE_EMBEDDED_OBJECT || pProperty->nWID == OWN_ATTR_OLE_EMBEDDED_OBJECT_NONEWCLIENT || svt::EmbeddedObjectRef::TryRunningState( xObj ) ) )
366 			{
367 				// Discussed with CL fue to the before GetPaintingPageView
368 				// usage. Removed it, former fallback is used now
369                 if ( pProperty->nWID == OWN_ATTR_OLEMODEL || pProperty->nWID == OWN_ATTR_OLE_EMBEDDED_OBJECT )
370                 {
371 #ifdef DBG_UTIL
372 				    const sal_Bool bSuccess(pObj->AddOwnLightClient());
373 				    OSL_ENSURE( bSuccess, "An object without client is provided!" );
374 #else
375 				    pObj->AddOwnLightClient();
376 #endif
377                 }
378 
379 				if ( pProperty->nWID == OWN_ATTR_OLEMODEL )
380 					rValue <<= pObj->GetObjRef()->getComponent();
381 				else
382 					rValue <<= xObj;
383 			}
384 		}
385 		break;
386 	}
387 
388 	case OWN_ATTR_VALUE_GRAPHIC:
389 	{
390 		uno::Reference< graphic::XGraphic > xGraphic;
391 		Graphic* pGraphic = static_cast<SdrOle2Obj*>( mpObj.get() )->GetGraphic();
392 		if( pGraphic )
393 			xGraphic = pGraphic->GetXGraphic();
394 		rValue <<= xGraphic;
395 		break;
396 	}
397 
398 	case OWN_ATTR_THUMBNAIL:
399 	{
400 		OUString    aURL;
401 		SdrOle2Obj* pOle = dynamic_cast< SdrOle2Obj* >( mpObj.get() );
402         if( pOle )
403 		{
404 			Graphic* pGraphic = pOle->GetGraphic();
405 
406 			// if there isn't already a preview graphic set, check if we need to generate
407 			// one if model says so
408 			if( pGraphic == NULL && !pOle->IsEmptyPresObj() && mpModel->IsSaveOLEPreview() )
409                 pGraphic = pOle->GetGraphic();
410 
411 			if( pGraphic )
412 			{
413 				GraphicObject aObj( *pGraphic );
414 				aURL = OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_NAME_GRAPHOBJ_URLPREFIX));
415 				aURL += OUString::createFromAscii( aObj.GetUniqueID().GetBuffer() );
416 			}
417 		}
418 		rValue <<= aURL;
419 		break;
420 	}
421 	case OWN_ATTR_PERSISTNAME:
422     {
423 		OUString    aPersistName;
424 		SdrOle2Obj* pOle = dynamic_cast< SdrOle2Obj* >( mpObj.get() );
425 
426         if( pOle )
427 		{
428             aPersistName = pOle->GetPersistName();
429 			if( aPersistName.getLength() )
430 			{
431                 ::comphelper::IEmbeddedHelper *pPersist = mpObj->GetModel()->GetPersist();
432                 if( (NULL == pPersist) || !pPersist->getEmbeddedObjectContainer().HasEmbeddedObject( pOle->GetPersistName() ) )
433 					aPersistName = OUString();
434 			}
435 		}
436 
437 		rValue <<= aPersistName;
438 		break;
439     }
440 	case OWN_ATTR_OLE_LINKURL:
441 	{
442 		OUString    aLinkURL;
443 		SdrOle2Obj* pOle = dynamic_cast< SdrOle2Obj* >( mpObj.get() );
444 
445         if( pOle )
446 		{
447 			uno::Reference< embed::XLinkageSupport > xLink( pOle->GetObjRef(), uno::UNO_QUERY );
448 			if ( xLink.is() && xLink->isLink() )
449 				aLinkURL = xLink->getLinkURL();
450 		}
451 
452 		rValue <<= aLinkURL;
453 		break;
454 	}
455 	default:
456         return SvxShapeText::getPropertyValueImpl( rName, pProperty, rValue );
457 	}
458 
459 	return true;
460 }
461 
462 sal_Bool SvxOle2Shape::createObject( const SvGlobalName &aClassName )
463 {
464     DBG_TESTSOLARMUTEX();
465 
466 	SdrOle2Obj* pOle2Obj = dynamic_cast< SdrOle2Obj* >( mpObj.get() );
467     if ( !pOle2Obj || !pOle2Obj->IsEmpty() )
468 		return sal_False;
469 
470 	// create storage and inplace object
471     ::comphelper::IEmbeddedHelper*     pPersist = mpModel->GetPersist();
472     ::rtl::OUString              aPersistName;
473     OUString            aTmpStr;
474 	if( getPropertyValue( OUString::createFromAscii( UNO_NAME_OLE2_PERSISTNAME ) ) >>= aTmpStr )
475         aPersistName = aTmpStr;
476 
477     //TODO/LATER: how to cope with creation failure?!
478     uno::Reference < embed::XEmbeddedObject > xObj( pPersist->getEmbeddedObjectContainer().CreateEmbeddedObject( aClassName.GetByteSequence(), aPersistName ) );
479     if( xObj.is() )
480     {
481         Rectangle aRect = pOle2Obj->GetLogicRect();
482         if ( aRect.GetWidth() == 100 && aRect.GetHeight() == 100 )
483         {
484 			// TODO/LATER: is it possible that this method is used to create an iconified object?
485             // default size
486 			try
487 			{
488             	awt::Size aSz = xObj->getVisualAreaSize( pOle2Obj->GetAspect() );
489             	aRect.SetSize( Size( aSz.Width, aSz.Height ) );
490 			}
491 			catch( embed::NoVisualAreaSizeException& )
492 			{}
493             pOle2Obj->SetLogicRect( aRect );
494         }
495         else
496         {
497             awt::Size aSz;
498             Size aSize = pOle2Obj->GetLogicRect().GetSize();
499             aSz.Width = aSize.Width();
500             aSz.Height = aSize.Height();
501 			xObj->setVisualAreaSize(  pOle2Obj->GetAspect(), aSz );
502         }
503 
504 		// connect the object after the visual area is set
505         setPropertyValue( OUString::createFromAscii( UNO_NAME_OLE2_PERSISTNAME ), Any( aTmpStr = aPersistName ) );
506 
507 		// the object is inserted during setting of PersistName property usually
508 		if( pOle2Obj->IsEmpty() )
509 			pOle2Obj->SetObjRef( xObj );
510     }
511 
512     return xObj.is();
513 }
514 
515 sal_Bool SvxOle2Shape::createLink( const ::rtl::OUString& aLinkURL )
516 {
517     DBG_TESTSOLARMUTEX();
518 
519 	SdrOle2Obj* pOle2Obj = dynamic_cast< SdrOle2Obj* >( mpObj.get() );
520     if ( !pOle2Obj || !pOle2Obj->IsEmpty() )
521 		return sal_False;
522 
523     ::rtl::OUString aPersistName;
524 
525     ::comphelper::IEmbeddedHelper* pPersist = mpModel->GetPersist();
526 
527 	uno::Sequence< beans::PropertyValue > aMediaDescr( 1 );
528 	aMediaDescr[0].Name = ::rtl::OUString::createFromAscii( "URL" );
529 	aMediaDescr[0].Value <<= aLinkURL;
530 
531 	uno::Reference< task::XInteractionHandler > xInteraction = pPersist->getInteractionHandler();
532 	if ( xInteraction.is() )
533 	{
534 		aMediaDescr.realloc( 2 );
535 		aMediaDescr[1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "InteractionHandler" ) );
536 		aMediaDescr[1].Value <<= xInteraction;
537 	}
538 
539     //TODO/LATER: how to cope with creation failure?!
540 	uno::Reference< embed::XEmbeddedObject > xObj =
541 			pPersist->getEmbeddedObjectContainer().InsertEmbeddedLink( aMediaDescr , aPersistName );
542 
543     if( xObj.is() )
544     {
545         Rectangle aRect = pOle2Obj->GetLogicRect();
546         if ( aRect.GetWidth() == 100 && aRect.GetHeight() == 100 )
547         {
548             // default size
549 			try
550 			{
551             	awt::Size aSz = xObj->getVisualAreaSize( pOle2Obj->GetAspect() );
552             	aRect.SetSize( Size( aSz.Width, aSz.Height ) );
553 			}
554 			catch( embed::NoVisualAreaSizeException& )
555 			{}
556 			pOle2Obj->SetLogicRect( aRect );
557         }
558         else
559         {
560             awt::Size aSz;
561             Size aSize = pOle2Obj->GetLogicRect().GetSize();
562             aSz.Width = aSize.Width();
563             aSz.Height = aSize.Height();
564             xObj->setVisualAreaSize(  pOle2Obj->GetAspect(), aSz );
565         }
566 
567 		// connect the object after the visual area is set
568         setPropertyValue( OUString::createFromAscii( UNO_NAME_OLE2_PERSISTNAME ), uno::makeAny( aPersistName ) );
569 
570 		// the object is inserted during setting of PersistName property usually
571 		if ( pOle2Obj->IsEmpty() )
572 			pOle2Obj->SetObjRef( xObj );
573     }
574 
575     return xObj.is();
576 }
577 
578 void SvxOle2Shape::resetModifiedState()
579 {
580 	::comphelper::IEmbeddedHelper* pPersist = mpModel ? mpModel->GetPersist() : 0;
581 	if( pPersist && !pPersist->isEnableSetModified() )
582 	{
583 		SdrOle2Obj* pOle = dynamic_cast< SdrOle2Obj* >( mpObj.get() );
584         if( pOle && !pOle->IsEmpty() )
585 		{
586             uno::Reference < util::XModifiable > xMod( pOle->GetObjRef(), uno::UNO_QUERY );
587             if( xMod.is() )
588                 // TODO/MBA: what's this?!
589                 xMod->setModified( sal_False );
590 		}
591 	}
592 }
593 
594 const SvGlobalName SvxOle2Shape::GetClassName_Impl(rtl::OUString& rHexCLSID)
595 {
596     DBG_TESTSOLARMUTEX();
597 	SvGlobalName aClassName;
598 	SdrOle2Obj* pOle2Obj = dynamic_cast< SdrOle2Obj* >( mpObj.get() );
599 
600 	if( pOle2Obj )
601 	{
602 		rHexCLSID = rtl::OUString();
603 
604 		if( pOle2Obj->IsEmpty() )
605 		{
606             ::comphelper::IEmbeddedHelper* pPersist = mpModel->GetPersist();
607             if( pPersist )
608 			{
609                 uno::Reference < embed::XEmbeddedObject > xObj =
610                         pPersist->getEmbeddedObjectContainer().GetEmbeddedObject( pOle2Obj->GetPersistName() );
611                 if ( xObj.is() )
612 				{
613                     aClassName = SvGlobalName( xObj->getClassID() );
614 					rHexCLSID = aClassName.GetHexName();
615 				}
616             }
617 		}
618 
619         if (!rHexCLSID.getLength())
620 		{
621             uno::Reference < embed::XEmbeddedObject > xObj( pOle2Obj->GetObjRef() );
622             if ( xObj.is() )
623 			{
624                 aClassName = SvGlobalName( xObj->getClassID() );
625 				rHexCLSID = aClassName.GetHexName();
626             }
627 		}
628 	}
629 
630     return aClassName;
631 }
632 
633 ///////////////////////////////////////////////////////////////////////
634 
635 SvxAppletShape::SvxAppletShape( SdrObject* pObject ) throw()
636 : SvxOle2Shape( pObject, aSvxMapProvider.GetMap(SVXMAP_APPLET), aSvxMapProvider.GetPropertySet(SVXMAP_APPLET, SdrObject::GetGlobalDrawObjectItemPool())  )
637 {
638 	SetShapeType( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.AppletShape" ) ) );
639 }
640 
641 SvxAppletShape::~SvxAppletShape() throw()
642 {
643 }
644 
645 void SvxAppletShape::Create( SdrObject* pNewObj, SvxDrawPage* pNewPage )
646 {
647 	SvxShape::Create( pNewObj, pNewPage );
648 	const SvGlobalName aAppletClassId( SO3_APPLET_CLASSID );
649 	createObject(aAppletClassId);
650 	SetShapeType( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.AppletShape" ) ) );
651 }
652 
653 void SAL_CALL SvxAppletShape::setPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& rValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
654 {
655 	SvxShape::setPropertyValue( aPropertyName, rValue );
656 	resetModifiedState();
657 }
658 
659 void SAL_CALL SvxAppletShape::setPropertyValues( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aPropertyNames, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& rValues ) throw (::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
660 {
661 	SvxShape::setPropertyValues( aPropertyNames, rValues );
662 	resetModifiedState();
663 }
664 
665 bool SvxAppletShape::setPropertyValueImpl( const ::rtl::OUString& rName, const SfxItemPropertySimpleEntry* pProperty, const ::com::sun::star::uno::Any& rValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
666 {
667 	if( (pProperty->nWID >= OWN_ATTR_APPLET_DOCBASE) && (pProperty->nWID <= OWN_ATTR_APPLET_ISSCRIPT) )
668 	{
669         if ( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef() ) )
670 		{
671 	        uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef()->getComponent(), uno::UNO_QUERY );
672 		    if( xSet.is() )
673 			{
674 				// allow exceptions to pass through
675                 xSet->setPropertyValue( rName, rValue );
676 			}
677 		}
678 		return true;
679 	}
680 	else
681 	{
682         return SvxOle2Shape::setPropertyValueImpl( rName, pProperty, rValue );
683 	}
684 }
685 
686 bool SvxAppletShape::getPropertyValueImpl( const ::rtl::OUString& rName, const SfxItemPropertySimpleEntry* pProperty, ::com::sun::star::uno::Any& rValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
687 {
688     if( (pProperty->nWID >= OWN_ATTR_APPLET_DOCBASE) && (pProperty->nWID <= OWN_ATTR_APPLET_ISSCRIPT) )
689 	{
690         if ( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef() ) )
691 		{
692 			uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef()->getComponent(), uno::UNO_QUERY );
693 			if( xSet.is() )
694 			{
695                 rValue = xSet->getPropertyValue( rName );
696 			}
697         }
698 		return true;
699 	}
700 	else
701 	{
702         return SvxOle2Shape::getPropertyValueImpl( rName, pProperty, rValue );
703 	}
704 }
705 
706 ///////////////////////////////////////////////////////////////////////
707 
708 SvxPluginShape::SvxPluginShape( SdrObject* pObject ) throw()
709 : SvxOle2Shape( pObject, aSvxMapProvider.GetMap(SVXMAP_PLUGIN), aSvxMapProvider.GetPropertySet(SVXMAP_PLUGIN, SdrObject::GetGlobalDrawObjectItemPool()) )
710 {
711 	SetShapeType( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.PluginShape" ) ) );
712 }
713 
714 SvxPluginShape::~SvxPluginShape() throw()
715 {
716 }
717 
718 void SvxPluginShape::Create( SdrObject* pNewObj, SvxDrawPage* pNewPage )
719 {
720 	SvxShape::Create( pNewObj, pNewPage );
721 	const SvGlobalName aPluginClassId( SO3_PLUGIN_CLASSID );
722 	createObject(aPluginClassId);
723 	SetShapeType( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.PluginShape" ) ) );
724 }
725 
726 void SAL_CALL SvxPluginShape::setPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& rValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
727 {
728 	SvxShape::setPropertyValue( aPropertyName, rValue );
729 	resetModifiedState();
730 }
731 
732 void SAL_CALL SvxPluginShape::setPropertyValues( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aPropertyNames, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& rValues ) throw (::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
733 {
734 	SvxShape::setPropertyValues( aPropertyNames, rValues );
735 	resetModifiedState();
736 }
737 
738 bool SvxPluginShape::setPropertyValueImpl( const ::rtl::OUString& rName, const SfxItemPropertySimpleEntry* pProperty, const ::com::sun::star::uno::Any& rValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
739 {
740 	if( (pProperty->nWID >= OWN_ATTR_PLUGIN_MIMETYPE) && (pProperty->nWID <= OWN_ATTR_PLUGIN_COMMANDS) )
741 	{
742         if( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef() ) )
743 		{
744 	        uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef()->getComponent(), uno::UNO_QUERY );
745 			if( xSet.is() )
746 			{
747                 // allow exceptions to pass through
748                 xSet->setPropertyValue( rName, rValue );
749 			}
750 		}
751 		return true;
752 	}
753 	else
754 	{
755         return SvxOle2Shape::setPropertyValueImpl( rName, pProperty, rValue );
756 	}
757 }
758 
759 bool SvxPluginShape::getPropertyValueImpl( const ::rtl::OUString& rName, const SfxItemPropertySimpleEntry* pProperty, ::com::sun::star::uno::Any& rValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
760 {
761 	if( (pProperty->nWID >= OWN_ATTR_PLUGIN_MIMETYPE) && (pProperty->nWID <= OWN_ATTR_PLUGIN_COMMANDS) )
762 	{
763 		if( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef() ) )
764 		{
765 			uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef()->getComponent(), uno::UNO_QUERY );
766 			if( xSet.is() )
767 			{
768                 rValue <<= xSet->getPropertyValue( rName );
769             }
770 		}
771 		return true;
772 	}
773 	else
774 	{
775         return SvxOle2Shape::getPropertyValueImpl( rName, pProperty, rValue );
776 	}
777 }
778 
779 ///////////////////////////////////////////////////////////////////////
780 
781 SvxFrameShape::SvxFrameShape( SdrObject* pObject ) throw()
782 : SvxOle2Shape( pObject, aSvxMapProvider.GetMap(SVXMAP_FRAME), aSvxMapProvider.GetPropertySet(SVXMAP_FRAME, SdrObject::GetGlobalDrawObjectItemPool())  )
783 {
784 	SetShapeType( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.FrameShape" ) ) );
785 }
786 
787 SvxFrameShape::~SvxFrameShape() throw()
788 {
789 }
790 
791 void SvxFrameShape::Create( SdrObject* pNewObj, SvxDrawPage* pNewPage ) throw ()
792 {
793 	SvxShape::Create( pNewObj, pNewPage );
794 	const SvGlobalName aIFrameClassId( SO3_IFRAME_CLASSID );
795 	createObject(aIFrameClassId);
796 	SetShapeType( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.FrameShape" ) ) );
797 }
798 
799 void SAL_CALL SvxFrameShape::setPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& rValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
800 {
801 	SvxShape::setPropertyValue( aPropertyName, rValue );
802 	resetModifiedState();
803 }
804 
805 void SAL_CALL SvxFrameShape::setPropertyValues( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aPropertyNames, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& rValues ) throw (::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
806 {
807 	SvxShape::setPropertyValues( aPropertyNames, rValues );
808 	resetModifiedState();
809 }
810 
811 bool SvxFrameShape::setPropertyValueImpl( const ::rtl::OUString& rName, const SfxItemPropertySimpleEntry* pProperty, const ::com::sun::star::uno::Any& rValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
812 {
813 	if( (pProperty->nWID >= OWN_ATTR_FRAME_URL) && (pProperty->nWID <= OWN_ATTR_FRAME_MARGIN_HEIGHT) )
814 	{
815 		if( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef() ) )
816 		{
817 			uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef()->getComponent(), uno::UNO_QUERY );
818 			if( xSet.is() )
819 			{
820 				// allow exceptions to pass through
821                 xSet->setPropertyValue( rName, rValue );
822 			}
823 		}
824 		return true;
825 	}
826 	else
827 	{
828         return SvxOle2Shape::setPropertyValueImpl( rName, pProperty, rValue );
829 	}
830 }
831 
832 bool SvxFrameShape::getPropertyValueImpl( const ::rtl::OUString& rName, const SfxItemPropertySimpleEntry* pProperty, ::com::sun::star::uno::Any& rValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
833 {
834 	if( (pProperty->nWID >= OWN_ATTR_FRAME_URL) && (pProperty->nWID <= OWN_ATTR_FRAME_MARGIN_HEIGHT) )
835 	{
836 		if( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef() ) )
837 		{
838 			uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef()->getComponent(), uno::UNO_QUERY );
839 			if( xSet.is() )
840 			{
841                 rValue <<= xSet->getPropertyValue( rName );
842 			}
843 		}
844 		return true;
845 	}
846 	else
847 	{
848         return SvxOle2Shape::getPropertyValueImpl( rName, pProperty, rValue );
849 	}
850 }
851 
852 /***********************************************************************
853 *                                                                      *
854 ***********************************************************************/
855 
856 SvxMediaShape::SvxMediaShape( SdrObject* pObj ) throw()
857 :	SvxShape( pObj, aSvxMapProvider.GetMap(SVXMAP_MEDIA), aSvxMapProvider.GetPropertySet(SVXMAP_MEDIA, SdrObject::GetGlobalDrawObjectItemPool()) )
858 {
859 	SetShapeType( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.MediaShape" ) ) );
860 }
861 
862 //----------------------------------------------------------------------
863 SvxMediaShape::~SvxMediaShape() throw()
864 {
865 }
866 
867 //----------------------------------------------------------------------
868 
869 bool SvxMediaShape::setPropertyValueImpl( const ::rtl::OUString& rName, const SfxItemPropertySimpleEntry* pProperty, const ::com::sun::star::uno::Any& rValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
870 {
871 	if( (pProperty->nWID >= OWN_ATTR_MEDIA_URL) && (pProperty->nWID <= OWN_ATTR_MEDIA_ZOOM) )
872 	{
873 		SdrMediaObj* pMedia = static_cast< SdrMediaObj* >( mpObj.get() );
874 		::avmedia::MediaItem aItem;
875 		bool bOk = false;
876 
877 		switch( pProperty->nWID )
878 		{
879 		case OWN_ATTR_MEDIA_URL:
880 		{
881 			OUString aURL;
882 			if( rValue >>= aURL )
883 			{
884 				bOk = true;
885 				aItem.setURL( aURL );
886 			}
887 		}
888 		break;
889 
890 		case( OWN_ATTR_MEDIA_LOOP ):
891 		{
892 			sal_Bool bLoop = sal_Bool();
893 
894 			if( rValue >>= bLoop )
895 			{
896 				bOk = true;
897 				aItem.setLoop( bLoop );
898 			}
899 		}
900 		break;
901 
902 		case( OWN_ATTR_MEDIA_MUTE ):
903 		{
904 			sal_Bool bMute = sal_Bool();
905 
906 			if( rValue >>= bMute )
907 			{
908 				bOk = true;
909 				aItem.setMute( bMute );
910 			}
911 		}
912 		break;
913 
914 		case( OWN_ATTR_MEDIA_VOLUMEDB ):
915 		{
916 			sal_Int16 nVolumeDB = sal_Int16();
917 
918 			if( rValue >>= nVolumeDB )
919 			{
920 				bOk = true;
921 				aItem.setVolumeDB( nVolumeDB );
922 			}
923 		}
924 		break;
925 
926 		case( OWN_ATTR_MEDIA_ZOOM ):
927 		{
928 			::com::sun::star::media::ZoomLevel eLevel;
929 
930 			if( rValue >>= eLevel )
931 			{
932 				bOk = true;
933 				aItem.setZoom( eLevel );
934 			}
935 		}
936 		break;
937 
938 		default:
939 			DBG_ERROR("SvxMediaShape::setPropertyValueImpl(), unknown argument!");
940 		}
941 
942 		if( bOk )
943 		{
944 			pMedia->setMediaProperties( aItem );
945 			return true;
946 		}
947 	}
948 	else
949 	{
950         return SvxShape::setPropertyValueImpl( rName, pProperty, rValue );
951 	}
952 
953 	throw IllegalArgumentException();
954 }
955 
956 //----------------------------------------------------------------------
957 
958 bool SvxMediaShape::getPropertyValueImpl( const ::rtl::OUString& rName, const SfxItemPropertySimpleEntry* pProperty, ::com::sun::star::uno::Any& rValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
959 {
960 	if( ( pProperty->nWID >= OWN_ATTR_MEDIA_URL ) && ( pProperty->nWID <= OWN_ATTR_MEDIA_ZOOM ) )
961 	{
962 		SdrMediaObj* pMedia = static_cast< SdrMediaObj* >( mpObj.get() );
963 		const ::avmedia::MediaItem aItem( pMedia->getMediaProperties() );
964 
965 		switch( pProperty->nWID )
966 		{
967 			case OWN_ATTR_MEDIA_URL:
968 				rValue <<= aItem.getURL();
969 				break;
970 
971 			case( OWN_ATTR_MEDIA_LOOP ):
972 				rValue <<= (sal_Bool) aItem.isLoop();
973 				break;
974 
975 			case( OWN_ATTR_MEDIA_MUTE ):
976 				rValue <<= (sal_Bool) aItem.isMute();
977 				break;
978 
979 			case( OWN_ATTR_MEDIA_VOLUMEDB ):
980 				rValue <<= (sal_Int16) aItem.getVolumeDB();
981 				break;
982 
983 			case( OWN_ATTR_MEDIA_ZOOM ):
984 				rValue <<= aItem.getZoom();
985 				break;
986 
987 			default:
988 				DBG_ERROR("SvxMediaShape::getPropertyValueImpl(), unknown property!");
989 		}
990 		return true;
991 	}
992 	else
993 	{
994         return SvxShape::getPropertyValueImpl( rName, pProperty, rValue );
995 	}
996 }
997