xref: /trunk/main/svx/source/unodraw/unoshap4.cxx (revision cb0a2370)
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 ///////////////////////////////////////////////////////////////////////
SvxOle2Shape(SdrObject * pObject)82 SvxOle2Shape::SvxOle2Shape( SdrObject* pObject ) throw()
83 : SvxShapeText( pObject, aSvxMapProvider.GetMap(SVXMAP_OLE2), aSvxMapProvider.GetPropertySet(SVXMAP_OLE2, SdrObject::GetGlobalDrawObjectItemPool())  )
84 {
85 }
86 
SvxOle2Shape(SdrObject * pObject,const SfxItemPropertyMapEntry * pPropertyMap,const SvxItemPropertySet * pPropertySet)87 SvxOle2Shape::SvxOle2Shape( SdrObject* pObject, const SfxItemPropertyMapEntry* pPropertyMap, const SvxItemPropertySet* pPropertySet ) throw ()
88 : SvxShapeText( pObject, pPropertyMap, pPropertySet  )
89 {
90 }
91 
~SvxOle2Shape()92 SvxOle2Shape::~SvxOle2Shape() throw()
93 {
94 }
95 
queryAggregation(const::com::sun::star::uno::Type & rType)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
setPropertyValueImpl(const::rtl::OUString & rName,const SfxItemPropertySimpleEntry * pProperty,const::com::sun::star::uno::Any & rValue)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 
getPropertyValueImpl(const::rtl::OUString & rName,const SfxItemPropertySimpleEntry * pProperty,::com::sun::star::uno::Any & rValue)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                     // #119735# just use GetGDIMetaFile, it will create a bufferd version of contained bitmap now automatically
298 					GDIMetaFile aMtf(pObj->GetGraphic()->GetGDIMetaFile());
299 					SvMemoryStream aDestStrm( 65535, 65535 );
300 					ConvertGDIMetaFileToWMF( aMtf, aDestStrm, NULL, sal_False );
301                     const uno::Sequence<sal_Int8> aSeq(
302                         static_cast< const sal_Int8* >(aDestStrm.GetData()),
303                         aDestStrm.GetEndOfData());
304 					rValue <<= aSeq;
305 				}
306 			}
307 		}
308 		else
309 		{
310 			rValue = GetBitmap( sal_True );
311 		}
312 		break;
313 	}
314 
315 	case OWN_ATTR_OLE_VISAREA:
316 	{
317 		awt::Rectangle aVisArea;
318 		if( mpObj->ISA(SdrOle2Obj))
319 		{
320 			MapMode aMapMode( MAP_100TH_MM ); // the API uses this map mode
321 			Size aTmp = ((SdrOle2Obj*)mpObj.get())->GetOrigObjSize( &aMapMode ); // get the size in the requested map mode
322 			aVisArea = awt::Rectangle( 0, 0, aTmp.Width(), aTmp.Height() );
323 		}
324 
325 		rValue <<= aVisArea;
326 		break;
327 	}
328 
329 	case OWN_ATTR_OLESIZE:
330 	{
331 		Size aTmp( static_cast<SdrOle2Obj*>(mpObj.get())->GetOrigObjSize() );
332 		rValue <<= awt::Size( aTmp.Width(), aTmp.Height() );
333 		break;
334 	}
335 
336 	case OWN_ATTR_OLE_ASPECT:
337 	{
338 		rValue <<= static_cast<SdrOle2Obj*>(mpObj.get())->GetAspect();
339 		break;
340 	}
341 
342 	case OWN_ATTR_OLEMODEL:
343 	case OWN_ATTR_OLE_EMBEDDED_OBJECT:
344 	case OWN_ATTR_OLE_EMBEDDED_OBJECT_NONEWCLIENT:
345 	{
346 		SdrOle2Obj* pObj = dynamic_cast<SdrOle2Obj*>( mpObj.get() );
347 		if( pObj )
348 		{
349             uno::Reference < embed::XEmbeddedObject > xObj( pObj->GetObjRef() );
350             if ( xObj.is()
351 			  && ( pProperty->nWID == OWN_ATTR_OLE_EMBEDDED_OBJECT || pProperty->nWID == OWN_ATTR_OLE_EMBEDDED_OBJECT_NONEWCLIENT || svt::EmbeddedObjectRef::TryRunningState( xObj ) ) )
352 			{
353 				// Discussed with CL fue to the before GetPaintingPageView
354 				// usage. Removed it, former fallback is used now
355                 if ( pProperty->nWID == OWN_ATTR_OLEMODEL || pProperty->nWID == OWN_ATTR_OLE_EMBEDDED_OBJECT )
356                 {
357 #ifdef DBG_UTIL
358 				    const sal_Bool bSuccess(pObj->AddOwnLightClient());
359 				    OSL_ENSURE( bSuccess, "An object without client is provided!" );
360 #else
361 				    pObj->AddOwnLightClient();
362 #endif
363                 }
364 
365 				if ( pProperty->nWID == OWN_ATTR_OLEMODEL )
366 					rValue <<= pObj->GetObjRef()->getComponent();
367 				else
368 					rValue <<= xObj;
369 			}
370 		}
371 		break;
372 	}
373 
374 	case OWN_ATTR_VALUE_GRAPHIC:
375 	{
376 		uno::Reference< graphic::XGraphic > xGraphic;
377 		Graphic* pGraphic = static_cast<SdrOle2Obj*>( mpObj.get() )->GetGraphic();
378 		if( pGraphic )
379 			xGraphic = pGraphic->GetXGraphic();
380 		rValue <<= xGraphic;
381 		break;
382 	}
383 
384 	case OWN_ATTR_THUMBNAIL:
385 	{
386 		OUString    aURL;
387 		SdrOle2Obj* pOle = dynamic_cast< SdrOle2Obj* >( mpObj.get() );
388         if( pOle )
389 		{
390 			Graphic* pGraphic = pOle->GetGraphic();
391 
392 			// if there isn't already a preview graphic set, check if we need to generate
393 			// one if model says so
394 			if( pGraphic == NULL && !pOle->IsEmptyPresObj() && mpModel->IsSaveOLEPreview() )
395                 pGraphic = pOle->GetGraphic();
396 
397 			if( pGraphic )
398 			{
399 				GraphicObject aObj( *pGraphic );
400 				aURL = OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_NAME_GRAPHOBJ_URLPREFIX));
401 				aURL += OUString::createFromAscii( aObj.GetUniqueID().GetBuffer() );
402 			}
403 		}
404 		rValue <<= aURL;
405 		break;
406 	}
407 	case OWN_ATTR_PERSISTNAME:
408     {
409 		OUString    aPersistName;
410 		SdrOle2Obj* pOle = dynamic_cast< SdrOle2Obj* >( mpObj.get() );
411 
412         if( pOle )
413 		{
414             aPersistName = pOle->GetPersistName();
415 			if( aPersistName.getLength() )
416 			{
417                 ::comphelper::IEmbeddedHelper *pPersist = mpObj->GetModel()->GetPersist();
418                 if( (NULL == pPersist) || !pPersist->getEmbeddedObjectContainer().HasEmbeddedObject( pOle->GetPersistName() ) )
419 					aPersistName = OUString();
420 			}
421 		}
422 
423 		rValue <<= aPersistName;
424 		break;
425     }
426 	case OWN_ATTR_OLE_LINKURL:
427 	{
428 		OUString    aLinkURL;
429 		SdrOle2Obj* pOle = dynamic_cast< SdrOle2Obj* >( mpObj.get() );
430 
431         if( pOle )
432 		{
433 			uno::Reference< embed::XLinkageSupport > xLink( pOle->GetObjRef(), uno::UNO_QUERY );
434 			if ( xLink.is() && xLink->isLink() )
435 				aLinkURL = xLink->getLinkURL();
436 		}
437 
438 		rValue <<= aLinkURL;
439 		break;
440 	}
441 	default:
442         return SvxShapeText::getPropertyValueImpl( rName, pProperty, rValue );
443 	}
444 
445 	return true;
446 }
447 
createObject(const SvGlobalName & aClassName)448 sal_Bool SvxOle2Shape::createObject( const SvGlobalName &aClassName )
449 {
450     DBG_TESTSOLARMUTEX();
451 
452 	SdrOle2Obj* pOle2Obj = dynamic_cast< SdrOle2Obj* >( mpObj.get() );
453     if ( !pOle2Obj || !pOle2Obj->IsEmpty() )
454 		return sal_False;
455 
456 	// create storage and inplace object
457     ::comphelper::IEmbeddedHelper*     pPersist = mpModel->GetPersist();
458     ::rtl::OUString              aPersistName;
459     OUString            aTmpStr;
460 	if( SvxShape::getPropertyValue( OUString::createFromAscii( UNO_NAME_OLE2_PERSISTNAME ) ) >>= aTmpStr )
461         aPersistName = aTmpStr;
462 
463     //TODO/LATER: how to cope with creation failure?!
464     uno::Reference < embed::XEmbeddedObject > xObj( pPersist->getEmbeddedObjectContainer().CreateEmbeddedObject( aClassName.GetByteSequence(), aPersistName ) );
465     if( xObj.is() )
466     {
467         Rectangle aRect = pOle2Obj->GetLogicRect();
468         if ( aRect.GetWidth() == 100 && aRect.GetHeight() == 100 )
469         {
470 			// TODO/LATER: is it possible that this method is used to create an iconified object?
471             // default size
472 			try
473 			{
474             	awt::Size aSz = xObj->getVisualAreaSize( pOle2Obj->GetAspect() );
475             	aRect.SetSize( Size( aSz.Width, aSz.Height ) );
476 			}
477 			catch( embed::NoVisualAreaSizeException& )
478 			{}
479             pOle2Obj->SetLogicRect( aRect );
480         }
481         else
482         {
483             awt::Size aSz;
484             Size aSize = pOle2Obj->GetLogicRect().GetSize();
485             aSz.Width = aSize.Width();
486             aSz.Height = aSize.Height();
487 			xObj->setVisualAreaSize(  pOle2Obj->GetAspect(), aSz );
488         }
489 
490 		// connect the object after the visual area is set
491         SvxShape::setPropertyValue( OUString::createFromAscii( UNO_NAME_OLE2_PERSISTNAME ), Any( aTmpStr = aPersistName ) );
492 
493 		// the object is inserted during setting of PersistName property usually
494 		if( pOle2Obj->IsEmpty() )
495 			pOle2Obj->SetObjRef( xObj );
496     }
497 
498     return xObj.is();
499 }
500 
createLink(const::rtl::OUString & aLinkURL)501 sal_Bool SvxOle2Shape::createLink( const ::rtl::OUString& aLinkURL )
502 {
503     DBG_TESTSOLARMUTEX();
504 
505 	SdrOle2Obj* pOle2Obj = dynamic_cast< SdrOle2Obj* >( mpObj.get() );
506     if ( !pOle2Obj || !pOle2Obj->IsEmpty() )
507 		return sal_False;
508 
509     ::rtl::OUString aPersistName;
510 
511     ::comphelper::IEmbeddedHelper* pPersist = mpModel->GetPersist();
512 
513 	uno::Sequence< beans::PropertyValue > aMediaDescr( 1 );
514 	aMediaDescr[0].Name = ::rtl::OUString::createFromAscii( "URL" );
515 	aMediaDescr[0].Value <<= aLinkURL;
516 
517 	uno::Reference< task::XInteractionHandler > xInteraction = pPersist->getInteractionHandler();
518 	if ( xInteraction.is() )
519 	{
520 		aMediaDescr.realloc( 2 );
521 		aMediaDescr[1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "InteractionHandler" ) );
522 		aMediaDescr[1].Value <<= xInteraction;
523 	}
524 
525     //TODO/LATER: how to cope with creation failure?!
526 	uno::Reference< embed::XEmbeddedObject > xObj =
527 			pPersist->getEmbeddedObjectContainer().InsertEmbeddedLink( aMediaDescr , aPersistName );
528 
529     if( xObj.is() )
530     {
531         Rectangle aRect = pOle2Obj->GetLogicRect();
532         if ( aRect.GetWidth() == 100 && aRect.GetHeight() == 100 )
533         {
534             // default size
535 			try
536 			{
537             	awt::Size aSz = xObj->getVisualAreaSize( pOle2Obj->GetAspect() );
538             	aRect.SetSize( Size( aSz.Width, aSz.Height ) );
539 			}
540 			catch( embed::NoVisualAreaSizeException& )
541 			{}
542 			pOle2Obj->SetLogicRect( aRect );
543         }
544         else
545         {
546             awt::Size aSz;
547             Size aSize = pOle2Obj->GetLogicRect().GetSize();
548             aSz.Width = aSize.Width();
549             aSz.Height = aSize.Height();
550             xObj->setVisualAreaSize(  pOle2Obj->GetAspect(), aSz );
551         }
552 
553 		// connect the object after the visual area is set
554         SvxShape::setPropertyValue( OUString::createFromAscii( UNO_NAME_OLE2_PERSISTNAME ), uno::makeAny( aPersistName ) );
555 
556 		// the object is inserted during setting of PersistName property usually
557 		if ( pOle2Obj->IsEmpty() )
558 			pOle2Obj->SetObjRef( xObj );
559     }
560 
561     return xObj.is();
562 }
563 
resetModifiedState()564 void SvxOle2Shape::resetModifiedState()
565 {
566 	::comphelper::IEmbeddedHelper* pPersist = mpModel ? mpModel->GetPersist() : 0;
567 	if( pPersist && !pPersist->isEnableSetModified() )
568 	{
569 		SdrOle2Obj* pOle = dynamic_cast< SdrOle2Obj* >( mpObj.get() );
570         if( pOle && !pOle->IsEmpty() )
571 		{
572             uno::Reference < util::XModifiable > xMod( pOle->GetObjRef(), uno::UNO_QUERY );
573             if( xMod.is() )
574                 // TODO/MBA: what's this?!
575                 xMod->setModified( sal_False );
576 		}
577 	}
578 }
579 
GetClassName_Impl(rtl::OUString & rHexCLSID)580 const SvGlobalName SvxOle2Shape::GetClassName_Impl(rtl::OUString& rHexCLSID)
581 {
582     DBG_TESTSOLARMUTEX();
583 	SvGlobalName aClassName;
584 	SdrOle2Obj* pOle2Obj = dynamic_cast< SdrOle2Obj* >( mpObj.get() );
585 
586 	if( pOle2Obj )
587 	{
588 		rHexCLSID = rtl::OUString();
589 
590 		if( pOle2Obj->IsEmpty() )
591 		{
592             ::comphelper::IEmbeddedHelper* pPersist = mpModel->GetPersist();
593             if( pPersist )
594 			{
595                 uno::Reference < embed::XEmbeddedObject > xObj =
596                         pPersist->getEmbeddedObjectContainer().GetEmbeddedObject( pOle2Obj->GetPersistName() );
597                 if ( xObj.is() )
598 				{
599                     aClassName = SvGlobalName( xObj->getClassID() );
600 					rHexCLSID = aClassName.GetHexName();
601 				}
602             }
603 		}
604 
605         if (!rHexCLSID.getLength())
606 		{
607             uno::Reference < embed::XEmbeddedObject > xObj( pOle2Obj->GetObjRef() );
608             if ( xObj.is() )
609 			{
610                 aClassName = SvGlobalName( xObj->getClassID() );
611 				rHexCLSID = aClassName.GetHexName();
612             }
613 		}
614 	}
615 
616     return aClassName;
617 }
618 
619 ///////////////////////////////////////////////////////////////////////
620 
SvxAppletShape(SdrObject * pObject)621 SvxAppletShape::SvxAppletShape( SdrObject* pObject ) throw()
622 : SvxOle2Shape( pObject, aSvxMapProvider.GetMap(SVXMAP_APPLET), aSvxMapProvider.GetPropertySet(SVXMAP_APPLET, SdrObject::GetGlobalDrawObjectItemPool())  )
623 {
624 	SetShapeType( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.AppletShape" ) ) );
625 }
626 
~SvxAppletShape()627 SvxAppletShape::~SvxAppletShape() throw()
628 {
629 }
630 
Create(SdrObject * pNewObj,SvxDrawPage * pNewPage)631 void SvxAppletShape::Create( SdrObject* pNewObj, SvxDrawPage* pNewPage )
632 {
633 	SvxShape::Create( pNewObj, pNewPage );
634 	const SvGlobalName aAppletClassId( SO3_APPLET_CLASSID );
635 	createObject(aAppletClassId);
636 	SetShapeType( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.AppletShape" ) ) );
637 }
638 
setPropertyValue(const::rtl::OUString & aPropertyName,const::com::sun::star::uno::Any & rValue)639 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)
640 {
641 	SvxShape::setPropertyValue( aPropertyName, rValue );
642 	resetModifiedState();
643 }
644 
setPropertyValues(const::com::sun::star::uno::Sequence<::rtl::OUString> & aPropertyNames,const::com::sun::star::uno::Sequence<::com::sun::star::uno::Any> & rValues)645 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)
646 {
647 	SvxShape::setPropertyValues( aPropertyNames, rValues );
648 	resetModifiedState();
649 }
650 
setPropertyValueImpl(const::rtl::OUString & rName,const SfxItemPropertySimpleEntry * pProperty,const::com::sun::star::uno::Any & rValue)651 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)
652 {
653 	if( (pProperty->nWID >= OWN_ATTR_APPLET_DOCBASE) && (pProperty->nWID <= OWN_ATTR_APPLET_ISSCRIPT) )
654 	{
655         if ( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef() ) )
656 		{
657 	        uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef()->getComponent(), uno::UNO_QUERY );
658 		    if( xSet.is() )
659 			{
660 				// allow exceptions to pass through
661                 xSet->setPropertyValue( rName, rValue );
662 			}
663 		}
664 		return true;
665 	}
666 	else
667 	{
668         return SvxOle2Shape::setPropertyValueImpl( rName, pProperty, rValue );
669 	}
670 }
671 
getPropertyValueImpl(const::rtl::OUString & rName,const SfxItemPropertySimpleEntry * pProperty,::com::sun::star::uno::Any & rValue)672 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)
673 {
674     if( (pProperty->nWID >= OWN_ATTR_APPLET_DOCBASE) && (pProperty->nWID <= OWN_ATTR_APPLET_ISSCRIPT) )
675 	{
676         if ( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef() ) )
677 		{
678 			uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef()->getComponent(), uno::UNO_QUERY );
679 			if( xSet.is() )
680 			{
681                 rValue = xSet->getPropertyValue( rName );
682 			}
683         }
684 		return true;
685 	}
686 	else
687 	{
688         return SvxOle2Shape::getPropertyValueImpl( rName, pProperty, rValue );
689 	}
690 }
691 
692 ///////////////////////////////////////////////////////////////////////
693 
SvxPluginShape(SdrObject * pObject)694 SvxPluginShape::SvxPluginShape( SdrObject* pObject ) throw()
695 : SvxOle2Shape( pObject, aSvxMapProvider.GetMap(SVXMAP_PLUGIN), aSvxMapProvider.GetPropertySet(SVXMAP_PLUGIN, SdrObject::GetGlobalDrawObjectItemPool()) )
696 {
697 	SetShapeType( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.PluginShape" ) ) );
698 }
699 
~SvxPluginShape()700 SvxPluginShape::~SvxPluginShape() throw()
701 {
702 }
703 
Create(SdrObject * pNewObj,SvxDrawPage * pNewPage)704 void SvxPluginShape::Create( SdrObject* pNewObj, SvxDrawPage* pNewPage )
705 {
706 	SvxShape::Create( pNewObj, pNewPage );
707 	const SvGlobalName aPluginClassId( SO3_PLUGIN_CLASSID );
708 	createObject(aPluginClassId);
709 	SetShapeType( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.PluginShape" ) ) );
710 }
711 
setPropertyValue(const::rtl::OUString & aPropertyName,const::com::sun::star::uno::Any & rValue)712 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)
713 {
714 	SvxShape::setPropertyValue( aPropertyName, rValue );
715 	resetModifiedState();
716 }
717 
setPropertyValues(const::com::sun::star::uno::Sequence<::rtl::OUString> & aPropertyNames,const::com::sun::star::uno::Sequence<::com::sun::star::uno::Any> & rValues)718 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)
719 {
720 	SvxShape::setPropertyValues( aPropertyNames, rValues );
721 	resetModifiedState();
722 }
723 
setPropertyValueImpl(const::rtl::OUString & rName,const SfxItemPropertySimpleEntry * pProperty,const::com::sun::star::uno::Any & rValue)724 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)
725 {
726 	if( (pProperty->nWID >= OWN_ATTR_PLUGIN_MIMETYPE) && (pProperty->nWID <= OWN_ATTR_PLUGIN_COMMANDS) )
727 	{
728         if( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef() ) )
729 		{
730 	        uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef()->getComponent(), uno::UNO_QUERY );
731 			if( xSet.is() )
732 			{
733                 // allow exceptions to pass through
734                 xSet->setPropertyValue( rName, rValue );
735 			}
736 		}
737 		return true;
738 	}
739 	else
740 	{
741         return SvxOle2Shape::setPropertyValueImpl( rName, pProperty, rValue );
742 	}
743 }
744 
getPropertyValueImpl(const::rtl::OUString & rName,const SfxItemPropertySimpleEntry * pProperty,::com::sun::star::uno::Any & rValue)745 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)
746 {
747 	if( (pProperty->nWID >= OWN_ATTR_PLUGIN_MIMETYPE) && (pProperty->nWID <= OWN_ATTR_PLUGIN_COMMANDS) )
748 	{
749 		if( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef() ) )
750 		{
751 			uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef()->getComponent(), uno::UNO_QUERY );
752 			if( xSet.is() )
753 			{
754                 rValue <<= xSet->getPropertyValue( rName );
755             }
756 		}
757 		return true;
758 	}
759 	else
760 	{
761         return SvxOle2Shape::getPropertyValueImpl( rName, pProperty, rValue );
762 	}
763 }
764 
765 ///////////////////////////////////////////////////////////////////////
766 
SvxFrameShape(SdrObject * pObject)767 SvxFrameShape::SvxFrameShape( SdrObject* pObject ) throw()
768 : SvxOle2Shape( pObject, aSvxMapProvider.GetMap(SVXMAP_FRAME), aSvxMapProvider.GetPropertySet(SVXMAP_FRAME, SdrObject::GetGlobalDrawObjectItemPool())  )
769 {
770 	SetShapeType( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.FrameShape" ) ) );
771 }
772 
~SvxFrameShape()773 SvxFrameShape::~SvxFrameShape() throw()
774 {
775 }
776 
Create(SdrObject * pNewObj,SvxDrawPage * pNewPage)777 void SvxFrameShape::Create( SdrObject* pNewObj, SvxDrawPage* pNewPage ) throw ()
778 {
779 	SvxShape::Create( pNewObj, pNewPage );
780 	const SvGlobalName aIFrameClassId( SO3_IFRAME_CLASSID );
781 	createObject(aIFrameClassId);
782 	SetShapeType( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.FrameShape" ) ) );
783 }
784 
setPropertyValue(const::rtl::OUString & aPropertyName,const::com::sun::star::uno::Any & rValue)785 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)
786 {
787 	SvxShape::setPropertyValue( aPropertyName, rValue );
788 	resetModifiedState();
789 }
790 
setPropertyValues(const::com::sun::star::uno::Sequence<::rtl::OUString> & aPropertyNames,const::com::sun::star::uno::Sequence<::com::sun::star::uno::Any> & rValues)791 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)
792 {
793 	SvxShape::setPropertyValues( aPropertyNames, rValues );
794 	resetModifiedState();
795 }
796 
setPropertyValueImpl(const::rtl::OUString & rName,const SfxItemPropertySimpleEntry * pProperty,const::com::sun::star::uno::Any & rValue)797 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)
798 {
799 	if( (pProperty->nWID >= OWN_ATTR_FRAME_URL) && (pProperty->nWID <= OWN_ATTR_FRAME_MARGIN_HEIGHT) )
800 	{
801 		if( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef() ) )
802 		{
803 			uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef()->getComponent(), uno::UNO_QUERY );
804 			if( xSet.is() )
805 			{
806 				// allow exceptions to pass through
807                 xSet->setPropertyValue( rName, rValue );
808 			}
809 		}
810 		return true;
811 	}
812 	else
813 	{
814         return SvxOle2Shape::setPropertyValueImpl( rName, pProperty, rValue );
815 	}
816 }
817 
getPropertyValueImpl(const::rtl::OUString & rName,const SfxItemPropertySimpleEntry * pProperty,::com::sun::star::uno::Any & rValue)818 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)
819 {
820 	if( (pProperty->nWID >= OWN_ATTR_FRAME_URL) && (pProperty->nWID <= OWN_ATTR_FRAME_MARGIN_HEIGHT) )
821 	{
822 		if( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef() ) )
823 		{
824 			uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef()->getComponent(), uno::UNO_QUERY );
825 			if( xSet.is() )
826 			{
827                 rValue <<= xSet->getPropertyValue( rName );
828 			}
829 		}
830 		return true;
831 	}
832 	else
833 	{
834         return SvxOle2Shape::getPropertyValueImpl( rName, pProperty, rValue );
835 	}
836 }
837 
838 /***********************************************************************
839 *                                                                      *
840 ***********************************************************************/
841 
SvxMediaShape(SdrObject * pObj)842 SvxMediaShape::SvxMediaShape( SdrObject* pObj ) throw()
843 :	SvxShape( pObj, aSvxMapProvider.GetMap(SVXMAP_MEDIA), aSvxMapProvider.GetPropertySet(SVXMAP_MEDIA, SdrObject::GetGlobalDrawObjectItemPool()) )
844 {
845 	SetShapeType( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.MediaShape" ) ) );
846 }
847 
848 //----------------------------------------------------------------------
~SvxMediaShape()849 SvxMediaShape::~SvxMediaShape() throw()
850 {
851 }
852 
853 //----------------------------------------------------------------------
854 
setPropertyValueImpl(const::rtl::OUString & rName,const SfxItemPropertySimpleEntry * pProperty,const::com::sun::star::uno::Any & rValue)855 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)
856 {
857 	if( (pProperty->nWID >= OWN_ATTR_MEDIA_URL) && (pProperty->nWID <= OWN_ATTR_MEDIA_ZOOM) )
858 	{
859 		SdrMediaObj* pMedia = static_cast< SdrMediaObj* >( mpObj.get() );
860 		::avmedia::MediaItem aItem;
861 		bool bOk = false;
862 
863 		switch( pProperty->nWID )
864 		{
865 		case OWN_ATTR_MEDIA_URL:
866 		{
867 			OUString aURL;
868 			if( rValue >>= aURL )
869 			{
870 				bOk = true;
871 				aItem.setURL( aURL );
872 			}
873 		}
874 		break;
875 
876 		case( OWN_ATTR_MEDIA_LOOP ):
877 		{
878 			sal_Bool bLoop = sal_Bool();
879 
880 			if( rValue >>= bLoop )
881 			{
882 				bOk = true;
883 				aItem.setLoop( bLoop );
884 			}
885 		}
886 		break;
887 
888 		case( OWN_ATTR_MEDIA_MUTE ):
889 		{
890 			sal_Bool bMute = sal_Bool();
891 
892 			if( rValue >>= bMute )
893 			{
894 				bOk = true;
895 				aItem.setMute( bMute );
896 			}
897 		}
898 		break;
899 
900 		case( OWN_ATTR_MEDIA_VOLUMEDB ):
901 		{
902 			sal_Int16 nVolumeDB = sal_Int16();
903 
904 			if( rValue >>= nVolumeDB )
905 			{
906 				bOk = true;
907 				aItem.setVolumeDB( nVolumeDB );
908 			}
909 		}
910 		break;
911 
912 		case( OWN_ATTR_MEDIA_ZOOM ):
913 		{
914 			::com::sun::star::media::ZoomLevel eLevel;
915 
916 			if( rValue >>= eLevel )
917 			{
918 				bOk = true;
919 				aItem.setZoom( eLevel );
920 			}
921 		}
922 		break;
923 
924 		default:
925 			DBG_ERROR("SvxMediaShape::setPropertyValueImpl(), unknown argument!");
926 		}
927 
928 		if( bOk )
929 		{
930 			pMedia->setMediaProperties( aItem );
931 			return true;
932 		}
933 	}
934 	else
935 	{
936         return SvxShape::setPropertyValueImpl( rName, pProperty, rValue );
937 	}
938 
939 	throw IllegalArgumentException();
940 }
941 
942 //----------------------------------------------------------------------
943 
getPropertyValueImpl(const::rtl::OUString & rName,const SfxItemPropertySimpleEntry * pProperty,::com::sun::star::uno::Any & rValue)944 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)
945 {
946 	if( ( pProperty->nWID >= OWN_ATTR_MEDIA_URL ) && ( pProperty->nWID <= OWN_ATTR_MEDIA_ZOOM ) )
947 	{
948 		SdrMediaObj* pMedia = static_cast< SdrMediaObj* >( mpObj.get() );
949 		const ::avmedia::MediaItem aItem( pMedia->getMediaProperties() );
950 
951 		switch( pProperty->nWID )
952 		{
953 			case OWN_ATTR_MEDIA_URL:
954 				rValue <<= aItem.getURL();
955 				break;
956 
957 			case( OWN_ATTR_MEDIA_LOOP ):
958 				rValue <<= (sal_Bool) aItem.isLoop();
959 				break;
960 
961 			case( OWN_ATTR_MEDIA_MUTE ):
962 				rValue <<= (sal_Bool) aItem.isMute();
963 				break;
964 
965 			case( OWN_ATTR_MEDIA_VOLUMEDB ):
966 				rValue <<= (sal_Int16) aItem.getVolumeDB();
967 				break;
968 
969 			case( OWN_ATTR_MEDIA_ZOOM ):
970 				rValue <<= aItem.getZoom();
971 				break;
972 
973 			default:
974 				DBG_ERROR("SvxMediaShape::getPropertyValueImpl(), unknown property!");
975 		}
976 		return true;
977 	}
978 	else
979 	{
980         return SvxShape::getPropertyValueImpl( rName, pProperty, rValue );
981 	}
982 }
983