LCOV - code coverage report
Current view: top level - svx/source/svdraw - svdoole2.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 358 900 39.8 %
Date: 2014-04-11 Functions: 55 111 49.5 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10