/src/libreoffice/svx/source/unodraw/unoshap4.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
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/media/ZoomLevel.hpp> |
26 | | #include <com/sun/star/task/XInteractionHandler.hpp> |
27 | | #include <com/sun/star/ucb/CommandFailedException.hpp> |
28 | | #include <com/sun/star/ucb/ContentCreationException.hpp> |
29 | | |
30 | | #include <svx/svdoole2.hxx> |
31 | | #include <svx/svdomedia.hxx> |
32 | | #include <svx/svdpool.hxx> |
33 | | #include <comphelper/classids.hxx> |
34 | | #include <comphelper/DirectoryHelper.hxx> |
35 | | #include <comphelper/embeddedobjectcontainer.hxx> |
36 | | #include <comphelper/mediamimetype.hxx> |
37 | | #include <comphelper/propertysequence.hxx> |
38 | | #include <comphelper/propertyvalue.hxx> |
39 | | #include <cppuhelper/exc_hlp.hxx> |
40 | | |
41 | | #include <toolkit/helper/vclunohelper.hxx> |
42 | | |
43 | | #include <sot/exchange.hxx> |
44 | | |
45 | | #include <svx/svdmodel.hxx> |
46 | | #include "shapeimpl.hxx" |
47 | | |
48 | | #include <svx/unoshprp.hxx> |
49 | | |
50 | | #include <utility> |
51 | | #include <vcl/gdimtf.hxx> |
52 | | #include <vcl/gfxlink.hxx> |
53 | | #include <vcl/wmf.hxx> |
54 | | #include <svtools/embedhlp.hxx> |
55 | | #include <sal/log.hxx> |
56 | | #include <tools/debug.hxx> |
57 | | #include <tools/globname.hxx> |
58 | | #include <tools/stream.hxx> |
59 | | |
60 | | #include <config_features.h> |
61 | | |
62 | | |
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::beans; |
68 | | |
69 | | |
70 | | SvxOle2Shape::SvxOle2Shape(SdrObject* pObject, OUString referer) |
71 | 0 | : SvxShapeText(pObject, getSvxMapProvider().GetMap(SVXMAP_OLE2), |
72 | 0 | getSvxMapProvider().GetPropertySet(SVXMAP_OLE2,SdrObject::GetGlobalDrawObjectItemPool())) |
73 | 0 | , m_referer(std::move(referer)) |
74 | 0 | { |
75 | 0 | } |
76 | | |
77 | | SvxOle2Shape::SvxOle2Shape(SdrObject* pObject, OUString referer, std::span<const SfxItemPropertyMapEntry> pPropertyMap, const SvxItemPropertySet* pPropertySet) |
78 | 609 | : SvxShapeText(pObject, pPropertyMap, pPropertySet) |
79 | 609 | , m_referer(std::move(referer)) |
80 | 609 | { |
81 | 609 | } |
82 | | |
83 | | SvxOle2Shape::~SvxOle2Shape() noexcept |
84 | 609 | { |
85 | 609 | } |
86 | | |
87 | | //XPropertySet |
88 | | bool SvxOle2Shape::setPropertyValueImpl( const OUString& rName, const SfxItemPropertyMapEntry* pProperty, const css::uno::Any& rValue ) |
89 | 7.88k | { |
90 | 7.88k | switch( pProperty->nWID ) |
91 | 7.88k | { |
92 | 0 | case OWN_ATTR_OLE_VISAREA: |
93 | 0 | { |
94 | | // TODO/LATER: seems to make no sense for iconified object |
95 | |
|
96 | 0 | awt::Rectangle aVisArea; |
97 | 0 | if( !(rValue >>= aVisArea)) |
98 | 0 | break; |
99 | 0 | if( auto pOle2Obj = dynamic_cast<SdrOle2Obj* >(GetSdrObject()) ) |
100 | 0 | { |
101 | 0 | Size aTmp( aVisArea.X + aVisArea.Width, aVisArea.Y + aVisArea.Height ); |
102 | 0 | uno::Reference < embed::XEmbeddedObject > xObj = pOle2Obj->GetObjRef(); |
103 | 0 | if( xObj.is() ) |
104 | 0 | { |
105 | 0 | try |
106 | 0 | { |
107 | | // the API handles with MapUnit::Map100thMM map mode |
108 | 0 | MapUnit aObjUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( embed::Aspects::MSOLE_CONTENT ) ); |
109 | 0 | aTmp = OutputDevice::LogicToLogic(aTmp, MapMode(MapUnit::Map100thMM), MapMode(aObjUnit)); |
110 | 0 | xObj->setVisualAreaSize( embed::Aspects::MSOLE_CONTENT, awt::Size( aTmp.Width(), aTmp.Height() ) ); |
111 | 0 | } |
112 | 0 | catch( uno::Exception& ) |
113 | 0 | { |
114 | 0 | OSL_FAIL( "Couldn't set the visual area for the object!" ); |
115 | 0 | } |
116 | 0 | } |
117 | |
|
118 | 0 | return true; |
119 | 0 | } |
120 | 0 | break; |
121 | 0 | } |
122 | 29 | case OWN_ATTR_OLE_ASPECT: |
123 | 29 | { |
124 | 29 | sal_Int64 nAspect = 0; |
125 | 29 | if( rValue >>= nAspect ) |
126 | 29 | { |
127 | 29 | static_cast<SdrOle2Obj*>(GetSdrObject())->SetAspect( nAspect ); |
128 | 29 | return true; |
129 | 29 | } |
130 | 0 | break; |
131 | 29 | } |
132 | 413 | case OWN_ATTR_CLSID: |
133 | 413 | { |
134 | 413 | OUString aCLSID; |
135 | 413 | if( rValue >>= aCLSID ) |
136 | 413 | { |
137 | | // init an OLE object with a global name |
138 | 413 | SvGlobalName aClassName; |
139 | 413 | if( aClassName.MakeId( aCLSID ) ) |
140 | 413 | { |
141 | 413 | if( createObject( aClassName ) ) |
142 | 0 | return true; |
143 | 413 | } |
144 | 413 | } |
145 | 413 | break; |
146 | 413 | } |
147 | 413 | case OWN_ATTR_THUMBNAIL: |
148 | 0 | { |
149 | 0 | uno::Reference< graphic::XGraphic > xGraphic( rValue, uno::UNO_QUERY ); |
150 | 0 | if( xGraphic.is() ) |
151 | 0 | { |
152 | 0 | const Graphic aGraphic(xGraphic); |
153 | 0 | static_cast<SdrOle2Obj*>(GetSdrObject())->SetGraphic(aGraphic); |
154 | 0 | return true; |
155 | 0 | } |
156 | 0 | break; |
157 | 0 | } |
158 | 10 | case OWN_ATTR_VALUE_GRAPHIC: |
159 | 10 | { |
160 | 10 | uno::Reference< graphic::XGraphic > xGraphic( rValue, uno::UNO_QUERY ); |
161 | 10 | if( xGraphic.is() ) |
162 | 10 | { |
163 | 10 | SdrOle2Obj* pOle = dynamic_cast< SdrOle2Obj* >( GetSdrObject() ); |
164 | 10 | if( pOle ) |
165 | 10 | { |
166 | 10 | GraphicObject aGrafObj( xGraphic ); |
167 | 10 | const Graphic& aGraphic( aGrafObj.GetGraphic() ); |
168 | 10 | pOle->SetGraphicToObj( aGraphic ); |
169 | 10 | } |
170 | 10 | return true; |
171 | 10 | } |
172 | 0 | break; |
173 | 10 | } |
174 | 12 | case OWN_ATTR_PERSISTNAME: |
175 | 12 | { |
176 | 12 | OUString aPersistName; |
177 | 12 | if( rValue >>= aPersistName ) |
178 | 12 | { |
179 | 12 | SdrOle2Obj *pOle; |
180 | | #if OSL_DEBUG_LEVEL > 0 |
181 | | pOle = dynamic_cast<SdrOle2Obj*>(GetSdrObject()); |
182 | | assert(pOle); |
183 | | #else |
184 | 12 | pOle = static_cast<SdrOle2Obj*>(GetSdrObject()); |
185 | 12 | #endif |
186 | 12 | pOle->SetPersistName( aPersistName, this ); |
187 | 12 | return true; |
188 | 12 | } |
189 | 0 | break; |
190 | 12 | } |
191 | 3 | case OWN_ATTR_OLE_LINKURL: |
192 | 3 | { |
193 | 3 | OUString aLinkURL; |
194 | 3 | if( rValue >>= aLinkURL ) |
195 | 3 | { |
196 | 3 | createLink( aLinkURL ); |
197 | 3 | return true; |
198 | 3 | } |
199 | 0 | break; |
200 | 3 | } |
201 | 7.41k | default: |
202 | 7.41k | return SvxShapeText::setPropertyValueImpl( rName, pProperty, rValue ); |
203 | 7.88k | } |
204 | | |
205 | 413 | throw IllegalArgumentException(); |
206 | 7.88k | } |
207 | | |
208 | | bool SvxOle2Shape::getPropertyValueImpl( const OUString& rName, const SfxItemPropertyMapEntry* pProperty, css::uno::Any& rValue ) |
209 | 1.70k | { |
210 | 1.70k | switch( pProperty->nWID ) |
211 | 1.70k | { |
212 | 0 | case OWN_ATTR_CLSID: |
213 | 0 | { |
214 | 0 | OUString aCLSID; |
215 | 0 | GetClassName_Impl(aCLSID); |
216 | 0 | rValue <<= aCLSID; |
217 | 0 | break; |
218 | 0 | } |
219 | | |
220 | 0 | case OWN_ATTR_INTERNAL_OLE: |
221 | 0 | { |
222 | 0 | OUString sCLSID; |
223 | 0 | rValue <<= SotExchange::IsInternal( GetClassName_Impl(sCLSID) ); |
224 | 0 | break; |
225 | 0 | } |
226 | | |
227 | 0 | case OWN_ATTR_METAFILE: |
228 | 0 | { |
229 | 0 | SdrOle2Obj* pObj = dynamic_cast<SdrOle2Obj*>(GetSdrObject()); |
230 | 0 | if( pObj ) |
231 | 0 | { |
232 | 0 | const Graphic* pGraphic = pObj->GetGraphic(); |
233 | 0 | if( pGraphic ) |
234 | 0 | { |
235 | 0 | bool bIsWMF = false; |
236 | 0 | if ( pGraphic->IsGfxLink() ) |
237 | 0 | { |
238 | 0 | GfxLink aLnk = pGraphic->GetGfxLink(); |
239 | 0 | if ( aLnk.GetType() == GfxLinkType::NativeWmf ) |
240 | 0 | { |
241 | 0 | bIsWMF = true; |
242 | 0 | uno::Sequence<sal_Int8> aSeq(reinterpret_cast<sal_Int8 const *>(aLnk.GetData()), static_cast<sal_Int32>(aLnk.GetDataSize())); |
243 | 0 | rValue <<= aSeq; |
244 | 0 | } |
245 | 0 | } |
246 | 0 | if ( !bIsWMF ) |
247 | 0 | { |
248 | | // #i119735# just use GetGDIMetaFile, it will create a buffered version of contained bitmap now automatically |
249 | 0 | GDIMetaFile aMtf(pGraphic->GetGDIMetaFile()); |
250 | 0 | SvMemoryStream aDestStrm( 65535, 65535 ); |
251 | 0 | ConvertGDIMetaFileToWMF( aMtf, aDestStrm, nullptr, false ); |
252 | 0 | const uno::Sequence<sal_Int8> aSeq( |
253 | 0 | static_cast< const sal_Int8* >(aDestStrm.GetData()), |
254 | 0 | aDestStrm.GetEndOfData()); |
255 | 0 | rValue <<= aSeq; |
256 | 0 | } |
257 | 0 | } |
258 | 0 | } |
259 | 0 | else |
260 | 0 | { |
261 | 0 | rValue = GetBitmap( true ); |
262 | 0 | } |
263 | 0 | break; |
264 | 0 | } |
265 | | |
266 | 0 | case OWN_ATTR_OLE_VISAREA: |
267 | 0 | { |
268 | 0 | awt::Rectangle aVisArea; |
269 | 0 | if( dynamic_cast<const SdrOle2Obj* >(GetSdrObject()) != nullptr) |
270 | 0 | { |
271 | 0 | MapMode aMapMode( MapUnit::Map100thMM ); // the API uses this map mode |
272 | 0 | Size aTmp = static_cast<SdrOle2Obj*>(GetSdrObject())->GetOrigObjSize( &aMapMode ); // get the size in the requested map mode |
273 | 0 | aVisArea = awt::Rectangle( 0, 0, aTmp.Width(), aTmp.Height() ); |
274 | 0 | } |
275 | |
|
276 | 0 | rValue <<= aVisArea; |
277 | 0 | break; |
278 | 0 | } |
279 | | |
280 | 0 | case OWN_ATTR_OLESIZE: |
281 | 0 | { |
282 | 0 | Size aTmp( static_cast<SdrOle2Obj*>(GetSdrObject())->GetOrigObjSize() ); |
283 | 0 | rValue <<= awt::Size( aTmp.Width(), aTmp.Height() ); |
284 | 0 | break; |
285 | 0 | } |
286 | | |
287 | 0 | case OWN_ATTR_OLE_ASPECT: |
288 | 0 | { |
289 | 0 | rValue <<= static_cast<SdrOle2Obj*>(GetSdrObject())->GetAspect(); |
290 | 0 | break; |
291 | 0 | } |
292 | | |
293 | 397 | case OWN_ATTR_OLEMODEL: |
294 | 420 | case OWN_ATTR_OLE_EMBEDDED_OBJECT: |
295 | 420 | case OWN_ATTR_OLE_EMBEDDED_OBJECT_NONEWCLIENT: |
296 | 420 | { |
297 | 420 | SdrOle2Obj* pObj = dynamic_cast<SdrOle2Obj*>( GetSdrObject() ); |
298 | 420 | if( pObj ) |
299 | 420 | { |
300 | 420 | uno::Reference < embed::XEmbeddedObject > xObj( pObj->GetObjRef() ); |
301 | 420 | if ( xObj.is() |
302 | 0 | && ( pProperty->nWID == OWN_ATTR_OLE_EMBEDDED_OBJECT || pProperty->nWID == OWN_ATTR_OLE_EMBEDDED_OBJECT_NONEWCLIENT || svt::EmbeddedObjectRef::TryRunningState( xObj ) ) ) |
303 | 0 | { |
304 | | // Discussed with CL due to the before GetPaintingPageView |
305 | | // usage. Removed it, former fallback is used now |
306 | 0 | if ( pProperty->nWID == OWN_ATTR_OLEMODEL || pProperty->nWID == OWN_ATTR_OLE_EMBEDDED_OBJECT ) |
307 | 0 | { |
308 | 0 | const bool bSuccess(pObj->AddOwnLightClient()); |
309 | 0 | SAL_WARN_IF(!bSuccess, "svx.svdraw", "An object without client is provided!"); |
310 | 0 | } |
311 | | |
312 | 0 | if ( pProperty->nWID == OWN_ATTR_OLEMODEL ) |
313 | 0 | rValue <<= pObj->GetObjRef()->getComponent(); |
314 | 0 | else |
315 | 0 | rValue <<= xObj; |
316 | 0 | } |
317 | 420 | } |
318 | 420 | break; |
319 | 420 | } |
320 | | |
321 | 420 | case OWN_ATTR_VALUE_GRAPHIC: |
322 | 0 | { |
323 | 0 | uno::Reference< graphic::XGraphic > xGraphic; |
324 | 0 | const Graphic* pGraphic = static_cast<SdrOle2Obj*>( GetSdrObject() )->GetGraphic(); |
325 | 0 | if( pGraphic ) |
326 | 0 | xGraphic = pGraphic->GetXGraphic(); |
327 | 0 | rValue <<= xGraphic; |
328 | 0 | break; |
329 | 420 | } |
330 | | |
331 | 0 | case OWN_ATTR_THUMBNAIL: |
332 | 0 | { |
333 | 0 | uno::Reference< graphic::XGraphic > xGraphic; |
334 | 0 | const Graphic* pGraphic = static_cast<SdrOle2Obj*>( GetSdrObject() )->GetGraphic(); |
335 | 0 | if( pGraphic ) |
336 | 0 | xGraphic = pGraphic->GetXGraphic(); |
337 | 0 | rValue <<= xGraphic; |
338 | 0 | break; |
339 | 420 | } |
340 | 413 | case OWN_ATTR_PERSISTNAME: |
341 | 413 | { |
342 | 413 | OUString aPersistName; |
343 | 413 | SdrOle2Obj* pOle = dynamic_cast< SdrOle2Obj* >( GetSdrObject() ); |
344 | | |
345 | 413 | if( pOle ) |
346 | 413 | { |
347 | 413 | aPersistName = pOle->GetPersistName(); |
348 | 413 | if( !aPersistName.isEmpty() ) |
349 | 0 | { |
350 | 0 | ::comphelper::IEmbeddedHelper* pPersist(GetSdrObject()->getSdrModelFromSdrObject().GetPersist()); |
351 | 0 | if( (nullptr == pPersist) || !pPersist->getEmbeddedObjectContainer().HasEmbeddedObject( pOle->GetPersistName() ) ) |
352 | 0 | aPersistName.clear(); |
353 | 0 | } |
354 | 413 | } |
355 | | |
356 | 413 | rValue <<= aPersistName; |
357 | 413 | break; |
358 | 420 | } |
359 | 0 | case OWN_ATTR_OLE_LINKURL: |
360 | 0 | { |
361 | 0 | OUString aLinkURL; |
362 | 0 | SdrOle2Obj* pOle = dynamic_cast< SdrOle2Obj* >( GetSdrObject() ); |
363 | |
|
364 | 0 | if( pOle ) |
365 | 0 | { |
366 | 0 | uno::Reference< embed::XLinkageSupport > xLink( pOle->GetObjRef(), uno::UNO_QUERY ); |
367 | 0 | if ( xLink.is() && xLink->isLink() ) |
368 | 0 | aLinkURL = xLink->getLinkURL(); |
369 | 0 | } |
370 | |
|
371 | 0 | rValue <<= aLinkURL; |
372 | 0 | break; |
373 | 420 | } |
374 | 875 | default: |
375 | 875 | return SvxShapeText::getPropertyValueImpl( rName, pProperty, rValue ); |
376 | 1.70k | } |
377 | | |
378 | 833 | return true; |
379 | 1.70k | } |
380 | | |
381 | | bool SvxOle2Shape::createObject( const SvGlobalName &aClassName ) |
382 | 413 | { |
383 | 413 | DBG_TESTSOLARMUTEX(); |
384 | | |
385 | 413 | SdrOle2Obj* pOle2Obj = dynamic_cast< SdrOle2Obj* >( GetSdrObject() ); |
386 | 413 | if ( !pOle2Obj || !pOle2Obj->IsEmpty() ) |
387 | 0 | return false; |
388 | | |
389 | | // create storage and inplace object |
390 | 413 | ::comphelper::IEmbeddedHelper* pPersist = GetSdrObject()->getSdrModelFromSdrObject().GetPersist(); |
391 | 413 | OUString aPersistName; |
392 | 413 | OUString aTmpStr; |
393 | 413 | if( SvxShape::getPropertyValue( UNO_NAME_OLE2_PERSISTNAME ) >>= aTmpStr ) |
394 | 413 | aPersistName = aTmpStr; |
395 | | |
396 | | //TODO/LATER: how to cope with creation failure?! |
397 | 413 | uno::Reference<embed::XEmbeddedObject> xObj( |
398 | 413 | pPersist->getEmbeddedObjectContainer().CreateEmbeddedObject( |
399 | 413 | aClassName.GetByteSequence(), aPersistName, pPersist->getDocumentBaseURL())); |
400 | 413 | if( xObj.is() ) |
401 | 0 | { |
402 | 0 | tools::Rectangle aRect = pOle2Obj->GetLogicRect(); |
403 | 0 | if ( aRect.GetWidth() == 101 && aRect.GetHeight() == 101 ) |
404 | 0 | { |
405 | | // TODO/LATER: is it possible that this method is used to create an iconified object? |
406 | | // default size |
407 | 0 | try |
408 | 0 | { |
409 | 0 | awt::Size aSz = xObj->getVisualAreaSize( pOle2Obj->GetAspect() ); |
410 | 0 | aRect.SetSize( Size( aSz.Width, aSz.Height ) ); |
411 | 0 | } |
412 | 0 | catch( embed::NoVisualAreaSizeException& ) |
413 | 0 | {} |
414 | 0 | pOle2Obj->SetLogicRect( aRect ); |
415 | 0 | } |
416 | 0 | else |
417 | 0 | { |
418 | 0 | awt::Size aSz; |
419 | 0 | Size aSize = aRect.GetSize(); |
420 | 0 | aSz.Width = aSize.Width(); |
421 | 0 | aSz.Height = aSize.Height(); |
422 | 0 | if (aSz.Width != 0 || aSz.Height != 0) |
423 | 0 | { |
424 | | //HACK: can aSz legally be empty? |
425 | 0 | xObj->setVisualAreaSize( pOle2Obj->GetAspect(), aSz ); |
426 | 0 | } |
427 | 0 | } |
428 | | |
429 | | // connect the object after the visual area is set |
430 | 0 | aTmpStr = aPersistName; |
431 | 0 | SvxShape::setPropertyValue( UNO_NAME_OLE2_PERSISTNAME, Any( aTmpStr ) ); |
432 | | |
433 | | // the object is inserted during setting of PersistName property usually |
434 | 0 | if( pOle2Obj->IsEmpty() ) |
435 | 0 | pOle2Obj->SetObjRef( xObj ); |
436 | 0 | } |
437 | | |
438 | 413 | return xObj.is(); |
439 | 413 | } |
440 | | |
441 | | void SvxOle2Shape::createLink( const OUString& aLinkURL ) |
442 | 3 | { |
443 | 3 | DBG_TESTSOLARMUTEX(); |
444 | | |
445 | 3 | SdrOle2Obj* pOle2Obj = dynamic_cast< SdrOle2Obj* >( GetSdrObject() ); |
446 | 3 | if ( !pOle2Obj || !pOle2Obj->IsEmpty() ) |
447 | 0 | return; |
448 | | |
449 | 3 | OUString aPersistName; |
450 | | |
451 | 3 | ::comphelper::IEmbeddedHelper* pPersist = GetSdrObject()->getSdrModelFromSdrObject().GetPersist(); |
452 | | |
453 | 3 | uno::Sequence< beans::PropertyValue > aMediaDescr{ |
454 | 3 | comphelper::makePropertyValue(u"URL"_ustr, aLinkURL), |
455 | 3 | comphelper::makePropertyValue(u"Referer"_ustr, m_referer) |
456 | 3 | }; |
457 | | |
458 | 3 | uno::Reference< task::XInteractionHandler > xInteraction = pPersist->getInteractionHandler(); |
459 | 3 | if ( xInteraction.is() ) |
460 | 0 | { |
461 | 0 | aMediaDescr.realloc( 3 ); |
462 | 0 | auto pMediaDescr = aMediaDescr.getArray(); |
463 | 0 | pMediaDescr[2].Name = "InteractionHandler"; |
464 | 0 | pMediaDescr[2].Value <<= xInteraction; |
465 | 0 | } |
466 | | |
467 | | //TODO/LATER: how to cope with creation failure?! |
468 | 3 | uno::Reference< embed::XEmbeddedObject > xObj = |
469 | 3 | pPersist->getEmbeddedObjectContainer().InsertEmbeddedLink( aMediaDescr , aPersistName ); |
470 | | |
471 | 3 | if( !xObj.is() ) |
472 | 3 | return; |
473 | | |
474 | 0 | tools::Rectangle aRect = pOle2Obj->GetLogicRect(); |
475 | 0 | if ( aRect.GetWidth() == 101 && aRect.GetHeight() == 101 ) |
476 | 0 | { |
477 | | // default size |
478 | 0 | try |
479 | 0 | { |
480 | 0 | awt::Size aSz = xObj->getVisualAreaSize( pOle2Obj->GetAspect() ); |
481 | 0 | aRect.SetSize( Size( aSz.Width, aSz.Height ) ); |
482 | 0 | } |
483 | 0 | catch (const uno::Exception&) |
484 | 0 | {} |
485 | 0 | pOle2Obj->SetLogicRect( aRect ); |
486 | 0 | } |
487 | 0 | else |
488 | 0 | { |
489 | 0 | awt::Size aSz; |
490 | 0 | Size aSize = pOle2Obj->GetLogicRect().GetSize(); |
491 | 0 | aSz.Width = aSize.Width(); |
492 | 0 | aSz.Height = aSize.Height(); |
493 | 0 | xObj->setVisualAreaSize( pOle2Obj->GetAspect(), aSz ); |
494 | 0 | } |
495 | | |
496 | | // connect the object after the visual area is set |
497 | 0 | SvxShape::setPropertyValue( UNO_NAME_OLE2_PERSISTNAME, uno::Any( aPersistName ) ); |
498 | | |
499 | | // the object is inserted during setting of PersistName property usually |
500 | 0 | if ( pOle2Obj->IsEmpty() ) |
501 | 0 | pOle2Obj->SetObjRef( xObj ); |
502 | 0 | } |
503 | | |
504 | | void SvxOle2Shape::resetModifiedState() |
505 | 0 | { |
506 | 0 | SdrObject* pObject = GetSdrObject(); |
507 | 0 | ::comphelper::IEmbeddedHelper* pPersist = pObject ? pObject->getSdrModelFromSdrObject().GetPersist() : nullptr; |
508 | 0 | if( pPersist && !pPersist->isEnableSetModified() ) |
509 | 0 | { |
510 | 0 | SdrOle2Obj* pOle = dynamic_cast< SdrOle2Obj* >(pObject); |
511 | 0 | if( pOle && !pOle->IsEmpty() ) |
512 | 0 | { |
513 | 0 | uno::Reference < util::XModifiable > xMod( pOle->GetObjRef(), uno::UNO_QUERY ); |
514 | 0 | if( xMod.is() ) |
515 | | // TODO/MBA: what's this?! |
516 | 0 | xMod->setModified( false ); |
517 | 0 | } |
518 | 0 | } |
519 | 0 | } |
520 | | |
521 | | SvGlobalName SvxOle2Shape::GetClassName_Impl(OUString& rHexCLSID) |
522 | 0 | { |
523 | 0 | DBG_TESTSOLARMUTEX(); |
524 | 0 | SvGlobalName aClassName; |
525 | 0 | SdrOle2Obj* pOle2Obj = dynamic_cast< SdrOle2Obj* >( GetSdrObject() ); |
526 | |
|
527 | 0 | if( pOle2Obj ) |
528 | 0 | { |
529 | 0 | rHexCLSID.clear(); |
530 | |
|
531 | 0 | if( pOle2Obj->IsEmpty() ) |
532 | 0 | { |
533 | 0 | ::comphelper::IEmbeddedHelper* pPersist = GetSdrObject()->getSdrModelFromSdrObject().GetPersist(); |
534 | 0 | if( pPersist ) |
535 | 0 | { |
536 | 0 | uno::Reference < embed::XEmbeddedObject > xObj = |
537 | 0 | pPersist->getEmbeddedObjectContainer().GetEmbeddedObject( pOle2Obj->GetPersistName() ); |
538 | 0 | if ( xObj.is() ) |
539 | 0 | { |
540 | 0 | aClassName = SvGlobalName( xObj->getClassID() ); |
541 | 0 | rHexCLSID = aClassName.GetHexName(); |
542 | 0 | } |
543 | 0 | } |
544 | 0 | } |
545 | |
|
546 | 0 | if (rHexCLSID.isEmpty()) |
547 | 0 | { |
548 | 0 | const uno::Reference < embed::XEmbeddedObject >& xObj( pOle2Obj->GetObjRef() ); |
549 | 0 | if ( xObj.is() ) |
550 | 0 | { |
551 | 0 | aClassName = SvGlobalName( xObj->getClassID() ); |
552 | 0 | rHexCLSID = aClassName.GetHexName(); |
553 | 0 | } |
554 | 0 | } |
555 | 0 | } |
556 | |
|
557 | 0 | return aClassName; |
558 | 0 | } |
559 | | |
560 | | OUString SvxOle2Shape::GetAndClearInitialFrameURL() |
561 | 12 | { |
562 | 12 | return OUString(); |
563 | 12 | } |
564 | | |
565 | | SvxAppletShape::SvxAppletShape(SdrObject* pObject, OUString referer) |
566 | 0 | : SvxOle2Shape(pObject, std::move(referer), getSvxMapProvider().GetMap(SVXMAP_APPLET), getSvxMapProvider().GetPropertySet(SVXMAP_APPLET, SdrObject::GetGlobalDrawObjectItemPool())) |
567 | 0 | { |
568 | 0 | SetShapeType( u"com.sun.star.drawing.AppletShape"_ustr ); |
569 | 0 | } |
570 | | |
571 | | SvxAppletShape::~SvxAppletShape() noexcept |
572 | | { |
573 | | } |
574 | | |
575 | | void SvxAppletShape::Create( SdrObject* pNewObj, SvxDrawPage* pNewPage ) |
576 | 0 | { |
577 | 0 | SvxShape::Create( pNewObj, pNewPage ); |
578 | 0 | const SvGlobalName aAppletClassId( SO3_APPLET_CLASSID ); |
579 | 0 | createObject(aAppletClassId); |
580 | 0 | SetShapeType( u"com.sun.star.drawing.AppletShape"_ustr ); |
581 | 0 | } |
582 | | |
583 | | void SAL_CALL SvxAppletShape::setPropertyValue( const OUString& aPropertyName, const css::uno::Any& rValue ) |
584 | 0 | { |
585 | 0 | SvxShape::setPropertyValue( aPropertyName, rValue ); |
586 | 0 | resetModifiedState(); |
587 | 0 | } |
588 | | |
589 | | void SAL_CALL SvxAppletShape::setPropertyValues( const css::uno::Sequence< OUString >& aPropertyNames, const css::uno::Sequence< css::uno::Any >& rValues ) |
590 | 0 | { |
591 | 0 | SvxShape::setPropertyValues( aPropertyNames, rValues ); |
592 | 0 | resetModifiedState(); |
593 | 0 | } |
594 | | |
595 | | bool SvxAppletShape::setPropertyValueImpl( const OUString& rName, const SfxItemPropertyMapEntry* pProperty, const css::uno::Any& rValue ) |
596 | 0 | { |
597 | 0 | if( (pProperty->nWID >= OWN_ATTR_APPLET_DOCBASE) && (pProperty->nWID <= OWN_ATTR_APPLET_ISSCRIPT) ) |
598 | 0 | { |
599 | 0 | if ( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef() ) ) |
600 | 0 | { |
601 | 0 | uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef()->getComponent(), uno::UNO_QUERY ); |
602 | 0 | if( xSet.is() ) |
603 | 0 | { |
604 | | // allow exceptions to pass through |
605 | 0 | xSet->setPropertyValue( rName, rValue ); |
606 | 0 | } |
607 | 0 | } |
608 | 0 | return true; |
609 | 0 | } |
610 | 0 | else |
611 | 0 | { |
612 | 0 | return SvxOle2Shape::setPropertyValueImpl( rName, pProperty, rValue ); |
613 | 0 | } |
614 | 0 | } |
615 | | |
616 | | bool SvxAppletShape::getPropertyValueImpl( const OUString& rName, const SfxItemPropertyMapEntry* pProperty, css::uno::Any& rValue ) |
617 | 0 | { |
618 | 0 | if( (pProperty->nWID >= OWN_ATTR_APPLET_DOCBASE) && (pProperty->nWID <= OWN_ATTR_APPLET_ISSCRIPT) ) |
619 | 0 | { |
620 | 0 | if ( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef() ) ) |
621 | 0 | { |
622 | 0 | uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef()->getComponent(), uno::UNO_QUERY ); |
623 | 0 | if( xSet.is() ) |
624 | 0 | { |
625 | 0 | rValue = xSet->getPropertyValue( rName ); |
626 | 0 | } |
627 | 0 | } |
628 | 0 | return true; |
629 | 0 | } |
630 | 0 | else |
631 | 0 | { |
632 | 0 | return SvxOle2Shape::getPropertyValueImpl( rName, pProperty, rValue ); |
633 | 0 | } |
634 | 0 | } |
635 | | |
636 | | SvxPluginShape::SvxPluginShape(SdrObject* pObject, OUString referer) |
637 | 0 | : SvxOle2Shape(pObject, std::move(referer), getSvxMapProvider().GetMap(SVXMAP_PLUGIN), getSvxMapProvider().GetPropertySet(SVXMAP_PLUGIN, SdrObject::GetGlobalDrawObjectItemPool())) |
638 | 0 | { |
639 | 0 | SetShapeType( u"com.sun.star.drawing.PluginShape"_ustr ); |
640 | 0 | } |
641 | | |
642 | | SvxPluginShape::~SvxPluginShape() noexcept |
643 | | { |
644 | | } |
645 | | |
646 | | void SvxPluginShape::Create( SdrObject* pNewObj, SvxDrawPage* pNewPage ) |
647 | 0 | { |
648 | 0 | SvxShape::Create( pNewObj, pNewPage ); |
649 | 0 | const SvGlobalName aPluginClassId( SO3_PLUGIN_CLASSID ); |
650 | 0 | createObject(aPluginClassId); |
651 | 0 | SetShapeType( u"com.sun.star.drawing.PluginShape"_ustr ); |
652 | 0 | } |
653 | | |
654 | | void SAL_CALL SvxPluginShape::setPropertyValue( const OUString& aPropertyName, const css::uno::Any& rValue ) |
655 | 0 | { |
656 | 0 | SvxShape::setPropertyValue( aPropertyName, rValue ); |
657 | 0 | resetModifiedState(); |
658 | 0 | } |
659 | | |
660 | | void SAL_CALL SvxPluginShape::setPropertyValues( const css::uno::Sequence< OUString >& aPropertyNames, const css::uno::Sequence< css::uno::Any >& rValues ) |
661 | 0 | { |
662 | 0 | SvxShape::setPropertyValues( aPropertyNames, rValues ); |
663 | 0 | resetModifiedState(); |
664 | 0 | } |
665 | | |
666 | | bool SvxPluginShape::setPropertyValueImpl( const OUString& rName, const SfxItemPropertyMapEntry* pProperty, const css::uno::Any& rValue ) |
667 | 0 | { |
668 | 0 | if( (pProperty->nWID >= OWN_ATTR_PLUGIN_MIMETYPE) && (pProperty->nWID <= OWN_ATTR_PLUGIN_COMMANDS) ) |
669 | 0 | { |
670 | 0 | if( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef() ) ) |
671 | 0 | { |
672 | 0 | uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef()->getComponent(), uno::UNO_QUERY ); |
673 | 0 | if( xSet.is() ) |
674 | 0 | { |
675 | | // allow exceptions to pass through |
676 | 0 | xSet->setPropertyValue( rName, rValue ); |
677 | 0 | } |
678 | 0 | } |
679 | 0 | return true; |
680 | 0 | } |
681 | 0 | else |
682 | 0 | { |
683 | 0 | return SvxOle2Shape::setPropertyValueImpl( rName, pProperty, rValue ); |
684 | 0 | } |
685 | 0 | } |
686 | | |
687 | | bool SvxPluginShape::getPropertyValueImpl( const OUString& rName, const SfxItemPropertyMapEntry* pProperty, css::uno::Any& rValue ) |
688 | 0 | { |
689 | 0 | if( (pProperty->nWID >= OWN_ATTR_PLUGIN_MIMETYPE) && (pProperty->nWID <= OWN_ATTR_PLUGIN_COMMANDS) ) |
690 | 0 | { |
691 | 0 | if( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef() ) ) |
692 | 0 | { |
693 | 0 | uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef()->getComponent(), uno::UNO_QUERY ); |
694 | 0 | if( xSet.is() ) |
695 | 0 | { |
696 | 0 | rValue = xSet->getPropertyValue( rName ); |
697 | 0 | } |
698 | 0 | } |
699 | 0 | return true; |
700 | 0 | } |
701 | 0 | else |
702 | 0 | { |
703 | 0 | return SvxOle2Shape::getPropertyValueImpl( rName, pProperty, rValue ); |
704 | 0 | } |
705 | 0 | } |
706 | | |
707 | | SvxFrameShape::SvxFrameShape(SdrObject* pObject, OUString referer) |
708 | 0 | : SvxOle2Shape(pObject, std::move(referer), getSvxMapProvider().GetMap(SVXMAP_FRAME), getSvxMapProvider().GetPropertySet(SVXMAP_FRAME, SdrObject::GetGlobalDrawObjectItemPool())) |
709 | 0 | { |
710 | 0 | SetShapeType( u"com.sun.star.drawing.FrameShape"_ustr ); |
711 | 0 | } |
712 | | |
713 | | SvxFrameShape::~SvxFrameShape() noexcept |
714 | 0 | { |
715 | 0 | } |
716 | | |
717 | | OUString SvxFrameShape::GetAndClearInitialFrameURL() |
718 | 0 | { |
719 | 0 | OUString sRet(m_sInitialFrameURL); |
720 | 0 | m_sInitialFrameURL.clear(); |
721 | 0 | return sRet; |
722 | 0 | } |
723 | | |
724 | | void SvxFrameShape::Create( SdrObject* pNewObj, SvxDrawPage* pNewPage ) |
725 | 0 | { |
726 | 0 | uno::Reference<beans::XPropertySet> xSet(static_cast<OWeakObject *>(this), uno::UNO_QUERY); |
727 | 0 | if (xSet) |
728 | 0 | xSet->getPropertyValue(u"FrameURL"_ustr) >>= m_sInitialFrameURL; |
729 | |
|
730 | 0 | SvxShape::Create( pNewObj, pNewPage ); |
731 | 0 | const SvGlobalName aIFrameClassId( SO3_IFRAME_CLASSID ); |
732 | 0 | createObject(aIFrameClassId); |
733 | 0 | SetShapeType( u"com.sun.star.drawing.FrameShape"_ustr ); |
734 | 0 | } |
735 | | |
736 | | void SAL_CALL SvxFrameShape::setPropertyValue( const OUString& aPropertyName, const css::uno::Any& rValue ) |
737 | 0 | { |
738 | 0 | SvxShape::setPropertyValue( aPropertyName, rValue ); |
739 | 0 | resetModifiedState(); |
740 | 0 | } |
741 | | |
742 | | void SAL_CALL SvxFrameShape::setPropertyValues( const css::uno::Sequence< OUString >& aPropertyNames, const css::uno::Sequence< css::uno::Any >& rValues ) |
743 | 0 | { |
744 | 0 | SvxShape::setPropertyValues( aPropertyNames, rValues ); |
745 | 0 | resetModifiedState(); |
746 | 0 | } |
747 | | |
748 | | bool SvxFrameShape::setPropertyValueImpl( const OUString& rName, const SfxItemPropertyMapEntry* pProperty, const css::uno::Any& rValue ) |
749 | 0 | { |
750 | 0 | if( (pProperty->nWID >= OWN_ATTR_FRAME_URL) && (pProperty->nWID <= OWN_ATTR_FRAME_MARGIN_HEIGHT) ) |
751 | 0 | { |
752 | 0 | if( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef() ) ) |
753 | 0 | { |
754 | 0 | uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef()->getComponent(), uno::UNO_QUERY ); |
755 | 0 | if( xSet.is() ) |
756 | 0 | { |
757 | | // allow exceptions to pass through |
758 | 0 | xSet->setPropertyValue( rName, rValue ); |
759 | 0 | } |
760 | 0 | } |
761 | 0 | return true; |
762 | 0 | } |
763 | 0 | else |
764 | 0 | { |
765 | 0 | return SvxOle2Shape::setPropertyValueImpl( rName, pProperty, rValue ); |
766 | 0 | } |
767 | 0 | } |
768 | | |
769 | | bool SvxFrameShape::getPropertyValueImpl(const OUString& rName, const SfxItemPropertyMapEntry* pProperty, |
770 | | css::uno::Any& rValue) |
771 | 0 | { |
772 | 0 | if( (pProperty->nWID >= OWN_ATTR_FRAME_URL) && (pProperty->nWID <= OWN_ATTR_FRAME_MARGIN_HEIGHT) ) |
773 | 0 | { |
774 | 0 | if( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef() ) ) |
775 | 0 | { |
776 | 0 | uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef()->getComponent(), uno::UNO_QUERY ); |
777 | 0 | if( xSet.is() ) |
778 | 0 | { |
779 | 0 | rValue = xSet->getPropertyValue( rName ); |
780 | 0 | } |
781 | 0 | } |
782 | 0 | return true; |
783 | 0 | } |
784 | 0 | else |
785 | 0 | { |
786 | 0 | return SvxOle2Shape::getPropertyValueImpl( rName, pProperty, rValue ); |
787 | 0 | } |
788 | 0 | } |
789 | | |
790 | | SvxMediaShape::SvxMediaShape(SdrObject* pObj, OUString referer) |
791 | 0 | : SvxShape( pObj, getSvxMapProvider().GetMap(SVXMAP_MEDIA), getSvxMapProvider().GetPropertySet(SVXMAP_MEDIA, SdrObject::GetGlobalDrawObjectItemPool()) ), |
792 | 0 | m_referer(std::move(referer)) |
793 | 0 | { |
794 | 0 | SetShapeType( u"com.sun.star.drawing.MediaShape"_ustr ); |
795 | 0 | } |
796 | | |
797 | | |
798 | | SvxMediaShape::~SvxMediaShape() noexcept |
799 | 0 | { |
800 | 0 | } |
801 | | |
802 | | |
803 | | bool SvxMediaShape::setPropertyValueImpl( const OUString& rName, const SfxItemPropertyMapEntry* pProperty, const css::uno::Any& rValue ) |
804 | 0 | { |
805 | 0 | if( ((pProperty->nWID >= OWN_ATTR_MEDIA_URL) && (pProperty->nWID <= OWN_ATTR_MEDIA_ZOOM)) |
806 | 0 | || (pProperty->nWID == OWN_ATTR_MEDIA_STREAM) |
807 | 0 | || (pProperty->nWID == OWN_ATTR_MEDIA_MIMETYPE) |
808 | 0 | || (pProperty->nWID == OWN_ATTR_VALUE_GRAPHIC) |
809 | 0 | || (pProperty->nWID == SDRATTR_GRAFCROP)) |
810 | 0 | { |
811 | 0 | #if HAVE_FEATURE_AVMEDIA |
812 | 0 | SdrMediaObj* pMedia = static_cast< SdrMediaObj* >( GetSdrObject() ); |
813 | 0 | ::avmedia::MediaItem aItem; |
814 | 0 | bool bOk = false; |
815 | 0 | #endif |
816 | |
|
817 | 0 | switch( pProperty->nWID ) |
818 | 0 | { |
819 | 0 | case OWN_ATTR_MEDIA_URL: |
820 | 0 | #if HAVE_FEATURE_AVMEDIA |
821 | 0 | { |
822 | 0 | OUString aURL; |
823 | 0 | if( rValue >>= aURL ) |
824 | 0 | { |
825 | 0 | bOk = true; |
826 | 0 | if ( aURL.startsWith("file:///") && !comphelper::DirectoryHelper::fileExists(aURL) ) |
827 | 0 | { |
828 | 0 | comphelper::IEmbeddedHelper* pPersist = GetSdrObject()->getSdrModelFromSdrObject().GetPersist(); |
829 | 0 | auto fileDirectoryEndIdx = pPersist->getDocumentBaseURL().lastIndexOf("/"); |
830 | 0 | auto fileNameStartIdx = aURL.lastIndexOf("/"); |
831 | 0 | if (fileDirectoryEndIdx != -1 && fileNameStartIdx != -1) |
832 | 0 | { |
833 | 0 | OUString aFallbackURL = OUString::Concat(pPersist->getDocumentBaseURL().subView(0, fileDirectoryEndIdx + 1)) |
834 | 0 | + aURL.subView(fileNameStartIdx + 1); |
835 | 0 | aItem.setFallbackURL(aFallbackURL); |
836 | 0 | } |
837 | 0 | } |
838 | 0 | aItem.setURL( aURL, u""_ustr, m_referer ); |
839 | 0 | } |
840 | 0 | } |
841 | 0 | #endif |
842 | 0 | break; |
843 | | |
844 | 0 | case OWN_ATTR_MEDIA_LOOP: |
845 | 0 | #if HAVE_FEATURE_AVMEDIA |
846 | 0 | { |
847 | 0 | bool bLoop; |
848 | |
|
849 | 0 | if( rValue >>= bLoop ) |
850 | 0 | { |
851 | 0 | bOk = true; |
852 | 0 | aItem.setLoop( bLoop ); |
853 | 0 | } |
854 | 0 | } |
855 | 0 | #endif |
856 | 0 | break; |
857 | | |
858 | 0 | case OWN_ATTR_MEDIA_MUTE: |
859 | 0 | #if HAVE_FEATURE_AVMEDIA |
860 | 0 | { |
861 | 0 | bool bMute; |
862 | |
|
863 | 0 | if( rValue >>= bMute ) |
864 | 0 | { |
865 | 0 | bOk = true; |
866 | 0 | aItem.setMute( bMute ); |
867 | 0 | } |
868 | 0 | } |
869 | 0 | #endif |
870 | 0 | break; |
871 | | |
872 | 0 | case OWN_ATTR_MEDIA_VOLUMEDB: |
873 | 0 | #if HAVE_FEATURE_AVMEDIA |
874 | 0 | { |
875 | 0 | sal_Int16 nVolumeDB = sal_Int16(); |
876 | |
|
877 | 0 | if( rValue >>= nVolumeDB ) |
878 | 0 | { |
879 | 0 | bOk = true; |
880 | 0 | aItem.setVolumeDB( nVolumeDB ); |
881 | 0 | } |
882 | 0 | } |
883 | 0 | #endif |
884 | 0 | break; |
885 | | |
886 | 0 | case OWN_ATTR_MEDIA_ZOOM: |
887 | 0 | #if HAVE_FEATURE_AVMEDIA |
888 | 0 | { |
889 | 0 | css::media::ZoomLevel eLevel; |
890 | |
|
891 | 0 | if( rValue >>= eLevel ) |
892 | 0 | { |
893 | 0 | bOk = true; |
894 | 0 | aItem.setZoom( eLevel ); |
895 | 0 | } |
896 | 0 | } |
897 | 0 | #endif |
898 | 0 | break; |
899 | | |
900 | 0 | case OWN_ATTR_MEDIA_MIMETYPE: |
901 | 0 | #if HAVE_FEATURE_AVMEDIA |
902 | 0 | { |
903 | 0 | OUString sMimeType; |
904 | 0 | if( rValue >>= sMimeType ) |
905 | 0 | { |
906 | 0 | bOk = true; |
907 | |
|
908 | 0 | if (aItem.getMimeType() != AVMEDIA_MIMETYPE_COMMON |
909 | 0 | && (sMimeType == "audio/unknown" || sMimeType == "video/unknown")) |
910 | 0 | { |
911 | 0 | break; |
912 | 0 | } |
913 | 0 | aItem.setMimeType( sMimeType ); |
914 | 0 | } |
915 | 0 | } |
916 | 0 | #endif |
917 | 0 | break; |
918 | | |
919 | 0 | case OWN_ATTR_VALUE_GRAPHIC: |
920 | 0 | #if HAVE_FEATURE_AVMEDIA |
921 | 0 | { |
922 | 0 | uno::Reference<graphic::XGraphic> xGraphic(rValue, uno::UNO_QUERY); |
923 | 0 | if (xGraphic.is()) |
924 | 0 | { |
925 | 0 | bOk = true; |
926 | 0 | aItem.setGraphic(Graphic(xGraphic)); |
927 | 0 | } |
928 | 0 | } |
929 | 0 | #endif |
930 | 0 | break; |
931 | | |
932 | 0 | case SDRATTR_GRAFCROP: |
933 | 0 | #if HAVE_FEATURE_AVMEDIA |
934 | 0 | { |
935 | 0 | text::GraphicCrop aCrop; |
936 | 0 | if (rValue >>= aCrop) |
937 | 0 | { |
938 | 0 | bOk = true; |
939 | 0 | aItem.setCrop(aCrop); |
940 | 0 | } |
941 | 0 | } |
942 | 0 | #endif |
943 | 0 | break; |
944 | | |
945 | 0 | case OWN_ATTR_MEDIA_STREAM: |
946 | 0 | #if HAVE_FEATURE_AVMEDIA |
947 | 0 | try |
948 | 0 | { |
949 | 0 | uno::Reference<io::XInputStream> xStream; |
950 | 0 | if (rValue >>= xStream) |
951 | 0 | { |
952 | 0 | pMedia->SetInputStream(xStream); |
953 | 0 | } |
954 | 0 | } |
955 | 0 | catch (const css::ucb::ContentCreationException&) |
956 | 0 | { |
957 | 0 | css::uno::Any exc = cppu::getCaughtException(); |
958 | 0 | throw css::lang::WrappedTargetException( |
959 | 0 | u"ContentCreationException Setting InputStream!"_ustr, |
960 | 0 | getXWeak(), |
961 | 0 | exc); |
962 | 0 | } |
963 | 0 | catch (const css::ucb::CommandFailedException&) |
964 | 0 | { |
965 | 0 | css::uno::Any anyEx = cppu::getCaughtException(); |
966 | 0 | throw css::lang::WrappedTargetException( |
967 | 0 | u"CommandFailedException Setting InputStream!"_ustr, |
968 | 0 | getXWeak(), |
969 | 0 | anyEx); |
970 | 0 | } |
971 | 0 | #endif |
972 | 0 | break; |
973 | | |
974 | 0 | default: |
975 | 0 | OSL_FAIL("SvxMediaShape::setPropertyValueImpl(), unknown argument!"); |
976 | 0 | } |
977 | | |
978 | 0 | #if HAVE_FEATURE_AVMEDIA |
979 | 0 | if( bOk ) |
980 | 0 | { |
981 | 0 | pMedia->setMediaProperties( aItem ); |
982 | 0 | return true; |
983 | 0 | } |
984 | 0 | #endif |
985 | 0 | } |
986 | 0 | else |
987 | 0 | { |
988 | 0 | return SvxShape::setPropertyValueImpl( rName, pProperty, rValue ); |
989 | 0 | } |
990 | | |
991 | 0 | throw IllegalArgumentException(); |
992 | 0 | } |
993 | | |
994 | | |
995 | | bool SvxMediaShape::getPropertyValueImpl( const OUString& rName, const SfxItemPropertyMapEntry* pProperty, css::uno::Any& rValue ) |
996 | 0 | { |
997 | 0 | if ( ((pProperty->nWID >= OWN_ATTR_MEDIA_URL) && |
998 | 0 | (pProperty->nWID <= OWN_ATTR_MEDIA_ZOOM)) |
999 | 0 | || (pProperty->nWID == OWN_ATTR_MEDIA_STREAM) |
1000 | 0 | || (pProperty->nWID == OWN_ATTR_MEDIA_TEMPFILEURL) |
1001 | 0 | || (pProperty->nWID == OWN_ATTR_MEDIA_MIMETYPE) |
1002 | 0 | || (pProperty->nWID == OWN_ATTR_FALLBACK_GRAPHIC) |
1003 | 0 | || (pProperty->nWID == OWN_ATTR_VALUE_GRAPHIC) |
1004 | 0 | || (pProperty->nWID == SDRATTR_GRAFCROP)) |
1005 | 0 | { |
1006 | 0 | SdrMediaObj* pMedia = static_cast< SdrMediaObj* >( GetSdrObject() ); |
1007 | 0 | #if HAVE_FEATURE_AVMEDIA |
1008 | 0 | const ::avmedia::MediaItem aItem( pMedia->getMediaProperties() ); |
1009 | 0 | #endif |
1010 | |
|
1011 | 0 | switch( pProperty->nWID ) |
1012 | 0 | { |
1013 | 0 | case OWN_ATTR_MEDIA_URL: |
1014 | 0 | #if HAVE_FEATURE_AVMEDIA |
1015 | 0 | rValue <<= aItem.getURL(); |
1016 | 0 | #endif |
1017 | 0 | break; |
1018 | | |
1019 | 0 | case OWN_ATTR_MEDIA_LOOP: |
1020 | 0 | #if HAVE_FEATURE_AVMEDIA |
1021 | 0 | rValue <<= aItem.isLoop(); |
1022 | 0 | #endif |
1023 | 0 | break; |
1024 | | |
1025 | 0 | case OWN_ATTR_MEDIA_MUTE: |
1026 | 0 | #if HAVE_FEATURE_AVMEDIA |
1027 | 0 | rValue <<= aItem.isMute(); |
1028 | 0 | #endif |
1029 | 0 | break; |
1030 | | |
1031 | 0 | case OWN_ATTR_MEDIA_VOLUMEDB: |
1032 | 0 | #if HAVE_FEATURE_AVMEDIA |
1033 | 0 | rValue <<= aItem.getVolumeDB(); |
1034 | 0 | #endif |
1035 | 0 | break; |
1036 | | |
1037 | 0 | case OWN_ATTR_MEDIA_ZOOM: |
1038 | 0 | #if HAVE_FEATURE_AVMEDIA |
1039 | 0 | rValue <<= aItem.getZoom(); |
1040 | 0 | #endif |
1041 | 0 | break; |
1042 | | |
1043 | 0 | case OWN_ATTR_MEDIA_STREAM: |
1044 | 0 | try |
1045 | 0 | { |
1046 | 0 | rValue <<= pMedia->GetInputStream(); |
1047 | 0 | } |
1048 | 0 | catch (const css::ucb::ContentCreationException&) |
1049 | 0 | { |
1050 | 0 | css::uno::Any anyEx = cppu::getCaughtException(); |
1051 | 0 | throw css::lang::WrappedTargetException( |
1052 | 0 | u"ContentCreationException Getting InputStream!"_ustr, |
1053 | 0 | getXWeak(), anyEx ); |
1054 | 0 | } |
1055 | 0 | catch (const css::ucb::CommandFailedException&) |
1056 | 0 | { |
1057 | 0 | css::uno::Any anyEx = cppu::getCaughtException(); |
1058 | 0 | throw css::lang::WrappedTargetException( |
1059 | 0 | u"CommandFailedException Getting InputStream!"_ustr, |
1060 | 0 | getXWeak(), anyEx ); |
1061 | 0 | } |
1062 | | |
1063 | 0 | break; |
1064 | | |
1065 | 0 | case OWN_ATTR_MEDIA_TEMPFILEURL: |
1066 | 0 | #if HAVE_FEATURE_AVMEDIA |
1067 | 0 | rValue <<= aItem.getTempURL(); |
1068 | 0 | #endif |
1069 | 0 | break; |
1070 | | |
1071 | 0 | case OWN_ATTR_MEDIA_MIMETYPE: |
1072 | 0 | #if HAVE_FEATURE_AVMEDIA |
1073 | 0 | rValue <<= aItem.getMimeType(); |
1074 | 0 | #endif |
1075 | 0 | break; |
1076 | | |
1077 | 0 | case OWN_ATTR_VALUE_GRAPHIC: |
1078 | 0 | #if HAVE_FEATURE_AVMEDIA |
1079 | 0 | { |
1080 | 0 | const Graphic& aGraphic = aItem.getGraphic(); |
1081 | 0 | if (!aGraphic.IsNone()) |
1082 | 0 | { |
1083 | 0 | rValue <<= aGraphic.GetXGraphic(); |
1084 | 0 | } |
1085 | 0 | } |
1086 | 0 | #endif |
1087 | 0 | break; |
1088 | | |
1089 | 0 | case SDRATTR_GRAFCROP: |
1090 | 0 | #if HAVE_FEATURE_AVMEDIA |
1091 | 0 | { |
1092 | 0 | text::GraphicCrop aCrop = aItem.getCrop(); |
1093 | 0 | rValue <<= aCrop; |
1094 | 0 | } |
1095 | 0 | #endif |
1096 | 0 | break; |
1097 | | |
1098 | 0 | case OWN_ATTR_FALLBACK_GRAPHIC: |
1099 | 0 | rValue <<= pMedia->getSnapshot(); |
1100 | 0 | break; |
1101 | | |
1102 | 0 | default: |
1103 | 0 | OSL_FAIL("SvxMediaShape::getPropertyValueImpl(), unknown property!"); |
1104 | 0 | } |
1105 | 0 | return true; |
1106 | 0 | } |
1107 | 0 | else |
1108 | 0 | { |
1109 | 0 | return SvxShape::getPropertyValueImpl( rName, pProperty, rValue ); |
1110 | 0 | } |
1111 | 0 | } |
1112 | | |
1113 | | bool SvxMediaShape::getPropertyStateImpl(const SfxItemPropertyMapEntry* pProperty, |
1114 | | css::beans::PropertyState& rState) |
1115 | 0 | { |
1116 | 0 | #if HAVE_FEATURE_AVMEDIA |
1117 | 0 | if (pProperty->nWID == SDRATTR_GRAFCROP) |
1118 | 0 | { |
1119 | 0 | auto pMedia = static_cast<SdrMediaObj*>(GetSdrObject()); |
1120 | 0 | const avmedia::MediaItem& rItem = pMedia->getMediaProperties(); |
1121 | 0 | const text::GraphicCrop& rCrop = rItem.getCrop(); |
1122 | 0 | if (rCrop.Bottom > 0 || rCrop.Left > 0 || rCrop.Right > 0 || rCrop.Top > 0) |
1123 | 0 | { |
1124 | | // The media has a crop, expose it to UNO-based export filters. |
1125 | 0 | rState = beans::PropertyState_DIRECT_VALUE; |
1126 | 0 | } |
1127 | 0 | else |
1128 | 0 | { |
1129 | 0 | rState = beans::PropertyState_AMBIGUOUS_VALUE; |
1130 | 0 | } |
1131 | 0 | return true; |
1132 | 0 | } |
1133 | 0 | #endif |
1134 | | |
1135 | 0 | return SvxShape::getPropertyStateImpl(pProperty, rState); |
1136 | 0 | } |
1137 | | |
1138 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |