Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / svdraw / svdoole2.cxx
blob58c0c5d8ff910da1ce0f353701127f14bcce417a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <svx/svdoole2.hxx>
22 #include <com/sun/star/beans/XPropertySet.hpp>
23 #include <com/sun/star/util/XModifyBroadcaster.hpp>
24 #include <com/sun/star/util/XModifiable.hpp>
25 #include <com/sun/star/embed/EmbedStates.hpp>
26 #include <com/sun/star/embed/EmbedMisc.hpp>
27 #include <com/sun/star/embed/Aspects.hpp>
28 #include <com/sun/star/embed/ObjectSaveVetoException.hpp>
29 #include <com/sun/star/embed/XEmbeddedObject.hpp>
30 #include <com/sun/star/embed/XEmbedPersist2.hpp>
31 #include <com/sun/star/embed/XInplaceClient.hpp>
32 #include <com/sun/star/embed/XInplaceObject.hpp>
33 #include <com/sun/star/embed/XLinkageSupport.hpp>
34 #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
35 #include <com/sun/star/embed/XWindowSupplier.hpp>
36 #include <com/sun/star/document/XEventListener.hpp>
37 #include <com/sun/star/container/XChild.hpp>
38 #include <com/sun/star/document/XStorageBasedDocument.hpp>
39 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
41 #include <cppuhelper/exc_hlp.hxx>
43 #include <toolkit/helper/vclunohelper.hxx>
44 #include <toolkit/helper/convert.hxx>
46 #include <svtools/colorcfg.hxx>
47 #include <svtools/embedhlp.hxx>
49 #include <sfx2/objsh.hxx>
50 #include <sfx2/ipclient.hxx>
51 #include <sfx2/lnkbase.hxx>
52 #include <sfx2/linkmgr.hxx>
53 #include <tools/debug.hxx>
54 #include <tools/globname.hxx>
55 #include <comphelper/diagnose_ex.hxx>
56 #include <comphelper/classids.hxx>
57 #include <comphelper/propertyvalue.hxx>
59 #include <sot/formats.hxx>
60 #include <cppuhelper/implbase.hxx>
62 #include <vcl/svapp.hxx>
64 #include <svx/svdmodel.hxx>
65 #include <svx/dialmgr.hxx>
66 #include <svx/strings.hrc>
67 #include <svx/svdetc.hxx>
68 #include <unomlstr.hxx>
69 #include <sdr/contact/viewcontactofsdrole2obj.hxx>
70 #include <svx/svdograf.hxx>
71 #include <sdr/properties/oleproperties.hxx>
72 #include <svx/unoshape.hxx>
73 #include <svx/xlineit0.hxx>
74 #include <svx/xlnclit.hxx>
75 #include <svx/xbtmpit.hxx>
76 #include <svx/xfillit0.hxx>
77 #include <svx/xflbmtit.hxx>
78 #include <svx/xflbstit.hxx>
79 #include <basegfx/matrix/b2dhommatrix.hxx>
80 #include <basegfx/polygon/b2dpolypolygon.hxx>
81 #include <editeng/outlobj.hxx>
82 #include <svx/svdpage.hxx>
83 #include <rtl/ustrbuf.hxx>
84 #include <rtl/ref.hxx>
85 #include <bitmaps.hlst>
87 using namespace ::com::sun::star;
89 static uno::Reference < beans::XPropertySet > lcl_getFrame_throw(const SdrOle2Obj* _pObject)
91 uno::Reference < beans::XPropertySet > xFrame;
92 if ( _pObject )
94 uno::Reference< frame::XController> xController = _pObject->GetParentXModel()->getCurrentController();
95 if ( xController.is() )
97 xFrame.set( xController->getFrame(),uno::UNO_QUERY_THROW);
99 } // if ( _pObject )
100 return xFrame;
103 namespace {
105 class SdrLightEmbeddedClient_Impl : public ::cppu::WeakImplHelper
106 < embed::XStateChangeListener
107 , document::XEventListener
108 , embed::XInplaceClient
109 , embed::XEmbeddedClient
110 , embed::XWindowSupplier
113 uno::Reference< awt::XWindow > m_xWindow;
114 SdrOle2Obj* mpObj;
116 Fraction m_aScaleWidth;
117 Fraction m_aScaleHeight;
120 public:
121 explicit SdrLightEmbeddedClient_Impl( SdrOle2Obj* pObj );
122 virtual ~SdrLightEmbeddedClient_Impl() override;
124 void SetSizeScale( const Fraction& aScaleWidth, const Fraction& aScaleHeight )
126 m_aScaleWidth = aScaleWidth;
127 m_aScaleHeight = aScaleHeight;
130 const Fraction& GetScaleWidth() const { return m_aScaleWidth; }
131 const Fraction& GetScaleHeight() const { return m_aScaleHeight; }
133 void setWindow(const uno::Reference< awt::XWindow >& _xWindow);
135 void disconnect();
136 private:
138 tools::Rectangle impl_getScaledRect_nothrow() const;
139 // XStateChangeListener
140 virtual void SAL_CALL changingState( const css::lang::EventObject& aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState ) override;
141 virtual void SAL_CALL stateChanged( const css::lang::EventObject& aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState ) override;
142 virtual void SAL_CALL disposing( const css::lang::EventObject& aEvent ) override;
144 // document::XEventListener
145 virtual void SAL_CALL notifyEvent( const document::EventObject& aEvent ) override;
147 // XEmbeddedClient
148 virtual void SAL_CALL saveObject() override;
149 virtual void SAL_CALL visibilityChanged( sal_Bool bVisible ) override;
151 // XComponentSupplier
152 virtual uno::Reference< util::XCloseable > SAL_CALL getComponent() override;
154 // XInplaceClient
155 virtual sal_Bool SAL_CALL canInplaceActivate() override;
156 virtual void SAL_CALL activatingInplace() override;
157 virtual void SAL_CALL activatingUI() override;
158 virtual void SAL_CALL deactivatedInplace() override;
159 virtual void SAL_CALL deactivatedUI() override;
160 virtual uno::Reference< css::frame::XLayoutManager > SAL_CALL getLayoutManager() override;
161 virtual uno::Reference< frame::XDispatchProvider > SAL_CALL getInplaceDispatchProvider() override;
162 virtual awt::Rectangle SAL_CALL getPlacement() override;
163 virtual awt::Rectangle SAL_CALL getClipRectangle() override;
164 virtual void SAL_CALL translateAccelerators( const uno::Sequence< awt::KeyEvent >& aKeys ) override;
165 virtual void SAL_CALL scrollObject( const awt::Size& aOffset ) override;
166 virtual void SAL_CALL changedPlacement( const awt::Rectangle& aPosRect ) override;
168 // XWindowSupplier
169 virtual uno::Reference< awt::XWindow > SAL_CALL getWindow() override;
174 SdrLightEmbeddedClient_Impl::SdrLightEmbeddedClient_Impl( SdrOle2Obj* pObj )
175 : mpObj( pObj )
178 SdrLightEmbeddedClient_Impl::~SdrLightEmbeddedClient_Impl()
180 assert(!mpObj);
182 tools::Rectangle SdrLightEmbeddedClient_Impl::impl_getScaledRect_nothrow() const
184 tools::Rectangle aLogicRect( mpObj->GetLogicRect() );
185 // apply scaling to object area and convert to pixels
186 aLogicRect.SetSize( Size( tools::Long( aLogicRect.GetWidth() * m_aScaleWidth),
187 tools::Long( aLogicRect.GetHeight() * m_aScaleHeight) ) );
188 return aLogicRect;
191 void SAL_CALL SdrLightEmbeddedClient_Impl::changingState( const css::lang::EventObject& /*aEvent*/, ::sal_Int32 /*nOldState*/, ::sal_Int32 /*nNewState*/ )
195 void SAL_CALL SdrLightEmbeddedClient_Impl::stateChanged( const css::lang::EventObject& /*aEvent*/, ::sal_Int32 nOldState, ::sal_Int32 nNewState )
197 SolarMutexGuard aGuard;
199 if ( mpObj && nOldState == embed::EmbedStates::LOADED && nNewState == embed::EmbedStates::RUNNING )
201 mpObj->ObjectLoaded();
202 GetSdrGlobalData().GetOLEObjCache().InsertObj(mpObj);
204 else if ( mpObj && nNewState == embed::EmbedStates::LOADED && nOldState == embed::EmbedStates::RUNNING )
206 GetSdrGlobalData().GetOLEObjCache().RemoveObj(mpObj);
210 void SdrLightEmbeddedClient_Impl::disconnect()
212 SolarMutexGuard aGuard;
213 if (!mpObj)
214 return;
215 GetSdrGlobalData().GetOLEObjCache().RemoveObj(mpObj);
216 mpObj = nullptr;
219 void SAL_CALL SdrLightEmbeddedClient_Impl::disposing( const css::lang::EventObject& /*aEvent*/ )
221 disconnect();
224 void SAL_CALL SdrLightEmbeddedClient_Impl::notifyEvent( const document::EventObject& aEvent )
226 // TODO/LATER: when writer uses this implementation the code could be shared with SfxInPlaceClient_Impl
228 SolarMutexGuard aGuard;
230 // the code currently makes sense only in case there is no other client
231 if ( !(mpObj && mpObj->GetAspect() != embed::Aspects::MSOLE_ICON && aEvent.EventName == "OnVisAreaChanged"
232 && mpObj->GetObjRef().is() && mpObj->GetObjRef()->getClientSite() == uno::Reference< embed::XEmbeddedClient >( this )) )
233 return;
237 MapUnit aContainerMapUnit( MapUnit::Map100thMM );
238 uno::Reference< embed::XVisualObject > xParentVis( mpObj->GetParentXModel(), uno::UNO_QUERY );
239 if ( xParentVis.is() )
240 aContainerMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xParentVis->getMapUnit( mpObj->GetAspect() ) );
242 MapUnit aObjMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( mpObj->GetObjRef()->getMapUnit( mpObj->GetAspect() ) );
244 tools::Rectangle aVisArea;
245 awt::Size aSz;
248 aSz = mpObj->GetObjRef()->getVisualAreaSize( mpObj->GetAspect() );
250 catch( embed::NoVisualAreaSizeException& )
252 TOOLS_WARN_EXCEPTION("svx.svdraw", "No visual area size!");
253 aSz.Width = 5000;
254 aSz.Height = 5000;
256 catch( uno::Exception& )
258 TOOLS_WARN_EXCEPTION("svx.svdraw", "");
259 aSz.Width = 5000;
260 aSz.Height = 5000;
263 aVisArea.SetSize( Size( aSz.Width, aSz.Height ) );
264 aVisArea = OutputDevice::LogicToLogic(aVisArea, MapMode(aObjMapUnit), MapMode(aContainerMapUnit));
265 Size aScaledSize( static_cast< tools::Long >( m_aScaleWidth * Fraction( aVisArea.GetWidth() ) ),
266 static_cast< tools::Long >( m_aScaleHeight * Fraction( aVisArea.GetHeight() ) ) );
267 tools::Rectangle aLogicRect( mpObj->GetLogicRect() );
269 // react to the change if the difference is bigger than one pixel
270 Size aPixelDiff =
271 Application::GetDefaultDevice()->LogicToPixel(
272 Size( aLogicRect.GetWidth() - aScaledSize.Width(),
273 aLogicRect.GetHeight() - aScaledSize.Height() ),
274 MapMode(aContainerMapUnit));
275 if( aPixelDiff.Width() || aPixelDiff.Height() )
277 mpObj->SetLogicRect( tools::Rectangle( aLogicRect.TopLeft(), aScaledSize ) );
278 mpObj->BroadcastObjectChange();
280 else
281 mpObj->ActionChanged();
283 catch( uno::Exception& )
285 TOOLS_WARN_EXCEPTION("svx.svdraw", "");
289 void SAL_CALL SdrLightEmbeddedClient_Impl::saveObject()
291 // TODO/LATER: when writer uses this implementation the code could be shared with SfxInPlaceClient_Impl
292 uno::Reference< embed::XCommonEmbedPersist > xPersist;
293 uno::Reference< util::XModifiable > xModifiable;
296 SolarMutexGuard aGuard;
298 if ( !mpObj )
299 throw embed::ObjectSaveVetoException();
301 // the common persistence is supported by objects and links
302 xPersist.set( mpObj->GetObjRef(), uno::UNO_QUERY_THROW );
303 xModifiable.set( mpObj->GetParentXModel(), uno::UNO_QUERY );
306 xPersist->storeOwn();
308 if ( xModifiable.is() )
309 xModifiable->setModified( true );
312 void SAL_CALL SdrLightEmbeddedClient_Impl::visibilityChanged( sal_Bool /*bVisible*/ )
314 // nothing to do currently
315 // TODO/LATER: when writer uses this implementation the code could be shared with SfxInPlaceClient_Impl
316 if ( mpObj )
318 tools::Rectangle aLogicRect( mpObj->GetLogicRect() );
319 Size aLogicSize( aLogicRect.GetWidth(), aLogicRect.GetHeight() );
321 if( mpObj->IsChart() )
323 //charts never should be stretched see #i84323# for example
324 mpObj->SetLogicRect( tools::Rectangle( aLogicRect.TopLeft(), aLogicSize ) );
325 mpObj->BroadcastObjectChange();
326 } // if( mpObj->IsChart() )
330 uno::Reference< util::XCloseable > SAL_CALL SdrLightEmbeddedClient_Impl::getComponent()
332 uno::Reference< util::XCloseable > xResult;
334 SolarMutexGuard aGuard;
335 if ( mpObj )
336 xResult.set( mpObj->GetParentXModel(), uno::UNO_QUERY );
338 return xResult;
340 // XInplaceClient
342 sal_Bool SAL_CALL SdrLightEmbeddedClient_Impl::canInplaceActivate()
344 bool bRet = false;
345 SolarMutexGuard aGuard;
346 if ( mpObj )
348 uno::Reference< embed::XEmbeddedObject > xObject = mpObj->GetObjRef();
349 if ( !xObject.is() )
350 throw uno::RuntimeException();
351 // we don't want to switch directly from outplace to inplace mode
352 bRet = ( xObject->getCurrentState() != embed::EmbedStates::ACTIVE && mpObj->GetAspect() != embed::Aspects::MSOLE_ICON );
353 } // if ( mpObj )
354 return bRet;
357 void SAL_CALL SdrLightEmbeddedClient_Impl::activatingInplace()
361 void SAL_CALL SdrLightEmbeddedClient_Impl::activatingUI()
363 SolarMutexGuard aGuard;
365 uno::Reference < beans::XPropertySet > xFrame( lcl_getFrame_throw(mpObj));
366 uno::Reference < frame::XFrame > xOwnFrame( xFrame,uno::UNO_QUERY);
367 uno::Reference < frame::XFramesSupplier > xParentFrame = xOwnFrame->getCreator();
368 if ( xParentFrame.is() )
369 xParentFrame->setActiveFrame( xOwnFrame );
371 OLEObjCache& rObjCache = GetSdrGlobalData().GetOLEObjCache();
372 const size_t nCount = rObjCache.size();
373 for(sal_Int32 i = nCount-1 ; i >= 0;--i)
375 SdrOle2Obj* pObj = rObjCache[i];
376 if ( pObj != mpObj )
378 // only deactivate ole objects which belongs to the same frame
379 if ( xFrame == lcl_getFrame_throw(pObj) )
381 const uno::Reference< embed::XEmbeddedObject >& xObject = pObj->GetObjRef();
384 if ( xObject->getStatus( pObj->GetAspect() ) & embed::EmbedMisc::MS_EMBED_ACTIVATEWHENVISIBLE )
385 xObject->changeState( embed::EmbedStates::INPLACE_ACTIVE );
386 else
388 // the links should not stay in running state for long time because of locking
389 uno::Reference< embed::XLinkageSupport > xLink( xObject, uno::UNO_QUERY );
390 if ( xLink.is() && xLink->isLink() )
391 xObject->changeState( embed::EmbedStates::LOADED );
392 else
393 xObject->changeState( embed::EmbedStates::RUNNING );
396 catch (css::uno::Exception& )
400 } // for(sal_Int32 i = nCount-1 ; i >= 0;--i)
403 void SAL_CALL SdrLightEmbeddedClient_Impl::deactivatedInplace()
407 void SAL_CALL SdrLightEmbeddedClient_Impl::deactivatedUI()
409 SolarMutexGuard aGuard;
410 css::uno::Reference< css::frame::XLayoutManager > xLayoutManager(getLayoutManager());
411 if ( xLayoutManager.is() )
413 static constexpr OUStringLiteral aMenuBarURL = u"private:resource/menubar/menubar";
414 if ( !xLayoutManager->isElementVisible( aMenuBarURL ) )
415 xLayoutManager->createElement( aMenuBarURL );
419 uno::Reference< css::frame::XLayoutManager > SAL_CALL SdrLightEmbeddedClient_Impl::getLayoutManager()
421 uno::Reference< css::frame::XLayoutManager > xMan;
422 SolarMutexGuard aGuard;
423 uno::Reference < beans::XPropertySet > xFrame( lcl_getFrame_throw(mpObj));
426 xMan.set(xFrame->getPropertyValue("LayoutManager"),uno::UNO_QUERY);
428 catch ( uno::Exception& ex )
430 css::uno::Any anyEx = cppu::getCaughtException();
431 throw css::lang::WrappedTargetRuntimeException( ex.Message,
432 nullptr, anyEx );
435 return xMan;
438 uno::Reference< frame::XDispatchProvider > SAL_CALL SdrLightEmbeddedClient_Impl::getInplaceDispatchProvider()
440 SolarMutexGuard aGuard;
441 return uno::Reference < frame::XDispatchProvider >( lcl_getFrame_throw(mpObj), uno::UNO_QUERY_THROW );
444 awt::Rectangle SAL_CALL SdrLightEmbeddedClient_Impl::getPlacement()
446 SolarMutexGuard aGuard;
447 if ( !mpObj )
448 throw uno::RuntimeException();
450 tools::Rectangle aLogicRect = impl_getScaledRect_nothrow();
451 MapUnit aContainerMapUnit( MapUnit::Map100thMM );
452 uno::Reference< embed::XVisualObject > xParentVis( mpObj->GetParentXModel(), uno::UNO_QUERY );
453 if ( xParentVis.is() )
454 aContainerMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xParentVis->getMapUnit( mpObj->GetAspect() ) );
456 aLogicRect = Application::GetDefaultDevice()->LogicToPixel(aLogicRect, MapMode(aContainerMapUnit));
457 return AWTRectangle( aLogicRect );
460 awt::Rectangle SAL_CALL SdrLightEmbeddedClient_Impl::getClipRectangle()
462 return getPlacement();
465 void SAL_CALL SdrLightEmbeddedClient_Impl::translateAccelerators( const uno::Sequence< awt::KeyEvent >& /*aKeys*/ )
469 void SAL_CALL SdrLightEmbeddedClient_Impl::scrollObject( const awt::Size& /*aOffset*/ )
473 void SAL_CALL SdrLightEmbeddedClient_Impl::changedPlacement( const awt::Rectangle& aPosRect )
475 SolarMutexGuard aGuard;
476 if ( !mpObj )
477 throw uno::RuntimeException();
479 uno::Reference< embed::XInplaceObject > xInplace( mpObj->GetObjRef(), uno::UNO_QUERY_THROW );
481 // check if the change is at least one pixel in size
482 awt::Rectangle aOldRect = getPlacement();
483 tools::Rectangle aNewPixelRect = VCLRectangle( aPosRect );
484 tools::Rectangle aOldPixelRect = VCLRectangle( aOldRect );
485 if ( aOldPixelRect == aNewPixelRect )
486 // nothing has changed
487 return;
489 // new scaled object area
490 MapUnit aContainerMapUnit( MapUnit::Map100thMM );
491 uno::Reference< embed::XVisualObject > xParentVis( mpObj->GetParentXModel(), uno::UNO_QUERY );
492 if ( xParentVis.is() )
493 aContainerMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xParentVis->getMapUnit( mpObj->GetAspect() ) );
495 tools::Rectangle aNewLogicRect = Application::GetDefaultDevice()->PixelToLogic(aNewPixelRect, MapMode(aContainerMapUnit));
496 tools::Rectangle aLogicRect = impl_getScaledRect_nothrow();
498 if ( aNewLogicRect == aLogicRect )
499 return;
501 // the calculation of the object area has not changed the object size
502 // it should be done here then
503 //SfxBooleanFlagGuard aGuard( m_bResizeNoScale, true );
505 // new size of the object area without scaling
506 Size aNewObjSize( tools::Long( aNewLogicRect.GetWidth() / m_aScaleWidth ),
507 tools::Long( aNewLogicRect.GetHeight() / m_aScaleHeight ) );
509 // now remove scaling from new placement and keep this at the new object area
510 aNewLogicRect.SetSize( aNewObjSize );
511 // react to the change if the difference is bigger than one pixel
512 Size aPixelDiff =
513 Application::GetDefaultDevice()->LogicToPixel(
514 Size( aLogicRect.GetWidth() - aNewObjSize.Width(),
515 aLogicRect.GetHeight() - aNewObjSize.Height() ),
516 MapMode(aContainerMapUnit));
517 if( aPixelDiff.Width() || aPixelDiff.Height() )
519 mpObj->SetLogicRect( tools::Rectangle( aLogicRect.TopLeft(), aNewObjSize ) );
520 mpObj->BroadcastObjectChange();
522 else
523 mpObj->ActionChanged();
525 // XWindowSupplier
527 uno::Reference< awt::XWindow > SAL_CALL SdrLightEmbeddedClient_Impl::getWindow()
529 SolarMutexGuard aGuard;
530 uno::Reference< awt::XWindow > xCurrent = m_xWindow;
531 if ( !xCurrent.is() )
533 if ( !mpObj )
534 throw uno::RuntimeException();
535 uno::Reference< frame::XFrame> xFrame(lcl_getFrame_throw(mpObj),uno::UNO_QUERY_THROW);
536 xCurrent = xFrame->getComponentWindow();
537 } // if ( !xCurrent.is() )
538 return xCurrent;
540 void SdrLightEmbeddedClient_Impl::setWindow(const uno::Reference< awt::XWindow >& _xWindow)
542 m_xWindow = _xWindow;
545 SdrEmbedObjectLink::SdrEmbedObjectLink(SdrOle2Obj* pObject):
546 ::sfx2::SvBaseLink( ::SfxLinkUpdateMode::ONCALL, SotClipboardFormatId::SVXB ),
547 pObj(pObject)
549 SetSynchron( false );
552 SdrEmbedObjectLink::~SdrEmbedObjectLink()
556 ::sfx2::SvBaseLink::UpdateResult SdrEmbedObjectLink::DataChanged(
557 const OUString& /*rMimeType*/, const css::uno::Any & /*rValue*/ )
559 if ( !pObj->UpdateLinkURL_Impl() )
561 // the link URL was not changed
562 uno::Reference< embed::XEmbeddedObject > xObject = pObj->GetObjRef();
563 OSL_ENSURE( xObject.is(), "The object must exist always!" );
564 if ( xObject.is() )
566 // let the object reload the link
567 // TODO/LATER: reload call could be used for this case
571 sal_Int32 nState = xObject->getCurrentState();
572 if ( nState != embed::EmbedStates::LOADED )
574 // in some cases the linked file probably is not locked so it could be changed
575 xObject->changeState( embed::EmbedStates::LOADED );
576 xObject->changeState( nState );
579 catch ( uno::Exception& )
585 pObj->GetNewReplacement();
586 pObj->SetChanged();
588 return SUCCESS;
591 void SdrEmbedObjectLink::Closed()
593 pObj->BreakFileLink_Impl();
594 SvBaseLink::Closed();
597 SdrIFrameLink::SdrIFrameLink(SdrOle2Obj* pObject)
598 : ::sfx2::SvBaseLink(::SfxLinkUpdateMode::ONCALL, SotClipboardFormatId::SVXB)
599 , m_pObject(pObject)
601 SetSynchron( false );
604 ::sfx2::SvBaseLink::UpdateResult SdrIFrameLink::DataChanged(
605 const OUString&, const uno::Any& )
607 uno::Reference<embed::XEmbeddedObject> xObject = m_pObject->GetObjRef();
608 uno::Reference<embed::XCommonEmbedPersist> xPersObj(xObject, uno::UNO_QUERY);
609 if (xPersObj.is())
611 // let the IFrameObject reload the link
614 xPersObj->reload(uno::Sequence<beans::PropertyValue>(), uno::Sequence<beans::PropertyValue>());
616 catch (const uno::Exception&)
620 m_pObject->SetChanged();
623 return SUCCESS;
626 class SdrOle2ObjImpl
628 public:
629 svt::EmbeddedObjectRef mxObjRef;
631 std::optional<Graphic> moGraphic;
632 OUString maProgName;
633 OUString aPersistName; // name of object in persist
634 rtl::Reference<SdrLightEmbeddedClient_Impl> mxLightClient; // must be registered as client only using AddOwnLightClient() call
636 bool mbFrame:1; // Due to compatibility at SdrTextObj for now
637 bool mbSuppressSetVisAreaSize:1; // #i118524#
638 mutable bool mbTypeAsked:1;
639 mutable bool mbIsChart:1;
640 bool mbLoadingOLEObjectFailed:1; // New local var to avoid repeated loading if load of OLE2 fails
641 bool mbConnected:1;
643 sfx2::SvBaseLink* mpObjectLink;
644 OUString maLinkURL;
646 rtl::Reference<SvxUnoShapeModifyListener> mxModifyListener;
648 explicit SdrOle2ObjImpl( bool bFrame ) :
649 mbFrame(bFrame),
650 mbSuppressSetVisAreaSize(false),
651 mbTypeAsked(false),
652 mbIsChart(false),
653 mbLoadingOLEObjectFailed(false),
654 mbConnected(false),
655 mpObjectLink(nullptr)
657 mxObjRef.Lock();
660 SdrOle2ObjImpl( bool bFrame, const svt::EmbeddedObjectRef& rObjRef ) :
661 mxObjRef(rObjRef),
662 mbFrame(bFrame),
663 mbSuppressSetVisAreaSize(false),
664 mbTypeAsked(false),
665 mbIsChart(false),
666 mbLoadingOLEObjectFailed(false),
667 mbConnected(false),
668 mpObjectLink(nullptr)
670 mxObjRef.Lock();
673 ~SdrOle2ObjImpl()
675 moGraphic.reset();
677 if (mxModifyListener.is())
679 mxModifyListener->invalidate();
684 // Predicate determining whether the given OLE is an internal math
685 // object
686 static bool ImplIsMathObj( const uno::Reference < embed::XEmbeddedObject >& rObjRef )
688 if ( !rObjRef.is() )
689 return false;
691 SvGlobalName aClassName( rObjRef->getClassID() );
692 return aClassName == SvGlobalName(SO3_SM_CLASSID_30) ||
693 aClassName == SvGlobalName(SO3_SM_CLASSID_40) ||
694 aClassName == SvGlobalName(SO3_SM_CLASSID_50) ||
695 aClassName == SvGlobalName(SO3_SM_CLASSID_60) ||
696 aClassName == SvGlobalName(SO3_SM_CLASSID);
699 // BaseProperties section
701 std::unique_ptr<sdr::properties::BaseProperties> SdrOle2Obj::CreateObjectSpecificProperties()
703 return std::make_unique<sdr::properties::OleProperties>(*this);
706 // DrawContact section
708 std::unique_ptr<sdr::contact::ViewContact> SdrOle2Obj::CreateObjectSpecificViewContact()
710 return std::make_unique<sdr::contact::ViewContactOfSdrOle2Obj>(*this);
713 void SdrOle2Obj::Init()
715 // Stuff that was done from old SetModel:
716 // #i43086# #i85304 redo the change for charts for the above bugfix, as #i43086# does not occur anymore
717 // so maybe the ImpSetVisAreaSize call can be removed here completely
718 // Nevertheless I leave it in for other objects as I am not sure about the side effects when removing now
719 if(!getSdrModelFromSdrObject().isLocked() && !IsChart())
721 ImpSetVisAreaSize();
724 ::comphelper::IEmbeddedHelper* pDestPers(getSdrModelFromSdrObject().GetPersist());
725 if(pDestPers && !IsEmptyPresObj())
727 // object wasn't connected, now it should be
728 Connect_Impl();
731 AddListeners_Impl();
734 SdrOle2Obj::SdrOle2Obj(
735 SdrModel& rSdrModel,
736 bool bFrame_)
737 : SdrRectObj(rSdrModel),
738 mpImpl(new SdrOle2ObjImpl(bFrame_))
740 Init();
743 SdrOle2Obj::SdrOle2Obj(SdrModel& rSdrModel, SdrOle2Obj const & rSource)
744 : SdrRectObj(rSdrModel, rSource),
745 mpImpl(new SdrOle2ObjImpl(/*bFrame*/false))
747 Init();
749 // Manually copying bClosedObj attribute
750 SetClosedObj( rSource.IsClosedObj() );
752 mpImpl->aPersistName = rSource.mpImpl->aPersistName;
753 mpImpl->maProgName = rSource.mpImpl->maProgName;
754 mpImpl->mbFrame = rSource.mpImpl->mbFrame;
756 if (rSource.mpImpl->moGraphic)
758 mpImpl->moGraphic.emplace(*rSource.mpImpl->moGraphic);
761 if( IsEmptyPresObj() )
762 return;
764 ::comphelper::IEmbeddedHelper* pDestPers(getSdrModelFromSdrObject().GetPersist());
765 ::comphelper::IEmbeddedHelper* pSrcPers(rSource.getSdrModelFromSdrObject().GetPersist());
766 if( !(pDestPers && pSrcPers) )
767 return;
769 DBG_ASSERT( !mpImpl->mxObjRef.is(), "Object already existing!" );
770 comphelper::EmbeddedObjectContainer& rContainer = pSrcPers->getEmbeddedObjectContainer();
771 uno::Reference < embed::XEmbeddedObject > xObj = rContainer.GetEmbeddedObject( mpImpl->aPersistName );
772 if ( xObj.is() )
774 OUString aTmp;
775 mpImpl->mxObjRef.Assign( pDestPers->getEmbeddedObjectContainer().CopyAndGetEmbeddedObject(
776 rContainer, xObj, aTmp, pSrcPers->getDocumentBaseURL(), pDestPers->getDocumentBaseURL()), rSource.GetAspect());
777 mpImpl->mbTypeAsked = false;
778 mpImpl->aPersistName = aTmp;
779 CheckFileLink_Impl();
782 Connect();
785 SdrOle2Obj::SdrOle2Obj(
786 SdrModel& rSdrModel,
787 const svt::EmbeddedObjectRef& rNewObjRef,
788 const OUString& rNewObjName,
789 const tools::Rectangle& rNewRect)
790 : SdrRectObj(rSdrModel, rNewRect),
791 mpImpl(new SdrOle2ObjImpl(false/*bFrame_*/, rNewObjRef))
793 osl_atomic_increment(&m_refCount);
795 mpImpl->aPersistName = rNewObjName;
797 if (mpImpl->mxObjRef.is() && (mpImpl->mxObjRef->getStatus( GetAspect() ) & embed::EmbedMisc::EMBED_NEVERRESIZE ) )
798 m_bSizProt = true;
800 // For math objects, set closed state to transparent
801 SetClosedObj(!ImplIsMathObj( mpImpl->mxObjRef.GetObject() ));
803 Init();
805 osl_atomic_decrement(&m_refCount);
808 OUString SdrOle2Obj::GetStyleString()
810 OUString strStyle;
811 if (mpImpl->mxObjRef.is() && mpImpl->mxObjRef.IsChart())
813 strStyle = mpImpl->mxObjRef.GetChartType();
815 return strStyle;
818 SdrOle2Obj::~SdrOle2Obj()
820 if ( mpImpl->mbConnected )
821 Disconnect();
823 DisconnectFileLink_Impl();
825 if (mpImpl->mxLightClient)
827 mpImpl->mxLightClient->disconnect();
828 mpImpl->mxLightClient.clear();
832 void SdrOle2Obj::SetAspect( sal_Int64 nAspect )
834 mpImpl->mxObjRef.SetViewAspect( nAspect );
837 const svt::EmbeddedObjectRef& SdrOle2Obj::getEmbeddedObjectRef() const
839 return mpImpl->mxObjRef;
842 sal_Int64 SdrOle2Obj::GetAspect() const
844 return mpImpl->mxObjRef.GetViewAspect();
847 bool SdrOle2Obj::isInplaceActive() const
849 return mpImpl->mxObjRef.is() && embed::EmbedStates::INPLACE_ACTIVE == mpImpl->mxObjRef->getCurrentState();
852 bool SdrOle2Obj::isUiActive() const
854 return mpImpl->mxObjRef.is() && embed::EmbedStates::UI_ACTIVE == mpImpl->mxObjRef->getCurrentState();
857 void SdrOle2Obj::SetGraphic(const Graphic& rGrf)
859 // only for setting a preview graphic
860 mpImpl->moGraphic.emplace(rGrf);
862 SetChanged();
863 BroadcastObjectChange();
866 void SdrOle2Obj::ClearGraphic()
868 mpImpl->moGraphic.reset();
870 SetChanged();
871 BroadcastObjectChange();
874 void SdrOle2Obj::SetProgName( const OUString& rName )
876 mpImpl->maProgName = rName;
879 const OUString& SdrOle2Obj::GetProgName() const
881 return mpImpl->maProgName;
884 bool SdrOle2Obj::IsEmpty() const
886 return !mpImpl->mxObjRef.is();
889 void SdrOle2Obj::Connect(SvxOle2Shape* pCreator)
891 if( IsEmptyPresObj() )
892 return;
894 if( mpImpl->mbConnected )
896 // currently there are situations where it seems to be unavoidable to have multiple connects
897 // changing this would need a larger code rewrite, so for now I remove the assertion
898 // OSL_FAIL("Connect() called on connected object!");
899 return;
902 Connect_Impl(pCreator);
903 AddListeners_Impl();
906 bool SdrOle2Obj::UpdateLinkURL_Impl()
908 bool bResult = false;
910 if ( mpImpl->mpObjectLink )
912 sfx2::LinkManager* pLinkManager(getSdrModelFromSdrObject().GetLinkManager());
914 if ( pLinkManager )
916 OUString aNewLinkURL;
917 sfx2::LinkManager::GetDisplayNames( mpImpl->mpObjectLink, nullptr, &aNewLinkURL );
918 if ( !aNewLinkURL.equalsIgnoreAsciiCase( mpImpl->maLinkURL ) )
920 GetObjRef_Impl();
921 uno::Reference<embed::XCommonEmbedPersist> xPersObj( mpImpl->mxObjRef.GetObject(), uno::UNO_QUERY );
922 OSL_ENSURE( xPersObj.is(), "The object must exist!" );
923 if ( xPersObj.is() )
927 sal_Int32 nCurState = mpImpl->mxObjRef->getCurrentState();
928 if ( nCurState != embed::EmbedStates::LOADED )
929 mpImpl->mxObjRef->changeState(embed::EmbedStates::LOADED);
931 // TODO/LATER: there should be possible to get current mediadescriptor settings from the object
932 uno::Sequence< beans::PropertyValue > aArgs{ comphelper::makePropertyValue(
933 "URL", aNewLinkURL) };
934 xPersObj->reload( aArgs, uno::Sequence< beans::PropertyValue >() );
936 mpImpl->maLinkURL = aNewLinkURL;
937 bResult = true;
939 if ( nCurState != embed::EmbedStates::LOADED )
940 mpImpl->mxObjRef->changeState(nCurState);
942 catch( css::uno::Exception const & )
944 TOOLS_WARN_EXCEPTION( "svx", "SdrOle2Obj::UpdateLinkURL_Impl()" );
948 if ( !bResult )
950 // TODO/LATER: return the old name to the link manager, is it possible?
956 return bResult;
959 void SdrOle2Obj::BreakFileLink_Impl()
961 uno::Reference<document::XStorageBasedDocument> xDoc(getSdrModelFromSdrObject().getUnoModel(), uno::UNO_QUERY);
963 if ( !xDoc.is() )
964 return;
966 uno::Reference< embed::XStorage > xStorage = xDoc->getDocumentStorage();
967 if ( !xStorage.is() )
968 return;
972 uno::Reference< embed::XLinkageSupport > xLinkSupport( mpImpl->mxObjRef.GetObject(), uno::UNO_QUERY_THROW );
973 xLinkSupport->breakLink( xStorage, mpImpl->aPersistName );
974 DisconnectFileLink_Impl();
975 mpImpl->maLinkURL.clear();
977 catch( css::uno::Exception& )
979 TOOLS_WARN_EXCEPTION( "svx", "SdrOle2Obj::BreakFileLink_Impl()" );
983 void SdrOle2Obj::DisconnectFileLink_Impl()
985 sfx2::LinkManager* pLinkManager(getSdrModelFromSdrObject().GetLinkManager());
987 if ( pLinkManager && mpImpl->mpObjectLink )
989 pLinkManager->Remove( mpImpl->mpObjectLink );
990 mpImpl->mpObjectLink = nullptr;
994 void SdrOle2Obj::CheckFileLink_Impl()
996 if (!mpImpl->mxObjRef.GetObject().is() || mpImpl->mpObjectLink)
997 return;
1001 uno::Reference<embed::XEmbeddedObject> xObject = mpImpl->mxObjRef.GetObject();
1002 if (!xObject)
1003 return;
1005 bool bIFrame = false;
1007 OUString aLinkURL;
1008 uno::Reference<embed::XLinkageSupport> xLinkSupport(xObject, uno::UNO_QUERY);
1009 if (xLinkSupport)
1011 if (xLinkSupport->isLink())
1012 aLinkURL = xLinkSupport->getLinkURL();
1014 else
1016 // get IFrame (Floating Frames) listed and updatable from the
1017 // manage links dialog
1018 SvGlobalName aClassId(xObject->getClassID());
1019 if (aClassId == SvGlobalName(SO3_IFRAME_CLASSID))
1021 uno::Reference<beans::XPropertySet> xSet(xObject->getComponent(), uno::UNO_QUERY);
1022 if (xSet.is())
1023 xSet->getPropertyValue("FrameURL") >>= aLinkURL;
1024 bIFrame = true;
1028 if (!aLinkURL.isEmpty()) // this is a file link so the model link manager should handle it
1030 sfx2::LinkManager* pLinkManager(getSdrModelFromSdrObject().GetLinkManager());
1032 if ( pLinkManager )
1034 SdrEmbedObjectLink* pEmbedObjectLink = nullptr;
1035 if (!bIFrame)
1037 pEmbedObjectLink = new SdrEmbedObjectLink(this);
1038 mpImpl->mpObjectLink = pEmbedObjectLink;
1040 else
1041 mpImpl->mpObjectLink = new SdrIFrameLink(this);
1042 mpImpl->maLinkURL = aLinkURL;
1043 pLinkManager->InsertFileLink( *mpImpl->mpObjectLink, sfx2::SvBaseLinkObjectType::ClientOle, aLinkURL );
1044 if (pEmbedObjectLink)
1045 pEmbedObjectLink->Connect();
1049 catch (const css::uno::Exception&)
1051 TOOLS_WARN_EXCEPTION("svx", "SdrOle2Obj::CheckFileLink_Impl()");
1055 void SdrOle2Obj::Connect_Impl(SvxOle2Shape* pCreator)
1057 if(mpImpl->aPersistName.isEmpty() )
1058 return;
1062 ::comphelper::IEmbeddedHelper* pPers(getSdrModelFromSdrObject().GetPersist());
1064 if ( pPers )
1066 comphelper::EmbeddedObjectContainer& rContainer = pPers->getEmbeddedObjectContainer();
1068 if ( !rContainer.HasEmbeddedObject( mpImpl->aPersistName )
1069 || ( mpImpl->mxObjRef.is() && !rContainer.HasEmbeddedObject( mpImpl->mxObjRef.GetObject() ) ) )
1071 // object not known to container document
1072 // No object -> disaster!
1073 DBG_ASSERT( mpImpl->mxObjRef.is(), "No object in connect!");
1074 if ( mpImpl->mxObjRef.is() )
1076 // object came from the outside, now add it to the container
1077 OUString aTmp;
1078 rContainer.InsertEmbeddedObject( mpImpl->mxObjRef.GetObject(), aTmp );
1079 mpImpl->aPersistName = aTmp;
1082 else if ( !mpImpl->mxObjRef.is() )
1084 mpImpl->mxObjRef.Assign( rContainer.GetEmbeddedObject( mpImpl->aPersistName ), mpImpl->mxObjRef.GetViewAspect() );
1085 mpImpl->mbTypeAsked = false;
1088 if ( mpImpl->mxObjRef.GetObject().is() )
1090 mpImpl->mxObjRef.AssignToContainer( &rContainer, mpImpl->aPersistName );
1091 mpImpl->mbConnected = true;
1092 mpImpl->mxObjRef.Lock();
1096 if (pCreator)
1098 OUString sFrameURL(pCreator->GetAndClearInitialFrameURL());
1099 if (!sFrameURL.isEmpty() && svt::EmbeddedObjectRef::TryRunningState(mpImpl->mxObjRef.GetObject()))
1101 uno::Reference<beans::XPropertySet> xSet(mpImpl->mxObjRef->getComponent(), uno::UNO_QUERY);
1102 if (xSet.is())
1103 xSet->setPropertyValue("FrameURL", uno::Any(sFrameURL));
1107 if ( mpImpl->mxObjRef.is() )
1109 if ( !mpImpl->mxLightClient.is() )
1110 mpImpl->mxLightClient = new SdrLightEmbeddedClient_Impl( this );
1112 mpImpl->mxObjRef->addStateChangeListener( mpImpl->mxLightClient );
1113 mpImpl->mxObjRef->addEventListener( mpImpl->mxLightClient );
1115 if ( mpImpl->mxObjRef->getCurrentState() != embed::EmbedStates::LOADED )
1116 GetSdrGlobalData().GetOLEObjCache().InsertObj(this);
1118 CheckFileLink_Impl();
1120 uno::Reference< container::XChild > xChild( mpImpl->mxObjRef.GetObject(), uno::UNO_QUERY );
1121 if( xChild.is() )
1123 uno::Reference< uno::XInterface > xParent( getSdrModelFromSdrObject().getUnoModel());
1124 if( xParent.is())
1125 xChild->setParent( getSdrModelFromSdrObject().getUnoModel() );
1130 catch( css::uno::Exception& )
1132 TOOLS_WARN_EXCEPTION( "svx", "SdrOle2Obj::Connect_Impl()" );
1136 void SdrOle2Obj::ObjectLoaded()
1138 AddListeners_Impl();
1141 void SdrOle2Obj::AddListeners_Impl()
1143 if( !(mpImpl->mxObjRef.is() && mpImpl->mxObjRef->getCurrentState() != embed::EmbedStates::LOADED) )
1144 return;
1146 // register modify listener
1147 if (!mpImpl->mxModifyListener.is())
1149 mpImpl->mxModifyListener = new SvxUnoShapeModifyListener(this);
1152 uno::Reference< util::XModifyBroadcaster > xBC( getXModel(), uno::UNO_QUERY );
1153 if (xBC.is())
1155 xBC->addModifyListener( mpImpl->mxModifyListener );
1159 void SdrOle2Obj::Disconnect()
1161 if( IsEmptyPresObj() )
1162 return;
1164 if( !mpImpl->mbConnected )
1166 OSL_FAIL("Disconnect() called on disconnected object!");
1167 return;
1170 RemoveListeners_Impl();
1171 Disconnect_Impl();
1174 void SdrOle2Obj::RemoveListeners_Impl()
1176 if ( !mpImpl->mxObjRef.is() || mpImpl->aPersistName.isEmpty() )
1177 return;
1181 sal_Int32 nState = mpImpl->mxObjRef->getCurrentState();
1182 if ( nState != embed::EmbedStates::LOADED )
1184 uno::Reference< util::XModifyBroadcaster > xBC( getXModel(), uno::UNO_QUERY );
1185 if (xBC.is() && mpImpl->mxModifyListener.is())
1187 xBC->removeModifyListener( mpImpl->mxModifyListener );
1191 catch( css::uno::Exception& )
1193 TOOLS_WARN_EXCEPTION( "svx", "SdrOle2Obj::RemoveListeners_Impl()" );
1197 void SdrOle2Obj::Disconnect_Impl()
1201 if ( !mpImpl->aPersistName.isEmpty() )
1203 if( getSdrModelFromSdrObject().IsInDestruction() )
1205 // TODO/LATER: here we must assume that the destruction of the model is enough to make clear that we will not
1206 // remove the object from the container, even if the DrawingObject itself is not destroyed (unfortunately this
1207 // There is no real need to do the following removing of the object from the container
1208 // in case the model has correct persistence, but in case of problems such a removing
1209 // would make the behavior of the office more stable
1211 comphelper::EmbeddedObjectContainer* pContainer = mpImpl->mxObjRef.GetContainer();
1212 if ( pContainer )
1214 pContainer->CloseEmbeddedObject( mpImpl->mxObjRef.GetObject() );
1215 mpImpl->mxObjRef.AssignToContainer( nullptr, mpImpl->aPersistName );
1218 // happens later than the destruction of the model, so we can't assert that).
1219 //DBG_ASSERT( bInDestruction, "Model is destroyed, but not me?!" );
1220 //TODO/LATER: should be make sure that the ObjectShell also forgets the object, because we will close it soon?
1222 uno::Reference < util::XCloseable > xClose( xObjRef, uno::UNO_QUERY );
1223 if ( xClose.is() )
1227 xClose->close( true );
1229 catch ( util::CloseVetoException& )
1231 // there's still someone who needs the object!
1235 xObjRef = NULL;*/
1237 else if ( mpImpl->mxObjRef.is() )
1239 if ( getSdrModelFromSdrObject().getUnoModel().is() )
1241 // remove object, but don't close it (that's up to someone else)
1242 comphelper::EmbeddedObjectContainer* pContainer = mpImpl->mxObjRef.GetContainer();
1243 if ( pContainer )
1245 pContainer->RemoveEmbeddedObject( mpImpl->mxObjRef.GetObject() );
1247 // TODO/LATER: mpImpl->aPersistName contains outdated information, to keep it updated
1248 // it should be returned from RemoveEmbeddedObject call. Currently it is no problem,
1249 // since no container is adjusted, actually the empty string could be provided as a name here
1250 mpImpl->mxObjRef.AssignToContainer( nullptr, mpImpl->aPersistName );
1253 DisconnectFileLink_Impl();
1258 if ( mpImpl->mxObjRef.is() && mpImpl->mxLightClient.is() )
1260 mpImpl->mxObjRef->removeStateChangeListener ( mpImpl->mxLightClient );
1261 mpImpl->mxObjRef->removeEventListener( mpImpl->mxLightClient );
1262 mpImpl->mxObjRef->setClientSite( nullptr );
1264 GetSdrGlobalData().GetOLEObjCache().RemoveObj(this);
1267 catch( css::uno::Exception& )
1269 TOOLS_WARN_EXCEPTION( "svx", "SdrOle2Obj::Disconnect_Impl()" );
1272 mpImpl->mbConnected = false;
1275 rtl::Reference<SdrObject> SdrOle2Obj::createSdrGrafObjReplacement(bool bAddText) const
1277 const Graphic* pOLEGraphic = GetGraphic();
1279 if(pOLEGraphic)
1281 // #i118485# allow creating a SdrGrafObj representation
1282 rtl::Reference<SdrGrafObj> pClone = new SdrGrafObj(
1283 getSdrModelFromSdrObject(),
1284 *pOLEGraphic);
1286 // copy transformation
1287 basegfx::B2DHomMatrix aMatrix;
1288 basegfx::B2DPolyPolygon aPolyPolygon;
1290 TRGetBaseGeometry(aMatrix, aPolyPolygon);
1291 pClone->TRSetBaseGeometry(aMatrix, aPolyPolygon);
1293 // copy all attributes to support graphic styles for OLEs
1294 pClone->SetStyleSheet(GetStyleSheet(), false);
1295 pClone->SetMergedItemSet(GetMergedItemSet());
1297 if(bAddText)
1299 // #i118485# copy text (Caution! Model needed, as guaranteed in aw080)
1300 OutlinerParaObject* pOPO = GetOutlinerParaObject();
1302 if(pOPO)
1304 pClone->NbcSetOutlinerParaObject(*pOPO);
1308 return rtl::Reference<SdrObject>(pClone);
1310 else
1312 // #i100710# pOLEGraphic may be zero (no visualisation available),
1313 // so we need to use the OLE replacement graphic
1314 rtl::Reference<SdrRectObj> pClone = new SdrRectObj(
1315 getSdrModelFromSdrObject(),
1316 GetSnapRect());
1318 // gray outline
1319 pClone->SetMergedItem(XLineStyleItem(css::drawing::LineStyle_SOLID));
1320 const svtools::ColorConfig aColorConfig;
1321 const svtools::ColorConfigValue aColor(aColorConfig.GetColorValue(svtools::OBJECTBOUNDARIES));
1322 pClone->SetMergedItem(XLineColorItem(OUString(), aColor.nColor));
1324 // bitmap fill
1325 pClone->SetMergedItem(XFillStyleItem(drawing::FillStyle_BITMAP));
1326 pClone->SetMergedItem(XFillBitmapItem(OUString(), GetEmptyOLEReplacementGraphic()));
1327 pClone->SetMergedItem(XFillBmpTileItem(false));
1328 pClone->SetMergedItem(XFillBmpStretchItem(false));
1330 return rtl::Reference<SdrObject>(pClone);
1334 rtl::Reference<SdrObject> SdrOle2Obj::DoConvertToPolyObj(bool bBezier, bool bAddText) const
1336 // #i118485# missing converter added
1337 rtl::Reference<SdrObject> pRetval = createSdrGrafObjReplacement(true);
1339 if(pRetval)
1341 return pRetval->DoConvertToPolyObj(bBezier, bAddText);
1344 return nullptr;
1347 void SdrOle2Obj::handlePageChange(SdrPage* pOldPage, SdrPage* pNewPage)
1349 const bool bRemove(pNewPage == nullptr && pOldPage != nullptr);
1350 const bool bInsert(pNewPage != nullptr && pOldPage == nullptr);
1352 if (bRemove && mpImpl->mbConnected )
1354 Disconnect();
1357 // call parent
1358 SdrRectObj::handlePageChange(pOldPage, pNewPage);
1360 if (bInsert && !mpImpl->mbConnected )
1362 Connect();
1366 void SdrOle2Obj::SetObjRef( const css::uno::Reference < css::embed::XEmbeddedObject >& rNewObjRef )
1368 DBG_ASSERT( !rNewObjRef.is() || !mpImpl->mxObjRef.GetObject().is(), "SetObjRef called on already initialized object!");
1369 if( rNewObjRef == mpImpl->mxObjRef.GetObject() )
1370 return;
1372 // the caller of the method is responsible to control the old object, it will not be closed here
1373 // Otherwise WW8 import crashes because it transfers control to OLENode by this method
1374 if ( mpImpl->mxObjRef.GetObject().is() )
1375 mpImpl->mxObjRef.Lock( false );
1377 // avoid removal of object in Disconnect! It is definitely a HACK to call SetObjRef(0)!
1378 // This call will try to close the objects; so if anybody else wants to keep it, it must be locked by a CloseListener
1379 mpImpl->mxObjRef.Clear();
1381 if ( mpImpl->mbConnected )
1382 Disconnect();
1384 mpImpl->mxObjRef.Assign( rNewObjRef, GetAspect() );
1385 mpImpl->mbTypeAsked = false;
1387 if ( mpImpl->mxObjRef.is() )
1389 mpImpl->moGraphic.reset();
1391 if ( mpImpl->mxObjRef->getStatus( GetAspect() ) & embed::EmbedMisc::EMBED_NEVERRESIZE )
1392 SetResizeProtect(true);
1394 // For math objects, set closed state to transparent
1395 SetClosedObj(!ImplIsMathObj( rNewObjRef ));
1397 Connect();
1400 SetChanged();
1401 BroadcastObjectChange();
1404 void SdrOle2Obj::SetClosedObj( bool bIsClosed )
1406 // TODO/LATER: do we still need this hack?
1407 // Allow changes to the closed state of OLE objects
1408 m_bClosedObj = bIsClosed;
1411 rtl::Reference<SdrObject> SdrOle2Obj::getFullDragClone() const
1413 // #i118485# use central replacement generator
1414 return createSdrGrafObjReplacement(false);
1417 void SdrOle2Obj::SetPersistName( const OUString& rPersistName, SvxOle2Shape* pCreator )
1419 DBG_ASSERT( mpImpl->aPersistName.isEmpty(), "Persist name changed!");
1421 mpImpl->aPersistName = rPersistName;
1422 mpImpl->mbLoadingOLEObjectFailed = false;
1424 Connect(pCreator);
1425 SetChanged();
1428 void SdrOle2Obj::AbandonObject()
1430 mpImpl->aPersistName.clear();
1431 mpImpl->mbLoadingOLEObjectFailed = false;
1432 SetObjRef(nullptr);
1435 const OUString& SdrOle2Obj::GetPersistName() const
1437 return mpImpl->aPersistName;
1440 void SdrOle2Obj::TakeObjInfo(SdrObjTransformInfoRec& rInfo) const
1442 // #i118485# Allowing much more attributes for OLEs
1443 rInfo.bRotateFreeAllowed = true;
1444 rInfo.bRotate90Allowed = true;
1445 rInfo.bMirrorFreeAllowed = true;
1446 rInfo.bMirror45Allowed = true;
1447 rInfo.bMirror90Allowed = true;
1448 rInfo.bTransparenceAllowed = true;
1449 rInfo.bShearAllowed = true;
1450 rInfo.bEdgeRadiusAllowed = false;
1451 rInfo.bNoOrthoDesired = false;
1452 rInfo.bCanConvToPath = true;
1453 rInfo.bCanConvToPoly = true;
1454 rInfo.bCanConvToPathLineToArea = false;
1455 rInfo.bCanConvToPolyLineToArea = false;
1456 rInfo.bCanConvToContour = true;
1459 SdrObjKind SdrOle2Obj::GetObjIdentifier() const
1461 return mpImpl->mbFrame ? SdrObjKind::OLEPluginFrame : SdrObjKind::OLE2;
1464 OUString SdrOle2Obj::TakeObjNameSingul() const
1466 OUStringBuffer sName(SvxResId(mpImpl->mbFrame ? STR_ObjNameSingulFrame : STR_ObjNameSingulOLE2));
1468 const OUString aName(GetName());
1470 if (!aName.isEmpty())
1472 sName.append(" '" + aName + "\'");
1475 return sName.makeStringAndClear();
1478 OUString SdrOle2Obj::TakeObjNamePlural() const
1480 return SvxResId(mpImpl->mbFrame ? STR_ObjNamePluralFrame : STR_ObjNamePluralOLE2);
1483 rtl::Reference<SdrObject> SdrOle2Obj::CloneSdrObject(SdrModel& rTargetModel) const
1485 return new SdrOle2Obj(rTargetModel, *this);
1488 void SdrOle2Obj::ImpSetVisAreaSize()
1490 // #i118524# do not again set VisAreaSize when the call comes from OLE client (e.g. ObjectAreaChanged)
1491 if (mpImpl->mbSuppressSetVisAreaSize)
1492 return;
1494 // currently there is no need to recalculate scaling for iconified objects
1495 // TODO/LATER: it might be needed in future when it is possible to change the icon
1496 if ( GetAspect() == embed::Aspects::MSOLE_ICON )
1497 return;
1499 // the object area of an embedded object was changed, e.g. by user interaction an a selected object
1500 GetObjRef();
1501 if (!mpImpl->mxObjRef.is())
1502 return;
1504 sal_Int64 nMiscStatus = mpImpl->mxObjRef->getStatus( GetAspect() );
1506 // the client is required to get access to scaling
1507 SfxInPlaceClient* pClient(
1508 SfxInPlaceClient::GetClient(
1509 dynamic_cast<SfxObjectShell*>(
1510 getSdrModelFromSdrObject().GetPersist()),
1511 mpImpl->mxObjRef.GetObject()));
1512 const bool bHasOwnClient(
1513 mpImpl->mxLightClient.is() &&
1514 mpImpl->mxObjRef->getClientSite() == uno::Reference< embed::XEmbeddedClient >( mpImpl->mxLightClient ) );
1516 if ( pClient || bHasOwnClient )
1518 // TODO: IMHO we need to do similar things when object is UIActive or OutplaceActive?!
1519 if ( ((nMiscStatus & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE) &&
1520 svt::EmbeddedObjectRef::TryRunningState( mpImpl->mxObjRef.GetObject() ))
1521 || mpImpl->mxObjRef->getCurrentState() == embed::EmbedStates::INPLACE_ACTIVE
1524 Fraction aScaleWidth;
1525 Fraction aScaleHeight;
1526 if ( pClient )
1528 aScaleWidth = pClient->GetScaleWidth();
1529 aScaleHeight = pClient->GetScaleHeight();
1531 else
1533 aScaleWidth = mpImpl->mxLightClient->GetScaleWidth();
1534 aScaleHeight = mpImpl->mxLightClient->GetScaleHeight();
1537 // The object wants to resize itself (f.e. Chart wants to recalculate the layout)
1538 // or object is inplace active and so has a window that must be resized also
1539 // In these cases the change in the object area size will be reflected in a change of the
1540 // objects' visual area. The scaling will not change, but it might exist already and must
1541 // be used in calculations
1542 MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( mpImpl->mxObjRef->getMapUnit( GetAspect() ) );
1543 Size aVisSize;
1544 if (sal_Int32(aScaleWidth) != 0 && sal_Int32(aScaleHeight) != 0) // avoid div by zero
1545 aVisSize = Size( static_cast<tools::Long>( Fraction( getRectangle().GetWidth() ) / aScaleWidth ),
1546 static_cast<tools::Long>( Fraction( getRectangle().GetHeight() ) / aScaleHeight ) );
1548 aVisSize = OutputDevice::LogicToLogic(
1549 aVisSize,
1550 MapMode(getSdrModelFromSdrObject().GetScaleUnit()),
1551 MapMode(aMapUnit));
1552 awt::Size aSz;
1553 aSz.Width = aVisSize.Width();
1554 aSz.Height = aVisSize.Height();
1555 mpImpl->mxObjRef->setVisualAreaSize( GetAspect(), aSz );
1559 aSz = mpImpl->mxObjRef->getVisualAreaSize( GetAspect() );
1561 catch( embed::NoVisualAreaSizeException& )
1564 tools::Rectangle aAcceptedVisArea;
1565 aAcceptedVisArea.SetSize( Size( static_cast<tools::Long>( Fraction( tools::Long( aSz.Width ) ) * aScaleWidth ),
1566 static_cast<tools::Long>( Fraction( tools::Long( aSz.Height ) ) * aScaleHeight ) ) );
1567 if (aVisSize != aAcceptedVisArea.GetSize())
1569 // server changed VisArea to its liking and the VisArea is different than the suggested one
1570 // store the new value as given by the object
1571 MapUnit aNewMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( mpImpl->mxObjRef->getMapUnit( GetAspect() ) );
1572 auto aSize = OutputDevice::LogicToLogic(aAcceptedVisArea.GetSize(), MapMode(aNewMapUnit), MapMode(getSdrModelFromSdrObject().GetScaleUnit()));
1573 setRectangleSize(aSize.Width(), aSize.Height());
1576 // make the new object area known to the client
1577 // compared to the "else" branch aRect might have been changed by the object and no additional scaling was applied
1578 // WHY this -> OSL_ASSERT( pClient );
1579 if( pClient )
1580 pClient->SetObjArea(getRectangle());
1582 // we need a new replacement image as the object has resized itself
1584 //#i79578# don't request a new replacement image for charts to often
1585 //a chart sends a modified call to the framework if it was changed
1586 //thus the replacement update is already handled there
1587 if( !IsChart() )
1588 mpImpl->mxObjRef.UpdateReplacement();
1590 else
1592 // The object isn't active and does not want to resize itself so the changed object area size
1593 // will be reflected in a changed object scaling
1594 Fraction aScaleWidth;
1595 Fraction aScaleHeight;
1596 Size aObjAreaSize;
1597 if ( CalculateNewScaling( aScaleWidth, aScaleHeight, aObjAreaSize ) )
1599 if ( pClient )
1601 tools::Rectangle aScaleRect(getRectangle().TopLeft(), aObjAreaSize);
1602 pClient->SetObjAreaAndScale( aScaleRect, aScaleWidth, aScaleHeight);
1604 else
1606 mpImpl->mxLightClient->SetSizeScale( aScaleWidth, aScaleHeight );
1611 else if( (nMiscStatus & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE) &&
1612 svt::EmbeddedObjectRef::TryRunningState( mpImpl->mxObjRef.GetObject() ) )
1614 //also handle not sfx based ole objects e.g. charts
1615 //#i83860# resizing charts in impress distorts fonts
1616 uno::Reference< embed::XVisualObject > xVisualObject( getXModel(), uno::UNO_QUERY );
1617 if( xVisualObject.is() )
1619 const MapUnit aMapUnit(
1620 VCLUnoHelper::UnoEmbed2VCLMapUnit(
1621 mpImpl->mxObjRef->getMapUnit(GetAspect())));
1622 const Point aTL( getRectangle().TopLeft() );
1623 const Point aBR( getRectangle().BottomRight() );
1624 const Point aTL2(
1625 OutputDevice::LogicToLogic(
1626 aTL,
1627 MapMode(getSdrModelFromSdrObject().GetScaleUnit()),
1628 MapMode(aMapUnit)));
1629 const Point aBR2(
1630 OutputDevice::LogicToLogic(
1631 aBR,
1632 MapMode(getSdrModelFromSdrObject().GetScaleUnit()),
1633 MapMode(aMapUnit)));
1634 const tools::Rectangle aNewRect(
1635 aTL2,
1636 aBR2);
1638 xVisualObject->setVisualAreaSize(
1639 GetAspect(),
1640 awt::Size(
1641 aNewRect.GetWidth(),
1642 aNewRect.GetHeight()));
1647 void SdrOle2Obj::NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact)
1649 if(!getSdrModelFromSdrObject().isLocked())
1651 GetObjRef();
1653 if ( mpImpl->mxObjRef.is() && ( mpImpl->mxObjRef->getStatus( GetAspect() ) & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE ) )
1655 // if the object needs recompose on resize
1656 // the client site should be created before the resize will take place
1657 // check whether there is no client site and create it if necessary
1658 AddOwnLightClient();
1662 SdrRectObj::NbcResize(rRef,xFact,yFact);
1664 if( !getSdrModelFromSdrObject().isLocked() )
1665 ImpSetVisAreaSize();
1668 void SdrOle2Obj::SetGeoData(const SdrObjGeoData& rGeo)
1670 SdrRectObj::SetGeoData(rGeo);
1672 if( !getSdrModelFromSdrObject().isLocked() )
1673 ImpSetVisAreaSize();
1676 void SdrOle2Obj::NbcSetSnapRect(const tools::Rectangle& rRect)
1678 SdrRectObj::NbcSetSnapRect(rRect);
1680 if( !getSdrModelFromSdrObject().isLocked() )
1681 ImpSetVisAreaSize();
1683 if ( mpImpl->mxObjRef.is() && IsChart() )
1685 //#i103460# charts do not necessarily have an own size within ODF files,
1686 //for this case they need to use the size settings from the surrounding frame,
1687 //which is made available with this method as there is no other way
1688 mpImpl->mxObjRef.SetDefaultSizeForChart( Size( rRect.GetWidth(), rRect.GetHeight() ) );
1692 void SdrOle2Obj::NbcSetLogicRect(const tools::Rectangle& rRect)
1694 SdrRectObj::NbcSetLogicRect(rRect);
1696 if( !getSdrModelFromSdrObject().isLocked() )
1697 ImpSetVisAreaSize();
1700 const Graphic* SdrOle2Obj::GetGraphic() const
1702 if ( mpImpl->mxObjRef.is() )
1703 return mpImpl->mxObjRef.GetGraphic();
1704 return mpImpl->moGraphic ? &*mpImpl->moGraphic : nullptr;
1707 void SdrOle2Obj::GetNewReplacement()
1709 if ( mpImpl->mxObjRef.is() )
1710 mpImpl->mxObjRef.UpdateReplacement();
1713 Size SdrOle2Obj::GetOrigObjSize( MapMode const * pTargetMapMode ) const
1715 return mpImpl->mxObjRef.GetSize( pTargetMapMode );
1718 void SdrOle2Obj::setSuppressSetVisAreaSize( bool bNew )
1720 mpImpl->mbSuppressSetVisAreaSize = bNew;
1723 void SdrOle2Obj::NbcMove(const Size& rSize)
1725 SdrRectObj::NbcMove(rSize);
1727 if( !getSdrModelFromSdrObject().isLocked() )
1728 ImpSetVisAreaSize();
1731 bool SdrOle2Obj::CanUnloadRunningObj( const uno::Reference< embed::XEmbeddedObject >& xObj, sal_Int64 nAspect )
1733 uno::Reference<embed::XEmbedPersist2> xPersist(xObj, uno::UNO_QUERY);
1734 if (xPersist.is())
1736 if (!xPersist->isStored())
1737 // It doesn't have persistent storage. We can't unload this.
1738 return false;
1741 bool bResult = false;
1743 sal_Int32 nState = xObj->getCurrentState();
1744 if ( nState == embed::EmbedStates::LOADED )
1746 // the object is already unloaded
1747 bResult = true;
1749 else
1751 uno::Reference < util::XModifiable > xModifiable( xObj->getComponent(), uno::UNO_QUERY );
1752 if ( !xModifiable.is() )
1753 bResult = true;
1754 else
1756 sal_Int64 nMiscStatus = xObj->getStatus( nAspect );
1758 if ( embed::EmbedMisc::MS_EMBED_ALWAYSRUN != ( nMiscStatus & embed::EmbedMisc::MS_EMBED_ALWAYSRUN ) &&
1759 embed::EmbedMisc::EMBED_ACTIVATEIMMEDIATELY != ( nMiscStatus & embed::EmbedMisc::EMBED_ACTIVATEIMMEDIATELY ) &&
1760 !( xModifiable.is() && xModifiable->isModified() ) &&
1761 !( nState == embed::EmbedStates::INPLACE_ACTIVE || nState == embed::EmbedStates::UI_ACTIVE || nState == embed::EmbedStates::ACTIVE ) )
1763 bResult = true;
1768 return bResult;
1771 bool SdrOle2Obj::Unload( const uno::Reference< embed::XEmbeddedObject >& xObj, sal_Int64 nAspect )
1773 bool bResult = false;
1775 if ( CanUnloadRunningObj( xObj, nAspect ) )
1779 xObj->changeState( embed::EmbedStates::LOADED );
1780 bResult = true;
1782 catch( css::uno::Exception& )
1784 TOOLS_WARN_EXCEPTION( "svx", "SdrOle2Obj::Unload()" );
1788 return bResult;
1791 bool SdrOle2Obj::Unload()
1793 if (!mpImpl->mxObjRef.is())
1794 // Already unloaded.
1795 return true;
1797 return Unload(mpImpl->mxObjRef.GetObject(), GetAspect());
1800 void SdrOle2Obj::GetObjRef_Impl()
1802 if ( !mpImpl->mxObjRef.is() && !mpImpl->aPersistName.isEmpty() && getSdrModelFromSdrObject().GetPersist() )
1804 // Only try loading if it did not went wrong up to now
1805 if(!mpImpl->mbLoadingOLEObjectFailed)
1807 mpImpl->mxObjRef.Assign(
1808 getSdrModelFromSdrObject().GetPersist()->getEmbeddedObjectContainer().GetEmbeddedObject(mpImpl->aPersistName),
1809 GetAspect());
1810 mpImpl->mbTypeAsked = false;
1811 CheckFileLink_Impl();
1813 // If loading of OLE object failed, remember that to not invoke an endless
1814 // loop trying to load it again and again.
1815 if( mpImpl->mxObjRef.is() )
1817 mpImpl->mbLoadingOLEObjectFailed = true;
1820 // For math objects, set closed state to transparent
1821 SetClosedObj(!ImplIsMathObj( mpImpl->mxObjRef.GetObject() ));
1824 if ( mpImpl->mxObjRef.is() )
1826 if( !IsEmptyPresObj() )
1828 // remember modified status of model
1829 const bool bWasChanged(getSdrModelFromSdrObject().IsChanged());
1831 // perhaps preview not valid anymore
1832 // This line changes the modified state of the model
1833 ClearGraphic();
1835 // if status was not set before, force it back
1836 // to not set, so that SetGraphic(0) above does not
1837 // set the modified state of the model.
1838 if(!bWasChanged && getSdrModelFromSdrObject().IsChanged())
1840 getSdrModelFromSdrObject().SetChanged( false );
1845 if ( mpImpl->mxObjRef.is() )
1846 Connect();
1849 if ( mpImpl->mbConnected )
1851 // move object to first position in cache
1852 GetSdrGlobalData().GetOLEObjCache().InsertObj(this);
1856 uno::Reference < embed::XEmbeddedObject > const & SdrOle2Obj::GetObjRef() const
1858 const_cast<SdrOle2Obj*>(this)->GetObjRef_Impl();
1859 return mpImpl->mxObjRef.GetObject();
1862 uno::Reference < embed::XEmbeddedObject > const & SdrOle2Obj::GetObjRef_NoInit() const
1864 return mpImpl->mxObjRef.GetObject();
1867 uno::Reference< frame::XModel > SdrOle2Obj::getXModel() const
1869 if (svt::EmbeddedObjectRef::TryRunningState(GetObjRef()))
1870 return uno::Reference< frame::XModel >( mpImpl->mxObjRef->getComponent(), uno::UNO_QUERY );
1871 else
1872 return uno::Reference< frame::XModel >();
1875 bool SdrOle2Obj::IsChart() const
1877 if (!mpImpl->mbTypeAsked)
1879 mpImpl->mbIsChart = mpImpl->mxObjRef.IsChart();
1880 mpImpl->mbTypeAsked = true;
1882 return mpImpl->mbIsChart;
1885 void SdrOle2Obj::SetGraphicToObj( const Graphic& aGraphic )
1887 mpImpl->mxObjRef.SetGraphic( aGraphic, OUString() );
1888 // if the object isn't valid, e.g. link to something that doesn't exist, set the fallback
1889 // graphic as mxGraphic so SdrOle2Obj::GetGraphic will show the fallback
1890 if (const Graphic* pObjGraphic = mpImpl->mxObjRef.is() ? nullptr : mpImpl->mxObjRef.GetGraphic())
1891 mpImpl->moGraphic.emplace(*pObjGraphic);
1894 void SdrOle2Obj::SetGraphicToObj( const uno::Reference< io::XInputStream >& xGrStream, const OUString& aMediaType )
1896 mpImpl->mxObjRef.SetGraphicStream( xGrStream, aMediaType );
1897 // if the object isn't valid, e.g. link to something that doesn't exist, set the fallback
1898 // graphic as mxGraphic so SdrOle2Obj::GetGraphic will show the fallback
1899 if (const Graphic* pObjGraphic = mpImpl->mxObjRef.is() ? nullptr : mpImpl->mxObjRef.GetGraphic())
1900 mpImpl->moGraphic.emplace(*pObjGraphic);
1903 bool SdrOle2Obj::IsCalc() const
1905 if ( !mpImpl->mxObjRef.is() )
1906 return false;
1908 SvGlobalName aObjClsId( mpImpl->mxObjRef->getClassID() );
1909 return SvGlobalName(SO3_SC_CLASSID_30) == aObjClsId
1910 || SvGlobalName(SO3_SC_CLASSID_40) == aObjClsId
1911 || SvGlobalName(SO3_SC_CLASSID_50) == aObjClsId
1912 || SvGlobalName(SO3_SC_CLASSID_60) == aObjClsId
1913 || SvGlobalName(SO3_SC_OLE_EMBED_CLASSID_60) == aObjClsId
1914 || SvGlobalName(SO3_SC_OLE_EMBED_CLASSID_8) == aObjClsId
1915 || SvGlobalName(SO3_SC_CLASSID) == aObjClsId;
1918 uno::Reference< frame::XModel > SdrOle2Obj::GetParentXModel() const
1920 uno::Reference< frame::XModel > xDoc(getSdrModelFromSdrObject().getUnoModel(), uno::UNO_QUERY);
1921 return xDoc;
1924 bool SdrOle2Obj::CalculateNewScaling( Fraction& aScaleWidth, Fraction& aScaleHeight, Size& aObjAreaSize )
1926 // TODO/LEAN: to avoid rounding errors scaling always uses the VisArea.
1927 // If we don't cache it for own objects also we must load the object here
1928 if (!mpImpl->mxObjRef.is())
1929 return false;
1931 MapMode aMapMode(getSdrModelFromSdrObject().GetScaleUnit());
1932 aObjAreaSize = mpImpl->mxObjRef.GetSize( &aMapMode );
1934 Size aSize = getRectangle().GetSize();
1935 if (!aObjAreaSize.Width() || !aObjAreaSize.Height())
1937 // avoid invalid fractions
1938 aScaleWidth = Fraction(1,1);
1939 aScaleHeight = Fraction(1,1);
1941 else
1943 aScaleWidth = Fraction(aSize.Width(), aObjAreaSize.Width() );
1944 aScaleHeight = Fraction(aSize.Height(), aObjAreaSize.Height() );
1945 // reduce to 10 binary digits
1946 aScaleHeight.ReduceInaccurate(10);
1947 aScaleWidth.ReduceInaccurate(10);
1950 return true;
1953 bool SdrOle2Obj::AddOwnLightClient()
1955 // The Own Light Client must be registered in object only using this method!
1956 if ( !SfxInPlaceClient::GetClient( dynamic_cast<SfxObjectShell*>(getSdrModelFromSdrObject().GetPersist()), mpImpl->mxObjRef.GetObject() )
1957 && !( mpImpl->mxLightClient.is() && mpImpl->mxObjRef->getClientSite() == uno::Reference< embed::XEmbeddedClient >( mpImpl->mxLightClient ) ) )
1959 Connect();
1961 if ( mpImpl->mxObjRef.is() && mpImpl->mxLightClient.is() )
1963 Fraction aScaleWidth;
1964 Fraction aScaleHeight;
1965 Size aObjAreaSize;
1966 if ( CalculateNewScaling( aScaleWidth, aScaleHeight, aObjAreaSize ) )
1968 mpImpl->mxLightClient->SetSizeScale( aScaleWidth, aScaleHeight );
1969 try {
1970 mpImpl->mxObjRef->setClientSite( mpImpl->mxLightClient );
1971 return true;
1972 } catch( uno::Exception& )
1978 return false;
1981 return true;
1984 Graphic SdrOle2Obj::GetEmptyOLEReplacementGraphic()
1986 return Graphic(BitmapEx(BMP_SVXOLEOBJ));
1989 void SdrOle2Obj::SetWindow(const css::uno::Reference < css::awt::XWindow >& _xWindow)
1991 if ( mpImpl->mxObjRef.is() && mpImpl->mxLightClient.is() )
1993 mpImpl->mxLightClient->setWindow(_xWindow);
1997 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */