ScriptForge - Methods about data arrays
[LibreOffice.git] / svx / source / unodraw / unoshap4.cxx
blob54ba90c804eb2fe0571d9f98826577c4e1795db3
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/DirectoryHelper.hxx>
34 #include <comphelper/embeddedobjectcontainer.hxx>
35 #include <comphelper/propertysequence.hxx>
36 #include <comphelper/propertyvalue.hxx>
37 #include <cppuhelper/exc_hlp.hxx>
39 #include <toolkit/helper/vclunohelper.hxx>
41 #include <sot/exchange.hxx>
43 #include <svx/svdmodel.hxx>
44 #include "shapeimpl.hxx"
46 #include <svx/unoshprp.hxx>
48 #include <utility>
49 #include <vcl/gdimtf.hxx>
50 #include <vcl/wmf.hxx>
51 #include <svtools/embedhlp.hxx>
52 #include <sal/log.hxx>
53 #include <tools/debug.hxx>
54 #include <tools/globname.hxx>
55 #include <tools/stream.hxx>
57 #include <config_features.h>
60 using namespace ::cppu;
61 using namespace ::com::sun::star;
62 using namespace ::com::sun::star::uno;
63 using namespace ::com::sun::star::lang;
64 using namespace ::com::sun::star::beans;
67 SvxOle2Shape::SvxOle2Shape(SdrObject* pObject, OUString referer)
68 : SvxShapeText(pObject, getSvxMapProvider().GetMap(SVXMAP_OLE2),
69 getSvxMapProvider().GetPropertySet(SVXMAP_OLE2,SdrObject::GetGlobalDrawObjectItemPool()))
70 , referer_(std::move(referer))
74 SvxOle2Shape::SvxOle2Shape(SdrObject* pObject, OUString referer, std::span<const SfxItemPropertyMapEntry> pPropertyMap, const SvxItemPropertySet* pPropertySet)
75 : SvxShapeText(pObject, pPropertyMap, pPropertySet)
76 , referer_(std::move(referer))
80 SvxOle2Shape::~SvxOle2Shape() noexcept
84 //XPropertySet
85 bool SvxOle2Shape::setPropertyValueImpl( const OUString& rName, const SfxItemPropertyMapEntry* pProperty, const css::uno::Any& rValue )
87 switch( pProperty->nWID )
89 case OWN_ATTR_OLE_VISAREA:
91 // TODO/LATER: seems to make no sense for iconified object
93 awt::Rectangle aVisArea;
94 if( !(rValue >>= aVisArea))
95 break;
96 if( auto pOle2Obj = dynamic_cast<SdrOle2Obj* >(GetSdrObject()) )
98 Size aTmp( aVisArea.X + aVisArea.Width, aVisArea.Y + aVisArea.Height );
99 uno::Reference < embed::XEmbeddedObject > xObj = pOle2Obj->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, this );
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 SfxItemPropertyMapEntry* 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 buffered version of contained bitmap now automatically
246 GDIMetaFile aMtf(pGraphic->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 due 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{
454 comphelper::makePropertyValue(u"URL"_ustr, aLinkURL),
455 comphelper::makePropertyValue(u"Referer"_ustr, referer_)
458 uno::Reference< task::XInteractionHandler > xInteraction = pPersist->getInteractionHandler();
459 if ( xInteraction.is() )
461 aMediaDescr.realloc( 3 );
462 auto pMediaDescr = aMediaDescr.getArray();
463 pMediaDescr[2].Name = "InteractionHandler";
464 pMediaDescr[2].Value <<= xInteraction;
467 //TODO/LATER: how to cope with creation failure?!
468 uno::Reference< embed::XEmbeddedObject > xObj =
469 pPersist->getEmbeddedObjectContainer().InsertEmbeddedLink( aMediaDescr , aPersistName );
471 if( !xObj.is() )
472 return;
474 tools::Rectangle aRect = pOle2Obj->GetLogicRect();
475 if ( aRect.GetWidth() == 101 && aRect.GetHeight() == 101 )
477 // default size
480 awt::Size aSz = xObj->getVisualAreaSize( pOle2Obj->GetAspect() );
481 aRect.SetSize( Size( aSz.Width, aSz.Height ) );
483 catch (const uno::Exception&)
485 pOle2Obj->SetLogicRect( aRect );
487 else
489 awt::Size aSz;
490 Size aSize = pOle2Obj->GetLogicRect().GetSize();
491 aSz.Width = aSize.Width();
492 aSz.Height = aSize.Height();
493 xObj->setVisualAreaSize( pOle2Obj->GetAspect(), aSz );
496 // connect the object after the visual area is set
497 SvxShape::setPropertyValue( UNO_NAME_OLE2_PERSISTNAME, uno::Any( aPersistName ) );
499 // the object is inserted during setting of PersistName property usually
500 if ( pOle2Obj->IsEmpty() )
501 pOle2Obj->SetObjRef( xObj );
504 void SvxOle2Shape::resetModifiedState()
506 SdrObject* pObject = GetSdrObject();
507 ::comphelper::IEmbeddedHelper* pPersist = pObject ? pObject->getSdrModelFromSdrObject().GetPersist() : nullptr;
508 if( pPersist && !pPersist->isEnableSetModified() )
510 SdrOle2Obj* pOle = dynamic_cast< SdrOle2Obj* >(pObject);
511 if( pOle && !pOle->IsEmpty() )
513 uno::Reference < util::XModifiable > xMod( pOle->GetObjRef(), uno::UNO_QUERY );
514 if( xMod.is() )
515 // TODO/MBA: what's this?!
516 xMod->setModified( false );
521 SvGlobalName SvxOle2Shape::GetClassName_Impl(OUString& rHexCLSID)
523 DBG_TESTSOLARMUTEX();
524 SvGlobalName aClassName;
525 SdrOle2Obj* pOle2Obj = dynamic_cast< SdrOle2Obj* >( GetSdrObject() );
527 if( pOle2Obj )
529 rHexCLSID.clear();
531 if( pOle2Obj->IsEmpty() )
533 ::comphelper::IEmbeddedHelper* pPersist = GetSdrObject()->getSdrModelFromSdrObject().GetPersist();
534 if( pPersist )
536 uno::Reference < embed::XEmbeddedObject > xObj =
537 pPersist->getEmbeddedObjectContainer().GetEmbeddedObject( pOle2Obj->GetPersistName() );
538 if ( xObj.is() )
540 aClassName = SvGlobalName( xObj->getClassID() );
541 rHexCLSID = aClassName.GetHexName();
546 if (rHexCLSID.isEmpty())
548 const uno::Reference < embed::XEmbeddedObject >& xObj( pOle2Obj->GetObjRef() );
549 if ( xObj.is() )
551 aClassName = SvGlobalName( xObj->getClassID() );
552 rHexCLSID = aClassName.GetHexName();
557 return aClassName;
560 OUString SvxOle2Shape::GetAndClearInitialFrameURL()
562 return OUString();
565 SvxAppletShape::SvxAppletShape(SdrObject* pObject, OUString referer)
566 : SvxOle2Shape(pObject, std::move(referer), getSvxMapProvider().GetMap(SVXMAP_APPLET), getSvxMapProvider().GetPropertySet(SVXMAP_APPLET, SdrObject::GetGlobalDrawObjectItemPool()))
568 SetShapeType( u"com.sun.star.drawing.AppletShape"_ustr );
571 SvxAppletShape::~SvxAppletShape() noexcept
575 void SvxAppletShape::Create( SdrObject* pNewObj, SvxDrawPage* pNewPage )
577 SvxShape::Create( pNewObj, pNewPage );
578 const SvGlobalName aAppletClassId( SO3_APPLET_CLASSID );
579 createObject(aAppletClassId);
580 SetShapeType( u"com.sun.star.drawing.AppletShape"_ustr );
583 void SAL_CALL SvxAppletShape::setPropertyValue( const OUString& aPropertyName, const css::uno::Any& rValue )
585 SvxShape::setPropertyValue( aPropertyName, rValue );
586 resetModifiedState();
589 void SAL_CALL SvxAppletShape::setPropertyValues( const css::uno::Sequence< OUString >& aPropertyNames, const css::uno::Sequence< css::uno::Any >& rValues )
591 SvxShape::setPropertyValues( aPropertyNames, rValues );
592 resetModifiedState();
595 bool SvxAppletShape::setPropertyValueImpl( const OUString& rName, const SfxItemPropertyMapEntry* pProperty, const css::uno::Any& rValue )
597 if( (pProperty->nWID >= OWN_ATTR_APPLET_DOCBASE) && (pProperty->nWID <= OWN_ATTR_APPLET_ISSCRIPT) )
599 if ( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef() ) )
601 uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef()->getComponent(), uno::UNO_QUERY );
602 if( xSet.is() )
604 // allow exceptions to pass through
605 xSet->setPropertyValue( rName, rValue );
608 return true;
610 else
612 return SvxOle2Shape::setPropertyValueImpl( rName, pProperty, rValue );
616 bool SvxAppletShape::getPropertyValueImpl( const OUString& rName, const SfxItemPropertyMapEntry* pProperty, css::uno::Any& rValue )
618 if( (pProperty->nWID >= OWN_ATTR_APPLET_DOCBASE) && (pProperty->nWID <= OWN_ATTR_APPLET_ISSCRIPT) )
620 if ( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef() ) )
622 uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef()->getComponent(), uno::UNO_QUERY );
623 if( xSet.is() )
625 rValue = xSet->getPropertyValue( rName );
628 return true;
630 else
632 return SvxOle2Shape::getPropertyValueImpl( rName, pProperty, rValue );
636 SvxPluginShape::SvxPluginShape(SdrObject* pObject, OUString referer)
637 : SvxOle2Shape(pObject, std::move(referer), getSvxMapProvider().GetMap(SVXMAP_PLUGIN), getSvxMapProvider().GetPropertySet(SVXMAP_PLUGIN, SdrObject::GetGlobalDrawObjectItemPool()))
639 SetShapeType( u"com.sun.star.drawing.PluginShape"_ustr );
642 SvxPluginShape::~SvxPluginShape() noexcept
646 void SvxPluginShape::Create( SdrObject* pNewObj, SvxDrawPage* pNewPage )
648 SvxShape::Create( pNewObj, pNewPage );
649 const SvGlobalName aPluginClassId( SO3_PLUGIN_CLASSID );
650 createObject(aPluginClassId);
651 SetShapeType( u"com.sun.star.drawing.PluginShape"_ustr );
654 void SAL_CALL SvxPluginShape::setPropertyValue( const OUString& aPropertyName, const css::uno::Any& rValue )
656 SvxShape::setPropertyValue( aPropertyName, rValue );
657 resetModifiedState();
660 void SAL_CALL SvxPluginShape::setPropertyValues( const css::uno::Sequence< OUString >& aPropertyNames, const css::uno::Sequence< css::uno::Any >& rValues )
662 SvxShape::setPropertyValues( aPropertyNames, rValues );
663 resetModifiedState();
666 bool SvxPluginShape::setPropertyValueImpl( const OUString& rName, const SfxItemPropertyMapEntry* pProperty, const css::uno::Any& rValue )
668 if( (pProperty->nWID >= OWN_ATTR_PLUGIN_MIMETYPE) && (pProperty->nWID <= OWN_ATTR_PLUGIN_COMMANDS) )
670 if( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef() ) )
672 uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef()->getComponent(), uno::UNO_QUERY );
673 if( xSet.is() )
675 // allow exceptions to pass through
676 xSet->setPropertyValue( rName, rValue );
679 return true;
681 else
683 return SvxOle2Shape::setPropertyValueImpl( rName, pProperty, rValue );
687 bool SvxPluginShape::getPropertyValueImpl( const OUString& rName, const SfxItemPropertyMapEntry* pProperty, css::uno::Any& rValue )
689 if( (pProperty->nWID >= OWN_ATTR_PLUGIN_MIMETYPE) && (pProperty->nWID <= OWN_ATTR_PLUGIN_COMMANDS) )
691 if( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef() ) )
693 uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef()->getComponent(), uno::UNO_QUERY );
694 if( xSet.is() )
696 rValue = xSet->getPropertyValue( rName );
699 return true;
701 else
703 return SvxOle2Shape::getPropertyValueImpl( rName, pProperty, rValue );
707 SvxFrameShape::SvxFrameShape(SdrObject* pObject, OUString referer)
708 : SvxOle2Shape(pObject, std::move(referer), getSvxMapProvider().GetMap(SVXMAP_FRAME), getSvxMapProvider().GetPropertySet(SVXMAP_FRAME, SdrObject::GetGlobalDrawObjectItemPool()))
710 SetShapeType( u"com.sun.star.drawing.FrameShape"_ustr );
713 SvxFrameShape::~SvxFrameShape() noexcept
717 OUString SvxFrameShape::GetAndClearInitialFrameURL()
719 OUString sRet(m_sInitialFrameURL);
720 m_sInitialFrameURL.clear();
721 return sRet;
724 void SvxFrameShape::Create( SdrObject* pNewObj, SvxDrawPage* pNewPage )
726 uno::Reference<beans::XPropertySet> xSet(static_cast<OWeakObject *>(this), uno::UNO_QUERY);
727 if (xSet)
728 xSet->getPropertyValue(u"FrameURL"_ustr) >>= m_sInitialFrameURL;
730 SvxShape::Create( pNewObj, pNewPage );
731 const SvGlobalName aIFrameClassId( SO3_IFRAME_CLASSID );
732 createObject(aIFrameClassId);
733 SetShapeType( u"com.sun.star.drawing.FrameShape"_ustr );
736 void SAL_CALL SvxFrameShape::setPropertyValue( const OUString& aPropertyName, const css::uno::Any& rValue )
738 SvxShape::setPropertyValue( aPropertyName, rValue );
739 resetModifiedState();
742 void SAL_CALL SvxFrameShape::setPropertyValues( const css::uno::Sequence< OUString >& aPropertyNames, const css::uno::Sequence< css::uno::Any >& rValues )
744 SvxShape::setPropertyValues( aPropertyNames, rValues );
745 resetModifiedState();
748 bool SvxFrameShape::setPropertyValueImpl( const OUString& rName, const SfxItemPropertyMapEntry* pProperty, const css::uno::Any& rValue )
750 if( (pProperty->nWID >= OWN_ATTR_FRAME_URL) && (pProperty->nWID <= OWN_ATTR_FRAME_MARGIN_HEIGHT) )
752 if( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef() ) )
754 uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef()->getComponent(), uno::UNO_QUERY );
755 if( xSet.is() )
757 // allow exceptions to pass through
758 xSet->setPropertyValue( rName, rValue );
761 return true;
763 else
765 return SvxOle2Shape::setPropertyValueImpl( rName, pProperty, rValue );
769 bool SvxFrameShape::getPropertyValueImpl(const OUString& rName, const SfxItemPropertyMapEntry* pProperty,
770 css::uno::Any& rValue)
772 if( (pProperty->nWID >= OWN_ATTR_FRAME_URL) && (pProperty->nWID <= OWN_ATTR_FRAME_MARGIN_HEIGHT) )
774 if( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef() ) )
776 uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef()->getComponent(), uno::UNO_QUERY );
777 if( xSet.is() )
779 rValue = xSet->getPropertyValue( rName );
782 return true;
784 else
786 return SvxOle2Shape::getPropertyValueImpl( rName, pProperty, rValue );
790 SvxMediaShape::SvxMediaShape(SdrObject* pObj, OUString referer)
791 : SvxShape( pObj, getSvxMapProvider().GetMap(SVXMAP_MEDIA), getSvxMapProvider().GetPropertySet(SVXMAP_MEDIA, SdrObject::GetGlobalDrawObjectItemPool()) ),
792 referer_(std::move(referer))
794 SetShapeType( u"com.sun.star.drawing.MediaShape"_ustr );
798 SvxMediaShape::~SvxMediaShape() noexcept
803 bool SvxMediaShape::setPropertyValueImpl( const OUString& rName, const SfxItemPropertyMapEntry* pProperty, const css::uno::Any& rValue )
805 if( ((pProperty->nWID >= OWN_ATTR_MEDIA_URL) && (pProperty->nWID <= OWN_ATTR_MEDIA_ZOOM))
806 || (pProperty->nWID == OWN_ATTR_MEDIA_STREAM)
807 || (pProperty->nWID == OWN_ATTR_MEDIA_MIMETYPE)
808 || (pProperty->nWID == OWN_ATTR_VALUE_GRAPHIC)
809 || (pProperty->nWID == SDRATTR_GRAFCROP))
811 #if HAVE_FEATURE_AVMEDIA
812 SdrMediaObj* pMedia = static_cast< SdrMediaObj* >( GetSdrObject() );
813 ::avmedia::MediaItem aItem;
814 bool bOk = false;
815 #endif
817 switch( pProperty->nWID )
819 case OWN_ATTR_MEDIA_URL:
820 #if HAVE_FEATURE_AVMEDIA
822 OUString aURL;
823 if( rValue >>= aURL )
825 bOk = true;
826 if ( aURL.startsWith("file:///") && !comphelper::DirectoryHelper::fileExists(aURL) )
828 comphelper::IEmbeddedHelper* pPersist = GetSdrObject()->getSdrModelFromSdrObject().GetPersist();
829 auto fileDirectoryEndIdx = pPersist->getDocumentBaseURL().lastIndexOf("/");
830 auto fileNameStartIdx = aURL.lastIndexOf("/");
831 if (fileDirectoryEndIdx != -1 && fileNameStartIdx != -1)
833 OUString aFallbackURL = OUString::Concat(pPersist->getDocumentBaseURL().subView(0, fileDirectoryEndIdx + 1))
834 + aURL.subView(fileNameStartIdx + 1);
835 aItem.setFallbackURL(aFallbackURL);
838 aItem.setURL( aURL, u""_ustr, referer_ );
841 #endif
842 break;
844 case OWN_ATTR_MEDIA_LOOP:
845 #if HAVE_FEATURE_AVMEDIA
847 bool bLoop;
849 if( rValue >>= bLoop )
851 bOk = true;
852 aItem.setLoop( bLoop );
855 #endif
856 break;
858 case OWN_ATTR_MEDIA_MUTE:
859 #if HAVE_FEATURE_AVMEDIA
861 bool bMute;
863 if( rValue >>= bMute )
865 bOk = true;
866 aItem.setMute( bMute );
869 #endif
870 break;
872 case OWN_ATTR_MEDIA_VOLUMEDB:
873 #if HAVE_FEATURE_AVMEDIA
875 sal_Int16 nVolumeDB = sal_Int16();
877 if( rValue >>= nVolumeDB )
879 bOk = true;
880 aItem.setVolumeDB( nVolumeDB );
883 #endif
884 break;
886 case OWN_ATTR_MEDIA_ZOOM:
887 #if HAVE_FEATURE_AVMEDIA
889 css::media::ZoomLevel eLevel;
891 if( rValue >>= eLevel )
893 bOk = true;
894 aItem.setZoom( eLevel );
897 #endif
898 break;
900 case OWN_ATTR_MEDIA_MIMETYPE:
901 #if HAVE_FEATURE_AVMEDIA
903 OUString sMimeType;
904 if( rValue >>= sMimeType )
906 bOk = true;
907 aItem.setMimeType( sMimeType );
910 #endif
911 break;
913 case OWN_ATTR_VALUE_GRAPHIC:
914 #if HAVE_FEATURE_AVMEDIA
916 uno::Reference<graphic::XGraphic> xGraphic(rValue, uno::UNO_QUERY);
917 if (xGraphic.is())
919 bOk = true;
920 aItem.setGraphic(Graphic(xGraphic));
923 #endif
924 break;
926 case SDRATTR_GRAFCROP:
927 #if HAVE_FEATURE_AVMEDIA
929 text::GraphicCrop aCrop;
930 if (rValue >>= aCrop)
932 bOk = true;
933 aItem.setCrop(aCrop);
936 #endif
937 break;
939 case OWN_ATTR_MEDIA_STREAM:
940 #if HAVE_FEATURE_AVMEDIA
943 uno::Reference<io::XInputStream> xStream;
944 if (rValue >>= xStream)
946 pMedia->SetInputStream(xStream);
949 catch (const css::ucb::ContentCreationException&)
951 css::uno::Any exc = cppu::getCaughtException();
952 throw css::lang::WrappedTargetException(
953 u"ContentCreationException Setting InputStream!"_ustr,
954 getXWeak(),
955 exc);
957 catch (const css::ucb::CommandFailedException&)
959 css::uno::Any anyEx = cppu::getCaughtException();
960 throw css::lang::WrappedTargetException(
961 u"CommandFailedException Setting InputStream!"_ustr,
962 getXWeak(),
963 anyEx);
965 #endif
966 break;
968 default:
969 OSL_FAIL("SvxMediaShape::setPropertyValueImpl(), unknown argument!");
972 #if HAVE_FEATURE_AVMEDIA
973 if( bOk )
975 pMedia->setMediaProperties( aItem );
976 return true;
978 #endif
980 else
982 return SvxShape::setPropertyValueImpl( rName, pProperty, rValue );
985 throw IllegalArgumentException();
989 bool SvxMediaShape::getPropertyValueImpl( const OUString& rName, const SfxItemPropertyMapEntry* pProperty, css::uno::Any& rValue )
991 if ( ((pProperty->nWID >= OWN_ATTR_MEDIA_URL) &&
992 (pProperty->nWID <= OWN_ATTR_MEDIA_ZOOM))
993 || (pProperty->nWID == OWN_ATTR_MEDIA_STREAM)
994 || (pProperty->nWID == OWN_ATTR_MEDIA_TEMPFILEURL)
995 || (pProperty->nWID == OWN_ATTR_MEDIA_MIMETYPE)
996 || (pProperty->nWID == OWN_ATTR_FALLBACK_GRAPHIC)
997 || (pProperty->nWID == OWN_ATTR_VALUE_GRAPHIC)
998 || (pProperty->nWID == SDRATTR_GRAFCROP))
1000 SdrMediaObj* pMedia = static_cast< SdrMediaObj* >( GetSdrObject() );
1001 #if HAVE_FEATURE_AVMEDIA
1002 const ::avmedia::MediaItem aItem( pMedia->getMediaProperties() );
1003 #endif
1005 switch( pProperty->nWID )
1007 case OWN_ATTR_MEDIA_URL:
1008 #if HAVE_FEATURE_AVMEDIA
1009 rValue <<= aItem.getURL();
1010 #endif
1011 break;
1013 case OWN_ATTR_MEDIA_LOOP:
1014 #if HAVE_FEATURE_AVMEDIA
1015 rValue <<= aItem.isLoop();
1016 #endif
1017 break;
1019 case OWN_ATTR_MEDIA_MUTE:
1020 #if HAVE_FEATURE_AVMEDIA
1021 rValue <<= aItem.isMute();
1022 #endif
1023 break;
1025 case OWN_ATTR_MEDIA_VOLUMEDB:
1026 #if HAVE_FEATURE_AVMEDIA
1027 rValue <<= aItem.getVolumeDB();
1028 #endif
1029 break;
1031 case OWN_ATTR_MEDIA_ZOOM:
1032 #if HAVE_FEATURE_AVMEDIA
1033 rValue <<= aItem.getZoom();
1034 #endif
1035 break;
1037 case OWN_ATTR_MEDIA_STREAM:
1040 rValue <<= pMedia->GetInputStream();
1042 catch (const css::ucb::ContentCreationException&)
1044 css::uno::Any anyEx = cppu::getCaughtException();
1045 throw css::lang::WrappedTargetException(
1046 u"ContentCreationException Getting InputStream!"_ustr,
1047 getXWeak(), anyEx );
1049 catch (const css::ucb::CommandFailedException&)
1051 css::uno::Any anyEx = cppu::getCaughtException();
1052 throw css::lang::WrappedTargetException(
1053 u"CommandFailedException Getting InputStream!"_ustr,
1054 getXWeak(), anyEx );
1057 break;
1059 case OWN_ATTR_MEDIA_TEMPFILEURL:
1060 #if HAVE_FEATURE_AVMEDIA
1061 rValue <<= aItem.getTempURL();
1062 #endif
1063 break;
1065 case OWN_ATTR_MEDIA_MIMETYPE:
1066 #if HAVE_FEATURE_AVMEDIA
1067 rValue <<= aItem.getMimeType();
1068 #endif
1069 break;
1071 case OWN_ATTR_VALUE_GRAPHIC:
1072 #if HAVE_FEATURE_AVMEDIA
1074 const Graphic& aGraphic = aItem.getGraphic();
1075 if (!aGraphic.IsNone())
1077 rValue <<= aGraphic.GetXGraphic();
1080 #endif
1081 break;
1083 case SDRATTR_GRAFCROP:
1084 #if HAVE_FEATURE_AVMEDIA
1086 text::GraphicCrop aCrop = aItem.getCrop();
1087 rValue <<= aCrop;
1089 #endif
1090 break;
1092 case OWN_ATTR_FALLBACK_GRAPHIC:
1093 rValue <<= pMedia->getSnapshot();
1094 break;
1096 default:
1097 OSL_FAIL("SvxMediaShape::getPropertyValueImpl(), unknown property!");
1099 return true;
1101 else
1103 return SvxShape::getPropertyValueImpl( rName, pProperty, rValue );
1107 bool SvxMediaShape::getPropertyStateImpl(const SfxItemPropertyMapEntry* pProperty,
1108 css::beans::PropertyState& rState)
1110 #if HAVE_FEATURE_AVMEDIA
1111 if (pProperty->nWID == SDRATTR_GRAFCROP)
1113 auto pMedia = static_cast<SdrMediaObj*>(GetSdrObject());
1114 const avmedia::MediaItem& rItem = pMedia->getMediaProperties();
1115 const text::GraphicCrop& rCrop = rItem.getCrop();
1116 if (rCrop.Bottom > 0 || rCrop.Left > 0 || rCrop.Right > 0 || rCrop.Top > 0)
1118 // The media has a crop, expose it to UNO-based export filters.
1119 rState = beans::PropertyState_DIRECT_VALUE;
1121 else
1123 rState = beans::PropertyState_AMBIGUOUS_VALUE;
1125 return true;
1127 #endif
1129 return SvxShape::getPropertyStateImpl(pProperty, rState);
1132 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */