Bump version to 6.4.7.2.M8
[LibreOffice.git] / svx / source / unodraw / unoshap4.cxx
blobf7629f3388587452268f81f39ca22c48805ca55b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/util/XModifiable.hpp>
21 #include <com/sun/star/embed/XEmbeddedObject.hpp>
22 #include <com/sun/star/embed/XLinkageSupport.hpp>
23 #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
24 #include <com/sun/star/embed/Aspects.hpp>
25 #include <com/sun/star/task/XInteractionHandler.hpp>
26 #include <com/sun/star/ucb/CommandFailedException.hpp>
27 #include <com/sun/star/ucb/ContentCreationException.hpp>
29 #include <vcl/virdev.hxx>
30 #include <svx/svdoole2.hxx>
31 #include <svx/svdomedia.hxx>
32 #include <svx/svdpool.hxx>
33 #include <comphelper/classids.hxx>
34 #include <comphelper/propertysequence.hxx>
35 #include <cppuhelper/exc_hlp.hxx>
36 #include <sfx2/frmdescr.hxx>
37 #include <vcl/svapp.hxx>
39 #include <toolkit/helper/vclunohelper.hxx>
40 #include <sfx2/objsh.hxx>
41 #include <sfx2/docfile.hxx>
43 #include <sot/storage.hxx>
44 #include <sot/exchange.hxx>
45 #include <vcl/FilterConfigItem.hxx>
47 #include <svx/svdmodel.hxx>
48 #include "shapeimpl.hxx"
50 #include <svx/unoshprp.hxx>
52 #include <svx/unoapi.hxx>
53 #include <svx/svdpagv.hxx>
54 #include <svx/svdview.hxx>
55 #include <vcl/wmf.hxx>
56 #include <svtools/embedhlp.hxx>
57 #include <sal/log.hxx>
58 #include <tools/debug.hxx>
60 #include <config_features.h>
63 using namespace ::cppu;
64 using namespace ::com::sun::star;
65 using namespace ::com::sun::star::uno;
66 using namespace ::com::sun::star::lang;
67 using namespace ::com::sun::star::container;
68 using namespace ::com::sun::star::beans;
71 SvxOle2Shape::SvxOle2Shape(SdrObject* pObject)
72 : SvxShapeText( pObject, getSvxMapProvider().GetMap(SVXMAP_OLE2),
73 getSvxMapProvider().GetPropertySet(SVXMAP_OLE2,SdrObject::GetGlobalDrawObjectItemPool()) )
77 SvxOle2Shape::SvxOle2Shape(SdrObject* pObject, const SfxItemPropertyMapEntry* pPropertyMap, const SvxItemPropertySet* pPropertySet)
78 : SvxShapeText( pObject, pPropertyMap, pPropertySet )
82 SvxOle2Shape::~SvxOle2Shape() throw()
86 //XPropertySet
87 bool SvxOle2Shape::setPropertyValueImpl( const OUString& rName, const SfxItemPropertySimpleEntry* pProperty, const css::uno::Any& rValue )
89 switch( pProperty->nWID )
91 case OWN_ATTR_OLE_VISAREA:
93 // TODO/LATER: seems to make no sense for iconified object
95 awt::Rectangle aVisArea;
96 if( (rValue >>= aVisArea) && dynamic_cast<const SdrOle2Obj* >(GetSdrObject()) != nullptr)
98 Size aTmp( aVisArea.X + aVisArea.Width, aVisArea.Y + aVisArea.Height );
99 uno::Reference < embed::XEmbeddedObject > xObj = static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef();
100 if( xObj.is() )
104 // the API handles with MapUnit::Map100thMM map mode
105 MapUnit aObjUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( embed::Aspects::MSOLE_CONTENT ) );
106 aTmp = OutputDevice::LogicToLogic(aTmp, MapMode(MapUnit::Map100thMM), MapMode(aObjUnit));
107 xObj->setVisualAreaSize( embed::Aspects::MSOLE_CONTENT, awt::Size( aTmp.Width(), aTmp.Height() ) );
109 catch( uno::Exception& )
111 OSL_FAIL( "Couldn't set the visual area for the object!" );
115 return true;
117 break;
119 case OWN_ATTR_OLE_ASPECT:
121 sal_Int64 nAspect = 0;
122 if( rValue >>= nAspect )
124 static_cast<SdrOle2Obj*>(GetSdrObject())->SetAspect( nAspect );
125 return true;
127 break;
129 case OWN_ATTR_CLSID:
131 OUString aCLSID;
132 if( rValue >>= aCLSID )
134 // init an OLE object with a global name
135 SvGlobalName aClassName;
136 if( aClassName.MakeId( aCLSID ) )
138 if( createObject( aClassName ) )
139 return true;
142 break;
144 case OWN_ATTR_THUMBNAIL:
146 uno::Reference< graphic::XGraphic > xGraphic( rValue, uno::UNO_QUERY );
147 if( xGraphic.is() )
149 const Graphic aGraphic(xGraphic);
150 static_cast<SdrOle2Obj*>(GetSdrObject())->SetGraphic(aGraphic);
151 return true;
153 break;
155 case OWN_ATTR_VALUE_GRAPHIC:
157 uno::Reference< graphic::XGraphic > xGraphic( rValue, uno::UNO_QUERY );
158 if( xGraphic.is() )
160 SdrOle2Obj* pOle = dynamic_cast< SdrOle2Obj* >( GetSdrObject() );
161 if( pOle )
163 GraphicObject aGrafObj( xGraphic );
164 const Graphic& aGraphic( aGrafObj.GetGraphic() );
165 pOle->SetGraphicToObj( aGraphic );
167 return true;
169 break;
171 case OWN_ATTR_PERSISTNAME:
173 OUString aPersistName;
174 if( rValue >>= aPersistName )
176 SdrOle2Obj *pOle;
177 #if OSL_DEBUG_LEVEL > 0
178 pOle = dynamic_cast<SdrOle2Obj*>(GetSdrObject());
179 assert(pOle);
180 #else
181 pOle = static_cast<SdrOle2Obj*>(GetSdrObject());
182 #endif
183 pOle->SetPersistName( aPersistName );
184 return true;
186 break;
188 case OWN_ATTR_OLE_LINKURL:
190 OUString aLinkURL;
191 if( rValue >>= aLinkURL )
193 createLink( aLinkURL );
194 return true;
196 break;
198 default:
199 return SvxShapeText::setPropertyValueImpl( rName, pProperty, rValue );
202 throw IllegalArgumentException();
205 bool SvxOle2Shape::getPropertyValueImpl( const OUString& rName, const SfxItemPropertySimpleEntry* pProperty, css::uno::Any& rValue )
207 switch( pProperty->nWID )
209 case OWN_ATTR_CLSID:
211 OUString aCLSID;
212 GetClassName_Impl(aCLSID);
213 rValue <<= aCLSID;
214 break;
217 case OWN_ATTR_INTERNAL_OLE:
219 OUString sCLSID;
220 rValue <<= SotExchange::IsInternal( GetClassName_Impl(sCLSID) );
221 break;
224 case OWN_ATTR_METAFILE:
226 SdrOle2Obj* pObj = dynamic_cast<SdrOle2Obj*>(GetSdrObject());
227 if( pObj )
229 const Graphic* pGraphic = pObj->GetGraphic();
230 if( pGraphic )
232 bool bIsWMF = false;
233 if ( pGraphic->IsGfxLink() )
235 GfxLink aLnk = pGraphic->GetGfxLink();
236 if ( aLnk.GetType() == GfxLinkType::NativeWmf )
238 bIsWMF = true;
239 uno::Sequence<sal_Int8> aSeq(reinterpret_cast<sal_Int8 const *>(aLnk.GetData()), static_cast<sal_Int32>(aLnk.GetDataSize()));
240 rValue <<= aSeq;
243 if ( !bIsWMF )
245 // #i119735# just use GetGDIMetaFile, it will create a bufferd version of contained bitmap now automatically
246 GDIMetaFile aMtf(pObj->GetGraphic()->GetGDIMetaFile());
247 SvMemoryStream aDestStrm( 65535, 65535 );
248 ConvertGDIMetaFileToWMF( aMtf, aDestStrm, nullptr, false );
249 const uno::Sequence<sal_Int8> aSeq(
250 static_cast< const sal_Int8* >(aDestStrm.GetData()),
251 aDestStrm.GetEndOfData());
252 rValue <<= aSeq;
256 else
258 rValue = GetBitmap( true );
260 break;
263 case OWN_ATTR_OLE_VISAREA:
265 awt::Rectangle aVisArea;
266 if( dynamic_cast<const SdrOle2Obj* >(GetSdrObject()) != nullptr)
268 MapMode aMapMode( MapUnit::Map100thMM ); // the API uses this map mode
269 Size aTmp = static_cast<SdrOle2Obj*>(GetSdrObject())->GetOrigObjSize( &aMapMode ); // get the size in the requested map mode
270 aVisArea = awt::Rectangle( 0, 0, aTmp.Width(), aTmp.Height() );
273 rValue <<= aVisArea;
274 break;
277 case OWN_ATTR_OLESIZE:
279 Size aTmp( static_cast<SdrOle2Obj*>(GetSdrObject())->GetOrigObjSize() );
280 rValue <<= awt::Size( aTmp.Width(), aTmp.Height() );
281 break;
284 case OWN_ATTR_OLE_ASPECT:
286 rValue <<= static_cast<SdrOle2Obj*>(GetSdrObject())->GetAspect();
287 break;
290 case OWN_ATTR_OLEMODEL:
291 case OWN_ATTR_OLE_EMBEDDED_OBJECT:
292 case OWN_ATTR_OLE_EMBEDDED_OBJECT_NONEWCLIENT:
294 SdrOle2Obj* pObj = dynamic_cast<SdrOle2Obj*>( GetSdrObject() );
295 if( pObj )
297 uno::Reference < embed::XEmbeddedObject > xObj( pObj->GetObjRef() );
298 if ( xObj.is()
299 && ( pProperty->nWID == OWN_ATTR_OLE_EMBEDDED_OBJECT || pProperty->nWID == OWN_ATTR_OLE_EMBEDDED_OBJECT_NONEWCLIENT || svt::EmbeddedObjectRef::TryRunningState( xObj ) ) )
301 // Discussed with CL fue to the before GetPaintingPageView
302 // usage. Removed it, former fallback is used now
303 if ( pProperty->nWID == OWN_ATTR_OLEMODEL || pProperty->nWID == OWN_ATTR_OLE_EMBEDDED_OBJECT )
305 const bool bSuccess(pObj->AddOwnLightClient());
306 SAL_WARN_IF(!bSuccess, "svx.svdraw", "An object without client is provided!");
309 if ( pProperty->nWID == OWN_ATTR_OLEMODEL )
310 rValue <<= pObj->GetObjRef()->getComponent();
311 else
312 rValue <<= xObj;
315 break;
318 case OWN_ATTR_VALUE_GRAPHIC:
320 uno::Reference< graphic::XGraphic > xGraphic;
321 const Graphic* pGraphic = static_cast<SdrOle2Obj*>( GetSdrObject() )->GetGraphic();
322 if( pGraphic )
323 xGraphic = pGraphic->GetXGraphic();
324 rValue <<= xGraphic;
325 break;
328 case OWN_ATTR_THUMBNAIL:
330 uno::Reference< graphic::XGraphic > xGraphic;
331 const Graphic* pGraphic = static_cast<SdrOle2Obj*>( GetSdrObject() )->GetGraphic();
332 if( pGraphic )
333 xGraphic = pGraphic->GetXGraphic();
334 rValue <<= xGraphic;
335 break;
337 case OWN_ATTR_PERSISTNAME:
339 OUString aPersistName;
340 SdrOle2Obj* pOle = dynamic_cast< SdrOle2Obj* >( GetSdrObject() );
342 if( pOle )
344 aPersistName = pOle->GetPersistName();
345 if( !aPersistName.isEmpty() )
347 ::comphelper::IEmbeddedHelper* pPersist(GetSdrObject()->getSdrModelFromSdrObject().GetPersist());
348 if( (nullptr == pPersist) || !pPersist->getEmbeddedObjectContainer().HasEmbeddedObject( pOle->GetPersistName() ) )
349 aPersistName.clear();
353 rValue <<= aPersistName;
354 break;
356 case OWN_ATTR_OLE_LINKURL:
358 OUString aLinkURL;
359 SdrOle2Obj* pOle = dynamic_cast< SdrOle2Obj* >( GetSdrObject() );
361 if( pOle )
363 uno::Reference< embed::XLinkageSupport > xLink( pOle->GetObjRef(), uno::UNO_QUERY );
364 if ( xLink.is() && xLink->isLink() )
365 aLinkURL = xLink->getLinkURL();
368 rValue <<= aLinkURL;
369 break;
371 default:
372 return SvxShapeText::getPropertyValueImpl( rName, pProperty, rValue );
375 return true;
378 bool SvxOle2Shape::createObject( const SvGlobalName &aClassName )
380 DBG_TESTSOLARMUTEX();
382 SdrOle2Obj* pOle2Obj = dynamic_cast< SdrOle2Obj* >( GetSdrObject() );
383 if ( !pOle2Obj || !pOle2Obj->IsEmpty() )
384 return false;
386 // create storage and inplace object
387 ::comphelper::IEmbeddedHelper* pPersist = GetSdrObject()->getSdrModelFromSdrObject().GetPersist();
388 OUString aPersistName;
389 OUString aTmpStr;
390 if( SvxShape::getPropertyValue( UNO_NAME_OLE2_PERSISTNAME ) >>= aTmpStr )
391 aPersistName = aTmpStr;
393 uno::Sequence<beans::PropertyValue> objArgs( comphelper::InitPropertySequence({
394 { "DefaultParentBaseURL", Any(pPersist->getDocumentBaseURL()) }
395 }));
396 //TODO/LATER: how to cope with creation failure?!
397 uno::Reference<embed::XEmbeddedObject> xObj(
398 pPersist->getEmbeddedObjectContainer().CreateEmbeddedObject(
399 aClassName.GetByteSequence(), objArgs, aPersistName));
400 if( xObj.is() )
402 tools::Rectangle aRect = pOle2Obj->GetLogicRect();
403 if ( aRect.GetWidth() == 101 && aRect.GetHeight() == 101 )
405 // TODO/LATER: is it possible that this method is used to create an iconified object?
406 // default size
409 awt::Size aSz = xObj->getVisualAreaSize( pOle2Obj->GetAspect() );
410 aRect.SetSize( Size( aSz.Width, aSz.Height ) );
412 catch( embed::NoVisualAreaSizeException& )
414 pOle2Obj->SetLogicRect( aRect );
416 else
418 awt::Size aSz;
419 Size aSize = aRect.GetSize();
420 aSz.Width = aSize.Width();
421 aSz.Height = aSize.Height();
422 if (aSz.Width != 0 || aSz.Height != 0)
424 //HACK: can aSz legally be empty?
425 xObj->setVisualAreaSize( pOle2Obj->GetAspect(), aSz );
429 // connect the object after the visual area is set
430 aTmpStr = aPersistName;
431 SvxShape::setPropertyValue( UNO_NAME_OLE2_PERSISTNAME, Any( aTmpStr ) );
433 // the object is inserted during setting of PersistName property usually
434 if( pOle2Obj->IsEmpty() )
435 pOle2Obj->SetObjRef( xObj );
438 return xObj.is();
441 void SvxOle2Shape::createLink( const OUString& aLinkURL )
443 DBG_TESTSOLARMUTEX();
445 SdrOle2Obj* pOle2Obj = dynamic_cast< SdrOle2Obj* >( GetSdrObject() );
446 if ( !pOle2Obj || !pOle2Obj->IsEmpty() )
447 return;
449 OUString aPersistName;
451 ::comphelper::IEmbeddedHelper* pPersist = GetSdrObject()->getSdrModelFromSdrObject().GetPersist();
453 uno::Sequence< beans::PropertyValue > aMediaDescr( 1 );
454 aMediaDescr[0].Name = "URL";
455 aMediaDescr[0].Value <<= aLinkURL;
457 uno::Reference< task::XInteractionHandler > xInteraction = pPersist->getInteractionHandler();
458 if ( xInteraction.is() )
460 aMediaDescr.realloc( 2 );
461 aMediaDescr[1].Name = "InteractionHandler";
462 aMediaDescr[1].Value <<= xInteraction;
465 //TODO/LATER: how to cope with creation failure?!
466 uno::Reference< embed::XEmbeddedObject > xObj =
467 pPersist->getEmbeddedObjectContainer().InsertEmbeddedLink( aMediaDescr , aPersistName );
469 if( xObj.is() )
471 tools::Rectangle aRect = pOle2Obj->GetLogicRect();
472 if ( aRect.GetWidth() == 101 && aRect.GetHeight() == 101 )
474 // default size
477 awt::Size aSz = xObj->getVisualAreaSize( pOle2Obj->GetAspect() );
478 aRect.SetSize( Size( aSz.Width, aSz.Height ) );
480 catch( embed::NoVisualAreaSizeException& )
482 pOle2Obj->SetLogicRect( aRect );
484 else
486 awt::Size aSz;
487 Size aSize = pOle2Obj->GetLogicRect().GetSize();
488 aSz.Width = aSize.Width();
489 aSz.Height = aSize.Height();
490 xObj->setVisualAreaSize( pOle2Obj->GetAspect(), aSz );
493 // connect the object after the visual area is set
494 SvxShape::setPropertyValue( UNO_NAME_OLE2_PERSISTNAME, uno::makeAny( aPersistName ) );
496 // the object is inserted during setting of PersistName property usually
497 if ( pOle2Obj->IsEmpty() )
498 pOle2Obj->SetObjRef( xObj );
502 void SvxOle2Shape::resetModifiedState()
504 ::comphelper::IEmbeddedHelper* pPersist = GetSdrObject()->getSdrModelFromSdrObject().GetPersist();
505 if( pPersist && !pPersist->isEnableSetModified() )
507 SdrOle2Obj* pOle = dynamic_cast< SdrOle2Obj* >( GetSdrObject() );
508 if( pOle && !pOle->IsEmpty() )
510 uno::Reference < util::XModifiable > xMod( pOle->GetObjRef(), uno::UNO_QUERY );
511 if( xMod.is() )
512 // TODO/MBA: what's this?!
513 xMod->setModified( false );
518 SvGlobalName SvxOle2Shape::GetClassName_Impl(OUString& rHexCLSID)
520 DBG_TESTSOLARMUTEX();
521 SvGlobalName aClassName;
522 SdrOle2Obj* pOle2Obj = dynamic_cast< SdrOle2Obj* >( GetSdrObject() );
524 if( pOle2Obj )
526 rHexCLSID.clear();
528 if( pOle2Obj->IsEmpty() )
530 ::comphelper::IEmbeddedHelper* pPersist = GetSdrObject()->getSdrModelFromSdrObject().GetPersist();
531 if( pPersist )
533 uno::Reference < embed::XEmbeddedObject > xObj =
534 pPersist->getEmbeddedObjectContainer().GetEmbeddedObject( pOle2Obj->GetPersistName() );
535 if ( xObj.is() )
537 aClassName = SvGlobalName( xObj->getClassID() );
538 rHexCLSID = aClassName.GetHexName();
543 if (rHexCLSID.isEmpty())
545 const uno::Reference < embed::XEmbeddedObject >& xObj( pOle2Obj->GetObjRef() );
546 if ( xObj.is() )
548 aClassName = SvGlobalName( xObj->getClassID() );
549 rHexCLSID = aClassName.GetHexName();
554 return aClassName;
557 SvxAppletShape::SvxAppletShape(SdrObject* pObject)
558 : SvxOle2Shape( pObject, getSvxMapProvider().GetMap(SVXMAP_APPLET), getSvxMapProvider().GetPropertySet(SVXMAP_APPLET, SdrObject::GetGlobalDrawObjectItemPool()) )
560 SetShapeType( "com.sun.star.drawing.AppletShape" );
563 SvxAppletShape::~SvxAppletShape() throw()
567 void SvxAppletShape::Create( SdrObject* pNewObj, SvxDrawPage* pNewPage )
569 SvxShape::Create( pNewObj, pNewPage );
570 const SvGlobalName aAppletClassId( SO3_APPLET_CLASSID );
571 createObject(aAppletClassId);
572 SetShapeType( "com.sun.star.drawing.AppletShape" );
575 void SAL_CALL SvxAppletShape::setPropertyValue( const OUString& aPropertyName, const css::uno::Any& rValue )
577 SvxShape::setPropertyValue( aPropertyName, rValue );
578 resetModifiedState();
581 void SAL_CALL SvxAppletShape::setPropertyValues( const css::uno::Sequence< OUString >& aPropertyNames, const css::uno::Sequence< css::uno::Any >& rValues )
583 SvxShape::setPropertyValues( aPropertyNames, rValues );
584 resetModifiedState();
587 bool SvxAppletShape::setPropertyValueImpl( const OUString& rName, const SfxItemPropertySimpleEntry* pProperty, const css::uno::Any& rValue )
589 if( (pProperty->nWID >= OWN_ATTR_APPLET_DOCBASE) && (pProperty->nWID <= OWN_ATTR_APPLET_ISSCRIPT) )
591 if ( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef() ) )
593 uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef()->getComponent(), uno::UNO_QUERY );
594 if( xSet.is() )
596 // allow exceptions to pass through
597 xSet->setPropertyValue( rName, rValue );
600 return true;
602 else
604 return SvxOle2Shape::setPropertyValueImpl( rName, pProperty, rValue );
608 bool SvxAppletShape::getPropertyValueImpl( const OUString& rName, const SfxItemPropertySimpleEntry* pProperty, css::uno::Any& rValue )
610 if( (pProperty->nWID >= OWN_ATTR_APPLET_DOCBASE) && (pProperty->nWID <= OWN_ATTR_APPLET_ISSCRIPT) )
612 if ( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef() ) )
614 uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef()->getComponent(), uno::UNO_QUERY );
615 if( xSet.is() )
617 rValue = xSet->getPropertyValue( rName );
620 return true;
622 else
624 return SvxOle2Shape::getPropertyValueImpl( rName, pProperty, rValue );
628 SvxPluginShape::SvxPluginShape(SdrObject* pObject)
629 : SvxOle2Shape( pObject, getSvxMapProvider().GetMap(SVXMAP_PLUGIN), getSvxMapProvider().GetPropertySet(SVXMAP_PLUGIN, SdrObject::GetGlobalDrawObjectItemPool()) )
631 SetShapeType( "com.sun.star.drawing.PluginShape" );
634 SvxPluginShape::~SvxPluginShape() throw()
638 void SvxPluginShape::Create( SdrObject* pNewObj, SvxDrawPage* pNewPage )
640 SvxShape::Create( pNewObj, pNewPage );
641 const SvGlobalName aPluginClassId( SO3_PLUGIN_CLASSID );
642 createObject(aPluginClassId);
643 SetShapeType( "com.sun.star.drawing.PluginShape" );
646 void SAL_CALL SvxPluginShape::setPropertyValue( const OUString& aPropertyName, const css::uno::Any& rValue )
648 SvxShape::setPropertyValue( aPropertyName, rValue );
649 resetModifiedState();
652 void SAL_CALL SvxPluginShape::setPropertyValues( const css::uno::Sequence< OUString >& aPropertyNames, const css::uno::Sequence< css::uno::Any >& rValues )
654 SvxShape::setPropertyValues( aPropertyNames, rValues );
655 resetModifiedState();
658 bool SvxPluginShape::setPropertyValueImpl( const OUString& rName, const SfxItemPropertySimpleEntry* pProperty, const css::uno::Any& rValue )
660 if( (pProperty->nWID >= OWN_ATTR_PLUGIN_MIMETYPE) && (pProperty->nWID <= OWN_ATTR_PLUGIN_COMMANDS) )
662 if( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef() ) )
664 uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef()->getComponent(), uno::UNO_QUERY );
665 if( xSet.is() )
667 // allow exceptions to pass through
668 xSet->setPropertyValue( rName, rValue );
671 return true;
673 else
675 return SvxOle2Shape::setPropertyValueImpl( rName, pProperty, rValue );
679 bool SvxPluginShape::getPropertyValueImpl( const OUString& rName, const SfxItemPropertySimpleEntry* pProperty, css::uno::Any& rValue )
681 if( (pProperty->nWID >= OWN_ATTR_PLUGIN_MIMETYPE) && (pProperty->nWID <= OWN_ATTR_PLUGIN_COMMANDS) )
683 if( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef() ) )
685 uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef()->getComponent(), uno::UNO_QUERY );
686 if( xSet.is() )
688 rValue = xSet->getPropertyValue( rName );
691 return true;
693 else
695 return SvxOle2Shape::getPropertyValueImpl( rName, pProperty, rValue );
700 SvxFrameShape::SvxFrameShape(SdrObject* pObject)
701 : SvxOle2Shape( pObject, getSvxMapProvider().GetMap(SVXMAP_FRAME), getSvxMapProvider().GetPropertySet(SVXMAP_FRAME, SdrObject::GetGlobalDrawObjectItemPool()) )
703 SetShapeType( "com.sun.star.drawing.FrameShape" );
706 SvxFrameShape::~SvxFrameShape() throw()
710 void SvxFrameShape::Create( SdrObject* pNewObj, SvxDrawPage* pNewPage )
712 SvxShape::Create( pNewObj, pNewPage );
713 const SvGlobalName aIFrameClassId( SO3_IFRAME_CLASSID );
714 createObject(aIFrameClassId);
715 SetShapeType( "com.sun.star.drawing.FrameShape" );
718 void SAL_CALL SvxFrameShape::setPropertyValue( const OUString& aPropertyName, const css::uno::Any& rValue )
720 SvxShape::setPropertyValue( aPropertyName, rValue );
721 resetModifiedState();
724 void SAL_CALL SvxFrameShape::setPropertyValues( const css::uno::Sequence< OUString >& aPropertyNames, const css::uno::Sequence< css::uno::Any >& rValues )
726 SvxShape::setPropertyValues( aPropertyNames, rValues );
727 resetModifiedState();
730 bool SvxFrameShape::setPropertyValueImpl( const OUString& rName, const SfxItemPropertySimpleEntry* pProperty, const css::uno::Any& rValue )
732 if( (pProperty->nWID >= OWN_ATTR_FRAME_URL) && (pProperty->nWID <= OWN_ATTR_FRAME_MARGIN_HEIGHT) )
734 if( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef() ) )
736 uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef()->getComponent(), uno::UNO_QUERY );
737 if( xSet.is() )
739 // allow exceptions to pass through
740 xSet->setPropertyValue( rName, rValue );
743 return true;
745 else
747 return SvxOle2Shape::setPropertyValueImpl( rName, pProperty, rValue );
751 bool SvxFrameShape::getPropertyValueImpl(const OUString& rName, const SfxItemPropertySimpleEntry* pProperty,
752 css::uno::Any& rValue)
754 if( (pProperty->nWID >= OWN_ATTR_FRAME_URL) && (pProperty->nWID <= OWN_ATTR_FRAME_MARGIN_HEIGHT) )
756 if( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef() ) )
758 uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef()->getComponent(), uno::UNO_QUERY );
759 if( xSet.is() )
761 rValue = xSet->getPropertyValue( rName );
764 return true;
766 else
768 return SvxOle2Shape::getPropertyValueImpl( rName, pProperty, rValue );
771 SvxMediaShape::SvxMediaShape(SdrObject* pObj, OUString const & referer)
772 : SvxShape( pObj, getSvxMapProvider().GetMap(SVXMAP_MEDIA), getSvxMapProvider().GetPropertySet(SVXMAP_MEDIA, SdrObject::GetGlobalDrawObjectItemPool()) ),
773 referer_(referer)
775 SetShapeType( "com.sun.star.drawing.MediaShape" );
779 SvxMediaShape::~SvxMediaShape() throw()
784 bool SvxMediaShape::setPropertyValueImpl( const OUString& rName, const SfxItemPropertySimpleEntry* pProperty, const css::uno::Any& rValue )
786 if( ((pProperty->nWID >= OWN_ATTR_MEDIA_URL) && (pProperty->nWID <= OWN_ATTR_MEDIA_ZOOM))
787 || (pProperty->nWID == OWN_ATTR_MEDIA_STREAM)
788 || (pProperty->nWID == OWN_ATTR_MEDIA_MIMETYPE) )
790 SdrMediaObj* pMedia = static_cast< SdrMediaObj* >( GetSdrObject() );
791 ::avmedia::MediaItem aItem;
792 bool bOk = false;
794 switch( pProperty->nWID )
796 case OWN_ATTR_MEDIA_URL:
797 #if HAVE_FEATURE_AVMEDIA
799 OUString aURL;
800 if( rValue >>= aURL )
802 bOk = true;
803 aItem.setURL( aURL, "", referer_ );
806 #endif
807 break;
809 case OWN_ATTR_MEDIA_LOOP:
810 #if HAVE_FEATURE_AVMEDIA
812 bool bLoop;
814 if( rValue >>= bLoop )
816 bOk = true;
817 aItem.setLoop( bLoop );
820 #endif
821 break;
823 case OWN_ATTR_MEDIA_MUTE:
824 #if HAVE_FEATURE_AVMEDIA
826 bool bMute;
828 if( rValue >>= bMute )
830 bOk = true;
831 aItem.setMute( bMute );
834 #endif
835 break;
837 case OWN_ATTR_MEDIA_VOLUMEDB:
838 #if HAVE_FEATURE_AVMEDIA
840 sal_Int16 nVolumeDB = sal_Int16();
842 if( rValue >>= nVolumeDB )
844 bOk = true;
845 aItem.setVolumeDB( nVolumeDB );
848 #endif
849 break;
851 case OWN_ATTR_MEDIA_ZOOM:
852 #if HAVE_FEATURE_AVMEDIA
854 css::media::ZoomLevel eLevel;
856 if( rValue >>= eLevel )
858 bOk = true;
859 aItem.setZoom( eLevel );
862 #endif
863 break;
865 case OWN_ATTR_MEDIA_MIMETYPE:
866 #if HAVE_FEATURE_AVMEDIA
868 OUString sMimeType;
869 if( rValue >>= sMimeType )
871 bOk = true;
872 aItem.setMimeType( sMimeType );
875 #endif
876 break;
878 case OWN_ATTR_MEDIA_STREAM:
879 #if HAVE_FEATURE_AVMEDIA
882 uno::Reference<io::XInputStream> xStream;
883 if (rValue >>= xStream)
885 pMedia->SetInputStream(xStream);
888 catch (const css::ucb::ContentCreationException&)
890 css::uno::Any exc = cppu::getCaughtException();
891 throw css::lang::WrappedTargetException(
892 "ContentCreationException Setting InputStream!",
893 static_cast<OWeakObject *>(this),
894 exc);
896 catch (const css::ucb::CommandFailedException&)
898 css::uno::Any anyEx = cppu::getCaughtException();
899 throw css::lang::WrappedTargetException(
900 "CommandFailedException Setting InputStream!",
901 static_cast<OWeakObject *>(this),
902 anyEx);
904 #endif
905 break;
907 default:
908 OSL_FAIL("SvxMediaShape::setPropertyValueImpl(), unknown argument!");
911 if( bOk )
913 pMedia->setMediaProperties( aItem );
914 return true;
917 else
919 return SvxShape::setPropertyValueImpl( rName, pProperty, rValue );
922 throw IllegalArgumentException();
926 bool SvxMediaShape::getPropertyValueImpl( const OUString& rName, const SfxItemPropertySimpleEntry* pProperty, css::uno::Any& rValue )
928 if ( ((pProperty->nWID >= OWN_ATTR_MEDIA_URL) &&
929 (pProperty->nWID <= OWN_ATTR_MEDIA_ZOOM))
930 || (pProperty->nWID == OWN_ATTR_MEDIA_STREAM)
931 || (pProperty->nWID == OWN_ATTR_MEDIA_TEMPFILEURL)
932 || (pProperty->nWID == OWN_ATTR_MEDIA_MIMETYPE)
933 || (pProperty->nWID == OWN_ATTR_FALLBACK_GRAPHIC))
935 SdrMediaObj* pMedia = static_cast< SdrMediaObj* >( GetSdrObject() );
936 const ::avmedia::MediaItem aItem( pMedia->getMediaProperties() );
938 switch( pProperty->nWID )
940 case OWN_ATTR_MEDIA_URL:
941 #if HAVE_FEATURE_AVMEDIA
942 rValue <<= aItem.getURL();
943 #endif
944 break;
946 case OWN_ATTR_MEDIA_LOOP:
947 #if HAVE_FEATURE_AVMEDIA
948 rValue <<= aItem.isLoop();
949 #endif
950 break;
952 case OWN_ATTR_MEDIA_MUTE:
953 #if HAVE_FEATURE_AVMEDIA
954 rValue <<= aItem.isMute();
955 #endif
956 break;
958 case OWN_ATTR_MEDIA_VOLUMEDB:
959 #if HAVE_FEATURE_AVMEDIA
960 rValue <<= aItem.getVolumeDB();
961 #endif
962 break;
964 case OWN_ATTR_MEDIA_ZOOM:
965 #if HAVE_FEATURE_AVMEDIA
966 rValue <<= aItem.getZoom();
967 #endif
968 break;
970 case OWN_ATTR_MEDIA_STREAM:
973 rValue <<= pMedia->GetInputStream();
975 catch (const css::ucb::ContentCreationException&)
977 css::uno::Any anyEx = cppu::getCaughtException();
978 throw css::lang::WrappedTargetException(
979 "ContentCreationException Getting InputStream!",
980 static_cast < OWeakObject * > ( this ), anyEx );
982 catch (const css::ucb::CommandFailedException&)
984 css::uno::Any anyEx = cppu::getCaughtException();
985 throw css::lang::WrappedTargetException(
986 "CommandFailedException Getting InputStream!",
987 static_cast < OWeakObject * > ( this ), anyEx );
990 break;
992 case OWN_ATTR_MEDIA_TEMPFILEURL:
993 #if HAVE_FEATURE_AVMEDIA
994 rValue <<= aItem.getTempURL();
995 #endif
996 break;
998 case OWN_ATTR_MEDIA_MIMETYPE:
999 #if HAVE_FEATURE_AVMEDIA
1000 rValue <<= aItem.getMimeType();
1001 #endif
1002 break;
1004 case OWN_ATTR_FALLBACK_GRAPHIC:
1005 rValue <<= pMedia->getSnapshot();
1006 break;
1008 default:
1009 OSL_FAIL("SvxMediaShape::getPropertyValueImpl(), unknown property!");
1011 return true;
1013 else
1015 return SvxShape::getPropertyValueImpl( rName, pProperty, rValue );
1019 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */