Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / svx / source / svdraw / svdoole2.cxx
blob8c111dce9133c785df3ae23f91e2e75290467255
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include <svx/svdoole2.hxx>
31 #include <com/sun/star/util/XModifyBroadcaster.hpp>
32 #include <com/sun/star/util/XModifiable.hpp>
33 #include <com/sun/star/embed/EmbedStates.hpp>
34 #include <com/sun/star/embed/ElementModes.hpp>
35 #include <com/sun/star/embed/EmbedMisc.hpp>
36 #include <com/sun/star/embed/Aspects.hpp>
37 #include <com/sun/star/embed/XInplaceClient.hpp>
38 #include <com/sun/star/embed/XInplaceObject.hpp>
39 #include <com/sun/star/embed/XLinkageSupport.hpp>
40 #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
41 #include <com/sun/star/embed/XWindowSupplier.hpp>
42 #include <com/sun/star/document/XEventListener.hpp>
43 #include <com/sun/star/container/XChild.hpp>
44 #include "com/sun/star/document/XStorageBasedDocument.hpp"
46 #include <comphelper/processfactory.hxx>
47 #include <cppuhelper/exc_hlp.hxx>
48 #include <unotools/ucbstreamhelper.hxx>
50 #include <toolkit/helper/vclunohelper.hxx>
51 #include <toolkit/awt/vclxwindow.hxx>
52 #include <toolkit/helper/convert.hxx>
54 #include <svtools/filter.hxx>
55 #include <svtools/embedhlp.hxx>
57 #include <sfx2/objsh.hxx>
58 #include <sfx2/ipclient.hxx>
59 #include <sfx2/lnkbase.hxx>
60 #include <tools/stream.hxx>
61 #include <comphelper/anytostring.hxx>
62 #include <svx/svdpagv.hxx>
63 #include <tools/globname.hxx>
64 #include <vcl/jobset.hxx>
65 #include <sot/clsids.hxx>
67 #include <sot/formats.hxx>
68 #include <sfx2/linkmgr.hxx>
69 #include <svtools/transfer.hxx>
70 #include <cppuhelper/implbase5.hxx>
72 #include <svl/solar.hrc>
73 #include <svl/urihelper.hxx>
74 #include <osl/mutex.hxx>
75 #include <vcl/svapp.hxx>
77 #include <svx/svdmodel.hxx>
78 #include "svx/svdglob.hxx" // Stringcache
79 #include "svx/svdstr.hrc" // the object's name
80 #include <svx/svdetc.hxx>
81 #include <svx/svdview.hxx>
82 #include "unomlstr.hxx"
83 #include <svtools/chartprettypainter.hxx>
84 #include <svx/sdr/contact/viewcontactofsdrole2obj.hxx>
85 #include <svx/svdograf.hxx>
86 #include <svx/sdr/properties/oleproperties.hxx>
88 // #i100710#
89 #include <svx/xlnclit.hxx>
90 #include <svx/xbtmpit.hxx>
91 #include <svx/xflbmtit.hxx>
92 #include <svx/xflbstit.hxx>
94 using namespace ::rtl;
95 using namespace ::com::sun::star;
97 uno::Reference < beans::XPropertySet > lcl_getFrame_throw(const SdrOle2Obj* _pObject)
99 uno::Reference < beans::XPropertySet > xFrame;
100 if ( _pObject )
102 uno::Reference< frame::XController> xController = _pObject->GetParentXModel()->getCurrentController();
103 if ( xController.is() )
105 xFrame.set( xController->getFrame(),uno::UNO_QUERY_THROW);
107 } // if ( _pObject )
108 return xFrame;
111 class SdrLightEmbeddedClient_Impl : public ::cppu::WeakImplHelper5
112 < embed::XStateChangeListener
113 , document::XEventListener
114 , embed::XInplaceClient
115 , embed::XEmbeddedClient
116 , embed::XWindowSupplier
119 uno::Reference< awt::XWindow > m_xWindow;
120 SdrOle2Obj* mpObj;
122 Fraction m_aScaleWidth;
123 Fraction m_aScaleHeight;
126 public:
127 SdrLightEmbeddedClient_Impl( SdrOle2Obj* pObj );
128 void Release();
130 void SetSizeScale( const Fraction& aScaleWidth, const Fraction& aScaleHeight )
132 m_aScaleWidth = aScaleWidth;
133 m_aScaleHeight = aScaleHeight;
136 Fraction GetScaleWidth() const { return m_aScaleWidth; }
137 Fraction GetScaleHeight() const { return m_aScaleHeight; }
139 void setWindow(const uno::Reference< awt::XWindow >& _xWindow);
141 private:
142 Rectangle impl_getScaledRect_nothrow() const;
143 // XStateChangeListener
144 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);
145 virtual void SAL_CALL stateChanged( const ::com::sun::star::lang::EventObject& aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState ) throw (::com::sun::star::uno::RuntimeException);
146 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
148 // document::XEventListener
149 virtual void SAL_CALL notifyEvent( const document::EventObject& aEvent ) throw( uno::RuntimeException );
151 // XEmbeddedClient
152 virtual void SAL_CALL saveObject() throw ( embed::ObjectSaveVetoException, uno::Exception, uno::RuntimeException );
153 virtual void SAL_CALL visibilityChanged( sal_Bool bVisible ) throw ( embed::WrongStateException, uno::RuntimeException );
155 // XComponentSupplier
156 virtual uno::Reference< util::XCloseable > SAL_CALL getComponent() throw ( uno::RuntimeException );
158 // XInplaceClient
159 virtual sal_Bool SAL_CALL canInplaceActivate() throw ( uno::RuntimeException );
160 virtual void SAL_CALL activatingInplace() throw ( embed::WrongStateException, uno::RuntimeException );
161 virtual void SAL_CALL activatingUI() throw ( embed::WrongStateException, uno::RuntimeException );
162 virtual void SAL_CALL deactivatedInplace() throw ( embed::WrongStateException, uno::RuntimeException );
163 virtual void SAL_CALL deactivatedUI() throw ( embed::WrongStateException, uno::RuntimeException );
164 virtual uno::Reference< ::com::sun::star::frame::XLayoutManager > SAL_CALL getLayoutManager() throw ( embed::WrongStateException, uno::RuntimeException );
165 virtual uno::Reference< frame::XDispatchProvider > SAL_CALL getInplaceDispatchProvider() throw ( embed::WrongStateException, uno::RuntimeException );
166 virtual awt::Rectangle SAL_CALL getPlacement() throw ( embed::WrongStateException, uno::RuntimeException );
167 virtual awt::Rectangle SAL_CALL getClipRectangle() throw ( embed::WrongStateException, uno::RuntimeException );
168 virtual void SAL_CALL translateAccelerators( const uno::Sequence< awt::KeyEvent >& aKeys ) throw ( embed::WrongStateException, uno::RuntimeException );
169 virtual void SAL_CALL scrollObject( const awt::Size& aOffset ) throw ( embed::WrongStateException, uno::RuntimeException );
170 virtual void SAL_CALL changedPlacement( const awt::Rectangle& aPosRect ) throw ( embed::WrongStateException, uno::Exception, uno::RuntimeException );
172 // XWindowSupplier
173 virtual uno::Reference< awt::XWindow > SAL_CALL getWindow() throw ( uno::RuntimeException );
176 //--------------------------------------------------------------------
177 SdrLightEmbeddedClient_Impl::SdrLightEmbeddedClient_Impl( SdrOle2Obj* pObj )
178 : mpObj( pObj )
181 Rectangle SdrLightEmbeddedClient_Impl::impl_getScaledRect_nothrow() const
183 Rectangle aLogicRect( mpObj->GetLogicRect() );
184 // apply scaling to object area and convert to pixels
185 aLogicRect.SetSize( Size( Fraction( aLogicRect.GetWidth() ) * m_aScaleWidth,
186 Fraction( aLogicRect.GetHeight() ) * m_aScaleHeight ) );
187 return aLogicRect;
189 //--------------------------------------------------------------------
190 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)
194 //--------------------------------------------------------------------
195 void SdrLightEmbeddedClient_Impl::Release()
198 SolarMutexGuard aGuard;
199 mpObj = NULL;
202 release();
205 //--------------------------------------------------------------------
206 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)
208 SolarMutexGuard aGuard;
210 if ( mpObj && nOldState == embed::EmbedStates::LOADED && nNewState == embed::EmbedStates::RUNNING )
212 mpObj->ObjectLoaded();
213 GetSdrGlobalData().GetOLEObjCache().InsertObj(mpObj);
215 else if ( mpObj && nNewState == embed::EmbedStates::LOADED && nOldState == embed::EmbedStates::RUNNING )
217 GetSdrGlobalData().GetOLEObjCache().RemoveObj(mpObj);
221 //--------------------------------------------------------------------
222 void SAL_CALL SdrLightEmbeddedClient_Impl::disposing( const ::com::sun::star::lang::EventObject& /*aEvent*/ ) throw (::com::sun::star::uno::RuntimeException)
224 SolarMutexGuard aGuard;
226 GetSdrGlobalData().GetOLEObjCache().RemoveObj(mpObj);
229 //--------------------------------------------------------------------
230 void SAL_CALL SdrLightEmbeddedClient_Impl::notifyEvent( const document::EventObject& aEvent ) throw( uno::RuntimeException )
232 // TODO/LATER: when writer uses this implementation the code could be shared with SfxInPlaceClient_Impl
234 SolarMutexGuard aGuard;
236 // the code currently makes sense only in case there is no other client
237 if ( mpObj && mpObj->GetAspect() != embed::Aspects::MSOLE_ICON && aEvent.EventName == "OnVisAreaChanged"
238 && mpObj->GetObjRef().is() && mpObj->GetObjRef()->getClientSite() == uno::Reference< embed::XEmbeddedClient >( this ) )
242 MapUnit aContainerMapUnit( MAP_100TH_MM );
243 uno::Reference< embed::XVisualObject > xParentVis( mpObj->GetParentXModel(), uno::UNO_QUERY );
244 if ( xParentVis.is() )
245 aContainerMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xParentVis->getMapUnit( mpObj->GetAspect() ) );
247 MapUnit aObjMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( mpObj->GetObjRef()->getMapUnit( mpObj->GetAspect() ) );
249 Rectangle aVisArea;
250 awt::Size aSz;
253 aSz = mpObj->GetObjRef()->getVisualAreaSize( mpObj->GetAspect() );
255 catch( embed::NoVisualAreaSizeException& )
257 OSL_FAIL( "No visual area size!\n" );
258 aSz.Width = 5000;
259 aSz.Height = 5000;
261 catch( uno::Exception& )
263 OSL_FAIL( "Unexpected exception!\n" );
264 aSz.Width = 5000;
265 aSz.Height = 5000;
268 aVisArea.SetSize( Size( aSz.Width, aSz.Height ) );
269 aVisArea = OutputDevice::LogicToLogic( aVisArea, aObjMapUnit, aContainerMapUnit );
270 Size aScaledSize( static_cast< long >( m_aScaleWidth * Fraction( aVisArea.GetWidth() ) ),
271 static_cast< long >( m_aScaleHeight * Fraction( aVisArea.GetHeight() ) ) );
272 Rectangle aLogicRect( mpObj->GetLogicRect() );
274 // react to the change if the difference is bigger than one pixel
275 Size aPixelDiff =
276 Application::GetDefaultDevice()->LogicToPixel(
277 Size( aLogicRect.GetWidth() - aScaledSize.Width(),
278 aLogicRect.GetHeight() - aScaledSize.Height() ),
279 aContainerMapUnit );
280 if( aPixelDiff.Width() || aPixelDiff.Height() )
282 mpObj->SetLogicRect( Rectangle( aLogicRect.TopLeft(), aScaledSize ) );
283 mpObj->BroadcastObjectChange();
285 else
286 mpObj->ActionChanged();
288 catch( uno::Exception& )
290 OSL_FAIL( "Unexpected exception!\n" );
295 //--------------------------------------------------------------------
296 void SAL_CALL SdrLightEmbeddedClient_Impl::saveObject()
297 throw ( embed::ObjectSaveVetoException,
298 uno::Exception,
299 uno::RuntimeException )
301 // TODO/LATER: when writer uses this implementation the code could be shared with SfxInPlaceClient_Impl
302 uno::Reference< embed::XCommonEmbedPersist > xPersist;
303 uno::Reference< util::XModifiable > xModifiable;
306 SolarMutexGuard aGuard;
308 if ( !mpObj )
309 throw embed::ObjectSaveVetoException();
311 // the common persistence is supported by objects and links
312 xPersist = uno::Reference< embed::XCommonEmbedPersist >( mpObj->GetObjRef(), uno::UNO_QUERY_THROW );
313 xModifiable = uno::Reference< util::XModifiable >( mpObj->GetParentXModel(), uno::UNO_QUERY );
316 xPersist->storeOwn();
318 if ( xModifiable.is() )
319 xModifiable->setModified( sal_True );
322 //--------------------------------------------------------------------
323 void SAL_CALL SdrLightEmbeddedClient_Impl::visibilityChanged( sal_Bool /*bVisible*/ )
324 throw ( embed::WrongStateException,
325 uno::RuntimeException )
327 // nothing to do currently
328 // TODO/LATER: when writer uses this implementation the code could be shared with SfxInPlaceClient_Impl
329 if ( mpObj )
331 Rectangle aLogicRect( mpObj->GetLogicRect() );
332 Size aLogicSize( aLogicRect.GetWidth(), aLogicRect.GetHeight() );
334 if( mpObj->IsChart() )
336 //charts never should be stretched see #i84323# for example
337 mpObj->SetLogicRect( Rectangle( aLogicRect.TopLeft(), aLogicSize ) );
338 mpObj->BroadcastObjectChange();
339 } // if( mpObj->IsChart() )
343 //--------------------------------------------------------------------
344 uno::Reference< util::XCloseable > SAL_CALL SdrLightEmbeddedClient_Impl::getComponent()
345 throw ( uno::RuntimeException )
347 uno::Reference< util::XCloseable > xResult;
349 SolarMutexGuard aGuard;
350 if ( mpObj )
351 xResult = uno::Reference< util::XCloseable >( mpObj->GetParentXModel(), uno::UNO_QUERY );
353 return xResult;
355 // XInplaceClient
356 //--------------------------------------------------------------------
357 sal_Bool SAL_CALL SdrLightEmbeddedClient_Impl::canInplaceActivate()
358 throw ( uno::RuntimeException )
360 sal_Bool bRet = sal_False;
361 SolarMutexGuard aGuard;
362 if ( mpObj )
364 uno::Reference< embed::XEmbeddedObject > xObject = mpObj->GetObjRef();
365 if ( !xObject.is() )
366 throw uno::RuntimeException();
367 // we don't want to switch directly from outplace to inplace mode
368 bRet = !( xObject->getCurrentState() == embed::EmbedStates::ACTIVE || mpObj->GetAspect() == embed::Aspects::MSOLE_ICON );
369 } // if ( mpObj )
370 return bRet;
373 //--------------------------------------------------------------------
374 void SAL_CALL SdrLightEmbeddedClient_Impl::activatingInplace()
375 throw ( embed::WrongStateException,
376 uno::RuntimeException )
380 //--------------------------------------------------------------------
381 void SAL_CALL SdrLightEmbeddedClient_Impl::activatingUI()
382 throw ( embed::WrongStateException,
383 uno::RuntimeException )
385 SolarMutexGuard aGuard;
387 uno::Reference < beans::XPropertySet > xFrame( lcl_getFrame_throw(mpObj));
388 uno::Reference < frame::XFrame > xOwnFrame( xFrame,uno::UNO_QUERY);
389 uno::Reference < frame::XFramesSupplier > xParentFrame( xOwnFrame->getCreator(), uno::UNO_QUERY );
390 if ( xParentFrame.is() )
391 xParentFrame->setActiveFrame( xOwnFrame );
393 OLEObjCache& rObjCache = GetSdrGlobalData().GetOLEObjCache();
394 const sal_uIntPtr nCount = rObjCache.Count();
395 for(sal_Int32 i = nCount-1 ; i >= 0;--i)
397 SdrOle2Obj* pObj = reinterpret_cast<SdrOle2Obj*>(rObjCache.GetObject(i));
398 if ( pObj != mpObj )
400 // only deactivate ole objects which belongs to the same frame
401 if ( xFrame == lcl_getFrame_throw(pObj) )
403 uno::Reference< embed::XEmbeddedObject > xObject = pObj->GetObjRef();
406 if ( xObject->getStatus( pObj->GetAspect() ) & embed::EmbedMisc::MS_EMBED_ACTIVATEWHENVISIBLE )
407 xObject->changeState( embed::EmbedStates::INPLACE_ACTIVE );
408 else
410 // the links should not stay in running state for long time because of locking
411 uno::Reference< embed::XLinkageSupport > xLink( xObject, uno::UNO_QUERY );
412 if ( xLink.is() && xLink->isLink() )
413 xObject->changeState( embed::EmbedStates::LOADED );
414 else
415 xObject->changeState( embed::EmbedStates::RUNNING );
418 catch (com::sun::star::uno::Exception& )
422 } // for(sal_Int32 i = nCount-1 ; i >= 0;--i)
425 //--------------------------------------------------------------------
426 void SAL_CALL SdrLightEmbeddedClient_Impl::deactivatedInplace()
427 throw ( embed::WrongStateException,
428 uno::RuntimeException )
432 //--------------------------------------------------------------------
433 void SAL_CALL SdrLightEmbeddedClient_Impl::deactivatedUI()
434 throw ( embed::WrongStateException,
435 uno::RuntimeException )
437 SolarMutexGuard aGuard;
438 com::sun::star::uno::Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager(getLayoutManager());
439 if ( xLayoutManager.is() )
441 const static rtl::OUString aMenuBarURL( "private:resource/menubar/menubar" );
442 if ( !xLayoutManager->isElementVisible( aMenuBarURL ) )
443 xLayoutManager->createElement( aMenuBarURL );
447 //--------------------------------------------------------------------
448 uno::Reference< ::com::sun::star::frame::XLayoutManager > SAL_CALL SdrLightEmbeddedClient_Impl::getLayoutManager()
449 throw ( embed::WrongStateException,
450 uno::RuntimeException )
452 uno::Reference< ::com::sun::star::frame::XLayoutManager > xMan;
453 SolarMutexGuard aGuard;
454 uno::Reference < beans::XPropertySet > xFrame( lcl_getFrame_throw(mpObj));
457 xMan.set(xFrame->getPropertyValue( ::rtl::OUString("LayoutManager") ),uno::UNO_QUERY);
459 catch ( uno::Exception& )
461 throw uno::RuntimeException();
464 return xMan;
467 //--------------------------------------------------------------------
468 uno::Reference< frame::XDispatchProvider > SAL_CALL SdrLightEmbeddedClient_Impl::getInplaceDispatchProvider()
469 throw ( embed::WrongStateException,
470 uno::RuntimeException )
472 SolarMutexGuard aGuard;
473 return uno::Reference < frame::XDispatchProvider >( lcl_getFrame_throw(mpObj), uno::UNO_QUERY_THROW );
476 //--------------------------------------------------------------------
477 awt::Rectangle SAL_CALL SdrLightEmbeddedClient_Impl::getPlacement()
478 throw ( embed::WrongStateException,
479 uno::RuntimeException )
481 SolarMutexGuard aGuard;
482 if ( !mpObj )
483 throw uno::RuntimeException();
485 Rectangle aLogicRect = impl_getScaledRect_nothrow();
486 MapUnit aContainerMapUnit( MAP_100TH_MM );
487 uno::Reference< embed::XVisualObject > xParentVis( mpObj->GetParentXModel(), uno::UNO_QUERY );
488 if ( xParentVis.is() )
489 aContainerMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xParentVis->getMapUnit( mpObj->GetAspect() ) );
491 aLogicRect = Application::GetDefaultDevice()->LogicToPixel(aLogicRect,aContainerMapUnit);
492 return AWTRectangle( aLogicRect );
495 //--------------------------------------------------------------------
496 awt::Rectangle SAL_CALL SdrLightEmbeddedClient_Impl::getClipRectangle()
497 throw ( embed::WrongStateException,
498 uno::RuntimeException )
500 return getPlacement();
503 //--------------------------------------------------------------------
504 void SAL_CALL SdrLightEmbeddedClient_Impl::translateAccelerators( const uno::Sequence< awt::KeyEvent >& /*aKeys*/ )
505 throw ( embed::WrongStateException,
506 uno::RuntimeException )
510 //--------------------------------------------------------------------
511 void SAL_CALL SdrLightEmbeddedClient_Impl::scrollObject( const awt::Size& /*aOffset*/ )
512 throw ( embed::WrongStateException,
513 uno::RuntimeException )
517 //--------------------------------------------------------------------
518 void SAL_CALL SdrLightEmbeddedClient_Impl::changedPlacement( const awt::Rectangle& aPosRect )
519 throw ( embed::WrongStateException,
520 uno::Exception,
521 uno::RuntimeException )
523 SolarMutexGuard aGuard;
524 if ( !mpObj )
525 throw uno::RuntimeException();
527 uno::Reference< embed::XInplaceObject > xInplace( mpObj->GetObjRef(), uno::UNO_QUERY );
528 if ( !xInplace.is() )
529 throw uno::RuntimeException();
531 // check if the change is at least one pixel in size
532 awt::Rectangle aOldRect = getPlacement();
533 Rectangle aNewPixelRect = VCLRectangle( aPosRect );
534 Rectangle aOldPixelRect = VCLRectangle( aOldRect );
535 if ( aOldPixelRect == aNewPixelRect )
536 // nothing has changed
537 return;
539 // new scaled object area
540 MapUnit aContainerMapUnit( MAP_100TH_MM );
541 uno::Reference< embed::XVisualObject > xParentVis( mpObj->GetParentXModel(), uno::UNO_QUERY );
542 if ( xParentVis.is() )
543 aContainerMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xParentVis->getMapUnit( mpObj->GetAspect() ) );
545 Rectangle aNewLogicRect = Application::GetDefaultDevice()->PixelToLogic(aNewPixelRect,aContainerMapUnit);
546 Rectangle aLogicRect = impl_getScaledRect_nothrow();
548 if ( aNewLogicRect != aLogicRect )
550 // the calculation of the object area has not changed the object size
551 // it should be done here then
552 //SfxBooleanFlagGuard aGuard( m_bResizeNoScale, sal_True );
554 // new size of the object area without scaling
555 Size aNewObjSize( Fraction( aNewLogicRect.GetWidth() ) / m_aScaleWidth,
556 Fraction( aNewLogicRect.GetHeight() ) / m_aScaleHeight );
558 // now remove scaling from new placement and keep this a the new object area
559 aNewLogicRect.SetSize( aNewObjSize );
560 // react to the change if the difference is bigger than one pixel
561 Size aPixelDiff =
562 Application::GetDefaultDevice()->LogicToPixel(
563 Size( aLogicRect.GetWidth() - aNewObjSize.Width(),
564 aLogicRect.GetHeight() - aNewObjSize.Height() ),
565 aContainerMapUnit );
566 if( aPixelDiff.Width() || aPixelDiff.Height() )
568 mpObj->SetLogicRect( Rectangle( aLogicRect.TopLeft(), aNewObjSize ) );
569 mpObj->BroadcastObjectChange();
571 else
572 mpObj->ActionChanged();
575 // XWindowSupplier
576 //--------------------------------------------------------------------
577 uno::Reference< awt::XWindow > SAL_CALL SdrLightEmbeddedClient_Impl::getWindow()
578 throw ( uno::RuntimeException )
580 SolarMutexGuard aGuard;
581 uno::Reference< awt::XWindow > xCurrent = m_xWindow;
582 if ( !xCurrent.is() )
584 if ( !mpObj )
585 throw uno::RuntimeException();
586 uno::Reference< frame::XFrame> xFrame(lcl_getFrame_throw(mpObj),uno::UNO_QUERY_THROW);
587 xCurrent = xFrame->getComponentWindow();
588 } // if ( !xCurrent.is() )
589 return xCurrent;
591 void SdrLightEmbeddedClient_Impl::setWindow(const uno::Reference< awt::XWindow >& _xWindow)
593 m_xWindow = _xWindow;
596 ////////////////////////////////////////////////////////////////////////////////////////////////////
598 class SdrEmbedObjectLink : public sfx2::SvBaseLink
600 SdrOle2Obj* pObj;
602 public:
603 SdrEmbedObjectLink(SdrOle2Obj* pObj);
604 virtual ~SdrEmbedObjectLink();
606 virtual void Closed();
607 virtual ::sfx2::SvBaseLink::UpdateResult DataChanged(
608 const String& rMimeType, const ::com::sun::star::uno::Any & rValue );
610 sal_Bool Connect() { return GetRealObject() != NULL; }
613 // -----------------------------------------------------------------------------
615 SdrEmbedObjectLink::SdrEmbedObjectLink(SdrOle2Obj* pObject):
616 ::sfx2::SvBaseLink( ::sfx2::LINKUPDATE_ONCALL, SOT_FORMATSTR_ID_SVXB ),
617 pObj(pObject)
619 SetSynchron( sal_False );
622 // -----------------------------------------------------------------------------
624 SdrEmbedObjectLink::~SdrEmbedObjectLink()
628 // -----------------------------------------------------------------------------
630 ::sfx2::SvBaseLink::UpdateResult SdrEmbedObjectLink::DataChanged(
631 const String& /*rMimeType*/, const ::com::sun::star::uno::Any & /*rValue*/ )
633 if ( !pObj->UpdateLinkURL_Impl() )
635 // the link URL was not changed
636 uno::Reference< embed::XEmbeddedObject > xObject = pObj->GetObjRef();
637 OSL_ENSURE( xObject.is(), "The object must exist always!\n" );
638 if ( xObject.is() )
640 // let the object reload the link
641 // TODO/LATER: reload call could be used for this case
645 sal_Int32 nState = xObject->getCurrentState();
646 if ( nState != embed::EmbedStates::LOADED )
648 // in some cases the linked file probably is not locked so it could be changed
649 xObject->changeState( embed::EmbedStates::LOADED );
650 xObject->changeState( nState );
653 catch ( uno::Exception& )
659 pObj->GetNewReplacement();
660 pObj->SetChanged();
662 return SUCCESS;
665 // -----------------------------------------------------------------------------
667 void SdrEmbedObjectLink::Closed()
669 pObj->BreakFileLink_Impl();
670 SvBaseLink::Closed();
673 ////////////////////////////////////////////////////////////////////////////////////////////////////
675 class SdrOle2ObjImpl
677 public:
678 // TODO/LATER: do we really need this pointer?
679 GraphicObject* pGraphicObject;
680 String aPersistName; // name of object in persist
681 SdrLightEmbeddedClient_Impl* pLightClient; // must be registered as client only using AddOwnLightClient() call
683 // New local var to avoid repeated loading if load of OLE2 fails
684 sal_Bool mbLoadingOLEObjectFailed;
685 sal_Bool mbConnected;
687 SdrEmbedObjectLink* mpObjectLink;
688 String maLinkURL;
690 SdrOle2ObjImpl()
691 : pGraphicObject( NULL )
692 , pLightClient ( NULL )
693 // init to start situation, loading did not fail
694 , mbLoadingOLEObjectFailed( sal_False )
695 , mbConnected( sal_False )
696 , mpObjectLink( NULL )
701 ////////////////////////////////////////////////////////////////////////////////////////////////////
703 // Predicate determining whether the given OLE is an internal math
704 // object
705 static bool ImplIsMathObj( const uno::Reference < embed::XEmbeddedObject >& rObjRef )
707 if ( !rObjRef.is() )
708 return false;
710 SvGlobalName aClassName( rObjRef->getClassID() );
711 if( aClassName == SvGlobalName(SO3_SM_CLASSID_30) ||
712 aClassName == SvGlobalName(SO3_SM_CLASSID_40) ||
713 aClassName == SvGlobalName(SO3_SM_CLASSID_50) ||
714 aClassName == SvGlobalName(SO3_SM_CLASSID_60) ||
715 aClassName == SvGlobalName(SO3_SM_CLASSID) )
717 return true;
719 else
721 return false;
725 //////////////////////////////////////////////////////////////////////////////
726 // BaseProperties section
728 sdr::properties::BaseProperties* SdrOle2Obj::CreateObjectSpecificProperties()
730 return new sdr::properties::OleProperties(*this);
733 //////////////////////////////////////////////////////////////////////////////
734 // DrawContact section
736 sdr::contact::ViewContact* SdrOle2Obj::CreateObjectSpecificViewContact()
738 return new sdr::contact::ViewContactOfSdrOle2Obj(*this);
741 // -----------------------------------------------------------------------------
743 TYPEINIT1(SdrOle2Obj,SdrRectObj);
744 DBG_NAME(SdrOle2Obj)
745 SdrOle2Obj::SdrOle2Obj(bool bFrame_) : m_bTypeAsked(false)
746 ,m_bChart(false)
748 DBG_CTOR( SdrOle2Obj,NULL);
749 bInDestruction = false;
750 Init();
751 bFrame=bFrame_;
754 // -----------------------------------------------------------------------------
756 SdrOle2Obj::SdrOle2Obj( const svt::EmbeddedObjectRef& rNewObjRef, const XubString& rNewObjName, const Rectangle& rNewRect, bool bFrame_)
757 : SdrRectObj(rNewRect)
758 , xObjRef( rNewObjRef )
759 , m_bTypeAsked(false)
760 , m_bChart(false)
762 DBG_CTOR( SdrOle2Obj,NULL);
763 bInDestruction = 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 if( pGraphic!=NULL )
801 delete pGraphic;
803 if(mpImpl->pGraphicObject!=NULL)
804 delete mpImpl->pGraphicObject;
806 if(pModifyListener)
808 pModifyListener->invalidate();
809 pModifyListener->release();
812 DisconnectFileLink_Impl();
814 if ( mpImpl->pLightClient )
816 mpImpl->pLightClient->Release();
817 mpImpl->pLightClient = NULL;
820 delete mpImpl;
823 // -----------------------------------------------------------------------------
824 void SdrOle2Obj::SetAspect( sal_Int64 nAspect )
826 xObjRef.SetViewAspect( nAspect );
829 // -----------------------------------------------------------------------------
831 void SdrOle2Obj::SetGraphic_Impl(const Graphic* pGrf)
833 if ( pGraphic )
835 delete pGraphic;
836 pGraphic = NULL;
837 delete mpImpl->pGraphicObject;
838 mpImpl->pGraphicObject = NULL;
841 if (pGrf!=NULL)
843 pGraphic = new Graphic(*pGrf);
844 mpImpl->pGraphicObject = new GraphicObject( *pGraphic );
847 SetChanged();
848 BroadcastObjectChange();
851 void SdrOle2Obj::SetGraphic(const Graphic* pGrf)
853 // only for setting a preview graphic
854 SetGraphic_Impl( pGrf );
857 // -----------------------------------------------------------------------------
859 bool SdrOle2Obj::IsEmpty() const
861 return !(xObjRef.is());
864 // -----------------------------------------------------------------------------
866 void SdrOle2Obj::Connect()
868 if( IsEmptyPresObj() )
869 return;
871 if( mpImpl->mbConnected )
873 // currently there are situations where it seems to be unavoidable to have multiple connects
874 // changing this would need a larger code rewrite, so for now I remove the assertion
875 // OSL_FAIL("Connect() called on connected object!");
876 return;
879 Connect_Impl();
880 AddListeners_Impl();
883 // -----------------------------------------------------------------------------
885 sal_Bool SdrOle2Obj::UpdateLinkURL_Impl()
887 sal_Bool bResult = sal_False;
889 if ( mpImpl->mpObjectLink )
891 sfx2::LinkManager* pLinkManager = pModel ? pModel->GetLinkManager() : NULL;
892 if ( pLinkManager )
894 String aNewLinkURL;
895 pLinkManager->GetDisplayNames( mpImpl->mpObjectLink, 0, &aNewLinkURL, 0, 0 );
896 if ( !aNewLinkURL.EqualsIgnoreCaseAscii( mpImpl->maLinkURL ) )
898 const_cast<SdrOle2Obj*>(this)->GetObjRef_Impl();
899 uno::Reference< embed::XCommonEmbedPersist > xPersObj( xObjRef.GetObject(), uno::UNO_QUERY );
900 OSL_ENSURE( xPersObj.is(), "The object must exist!\n" );
901 if ( xPersObj.is() )
905 sal_Int32 nCurState = xObjRef->getCurrentState();
906 if ( nCurState != embed::EmbedStates::LOADED )
907 xObjRef->changeState( embed::EmbedStates::LOADED );
909 // TODO/LATER: there should be possible to get current mediadescriptor settings from the object
910 uno::Sequence< beans::PropertyValue > aArgs( 1 );
911 aArgs[0].Name = ::rtl::OUString( "URL" );
912 aArgs[0].Value <<= ::rtl::OUString( aNewLinkURL );
913 xPersObj->reload( aArgs, uno::Sequence< beans::PropertyValue >() );
915 mpImpl->maLinkURL = aNewLinkURL;
916 bResult = sal_True;
918 if ( nCurState != embed::EmbedStates::LOADED )
919 xObjRef->changeState( nCurState );
921 catch( ::com::sun::star::uno::Exception& )
923 OSL_FAIL(
924 (OString("SdrOle2Obj::UpdateLinkURL_Impl(), "
925 "exception caught: ") +
926 rtl::OUStringToOString(
927 comphelper::anyToString( cppu::getCaughtException() ),
928 RTL_TEXTENCODING_UTF8 )).getStr() );
932 if ( !bResult )
934 // TODO/LATER: return the old name to the link manager, is it possible?
940 return bResult;
943 // -----------------------------------------------------------------------------
945 void SdrOle2Obj::BreakFileLink_Impl()
947 uno::Reference<document::XStorageBasedDocument> xDoc;
948 if ( pModel )
949 xDoc.set( pModel->getUnoModel(),uno::UNO_QUERY);
951 if ( xDoc.is() )
953 uno::Reference< embed::XStorage > xStorage = xDoc->getDocumentStorage();
954 if ( xStorage.is() )
958 uno::Reference< embed::XLinkageSupport > xLinkSupport( xObjRef.GetObject(), uno::UNO_QUERY_THROW );
959 xLinkSupport->breakLink( xStorage, mpImpl->aPersistName );
960 DisconnectFileLink_Impl();
961 mpImpl->maLinkURL = String();
963 catch( ::com::sun::star::uno::Exception& )
965 OSL_FAIL(
966 (OString("SdrOle2Obj::BreakFileLink_Impl(), "
967 "exception caught: ") +
968 rtl::OUStringToOString(
969 comphelper::anyToString( cppu::getCaughtException() ),
970 RTL_TEXTENCODING_UTF8 )).getStr() );
976 // -----------------------------------------------------------------------------
978 void SdrOle2Obj::DisconnectFileLink_Impl()
980 sfx2::LinkManager* pLinkManager = pModel ? pModel->GetLinkManager() : NULL;
981 if ( pLinkManager && mpImpl->mpObjectLink )
983 pLinkManager->Remove( mpImpl->mpObjectLink );
984 mpImpl->mpObjectLink = NULL;
988 // -----------------------------------------------------------------------------
990 void SdrOle2Obj::CheckFileLink_Impl()
992 if ( pModel && xObjRef.GetObject().is() && !mpImpl->mpObjectLink )
996 uno::Reference< embed::XLinkageSupport > xLinkSupport( xObjRef.GetObject(), uno::UNO_QUERY );
997 if ( xLinkSupport.is() && xLinkSupport->isLink() )
999 String aLinkURL = xLinkSupport->getLinkURL();
1000 if ( aLinkURL.Len() )
1002 // this is a file link so the model link manager should handle it
1003 sfx2::LinkManager* pLinkManager = pModel->GetLinkManager();
1004 if ( pLinkManager )
1006 mpImpl->mpObjectLink = new SdrEmbedObjectLink( this );
1007 mpImpl->maLinkURL = aLinkURL;
1008 pLinkManager->InsertFileLink( *mpImpl->mpObjectLink, OBJECT_CLIENT_OLE, aLinkURL, NULL, NULL );
1009 mpImpl->mpObjectLink->Connect();
1014 catch( ::com::sun::star::uno::Exception& )
1016 OSL_FAIL(
1017 (OString("SdrOle2Obj::CheckFileLink_Impl(), "
1018 "exception caught: ") +
1019 rtl::OUStringToOString(
1020 comphelper::anyToString( cppu::getCaughtException() ),
1021 RTL_TEXTENCODING_UTF8 )).getStr() );
1026 // -----------------------------------------------------------------------------
1028 void SdrOle2Obj::Reconnect_Impl()
1030 DBG_ASSERT( mpImpl->mbConnected, "Assigned unconnected object?!" );
1031 Connect_Impl();
1034 void SdrOle2Obj::Connect_Impl()
1036 if( pModel && mpImpl->aPersistName.Len() )
1040 ::comphelper::IEmbeddedHelper* pPers = pModel->GetPersist();
1041 if ( pPers )
1043 comphelper::EmbeddedObjectContainer& rContainer = pPers->getEmbeddedObjectContainer();
1044 if ( !rContainer.HasEmbeddedObject( mpImpl->aPersistName )
1045 || ( xObjRef.is() && !rContainer.HasEmbeddedObject( xObjRef.GetObject() ) ) )
1047 // object not known to container document
1048 // No object -> disaster!
1049 DBG_ASSERT( xObjRef.is(), "No object in connect!");
1050 if ( xObjRef.is() )
1052 // object came from the outside, now add it to the container
1053 ::rtl::OUString aTmp;
1054 rContainer.InsertEmbeddedObject( xObjRef.GetObject(), aTmp );
1055 mpImpl->aPersistName = aTmp;
1058 else if ( !xObjRef.is() )
1060 xObjRef.Assign( rContainer.GetEmbeddedObject( mpImpl->aPersistName ), xObjRef.GetViewAspect() );
1061 m_bTypeAsked = false;
1064 if ( xObjRef.GetObject().is() )
1066 xObjRef.AssignToContainer( &rContainer, mpImpl->aPersistName );
1067 mpImpl->mbConnected = true;
1068 xObjRef.Lock( sal_True );
1072 if ( xObjRef.is() )
1074 if ( !mpImpl->pLightClient )
1076 mpImpl->pLightClient = new SdrLightEmbeddedClient_Impl( this );
1077 mpImpl->pLightClient->acquire();
1080 xObjRef->addStateChangeListener( mpImpl->pLightClient );
1081 xObjRef->addEventListener( uno::Reference< document::XEventListener >( mpImpl->pLightClient ) );
1083 if ( xObjRef->getCurrentState() != embed::EmbedStates::LOADED )
1084 GetSdrGlobalData().GetOLEObjCache().InsertObj(this);
1086 CheckFileLink_Impl();
1088 uno::Reference< container::XChild > xChild( xObjRef.GetObject(), uno::UNO_QUERY );
1089 if( xChild.is() )
1091 uno::Reference< uno::XInterface > xParent( pModel->getUnoModel());
1092 if( xParent.is())
1093 xChild->setParent( pModel->getUnoModel() );
1098 catch( ::com::sun::star::uno::Exception& )
1100 OSL_FAIL(
1101 (OString("SdrOle2Obj::Connect_Impl(), "
1102 "exception caught: ") +
1103 rtl::OUStringToOString(
1104 comphelper::anyToString( cppu::getCaughtException() ),
1105 RTL_TEXTENCODING_UTF8 )).getStr() );
1109 //TODO/LATER: wait for definition of MiscStatus RESIZEONPRINTERCHANGE
1110 //if ( xObjRef.is() && (*ppObjRef)->GetMiscStatus() & SVOBJ_MISCSTATUS_RESIZEONPRINTERCHANGE )
1112 //TODO/LATER: needs a new handling for OnPrinterChanged
1114 if (pModel && pModel->GetRefDevice() &&
1115 pModel->GetRefDevice()->GetOutDevType() == OUTDEV_PRINTER)
1117 // Kein RefDevice oder RefDevice kein Printer
1118 sal_Bool bModified = (*ppObjRef)->IsModified();
1119 Printer* pPrinter = (Printer*) pModel->GetRefDevice();
1120 (*ppObjRef)->OnDocumentPrinterChanged( pPrinter );
1121 (*ppObjRef)->SetModified( bModified );
1126 void SdrOle2Obj::ObjectLoaded()
1128 AddListeners_Impl();
1131 void SdrOle2Obj::AddListeners_Impl()
1133 if( xObjRef.is() && xObjRef->getCurrentState() != embed::EmbedStates::LOADED )
1135 // register modify listener
1136 if( !pModifyListener )
1138 ((SdrOle2Obj*)this)->pModifyListener = new SvxUnoShapeModifyListener( (SdrOle2Obj*)this );
1139 pModifyListener->acquire();
1142 uno::Reference< util::XModifyBroadcaster > xBC( getXModel(), uno::UNO_QUERY );
1143 if( xBC.is() && pModifyListener )
1145 uno::Reference< util::XModifyListener > xListener( pModifyListener );
1146 xBC->addModifyListener( xListener );
1151 // -----------------------------------------------------------------------------
1153 void SdrOle2Obj::Disconnect()
1155 if( IsEmptyPresObj() )
1156 return;
1158 if( !mpImpl->mbConnected )
1160 OSL_FAIL("Disconnect() called on disconnected object!");
1161 return;
1164 RemoveListeners_Impl();
1165 Disconnect_Impl();
1168 void SdrOle2Obj::RemoveListeners_Impl()
1170 if( xObjRef.is() && mpImpl->aPersistName.Len() )
1174 sal_Int32 nState = xObjRef->getCurrentState();
1175 if ( nState != embed::EmbedStates::LOADED )
1177 uno::Reference< util::XModifyBroadcaster > xBC( getXModel(), uno::UNO_QUERY );
1178 if( xBC.is() && pModifyListener )
1180 uno::Reference< util::XModifyListener > xListener( pModifyListener );
1181 xBC->removeModifyListener( xListener );
1185 catch( ::com::sun::star::uno::Exception& )
1187 OSL_FAIL(
1188 (OString("SdrOle2Obj::RemoveListeners_Impl(), "
1189 "exception caught: ") +
1190 rtl::OUStringToOString(
1191 comphelper::anyToString( cppu::getCaughtException() ),
1192 RTL_TEXTENCODING_UTF8 )).getStr() );
1197 void SdrOle2Obj::Disconnect_Impl()
1201 if ( pModel && mpImpl->aPersistName.Len() )
1203 if( pModel->IsInDestruction() )
1205 // TODO/LATER: here we must assume that the destruction of the model is enough to make clear that we will not
1206 // remove the object from the container, even if the DrawingObject itself is not destroyed (unfortunately this
1207 // There is no real need to do the following removing of the object from the container
1208 // in case the model has correct persistence, but in case of problems such a removing
1209 // would make the behavior of the office more stable
1211 comphelper::EmbeddedObjectContainer* pContainer = xObjRef.GetContainer();
1212 if ( pContainer )
1214 pContainer->CloseEmbeddedObject( xObjRef.GetObject() );
1215 xObjRef.AssignToContainer( NULL, mpImpl->aPersistName );
1218 // happens later than the destruction of the model, so we can't assert that).
1219 //DBG_ASSERT( bInDestruction, "Model is destroyed, but not me?!" );
1220 //TODO/LATER: should be make sure that the ObjectShell also forgets the object, because we will close it soon?
1222 uno::Reference < util::XCloseable > xClose( xObjRef, uno::UNO_QUERY );
1223 if ( xClose.is() )
1227 xClose->close( sal_True );
1229 catch ( util::CloseVetoException& )
1231 // there's still someone who needs the object!
1235 xObjRef = NULL;*/
1237 else if ( xObjRef.is() )
1239 if ( pModel->getUnoModel().is() )
1241 // remove object, but don't close it (that's up to someone else)
1242 comphelper::EmbeddedObjectContainer* pContainer = xObjRef.GetContainer();
1243 if ( pContainer )
1245 pContainer->RemoveEmbeddedObject( xObjRef.GetObject(), sal_False);
1247 // TODO/LATER: mpImpl->aPersistName contains outdated information, to keep it updated
1248 // it should be returned from RemoveEmbeddedObject call. Currently it is no problem,
1249 // since no container is adjusted, actually the empty string could be provided as a name here
1250 xObjRef.AssignToContainer( NULL, mpImpl->aPersistName );
1253 DisconnectFileLink_Impl();
1258 if ( xObjRef.is() && mpImpl->pLightClient )
1260 xObjRef->removeStateChangeListener ( mpImpl->pLightClient );
1261 xObjRef->removeEventListener( uno::Reference< document::XEventListener >( mpImpl->pLightClient ) );
1262 xObjRef->setClientSite( NULL );
1264 GetSdrGlobalData().GetOLEObjCache().RemoveObj(this);
1267 catch( ::com::sun::star::uno::Exception& )
1269 OSL_FAIL(
1270 (OString("SdrOle2Obj::Disconnect_Impl(), "
1271 "exception caught: ") +
1272 rtl::OUStringToOString(
1273 comphelper::anyToString( cppu::getCaughtException() ),
1274 RTL_TEXTENCODING_UTF8 )).getStr() );
1277 mpImpl->mbConnected = false;
1280 // -----------------------------------------------------------------------------
1282 void SdrOle2Obj::SetModel(SdrModel* pNewModel)
1284 ::comphelper::IEmbeddedHelper* pDestPers = pNewModel ? pNewModel->GetPersist() : 0;
1285 ::comphelper::IEmbeddedHelper* pSrcPers = pModel ? pModel->GetPersist() : 0;
1287 if ( pNewModel == pModel )
1289 // don't know if this is necessary or if it will ever happen, but who knows?!
1290 SdrRectObj::SetModel( pNewModel );
1291 return;
1294 // assignment to model has changed
1295 DBG_ASSERT( pSrcPers || !mpImpl->mbConnected, "Connected object without a model?!" );
1297 DBG_ASSERT( pDestPers, "The destination model must have a persistence! Please submit an issue!" );
1298 DBG_ASSERT( pDestPers != pSrcPers, "The source and the destination models should have different persistences! Problems are possible!" );
1300 // this is a bug if the target model has no persistence
1301 // no error handling is possible so just do nothing in this method
1302 if ( !pDestPers )
1303 return;
1305 RemoveListeners_Impl();
1307 if( pDestPers && pSrcPers && !IsEmptyPresObj() )
1311 // move the object's storage; ObjectRef remains the same, but PersistName may change
1312 ::rtl::OUString aTmp;
1313 comphelper::EmbeddedObjectContainer& rContainer = pSrcPers->getEmbeddedObjectContainer();
1314 uno::Reference < embed::XEmbeddedObject > xObj = rContainer.GetEmbeddedObject( mpImpl->aPersistName );
1315 DBG_ASSERT( !xObjRef.is() || xObjRef.GetObject() == xObj, "Wrong object identity!" );
1316 if ( xObj.is() )
1318 pDestPers->getEmbeddedObjectContainer().MoveEmbeddedObject( rContainer, xObj, aTmp );
1319 mpImpl->aPersistName = aTmp;
1320 xObjRef.AssignToContainer( &pDestPers->getEmbeddedObjectContainer(), aTmp );
1322 DBG_ASSERT( !aTmp.isEmpty(), "Copying embedded object failed!" );
1324 catch( ::com::sun::star::uno::Exception& )
1326 OSL_FAIL(
1327 (OString("SdrOle2Obj::SetModel(), "
1328 "exception caught: ") +
1329 rtl::OUStringToOString(
1330 comphelper::anyToString( cppu::getCaughtException() ),
1331 RTL_TEXTENCODING_UTF8 )).getStr() );
1335 SdrRectObj::SetModel( pNewModel );
1337 // #i43086#
1338 // #i85304 redo the change for charts for the above bugfix, as #i43086# does not occur anymore
1339 //so maybe the ImpSetVisAreaSize call can be removed here completely
1340 //Nevertheless I leave it in for other objects as I am not sure about the side effects when removing now
1341 if( pModel && !pModel->isLocked() && !IsChart() )
1342 ImpSetVisAreaSize();
1344 if( pDestPers && !IsEmptyPresObj() )
1346 if ( !pSrcPers || IsEmptyPresObj() )
1347 // object wasn't connected, now it should be
1348 Connect_Impl();
1349 else
1350 Reconnect_Impl();
1353 AddListeners_Impl();
1356 // -----------------------------------------------------------------------------
1358 void SdrOle2Obj::SetPage(SdrPage* pNewPage)
1360 bool bRemove=pNewPage==NULL && pPage!=NULL;
1361 bool bInsert=pNewPage!=NULL && pPage==NULL;
1363 if (bRemove && mpImpl->mbConnected )
1364 Disconnect();
1366 SdrRectObj::SetPage(pNewPage);
1368 if (bInsert && !mpImpl->mbConnected )
1369 Connect();
1372 // -----------------------------------------------------------------------------
1374 void SdrOle2Obj::SetObjRef( const com::sun::star::uno::Reference < com::sun::star::embed::XEmbeddedObject >& rNewObjRef )
1376 DBG_ASSERT( !rNewObjRef.is() || !xObjRef.GetObject().is(), "SetObjRef called on already initialized object!");
1377 if( rNewObjRef == xObjRef.GetObject() )
1378 return;
1380 // the caller of the method is responsible to control the old object, it will not be closed here
1381 // Otherwise WW8 import crashes because it transfers control to OLENode by this method
1382 if ( xObjRef.GetObject().is() )
1383 xObjRef.Lock( sal_False );
1385 // avoid removal of object in Disconnect! It is definitely a HACK to call SetObjRef(0)!
1386 // This call will try to close the objects; so if anybody else wants to keep it, it must be locked by a CloseListener
1387 xObjRef.Clear();
1389 if ( mpImpl->mbConnected )
1390 Disconnect();
1392 xObjRef.Assign( rNewObjRef, GetAspect() );
1393 m_bTypeAsked = false;
1395 if ( xObjRef.is() )
1397 DELETEZ( pGraphic );
1399 if ( (xObjRef->getStatus( GetAspect() ) & embed::EmbedMisc::EMBED_NEVERRESIZE ) )
1400 SetResizeProtect(sal_True);
1402 // For math objects, set closed state to transparent
1403 if( ImplIsMathObj( rNewObjRef ) )
1404 SetClosedObj( false );
1406 Connect();
1409 SetChanged();
1410 BroadcastObjectChange();
1413 // -----------------------------------------------------------------------------
1415 void SdrOle2Obj::SetClosedObj( bool bIsClosed )
1417 // TODO/LATER: do we still need this hack?
1418 // Allow changes to the closed state of OLE objects
1419 bClosedObj = bIsClosed;
1422 // -----------------------------------------------------------------------------
1424 SdrObject* SdrOle2Obj::getFullDragClone() const
1426 // special handling for OLE. The default handling works, but is too
1427 // slow when the whole OLE needs to be cloned. Get the Metafile and
1428 // create a graphic object with it
1429 Graphic* pOLEGraphic = GetGraphic();
1430 SdrObject* pClone = 0;
1432 if(pOLEGraphic)
1434 pClone = new SdrGrafObj(*pOLEGraphic, GetSnapRect());
1436 // this would be the place where to copy all attributes
1437 // when OLE will support fill and line style
1438 // pClone->SetMergedItem(pOleObject->GetMergedItemSet());
1440 else
1442 // #i100710# pOLEGraphic may be zero (no visualisation available),
1443 // so we need to use the OLE replacement graphic
1444 pClone = new SdrRectObj(GetSnapRect());
1446 // gray outline
1447 pClone->SetMergedItem(XLineStyleItem(XLINE_SOLID));
1448 const svtools::ColorConfig aColorConfig;
1449 const svtools::ColorConfigValue aColor(aColorConfig.GetColorValue(svtools::OBJECTBOUNDARIES));
1450 pClone->SetMergedItem(XLineColorItem(String(), aColor.nColor));
1452 // bitmap fill
1453 pClone->SetMergedItem(XFillStyleItem(XFILL_BITMAP));
1454 pClone->SetMergedItem(XFillBitmapItem(String(), GetEmtyOLEReplacementBitmap()));
1455 pClone->SetMergedItem(XFillBmpTileItem(false));
1456 pClone->SetMergedItem(XFillBmpStretchItem(false));
1459 return pClone;
1462 // -----------------------------------------------------------------------------
1464 void SdrOle2Obj::SetPersistName( const String& rPersistName )
1466 DBG_ASSERT( !mpImpl->aPersistName.Len(), "Persist name changed!");
1468 mpImpl->aPersistName = rPersistName;
1469 mpImpl->mbLoadingOLEObjectFailed = false;
1471 Connect();
1472 SetChanged();
1475 void SdrOle2Obj::AbandonObject()
1477 mpImpl->aPersistName.Erase();
1478 mpImpl->mbLoadingOLEObjectFailed = false;
1479 SetObjRef(0);
1482 // -----------------------------------------------------------------------------
1484 String SdrOle2Obj::GetPersistName() const
1486 return mpImpl->aPersistName;
1489 // -----------------------------------------------------------------------------
1491 void SdrOle2Obj::TakeObjInfo(SdrObjTransformInfoRec& rInfo) const
1493 rInfo.bRotateFreeAllowed=sal_False;
1494 rInfo.bRotate90Allowed =sal_False;
1495 rInfo.bMirrorFreeAllowed=sal_False;
1496 rInfo.bMirror45Allowed =sal_False;
1497 rInfo.bMirror90Allowed =sal_False;
1498 rInfo.bTransparenceAllowed = sal_False;
1499 rInfo.bGradientAllowed = sal_False;
1500 rInfo.bShearAllowed =sal_False;
1501 rInfo.bEdgeRadiusAllowed=sal_False;
1502 rInfo.bNoOrthoDesired =sal_False;
1503 rInfo.bCanConvToPath =sal_False;
1504 rInfo.bCanConvToPoly =sal_False;
1505 rInfo.bCanConvToPathLineToArea=sal_False;
1506 rInfo.bCanConvToPolyLineToArea=sal_False;
1507 rInfo.bCanConvToContour = sal_False;
1510 // -----------------------------------------------------------------------------
1512 sal_uInt16 SdrOle2Obj::GetObjIdentifier() const
1514 return bFrame ? sal_uInt16(OBJ_FRAME) : sal_uInt16(OBJ_OLE2);
1517 // -----------------------------------------------------------------------------
1519 void SdrOle2Obj::TakeObjNameSingul(XubString& rName) const
1521 rName = ImpGetResStr(bFrame ? STR_ObjNameSingulFrame : STR_ObjNameSingulOLE2);
1523 const String aName(GetName());
1525 if( aName.Len() )
1527 rName.AppendAscii(" '");
1528 rName += aName;
1529 rName += sal_Unicode('\'');
1533 // -----------------------------------------------------------------------------
1535 void SdrOle2Obj::TakeObjNamePlural(XubString& rName) const
1537 rName=ImpGetResStr(bFrame ? STR_ObjNamePluralFrame : STR_ObjNamePluralOLE2);
1540 // -----------------------------------------------------------------------------
1542 SdrOle2Obj* SdrOle2Obj::Clone() const
1544 return CloneHelper< SdrOle2Obj >();
1547 SdrOle2Obj& SdrOle2Obj::operator=(const SdrOle2Obj& rObj)
1549 //TODO/LATER: who takes over control of my old object?!
1550 if( &rObj != this )
1552 // #116235#
1553 // ImpAssign( rObj );
1554 const SdrOle2Obj& rOle2Obj = static_cast< const SdrOle2Obj& >( rObj );
1556 uno::Reference < util::XCloseable > xClose( xObjRef.GetObject(), uno::UNO_QUERY );
1558 if( pModel && mpImpl->mbConnected )
1559 Disconnect();
1561 SdrRectObj::operator=( rObj );
1563 // Manually copying bClosedObj attribute
1564 SetClosedObj( rObj.IsClosedObj() );
1566 mpImpl->aPersistName = rOle2Obj.mpImpl->aPersistName;
1567 aProgName = rOle2Obj.aProgName;
1568 bFrame = rOle2Obj.bFrame;
1570 if( rOle2Obj.pGraphic )
1572 if( pGraphic )
1574 delete pGraphic;
1575 delete mpImpl->pGraphicObject;
1578 pGraphic = new Graphic( *rOle2Obj.pGraphic );
1579 mpImpl->pGraphicObject = new GraphicObject( *pGraphic );
1582 if( pModel && rObj.GetModel() && !IsEmptyPresObj() )
1584 ::comphelper::IEmbeddedHelper* pDestPers = pModel->GetPersist();
1585 ::comphelper::IEmbeddedHelper* pSrcPers = rObj.GetModel()->GetPersist();
1586 if( pDestPers && pSrcPers )
1588 DBG_ASSERT( !xObjRef.is(), "Object already existing!" );
1589 comphelper::EmbeddedObjectContainer& rContainer = pSrcPers->getEmbeddedObjectContainer();
1590 uno::Reference < embed::XEmbeddedObject > xObj = rContainer.GetEmbeddedObject( mpImpl->aPersistName );
1591 if ( xObj.is() )
1593 ::rtl::OUString aTmp;
1594 xObjRef.Assign( pDestPers->getEmbeddedObjectContainer().CopyAndGetEmbeddedObject( rContainer, xObj, aTmp ), rOle2Obj.GetAspect() );
1595 m_bTypeAsked = false;
1596 mpImpl->aPersistName = aTmp;
1597 CheckFileLink_Impl();
1600 Connect();
1604 return *this;
1607 // -----------------------------------------------------------------------------
1609 void SdrOle2Obj::ImpSetVisAreaSize()
1611 // currently there is no need to recalculate scaling for iconified objects
1612 // TODO/LATER: it might be needed in future when it is possible to change the icon
1613 if ( GetAspect() == embed::Aspects::MSOLE_ICON )
1614 return;
1616 // the object area of an embedded object was changed, e.g. by user interaction an a selected object
1617 GetObjRef();
1618 if ( xObjRef.is() )
1620 OSL_ASSERT( pModel );
1621 sal_Int64 nMiscStatus = xObjRef->getStatus( GetAspect() );
1623 // the client is required to get access to scaling
1624 SfxInPlaceClient* pClient = SfxInPlaceClient::GetClient( dynamic_cast<SfxObjectShell*>(pModel->GetPersist()), xObjRef.GetObject() );
1625 sal_Bool bHasOwnClient =
1626 ( mpImpl->pLightClient
1627 && xObjRef->getClientSite() == uno::Reference< embed::XEmbeddedClient >( mpImpl->pLightClient ) );
1629 if ( pClient || bHasOwnClient )
1631 // TODO: IMHO we need to do similar things when object is UIActive or OutplaceActive?!
1632 if ( ((nMiscStatus & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE) &&
1633 svt::EmbeddedObjectRef::TryRunningState( xObjRef.GetObject() ))
1634 || xObjRef->getCurrentState() == embed::EmbedStates::INPLACE_ACTIVE
1637 Fraction aScaleWidth;
1638 Fraction aScaleHeight;
1639 if ( pClient )
1641 aScaleWidth = pClient->GetScaleWidth();
1642 aScaleHeight = pClient->GetScaleHeight();
1644 else
1646 aScaleWidth = mpImpl->pLightClient->GetScaleWidth();
1647 aScaleHeight = mpImpl->pLightClient->GetScaleHeight();
1650 // The object wants to resize itself (f.e. Chart wants to recalculate the layout)
1651 // or object is inplace active and so has a window that must be resized also
1652 // In these cases the change in the object area size will be reflected in a change of the
1653 // objects' visual area. The scaling will not change, but it might exist already and must
1654 // be used in calculations
1655 MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObjRef->getMapUnit( GetAspect() ) );
1656 Size aVisSize( (long)( Fraction( aRect.GetWidth() ) / aScaleWidth ),
1657 (long)( Fraction( aRect.GetHeight() ) / aScaleHeight ) );
1659 aVisSize = OutputDevice::LogicToLogic( aVisSize, pModel->GetScaleUnit(), aMapUnit);
1660 awt::Size aSz;
1661 aSz.Width = aVisSize.Width();
1662 aSz.Height = aVisSize.Height();
1663 xObjRef->setVisualAreaSize( GetAspect(), aSz );
1667 aSz = xObjRef->getVisualAreaSize( GetAspect() );
1669 catch( embed::NoVisualAreaSizeException& )
1672 Rectangle aAcceptedVisArea;
1673 aAcceptedVisArea.SetSize( Size( (long)( Fraction( long( aSz.Width ) ) * aScaleWidth ),
1674 (long)( Fraction( long( aSz.Height ) ) * aScaleHeight ) ) );
1675 if (aVisSize != aAcceptedVisArea.GetSize())
1677 // server changed VisArea to its liking and the VisArea is different than the suggested one
1678 // store the new value as given by the object
1679 MapUnit aNewMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObjRef->getMapUnit( GetAspect() ) );
1680 aRect.SetSize(OutputDevice::LogicToLogic( aAcceptedVisArea.GetSize(), aNewMapUnit, pModel->GetScaleUnit()));
1683 // make the new object area known to the client
1684 // compared to the "else" branch aRect might have been changed by the object and no additional scaling was applied
1685 // WHY this -> OSL_ASSERT( pClient );
1686 if( pClient )
1687 pClient->SetObjArea(aRect);
1689 // we need a new replacement image as the object has resized itself
1691 //#i79578# don't request a new replacement image for charts to often
1692 //a chart sends a modified call to the framework if it was changed
1693 //thus the replacement update is already handled there
1694 if( !IsChart() )
1695 xObjRef.UpdateReplacement();
1697 else
1699 // The object isn't active and does not want to resize itself so the changed object area size
1700 // will be reflected in a changed object scaling
1701 Fraction aScaleWidth;
1702 Fraction aScaleHeight;
1703 Size aObjAreaSize;
1704 if ( CalculateNewScaling( aScaleWidth, aScaleHeight, aObjAreaSize ) )
1706 if ( pClient )
1708 Rectangle aScaleRect(aRect.TopLeft(), aObjAreaSize);
1709 pClient->SetObjAreaAndScale( aScaleRect, aScaleWidth, aScaleHeight);
1711 else
1713 mpImpl->pLightClient->SetSizeScale( aScaleWidth, aScaleHeight );
1718 else if( (nMiscStatus & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE) &&
1719 svt::EmbeddedObjectRef::TryRunningState( xObjRef.GetObject() ) )
1721 //also handle not sfx based ole objects e.g. charts
1722 //#i83860# resizing charts in impress distorts fonts
1723 uno::Reference< embed::XVisualObject > xVisualObject( this->getXModel(), uno::UNO_QUERY );
1724 if( xVisualObject.is() )
1726 MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObjRef->getMapUnit( GetAspect() ) );
1727 Point aTL( aRect.TopLeft() );
1728 Point aBR( aRect.BottomRight() );
1729 Point aTL2( OutputDevice::LogicToLogic( aTL, pModel->GetScaleUnit(), aMapUnit) );
1730 Point aBR2( OutputDevice::LogicToLogic( aBR, pModel->GetScaleUnit(), aMapUnit) );
1731 Rectangle aNewRect( aTL2, aBR2 );
1732 xVisualObject->setVisualAreaSize( GetAspect(), awt::Size( aNewRect.GetWidth(), aNewRect.GetHeight() ) );
1738 // -----------------------------------------------------------------------------
1740 void SdrOle2Obj::NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact)
1742 if( pModel && !pModel->isLocked() )
1744 GetObjRef();
1745 if ( xObjRef.is() && ( xObjRef->getStatus( GetAspect() ) & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE ) )
1747 // if the object needs recompose on resize
1748 // the client site should be created before the resize will take place
1749 // check whether there is no client site and create it if necessary
1750 AddOwnLightClient();
1754 SdrRectObj::NbcResize(rRef,xFact,yFact);
1755 if (aGeo.nShearWink!=0 || aGeo.nDrehWink!=0) { // little corrections
1756 if (aGeo.nDrehWink>=9000 && aGeo.nDrehWink<27000) {
1757 aRect.Move(aRect.Left()-aRect.Right(),aRect.Top()-aRect.Bottom());
1759 aGeo.nDrehWink=0;
1760 aGeo.nShearWink=0;
1761 aGeo.nSin=0.0;
1762 aGeo.nCos=1.0;
1763 aGeo.nTan=0.0;
1764 SetRectsDirty();
1766 if( pModel && !pModel->isLocked() )
1767 ImpSetVisAreaSize();
1770 // -----------------------------------------------------------------------------
1772 void SdrOle2Obj::SetGeoData(const SdrObjGeoData& rGeo)
1774 SdrRectObj::SetGeoData(rGeo);
1775 if( pModel && !pModel->isLocked() )
1776 ImpSetVisAreaSize();
1779 // -----------------------------------------------------------------------------
1781 void SdrOle2Obj::NbcSetSnapRect(const Rectangle& rRect)
1783 SdrRectObj::NbcSetSnapRect(rRect);
1784 if( pModel && !pModel->isLocked() )
1785 ImpSetVisAreaSize();
1787 if ( xObjRef.is() && IsChart() )
1789 //#i103460# charts do not necessarily have an own size within ODF files,
1790 //for this case they need to use the size settings from the surrounding frame,
1791 //which is made available with this method as there is no other way
1792 xObjRef.SetDefaultSizeForChart( Size( rRect.GetWidth(), rRect.GetHeight() ) );
1796 // -----------------------------------------------------------------------------
1798 void SdrOle2Obj::NbcSetLogicRect(const Rectangle& rRect)
1800 SdrRectObj::NbcSetLogicRect(rRect);
1801 if( pModel && !pModel->isLocked() )
1802 ImpSetVisAreaSize();
1805 Graphic* SdrOle2Obj::GetGraphic() const
1807 if ( xObjRef.is() )
1808 return xObjRef.GetGraphic();
1809 return pGraphic;
1812 void SdrOle2Obj::GetNewReplacement()
1814 if ( xObjRef.is() )
1815 xObjRef.UpdateReplacement();
1818 // -----------------------------------------------------------------------------
1820 Size SdrOle2Obj::GetOrigObjSize( MapMode* pTargetMapMode ) const
1822 return xObjRef.GetSize( pTargetMapMode );
1825 // -----------------------------------------------------------------------------
1827 void SdrOle2Obj::NbcMove(const Size& rSize)
1829 SdrRectObj::NbcMove(rSize);
1830 if( pModel && !pModel->isLocked() )
1831 ImpSetVisAreaSize();
1834 // -----------------------------------------------------------------------------
1836 sal_Bool SdrOle2Obj::CanUnloadRunningObj( const uno::Reference< embed::XEmbeddedObject >& xObj, sal_Int64 nAspect )
1838 sal_Bool bResult = sal_False;
1840 sal_Int32 nState = xObj->getCurrentState();
1841 if ( nState == embed::EmbedStates::LOADED )
1843 // the object is already unloaded
1844 bResult = sal_True;
1846 else
1848 uno::Reference < util::XModifiable > xModifiable( xObj->getComponent(), uno::UNO_QUERY );
1849 if ( !xModifiable.is() )
1850 bResult = sal_True;
1851 else
1853 sal_Int64 nMiscStatus = xObj->getStatus( nAspect );
1855 if ( embed::EmbedMisc::MS_EMBED_ALWAYSRUN != ( nMiscStatus & embed::EmbedMisc::MS_EMBED_ALWAYSRUN ) &&
1856 embed::EmbedMisc::EMBED_ACTIVATEIMMEDIATELY != ( nMiscStatus & embed::EmbedMisc::EMBED_ACTIVATEIMMEDIATELY ) &&
1857 !( xModifiable.is() && xModifiable->isModified() ) &&
1858 !( nState == embed::EmbedStates::INPLACE_ACTIVE || nState == embed::EmbedStates::UI_ACTIVE || nState == embed::EmbedStates::ACTIVE ) )
1860 bResult = sal_True;
1865 return bResult;
1868 // -----------------------------------------------------------------------------
1870 sal_Bool SdrOle2Obj::Unload( const uno::Reference< embed::XEmbeddedObject >& xObj, sal_Int64 nAspect )
1872 sal_Bool bResult = sal_False;
1874 if ( CanUnloadRunningObj( xObj, nAspect ) )
1878 xObj->changeState( embed::EmbedStates::LOADED );
1879 bResult = sal_True;
1881 catch( ::com::sun::star::uno::Exception& )
1883 OSL_FAIL(
1884 (OString("SdrOle2Obj::Unload=(), "
1885 "exception caught: ") +
1886 rtl::OUStringToOString(
1887 comphelper::anyToString( cppu::getCaughtException() ),
1888 RTL_TEXTENCODING_UTF8 )).getStr() );
1892 return bResult;
1895 // -----------------------------------------------------------------------------
1897 sal_Bool SdrOle2Obj::Unload()
1899 sal_Bool bUnloaded = sal_False;
1901 if( xObjRef.is() )
1903 //TODO/LATER: no refcounting tricks anymore!
1904 //"customers" must register as state change listeners
1905 // Not necessary in Doc DTor (MM)
1906 //sal_uIntPtr nRefCount = (*ppObjRef)->GetRefCount();
1907 // prevent Unload if there are external references
1908 //if( nRefCount > 2 )
1909 // return sal_False;
1910 //DBG_ASSERT( nRefCount == 2, "Wrong RefCount for unload" );
1912 else
1913 bUnloaded = sal_True;
1915 if ( pModel && xObjRef.is() )
1917 bUnloaded = Unload( xObjRef.GetObject(), GetAspect() );
1920 return bUnloaded;
1923 // -----------------------------------------------------------------------------
1925 void SdrOle2Obj::GetObjRef_Impl()
1927 if ( !xObjRef.is() && mpImpl->aPersistName.Len() && pModel && pModel->GetPersist() )
1929 // Only try loading if it did not went wrong up to now
1930 if(!mpImpl->mbLoadingOLEObjectFailed)
1932 xObjRef.Assign( pModel->GetPersist()->getEmbeddedObjectContainer().GetEmbeddedObject( mpImpl->aPersistName ), GetAspect() );
1933 m_bTypeAsked = false;
1934 CheckFileLink_Impl();
1936 // If loading of OLE object failed, remember that to not invoke a endless
1937 // loop trying to load it again and again.
1938 if( xObjRef.is() )
1940 mpImpl->mbLoadingOLEObjectFailed = sal_True;
1943 // For math objects, set closed state to transparent
1944 if( ImplIsMathObj( xObjRef.GetObject() ) )
1945 SetClosedObj( false );
1948 if ( xObjRef.is() )
1950 if( !IsEmptyPresObj() )
1952 // remember modified status of model
1953 const sal_Bool bWasChanged(pModel ? pModel->IsChanged() : sal_False);
1955 // perhaps preview not valid anymore
1956 // This line changes the modified state of the model
1957 SetGraphic_Impl( NULL );
1959 // if status was not set before, force it back
1960 // to not set, so that SetGraphic(0L) above does not
1961 // set the modified state of the model.
1962 if(!bWasChanged && pModel && pModel->IsChanged())
1964 pModel->SetChanged( sal_False );
1968 sal_Int64 nMiscStatus = xObjRef->getStatus( GetAspect() );
1969 (void)nMiscStatus;
1970 //TODO/LATER: wait until ResizeOnPrinterChange is defined
1971 //if ( nMiscStatus & SVOBJ_MISCSTATUS_RESIZEONPRINTERCHANGE )
1973 if (pModel && pModel->GetRefDevice() &&
1974 pModel->GetRefDevice()->GetOutDevType() == OUTDEV_PRINTER)
1976 if(!bInDestruction)
1978 //TODO/LATER: printerchange notification
1980 // prevent SetModified (don't want no update here)
1981 sal_Bool bWasEnabled = (*ppObjRef)->IsEnableSetModified();
1982 if ( bWasEnabled )
1983 (*ppObjRef)->EnableSetModified( sal_False );
1985 // Kein RefDevice oder RefDevice kein Printer
1986 Printer* pPrinter = (Printer*) pModel->GetRefDevice();
1987 (*ppObjRef)->OnDocumentPrinterChanged( pPrinter );
1989 // reset state
1990 (*ppObjRef)->EnableSetModified( bWasEnabled );*/
1996 if ( xObjRef.is() )
1997 Connect();
2000 if ( mpImpl->mbConnected )
2001 // move object to first position in cache
2002 GetSdrGlobalData().GetOLEObjCache().InsertObj(this);
2005 uno::Reference < embed::XEmbeddedObject > SdrOle2Obj::GetObjRef() const
2007 const_cast<SdrOle2Obj*>(this)->GetObjRef_Impl();
2008 return xObjRef.GetObject();
2011 uno::Reference < embed::XEmbeddedObject > SdrOle2Obj::GetObjRef_NoInit() const
2013 return xObjRef.GetObject();
2016 // -----------------------------------------------------------------------------
2018 uno::Reference< frame::XModel > SdrOle2Obj::getXModel() const
2020 GetObjRef();
2021 if ( svt::EmbeddedObjectRef::TryRunningState(xObjRef.GetObject()) )
2022 return uno::Reference< frame::XModel >( xObjRef->getComponent(), uno::UNO_QUERY );
2023 else
2024 return uno::Reference< frame::XModel >();
2027 // -----------------------------------------------------------------------------
2029 sal_Bool SdrOle2Obj::IsChart() const
2031 if ( !m_bTypeAsked )
2033 m_bChart = ChartPrettyPainter::IsChart(xObjRef);
2034 m_bTypeAsked = true;
2036 return m_bChart;
2039 // -----------------------------------------------------------------------------
2040 void SdrOle2Obj::SetGraphicToObj( const Graphic& aGraphic, const ::rtl::OUString& aMediaType )
2042 xObjRef.SetGraphic( aGraphic, aMediaType );
2045 // -----------------------------------------------------------------------------
2046 void SdrOle2Obj::SetGraphicToObj( const uno::Reference< io::XInputStream >& xGrStream, const ::rtl::OUString& aMediaType )
2048 xObjRef.SetGraphicStream( xGrStream, aMediaType );
2051 // -----------------------------------------------------------------------------
2052 sal_Bool SdrOle2Obj::IsCalc() const
2054 if ( !xObjRef.is() )
2055 return false;
2057 SvGlobalName aObjClsId( xObjRef->getClassID() );
2058 if( SvGlobalName(SO3_SC_CLASSID_30) == aObjClsId
2059 || SvGlobalName(SO3_SC_CLASSID_40) == aObjClsId
2060 || SvGlobalName(SO3_SC_CLASSID_50) == aObjClsId
2061 || SvGlobalName(SO3_SC_CLASSID_60) == aObjClsId
2062 || SvGlobalName(SO3_SC_OLE_EMBED_CLASSID_60) == aObjClsId
2063 || SvGlobalName(SO3_SC_OLE_EMBED_CLASSID_8) == aObjClsId
2064 || SvGlobalName(SO3_SC_CLASSID) == aObjClsId )
2066 return sal_True;
2069 return sal_False;
2072 // -----------------------------------------------------------------------------
2073 uno::Reference< frame::XModel > SdrOle2Obj::GetParentXModel() const
2075 uno::Reference< frame::XModel > xDoc;
2076 if ( pModel )
2077 xDoc.set( pModel->getUnoModel(),uno::UNO_QUERY);
2078 return xDoc;
2081 // -----------------------------------------------------------------------------
2082 sal_Bool SdrOle2Obj::CalculateNewScaling( Fraction& aScaleWidth, Fraction& aScaleHeight, Size& aObjAreaSize )
2084 // TODO/LEAN: to avoid rounding errors scaling always uses the VisArea.
2085 // If we don't cache it for own objects also we must load the object here
2086 if ( !xObjRef.is() || !pModel )
2087 return sal_False;
2089 MapMode aMapMode( pModel->GetScaleUnit() );
2090 aObjAreaSize = xObjRef.GetSize( &aMapMode );
2092 Size aSize = aRect.GetSize();
2093 aScaleWidth = Fraction(aSize.Width(), aObjAreaSize.Width() );
2094 aScaleHeight = Fraction(aSize.Height(), aObjAreaSize.Height() );
2096 // reduce to 10 binary digits
2097 Kuerzen(aScaleHeight, 10);
2098 Kuerzen(aScaleWidth, 10);
2100 return sal_True;
2103 // -----------------------------------------------------------------------------
2104 sal_Bool SdrOle2Obj::AddOwnLightClient()
2106 // The Own Light Client must be registered in object only using this method!
2107 if ( !SfxInPlaceClient::GetClient( dynamic_cast<SfxObjectShell*>(pModel->GetPersist()), xObjRef.GetObject() )
2108 && !( mpImpl->pLightClient && xObjRef->getClientSite() == uno::Reference< embed::XEmbeddedClient >( mpImpl->pLightClient ) ) )
2110 Connect();
2112 if ( xObjRef.is() && mpImpl->pLightClient )
2114 Fraction aScaleWidth;
2115 Fraction aScaleHeight;
2116 Size aObjAreaSize;
2117 if ( CalculateNewScaling( aScaleWidth, aScaleHeight, aObjAreaSize ) )
2119 mpImpl->pLightClient->SetSizeScale( aScaleWidth, aScaleHeight );
2120 try {
2121 xObjRef->setClientSite( mpImpl->pLightClient );
2122 return sal_True;
2123 } catch( uno::Exception& )
2129 return sal_False;
2132 return sal_True;
2135 //////////////////////////////////////////////////////////////////////////////
2137 Bitmap SdrOle2Obj::GetEmtyOLEReplacementBitmap()
2139 return Bitmap(ResId(BMP_SVXOLEOBJ, *ImpGetResMgr()));
2142 //////////////////////////////////////////////////////////////////////////////
2144 void SdrOle2Obj::SetWindow(const com::sun::star::uno::Reference < com::sun::star::awt::XWindow >& _xWindow)
2146 if ( xObjRef.is() && mpImpl->pLightClient )
2148 mpImpl->pLightClient->setWindow(_xWindow);
2152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */