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

Generated by: LCOV version 1.10