bump product version to 4.1.6.2
[LibreOffice.git] / svx / source / svdraw / svdoole2.cxx
blobfcf27cc5bcbb1923b7a127f56bf6801726cbe99b
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 .
21 #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/embed/EmbedStates.hpp>
25 #include <com/sun/star/embed/ElementModes.hpp>
26 #include <com/sun/star/embed/EmbedMisc.hpp>
27 #include <com/sun/star/embed/Aspects.hpp>
28 #include <com/sun/star/embed/XInplaceClient.hpp>
29 #include <com/sun/star/embed/XInplaceObject.hpp>
30 #include <com/sun/star/embed/XLinkageSupport.hpp>
31 #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
32 #include <com/sun/star/embed/XWindowSupplier.hpp>
33 #include <com/sun/star/document/XEventListener.hpp>
34 #include <com/sun/star/container/XChild.hpp>
35 #include "com/sun/star/document/XStorageBasedDocument.hpp"
37 #include <comphelper/processfactory.hxx>
38 #include <cppuhelper/exc_hlp.hxx>
39 #include <unotools/ucbstreamhelper.hxx>
41 #include <toolkit/helper/vclunohelper.hxx>
42 #include <toolkit/awt/vclxwindow.hxx>
43 #include <toolkit/helper/convert.hxx>
45 #include <vcl/graphicfilter.hxx>
46 #include <svtools/embedhlp.hxx>
48 #include <sfx2/objsh.hxx>
49 #include <sfx2/ipclient.hxx>
50 #include <sfx2/lnkbase.hxx>
51 #include <tools/stream.hxx>
52 #include <comphelper/anytostring.hxx>
53 #include <svx/svdpagv.hxx>
54 #include <tools/globname.hxx>
55 #include <vcl/jobset.hxx>
56 #include <comphelper/classids.hxx>
58 #include <sot/formats.hxx>
59 #include <sfx2/linkmgr.hxx>
60 #include <svtools/transfer.hxx>
61 #include <cppuhelper/implbase5.hxx>
63 #include <svl/solar.hrc>
64 #include <svl/urihelper.hxx>
65 #include <osl/mutex.hxx>
66 #include <vcl/svapp.hxx>
68 #include <svx/svdmodel.hxx>
69 #include "svx/svdglob.hxx" // Stringcache
70 #include "svx/svdstr.hrc" // the object's name
71 #include <svx/svdetc.hxx>
72 #include <svx/svdview.hxx>
73 #include "unomlstr.hxx"
74 #include <svx/charthelper.hxx>
75 #include <svx/sdr/contact/viewcontactofsdrole2obj.hxx>
76 #include <svx/svdograf.hxx>
77 #include <svx/sdr/properties/oleproperties.hxx>
79 // #i100710#
80 #include <svx/xlnclit.hxx>
81 #include <svx/xbtmpit.hxx>
82 #include <svx/xflbmtit.hxx>
83 #include <svx/xflbstit.hxx>
85 // #i118485#
86 #include <basegfx/matrix/b2dhommatrix.hxx>
87 #include <basegfx/polygon/b2dpolypolygon.hxx>
88 #include <editeng/outlobj.hxx>
90 #include <svx/svdpage.hxx>
92 using namespace ::rtl;
93 using namespace ::com::sun::star;
95 static uno::Reference < beans::XPropertySet > lcl_getFrame_throw(const SdrOle2Obj* _pObject)
97 uno::Reference < beans::XPropertySet > xFrame;
98 if ( _pObject )
100 uno::Reference< frame::XController> xController = _pObject->GetParentXModel()->getCurrentController();
101 if ( xController.is() )
103 xFrame.set( xController->getFrame(),uno::UNO_QUERY_THROW);
105 } // if ( _pObject )
106 return xFrame;
109 class SdrLightEmbeddedClient_Impl : public ::cppu::WeakImplHelper5
110 < embed::XStateChangeListener
111 , document::XEventListener
112 , embed::XInplaceClient
113 , embed::XEmbeddedClient
114 , embed::XWindowSupplier
117 uno::Reference< awt::XWindow > m_xWindow;
118 SdrOle2Obj* mpObj;
120 Fraction m_aScaleWidth;
121 Fraction m_aScaleHeight;
124 public:
125 SdrLightEmbeddedClient_Impl( SdrOle2Obj* pObj );
126 void Release();
128 void SetSizeScale( const Fraction& aScaleWidth, const Fraction& aScaleHeight )
130 m_aScaleWidth = aScaleWidth;
131 m_aScaleHeight = aScaleHeight;
134 Fraction GetScaleWidth() const { return m_aScaleWidth; }
135 Fraction GetScaleHeight() const { return m_aScaleHeight; }
137 void setWindow(const uno::Reference< awt::XWindow >& _xWindow);
139 private:
140 Rectangle impl_getScaledRect_nothrow() const;
141 // XStateChangeListener
142 virtual void SAL_CALL changingState( const ::com::sun::star::lang::EventObject& aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState ) throw (::com::sun::star::embed::WrongStateException, ::com::sun::star::uno::RuntimeException);
143 virtual void SAL_CALL stateChanged( const ::com::sun::star::lang::EventObject& aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState ) throw (::com::sun::star::uno::RuntimeException);
144 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
146 // document::XEventListener
147 virtual void SAL_CALL notifyEvent( const document::EventObject& aEvent ) throw( uno::RuntimeException );
149 // XEmbeddedClient
150 virtual void SAL_CALL saveObject() throw ( embed::ObjectSaveVetoException, uno::Exception, uno::RuntimeException );
151 virtual void SAL_CALL visibilityChanged( sal_Bool bVisible ) throw ( embed::WrongStateException, uno::RuntimeException );
153 // XComponentSupplier
154 virtual uno::Reference< util::XCloseable > SAL_CALL getComponent() throw ( uno::RuntimeException );
156 // XInplaceClient
157 virtual sal_Bool SAL_CALL canInplaceActivate() throw ( uno::RuntimeException );
158 virtual void SAL_CALL activatingInplace() throw ( embed::WrongStateException, uno::RuntimeException );
159 virtual void SAL_CALL activatingUI() throw ( embed::WrongStateException, uno::RuntimeException );
160 virtual void SAL_CALL deactivatedInplace() throw ( embed::WrongStateException, uno::RuntimeException );
161 virtual void SAL_CALL deactivatedUI() throw ( embed::WrongStateException, uno::RuntimeException );
162 virtual uno::Reference< ::com::sun::star::frame::XLayoutManager > SAL_CALL getLayoutManager() throw ( embed::WrongStateException, uno::RuntimeException );
163 virtual uno::Reference< frame::XDispatchProvider > SAL_CALL getInplaceDispatchProvider() throw ( embed::WrongStateException, uno::RuntimeException );
164 virtual awt::Rectangle SAL_CALL getPlacement() throw ( embed::WrongStateException, uno::RuntimeException );
165 virtual awt::Rectangle SAL_CALL getClipRectangle() throw ( embed::WrongStateException, uno::RuntimeException );
166 virtual void SAL_CALL translateAccelerators( const uno::Sequence< awt::KeyEvent >& aKeys ) throw ( embed::WrongStateException, uno::RuntimeException );
167 virtual void SAL_CALL scrollObject( const awt::Size& aOffset ) throw ( embed::WrongStateException, uno::RuntimeException );
168 virtual void SAL_CALL changedPlacement( const awt::Rectangle& aPosRect ) throw ( embed::WrongStateException, uno::Exception, uno::RuntimeException );
170 // XWindowSupplier
171 virtual uno::Reference< awt::XWindow > SAL_CALL getWindow() throw ( uno::RuntimeException );
174 //--------------------------------------------------------------------
175 SdrLightEmbeddedClient_Impl::SdrLightEmbeddedClient_Impl( SdrOle2Obj* pObj )
176 : mpObj( pObj )
179 Rectangle SdrLightEmbeddedClient_Impl::impl_getScaledRect_nothrow() const
181 Rectangle aLogicRect( mpObj->GetLogicRect() );
182 // apply scaling to object area and convert to pixels
183 aLogicRect.SetSize( Size( Fraction( aLogicRect.GetWidth() ) * m_aScaleWidth,
184 Fraction( aLogicRect.GetHeight() ) * m_aScaleHeight ) );
185 return aLogicRect;
187 //--------------------------------------------------------------------
188 void SAL_CALL SdrLightEmbeddedClient_Impl::changingState( const ::com::sun::star::lang::EventObject& /*aEvent*/, ::sal_Int32 /*nOldState*/, ::sal_Int32 /*nNewState*/ ) throw (::com::sun::star::embed::WrongStateException, ::com::sun::star::uno::RuntimeException)
192 //--------------------------------------------------------------------
193 void SdrLightEmbeddedClient_Impl::Release()
196 SolarMutexGuard aGuard;
197 mpObj = NULL;
200 release();
203 //--------------------------------------------------------------------
204 void SAL_CALL SdrLightEmbeddedClient_Impl::stateChanged( const ::com::sun::star::lang::EventObject& /*aEvent*/, ::sal_Int32 nOldState, ::sal_Int32 nNewState ) throw (::com::sun::star::uno::RuntimeException)
206 SolarMutexGuard aGuard;
208 if ( mpObj && nOldState == embed::EmbedStates::LOADED && nNewState == embed::EmbedStates::RUNNING )
210 mpObj->ObjectLoaded();
211 GetSdrGlobalData().GetOLEObjCache().InsertObj(mpObj);
213 else if ( mpObj && nNewState == embed::EmbedStates::LOADED && nOldState == embed::EmbedStates::RUNNING )
215 GetSdrGlobalData().GetOLEObjCache().RemoveObj(mpObj);
219 //--------------------------------------------------------------------
220 void SAL_CALL SdrLightEmbeddedClient_Impl::disposing( const ::com::sun::star::lang::EventObject& /*aEvent*/ ) throw (::com::sun::star::uno::RuntimeException)
222 SolarMutexGuard aGuard;
224 GetSdrGlobalData().GetOLEObjCache().RemoveObj(mpObj);
227 //--------------------------------------------------------------------
228 void SAL_CALL SdrLightEmbeddedClient_Impl::notifyEvent( const document::EventObject& aEvent ) throw( uno::RuntimeException )
230 // TODO/LATER: when writer uses this implementation the code could be shared with SfxInPlaceClient_Impl
232 SolarMutexGuard aGuard;
234 // the code currently makes sense only in case there is no other client
235 if ( mpObj && mpObj->GetAspect() != embed::Aspects::MSOLE_ICON && aEvent.EventName == "OnVisAreaChanged"
236 && mpObj->GetObjRef().is() && mpObj->GetObjRef()->getClientSite() == uno::Reference< embed::XEmbeddedClient >( this ) )
240 MapUnit aContainerMapUnit( MAP_100TH_MM );
241 uno::Reference< embed::XVisualObject > xParentVis( mpObj->GetParentXModel(), uno::UNO_QUERY );
242 if ( xParentVis.is() )
243 aContainerMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xParentVis->getMapUnit( mpObj->GetAspect() ) );
245 MapUnit aObjMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( mpObj->GetObjRef()->getMapUnit( mpObj->GetAspect() ) );
247 Rectangle aVisArea;
248 awt::Size aSz;
251 aSz = mpObj->GetObjRef()->getVisualAreaSize( mpObj->GetAspect() );
253 catch( embed::NoVisualAreaSizeException& )
255 OSL_FAIL( "No visual area size!\n" );
256 aSz.Width = 5000;
257 aSz.Height = 5000;
259 catch( uno::Exception& )
261 OSL_FAIL( "Unexpected exception!\n" );
262 aSz.Width = 5000;
263 aSz.Height = 5000;
266 aVisArea.SetSize( Size( aSz.Width, aSz.Height ) );
267 aVisArea = OutputDevice::LogicToLogic( aVisArea, aObjMapUnit, aContainerMapUnit );
268 Size aScaledSize( static_cast< long >( m_aScaleWidth * Fraction( aVisArea.GetWidth() ) ),
269 static_cast< long >( m_aScaleHeight * Fraction( aVisArea.GetHeight() ) ) );
270 Rectangle aLogicRect( mpObj->GetLogicRect() );
272 // react to the change if the difference is bigger than one pixel
273 Size aPixelDiff =
274 Application::GetDefaultDevice()->LogicToPixel(
275 Size( aLogicRect.GetWidth() - aScaledSize.Width(),
276 aLogicRect.GetHeight() - aScaledSize.Height() ),
277 aContainerMapUnit );
278 if( aPixelDiff.Width() || aPixelDiff.Height() )
280 mpObj->SetLogicRect( Rectangle( aLogicRect.TopLeft(), aScaledSize ) );
281 mpObj->BroadcastObjectChange();
283 else
284 mpObj->ActionChanged();
286 catch( uno::Exception& )
288 OSL_FAIL( "Unexpected exception!\n" );
293 //--------------------------------------------------------------------
294 void SAL_CALL SdrLightEmbeddedClient_Impl::saveObject()
295 throw ( embed::ObjectSaveVetoException,
296 uno::Exception,
297 uno::RuntimeException )
299 // TODO/LATER: when writer uses this implementation the code could be shared with SfxInPlaceClient_Impl
300 uno::Reference< embed::XCommonEmbedPersist > xPersist;
301 uno::Reference< util::XModifiable > xModifiable;
304 SolarMutexGuard aGuard;
306 if ( !mpObj )
307 throw embed::ObjectSaveVetoException();
309 // the common persistence is supported by objects and links
310 xPersist = uno::Reference< embed::XCommonEmbedPersist >( mpObj->GetObjRef(), uno::UNO_QUERY_THROW );
311 xModifiable = uno::Reference< util::XModifiable >( mpObj->GetParentXModel(), uno::UNO_QUERY );
314 xPersist->storeOwn();
316 if ( xModifiable.is() )
317 xModifiable->setModified( sal_True );
320 //--------------------------------------------------------------------
321 void SAL_CALL SdrLightEmbeddedClient_Impl::visibilityChanged( sal_Bool /*bVisible*/ )
322 throw ( embed::WrongStateException,
323 uno::RuntimeException )
325 // nothing to do currently
326 // TODO/LATER: when writer uses this implementation the code could be shared with SfxInPlaceClient_Impl
327 if ( mpObj )
329 Rectangle aLogicRect( mpObj->GetLogicRect() );
330 Size aLogicSize( aLogicRect.GetWidth(), aLogicRect.GetHeight() );
332 if( mpObj->IsChart() )
334 //charts never should be stretched see #i84323# for example
335 mpObj->SetLogicRect( Rectangle( aLogicRect.TopLeft(), aLogicSize ) );
336 mpObj->BroadcastObjectChange();
337 } // if( mpObj->IsChart() )
341 //--------------------------------------------------------------------
342 uno::Reference< util::XCloseable > SAL_CALL SdrLightEmbeddedClient_Impl::getComponent()
343 throw ( uno::RuntimeException )
345 uno::Reference< util::XCloseable > xResult;
347 SolarMutexGuard aGuard;
348 if ( mpObj )
349 xResult = uno::Reference< util::XCloseable >( mpObj->GetParentXModel(), uno::UNO_QUERY );
351 return xResult;
353 // XInplaceClient
354 //--------------------------------------------------------------------
355 sal_Bool SAL_CALL SdrLightEmbeddedClient_Impl::canInplaceActivate()
356 throw ( uno::RuntimeException )
358 sal_Bool bRet = sal_False;
359 SolarMutexGuard aGuard;
360 if ( mpObj )
362 uno::Reference< embed::XEmbeddedObject > xObject = mpObj->GetObjRef();
363 if ( !xObject.is() )
364 throw uno::RuntimeException();
365 // we don't want to switch directly from outplace to inplace mode
366 bRet = !( xObject->getCurrentState() == embed::EmbedStates::ACTIVE || mpObj->GetAspect() == embed::Aspects::MSOLE_ICON );
367 } // if ( mpObj )
368 return bRet;
371 //--------------------------------------------------------------------
372 void SAL_CALL SdrLightEmbeddedClient_Impl::activatingInplace()
373 throw ( embed::WrongStateException,
374 uno::RuntimeException )
378 //--------------------------------------------------------------------
379 void SAL_CALL SdrLightEmbeddedClient_Impl::activatingUI()
380 throw ( embed::WrongStateException,
381 uno::RuntimeException )
383 SolarMutexGuard aGuard;
385 uno::Reference < beans::XPropertySet > xFrame( lcl_getFrame_throw(mpObj));
386 uno::Reference < frame::XFrame > xOwnFrame( xFrame,uno::UNO_QUERY);
387 uno::Reference < frame::XFramesSupplier > xParentFrame( xOwnFrame->getCreator(), uno::UNO_QUERY );
388 if ( xParentFrame.is() )
389 xParentFrame->setActiveFrame( xOwnFrame );
391 OLEObjCache& rObjCache = GetSdrGlobalData().GetOLEObjCache();
392 const sal_uIntPtr nCount = rObjCache.size();
393 for(sal_Int32 i = nCount-1 ; i >= 0;--i)
395 SdrOle2Obj* pObj = rObjCache[i];
396 if ( pObj != mpObj )
398 // only deactivate ole objects which belongs to the same frame
399 if ( xFrame == lcl_getFrame_throw(pObj) )
401 uno::Reference< embed::XEmbeddedObject > xObject = pObj->GetObjRef();
404 if ( xObject->getStatus( pObj->GetAspect() ) & embed::EmbedMisc::MS_EMBED_ACTIVATEWHENVISIBLE )
405 xObject->changeState( embed::EmbedStates::INPLACE_ACTIVE );
406 else
408 // the links should not stay in running state for long time because of locking
409 uno::Reference< embed::XLinkageSupport > xLink( xObject, uno::UNO_QUERY );
410 if ( xLink.is() && xLink->isLink() )
411 xObject->changeState( embed::EmbedStates::LOADED );
412 else
413 xObject->changeState( embed::EmbedStates::RUNNING );
416 catch (com::sun::star::uno::Exception& )
420 } // for(sal_Int32 i = nCount-1 ; i >= 0;--i)
423 //--------------------------------------------------------------------
424 void SAL_CALL SdrLightEmbeddedClient_Impl::deactivatedInplace()
425 throw ( embed::WrongStateException,
426 uno::RuntimeException )
430 //--------------------------------------------------------------------
431 void SAL_CALL SdrLightEmbeddedClient_Impl::deactivatedUI()
432 throw ( embed::WrongStateException,
433 uno::RuntimeException )
435 SolarMutexGuard aGuard;
436 com::sun::star::uno::Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager(getLayoutManager());
437 if ( xLayoutManager.is() )
439 const static OUString aMenuBarURL( "private:resource/menubar/menubar" );
440 if ( !xLayoutManager->isElementVisible( aMenuBarURL ) )
441 xLayoutManager->createElement( aMenuBarURL );
445 //--------------------------------------------------------------------
446 uno::Reference< ::com::sun::star::frame::XLayoutManager > SAL_CALL SdrLightEmbeddedClient_Impl::getLayoutManager()
447 throw ( embed::WrongStateException,
448 uno::RuntimeException )
450 uno::Reference< ::com::sun::star::frame::XLayoutManager > xMan;
451 SolarMutexGuard aGuard;
452 uno::Reference < beans::XPropertySet > xFrame( lcl_getFrame_throw(mpObj));
455 xMan.set(xFrame->getPropertyValue( OUString("LayoutManager") ),uno::UNO_QUERY);
457 catch ( uno::Exception& )
459 throw uno::RuntimeException();
462 return xMan;
465 //--------------------------------------------------------------------
466 uno::Reference< frame::XDispatchProvider > SAL_CALL SdrLightEmbeddedClient_Impl::getInplaceDispatchProvider()
467 throw ( embed::WrongStateException,
468 uno::RuntimeException )
470 SolarMutexGuard aGuard;
471 return uno::Reference < frame::XDispatchProvider >( lcl_getFrame_throw(mpObj), uno::UNO_QUERY_THROW );
474 //--------------------------------------------------------------------
475 awt::Rectangle SAL_CALL SdrLightEmbeddedClient_Impl::getPlacement()
476 throw ( embed::WrongStateException,
477 uno::RuntimeException )
479 SolarMutexGuard aGuard;
480 if ( !mpObj )
481 throw uno::RuntimeException();
483 Rectangle aLogicRect = impl_getScaledRect_nothrow();
484 MapUnit aContainerMapUnit( MAP_100TH_MM );
485 uno::Reference< embed::XVisualObject > xParentVis( mpObj->GetParentXModel(), uno::UNO_QUERY );
486 if ( xParentVis.is() )
487 aContainerMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xParentVis->getMapUnit( mpObj->GetAspect() ) );
489 aLogicRect = Application::GetDefaultDevice()->LogicToPixel(aLogicRect,aContainerMapUnit);
490 return AWTRectangle( aLogicRect );
493 //--------------------------------------------------------------------
494 awt::Rectangle SAL_CALL SdrLightEmbeddedClient_Impl::getClipRectangle()
495 throw ( embed::WrongStateException,
496 uno::RuntimeException )
498 return getPlacement();
501 //--------------------------------------------------------------------
502 void SAL_CALL SdrLightEmbeddedClient_Impl::translateAccelerators( const uno::Sequence< awt::KeyEvent >& /*aKeys*/ )
503 throw ( embed::WrongStateException,
504 uno::RuntimeException )
508 //--------------------------------------------------------------------
509 void SAL_CALL SdrLightEmbeddedClient_Impl::scrollObject( const awt::Size& /*aOffset*/ )
510 throw ( embed::WrongStateException,
511 uno::RuntimeException )
515 //--------------------------------------------------------------------
516 void SAL_CALL SdrLightEmbeddedClient_Impl::changedPlacement( const awt::Rectangle& aPosRect )
517 throw ( embed::WrongStateException,
518 uno::Exception,
519 uno::RuntimeException )
521 SolarMutexGuard aGuard;
522 if ( !mpObj )
523 throw uno::RuntimeException();
525 uno::Reference< embed::XInplaceObject > xInplace( mpObj->GetObjRef(), uno::UNO_QUERY );
526 if ( !xInplace.is() )
527 throw uno::RuntimeException();
529 // check if the change is at least one pixel in size
530 awt::Rectangle aOldRect = getPlacement();
531 Rectangle aNewPixelRect = VCLRectangle( aPosRect );
532 Rectangle aOldPixelRect = VCLRectangle( aOldRect );
533 if ( aOldPixelRect == aNewPixelRect )
534 // nothing has changed
535 return;
537 // new scaled object area
538 MapUnit aContainerMapUnit( MAP_100TH_MM );
539 uno::Reference< embed::XVisualObject > xParentVis( mpObj->GetParentXModel(), uno::UNO_QUERY );
540 if ( xParentVis.is() )
541 aContainerMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xParentVis->getMapUnit( mpObj->GetAspect() ) );
543 Rectangle aNewLogicRect = Application::GetDefaultDevice()->PixelToLogic(aNewPixelRect,aContainerMapUnit);
544 Rectangle aLogicRect = impl_getScaledRect_nothrow();
546 if ( aNewLogicRect != aLogicRect )
548 // the calculation of the object area has not changed the object size
549 // it should be done here then
550 //SfxBooleanFlagGuard aGuard( m_bResizeNoScale, sal_True );
552 // new size of the object area without scaling
553 Size aNewObjSize( Fraction( aNewLogicRect.GetWidth() ) / m_aScaleWidth,
554 Fraction( aNewLogicRect.GetHeight() ) / m_aScaleHeight );
556 // now remove scaling from new placement and keep this a the new object area
557 aNewLogicRect.SetSize( aNewObjSize );
558 // react to the change if the difference is bigger than one pixel
559 Size aPixelDiff =
560 Application::GetDefaultDevice()->LogicToPixel(
561 Size( aLogicRect.GetWidth() - aNewObjSize.Width(),
562 aLogicRect.GetHeight() - aNewObjSize.Height() ),
563 aContainerMapUnit );
564 if( aPixelDiff.Width() || aPixelDiff.Height() )
566 mpObj->SetLogicRect( Rectangle( aLogicRect.TopLeft(), aNewObjSize ) );
567 mpObj->BroadcastObjectChange();
569 else
570 mpObj->ActionChanged();
573 // XWindowSupplier
574 //--------------------------------------------------------------------
575 uno::Reference< awt::XWindow > SAL_CALL SdrLightEmbeddedClient_Impl::getWindow()
576 throw ( uno::RuntimeException )
578 SolarMutexGuard aGuard;
579 uno::Reference< awt::XWindow > xCurrent = m_xWindow;
580 if ( !xCurrent.is() )
582 if ( !mpObj )
583 throw uno::RuntimeException();
584 uno::Reference< frame::XFrame> xFrame(lcl_getFrame_throw(mpObj),uno::UNO_QUERY_THROW);
585 xCurrent = xFrame->getComponentWindow();
586 } // if ( !xCurrent.is() )
587 return xCurrent;
589 void SdrLightEmbeddedClient_Impl::setWindow(const uno::Reference< awt::XWindow >& _xWindow)
591 m_xWindow = _xWindow;
594 ////////////////////////////////////////////////////////////////////////////////////////////////////
596 class SdrEmbedObjectLink : public sfx2::SvBaseLink
598 SdrOle2Obj* pObj;
600 public:
601 SdrEmbedObjectLink(SdrOle2Obj* pObj);
602 virtual ~SdrEmbedObjectLink();
604 virtual void Closed();
605 virtual ::sfx2::SvBaseLink::UpdateResult DataChanged(
606 const String& rMimeType, const ::com::sun::star::uno::Any & rValue );
608 bool Connect() { return GetRealObject() != NULL; }
611 // -----------------------------------------------------------------------------
613 SdrEmbedObjectLink::SdrEmbedObjectLink(SdrOle2Obj* pObject):
614 ::sfx2::SvBaseLink( ::sfx2::LINKUPDATE_ONCALL, SOT_FORMATSTR_ID_SVXB ),
615 pObj(pObject)
617 SetSynchron( sal_False );
620 // -----------------------------------------------------------------------------
622 SdrEmbedObjectLink::~SdrEmbedObjectLink()
626 // -----------------------------------------------------------------------------
628 ::sfx2::SvBaseLink::UpdateResult SdrEmbedObjectLink::DataChanged(
629 const String& /*rMimeType*/, const ::com::sun::star::uno::Any & /*rValue*/ )
631 if ( !pObj->UpdateLinkURL_Impl() )
633 // the link URL was not changed
634 uno::Reference< embed::XEmbeddedObject > xObject = pObj->GetObjRef();
635 OSL_ENSURE( xObject.is(), "The object must exist always!\n" );
636 if ( xObject.is() )
638 // let the object reload the link
639 // TODO/LATER: reload call could be used for this case
643 sal_Int32 nState = xObject->getCurrentState();
644 if ( nState != embed::EmbedStates::LOADED )
646 // in some cases the linked file probably is not locked so it could be changed
647 xObject->changeState( embed::EmbedStates::LOADED );
648 xObject->changeState( nState );
651 catch ( uno::Exception& )
657 pObj->GetNewReplacement();
658 pObj->SetChanged();
660 return SUCCESS;
663 // -----------------------------------------------------------------------------
665 void SdrEmbedObjectLink::Closed()
667 pObj->BreakFileLink_Impl();
668 SvBaseLink::Closed();
671 ////////////////////////////////////////////////////////////////////////////////////////////////////
673 class SdrOle2ObjImpl
675 public:
676 // TODO/LATER: do we really need this pointer?
677 GraphicObject* pGraphicObject;
678 String aPersistName; // name of object in persist
679 SdrLightEmbeddedClient_Impl* pLightClient; // must be registered as client only using AddOwnLightClient() call
681 // New local var to avoid repeated loading if load of OLE2 fails
682 bool mbLoadingOLEObjectFailed;
683 bool mbConnected;
685 SdrEmbedObjectLink* mpObjectLink;
686 String maLinkURL;
688 SdrOle2ObjImpl()
689 : pGraphicObject( NULL )
690 , pLightClient ( NULL )
691 // init to start situation, loading did not fail
692 , mbLoadingOLEObjectFailed( false )
693 , mbConnected( false )
694 , mpObjectLink( NULL )
699 ////////////////////////////////////////////////////////////////////////////////////////////////////
701 // Predicate determining whether the given OLE is an internal math
702 // object
703 static bool ImplIsMathObj( const uno::Reference < embed::XEmbeddedObject >& rObjRef )
705 if ( !rObjRef.is() )
706 return false;
708 SvGlobalName aClassName( rObjRef->getClassID() );
709 if( aClassName == SvGlobalName(SO3_SM_CLASSID_30) ||
710 aClassName == SvGlobalName(SO3_SM_CLASSID_40) ||
711 aClassName == SvGlobalName(SO3_SM_CLASSID_50) ||
712 aClassName == SvGlobalName(SO3_SM_CLASSID_60) ||
713 aClassName == SvGlobalName(SO3_SM_CLASSID) )
715 return true;
717 else
719 return false;
723 //////////////////////////////////////////////////////////////////////////////
724 // BaseProperties section
726 sdr::properties::BaseProperties* SdrOle2Obj::CreateObjectSpecificProperties()
728 return new sdr::properties::OleProperties(*this);
731 //////////////////////////////////////////////////////////////////////////////
732 // DrawContact section
734 sdr::contact::ViewContact* SdrOle2Obj::CreateObjectSpecificViewContact()
736 return new sdr::contact::ViewContactOfSdrOle2Obj(*this);
739 // -----------------------------------------------------------------------------
741 TYPEINIT1(SdrOle2Obj,SdrRectObj);
742 DBG_NAME(SdrOle2Obj)
743 SdrOle2Obj::SdrOle2Obj(bool bFrame_) : m_bTypeAsked(false)
744 ,m_bChart(false)
746 DBG_CTOR( SdrOle2Obj,NULL);
747 bInDestruction = false;
748 mbSuppressSetVisAreaSize = false;
749 Init();
750 bFrame=bFrame_;
753 // -----------------------------------------------------------------------------
755 SdrOle2Obj::SdrOle2Obj( const svt::EmbeddedObjectRef& rNewObjRef, const XubString& rNewObjName, const Rectangle& rNewRect, bool bFrame_)
756 : SdrRectObj(rNewRect)
757 , xObjRef( rNewObjRef )
758 , m_bTypeAsked(false)
759 , m_bChart(false)
761 DBG_CTOR( SdrOle2Obj,NULL);
762 bInDestruction = false;
763 mbSuppressSetVisAreaSize = false;
764 Init();
766 mpImpl->aPersistName = rNewObjName;
767 bFrame=bFrame_;
769 if ( xObjRef.is() && (xObjRef->getStatus( GetAspect() ) & embed::EmbedMisc::EMBED_NEVERRESIZE ) )
770 SetResizeProtect(sal_True);
772 // For math objects, set closed state to transparent
773 if( ImplIsMathObj( xObjRef.GetObject() ) )
774 SetClosedObj( false );
777 // -----------------------------------------------------------------------------
779 void SdrOle2Obj::Init()
781 mpImpl = new SdrOle2ObjImpl;
782 pModifyListener = NULL;
783 pGraphic=NULL;
784 mpImpl->pGraphicObject=NULL;
785 mpImpl->pLightClient = 0;
787 xObjRef.Lock( sal_True );
790 // -----------------------------------------------------------------------------
792 SdrOle2Obj::~SdrOle2Obj()
794 DBG_DTOR( SdrOle2Obj,NULL);
795 bInDestruction = true;
797 if ( mpImpl->mbConnected )
798 Disconnect();
800 delete pGraphic;
802 delete mpImpl->pGraphicObject;
804 if(pModifyListener)
806 pModifyListener->invalidate();
807 pModifyListener->release();
810 DisconnectFileLink_Impl();
812 if ( mpImpl->pLightClient )
814 mpImpl->pLightClient->Release();
815 mpImpl->pLightClient = NULL;
818 delete mpImpl;
821 // -----------------------------------------------------------------------------
822 void SdrOle2Obj::SetAspect( sal_Int64 nAspect )
824 xObjRef.SetViewAspect( nAspect );
827 // -----------------------------------------------------------------------------
828 bool SdrOle2Obj::isInplaceActive() const
830 return xObjRef.is() && embed::EmbedStates::INPLACE_ACTIVE == xObjRef->getCurrentState();
833 // -----------------------------------------------------------------------------
834 bool SdrOle2Obj::isUiActive() const
836 return xObjRef.is() && embed::EmbedStates::UI_ACTIVE == xObjRef->getCurrentState();
839 // -----------------------------------------------------------------------------
841 void SdrOle2Obj::SetGraphic_Impl(const Graphic* pGrf)
843 if ( pGraphic )
845 delete pGraphic;
846 pGraphic = NULL;
847 delete mpImpl->pGraphicObject;
848 mpImpl->pGraphicObject = NULL;
851 if (pGrf!=NULL)
853 pGraphic = new Graphic(*pGrf);
854 mpImpl->pGraphicObject = new GraphicObject( *pGraphic );
857 SetChanged();
858 BroadcastObjectChange();
861 void SdrOle2Obj::SetGraphic(const Graphic* pGrf)
863 // only for setting a preview graphic
864 SetGraphic_Impl( pGrf );
867 // -----------------------------------------------------------------------------
869 bool SdrOle2Obj::IsEmpty() const
871 return !(xObjRef.is());
874 // -----------------------------------------------------------------------------
876 void SdrOle2Obj::Connect()
878 if( IsEmptyPresObj() )
879 return;
881 if( mpImpl->mbConnected )
883 // currently there are situations where it seems to be unavoidable to have multiple connects
884 // changing this would need a larger code rewrite, so for now I remove the assertion
885 // OSL_FAIL("Connect() called on connected object!");
886 return;
889 Connect_Impl();
890 AddListeners_Impl();
893 // -----------------------------------------------------------------------------
895 sal_Bool SdrOle2Obj::UpdateLinkURL_Impl()
897 sal_Bool bResult = sal_False;
899 if ( mpImpl->mpObjectLink )
901 sfx2::LinkManager* pLinkManager = pModel ? pModel->GetLinkManager() : NULL;
902 if ( pLinkManager )
904 String aNewLinkURL;
905 pLinkManager->GetDisplayNames( mpImpl->mpObjectLink, 0, &aNewLinkURL, 0, 0 );
906 if ( !aNewLinkURL.EqualsIgnoreCaseAscii( mpImpl->maLinkURL ) )
908 const_cast<SdrOle2Obj*>(this)->GetObjRef_Impl();
909 uno::Reference< embed::XCommonEmbedPersist > xPersObj( xObjRef.GetObject(), uno::UNO_QUERY );
910 OSL_ENSURE( xPersObj.is(), "The object must exist!\n" );
911 if ( xPersObj.is() )
915 sal_Int32 nCurState = xObjRef->getCurrentState();
916 if ( nCurState != embed::EmbedStates::LOADED )
917 xObjRef->changeState( embed::EmbedStates::LOADED );
919 // TODO/LATER: there should be possible to get current mediadescriptor settings from the object
920 uno::Sequence< beans::PropertyValue > aArgs( 1 );
921 aArgs[0].Name = OUString( "URL" );
922 aArgs[0].Value <<= OUString( aNewLinkURL );
923 xPersObj->reload( aArgs, uno::Sequence< beans::PropertyValue >() );
925 mpImpl->maLinkURL = aNewLinkURL;
926 bResult = sal_True;
928 if ( nCurState != embed::EmbedStates::LOADED )
929 xObjRef->changeState( nCurState );
931 catch( ::com::sun::star::uno::Exception& )
933 OSL_FAIL(
934 OString(OString("SdrOle2Obj::UpdateLinkURL_Impl(), "
935 "exception caught: ") +
936 OUStringToOString(
937 comphelper::anyToString( cppu::getCaughtException() ),
938 RTL_TEXTENCODING_UTF8 )).getStr() );
942 if ( !bResult )
944 // TODO/LATER: return the old name to the link manager, is it possible?
950 return bResult;
953 // -----------------------------------------------------------------------------
955 void SdrOle2Obj::BreakFileLink_Impl()
957 uno::Reference<document::XStorageBasedDocument> xDoc;
958 if ( pModel )
959 xDoc.set( pModel->getUnoModel(),uno::UNO_QUERY);
961 if ( xDoc.is() )
963 uno::Reference< embed::XStorage > xStorage = xDoc->getDocumentStorage();
964 if ( xStorage.is() )
968 uno::Reference< embed::XLinkageSupport > xLinkSupport( xObjRef.GetObject(), uno::UNO_QUERY_THROW );
969 xLinkSupport->breakLink( xStorage, mpImpl->aPersistName );
970 DisconnectFileLink_Impl();
971 mpImpl->maLinkURL = String();
973 catch( ::com::sun::star::uno::Exception& )
975 OSL_FAIL(
976 OString(OString("SdrOle2Obj::BreakFileLink_Impl(), "
977 "exception caught: ") +
978 OUStringToOString(
979 comphelper::anyToString( cppu::getCaughtException() ),
980 RTL_TEXTENCODING_UTF8 )).getStr() );
986 // -----------------------------------------------------------------------------
988 void SdrOle2Obj::DisconnectFileLink_Impl()
990 sfx2::LinkManager* pLinkManager = pModel ? pModel->GetLinkManager() : NULL;
991 if ( pLinkManager && mpImpl->mpObjectLink )
993 pLinkManager->Remove( mpImpl->mpObjectLink );
994 mpImpl->mpObjectLink = NULL;
998 // -----------------------------------------------------------------------------
1000 void SdrOle2Obj::CheckFileLink_Impl()
1002 if ( pModel && xObjRef.GetObject().is() && !mpImpl->mpObjectLink )
1006 uno::Reference< embed::XLinkageSupport > xLinkSupport( xObjRef.GetObject(), uno::UNO_QUERY );
1007 if ( xLinkSupport.is() && xLinkSupport->isLink() )
1009 String aLinkURL = xLinkSupport->getLinkURL();
1010 if ( aLinkURL.Len() )
1012 // this is a file link so the model link manager should handle it
1013 sfx2::LinkManager* pLinkManager = pModel->GetLinkManager();
1014 if ( pLinkManager )
1016 mpImpl->mpObjectLink = new SdrEmbedObjectLink( this );
1017 mpImpl->maLinkURL = aLinkURL;
1018 pLinkManager->InsertFileLink( *mpImpl->mpObjectLink, OBJECT_CLIENT_OLE, aLinkURL, NULL, NULL );
1019 mpImpl->mpObjectLink->Connect();
1024 catch( ::com::sun::star::uno::Exception& )
1026 OSL_FAIL(
1027 OString(OString("SdrOle2Obj::CheckFileLink_Impl(), "
1028 "exception caught: ") +
1029 OUStringToOString(
1030 comphelper::anyToString( cppu::getCaughtException() ),
1031 RTL_TEXTENCODING_UTF8 )).getStr() );
1036 // -----------------------------------------------------------------------------
1038 void SdrOle2Obj::Reconnect_Impl()
1040 DBG_ASSERT( mpImpl->mbConnected, "Assigned unconnected object?!" );
1041 Connect_Impl();
1044 void SdrOle2Obj::Connect_Impl()
1046 if( pModel && mpImpl->aPersistName.Len() )
1050 ::comphelper::IEmbeddedHelper* pPers = pModel->GetPersist();
1051 if ( pPers )
1053 comphelper::EmbeddedObjectContainer& rContainer = pPers->getEmbeddedObjectContainer();
1054 if ( !rContainer.HasEmbeddedObject( mpImpl->aPersistName )
1055 || ( xObjRef.is() && !rContainer.HasEmbeddedObject( xObjRef.GetObject() ) ) )
1057 // object not known to container document
1058 // No object -> disaster!
1059 DBG_ASSERT( xObjRef.is(), "No object in connect!");
1060 if ( xObjRef.is() )
1062 // object came from the outside, now add it to the container
1063 OUString aTmp;
1064 rContainer.InsertEmbeddedObject( xObjRef.GetObject(), aTmp );
1065 mpImpl->aPersistName = aTmp;
1068 else if ( !xObjRef.is() )
1070 xObjRef.Assign( rContainer.GetEmbeddedObject( mpImpl->aPersistName ), xObjRef.GetViewAspect() );
1071 m_bTypeAsked = false;
1074 if ( xObjRef.GetObject().is() )
1076 xObjRef.AssignToContainer( &rContainer, mpImpl->aPersistName );
1077 mpImpl->mbConnected = true;
1078 xObjRef.Lock( sal_True );
1082 if ( xObjRef.is() )
1084 if ( !mpImpl->pLightClient )
1086 mpImpl->pLightClient = new SdrLightEmbeddedClient_Impl( this );
1087 mpImpl->pLightClient->acquire();
1090 xObjRef->addStateChangeListener( mpImpl->pLightClient );
1091 xObjRef->addEventListener( uno::Reference< document::XEventListener >( mpImpl->pLightClient ) );
1093 if ( xObjRef->getCurrentState() != embed::EmbedStates::LOADED )
1094 GetSdrGlobalData().GetOLEObjCache().InsertObj(this);
1096 CheckFileLink_Impl();
1098 uno::Reference< container::XChild > xChild( xObjRef.GetObject(), uno::UNO_QUERY );
1099 if( xChild.is() )
1101 uno::Reference< uno::XInterface > xParent( pModel->getUnoModel());
1102 if( xParent.is())
1103 xChild->setParent( pModel->getUnoModel() );
1108 catch( ::com::sun::star::uno::Exception& )
1110 OSL_FAIL(
1111 OString(OString("SdrOle2Obj::Connect_Impl(), "
1112 "exception caught: ") +
1113 OUStringToOString(
1114 comphelper::anyToString( cppu::getCaughtException() ),
1115 RTL_TEXTENCODING_UTF8 )).getStr() );
1119 //TODO/LATER: wait for definition of MiscStatus RESIZEONPRINTERCHANGE
1120 //if ( xObjRef.is() && (*ppObjRef)->GetMiscStatus() & SVOBJ_MISCSTATUS_RESIZEONPRINTERCHANGE )
1122 //TODO/LATER: needs a new handling for OnPrinterChanged
1124 if (pModel && pModel->GetRefDevice() &&
1125 pModel->GetRefDevice()->GetOutDevType() == OUTDEV_PRINTER)
1127 // Kein RefDevice oder RefDevice kein Printer
1128 sal_Bool bModified = (*ppObjRef)->IsModified();
1129 Printer* pPrinter = (Printer*) pModel->GetRefDevice();
1130 (*ppObjRef)->OnDocumentPrinterChanged( pPrinter );
1131 (*ppObjRef)->SetModified( bModified );
1136 void SdrOle2Obj::ObjectLoaded()
1138 AddListeners_Impl();
1141 void SdrOle2Obj::AddListeners_Impl()
1143 if( xObjRef.is() && xObjRef->getCurrentState() != embed::EmbedStates::LOADED )
1145 // register modify listener
1146 if( !pModifyListener )
1148 ((SdrOle2Obj*)this)->pModifyListener = new SvxUnoShapeModifyListener( (SdrOle2Obj*)this );
1149 pModifyListener->acquire();
1152 uno::Reference< util::XModifyBroadcaster > xBC( getXModel(), uno::UNO_QUERY );
1153 if( xBC.is() && pModifyListener )
1155 uno::Reference< util::XModifyListener > xListener( pModifyListener );
1156 xBC->addModifyListener( xListener );
1161 // -----------------------------------------------------------------------------
1163 void SdrOle2Obj::Disconnect()
1165 if( IsEmptyPresObj() )
1166 return;
1168 if( !mpImpl->mbConnected )
1170 OSL_FAIL("Disconnect() called on disconnected object!");
1171 return;
1174 RemoveListeners_Impl();
1175 Disconnect_Impl();
1178 void SdrOle2Obj::RemoveListeners_Impl()
1180 if( xObjRef.is() && mpImpl->aPersistName.Len() )
1184 sal_Int32 nState = xObjRef->getCurrentState();
1185 if ( nState != embed::EmbedStates::LOADED )
1187 uno::Reference< util::XModifyBroadcaster > xBC( getXModel(), uno::UNO_QUERY );
1188 if( xBC.is() && pModifyListener )
1190 uno::Reference< util::XModifyListener > xListener( pModifyListener );
1191 xBC->removeModifyListener( xListener );
1195 catch( ::com::sun::star::uno::Exception& )
1197 OSL_FAIL(
1198 OString(OString("SdrOle2Obj::RemoveListeners_Impl(), "
1199 "exception caught: ") +
1200 OUStringToOString(
1201 comphelper::anyToString( cppu::getCaughtException() ),
1202 RTL_TEXTENCODING_UTF8 )).getStr() );
1207 void SdrOle2Obj::Disconnect_Impl()
1211 if ( pModel && mpImpl->aPersistName.Len() )
1213 if( pModel->IsInDestruction() )
1215 // TODO/LATER: here we must assume that the destruction of the model is enough to make clear that we will not
1216 // remove the object from the container, even if the DrawingObject itself is not destroyed (unfortunately this
1217 // There is no real need to do the following removing of the object from the container
1218 // in case the model has correct persistence, but in case of problems such a removing
1219 // would make the behavior of the office more stable
1221 comphelper::EmbeddedObjectContainer* pContainer = xObjRef.GetContainer();
1222 if ( pContainer )
1224 pContainer->CloseEmbeddedObject( xObjRef.GetObject() );
1225 xObjRef.AssignToContainer( NULL, mpImpl->aPersistName );
1228 // happens later than the destruction of the model, so we can't assert that).
1229 //DBG_ASSERT( bInDestruction, "Model is destroyed, but not me?!" );
1230 //TODO/LATER: should be make sure that the ObjectShell also forgets the object, because we will close it soon?
1232 uno::Reference < util::XCloseable > xClose( xObjRef, uno::UNO_QUERY );
1233 if ( xClose.is() )
1237 xClose->close( sal_True );
1239 catch ( util::CloseVetoException& )
1241 // there's still someone who needs the object!
1245 xObjRef = NULL;*/
1247 else if ( xObjRef.is() )
1249 if ( pModel->getUnoModel().is() )
1251 // remove object, but don't close it (that's up to someone else)
1252 comphelper::EmbeddedObjectContainer* pContainer = xObjRef.GetContainer();
1253 if ( pContainer )
1255 pContainer->RemoveEmbeddedObject( xObjRef.GetObject(), sal_False);
1257 // TODO/LATER: mpImpl->aPersistName contains outdated information, to keep it updated
1258 // it should be returned from RemoveEmbeddedObject call. Currently it is no problem,
1259 // since no container is adjusted, actually the empty string could be provided as a name here
1260 xObjRef.AssignToContainer( NULL, mpImpl->aPersistName );
1263 DisconnectFileLink_Impl();
1268 if ( xObjRef.is() && mpImpl->pLightClient )
1270 xObjRef->removeStateChangeListener ( mpImpl->pLightClient );
1271 xObjRef->removeEventListener( uno::Reference< document::XEventListener >( mpImpl->pLightClient ) );
1272 xObjRef->setClientSite( NULL );
1274 GetSdrGlobalData().GetOLEObjCache().RemoveObj(this);
1277 catch( ::com::sun::star::uno::Exception& )
1279 OSL_FAIL(
1280 OString(OString("SdrOle2Obj::Disconnect_Impl(), "
1281 "exception caught: ") +
1282 OUStringToOString(
1283 comphelper::anyToString( cppu::getCaughtException() ),
1284 RTL_TEXTENCODING_UTF8 )).getStr() );
1287 mpImpl->mbConnected = false;
1290 // -----------------------------------------------------------------------------
1292 SdrObject* SdrOle2Obj::createSdrGrafObjReplacement(bool bAddText, bool /* bUseHCGraphic */) const
1294 const Graphic* pOLEGraphic = GetGraphic();
1296 if(pOLEGraphic)
1298 // #i118485# allow creating a SdrGrafObj representation
1299 SdrGrafObj* pClone = new SdrGrafObj(*pOLEGraphic);
1300 pClone->SetModel(GetModel());
1302 // copy transformation
1303 basegfx::B2DHomMatrix aMatrix;
1304 basegfx::B2DPolyPolygon aPolyPolygon;
1306 TRGetBaseGeometry(aMatrix, aPolyPolygon);
1307 pClone->TRSetBaseGeometry(aMatrix, aPolyPolygon);
1309 // copy all attributes to support graphic styles for OLEs
1310 pClone->SetStyleSheet(GetStyleSheet(), false);
1311 pClone->SetMergedItemSet(GetMergedItemSet());
1313 if(bAddText)
1315 // #i118485# copy text (Caution! Model needed, as guaranteed in aw080)
1316 OutlinerParaObject* pOPO = GetOutlinerParaObject();
1318 if(pOPO && GetModel())
1320 pClone->NbcSetOutlinerParaObject(new OutlinerParaObject(*pOPO));
1324 return pClone;
1326 else
1328 // #i100710# pOLEGraphic may be zero (no visualisation available),
1329 // so we need to use the OLE replacement graphic
1330 SdrRectObj* pClone = new SdrRectObj(GetSnapRect());
1331 pClone->SetModel(GetModel());
1333 // gray outline
1334 pClone->SetMergedItem(XLineStyleItem(XLINE_SOLID));
1335 const svtools::ColorConfig aColorConfig;
1336 const svtools::ColorConfigValue aColor(aColorConfig.GetColorValue(svtools::OBJECTBOUNDARIES));
1337 pClone->SetMergedItem(XLineColorItem(String(), aColor.nColor));
1339 // bitmap fill
1340 pClone->SetMergedItem(XFillStyleItem(XFILL_BITMAP));
1341 pClone->SetMergedItem(XFillBitmapItem(String(), Graphic(GetEmtyOLEReplacementBitmap())));
1342 pClone->SetMergedItem(XFillBmpTileItem(false));
1343 pClone->SetMergedItem(XFillBmpStretchItem(false));
1345 return pClone;
1349 SdrObject* SdrOle2Obj::DoConvertToPolyObj(sal_Bool bBezier, bool bAddText) const
1351 // #i118485# missing converter added
1352 if(GetModel())
1354 SdrObject* pRetval = createSdrGrafObjReplacement(true, false);
1356 if(pRetval)
1358 SdrObject* pRetval2 = pRetval->DoConvertToPolyObj(bBezier, bAddText);
1359 SdrObject::Free(pRetval);
1361 return pRetval2;
1365 return 0;
1368 // -----------------------------------------------------------------------------
1370 void SdrOle2Obj::SetModel(SdrModel* pNewModel)
1372 ::comphelper::IEmbeddedHelper* pDestPers = pNewModel ? pNewModel->GetPersist() : 0;
1373 ::comphelper::IEmbeddedHelper* pSrcPers = pModel ? pModel->GetPersist() : 0;
1375 if ( pNewModel == pModel )
1377 // don't know if this is necessary or if it will ever happen, but who knows?!
1378 SdrRectObj::SetModel( pNewModel );
1379 return;
1382 // assignment to model has changed
1383 DBG_ASSERT( pSrcPers || !mpImpl->mbConnected, "Connected object without a model?!" );
1385 DBG_ASSERT( pDestPers, "The destination model must have a persistence! Please submit an issue!" );
1386 DBG_ASSERT( pDestPers != pSrcPers, "The source and the destination models should have different persistences! Problems are possible!" );
1388 // this is a bug if the target model has no persistence
1389 // no error handling is possible so just do nothing in this method
1390 if ( !pDestPers )
1391 return;
1393 RemoveListeners_Impl();
1395 if( pDestPers && pSrcPers && !IsEmptyPresObj() )
1399 // move the object's storage; ObjectRef remains the same, but PersistName may change
1400 OUString aTmp;
1401 comphelper::EmbeddedObjectContainer& rContainer = pSrcPers->getEmbeddedObjectContainer();
1402 uno::Reference < embed::XEmbeddedObject > xObj = rContainer.GetEmbeddedObject( mpImpl->aPersistName );
1403 DBG_ASSERT( !xObjRef.is() || xObjRef.GetObject() == xObj, "Wrong object identity!" );
1404 if ( xObj.is() )
1406 pDestPers->getEmbeddedObjectContainer().MoveEmbeddedObject( rContainer, xObj, aTmp );
1407 mpImpl->aPersistName = aTmp;
1408 xObjRef.AssignToContainer( &pDestPers->getEmbeddedObjectContainer(), aTmp );
1410 DBG_ASSERT( !aTmp.isEmpty(), "Copying embedded object failed!" );
1412 catch( ::com::sun::star::uno::Exception& )
1414 OSL_FAIL(
1415 OString(OString("SdrOle2Obj::SetModel(), "
1416 "exception caught: ") +
1417 OUStringToOString(
1418 comphelper::anyToString( cppu::getCaughtException() ),
1419 RTL_TEXTENCODING_UTF8 )).getStr() );
1423 SdrRectObj::SetModel( pNewModel );
1425 // #i43086#
1426 // #i85304 redo the change for charts for the above bugfix, as #i43086# does not occur anymore
1427 //so maybe the ImpSetVisAreaSize call can be removed here completely
1428 //Nevertheless I leave it in for other objects as I am not sure about the side effects when removing now
1429 if( pModel && !pModel->isLocked() && !IsChart() )
1430 ImpSetVisAreaSize();
1432 if( pDestPers && !IsEmptyPresObj() )
1434 if ( !pSrcPers || IsEmptyPresObj() )
1435 // object wasn't connected, now it should be
1436 Connect_Impl();
1437 else
1438 Reconnect_Impl();
1441 AddListeners_Impl();
1444 // -----------------------------------------------------------------------------
1446 void SdrOle2Obj::SetPage(SdrPage* pNewPage)
1448 bool bRemove=pNewPage==NULL && pPage!=NULL;
1449 bool bInsert=pNewPage!=NULL && pPage==NULL;
1451 if (bRemove && mpImpl->mbConnected )
1452 Disconnect();
1454 if(!pModel && !GetStyleSheet() && pNewPage->GetModel())
1456 // #i119287# Set default StyleSheet for SdrGrafObj here, it is different from 'Default'. This
1457 // needs to be done before the style 'Default' is set from the :SetModel() call which is triggered
1458 // from the following :SetPage().
1459 // TTTT: Needs to be moved in branch aw080 due to having a SdrModel from the beginning, is at this
1460 // place for convenience currently (works in both versions, is not in the way)
1461 SfxStyleSheet* pSheet = pNewPage->GetModel()->GetDefaultStyleSheetForSdrGrafObjAndSdrOle2Obj();
1463 if(pSheet)
1465 SetStyleSheet(pSheet, false);
1467 else
1469 SetMergedItem(XFillStyleItem(XFILL_NONE));
1470 SetMergedItem(XLineStyleItem(XLINE_NONE));
1474 SdrRectObj::SetPage(pNewPage);
1476 if (bInsert && !mpImpl->mbConnected )
1477 Connect();
1480 // -----------------------------------------------------------------------------
1482 void SdrOle2Obj::SetObjRef( const com::sun::star::uno::Reference < com::sun::star::embed::XEmbeddedObject >& rNewObjRef )
1484 DBG_ASSERT( !rNewObjRef.is() || !xObjRef.GetObject().is(), "SetObjRef called on already initialized object!");
1485 if( rNewObjRef == xObjRef.GetObject() )
1486 return;
1488 // the caller of the method is responsible to control the old object, it will not be closed here
1489 // Otherwise WW8 import crashes because it transfers control to OLENode by this method
1490 if ( xObjRef.GetObject().is() )
1491 xObjRef.Lock( sal_False );
1493 // avoid removal of object in Disconnect! It is definitely a HACK to call SetObjRef(0)!
1494 // This call will try to close the objects; so if anybody else wants to keep it, it must be locked by a CloseListener
1495 xObjRef.Clear();
1497 if ( mpImpl->mbConnected )
1498 Disconnect();
1500 xObjRef.Assign( rNewObjRef, GetAspect() );
1501 m_bTypeAsked = false;
1503 if ( xObjRef.is() )
1505 DELETEZ( pGraphic );
1507 if ( (xObjRef->getStatus( GetAspect() ) & embed::EmbedMisc::EMBED_NEVERRESIZE ) )
1508 SetResizeProtect(sal_True);
1510 // For math objects, set closed state to transparent
1511 if( ImplIsMathObj( rNewObjRef ) )
1512 SetClosedObj( false );
1514 Connect();
1517 SetChanged();
1518 BroadcastObjectChange();
1521 // -----------------------------------------------------------------------------
1523 void SdrOle2Obj::SetClosedObj( bool bIsClosed )
1525 // TODO/LATER: do we still need this hack?
1526 // Allow changes to the closed state of OLE objects
1527 bClosedObj = bIsClosed;
1530 // -----------------------------------------------------------------------------
1532 SdrObject* SdrOle2Obj::getFullDragClone() const
1534 // #i118485# use central replacement generator
1535 return createSdrGrafObjReplacement(false, true);
1538 // -----------------------------------------------------------------------------
1540 void SdrOle2Obj::SetPersistName( const String& rPersistName )
1542 DBG_ASSERT( !mpImpl->aPersistName.Len(), "Persist name changed!");
1544 mpImpl->aPersistName = rPersistName;
1545 mpImpl->mbLoadingOLEObjectFailed = false;
1547 Connect();
1548 SetChanged();
1551 void SdrOle2Obj::AbandonObject()
1553 mpImpl->aPersistName.Erase();
1554 mpImpl->mbLoadingOLEObjectFailed = false;
1555 SetObjRef(0);
1558 // -----------------------------------------------------------------------------
1560 String SdrOle2Obj::GetPersistName() const
1562 return mpImpl->aPersistName;
1565 // -----------------------------------------------------------------------------
1567 void SdrOle2Obj::TakeObjInfo(SdrObjTransformInfoRec& rInfo) const
1569 // #i118485# Allowing much more attributes for OLEs
1570 rInfo.bRotateFreeAllowed = true;
1571 rInfo.bRotate90Allowed = true;
1572 rInfo.bMirrorFreeAllowed = true;
1573 rInfo.bMirror45Allowed = true;
1574 rInfo.bMirror90Allowed = true;
1575 rInfo.bTransparenceAllowed = true;
1576 rInfo.bGradientAllowed = true;
1577 rInfo.bShearAllowed = true;
1578 rInfo.bEdgeRadiusAllowed = false;
1579 rInfo.bNoOrthoDesired = false;
1580 rInfo.bCanConvToPath = true;
1581 rInfo.bCanConvToPoly = true;
1582 rInfo.bCanConvToPathLineToArea = false;
1583 rInfo.bCanConvToPolyLineToArea = false;
1584 rInfo.bCanConvToContour = true;
1587 // -----------------------------------------------------------------------------
1589 sal_uInt16 SdrOle2Obj::GetObjIdentifier() const
1591 return bFrame ? sal_uInt16(OBJ_FRAME) : sal_uInt16(OBJ_OLE2);
1594 // -----------------------------------------------------------------------------
1596 void SdrOle2Obj::TakeObjNameSingul(XubString& rName) const
1598 rName = ImpGetResStr(bFrame ? STR_ObjNameSingulFrame : STR_ObjNameSingulOLE2);
1600 const String aName(GetName());
1602 if( aName.Len() )
1604 rName.AppendAscii(" '");
1605 rName += aName;
1606 rName += sal_Unicode('\'');
1610 // -----------------------------------------------------------------------------
1612 void SdrOle2Obj::TakeObjNamePlural(XubString& rName) const
1614 rName=ImpGetResStr(bFrame ? STR_ObjNamePluralFrame : STR_ObjNamePluralOLE2);
1617 // -----------------------------------------------------------------------------
1619 SdrOle2Obj* SdrOle2Obj::Clone() const
1621 return CloneHelper< SdrOle2Obj >();
1624 SdrOle2Obj& SdrOle2Obj::operator=(const SdrOle2Obj& rObj)
1626 //TODO/LATER: who takes over control of my old object?!
1627 if( &rObj != this )
1629 // #116235#
1630 // ImpAssign( rObj );
1631 const SdrOle2Obj& rOle2Obj = static_cast< const SdrOle2Obj& >( rObj );
1633 uno::Reference < util::XCloseable > xClose( xObjRef.GetObject(), uno::UNO_QUERY );
1635 if( pModel && mpImpl->mbConnected )
1636 Disconnect();
1638 SdrRectObj::operator=( rObj );
1640 // Manually copying bClosedObj attribute
1641 SetClosedObj( rObj.IsClosedObj() );
1643 mpImpl->aPersistName = rOle2Obj.mpImpl->aPersistName;
1644 aProgName = rOle2Obj.aProgName;
1645 bFrame = rOle2Obj.bFrame;
1647 if( rOle2Obj.pGraphic )
1649 if( pGraphic )
1651 delete pGraphic;
1652 delete mpImpl->pGraphicObject;
1655 pGraphic = new Graphic( *rOle2Obj.pGraphic );
1656 mpImpl->pGraphicObject = new GraphicObject( *pGraphic );
1659 if( pModel && rObj.GetModel() && !IsEmptyPresObj() )
1661 ::comphelper::IEmbeddedHelper* pDestPers = pModel->GetPersist();
1662 ::comphelper::IEmbeddedHelper* pSrcPers = rObj.GetModel()->GetPersist();
1663 if( pDestPers && pSrcPers )
1665 DBG_ASSERT( !xObjRef.is(), "Object already existing!" );
1666 comphelper::EmbeddedObjectContainer& rContainer = pSrcPers->getEmbeddedObjectContainer();
1667 uno::Reference < embed::XEmbeddedObject > xObj = rContainer.GetEmbeddedObject( mpImpl->aPersistName );
1668 if ( xObj.is() )
1670 OUString aTmp;
1671 xObjRef.Assign( pDestPers->getEmbeddedObjectContainer().CopyAndGetEmbeddedObject( rContainer, xObj, aTmp ), rOle2Obj.GetAspect() );
1672 m_bTypeAsked = false;
1673 mpImpl->aPersistName = aTmp;
1674 CheckFileLink_Impl();
1677 Connect();
1681 return *this;
1684 // -----------------------------------------------------------------------------
1686 void SdrOle2Obj::ImpSetVisAreaSize()
1688 // #i118524# do not again set VisAreaSize when the call comes from OLE client (e.g. ObjectAreaChanged)
1689 if(mbSuppressSetVisAreaSize)
1690 return;
1692 // currently there is no need to recalculate scaling for iconified objects
1693 // TODO/LATER: it might be needed in future when it is possible to change the icon
1694 if ( GetAspect() == embed::Aspects::MSOLE_ICON )
1695 return;
1697 // the object area of an embedded object was changed, e.g. by user interaction an a selected object
1698 GetObjRef();
1699 if ( xObjRef.is() )
1701 OSL_ASSERT( pModel );
1702 sal_Int64 nMiscStatus = xObjRef->getStatus( GetAspect() );
1704 // the client is required to get access to scaling
1705 SfxInPlaceClient* pClient = SfxInPlaceClient::GetClient( dynamic_cast<SfxObjectShell*>(pModel->GetPersist()), xObjRef.GetObject() );
1706 bool bHasOwnClient =
1707 ( mpImpl->pLightClient
1708 && xObjRef->getClientSite() == uno::Reference< embed::XEmbeddedClient >( mpImpl->pLightClient ) );
1710 if ( pClient || bHasOwnClient )
1712 // TODO: IMHO we need to do similar things when object is UIActive or OutplaceActive?!
1713 if ( ((nMiscStatus & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE) &&
1714 svt::EmbeddedObjectRef::TryRunningState( xObjRef.GetObject() ))
1715 || xObjRef->getCurrentState() == embed::EmbedStates::INPLACE_ACTIVE
1718 Fraction aScaleWidth;
1719 Fraction aScaleHeight;
1720 if ( pClient )
1722 aScaleWidth = pClient->GetScaleWidth();
1723 aScaleHeight = pClient->GetScaleHeight();
1725 else
1727 aScaleWidth = mpImpl->pLightClient->GetScaleWidth();
1728 aScaleHeight = mpImpl->pLightClient->GetScaleHeight();
1731 // The object wants to resize itself (f.e. Chart wants to recalculate the layout)
1732 // or object is inplace active and so has a window that must be resized also
1733 // In these cases the change in the object area size will be reflected in a change of the
1734 // objects' visual area. The scaling will not change, but it might exist already and must
1735 // be used in calculations
1736 MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObjRef->getMapUnit( GetAspect() ) );
1737 Size aVisSize( (long)( Fraction( aRect.GetWidth() ) / aScaleWidth ),
1738 (long)( Fraction( aRect.GetHeight() ) / aScaleHeight ) );
1740 aVisSize = OutputDevice::LogicToLogic( aVisSize, pModel->GetScaleUnit(), aMapUnit);
1741 awt::Size aSz;
1742 aSz.Width = aVisSize.Width();
1743 aSz.Height = aVisSize.Height();
1744 xObjRef->setVisualAreaSize( GetAspect(), aSz );
1748 aSz = xObjRef->getVisualAreaSize( GetAspect() );
1750 catch( embed::NoVisualAreaSizeException& )
1753 Rectangle aAcceptedVisArea;
1754 aAcceptedVisArea.SetSize( Size( (long)( Fraction( long( aSz.Width ) ) * aScaleWidth ),
1755 (long)( Fraction( long( aSz.Height ) ) * aScaleHeight ) ) );
1756 if (aVisSize != aAcceptedVisArea.GetSize())
1758 // server changed VisArea to its liking and the VisArea is different than the suggested one
1759 // store the new value as given by the object
1760 MapUnit aNewMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObjRef->getMapUnit( GetAspect() ) );
1761 aRect.SetSize(OutputDevice::LogicToLogic( aAcceptedVisArea.GetSize(), aNewMapUnit, pModel->GetScaleUnit()));
1764 // make the new object area known to the client
1765 // compared to the "else" branch aRect might have been changed by the object and no additional scaling was applied
1766 // WHY this -> OSL_ASSERT( pClient );
1767 if( pClient )
1768 pClient->SetObjArea(aRect);
1770 // we need a new replacement image as the object has resized itself
1772 //#i79578# don't request a new replacement image for charts to often
1773 //a chart sends a modified call to the framework if it was changed
1774 //thus the replacement update is already handled there
1775 if( !IsChart() )
1776 xObjRef.UpdateReplacement();
1778 else
1780 // The object isn't active and does not want to resize itself so the changed object area size
1781 // will be reflected in a changed object scaling
1782 Fraction aScaleWidth;
1783 Fraction aScaleHeight;
1784 Size aObjAreaSize;
1785 if ( CalculateNewScaling( aScaleWidth, aScaleHeight, aObjAreaSize ) )
1787 if ( pClient )
1789 Rectangle aScaleRect(aRect.TopLeft(), aObjAreaSize);
1790 pClient->SetObjAreaAndScale( aScaleRect, aScaleWidth, aScaleHeight);
1792 else
1794 mpImpl->pLightClient->SetSizeScale( aScaleWidth, aScaleHeight );
1799 else if( (nMiscStatus & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE) &&
1800 svt::EmbeddedObjectRef::TryRunningState( xObjRef.GetObject() ) )
1802 //also handle not sfx based ole objects e.g. charts
1803 //#i83860# resizing charts in impress distorts fonts
1804 uno::Reference< embed::XVisualObject > xVisualObject( this->getXModel(), uno::UNO_QUERY );
1805 if( xVisualObject.is() )
1807 MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObjRef->getMapUnit( GetAspect() ) );
1808 Point aTL( aRect.TopLeft() );
1809 Point aBR( aRect.BottomRight() );
1810 Point aTL2( OutputDevice::LogicToLogic( aTL, pModel->GetScaleUnit(), aMapUnit) );
1811 Point aBR2( OutputDevice::LogicToLogic( aBR, pModel->GetScaleUnit(), aMapUnit) );
1812 Rectangle aNewRect( aTL2, aBR2 );
1813 xVisualObject->setVisualAreaSize( GetAspect(), awt::Size( aNewRect.GetWidth(), aNewRect.GetHeight() ) );
1819 // -----------------------------------------------------------------------------
1821 void SdrOle2Obj::NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact)
1823 if( pModel && !pModel->isLocked() )
1825 GetObjRef();
1826 if ( xObjRef.is() && ( xObjRef->getStatus( GetAspect() ) & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE ) )
1828 // if the object needs recompose on resize
1829 // the client site should be created before the resize will take place
1830 // check whether there is no client site and create it if necessary
1831 AddOwnLightClient();
1835 SdrRectObj::NbcResize(rRef,xFact,yFact);
1836 if( pModel && !pModel->isLocked() )
1837 ImpSetVisAreaSize();
1840 // -----------------------------------------------------------------------------
1842 void SdrOle2Obj::SetGeoData(const SdrObjGeoData& rGeo)
1844 SdrRectObj::SetGeoData(rGeo);
1846 if( pModel && !pModel->isLocked() )
1847 ImpSetVisAreaSize();
1850 // -----------------------------------------------------------------------------
1852 void SdrOle2Obj::NbcSetSnapRect(const Rectangle& rRect)
1854 SdrRectObj::NbcSetSnapRect(rRect);
1856 if( pModel && !pModel->isLocked() )
1857 ImpSetVisAreaSize();
1859 if ( xObjRef.is() && IsChart() )
1861 //#i103460# charts do not necessarily have an own size within ODF files,
1862 //for this case they need to use the size settings from the surrounding frame,
1863 //which is made available with this method as there is no other way
1864 xObjRef.SetDefaultSizeForChart( Size( rRect.GetWidth(), rRect.GetHeight() ) );
1868 // -----------------------------------------------------------------------------
1870 void SdrOle2Obj::NbcSetLogicRect(const Rectangle& rRect)
1872 SdrRectObj::NbcSetLogicRect(rRect);
1874 if( pModel && !pModel->isLocked() )
1875 ImpSetVisAreaSize();
1878 const Graphic* SdrOle2Obj::GetGraphic() const
1880 if ( xObjRef.is() )
1881 return xObjRef.GetGraphic();
1882 return pGraphic;
1885 void SdrOle2Obj::GetNewReplacement()
1887 if ( xObjRef.is() )
1888 xObjRef.UpdateReplacement();
1891 // -----------------------------------------------------------------------------
1893 Size SdrOle2Obj::GetOrigObjSize( MapMode* pTargetMapMode ) const
1895 return xObjRef.GetSize( pTargetMapMode );
1898 // -----------------------------------------------------------------------------
1900 void SdrOle2Obj::NbcMove(const Size& rSize)
1902 SdrRectObj::NbcMove(rSize);
1904 if( pModel && !pModel->isLocked() )
1905 ImpSetVisAreaSize();
1908 // -----------------------------------------------------------------------------
1910 sal_Bool SdrOle2Obj::CanUnloadRunningObj( const uno::Reference< embed::XEmbeddedObject >& xObj, sal_Int64 nAspect )
1912 sal_Bool bResult = sal_False;
1914 sal_Int32 nState = xObj->getCurrentState();
1915 if ( nState == embed::EmbedStates::LOADED )
1917 // the object is already unloaded
1918 bResult = sal_True;
1920 else
1922 uno::Reference < util::XModifiable > xModifiable( xObj->getComponent(), uno::UNO_QUERY );
1923 if ( !xModifiable.is() )
1924 bResult = sal_True;
1925 else
1927 sal_Int64 nMiscStatus = xObj->getStatus( nAspect );
1929 if ( embed::EmbedMisc::MS_EMBED_ALWAYSRUN != ( nMiscStatus & embed::EmbedMisc::MS_EMBED_ALWAYSRUN ) &&
1930 embed::EmbedMisc::EMBED_ACTIVATEIMMEDIATELY != ( nMiscStatus & embed::EmbedMisc::EMBED_ACTIVATEIMMEDIATELY ) &&
1931 !( xModifiable.is() && xModifiable->isModified() ) &&
1932 !( nState == embed::EmbedStates::INPLACE_ACTIVE || nState == embed::EmbedStates::UI_ACTIVE || nState == embed::EmbedStates::ACTIVE ) )
1934 bResult = sal_True;
1939 return bResult;
1942 // -----------------------------------------------------------------------------
1944 sal_Bool SdrOle2Obj::Unload( const uno::Reference< embed::XEmbeddedObject >& xObj, sal_Int64 nAspect )
1946 sal_Bool bResult = sal_False;
1948 if ( CanUnloadRunningObj( xObj, nAspect ) )
1952 xObj->changeState( embed::EmbedStates::LOADED );
1953 bResult = sal_True;
1955 catch( ::com::sun::star::uno::Exception& )
1957 OSL_FAIL(
1958 OString(OString("SdrOle2Obj::Unload=(), "
1959 "exception caught: ") +
1960 OUStringToOString(
1961 comphelper::anyToString( cppu::getCaughtException() ),
1962 RTL_TEXTENCODING_UTF8 )).getStr() );
1966 return bResult;
1969 // -----------------------------------------------------------------------------
1971 sal_Bool SdrOle2Obj::Unload()
1973 sal_Bool bUnloaded = sal_False;
1975 if( xObjRef.is() )
1977 //TODO/LATER: no refcounting tricks anymore!
1978 //"customers" must register as state change listeners
1979 // Not necessary in Doc DTor (MM)
1980 //sal_uIntPtr nRefCount = (*ppObjRef)->GetRefCount();
1981 // prevent Unload if there are external references
1982 //if( nRefCount > 2 )
1983 // return sal_False;
1984 //DBG_ASSERT( nRefCount == 2, "Wrong RefCount for unload" );
1986 else
1987 bUnloaded = sal_True;
1989 if ( pModel && xObjRef.is() )
1991 bUnloaded = Unload( xObjRef.GetObject(), GetAspect() );
1994 return bUnloaded;
1997 // -----------------------------------------------------------------------------
1999 void SdrOle2Obj::GetObjRef_Impl()
2001 if ( !xObjRef.is() && mpImpl->aPersistName.Len() && pModel && pModel->GetPersist() )
2003 // Only try loading if it did not went wrong up to now
2004 if(!mpImpl->mbLoadingOLEObjectFailed)
2006 xObjRef.Assign( pModel->GetPersist()->getEmbeddedObjectContainer().GetEmbeddedObject( mpImpl->aPersistName ), GetAspect() );
2007 m_bTypeAsked = false;
2008 CheckFileLink_Impl();
2010 // If loading of OLE object failed, remember that to not invoke a endless
2011 // loop trying to load it again and again.
2012 if( xObjRef.is() )
2014 mpImpl->mbLoadingOLEObjectFailed = true;
2017 // For math objects, set closed state to transparent
2018 if( ImplIsMathObj( xObjRef.GetObject() ) )
2019 SetClosedObj( false );
2022 if ( xObjRef.is() )
2024 if( !IsEmptyPresObj() )
2026 // remember modified status of model
2027 const sal_Bool bWasChanged(pModel ? pModel->IsChanged() : sal_False);
2029 // perhaps preview not valid anymore
2030 // This line changes the modified state of the model
2031 SetGraphic_Impl( NULL );
2033 // if status was not set before, force it back
2034 // to not set, so that SetGraphic(0L) above does not
2035 // set the modified state of the model.
2036 if(!bWasChanged && pModel && pModel->IsChanged())
2038 pModel->SetChanged( sal_False );
2042 sal_Int64 nMiscStatus = xObjRef->getStatus( GetAspect() );
2043 (void)nMiscStatus;
2044 //TODO/LATER: wait until ResizeOnPrinterChange is defined
2045 //if ( nMiscStatus & SVOBJ_MISCSTATUS_RESIZEONPRINTERCHANGE )
2047 if (pModel && pModel->GetRefDevice() &&
2048 pModel->GetRefDevice()->GetOutDevType() == OUTDEV_PRINTER)
2050 if(!bInDestruction)
2052 //TODO/LATER: printerchange notification
2054 // prevent SetModified (don't want no update here)
2055 sal_Bool bWasEnabled = (*ppObjRef)->IsEnableSetModified();
2056 if ( bWasEnabled )
2057 (*ppObjRef)->EnableSetModified( sal_False );
2059 // Kein RefDevice oder RefDevice kein Printer
2060 Printer* pPrinter = (Printer*) pModel->GetRefDevice();
2061 (*ppObjRef)->OnDocumentPrinterChanged( pPrinter );
2063 // reset state
2064 (*ppObjRef)->EnableSetModified( bWasEnabled );*/
2070 if ( xObjRef.is() )
2071 Connect();
2074 if ( mpImpl->mbConnected )
2075 // move object to first position in cache
2076 GetSdrGlobalData().GetOLEObjCache().InsertObj(this);
2079 uno::Reference < embed::XEmbeddedObject > SdrOle2Obj::GetObjRef() const
2081 const_cast<SdrOle2Obj*>(this)->GetObjRef_Impl();
2082 return xObjRef.GetObject();
2085 uno::Reference < embed::XEmbeddedObject > SdrOle2Obj::GetObjRef_NoInit() const
2087 return xObjRef.GetObject();
2090 // -----------------------------------------------------------------------------
2092 uno::Reference< frame::XModel > SdrOle2Obj::getXModel() const
2094 GetObjRef();
2095 if ( svt::EmbeddedObjectRef::TryRunningState(xObjRef.GetObject()) )
2096 return uno::Reference< frame::XModel >( xObjRef->getComponent(), uno::UNO_QUERY );
2097 else
2098 return uno::Reference< frame::XModel >();
2101 // -----------------------------------------------------------------------------
2103 sal_Bool SdrOle2Obj::IsChart() const
2105 if ( !m_bTypeAsked )
2107 m_bChart = ChartHelper::IsChart(xObjRef);
2108 m_bTypeAsked = true;
2110 return m_bChart;
2113 // -----------------------------------------------------------------------------
2114 void SdrOle2Obj::SetGraphicToObj( const Graphic& aGraphic, const OUString& aMediaType )
2116 xObjRef.SetGraphic( aGraphic, aMediaType );
2119 // -----------------------------------------------------------------------------
2120 void SdrOle2Obj::SetGraphicToObj( const uno::Reference< io::XInputStream >& xGrStream, const OUString& aMediaType )
2122 xObjRef.SetGraphicStream( xGrStream, aMediaType );
2125 // -----------------------------------------------------------------------------
2126 sal_Bool SdrOle2Obj::IsCalc() const
2128 if ( !xObjRef.is() )
2129 return false;
2131 SvGlobalName aObjClsId( xObjRef->getClassID() );
2132 if( SvGlobalName(SO3_SC_CLASSID_30) == aObjClsId
2133 || SvGlobalName(SO3_SC_CLASSID_40) == aObjClsId
2134 || SvGlobalName(SO3_SC_CLASSID_50) == aObjClsId
2135 || SvGlobalName(SO3_SC_CLASSID_60) == aObjClsId
2136 || SvGlobalName(SO3_SC_OLE_EMBED_CLASSID_60) == aObjClsId
2137 || SvGlobalName(SO3_SC_OLE_EMBED_CLASSID_8) == aObjClsId
2138 || SvGlobalName(SO3_SC_CLASSID) == aObjClsId )
2140 return sal_True;
2143 return sal_False;
2146 // -----------------------------------------------------------------------------
2147 uno::Reference< frame::XModel > SdrOle2Obj::GetParentXModel() const
2149 uno::Reference< frame::XModel > xDoc;
2150 if ( pModel )
2151 xDoc.set( pModel->getUnoModel(),uno::UNO_QUERY);
2152 return xDoc;
2155 // -----------------------------------------------------------------------------
2156 sal_Bool SdrOle2Obj::CalculateNewScaling( Fraction& aScaleWidth, Fraction& aScaleHeight, Size& aObjAreaSize )
2158 // TODO/LEAN: to avoid rounding errors scaling always uses the VisArea.
2159 // If we don't cache it for own objects also we must load the object here
2160 if ( !xObjRef.is() || !pModel )
2161 return sal_False;
2163 MapMode aMapMode( pModel->GetScaleUnit() );
2164 aObjAreaSize = xObjRef.GetSize( &aMapMode );
2166 Size aSize = aRect.GetSize();
2167 aScaleWidth = Fraction(aSize.Width(), aObjAreaSize.Width() );
2168 aScaleHeight = Fraction(aSize.Height(), aObjAreaSize.Height() );
2170 // reduce to 10 binary digits
2171 Kuerzen(aScaleHeight, 10);
2172 Kuerzen(aScaleWidth, 10);
2174 return sal_True;
2177 // -----------------------------------------------------------------------------
2178 sal_Bool SdrOle2Obj::AddOwnLightClient()
2180 // The Own Light Client must be registered in object only using this method!
2181 if ( !SfxInPlaceClient::GetClient( dynamic_cast<SfxObjectShell*>(pModel->GetPersist()), xObjRef.GetObject() )
2182 && !( mpImpl->pLightClient && xObjRef->getClientSite() == uno::Reference< embed::XEmbeddedClient >( mpImpl->pLightClient ) ) )
2184 Connect();
2186 if ( xObjRef.is() && mpImpl->pLightClient )
2188 Fraction aScaleWidth;
2189 Fraction aScaleHeight;
2190 Size aObjAreaSize;
2191 if ( CalculateNewScaling( aScaleWidth, aScaleHeight, aObjAreaSize ) )
2193 mpImpl->pLightClient->SetSizeScale( aScaleWidth, aScaleHeight );
2194 try {
2195 xObjRef->setClientSite( mpImpl->pLightClient );
2196 return sal_True;
2197 } catch( uno::Exception& )
2203 return sal_False;
2206 return sal_True;
2209 //////////////////////////////////////////////////////////////////////////////
2211 Bitmap SdrOle2Obj::GetEmtyOLEReplacementBitmap()
2213 return Bitmap(ResId(BMP_SVXOLEOBJ, *ImpGetResMgr()));
2216 //////////////////////////////////////////////////////////////////////////////
2218 void SdrOle2Obj::SetWindow(const com::sun::star::uno::Reference < com::sun::star::awt::XWindow >& _xWindow)
2220 if ( xObjRef.is() && mpImpl->pLightClient )
2222 mpImpl->pLightClient->setWindow(_xWindow);
2226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */