Line data Source code
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/XLinkageSupport.hpp>
22 : #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
23 : #include <com/sun/star/task/XInteractionHandler.hpp>
24 :
25 : #include <vcl/virdev.hxx>
26 : #include <svx/svdoole2.hxx>
27 : #include <svx/svdomedia.hxx>
28 : #include <svx/svdpool.hxx>
29 : #include <sot/clsids.hxx>
30 : #include <sfx2/frmdescr.hxx>
31 : #include <vcl/svapp.hxx>
32 : #include <osl/mutex.hxx>
33 :
34 : #include <toolkit/helper/vclunohelper.hxx>
35 : #include <sfx2/objsh.hxx>
36 : #include <sfx2/docfile.hxx>
37 :
38 : #include <sot/storage.hxx>
39 : #include <sot/exchange.hxx>
40 : #include <svtools/FilterConfigItem.hxx>
41 :
42 : #include <svx/svdmodel.hxx>
43 : #include "shapeimpl.hxx"
44 :
45 : #include <svx/unoshprp.hxx>
46 :
47 : #include "svx/unoapi.hxx"
48 : #include "svx/svdpagv.hxx"
49 : #include "svx/svdview.hxx"
50 : #include "svx/svdglob.hxx"
51 : #include "svx/svdstr.hrc"
52 : #include <svtools/wmf.hxx>
53 :
54 : ///////////////////////////////////////////////////////////////////////
55 :
56 : using namespace ::osl;
57 : using namespace ::rtl;
58 : using namespace ::cppu;
59 : using namespace ::com::sun::star;
60 : using namespace ::com::sun::star::uno;
61 : using namespace ::com::sun::star::lang;
62 : using namespace ::com::sun::star::container;
63 : using namespace ::com::sun::star::beans;
64 :
65 : ///////////////////////////////////////////////////////////////////////
66 0 : SvxOle2Shape::SvxOle2Shape( SdrObject* pObject ) throw()
67 0 : : SvxShapeText( pObject, getSvxMapProvider().GetMap(SVXMAP_OLE2),
68 0 : getSvxMapProvider().GetPropertySet(SVXMAP_OLE2,SdrObject::GetGlobalDrawObjectItemPool()) )
69 : {
70 0 : }
71 :
72 5 : SvxOle2Shape::SvxOle2Shape( SdrObject* pObject, const SfxItemPropertyMapEntry* pPropertyMap, const SvxItemPropertySet* pPropertySet ) throw ()
73 5 : : SvxShapeText( pObject, pPropertyMap, pPropertySet )
74 : {
75 5 : }
76 :
77 10 : SvxOle2Shape::~SvxOle2Shape() throw()
78 : {
79 10 : }
80 :
81 78 : ::com::sun::star::uno::Any SAL_CALL SvxOle2Shape::queryAggregation( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException)
82 : {
83 78 : return SvxShapeText::queryAggregation( rType );
84 : }
85 :
86 : //XPropertySet
87 24 : bool SvxOle2Shape::setPropertyValueImpl( const ::rtl::OUString& rName, const SfxItemPropertySimpleEntry* pProperty, const ::com::sun::star::uno::Any& rValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
88 : {
89 24 : switch( pProperty->nWID )
90 : {
91 : case OWN_ATTR_OLE_VISAREA:
92 : {
93 : // TODO/LATER: seems to make no sence for iconified object
94 :
95 0 : awt::Rectangle aVisArea;
96 0 : if( (rValue >>= aVisArea) && mpObj->ISA(SdrOle2Obj))
97 : {
98 0 : Size aTmp( aVisArea.X + aVisArea.Width, aVisArea.Y + aVisArea.Height );
99 0 : uno::Reference < embed::XEmbeddedObject > xObj = ((SdrOle2Obj*)mpObj.get())->GetObjRef();
100 0 : if( xObj.is() )
101 : {
102 : try
103 : {
104 0 : MapUnit aMapUnit( MAP_100TH_MM ); // the API handles with MAP_100TH_MM map mode
105 0 : MapUnit aObjUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( embed::Aspects::MSOLE_CONTENT ) );
106 0 : aTmp = OutputDevice::LogicToLogic( aTmp, aMapUnit, aObjUnit );
107 0 : xObj->setVisualAreaSize( embed::Aspects::MSOLE_CONTENT, awt::Size( aTmp.Width(), aTmp.Height() ) );
108 : }
109 0 : catch( uno::Exception& )
110 : {
111 : OSL_FAIL( "Couldn't set the visual area for the object!\n" );
112 : }
113 : }
114 :
115 0 : return true;
116 : }
117 : break;
118 : }
119 : case OWN_ATTR_OLE_ASPECT:
120 : {
121 4 : sal_Int64 nAspect = 0;
122 4 : if( rValue >>= nAspect )
123 : {
124 4 : static_cast<SdrOle2Obj*>(mpObj.get())->SetAspect( nAspect );
125 4 : return true;
126 : }
127 : break;
128 : }
129 : case OWN_ATTR_CLSID:
130 : {
131 0 : OUString aCLSID;
132 0 : if( rValue >>= aCLSID )
133 : {
134 : // init a ole object with a global name
135 0 : SvGlobalName aClassName;
136 0 : if( aClassName.MakeId( aCLSID ) )
137 : {
138 0 : if( createObject( aClassName ) )
139 0 : return true;
140 0 : }
141 : }
142 0 : break;
143 : }
144 : case OWN_ATTR_THUMBNAIL:
145 : {
146 0 : OUString aURL;
147 0 : if( rValue >>= aURL )
148 : {
149 0 : GraphicObject aGrafObj( GraphicObject::CreateGraphicObjectFromURL( aURL ) );
150 0 : static_cast<SdrOle2Obj*>(mpObj.get())->SetGraphic( &aGrafObj.GetGraphic() );
151 0 : return true;
152 : }
153 0 : break;
154 : }
155 : case OWN_ATTR_VALUE_GRAPHIC:
156 : {
157 0 : uno::Reference< graphic::XGraphic > xGraphic( rValue, uno::UNO_QUERY );
158 0 : if( xGraphic.is() )
159 : {
160 0 : SdrOle2Obj* pOle = dynamic_cast< SdrOle2Obj* >( mpObj.get() );
161 0 : if( pOle )
162 : {
163 0 : GraphicObject aGrafObj( xGraphic );
164 0 : const Graphic aGraphic( aGrafObj.GetGraphic() );
165 0 : pOle->SetGraphicToObj( aGraphic, rtl::OUString() );
166 : }
167 0 : return true;
168 : }
169 0 : break;
170 : }
171 : case OWN_ATTR_PERSISTNAME:
172 : {
173 4 : OUString aPersistName;
174 4 : if( rValue >>= aPersistName )
175 : {
176 4 : static_cast<SdrOle2Obj*>(mpObj.get())->SetPersistName( aPersistName );
177 4 : return true;
178 : }
179 4 : break;
180 : }
181 : case OWN_ATTR_OLE_LINKURL:
182 : {
183 0 : OUString aLinkURL;
184 0 : if( rValue >>= aLinkURL )
185 : {
186 0 : createLink( aLinkURL );
187 0 : return true;
188 : }
189 0 : break;
190 : }
191 : default:
192 16 : return SvxShapeText::setPropertyValueImpl( rName, pProperty, rValue );
193 : }
194 :
195 0 : throw IllegalArgumentException();
196 : }
197 :
198 0 : bool SvxOle2Shape::getPropertyValueImpl( const ::rtl::OUString& rName, const SfxItemPropertySimpleEntry* pProperty, ::com::sun::star::uno::Any& rValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
199 : {
200 0 : switch( pProperty->nWID )
201 : {
202 : case OWN_ATTR_CLSID:
203 : {
204 0 : OUString aCLSID;
205 0 : SvGlobalName aClassName = GetClassName_Impl(aCLSID);
206 0 : rValue <<= aCLSID;
207 0 : break;
208 : }
209 :
210 : case OWN_ATTR_INTERNAL_OLE:
211 : {
212 0 : rtl::OUString sCLSID;
213 0 : rValue <<= SotExchange::IsInternal( GetClassName_Impl(sCLSID) );
214 0 : break;
215 : }
216 :
217 : case OWN_ATTR_METAFILE:
218 : {
219 0 : SdrOle2Obj* pObj = dynamic_cast<SdrOle2Obj*>(mpObj.get());
220 0 : if( pObj )
221 : {
222 0 : Graphic* pGraphic = pObj->GetGraphic();
223 0 : if( pGraphic )
224 : {
225 0 : sal_Bool bIsWMF = sal_False;
226 0 : if ( pGraphic->IsLink() )
227 : {
228 0 : GfxLink aLnk = pGraphic->GetLink();
229 0 : if ( aLnk.GetType() == GFX_LINK_TYPE_NATIVE_WMF )
230 : {
231 0 : bIsWMF = sal_True;
232 0 : uno::Sequence<sal_Int8> aSeq((sal_Int8*)aLnk.GetData(), (sal_Int32) aLnk.GetDataSize());
233 0 : rValue <<= aSeq;
234 0 : }
235 : }
236 0 : if ( !bIsWMF )
237 : {
238 0 : GDIMetaFile aMtf;
239 0 : if ( pGraphic->GetType() != GRAPHIC_BITMAP )
240 0 : aMtf = pObj->GetGraphic()->GetGDIMetaFile();
241 : else
242 : {
243 0 : VirtualDevice aVirDev;
244 0 : aMtf.Record( &aVirDev );
245 0 : pGraphic->Draw( &aVirDev, Point(), pGraphic->GetPrefSize() );
246 0 : aMtf.Stop();
247 0 : aMtf.SetPrefSize( pGraphic->GetPrefSize() );
248 0 : aMtf.SetPrefMapMode( pGraphic->GetPrefMapMode() );
249 : }
250 0 : SvMemoryStream aDestStrm( 65535, 65535 );
251 0 : ConvertGDIMetaFileToWMF( aMtf, aDestStrm, NULL, sal_False );
252 : const uno::Sequence<sal_Int8> aSeq(
253 0 : static_cast< const sal_Int8* >(aDestStrm.GetData()),
254 0 : aDestStrm.GetEndOfData());
255 0 : rValue <<= aSeq;
256 : }
257 : }
258 : }
259 : else
260 : {
261 0 : rValue = GetBitmap( sal_True );
262 : }
263 0 : break;
264 : }
265 :
266 : case OWN_ATTR_OLE_VISAREA:
267 : {
268 0 : awt::Rectangle aVisArea;
269 0 : if( mpObj->ISA(SdrOle2Obj))
270 : {
271 0 : MapMode aMapMode( MAP_100TH_MM ); // the API uses this map mode
272 0 : Size aTmp = ((SdrOle2Obj*)mpObj.get())->GetOrigObjSize( &aMapMode ); // get the size in the requested map mode
273 0 : aVisArea = awt::Rectangle( 0, 0, aTmp.Width(), aTmp.Height() );
274 : }
275 :
276 0 : rValue <<= aVisArea;
277 : break;
278 : }
279 :
280 : case OWN_ATTR_OLESIZE:
281 : {
282 0 : Size aTmp( static_cast<SdrOle2Obj*>(mpObj.get())->GetOrigObjSize() );
283 0 : rValue <<= awt::Size( aTmp.Width(), aTmp.Height() );
284 : break;
285 : }
286 :
287 : case OWN_ATTR_OLE_ASPECT:
288 : {
289 0 : rValue <<= static_cast<SdrOle2Obj*>(mpObj.get())->GetAspect();
290 0 : break;
291 : }
292 :
293 : case OWN_ATTR_OLEMODEL:
294 : case OWN_ATTR_OLE_EMBEDDED_OBJECT:
295 : case OWN_ATTR_OLE_EMBEDDED_OBJECT_NONEWCLIENT:
296 : {
297 0 : SdrOle2Obj* pObj = dynamic_cast<SdrOle2Obj*>( mpObj.get() );
298 0 : if( pObj )
299 : {
300 0 : uno::Reference < embed::XEmbeddedObject > xObj( pObj->GetObjRef() );
301 0 : 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 : {
304 : // Discussed with CL fue 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 : {
308 : #if OSL_DEBUG_LEVEL > 0
309 : const sal_Bool bSuccess(pObj->AddOwnLightClient());
310 : OSL_ENSURE( bSuccess, "An object without client is provided!" );
311 : #else
312 0 : pObj->AddOwnLightClient();
313 : #endif
314 : }
315 :
316 0 : if ( pProperty->nWID == OWN_ATTR_OLEMODEL )
317 0 : rValue <<= pObj->GetObjRef()->getComponent();
318 : else
319 0 : rValue <<= xObj;
320 0 : }
321 : }
322 0 : break;
323 : }
324 :
325 : case OWN_ATTR_VALUE_GRAPHIC:
326 : {
327 0 : uno::Reference< graphic::XGraphic > xGraphic;
328 0 : Graphic* pGraphic = static_cast<SdrOle2Obj*>( mpObj.get() )->GetGraphic();
329 0 : if( pGraphic )
330 0 : xGraphic = pGraphic->GetXGraphic();
331 0 : rValue <<= xGraphic;
332 0 : break;
333 : }
334 :
335 : case OWN_ATTR_THUMBNAIL:
336 : {
337 0 : OUString aURL;
338 0 : SdrOle2Obj* pOle = dynamic_cast< SdrOle2Obj* >( mpObj.get() );
339 0 : if( pOle )
340 : {
341 0 : Graphic* pGraphic = pOle->GetGraphic();
342 :
343 : // if there isn't already a preview graphic set, check if we need to generate
344 : // one if model says so
345 0 : if( pGraphic == NULL && !pOle->IsEmptyPresObj() && mpModel->IsSaveOLEPreview() )
346 0 : pGraphic = pOle->GetGraphic();
347 :
348 0 : if( pGraphic )
349 : {
350 0 : GraphicObject aObj( *pGraphic );
351 0 : aURL = OUString( UNO_NAME_GRAPHOBJ_URLPREFIX);
352 : aURL += rtl::OStringToOUString(aObj.GetUniqueID(),
353 0 : RTL_TEXTENCODING_ASCII_US);
354 : }
355 : }
356 0 : rValue <<= aURL;
357 0 : break;
358 : }
359 : case OWN_ATTR_PERSISTNAME:
360 : {
361 0 : OUString aPersistName;
362 0 : SdrOle2Obj* pOle = dynamic_cast< SdrOle2Obj* >( mpObj.get() );
363 :
364 0 : if( pOle )
365 : {
366 0 : aPersistName = pOle->GetPersistName();
367 0 : if( !aPersistName.isEmpty() )
368 : {
369 0 : ::comphelper::IEmbeddedHelper *pPersist = mpObj->GetModel()->GetPersist();
370 0 : if( (NULL == pPersist) || !pPersist->getEmbeddedObjectContainer().HasEmbeddedObject( pOle->GetPersistName() ) )
371 0 : aPersistName = OUString();
372 : }
373 : }
374 :
375 0 : rValue <<= aPersistName;
376 0 : break;
377 : }
378 : case OWN_ATTR_OLE_LINKURL:
379 : {
380 0 : OUString aLinkURL;
381 0 : SdrOle2Obj* pOle = dynamic_cast< SdrOle2Obj* >( mpObj.get() );
382 :
383 0 : if( pOle )
384 : {
385 0 : uno::Reference< embed::XLinkageSupport > xLink( pOle->GetObjRef(), uno::UNO_QUERY );
386 0 : if ( xLink.is() && xLink->isLink() )
387 0 : aLinkURL = xLink->getLinkURL();
388 : }
389 :
390 0 : rValue <<= aLinkURL;
391 0 : break;
392 : }
393 : default:
394 0 : return SvxShapeText::getPropertyValueImpl( rName, pProperty, rValue );
395 : }
396 :
397 0 : return true;
398 : }
399 :
400 0 : sal_Bool SvxOle2Shape::createObject( const SvGlobalName &aClassName )
401 : {
402 : DBG_TESTSOLARMUTEX();
403 :
404 0 : SdrOle2Obj* pOle2Obj = dynamic_cast< SdrOle2Obj* >( mpObj.get() );
405 0 : if ( !pOle2Obj || !pOle2Obj->IsEmpty() )
406 0 : return sal_False;
407 :
408 : // create storage and inplace object
409 0 : ::comphelper::IEmbeddedHelper* pPersist = mpModel->GetPersist();
410 0 : ::rtl::OUString aPersistName;
411 0 : OUString aTmpStr;
412 0 : if( SvxShape::getPropertyValue( UNO_NAME_OLE2_PERSISTNAME ) >>= aTmpStr )
413 0 : aPersistName = aTmpStr;
414 :
415 : //TODO/LATER: how to cope with creation failure?!
416 0 : uno::Reference < embed::XEmbeddedObject > xObj( pPersist->getEmbeddedObjectContainer().CreateEmbeddedObject( aClassName.GetByteSequence(), aPersistName ) );
417 0 : if( xObj.is() )
418 : {
419 0 : Rectangle aRect = pOle2Obj->GetLogicRect();
420 0 : if ( aRect.GetWidth() == 100 && aRect.GetHeight() == 100 )
421 : {
422 : // TODO/LATER: is it possible that this method is used to create an iconified object?
423 : // default size
424 : try
425 : {
426 0 : awt::Size aSz = xObj->getVisualAreaSize( pOle2Obj->GetAspect() );
427 0 : aRect.SetSize( Size( aSz.Width, aSz.Height ) );
428 : }
429 0 : catch( embed::NoVisualAreaSizeException& )
430 : {}
431 0 : pOle2Obj->SetLogicRect( aRect );
432 : }
433 : else
434 : {
435 0 : awt::Size aSz;
436 0 : Size aSize = pOle2Obj->GetLogicRect().GetSize();
437 0 : aSz.Width = aSize.Width();
438 0 : aSz.Height = aSize.Height();
439 0 : xObj->setVisualAreaSize( pOle2Obj->GetAspect(), aSz );
440 : }
441 :
442 : // connect the object after the visual area is set
443 0 : SvxShape::setPropertyValue( UNO_NAME_OLE2_PERSISTNAME, Any( aTmpStr = aPersistName ) );
444 :
445 : // the object is inserted during setting of PersistName property usually
446 0 : if( pOle2Obj->IsEmpty() )
447 0 : pOle2Obj->SetObjRef( xObj );
448 : }
449 :
450 0 : return xObj.is();
451 : }
452 :
453 0 : sal_Bool SvxOle2Shape::createLink( const ::rtl::OUString& aLinkURL )
454 : {
455 : DBG_TESTSOLARMUTEX();
456 :
457 0 : SdrOle2Obj* pOle2Obj = dynamic_cast< SdrOle2Obj* >( mpObj.get() );
458 0 : if ( !pOle2Obj || !pOle2Obj->IsEmpty() )
459 0 : return sal_False;
460 :
461 0 : ::rtl::OUString aPersistName;
462 :
463 0 : ::comphelper::IEmbeddedHelper* pPersist = mpModel->GetPersist();
464 :
465 0 : uno::Sequence< beans::PropertyValue > aMediaDescr( 1 );
466 0 : aMediaDescr[0].Name = ::rtl::OUString("URL");
467 0 : aMediaDescr[0].Value <<= aLinkURL;
468 :
469 0 : uno::Reference< task::XInteractionHandler > xInteraction = pPersist->getInteractionHandler();
470 0 : if ( xInteraction.is() )
471 : {
472 0 : aMediaDescr.realloc( 2 );
473 0 : aMediaDescr[1].Name = ::rtl::OUString( "InteractionHandler" );
474 0 : aMediaDescr[1].Value <<= xInteraction;
475 : }
476 :
477 : //TODO/LATER: how to cope with creation failure?!
478 : uno::Reference< embed::XEmbeddedObject > xObj =
479 0 : pPersist->getEmbeddedObjectContainer().InsertEmbeddedLink( aMediaDescr , aPersistName );
480 :
481 0 : if( xObj.is() )
482 : {
483 0 : Rectangle aRect = pOle2Obj->GetLogicRect();
484 0 : if ( aRect.GetWidth() == 100 && aRect.GetHeight() == 100 )
485 : {
486 : // default size
487 : try
488 : {
489 0 : awt::Size aSz = xObj->getVisualAreaSize( pOle2Obj->GetAspect() );
490 0 : aRect.SetSize( Size( aSz.Width, aSz.Height ) );
491 : }
492 0 : catch( embed::NoVisualAreaSizeException& )
493 : {}
494 0 : pOle2Obj->SetLogicRect( aRect );
495 : }
496 : else
497 : {
498 0 : awt::Size aSz;
499 0 : Size aSize = pOle2Obj->GetLogicRect().GetSize();
500 0 : aSz.Width = aSize.Width();
501 0 : aSz.Height = aSize.Height();
502 0 : xObj->setVisualAreaSize( pOle2Obj->GetAspect(), aSz );
503 : }
504 :
505 : // connect the object after the visual area is set
506 0 : SvxShape::setPropertyValue( UNO_NAME_OLE2_PERSISTNAME, uno::makeAny( aPersistName ) );
507 :
508 : // the object is inserted during setting of PersistName property usually
509 0 : if ( pOle2Obj->IsEmpty() )
510 0 : pOle2Obj->SetObjRef( xObj );
511 : }
512 :
513 0 : return xObj.is();
514 : }
515 :
516 0 : void SvxOle2Shape::resetModifiedState()
517 : {
518 0 : ::comphelper::IEmbeddedHelper* pPersist = mpModel ? mpModel->GetPersist() : 0;
519 0 : if( pPersist && !pPersist->isEnableSetModified() )
520 : {
521 0 : SdrOle2Obj* pOle = dynamic_cast< SdrOle2Obj* >( mpObj.get() );
522 0 : if( pOle && !pOle->IsEmpty() )
523 : {
524 0 : uno::Reference < util::XModifiable > xMod( pOle->GetObjRef(), uno::UNO_QUERY );
525 0 : if( xMod.is() )
526 : // TODO/MBA: what's this?!
527 0 : xMod->setModified( sal_False );
528 : }
529 : }
530 0 : }
531 :
532 0 : const SvGlobalName SvxOle2Shape::GetClassName_Impl(rtl::OUString& rHexCLSID)
533 : {
534 : DBG_TESTSOLARMUTEX();
535 0 : SvGlobalName aClassName;
536 0 : SdrOle2Obj* pOle2Obj = dynamic_cast< SdrOle2Obj* >( mpObj.get() );
537 :
538 0 : if( pOle2Obj )
539 : {
540 0 : rHexCLSID = rtl::OUString();
541 :
542 0 : if( pOle2Obj->IsEmpty() )
543 : {
544 0 : ::comphelper::IEmbeddedHelper* pPersist = mpModel->GetPersist();
545 0 : if( pPersist )
546 : {
547 : uno::Reference < embed::XEmbeddedObject > xObj =
548 0 : pPersist->getEmbeddedObjectContainer().GetEmbeddedObject( pOle2Obj->GetPersistName() );
549 0 : if ( xObj.is() )
550 : {
551 0 : aClassName = SvGlobalName( xObj->getClassID() );
552 0 : rHexCLSID = aClassName.GetHexName();
553 0 : }
554 : }
555 : }
556 :
557 0 : if (rHexCLSID.isEmpty())
558 : {
559 0 : uno::Reference < embed::XEmbeddedObject > xObj( pOle2Obj->GetObjRef() );
560 0 : if ( xObj.is() )
561 : {
562 0 : aClassName = SvGlobalName( xObj->getClassID() );
563 0 : rHexCLSID = aClassName.GetHexName();
564 0 : }
565 : }
566 : }
567 :
568 0 : return aClassName;
569 : }
570 :
571 : ///////////////////////////////////////////////////////////////////////
572 :
573 0 : SvxAppletShape::SvxAppletShape( SdrObject* pObject ) throw()
574 0 : : SvxOle2Shape( pObject, getSvxMapProvider().GetMap(SVXMAP_APPLET), getSvxMapProvider().GetPropertySet(SVXMAP_APPLET, SdrObject::GetGlobalDrawObjectItemPool()) )
575 : {
576 0 : SetShapeType( rtl::OUString( "com.sun.star.drawing.AppletShape" ) );
577 0 : }
578 :
579 0 : SvxAppletShape::~SvxAppletShape() throw()
580 : {
581 0 : }
582 :
583 0 : void SvxAppletShape::Create( SdrObject* pNewObj, SvxDrawPage* pNewPage )
584 : {
585 0 : SvxShape::Create( pNewObj, pNewPage );
586 0 : const SvGlobalName aAppletClassId( SO3_APPLET_CLASSID );
587 0 : createObject(aAppletClassId);
588 0 : SetShapeType( rtl::OUString( "com.sun.star.drawing.AppletShape" ) );
589 0 : }
590 :
591 0 : void SAL_CALL SvxAppletShape::setPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& rValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
592 : {
593 0 : SvxShape::setPropertyValue( aPropertyName, rValue );
594 0 : resetModifiedState();
595 0 : }
596 :
597 0 : void SAL_CALL SvxAppletShape::setPropertyValues( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aPropertyNames, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& rValues ) throw (::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
598 : {
599 0 : SvxShape::setPropertyValues( aPropertyNames, rValues );
600 0 : resetModifiedState();
601 0 : }
602 :
603 0 : bool SvxAppletShape::setPropertyValueImpl( const ::rtl::OUString& rName, const SfxItemPropertySimpleEntry* pProperty, const ::com::sun::star::uno::Any& rValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
604 : {
605 0 : if( (pProperty->nWID >= OWN_ATTR_APPLET_DOCBASE) && (pProperty->nWID <= OWN_ATTR_APPLET_ISSCRIPT) )
606 : {
607 0 : if ( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef() ) )
608 : {
609 0 : uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef()->getComponent(), uno::UNO_QUERY );
610 0 : if( xSet.is() )
611 : {
612 : // allow exceptions to pass through
613 0 : xSet->setPropertyValue( rName, rValue );
614 0 : }
615 : }
616 0 : return true;
617 : }
618 : else
619 : {
620 0 : return SvxOle2Shape::setPropertyValueImpl( rName, pProperty, rValue );
621 : }
622 : }
623 :
624 0 : bool SvxAppletShape::getPropertyValueImpl( const ::rtl::OUString& rName, const SfxItemPropertySimpleEntry* pProperty, ::com::sun::star::uno::Any& rValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
625 : {
626 0 : if( (pProperty->nWID >= OWN_ATTR_APPLET_DOCBASE) && (pProperty->nWID <= OWN_ATTR_APPLET_ISSCRIPT) )
627 : {
628 0 : if ( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef() ) )
629 : {
630 0 : uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef()->getComponent(), uno::UNO_QUERY );
631 0 : if( xSet.is() )
632 : {
633 0 : rValue = xSet->getPropertyValue( rName );
634 0 : }
635 : }
636 0 : return true;
637 : }
638 : else
639 : {
640 0 : return SvxOle2Shape::getPropertyValueImpl( rName, pProperty, rValue );
641 : }
642 : }
643 :
644 : ///////////////////////////////////////////////////////////////////////
645 :
646 0 : SvxPluginShape::SvxPluginShape( SdrObject* pObject ) throw()
647 0 : : SvxOle2Shape( pObject, getSvxMapProvider().GetMap(SVXMAP_PLUGIN), getSvxMapProvider().GetPropertySet(SVXMAP_PLUGIN, SdrObject::GetGlobalDrawObjectItemPool()) )
648 : {
649 0 : SetShapeType( rtl::OUString( "com.sun.star.drawing.PluginShape" ) );
650 0 : }
651 :
652 0 : SvxPluginShape::~SvxPluginShape() throw()
653 : {
654 0 : }
655 :
656 0 : void SvxPluginShape::Create( SdrObject* pNewObj, SvxDrawPage* pNewPage )
657 : {
658 0 : SvxShape::Create( pNewObj, pNewPage );
659 0 : const SvGlobalName aPluginClassId( SO3_PLUGIN_CLASSID );
660 0 : createObject(aPluginClassId);
661 0 : SetShapeType( rtl::OUString( "com.sun.star.drawing.PluginShape" ) );
662 0 : }
663 :
664 0 : void SAL_CALL SvxPluginShape::setPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& rValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
665 : {
666 0 : SvxShape::setPropertyValue( aPropertyName, rValue );
667 0 : resetModifiedState();
668 0 : }
669 :
670 0 : void SAL_CALL SvxPluginShape::setPropertyValues( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aPropertyNames, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& rValues ) throw (::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
671 : {
672 0 : SvxShape::setPropertyValues( aPropertyNames, rValues );
673 0 : resetModifiedState();
674 0 : }
675 :
676 0 : bool SvxPluginShape::setPropertyValueImpl( const ::rtl::OUString& rName, const SfxItemPropertySimpleEntry* pProperty, const ::com::sun::star::uno::Any& rValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
677 : {
678 0 : if( (pProperty->nWID >= OWN_ATTR_PLUGIN_MIMETYPE) && (pProperty->nWID <= OWN_ATTR_PLUGIN_COMMANDS) )
679 : {
680 0 : if( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef() ) )
681 : {
682 0 : uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef()->getComponent(), uno::UNO_QUERY );
683 0 : if( xSet.is() )
684 : {
685 : // allow exceptions to pass through
686 0 : xSet->setPropertyValue( rName, rValue );
687 0 : }
688 : }
689 0 : return true;
690 : }
691 : else
692 : {
693 0 : return SvxOle2Shape::setPropertyValueImpl( rName, pProperty, rValue );
694 : }
695 : }
696 :
697 0 : bool SvxPluginShape::getPropertyValueImpl( const ::rtl::OUString& rName, const SfxItemPropertySimpleEntry* pProperty, ::com::sun::star::uno::Any& rValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
698 : {
699 0 : if( (pProperty->nWID >= OWN_ATTR_PLUGIN_MIMETYPE) && (pProperty->nWID <= OWN_ATTR_PLUGIN_COMMANDS) )
700 : {
701 0 : if( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef() ) )
702 : {
703 0 : uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef()->getComponent(), uno::UNO_QUERY );
704 0 : if( xSet.is() )
705 : {
706 0 : rValue <<= xSet->getPropertyValue( rName );
707 0 : }
708 : }
709 0 : return true;
710 : }
711 : else
712 : {
713 0 : return SvxOle2Shape::getPropertyValueImpl( rName, pProperty, rValue );
714 : }
715 : }
716 :
717 : ///////////////////////////////////////////////////////////////////////
718 :
719 0 : SvxFrameShape::SvxFrameShape( SdrObject* pObject ) throw()
720 0 : : SvxOle2Shape( pObject, getSvxMapProvider().GetMap(SVXMAP_FRAME), getSvxMapProvider().GetPropertySet(SVXMAP_FRAME, SdrObject::GetGlobalDrawObjectItemPool()) )
721 : {
722 0 : SetShapeType( rtl::OUString( "com.sun.star.drawing.FrameShape" ) );
723 0 : }
724 :
725 0 : SvxFrameShape::~SvxFrameShape() throw()
726 : {
727 0 : }
728 :
729 0 : void SvxFrameShape::Create( SdrObject* pNewObj, SvxDrawPage* pNewPage ) throw ()
730 : {
731 0 : SvxShape::Create( pNewObj, pNewPage );
732 0 : const SvGlobalName aIFrameClassId( SO3_IFRAME_CLASSID );
733 0 : createObject(aIFrameClassId);
734 0 : SetShapeType( rtl::OUString( "com.sun.star.drawing.FrameShape" ) );
735 0 : }
736 :
737 0 : void SAL_CALL SvxFrameShape::setPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& rValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
738 : {
739 0 : SvxShape::setPropertyValue( aPropertyName, rValue );
740 0 : resetModifiedState();
741 0 : }
742 :
743 0 : void SAL_CALL SvxFrameShape::setPropertyValues( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aPropertyNames, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& rValues ) throw (::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
744 : {
745 0 : SvxShape::setPropertyValues( aPropertyNames, rValues );
746 0 : resetModifiedState();
747 0 : }
748 :
749 0 : bool SvxFrameShape::setPropertyValueImpl( const ::rtl::OUString& rName, const SfxItemPropertySimpleEntry* pProperty, const ::com::sun::star::uno::Any& rValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
750 : {
751 0 : if( (pProperty->nWID >= OWN_ATTR_FRAME_URL) && (pProperty->nWID <= OWN_ATTR_FRAME_MARGIN_HEIGHT) )
752 : {
753 0 : if( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef() ) )
754 : {
755 0 : uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef()->getComponent(), uno::UNO_QUERY );
756 0 : if( xSet.is() )
757 : {
758 : // allow exceptions to pass through
759 0 : xSet->setPropertyValue( rName, rValue );
760 0 : }
761 : }
762 0 : return true;
763 : }
764 : else
765 : {
766 0 : return SvxOle2Shape::setPropertyValueImpl( rName, pProperty, rValue );
767 : }
768 : }
769 :
770 0 : bool SvxFrameShape::getPropertyValueImpl( const ::rtl::OUString& rName, const SfxItemPropertySimpleEntry* pProperty, ::com::sun::star::uno::Any& rValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
771 : {
772 0 : if( (pProperty->nWID >= OWN_ATTR_FRAME_URL) && (pProperty->nWID <= OWN_ATTR_FRAME_MARGIN_HEIGHT) )
773 : {
774 0 : if( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef() ) )
775 : {
776 0 : uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef()->getComponent(), uno::UNO_QUERY );
777 0 : if( xSet.is() )
778 : {
779 0 : rValue <<= xSet->getPropertyValue( rName );
780 0 : }
781 : }
782 0 : return true;
783 : }
784 : else
785 : {
786 0 : return SvxOle2Shape::getPropertyValueImpl( rName, pProperty, rValue );
787 : }
788 : }
789 :
790 : /***********************************************************************
791 : * *
792 : ***********************************************************************/
793 :
794 0 : SvxMediaShape::SvxMediaShape( SdrObject* pObj ) throw()
795 0 : : SvxShape( pObj, getSvxMapProvider().GetMap(SVXMAP_MEDIA), getSvxMapProvider().GetPropertySet(SVXMAP_MEDIA, SdrObject::GetGlobalDrawObjectItemPool()) )
796 : {
797 0 : SetShapeType( rtl::OUString( "com.sun.star.drawing.MediaShape" ) );
798 0 : }
799 :
800 : //----------------------------------------------------------------------
801 0 : SvxMediaShape::~SvxMediaShape() throw()
802 : {
803 0 : }
804 :
805 : //----------------------------------------------------------------------
806 :
807 0 : bool SvxMediaShape::setPropertyValueImpl( const ::rtl::OUString& rName, const SfxItemPropertySimpleEntry* pProperty, const ::com::sun::star::uno::Any& rValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
808 : {
809 0 : if( (pProperty->nWID >= OWN_ATTR_MEDIA_URL) && (pProperty->nWID <= OWN_ATTR_MEDIA_ZOOM) )
810 : {
811 0 : SdrMediaObj* pMedia = static_cast< SdrMediaObj* >( mpObj.get() );
812 0 : ::avmedia::MediaItem aItem;
813 0 : bool bOk = false;
814 :
815 0 : switch( pProperty->nWID )
816 : {
817 : case OWN_ATTR_MEDIA_URL:
818 : {
819 0 : OUString aURL;
820 0 : if( rValue >>= aURL )
821 : {
822 0 : bOk = true;
823 0 : aItem.setURL( aURL, 0 );
824 0 : }
825 : }
826 0 : break;
827 :
828 : case( OWN_ATTR_MEDIA_LOOP ):
829 : {
830 0 : sal_Bool bLoop = sal_Bool();
831 :
832 0 : if( rValue >>= bLoop )
833 : {
834 0 : bOk = true;
835 0 : aItem.setLoop( bLoop );
836 : }
837 : }
838 0 : break;
839 :
840 : case( OWN_ATTR_MEDIA_MUTE ):
841 : {
842 0 : sal_Bool bMute = sal_Bool();
843 :
844 0 : if( rValue >>= bMute )
845 : {
846 0 : bOk = true;
847 0 : aItem.setMute( bMute );
848 : }
849 : }
850 0 : break;
851 :
852 : case( OWN_ATTR_MEDIA_VOLUMEDB ):
853 : {
854 0 : sal_Int16 nVolumeDB = sal_Int16();
855 :
856 0 : if( rValue >>= nVolumeDB )
857 : {
858 0 : bOk = true;
859 0 : aItem.setVolumeDB( nVolumeDB );
860 : }
861 : }
862 0 : break;
863 :
864 : case( OWN_ATTR_MEDIA_ZOOM ):
865 : {
866 : ::com::sun::star::media::ZoomLevel eLevel;
867 :
868 0 : if( rValue >>= eLevel )
869 : {
870 0 : bOk = true;
871 0 : aItem.setZoom( eLevel );
872 : }
873 : }
874 0 : break;
875 :
876 : default:
877 : OSL_FAIL("SvxMediaShape::setPropertyValueImpl(), unknown argument!");
878 : }
879 :
880 0 : if( bOk )
881 : {
882 0 : pMedia->setMediaProperties( aItem );
883 0 : return true;
884 0 : }
885 : }
886 : else
887 : {
888 0 : return SvxShape::setPropertyValueImpl( rName, pProperty, rValue );
889 : }
890 :
891 0 : throw IllegalArgumentException();
892 : }
893 :
894 : //----------------------------------------------------------------------
895 :
896 0 : bool SvxMediaShape::getPropertyValueImpl( const ::rtl::OUString& rName, const SfxItemPropertySimpleEntry* pProperty, ::com::sun::star::uno::Any& rValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
897 : {
898 0 : if ( ((pProperty->nWID >= OWN_ATTR_MEDIA_URL) &&
899 : (pProperty->nWID <= OWN_ATTR_MEDIA_ZOOM))
900 : || (pProperty->nWID == OWN_ATTR_MEDIA_STREAM)
901 : || (pProperty->nWID == OWN_ATTR_MEDIA_TEMPFILEURL))
902 : {
903 0 : SdrMediaObj* pMedia = static_cast< SdrMediaObj* >( mpObj.get() );
904 0 : const ::avmedia::MediaItem aItem( pMedia->getMediaProperties() );
905 :
906 0 : switch( pProperty->nWID )
907 : {
908 : case OWN_ATTR_MEDIA_URL:
909 0 : rValue <<= aItem.getURL();
910 0 : break;
911 :
912 : case( OWN_ATTR_MEDIA_LOOP ):
913 0 : rValue <<= (sal_Bool) aItem.isLoop();
914 0 : break;
915 :
916 : case( OWN_ATTR_MEDIA_MUTE ):
917 0 : rValue <<= (sal_Bool) aItem.isMute();
918 0 : break;
919 :
920 : case( OWN_ATTR_MEDIA_VOLUMEDB ):
921 0 : rValue <<= (sal_Int16) aItem.getVolumeDB();
922 0 : break;
923 :
924 : case( OWN_ATTR_MEDIA_ZOOM ):
925 0 : rValue <<= aItem.getZoom();
926 0 : break;
927 :
928 : case OWN_ATTR_MEDIA_STREAM:
929 0 : rValue <<= pMedia->GetInputStream();
930 0 : break;
931 :
932 : case OWN_ATTR_MEDIA_TEMPFILEURL:
933 0 : rValue <<= aItem.getTempURL();
934 0 : break;
935 :
936 : default:
937 : OSL_FAIL("SvxMediaShape::getPropertyValueImpl(), unknown property!");
938 : }
939 0 : return true;
940 : }
941 : else
942 : {
943 0 : return SvxShape::getPropertyValueImpl( rName, pProperty, rValue );
944 : }
945 : }
946 :
947 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|