xref: /trunk/main/svx/source/svdraw/svdoole2.cxx (revision 3cb38764)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26 
27 #include <svx/svdoole2.hxx>
28 #include <com/sun/star/util/XModifyBroadcaster.hpp>
29 #include <com/sun/star/util/XModifiable.hpp>
30 #include <com/sun/star/embed/EmbedStates.hpp>
31 #include <com/sun/star/embed/ElementModes.hpp>
32 #include <com/sun/star/embed/EmbedMisc.hpp>
33 #include <com/sun/star/embed/Aspects.hpp>
34 #include <com/sun/star/embed/XInplaceClient.hpp>
35 #include <com/sun/star/embed/XInplaceObject.hpp>
36 #include <com/sun/star/embed/XLinkageSupport.hpp>
37 #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
38 #include <com/sun/star/embed/XWindowSupplier.hpp>
39 #include <com/sun/star/document/XEventListener.hpp>
40 #include <com/sun/star/container/XChild.hpp>
41 #include "com/sun/star/document/XStorageBasedDocument.hpp"
42 
43 #include <comphelper/processfactory.hxx>
44 #include <cppuhelper/exc_hlp.hxx>
45 #include <unotools/ucbstreamhelper.hxx>
46 
47 #include <toolkit/helper/vclunohelper.hxx>
48 #include <toolkit/awt/vclxwindow.hxx>
49 #include <toolkit/helper/convert.hxx>
50 
51 #include <svtools/filter.hxx>
52 #include <svtools/embedhlp.hxx>
53 
54 #include <sfx2/objsh.hxx>
55 #include <sfx2/ipclient.hxx>
56 #include <sfx2/lnkbase.hxx>
57 #include <tools/stream.hxx>
58 #include <comphelper/anytostring.hxx>
59 #include <svx/svdpagv.hxx>
60 #include <tools/globname.hxx>
61 #include <vcl/jobset.hxx>
62 #include <sot/clsids.hxx>
63 
64 #include <sot/formats.hxx>
65 #include <sfx2/linkmgr.hxx>
66 #include <svtools/transfer.hxx>
67 #include <cppuhelper/implbase5.hxx>
68 
69 #include <svl/solar.hrc>
70 #include <svl/urihelper.hxx>
71 #include <vos/mutex.hxx>
72 #include <vcl/svapp.hxx>
73 
74 #include <svx/svdpagv.hxx>
75 #include <svx/svdmodel.hxx>
76 #include "svx/svdglob.hxx"  // Stringcache
77 #include "svx/svdstr.hrc"   // Objektname
78 #include <svx/svdetc.hxx>
79 #include <svx/svdview.hxx>
80 #include "unomlstr.hxx"
81 #include <svx/charthelper.hxx>
82 #include <svx/sdr/contact/viewcontactofsdrole2obj.hxx>
83 #include <svx/svdograf.hxx>
84 #include <svx/sdr/properties/oleproperties.hxx>
85 
86 // #i100710#
87 #include <svx/xlnclit.hxx>
88 #include <svx/xbtmpit.hxx>
89 #include <svx/xflbmtit.hxx>
90 #include <svx/xflbstit.hxx>
91 
92 // #i118485#
93 #include <basegfx/matrix/b2dhommatrix.hxx>
94 #include <basegfx/polygon/b2dpolypolygon.hxx>
95 #include <editeng/outlobj.hxx>
96 
97 #include <svx/svdpage.hxx>
98 
99 using namespace ::rtl;
100 using namespace ::com::sun::star;
101 
lcl_getFrame_throw(const SdrOle2Obj * _pObject)102 uno::Reference < beans::XPropertySet > lcl_getFrame_throw(const SdrOle2Obj* _pObject)
103 {
104     uno::Reference < beans::XPropertySet > xFrame;
105     if ( _pObject )
106     {
107         uno::Reference< frame::XController> xController = _pObject->GetParentXModel()->getCurrentController();
108         if ( xController.is() )
109         {
110             xFrame.set( xController->getFrame(),uno::UNO_QUERY_THROW);
111         }
112     } // if ( _pObject )
113     return xFrame;
114 }
115 
116 class SdrLightEmbeddedClient_Impl : public ::cppu::WeakImplHelper5
117 															< embed::XStateChangeListener
118 															, document::XEventListener
119                                                             , embed::XInplaceClient
120 															, embed::XEmbeddedClient
121                                                             , embed::XWindowSupplier
122                                                             >
123 {
124     uno::Reference< awt::XWindow > m_xWindow;
125 	SdrOle2Obj* mpObj;
126 
127 	Fraction m_aScaleWidth;
128 	Fraction m_aScaleHeight;
129 
130 
131 public:
132     SdrLightEmbeddedClient_Impl( SdrOle2Obj* pObj );
133     void Release();
134 
SetSizeScale(const Fraction & aScaleWidth,const Fraction & aScaleHeight)135 	void SetSizeScale( const Fraction& aScaleWidth, const Fraction& aScaleHeight )
136 	{
137 		m_aScaleWidth = aScaleWidth;
138 		m_aScaleHeight = aScaleHeight;
139 	}
140 
GetScaleWidth() const141 	Fraction GetScaleWidth() const { return m_aScaleWidth; }
GetScaleHeight() const142 	Fraction GetScaleHeight() const { return m_aScaleHeight; }
143 
144     void setWindow(const uno::Reference< awt::XWindow >& _xWindow);
145 
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);
152 
153     // document::XEventListener
154     virtual void SAL_CALL       notifyEvent( const document::EventObject& aEvent ) throw( uno::RuntimeException );
155 
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 );
159 
160 	// XComponentSupplier
161     virtual uno::Reference< util::XCloseable > SAL_CALL getComponent() throw ( uno::RuntimeException );
162 
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 );
176 
177     // XWindowSupplier
178     virtual uno::Reference< awt::XWindow > SAL_CALL getWindow() throw ( uno::RuntimeException );
179 };
180 
181 //--------------------------------------------------------------------
SdrLightEmbeddedClient_Impl(SdrOle2Obj * pObj)182 SdrLightEmbeddedClient_Impl::SdrLightEmbeddedClient_Impl( SdrOle2Obj* pObj )
183 : mpObj( pObj )
184 {
185 }
impl_getScaledRect_nothrow() const186 Rectangle SdrLightEmbeddedClient_Impl::impl_getScaledRect_nothrow() const
187 {
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;
197 }
198 //--------------------------------------------------------------------
changingState(const::com::sun::star::lang::EventObject &,::sal_Int32,::sal_Int32)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)
200 {
201 }
202 
203 //--------------------------------------------------------------------
Release()204 void SdrLightEmbeddedClient_Impl::Release()
205 {
206 	{
207 		::vos::OGuard aGuard( Application::GetSolarMutex() );
208     	mpObj = NULL;
209 	}
210 
211     release();
212 }
213 
214 //--------------------------------------------------------------------
stateChanged(const::com::sun::star::lang::EventObject &,::sal_Int32 nOldState,::sal_Int32 nNewState)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)
216 {
217 	::vos::OGuard aGuard( Application::GetSolarMutex() );
218 
219     if ( mpObj && nOldState == embed::EmbedStates::LOADED && nNewState == embed::EmbedStates::RUNNING )
220     {
221         mpObj->ObjectLoaded();
222         GetSdrGlobalData().GetOLEObjCache().InsertObj(mpObj);
223     }
224     else if ( mpObj && nNewState == embed::EmbedStates::LOADED && nOldState == embed::EmbedStates::RUNNING )
225     {
226         GetSdrGlobalData().GetOLEObjCache().RemoveObj(mpObj);
227     }
228 }
229 
230 //--------------------------------------------------------------------
disposing(const::com::sun::star::lang::EventObject &)231 void SAL_CALL SdrLightEmbeddedClient_Impl::disposing( const ::com::sun::star::lang::EventObject& /*aEvent*/ ) throw (::com::sun::star::uno::RuntimeException)
232 {
233 	::vos::OGuard aGuard( Application::GetSolarMutex() );
234 
235     GetSdrGlobalData().GetOLEObjCache().RemoveObj(mpObj);
236 }
237 
238 //--------------------------------------------------------------------
notifyEvent(const document::EventObject & aEvent)239 void SAL_CALL SdrLightEmbeddedClient_Impl::notifyEvent( const document::EventObject& aEvent ) throw( uno::RuntimeException )
240 {
241 	// TODO/LATER: when writer uses this implementation the code could be shared with SfxInPlaceClient_Impl
242 
243 	::vos::OGuard aGuard( Application::GetSolarMutex() );
244 
245 	// the code currently makes sense 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 ) )
248 	{
249 		try
250 		{
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() ) );
255 
256 		    MapUnit aObjMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( mpObj->GetObjRef()->getMapUnit( mpObj->GetAspect() ) );
257 
258 		    Rectangle		   aVisArea;
259 		    awt::Size aSz;
260 		    try
261 		    {
262 			    aSz = mpObj->GetObjRef()->getVisualAreaSize( mpObj->GetAspect() );
263 		    }
264 		    catch( embed::NoVisualAreaSizeException& )
265 		    {
266 			    OSL_ENSURE( sal_False, "No visual area size!\n" );
267 			    aSz.Width = 5000;
268 			    aSz.Height = 5000;
269 		    }
270 		    catch( uno::Exception& )
271 		    {
272 			    OSL_ENSURE( sal_False, "Unexpected exception!\n" );
273 			    aSz.Width = 5000;
274 			    aSz.Height = 5000;
275 		    }
276 
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() );
282 
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() )
290 			{
291 				mpObj->SetLogicRect( Rectangle( aLogicRect.TopLeft(), aScaledSize ) );
292 				mpObj->BroadcastObjectChange();
293 			}
294 			else
295 				mpObj->ActionChanged();
296 		}
297 		catch( uno::Exception& )
298 		{
299 			OSL_ENSURE( sal_False, "Unexpected exception!\n" );
300 		}
301 	}
302 }
303 
304 //--------------------------------------------------------------------
saveObject()305 void SAL_CALL SdrLightEmbeddedClient_Impl::saveObject()
306 	throw ( embed::ObjectSaveVetoException,
307 			uno::Exception,
308 			uno::RuntimeException )
309 {
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;
313 
314 	{
315 		::vos::OGuard aGuard( Application::GetSolarMutex() );
316 
317 		if ( !mpObj )
318 			throw embed::ObjectSaveVetoException();
319 
320 		// the common persistence 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 );
323 	}
324 
325 	xPersist->storeOwn();
326 
327 	if ( xModifiable.is() )
328 		xModifiable->setModified( sal_True );
329 }
330 
331 //--------------------------------------------------------------------
visibilityChanged(sal_Bool)332 void SAL_CALL SdrLightEmbeddedClient_Impl::visibilityChanged( sal_Bool /*bVisible*/ )
333 	throw ( embed::WrongStateException,
334 			uno::RuntimeException )
335 {
336 	// nothing to do currently
337 	// TODO/LATER: when writer uses this implementation the code could be shared with SfxInPlaceClient_Impl
338     if ( mpObj )
339     {
340         Rectangle aLogicRect( mpObj->GetLogicRect() );
341         Size aLogicSize( aLogicRect.GetWidth(), aLogicRect.GetHeight() );
342 
343         if( mpObj->IsChart() )
344         {
345             //charts never should be stretched see #i84323# for example
346             mpObj->SetLogicRect( Rectangle( aLogicRect.TopLeft(), aLogicSize ) );
347             mpObj->BroadcastObjectChange();
348         } // if( mpObj->IsChart() )
349     }
350 }
351 
352 //--------------------------------------------------------------------
getComponent()353 uno::Reference< util::XCloseable > SAL_CALL SdrLightEmbeddedClient_Impl::getComponent()
354 	throw ( uno::RuntimeException )
355 {
356 	uno::Reference< util::XCloseable > xResult;
357 
358 	::vos::OGuard aGuard( Application::GetSolarMutex() );
359 	if ( mpObj )
360 		xResult = uno::Reference< util::XCloseable >( mpObj->GetParentXModel(), uno::UNO_QUERY );
361 
362 	return xResult;
363 }
364 // XInplaceClient
365 //--------------------------------------------------------------------
canInplaceActivate()366 sal_Bool SAL_CALL SdrLightEmbeddedClient_Impl::canInplaceActivate()
367 	throw ( uno::RuntimeException )
368 {
369     sal_Bool bRet = sal_False;
370     ::vos::OGuard aGuard( Application::GetSolarMutex() );
371     if ( mpObj )
372     {
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;
380 }
381 
382 //--------------------------------------------------------------------
activatingInplace()383 void SAL_CALL SdrLightEmbeddedClient_Impl::activatingInplace()
384 	throw ( embed::WrongStateException,
385 			uno::RuntimeException )
386 {
387 }
388 
389 //--------------------------------------------------------------------
activatingUI()390 void SAL_CALL SdrLightEmbeddedClient_Impl::activatingUI()
391 	throw ( embed::WrongStateException,
392 			uno::RuntimeException )
393 {
394     ::vos::OGuard aGuard( Application::GetSolarMutex() );
395 
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 );
401 
402     OLEObjCache& rObjCache = GetSdrGlobalData().GetOLEObjCache();
403     const sal_uIntPtr nCount = rObjCache.Count();
404     for(sal_Int32 i = nCount-1 ; i >= 0;--i)
405     {
406         SdrOle2Obj* pObj = reinterpret_cast<SdrOle2Obj*>(rObjCache.GetObject(i));
407         if ( pObj != mpObj )
408         {
409             // only deactivate ole objects which belongs to the same frame
410             if ( xFrame == lcl_getFrame_throw(pObj) )
411             {
412                 uno::Reference< embed::XEmbeddedObject > xObject = pObj->GetObjRef();
413                 try
414                 {
415                     if ( xObject->getStatus( pObj->GetAspect() ) & embed::EmbedMisc::MS_EMBED_ACTIVATEWHENVISIBLE )
416                         xObject->changeState( embed::EmbedStates::INPLACE_ACTIVE );
417                     else
418                     {
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 );
425                     }
426                 }
427                 catch (com::sun::star::uno::Exception& )
428                 {}
429             }
430         }
431     } // for(sal_Int32 i = nCount-1 ; i >= 0;--i)
432 
433     //m_pClient->GetViewShell()->UIActivating( m_pClient );
434 }
435 
436 //--------------------------------------------------------------------
deactivatedInplace()437 void SAL_CALL SdrLightEmbeddedClient_Impl::deactivatedInplace()
438 	throw ( embed::WrongStateException,
439 			uno::RuntimeException )
440 {
441 }
442 
443 //--------------------------------------------------------------------
deactivatedUI()444 void SAL_CALL SdrLightEmbeddedClient_Impl::deactivatedUI()
445 	throw ( embed::WrongStateException,
446 			uno::RuntimeException )
447 {
448     ::vos::OGuard aGuard( Application::GetSolarMutex() );
449     com::sun::star::uno::Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager(getLayoutManager());
450     if ( xLayoutManager.is() )
451     {
452         const static rtl::OUString aMenuBarURL( RTL_CONSTASCII_USTRINGPARAM( "private:resource/menubar/menubar" ));
453 		if ( !xLayoutManager->isElementVisible( aMenuBarURL ) )
454         	xLayoutManager->createElement( aMenuBarURL );
455     }
456 }
457 
458 //--------------------------------------------------------------------
getLayoutManager()459 uno::Reference< ::com::sun::star::frame::XLayoutManager > SAL_CALL SdrLightEmbeddedClient_Impl::getLayoutManager()
460 	throw ( embed::WrongStateException,
461 			uno::RuntimeException )
462 {
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));
466     try
467     {
468         xMan.set(xFrame->getPropertyValue( ::rtl::OUString::createFromAscii("LayoutManager") ),uno::UNO_QUERY);
469     }
470     catch ( uno::Exception& )
471     {
472         throw uno::RuntimeException();
473     }
474 
475     return xMan;
476 }
477 
478 //--------------------------------------------------------------------
getInplaceDispatchProvider()479 uno::Reference< frame::XDispatchProvider > SAL_CALL SdrLightEmbeddedClient_Impl::getInplaceDispatchProvider()
480 	throw ( embed::WrongStateException,
481 			uno::RuntimeException )
482 {
483     ::vos::OGuard aGuard( Application::GetSolarMutex() );
484 	return uno::Reference < frame::XDispatchProvider >( lcl_getFrame_throw(mpObj), uno::UNO_QUERY_THROW );
485 }
486 
487 //--------------------------------------------------------------------
getPlacement()488 awt::Rectangle SAL_CALL SdrLightEmbeddedClient_Impl::getPlacement()
489 	throw ( embed::WrongStateException,
490 			uno::RuntimeException )
491 {
492     ::vos::OGuard aGuard( Application::GetSolarMutex() );
493     if ( !mpObj )
494         throw uno::RuntimeException();
495 
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() ) );
501 
502     aLogicRect = Application::GetDefaultDevice()->LogicToPixel(aLogicRect,aContainerMapUnit);
503 	return AWTRectangle( aLogicRect );
504 }
505 
506 //--------------------------------------------------------------------
getClipRectangle()507 awt::Rectangle SAL_CALL SdrLightEmbeddedClient_Impl::getClipRectangle()
508 	throw ( embed::WrongStateException,
509 			uno::RuntimeException )
510 {
511 	return getPlacement();
512 }
513 
514 //--------------------------------------------------------------------
translateAccelerators(const uno::Sequence<awt::KeyEvent> &)515 void SAL_CALL SdrLightEmbeddedClient_Impl::translateAccelerators( const uno::Sequence< awt::KeyEvent >& /*aKeys*/ )
516 	throw ( embed::WrongStateException,
517 			uno::RuntimeException )
518 {
519 }
520 
521 //--------------------------------------------------------------------
scrollObject(const awt::Size &)522 void SAL_CALL SdrLightEmbeddedClient_Impl::scrollObject( const awt::Size& /*aOffset*/ )
523 	throw ( embed::WrongStateException,
524 			uno::RuntimeException )
525 {
526 }
527 
528 //--------------------------------------------------------------------
changedPlacement(const awt::Rectangle & aPosRect)529 void SAL_CALL SdrLightEmbeddedClient_Impl::changedPlacement( const awt::Rectangle& aPosRect )
530 	throw ( embed::WrongStateException,
531 			uno::Exception,
532 			uno::RuntimeException )
533 {
534     ::vos::OGuard aGuard( Application::GetSolarMutex() );
535     if ( !mpObj )
536         throw uno::RuntimeException();
537 
538 	uno::Reference< embed::XInplaceObject > xInplace( mpObj->GetObjRef(), uno::UNO_QUERY );
539     if ( !xInplace.is() )
540 		throw uno::RuntimeException();
541 
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;
549 
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() ) );
555 
556     Rectangle aNewLogicRect = Application::GetDefaultDevice()->PixelToLogic(aNewPixelRect,aContainerMapUnit);
557     Rectangle aLogicRect = impl_getScaledRect_nothrow();
558 
559     if ( aNewLogicRect != aLogicRect )
560 	{
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 );
564 
565     	// new size of the object area without scaling
566     	Size aNewObjSize( Fraction( aNewLogicRect.GetWidth() ) / m_aScaleWidth,
567                           Fraction( aNewLogicRect.GetHeight() ) / m_aScaleHeight );
568 
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() )
578 		{
579 			mpObj->SetLogicRect( Rectangle( aLogicRect.TopLeft(), aNewObjSize ) );
580 			mpObj->BroadcastObjectChange();
581 		}
582 		else
583 			mpObj->ActionChanged();
584 
585 		// let the window size be recalculated
586 		//SizeHasChanged(); // TODO: OJ
587 	}
588 }
589 // XWindowSupplier
590 //--------------------------------------------------------------------
getWindow()591 uno::Reference< awt::XWindow > SAL_CALL SdrLightEmbeddedClient_Impl::getWindow()
592 	throw ( uno::RuntimeException )
593 {
594 	::vos::OGuard aGuard( Application::GetSolarMutex() );
595     uno::Reference< awt::XWindow > xCurrent = m_xWindow;
596     if ( !xCurrent.is() )
597     {
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;
604 }
setWindow(const uno::Reference<awt::XWindow> & _xWindow)605 void SdrLightEmbeddedClient_Impl::setWindow(const uno::Reference< awt::XWindow >& _xWindow)
606 {
607     m_xWindow = _xWindow;
608 }
609 
610 ////////////////////////////////////////////////////////////////////////////////////////////////////
611 
612 class SdrEmbedObjectLink : public sfx2::SvBaseLink
613 {
614 	SdrOle2Obj*			pObj;
615 
616 public:
617 						SdrEmbedObjectLink(SdrOle2Obj* pObj);
618 	virtual				~SdrEmbedObjectLink();
619 
620 	virtual void		Closed();
621 	virtual void		DataChanged( const String& rMimeType,
622 								const ::com::sun::star::uno::Any & rValue );
623 
Connect()624 	sal_Bool			Connect() { return GetRealObject() != NULL; }
625 };
626 
627 // -----------------------------------------------------------------------------
628 
SdrEmbedObjectLink(SdrOle2Obj * pObject)629 SdrEmbedObjectLink::SdrEmbedObjectLink(SdrOle2Obj* pObject):
630 	::sfx2::SvBaseLink( ::sfx2::LINKUPDATE_ONCALL, SOT_FORMATSTR_ID_SVXB ),
631 	pObj(pObject)
632 {
633 	SetSynchron( sal_False );
634 }
635 
636 // -----------------------------------------------------------------------------
637 
~SdrEmbedObjectLink()638 SdrEmbedObjectLink::~SdrEmbedObjectLink()
639 {
640 }
641 
642 // -----------------------------------------------------------------------------
643 
DataChanged(const String &,const::com::sun::star::uno::Any &)644 void SdrEmbedObjectLink::DataChanged( const String& /*rMimeType*/,
645 								const ::com::sun::star::uno::Any & /*rValue*/ )
646 {
647 	if ( !pObj->UpdateLinkURL_Impl() )
648 	{
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() )
653 		{
654 			// let the object reload the link
655 			// TODO/LATER: reload call could be used for this case
656 
657 			try
658 			{
659 				sal_Int32 nState = xObject->getCurrentState();
660 				if ( nState != embed::EmbedStates::LOADED )
661 				{
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 );
665 				}
666 			}
667 			catch ( uno::Exception& )
668 			{
669 			}
670 		}
671 	}
672 
673 	pObj->GetNewReplacement();
674 	pObj->SetChanged();
675 }
676 
677 // -----------------------------------------------------------------------------
678 
Closed()679 void SdrEmbedObjectLink::Closed()
680 {
681 	pObj->BreakFileLink_Impl();
682 	SvBaseLink::Closed();
683 }
684 
685 ////////////////////////////////////////////////////////////////////////////////////////////////////
686 
687 class SdrOle2ObjImpl
688 {
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
694 
695 	// #107645#
696 	// New local var to avoid repeated loading if load of OLE2 fails
697 	sal_Bool		mbLoadingOLEObjectFailed;
698     sal_Bool        mbConnected;
699 
700 	SdrEmbedObjectLink*	mpObjectLink;
701 	String maLinkURL;
702 
SdrOle2ObjImpl()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 )
710 	{
711 	}
712 };
713 
714 ////////////////////////////////////////////////////////////////////////////////////////////////////
715 
716 // Predicate determining whether the given OLE is an internal math
717 // object
ImplIsMathObj(const uno::Reference<embed::XEmbeddedObject> & rObjRef)718 static bool ImplIsMathObj( const uno::Reference < embed::XEmbeddedObject >& rObjRef )
719 {
720     if ( !rObjRef.is() )
721         return false;
722 
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) 		)
729     {
730         return true;
731     }
732     else
733     {
734         return false;
735     }
736 }
737 
738 //////////////////////////////////////////////////////////////////////////////
739 // BaseProperties section
740 
CreateObjectSpecificProperties()741 sdr::properties::BaseProperties* SdrOle2Obj::CreateObjectSpecificProperties()
742 {
743 	return new sdr::properties::OleProperties(*this);
744 }
745 
746 //////////////////////////////////////////////////////////////////////////////
747 // DrawContact section
748 
CreateObjectSpecificViewContact()749 sdr::contact::ViewContact* SdrOle2Obj::CreateObjectSpecificViewContact()
750 {
751 	return new sdr::contact::ViewContactOfSdrOle2Obj(*this);
752 }
753 
754 // -----------------------------------------------------------------------------
755 
756 TYPEINIT1(SdrOle2Obj,SdrRectObj);
DBG_NAME(SdrOle2Obj)757 DBG_NAME(SdrOle2Obj)
758 SdrOle2Obj::SdrOle2Obj(FASTBOOL bFrame_) : m_bTypeAsked(false)
759 ,m_bChart(false)
760 {
761     DBG_CTOR( SdrOle2Obj,NULL);
762 	bInDestruction = sal_False;
763     mbSuppressSetVisAreaSize = false;
764 	Init();
765 	bFrame=bFrame_;
766 }
767 
768 // -----------------------------------------------------------------------------
SdrOle2Obj(const svt::EmbeddedObjectRef & rNewObjRef,FASTBOOL bFrame_)769 SdrOle2Obj::SdrOle2Obj( const svt::EmbeddedObjectRef& rNewObjRef, FASTBOOL bFrame_)
770     : xObjRef( rNewObjRef )
771     , m_bTypeAsked(false)
772     , m_bChart(false)
773 {
774     DBG_CTOR( SdrOle2Obj,NULL);
775 	bInDestruction = sal_False;
776     mbSuppressSetVisAreaSize = false;
777 	Init();
778 
779 	bFrame=bFrame_;
780 
781     if ( xObjRef.is() && (xObjRef->getStatus( GetAspect() ) & embed::EmbedMisc::EMBED_NEVERRESIZE ) )
782         SetResizeProtect(sal_True);
783 
784     // #108759# For math objects, set closed state to transparent
785     SetClosedObj(!ImplIsMathObj( xObjRef.GetObject() ));
786 }
787 
788 // -----------------------------------------------------------------------------
789 
SdrOle2Obj(const svt::EmbeddedObjectRef & rNewObjRef,const XubString & rNewObjName,FASTBOOL bFrame_)790 SdrOle2Obj::SdrOle2Obj( const svt::EmbeddedObjectRef& rNewObjRef, const XubString& rNewObjName, FASTBOOL bFrame_)
791     : xObjRef( rNewObjRef )
792     , m_bTypeAsked(false)
793     , m_bChart(false)
794 {
795     DBG_CTOR( SdrOle2Obj,NULL);
796 	bInDestruction = sal_False;
797     mbSuppressSetVisAreaSize = false;
798 	Init();
799 
800 	mpImpl->aPersistName = rNewObjName;
801 	bFrame=bFrame_;
802 
803     if ( xObjRef.is() && (xObjRef->getStatus( GetAspect() ) & embed::EmbedMisc::EMBED_NEVERRESIZE ) )
804         SetResizeProtect(sal_True);
805 
806     // #108759# For math objects, set closed state to transparent
807     SetClosedObj(!ImplIsMathObj( xObjRef.GetObject() ));
808 }
809 
810 // -----------------------------------------------------------------------------
811 
SdrOle2Obj(const svt::EmbeddedObjectRef & rNewObjRef,const XubString & rNewObjName,const Rectangle & rNewRect,FASTBOOL bFrame_)812 SdrOle2Obj::SdrOle2Obj( const svt::EmbeddedObjectRef&  rNewObjRef, const XubString& rNewObjName, const Rectangle& rNewRect, FASTBOOL bFrame_)
813     : SdrRectObj(rNewRect)
814     , xObjRef( rNewObjRef )
815     , m_bTypeAsked(false)
816     , m_bChart(false)
817 {
818     DBG_CTOR( SdrOle2Obj,NULL);
819 	bInDestruction = sal_False;
820     mbSuppressSetVisAreaSize = false;
821 	Init();
822 
823 	mpImpl->aPersistName = rNewObjName;
824 	bFrame=bFrame_;
825 
826     if ( xObjRef.is() && (xObjRef->getStatus( GetAspect() ) & embed::EmbedMisc::EMBED_NEVERRESIZE ) )
827         SetResizeProtect(sal_True);
828 
829     // #108759# For math objects, set closed state to transparent
830     SetClosedObj(!ImplIsMathObj( xObjRef.GetObject() ));
831 }
832 
833 // -----------------------------------------------------------------------------
834 
Init()835 void SdrOle2Obj::Init()
836 {
837 	mpImpl = new SdrOle2ObjImpl;
838 	pModifyListener = NULL;
839 	pGraphic=NULL;
840 	mpImpl->pGraphicObject=NULL;
841     mpImpl->pLightClient = 0;
842 
843     xObjRef.Lock( sal_True );
844 }
845 
846 // -----------------------------------------------------------------------------
GetStyleString()847 String SdrOle2Obj::GetStyleString()
848 {
849 	String strStyle;
850 	if( xObjRef.is() && xObjRef.IsChart() )
851 	{
852 		strStyle = xObjRef.GetChartType();
853 	}
854 	return strStyle;
855 }
856 
857 // -----------------------------------------------------------------------------
~SdrOle2Obj()858 SdrOle2Obj::~SdrOle2Obj()
859 {
860     DBG_DTOR( SdrOle2Obj,NULL);
861 	bInDestruction = sal_True;
862 
863     if ( mpImpl->mbConnected )
864         Disconnect();
865 
866     if( pGraphic!=NULL )
867 		delete pGraphic;
868 
869 	if(mpImpl->pGraphicObject!=NULL)
870 		delete mpImpl->pGraphicObject;
871 
872 	if(pModifyListener)
873 	{
874 		pModifyListener->invalidate();
875 		pModifyListener->release();
876 	}
877 
878 	DisconnectFileLink_Impl();
879 
880     if ( mpImpl->pLightClient )
881 	{
882         mpImpl->pLightClient->Release();
883 		mpImpl->pLightClient = NULL;
884 	}
885 
886 	delete mpImpl;
887 }
888 
889 // -----------------------------------------------------------------------------
SetAspect(sal_Int64 nAspect)890 void SdrOle2Obj::SetAspect( sal_Int64 nAspect )
891 {
892 	xObjRef.SetViewAspect( nAspect );
893 }
894 
895 // -----------------------------------------------------------------------------
isInplaceActive() const896 bool SdrOle2Obj::isInplaceActive() const
897 {
898     return xObjRef.is() && embed::EmbedStates::INPLACE_ACTIVE == xObjRef->getCurrentState();
899 }
900 
901 // -----------------------------------------------------------------------------
isUiActive() const902 bool SdrOle2Obj::isUiActive() const
903 {
904     return xObjRef.is() && embed::EmbedStates::UI_ACTIVE == xObjRef->getCurrentState();
905 }
906 
907 // -----------------------------------------------------------------------------
908 
SetGraphic_Impl(const Graphic * pGrf)909 void SdrOle2Obj::SetGraphic_Impl(const Graphic* pGrf)
910 {
911 	if ( pGraphic )
912 	{
913 		delete pGraphic;
914 		pGraphic = NULL;
915 		delete mpImpl->pGraphicObject;
916 		mpImpl->pGraphicObject = NULL;
917 	}
918 
919 	if (pGrf!=NULL)
920 	{
921 		pGraphic = new Graphic(*pGrf);
922 		mpImpl->pGraphicObject = new GraphicObject( *pGraphic );
923 	}
924 
925 	SetChanged();
926 	BroadcastObjectChange();
927 
928 	//if ( ppObjRef->Is() && pGrf )
929 	//	BroadcastObjectChange();
930 }
931 
SetGraphic(const Graphic * pGrf)932 void SdrOle2Obj::SetGraphic(const Graphic* pGrf)
933 {
934     // only for setting a preview graphic
935     SetGraphic_Impl( pGrf );
936 }
937 
938 // -----------------------------------------------------------------------------
939 
IsEmpty() const940 FASTBOOL SdrOle2Obj::IsEmpty() const
941 {
942     return !(xObjRef.is());
943 }
944 
945 // -----------------------------------------------------------------------------
946 
Connect()947 void SdrOle2Obj::Connect()
948 {
949 	if( IsEmptyPresObj() )
950 		return;
951 
952     if( mpImpl->mbConnected )
953     {
954         // mba: currently there are situations where it seems to be unavoidable to have multiple connects
955         // changing this would need a larger code rewrite, so for now I remove the assertion
956         // DBG_ERROR("Connect() called on connected object!");
957 		return;
958     }
959 
960     Connect_Impl();
961     AddListeners_Impl();
962 }
963 
964 // -----------------------------------------------------------------------------
965 
UpdateLinkURL_Impl()966 sal_Bool SdrOle2Obj::UpdateLinkURL_Impl()
967 {
968 	sal_Bool bResult = sal_False;
969 
970 	if ( mpImpl->mpObjectLink )
971 	{
972 		sfx2::LinkManager* pLinkManager = pModel ? pModel->GetLinkManager() : NULL;
973 		if ( pLinkManager )
974 		{
975 			String aNewLinkURL;
976 			pLinkManager->GetDisplayNames( mpImpl->mpObjectLink, 0, &aNewLinkURL, 0, 0 );
977 			if ( !aNewLinkURL.EqualsIgnoreCaseAscii( mpImpl->maLinkURL ) )
978 			{
979     			const_cast<SdrOle2Obj*>(this)->GetObjRef_Impl();
980 				uno::Reference< embed::XCommonEmbedPersist > xPersObj( xObjRef.GetObject(), uno::UNO_QUERY );
981 				OSL_ENSURE( xPersObj.is(), "The object must exist!\n" );
982     			if ( xPersObj.is() )
983 				{
984 					try
985 					{
986 						sal_Int32 nCurState = xObjRef->getCurrentState();
987 						if ( nCurState != embed::EmbedStates::LOADED )
988 							xObjRef->changeState( embed::EmbedStates::LOADED );
989 
990 						// TODO/LATER: there should be possible to get current mediadescriptor settings from the object
991 						uno::Sequence< beans::PropertyValue > aArgs( 1 );
992 						aArgs[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) );
993 						aArgs[0].Value <<= ::rtl::OUString( aNewLinkURL );
994 						xPersObj->reload( aArgs, uno::Sequence< beans::PropertyValue >() );
995 
996 						mpImpl->maLinkURL = aNewLinkURL;
997 						bResult = sal_True;
998 
999 						if ( nCurState != embed::EmbedStates::LOADED )
1000 							xObjRef->changeState( nCurState );
1001 					}
1002 					catch( ::com::sun::star::uno::Exception& e )
1003 					{
1004 						(void)e;
1005 						DBG_ERROR(
1006 							(OString("SdrOle2Obj::UpdateLinkURL_Impl(), "
1007 									"exception caught: ") +
1008 							rtl::OUStringToOString(
1009 								comphelper::anyToString( cppu::getCaughtException() ),
1010 								RTL_TEXTENCODING_UTF8 )).getStr() );
1011 					}
1012 				}
1013 
1014 				if ( !bResult )
1015 				{
1016 					// TODO/LATER: return the old name to the link manager, is it possible?
1017 				}
1018 			}
1019 		}
1020 	}
1021 
1022 	return bResult;
1023 }
1024 
1025 // -----------------------------------------------------------------------------
1026 
BreakFileLink_Impl()1027 void SdrOle2Obj::BreakFileLink_Impl()
1028 {
1029     uno::Reference<document::XStorageBasedDocument> xDoc;
1030 	if ( pModel )
1031 		xDoc.set( pModel->getUnoModel(),uno::UNO_QUERY);
1032 
1033 	if ( xDoc.is() )
1034 	{
1035 		uno::Reference< embed::XStorage > xStorage = xDoc->getDocumentStorage();
1036 		if ( xStorage.is() )
1037 		{
1038 			try
1039 			{
1040 				uno::Reference< embed::XLinkageSupport > xLinkSupport( xObjRef.GetObject(), uno::UNO_QUERY_THROW );
1041 				xLinkSupport->breakLink( xStorage, mpImpl->aPersistName );
1042 				DisconnectFileLink_Impl();
1043 				mpImpl->maLinkURL = String();
1044 			}
1045 			catch( ::com::sun::star::uno::Exception& e )
1046 			{
1047 				(void)e;
1048 				DBG_ERROR(
1049 					(OString("SdrOle2Obj::BreakFileLink_Impl(), "
1050 							"exception caught: ") +
1051 					rtl::OUStringToOString(
1052 						comphelper::anyToString( cppu::getCaughtException() ),
1053 						RTL_TEXTENCODING_UTF8 )).getStr() );
1054 			}
1055 		}
1056 	}
1057 }
1058 
1059 // -----------------------------------------------------------------------------
1060 
DisconnectFileLink_Impl()1061 void SdrOle2Obj::DisconnectFileLink_Impl()
1062 {
1063 	sfx2::LinkManager* pLinkManager = pModel ? pModel->GetLinkManager() : NULL;
1064 	if ( pLinkManager && mpImpl->mpObjectLink )
1065 	{
1066 		pLinkManager->Remove( mpImpl->mpObjectLink );
1067 		mpImpl->mpObjectLink = NULL;
1068 	}
1069 }
1070 
1071 // -----------------------------------------------------------------------------
1072 
CheckFileLink_Impl()1073 void SdrOle2Obj::CheckFileLink_Impl()
1074 {
1075 	if ( pModel && xObjRef.GetObject().is() && !mpImpl->mpObjectLink )
1076 	{
1077 		try
1078 		{
1079 			uno::Reference< embed::XLinkageSupport > xLinkSupport( xObjRef.GetObject(), uno::UNO_QUERY );
1080 			if ( xLinkSupport.is() && xLinkSupport->isLink() )
1081 			{
1082 				String aLinkURL = xLinkSupport->getLinkURL();
1083 				if ( aLinkURL.Len() )
1084 				{
1085 					// this is a file link so the model link manager should handle it
1086 					sfx2::LinkManager* pLinkManager = pModel->GetLinkManager();
1087 					if ( pLinkManager )
1088 					{
1089 						mpImpl->mpObjectLink = new SdrEmbedObjectLink( this );
1090 						mpImpl->maLinkURL = aLinkURL;
1091 						pLinkManager->InsertFileLink( *mpImpl->mpObjectLink, OBJECT_CLIENT_OLE, aLinkURL, NULL, NULL );
1092 						mpImpl->mpObjectLink->Connect();
1093 					}
1094 				}
1095 			}
1096 		}
1097 		catch( ::com::sun::star::uno::Exception& e )
1098 		{
1099 			(void)e;
1100 			DBG_ERROR(
1101 				(OString("SdrOle2Obj::CheckFileLink_Impl(), "
1102 						"exception caught: ") +
1103 				rtl::OUStringToOString(
1104 					comphelper::anyToString( cppu::getCaughtException() ),
1105 					RTL_TEXTENCODING_UTF8 )).getStr() );
1106 		}
1107 	}
1108 }
1109 
1110 // -----------------------------------------------------------------------------
1111 
Reconnect_Impl()1112 void SdrOle2Obj::Reconnect_Impl()
1113 {
1114     DBG_ASSERT( mpImpl->mbConnected, "Assigned unconnected object?!" );
1115     Connect_Impl();
1116 }
1117 
Connect_Impl()1118 void SdrOle2Obj::Connect_Impl()
1119 {
1120     if( pModel && mpImpl->aPersistName.Len() )
1121 	{
1122 		try
1123 		{
1124 			::comphelper::IEmbeddedHelper* pPers = pModel->GetPersist();
1125 			if ( pPers )
1126 			{
1127 				comphelper::EmbeddedObjectContainer& rContainer = pPers->getEmbeddedObjectContainer();
1128 				if ( !rContainer.HasEmbeddedObject( mpImpl->aPersistName )
1129 				  || ( xObjRef.is() && !rContainer.HasEmbeddedObject( xObjRef.GetObject() ) ) )
1130 				{
1131 					// object not known to container document
1132 					// No object -> disaster!
1133 					DBG_ASSERT( xObjRef.is(), "No object in connect!");
1134 					if ( xObjRef.is() )
1135 					{
1136 						// object came from the outside, now add it to the container
1137 						::rtl::OUString aTmp;
1138 						rContainer.InsertEmbeddedObject( xObjRef.GetObject(), aTmp );
1139                         mpImpl->aPersistName = aTmp;
1140 					}
1141 				}
1142 				else if ( !xObjRef.is() )
1143                 {
1144 					xObjRef.Assign( rContainer.GetEmbeddedObject( mpImpl->aPersistName ), xObjRef.GetViewAspect() );
1145                     m_bTypeAsked = false;
1146                 }
1147 
1148 				if ( xObjRef.GetObject().is() )
1149 				{
1150 					xObjRef.AssignToContainer( &rContainer, mpImpl->aPersistName );
1151 					mpImpl->mbConnected = true;
1152 					xObjRef.Lock( sal_True );
1153 				}
1154 			}
1155 
1156 			if ( xObjRef.is() )
1157 			{
1158 				if ( !mpImpl->pLightClient )
1159 				{
1160 					mpImpl->pLightClient = new SdrLightEmbeddedClient_Impl( this );
1161 					mpImpl->pLightClient->acquire();
1162 				}
1163 
1164 				xObjRef->addStateChangeListener( mpImpl->pLightClient );
1165 				xObjRef->addEventListener( uno::Reference< document::XEventListener >( mpImpl->pLightClient ) );
1166 
1167 				if ( xObjRef->getCurrentState() != embed::EmbedStates::LOADED )
1168 					GetSdrGlobalData().GetOLEObjCache().InsertObj(this);
1169 
1170 				CheckFileLink_Impl();
1171 
1172 				uno::Reference< container::XChild > xChild( xObjRef.GetObject(), uno::UNO_QUERY );
1173 				if( xChild.is() )
1174                 {
1175                     uno::Reference< uno::XInterface > xParent( pModel->getUnoModel());
1176                     if( xParent.is())
1177                         xChild->setParent( pModel->getUnoModel() );
1178                 }
1179 
1180 			}
1181 		}
1182 		catch( ::com::sun::star::uno::Exception& e )
1183 		{
1184 			(void)e;
1185 			DBG_ERROR(
1186 				(OString("SdrOle2Obj::Connect_Impl(), "
1187 						"exception caught: ") +
1188 				rtl::OUStringToOString(
1189 					comphelper::anyToString( cppu::getCaughtException() ),
1190 					RTL_TEXTENCODING_UTF8 )).getStr() );
1191 		}
1192 	}
1193 
1194     //TODO/LATER: wait for definition of MiscStatus RESIZEONPRINTERCHANGE
1195     //if ( xObjRef.is() && (*ppObjRef)->GetMiscStatus() & SVOBJ_MISCSTATUS_RESIZEONPRINTERCHANGE )
1196 	{
1197         //TODO/LATER: needs a new handling for OnPrinterChanged
1198         /*
1199 		if (pModel && pModel->GetRefDevice() &&
1200 			pModel->GetRefDevice()->GetOutDevType() == OUTDEV_PRINTER)
1201 		{
1202 			// Kein RefDevice oder RefDevice kein Printer
1203 			sal_Bool bModified = (*ppObjRef)->IsModified();
1204 			Printer* pPrinter = (Printer*) pModel->GetRefDevice();
1205 			(*ppObjRef)->OnDocumentPrinterChanged( pPrinter );
1206 			(*ppObjRef)->SetModified( bModified );
1207         }*/
1208 	}
1209 }
1210 
ObjectLoaded()1211 void SdrOle2Obj::ObjectLoaded()
1212 {
1213     AddListeners_Impl();
1214 }
1215 
AddListeners_Impl()1216 void SdrOle2Obj::AddListeners_Impl()
1217 {
1218     if( xObjRef.is() && xObjRef->getCurrentState() != embed::EmbedStates::LOADED )
1219 	{
1220 		// register modify listener
1221         if( !pModifyListener )
1222 		{
1223 			((SdrOle2Obj*)this)->pModifyListener = new SvxUnoShapeModifyListener( (SdrOle2Obj*)this );
1224 			pModifyListener->acquire();
1225 		}
1226 
1227 		uno::Reference< util::XModifyBroadcaster > xBC( getXModel(), uno::UNO_QUERY );
1228 		if( xBC.is() && pModifyListener )
1229 		{
1230 			uno::Reference< util::XModifyListener > xListener( pModifyListener );
1231 			xBC->addModifyListener( xListener );
1232 		}
1233 	}
1234 }
1235 
1236 // -----------------------------------------------------------------------------
1237 
Disconnect()1238 void SdrOle2Obj::Disconnect()
1239 {
1240 	if( IsEmptyPresObj() )
1241 		return;
1242 
1243 	if( !mpImpl->mbConnected )
1244     {
1245         DBG_ERROR("Disconnect() called on disconnected object!");
1246 		return;
1247     }
1248 
1249     RemoveListeners_Impl();
1250     Disconnect_Impl();
1251 }
1252 
RemoveListeners_Impl()1253 void SdrOle2Obj::RemoveListeners_Impl()
1254 {
1255     if( xObjRef.is() && mpImpl->aPersistName.Len() )
1256 	{
1257 		try
1258 		{
1259 			sal_Int32 nState = xObjRef->getCurrentState();
1260 			if ( nState != embed::EmbedStates::LOADED )
1261 			{
1262 				uno::Reference< util::XModifyBroadcaster > xBC( getXModel(), uno::UNO_QUERY );
1263 				if( xBC.is() && pModifyListener )
1264 				{
1265 					uno::Reference< util::XModifyListener > xListener( pModifyListener );
1266 					xBC->removeModifyListener( xListener );
1267 				}
1268 			}
1269 		}
1270 		catch( ::com::sun::star::uno::Exception& e )
1271 		{
1272 			(void)e;
1273 			DBG_ERROR(
1274 				(OString("SdrOle2Obj::RemoveListeners_Impl(), "
1275 						"exception caught: ") +
1276 				rtl::OUStringToOString(
1277 					comphelper::anyToString( cppu::getCaughtException() ),
1278 					RTL_TEXTENCODING_UTF8 )).getStr() );
1279 		}
1280 	}
1281 }
1282 
Disconnect_Impl()1283 void SdrOle2Obj::Disconnect_Impl()
1284 {
1285 	try
1286 	{
1287 		if ( pModel && mpImpl->aPersistName.Len() )
1288 		{
1289 			if( pModel->IsInDestruction() )
1290 			{
1291 				// TODO/LATER: here we must assume that the destruction of the model is enough to make clear that we will not
1292 				// remove the object from the container, even if the DrawingObject itself is not destroyed (unfortunately this
1293 				// There is no real need to do the following removing of the object from the container
1294 				// in case the model has correct persistence, but in case of problems such a removing
1295 				// would make the behavior of the office more stable
1296 
1297 				comphelper::EmbeddedObjectContainer* pContainer = xObjRef.GetContainer();
1298 				if ( pContainer )
1299 				{
1300 					pContainer->CloseEmbeddedObject( xObjRef.GetObject() );
1301 					xObjRef.AssignToContainer( NULL, mpImpl->aPersistName );
1302 				}
1303 
1304 				// happens later than the destruction of the model, so we can't assert that).
1305 				//DBG_ASSERT( bInDestruction, "Model is destroyed, but not me?!" );
1306 				//TODO/LATER: should be make sure that the ObjectShell also forgets the object, because we will close it soon?
1307 				/*
1308 				uno::Reference < util::XCloseable > xClose( xObjRef, uno::UNO_QUERY );
1309 				if ( xClose.is() )
1310 				{
1311 					try
1312 					{
1313 						xClose->close( sal_True );
1314 					}
1315 					catch ( util::CloseVetoException& )
1316 					{
1317 						// there's still someone who needs the object!
1318 					}
1319 				}
1320 
1321 				xObjRef = NULL;*/
1322 			}
1323 			else if ( xObjRef.is() )
1324 			{
1325 				if ( pModel->getUnoModel().is() )
1326 				{
1327 					// remove object, but don't close it (that's up to someone else)
1328 					comphelper::EmbeddedObjectContainer* pContainer = xObjRef.GetContainer();
1329 					if ( pContainer )
1330 					{
1331 						pContainer->RemoveEmbeddedObject( xObjRef.GetObject(), sal_False);
1332 
1333 						// TODO/LATER: mpImpl->aPersistName contains outdated information, to have it uptodate
1334 						// it should be returned from RemoveEmbeddedObject call. Currently it is no problem,
1335 						// since no container is adjusted, actually the empty string could be provided as a name here
1336 						xObjRef.AssignToContainer( NULL, mpImpl->aPersistName );
1337 					}
1338 
1339 					DisconnectFileLink_Impl();
1340 				}
1341 			}
1342 		}
1343 
1344 		if ( xObjRef.is() && mpImpl->pLightClient )
1345 		{
1346 			xObjRef->removeStateChangeListener ( mpImpl->pLightClient );
1347 			xObjRef->removeEventListener( uno::Reference< document::XEventListener >( mpImpl->pLightClient ) );
1348 			xObjRef->setClientSite( NULL );
1349 
1350 			GetSdrGlobalData().GetOLEObjCache().RemoveObj(this);
1351 		}
1352 	}
1353 	catch( ::com::sun::star::uno::Exception& e )
1354 	{
1355 		(void)e;
1356 		DBG_ERROR(
1357 			(OString("SdrOle2Obj::Disconnect_Impl(), "
1358 					"exception caught: ") +
1359 			rtl::OUStringToOString(
1360 				comphelper::anyToString( cppu::getCaughtException() ),
1361 				RTL_TEXTENCODING_UTF8 )).getStr() );
1362 	}
1363 
1364 	mpImpl->mbConnected = false;
1365 }
1366 
1367 // -----------------------------------------------------------------------------
1368 
createSdrGrafObjReplacement(bool bAddText,bool bUseHCGraphic) const1369 SdrObject* SdrOle2Obj::createSdrGrafObjReplacement(bool bAddText, bool bUseHCGraphic) const
1370 {
1371     Graphic* pOLEGraphic = GetGraphic();
1372 
1373     if(bUseHCGraphic && Application::GetSettings().GetStyleSettings().GetHighContrastMode())
1374     {
1375         pOLEGraphic = getEmbeddedObjectRef().GetHCGraphic();
1376     }
1377 
1378     if(pOLEGraphic)
1379     {
1380         // #i118485# allow creating a SdrGrafObj representation
1381         SdrGrafObj* pClone = new SdrGrafObj(*pOLEGraphic);
1382         pClone->SetModel(GetModel());
1383 
1384         // copy transformation
1385         basegfx::B2DHomMatrix aMatrix;
1386         basegfx::B2DPolyPolygon aPolyPolygon;
1387 
1388         TRGetBaseGeometry(aMatrix, aPolyPolygon);
1389         pClone->TRSetBaseGeometry(aMatrix, aPolyPolygon);
1390 
1391         // copy all attributes to support graphic styles for OLEs
1392         pClone->SetStyleSheet(GetStyleSheet(), false);
1393         pClone->SetMergedItemSet(GetMergedItemSet());
1394 
1395         if(bAddText)
1396         {
1397             // #i118485# copy text (Caution! Model needed, as guaranteed in aw080)
1398             OutlinerParaObject* pOPO = GetOutlinerParaObject();
1399 
1400             if(pOPO && GetModel())
1401             {
1402                 pClone->NbcSetOutlinerParaObject(new OutlinerParaObject(*pOPO));
1403             }
1404         }
1405 
1406         return pClone;
1407     }
1408     else
1409     {
1410         // #i100710# pOLEGraphic may be zero (no visualization available),
1411         // so we need to use the OLE replacement graphic
1412         SdrRectObj* pClone = new SdrRectObj(GetSnapRect());
1413         pClone->SetModel(GetModel());
1414 
1415         // gray outline
1416         pClone->SetMergedItem(XLineStyleItem(XLINE_SOLID));
1417         const svtools::ColorConfig aColorConfig;
1418         const svtools::ColorConfigValue aColor(aColorConfig.GetColorValue(svtools::OBJECTBOUNDARIES));
1419         pClone->SetMergedItem(XLineColorItem(String(), aColor.nColor));
1420 
1421         // bitmap fill
1422         pClone->SetMergedItem(XFillStyleItem(XFILL_BITMAP));
1423         pClone->SetMergedItem(XFillBitmapItem(String(), Graphic(GetEmptyOLEReplacementBitmap())));
1424         pClone->SetMergedItem(XFillBmpTileItem(false));
1425         pClone->SetMergedItem(XFillBmpStretchItem(false));
1426 
1427         return pClone;
1428     }
1429 }
1430 
DoConvertToPolyObj(sal_Bool bBezier,bool bAddText) const1431 SdrObject* SdrOle2Obj::DoConvertToPolyObj(sal_Bool bBezier, bool bAddText) const
1432 {
1433     // #i118485# missing converter added
1434     if(GetModel())
1435     {
1436         SdrObject* pRetval = createSdrGrafObjReplacement(true, false);
1437 
1438         if(pRetval)
1439         {
1440             SdrObject* pRetval2 = pRetval->DoConvertToPolyObj(bBezier, bAddText);
1441             SdrObject::Free(pRetval);
1442 
1443             return pRetval2;
1444         }
1445     }
1446 
1447     return 0;
1448 }
1449 
1450 // -----------------------------------------------------------------------------
1451 
SetModel(SdrModel * pNewModel)1452 void SdrOle2Obj::SetModel(SdrModel* pNewModel)
1453 {
1454     ::comphelper::IEmbeddedHelper* pDestPers = pNewModel ? pNewModel->GetPersist() : 0;
1455     ::comphelper::IEmbeddedHelper* pSrcPers  = pModel ? pModel->GetPersist() : 0;
1456 
1457     if ( pNewModel == pModel )
1458     {
1459         // don't know if this is necessary or if it will ever happen, but who know?!
1460         SdrRectObj::SetModel( pNewModel );
1461         return;
1462     }
1463 
1464     // assignment to model has changed
1465     DBG_ASSERT( pSrcPers || !mpImpl->mbConnected, "Connected object without a model?!" );
1466 
1467 	DBG_ASSERT( pDestPers, "The destination model must have a persistence! Please submit an issue!" );
1468 	DBG_ASSERT( pDestPers != pSrcPers, "The source and the destination models should have different persistences! Problems are possible!" );
1469 
1470 	// this is a bug if the target model has no persistence
1471 	// no error handling is possible so just do nothing in this method
1472 	if ( !pDestPers )
1473 		return;
1474 
1475     RemoveListeners_Impl();
1476 
1477     if( pDestPers && pSrcPers && !IsEmptyPresObj() )
1478     {
1479 		try
1480 		{
1481 			// move the objects' storage; ObjectRef remains the same, but PersistName may change
1482 			::rtl::OUString aTmp;
1483 			comphelper::EmbeddedObjectContainer& rContainer = pSrcPers->getEmbeddedObjectContainer();
1484 			uno::Reference < embed::XEmbeddedObject > xObj = rContainer.GetEmbeddedObject( mpImpl->aPersistName );
1485 			DBG_ASSERT( !xObjRef.is() || xObjRef.GetObject() == xObj, "Wrong object identity!" );
1486 			if ( xObj.is() )
1487 			{
1488 				pDestPers->getEmbeddedObjectContainer().MoveEmbeddedObject( rContainer, xObj, aTmp );
1489 				mpImpl->aPersistName = aTmp;
1490 				xObjRef.AssignToContainer( &pDestPers->getEmbeddedObjectContainer(), aTmp );
1491 			}
1492 	        DBG_ASSERT( aTmp.getLength(), "Copying embedded object failed!" );
1493 		}
1494 		catch( ::com::sun::star::uno::Exception& e )
1495 		{
1496 			(void)e;
1497 			DBG_ERROR(
1498 				(OString("SdrOle2Obj::SetModel(), "
1499 						"exception caught: ") +
1500 				rtl::OUStringToOString(
1501 					comphelper::anyToString( cppu::getCaughtException() ),
1502 					RTL_TEXTENCODING_UTF8 )).getStr() );
1503 		}
1504     }
1505 
1506 	SdrRectObj::SetModel( pNewModel );
1507 
1508     // #i43086#
1509     // #i85304 redo the change for charts for the above bugfix, as #i43086# does not occur anymore
1510     //so maybe the ImpSetVisAreaSize call can be removed here completely
1511     //Nevertheless I leave it in for other objects as I am not sure about the side effects when removing now
1512     if( pModel && !pModel->isLocked() && !IsChart() )
1513         ImpSetVisAreaSize();
1514 
1515     if( pDestPers && !IsEmptyPresObj() )
1516     {
1517         if ( !pSrcPers || IsEmptyPresObj() )
1518             // object wasn't connected, now it should
1519             Connect_Impl();
1520         else
1521             Reconnect_Impl();
1522     }
1523 
1524     AddListeners_Impl();
1525 }
1526 
1527 // -----------------------------------------------------------------------------
1528 
SetPage(SdrPage * pNewPage)1529 void SdrOle2Obj::SetPage(SdrPage* pNewPage)
1530 {
1531 	FASTBOOL bRemove=pNewPage==NULL && pPage!=NULL;
1532 	FASTBOOL bInsert=pNewPage!=NULL && pPage==NULL;
1533 
1534     if (bRemove && mpImpl->mbConnected )
1535         Disconnect();
1536 
1537     if(!pModel && !GetStyleSheet() && pNewPage->GetModel())
1538     {
1539         // #119287# Set default StyleSheet for SdrGrafObj here, it is different from 'Default'. This
1540         // needs to be done before the style 'Default' is set from the :SetModel() call which is triggered
1541         // from the following :SetPage().
1542         // TTTT: Needs to be moved in branch aw080 due to having a SdrModel from the beginning, is at this
1543         // place for convenience currently (works in both versions, is not in the way)
1544 		SfxStyleSheet* pSheet = pNewPage->GetModel()->GetDefaultStyleSheetForSdrGrafObjAndSdrOle2Obj();
1545 
1546 		if(pSheet)
1547 		{
1548 			SetStyleSheet(pSheet, false);
1549 		}
1550         else
1551         {
1552 		    SetMergedItem(XFillStyleItem(XFILL_NONE));
1553 		    SetMergedItem(XLineStyleItem(XLINE_NONE));
1554         }
1555     }
1556 
1557     SdrRectObj::SetPage(pNewPage);
1558 
1559     if (bInsert && !mpImpl->mbConnected )
1560         Connect();
1561 }
1562 
1563 // -----------------------------------------------------------------------------
1564 
SetObjRef(const com::sun::star::uno::Reference<com::sun::star::embed::XEmbeddedObject> & rNewObjRef)1565 void SdrOle2Obj::SetObjRef( const com::sun::star::uno::Reference < com::sun::star::embed::XEmbeddedObject >& rNewObjRef )
1566 {
1567     DBG_ASSERT( !rNewObjRef.is() || !xObjRef.GetObject().is(), "SetObjRef called on already initialized object!");
1568     if( rNewObjRef == xObjRef.GetObject() )
1569 		return;
1570 
1571     // MBA: the caller of the method is responsible to control the old object, it will not be closed here
1572     // Otherwise WW8 import crashes because it transfers control to OLENode by this method
1573     if ( xObjRef.GetObject().is() )
1574         xObjRef.Lock( sal_False );
1575 
1576     // MBA: avoid removal of object in Disconnect! It is definitely a HACK to call SetObjRef(0)!
1577     // This call will try to close the objects; so if anybody else wants to keep it, it must be locked by a CloseListener
1578     xObjRef.Clear();
1579 
1580     if ( mpImpl->mbConnected )
1581         Disconnect();
1582 
1583     xObjRef.Assign( rNewObjRef, GetAspect() );
1584     m_bTypeAsked = false;
1585 
1586     if ( xObjRef.is() )
1587     {
1588         DELETEZ( pGraphic );
1589 
1590         if ( (xObjRef->getStatus( GetAspect() ) & embed::EmbedMisc::EMBED_NEVERRESIZE ) )
1591             SetResizeProtect(sal_True);
1592 
1593         // #108759# For math objects, set closed state to transparent
1594         SetClosedObj(!ImplIsMathObj( rNewObjRef ));
1595 
1596         Connect();
1597     }
1598 
1599 	SetChanged();
1600 	BroadcastObjectChange();
1601 }
1602 
1603 // -----------------------------------------------------------------------------
1604 
SetClosedObj(bool bIsClosed)1605 void SdrOle2Obj::SetClosedObj( bool bIsClosed )
1606 {
1607     // TODO/LATER: do we still need this hack?
1608     // #108759# Allow changes to the closed state of OLE objects
1609     bClosedObj = bIsClosed;
1610 }
1611 
1612 // -----------------------------------------------------------------------------
1613 
getFullDragClone() const1614 SdrObject* SdrOle2Obj::getFullDragClone() const
1615 {
1616     // special handling for OLE. The default handling works, but is too
1617     // slow when the whole OLE needs to be cloned. Get the Metafile and
1618     // create a graphic object with it
1619 
1620     // #i118485# use central replacement generator
1621     return createSdrGrafObjReplacement(false, true);
1622 }
1623 
1624 // -----------------------------------------------------------------------------
1625 
SetPersistName(const String & rPersistName)1626 void SdrOle2Obj::SetPersistName( const String& rPersistName )
1627 {
1628     DBG_ASSERT( !mpImpl->aPersistName.Len(), "Persist name changed!");
1629 
1630     mpImpl->aPersistName = rPersistName;
1631 	mpImpl->mbLoadingOLEObjectFailed = false;
1632 
1633 	Connect();
1634     SetChanged();
1635 }
1636 
AbandonObject()1637 void SdrOle2Obj::AbandonObject()
1638 {
1639     mpImpl->aPersistName.Erase();
1640 	mpImpl->mbLoadingOLEObjectFailed = false;
1641     SetObjRef(0);
1642 }
1643 
1644 // -----------------------------------------------------------------------------
1645 
GetPersistName() const1646 String SdrOle2Obj::GetPersistName() const
1647 {
1648     return mpImpl->aPersistName;
1649 }
1650 
1651 // -----------------------------------------------------------------------------
1652 
TakeObjInfo(SdrObjTransformInfoRec & rInfo) const1653 void SdrOle2Obj::TakeObjInfo(SdrObjTransformInfoRec& rInfo) const
1654 {
1655     // #i118485# Allowing much more attributes for OLEs
1656 	rInfo.bRotateFreeAllowed = true;
1657 	rInfo.bRotate90Allowed = true;
1658 	rInfo.bMirrorFreeAllowed = true;
1659 	rInfo.bMirror45Allowed = true;
1660 	rInfo.bMirror90Allowed = true;
1661 	rInfo.bTransparenceAllowed = true;
1662 	rInfo.bGradientAllowed = true;
1663 	rInfo.bShearAllowed = true;
1664 	rInfo.bEdgeRadiusAllowed = false;
1665 	rInfo.bNoOrthoDesired = false;
1666 	rInfo.bCanConvToPath = true;
1667 	rInfo.bCanConvToPoly = true;
1668 	rInfo.bCanConvToPathLineToArea = false;
1669 	rInfo.bCanConvToPolyLineToArea = false;
1670 	rInfo.bCanConvToContour = true;
1671 }
1672 
1673 // -----------------------------------------------------------------------------
1674 
GetObjIdentifier() const1675 sal_uInt16 SdrOle2Obj::GetObjIdentifier() const
1676 {
1677 	return bFrame ? sal_uInt16(OBJ_FRAME) : sal_uInt16(OBJ_OLE2);
1678 }
1679 
1680 // -----------------------------------------------------------------------------
1681 
TakeObjNameSingul(XubString & rName) const1682 void SdrOle2Obj::TakeObjNameSingul(XubString& rName) const
1683 {
1684 	rName = ImpGetResStr(bFrame ? STR_ObjNameSingulFrame : STR_ObjNameSingulOLE2);
1685 
1686 	const String aName(GetName());
1687 
1688 	if( aName.Len() )
1689 	{
1690 		rName.AppendAscii(" '");
1691 		rName += aName;
1692 		rName += sal_Unicode('\'');
1693 	}
1694 }
1695 
1696 // -----------------------------------------------------------------------------
1697 
TakeObjNamePlural(XubString & rName) const1698 void SdrOle2Obj::TakeObjNamePlural(XubString& rName) const
1699 {
1700 	rName=ImpGetResStr(bFrame ? STR_ObjNamePluralFrame : STR_ObjNamePluralOLE2);
1701 }
1702 
1703 // -----------------------------------------------------------------------------
1704 
operator =(const SdrObject & rObj)1705 void SdrOle2Obj::operator=(const SdrObject& rObj)
1706 {
1707     //TODO/LATER: who takes over control of my old object?!
1708     if( &rObj != this )
1709 	{
1710 		// #116235#
1711 		// ImpAssign( rObj );
1712         const SdrOle2Obj& rOle2Obj = static_cast< const SdrOle2Obj& >( rObj );
1713 
1714         uno::Reference < util::XCloseable > xClose( xObjRef.GetObject(), uno::UNO_QUERY );
1715 
1716         if( pModel && mpImpl->mbConnected )
1717             Disconnect();
1718 
1719         SdrRectObj::operator=( rObj );
1720 
1721         // #108867# Manually copying bClosedObj attribute
1722         SetClosedObj( rObj.IsClosedObj() );
1723 
1724         mpImpl->aPersistName = rOle2Obj.mpImpl->aPersistName;
1725         aProgName = rOle2Obj.aProgName;
1726         bFrame = rOle2Obj.bFrame;
1727 
1728         if( rOle2Obj.pGraphic )
1729         {
1730             if( pGraphic )
1731             {
1732                 delete pGraphic;
1733                 delete mpImpl->pGraphicObject;
1734             }
1735 
1736             pGraphic = new Graphic( *rOle2Obj.pGraphic );
1737             mpImpl->pGraphicObject = new GraphicObject( *pGraphic );
1738         }
1739 
1740         if( pModel && rObj.GetModel() && !IsEmptyPresObj() )
1741         {
1742             ::comphelper::IEmbeddedHelper* pDestPers = pModel->GetPersist();
1743             ::comphelper::IEmbeddedHelper* pSrcPers = rObj.GetModel()->GetPersist();
1744             if( pDestPers && pSrcPers )
1745             {
1746     			DBG_ASSERT( !xObjRef.is(), "Object already existing!" );
1747     			comphelper::EmbeddedObjectContainer& rContainer = pSrcPers->getEmbeddedObjectContainer();
1748     			uno::Reference < embed::XEmbeddedObject > xObj = rContainer.GetEmbeddedObject( mpImpl->aPersistName );
1749     			if ( xObj.is() )
1750     			{
1751         			::rtl::OUString aTmp;
1752         			xObjRef.Assign( pDestPers->getEmbeddedObjectContainer().CopyAndGetEmbeddedObject( rContainer, xObj, aTmp ), rOle2Obj.GetAspect() );
1753                     m_bTypeAsked = false;
1754         			mpImpl->aPersistName = aTmp;
1755 					CheckFileLink_Impl();
1756     			}
1757 
1758                 Connect();
1759 
1760                 /* only needed for MSOLE-Objects, now handled inside implementation of Object
1761 				if ( xObjRef.is() && rOle2Obj.xObjRef.is() && rOle2Obj.GetAspect() != embed::Aspects::MSOLE_ICON )
1762 				{
1763 					try
1764 					{
1765 						awt::Size aVisSize = rOle2Obj.xObjRef->getVisualAreaSize( rOle2Obj.GetAspect() );
1766 						if( rOle2Obj.xObjRef->getMapUnit( rOle2Obj.GetAspect() ) == xObjRef->getMapUnit( GetAspect() ) )
1767 						xObjRef->setVisualAreaSize( GetAspect(), aVisSize );
1768 					}
1769 					catch ( embed::WrongStateException& )
1770 					{
1771 						// setting of VisArea not necessary for objects that don't cache it in loaded state
1772 					}
1773 					catch( embed::NoVisualAreaSizeException& )
1774 					{
1775 						// objects my not have visual areas
1776 					}
1777 					catch( uno::Exception& e )
1778 					{
1779 						(void)e;
1780 						DBG_ERROR( "SdrOle2Obj::operator=(), unexpected exception caught!" );
1781 					}
1782                 }                                                                            */
1783             }
1784         }
1785     }
1786 }
1787 
1788 // -----------------------------------------------------------------------------
1789 
ImpSetVisAreaSize()1790 void SdrOle2Obj::ImpSetVisAreaSize()
1791 {
1792     // #i118524# do not again set VisAreaSize when the call comes from OLE client (e.g. ObjectAreaChanged)
1793     if(mbSuppressSetVisAreaSize)
1794         return;
1795 
1796 	// currently there is no need to recalculate scaling for iconified objects
1797 	// TODO/LATER: it might be needed in future when it is possible to change the icon
1798 	if ( GetAspect() == embed::Aspects::MSOLE_ICON )
1799 		return;
1800 
1801     // the object area of an embedded object was changed, e.g. by user interaction an a selected object
1802     GetObjRef();
1803     if ( xObjRef.is() )
1804 	{
1805         OSL_ASSERT( pModel );
1806         sal_Int64 nMiscStatus = xObjRef->getStatus( GetAspect() );
1807 
1808 		// the client is required to get access to scaling
1809 		SfxInPlaceClient* pClient = SfxInPlaceClient::GetClient( dynamic_cast<SfxObjectShell*>(pModel->GetPersist()), xObjRef.GetObject() );
1810 		sal_Bool bHasOwnClient =
1811 						( mpImpl->pLightClient
1812 						&& xObjRef->getClientSite() == uno::Reference< embed::XEmbeddedClient >( mpImpl->pLightClient ) );
1813 
1814 		if ( pClient || bHasOwnClient )
1815 		{
1816             // TODO/LATER: IMHO we need to do similar things when object is UIActive or OutplaceActive?! (MBA)
1817             if ( ((nMiscStatus & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE) &&
1818                     svt::EmbeddedObjectRef::TryRunningState( xObjRef.GetObject() ))
1819                     || xObjRef->getCurrentState() == embed::EmbedStates::INPLACE_ACTIVE
1820                     )
1821 			{
1822 				Fraction aScaleWidth;
1823 				Fraction aScaleHeight;
1824 				if ( pClient )
1825 				{
1826 					aScaleWidth = pClient->GetScaleWidth();
1827 					aScaleHeight = pClient->GetScaleHeight();
1828 				}
1829 				else
1830 				{
1831 					aScaleWidth = mpImpl->pLightClient->GetScaleWidth();
1832 					aScaleHeight = mpImpl->pLightClient->GetScaleHeight();
1833 				}
1834 
1835                 // The object wants to resize itself (f.e. Chart wants to recalculate the layout)
1836                 // or object is inplace active and so has a window that must be resized also
1837                 // In these cases the change in the object area size will be reflected in a change of the
1838                 // objects' visual area. The scaling will not change, but it might exist already and must
1839                 // be used in calculations
1840 				MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObjRef->getMapUnit( GetAspect() ) );
1841 				Size aVisSize( (long)( Fraction( aRect.GetWidth() ) / aScaleWidth ),
1842 								(long)( Fraction( aRect.GetHeight() ) / aScaleHeight ) );
1843 
1844 				aVisSize = OutputDevice::LogicToLogic( aVisSize, pModel->GetScaleUnit(), aMapUnit);
1845 				awt::Size aSz;
1846 				aSz.Width = aVisSize.Width();
1847 				aSz.Height = aVisSize.Height();
1848 				xObjRef->setVisualAreaSize( GetAspect(), aSz );
1849 
1850 				try
1851 				{
1852 					aSz = xObjRef->getVisualAreaSize( GetAspect() );
1853 				}
1854 				catch( embed::NoVisualAreaSizeException& )
1855 				{}
1856 
1857 				Rectangle aAcceptedVisArea;
1858 				aAcceptedVisArea.SetSize( Size( (long)( Fraction( long( aSz.Width ) ) * aScaleWidth ),
1859 												(long)( Fraction( long( aSz.Height ) ) * aScaleHeight ) ) );
1860 				if (aVisSize != aAcceptedVisArea.GetSize())
1861 				{
1862                     // server changed VisArea to its liking and the VisArea is different than the suggested one
1863                     // store the new value as given by the object
1864 					MapUnit aNewMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObjRef->getMapUnit( GetAspect() ) );
1865 					aRect.SetSize(OutputDevice::LogicToLogic( aAcceptedVisArea.GetSize(), aNewMapUnit, pModel->GetScaleUnit()));
1866                 }
1867 
1868                 // make the new object area known to the client
1869                 // compared to the "else" branch aRect might have been changed by the object and no additional scaling was applied
1870                 // OJ: WHY this -> OSL_ASSERT( pClient );
1871                 if( pClient )
1872                     pClient->SetObjArea(aRect);
1873 
1874                 // we need a new replacement image as the object has resized itself
1875 
1876                 // #i79578# don't request a new replacement image for charts to often
1877                 // a chart sends a modified call to the framework if it was changed
1878                 // thus the replacement update is already handled there
1879                 if( !IsChart() )
1880                     xObjRef.UpdateReplacement();
1881 			}
1882 			else
1883 			{
1884                 // The object isn't active and does not want to resize itself so the changed object area size
1885                 // will be reflected in a changed object scaling
1886 				Fraction aScaleWidth;
1887 				Fraction aScaleHeight;
1888 				Size aObjAreaSize;
1889 				if ( CalculateNewScaling( aScaleWidth, aScaleHeight, aObjAreaSize ) )
1890 				{
1891 					if ( pClient )
1892 					{
1893 						Rectangle aScaleRect(aRect.TopLeft(), aObjAreaSize);
1894 						pClient->SetObjAreaAndScale( aScaleRect, aScaleWidth, aScaleHeight);
1895 					}
1896 					else
1897 					{
1898 						mpImpl->pLightClient->SetSizeScale( aScaleWidth, aScaleHeight );
1899 					}
1900 				}
1901 			}
1902 		}
1903         else if( (nMiscStatus & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE) &&
1904             svt::EmbeddedObjectRef::TryRunningState( xObjRef.GetObject() ) )
1905         {
1906             // also handle not sfx based ole objects e.g. charts
1907             // #i83860# resizing charts in Impress distorts fonts
1908             uno::Reference< embed::XVisualObject > xVisualObject( this->getXModel(), uno::UNO_QUERY );
1909             if( xVisualObject.is() )
1910             {
1911                 MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObjRef->getMapUnit( GetAspect() ) );
1912                 Point aTL( aRect.TopLeft() );
1913                 Point aBR( aRect.BottomRight() );
1914                 Point aTL2( OutputDevice::LogicToLogic( aTL, pModel->GetScaleUnit(), aMapUnit) );
1915                 Point aBR2( OutputDevice::LogicToLogic( aBR, pModel->GetScaleUnit(), aMapUnit) );
1916                 Rectangle aNewRect( aTL2, aBR2 );
1917                 xVisualObject->setVisualAreaSize( GetAspect(), awt::Size( aNewRect.GetWidth(), aNewRect.GetHeight() ) );
1918             }
1919         }
1920 	}
1921 }
1922 
1923 // -----------------------------------------------------------------------------
1924 
NbcResize(const Point & rRef,const Fraction & xFact,const Fraction & yFact)1925 void SdrOle2Obj::NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact)
1926 {
1927 	if( pModel && !pModel->isLocked() )
1928     {
1929         GetObjRef();
1930         if ( xObjRef.is() && ( xObjRef->getStatus( GetAspect() ) & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE ) )
1931         {
1932             // if the object needs recompose on resize
1933             // the client site should be created before the resize will take place
1934             // check whether there is no client site and create it if necessary
1935             AddOwnLightClient();
1936         }
1937     }
1938 
1939 	SdrRectObj::NbcResize(rRef,xFact,yFact);
1940 
1941     if( pModel && !pModel->isLocked() )
1942 		ImpSetVisAreaSize();
1943 }
1944 
1945 // -----------------------------------------------------------------------------
1946 
SetGeoData(const SdrObjGeoData & rGeo)1947 void SdrOle2Obj::SetGeoData(const SdrObjGeoData& rGeo)
1948 {
1949 	SdrRectObj::SetGeoData(rGeo);
1950 
1951     if( pModel && !pModel->isLocked() )
1952 		ImpSetVisAreaSize();
1953 }
1954 
1955 // -----------------------------------------------------------------------------
1956 
NbcSetSnapRect(const Rectangle & rRect)1957 void SdrOle2Obj::NbcSetSnapRect(const Rectangle& rRect)
1958 {
1959 	SdrRectObj::NbcSetSnapRect(rRect);
1960 
1961     if( pModel && !pModel->isLocked() )
1962 		ImpSetVisAreaSize();
1963 
1964     if ( xObjRef.is() && IsChart() )
1965     {
1966         //#i103460# charts do not necessarily have an own size within ODF files,
1967         //for this case they need to use the size settings from the surrounding frame,
1968         //which is made available with this method as there is no other way
1969         xObjRef.SetDefaultSizeForChart( Size( rRect.GetWidth(), rRect.GetHeight() ) );
1970     }
1971 }
1972 
1973 // -----------------------------------------------------------------------------
1974 
NbcSetLogicRect(const Rectangle & rRect)1975 void SdrOle2Obj::NbcSetLogicRect(const Rectangle& rRect)
1976 {
1977 	SdrRectObj::NbcSetLogicRect(rRect);
1978 
1979     if( pModel && !pModel->isLocked() )
1980 		ImpSetVisAreaSize();
1981 }
1982 
GetGraphic() const1983 Graphic* SdrOle2Obj::GetGraphic() const
1984 {
1985     if ( xObjRef.is() )
1986         return xObjRef.GetGraphic();
1987     return pGraphic;
1988 }
1989 
GetNewReplacement()1990 void SdrOle2Obj::GetNewReplacement()
1991 {
1992 	if ( xObjRef.is() )
1993 		xObjRef.UpdateReplacement();
1994 }
1995 
1996 // -----------------------------------------------------------------------------
1997 
GetOrigObjSize(MapMode * pTargetMapMode) const1998 Size SdrOle2Obj::GetOrigObjSize( MapMode* pTargetMapMode ) const
1999 {
2000 	return xObjRef.GetSize( pTargetMapMode );
2001 }
2002 
2003 // -----------------------------------------------------------------------------
2004 
NbcMove(const Size & rSize)2005 void SdrOle2Obj::NbcMove(const Size& rSize)
2006 {
2007 	SdrRectObj::NbcMove(rSize);
2008 
2009     if( pModel && !pModel->isLocked() )
2010 		ImpSetVisAreaSize();
2011 }
2012 
2013 // -----------------------------------------------------------------------------
2014 
CanUnloadRunningObj(const uno::Reference<embed::XEmbeddedObject> & xObj,sal_Int64 nAspect)2015 sal_Bool SdrOle2Obj::CanUnloadRunningObj( const uno::Reference< embed::XEmbeddedObject >& xObj, sal_Int64 nAspect )
2016 {
2017 	sal_Bool bResult = sal_False;
2018 
2019 	sal_Int32 nState = xObj->getCurrentState();
2020 	if ( nState == embed::EmbedStates::LOADED )
2021 	{
2022         // the object is already unloaded
2023 		bResult = sal_True;
2024 	}
2025 	else
2026 	{
2027         uno::Reference < util::XModifiable > xModifiable( xObj->getComponent(), uno::UNO_QUERY );
2028         if ( !xModifiable.is() )
2029             bResult = sal_True;
2030         else
2031         {
2032             sal_Int64 nMiscStatus = xObj->getStatus( nAspect );
2033 
2034             if ( embed::EmbedMisc::MS_EMBED_ALWAYSRUN != ( nMiscStatus & embed::EmbedMisc::MS_EMBED_ALWAYSRUN ) &&
2035             embed::EmbedMisc::EMBED_ACTIVATEIMMEDIATELY != ( nMiscStatus & embed::EmbedMisc::EMBED_ACTIVATEIMMEDIATELY ) &&
2036             !( xModifiable.is() && xModifiable->isModified() ) &&
2037             !( nState == embed::EmbedStates::INPLACE_ACTIVE || nState == embed::EmbedStates::UI_ACTIVE || nState == embed::EmbedStates::ACTIVE ) )
2038             {
2039                 bResult = sal_True;
2040             }
2041         }
2042     }
2043 
2044 	return bResult;
2045 }
2046 
2047 // -----------------------------------------------------------------------------
2048 
Unload(const uno::Reference<embed::XEmbeddedObject> & xObj,sal_Int64 nAspect)2049 sal_Bool SdrOle2Obj::Unload( const uno::Reference< embed::XEmbeddedObject >& xObj, sal_Int64 nAspect )
2050 {
2051 	sal_Bool bResult = sal_False;
2052 
2053     if ( CanUnloadRunningObj( xObj, nAspect ) )
2054     {
2055         try
2056         {
2057             xObj->changeState( embed::EmbedStates::LOADED );
2058             bResult = sal_True;
2059         }
2060         catch( ::com::sun::star::uno::Exception& e )
2061         {
2062             (void)e;
2063             DBG_ERROR(
2064                 (OString("SdrOle2Obj::Unload=(), "
2065                         "exception caught: ") +
2066                 rtl::OUStringToOString(
2067                     comphelper::anyToString( cppu::getCaughtException() ),
2068                     RTL_TEXTENCODING_UTF8 )).getStr() );
2069         }
2070     }
2071 
2072 	return bResult;
2073 }
2074 
2075 // -----------------------------------------------------------------------------
2076 
Unload()2077 sal_Bool SdrOle2Obj::Unload()
2078 {
2079 	sal_Bool bUnloaded = sal_False;
2080 
2081     if( xObjRef.is() )
2082 	{
2083         //TODO/LATER: no refcounting tricks anymore!
2084         //"customers" must register as state change listeners
2085 		//Nicht notwendig im Doc DTor (MM)
2086         //sal_uIntPtr nRefCount = (*ppObjRef)->GetRefCount();
2087 		// prevent Unload if there are external references
2088         //if( nRefCount > 2 )
2089         //    return sal_False;
2090         //DBG_ASSERT( nRefCount == 2, "Wrong RefCount for unload" );
2091 	}
2092 	else
2093 		bUnloaded = sal_True;
2094 
2095     if ( pModel && xObjRef.is() )
2096     {
2097 		bUnloaded = Unload( xObjRef.GetObject(), GetAspect() );
2098 	}
2099 
2100 	return bUnloaded;
2101 }
2102 
2103 // -----------------------------------------------------------------------------
2104 
GetObjRef_Impl()2105 void SdrOle2Obj::GetObjRef_Impl()
2106 {
2107     if ( !xObjRef.is() && mpImpl->aPersistName.Len() && pModel && pModel->GetPersist() )
2108     {
2109 		// #107645#
2110         // Only try loading if it did not went wrong up to now
2111 		if(!mpImpl->mbLoadingOLEObjectFailed)
2112 		{
2113             xObjRef.Assign( pModel->GetPersist()->getEmbeddedObjectContainer().GetEmbeddedObject( mpImpl->aPersistName ), GetAspect() );
2114             m_bTypeAsked = false;
2115 			CheckFileLink_Impl();
2116 
2117 			// #107645#
2118 			// If loading of OLE object failed, remember that to not invoke a endless
2119 			// loop trying to load it again and again.
2120             if( xObjRef.is() )
2121 			{
2122 				mpImpl->mbLoadingOLEObjectFailed = sal_True;
2123 			}
2124 
2125             // #108759# For math objects, set closed state to transparent
2126             SetClosedObj(!ImplIsMathObj( xObjRef.GetObject() ));
2127 		}
2128 
2129         if ( xObjRef.is() )
2130 		{
2131 			if( !IsEmptyPresObj() )
2132 			{
2133 				// #75637# remember modified status of model
2134 				const sal_Bool bWasChanged(pModel ? pModel->IsChanged() : sal_False);
2135 
2136 				// perhaps preview not valid anymore
2137 				// #75637# This line changes the modified state of the model
2138                 SetGraphic_Impl( NULL );
2139 
2140 				// #75637# if status was not set before, force it back
2141 				// to not set, so that SetGraphic(0L) above does not
2142 				// set the modified state of the model.
2143 				if(!bWasChanged && pModel && pModel->IsChanged())
2144 				{
2145 					pModel->SetChanged( sal_False );
2146 				}
2147 			}
2148 
2149             sal_Int64 nMiscStatus = xObjRef->getStatus( GetAspect() );
2150             (void)nMiscStatus;
2151             //TODO/LATER: wait until ResizeOnPrinterChange is defined
2152             //if ( nMiscStatus & SVOBJ_MISCSTATUS_RESIZEONPRINTERCHANGE )
2153 			{
2154 				if (pModel && pModel->GetRefDevice() &&
2155 					pModel->GetRefDevice()->GetOutDevType() == OUTDEV_PRINTER)
2156 				{
2157 					if(!bInDestruction)
2158 					{
2159                         //TODO/LATER: printerchange notification
2160                         /*
2161 						// prevent SetModified (don't want no update here)
2162 						sal_Bool bWasEnabled = (*ppObjRef)->IsEnableSetModified();
2163 						if ( bWasEnabled )
2164 							(*ppObjRef)->EnableSetModified( sal_False );
2165 
2166 						// Kein RefDevice oder RefDevice kein Printer
2167 						Printer* pPrinter = (Printer*) pModel->GetRefDevice();
2168 						(*ppObjRef)->OnDocumentPrinterChanged( pPrinter );
2169 
2170 						// reset state
2171                         (*ppObjRef)->EnableSetModified( bWasEnabled );*/
2172 					}
2173 				}
2174 			}
2175         }
2176 
2177         if ( xObjRef.is() )
2178             Connect();
2179     }
2180 
2181     if ( mpImpl->mbConnected )
2182         // move object to first position in cache
2183         GetSdrGlobalData().GetOLEObjCache().InsertObj(this);
2184 }
2185 
GetObjRef() const2186 uno::Reference < embed::XEmbeddedObject > SdrOle2Obj::GetObjRef() const
2187 {
2188     const_cast<SdrOle2Obj*>(this)->GetObjRef_Impl();
2189     return xObjRef.GetObject();
2190 }
2191 
GetObjRef_NoInit() const2192 uno::Reference < embed::XEmbeddedObject > SdrOle2Obj::GetObjRef_NoInit() const
2193 {
2194     return xObjRef.GetObject();
2195 }
2196 
2197 // -----------------------------------------------------------------------------
2198 
getXModel() const2199 uno::Reference< frame::XModel > SdrOle2Obj::getXModel() const
2200 {
2201     GetObjRef();
2202     if ( svt::EmbeddedObjectRef::TryRunningState(xObjRef.GetObject()) )
2203         return uno::Reference< frame::XModel >( xObjRef->getComponent(), uno::UNO_QUERY );
2204     else
2205         return uno::Reference< frame::XModel >();
2206 }
2207 
2208 // -----------------------------------------------------------------------------
2209 
2210 // #109985#
IsChart() const2211 sal_Bool SdrOle2Obj::IsChart() const
2212 {
2213     if ( !m_bTypeAsked )
2214     {
2215         m_bChart = ChartHelper::IsChart(xObjRef);
2216         m_bTypeAsked = true;
2217     }
2218     return m_bChart;
2219 }
2220 
2221 // -----------------------------------------------------------------------------
SetGraphicToObj(const Graphic & aGraphic,const::rtl::OUString & aMediaType)2222 void SdrOle2Obj::SetGraphicToObj( const Graphic& aGraphic, const ::rtl::OUString& aMediaType )
2223 {
2224 	xObjRef.SetGraphic( aGraphic, aMediaType );
2225 }
2226 
2227 // -----------------------------------------------------------------------------
SetGraphicToObj(const uno::Reference<io::XInputStream> & xGrStream,const::rtl::OUString & aMediaType)2228 void SdrOle2Obj::SetGraphicToObj( const uno::Reference< io::XInputStream >& xGrStream, const ::rtl::OUString& aMediaType )
2229 {
2230 	xObjRef.SetGraphicStream( xGrStream, aMediaType );
2231 }
2232 
2233 // -----------------------------------------------------------------------------
IsCalc() const2234 sal_Bool SdrOle2Obj::IsCalc() const
2235 {
2236     if ( !xObjRef.is() )
2237         return false;
2238 
2239     SvGlobalName aObjClsId( xObjRef->getClassID() );
2240     if(    SvGlobalName(SO3_SC_CLASSID_30) == aObjClsId
2241         || SvGlobalName(SO3_SC_CLASSID_40) == aObjClsId
2242         || SvGlobalName(SO3_SC_CLASSID_50) == aObjClsId
2243         || SvGlobalName(SO3_SC_CLASSID_60) == aObjClsId
2244 		|| SvGlobalName(SO3_SC_OLE_EMBED_CLASSID_60) == aObjClsId
2245 		|| SvGlobalName(SO3_SC_OLE_EMBED_CLASSID_8) == aObjClsId
2246 		|| SvGlobalName(SO3_SC_CLASSID) == aObjClsId )
2247     {
2248         return sal_True;
2249     }
2250 
2251 	return sal_False;
2252 }
2253 
2254 // -----------------------------------------------------------------------------
GetParentXModel() const2255 uno::Reference< frame::XModel > SdrOle2Obj::GetParentXModel() const
2256 {
2257     uno::Reference< frame::XModel > xDoc;
2258 	if ( pModel )
2259 		xDoc.set( pModel->getUnoModel(),uno::UNO_QUERY);
2260     return xDoc;
2261 }
2262 
2263 // -----------------------------------------------------------------------------
CalculateNewScaling(Fraction & aScaleWidth,Fraction & aScaleHeight,Size & aObjAreaSize)2264 sal_Bool SdrOle2Obj::CalculateNewScaling( Fraction& aScaleWidth, Fraction& aScaleHeight, Size& aObjAreaSize )
2265 {
2266 	// TODO/LEAN: to avoid rounding errors scaling always uses the VisArea.
2267 	// If we don't cache it for own objects also we must load the object here
2268 	if ( !xObjRef.is() || !pModel )
2269 		return sal_False;
2270 
2271 	MapMode aMapMode( pModel->GetScaleUnit() );
2272 	aObjAreaSize = xObjRef.GetSize( &aMapMode );
2273 
2274 	Size aSize = aRect.GetSize();
2275 	aScaleWidth = Fraction(aSize.Width(),  aObjAreaSize.Width() );
2276 	aScaleHeight = Fraction(aSize.Height(), aObjAreaSize.Height() );
2277 
2278 	// reduce to 10 binary digits
2279 	Kuerzen(aScaleHeight, 10);
2280 	Kuerzen(aScaleWidth,  10);
2281 
2282 	return sal_True;
2283 }
2284 
2285 // -----------------------------------------------------------------------------
AddOwnLightClient()2286 sal_Bool SdrOle2Obj::AddOwnLightClient()
2287 {
2288 	// The Own Light Client must be registered in object only using this method!
2289     if ( !SfxInPlaceClient::GetClient( dynamic_cast<SfxObjectShell*>(pModel->GetPersist()), xObjRef.GetObject() )
2290       && !( mpImpl->pLightClient && xObjRef->getClientSite() == uno::Reference< embed::XEmbeddedClient >( mpImpl->pLightClient ) ) )
2291     {
2292 	    Connect();
2293 
2294 	    if ( xObjRef.is() && mpImpl->pLightClient )
2295 	    {
2296 		    Fraction aScaleWidth;
2297 		    Fraction aScaleHeight;
2298 		    Size aObjAreaSize;
2299 		    if ( CalculateNewScaling( aScaleWidth, aScaleHeight, aObjAreaSize ) )
2300 		    {
2301 			    mpImpl->pLightClient->SetSizeScale( aScaleWidth, aScaleHeight );
2302 			    try {
2303 				    xObjRef->setClientSite( mpImpl->pLightClient );
2304 				    return sal_True;
2305 			    } catch( uno::Exception& )
2306 			    {}
2307 		    }
2308 
2309 	    }
2310 
2311     	return sal_False;
2312     }
2313 
2314    	return sal_True;
2315 }
2316 
2317 //////////////////////////////////////////////////////////////////////////////
2318 
GetEmptyOLEReplacementBitmap()2319 Bitmap SdrOle2Obj::GetEmptyOLEReplacementBitmap()
2320 {
2321 	return Bitmap(ResId(BMP_SVXOLEOBJ, *ImpGetResMgr()));
2322 }
2323 
2324 //////////////////////////////////////////////////////////////////////////////
2325 
SetWindow(const com::sun::star::uno::Reference<com::sun::star::awt::XWindow> & _xWindow)2326 void SdrOle2Obj::SetWindow(const com::sun::star::uno::Reference < com::sun::star::awt::XWindow >& _xWindow)
2327 {
2328     if ( xObjRef.is() && mpImpl->pLightClient )
2329     {
2330         mpImpl->pLightClient->setWindow(_xWindow);
2331     }
2332 }
2333 
2334 /* vim: set noet sw=4 ts=4: */
2335