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

Generated by: LCOV version 1.11