xref: /AOO41X/main/svx/source/svdraw/svdoole2.cxx (revision 54628ca40d27d15cc98fe861da7fff7e60c2f7d6)
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 
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 
135     void SetSizeScale( const Fraction& aScaleWidth, const Fraction& aScaleHeight )
136     {
137         m_aScaleWidth = aScaleWidth;
138         m_aScaleHeight = aScaleHeight;
139     }
140 
141     Fraction GetScaleWidth() const { return m_aScaleWidth; }
142     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 //--------------------------------------------------------------------
182 SdrLightEmbeddedClient_Impl::SdrLightEmbeddedClient_Impl( SdrOle2Obj* pObj )
183 : mpObj( pObj )
184 {
185 }
186 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 //--------------------------------------------------------------------
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 //--------------------------------------------------------------------
204 void SdrLightEmbeddedClient_Impl::Release()
205 {
206     {
207         ::vos::OGuard aGuard( Application::GetSolarMutex() );
208         mpObj = NULL;
209     }
210 
211     release();
212 }
213 
214 //--------------------------------------------------------------------
215 void SAL_CALL SdrLightEmbeddedClient_Impl::stateChanged( const ::com::sun::star::lang::EventObject& /*aEvent*/, ::sal_Int32 nOldState, ::sal_Int32 nNewState ) throw (::com::sun::star::uno::RuntimeException)
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 //--------------------------------------------------------------------
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 //--------------------------------------------------------------------
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 sence only in case there is no other client
246     if ( mpObj && mpObj->GetAspect() != embed::Aspects::MSOLE_ICON && aEvent.EventName.equalsAscii("OnVisAreaChanged")
247       && mpObj->GetObjRef().is() && mpObj->GetObjRef()->getClientSite() == uno::Reference< embed::XEmbeddedClient >( this ) )
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 //--------------------------------------------------------------------
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 persistance is supported by objects and links
321         xPersist = uno::Reference< embed::XCommonEmbedPersist >( mpObj->GetObjRef(), uno::UNO_QUERY_THROW );
322         xModifiable = uno::Reference< util::XModifiable >( mpObj->GetParentXModel(), uno::UNO_QUERY );
323     }
324 
325     xPersist->storeOwn();
326 
327     if ( xModifiable.is() )
328         xModifiable->setModified( sal_True );
329 }
330 
331 //--------------------------------------------------------------------
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 //--------------------------------------------------------------------
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 //--------------------------------------------------------------------
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 //--------------------------------------------------------------------
383 void SAL_CALL SdrLightEmbeddedClient_Impl::activatingInplace()
384     throw ( embed::WrongStateException,
385             uno::RuntimeException )
386 {
387 }
388 
389 //--------------------------------------------------------------------
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 //--------------------------------------------------------------------
437 void SAL_CALL SdrLightEmbeddedClient_Impl::deactivatedInplace()
438     throw ( embed::WrongStateException,
439             uno::RuntimeException )
440 {
441 }
442 
443 //--------------------------------------------------------------------
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 //--------------------------------------------------------------------
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 //--------------------------------------------------------------------
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 //--------------------------------------------------------------------
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 //--------------------------------------------------------------------
507 awt::Rectangle SAL_CALL SdrLightEmbeddedClient_Impl::getClipRectangle()
508     throw ( embed::WrongStateException,
509             uno::RuntimeException )
510 {
511     return getPlacement();
512 }
513 
514 //--------------------------------------------------------------------
515 void SAL_CALL SdrLightEmbeddedClient_Impl::translateAccelerators( const uno::Sequence< awt::KeyEvent >& /*aKeys*/ )
516     throw ( embed::WrongStateException,
517             uno::RuntimeException )
518 {
519 }
520 
521 //--------------------------------------------------------------------
522 void SAL_CALL SdrLightEmbeddedClient_Impl::scrollObject( const awt::Size& /*aOffset*/ )
523     throw ( embed::WrongStateException,
524             uno::RuntimeException )
525 {
526 }
527 
528 //--------------------------------------------------------------------
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 //--------------------------------------------------------------------
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 }
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 
624     sal_Bool            Connect() { return GetRealObject() != NULL; }
625 };
626 
627 // -----------------------------------------------------------------------------
628 
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 
638 SdrEmbedObjectLink::~SdrEmbedObjectLink()
639 {
640 }
641 
642 // -----------------------------------------------------------------------------
643 
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 
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 
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
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 
741 sdr::properties::BaseProperties* SdrOle2Obj::CreateObjectSpecificProperties()
742 {
743     return new sdr::properties::OleProperties(*this);
744 }
745 
746 //////////////////////////////////////////////////////////////////////////////
747 // DrawContact section
748 
749 sdr::contact::ViewContact* SdrOle2Obj::CreateObjectSpecificViewContact()
750 {
751     return new sdr::contact::ViewContactOfSdrOle2Obj(*this);
752 }
753 
754 // -----------------------------------------------------------------------------
755 
756 TYPEINIT1(SdrOle2Obj,SdrRectObj);
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 // -----------------------------------------------------------------------------
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     if( ImplIsMathObj( xObjRef.GetObject() ) )
786         SetClosedObj( false );
787 }
788 
789 // -----------------------------------------------------------------------------
790 
791 SdrOle2Obj::SdrOle2Obj( const svt::EmbeddedObjectRef& rNewObjRef, const XubString& rNewObjName, FASTBOOL bFrame_)
792     : xObjRef( rNewObjRef )
793     , m_bTypeAsked(false)
794     , m_bChart(false)
795 {
796     DBG_CTOR( SdrOle2Obj,NULL);
797     bInDestruction = sal_False;
798     mbSuppressSetVisAreaSize = false;
799     Init();
800 
801     mpImpl->aPersistName = rNewObjName;
802     bFrame=bFrame_;
803 
804     if ( xObjRef.is() && (xObjRef->getStatus( GetAspect() ) & embed::EmbedMisc::EMBED_NEVERRESIZE ) )
805         SetResizeProtect(sal_True);
806 
807     // #108759# For math objects, set closed state to transparent
808     if( ImplIsMathObj( xObjRef.GetObject() ) )
809         SetClosedObj( false );
810 }
811 
812 // -----------------------------------------------------------------------------
813 
814 SdrOle2Obj::SdrOle2Obj( const svt::EmbeddedObjectRef&  rNewObjRef, const XubString& rNewObjName, const Rectangle& rNewRect, FASTBOOL bFrame_)
815     : SdrRectObj(rNewRect)
816     , xObjRef( rNewObjRef )
817     , m_bTypeAsked(false)
818     , m_bChart(false)
819 {
820     DBG_CTOR( SdrOle2Obj,NULL);
821     bInDestruction = sal_False;
822     mbSuppressSetVisAreaSize = false;
823     Init();
824 
825     mpImpl->aPersistName = rNewObjName;
826     bFrame=bFrame_;
827 
828     if ( xObjRef.is() && (xObjRef->getStatus( GetAspect() ) & embed::EmbedMisc::EMBED_NEVERRESIZE ) )
829         SetResizeProtect(sal_True);
830 
831     // #108759# For math objects, set closed state to transparent
832     if( ImplIsMathObj( xObjRef.GetObject() ) )
833         SetClosedObj( false );
834 }
835 
836 // -----------------------------------------------------------------------------
837 
838 void SdrOle2Obj::Init()
839 {
840     mpImpl = new SdrOle2ObjImpl;
841     pModifyListener = NULL;
842     pGraphic=NULL;
843     mpImpl->pGraphicObject=NULL;
844     mpImpl->pLightClient = 0;
845 
846     xObjRef.Lock( sal_True );
847 }
848 
849 // -----------------------------------------------------------------------------
850 
851 SdrOle2Obj::~SdrOle2Obj()
852 {
853     DBG_DTOR( SdrOle2Obj,NULL);
854     bInDestruction = sal_True;
855 
856     if ( mpImpl->mbConnected )
857         Disconnect();
858 
859     if( pGraphic!=NULL )
860         delete pGraphic;
861 
862     if(mpImpl->pGraphicObject!=NULL)
863         delete mpImpl->pGraphicObject;
864 
865     if(pModifyListener)
866     {
867         pModifyListener->invalidate();
868         pModifyListener->release();
869     }
870 
871     DisconnectFileLink_Impl();
872 
873     if ( mpImpl->pLightClient )
874     {
875         mpImpl->pLightClient->Release();
876         mpImpl->pLightClient = NULL;
877     }
878 
879     delete mpImpl;
880 }
881 
882 // -----------------------------------------------------------------------------
883 void SdrOle2Obj::SetAspect( sal_Int64 nAspect )
884 {
885     xObjRef.SetViewAspect( nAspect );
886 }
887 
888 // -----------------------------------------------------------------------------
889 bool SdrOle2Obj::isInplaceActive() const
890 {
891     return xObjRef.is() && embed::EmbedStates::INPLACE_ACTIVE == xObjRef->getCurrentState();
892 }
893 
894 // -----------------------------------------------------------------------------
895 bool SdrOle2Obj::isUiActive() const
896 {
897     return xObjRef.is() && embed::EmbedStates::UI_ACTIVE == xObjRef->getCurrentState();
898 }
899 
900 // -----------------------------------------------------------------------------
901 
902 void SdrOle2Obj::SetGraphic_Impl(const Graphic* pGrf)
903 {
904     if ( pGraphic )
905     {
906         delete pGraphic;
907         pGraphic = NULL;
908         delete mpImpl->pGraphicObject;
909         mpImpl->pGraphicObject = NULL;
910     }
911 
912     if (pGrf!=NULL)
913     {
914         pGraphic = new Graphic(*pGrf);
915         mpImpl->pGraphicObject = new GraphicObject( *pGraphic );
916     }
917 
918     SetChanged();
919     BroadcastObjectChange();
920 
921     //if ( ppObjRef->Is() && pGrf )
922     //  BroadcastObjectChange();
923 }
924 
925 void SdrOle2Obj::SetGraphic(const Graphic* pGrf)
926 {
927     // only for setting a preview graphic
928     SetGraphic_Impl( pGrf );
929 }
930 
931 // -----------------------------------------------------------------------------
932 
933 FASTBOOL SdrOle2Obj::IsEmpty() const
934 {
935     return !(xObjRef.is());
936 }
937 
938 // -----------------------------------------------------------------------------
939 
940 void SdrOle2Obj::Connect()
941 {
942     if( IsEmptyPresObj() )
943         return;
944 
945     if( mpImpl->mbConnected )
946     {
947         // mba: currently there are situations where it seems to be unavoidable to have multiple connects
948         // changing this would need a larger code rewrite, so for now I remove the assertion
949         // DBG_ERROR("Connect() called on connected object!");
950         return;
951     }
952 
953     Connect_Impl();
954     AddListeners_Impl();
955 }
956 
957 // -----------------------------------------------------------------------------
958 
959 sal_Bool SdrOle2Obj::UpdateLinkURL_Impl()
960 {
961     sal_Bool bResult = sal_False;
962 
963     if ( mpImpl->mpObjectLink )
964     {
965         sfx2::LinkManager* pLinkManager = pModel ? pModel->GetLinkManager() : NULL;
966         if ( pLinkManager )
967         {
968             String aNewLinkURL;
969             pLinkManager->GetDisplayNames( mpImpl->mpObjectLink, 0, &aNewLinkURL, 0, 0 );
970             if ( !aNewLinkURL.EqualsIgnoreCaseAscii( mpImpl->maLinkURL ) )
971             {
972                 const_cast<SdrOle2Obj*>(this)->GetObjRef_Impl();
973                 uno::Reference< embed::XCommonEmbedPersist > xPersObj( xObjRef.GetObject(), uno::UNO_QUERY );
974                 OSL_ENSURE( xPersObj.is(), "The object must exist!\n" );
975                 if ( xPersObj.is() )
976                 {
977                     try
978                     {
979                         sal_Int32 nCurState = xObjRef->getCurrentState();
980                         if ( nCurState != embed::EmbedStates::LOADED )
981                             xObjRef->changeState( embed::EmbedStates::LOADED );
982 
983                         // TODO/LATER: there should be possible to get current mediadescriptor settings from the object
984                         uno::Sequence< beans::PropertyValue > aArgs( 1 );
985                         aArgs[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) );
986                         aArgs[0].Value <<= ::rtl::OUString( aNewLinkURL );
987                         xPersObj->reload( aArgs, uno::Sequence< beans::PropertyValue >() );
988 
989                         mpImpl->maLinkURL = aNewLinkURL;
990                         bResult = sal_True;
991 
992                         if ( nCurState != embed::EmbedStates::LOADED )
993                             xObjRef->changeState( nCurState );
994                     }
995                     catch( ::com::sun::star::uno::Exception& e )
996                     {
997                         (void)e;
998                         DBG_ERROR(
999                             (OString("SdrOle2Obj::UpdateLinkURL_Impl(), "
1000                                     "exception caught: ") +
1001                             rtl::OUStringToOString(
1002                                 comphelper::anyToString( cppu::getCaughtException() ),
1003                                 RTL_TEXTENCODING_UTF8 )).getStr() );
1004                     }
1005                 }
1006 
1007                 if ( !bResult )
1008                 {
1009                     // TODO/LATER: return the old name to the link manager, is it possible?
1010                 }
1011             }
1012         }
1013     }
1014 
1015     return bResult;
1016 }
1017 
1018 // -----------------------------------------------------------------------------
1019 
1020 void SdrOle2Obj::BreakFileLink_Impl()
1021 {
1022     uno::Reference<document::XStorageBasedDocument> xDoc;
1023     if ( pModel )
1024         xDoc.set( pModel->getUnoModel(),uno::UNO_QUERY);
1025 
1026     if ( xDoc.is() )
1027     {
1028         uno::Reference< embed::XStorage > xStorage = xDoc->getDocumentStorage();
1029         if ( xStorage.is() )
1030         {
1031             try
1032             {
1033                 uno::Reference< embed::XLinkageSupport > xLinkSupport( xObjRef.GetObject(), uno::UNO_QUERY_THROW );
1034                 xLinkSupport->breakLink( xStorage, mpImpl->aPersistName );
1035                 DisconnectFileLink_Impl();
1036                 mpImpl->maLinkURL = String();
1037             }
1038             catch( ::com::sun::star::uno::Exception& e )
1039             {
1040                 (void)e;
1041                 DBG_ERROR(
1042                     (OString("SdrOle2Obj::BreakFileLink_Impl(), "
1043                             "exception caught: ") +
1044                     rtl::OUStringToOString(
1045                         comphelper::anyToString( cppu::getCaughtException() ),
1046                         RTL_TEXTENCODING_UTF8 )).getStr() );
1047             }
1048         }
1049     }
1050 }
1051 
1052 // -----------------------------------------------------------------------------
1053 
1054 void SdrOle2Obj::DisconnectFileLink_Impl()
1055 {
1056     sfx2::LinkManager* pLinkManager = pModel ? pModel->GetLinkManager() : NULL;
1057     if ( pLinkManager && mpImpl->mpObjectLink )
1058     {
1059         pLinkManager->Remove( mpImpl->mpObjectLink );
1060         mpImpl->mpObjectLink = NULL;
1061     }
1062 }
1063 
1064 // -----------------------------------------------------------------------------
1065 
1066 void SdrOle2Obj::CheckFileLink_Impl()
1067 {
1068     if ( pModel && xObjRef.GetObject().is() && !mpImpl->mpObjectLink )
1069     {
1070         try
1071         {
1072             uno::Reference< embed::XLinkageSupport > xLinkSupport( xObjRef.GetObject(), uno::UNO_QUERY );
1073             if ( xLinkSupport.is() && xLinkSupport->isLink() )
1074             {
1075                 String aLinkURL = xLinkSupport->getLinkURL();
1076                 if ( aLinkURL.Len() )
1077                 {
1078                     // this is a file link so the model link manager should handle it
1079                     sfx2::LinkManager* pLinkManager = pModel->GetLinkManager();
1080                     if ( pLinkManager )
1081                     {
1082                         mpImpl->mpObjectLink = new SdrEmbedObjectLink( this );
1083                         mpImpl->maLinkURL = aLinkURL;
1084                         pLinkManager->InsertFileLink( *mpImpl->mpObjectLink, OBJECT_CLIENT_OLE, aLinkURL, NULL, NULL );
1085                         mpImpl->mpObjectLink->Connect();
1086                     }
1087                 }
1088             }
1089         }
1090         catch( ::com::sun::star::uno::Exception& e )
1091         {
1092             (void)e;
1093             DBG_ERROR(
1094                 (OString("SdrOle2Obj::CheckFileLink_Impl(), "
1095                         "exception caught: ") +
1096                 rtl::OUStringToOString(
1097                     comphelper::anyToString( cppu::getCaughtException() ),
1098                     RTL_TEXTENCODING_UTF8 )).getStr() );
1099         }
1100     }
1101 }
1102 
1103 // -----------------------------------------------------------------------------
1104 
1105 void SdrOle2Obj::Reconnect_Impl()
1106 {
1107     DBG_ASSERT( mpImpl->mbConnected, "Assigned unconnected object?!" );
1108     Connect_Impl();
1109 }
1110 
1111 void SdrOle2Obj::Connect_Impl()
1112 {
1113     if( pModel && mpImpl->aPersistName.Len() )
1114     {
1115         try
1116         {
1117             ::comphelper::IEmbeddedHelper* pPers = pModel->GetPersist();
1118             if ( pPers )
1119             {
1120                 comphelper::EmbeddedObjectContainer& rContainer = pPers->getEmbeddedObjectContainer();
1121                 if ( !rContainer.HasEmbeddedObject( mpImpl->aPersistName )
1122                   || ( xObjRef.is() && !rContainer.HasEmbeddedObject( xObjRef.GetObject() ) ) )
1123                 {
1124                     // object not known to container document
1125                     // No object -> disaster!
1126                     DBG_ASSERT( xObjRef.is(), "No object in connect!");
1127                     if ( xObjRef.is() )
1128                     {
1129                         // object came from the outside, now add it to the container
1130                         ::rtl::OUString aTmp;
1131                         rContainer.InsertEmbeddedObject( xObjRef.GetObject(), aTmp );
1132                         mpImpl->aPersistName = aTmp;
1133                     }
1134                 }
1135                 else if ( !xObjRef.is() )
1136                 {
1137                     xObjRef.Assign( rContainer.GetEmbeddedObject( mpImpl->aPersistName ), xObjRef.GetViewAspect() );
1138                     m_bTypeAsked = false;
1139                 }
1140 
1141                 if ( xObjRef.GetObject().is() )
1142                 {
1143                     xObjRef.AssignToContainer( &rContainer, mpImpl->aPersistName );
1144                     mpImpl->mbConnected = true;
1145                     xObjRef.Lock( sal_True );
1146                 }
1147             }
1148 
1149             if ( xObjRef.is() )
1150             {
1151                 if ( !mpImpl->pLightClient )
1152                 {
1153                     mpImpl->pLightClient = new SdrLightEmbeddedClient_Impl( this );
1154                     mpImpl->pLightClient->acquire();
1155                 }
1156 
1157                 xObjRef->addStateChangeListener( mpImpl->pLightClient );
1158                 xObjRef->addEventListener( uno::Reference< document::XEventListener >( mpImpl->pLightClient ) );
1159 
1160                 if ( xObjRef->getCurrentState() != embed::EmbedStates::LOADED )
1161                     GetSdrGlobalData().GetOLEObjCache().InsertObj(this);
1162 
1163                 CheckFileLink_Impl();
1164 
1165                 uno::Reference< container::XChild > xChild( xObjRef.GetObject(), uno::UNO_QUERY );
1166                 if( xChild.is() )
1167                 {
1168                     uno::Reference< uno::XInterface > xParent( pModel->getUnoModel());
1169                     if( xParent.is())
1170                         xChild->setParent( pModel->getUnoModel() );
1171                 }
1172 
1173             }
1174         }
1175         catch( ::com::sun::star::uno::Exception& e )
1176         {
1177             (void)e;
1178             DBG_ERROR(
1179                 (OString("SdrOle2Obj::Connect_Impl(), "
1180                         "exception caught: ") +
1181                 rtl::OUStringToOString(
1182                     comphelper::anyToString( cppu::getCaughtException() ),
1183                     RTL_TEXTENCODING_UTF8 )).getStr() );
1184         }
1185     }
1186 
1187     //TODO/LATER: wait for definition of MiscStatus RESIZEONPRINTERCHANGE
1188     //if ( xObjRef.is() && (*ppObjRef)->GetMiscStatus() & SVOBJ_MISCSTATUS_RESIZEONPRINTERCHANGE )
1189     {
1190         //TODO/LATER: needs a new handling for OnPrinterChanged
1191         /*
1192         if (pModel && pModel->GetRefDevice() &&
1193             pModel->GetRefDevice()->GetOutDevType() == OUTDEV_PRINTER)
1194         {
1195             // Kein RefDevice oder RefDevice kein Printer
1196             sal_Bool bModified = (*ppObjRef)->IsModified();
1197             Printer* pPrinter = (Printer*) pModel->GetRefDevice();
1198             (*ppObjRef)->OnDocumentPrinterChanged( pPrinter );
1199             (*ppObjRef)->SetModified( bModified );
1200         }*/
1201     }
1202 }
1203 
1204 void SdrOle2Obj::ObjectLoaded()
1205 {
1206     AddListeners_Impl();
1207 }
1208 
1209 void SdrOle2Obj::AddListeners_Impl()
1210 {
1211     if( xObjRef.is() && xObjRef->getCurrentState() != embed::EmbedStates::LOADED )
1212     {
1213         // register modify listener
1214         if( !pModifyListener )
1215         {
1216             ((SdrOle2Obj*)this)->pModifyListener = new SvxUnoShapeModifyListener( (SdrOle2Obj*)this );
1217             pModifyListener->acquire();
1218         }
1219 
1220         uno::Reference< util::XModifyBroadcaster > xBC( getXModel(), uno::UNO_QUERY );
1221         if( xBC.is() && pModifyListener )
1222         {
1223             uno::Reference< util::XModifyListener > xListener( pModifyListener );
1224             xBC->addModifyListener( xListener );
1225         }
1226     }
1227 }
1228 
1229 // -----------------------------------------------------------------------------
1230 
1231 void SdrOle2Obj::Disconnect()
1232 {
1233     if( IsEmptyPresObj() )
1234         return;
1235 
1236     if( !mpImpl->mbConnected )
1237     {
1238         DBG_ERROR("Disconnect() called on disconnected object!");
1239         return;
1240     }
1241 
1242     RemoveListeners_Impl();
1243     Disconnect_Impl();
1244 }
1245 
1246 void SdrOle2Obj::RemoveListeners_Impl()
1247 {
1248     if( xObjRef.is() && mpImpl->aPersistName.Len() )
1249     {
1250         try
1251         {
1252             sal_Int32 nState = xObjRef->getCurrentState();
1253             if ( nState != embed::EmbedStates::LOADED )
1254             {
1255                 uno::Reference< util::XModifyBroadcaster > xBC( getXModel(), uno::UNO_QUERY );
1256                 if( xBC.is() && pModifyListener )
1257                 {
1258                     uno::Reference< util::XModifyListener > xListener( pModifyListener );
1259                     xBC->removeModifyListener( xListener );
1260                 }
1261             }
1262         }
1263         catch( ::com::sun::star::uno::Exception& e )
1264         {
1265             (void)e;
1266             DBG_ERROR(
1267                 (OString("SdrOle2Obj::RemoveListeners_Impl(), "
1268                         "exception caught: ") +
1269                 rtl::OUStringToOString(
1270                     comphelper::anyToString( cppu::getCaughtException() ),
1271                     RTL_TEXTENCODING_UTF8 )).getStr() );
1272         }
1273     }
1274 }
1275 
1276 void SdrOle2Obj::Disconnect_Impl()
1277 {
1278     try
1279     {
1280         if ( pModel && mpImpl->aPersistName.Len() )
1281         {
1282             if( pModel->IsInDestruction() )
1283             {
1284                 // TODO/LATER: here we must assume that the destruction of the model is enough to make clear that we will not
1285                 // remove the object from the container, even if the DrawingObject itself is not destroyed (unfortunately this
1286                 // There is no real need to do the following removing of the object from the container
1287                 // in case the model has correct persistance, but in case of problems such a removing
1288                 // would make the behaviour of the office more stable
1289 
1290                 comphelper::EmbeddedObjectContainer* pContainer = xObjRef.GetContainer();
1291                 if ( pContainer )
1292                 {
1293                     pContainer->CloseEmbeddedObject( xObjRef.GetObject() );
1294                     xObjRef.AssignToContainer( NULL, mpImpl->aPersistName );
1295                 }
1296 
1297                 // happens later than the destruction of the model, so we can't assert that).
1298                 //DBG_ASSERT( bInDestruction, "Model is destroyed, but not me?!" );
1299                 //TODO/LATER: should be make sure that the ObjectShell also forgets the object, because we will close it soon?
1300                 /*
1301                 uno::Reference < util::XCloseable > xClose( xObjRef, uno::UNO_QUERY );
1302                 if ( xClose.is() )
1303                 {
1304                     try
1305                     {
1306                         xClose->close( sal_True );
1307                     }
1308                     catch ( util::CloseVetoException& )
1309                     {
1310                         // there's still someone who needs the object!
1311                     }
1312                 }
1313 
1314                 xObjRef = NULL;*/
1315             }
1316             else if ( xObjRef.is() )
1317             {
1318                 if ( pModel->getUnoModel().is() )
1319                 {
1320                     // remove object, but don't close it (that's up to someone else)
1321                     comphelper::EmbeddedObjectContainer* pContainer = xObjRef.GetContainer();
1322                     if ( pContainer )
1323                     {
1324                         pContainer->RemoveEmbeddedObject( xObjRef.GetObject(), sal_False);
1325 
1326                         // TODO/LATER: mpImpl->aPersistName contains outdated information, to have it uptodate
1327                         // it should be returned from RemoveEmbeddedObject call. Currently it is no problem,
1328                         // since no container is adjusted, actually the empty string could be provided as a name here
1329                         xObjRef.AssignToContainer( NULL, mpImpl->aPersistName );
1330                     }
1331 
1332                     DisconnectFileLink_Impl();
1333                 }
1334             }
1335         }
1336 
1337         if ( xObjRef.is() && mpImpl->pLightClient )
1338         {
1339             xObjRef->removeStateChangeListener ( mpImpl->pLightClient );
1340             xObjRef->removeEventListener( uno::Reference< document::XEventListener >( mpImpl->pLightClient ) );
1341             xObjRef->setClientSite( NULL );
1342 
1343             GetSdrGlobalData().GetOLEObjCache().RemoveObj(this);
1344         }
1345     }
1346     catch( ::com::sun::star::uno::Exception& e )
1347     {
1348         (void)e;
1349         DBG_ERROR(
1350             (OString("SdrOle2Obj::Disconnect_Impl(), "
1351                     "exception caught: ") +
1352             rtl::OUStringToOString(
1353                 comphelper::anyToString( cppu::getCaughtException() ),
1354                 RTL_TEXTENCODING_UTF8 )).getStr() );
1355     }
1356 
1357     mpImpl->mbConnected = false;
1358 }
1359 
1360 // -----------------------------------------------------------------------------
1361 
1362 SdrObject* SdrOle2Obj::createSdrGrafObjReplacement(bool bAddText, bool bUseHCGraphic) const
1363 {
1364     Graphic* pOLEGraphic = GetGraphic();
1365 
1366     if(bUseHCGraphic && Application::GetSettings().GetStyleSettings().GetHighContrastMode())
1367     {
1368         pOLEGraphic = getEmbeddedObjectRef().GetHCGraphic();
1369     }
1370 
1371     if(pOLEGraphic)
1372     {
1373         // #i118485# allow creating a SdrGrafObj representation
1374         SdrGrafObj* pClone = new SdrGrafObj(*pOLEGraphic);
1375         pClone->SetModel(GetModel());
1376 
1377         // copy transformation
1378         basegfx::B2DHomMatrix aMatrix;
1379         basegfx::B2DPolyPolygon aPolyPolygon;
1380 
1381         TRGetBaseGeometry(aMatrix, aPolyPolygon);
1382         pClone->TRSetBaseGeometry(aMatrix, aPolyPolygon);
1383 
1384         // copy all attributes to support graphic styles for OLEs
1385         pClone->SetStyleSheet(GetStyleSheet(), false);
1386         pClone->SetMergedItemSet(GetMergedItemSet());
1387 
1388         if(bAddText)
1389         {
1390             // #i118485# copy text (Caution! Model needed, as guaranteed in aw080)
1391             OutlinerParaObject* pOPO = GetOutlinerParaObject();
1392 
1393             if(pOPO && GetModel())
1394             {
1395                 pClone->NbcSetOutlinerParaObject(new OutlinerParaObject(*pOPO));
1396             }
1397         }
1398 
1399         return pClone;
1400     }
1401     else
1402     {
1403         // #i100710# pOLEGraphic may be zero (no visualisation available),
1404         // so we need to use the OLE replacement graphic
1405         SdrRectObj* pClone = new SdrRectObj(GetSnapRect());
1406         pClone->SetModel(GetModel());
1407 
1408         // gray outline
1409         pClone->SetMergedItem(XLineStyleItem(XLINE_SOLID));
1410         const svtools::ColorConfig aColorConfig;
1411         const svtools::ColorConfigValue aColor(aColorConfig.GetColorValue(svtools::OBJECTBOUNDARIES));
1412         pClone->SetMergedItem(XLineColorItem(String(), aColor.nColor));
1413 
1414         // bitmap fill
1415         pClone->SetMergedItem(XFillStyleItem(XFILL_BITMAP));
1416         pClone->SetMergedItem(XFillBitmapItem(String(), Graphic(GetEmtyOLEReplacementBitmap())));
1417         pClone->SetMergedItem(XFillBmpTileItem(false));
1418         pClone->SetMergedItem(XFillBmpStretchItem(false));
1419 
1420         return pClone;
1421     }
1422 }
1423 
1424 SdrObject* SdrOle2Obj::DoConvertToPolyObj(sal_Bool bBezier, bool bAddText) const
1425 {
1426     // #i118485# missing converter added
1427     if(GetModel())
1428     {
1429         SdrObject* pRetval = createSdrGrafObjReplacement(true, false);
1430 
1431         if(pRetval)
1432         {
1433             SdrObject* pRetval2 = pRetval->DoConvertToPolyObj(bBezier, bAddText);
1434             SdrObject::Free(pRetval);
1435 
1436             return pRetval2;
1437         }
1438     }
1439 
1440     return 0;
1441 }
1442 
1443 // -----------------------------------------------------------------------------
1444 
1445 void SdrOle2Obj::SetModel(SdrModel* pNewModel)
1446 {
1447     ::comphelper::IEmbeddedHelper* pDestPers = pNewModel ? pNewModel->GetPersist() : 0;
1448     ::comphelper::IEmbeddedHelper* pSrcPers  = pModel ? pModel->GetPersist() : 0;
1449 
1450     if ( pNewModel == pModel )
1451     {
1452         // don't know if this is necessary or if it will ever happen, but who know?!
1453         SdrRectObj::SetModel( pNewModel );
1454         return;
1455     }
1456 
1457     // assignment to model has changed
1458     DBG_ASSERT( pSrcPers || !mpImpl->mbConnected, "Connected object without a model?!" );
1459 
1460     DBG_ASSERT( pDestPers, "The destination model must have a persistence! Please submit an issue!" );
1461     DBG_ASSERT( pDestPers != pSrcPers, "The source and the destination models should have different persistences! Problems are possible!" );
1462 
1463     // this is a bug if the target model has no persistence
1464     // no error handling is possible so just do nothing in this method
1465     if ( !pDestPers )
1466         return;
1467 
1468     RemoveListeners_Impl();
1469 
1470     if( pDestPers && pSrcPers && !IsEmptyPresObj() )
1471     {
1472         try
1473         {
1474             // move the objects' storage; ObjectRef remains the same, but PersistName may change
1475             ::rtl::OUString aTmp;
1476             comphelper::EmbeddedObjectContainer& rContainer = pSrcPers->getEmbeddedObjectContainer();
1477             uno::Reference < embed::XEmbeddedObject > xObj = rContainer.GetEmbeddedObject( mpImpl->aPersistName );
1478             DBG_ASSERT( !xObjRef.is() || xObjRef.GetObject() == xObj, "Wrong object identity!" );
1479             if ( xObj.is() )
1480             {
1481                 pDestPers->getEmbeddedObjectContainer().MoveEmbeddedObject( rContainer, xObj, aTmp );
1482                 mpImpl->aPersistName = aTmp;
1483                 xObjRef.AssignToContainer( &pDestPers->getEmbeddedObjectContainer(), aTmp );
1484             }
1485             DBG_ASSERT( aTmp.getLength(), "Copying embedded object failed!" );
1486         }
1487         catch( ::com::sun::star::uno::Exception& e )
1488         {
1489             (void)e;
1490             DBG_ERROR(
1491                 (OString("SdrOle2Obj::SetModel(), "
1492                         "exception caught: ") +
1493                 rtl::OUStringToOString(
1494                     comphelper::anyToString( cppu::getCaughtException() ),
1495                     RTL_TEXTENCODING_UTF8 )).getStr() );
1496         }
1497     }
1498 
1499     SdrRectObj::SetModel( pNewModel );
1500 
1501     // #i43086#
1502     // #i85304 redo the change for charts for the above bugfix, as #i43086# does not ocur anymore
1503     //so maybe the ImpSetVisAreaSize call can be removed here completely
1504     //Nevertheless I leave it in for other objects as I am not sure about the side effects when removing now
1505     if( pModel && !pModel->isLocked() && !IsChart() )
1506         ImpSetVisAreaSize();
1507 
1508     if( pDestPers && !IsEmptyPresObj() )
1509     {
1510         if ( !pSrcPers || IsEmptyPresObj() )
1511             // object wasn't connected, now it should
1512             Connect_Impl();
1513         else
1514             Reconnect_Impl();
1515     }
1516 
1517     AddListeners_Impl();
1518 }
1519 
1520 // -----------------------------------------------------------------------------
1521 
1522 void SdrOle2Obj::SetPage(SdrPage* pNewPage)
1523 {
1524     FASTBOOL bRemove=pNewPage==NULL && pPage!=NULL;
1525     FASTBOOL bInsert=pNewPage!=NULL && pPage==NULL;
1526 
1527     if (bRemove && mpImpl->mbConnected )
1528         Disconnect();
1529 
1530     if(!pModel && !GetStyleSheet() && pNewPage->GetModel())
1531     {
1532         // #119287# Set default StyleSheet for SdrGrafObj here, it is different from 'Default'. This
1533         // needs to be done before the style 'Default' is set from the :SetModel() call which is triggered
1534         // from the following :SetPage().
1535         // TTTT: Needs to be moved in branch aw080 due to having a SdrModel from the beginning, is at this
1536         // place for convenience currently (works in both versions, is not in the way)
1537         SfxStyleSheet* pSheet = pNewPage->GetModel()->GetDefaultStyleSheetForSdrGrafObjAndSdrOle2Obj();
1538 
1539         if(pSheet)
1540         {
1541             SetStyleSheet(pSheet, false);
1542         }
1543         else
1544         {
1545             SetMergedItem(XFillStyleItem(XFILL_NONE));
1546             SetMergedItem(XLineStyleItem(XLINE_NONE));
1547         }
1548     }
1549 
1550     SdrRectObj::SetPage(pNewPage);
1551 
1552     if (bInsert && !mpImpl->mbConnected )
1553         Connect();
1554 }
1555 
1556 // -----------------------------------------------------------------------------
1557 
1558 void SdrOle2Obj::SetObjRef( const com::sun::star::uno::Reference < com::sun::star::embed::XEmbeddedObject >& rNewObjRef )
1559 {
1560     DBG_ASSERT( !rNewObjRef.is() || !xObjRef.GetObject().is(), "SetObjRef called on already initialized object!");
1561     if( rNewObjRef == xObjRef.GetObject() )
1562         return;
1563 
1564     // MBA: the caller of the method is responsible to control the old object, it will not be closed here
1565     // Otherwise WW8 import crashes because it tranfers control to OLENode by this method
1566     if ( xObjRef.GetObject().is() )
1567         xObjRef.Lock( sal_False );
1568 
1569     // MBA: avoid removal of object in Disconnect! It is definitely a HACK to call SetObjRef(0)!
1570     // This call will try to close the objects; so if anybody else wants to keep it, it must be locked by a CloseListener
1571     xObjRef.Clear();
1572 
1573     if ( mpImpl->mbConnected )
1574         Disconnect();
1575 
1576     xObjRef.Assign( rNewObjRef, GetAspect() );
1577     m_bTypeAsked = false;
1578 
1579     if ( xObjRef.is() )
1580     {
1581         DELETEZ( pGraphic );
1582 
1583         if ( (xObjRef->getStatus( GetAspect() ) & embed::EmbedMisc::EMBED_NEVERRESIZE ) )
1584             SetResizeProtect(sal_True);
1585 
1586         // #108759# For math objects, set closed state to transparent
1587         if( ImplIsMathObj( rNewObjRef ) )
1588             SetClosedObj( false );
1589 
1590         Connect();
1591     }
1592 
1593     SetChanged();
1594     BroadcastObjectChange();
1595 }
1596 
1597 // -----------------------------------------------------------------------------
1598 
1599 void SdrOle2Obj::SetClosedObj( bool bIsClosed )
1600 {
1601     // TODO/LATER: do we still need this hack?
1602     // #108759# Allow changes to the closed state of OLE objects
1603     bClosedObj = bIsClosed;
1604 }
1605 
1606 // -----------------------------------------------------------------------------
1607 
1608 SdrObject* SdrOle2Obj::getFullDragClone() const
1609 {
1610     // special handling for OLE. The default handling works, but is too
1611     // slow when the whole OLE needs to be cloned. Get the Metafile and
1612     // create a graphic object with it
1613 
1614     // #i118485# use central replacement generator
1615     return createSdrGrafObjReplacement(false, true);
1616 }
1617 
1618 // -----------------------------------------------------------------------------
1619 
1620 void SdrOle2Obj::SetPersistName( const String& rPersistName )
1621 {
1622     DBG_ASSERT( !mpImpl->aPersistName.Len(), "Persist name changed!");
1623 
1624     mpImpl->aPersistName = rPersistName;
1625     mpImpl->mbLoadingOLEObjectFailed = false;
1626 
1627     Connect();
1628     SetChanged();
1629 }
1630 
1631 void SdrOle2Obj::AbandonObject()
1632 {
1633     mpImpl->aPersistName.Erase();
1634     mpImpl->mbLoadingOLEObjectFailed = false;
1635     SetObjRef(0);
1636 }
1637 
1638 // -----------------------------------------------------------------------------
1639 
1640 String SdrOle2Obj::GetPersistName() const
1641 {
1642     return mpImpl->aPersistName;
1643 }
1644 
1645 // -----------------------------------------------------------------------------
1646 
1647 void SdrOle2Obj::TakeObjInfo(SdrObjTransformInfoRec& rInfo) const
1648 {
1649     // #i118485# Allowing much more attributes for OLEs
1650     rInfo.bRotateFreeAllowed = true;
1651     rInfo.bRotate90Allowed = true;
1652     rInfo.bMirrorFreeAllowed = true;
1653     rInfo.bMirror45Allowed = true;
1654     rInfo.bMirror90Allowed = true;
1655     rInfo.bTransparenceAllowed = true;
1656     rInfo.bGradientAllowed = true;
1657     rInfo.bShearAllowed = true;
1658     rInfo.bEdgeRadiusAllowed = false;
1659     rInfo.bNoOrthoDesired = false;
1660     rInfo.bCanConvToPath = true;
1661     rInfo.bCanConvToPoly = true;
1662     rInfo.bCanConvToPathLineToArea = false;
1663     rInfo.bCanConvToPolyLineToArea = false;
1664     rInfo.bCanConvToContour = true;
1665 }
1666 
1667 // -----------------------------------------------------------------------------
1668 
1669 sal_uInt16 SdrOle2Obj::GetObjIdentifier() const
1670 {
1671     return bFrame ? sal_uInt16(OBJ_FRAME) : sal_uInt16(OBJ_OLE2);
1672 }
1673 
1674 // -----------------------------------------------------------------------------
1675 
1676 void SdrOle2Obj::TakeObjNameSingul(XubString& rName) const
1677 {
1678     rName = ImpGetResStr(bFrame ? STR_ObjNameSingulFrame : STR_ObjNameSingulOLE2);
1679 
1680     const String aName(GetName());
1681 
1682     if( aName.Len() )
1683     {
1684         rName.AppendAscii(" '");
1685         rName += aName;
1686         rName += sal_Unicode('\'');
1687     }
1688 }
1689 
1690 // -----------------------------------------------------------------------------
1691 
1692 void SdrOle2Obj::TakeObjNamePlural(XubString& rName) const
1693 {
1694     rName=ImpGetResStr(bFrame ? STR_ObjNamePluralFrame : STR_ObjNamePluralOLE2);
1695 }
1696 
1697 // -----------------------------------------------------------------------------
1698 
1699 void SdrOle2Obj::operator=(const SdrObject& rObj)
1700 {
1701     //TODO/LATER: who takes over control of my old object?!
1702     if( &rObj != this )
1703     {
1704         // #116235#
1705         // ImpAssign( rObj );
1706         const SdrOle2Obj& rOle2Obj = static_cast< const SdrOle2Obj& >( rObj );
1707 
1708         uno::Reference < util::XCloseable > xClose( xObjRef.GetObject(), uno::UNO_QUERY );
1709 
1710         if( pModel && mpImpl->mbConnected )
1711             Disconnect();
1712 
1713         SdrRectObj::operator=( rObj );
1714 
1715         // #108867# Manually copying bClosedObj attribute
1716         SetClosedObj( rObj.IsClosedObj() );
1717 
1718         mpImpl->aPersistName = rOle2Obj.mpImpl->aPersistName;
1719         aProgName = rOle2Obj.aProgName;
1720         bFrame = rOle2Obj.bFrame;
1721 
1722         if( rOle2Obj.pGraphic )
1723         {
1724             if( pGraphic )
1725             {
1726                 delete pGraphic;
1727                 delete mpImpl->pGraphicObject;
1728             }
1729 
1730             pGraphic = new Graphic( *rOle2Obj.pGraphic );
1731             mpImpl->pGraphicObject = new GraphicObject( *pGraphic );
1732         }
1733 
1734         if( pModel && rObj.GetModel() && !IsEmptyPresObj() )
1735         {
1736             ::comphelper::IEmbeddedHelper* pDestPers = pModel->GetPersist();
1737             ::comphelper::IEmbeddedHelper* pSrcPers = rObj.GetModel()->GetPersist();
1738             if( pDestPers && pSrcPers )
1739             {
1740                 DBG_ASSERT( !xObjRef.is(), "Object already existing!" );
1741                 comphelper::EmbeddedObjectContainer& rContainer = pSrcPers->getEmbeddedObjectContainer();
1742                 uno::Reference < embed::XEmbeddedObject > xObj = rContainer.GetEmbeddedObject( mpImpl->aPersistName );
1743                 if ( xObj.is() )
1744                 {
1745                     ::rtl::OUString aTmp;
1746                     xObjRef.Assign( pDestPers->getEmbeddedObjectContainer().CopyAndGetEmbeddedObject( rContainer, xObj, aTmp ), rOle2Obj.GetAspect() );
1747                     m_bTypeAsked = false;
1748                     mpImpl->aPersistName = aTmp;
1749                     CheckFileLink_Impl();
1750                 }
1751 
1752                 Connect();
1753 
1754                 /* only needed for MSOLE-Objects, now handled inside implementation of Object
1755                 if ( xObjRef.is() && rOle2Obj.xObjRef.is() && rOle2Obj.GetAspect() != embed::Aspects::MSOLE_ICON )
1756                 {
1757                     try
1758                     {
1759                         awt::Size aVisSize = rOle2Obj.xObjRef->getVisualAreaSize( rOle2Obj.GetAspect() );
1760                         if( rOle2Obj.xObjRef->getMapUnit( rOle2Obj.GetAspect() ) == xObjRef->getMapUnit( GetAspect() ) )
1761                         xObjRef->setVisualAreaSize( GetAspect(), aVisSize );
1762                     }
1763                     catch ( embed::WrongStateException& )
1764                     {
1765                         // setting of VisArea not necessary for objects that don't cache it in loaded state
1766                     }
1767                     catch( embed::NoVisualAreaSizeException& )
1768                     {
1769                         // objects my not have visual areas
1770                     }
1771                     catch( uno::Exception& e )
1772                     {
1773                         (void)e;
1774                         DBG_ERROR( "SdrOle2Obj::operator=(), unexcpected exception caught!" );
1775                     }
1776                 }                                                                            */
1777             }
1778         }
1779     }
1780 }
1781 
1782 // -----------------------------------------------------------------------------
1783 
1784 void SdrOle2Obj::ImpSetVisAreaSize()
1785 {
1786     // #i118524# do not again set VisAreaSize when the call comes from OLE client (e.g. ObjectAreaChanged)
1787     if(mbSuppressSetVisAreaSize)
1788         return;
1789 
1790     // currently there is no need to recalculate scaling for iconified objects
1791     // TODO/LATER: it might be needed in future when it is possible to change the icon
1792     if ( GetAspect() == embed::Aspects::MSOLE_ICON )
1793         return;
1794 
1795     // the object area of an embedded object was changed, e.g. by user interaction an a selected object
1796     GetObjRef();
1797     if ( xObjRef.is() )
1798     {
1799         OSL_ASSERT( pModel );
1800         sal_Int64 nMiscStatus = xObjRef->getStatus( GetAspect() );
1801 
1802         // the client is required to get access to scaling
1803         SfxInPlaceClient* pClient = SfxInPlaceClient::GetClient( dynamic_cast<SfxObjectShell*>(pModel->GetPersist()), xObjRef.GetObject() );
1804         sal_Bool bHasOwnClient =
1805                         ( mpImpl->pLightClient
1806                         && xObjRef->getClientSite() == uno::Reference< embed::XEmbeddedClient >( mpImpl->pLightClient ) );
1807 
1808         if ( pClient || bHasOwnClient )
1809         {
1810             // TODO/LATER: IMHO we need to do similar things when object is UIActive or OutplaceActive?! (MBA)
1811             if ( ((nMiscStatus & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE) &&
1812                     svt::EmbeddedObjectRef::TryRunningState( xObjRef.GetObject() ))
1813                     || xObjRef->getCurrentState() == embed::EmbedStates::INPLACE_ACTIVE
1814                     )
1815             {
1816                 Fraction aScaleWidth;
1817                 Fraction aScaleHeight;
1818                 if ( pClient )
1819                 {
1820                     aScaleWidth = pClient->GetScaleWidth();
1821                     aScaleHeight = pClient->GetScaleHeight();
1822                 }
1823                 else
1824                 {
1825                     aScaleWidth = mpImpl->pLightClient->GetScaleWidth();
1826                     aScaleHeight = mpImpl->pLightClient->GetScaleHeight();
1827                 }
1828 
1829                 // The object wants to resize itself (f.e. Chart wants to recalculate the layout)
1830                 // or object is inplace active and so has a window that must be resized also
1831                 // In these cases the change in the object area size will be reflected in a change of the
1832                 // objects' visual area. The scaling will not change, but it might exist already and must
1833                 // be used in calculations
1834                 MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObjRef->getMapUnit( GetAspect() ) );
1835                 Size aVisSize( (long)( Fraction( aRect.GetWidth() ) / aScaleWidth ),
1836                                 (long)( Fraction( aRect.GetHeight() ) / aScaleHeight ) );
1837 
1838                 aVisSize = OutputDevice::LogicToLogic( aVisSize, pModel->GetScaleUnit(), aMapUnit);
1839                 awt::Size aSz;
1840                 aSz.Width = aVisSize.Width();
1841                 aSz.Height = aVisSize.Height();
1842                 xObjRef->setVisualAreaSize( GetAspect(), aSz );
1843 
1844                 try
1845                 {
1846                     aSz = xObjRef->getVisualAreaSize( GetAspect() );
1847                 }
1848                 catch( embed::NoVisualAreaSizeException& )
1849                 {}
1850 
1851                 Rectangle aAcceptedVisArea;
1852                 aAcceptedVisArea.SetSize( Size( (long)( Fraction( long( aSz.Width ) ) * aScaleWidth ),
1853                                                 (long)( Fraction( long( aSz.Height ) ) * aScaleHeight ) ) );
1854                 if (aVisSize != aAcceptedVisArea.GetSize())
1855                 {
1856                     // server changed VisArea to its liking and the VisArea is different than the suggested one
1857                     // store the new value as given by the object
1858                     MapUnit aNewMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObjRef->getMapUnit( GetAspect() ) );
1859                     aRect.SetSize(OutputDevice::LogicToLogic( aAcceptedVisArea.GetSize(), aNewMapUnit, pModel->GetScaleUnit()));
1860                 }
1861 
1862                 // make the new object area known to the client
1863                 // compared to the "else" branch aRect might have been changed by the object and no additional scaling was applied
1864                 // OJ: WHY this -> OSL_ASSERT( pClient );
1865                 if( pClient )
1866                     pClient->SetObjArea(aRect);
1867 
1868                 // we need a new replacement image as the object has resized itself
1869 
1870                 //#i79578# don't request a new replacement image for charts to often
1871                 //a chart sends a modified call to the framework if it was changed
1872                 //thus the replacement update is already handled there
1873                 if( !IsChart() )
1874                     xObjRef.UpdateReplacement();
1875             }
1876             else
1877             {
1878                 // The object isn't active and does not want to resize itself so the changed object area size
1879                 // will be reflected in a changed object scaling
1880                 Fraction aScaleWidth;
1881                 Fraction aScaleHeight;
1882                 Size aObjAreaSize;
1883                 if ( CalculateNewScaling( aScaleWidth, aScaleHeight, aObjAreaSize ) )
1884                 {
1885                     if ( pClient )
1886                     {
1887                         Rectangle aScaleRect(aRect.TopLeft(), aObjAreaSize);
1888                         pClient->SetObjAreaAndScale( aScaleRect, aScaleWidth, aScaleHeight);
1889                     }
1890                     else
1891                     {
1892                         mpImpl->pLightClient->SetSizeScale( aScaleWidth, aScaleHeight );
1893                     }
1894                 }
1895             }
1896         }
1897         else if( (nMiscStatus & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE) &&
1898             svt::EmbeddedObjectRef::TryRunningState( xObjRef.GetObject() ) )
1899         {
1900             //also handle not sfx based ole objects e.g. charts
1901             //#i83860# resizing charts in impress distorts fonts
1902             uno::Reference< embed::XVisualObject > xVisualObject( this->getXModel(), uno::UNO_QUERY );
1903             if( xVisualObject.is() )
1904             {
1905                 MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObjRef->getMapUnit( GetAspect() ) );
1906                 Point aTL( aRect.TopLeft() );
1907                 Point aBR( aRect.BottomRight() );
1908                 Point aTL2( OutputDevice::LogicToLogic( aTL, pModel->GetScaleUnit(), aMapUnit) );
1909                 Point aBR2( OutputDevice::LogicToLogic( aBR, pModel->GetScaleUnit(), aMapUnit) );
1910                 Rectangle aNewRect( aTL2, aBR2 );
1911                 xVisualObject->setVisualAreaSize( GetAspect(), awt::Size( aNewRect.GetWidth(), aNewRect.GetHeight() ) );
1912             }
1913         }
1914     }
1915 }
1916 
1917 // -----------------------------------------------------------------------------
1918 
1919 void SdrOle2Obj::NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact)
1920 {
1921     if( pModel && !pModel->isLocked() )
1922     {
1923         GetObjRef();
1924         if ( xObjRef.is() && ( xObjRef->getStatus( GetAspect() ) & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE ) )
1925         {
1926             // if the object needs recompose on resize
1927             // the client site should be created before the resize will take place
1928             // check whether there is no client site and create it if necessary
1929             AddOwnLightClient();
1930         }
1931     }
1932 
1933     SdrRectObj::NbcResize(rRef,xFact,yFact);
1934 
1935     if( pModel && !pModel->isLocked() )
1936         ImpSetVisAreaSize();
1937 }
1938 
1939 // -----------------------------------------------------------------------------
1940 
1941 void SdrOle2Obj::SetGeoData(const SdrObjGeoData& rGeo)
1942 {
1943     SdrRectObj::SetGeoData(rGeo);
1944 
1945     if( pModel && !pModel->isLocked() )
1946         ImpSetVisAreaSize();
1947 }
1948 
1949 // -----------------------------------------------------------------------------
1950 
1951 void SdrOle2Obj::NbcSetSnapRect(const Rectangle& rRect)
1952 {
1953     SdrRectObj::NbcSetSnapRect(rRect);
1954 
1955     if( pModel && !pModel->isLocked() )
1956         ImpSetVisAreaSize();
1957 
1958     if ( xObjRef.is() && IsChart() )
1959     {
1960         //#i103460# charts do not necessaryly have an own size within ODF files,
1961         //for this case they need to use the size settings from the surrounding frame,
1962         //which is made available with this method as there is no other way
1963         xObjRef.SetDefaultSizeForChart( Size( rRect.GetWidth(), rRect.GetHeight() ) );
1964     }
1965 }
1966 
1967 // -----------------------------------------------------------------------------
1968 
1969 void SdrOle2Obj::NbcSetLogicRect(const Rectangle& rRect)
1970 {
1971     SdrRectObj::NbcSetLogicRect(rRect);
1972 
1973     if( pModel && !pModel->isLocked() )
1974         ImpSetVisAreaSize();
1975 }
1976 
1977 Graphic* SdrOle2Obj::GetGraphic() const
1978 {
1979     if ( xObjRef.is() )
1980         return xObjRef.GetGraphic();
1981     return pGraphic;
1982 }
1983 
1984 void SdrOle2Obj::GetNewReplacement()
1985 {
1986     if ( xObjRef.is() )
1987         xObjRef.UpdateReplacement();
1988 }
1989 
1990 // -----------------------------------------------------------------------------
1991 
1992 Size SdrOle2Obj::GetOrigObjSize( MapMode* pTargetMapMode ) const
1993 {
1994     return xObjRef.GetSize( pTargetMapMode );
1995 }
1996 
1997 // -----------------------------------------------------------------------------
1998 
1999 void SdrOle2Obj::NbcMove(const Size& rSize)
2000 {
2001     SdrRectObj::NbcMove(rSize);
2002 
2003     if( pModel && !pModel->isLocked() )
2004         ImpSetVisAreaSize();
2005 }
2006 
2007 // -----------------------------------------------------------------------------
2008 
2009 sal_Bool SdrOle2Obj::CanUnloadRunningObj( const uno::Reference< embed::XEmbeddedObject >& xObj, sal_Int64 nAspect )
2010 {
2011     sal_Bool bResult = sal_False;
2012 
2013     sal_Int32 nState = xObj->getCurrentState();
2014     if ( nState == embed::EmbedStates::LOADED )
2015     {
2016         // the object is already unloaded
2017         bResult = sal_True;
2018     }
2019     else
2020     {
2021         uno::Reference < util::XModifiable > xModifiable( xObj->getComponent(), uno::UNO_QUERY );
2022         if ( !xModifiable.is() )
2023             bResult = sal_True;
2024         else
2025         {
2026             sal_Int64 nMiscStatus = xObj->getStatus( nAspect );
2027 
2028             if ( embed::EmbedMisc::MS_EMBED_ALWAYSRUN != ( nMiscStatus & embed::EmbedMisc::MS_EMBED_ALWAYSRUN ) &&
2029             embed::EmbedMisc::EMBED_ACTIVATEIMMEDIATELY != ( nMiscStatus & embed::EmbedMisc::EMBED_ACTIVATEIMMEDIATELY ) &&
2030             !( xModifiable.is() && xModifiable->isModified() ) &&
2031             !( nState == embed::EmbedStates::INPLACE_ACTIVE || nState == embed::EmbedStates::UI_ACTIVE || nState == embed::EmbedStates::ACTIVE ) )
2032             {
2033                 bResult = sal_True;
2034             }
2035         }
2036     }
2037 
2038     return bResult;
2039 }
2040 
2041 // -----------------------------------------------------------------------------
2042 
2043 sal_Bool SdrOle2Obj::Unload( const uno::Reference< embed::XEmbeddedObject >& xObj, sal_Int64 nAspect )
2044 {
2045     sal_Bool bResult = sal_False;
2046 
2047     if ( CanUnloadRunningObj( xObj, nAspect ) )
2048     {
2049         try
2050         {
2051             xObj->changeState( embed::EmbedStates::LOADED );
2052             bResult = sal_True;
2053         }
2054         catch( ::com::sun::star::uno::Exception& e )
2055         {
2056             (void)e;
2057             DBG_ERROR(
2058                 (OString("SdrOle2Obj::Unload=(), "
2059                         "exception caught: ") +
2060                 rtl::OUStringToOString(
2061                     comphelper::anyToString( cppu::getCaughtException() ),
2062                     RTL_TEXTENCODING_UTF8 )).getStr() );
2063         }
2064     }
2065 
2066     return bResult;
2067 }
2068 
2069 // -----------------------------------------------------------------------------
2070 
2071 sal_Bool SdrOle2Obj::Unload()
2072 {
2073     sal_Bool bUnloaded = sal_False;
2074 
2075     if( xObjRef.is() )
2076     {
2077         //TODO/LATER: no refcounting tricks anymore!
2078         //"customers" must register as state change listeners
2079         //Nicht notwendig im Doc DTor (MM)
2080         //sal_uIntPtr nRefCount = (*ppObjRef)->GetRefCount();
2081         // prevent Unload if there are external references
2082         //if( nRefCount > 2 )
2083         //    return sal_False;
2084         //DBG_ASSERT( nRefCount == 2, "Wrong RefCount for unload" );
2085     }
2086     else
2087         bUnloaded = sal_True;
2088 
2089     if ( pModel && xObjRef.is() )
2090     {
2091         bUnloaded = Unload( xObjRef.GetObject(), GetAspect() );
2092     }
2093 
2094     return bUnloaded;
2095 }
2096 
2097 // -----------------------------------------------------------------------------
2098 
2099 void SdrOle2Obj::GetObjRef_Impl()
2100 {
2101     if ( !xObjRef.is() && mpImpl->aPersistName.Len() && pModel && pModel->GetPersist() )
2102     {
2103         // #107645#
2104         // Only try loading if it did not went wrong up to now
2105         if(!mpImpl->mbLoadingOLEObjectFailed)
2106         {
2107             xObjRef.Assign( pModel->GetPersist()->getEmbeddedObjectContainer().GetEmbeddedObject( mpImpl->aPersistName ), GetAspect() );
2108             m_bTypeAsked = false;
2109             CheckFileLink_Impl();
2110 
2111             // #107645#
2112             // If loading of OLE object failed, remember that to not invoke a endless
2113             // loop trying to load it again and again.
2114             if( xObjRef.is() )
2115             {
2116                 mpImpl->mbLoadingOLEObjectFailed = sal_True;
2117             }
2118 
2119             // #108759# For math objects, set closed state to transparent
2120             if( ImplIsMathObj( xObjRef.GetObject() ) )
2121                 SetClosedObj( false );
2122         }
2123 
2124         if ( xObjRef.is() )
2125         {
2126             if( !IsEmptyPresObj() )
2127             {
2128                 // #75637# remember modified status of model
2129                 const sal_Bool bWasChanged(pModel ? pModel->IsChanged() : sal_False);
2130 
2131                 // perhaps preview not valid anymore
2132                 // #75637# This line changes the modified state of the model
2133                 SetGraphic_Impl( NULL );
2134 
2135                 // #75637# if status was not set before, force it back
2136                 // to not set, so that SetGraphic(0L) above does not
2137                 // set the modified state of the model.
2138                 if(!bWasChanged && pModel && pModel->IsChanged())
2139                 {
2140                     pModel->SetChanged( sal_False );
2141                 }
2142             }
2143 
2144             sal_Int64 nMiscStatus = xObjRef->getStatus( GetAspect() );
2145             (void)nMiscStatus;
2146             //TODO/LATER: wait until ResizeOnPrinterChange is defined
2147             //if ( nMiscStatus & SVOBJ_MISCSTATUS_RESIZEONPRINTERCHANGE )
2148             {
2149                 if (pModel && pModel->GetRefDevice() &&
2150                     pModel->GetRefDevice()->GetOutDevType() == OUTDEV_PRINTER)
2151                 {
2152                     if(!bInDestruction)
2153                     {
2154                         //TODO/LATER: printerchange notification
2155                         /*
2156                         // prevent SetModified (don't want no update here)
2157                         sal_Bool bWasEnabled = (*ppObjRef)->IsEnableSetModified();
2158                         if ( bWasEnabled )
2159                             (*ppObjRef)->EnableSetModified( sal_False );
2160 
2161                         // Kein RefDevice oder RefDevice kein Printer
2162                         Printer* pPrinter = (Printer*) pModel->GetRefDevice();
2163                         (*ppObjRef)->OnDocumentPrinterChanged( pPrinter );
2164 
2165                         // reset state
2166                         (*ppObjRef)->EnableSetModified( bWasEnabled );*/
2167                     }
2168                 }
2169             }
2170         }
2171 
2172         if ( xObjRef.is() )
2173             Connect();
2174     }
2175 
2176     if ( mpImpl->mbConnected )
2177         // move object to first position in cache
2178         GetSdrGlobalData().GetOLEObjCache().InsertObj(this);
2179 }
2180 
2181 uno::Reference < embed::XEmbeddedObject > SdrOle2Obj::GetObjRef() const
2182 {
2183     const_cast<SdrOle2Obj*>(this)->GetObjRef_Impl();
2184     return xObjRef.GetObject();
2185 }
2186 
2187 uno::Reference < embed::XEmbeddedObject > SdrOle2Obj::GetObjRef_NoInit() const
2188 {
2189     return xObjRef.GetObject();
2190 }
2191 
2192 // -----------------------------------------------------------------------------
2193 
2194 uno::Reference< frame::XModel > SdrOle2Obj::getXModel() const
2195 {
2196     GetObjRef();
2197     if ( svt::EmbeddedObjectRef::TryRunningState(xObjRef.GetObject()) )
2198         return uno::Reference< frame::XModel >( xObjRef->getComponent(), uno::UNO_QUERY );
2199     else
2200         return uno::Reference< frame::XModel >();
2201 }
2202 
2203 // -----------------------------------------------------------------------------
2204 
2205 // #109985#
2206 sal_Bool SdrOle2Obj::IsChart() const
2207 {
2208     if ( !m_bTypeAsked )
2209     {
2210         m_bChart = ChartHelper::IsChart(xObjRef);
2211         m_bTypeAsked = true;
2212     }
2213     return m_bChart;
2214 }
2215 
2216 // -----------------------------------------------------------------------------
2217 void SdrOle2Obj::SetGraphicToObj( const Graphic& aGraphic, const ::rtl::OUString& aMediaType )
2218 {
2219     xObjRef.SetGraphic( aGraphic, aMediaType );
2220 }
2221 
2222 // -----------------------------------------------------------------------------
2223 void SdrOle2Obj::SetGraphicToObj( const uno::Reference< io::XInputStream >& xGrStream, const ::rtl::OUString& aMediaType )
2224 {
2225     xObjRef.SetGraphicStream( xGrStream, aMediaType );
2226 }
2227 
2228 // -----------------------------------------------------------------------------
2229 sal_Bool SdrOle2Obj::IsCalc() const
2230 {
2231     if ( !xObjRef.is() )
2232         return false;
2233 
2234     SvGlobalName aObjClsId( xObjRef->getClassID() );
2235     if(    SvGlobalName(SO3_SC_CLASSID_30) == aObjClsId
2236         || SvGlobalName(SO3_SC_CLASSID_40) == aObjClsId
2237         || SvGlobalName(SO3_SC_CLASSID_50) == aObjClsId
2238         || SvGlobalName(SO3_SC_CLASSID_60) == aObjClsId
2239         || SvGlobalName(SO3_SC_OLE_EMBED_CLASSID_60) == aObjClsId
2240         || SvGlobalName(SO3_SC_OLE_EMBED_CLASSID_8) == aObjClsId
2241         || SvGlobalName(SO3_SC_CLASSID) == aObjClsId )
2242     {
2243         return sal_True;
2244     }
2245 
2246     return sal_False;
2247 }
2248 
2249 // -----------------------------------------------------------------------------
2250 uno::Reference< frame::XModel > SdrOle2Obj::GetParentXModel() const
2251 {
2252     uno::Reference< frame::XModel > xDoc;
2253     if ( pModel )
2254         xDoc.set( pModel->getUnoModel(),uno::UNO_QUERY);
2255     return xDoc;
2256 }
2257 
2258 // -----------------------------------------------------------------------------
2259 sal_Bool SdrOle2Obj::CalculateNewScaling( Fraction& aScaleWidth, Fraction& aScaleHeight, Size& aObjAreaSize )
2260 {
2261     // TODO/LEAN: to avoid rounding errors scaling always uses the VisArea.
2262     // If we don't cache it for own objects also we must load the object here
2263     if ( !xObjRef.is() || !pModel )
2264         return sal_False;
2265 
2266     MapMode aMapMode( pModel->GetScaleUnit() );
2267     aObjAreaSize = xObjRef.GetSize( &aMapMode );
2268 
2269     Size aSize = aRect.GetSize();
2270     aScaleWidth = Fraction(aSize.Width(),  aObjAreaSize.Width() );
2271     aScaleHeight = Fraction(aSize.Height(), aObjAreaSize.Height() );
2272 
2273     // reduce to 10 binary digits
2274     Kuerzen(aScaleHeight, 10);
2275     Kuerzen(aScaleWidth,  10);
2276 
2277     return sal_True;
2278 }
2279 
2280 // -----------------------------------------------------------------------------
2281 sal_Bool SdrOle2Obj::AddOwnLightClient()
2282 {
2283     // The Own Light Client must be registered in object only using this method!
2284     if ( !SfxInPlaceClient::GetClient( dynamic_cast<SfxObjectShell*>(pModel->GetPersist()), xObjRef.GetObject() )
2285       && !( mpImpl->pLightClient && xObjRef->getClientSite() == uno::Reference< embed::XEmbeddedClient >( mpImpl->pLightClient ) ) )
2286     {
2287         Connect();
2288 
2289         if ( xObjRef.is() && mpImpl->pLightClient )
2290         {
2291             Fraction aScaleWidth;
2292             Fraction aScaleHeight;
2293             Size aObjAreaSize;
2294             if ( CalculateNewScaling( aScaleWidth, aScaleHeight, aObjAreaSize ) )
2295             {
2296                 mpImpl->pLightClient->SetSizeScale( aScaleWidth, aScaleHeight );
2297                 try {
2298                     xObjRef->setClientSite( mpImpl->pLightClient );
2299                     return sal_True;
2300                 } catch( uno::Exception& )
2301                 {}
2302             }
2303 
2304         }
2305 
2306         return sal_False;
2307     }
2308 
2309     return sal_True;
2310 }
2311 
2312 //////////////////////////////////////////////////////////////////////////////
2313 
2314 Bitmap SdrOle2Obj::GetEmtyOLEReplacementBitmap()
2315 {
2316     return Bitmap(ResId(BMP_SVXOLEOBJ, *ImpGetResMgr()));
2317 }
2318 
2319 //////////////////////////////////////////////////////////////////////////////
2320 
2321 void SdrOle2Obj::SetWindow(const com::sun::star::uno::Reference < com::sun::star::awt::XWindow >& _xWindow)
2322 {
2323     if ( xObjRef.is() && mpImpl->pLightClient )
2324     {
2325         mpImpl->pLightClient->setWindow(_xWindow);
2326     }
2327 }
2328 
2329 //////////////////////////////////////////////////////////////////////////////
2330 // eof
2331