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