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