LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/svx/source/svdraw - svdoole2.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 339 896 37.8 %
Date: 2013-07-09 Functions: 55 112 49.1 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10