bump product version to 7.2.5.1
[LibreOffice.git] / svx / source / unodraw / unoshap4.cxx
blob9274a60a2e28789c86e97bccdf6b5ee619d1eeb0
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 <svx/svdoole2.hxx>
30 #include <svx/svdomedia.hxx>
31 #include <svx/svdpool.hxx>
32 #include <comphelper/classids.hxx>
33 #include <comphelper/embeddedobjectcontainer.hxx>
34 #include <comphelper/propertysequence.hxx>
35 #include <cppuhelper/exc_hlp.hxx>
37 #include <toolkit/helper/vclunohelper.hxx>
39 #include <sot/exchange.hxx>
41 #include <svx/svdmodel.hxx>
42 #include "shapeimpl.hxx"
44 #include <svx/unoshprp.hxx>
46 #include <vcl/gdimtf.hxx>
47 #include <vcl/wmf.hxx>
48 #include <svtools/embedhlp.hxx>
49 #include <sal/log.hxx>
50 #include <tools/debug.hxx>
51 #include <tools/globname.hxx>
52 #include <tools/stream.hxx>
54 #include <config_features.h>
57 using namespace ::cppu;
58 using namespace ::com::sun::star;
59 using namespace ::com::sun::star::uno;
60 using namespace ::com::sun::star::lang;
61 using namespace ::com::sun::star::container;
62 using namespace ::com::sun::star::beans;
65 SvxOle2Shape::SvxOle2Shape(SdrObject* pObject)
66 : SvxShapeText( pObject, getSvxMapProvider().GetMap(SVXMAP_OLE2),
67 getSvxMapProvider().GetPropertySet(SVXMAP_OLE2,SdrObject::GetGlobalDrawObjectItemPool()) )
71 SvxOle2Shape::SvxOle2Shape(SdrObject* pObject, const SfxItemPropertyMapEntry* pPropertyMap, const SvxItemPropertySet* pPropertySet)
72 : SvxShapeText( pObject, pPropertyMap, pPropertySet )
76 SvxOle2Shape::~SvxOle2Shape() noexcept
80 //XPropertySet
81 bool SvxOle2Shape::setPropertyValueImpl( const OUString& rName, const SfxItemPropertyMapEntry* pProperty, const css::uno::Any& rValue )
83 switch( pProperty->nWID )
85 case OWN_ATTR_OLE_VISAREA:
87 // TODO/LATER: seems to make no sense for iconified object
89 awt::Rectangle aVisArea;
90 if( (rValue >>= aVisArea) && dynamic_cast<const SdrOle2Obj* >(GetSdrObject()) != nullptr)
92 Size aTmp( aVisArea.X + aVisArea.Width, aVisArea.Y + aVisArea.Height );
93 uno::Reference < embed::XEmbeddedObject > xObj = static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef();
94 if( xObj.is() )
96 try
98 // the API handles with MapUnit::Map100thMM map mode
99 MapUnit aObjUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( embed::Aspects::MSOLE_CONTENT ) );
100 aTmp = OutputDevice::LogicToLogic(aTmp, MapMode(MapUnit::Map100thMM), MapMode(aObjUnit));
101 xObj->setVisualAreaSize( embed::Aspects::MSOLE_CONTENT, awt::Size( aTmp.Width(), aTmp.Height() ) );
103 catch( uno::Exception& )
105 OSL_FAIL( "Couldn't set the visual area for the object!" );
109 return true;
111 break;
113 case OWN_ATTR_OLE_ASPECT:
115 sal_Int64 nAspect = 0;
116 if( rValue >>= nAspect )
118 static_cast<SdrOle2Obj*>(GetSdrObject())->SetAspect( nAspect );
119 return true;
121 break;
123 case OWN_ATTR_CLSID:
125 OUString aCLSID;
126 if( rValue >>= aCLSID )
128 // init an OLE object with a global name
129 SvGlobalName aClassName;
130 if( aClassName.MakeId( aCLSID ) )
132 if( createObject( aClassName ) )
133 return true;
136 break;
138 case OWN_ATTR_THUMBNAIL:
140 uno::Reference< graphic::XGraphic > xGraphic( rValue, uno::UNO_QUERY );
141 if( xGraphic.is() )
143 const Graphic aGraphic(xGraphic);
144 static_cast<SdrOle2Obj*>(GetSdrObject())->SetGraphic(aGraphic);
145 return true;
147 break;
149 case OWN_ATTR_VALUE_GRAPHIC:
151 uno::Reference< graphic::XGraphic > xGraphic( rValue, uno::UNO_QUERY );
152 if( xGraphic.is() )
154 SdrOle2Obj* pOle = dynamic_cast< SdrOle2Obj* >( GetSdrObject() );
155 if( pOle )
157 GraphicObject aGrafObj( xGraphic );
158 const Graphic& aGraphic( aGrafObj.GetGraphic() );
159 pOle->SetGraphicToObj( aGraphic );
161 return true;
163 break;
165 case OWN_ATTR_PERSISTNAME:
167 OUString aPersistName;
168 if( rValue >>= aPersistName )
170 SdrOle2Obj *pOle;
171 #if OSL_DEBUG_LEVEL > 0
172 pOle = dynamic_cast<SdrOle2Obj*>(GetSdrObject());
173 assert(pOle);
174 #else
175 pOle = static_cast<SdrOle2Obj*>(GetSdrObject());
176 #endif
177 pOle->SetPersistName( aPersistName );
178 return true;
180 break;
182 case OWN_ATTR_OLE_LINKURL:
184 OUString aLinkURL;
185 if( rValue >>= aLinkURL )
187 createLink( aLinkURL );
188 return true;
190 break;
192 default:
193 return SvxShapeText::setPropertyValueImpl( rName, pProperty, rValue );
196 throw IllegalArgumentException();
199 bool SvxOle2Shape::getPropertyValueImpl( const OUString& rName, const SfxItemPropertyMapEntry* pProperty, css::uno::Any& rValue )
201 switch( pProperty->nWID )
203 case OWN_ATTR_CLSID:
205 OUString aCLSID;
206 GetClassName_Impl(aCLSID);
207 rValue <<= aCLSID;
208 break;
211 case OWN_ATTR_INTERNAL_OLE:
213 OUString sCLSID;
214 rValue <<= SotExchange::IsInternal( GetClassName_Impl(sCLSID) );
215 break;
218 case OWN_ATTR_METAFILE:
220 SdrOle2Obj* pObj = dynamic_cast<SdrOle2Obj*>(GetSdrObject());
221 if( pObj )
223 const Graphic* pGraphic = pObj->GetGraphic();
224 if( pGraphic )
226 bool bIsWMF = false;
227 if ( pGraphic->IsGfxLink() )
229 GfxLink aLnk = pGraphic->GetGfxLink();
230 if ( aLnk.GetType() == GfxLinkType::NativeWmf )
232 bIsWMF = true;
233 uno::Sequence<sal_Int8> aSeq(reinterpret_cast<sal_Int8 const *>(aLnk.GetData()), static_cast<sal_Int32>(aLnk.GetDataSize()));
234 rValue <<= aSeq;
237 if ( !bIsWMF )
239 // #i119735# just use GetGDIMetaFile, it will create a buffered version of contained bitmap now automatically
240 GDIMetaFile aMtf(pObj->GetGraphic()->GetGDIMetaFile());
241 SvMemoryStream aDestStrm( 65535, 65535 );
242 ConvertGDIMetaFileToWMF( aMtf, aDestStrm, nullptr, false );
243 const uno::Sequence<sal_Int8> aSeq(
244 static_cast< const sal_Int8* >(aDestStrm.GetData()),
245 aDestStrm.GetEndOfData());
246 rValue <<= aSeq;
250 else
252 rValue = GetBitmap( true );
254 break;
257 case OWN_ATTR_OLE_VISAREA:
259 awt::Rectangle aVisArea;
260 if( dynamic_cast<const SdrOle2Obj* >(GetSdrObject()) != nullptr)
262 MapMode aMapMode( MapUnit::Map100thMM ); // the API uses this map mode
263 Size aTmp = static_cast<SdrOle2Obj*>(GetSdrObject())->GetOrigObjSize( &aMapMode ); // get the size in the requested map mode
264 aVisArea = awt::Rectangle( 0, 0, aTmp.Width(), aTmp.Height() );
267 rValue <<= aVisArea;
268 break;
271 case OWN_ATTR_OLESIZE:
273 Size aTmp( static_cast<SdrOle2Obj*>(GetSdrObject())->GetOrigObjSize() );
274 rValue <<= awt::Size( aTmp.Width(), aTmp.Height() );
275 break;
278 case OWN_ATTR_OLE_ASPECT:
280 rValue <<= static_cast<SdrOle2Obj*>(GetSdrObject())->GetAspect();
281 break;
284 case OWN_ATTR_OLEMODEL:
285 case OWN_ATTR_OLE_EMBEDDED_OBJECT:
286 case OWN_ATTR_OLE_EMBEDDED_OBJECT_NONEWCLIENT:
288 SdrOle2Obj* pObj = dynamic_cast<SdrOle2Obj*>( GetSdrObject() );
289 if( pObj )
291 uno::Reference < embed::XEmbeddedObject > xObj( pObj->GetObjRef() );
292 if ( xObj.is()
293 && ( pProperty->nWID == OWN_ATTR_OLE_EMBEDDED_OBJECT || pProperty->nWID == OWN_ATTR_OLE_EMBEDDED_OBJECT_NONEWCLIENT || svt::EmbeddedObjectRef::TryRunningState( xObj ) ) )
295 // Discussed with CL fue to the before GetPaintingPageView
296 // usage. Removed it, former fallback is used now
297 if ( pProperty->nWID == OWN_ATTR_OLEMODEL || pProperty->nWID == OWN_ATTR_OLE_EMBEDDED_OBJECT )
299 const bool bSuccess(pObj->AddOwnLightClient());
300 SAL_WARN_IF(!bSuccess, "svx.svdraw", "An object without client is provided!");
303 if ( pProperty->nWID == OWN_ATTR_OLEMODEL )
304 rValue <<= pObj->GetObjRef()->getComponent();
305 else
306 rValue <<= xObj;
309 break;
312 case OWN_ATTR_VALUE_GRAPHIC:
314 uno::Reference< graphic::XGraphic > xGraphic;
315 const Graphic* pGraphic = static_cast<SdrOle2Obj*>( GetSdrObject() )->GetGraphic();
316 if( pGraphic )
317 xGraphic = pGraphic->GetXGraphic();
318 rValue <<= xGraphic;
319 break;
322 case OWN_ATTR_THUMBNAIL:
324 uno::Reference< graphic::XGraphic > xGraphic;
325 const Graphic* pGraphic = static_cast<SdrOle2Obj*>( GetSdrObject() )->GetGraphic();
326 if( pGraphic )
327 xGraphic = pGraphic->GetXGraphic();
328 rValue <<= xGraphic;
329 break;
331 case OWN_ATTR_PERSISTNAME:
333 OUString aPersistName;
334 SdrOle2Obj* pOle = dynamic_cast< SdrOle2Obj* >( GetSdrObject() );
336 if( pOle )
338 aPersistName = pOle->GetPersistName();
339 if( !aPersistName.isEmpty() )
341 ::comphelper::IEmbeddedHelper* pPersist(GetSdrObject()->getSdrModelFromSdrObject().GetPersist());
342 if( (nullptr == pPersist) || !pPersist->getEmbeddedObjectContainer().HasEmbeddedObject( pOle->GetPersistName() ) )
343 aPersistName.clear();
347 rValue <<= aPersistName;
348 break;
350 case OWN_ATTR_OLE_LINKURL:
352 OUString aLinkURL;
353 SdrOle2Obj* pOle = dynamic_cast< SdrOle2Obj* >( GetSdrObject() );
355 if( pOle )
357 uno::Reference< embed::XLinkageSupport > xLink( pOle->GetObjRef(), uno::UNO_QUERY );
358 if ( xLink.is() && xLink->isLink() )
359 aLinkURL = xLink->getLinkURL();
362 rValue <<= aLinkURL;
363 break;
365 default:
366 return SvxShapeText::getPropertyValueImpl( rName, pProperty, rValue );
369 return true;
372 bool SvxOle2Shape::createObject( const SvGlobalName &aClassName )
374 DBG_TESTSOLARMUTEX();
376 SdrOle2Obj* pOle2Obj = dynamic_cast< SdrOle2Obj* >( GetSdrObject() );
377 if ( !pOle2Obj || !pOle2Obj->IsEmpty() )
378 return false;
380 // create storage and inplace object
381 ::comphelper::IEmbeddedHelper* pPersist = GetSdrObject()->getSdrModelFromSdrObject().GetPersist();
382 OUString aPersistName;
383 OUString aTmpStr;
384 if( SvxShape::getPropertyValue( UNO_NAME_OLE2_PERSISTNAME ) >>= aTmpStr )
385 aPersistName = aTmpStr;
387 uno::Sequence<beans::PropertyValue> objArgs( comphelper::InitPropertySequence({
388 { "DefaultParentBaseURL", Any(pPersist->getDocumentBaseURL()) }
389 }));
390 //TODO/LATER: how to cope with creation failure?!
391 uno::Reference<embed::XEmbeddedObject> xObj(
392 pPersist->getEmbeddedObjectContainer().CreateEmbeddedObject(
393 aClassName.GetByteSequence(), objArgs, aPersistName));
394 if( xObj.is() )
396 tools::Rectangle aRect = pOle2Obj->GetLogicRect();
397 if ( aRect.GetWidth() == 101 && aRect.GetHeight() == 101 )
399 // TODO/LATER: is it possible that this method is used to create an iconified object?
400 // default size
403 awt::Size aSz = xObj->getVisualAreaSize( pOle2Obj->GetAspect() );
404 aRect.SetSize( Size( aSz.Width, aSz.Height ) );
406 catch( embed::NoVisualAreaSizeException& )
408 pOle2Obj->SetLogicRect( aRect );
410 else
412 awt::Size aSz;
413 Size aSize = aRect.GetSize();
414 aSz.Width = aSize.Width();
415 aSz.Height = aSize.Height();
416 if (aSz.Width != 0 || aSz.Height != 0)
418 //HACK: can aSz legally be empty?
419 xObj->setVisualAreaSize( pOle2Obj->GetAspect(), aSz );
423 // connect the object after the visual area is set
424 aTmpStr = aPersistName;
425 SvxShape::setPropertyValue( UNO_NAME_OLE2_PERSISTNAME, Any( aTmpStr ) );
427 // the object is inserted during setting of PersistName property usually
428 if( pOle2Obj->IsEmpty() )
429 pOle2Obj->SetObjRef( xObj );
432 return xObj.is();
435 void SvxOle2Shape::createLink( const OUString& aLinkURL )
437 DBG_TESTSOLARMUTEX();
439 SdrOle2Obj* pOle2Obj = dynamic_cast< SdrOle2Obj* >( GetSdrObject() );
440 if ( !pOle2Obj || !pOle2Obj->IsEmpty() )
441 return;
443 OUString aPersistName;
445 ::comphelper::IEmbeddedHelper* pPersist = GetSdrObject()->getSdrModelFromSdrObject().GetPersist();
447 uno::Sequence< beans::PropertyValue > aMediaDescr( 1 );
448 aMediaDescr[0].Name = "URL";
449 aMediaDescr[0].Value <<= aLinkURL;
451 uno::Reference< task::XInteractionHandler > xInteraction = pPersist->getInteractionHandler();
452 if ( xInteraction.is() )
454 aMediaDescr.realloc( 2 );
455 aMediaDescr[1].Name = "InteractionHandler";
456 aMediaDescr[1].Value <<= xInteraction;
459 //TODO/LATER: how to cope with creation failure?!
460 uno::Reference< embed::XEmbeddedObject > xObj =
461 pPersist->getEmbeddedObjectContainer().InsertEmbeddedLink( aMediaDescr , aPersistName );
463 if( !xObj.is() )
464 return;
466 tools::Rectangle aRect = pOle2Obj->GetLogicRect();
467 if ( aRect.GetWidth() == 101 && aRect.GetHeight() == 101 )
469 // default size
472 awt::Size aSz = xObj->getVisualAreaSize( pOle2Obj->GetAspect() );
473 aRect.SetSize( Size( aSz.Width, aSz.Height ) );
475 catch( embed::NoVisualAreaSizeException& )
477 pOle2Obj->SetLogicRect( aRect );
479 else
481 awt::Size aSz;
482 Size aSize = pOle2Obj->GetLogicRect().GetSize();
483 aSz.Width = aSize.Width();
484 aSz.Height = aSize.Height();
485 xObj->setVisualAreaSize( pOle2Obj->GetAspect(), aSz );
488 // connect the object after the visual area is set
489 SvxShape::setPropertyValue( UNO_NAME_OLE2_PERSISTNAME, uno::makeAny( aPersistName ) );
491 // the object is inserted during setting of PersistName property usually
492 if ( pOle2Obj->IsEmpty() )
493 pOle2Obj->SetObjRef( xObj );
496 void SvxOle2Shape::resetModifiedState()
498 ::comphelper::IEmbeddedHelper* pPersist = GetSdrObject()->getSdrModelFromSdrObject().GetPersist();
499 if( pPersist && !pPersist->isEnableSetModified() )
501 SdrOle2Obj* pOle = dynamic_cast< SdrOle2Obj* >( GetSdrObject() );
502 if( pOle && !pOle->IsEmpty() )
504 uno::Reference < util::XModifiable > xMod( pOle->GetObjRef(), uno::UNO_QUERY );
505 if( xMod.is() )
506 // TODO/MBA: what's this?!
507 xMod->setModified( false );
512 SvGlobalName SvxOle2Shape::GetClassName_Impl(OUString& rHexCLSID)
514 DBG_TESTSOLARMUTEX();
515 SvGlobalName aClassName;
516 SdrOle2Obj* pOle2Obj = dynamic_cast< SdrOle2Obj* >( GetSdrObject() );
518 if( pOle2Obj )
520 rHexCLSID.clear();
522 if( pOle2Obj->IsEmpty() )
524 ::comphelper::IEmbeddedHelper* pPersist = GetSdrObject()->getSdrModelFromSdrObject().GetPersist();
525 if( pPersist )
527 uno::Reference < embed::XEmbeddedObject > xObj =
528 pPersist->getEmbeddedObjectContainer().GetEmbeddedObject( pOle2Obj->GetPersistName() );
529 if ( xObj.is() )
531 aClassName = SvGlobalName( xObj->getClassID() );
532 rHexCLSID = aClassName.GetHexName();
537 if (rHexCLSID.isEmpty())
539 const uno::Reference < embed::XEmbeddedObject >& xObj( pOle2Obj->GetObjRef() );
540 if ( xObj.is() )
542 aClassName = SvGlobalName( xObj->getClassID() );
543 rHexCLSID = aClassName.GetHexName();
548 return aClassName;
551 SvxAppletShape::SvxAppletShape(SdrObject* pObject)
552 : SvxOle2Shape( pObject, getSvxMapProvider().GetMap(SVXMAP_APPLET), getSvxMapProvider().GetPropertySet(SVXMAP_APPLET, SdrObject::GetGlobalDrawObjectItemPool()) )
554 SetShapeType( "com.sun.star.drawing.AppletShape" );
557 SvxAppletShape::~SvxAppletShape() noexcept
561 void SvxAppletShape::Create( SdrObject* pNewObj, SvxDrawPage* pNewPage )
563 SvxShape::Create( pNewObj, pNewPage );
564 const SvGlobalName aAppletClassId( SO3_APPLET_CLASSID );
565 createObject(aAppletClassId);
566 SetShapeType( "com.sun.star.drawing.AppletShape" );
569 void SAL_CALL SvxAppletShape::setPropertyValue( const OUString& aPropertyName, const css::uno::Any& rValue )
571 SvxShape::setPropertyValue( aPropertyName, rValue );
572 resetModifiedState();
575 void SAL_CALL SvxAppletShape::setPropertyValues( const css::uno::Sequence< OUString >& aPropertyNames, const css::uno::Sequence< css::uno::Any >& rValues )
577 SvxShape::setPropertyValues( aPropertyNames, rValues );
578 resetModifiedState();
581 bool SvxAppletShape::setPropertyValueImpl( const OUString& rName, const SfxItemPropertyMapEntry* pProperty, const css::uno::Any& rValue )
583 if( (pProperty->nWID >= OWN_ATTR_APPLET_DOCBASE) && (pProperty->nWID <= OWN_ATTR_APPLET_ISSCRIPT) )
585 if ( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef() ) )
587 uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef()->getComponent(), uno::UNO_QUERY );
588 if( xSet.is() )
590 // allow exceptions to pass through
591 xSet->setPropertyValue( rName, rValue );
594 return true;
596 else
598 return SvxOle2Shape::setPropertyValueImpl( rName, pProperty, rValue );
602 bool SvxAppletShape::getPropertyValueImpl( const OUString& rName, const SfxItemPropertyMapEntry* pProperty, css::uno::Any& rValue )
604 if( (pProperty->nWID >= OWN_ATTR_APPLET_DOCBASE) && (pProperty->nWID <= OWN_ATTR_APPLET_ISSCRIPT) )
606 if ( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef() ) )
608 uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef()->getComponent(), uno::UNO_QUERY );
609 if( xSet.is() )
611 rValue = xSet->getPropertyValue( rName );
614 return true;
616 else
618 return SvxOle2Shape::getPropertyValueImpl( rName, pProperty, rValue );
622 SvxPluginShape::SvxPluginShape(SdrObject* pObject)
623 : SvxOle2Shape( pObject, getSvxMapProvider().GetMap(SVXMAP_PLUGIN), getSvxMapProvider().GetPropertySet(SVXMAP_PLUGIN, SdrObject::GetGlobalDrawObjectItemPool()) )
625 SetShapeType( "com.sun.star.drawing.PluginShape" );
628 SvxPluginShape::~SvxPluginShape() noexcept
632 void SvxPluginShape::Create( SdrObject* pNewObj, SvxDrawPage* pNewPage )
634 SvxShape::Create( pNewObj, pNewPage );
635 const SvGlobalName aPluginClassId( SO3_PLUGIN_CLASSID );
636 createObject(aPluginClassId);
637 SetShapeType( "com.sun.star.drawing.PluginShape" );
640 void SAL_CALL SvxPluginShape::setPropertyValue( const OUString& aPropertyName, const css::uno::Any& rValue )
642 SvxShape::setPropertyValue( aPropertyName, rValue );
643 resetModifiedState();
646 void SAL_CALL SvxPluginShape::setPropertyValues( const css::uno::Sequence< OUString >& aPropertyNames, const css::uno::Sequence< css::uno::Any >& rValues )
648 SvxShape::setPropertyValues( aPropertyNames, rValues );
649 resetModifiedState();
652 bool SvxPluginShape::setPropertyValueImpl( const OUString& rName, const SfxItemPropertyMapEntry* pProperty, const css::uno::Any& rValue )
654 if( (pProperty->nWID >= OWN_ATTR_PLUGIN_MIMETYPE) && (pProperty->nWID <= OWN_ATTR_PLUGIN_COMMANDS) )
656 if( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef() ) )
658 uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef()->getComponent(), uno::UNO_QUERY );
659 if( xSet.is() )
661 // allow exceptions to pass through
662 xSet->setPropertyValue( rName, rValue );
665 return true;
667 else
669 return SvxOle2Shape::setPropertyValueImpl( rName, pProperty, rValue );
673 bool SvxPluginShape::getPropertyValueImpl( const OUString& rName, const SfxItemPropertyMapEntry* pProperty, css::uno::Any& rValue )
675 if( (pProperty->nWID >= OWN_ATTR_PLUGIN_MIMETYPE) && (pProperty->nWID <= OWN_ATTR_PLUGIN_COMMANDS) )
677 if( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef() ) )
679 uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef()->getComponent(), uno::UNO_QUERY );
680 if( xSet.is() )
682 rValue = xSet->getPropertyValue( rName );
685 return true;
687 else
689 return SvxOle2Shape::getPropertyValueImpl( rName, pProperty, rValue );
694 SvxFrameShape::SvxFrameShape(SdrObject* pObject)
695 : SvxOle2Shape( pObject, getSvxMapProvider().GetMap(SVXMAP_FRAME), getSvxMapProvider().GetPropertySet(SVXMAP_FRAME, SdrObject::GetGlobalDrawObjectItemPool()) )
697 SetShapeType( "com.sun.star.drawing.FrameShape" );
700 SvxFrameShape::~SvxFrameShape() noexcept
704 void SvxFrameShape::Create( SdrObject* pNewObj, SvxDrawPage* pNewPage )
706 SvxShape::Create( pNewObj, pNewPage );
707 const SvGlobalName aIFrameClassId( SO3_IFRAME_CLASSID );
708 createObject(aIFrameClassId);
709 SetShapeType( "com.sun.star.drawing.FrameShape" );
712 void SAL_CALL SvxFrameShape::setPropertyValue( const OUString& aPropertyName, const css::uno::Any& rValue )
714 SvxShape::setPropertyValue( aPropertyName, rValue );
715 resetModifiedState();
718 void SAL_CALL SvxFrameShape::setPropertyValues( const css::uno::Sequence< OUString >& aPropertyNames, const css::uno::Sequence< css::uno::Any >& rValues )
720 SvxShape::setPropertyValues( aPropertyNames, rValues );
721 resetModifiedState();
724 bool SvxFrameShape::setPropertyValueImpl( const OUString& rName, const SfxItemPropertyMapEntry* pProperty, const css::uno::Any& rValue )
726 if( (pProperty->nWID >= OWN_ATTR_FRAME_URL) && (pProperty->nWID <= OWN_ATTR_FRAME_MARGIN_HEIGHT) )
728 if( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef() ) )
730 uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef()->getComponent(), uno::UNO_QUERY );
731 if( xSet.is() )
733 // allow exceptions to pass through
734 xSet->setPropertyValue( rName, rValue );
737 return true;
739 else
741 return SvxOle2Shape::setPropertyValueImpl( rName, pProperty, rValue );
745 bool SvxFrameShape::getPropertyValueImpl(const OUString& rName, const SfxItemPropertyMapEntry* pProperty,
746 css::uno::Any& rValue)
748 if( (pProperty->nWID >= OWN_ATTR_FRAME_URL) && (pProperty->nWID <= OWN_ATTR_FRAME_MARGIN_HEIGHT) )
750 if( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef() ) )
752 uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef()->getComponent(), uno::UNO_QUERY );
753 if( xSet.is() )
755 rValue = xSet->getPropertyValue( rName );
758 return true;
760 else
762 return SvxOle2Shape::getPropertyValueImpl( rName, pProperty, rValue );
765 SvxMediaShape::SvxMediaShape(SdrObject* pObj, OUString const & referer)
766 : SvxShape( pObj, getSvxMapProvider().GetMap(SVXMAP_MEDIA), getSvxMapProvider().GetPropertySet(SVXMAP_MEDIA, SdrObject::GetGlobalDrawObjectItemPool()) ),
767 referer_(referer)
769 SetShapeType( "com.sun.star.drawing.MediaShape" );
773 SvxMediaShape::~SvxMediaShape() noexcept
778 bool SvxMediaShape::setPropertyValueImpl( const OUString& rName, const SfxItemPropertyMapEntry* pProperty, const css::uno::Any& rValue )
780 if( ((pProperty->nWID >= OWN_ATTR_MEDIA_URL) && (pProperty->nWID <= OWN_ATTR_MEDIA_ZOOM))
781 || (pProperty->nWID == OWN_ATTR_MEDIA_STREAM)
782 || (pProperty->nWID == OWN_ATTR_MEDIA_MIMETYPE)
783 || (pProperty->nWID == OWN_ATTR_VALUE_GRAPHIC))
785 SdrMediaObj* pMedia = static_cast< SdrMediaObj* >( GetSdrObject() );
786 ::avmedia::MediaItem aItem;
787 bool bOk = false;
789 switch( pProperty->nWID )
791 case OWN_ATTR_MEDIA_URL:
792 #if HAVE_FEATURE_AVMEDIA
794 OUString aURL;
795 if( rValue >>= aURL )
797 bOk = true;
798 aItem.setURL( aURL, "", referer_ );
801 #endif
802 break;
804 case OWN_ATTR_MEDIA_LOOP:
805 #if HAVE_FEATURE_AVMEDIA
807 bool bLoop;
809 if( rValue >>= bLoop )
811 bOk = true;
812 aItem.setLoop( bLoop );
815 #endif
816 break;
818 case OWN_ATTR_MEDIA_MUTE:
819 #if HAVE_FEATURE_AVMEDIA
821 bool bMute;
823 if( rValue >>= bMute )
825 bOk = true;
826 aItem.setMute( bMute );
829 #endif
830 break;
832 case OWN_ATTR_MEDIA_VOLUMEDB:
833 #if HAVE_FEATURE_AVMEDIA
835 sal_Int16 nVolumeDB = sal_Int16();
837 if( rValue >>= nVolumeDB )
839 bOk = true;
840 aItem.setVolumeDB( nVolumeDB );
843 #endif
844 break;
846 case OWN_ATTR_MEDIA_ZOOM:
847 #if HAVE_FEATURE_AVMEDIA
849 css::media::ZoomLevel eLevel;
851 if( rValue >>= eLevel )
853 bOk = true;
854 aItem.setZoom( eLevel );
857 #endif
858 break;
860 case OWN_ATTR_MEDIA_MIMETYPE:
861 #if HAVE_FEATURE_AVMEDIA
863 OUString sMimeType;
864 if( rValue >>= sMimeType )
866 bOk = true;
867 aItem.setMimeType( sMimeType );
870 #endif
871 break;
873 case OWN_ATTR_VALUE_GRAPHIC:
874 #if HAVE_FEATURE_AVMEDIA
876 uno::Reference<graphic::XGraphic> xGraphic(rValue, uno::UNO_QUERY);
877 if (xGraphic.is())
879 bOk = true;
880 aItem.setGraphic(Graphic(xGraphic));
883 #endif
884 break;
886 case OWN_ATTR_MEDIA_STREAM:
887 #if HAVE_FEATURE_AVMEDIA
890 uno::Reference<io::XInputStream> xStream;
891 if (rValue >>= xStream)
893 pMedia->SetInputStream(xStream);
896 catch (const css::ucb::ContentCreationException&)
898 css::uno::Any exc = cppu::getCaughtException();
899 throw css::lang::WrappedTargetException(
900 "ContentCreationException Setting InputStream!",
901 static_cast<OWeakObject *>(this),
902 exc);
904 catch (const css::ucb::CommandFailedException&)
906 css::uno::Any anyEx = cppu::getCaughtException();
907 throw css::lang::WrappedTargetException(
908 "CommandFailedException Setting InputStream!",
909 static_cast<OWeakObject *>(this),
910 anyEx);
912 #endif
913 break;
915 default:
916 OSL_FAIL("SvxMediaShape::setPropertyValueImpl(), unknown argument!");
919 if( bOk )
921 pMedia->setMediaProperties( aItem );
922 return true;
925 else
927 return SvxShape::setPropertyValueImpl( rName, pProperty, rValue );
930 throw IllegalArgumentException();
934 bool SvxMediaShape::getPropertyValueImpl( const OUString& rName, const SfxItemPropertyMapEntry* pProperty, css::uno::Any& rValue )
936 if ( ((pProperty->nWID >= OWN_ATTR_MEDIA_URL) &&
937 (pProperty->nWID <= OWN_ATTR_MEDIA_ZOOM))
938 || (pProperty->nWID == OWN_ATTR_MEDIA_STREAM)
939 || (pProperty->nWID == OWN_ATTR_MEDIA_TEMPFILEURL)
940 || (pProperty->nWID == OWN_ATTR_MEDIA_MIMETYPE)
941 || (pProperty->nWID == OWN_ATTR_FALLBACK_GRAPHIC)
942 || (pProperty->nWID == OWN_ATTR_VALUE_GRAPHIC))
944 SdrMediaObj* pMedia = static_cast< SdrMediaObj* >( GetSdrObject() );
945 const ::avmedia::MediaItem aItem( pMedia->getMediaProperties() );
947 switch( pProperty->nWID )
949 case OWN_ATTR_MEDIA_URL:
950 #if HAVE_FEATURE_AVMEDIA
951 rValue <<= aItem.getURL();
952 #endif
953 break;
955 case OWN_ATTR_MEDIA_LOOP:
956 #if HAVE_FEATURE_AVMEDIA
957 rValue <<= aItem.isLoop();
958 #endif
959 break;
961 case OWN_ATTR_MEDIA_MUTE:
962 #if HAVE_FEATURE_AVMEDIA
963 rValue <<= aItem.isMute();
964 #endif
965 break;
967 case OWN_ATTR_MEDIA_VOLUMEDB:
968 #if HAVE_FEATURE_AVMEDIA
969 rValue <<= aItem.getVolumeDB();
970 #endif
971 break;
973 case OWN_ATTR_MEDIA_ZOOM:
974 #if HAVE_FEATURE_AVMEDIA
975 rValue <<= aItem.getZoom();
976 #endif
977 break;
979 case OWN_ATTR_MEDIA_STREAM:
982 rValue <<= pMedia->GetInputStream();
984 catch (const css::ucb::ContentCreationException&)
986 css::uno::Any anyEx = cppu::getCaughtException();
987 throw css::lang::WrappedTargetException(
988 "ContentCreationException Getting InputStream!",
989 static_cast < OWeakObject * > ( this ), anyEx );
991 catch (const css::ucb::CommandFailedException&)
993 css::uno::Any anyEx = cppu::getCaughtException();
994 throw css::lang::WrappedTargetException(
995 "CommandFailedException Getting InputStream!",
996 static_cast < OWeakObject * > ( this ), anyEx );
999 break;
1001 case OWN_ATTR_MEDIA_TEMPFILEURL:
1002 #if HAVE_FEATURE_AVMEDIA
1003 rValue <<= aItem.getTempURL();
1004 #endif
1005 break;
1007 case OWN_ATTR_MEDIA_MIMETYPE:
1008 #if HAVE_FEATURE_AVMEDIA
1009 rValue <<= aItem.getMimeType();
1010 #endif
1011 break;
1013 case OWN_ATTR_VALUE_GRAPHIC:
1014 #if HAVE_FEATURE_AVMEDIA
1016 Graphic aGraphic = aItem.getGraphic();
1017 if (!aGraphic.IsNone())
1019 rValue <<= aGraphic.GetXGraphic();
1022 #endif
1023 break;
1025 case OWN_ATTR_FALLBACK_GRAPHIC:
1026 rValue <<= pMedia->getSnapshot();
1027 break;
1029 default:
1030 OSL_FAIL("SvxMediaShape::getPropertyValueImpl(), unknown property!");
1032 return true;
1034 else
1036 return SvxShape::getPropertyValueImpl( rName, pProperty, rValue );
1040 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */