Update ooo320-m1
[ooovba.git] / svx / source / svdraw / svdoole2.cxx
blob1e89aab1b093698b2168b586fdc61cc7f78a15fa
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: svdoole2.cxx,v $
10 * $Revision: 1.89.60.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #include <svx/svdoole2.hxx>
35 #include <com/sun/star/util/XModifyBroadcaster.hpp>
36 #include <com/sun/star/util/XModifiable.hpp>
37 #include <com/sun/star/embed/EmbedStates.hpp>
38 #include <com/sun/star/embed/ElementModes.hpp>
39 #include <com/sun/star/embed/EmbedMisc.hpp>
40 #include <com/sun/star/embed/Aspects.hpp>
41 #include <com/sun/star/embed/XInplaceClient.hpp>
42 #include <com/sun/star/embed/XInplaceObject.hpp>
43 #include <com/sun/star/embed/XLinkageSupport.hpp>
44 #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
45 #include <com/sun/star/embed/XWindowSupplier.hpp>
46 #include <com/sun/star/document/XEventListener.hpp>
47 #include <com/sun/star/container/XChild.hpp>
48 #include "com/sun/star/document/XStorageBasedDocument.hpp"
50 #include <comphelper/processfactory.hxx>
51 #include <cppuhelper/exc_hlp.hxx>
52 #include <unotools/ucbstreamhelper.hxx>
54 #include <toolkit/helper/vclunohelper.hxx>
55 #include <toolkit/awt/vclxwindow.hxx>
56 #include <toolkit/helper/convert.hxx>
58 #include <svtools/filter.hxx>
59 #include <svtools/embedhlp.hxx>
61 #include <sfx2/objsh.hxx>
62 #include <sfx2/ipclient.hxx>
63 #include <sfx2/lnkbase.hxx>
64 #include <tools/stream.hxx>
65 #include <comphelper/anytostring.hxx>
66 #include <svx/svdpagv.hxx>
67 #include <tools/globname.hxx>
68 #include <vcl/jobset.hxx>
69 #include <sot/clsids.hxx>
71 #include <sot/formats.hxx>
72 #include <linkmgr.hxx>
73 #include <svtools/transfer.hxx>
74 #include <cppuhelper/implbase5.hxx>
76 #include <svtools/solar.hrc>
77 #include <svtools/urihelper.hxx>
78 #include <vos/mutex.hxx>
79 #include <vcl/svapp.hxx>
81 #include <svx/svdpagv.hxx>
82 #include <svx/svdmodel.hxx>
83 #include "svdglob.hxx" // Stringcache
84 #include "svdstr.hrc" // Objektname
85 #include <svx/svdetc.hxx>
86 #include <svx/svdview.hxx>
87 #include "unomlstr.hxx"
88 #include "impgrf.hxx"
89 #include <svtools/chartprettypainter.hxx>
90 #include <svx/sdr/contact/viewcontactofsdrole2obj.hxx>
91 #include <svx/svdograf.hxx>
93 // #i100710#
94 #include <svx/xlnclit.hxx>
95 #include <svx/xbtmpit.hxx>
96 #include <svx/xflbmtit.hxx>
97 #include <svx/xflbstit.hxx>
99 using namespace ::rtl;
100 using namespace ::com::sun::star;
102 uno::Reference < beans::XPropertySet > lcl_getFrame_throw(const SdrOle2Obj* _pObject)
104 uno::Reference < beans::XPropertySet > xFrame;
105 if ( _pObject )
107 uno::Reference< frame::XController> xController = _pObject->GetParentXModel()->getCurrentController();
108 if ( xController.is() )
110 xFrame.set( xController->getFrame(),uno::UNO_QUERY_THROW);
112 } // if ( _pObject )
113 return xFrame;
116 class SdrLightEmbeddedClient_Impl : public ::cppu::WeakImplHelper5
117 < embed::XStateChangeListener
118 , document::XEventListener
119 , embed::XInplaceClient
120 , embed::XEmbeddedClient
121 , embed::XWindowSupplier
124 uno::Reference< awt::XWindow > m_xWindow;
125 SdrOle2Obj* mpObj;
127 Fraction m_aScaleWidth;
128 Fraction m_aScaleHeight;
131 public:
132 SdrLightEmbeddedClient_Impl( SdrOle2Obj* pObj );
133 void Release();
135 void SetSizeScale( const Fraction& aScaleWidth, const Fraction& aScaleHeight )
137 m_aScaleWidth = aScaleWidth;
138 m_aScaleHeight = aScaleHeight;
141 Fraction GetScaleWidth() const { return m_aScaleWidth; }
142 Fraction GetScaleHeight() const { return m_aScaleHeight; }
144 void setWindow(const uno::Reference< awt::XWindow >& _xWindow);
146 private:
147 Rectangle impl_getScaledRect_nothrow() const;
148 // XStateChangeListener
149 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);
150 virtual void SAL_CALL stateChanged( const ::com::sun::star::lang::EventObject& aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState ) throw (::com::sun::star::uno::RuntimeException);
151 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
153 // document::XEventListener
154 virtual void SAL_CALL notifyEvent( const document::EventObject& aEvent ) throw( uno::RuntimeException );
156 // XEmbeddedClient
157 virtual void SAL_CALL saveObject() throw ( embed::ObjectSaveVetoException, uno::Exception, uno::RuntimeException );
158 virtual void SAL_CALL visibilityChanged( sal_Bool bVisible ) throw ( embed::WrongStateException, uno::RuntimeException );
160 // XComponentSupplier
161 virtual uno::Reference< util::XCloseable > SAL_CALL getComponent() throw ( uno::RuntimeException );
163 // XInplaceClient
164 virtual sal_Bool SAL_CALL canInplaceActivate() throw ( uno::RuntimeException );
165 virtual void SAL_CALL activatingInplace() throw ( embed::WrongStateException, uno::RuntimeException );
166 virtual void SAL_CALL activatingUI() throw ( embed::WrongStateException, uno::RuntimeException );
167 virtual void SAL_CALL deactivatedInplace() throw ( embed::WrongStateException, uno::RuntimeException );
168 virtual void SAL_CALL deactivatedUI() throw ( embed::WrongStateException, uno::RuntimeException );
169 virtual uno::Reference< ::com::sun::star::frame::XLayoutManager > SAL_CALL getLayoutManager() throw ( embed::WrongStateException, uno::RuntimeException );
170 virtual uno::Reference< frame::XDispatchProvider > SAL_CALL getInplaceDispatchProvider() throw ( embed::WrongStateException, uno::RuntimeException );
171 virtual awt::Rectangle SAL_CALL getPlacement() throw ( embed::WrongStateException, uno::RuntimeException );
172 virtual awt::Rectangle SAL_CALL getClipRectangle() throw ( embed::WrongStateException, uno::RuntimeException );
173 virtual void SAL_CALL translateAccelerators( const uno::Sequence< awt::KeyEvent >& aKeys ) throw ( embed::WrongStateException, uno::RuntimeException );
174 virtual void SAL_CALL scrollObject( const awt::Size& aOffset ) throw ( embed::WrongStateException, uno::RuntimeException );
175 virtual void SAL_CALL changedPlacement( const awt::Rectangle& aPosRect ) throw ( embed::WrongStateException, uno::Exception, uno::RuntimeException );
177 // XWindowSupplier
178 virtual uno::Reference< awt::XWindow > SAL_CALL getWindow() throw ( uno::RuntimeException );
181 //--------------------------------------------------------------------
182 SdrLightEmbeddedClient_Impl::SdrLightEmbeddedClient_Impl( SdrOle2Obj* pObj )
183 : mpObj( pObj )
186 Rectangle SdrLightEmbeddedClient_Impl::impl_getScaledRect_nothrow() const
188 MapUnit aContainerMapUnit( MAP_100TH_MM );
189 uno::Reference< embed::XVisualObject > xParentVis( mpObj->GetParentXModel(), uno::UNO_QUERY );
190 if ( xParentVis.is() )
191 aContainerMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xParentVis->getMapUnit( mpObj->GetAspect() ) );
192 Rectangle aLogicRect( mpObj->GetLogicRect() );
193 // apply scaling to object area and convert to pixels
194 aLogicRect.SetSize( Size( Fraction( aLogicRect.GetWidth() ) * m_aScaleWidth,
195 Fraction( aLogicRect.GetHeight() ) * m_aScaleHeight ) );
196 return aLogicRect;
198 //--------------------------------------------------------------------
199 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)
203 //--------------------------------------------------------------------
204 void SdrLightEmbeddedClient_Impl::Release()
207 ::vos::OGuard aGuard( Application::GetSolarMutex() );
208 mpObj = NULL;
211 release();
214 //--------------------------------------------------------------------
215 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)
217 ::vos::OGuard aGuard( Application::GetSolarMutex() );
219 if ( mpObj && nOldState == embed::EmbedStates::LOADED && nNewState == embed::EmbedStates::RUNNING )
221 mpObj->ObjectLoaded();
222 GetSdrGlobalData().GetOLEObjCache().InsertObj(mpObj);
224 else if ( mpObj && nNewState == embed::EmbedStates::LOADED && nOldState == embed::EmbedStates::RUNNING )
226 GetSdrGlobalData().GetOLEObjCache().RemoveObj(mpObj);
230 //--------------------------------------------------------------------
231 void SAL_CALL SdrLightEmbeddedClient_Impl::disposing( const ::com::sun::star::lang::EventObject& /*aEvent*/ ) throw (::com::sun::star::uno::RuntimeException)
233 ::vos::OGuard aGuard( Application::GetSolarMutex() );
235 GetSdrGlobalData().GetOLEObjCache().RemoveObj(mpObj);
238 //--------------------------------------------------------------------
239 void SAL_CALL SdrLightEmbeddedClient_Impl::notifyEvent( const document::EventObject& aEvent ) throw( uno::RuntimeException )
241 // TODO/LATER: when writer uses this implementation the code could be shared with SfxInPlaceClient_Impl
243 ::vos::OGuard aGuard( Application::GetSolarMutex() );
245 // the code currently makes sence only in case there is no other client
246 if ( mpObj && mpObj->GetAspect() != embed::Aspects::MSOLE_ICON && aEvent.EventName.equalsAscii("OnVisAreaChanged")
247 && mpObj->GetObjRef().is() && mpObj->GetObjRef()->getClientSite() == uno::Reference< embed::XEmbeddedClient >( this ) )
251 MapUnit aContainerMapUnit( MAP_100TH_MM );
252 uno::Reference< embed::XVisualObject > xParentVis( mpObj->GetParentXModel(), uno::UNO_QUERY );
253 if ( xParentVis.is() )
254 aContainerMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xParentVis->getMapUnit( mpObj->GetAspect() ) );
256 MapUnit aObjMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( mpObj->GetObjRef()->getMapUnit( mpObj->GetAspect() ) );
258 Rectangle aVisArea;
259 awt::Size aSz;
262 aSz = mpObj->GetObjRef()->getVisualAreaSize( mpObj->GetAspect() );
264 catch( embed::NoVisualAreaSizeException& )
266 OSL_ENSURE( sal_False, "No visual area size!\n" );
267 aSz.Width = 5000;
268 aSz.Height = 5000;
270 catch( uno::Exception& )
272 OSL_ENSURE( sal_False, "Unexpected exception!\n" );
273 aSz.Width = 5000;
274 aSz.Height = 5000;
277 aVisArea.SetSize( Size( aSz.Width, aSz.Height ) );
278 aVisArea = OutputDevice::LogicToLogic( aVisArea, aObjMapUnit, aContainerMapUnit );
279 Size aScaledSize( static_cast< long >( m_aScaleWidth * Fraction( aVisArea.GetWidth() ) ),
280 static_cast< long >( m_aScaleHeight * Fraction( aVisArea.GetHeight() ) ) );
281 Rectangle aLogicRect( mpObj->GetLogicRect() );
283 // react to the change if the difference is bigger than one pixel
284 Size aPixelDiff =
285 Application::GetDefaultDevice()->LogicToPixel(
286 Size( aLogicRect.GetWidth() - aScaledSize.Width(),
287 aLogicRect.GetHeight() - aScaledSize.Height() ),
288 aContainerMapUnit );
289 if( aPixelDiff.Width() || aPixelDiff.Height() )
291 mpObj->SetLogicRect( Rectangle( aLogicRect.TopLeft(), aScaledSize ) );
292 mpObj->BroadcastObjectChange();
294 else
295 mpObj->ActionChanged();
297 catch( uno::Exception& )
299 OSL_ENSURE( sal_False, "Unexpected exception!\n" );
304 //--------------------------------------------------------------------
305 void SAL_CALL SdrLightEmbeddedClient_Impl::saveObject()
306 throw ( embed::ObjectSaveVetoException,
307 uno::Exception,
308 uno::RuntimeException )
310 // TODO/LATER: when writer uses this implementation the code could be shared with SfxInPlaceClient_Impl
311 uno::Reference< embed::XCommonEmbedPersist > xPersist;
312 uno::Reference< util::XModifiable > xModifiable;
315 ::vos::OGuard aGuard( Application::GetSolarMutex() );
317 if ( !mpObj )
318 throw embed::ObjectSaveVetoException();
320 // the common persistance is supported by objects and links
321 xPersist = uno::Reference< embed::XCommonEmbedPersist >( mpObj->GetObjRef(), uno::UNO_QUERY_THROW );
322 xModifiable = uno::Reference< util::XModifiable >( mpObj->GetParentXModel(), uno::UNO_QUERY );
325 xPersist->storeOwn();
327 if ( xModifiable.is() )
328 xModifiable->setModified( sal_True );
331 //--------------------------------------------------------------------
332 void SAL_CALL SdrLightEmbeddedClient_Impl::visibilityChanged( sal_Bool /*bVisible*/ )
333 throw ( embed::WrongStateException,
334 uno::RuntimeException )
336 // nothing to do currently
337 // TODO/LATER: when writer uses this implementation the code could be shared with SfxInPlaceClient_Impl
338 if ( mpObj )
340 Rectangle aLogicRect( mpObj->GetLogicRect() );
341 Size aLogicSize( aLogicRect.GetWidth(), aLogicRect.GetHeight() );
343 if( mpObj->IsChart() )
345 //charts never should be stretched see #i84323# for example
346 mpObj->SetLogicRect( Rectangle( aLogicRect.TopLeft(), aLogicSize ) );
347 mpObj->BroadcastObjectChange();
348 } // if( mpObj->IsChart() )
352 //--------------------------------------------------------------------
353 uno::Reference< util::XCloseable > SAL_CALL SdrLightEmbeddedClient_Impl::getComponent()
354 throw ( uno::RuntimeException )
356 uno::Reference< util::XCloseable > xResult;
358 ::vos::OGuard aGuard( Application::GetSolarMutex() );
359 if ( mpObj )
360 xResult = uno::Reference< util::XCloseable >( mpObj->GetParentXModel(), uno::UNO_QUERY );
362 return xResult;
364 // XInplaceClient
365 //--------------------------------------------------------------------
366 sal_Bool SAL_CALL SdrLightEmbeddedClient_Impl::canInplaceActivate()
367 throw ( uno::RuntimeException )
369 sal_Bool bRet = sal_False;
370 ::vos::OGuard aGuard( Application::GetSolarMutex() );
371 if ( mpObj )
373 uno::Reference< embed::XEmbeddedObject > xObject = mpObj->GetObjRef();
374 if ( !xObject.is() )
375 throw uno::RuntimeException();
376 // we don't want to switch directly from outplace to inplace mode
377 bRet = !( xObject->getCurrentState() == embed::EmbedStates::ACTIVE || mpObj->GetAspect() == embed::Aspects::MSOLE_ICON );
378 } // if ( mpObj )
379 return bRet;
382 //--------------------------------------------------------------------
383 void SAL_CALL SdrLightEmbeddedClient_Impl::activatingInplace()
384 throw ( embed::WrongStateException,
385 uno::RuntimeException )
389 //--------------------------------------------------------------------
390 void SAL_CALL SdrLightEmbeddedClient_Impl::activatingUI()
391 throw ( embed::WrongStateException,
392 uno::RuntimeException )
394 ::vos::OGuard aGuard( Application::GetSolarMutex() );
396 uno::Reference < beans::XPropertySet > xFrame( lcl_getFrame_throw(mpObj));
397 uno::Reference < frame::XFrame > xOwnFrame( xFrame,uno::UNO_QUERY);
398 uno::Reference < frame::XFramesSupplier > xParentFrame( xOwnFrame->getCreator(), uno::UNO_QUERY );
399 if ( xParentFrame.is() )
400 xParentFrame->setActiveFrame( xOwnFrame );
402 OLEObjCache& rObjCache = GetSdrGlobalData().GetOLEObjCache();
403 const ULONG nCount = rObjCache.Count();
404 for(sal_Int32 i = nCount-1 ; i >= 0;--i)
406 SdrOle2Obj* pObj = reinterpret_cast<SdrOle2Obj*>(rObjCache.GetObject(i));
407 if ( pObj != mpObj )
409 // only deactivate ole objects which belongs to the same frame
410 if ( xFrame == lcl_getFrame_throw(pObj) )
412 uno::Reference< embed::XEmbeddedObject > xObject = pObj->GetObjRef();
415 if ( xObject->getStatus( pObj->GetAspect() ) & embed::EmbedMisc::MS_EMBED_ACTIVATEWHENVISIBLE )
416 xObject->changeState( embed::EmbedStates::INPLACE_ACTIVE );
417 else
419 // the links should not stay in running state for long time because of locking
420 uno::Reference< embed::XLinkageSupport > xLink( xObject, uno::UNO_QUERY );
421 if ( xLink.is() && xLink->isLink() )
422 xObject->changeState( embed::EmbedStates::LOADED );
423 else
424 xObject->changeState( embed::EmbedStates::RUNNING );
427 catch (com::sun::star::uno::Exception& )
431 } // for(sal_Int32 i = nCount-1 ; i >= 0;--i)
433 //m_pClient->GetViewShell()->UIActivating( m_pClient );
436 //--------------------------------------------------------------------
437 void SAL_CALL SdrLightEmbeddedClient_Impl::deactivatedInplace()
438 throw ( embed::WrongStateException,
439 uno::RuntimeException )
443 //--------------------------------------------------------------------
444 void SAL_CALL SdrLightEmbeddedClient_Impl::deactivatedUI()
445 throw ( embed::WrongStateException,
446 uno::RuntimeException )
448 ::vos::OGuard aGuard( Application::GetSolarMutex() );
449 com::sun::star::uno::Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager(getLayoutManager());
450 if ( xLayoutManager.is() )
452 const static rtl::OUString aMenuBarURL( RTL_CONSTASCII_USTRINGPARAM( "private:resource/menubar/menubar" ));
453 if ( !xLayoutManager->isElementVisible( aMenuBarURL ) )
454 xLayoutManager->createElement( aMenuBarURL );
458 //--------------------------------------------------------------------
459 uno::Reference< ::com::sun::star::frame::XLayoutManager > SAL_CALL SdrLightEmbeddedClient_Impl::getLayoutManager()
460 throw ( embed::WrongStateException,
461 uno::RuntimeException )
463 uno::Reference< ::com::sun::star::frame::XLayoutManager > xMan;
464 ::vos::OGuard aGuard( Application::GetSolarMutex() );
465 uno::Reference < beans::XPropertySet > xFrame( lcl_getFrame_throw(mpObj));
468 xMan.set(xFrame->getPropertyValue( ::rtl::OUString::createFromAscii("LayoutManager") ),uno::UNO_QUERY);
470 catch ( uno::Exception& )
472 throw uno::RuntimeException();
475 return xMan;
478 //--------------------------------------------------------------------
479 uno::Reference< frame::XDispatchProvider > SAL_CALL SdrLightEmbeddedClient_Impl::getInplaceDispatchProvider()
480 throw ( embed::WrongStateException,
481 uno::RuntimeException )
483 ::vos::OGuard aGuard( Application::GetSolarMutex() );
484 return uno::Reference < frame::XDispatchProvider >( lcl_getFrame_throw(mpObj), uno::UNO_QUERY_THROW );
487 //--------------------------------------------------------------------
488 awt::Rectangle SAL_CALL SdrLightEmbeddedClient_Impl::getPlacement()
489 throw ( embed::WrongStateException,
490 uno::RuntimeException )
492 ::vos::OGuard aGuard( Application::GetSolarMutex() );
493 if ( !mpObj )
494 throw uno::RuntimeException();
496 Rectangle aLogicRect = impl_getScaledRect_nothrow();
497 MapUnit aContainerMapUnit( MAP_100TH_MM );
498 uno::Reference< embed::XVisualObject > xParentVis( mpObj->GetParentXModel(), uno::UNO_QUERY );
499 if ( xParentVis.is() )
500 aContainerMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xParentVis->getMapUnit( mpObj->GetAspect() ) );
502 aLogicRect = Application::GetDefaultDevice()->LogicToPixel(aLogicRect,aContainerMapUnit);
503 return AWTRectangle( aLogicRect );
506 //--------------------------------------------------------------------
507 awt::Rectangle SAL_CALL SdrLightEmbeddedClient_Impl::getClipRectangle()
508 throw ( embed::WrongStateException,
509 uno::RuntimeException )
511 return getPlacement();
514 //--------------------------------------------------------------------
515 void SAL_CALL SdrLightEmbeddedClient_Impl::translateAccelerators( const uno::Sequence< awt::KeyEvent >& /*aKeys*/ )
516 throw ( embed::WrongStateException,
517 uno::RuntimeException )
521 //--------------------------------------------------------------------
522 void SAL_CALL SdrLightEmbeddedClient_Impl::scrollObject( const awt::Size& /*aOffset*/ )
523 throw ( embed::WrongStateException,
524 uno::RuntimeException )
528 //--------------------------------------------------------------------
529 void SAL_CALL SdrLightEmbeddedClient_Impl::changedPlacement( const awt::Rectangle& aPosRect )
530 throw ( embed::WrongStateException,
531 uno::Exception,
532 uno::RuntimeException )
534 ::vos::OGuard aGuard( Application::GetSolarMutex() );
535 if ( !mpObj )
536 throw uno::RuntimeException();
538 uno::Reference< embed::XInplaceObject > xInplace( mpObj->GetObjRef(), uno::UNO_QUERY );
539 if ( !xInplace.is() )
540 throw uno::RuntimeException();
542 // check if the change is at least one pixel in size
543 awt::Rectangle aOldRect = getPlacement();
544 Rectangle aNewPixelRect = VCLRectangle( aPosRect );
545 Rectangle aOldPixelRect = VCLRectangle( aOldRect );
546 if ( aOldPixelRect == aNewPixelRect )
547 // nothing has changed
548 return;
550 // new scaled object area
551 MapUnit aContainerMapUnit( MAP_100TH_MM );
552 uno::Reference< embed::XVisualObject > xParentVis( mpObj->GetParentXModel(), uno::UNO_QUERY );
553 if ( xParentVis.is() )
554 aContainerMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xParentVis->getMapUnit( mpObj->GetAspect() ) );
556 Rectangle aNewLogicRect = Application::GetDefaultDevice()->PixelToLogic(aNewPixelRect,aContainerMapUnit);
557 Rectangle aLogicRect = impl_getScaledRect_nothrow();
559 if ( aNewLogicRect != aLogicRect )
561 // the calculation of the object area has not changed the object size
562 // it should be done here then
563 //SfxBooleanFlagGuard aGuard( m_bResizeNoScale, sal_True );
565 // new size of the object area without scaling
566 Size aNewObjSize( Fraction( aNewLogicRect.GetWidth() ) / m_aScaleWidth,
567 Fraction( aNewLogicRect.GetHeight() ) / m_aScaleHeight );
569 // now remove scaling from new placement and keep this a the new object area
570 aNewLogicRect.SetSize( aNewObjSize );
571 // react to the change if the difference is bigger than one pixel
572 Size aPixelDiff =
573 Application::GetDefaultDevice()->LogicToPixel(
574 Size( aLogicRect.GetWidth() - aNewObjSize.Width(),
575 aLogicRect.GetHeight() - aNewObjSize.Height() ),
576 aContainerMapUnit );
577 if( aPixelDiff.Width() || aPixelDiff.Height() )
579 mpObj->SetLogicRect( Rectangle( aLogicRect.TopLeft(), aNewObjSize ) );
580 mpObj->BroadcastObjectChange();
582 else
583 mpObj->ActionChanged();
585 // let the window size be recalculated
586 //SizeHasChanged(); // TODO: OJ
589 // XWindowSupplier
590 //--------------------------------------------------------------------
591 uno::Reference< awt::XWindow > SAL_CALL SdrLightEmbeddedClient_Impl::getWindow()
592 throw ( uno::RuntimeException )
594 ::vos::OGuard aGuard( Application::GetSolarMutex() );
595 uno::Reference< awt::XWindow > xCurrent = m_xWindow;
596 if ( !xCurrent.is() )
598 if ( !mpObj )
599 throw uno::RuntimeException();
600 uno::Reference< frame::XFrame> xFrame(lcl_getFrame_throw(mpObj),uno::UNO_QUERY_THROW);
601 xCurrent = xFrame->getComponentWindow();
602 } // if ( !xCurrent.is() )
603 return xCurrent;
605 void SdrLightEmbeddedClient_Impl::setWindow(const uno::Reference< awt::XWindow >& _xWindow)
607 m_xWindow = _xWindow;
610 ////////////////////////////////////////////////////////////////////////////////////////////////////
612 class SdrEmbedObjectLink : public sfx2::SvBaseLink
614 SdrOle2Obj* pObj;
616 public:
617 SdrEmbedObjectLink(SdrOle2Obj* pObj);
618 virtual ~SdrEmbedObjectLink();
620 virtual void Closed();
621 virtual void DataChanged( const String& rMimeType,
622 const ::com::sun::star::uno::Any & rValue );
624 sal_Bool Connect() { return GetRealObject() != NULL; }
627 // -----------------------------------------------------------------------------
629 SdrEmbedObjectLink::SdrEmbedObjectLink(SdrOle2Obj* pObject):
630 ::sfx2::SvBaseLink( ::sfx2::LINKUPDATE_ONCALL, SOT_FORMATSTR_ID_SVXB ),
631 pObj(pObject)
633 SetSynchron( FALSE );
636 // -----------------------------------------------------------------------------
638 SdrEmbedObjectLink::~SdrEmbedObjectLink()
642 // -----------------------------------------------------------------------------
644 void SdrEmbedObjectLink::DataChanged( const String& /*rMimeType*/,
645 const ::com::sun::star::uno::Any & /*rValue*/ )
647 if ( !pObj->UpdateLinkURL_Impl() )
649 // the link URL was not changed
650 uno::Reference< embed::XEmbeddedObject > xObject = pObj->GetObjRef();
651 OSL_ENSURE( xObject.is(), "The object must exist always!\n" );
652 if ( xObject.is() )
654 // let the object reload the link
655 // TODO/LATER: reload call could be used for this case
659 sal_Int32 nState = xObject->getCurrentState();
660 if ( nState != embed::EmbedStates::LOADED )
662 // in some cases the linked file probably is not locked so it could be changed
663 xObject->changeState( embed::EmbedStates::LOADED );
664 xObject->changeState( nState );
667 catch ( uno::Exception& )
673 pObj->GetNewReplacement();
674 pObj->SetChanged();
677 // -----------------------------------------------------------------------------
679 void SdrEmbedObjectLink::Closed()
681 pObj->BreakFileLink_Impl();
682 SvBaseLink::Closed();
685 ////////////////////////////////////////////////////////////////////////////////////////////////////
687 class SdrOle2ObjImpl
689 public:
690 // TODO/LATER: do we really need this pointer?
691 GraphicObject* pGraphicObject;
692 String aPersistName; // name of object in persist
693 SdrLightEmbeddedClient_Impl* pLightClient; // must be registered as client only using AddOwnLightClient() call
695 // #107645#
696 // New local var to avoid repeated loading if load of OLE2 fails
697 sal_Bool mbLoadingOLEObjectFailed;
698 sal_Bool mbConnected;
700 SdrEmbedObjectLink* mpObjectLink;
701 String maLinkURL;
703 SdrOle2ObjImpl()
704 : pGraphicObject( NULL )
705 // #107645#
706 // init to start situation, loading did not fail
707 , mbLoadingOLEObjectFailed( sal_False )
708 , mbConnected( sal_False )
709 , mpObjectLink( NULL )
714 ////////////////////////////////////////////////////////////////////////////////////////////////////
716 // Predicate determining whether the given OLE is an internal math
717 // object
718 static bool ImplIsMathObj( const uno::Reference < embed::XEmbeddedObject >& rObjRef )
720 if ( !rObjRef.is() )
721 return false;
723 SvGlobalName aClassName( rObjRef->getClassID() );
724 if( aClassName == SvGlobalName(SO3_SM_CLASSID_30) ||
725 aClassName == SvGlobalName(SO3_SM_CLASSID_40) ||
726 aClassName == SvGlobalName(SO3_SM_CLASSID_50) ||
727 aClassName == SvGlobalName(SO3_SM_CLASSID_60) ||
728 aClassName == SvGlobalName(SO3_SM_CLASSID) )
730 return true;
732 else
734 return false;
738 //////////////////////////////////////////////////////////////////////////////
739 // DrawContact section
741 sdr::contact::ViewContact* SdrOle2Obj::CreateObjectSpecificViewContact()
743 return new sdr::contact::ViewContactOfSdrOle2Obj(*this);
746 // -----------------------------------------------------------------------------
748 TYPEINIT1(SdrOle2Obj,SdrRectObj);
749 DBG_NAME(SdrOle2Obj)
750 SdrOle2Obj::SdrOle2Obj(FASTBOOL bFrame_) : m_bTypeAsked(false)
751 ,m_bChart(false)
753 DBG_CTOR( SdrOle2Obj,NULL);
754 bInDestruction = FALSE;
755 Init();
756 bFrame=bFrame_;
759 // -----------------------------------------------------------------------------
760 SdrOle2Obj::SdrOle2Obj( const svt::EmbeddedObjectRef& rNewObjRef, FASTBOOL bFrame_)
761 : xObjRef( rNewObjRef )
762 , m_bTypeAsked(false)
763 , m_bChart(false)
765 DBG_CTOR( SdrOle2Obj,NULL);
766 bInDestruction = FALSE;
767 Init();
769 bFrame=bFrame_;
771 if ( xObjRef.is() && (xObjRef->getStatus( GetAspect() ) & embed::EmbedMisc::EMBED_NEVERRESIZE ) )
772 SetResizeProtect(TRUE);
774 // #108759# For math objects, set closed state to transparent
775 if( ImplIsMathObj( xObjRef.GetObject() ) )
776 SetClosedObj( false );
779 // -----------------------------------------------------------------------------
781 SdrOle2Obj::SdrOle2Obj( const svt::EmbeddedObjectRef& rNewObjRef, const XubString& rNewObjName, FASTBOOL bFrame_)
782 : xObjRef( rNewObjRef )
783 , m_bTypeAsked(false)
784 , m_bChart(false)
786 DBG_CTOR( SdrOle2Obj,NULL);
787 bInDestruction = FALSE;
788 Init();
790 mpImpl->aPersistName = rNewObjName;
791 bFrame=bFrame_;
793 if ( xObjRef.is() && (xObjRef->getStatus( GetAspect() ) & embed::EmbedMisc::EMBED_NEVERRESIZE ) )
794 SetResizeProtect(TRUE);
796 // #108759# For math objects, set closed state to transparent
797 if( ImplIsMathObj( xObjRef.GetObject() ) )
798 SetClosedObj( false );
801 // -----------------------------------------------------------------------------
803 SdrOle2Obj::SdrOle2Obj( const svt::EmbeddedObjectRef& rNewObjRef, const XubString& rNewObjName, const Rectangle& rNewRect, FASTBOOL bFrame_)
804 : SdrRectObj(rNewRect)
805 , xObjRef( rNewObjRef )
806 , m_bTypeAsked(false)
807 , m_bChart(false)
809 DBG_CTOR( SdrOle2Obj,NULL);
810 bInDestruction = FALSE;
811 Init();
813 mpImpl->aPersistName = rNewObjName;
814 bFrame=bFrame_;
816 if ( xObjRef.is() && (xObjRef->getStatus( GetAspect() ) & embed::EmbedMisc::EMBED_NEVERRESIZE ) )
817 SetResizeProtect(TRUE);
819 // #108759# For math objects, set closed state to transparent
820 if( ImplIsMathObj( xObjRef.GetObject() ) )
821 SetClosedObj( false );
824 // -----------------------------------------------------------------------------
826 void SdrOle2Obj::Init()
828 mpImpl = new SdrOle2ObjImpl;
829 pModifyListener = NULL;
830 pGraphic=NULL;
831 mpImpl->pGraphicObject=NULL;
832 mpImpl->pLightClient = 0;
834 xObjRef.Lock( TRUE );
837 // -----------------------------------------------------------------------------
839 SdrOle2Obj::~SdrOle2Obj()
841 DBG_DTOR( SdrOle2Obj,NULL);
842 bInDestruction = TRUE;
844 if ( mpImpl->mbConnected )
845 Disconnect();
847 if( pGraphic!=NULL )
848 delete pGraphic;
850 if(mpImpl->pGraphicObject!=NULL)
851 delete mpImpl->pGraphicObject;
853 if(pModifyListener)
855 pModifyListener->invalidate();
856 pModifyListener->release();
859 DisconnectFileLink_Impl();
861 if ( mpImpl->pLightClient )
863 mpImpl->pLightClient->Release();
864 mpImpl->pLightClient = NULL;
867 delete mpImpl;
870 // -----------------------------------------------------------------------------
871 void SdrOle2Obj::SetAspect( sal_Int64 nAspect )
873 xObjRef.SetViewAspect( nAspect );
876 // -----------------------------------------------------------------------------
878 void SdrOle2Obj::SetGraphic_Impl(const Graphic* pGrf)
880 if ( pGraphic )
882 delete pGraphic;
883 pGraphic = NULL;
884 delete mpImpl->pGraphicObject;
885 mpImpl->pGraphicObject = NULL;
888 if (pGrf!=NULL)
890 pGraphic = new Graphic(*pGrf);
891 mpImpl->pGraphicObject = new GraphicObject( *pGraphic );
894 SetChanged();
895 BroadcastObjectChange();
897 //if ( ppObjRef->Is() && pGrf )
898 // BroadcastObjectChange();
901 void SdrOle2Obj::SetGraphic(const Graphic* pGrf)
903 // only for setting a preview graphic
904 SetGraphic_Impl( pGrf );
907 // -----------------------------------------------------------------------------
909 FASTBOOL SdrOle2Obj::IsEmpty() const
911 return !(xObjRef.is());
914 // -----------------------------------------------------------------------------
916 void SdrOle2Obj::Connect()
918 if( IsEmptyPresObj() )
919 return;
921 if( mpImpl->mbConnected )
923 // mba: currently there are situations where it seems to be unavoidable to have multiple connects
924 // changing this would need a larger code rewrite, so for now I remove the assertion
925 // DBG_ERROR("Connect() called on connected object!");
926 return;
929 Connect_Impl();
930 AddListeners_Impl();
933 // -----------------------------------------------------------------------------
935 sal_Bool SdrOle2Obj::UpdateLinkURL_Impl()
937 sal_Bool bResult = sal_False;
939 if ( mpImpl->mpObjectLink )
941 SvxLinkManager* pLinkManager = pModel ? pModel->GetLinkManager() : NULL;
942 if ( pLinkManager )
944 String aNewLinkURL;
945 pLinkManager->GetDisplayNames( mpImpl->mpObjectLink, 0, &aNewLinkURL, 0, 0 );
946 if ( !aNewLinkURL.EqualsIgnoreCaseAscii( mpImpl->maLinkURL ) )
948 const_cast<SdrOle2Obj*>(this)->GetObjRef_Impl();
949 uno::Reference< embed::XCommonEmbedPersist > xPersObj( xObjRef.GetObject(), uno::UNO_QUERY );
950 OSL_ENSURE( xPersObj.is(), "The object must exist!\n" );
951 if ( xPersObj.is() )
955 sal_Int32 nCurState = xObjRef->getCurrentState();
956 if ( nCurState != embed::EmbedStates::LOADED )
957 xObjRef->changeState( embed::EmbedStates::LOADED );
959 // TODO/LATER: there should be possible to get current mediadescriptor settings from the object
960 uno::Sequence< beans::PropertyValue > aArgs( 1 );
961 aArgs[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) );
962 aArgs[0].Value <<= ::rtl::OUString( aNewLinkURL );
963 xPersObj->reload( aArgs, uno::Sequence< beans::PropertyValue >() );
965 mpImpl->maLinkURL = aNewLinkURL;
966 bResult = sal_True;
968 if ( nCurState != embed::EmbedStates::LOADED )
969 xObjRef->changeState( nCurState );
971 catch( ::com::sun::star::uno::Exception& e )
973 (void)e;
974 DBG_ERROR(
975 (OString("SdrOle2Obj::UpdateLinkURL_Impl(), "
976 "exception caught: ") +
977 rtl::OUStringToOString(
978 comphelper::anyToString( cppu::getCaughtException() ),
979 RTL_TEXTENCODING_UTF8 )).getStr() );
983 if ( !bResult )
985 // TODO/LATER: return the old name to the link manager, is it possible?
991 return bResult;
994 // -----------------------------------------------------------------------------
996 void SdrOle2Obj::BreakFileLink_Impl()
998 uno::Reference<document::XStorageBasedDocument> xDoc;
999 if ( pModel )
1000 xDoc.set( pModel->getUnoModel(),uno::UNO_QUERY);
1002 if ( xDoc.is() )
1004 uno::Reference< embed::XStorage > xStorage = xDoc->getDocumentStorage();
1005 if ( xStorage.is() )
1009 uno::Reference< embed::XLinkageSupport > xLinkSupport( xObjRef.GetObject(), uno::UNO_QUERY_THROW );
1010 xLinkSupport->breakLink( xStorage, mpImpl->aPersistName );
1011 DisconnectFileLink_Impl();
1012 mpImpl->maLinkURL = String();
1014 catch( ::com::sun::star::uno::Exception& e )
1016 (void)e;
1017 DBG_ERROR(
1018 (OString("SdrOle2Obj::BreakFileLink_Impl(), "
1019 "exception caught: ") +
1020 rtl::OUStringToOString(
1021 comphelper::anyToString( cppu::getCaughtException() ),
1022 RTL_TEXTENCODING_UTF8 )).getStr() );
1028 // -----------------------------------------------------------------------------
1030 void SdrOle2Obj::DisconnectFileLink_Impl()
1032 SvxLinkManager* pLinkManager = pModel ? pModel->GetLinkManager() : NULL;
1033 if ( pLinkManager && mpImpl->mpObjectLink )
1035 pLinkManager->Remove( mpImpl->mpObjectLink );
1036 mpImpl->mpObjectLink = NULL;
1040 // -----------------------------------------------------------------------------
1042 void SdrOle2Obj::CheckFileLink_Impl()
1044 if ( pModel && xObjRef.GetObject().is() && !mpImpl->mpObjectLink )
1048 uno::Reference< embed::XLinkageSupport > xLinkSupport( xObjRef.GetObject(), uno::UNO_QUERY );
1049 if ( xLinkSupport.is() && xLinkSupport->isLink() )
1051 String aLinkURL = xLinkSupport->getLinkURL();
1052 if ( aLinkURL.Len() )
1054 // this is a file link so the model link manager should handle it
1055 SvxLinkManager* pLinkManager = pModel->GetLinkManager();
1056 if ( pLinkManager )
1058 mpImpl->mpObjectLink = new SdrEmbedObjectLink( this );
1059 mpImpl->maLinkURL = aLinkURL;
1060 pLinkManager->InsertFileLink( *mpImpl->mpObjectLink, OBJECT_CLIENT_OLE, aLinkURL, NULL, NULL );
1061 mpImpl->mpObjectLink->Connect();
1066 catch( ::com::sun::star::uno::Exception& e )
1068 (void)e;
1069 DBG_ERROR(
1070 (OString("SdrOle2Obj::CheckFileLink_Impl(), "
1071 "exception caught: ") +
1072 rtl::OUStringToOString(
1073 comphelper::anyToString( cppu::getCaughtException() ),
1074 RTL_TEXTENCODING_UTF8 )).getStr() );
1079 // -----------------------------------------------------------------------------
1081 void SdrOle2Obj::Reconnect_Impl()
1083 DBG_ASSERT( mpImpl->mbConnected, "Assigned unconnected object?!" );
1084 Connect_Impl();
1087 void SdrOle2Obj::Connect_Impl()
1089 if( pModel && mpImpl->aPersistName.Len() )
1093 ::comphelper::IEmbeddedHelper* pPers = pModel->GetPersist();
1094 if ( pPers )
1096 comphelper::EmbeddedObjectContainer& rContainer = pPers->getEmbeddedObjectContainer();
1097 if ( !rContainer.HasEmbeddedObject( mpImpl->aPersistName )
1098 || ( xObjRef.is() && !rContainer.HasEmbeddedObject( xObjRef.GetObject() ) ) )
1100 // object not known to container document
1101 // No object -> disaster!
1102 DBG_ASSERT( xObjRef.is(), "No object in connect!");
1103 if ( xObjRef.is() )
1105 // object came from the outside, now add it to the container
1106 ::rtl::OUString aTmp;
1107 rContainer.InsertEmbeddedObject( xObjRef.GetObject(), aTmp );
1108 mpImpl->aPersistName = aTmp;
1111 else if ( !xObjRef.is() )
1113 xObjRef.Assign( rContainer.GetEmbeddedObject( mpImpl->aPersistName ), xObjRef.GetViewAspect() );
1114 m_bTypeAsked = false;
1117 if ( xObjRef.GetObject().is() )
1119 xObjRef.AssignToContainer( &rContainer, mpImpl->aPersistName );
1120 mpImpl->mbConnected = true;
1121 xObjRef.Lock( TRUE );
1125 if ( xObjRef.is() )
1127 if ( !mpImpl->pLightClient )
1129 mpImpl->pLightClient = new SdrLightEmbeddedClient_Impl( this );
1130 mpImpl->pLightClient->acquire();
1133 xObjRef->addStateChangeListener( mpImpl->pLightClient );
1134 xObjRef->addEventListener( uno::Reference< document::XEventListener >( mpImpl->pLightClient ) );
1136 if ( xObjRef->getCurrentState() != embed::EmbedStates::LOADED )
1137 GetSdrGlobalData().GetOLEObjCache().InsertObj(this);
1139 CheckFileLink_Impl();
1141 uno::Reference< container::XChild > xChild( xObjRef.GetObject(), uno::UNO_QUERY );
1142 if( xChild.is() )
1144 uno::Reference< uno::XInterface > xParent( pModel->getUnoModel());
1145 if( xParent.is())
1146 xChild->setParent( pModel->getUnoModel() );
1151 catch( ::com::sun::star::uno::Exception& e )
1153 (void)e;
1154 DBG_ERROR(
1155 (OString("SdrOle2Obj::Connect_Impl(), "
1156 "exception caught: ") +
1157 rtl::OUStringToOString(
1158 comphelper::anyToString( cppu::getCaughtException() ),
1159 RTL_TEXTENCODING_UTF8 )).getStr() );
1163 //TODO/LATER: wait for definition of MiscStatus RESIZEONPRINTERCHANGE
1164 //if ( xObjRef.is() && (*ppObjRef)->GetMiscStatus() & SVOBJ_MISCSTATUS_RESIZEONPRINTERCHANGE )
1166 //TODO/LATER: needs a new handling for OnPrinterChanged
1168 if (pModel && pModel->GetRefDevice() &&
1169 pModel->GetRefDevice()->GetOutDevType() == OUTDEV_PRINTER)
1171 // Kein RefDevice oder RefDevice kein Printer
1172 BOOL bModified = (*ppObjRef)->IsModified();
1173 Printer* pPrinter = (Printer*) pModel->GetRefDevice();
1174 (*ppObjRef)->OnDocumentPrinterChanged( pPrinter );
1175 (*ppObjRef)->SetModified( bModified );
1180 void SdrOle2Obj::ObjectLoaded()
1182 AddListeners_Impl();
1185 void SdrOle2Obj::AddListeners_Impl()
1187 if( xObjRef.is() && xObjRef->getCurrentState() != embed::EmbedStates::LOADED )
1189 // register modify listener
1190 if( !pModifyListener )
1192 ((SdrOle2Obj*)this)->pModifyListener = new SvxUnoShapeModifyListener( (SdrOle2Obj*)this );
1193 pModifyListener->acquire();
1196 uno::Reference< util::XModifyBroadcaster > xBC( getXModel(), uno::UNO_QUERY );
1197 if( xBC.is() && pModifyListener )
1199 uno::Reference< util::XModifyListener > xListener( pModifyListener );
1200 xBC->addModifyListener( xListener );
1205 // -----------------------------------------------------------------------------
1207 void SdrOle2Obj::Disconnect()
1209 if( IsEmptyPresObj() )
1210 return;
1212 if( !mpImpl->mbConnected )
1214 DBG_ERROR("Disconnect() called on disconnected object!");
1215 return;
1218 RemoveListeners_Impl();
1219 Disconnect_Impl();
1222 void SdrOle2Obj::RemoveListeners_Impl()
1224 if( xObjRef.is() && mpImpl->aPersistName.Len() )
1228 sal_Int32 nState = xObjRef->getCurrentState();
1229 if ( nState != embed::EmbedStates::LOADED )
1231 uno::Reference< util::XModifyBroadcaster > xBC( getXModel(), uno::UNO_QUERY );
1232 if( xBC.is() && pModifyListener )
1234 uno::Reference< util::XModifyListener > xListener( pModifyListener );
1235 xBC->removeModifyListener( xListener );
1239 catch( ::com::sun::star::uno::Exception& e )
1241 (void)e;
1242 DBG_ERROR(
1243 (OString("SdrOle2Obj::RemoveListeners_Impl(), "
1244 "exception caught: ") +
1245 rtl::OUStringToOString(
1246 comphelper::anyToString( cppu::getCaughtException() ),
1247 RTL_TEXTENCODING_UTF8 )).getStr() );
1252 void SdrOle2Obj::Disconnect_Impl()
1256 if ( pModel && mpImpl->aPersistName.Len() )
1258 if( pModel->IsInDestruction() )
1260 // TODO/LATER: here we must assume that the destruction of the model is enough to make clear that we will not
1261 // remove the object from the container, even if the DrawingObject itself is not destroyed (unfortunately this
1262 // There is no real need to do the following removing of the object from the container
1263 // in case the model has correct persistance, but in case of problems such a removing
1264 // would make the behaviour of the office more stable
1266 comphelper::EmbeddedObjectContainer* pContainer = xObjRef.GetContainer();
1267 if ( pContainer )
1269 pContainer->CloseEmbeddedObject( xObjRef.GetObject() );
1270 xObjRef.AssignToContainer( NULL, mpImpl->aPersistName );
1273 // happens later than the destruction of the model, so we can't assert that).
1274 //DBG_ASSERT( bInDestruction, "Model is destroyed, but not me?!" );
1275 //TODO/LATER: should be make sure that the ObjectShell also forgets the object, because we will close it soon?
1277 uno::Reference < util::XCloseable > xClose( xObjRef, uno::UNO_QUERY );
1278 if ( xClose.is() )
1282 xClose->close( sal_True );
1284 catch ( util::CloseVetoException& )
1286 // there's still someone who needs the object!
1290 xObjRef = NULL;*/
1292 else if ( xObjRef.is() )
1294 if ( pModel->getUnoModel().is() )
1296 // remove object, but don't close it (that's up to someone else)
1297 comphelper::EmbeddedObjectContainer* pContainer = xObjRef.GetContainer();
1298 if ( pContainer )
1300 pContainer->RemoveEmbeddedObject( xObjRef.GetObject(), sal_False);
1302 // TODO/LATER: mpImpl->aPersistName contains outdated information, to have it uptodate
1303 // it should be returned from RemoveEmbeddedObject call. Currently it is no problem,
1304 // since no container is adjusted, actually the empty string could be provided as a name here
1305 xObjRef.AssignToContainer( NULL, mpImpl->aPersistName );
1308 DisconnectFileLink_Impl();
1313 if ( xObjRef.is() && mpImpl->pLightClient )
1315 xObjRef->removeStateChangeListener ( mpImpl->pLightClient );
1316 xObjRef->removeEventListener( uno::Reference< document::XEventListener >( mpImpl->pLightClient ) );
1317 xObjRef->setClientSite( NULL );
1319 GetSdrGlobalData().GetOLEObjCache().RemoveObj(this);
1322 catch( ::com::sun::star::uno::Exception& e )
1324 (void)e;
1325 DBG_ERROR(
1326 (OString("SdrOle2Obj::Disconnect_Impl(), "
1327 "exception caught: ") +
1328 rtl::OUStringToOString(
1329 comphelper::anyToString( cppu::getCaughtException() ),
1330 RTL_TEXTENCODING_UTF8 )).getStr() );
1333 mpImpl->mbConnected = false;
1336 // -----------------------------------------------------------------------------
1338 void SdrOle2Obj::SetModel(SdrModel* pNewModel)
1340 ::comphelper::IEmbeddedHelper* pDestPers = pNewModel ? pNewModel->GetPersist() : 0;
1341 ::comphelper::IEmbeddedHelper* pSrcPers = pModel ? pModel->GetPersist() : 0;
1343 if ( pNewModel == pModel )
1345 // don't know if this is necessary or if it will ever happen, but who know?!
1346 SdrRectObj::SetModel( pNewModel );
1347 return;
1350 // assignment to model has changed
1351 DBG_ASSERT( pSrcPers || !mpImpl->mbConnected, "Connected object without a model?!" );
1353 DBG_ASSERT( pDestPers, "The destination model must have a persistence! Please submit an issue!" );
1354 DBG_ASSERT( pDestPers != pSrcPers, "The source and the destination models should have different persistences! Problems are possible!" );
1356 // this is a bug if the target model has no persistence
1357 // no error handling is possible so just do nothing in this method
1358 if ( !pDestPers )
1359 return;
1361 RemoveListeners_Impl();
1363 if( pDestPers && pSrcPers && !IsEmptyPresObj() )
1367 // move the objects' storage; ObjectRef remains the same, but PersistName may change
1368 ::rtl::OUString aTmp;
1369 comphelper::EmbeddedObjectContainer& rContainer = pSrcPers->getEmbeddedObjectContainer();
1370 uno::Reference < embed::XEmbeddedObject > xObj = rContainer.GetEmbeddedObject( mpImpl->aPersistName );
1371 DBG_ASSERT( !xObjRef.is() || xObjRef.GetObject() == xObj, "Wrong object identity!" );
1372 if ( xObj.is() )
1374 pDestPers->getEmbeddedObjectContainer().MoveEmbeddedObject( rContainer, xObj, aTmp );
1375 mpImpl->aPersistName = aTmp;
1376 xObjRef.AssignToContainer( &pDestPers->getEmbeddedObjectContainer(), aTmp );
1378 DBG_ASSERT( aTmp.getLength(), "Copying embedded object failed!" );
1380 catch( ::com::sun::star::uno::Exception& e )
1382 (void)e;
1383 DBG_ERROR(
1384 (OString("SdrOle2Obj::SetModel(), "
1385 "exception caught: ") +
1386 rtl::OUStringToOString(
1387 comphelper::anyToString( cppu::getCaughtException() ),
1388 RTL_TEXTENCODING_UTF8 )).getStr() );
1392 SdrRectObj::SetModel( pNewModel );
1394 // #i43086#
1395 // #i85304 redo the change for charts for the above bugfix, as #i43086# does not ocur anymore
1396 //so maybe the ImpSetVisAreaSize call can be removed here completely
1397 //Nevertheless I leave it in for other objects as I am not sure about the side effects when removing now
1398 if( pModel && !pModel->isLocked() && !IsChart() )
1399 ImpSetVisAreaSize();
1401 if( pDestPers && !IsEmptyPresObj() )
1403 if ( !pSrcPers || IsEmptyPresObj() )
1404 // object wasn't connected, now it should
1405 Connect_Impl();
1406 else
1407 Reconnect_Impl();
1410 AddListeners_Impl();
1413 // -----------------------------------------------------------------------------
1415 void SdrOle2Obj::SetPage(SdrPage* pNewPage)
1417 FASTBOOL bRemove=pNewPage==NULL && pPage!=NULL;
1418 FASTBOOL bInsert=pNewPage!=NULL && pPage==NULL;
1420 if (bRemove && mpImpl->mbConnected )
1421 Disconnect();
1423 SdrRectObj::SetPage(pNewPage);
1425 if (bInsert && !mpImpl->mbConnected )
1426 Connect();
1429 // -----------------------------------------------------------------------------
1431 void SdrOle2Obj::SetObjRef( const com::sun::star::uno::Reference < com::sun::star::embed::XEmbeddedObject >& rNewObjRef )
1433 DBG_ASSERT( !rNewObjRef.is() || !xObjRef.GetObject().is(), "SetObjRef called on already initialized object!");
1434 if( rNewObjRef == xObjRef.GetObject() )
1435 return;
1437 // MBA: the caller of the method is responsible to control the old object, it will not be closed here
1438 // Otherwise WW8 import crashes because it tranfers control to OLENode by this method
1439 if ( xObjRef.GetObject().is() )
1440 xObjRef.Lock( FALSE );
1442 // MBA: avoid removal of object in Disconnect! It is definitely a HACK to call SetObjRef(0)!
1443 // This call will try to close the objects; so if anybody else wants to keep it, it must be locked by a CloseListener
1444 xObjRef.Clear();
1446 if ( mpImpl->mbConnected )
1447 Disconnect();
1449 xObjRef.Assign( rNewObjRef, GetAspect() );
1450 m_bTypeAsked = false;
1452 if ( xObjRef.is() )
1454 DELETEZ( pGraphic );
1456 if ( (xObjRef->getStatus( GetAspect() ) & embed::EmbedMisc::EMBED_NEVERRESIZE ) )
1457 SetResizeProtect(TRUE);
1459 // #108759# For math objects, set closed state to transparent
1460 if( ImplIsMathObj( rNewObjRef ) )
1461 SetClosedObj( false );
1463 Connect();
1466 SetChanged();
1467 BroadcastObjectChange();
1470 // -----------------------------------------------------------------------------
1472 void SdrOle2Obj::SetClosedObj( bool bIsClosed )
1474 // TODO/LATER: do we still need this hack?
1475 // #108759# Allow changes to the closed state of OLE objects
1476 bClosedObj = bIsClosed;
1479 // -----------------------------------------------------------------------------
1481 SdrObject* SdrOle2Obj::getFullDragClone() const
1483 // special handling for OLE. The default handling works, but is too
1484 // slow when the whole OLE needs to be cloned. Get the Metafile and
1485 // create a graphic object with it
1486 Graphic* pOLEGraphic = GetGraphic();
1487 SdrObject* pClone = 0;
1489 if(Application::GetSettings().GetStyleSettings().GetHighContrastMode())
1491 pOLEGraphic = getEmbeddedObjectRef().GetHCGraphic();
1494 if(pOLEGraphic)
1496 pClone = new SdrGrafObj(*pOLEGraphic, GetSnapRect());
1498 // this would be the place where to copy all attributes
1499 // when OLE will support fill and line style
1500 // pClone->SetMergedItem(pOleObject->GetMergedItemSet());
1502 else
1504 // #i100710# pOLEGraphic may be zero (no visualisation available),
1505 // so we need to use the OLE replacement graphic
1506 pClone = new SdrRectObj(GetSnapRect());
1508 // gray outline
1509 pClone->SetMergedItem(XLineStyleItem(XLINE_SOLID));
1510 const svtools::ColorConfig aColorConfig;
1511 const svtools::ColorConfigValue aColor(aColorConfig.GetColorValue(svtools::OBJECTBOUNDARIES));
1512 pClone->SetMergedItem(XLineColorItem(String(), aColor.nColor));
1514 // bitmap fill
1515 pClone->SetMergedItem(XFillStyleItem(XFILL_BITMAP));
1516 pClone->SetMergedItem(XFillBitmapItem(String(), GetEmtyOLEReplacementBitmap()));
1517 pClone->SetMergedItem(XFillBmpTileItem(false));
1518 pClone->SetMergedItem(XFillBmpStretchItem(false));
1521 return pClone;
1524 // -----------------------------------------------------------------------------
1526 void SdrOle2Obj::SetPersistName( const String& rPersistName )
1528 DBG_ASSERT( !mpImpl->aPersistName.Len(), "Persist name changed!");
1530 mpImpl->aPersistName = rPersistName;
1531 mpImpl->mbLoadingOLEObjectFailed = false;
1533 Connect();
1534 SetChanged();
1537 void SdrOle2Obj::AbandonObject()
1539 mpImpl->aPersistName.Erase();
1540 mpImpl->mbLoadingOLEObjectFailed = false;
1541 SetObjRef(0);
1544 // -----------------------------------------------------------------------------
1546 String SdrOle2Obj::GetPersistName() const
1548 return mpImpl->aPersistName;
1551 // -----------------------------------------------------------------------------
1553 void SdrOle2Obj::TakeObjInfo(SdrObjTransformInfoRec& rInfo) const
1555 rInfo.bRotateFreeAllowed=FALSE;
1556 rInfo.bRotate90Allowed =FALSE;
1557 rInfo.bMirrorFreeAllowed=FALSE;
1558 rInfo.bMirror45Allowed =FALSE;
1559 rInfo.bMirror90Allowed =FALSE;
1560 rInfo.bTransparenceAllowed = FALSE;
1561 rInfo.bGradientAllowed = FALSE;
1562 rInfo.bShearAllowed =FALSE;
1563 rInfo.bEdgeRadiusAllowed=FALSE;
1564 rInfo.bNoOrthoDesired =FALSE;
1565 rInfo.bCanConvToPath =FALSE;
1566 rInfo.bCanConvToPoly =FALSE;
1567 rInfo.bCanConvToPathLineToArea=FALSE;
1568 rInfo.bCanConvToPolyLineToArea=FALSE;
1569 rInfo.bCanConvToContour = FALSE;
1572 // -----------------------------------------------------------------------------
1574 UINT16 SdrOle2Obj::GetObjIdentifier() const
1576 return bFrame ? UINT16(OBJ_FRAME) : UINT16(OBJ_OLE2);
1579 // -----------------------------------------------------------------------------
1581 void SdrOle2Obj::TakeObjNameSingul(XubString& rName) const
1583 rName = ImpGetResStr(bFrame ? STR_ObjNameSingulFrame : STR_ObjNameSingulOLE2);
1585 const String aName(GetName());
1587 if( aName.Len() )
1589 rName.AppendAscii(" '");
1590 rName += aName;
1591 rName += sal_Unicode('\'');
1595 // -----------------------------------------------------------------------------
1597 void SdrOle2Obj::TakeObjNamePlural(XubString& rName) const
1599 rName=ImpGetResStr(bFrame ? STR_ObjNamePluralFrame : STR_ObjNamePluralOLE2);
1602 // -----------------------------------------------------------------------------
1604 void SdrOle2Obj::operator=(const SdrObject& rObj)
1606 //TODO/LATER: who takes over control of my old object?!
1607 if( &rObj != this )
1609 // #116235#
1610 // ImpAssign( rObj );
1611 const SdrOle2Obj& rOle2Obj = static_cast< const SdrOle2Obj& >( rObj );
1613 uno::Reference < util::XCloseable > xClose( xObjRef.GetObject(), uno::UNO_QUERY );
1615 if( pModel && mpImpl->mbConnected )
1616 Disconnect();
1618 SdrRectObj::operator=( rObj );
1620 // #108867# Manually copying bClosedObj attribute
1621 SetClosedObj( rObj.IsClosedObj() );
1623 mpImpl->aPersistName = rOle2Obj.mpImpl->aPersistName;
1624 aProgName = rOle2Obj.aProgName;
1625 bFrame = rOle2Obj.bFrame;
1627 if( rOle2Obj.pGraphic )
1629 if( pGraphic )
1631 delete pGraphic;
1632 delete mpImpl->pGraphicObject;
1635 pGraphic = new Graphic( *rOle2Obj.pGraphic );
1636 mpImpl->pGraphicObject = new GraphicObject( *pGraphic );
1639 if( pModel && rObj.GetModel() && !IsEmptyPresObj() )
1641 ::comphelper::IEmbeddedHelper* pDestPers = pModel->GetPersist();
1642 ::comphelper::IEmbeddedHelper* pSrcPers = rObj.GetModel()->GetPersist();
1643 if( pDestPers && pSrcPers )
1645 DBG_ASSERT( !xObjRef.is(), "Object already existing!" );
1646 comphelper::EmbeddedObjectContainer& rContainer = pSrcPers->getEmbeddedObjectContainer();
1647 uno::Reference < embed::XEmbeddedObject > xObj = rContainer.GetEmbeddedObject( mpImpl->aPersistName );
1648 if ( xObj.is() )
1650 ::rtl::OUString aTmp;
1651 xObjRef.Assign( pDestPers->getEmbeddedObjectContainer().CopyAndGetEmbeddedObject( rContainer, xObj, aTmp ), rOle2Obj.GetAspect() );
1652 m_bTypeAsked = false;
1653 mpImpl->aPersistName = aTmp;
1654 CheckFileLink_Impl();
1657 Connect();
1659 /* only needed for MSOLE-Objects, now handled inside implementation of Object
1660 if ( xObjRef.is() && rOle2Obj.xObjRef.is() && rOle2Obj.GetAspect() != embed::Aspects::MSOLE_ICON )
1664 awt::Size aVisSize = rOle2Obj.xObjRef->getVisualAreaSize( rOle2Obj.GetAspect() );
1665 if( rOle2Obj.xObjRef->getMapUnit( rOle2Obj.GetAspect() ) == xObjRef->getMapUnit( GetAspect() ) )
1666 xObjRef->setVisualAreaSize( GetAspect(), aVisSize );
1668 catch ( embed::WrongStateException& )
1670 // setting of VisArea not necessary for objects that don't cache it in loaded state
1672 catch( embed::NoVisualAreaSizeException& )
1674 // objects my not have visual areas
1676 catch( uno::Exception& e )
1678 (void)e;
1679 DBG_ERROR( "SdrOle2Obj::operator=(), unexcpected exception caught!" );
1681 } */
1687 // -----------------------------------------------------------------------------
1689 void SdrOle2Obj::ImpSetVisAreaSize()
1691 // currently there is no need to recalculate scaling for iconified objects
1692 // TODO/LATER: it might be needed in future when it is possible to change the icon
1693 if ( GetAspect() == embed::Aspects::MSOLE_ICON )
1694 return;
1696 // the object area of an embedded object was changed, e.g. by user interaction an a selected object
1697 GetObjRef();
1698 if ( xObjRef.is() )
1700 OSL_ASSERT( pModel );
1701 sal_Int64 nMiscStatus = xObjRef->getStatus( GetAspect() );
1703 // the client is required to get access to scaling
1704 SfxInPlaceClient* pClient = SfxInPlaceClient::GetClient( dynamic_cast<SfxObjectShell*>(pModel->GetPersist()), xObjRef.GetObject() );
1705 sal_Bool bHasOwnClient =
1706 ( mpImpl->pLightClient
1707 && xObjRef->getClientSite() == uno::Reference< embed::XEmbeddedClient >( mpImpl->pLightClient ) );
1709 if ( pClient || bHasOwnClient )
1711 // TODO/LATER: IMHO we need to do similar things when object is UIActive or OutplaceActive?! (MBA)
1712 if ( (nMiscStatus & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE) &&
1713 svt::EmbeddedObjectRef::TryRunningState( xObjRef.GetObject() )
1714 || xObjRef->getCurrentState() == embed::EmbedStates::INPLACE_ACTIVE
1717 Fraction aScaleWidth;
1718 Fraction aScaleHeight;
1719 if ( pClient )
1721 aScaleWidth = pClient->GetScaleWidth();
1722 aScaleHeight = pClient->GetScaleHeight();
1724 else
1726 aScaleWidth = mpImpl->pLightClient->GetScaleWidth();
1727 aScaleHeight = mpImpl->pLightClient->GetScaleHeight();
1730 // The object wants to resize itself (f.e. Chart wants to recalculate the layout)
1731 // or object is inplace active and so has a window that must be resized also
1732 // In these cases the change in the object area size will be reflected in a change of the
1733 // objects' visual area. The scaling will not change, but it might exist already and must
1734 // be used in calculations
1735 MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObjRef->getMapUnit( GetAspect() ) );
1736 Size aVisSize( (long)( Fraction( aRect.GetWidth() ) / aScaleWidth ),
1737 (long)( Fraction( aRect.GetHeight() ) / aScaleHeight ) );
1739 aVisSize = OutputDevice::LogicToLogic( aVisSize, pModel->GetScaleUnit(), aMapUnit);
1740 awt::Size aSz;
1741 aSz.Width = aVisSize.Width();
1742 aSz.Height = aVisSize.Height();
1743 xObjRef->setVisualAreaSize( GetAspect(), aSz );
1747 aSz = xObjRef->getVisualAreaSize( GetAspect() );
1749 catch( embed::NoVisualAreaSizeException& )
1752 Rectangle aAcceptedVisArea;
1753 aAcceptedVisArea.SetSize( Size( (long)( Fraction( long( aSz.Width ) ) * aScaleWidth ),
1754 (long)( Fraction( long( aSz.Height ) ) * aScaleHeight ) ) );
1755 if (aVisSize != aAcceptedVisArea.GetSize())
1757 // server changed VisArea to its liking and the VisArea is different than the suggested one
1758 // store the new value as given by the object
1759 MapUnit aNewMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObjRef->getMapUnit( GetAspect() ) );
1760 aRect.SetSize(OutputDevice::LogicToLogic( aAcceptedVisArea.GetSize(), aNewMapUnit, pModel->GetScaleUnit()));
1763 // make the new object area known to the client
1764 // compared to the "else" branch aRect might have been changed by the object and no additional scaling was applied
1765 // OJ: WHY this -> OSL_ASSERT( pClient );
1766 if( pClient )
1767 pClient->SetObjArea(aRect);
1769 // we need a new replacement image as the object has resized itself
1771 //#i79578# don't request a new replacement image for charts to often
1772 //a chart sends a modified call to the framework if it was changed
1773 //thus the replacement update is already handled there
1774 if( !IsChart() )
1775 xObjRef.UpdateReplacement();
1777 else
1779 // The object isn't active and does not want to resize itself so the changed object area size
1780 // will be reflected in a changed object scaling
1781 Fraction aScaleWidth;
1782 Fraction aScaleHeight;
1783 Size aObjAreaSize;
1784 if ( CalculateNewScaling( aScaleWidth, aScaleHeight, aObjAreaSize ) )
1786 if ( pClient )
1788 Rectangle aScaleRect(aRect.TopLeft(), aObjAreaSize);
1789 pClient->SetObjAreaAndScale( aScaleRect, aScaleWidth, aScaleHeight);
1791 else
1793 mpImpl->pLightClient->SetSizeScale( aScaleWidth, aScaleHeight );
1798 else if( (nMiscStatus & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE) &&
1799 svt::EmbeddedObjectRef::TryRunningState( xObjRef.GetObject() ) )
1801 //also handle not sfx based ole objects e.g. charts
1802 //#i83860# resizing charts in impress distorts fonts
1803 uno::Reference< embed::XVisualObject > xVisualObject( this->getXModel(), uno::UNO_QUERY );
1804 if( xVisualObject.is() )
1806 MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObjRef->getMapUnit( GetAspect() ) );
1807 Point aTL( aRect.TopLeft() );
1808 Point aBR( aRect.BottomRight() );
1809 Point aTL2( OutputDevice::LogicToLogic( aTL, pModel->GetScaleUnit(), aMapUnit) );
1810 Point aBR2( OutputDevice::LogicToLogic( aBR, pModel->GetScaleUnit(), aMapUnit) );
1811 Rectangle aNewRect( aTL2, aBR2 );
1812 xVisualObject->setVisualAreaSize( GetAspect(), awt::Size( aNewRect.GetWidth(), aNewRect.GetHeight() ) );
1818 // -----------------------------------------------------------------------------
1820 void SdrOle2Obj::NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact)
1822 if( pModel && !pModel->isLocked() )
1824 GetObjRef();
1825 if ( xObjRef.is() && ( xObjRef->getStatus( GetAspect() ) & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE ) )
1827 // if the object needs recompose on resize
1828 // the client site should be created before the resize will take place
1829 // check whether there is no client site and create it if necessary
1830 if ( !SfxInPlaceClient::GetClient( dynamic_cast<SfxObjectShell*>(pModel->GetPersist()), xObjRef.GetObject() )
1831 && !( mpImpl->pLightClient && xObjRef->getClientSite() == uno::Reference< embed::XEmbeddedClient >( mpImpl->pLightClient ) ) )
1833 AddOwnLightClient();
1838 SdrRectObj::NbcResize(rRef,xFact,yFact);
1839 if (aGeo.nShearWink!=0 || aGeo.nDrehWink!=0) { // kleine Korrekturen
1840 if (aGeo.nDrehWink>=9000 && aGeo.nDrehWink<27000) {
1841 aRect.Move(aRect.Left()-aRect.Right(),aRect.Top()-aRect.Bottom());
1843 aGeo.nDrehWink=0;
1844 aGeo.nShearWink=0;
1845 aGeo.nSin=0.0;
1846 aGeo.nCos=1.0;
1847 aGeo.nTan=0.0;
1848 SetRectsDirty();
1850 if( pModel && !pModel->isLocked() )
1851 ImpSetVisAreaSize();
1854 // -----------------------------------------------------------------------------
1856 void SdrOle2Obj::SetGeoData(const SdrObjGeoData& rGeo)
1858 SdrRectObj::SetGeoData(rGeo);
1859 if( pModel && !pModel->isLocked() )
1860 ImpSetVisAreaSize();
1863 // -----------------------------------------------------------------------------
1865 void SdrOle2Obj::NbcSetSnapRect(const Rectangle& rRect)
1867 SdrRectObj::NbcSetSnapRect(rRect);
1868 if( pModel && !pModel->isLocked() )
1869 ImpSetVisAreaSize();
1871 if ( xObjRef.is() && IsChart() )
1873 //#i103460# charts do not necessaryly have an own size within ODF files,
1874 //for this case they need to use the size settings from the surrounding frame,
1875 //which is made available with this method as there is no other way
1876 xObjRef.SetDefaultSizeForChart( Size( rRect.GetWidth(), rRect.GetHeight() ) );
1880 // -----------------------------------------------------------------------------
1882 void SdrOle2Obj::NbcSetLogicRect(const Rectangle& rRect)
1884 SdrRectObj::NbcSetLogicRect(rRect);
1885 if( pModel && !pModel->isLocked() )
1886 ImpSetVisAreaSize();
1889 Graphic* SdrOle2Obj::GetGraphic() const
1891 if ( xObjRef.is() )
1892 return xObjRef.GetGraphic();
1893 return pGraphic;
1896 void SdrOle2Obj::GetNewReplacement()
1898 if ( xObjRef.is() )
1899 xObjRef.UpdateReplacement();
1902 // -----------------------------------------------------------------------------
1904 Size SdrOle2Obj::GetOrigObjSize( MapMode* pTargetMapMode ) const
1906 return xObjRef.GetSize( pTargetMapMode );
1909 // -----------------------------------------------------------------------------
1911 void SdrOle2Obj::NbcMove(const Size& rSize)
1913 SdrRectObj::NbcMove(rSize);
1914 if( pModel && !pModel->isLocked() )
1915 ImpSetVisAreaSize();
1918 // -----------------------------------------------------------------------------
1920 sal_Bool SdrOle2Obj::CanUnloadRunningObj( const uno::Reference< embed::XEmbeddedObject >& xObj, sal_Int64 nAspect )
1922 sal_Bool bResult = sal_False;
1924 sal_Int32 nState = xObj->getCurrentState();
1925 if ( nState == embed::EmbedStates::LOADED )
1927 // the object is already unloaded
1928 bResult = sal_True;
1930 else
1932 uno::Reference < util::XModifiable > xModifiable( xObj->getComponent(), uno::UNO_QUERY );
1933 if ( !xModifiable.is() )
1934 bResult = sal_True;
1935 else
1937 sal_Int64 nMiscStatus = xObj->getStatus( nAspect );
1939 if ( embed::EmbedMisc::MS_EMBED_ALWAYSRUN != ( nMiscStatus & embed::EmbedMisc::MS_EMBED_ALWAYSRUN ) &&
1940 embed::EmbedMisc::EMBED_ACTIVATEIMMEDIATELY != ( nMiscStatus & embed::EmbedMisc::EMBED_ACTIVATEIMMEDIATELY ) &&
1941 !( xModifiable.is() && xModifiable->isModified() ) &&
1942 !( nState == embed::EmbedStates::INPLACE_ACTIVE || nState == embed::EmbedStates::UI_ACTIVE || nState == embed::EmbedStates::ACTIVE ) )
1944 bResult = sal_True;
1949 return bResult;
1952 // -----------------------------------------------------------------------------
1954 sal_Bool SdrOle2Obj::Unload( const uno::Reference< embed::XEmbeddedObject >& xObj, sal_Int64 nAspect )
1956 sal_Bool bResult = sal_False;
1958 if ( CanUnloadRunningObj( xObj, nAspect ) )
1962 xObj->changeState( embed::EmbedStates::LOADED );
1963 bResult = sal_True;
1965 catch( ::com::sun::star::uno::Exception& e )
1967 (void)e;
1968 DBG_ERROR(
1969 (OString("SdrOle2Obj::Unload=(), "
1970 "exception caught: ") +
1971 rtl::OUStringToOString(
1972 comphelper::anyToString( cppu::getCaughtException() ),
1973 RTL_TEXTENCODING_UTF8 )).getStr() );
1977 return bResult;
1980 // -----------------------------------------------------------------------------
1982 BOOL SdrOle2Obj::Unload()
1984 BOOL bUnloaded = FALSE;
1986 if( xObjRef.is() )
1988 //TODO/LATER: no refcounting tricks anymore!
1989 //"customers" must register as state change listeners
1990 //Nicht notwendig im Doc DTor (MM)
1991 //ULONG nRefCount = (*ppObjRef)->GetRefCount();
1992 // prevent Unload if there are external references
1993 //if( nRefCount > 2 )
1994 // return FALSE;
1995 //DBG_ASSERT( nRefCount == 2, "Wrong RefCount for unload" );
1997 else
1998 bUnloaded = TRUE;
2000 if ( pModel && xObjRef.is() )
2002 bUnloaded = Unload( xObjRef.GetObject(), GetAspect() );
2005 return bUnloaded;
2008 // -----------------------------------------------------------------------------
2010 void SdrOle2Obj::GetObjRef_Impl()
2012 if ( !xObjRef.is() && mpImpl->aPersistName.Len() && pModel && pModel->GetPersist() )
2014 // #107645#
2015 // Only try loading if it did not went wrong up to now
2016 if(!mpImpl->mbLoadingOLEObjectFailed)
2018 xObjRef.Assign( pModel->GetPersist()->getEmbeddedObjectContainer().GetEmbeddedObject( mpImpl->aPersistName ), GetAspect() );
2019 m_bTypeAsked = false;
2020 CheckFileLink_Impl();
2022 // #107645#
2023 // If loading of OLE object failed, remember that to not invoke a endless
2024 // loop trying to load it again and again.
2025 if( xObjRef.is() )
2027 mpImpl->mbLoadingOLEObjectFailed = sal_True;
2030 // #108759# For math objects, set closed state to transparent
2031 if( ImplIsMathObj( xObjRef.GetObject() ) )
2032 SetClosedObj( false );
2035 if ( xObjRef.is() )
2037 if( !IsEmptyPresObj() )
2039 // #75637# remember modified status of model
2040 const sal_Bool bWasChanged(pModel ? pModel->IsChanged() : sal_False);
2042 // perhaps preview not valid anymore
2043 // #75637# This line changes the modified state of the model
2044 SetGraphic_Impl( NULL );
2046 // #75637# if status was not set before, force it back
2047 // to not set, so that SetGraphic(0L) above does not
2048 // set the modified state of the model.
2049 if(!bWasChanged && pModel && pModel->IsChanged())
2051 pModel->SetChanged( sal_False );
2055 sal_Int64 nMiscStatus = xObjRef->getStatus( GetAspect() );
2056 (void)nMiscStatus;
2057 //TODO/LATER: wait until ResizeOnPrinterChange is defined
2058 //if ( nMiscStatus & SVOBJ_MISCSTATUS_RESIZEONPRINTERCHANGE )
2060 if (pModel && pModel->GetRefDevice() &&
2061 pModel->GetRefDevice()->GetOutDevType() == OUTDEV_PRINTER)
2063 if(!bInDestruction)
2065 //TODO/LATER: printerchange notification
2067 // prevent SetModified (don't want no update here)
2068 sal_Bool bWasEnabled = (*ppObjRef)->IsEnableSetModified();
2069 if ( bWasEnabled )
2070 (*ppObjRef)->EnableSetModified( sal_False );
2072 // Kein RefDevice oder RefDevice kein Printer
2073 Printer* pPrinter = (Printer*) pModel->GetRefDevice();
2074 (*ppObjRef)->OnDocumentPrinterChanged( pPrinter );
2076 // reset state
2077 (*ppObjRef)->EnableSetModified( bWasEnabled );*/
2083 if ( xObjRef.is() )
2084 Connect();
2087 if ( mpImpl->mbConnected )
2088 // move object to first position in cache
2089 GetSdrGlobalData().GetOLEObjCache().InsertObj(this);
2092 uno::Reference < embed::XEmbeddedObject > SdrOle2Obj::GetObjRef() const
2094 const_cast<SdrOle2Obj*>(this)->GetObjRef_Impl();
2095 return xObjRef.GetObject();
2098 uno::Reference < embed::XEmbeddedObject > SdrOle2Obj::GetObjRef_NoInit() const
2100 return xObjRef.GetObject();
2103 // -----------------------------------------------------------------------------
2105 uno::Reference< frame::XModel > SdrOle2Obj::getXModel() const
2107 GetObjRef();
2108 if ( svt::EmbeddedObjectRef::TryRunningState(xObjRef.GetObject()) )
2109 return uno::Reference< frame::XModel >( xObjRef->getComponent(), uno::UNO_QUERY );
2110 else
2111 return uno::Reference< frame::XModel >();
2114 // -----------------------------------------------------------------------------
2116 // #109985#
2117 sal_Bool SdrOle2Obj::IsChart() const
2119 if ( !m_bTypeAsked )
2121 m_bChart = ChartPrettyPainter::IsChart(xObjRef);
2122 m_bTypeAsked = true;
2124 return m_bChart;
2127 // -----------------------------------------------------------------------------
2128 void SdrOle2Obj::SetGraphicToObj( const Graphic& aGraphic, const ::rtl::OUString& aMediaType )
2130 xObjRef.SetGraphic( aGraphic, aMediaType );
2133 // -----------------------------------------------------------------------------
2134 void SdrOle2Obj::SetGraphicToObj( const uno::Reference< io::XInputStream >& xGrStream, const ::rtl::OUString& aMediaType )
2136 xObjRef.SetGraphicStream( xGrStream, aMediaType );
2139 // -----------------------------------------------------------------------------
2140 sal_Bool SdrOle2Obj::IsCalc() const
2142 if ( !xObjRef.is() )
2143 return false;
2145 SvGlobalName aObjClsId( xObjRef->getClassID() );
2146 if( SvGlobalName(SO3_SC_CLASSID_30) == aObjClsId
2147 || SvGlobalName(SO3_SC_CLASSID_40) == aObjClsId
2148 || SvGlobalName(SO3_SC_CLASSID_50) == aObjClsId
2149 || SvGlobalName(SO3_SC_CLASSID_60) == aObjClsId
2150 || SvGlobalName(SO3_SC_OLE_EMBED_CLASSID_60) == aObjClsId
2151 || SvGlobalName(SO3_SC_OLE_EMBED_CLASSID_8) == aObjClsId
2152 || SvGlobalName(SO3_SC_CLASSID) == aObjClsId )
2154 return sal_True;
2157 return sal_False;
2160 // -----------------------------------------------------------------------------
2161 uno::Reference< frame::XModel > SdrOle2Obj::GetParentXModel() const
2163 uno::Reference< frame::XModel > xDoc;
2164 if ( pModel )
2165 xDoc.set( pModel->getUnoModel(),uno::UNO_QUERY);
2166 return xDoc;
2169 // -----------------------------------------------------------------------------
2170 sal_Bool SdrOle2Obj::CalculateNewScaling( Fraction& aScaleWidth, Fraction& aScaleHeight, Size& aObjAreaSize )
2172 // TODO/LEAN: to avoid rounding errors scaling always uses the VisArea.
2173 // If we don't cache it for own objects also we must load the object here
2174 if ( !xObjRef.is() || !pModel )
2175 return sal_False;
2177 MapMode aMapMode( pModel->GetScaleUnit() );
2178 aObjAreaSize = xObjRef.GetSize( &aMapMode );
2180 Size aSize = aRect.GetSize();
2181 aScaleWidth = Fraction(aSize.Width(), aObjAreaSize.Width() );
2182 aScaleHeight = Fraction(aSize.Height(), aObjAreaSize.Height() );
2184 // reduce to 10 binary digits
2185 Kuerzen(aScaleHeight, 10);
2186 Kuerzen(aScaleWidth, 10);
2188 return sal_True;
2191 // -----------------------------------------------------------------------------
2192 sal_Bool SdrOle2Obj::AddOwnLightClient()
2194 // The Own Light Client must be registered in object only using this method!
2195 Connect();
2197 if ( xObjRef.is() && mpImpl->pLightClient )
2199 Fraction aScaleWidth;
2200 Fraction aScaleHeight;
2201 Size aObjAreaSize;
2202 if ( CalculateNewScaling( aScaleWidth, aScaleHeight, aObjAreaSize ) )
2204 mpImpl->pLightClient->SetSizeScale( aScaleWidth, aScaleHeight );
2205 try {
2206 xObjRef->setClientSite( mpImpl->pLightClient );
2207 return sal_True;
2208 } catch( uno::Exception& )
2214 return sal_False;
2217 //////////////////////////////////////////////////////////////////////////////
2219 Bitmap SdrOle2Obj::GetEmtyOLEReplacementBitmap()
2221 return Bitmap(ResId(BMP_SVXOLEOBJ, *ImpGetResMgr()));
2224 //////////////////////////////////////////////////////////////////////////////
2226 void SdrOle2Obj::SetWindow(const com::sun::star::uno::Reference < com::sun::star::awt::XWindow >& _xWindow)
2228 if ( xObjRef.is() && mpImpl->pLightClient )
2230 mpImpl->pLightClient->setWindow(_xWindow);
2234 //////////////////////////////////////////////////////////////////////////////
2235 // eof