Adjust includes
[LibreOffice.git] / svx / source / svdraw / svdoole2.cxx
bloba43c341193dbab80e678b480d4bc4226d01fa90c
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/util/XModifyBroadcaster.hpp>
23 #include <com/sun/star/util/XModifiable.hpp>
24 #include <com/sun/star/chart2/XChartDocument.hpp>
25 #include <com/sun/star/embed/EmbedStates.hpp>
26 #include <com/sun/star/embed/ElementModes.hpp>
27 #include <com/sun/star/embed/EmbedMisc.hpp>
28 #include <com/sun/star/embed/Aspects.hpp>
29 #include <com/sun/star/embed/ObjectSaveVetoException.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>
40 #include <comphelper/processfactory.hxx>
41 #include <cppuhelper/exc_hlp.hxx>
42 #include <unotools/ucbstreamhelper.hxx>
44 #include <toolkit/helper/vclunohelper.hxx>
45 #include <toolkit/awt/vclxwindow.hxx>
46 #include <toolkit/helper/convert.hxx>
48 #include <vcl/graphicfilter.hxx>
49 #include <svtools/embedhlp.hxx>
51 #include <sfx2/objsh.hxx>
52 #include <sfx2/ipclient.hxx>
53 #include <sfx2/lnkbase.hxx>
54 #include <tools/stream.hxx>
55 #include <comphelper/anytostring.hxx>
56 #include <svx/svdpagv.hxx>
57 #include <tools/globname.hxx>
58 #include <vcl/jobset.hxx>
59 #include <comphelper/classids.hxx>
61 #include <sot/formats.hxx>
62 #include <svtools/transfer.hxx>
63 #include <cppuhelper/implbase.hxx>
65 #include <svl/solar.hrc>
66 #include <svl/urihelper.hxx>
67 #include <vcl/svapp.hxx>
69 #include <svx/charthelper.hxx>
70 #include <svx/svdmodel.hxx>
71 #include <svdglob.hxx>
72 #include <svx/strings.hrc>
73 #include <svx/svdetc.hxx>
74 #include <svx/svdview.hxx>
75 #include <unomlstr.hxx>
76 #include <sdr/contact/viewcontactofsdrole2obj.hxx>
77 #include <svx/svdograf.hxx>
78 #include <sdr/properties/oleproperties.hxx>
79 #include <svx/xlnclit.hxx>
80 #include <svx/xbtmpit.hxx>
81 #include <svx/xflbmtit.hxx>
82 #include <svx/xflbstit.hxx>
83 #include <basegfx/matrix/b2dhommatrix.hxx>
84 #include <basegfx/polygon/b2dpolypolygon.hxx>
85 #include <editeng/outlobj.hxx>
86 #include <svx/svdpage.hxx>
87 #include <rtl/ref.hxx>
88 #include <bitmaps.hlst>
90 using namespace ::com::sun::star;
92 static uno::Reference < beans::XPropertySet > lcl_getFrame_throw(const SdrOle2Obj* _pObject)
94 uno::Reference < beans::XPropertySet > xFrame;
95 if ( _pObject )
97 uno::Reference< frame::XController> xController = _pObject->GetParentXModel()->getCurrentController();
98 if ( xController.is() )
100 xFrame.set( xController->getFrame(),uno::UNO_QUERY_THROW);
102 } // if ( _pObject )
103 return xFrame;
106 class SdrLightEmbeddedClient_Impl : public ::cppu::WeakImplHelper
107 < embed::XStateChangeListener
108 , document::XEventListener
109 , embed::XInplaceClient
110 , embed::XEmbeddedClient
111 , embed::XWindowSupplier
114 uno::Reference< awt::XWindow > m_xWindow;
115 SdrOle2Obj* mpObj;
117 Fraction m_aScaleWidth;
118 Fraction m_aScaleHeight;
121 public:
122 explicit SdrLightEmbeddedClient_Impl( SdrOle2Obj* pObj );
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 private:
136 tools::Rectangle impl_getScaledRect_nothrow() const;
137 // XStateChangeListener
138 virtual void SAL_CALL changingState( const css::lang::EventObject& aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState ) override;
139 virtual void SAL_CALL stateChanged( const css::lang::EventObject& aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState ) override;
140 virtual void SAL_CALL disposing( const css::lang::EventObject& aEvent ) override;
142 // document::XEventListener
143 virtual void SAL_CALL notifyEvent( const document::EventObject& aEvent ) override;
145 // XEmbeddedClient
146 virtual void SAL_CALL saveObject() override;
147 virtual void SAL_CALL visibilityChanged( sal_Bool bVisible ) override;
149 // XComponentSupplier
150 virtual uno::Reference< util::XCloseable > SAL_CALL getComponent() override;
152 // XInplaceClient
153 virtual sal_Bool SAL_CALL canInplaceActivate() override;
154 virtual void SAL_CALL activatingInplace() override;
155 virtual void SAL_CALL activatingUI() override;
156 virtual void SAL_CALL deactivatedInplace() override;
157 virtual void SAL_CALL deactivatedUI() override;
158 virtual uno::Reference< css::frame::XLayoutManager > SAL_CALL getLayoutManager() override;
159 virtual uno::Reference< frame::XDispatchProvider > SAL_CALL getInplaceDispatchProvider() override;
160 virtual awt::Rectangle SAL_CALL getPlacement() override;
161 virtual awt::Rectangle SAL_CALL getClipRectangle() override;
162 virtual void SAL_CALL translateAccelerators( const uno::Sequence< awt::KeyEvent >& aKeys ) override;
163 virtual void SAL_CALL scrollObject( const awt::Size& aOffset ) override;
164 virtual void SAL_CALL changedPlacement( const awt::Rectangle& aPosRect ) override;
166 // XWindowSupplier
167 virtual uno::Reference< awt::XWindow > SAL_CALL getWindow() override;
170 SdrLightEmbeddedClient_Impl::SdrLightEmbeddedClient_Impl( SdrOle2Obj* pObj )
171 : mpObj( pObj )
174 tools::Rectangle SdrLightEmbeddedClient_Impl::impl_getScaledRect_nothrow() const
176 tools::Rectangle aLogicRect( mpObj->GetLogicRect() );
177 // apply scaling to object area and convert to pixels
178 aLogicRect.SetSize( Size( long( aLogicRect.GetWidth() * m_aScaleWidth),
179 long( aLogicRect.GetHeight() * m_aScaleHeight) ) );
180 return aLogicRect;
183 void SAL_CALL SdrLightEmbeddedClient_Impl::changingState( const css::lang::EventObject& /*aEvent*/, ::sal_Int32 /*nOldState*/, ::sal_Int32 /*nNewState*/ )
187 void SAL_CALL SdrLightEmbeddedClient_Impl::stateChanged( const css::lang::EventObject& /*aEvent*/, ::sal_Int32 nOldState, ::sal_Int32 nNewState )
189 SolarMutexGuard aGuard;
191 if ( mpObj && nOldState == embed::EmbedStates::LOADED && nNewState == embed::EmbedStates::RUNNING )
193 mpObj->ObjectLoaded();
194 GetSdrGlobalData().GetOLEObjCache().InsertObj(mpObj);
196 else if ( mpObj && nNewState == embed::EmbedStates::LOADED && nOldState == embed::EmbedStates::RUNNING )
198 GetSdrGlobalData().GetOLEObjCache().RemoveObj(mpObj);
202 void SAL_CALL SdrLightEmbeddedClient_Impl::disposing( const css::lang::EventObject& /*aEvent*/ )
204 SolarMutexGuard aGuard;
206 GetSdrGlobalData().GetOLEObjCache().RemoveObj(mpObj);
209 void SAL_CALL SdrLightEmbeddedClient_Impl::notifyEvent( const document::EventObject& aEvent )
211 // TODO/LATER: when writer uses this implementation the code could be shared with SfxInPlaceClient_Impl
213 SolarMutexGuard aGuard;
215 // the code currently makes sense only in case there is no other client
216 if ( mpObj && mpObj->GetAspect() != embed::Aspects::MSOLE_ICON && aEvent.EventName == "OnVisAreaChanged"
217 && mpObj->GetObjRef().is() && mpObj->GetObjRef()->getClientSite() == uno::Reference< embed::XEmbeddedClient >( this ) )
221 MapUnit aContainerMapUnit( MapUnit::Map100thMM );
222 uno::Reference< embed::XVisualObject > xParentVis( mpObj->GetParentXModel(), uno::UNO_QUERY );
223 if ( xParentVis.is() )
224 aContainerMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xParentVis->getMapUnit( mpObj->GetAspect() ) );
226 MapUnit aObjMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( mpObj->GetObjRef()->getMapUnit( mpObj->GetAspect() ) );
228 tools::Rectangle aVisArea;
229 awt::Size aSz;
232 aSz = mpObj->GetObjRef()->getVisualAreaSize( mpObj->GetAspect() );
234 catch( embed::NoVisualAreaSizeException& )
236 OSL_FAIL( "No visual area size!" );
237 aSz.Width = 5000;
238 aSz.Height = 5000;
240 catch( uno::Exception& )
242 OSL_FAIL( "Unexpected exception!" );
243 aSz.Width = 5000;
244 aSz.Height = 5000;
247 aVisArea.SetSize( Size( aSz.Width, aSz.Height ) );
248 aVisArea = OutputDevice::LogicToLogic(aVisArea, MapMode(aObjMapUnit), MapMode(aContainerMapUnit));
249 Size aScaledSize( static_cast< long >( m_aScaleWidth * Fraction( aVisArea.GetWidth() ) ),
250 static_cast< long >( m_aScaleHeight * Fraction( aVisArea.GetHeight() ) ) );
251 tools::Rectangle aLogicRect( mpObj->GetLogicRect() );
253 // react to the change if the difference is bigger than one pixel
254 Size aPixelDiff =
255 Application::GetDefaultDevice()->LogicToPixel(
256 Size( aLogicRect.GetWidth() - aScaledSize.Width(),
257 aLogicRect.GetHeight() - aScaledSize.Height() ),
258 MapMode(aContainerMapUnit));
259 if( aPixelDiff.Width() || aPixelDiff.Height() )
261 mpObj->SetLogicRect( tools::Rectangle( aLogicRect.TopLeft(), aScaledSize ) );
262 mpObj->BroadcastObjectChange();
264 else
265 mpObj->ActionChanged();
267 catch( uno::Exception& )
269 OSL_FAIL( "Unexpected exception!" );
274 void SAL_CALL SdrLightEmbeddedClient_Impl::saveObject()
276 // TODO/LATER: when writer uses this implementation the code could be shared with SfxInPlaceClient_Impl
277 uno::Reference< embed::XCommonEmbedPersist > xPersist;
278 uno::Reference< util::XModifiable > xModifiable;
281 SolarMutexGuard aGuard;
283 if ( !mpObj )
284 throw embed::ObjectSaveVetoException();
286 // the common persistence is supported by objects and links
287 xPersist.set( mpObj->GetObjRef(), uno::UNO_QUERY_THROW );
288 xModifiable.set( mpObj->GetParentXModel(), uno::UNO_QUERY );
291 xPersist->storeOwn();
293 if ( xModifiable.is() )
294 xModifiable->setModified( true );
297 void SAL_CALL SdrLightEmbeddedClient_Impl::visibilityChanged( sal_Bool /*bVisible*/ )
299 // nothing to do currently
300 // TODO/LATER: when writer uses this implementation the code could be shared with SfxInPlaceClient_Impl
301 if ( mpObj )
303 tools::Rectangle aLogicRect( mpObj->GetLogicRect() );
304 Size aLogicSize( aLogicRect.GetWidth(), aLogicRect.GetHeight() );
306 if( mpObj->IsChart() )
308 //charts never should be stretched see #i84323# for example
309 mpObj->SetLogicRect( tools::Rectangle( aLogicRect.TopLeft(), aLogicSize ) );
310 mpObj->BroadcastObjectChange();
311 } // if( mpObj->IsChart() )
315 uno::Reference< util::XCloseable > SAL_CALL SdrLightEmbeddedClient_Impl::getComponent()
317 uno::Reference< util::XCloseable > xResult;
319 SolarMutexGuard aGuard;
320 if ( mpObj )
321 xResult.set( mpObj->GetParentXModel(), uno::UNO_QUERY );
323 return xResult;
325 // XInplaceClient
327 sal_Bool SAL_CALL SdrLightEmbeddedClient_Impl::canInplaceActivate()
329 bool bRet = false;
330 SolarMutexGuard aGuard;
331 if ( mpObj )
333 uno::Reference< embed::XEmbeddedObject > xObject = mpObj->GetObjRef();
334 if ( !xObject.is() )
335 throw uno::RuntimeException();
336 // we don't want to switch directly from outplace to inplace mode
337 bRet = !( xObject->getCurrentState() == embed::EmbedStates::ACTIVE || mpObj->GetAspect() == embed::Aspects::MSOLE_ICON );
338 } // if ( mpObj )
339 return bRet;
342 void SAL_CALL SdrLightEmbeddedClient_Impl::activatingInplace()
346 void SAL_CALL SdrLightEmbeddedClient_Impl::activatingUI()
348 SolarMutexGuard aGuard;
350 uno::Reference < beans::XPropertySet > xFrame( lcl_getFrame_throw(mpObj));
351 uno::Reference < frame::XFrame > xOwnFrame( xFrame,uno::UNO_QUERY);
352 uno::Reference < frame::XFramesSupplier > xParentFrame( xOwnFrame->getCreator(), uno::UNO_QUERY );
353 if ( xParentFrame.is() )
354 xParentFrame->setActiveFrame( xOwnFrame );
356 OLEObjCache& rObjCache = GetSdrGlobalData().GetOLEObjCache();
357 const sal_uIntPtr nCount = rObjCache.size();
358 for(sal_Int32 i = nCount-1 ; i >= 0;--i)
360 SdrOle2Obj* pObj = rObjCache[i];
361 if ( pObj != mpObj )
363 // only deactivate ole objects which belongs to the same frame
364 if ( xFrame == lcl_getFrame_throw(pObj) )
366 uno::Reference< embed::XEmbeddedObject > xObject = pObj->GetObjRef();
369 if ( (xObject->getStatus( pObj->GetAspect() ) & embed::EmbedMisc::MS_EMBED_ACTIVATEWHENVISIBLE) ||
370 svt::EmbeddedObjectRef::IsGLChart(xObject) )
371 xObject->changeState( embed::EmbedStates::INPLACE_ACTIVE );
372 else
374 // the links should not stay in running state for long time because of locking
375 uno::Reference< embed::XLinkageSupport > xLink( xObject, uno::UNO_QUERY );
376 if ( xLink.is() && xLink->isLink() )
377 xObject->changeState( embed::EmbedStates::LOADED );
378 else
379 xObject->changeState( embed::EmbedStates::RUNNING );
382 catch (css::uno::Exception& )
386 } // for(sal_Int32 i = nCount-1 ; i >= 0;--i)
389 void SAL_CALL SdrLightEmbeddedClient_Impl::deactivatedInplace()
393 void SAL_CALL SdrLightEmbeddedClient_Impl::deactivatedUI()
395 SolarMutexGuard aGuard;
396 css::uno::Reference< css::frame::XLayoutManager > xLayoutManager(getLayoutManager());
397 if ( xLayoutManager.is() )
399 static const char aMenuBarURL[] = "private:resource/menubar/menubar";
400 if ( !xLayoutManager->isElementVisible( aMenuBarURL ) )
401 xLayoutManager->createElement( aMenuBarURL );
405 uno::Reference< css::frame::XLayoutManager > SAL_CALL SdrLightEmbeddedClient_Impl::getLayoutManager()
407 uno::Reference< css::frame::XLayoutManager > xMan;
408 SolarMutexGuard aGuard;
409 uno::Reference < beans::XPropertySet > xFrame( lcl_getFrame_throw(mpObj));
412 xMan.set(xFrame->getPropertyValue("LayoutManager"),uno::UNO_QUERY);
414 catch ( uno::Exception& )
416 throw uno::RuntimeException();
419 return xMan;
422 uno::Reference< frame::XDispatchProvider > SAL_CALL SdrLightEmbeddedClient_Impl::getInplaceDispatchProvider()
424 SolarMutexGuard aGuard;
425 return uno::Reference < frame::XDispatchProvider >( lcl_getFrame_throw(mpObj), uno::UNO_QUERY_THROW );
428 awt::Rectangle SAL_CALL SdrLightEmbeddedClient_Impl::getPlacement()
430 SolarMutexGuard aGuard;
431 if ( !mpObj )
432 throw uno::RuntimeException();
434 tools::Rectangle aLogicRect = impl_getScaledRect_nothrow();
435 MapUnit aContainerMapUnit( MapUnit::Map100thMM );
436 uno::Reference< embed::XVisualObject > xParentVis( mpObj->GetParentXModel(), uno::UNO_QUERY );
437 if ( xParentVis.is() )
438 aContainerMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xParentVis->getMapUnit( mpObj->GetAspect() ) );
440 aLogicRect = Application::GetDefaultDevice()->LogicToPixel(aLogicRect, MapMode(aContainerMapUnit));
441 return AWTRectangle( aLogicRect );
444 awt::Rectangle SAL_CALL SdrLightEmbeddedClient_Impl::getClipRectangle()
446 return getPlacement();
449 void SAL_CALL SdrLightEmbeddedClient_Impl::translateAccelerators( const uno::Sequence< awt::KeyEvent >& /*aKeys*/ )
453 void SAL_CALL SdrLightEmbeddedClient_Impl::scrollObject( const awt::Size& /*aOffset*/ )
457 void SAL_CALL SdrLightEmbeddedClient_Impl::changedPlacement( const awt::Rectangle& aPosRect )
459 SolarMutexGuard aGuard;
460 if ( !mpObj )
461 throw uno::RuntimeException();
463 uno::Reference< embed::XInplaceObject > xInplace( mpObj->GetObjRef(), uno::UNO_QUERY_THROW );
465 // check if the change is at least one pixel in size
466 awt::Rectangle aOldRect = getPlacement();
467 tools::Rectangle aNewPixelRect = VCLRectangle( aPosRect );
468 tools::Rectangle aOldPixelRect = VCLRectangle( aOldRect );
469 if ( aOldPixelRect == aNewPixelRect )
470 // nothing has changed
471 return;
473 // new scaled object area
474 MapUnit aContainerMapUnit( MapUnit::Map100thMM );
475 uno::Reference< embed::XVisualObject > xParentVis( mpObj->GetParentXModel(), uno::UNO_QUERY );
476 if ( xParentVis.is() )
477 aContainerMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xParentVis->getMapUnit( mpObj->GetAspect() ) );
479 tools::Rectangle aNewLogicRect = Application::GetDefaultDevice()->PixelToLogic(aNewPixelRect, MapMode(aContainerMapUnit));
480 tools::Rectangle aLogicRect = impl_getScaledRect_nothrow();
482 if ( aNewLogicRect != aLogicRect )
484 // the calculation of the object area has not changed the object size
485 // it should be done here then
486 //SfxBooleanFlagGuard aGuard( m_bResizeNoScale, true );
488 // new size of the object area without scaling
489 Size aNewObjSize( long( aNewLogicRect.GetWidth() / m_aScaleWidth ),
490 long( aNewLogicRect.GetHeight() / m_aScaleHeight ) );
492 // now remove scaling from new placement and keep this a the new object area
493 aNewLogicRect.SetSize( aNewObjSize );
494 // react to the change if the difference is bigger than one pixel
495 Size aPixelDiff =
496 Application::GetDefaultDevice()->LogicToPixel(
497 Size( aLogicRect.GetWidth() - aNewObjSize.Width(),
498 aLogicRect.GetHeight() - aNewObjSize.Height() ),
499 MapMode(aContainerMapUnit));
500 if( aPixelDiff.Width() || aPixelDiff.Height() )
502 mpObj->SetLogicRect( tools::Rectangle( aLogicRect.TopLeft(), aNewObjSize ) );
503 mpObj->BroadcastObjectChange();
505 else
506 mpObj->ActionChanged();
509 // XWindowSupplier
511 uno::Reference< awt::XWindow > SAL_CALL SdrLightEmbeddedClient_Impl::getWindow()
513 SolarMutexGuard aGuard;
514 uno::Reference< awt::XWindow > xCurrent = m_xWindow;
515 if ( !xCurrent.is() )
517 if ( !mpObj )
518 throw uno::RuntimeException();
519 uno::Reference< frame::XFrame> xFrame(lcl_getFrame_throw(mpObj),uno::UNO_QUERY_THROW);
520 xCurrent = xFrame->getComponentWindow();
521 } // if ( !xCurrent.is() )
522 return xCurrent;
524 void SdrLightEmbeddedClient_Impl::setWindow(const uno::Reference< awt::XWindow >& _xWindow)
526 m_xWindow = _xWindow;
529 SdrEmbedObjectLink::SdrEmbedObjectLink(SdrOle2Obj* pObject):
530 ::sfx2::SvBaseLink( ::SfxLinkUpdateMode::ONCALL, SotClipboardFormatId::SVXB ),
531 pObj(pObject)
533 SetSynchron( false );
536 SdrEmbedObjectLink::~SdrEmbedObjectLink()
540 ::sfx2::SvBaseLink::UpdateResult SdrEmbedObjectLink::DataChanged(
541 const OUString& /*rMimeType*/, const css::uno::Any & /*rValue*/ )
543 if ( !pObj->UpdateLinkURL_Impl() )
545 // the link URL was not changed
546 uno::Reference< embed::XEmbeddedObject > xObject = pObj->GetObjRef();
547 OSL_ENSURE( xObject.is(), "The object must exist always!" );
548 if ( xObject.is() )
550 // let the object reload the link
551 // TODO/LATER: reload call could be used for this case
555 sal_Int32 nState = xObject->getCurrentState();
556 if ( nState != embed::EmbedStates::LOADED )
558 // in some cases the linked file probably is not locked so it could be changed
559 xObject->changeState( embed::EmbedStates::LOADED );
560 xObject->changeState( nState );
563 catch ( uno::Exception& )
569 pObj->GetNewReplacement();
570 pObj->SetChanged();
572 return SUCCESS;
575 void SdrEmbedObjectLink::Closed()
577 pObj->BreakFileLink_Impl();
578 SvBaseLink::Closed();
581 class SdrOle2ObjImpl
583 public:
584 svt::EmbeddedObjectRef mxObjRef;
586 std::unique_ptr<Graphic> mxGraphic;
587 OUString maProgName;
588 OUString aPersistName; // name of object in persist
589 rtl::Reference<SdrLightEmbeddedClient_Impl> mxLightClient; // must be registered as client only using AddOwnLightClient() call
591 bool mbFrame:1; // Due to compatibility at SdrTextObj for now
592 bool mbSuppressSetVisAreaSize:1; // #i118524#
593 mutable bool mbTypeAsked:1;
594 mutable bool mbIsChart:1;
595 bool mbLoadingOLEObjectFailed:1; // New local var to avoid repeated loading if load of OLE2 fails
596 bool mbConnected:1;
598 SdrEmbedObjectLink* mpObjectLink;
599 OUString maLinkURL;
601 rtl::Reference<SvxUnoShapeModifyListener> mxModifyListener;
603 explicit SdrOle2ObjImpl( bool bFrame ) :
604 mbFrame(bFrame),
605 mbSuppressSetVisAreaSize(false),
606 mbTypeAsked(false),
607 mbIsChart(false),
608 mbLoadingOLEObjectFailed(false),
609 mbConnected(false),
610 mpObjectLink(nullptr)
612 mxObjRef.Lock();
615 SdrOle2ObjImpl( bool bFrame, const svt::EmbeddedObjectRef& rObjRef ) :
616 mxObjRef(rObjRef),
617 mbFrame(bFrame),
618 mbSuppressSetVisAreaSize(false),
619 mbTypeAsked(false),
620 mbIsChart(false),
621 mbLoadingOLEObjectFailed(false),
622 mbConnected(false),
623 mpObjectLink(nullptr)
625 mxObjRef.Lock();
628 ~SdrOle2ObjImpl()
630 mxGraphic.reset();
632 if (mxModifyListener.is())
634 mxModifyListener->invalidate();
639 // Predicate determining whether the given OLE is an internal math
640 // object
641 static bool ImplIsMathObj( const uno::Reference < embed::XEmbeddedObject >& rObjRef )
643 if ( !rObjRef.is() )
644 return false;
646 SvGlobalName aClassName( rObjRef->getClassID() );
647 return aClassName == SvGlobalName(SO3_SM_CLASSID_30) ||
648 aClassName == SvGlobalName(SO3_SM_CLASSID_40) ||
649 aClassName == SvGlobalName(SO3_SM_CLASSID_50) ||
650 aClassName == SvGlobalName(SO3_SM_CLASSID_60) ||
651 aClassName == SvGlobalName(SO3_SM_CLASSID);
654 // BaseProperties section
656 sdr::properties::BaseProperties* SdrOle2Obj::CreateObjectSpecificProperties()
658 return new sdr::properties::OleProperties(*this);
661 // DrawContact section
663 sdr::contact::ViewContact* SdrOle2Obj::CreateObjectSpecificViewContact()
665 return new sdr::contact::ViewContactOfSdrOle2Obj(*this);
668 SdrOle2Obj::SdrOle2Obj( bool bFrame_ ) :
669 mpImpl(new SdrOle2ObjImpl(bFrame_))
673 SdrOle2Obj::SdrOle2Obj( const svt::EmbeddedObjectRef& rNewObjRef, const OUString& rNewObjName, const tools::Rectangle& rNewRect) :
674 SdrRectObj(rNewRect),
675 mpImpl(new SdrOle2ObjImpl(false/*bFrame_*/, rNewObjRef))
677 mpImpl->aPersistName = rNewObjName;
679 if (mpImpl->mxObjRef.is() && (mpImpl->mxObjRef->getStatus( GetAspect() ) & embed::EmbedMisc::EMBED_NEVERRESIZE ) )
680 SetResizeProtect(true);
682 // For math objects, set closed state to transparent
683 SetClosedObj(!ImplIsMathObj( mpImpl->mxObjRef.GetObject() ));
686 OUString SdrOle2Obj::GetStyleString()
688 OUString strStyle;
689 if (mpImpl->mxObjRef.is() && mpImpl->mxObjRef.IsChart())
691 strStyle = mpImpl->mxObjRef.GetChartType();
693 return strStyle;
696 SdrOle2Obj::~SdrOle2Obj()
698 if ( mpImpl->mbConnected )
699 Disconnect();
701 DisconnectFileLink_Impl();
703 mpImpl->mxLightClient.clear();
706 void SdrOle2Obj::SetAspect( sal_Int64 nAspect )
708 mpImpl->mxObjRef.SetViewAspect( nAspect );
711 const svt::EmbeddedObjectRef& SdrOle2Obj::getEmbeddedObjectRef() const
713 return mpImpl->mxObjRef;
716 sal_Int64 SdrOle2Obj::GetAspect() const
718 return mpImpl->mxObjRef.GetViewAspect();
721 bool SdrOle2Obj::isInplaceActive() const
723 return mpImpl->mxObjRef.is() && embed::EmbedStates::INPLACE_ACTIVE == mpImpl->mxObjRef->getCurrentState();
726 bool SdrOle2Obj::isUiActive() const
728 return mpImpl->mxObjRef.is() && embed::EmbedStates::UI_ACTIVE == mpImpl->mxObjRef->getCurrentState();
731 void SdrOle2Obj::SetGraphic(const Graphic& rGrf)
733 // only for setting a preview graphic
734 mpImpl->mxGraphic.reset(new Graphic(rGrf));
736 SetChanged();
737 BroadcastObjectChange();
740 void SdrOle2Obj::ClearGraphic()
742 mpImpl->mxGraphic.reset();
744 SetChanged();
745 BroadcastObjectChange();
748 void SdrOle2Obj::SetProgName( const OUString& rName )
750 mpImpl->maProgName = rName;
753 const OUString& SdrOle2Obj::GetProgName() const
755 return mpImpl->maProgName;
758 bool SdrOle2Obj::IsEmpty() const
760 return !mpImpl->mxObjRef.is();
763 void SdrOle2Obj::Connect()
765 if( IsEmptyPresObj() )
766 return;
768 if( mpImpl->mbConnected )
770 // currently there are situations where it seems to be unavoidable to have multiple connects
771 // changing this would need a larger code rewrite, so for now I remove the assertion
772 // OSL_FAIL("Connect() called on connected object!");
773 return;
776 Connect_Impl();
777 AddListeners_Impl();
780 bool SdrOle2Obj::UpdateLinkURL_Impl()
782 bool bResult = false;
784 if ( mpImpl->mpObjectLink )
786 sfx2::LinkManager* pLinkManager = pModel ? pModel->GetLinkManager() : nullptr;
787 if ( pLinkManager )
789 OUString aNewLinkURL;
790 sfx2::LinkManager::GetDisplayNames( mpImpl->mpObjectLink, nullptr, &aNewLinkURL );
791 if ( !aNewLinkURL.equalsIgnoreAsciiCase( mpImpl->maLinkURL ) )
793 GetObjRef_Impl();
794 uno::Reference<embed::XCommonEmbedPersist> xPersObj( mpImpl->mxObjRef.GetObject(), uno::UNO_QUERY );
795 OSL_ENSURE( xPersObj.is(), "The object must exist!" );
796 if ( xPersObj.is() )
800 sal_Int32 nCurState = mpImpl->mxObjRef->getCurrentState();
801 if ( nCurState != embed::EmbedStates::LOADED )
802 mpImpl->mxObjRef->changeState(embed::EmbedStates::LOADED);
804 // TODO/LATER: there should be possible to get current mediadescriptor settings from the object
805 uno::Sequence< beans::PropertyValue > aArgs( 1 );
806 aArgs[0].Name = "URL";
807 aArgs[0].Value <<= aNewLinkURL;
808 xPersObj->reload( aArgs, uno::Sequence< beans::PropertyValue >() );
810 mpImpl->maLinkURL = aNewLinkURL;
811 bResult = true;
813 if ( nCurState != embed::EmbedStates::LOADED )
814 mpImpl->mxObjRef->changeState(nCurState);
816 catch( css::uno::Exception const & )
818 SAL_WARN( "svx", "SdrOle2Obj::UpdateLinkURL_Impl(), exception caught: "
819 << comphelper::anyToString( cppu::getCaughtException() ) );
823 if ( !bResult )
825 // TODO/LATER: return the old name to the link manager, is it possible?
831 return bResult;
834 void SdrOle2Obj::BreakFileLink_Impl()
836 uno::Reference<document::XStorageBasedDocument> xDoc;
837 if ( pModel )
838 xDoc.set( pModel->getUnoModel(),uno::UNO_QUERY);
840 if ( xDoc.is() )
842 uno::Reference< embed::XStorage > xStorage = xDoc->getDocumentStorage();
843 if ( xStorage.is() )
847 uno::Reference< embed::XLinkageSupport > xLinkSupport( mpImpl->mxObjRef.GetObject(), uno::UNO_QUERY_THROW );
848 xLinkSupport->breakLink( xStorage, mpImpl->aPersistName );
849 DisconnectFileLink_Impl();
850 mpImpl->maLinkURL.clear();
852 catch( css::uno::Exception& )
854 SAL_WARN( "svx", "SdrOle2Obj::BreakFileLink_Impl(), exception caught: "
855 << comphelper::anyToString( cppu::getCaughtException() ) );
861 void SdrOle2Obj::DisconnectFileLink_Impl()
863 sfx2::LinkManager* pLinkManager = pModel ? pModel->GetLinkManager() : nullptr;
864 if ( pLinkManager && mpImpl->mpObjectLink )
866 pLinkManager->Remove( mpImpl->mpObjectLink );
867 mpImpl->mpObjectLink = nullptr;
871 void SdrOle2Obj::CheckFileLink_Impl()
873 if (pModel && mpImpl->mxObjRef.GetObject().is() && !mpImpl->mpObjectLink)
877 uno::Reference< embed::XLinkageSupport > xLinkSupport( mpImpl->mxObjRef.GetObject(), uno::UNO_QUERY );
878 if ( xLinkSupport.is() && xLinkSupport->isLink() )
880 OUString aLinkURL = xLinkSupport->getLinkURL();
881 if ( !aLinkURL.isEmpty() )
883 // this is a file link so the model link manager should handle it
884 sfx2::LinkManager* pLinkManager = pModel->GetLinkManager();
885 if ( pLinkManager )
887 mpImpl->mpObjectLink = new SdrEmbedObjectLink( this );
888 mpImpl->maLinkURL = aLinkURL;
889 pLinkManager->InsertFileLink( *mpImpl->mpObjectLink, OBJECT_CLIENT_OLE, aLinkURL );
890 mpImpl->mpObjectLink->Connect();
895 catch (const css::uno::Exception& e)
897 SAL_WARN("svx", "SdrOle2Obj::CheckFileLink_Impl(), " << e);
902 void SdrOle2Obj::Reconnect_Impl()
904 DBG_ASSERT( mpImpl->mbConnected, "Assigned unconnected object?!" );
905 Connect_Impl();
908 void SdrOle2Obj::Connect_Impl()
910 if( pModel && !mpImpl->aPersistName.isEmpty() )
914 ::comphelper::IEmbeddedHelper* pPers = pModel->GetPersist();
915 if ( pPers )
917 comphelper::EmbeddedObjectContainer& rContainer = pPers->getEmbeddedObjectContainer();
918 if ( !rContainer.HasEmbeddedObject( mpImpl->aPersistName )
919 || ( mpImpl->mxObjRef.is() && !rContainer.HasEmbeddedObject( mpImpl->mxObjRef.GetObject() ) ) )
921 // object not known to container document
922 // No object -> disaster!
923 DBG_ASSERT( mpImpl->mxObjRef.is(), "No object in connect!");
924 if ( mpImpl->mxObjRef.is() )
926 // object came from the outside, now add it to the container
927 OUString aTmp;
928 rContainer.InsertEmbeddedObject( mpImpl->mxObjRef.GetObject(), aTmp );
929 mpImpl->aPersistName = aTmp;
932 else if ( !mpImpl->mxObjRef.is() )
934 mpImpl->mxObjRef.Assign( rContainer.GetEmbeddedObject( mpImpl->aPersistName ), mpImpl->mxObjRef.GetViewAspect() );
935 mpImpl->mbTypeAsked = false;
938 if ( mpImpl->mxObjRef.GetObject().is() )
940 mpImpl->mxObjRef.AssignToContainer( &rContainer, mpImpl->aPersistName );
941 mpImpl->mbConnected = true;
942 mpImpl->mxObjRef.Lock();
946 if ( mpImpl->mxObjRef.is() )
948 if ( !mpImpl->mxLightClient.is() )
949 mpImpl->mxLightClient = new SdrLightEmbeddedClient_Impl( this );
951 mpImpl->mxObjRef->addStateChangeListener( mpImpl->mxLightClient.get() );
952 mpImpl->mxObjRef->addEventListener( uno::Reference< document::XEventListener >( mpImpl->mxLightClient.get() ) );
954 if ( mpImpl->mxObjRef->getCurrentState() != embed::EmbedStates::LOADED )
955 GetSdrGlobalData().GetOLEObjCache().InsertObj(this);
957 CheckFileLink_Impl();
959 uno::Reference< container::XChild > xChild( mpImpl->mxObjRef.GetObject(), uno::UNO_QUERY );
960 if( xChild.is() )
962 uno::Reference< uno::XInterface > xParent( pModel->getUnoModel());
963 if( xParent.is())
964 xChild->setParent( pModel->getUnoModel() );
969 catch( css::uno::Exception& )
971 SAL_WARN( "svx", "SdrOle2Obj::Connect_Impl(), exception caught: "
972 << comphelper::anyToString( cppu::getCaughtException() ) );
977 void SdrOle2Obj::ObjectLoaded()
979 AddListeners_Impl();
982 void SdrOle2Obj::AddListeners_Impl()
984 if( mpImpl->mxObjRef.is() && mpImpl->mxObjRef->getCurrentState() != embed::EmbedStates::LOADED )
986 // register modify listener
987 if (!mpImpl->mxModifyListener.is())
989 mpImpl->mxModifyListener = new SvxUnoShapeModifyListener(this);
992 uno::Reference< util::XModifyBroadcaster > xBC( getXModel(), uno::UNO_QUERY );
993 if (xBC.is())
995 uno::Reference<util::XModifyListener> xListener(mpImpl->mxModifyListener.get());
996 xBC->addModifyListener( xListener );
1001 void SdrOle2Obj::Disconnect()
1003 if( IsEmptyPresObj() )
1004 return;
1006 if( !mpImpl->mbConnected )
1008 OSL_FAIL("Disconnect() called on disconnected object!");
1009 return;
1012 RemoveListeners_Impl();
1013 Disconnect_Impl();
1016 void SdrOle2Obj::RemoveListeners_Impl()
1018 if ( mpImpl->mxObjRef.is() && !mpImpl->aPersistName.isEmpty() )
1022 sal_Int32 nState = mpImpl->mxObjRef->getCurrentState();
1023 if ( nState != embed::EmbedStates::LOADED )
1025 uno::Reference< util::XModifyBroadcaster > xBC( getXModel(), uno::UNO_QUERY );
1026 if (xBC.is() && mpImpl->mxModifyListener.is())
1028 uno::Reference<util::XModifyListener> xListener(mpImpl->mxModifyListener.get());
1029 xBC->removeModifyListener( xListener );
1033 catch( css::uno::Exception& )
1035 SAL_WARN( "svx", "SdrOle2Obj::RemoveListeners_Impl(), exception caught: "
1036 << comphelper::anyToString( cppu::getCaughtException() ) );
1041 void SdrOle2Obj::Disconnect_Impl()
1045 if ( pModel && !mpImpl->aPersistName.isEmpty() )
1047 if( pModel->IsInDestruction() )
1049 // TODO/LATER: here we must assume that the destruction of the model is enough to make clear that we will not
1050 // remove the object from the container, even if the DrawingObject itself is not destroyed (unfortunately this
1051 // There is no real need to do the following removing of the object from the container
1052 // in case the model has correct persistence, but in case of problems such a removing
1053 // would make the behavior of the office more stable
1055 comphelper::EmbeddedObjectContainer* pContainer = mpImpl->mxObjRef.GetContainer();
1056 if ( pContainer )
1058 pContainer->CloseEmbeddedObject( mpImpl->mxObjRef.GetObject() );
1059 mpImpl->mxObjRef.AssignToContainer( nullptr, mpImpl->aPersistName );
1062 // happens later than the destruction of the model, so we can't assert that).
1063 //DBG_ASSERT( bInDestruction, "Model is destroyed, but not me?!" );
1064 //TODO/LATER: should be make sure that the ObjectShell also forgets the object, because we will close it soon?
1066 uno::Reference < util::XCloseable > xClose( xObjRef, uno::UNO_QUERY );
1067 if ( xClose.is() )
1071 xClose->close( true );
1073 catch ( util::CloseVetoException& )
1075 // there's still someone who needs the object!
1079 xObjRef = NULL;*/
1081 else if ( mpImpl->mxObjRef.is() )
1083 if ( pModel->getUnoModel().is() )
1085 // remove object, but don't close it (that's up to someone else)
1086 comphelper::EmbeddedObjectContainer* pContainer = mpImpl->mxObjRef.GetContainer();
1087 if ( pContainer )
1089 pContainer->RemoveEmbeddedObject( mpImpl->mxObjRef.GetObject() );
1091 // TODO/LATER: mpImpl->aPersistName contains outdated information, to keep it updated
1092 // it should be returned from RemoveEmbeddedObject call. Currently it is no problem,
1093 // since no container is adjusted, actually the empty string could be provided as a name here
1094 mpImpl->mxObjRef.AssignToContainer( nullptr, mpImpl->aPersistName );
1097 DisconnectFileLink_Impl();
1102 if ( mpImpl->mxObjRef.is() && mpImpl->mxLightClient.is() )
1104 mpImpl->mxObjRef->removeStateChangeListener ( mpImpl->mxLightClient.get() );
1105 mpImpl->mxObjRef->removeEventListener( uno::Reference< document::XEventListener >( mpImpl->mxLightClient.get() ) );
1106 mpImpl->mxObjRef->setClientSite( nullptr );
1108 GetSdrGlobalData().GetOLEObjCache().RemoveObj(this);
1111 catch( css::uno::Exception& )
1113 SAL_WARN( "svx", "SdrOle2Obj::Disconnect_Impl(), exception caught: "
1114 << comphelper::anyToString( cppu::getCaughtException() ) );
1117 mpImpl->mbConnected = false;
1120 SdrObject* SdrOle2Obj::createSdrGrafObjReplacement(bool bAddText) const
1122 const Graphic* pOLEGraphic = GetGraphic();
1124 if(pOLEGraphic)
1126 // #i118485# allow creating a SdrGrafObj representation
1127 SdrGrafObj* pClone = new SdrGrafObj(*pOLEGraphic);
1128 pClone->SetModel(GetModel());
1130 // copy transformation
1131 basegfx::B2DHomMatrix aMatrix;
1132 basegfx::B2DPolyPolygon aPolyPolygon;
1134 TRGetBaseGeometry(aMatrix, aPolyPolygon);
1135 pClone->TRSetBaseGeometry(aMatrix, aPolyPolygon);
1137 // copy all attributes to support graphic styles for OLEs
1138 pClone->SetStyleSheet(GetStyleSheet(), false);
1139 pClone->SetMergedItemSet(GetMergedItemSet());
1141 if(bAddText)
1143 // #i118485# copy text (Caution! Model needed, as guaranteed in aw080)
1144 OutlinerParaObject* pOPO = GetOutlinerParaObject();
1146 if(pOPO && GetModel())
1148 pClone->NbcSetOutlinerParaObject(new OutlinerParaObject(*pOPO));
1152 return pClone;
1154 else
1156 // #i100710# pOLEGraphic may be zero (no visualisation available),
1157 // so we need to use the OLE replacement graphic
1158 SdrRectObj* pClone = new SdrRectObj(GetSnapRect());
1159 pClone->SetModel(GetModel());
1161 // gray outline
1162 pClone->SetMergedItem(XLineStyleItem(css::drawing::LineStyle_SOLID));
1163 const svtools::ColorConfig aColorConfig;
1164 const svtools::ColorConfigValue aColor(aColorConfig.GetColorValue(svtools::OBJECTBOUNDARIES));
1165 pClone->SetMergedItem(XLineColorItem(OUString(), aColor.nColor));
1167 // bitmap fill
1168 pClone->SetMergedItem(XFillStyleItem(drawing::FillStyle_BITMAP));
1169 pClone->SetMergedItem(XFillBitmapItem(OUString(), GetEmptyOLEReplacementGraphic()));
1170 pClone->SetMergedItem(XFillBmpTileItem(false));
1171 pClone->SetMergedItem(XFillBmpStretchItem(false));
1173 return pClone;
1177 SdrObject* SdrOle2Obj::DoConvertToPolyObj(bool bBezier, bool bAddText) const
1179 // #i118485# missing converter added
1180 if(GetModel())
1182 SdrObject* pRetval = createSdrGrafObjReplacement(true);
1184 if(pRetval)
1186 SdrObject* pRetval2 = pRetval->DoConvertToPolyObj(bBezier, bAddText);
1187 SdrObject::Free(pRetval);
1189 return pRetval2;
1193 return nullptr;
1196 void SdrOle2Obj::SetModel(SdrModel* pNewModel)
1198 ::comphelper::IEmbeddedHelper* pDestPers = pNewModel ? pNewModel->GetPersist() : nullptr;
1199 ::comphelper::IEmbeddedHelper* pSrcPers = pModel ? pModel->GetPersist() : nullptr;
1201 if ( pNewModel == pModel )
1203 // don't know if this is necessary or if it will ever happen, but who knows?!
1204 SdrRectObj::SetModel( pNewModel );
1205 return;
1208 // assignment to model has changed
1209 DBG_ASSERT( pSrcPers || !mpImpl->mbConnected, "Connected object without a model?!" );
1211 DBG_ASSERT( pDestPers, "The destination model must have a persistence! Please submit an issue!" );
1212 DBG_ASSERT( pDestPers != pSrcPers, "The source and the destination models should have different persistences! Problems are possible!" );
1214 // this is a bug if the target model has no persistence
1215 // no error handling is possible so just do nothing in this method
1216 if ( !pDestPers )
1217 return;
1219 RemoveListeners_Impl();
1221 if( pDestPers && pSrcPers && !IsEmptyPresObj() )
1225 // move the object's storage; ObjectRef remains the same, but PersistName may change
1226 OUString aTmp;
1227 comphelper::EmbeddedObjectContainer& rContainer = pSrcPers->getEmbeddedObjectContainer();
1228 uno::Reference < embed::XEmbeddedObject > xObj = rContainer.GetEmbeddedObject( mpImpl->aPersistName );
1229 DBG_ASSERT( !mpImpl->mxObjRef.is() || mpImpl->mxObjRef.GetObject() == xObj, "Wrong object identity!" );
1230 if ( xObj.is() )
1232 pDestPers->getEmbeddedObjectContainer().MoveEmbeddedObject( rContainer, xObj, aTmp );
1233 mpImpl->aPersistName = aTmp;
1234 mpImpl->mxObjRef.AssignToContainer( &pDestPers->getEmbeddedObjectContainer(), aTmp );
1236 DBG_ASSERT( !aTmp.isEmpty(), "Copying embedded object failed!" );
1238 catch( css::uno::Exception& )
1240 SAL_WARN( "svx", "SdrOle2Obj::SetModel(), exception caught: "
1241 << comphelper::anyToString( cppu::getCaughtException() ) );
1245 SdrRectObj::SetModel( pNewModel );
1247 // #i43086#
1248 // #i85304 redo the change for charts for the above bugfix, as #i43086# does not occur anymore
1249 //so maybe the ImpSetVisAreaSize call can be removed here completely
1250 //Nevertheless I leave it in for other objects as I am not sure about the side effects when removing now
1251 if( pModel && !pModel->isLocked() && !IsChart() )
1252 ImpSetVisAreaSize();
1254 if( pDestPers && !IsEmptyPresObj() )
1256 if ( !pSrcPers || IsEmptyPresObj() )
1257 // object wasn't connected, now it should be
1258 Connect_Impl();
1259 else
1260 Reconnect_Impl();
1263 AddListeners_Impl();
1266 void SdrOle2Obj::SetPage(SdrPage* pNewPage)
1268 bool bRemove=pNewPage==nullptr && pPage!=nullptr;
1269 bool bInsert=pNewPage!=nullptr && pPage==nullptr;
1271 if (bRemove && mpImpl->mbConnected )
1272 Disconnect();
1274 if(!pModel && !GetStyleSheet() && pNewPage && pNewPage->GetModel())
1276 // #i119287# Set default StyleSheet for SdrGrafObj here, it is different from 'Default'. This
1277 // needs to be done before the style 'Default' is set from the :SetModel() call which is triggered
1278 // from the following :SetPage().
1279 // TTTT: Needs to be moved in branch aw080 due to having a SdrModel from the beginning, is at this
1280 // place for convenience currently (works in both versions, is not in the way)
1281 SfxStyleSheet* pSheet = pNewPage->GetModel()->GetDefaultStyleSheetForSdrGrafObjAndSdrOle2Obj();
1283 if(pSheet)
1285 SetStyleSheet(pSheet, false);
1287 else
1289 SetMergedItem(XFillStyleItem(drawing::FillStyle_NONE));
1290 SetMergedItem(XLineStyleItem(drawing::LineStyle_NONE));
1294 SdrRectObj::SetPage(pNewPage);
1296 if (bInsert && !mpImpl->mbConnected )
1297 Connect();
1300 void SdrOle2Obj::SetObjRef( const css::uno::Reference < css::embed::XEmbeddedObject >& rNewObjRef )
1302 DBG_ASSERT( !rNewObjRef.is() || !mpImpl->mxObjRef.GetObject().is(), "SetObjRef called on already initialized object!");
1303 if( rNewObjRef == mpImpl->mxObjRef.GetObject() )
1304 return;
1306 // the caller of the method is responsible to control the old object, it will not be closed here
1307 // Otherwise WW8 import crashes because it transfers control to OLENode by this method
1308 if ( mpImpl->mxObjRef.GetObject().is() )
1309 mpImpl->mxObjRef.Lock( false );
1311 // avoid removal of object in Disconnect! It is definitely a HACK to call SetObjRef(0)!
1312 // This call will try to close the objects; so if anybody else wants to keep it, it must be locked by a CloseListener
1313 mpImpl->mxObjRef.Clear();
1315 if ( mpImpl->mbConnected )
1316 Disconnect();
1318 mpImpl->mxObjRef.Assign( rNewObjRef, GetAspect() );
1319 mpImpl->mbTypeAsked = false;
1321 if ( mpImpl->mxObjRef.is() )
1323 mpImpl->mxGraphic.reset();
1325 if ( mpImpl->mxObjRef->getStatus( GetAspect() ) & embed::EmbedMisc::EMBED_NEVERRESIZE )
1326 SetResizeProtect(true);
1328 // For math objects, set closed state to transparent
1329 SetClosedObj(!ImplIsMathObj( rNewObjRef ));
1331 Connect();
1334 SetChanged();
1335 BroadcastObjectChange();
1338 void SdrOle2Obj::SetClosedObj( bool bIsClosed )
1340 // TODO/LATER: do we still need this hack?
1341 // Allow changes to the closed state of OLE objects
1342 bClosedObj = bIsClosed;
1345 SdrObject* SdrOle2Obj::getFullDragClone() const
1347 // #i118485# use central replacement generator
1348 return createSdrGrafObjReplacement(false);
1351 void SdrOle2Obj::SetPersistName( const OUString& rPersistName )
1353 DBG_ASSERT( mpImpl->aPersistName.isEmpty(), "Persist name changed!");
1355 mpImpl->aPersistName = rPersistName;
1356 mpImpl->mbLoadingOLEObjectFailed = false;
1358 Connect();
1359 SetChanged();
1362 void SdrOle2Obj::AbandonObject()
1364 mpImpl->aPersistName.clear();
1365 mpImpl->mbLoadingOLEObjectFailed = false;
1366 SetObjRef(nullptr);
1369 const OUString& SdrOle2Obj::GetPersistName() const
1371 return mpImpl->aPersistName;
1374 void SdrOle2Obj::TakeObjInfo(SdrObjTransformInfoRec& rInfo) const
1376 // #i118485# Allowing much more attributes for OLEs
1377 rInfo.bRotateFreeAllowed = true;
1378 rInfo.bRotate90Allowed = true;
1379 rInfo.bMirrorFreeAllowed = true;
1380 rInfo.bMirror45Allowed = true;
1381 rInfo.bMirror90Allowed = true;
1382 rInfo.bTransparenceAllowed = true;
1383 rInfo.bShearAllowed = true;
1384 rInfo.bEdgeRadiusAllowed = false;
1385 rInfo.bNoOrthoDesired = false;
1386 rInfo.bCanConvToPath = true;
1387 rInfo.bCanConvToPoly = true;
1388 rInfo.bCanConvToPathLineToArea = false;
1389 rInfo.bCanConvToPolyLineToArea = false;
1390 rInfo.bCanConvToContour = true;
1393 sal_uInt16 SdrOle2Obj::GetObjIdentifier() const
1395 return mpImpl->mbFrame ? sal_uInt16(OBJ_FRAME) : sal_uInt16(OBJ_OLE2);
1398 OUString SdrOle2Obj::TakeObjNameSingul() const
1400 OUStringBuffer sName(ImpGetResStr(mpImpl->mbFrame ? STR_ObjNameSingulFrame : STR_ObjNameSingulOLE2));
1402 const OUString aName(GetName());
1404 if (!aName.isEmpty())
1406 sName.append(" '");
1407 sName.append(aName);
1408 sName.append('\'');
1411 return sName.makeStringAndClear();
1414 OUString SdrOle2Obj::TakeObjNamePlural() const
1416 return ImpGetResStr(mpImpl->mbFrame ? STR_ObjNamePluralFrame : STR_ObjNamePluralOLE2);
1419 SdrOle2Obj* SdrOle2Obj::Clone() const
1421 return CloneHelper< SdrOle2Obj >();
1424 SdrOle2Obj& SdrOle2Obj::assignFrom(const SdrOle2Obj& rObj)
1426 //TODO/LATER: who takes over control of my old object?!
1427 if( &rObj != this )
1429 // ImpAssign( rObj );
1430 const SdrOle2Obj& rOle2Obj = rObj;
1432 if( pModel && mpImpl->mbConnected )
1433 Disconnect();
1435 SdrRectObj::operator=( rObj );
1437 // Manually copying bClosedObj attribute
1438 SetClosedObj( rObj.IsClosedObj() );
1440 mpImpl->aPersistName = rOle2Obj.mpImpl->aPersistName;
1441 mpImpl->maProgName = rOle2Obj.mpImpl->maProgName;
1442 mpImpl->mbFrame = rOle2Obj.mpImpl->mbFrame;
1444 if (rOle2Obj.mpImpl->mxGraphic)
1446 mpImpl->mxGraphic.reset(new Graphic(*rOle2Obj.mpImpl->mxGraphic));
1449 if( pModel && rObj.GetModel() && !IsEmptyPresObj() )
1451 ::comphelper::IEmbeddedHelper* pDestPers = pModel->GetPersist();
1452 ::comphelper::IEmbeddedHelper* pSrcPers = rObj.GetModel()->GetPersist();
1453 if( pDestPers && pSrcPers )
1455 DBG_ASSERT( !mpImpl->mxObjRef.is(), "Object already existing!" );
1456 comphelper::EmbeddedObjectContainer& rContainer = pSrcPers->getEmbeddedObjectContainer();
1457 uno::Reference < embed::XEmbeddedObject > xObj = rContainer.GetEmbeddedObject( mpImpl->aPersistName );
1458 if ( xObj.is() )
1460 OUString aTmp;
1461 mpImpl->mxObjRef.Assign( pDestPers->getEmbeddedObjectContainer().CopyAndGetEmbeddedObject(
1462 rContainer, xObj, aTmp, pSrcPers->getDocumentBaseURL(), pDestPers->getDocumentBaseURL()), rOle2Obj.GetAspect());
1463 mpImpl->mbTypeAsked = false;
1464 mpImpl->aPersistName = aTmp;
1465 CheckFileLink_Impl();
1468 Connect();
1472 return *this;
1475 SdrOle2Obj& SdrOle2Obj::operator=(const SdrOle2Obj& rObj)
1477 return assignFrom(rObj);
1480 void SdrOle2Obj::ImpSetVisAreaSize()
1482 // #i118524# do not again set VisAreaSize when the call comes from OLE client (e.g. ObjectAreaChanged)
1483 if (mpImpl->mbSuppressSetVisAreaSize)
1484 return;
1486 // currently there is no need to recalculate scaling for iconified objects
1487 // TODO/LATER: it might be needed in future when it is possible to change the icon
1488 if ( GetAspect() == embed::Aspects::MSOLE_ICON )
1489 return;
1491 // the object area of an embedded object was changed, e.g. by user interaction an a selected object
1492 GetObjRef();
1493 if (mpImpl->mxObjRef.is())
1495 OSL_ASSERT( pModel );
1496 sal_Int64 nMiscStatus = mpImpl->mxObjRef->getStatus( GetAspect() );
1498 // the client is required to get access to scaling
1499 SfxInPlaceClient* pClient = SfxInPlaceClient::GetClient( dynamic_cast<SfxObjectShell*>(pModel->GetPersist()), mpImpl->mxObjRef.GetObject() );
1500 bool bHasOwnClient =
1501 ( mpImpl->mxLightClient.is()
1502 && mpImpl->mxObjRef->getClientSite() == uno::Reference< embed::XEmbeddedClient >( mpImpl->mxLightClient.get() ) );
1504 if ( pClient || bHasOwnClient )
1506 // TODO: IMHO we need to do similar things when object is UIActive or OutplaceActive?!
1507 if ( ((nMiscStatus & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE) &&
1508 svt::EmbeddedObjectRef::TryRunningState( mpImpl->mxObjRef.GetObject() ))
1509 || mpImpl->mxObjRef->getCurrentState() == embed::EmbedStates::INPLACE_ACTIVE
1512 Fraction aScaleWidth;
1513 Fraction aScaleHeight;
1514 if ( pClient )
1516 aScaleWidth = pClient->GetScaleWidth();
1517 aScaleHeight = pClient->GetScaleHeight();
1519 else
1521 aScaleWidth = mpImpl->mxLightClient->GetScaleWidth();
1522 aScaleHeight = mpImpl->mxLightClient->GetScaleHeight();
1525 // The object wants to resize itself (f.e. Chart wants to recalculate the layout)
1526 // or object is inplace active and so has a window that must be resized also
1527 // In these cases the change in the object area size will be reflected in a change of the
1528 // objects' visual area. The scaling will not change, but it might exist already and must
1529 // be used in calculations
1530 MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( mpImpl->mxObjRef->getMapUnit( GetAspect() ) );
1531 Size aVisSize( (long)( Fraction( maRect.GetWidth() ) / aScaleWidth ),
1532 (long)( Fraction( maRect.GetHeight() ) / aScaleHeight ) );
1534 aVisSize = OutputDevice::LogicToLogic(aVisSize, MapMode(pModel->GetScaleUnit()), MapMode(aMapUnit));
1535 awt::Size aSz;
1536 aSz.Width = aVisSize.Width();
1537 aSz.Height = aVisSize.Height();
1538 mpImpl->mxObjRef->setVisualAreaSize( GetAspect(), aSz );
1542 aSz = mpImpl->mxObjRef->getVisualAreaSize( GetAspect() );
1544 catch( embed::NoVisualAreaSizeException& )
1547 tools::Rectangle aAcceptedVisArea;
1548 aAcceptedVisArea.SetSize( Size( (long)( Fraction( long( aSz.Width ) ) * aScaleWidth ),
1549 (long)( Fraction( long( aSz.Height ) ) * aScaleHeight ) ) );
1550 if (aVisSize != aAcceptedVisArea.GetSize())
1552 // server changed VisArea to its liking and the VisArea is different than the suggested one
1553 // store the new value as given by the object
1554 MapUnit aNewMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( mpImpl->mxObjRef->getMapUnit( GetAspect() ) );
1555 maRect.SetSize(OutputDevice::LogicToLogic(aAcceptedVisArea.GetSize(), MapMode(aNewMapUnit), MapMode(pModel->GetScaleUnit())));
1558 // make the new object area known to the client
1559 // compared to the "else" branch aRect might have been changed by the object and no additional scaling was applied
1560 // WHY this -> OSL_ASSERT( pClient );
1561 if( pClient )
1562 pClient->SetObjArea(maRect);
1564 // we need a new replacement image as the object has resized itself
1566 //#i79578# don't request a new replacement image for charts to often
1567 //a chart sends a modified call to the framework if it was changed
1568 //thus the replacement update is already handled there
1569 if( !IsChart() )
1570 mpImpl->mxObjRef.UpdateReplacement();
1572 else
1574 // The object isn't active and does not want to resize itself so the changed object area size
1575 // will be reflected in a changed object scaling
1576 Fraction aScaleWidth;
1577 Fraction aScaleHeight;
1578 Size aObjAreaSize;
1579 if ( CalculateNewScaling( aScaleWidth, aScaleHeight, aObjAreaSize ) )
1581 if ( pClient )
1583 tools::Rectangle aScaleRect(maRect.TopLeft(), aObjAreaSize);
1584 pClient->SetObjAreaAndScale( aScaleRect, aScaleWidth, aScaleHeight);
1586 else
1588 mpImpl->mxLightClient->SetSizeScale( aScaleWidth, aScaleHeight );
1593 else if( (nMiscStatus & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE) &&
1594 svt::EmbeddedObjectRef::TryRunningState( mpImpl->mxObjRef.GetObject() ) )
1596 //also handle not sfx based ole objects e.g. charts
1597 //#i83860# resizing charts in impress distorts fonts
1598 uno::Reference< embed::XVisualObject > xVisualObject( getXModel(), uno::UNO_QUERY );
1599 if( xVisualObject.is() )
1601 MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( mpImpl->mxObjRef->getMapUnit( GetAspect() ) );
1602 Point aTL( maRect.TopLeft() );
1603 Point aBR( maRect.BottomRight() );
1604 Point aTL2(OutputDevice::LogicToLogic(aTL, MapMode(pModel->GetScaleUnit()), MapMode(aMapUnit)));
1605 Point aBR2(OutputDevice::LogicToLogic(aBR, MapMode(pModel->GetScaleUnit()), MapMode(aMapUnit)));
1606 tools::Rectangle aNewRect( aTL2, aBR2 );
1607 xVisualObject->setVisualAreaSize( GetAspect(), awt::Size( aNewRect.GetWidth(), aNewRect.GetHeight() ) );
1613 void SdrOle2Obj::NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact)
1615 if( pModel && !pModel->isLocked() )
1617 GetObjRef();
1618 if ( mpImpl->mxObjRef.is() && ( mpImpl->mxObjRef->getStatus( GetAspect() ) & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE ) )
1620 // if the object needs recompose on resize
1621 // the client site should be created before the resize will take place
1622 // check whether there is no client site and create it if necessary
1623 AddOwnLightClient();
1627 SdrRectObj::NbcResize(rRef,xFact,yFact);
1628 if( pModel && !pModel->isLocked() )
1629 ImpSetVisAreaSize();
1632 void SdrOle2Obj::SetGeoData(const SdrObjGeoData& rGeo)
1634 SdrRectObj::SetGeoData(rGeo);
1636 if( pModel && !pModel->isLocked() )
1637 ImpSetVisAreaSize();
1640 void SdrOle2Obj::NbcSetSnapRect(const tools::Rectangle& rRect)
1642 SdrRectObj::NbcSetSnapRect(rRect);
1644 if( pModel && !pModel->isLocked() )
1645 ImpSetVisAreaSize();
1647 if ( mpImpl->mxObjRef.is() && IsChart() )
1649 //#i103460# charts do not necessarily have an own size within ODF files,
1650 //for this case they need to use the size settings from the surrounding frame,
1651 //which is made available with this method as there is no other way
1652 mpImpl->mxObjRef.SetDefaultSizeForChart( Size( rRect.GetWidth(), rRect.GetHeight() ) );
1656 void SdrOle2Obj::NbcSetLogicRect(const tools::Rectangle& rRect)
1658 SdrRectObj::NbcSetLogicRect(rRect);
1660 if( pModel && !pModel->isLocked() )
1661 ImpSetVisAreaSize();
1664 const Graphic* SdrOle2Obj::GetGraphic() const
1666 if ( mpImpl->mxObjRef.is() )
1667 return mpImpl->mxObjRef.GetGraphic();
1668 return mpImpl->mxGraphic.get();
1671 void SdrOle2Obj::GetNewReplacement()
1673 if ( mpImpl->mxObjRef.is() )
1674 mpImpl->mxObjRef.UpdateReplacement();
1677 Size SdrOle2Obj::GetOrigObjSize( MapMode const * pTargetMapMode ) const
1679 return mpImpl->mxObjRef.GetSize( pTargetMapMode );
1682 void SdrOle2Obj::setSuppressSetVisAreaSize( bool bNew )
1684 mpImpl->mbSuppressSetVisAreaSize = bNew;
1687 void SdrOle2Obj::NbcMove(const Size& rSize)
1689 SdrRectObj::NbcMove(rSize);
1691 if( pModel && !pModel->isLocked() )
1692 ImpSetVisAreaSize();
1695 bool SdrOle2Obj::CanUnloadRunningObj( const uno::Reference< embed::XEmbeddedObject >& xObj, sal_Int64 nAspect )
1697 uno::Reference<embed::XEmbedPersist2> xPersist(xObj, uno::UNO_QUERY);
1698 if (xPersist.is())
1700 if (!xPersist->isStored())
1701 // It doesn't have persistent storage. We can't unload this.
1702 return false;
1705 bool bResult = false;
1707 sal_Int32 nState = xObj->getCurrentState();
1708 if ( nState == embed::EmbedStates::LOADED )
1710 // the object is already unloaded
1711 bResult = true;
1713 else
1715 uno::Reference < util::XModifiable > xModifiable( xObj->getComponent(), uno::UNO_QUERY );
1716 if ( !xModifiable.is() )
1717 bResult = true;
1718 else
1720 sal_Int64 nMiscStatus = xObj->getStatus( nAspect );
1722 if ( embed::EmbedMisc::MS_EMBED_ALWAYSRUN != ( nMiscStatus & embed::EmbedMisc::MS_EMBED_ALWAYSRUN ) &&
1723 embed::EmbedMisc::EMBED_ACTIVATEIMMEDIATELY != ( nMiscStatus & embed::EmbedMisc::EMBED_ACTIVATEIMMEDIATELY ) &&
1724 !( xModifiable.is() && xModifiable->isModified() ) &&
1725 !( nState == embed::EmbedStates::INPLACE_ACTIVE || nState == embed::EmbedStates::UI_ACTIVE || nState == embed::EmbedStates::ACTIVE ) )
1727 bResult = true;
1732 return bResult;
1735 bool SdrOle2Obj::Unload( const uno::Reference< embed::XEmbeddedObject >& xObj, sal_Int64 nAspect )
1737 bool bResult = false;
1739 if ( CanUnloadRunningObj( xObj, nAspect ) )
1743 xObj->changeState( embed::EmbedStates::LOADED );
1744 bResult = true;
1746 catch( css::uno::Exception& )
1748 SAL_WARN( "svx", "SdrOle2Obj::Unload=(), exception caught: "
1749 << comphelper::anyToString( cppu::getCaughtException() ) );
1753 return bResult;
1756 bool SdrOle2Obj::Unload()
1758 if (!mpImpl->mxObjRef.is())
1759 // Already unloaded.
1760 return true;
1762 bool bUnloaded = false;
1763 if ( pModel && mpImpl->mxObjRef.is() )
1765 bUnloaded = Unload( mpImpl->mxObjRef.GetObject(), GetAspect() );
1768 return bUnloaded;
1771 void SdrOle2Obj::GetObjRef_Impl()
1773 if ( !mpImpl->mxObjRef.is() && !mpImpl->aPersistName.isEmpty() && pModel && pModel->GetPersist() )
1775 // Only try loading if it did not went wrong up to now
1776 if(!mpImpl->mbLoadingOLEObjectFailed)
1778 mpImpl->mxObjRef.Assign( pModel->GetPersist()->getEmbeddedObjectContainer().GetEmbeddedObject( mpImpl->aPersistName ), GetAspect() );
1779 mpImpl->mbTypeAsked = false;
1780 CheckFileLink_Impl();
1782 // If loading of OLE object failed, remember that to not invoke a endless
1783 // loop trying to load it again and again.
1784 if( mpImpl->mxObjRef.is() )
1786 mpImpl->mbLoadingOLEObjectFailed = true;
1789 // For math objects, set closed state to transparent
1790 SetClosedObj(!ImplIsMathObj( mpImpl->mxObjRef.GetObject() ));
1793 if ( mpImpl->mxObjRef.is() )
1795 if( !IsEmptyPresObj() )
1797 // remember modified status of model
1798 const bool bWasChanged = pModel && pModel->IsChanged();
1800 // perhaps preview not valid anymore
1801 // This line changes the modified state of the model
1802 ClearGraphic();
1804 // if status was not set before, force it back
1805 // to not set, so that SetGraphic(0) above does not
1806 // set the modified state of the model.
1807 if(!bWasChanged && pModel && pModel->IsChanged())
1809 pModel->SetChanged( false );
1814 if ( mpImpl->mxObjRef.is() )
1815 Connect();
1818 if ( mpImpl->mbConnected )
1819 // move object to first position in cache
1820 GetSdrGlobalData().GetOLEObjCache().InsertObj(this);
1823 uno::Reference < embed::XEmbeddedObject > SdrOle2Obj::GetObjRef() const
1825 const_cast<SdrOle2Obj*>(this)->GetObjRef_Impl();
1826 return mpImpl->mxObjRef.GetObject();
1829 uno::Reference < embed::XEmbeddedObject > SdrOle2Obj::GetObjRef_NoInit() const
1831 return mpImpl->mxObjRef.GetObject();
1834 uno::Reference< frame::XModel > SdrOle2Obj::getXModel() const
1836 GetObjRef();
1837 if ( svt::EmbeddedObjectRef::TryRunningState(mpImpl->mxObjRef.GetObject()) )
1838 return uno::Reference< frame::XModel >( mpImpl->mxObjRef->getComponent(), uno::UNO_QUERY );
1839 else
1840 return uno::Reference< frame::XModel >();
1843 bool SdrOle2Obj::IsChart() const
1845 if (!mpImpl->mbTypeAsked)
1847 mpImpl->mbIsChart = mpImpl->mxObjRef.IsChart();
1848 mpImpl->mbTypeAsked = true;
1850 return mpImpl->mbIsChart;
1853 bool SdrOle2Obj::IsReal3DChart() const
1855 if (!IsChart())
1856 return false;
1858 uno::Reference<chart2::XChartDocument> xChart2Document(getXModel(), uno::UNO_QUERY);
1859 uno::Reference<chart2::XDiagram> xChart2Diagram(xChart2Document->getFirstDiagram(), uno::UNO_QUERY);
1861 if (!xChart2Diagram.is())
1862 return false;
1864 return ChartHelper::isGL3DDiagram(xChart2Diagram);
1867 void SdrOle2Obj::SetGraphicToObj( const Graphic& aGraphic, const OUString& aMediaType )
1869 mpImpl->mxObjRef.SetGraphic( aGraphic, aMediaType );
1872 void SdrOle2Obj::SetGraphicToObj( const uno::Reference< io::XInputStream >& xGrStream, const OUString& aMediaType )
1874 mpImpl->mxObjRef.SetGraphicStream( xGrStream, aMediaType );
1877 bool SdrOle2Obj::IsCalc() const
1879 if ( !mpImpl->mxObjRef.is() )
1880 return false;
1882 SvGlobalName aObjClsId( mpImpl->mxObjRef->getClassID() );
1883 return SvGlobalName(SO3_SC_CLASSID_30) == aObjClsId
1884 || SvGlobalName(SO3_SC_CLASSID_40) == aObjClsId
1885 || SvGlobalName(SO3_SC_CLASSID_50) == aObjClsId
1886 || SvGlobalName(SO3_SC_CLASSID_60) == aObjClsId
1887 || SvGlobalName(SO3_SC_OLE_EMBED_CLASSID_60) == aObjClsId
1888 || SvGlobalName(SO3_SC_OLE_EMBED_CLASSID_8) == aObjClsId
1889 || SvGlobalName(SO3_SC_CLASSID) == aObjClsId;
1892 uno::Reference< frame::XModel > SdrOle2Obj::GetParentXModel() const
1894 uno::Reference< frame::XModel > xDoc;
1895 if ( pModel )
1896 xDoc.set( pModel->getUnoModel(),uno::UNO_QUERY);
1897 return xDoc;
1900 bool SdrOle2Obj::CalculateNewScaling( Fraction& aScaleWidth, Fraction& aScaleHeight, Size& aObjAreaSize )
1902 // TODO/LEAN: to avoid rounding errors scaling always uses the VisArea.
1903 // If we don't cache it for own objects also we must load the object here
1904 if ( !mpImpl->mxObjRef.is() || !pModel )
1905 return false;
1907 MapMode aMapMode( pModel->GetScaleUnit() );
1908 aObjAreaSize = mpImpl->mxObjRef.GetSize( &aMapMode );
1910 Size aSize = maRect.GetSize();
1911 aScaleWidth = Fraction(aSize.Width(), aObjAreaSize.Width() );
1912 aScaleHeight = Fraction(aSize.Height(), aObjAreaSize.Height() );
1914 // reduce to 10 binary digits
1915 aScaleHeight.ReduceInaccurate(10);
1916 aScaleWidth.ReduceInaccurate(10);
1918 return true;
1921 bool SdrOle2Obj::AddOwnLightClient()
1923 // The Own Light Client must be registered in object only using this method!
1924 if ( !SfxInPlaceClient::GetClient( dynamic_cast<SfxObjectShell*>(pModel->GetPersist()), mpImpl->mxObjRef.GetObject() )
1925 && !( mpImpl->mxLightClient.is() && mpImpl->mxObjRef->getClientSite() == uno::Reference< embed::XEmbeddedClient >( mpImpl->mxLightClient.get() ) ) )
1927 Connect();
1929 if ( mpImpl->mxObjRef.is() && mpImpl->mxLightClient.is() )
1931 Fraction aScaleWidth;
1932 Fraction aScaleHeight;
1933 Size aObjAreaSize;
1934 if ( CalculateNewScaling( aScaleWidth, aScaleHeight, aObjAreaSize ) )
1936 mpImpl->mxLightClient->SetSizeScale( aScaleWidth, aScaleHeight );
1937 try {
1938 mpImpl->mxObjRef->setClientSite( mpImpl->mxLightClient.get() );
1939 return true;
1940 } catch( uno::Exception& )
1946 return false;
1949 return true;
1952 Graphic SdrOle2Obj::GetEmptyOLEReplacementGraphic()
1954 return Graphic(BitmapEx(BMP_SVXOLEOBJ));
1957 void SdrOle2Obj::SetWindow(const css::uno::Reference < css::awt::XWindow >& _xWindow)
1959 if ( mpImpl->mxObjRef.is() && mpImpl->mxLightClient.is() )
1961 mpImpl->mxLightClient->setWindow(_xWindow);
1965 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */