1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <comphelper/propertyvalue.hxx>
36 #include <cppuhelper/exc_hlp.hxx>
38 #include <toolkit/helper/vclunohelper.hxx>
40 #include <sot/exchange.hxx>
42 #include <svx/svdmodel.hxx>
43 #include "shapeimpl.hxx"
45 #include <svx/unoshprp.hxx>
48 #include <vcl/gdimtf.hxx>
49 #include <vcl/wmf.hxx>
50 #include <svtools/embedhlp.hxx>
51 #include <sal/log.hxx>
52 #include <tools/debug.hxx>
53 #include <tools/globname.hxx>
54 #include <tools/stream.hxx>
56 #include <config_features.h>
59 using namespace ::cppu
;
60 using namespace ::com::sun::star
;
61 using namespace ::com::sun::star::uno
;
62 using namespace ::com::sun::star::lang
;
63 using namespace ::com::sun::star::container
;
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
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
))
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();
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!" );
119 case OWN_ATTR_OLE_ASPECT
:
121 sal_Int64 nAspect
= 0;
122 if( rValue
>>= nAspect
)
124 static_cast<SdrOle2Obj
*>(GetSdrObject())->SetAspect( nAspect
);
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
) )
144 case OWN_ATTR_THUMBNAIL
:
146 uno::Reference
< graphic::XGraphic
> xGraphic( rValue
, uno::UNO_QUERY
);
149 const Graphic
aGraphic(xGraphic
);
150 static_cast<SdrOle2Obj
*>(GetSdrObject())->SetGraphic(aGraphic
);
155 case OWN_ATTR_VALUE_GRAPHIC
:
157 uno::Reference
< graphic::XGraphic
> xGraphic( rValue
, uno::UNO_QUERY
);
160 SdrOle2Obj
* pOle
= dynamic_cast< SdrOle2Obj
* >( GetSdrObject() );
163 GraphicObject
aGrafObj( xGraphic
);
164 const Graphic
& aGraphic( aGrafObj
.GetGraphic() );
165 pOle
->SetGraphicToObj( aGraphic
);
171 case OWN_ATTR_PERSISTNAME
:
173 OUString aPersistName
;
174 if( rValue
>>= aPersistName
)
177 #if OSL_DEBUG_LEVEL > 0
178 pOle
= dynamic_cast<SdrOle2Obj
*>(GetSdrObject());
181 pOle
= static_cast<SdrOle2Obj
*>(GetSdrObject());
183 pOle
->SetPersistName( aPersistName
, this );
188 case OWN_ATTR_OLE_LINKURL
:
191 if( rValue
>>= aLinkURL
)
193 createLink( aLinkURL
);
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
)
212 GetClassName_Impl(aCLSID
);
217 case OWN_ATTR_INTERNAL_OLE
:
220 rValue
<<= SotExchange::IsInternal( GetClassName_Impl(sCLSID
) );
224 case OWN_ATTR_METAFILE
:
226 SdrOle2Obj
* pObj
= dynamic_cast<SdrOle2Obj
*>(GetSdrObject());
229 const Graphic
* pGraphic
= pObj
->GetGraphic();
233 if ( pGraphic
->IsGfxLink() )
235 GfxLink aLnk
= pGraphic
->GetGfxLink();
236 if ( aLnk
.GetType() == GfxLinkType::NativeWmf
)
239 uno::Sequence
<sal_Int8
> aSeq(reinterpret_cast<sal_Int8
const *>(aLnk
.GetData()), static_cast<sal_Int32
>(aLnk
.GetDataSize()));
245 // #i119735# just use GetGDIMetaFile, it will create a buffered 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());
258 rValue
= GetBitmap( true );
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() );
277 case OWN_ATTR_OLESIZE
:
279 Size
aTmp( static_cast<SdrOle2Obj
*>(GetSdrObject())->GetOrigObjSize() );
280 rValue
<<= awt::Size( aTmp
.Width(), aTmp
.Height() );
284 case OWN_ATTR_OLE_ASPECT
:
286 rValue
<<= static_cast<SdrOle2Obj
*>(GetSdrObject())->GetAspect();
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() );
297 uno::Reference
< embed::XEmbeddedObject
> xObj( pObj
->GetObjRef() );
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();
318 case OWN_ATTR_VALUE_GRAPHIC
:
320 uno::Reference
< graphic::XGraphic
> xGraphic
;
321 const Graphic
* pGraphic
= static_cast<SdrOle2Obj
*>( GetSdrObject() )->GetGraphic();
323 xGraphic
= pGraphic
->GetXGraphic();
328 case OWN_ATTR_THUMBNAIL
:
330 uno::Reference
< graphic::XGraphic
> xGraphic
;
331 const Graphic
* pGraphic
= static_cast<SdrOle2Obj
*>( GetSdrObject() )->GetGraphic();
333 xGraphic
= pGraphic
->GetXGraphic();
337 case OWN_ATTR_PERSISTNAME
:
339 OUString aPersistName
;
340 SdrOle2Obj
* pOle
= dynamic_cast< SdrOle2Obj
* >( GetSdrObject() );
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
;
356 case OWN_ATTR_OLE_LINKURL
:
359 SdrOle2Obj
* pOle
= dynamic_cast< SdrOle2Obj
* >( GetSdrObject() );
363 uno::Reference
< embed::XLinkageSupport
> xLink( pOle
->GetObjRef(), uno::UNO_QUERY
);
364 if ( xLink
.is() && xLink
->isLink() )
365 aLinkURL
= xLink
->getLinkURL();
372 return SvxShapeText::getPropertyValueImpl( rName
, pProperty
, rValue
);
378 bool SvxOle2Shape::createObject( const SvGlobalName
&aClassName
)
380 DBG_TESTSOLARMUTEX();
382 SdrOle2Obj
* pOle2Obj
= dynamic_cast< SdrOle2Obj
* >( GetSdrObject() );
383 if ( !pOle2Obj
|| !pOle2Obj
->IsEmpty() )
386 // create storage and inplace object
387 ::comphelper::IEmbeddedHelper
* pPersist
= GetSdrObject()->getSdrModelFromSdrObject().GetPersist();
388 OUString aPersistName
;
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()) }
396 //TODO/LATER: how to cope with creation failure?!
397 uno::Reference
<embed::XEmbeddedObject
> xObj(
398 pPersist
->getEmbeddedObjectContainer().CreateEmbeddedObject(
399 aClassName
.GetByteSequence(), objArgs
, aPersistName
));
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?
409 awt::Size aSz
= xObj
->getVisualAreaSize( pOle2Obj
->GetAspect() );
410 aRect
.SetSize( Size( aSz
.Width
, aSz
.Height
) );
412 catch( embed::NoVisualAreaSizeException
& )
414 pOle2Obj
->SetLogicRect( aRect
);
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
);
441 void SvxOle2Shape::createLink( const OUString
& aLinkURL
)
443 DBG_TESTSOLARMUTEX();
445 SdrOle2Obj
* pOle2Obj
= dynamic_cast< SdrOle2Obj
* >( GetSdrObject() );
446 if ( !pOle2Obj
|| !pOle2Obj
->IsEmpty() )
449 OUString aPersistName
;
451 ::comphelper::IEmbeddedHelper
* pPersist
= GetSdrObject()->getSdrModelFromSdrObject().GetPersist();
453 uno::Sequence
< beans::PropertyValue
> aMediaDescr
{
454 comphelper::makePropertyValue("URL", aLinkURL
),
455 comphelper::makePropertyValue("Referer", 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
);
474 tools::Rectangle aRect
= pOle2Obj
->GetLogicRect();
475 if ( aRect
.GetWidth() == 101 && aRect
.GetHeight() == 101 )
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
);
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
);
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() );
531 if( pOle2Obj
->IsEmpty() )
533 ::comphelper::IEmbeddedHelper
* pPersist
= GetSdrObject()->getSdrModelFromSdrObject().GetPersist();
536 uno::Reference
< embed::XEmbeddedObject
> xObj
=
537 pPersist
->getEmbeddedObjectContainer().GetEmbeddedObject( pOle2Obj
->GetPersistName() );
540 aClassName
= SvGlobalName( xObj
->getClassID() );
541 rHexCLSID
= aClassName
.GetHexName();
546 if (rHexCLSID
.isEmpty())
548 const uno::Reference
< embed::XEmbeddedObject
>& xObj( pOle2Obj
->GetObjRef() );
551 aClassName
= SvGlobalName( xObj
->getClassID() );
552 rHexCLSID
= aClassName
.GetHexName();
560 OUString
SvxOle2Shape::GetAndClearInitialFrameURL()
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( "com.sun.star.drawing.AppletShape" );
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( "com.sun.star.drawing.AppletShape" );
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
);
604 // allow exceptions to pass through
605 xSet
->setPropertyValue( rName
, rValue
);
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
);
625 rValue
= xSet
->getPropertyValue( rName
);
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( "com.sun.star.drawing.PluginShape" );
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( "com.sun.star.drawing.PluginShape" );
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
);
675 // allow exceptions to pass through
676 xSet
->setPropertyValue( rName
, rValue
);
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
);
696 rValue
= xSet
->getPropertyValue( rName
);
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( "com.sun.star.drawing.FrameShape" );
713 SvxFrameShape::~SvxFrameShape() noexcept
717 OUString
SvxFrameShape::GetAndClearInitialFrameURL()
719 OUString
sRet(m_sInitialFrameURL
);
720 m_sInitialFrameURL
.clear();
724 void SvxFrameShape::Create( SdrObject
* pNewObj
, SvxDrawPage
* pNewPage
)
726 uno::Reference
<beans::XPropertySet
> xSet(static_cast<OWeakObject
*>(this), uno::UNO_QUERY
);
728 xSet
->getPropertyValue("FrameURL") >>= m_sInitialFrameURL
;
730 SvxShape::Create( pNewObj
, pNewPage
);
731 const SvGlobalName
aIFrameClassId( SO3_IFRAME_CLASSID
);
732 createObject(aIFrameClassId
);
733 SetShapeType( "com.sun.star.drawing.FrameShape" );
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
);
757 // allow exceptions to pass through
758 xSet
->setPropertyValue( rName
, rValue
);
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
);
779 rValue
= xSet
->getPropertyValue( rName
);
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( "com.sun.star.drawing.MediaShape" );
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
;
817 switch( pProperty
->nWID
)
819 case OWN_ATTR_MEDIA_URL
:
820 #if HAVE_FEATURE_AVMEDIA
823 if( rValue
>>= aURL
)
826 aItem
.setURL( aURL
, "", referer_
);
832 case OWN_ATTR_MEDIA_LOOP
:
833 #if HAVE_FEATURE_AVMEDIA
837 if( rValue
>>= bLoop
)
840 aItem
.setLoop( bLoop
);
846 case OWN_ATTR_MEDIA_MUTE
:
847 #if HAVE_FEATURE_AVMEDIA
851 if( rValue
>>= bMute
)
854 aItem
.setMute( bMute
);
860 case OWN_ATTR_MEDIA_VOLUMEDB
:
861 #if HAVE_FEATURE_AVMEDIA
863 sal_Int16 nVolumeDB
= sal_Int16();
865 if( rValue
>>= nVolumeDB
)
868 aItem
.setVolumeDB( nVolumeDB
);
874 case OWN_ATTR_MEDIA_ZOOM
:
875 #if HAVE_FEATURE_AVMEDIA
877 css::media::ZoomLevel eLevel
;
879 if( rValue
>>= eLevel
)
882 aItem
.setZoom( eLevel
);
888 case OWN_ATTR_MEDIA_MIMETYPE
:
889 #if HAVE_FEATURE_AVMEDIA
892 if( rValue
>>= sMimeType
)
895 aItem
.setMimeType( sMimeType
);
901 case OWN_ATTR_VALUE_GRAPHIC
:
902 #if HAVE_FEATURE_AVMEDIA
904 uno::Reference
<graphic::XGraphic
> xGraphic(rValue
, uno::UNO_QUERY
);
908 aItem
.setGraphic(Graphic(xGraphic
));
914 case SDRATTR_GRAFCROP
:
915 #if HAVE_FEATURE_AVMEDIA
917 text::GraphicCrop aCrop
;
918 if (rValue
>>= aCrop
)
921 aItem
.setCrop(aCrop
);
927 case OWN_ATTR_MEDIA_STREAM
:
928 #if HAVE_FEATURE_AVMEDIA
931 uno::Reference
<io::XInputStream
> xStream
;
932 if (rValue
>>= xStream
)
934 pMedia
->SetInputStream(xStream
);
937 catch (const css::ucb::ContentCreationException
&)
939 css::uno::Any exc
= cppu::getCaughtException();
940 throw css::lang::WrappedTargetException(
941 "ContentCreationException Setting InputStream!",
945 catch (const css::ucb::CommandFailedException
&)
947 css::uno::Any anyEx
= cppu::getCaughtException();
948 throw css::lang::WrappedTargetException(
949 "CommandFailedException Setting InputStream!",
957 OSL_FAIL("SvxMediaShape::setPropertyValueImpl(), unknown argument!");
960 #if HAVE_FEATURE_AVMEDIA
963 pMedia
->setMediaProperties( aItem
);
970 return SvxShape::setPropertyValueImpl( rName
, pProperty
, rValue
);
973 throw IllegalArgumentException();
977 bool SvxMediaShape::getPropertyValueImpl( const OUString
& rName
, const SfxItemPropertyMapEntry
* pProperty
, css::uno::Any
& rValue
)
979 if ( ((pProperty
->nWID
>= OWN_ATTR_MEDIA_URL
) &&
980 (pProperty
->nWID
<= OWN_ATTR_MEDIA_ZOOM
))
981 || (pProperty
->nWID
== OWN_ATTR_MEDIA_STREAM
)
982 || (pProperty
->nWID
== OWN_ATTR_MEDIA_TEMPFILEURL
)
983 || (pProperty
->nWID
== OWN_ATTR_MEDIA_MIMETYPE
)
984 || (pProperty
->nWID
== OWN_ATTR_FALLBACK_GRAPHIC
)
985 || (pProperty
->nWID
== OWN_ATTR_VALUE_GRAPHIC
)
986 || (pProperty
->nWID
== SDRATTR_GRAFCROP
))
988 SdrMediaObj
* pMedia
= static_cast< SdrMediaObj
* >( GetSdrObject() );
989 #if HAVE_FEATURE_AVMEDIA
990 const ::avmedia::MediaItem
aItem( pMedia
->getMediaProperties() );
993 switch( pProperty
->nWID
)
995 case OWN_ATTR_MEDIA_URL
:
996 #if HAVE_FEATURE_AVMEDIA
997 rValue
<<= aItem
.getURL();
1001 case OWN_ATTR_MEDIA_LOOP
:
1002 #if HAVE_FEATURE_AVMEDIA
1003 rValue
<<= aItem
.isLoop();
1007 case OWN_ATTR_MEDIA_MUTE
:
1008 #if HAVE_FEATURE_AVMEDIA
1009 rValue
<<= aItem
.isMute();
1013 case OWN_ATTR_MEDIA_VOLUMEDB
:
1014 #if HAVE_FEATURE_AVMEDIA
1015 rValue
<<= aItem
.getVolumeDB();
1019 case OWN_ATTR_MEDIA_ZOOM
:
1020 #if HAVE_FEATURE_AVMEDIA
1021 rValue
<<= aItem
.getZoom();
1025 case OWN_ATTR_MEDIA_STREAM
:
1028 rValue
<<= pMedia
->GetInputStream();
1030 catch (const css::ucb::ContentCreationException
&)
1032 css::uno::Any anyEx
= cppu::getCaughtException();
1033 throw css::lang::WrappedTargetException(
1034 "ContentCreationException Getting InputStream!",
1035 getXWeak(), anyEx
);
1037 catch (const css::ucb::CommandFailedException
&)
1039 css::uno::Any anyEx
= cppu::getCaughtException();
1040 throw css::lang::WrappedTargetException(
1041 "CommandFailedException Getting InputStream!",
1042 getXWeak(), anyEx
);
1047 case OWN_ATTR_MEDIA_TEMPFILEURL
:
1048 #if HAVE_FEATURE_AVMEDIA
1049 rValue
<<= aItem
.getTempURL();
1053 case OWN_ATTR_MEDIA_MIMETYPE
:
1054 #if HAVE_FEATURE_AVMEDIA
1055 rValue
<<= aItem
.getMimeType();
1059 case OWN_ATTR_VALUE_GRAPHIC
:
1060 #if HAVE_FEATURE_AVMEDIA
1062 Graphic aGraphic
= aItem
.getGraphic();
1063 if (!aGraphic
.IsNone())
1065 rValue
<<= aGraphic
.GetXGraphic();
1071 case SDRATTR_GRAFCROP
:
1072 #if HAVE_FEATURE_AVMEDIA
1074 text::GraphicCrop aCrop
= aItem
.getCrop();
1080 case OWN_ATTR_FALLBACK_GRAPHIC
:
1081 rValue
<<= pMedia
->getSnapshot();
1085 OSL_FAIL("SvxMediaShape::getPropertyValueImpl(), unknown property!");
1091 return SvxShape::getPropertyValueImpl( rName
, pProperty
, rValue
);
1095 bool SvxMediaShape::getPropertyStateImpl(const SfxItemPropertyMapEntry
* pProperty
,
1096 css::beans::PropertyState
& rState
)
1098 #if HAVE_FEATURE_AVMEDIA
1099 if (pProperty
->nWID
== SDRATTR_GRAFCROP
)
1101 auto pMedia
= static_cast<SdrMediaObj
*>(GetSdrObject());
1102 const avmedia::MediaItem
& rItem
= pMedia
->getMediaProperties();
1103 const text::GraphicCrop
& rCrop
= rItem
.getCrop();
1104 if (rCrop
.Bottom
> 0 || rCrop
.Left
> 0 || rCrop
.Right
> 0 || rCrop
.Top
> 0)
1106 // The media has a crop, expose it to UNO-based export filters.
1107 rState
= beans::PropertyState_DIRECT_VALUE
;
1111 rState
= beans::PropertyState_AMBIGUOUS_VALUE
;
1117 return SvxShape::getPropertyStateImpl(pProperty
, rState
);
1120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */