LCOV - code coverage report
Current view: top level - sfx2/source/view - ipclient.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 198 431 45.9 %
Date: 2014-11-03 Functions: 42 60 70.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <com/sun/star/embed/EmbedStates.hpp>
      21             : #include <com/sun/star/embed/XVisualObject.hpp>
      22             : #include <com/sun/star/embed/XEmbeddedClient.hpp>
      23             : #include <com/sun/star/embed/XInplaceClient.hpp>
      24             : #include <com/sun/star/embed/XInplaceObject.hpp>
      25             : #include <com/sun/star/embed/XComponentSupplier.hpp>
      26             : #include <com/sun/star/embed/XWindowSupplier.hpp>
      27             : #include <com/sun/star/embed/XEmbedPersist.hpp>
      28             : #include <com/sun/star/embed/EmbedVerbs.hpp>
      29             : #include <com/sun/star/container/XChild.hpp>
      30             : #include <com/sun/star/beans/XPropertySet.hpp>
      31             : #include <com/sun/star/beans/PropertyValue.hpp>
      32             : #include <com/sun/star/embed/XStateChangeListener.hpp>
      33             : #include <com/sun/star/embed/StateChangeInProgressException.hpp>
      34             : #include <com/sun/star/embed/XLinkageSupport.hpp>
      35             : #include <com/sun/star/lang/XInitialization.hpp>
      36             : #include <com/sun/star/task/ErrorCodeIOException.hpp>
      37             : #include <com/sun/star/task/StatusIndicatorFactory.hpp>
      38             : #include <com/sun/star/task/XStatusIndicator.hpp>
      39             : 
      40             : #include <com/sun/star/embed/EmbedMisc.hpp>
      41             : #include <svtools/embedhlp.hxx>
      42             : #include <vcl/svapp.hxx>
      43             : 
      44             : #include <sfx2/ipclient.hxx>
      45             : #include <sfx2/viewsh.hxx>
      46             : #include <sfx2/viewfrm.hxx>
      47             : #include <sfx2/objsh.hxx>
      48             : #include <sfx2/dispatch.hxx>
      49             : #include "workwin.hxx"
      50             : #include "guisaveas.hxx"
      51             : #include <cppuhelper/implbase5.hxx>
      52             : #include <svtools/ehdl.hxx>
      53             : 
      54             : #include <vcl/timer.hxx>
      55             : #include <vcl/window.hxx>
      56             : #include <toolkit/awt/vclxwindow.hxx>
      57             : #include <toolkit/helper/vclunohelper.hxx>
      58             : #include <toolkit/helper/convert.hxx>
      59             : #include <tools/fract.hxx>
      60             : #include <tools/gen.hxx>
      61             : #include <svl/rectitem.hxx>
      62             : #include <svtools/soerr.hxx>
      63             : #include <comphelper/processfactory.hxx>
      64             : 
      65             : #define SFX_CLIENTACTIVATE_TIMEOUT 100
      66             : 
      67             : using namespace com::sun::star;
      68             : 
      69             : 
      70             : // SfxEmbedResizeGuard
      71             : class SfxBooleanFlagGuard
      72             : {
      73             :     bool& m_rFlag;
      74             :     bool  m_bLifeValue;
      75             : public:
      76           0 :     SfxBooleanFlagGuard( bool& bFlag, bool bLifeValue )
      77             :     : m_rFlag( bFlag )
      78           0 :     , m_bLifeValue( bLifeValue )
      79             :     {
      80           0 :         m_rFlag = m_bLifeValue;
      81           0 :     }
      82             : 
      83           0 :     ~SfxBooleanFlagGuard()
      84             :     {
      85           0 :         m_rFlag = !m_bLifeValue;
      86           0 :     }
      87             : };
      88             : 
      89             : 
      90             : // SfxInPlaceClient_Impl
      91             : 
      92             : 
      93             : class SfxInPlaceClient_Impl : public ::cppu::WeakImplHelper5< embed::XEmbeddedClient,
      94             :                                                               embed::XInplaceClient,
      95             :                                                               document::XEventListener,
      96             :                                                               embed::XStateChangeListener,
      97             :                                                               embed::XWindowSupplier >
      98             : {
      99             : public:
     100             :     Timer                           m_aTimer;               // activation timeout, starts after object connection
     101             :     Rectangle                       m_aObjArea;             // area of object in coordinate system of the container (without scaling)
     102             :     Fraction                        m_aScaleWidth;          // scaling that was applied to the object when it was not active
     103             :     Fraction                        m_aScaleHeight;
     104             :     SfxInPlaceClient*               m_pClient;
     105             :     sal_Int64                       m_nAspect;              // ViewAspect that is assigned from the container
     106             :     Rectangle                       m_aLastObjAreaPixel;    // area of object in coordinate system of the container (without scaling)
     107             :     bool                            m_bStoreObject;
     108             :     bool                            m_bUIActive;            // set and cleared when notification for UI (de)activation is sent
     109             :     bool                            m_bResizeNoScale;
     110             : 
     111             :     uno::Reference < embed::XEmbeddedObject > m_xObject;
     112             :     uno::Reference < embed::XEmbeddedClient > m_xClient;
     113             : 
     114             : 
     115          20 :     SfxInPlaceClient_Impl()
     116             :     : m_pClient( NULL )
     117             :     , m_nAspect( 0 )
     118             :     , m_bStoreObject( true )
     119             :     , m_bUIActive( false )
     120          20 :     , m_bResizeNoScale( false )
     121          20 :     {}
     122             : 
     123             :     virtual ~SfxInPlaceClient_Impl();
     124             : 
     125             :     void SizeHasChanged();
     126             :     DECL_LINK(TimerHdl, void *);
     127             :     uno::Reference < frame::XFrame > GetFrame() const;
     128             : 
     129             :     // XEmbeddedClient
     130             :     virtual void SAL_CALL saveObject() throw ( embed::ObjectSaveVetoException, uno::Exception, uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     131             :     virtual void SAL_CALL visibilityChanged( sal_Bool bVisible ) throw ( embed::WrongStateException, uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     132             : 
     133             :     // XInplaceClient
     134             :     virtual sal_Bool SAL_CALL canInplaceActivate() throw ( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     135             :     virtual void SAL_CALL activatingInplace() throw ( embed::WrongStateException, uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     136             :     virtual void SAL_CALL activatingUI() throw ( embed::WrongStateException, uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     137             :     virtual void SAL_CALL deactivatedInplace() throw ( embed::WrongStateException, uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     138             :     virtual void SAL_CALL deactivatedUI() throw ( embed::WrongStateException, uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     139             :     virtual uno::Reference< ::com::sun::star::frame::XLayoutManager > SAL_CALL getLayoutManager() throw ( embed::WrongStateException, uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     140             :     virtual uno::Reference< frame::XDispatchProvider > SAL_CALL getInplaceDispatchProvider() throw ( embed::WrongStateException, uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     141             :     virtual awt::Rectangle SAL_CALL getPlacement() throw ( embed::WrongStateException, uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     142             :     virtual awt::Rectangle SAL_CALL getClipRectangle() throw ( embed::WrongStateException, uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     143             :     virtual void SAL_CALL translateAccelerators( const uno::Sequence< awt::KeyEvent >& aKeys ) throw ( embed::WrongStateException, uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     144             :     virtual void SAL_CALL scrollObject( const awt::Size& aOffset ) throw ( embed::WrongStateException, uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     145             :     virtual void SAL_CALL changedPlacement( const awt::Rectangle& aPosRect ) throw ( embed::WrongStateException, uno::Exception, uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     146             : 
     147             :     // XComponentSupplier
     148             :     virtual uno::Reference< util::XCloseable > SAL_CALL getComponent() throw ( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     149             : 
     150             :     // XWindowSupplier
     151             :     virtual uno::Reference< awt::XWindow > SAL_CALL getWindow() throw ( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     152             : 
     153             :     // document::XEventListener
     154             :     virtual void SAL_CALL       notifyEvent( const document::EventObject& aEvent ) throw( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     155             : 
     156             :     // XStateChangeListener
     157             :     virtual void SAL_CALL changingState( const ::com::sun::star::lang::EventObject& aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState ) throw (::com::sun::star::embed::WrongStateException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     158             :     virtual void SAL_CALL stateChanged( const ::com::sun::star::lang::EventObject& aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     159             :     virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     160             : };
     161             : 
     162          40 : SfxInPlaceClient_Impl::~SfxInPlaceClient_Impl()
     163             : {
     164          40 : }
     165             : 
     166           6 : void SAL_CALL SfxInPlaceClient_Impl::changingState(
     167             :     const ::com::sun::star::lang::EventObject& /*aEvent*/,
     168             :     ::sal_Int32 /*nOldState*/,
     169             :     ::sal_Int32 /*nNewState*/ )
     170             : throw (::com::sun::star::embed::WrongStateException, ::com::sun::star::uno::RuntimeException, std::exception)
     171             : {
     172           6 : }
     173             : 
     174           6 : void SAL_CALL SfxInPlaceClient_Impl::stateChanged(
     175             :     const ::com::sun::star::lang::EventObject& /*aEvent*/,
     176             :     ::sal_Int32 nOldState,
     177             :     ::sal_Int32 nNewState )
     178             : throw (::com::sun::star::uno::RuntimeException, std::exception)
     179             : {
     180           6 :     if ( m_pClient && nOldState != embed::EmbedStates::LOADED && nNewState == embed::EmbedStates::RUNNING )
     181             :     {
     182             :         // deactivation of object
     183           2 :         uno::Reference< frame::XModel > xDocument;
     184           2 :         if ( m_pClient->GetViewShell()->GetObjectShell() )
     185           2 :             xDocument = m_pClient->GetViewShell()->GetObjectShell()->GetModel();
     186           2 :         SfxObjectShell::SetCurrentComponent( xDocument );
     187             :     }
     188           6 : }
     189             : 
     190          52 : void SAL_CALL SfxInPlaceClient_Impl::notifyEvent( const document::EventObject& aEvent ) throw( uno::RuntimeException, std::exception )
     191             : {
     192          52 :     SolarMutexGuard aGuard;
     193             : 
     194          52 :     if ( m_pClient && aEvent.EventName == "OnVisAreaChanged" && m_nAspect != embed::Aspects::MSOLE_ICON )
     195             :     {
     196          20 :         m_pClient->FormatChanged(); // for Writer when format of the object is changed with the area
     197          20 :         m_pClient->ViewChanged();
     198          20 :         m_pClient->Invalidate();
     199          52 :     }
     200          52 : }
     201             : 
     202           0 : void SAL_CALL SfxInPlaceClient_Impl::disposing( const ::com::sun::star::lang::EventObject& /*aEvent*/ )
     203             : throw (::com::sun::star::uno::RuntimeException, std::exception)
     204             : {
     205           0 :     DELETEZ( m_pClient );
     206           0 : }
     207             : 
     208             : // XEmbeddedClient
     209             : 
     210           8 : uno::Reference < frame::XFrame > SfxInPlaceClient_Impl::GetFrame() const
     211             : {
     212           8 :     if ( !m_pClient )
     213           0 :         throw uno::RuntimeException();
     214           8 :     return m_pClient->GetViewShell()->GetViewFrame()->GetFrame().GetFrameInterface();
     215             : }
     216             : 
     217           2 : void SAL_CALL SfxInPlaceClient_Impl::saveObject()
     218             :     throw ( embed::ObjectSaveVetoException,
     219             :             uno::Exception,
     220             :             uno::RuntimeException, std::exception )
     221             : {
     222           2 :     if ( !m_bStoreObject )
     223             :         // client wants to discard the object (usually it means the container document is closed while an object is active
     224             :         // and the user didn't request saving the changes
     225           4 :         return;
     226             : 
     227             :     // the common persistence is supported by objects and links
     228           0 :     uno::Reference< embed::XCommonEmbedPersist > xPersist( m_xObject, uno::UNO_QUERY );
     229           0 :     if ( !xPersist.is() )
     230           0 :         throw uno::RuntimeException();
     231             : 
     232           0 :     uno::Reference< frame::XFrame >              xFrame;
     233           0 :     uno::Reference< task::XStatusIndicator >     xStatusIndicator;
     234           0 :     uno::Reference< frame::XModel >              xModel( m_xObject->getComponent(), uno::UNO_QUERY );
     235           0 :     uno::Reference< uno::XComponentContext >     xContext( ::comphelper::getProcessComponentContext() );
     236             : 
     237           0 :     if ( xModel.is() )
     238             :     {
     239           0 :         uno::Reference< frame::XController > xController = xModel->getCurrentController();
     240           0 :         if ( xController.is() )
     241           0 :             xFrame = xController->getFrame();
     242             :     }
     243             : 
     244           0 :     if ( xFrame.is() )
     245             :     {
     246             :         // set non-reschedule progress to prevent problems when asynchronous calls are made
     247             :         // during storing of the embedded object
     248             :         uno::Reference< task::XStatusIndicatorFactory > xStatusIndicatorFactory =
     249           0 :                task::StatusIndicatorFactory::createWithFrame( xContext, xFrame, sal_True/*DisableReschedule*/, sal_False/*AllowParentShow*/ );
     250             : 
     251           0 :         uno::Reference< beans::XPropertySet > xPropSet( xFrame, uno::UNO_QUERY );
     252           0 :         if ( xPropSet.is() )
     253             :         {
     254             :             try
     255             :             {
     256           0 :                 xStatusIndicator = xStatusIndicatorFactory->createStatusIndicator();
     257           0 :                 xPropSet->setPropertyValue( "IndicatorInterception" , uno::makeAny( xStatusIndicator ));
     258             :             }
     259           0 :             catch ( const uno::RuntimeException& )
     260             :             {
     261           0 :                 throw;
     262             :             }
     263           0 :             catch ( uno::Exception& )
     264             :             {
     265             :             }
     266           0 :         }
     267             :     }
     268             : 
     269             :     try
     270             :     {
     271           0 :         xPersist->storeOwn();
     272           0 :         m_xObject->update();
     273             :     }
     274           0 :     catch ( uno::Exception& )
     275             :     {
     276             :         //TODO/LATER: what should happen if object can't be saved?!
     277             :     }
     278             : 
     279             :     // reset status indicator interception after storing
     280             :     try
     281             :     {
     282           0 :         uno::Reference< beans::XPropertySet > xPropSet( xFrame, uno::UNO_QUERY );
     283           0 :         if ( xPropSet.is() )
     284             :         {
     285           0 :             xStatusIndicator.clear();
     286           0 :             xPropSet->setPropertyValue( "IndicatorInterception" , uno::makeAny( xStatusIndicator ));
     287           0 :         }
     288             :     }
     289           0 :     catch ( const uno::RuntimeException& )
     290             :     {
     291           0 :         throw;
     292             :     }
     293           0 :     catch ( uno::Exception& )
     294             :     {
     295             :     }
     296             : 
     297             :     // the client can exist only in case there is a view shell
     298           0 :     if ( !m_pClient || !m_pClient->GetViewShell() )
     299           0 :         throw uno::RuntimeException();
     300             : 
     301           0 :     SfxObjectShell* pDocShell = m_pClient->GetViewShell()->GetObjectShell();
     302           0 :     if ( !pDocShell )
     303           0 :         throw uno::RuntimeException();
     304             : 
     305           0 :     pDocShell->SetModified( true );
     306             : 
     307             :     //TODO/LATER: invalidation might be necessary when object was modified, but is not
     308             :     //saved through this method
     309             :     // m_pClient->Invalidate();
     310             : }
     311             : 
     312             : 
     313           4 : void SAL_CALL SfxInPlaceClient_Impl::visibilityChanged( sal_Bool bVisible )
     314             :     throw ( embed::WrongStateException,
     315             :             uno::RuntimeException, std::exception )
     316             : {
     317           4 :     SolarMutexGuard aGuard;
     318             : 
     319           4 :     if ( !m_pClient || !m_pClient->GetViewShell() )
     320           0 :         throw uno::RuntimeException();
     321             : 
     322           4 :     m_pClient->GetViewShell()->OutplaceActivated( bVisible, m_pClient );
     323           4 :     m_pClient->Invalidate();
     324           4 : }
     325             : 
     326             : 
     327             : // XInplaceClient
     328             : 
     329           2 : sal_Bool SAL_CALL SfxInPlaceClient_Impl::canInplaceActivate()
     330             :     throw ( uno::RuntimeException, std::exception )
     331             : {
     332           2 :     if ( !m_xObject.is() )
     333           0 :         throw uno::RuntimeException();
     334             : 
     335             :     // we don't want to switch directly from outplace to inplace mode
     336           2 :     if ( m_xObject->getCurrentState() == embed::EmbedStates::ACTIVE || m_nAspect == embed::Aspects::MSOLE_ICON )
     337           0 :         return sal_False;
     338             : 
     339           2 :     return sal_True;
     340             : }
     341             : 
     342             : 
     343           2 : void SAL_CALL SfxInPlaceClient_Impl::activatingInplace()
     344             :     throw ( embed::WrongStateException,
     345             :             uno::RuntimeException, std::exception )
     346             : {
     347           2 :     if ( !m_pClient || !m_pClient->GetViewShell() )
     348           0 :         throw uno::RuntimeException();
     349             : 
     350           2 :     m_pClient->GetViewShell()->InplaceActivating( m_pClient );
     351           2 : }
     352             : 
     353             : 
     354           2 : void SAL_CALL SfxInPlaceClient_Impl::activatingUI()
     355             :     throw ( embed::WrongStateException,
     356             :             uno::RuntimeException, std::exception )
     357             : {
     358           2 :     if ( !m_pClient || !m_pClient->GetViewShell() )
     359           0 :         throw uno::RuntimeException();
     360             : 
     361           2 :     m_pClient->GetViewShell()->ResetAllClients_Impl(m_pClient);
     362           2 :     m_bUIActive = true;
     363           2 :     m_pClient->GetViewShell()->UIActivating( m_pClient );
     364           2 : }
     365             : 
     366             : 
     367           2 : void SAL_CALL SfxInPlaceClient_Impl::deactivatedInplace()
     368             :     throw ( embed::WrongStateException,
     369             :             uno::RuntimeException, std::exception )
     370             : {
     371           2 :     if ( !m_pClient || !m_pClient->GetViewShell() )
     372           0 :         throw uno::RuntimeException();
     373             : 
     374           2 :     m_pClient->GetViewShell()->InplaceDeactivated( m_pClient );
     375           2 : }
     376             : 
     377             : 
     378           2 : void SAL_CALL SfxInPlaceClient_Impl::deactivatedUI()
     379             :     throw ( embed::WrongStateException,
     380             :             uno::RuntimeException, std::exception )
     381             : {
     382           2 :     if ( !m_pClient || !m_pClient->GetViewShell() )
     383           0 :         throw uno::RuntimeException();
     384             : 
     385           2 :     m_pClient->GetViewShell()->UIDeactivated( m_pClient );
     386           2 :     m_bUIActive = false;
     387           2 : }
     388             : 
     389             : 
     390           4 : uno::Reference< ::com::sun::star::frame::XLayoutManager > SAL_CALL SfxInPlaceClient_Impl::getLayoutManager()
     391             :     throw ( embed::WrongStateException,
     392             :             uno::RuntimeException, std::exception )
     393             : {
     394           4 :     uno::Reference < beans::XPropertySet > xFrame( GetFrame(), uno::UNO_QUERY );
     395           4 :     if ( !xFrame.is() )
     396           0 :         throw uno::RuntimeException();
     397             : 
     398           4 :     uno::Reference< ::com::sun::star::frame::XLayoutManager > xMan;
     399             :     try
     400             :     {
     401           4 :         uno::Any aAny = xFrame->getPropertyValue( "LayoutManager" );
     402           4 :         aAny >>= xMan;
     403             :     }
     404           0 :     catch ( uno::Exception& )
     405             :     {
     406           0 :         throw uno::RuntimeException();
     407             :     }
     408             : 
     409           4 :     return xMan;
     410             : }
     411             : 
     412             : 
     413           4 : uno::Reference< frame::XDispatchProvider > SAL_CALL SfxInPlaceClient_Impl::getInplaceDispatchProvider()
     414             :     throw ( embed::WrongStateException,
     415             :             uno::RuntimeException, std::exception )
     416             : {
     417           4 :     return uno::Reference < frame::XDispatchProvider >( GetFrame(), uno::UNO_QUERY_THROW );
     418             : }
     419             : 
     420             : 
     421           6 : awt::Rectangle SAL_CALL SfxInPlaceClient_Impl::getPlacement()
     422             :     throw ( embed::WrongStateException,
     423             :             uno::RuntimeException, std::exception )
     424             : {
     425           6 :     if ( !m_pClient || !m_pClient->GetViewShell() )
     426           0 :         throw uno::RuntimeException();
     427             : 
     428             :     // apply scaling to object area and convert to pixels
     429           6 :     Rectangle aRealObjArea( m_aObjArea );
     430          12 :     aRealObjArea.SetSize( Size( Fraction( aRealObjArea.GetWidth() ) * m_aScaleWidth,
     431          18 :                                 Fraction( aRealObjArea.GetHeight() ) * m_aScaleHeight ) );
     432             : 
     433           6 :     aRealObjArea = m_pClient->GetEditWin()->LogicToPixel( aRealObjArea );
     434           6 :     return AWTRectangle( aRealObjArea );
     435             : }
     436             : 
     437             : 
     438           6 : awt::Rectangle SAL_CALL SfxInPlaceClient_Impl::getClipRectangle()
     439             :     throw ( embed::WrongStateException,
     440             :             uno::RuntimeException, std::exception )
     441             : {
     442           6 :     if ( !m_pClient || !m_pClient->GetViewShell() )
     443           0 :         throw uno::RuntimeException();
     444             : 
     445             :     // currently(?) same as placement
     446           6 :     Rectangle aRealObjArea( m_aObjArea );
     447          12 :     aRealObjArea.SetSize( Size( Fraction( aRealObjArea.GetWidth() ) * m_aScaleWidth,
     448          18 :                                 Fraction( aRealObjArea.GetHeight() ) * m_aScaleHeight ) );
     449             : 
     450           6 :     aRealObjArea = m_pClient->GetEditWin()->LogicToPixel( aRealObjArea );
     451           6 :     return AWTRectangle( aRealObjArea );
     452             : }
     453             : 
     454             : 
     455           0 : void SAL_CALL SfxInPlaceClient_Impl::translateAccelerators( const uno::Sequence< awt::KeyEvent >& /*aKeys*/ )
     456             :     throw ( embed::WrongStateException,
     457             :             uno::RuntimeException, std::exception )
     458             : {
     459           0 :     if ( !m_pClient || !m_pClient->GetViewShell() )
     460           0 :         throw uno::RuntimeException();
     461             : 
     462             :     // TODO/MBA: keyboard accelerators
     463           0 : }
     464             : 
     465             : 
     466           0 : void SAL_CALL SfxInPlaceClient_Impl::scrollObject( const awt::Size& /*aOffset*/ )
     467             :     throw ( embed::WrongStateException,
     468             :             uno::RuntimeException, std::exception )
     469             : {
     470           0 :     if ( !m_pClient || !m_pClient->GetViewShell() )
     471           0 :         throw uno::RuntimeException();
     472           0 : }
     473             : 
     474             : 
     475           0 : void SAL_CALL SfxInPlaceClient_Impl::changedPlacement( const awt::Rectangle& aPosRect )
     476             :     throw ( embed::WrongStateException,
     477             :             uno::Exception,
     478             :             uno::RuntimeException, std::exception )
     479             : {
     480           0 :     uno::Reference< embed::XInplaceObject > xInplace( m_xObject, uno::UNO_QUERY );
     481           0 :     if ( !xInplace.is() || !m_pClient || !m_pClient->GetEditWin() || !m_pClient->GetViewShell() )
     482           0 :         throw uno::RuntimeException();
     483             : 
     484             :     // check if the change is at least one pixel in size
     485           0 :     awt::Rectangle aOldRect = getPlacement();
     486           0 :     Rectangle aNewPixelRect = VCLRectangle( aPosRect );
     487           0 :     Rectangle aOldPixelRect = VCLRectangle( aOldRect );
     488           0 :     if ( aOldPixelRect == aNewPixelRect )
     489             :         // nothing has changed
     490           0 :         return;
     491             : 
     492             :     // new scaled object area
     493           0 :     Rectangle aNewLogicRect = m_pClient->GetEditWin()->PixelToLogic( aNewPixelRect );
     494             : 
     495             :     // all the size changes in this method should happen without scaling
     496             :     // SfxBooleanFlagGuard aGuard( m_bResizeNoScale, sal_True );
     497             : 
     498             :     // allow container to apply restrictions on the requested new area;
     499             :     // the container might change the object view during size calculation;
     500             :     // currently only writer does it
     501           0 :     m_pClient->RequestNewObjectArea( aNewLogicRect);
     502             : 
     503           0 :     if ( aNewLogicRect != m_pClient->GetScaledObjArea() )
     504             :     {
     505             :         // the calculation of the object area has not changed the object size
     506             :         // it should be done here then
     507           0 :         SfxBooleanFlagGuard aGuard( m_bResizeNoScale, true );
     508             : 
     509             :         // new size of the object area without scaling
     510           0 :         Size aNewObjSize( Fraction( aNewLogicRect.GetWidth() ) / m_aScaleWidth,
     511           0 :                           Fraction( aNewLogicRect.GetHeight() ) / m_aScaleHeight );
     512             : 
     513             :         // now remove scaling from new placement and keep this a the new object area
     514           0 :         aNewLogicRect.SetSize( aNewObjSize );
     515           0 :         m_aObjArea = aNewLogicRect;
     516             : 
     517             :         // let the window size be recalculated
     518           0 :         SizeHasChanged();
     519             :     }
     520             : 
     521             :     // notify container view about changes
     522           0 :     m_pClient->ObjectAreaChanged();
     523             : }
     524             : 
     525             : // XComponentSupplier
     526             : 
     527           2 : uno::Reference< util::XCloseable > SAL_CALL SfxInPlaceClient_Impl::getComponent()
     528             :     throw ( uno::RuntimeException, std::exception )
     529             : {
     530           2 :     if ( !m_pClient || !m_pClient->GetViewShell() )
     531           0 :         throw uno::RuntimeException();
     532             : 
     533           2 :     SfxObjectShell* pDocShell = m_pClient->GetViewShell()->GetObjectShell();
     534           2 :     if ( !pDocShell )
     535           0 :         throw uno::RuntimeException();
     536             : 
     537             :     // all the components must implement XCloseable
     538           2 :     uno::Reference< util::XCloseable > xComp( pDocShell->GetModel(), uno::UNO_QUERY );
     539           2 :     if ( !xComp.is() )
     540           0 :         throw uno::RuntimeException();
     541             : 
     542           2 :     return xComp;
     543             : }
     544             : 
     545             : 
     546             : // XWindowSupplier
     547             : 
     548           2 : uno::Reference< awt::XWindow > SAL_CALL SfxInPlaceClient_Impl::getWindow()
     549             :     throw ( uno::RuntimeException, std::exception )
     550             : {
     551           2 :     if ( !m_pClient || !m_pClient->GetEditWin() )
     552           0 :         throw uno::RuntimeException();
     553             : 
     554           2 :     uno::Reference< awt::XWindow > xWin( m_pClient->GetEditWin()->GetComponentInterface(), uno::UNO_QUERY );
     555           2 :     return xWin;
     556             : }
     557             : 
     558             : 
     559             : // notification to the client implementation that either the object area or the scaling has been changed
     560             : // as a result the logical size of the window has changed also
     561          26 : void SfxInPlaceClient_Impl::SizeHasChanged()
     562             : {
     563          26 :     if ( !m_pClient || !m_pClient->GetViewShell() )
     564           0 :         throw uno::RuntimeException();
     565             : 
     566             :     try {
     567          52 :         if ( m_xObject.is()
     568          30 :           && ( m_xObject->getCurrentState() == embed::EmbedStates::INPLACE_ACTIVE
     569          22 :                 || m_xObject->getCurrentState() == embed::EmbedStates::UI_ACTIVE ) )
     570             :         {
     571             :             // only possible in active states
     572           4 :             uno::Reference< embed::XInplaceObject > xInplace( m_xObject, uno::UNO_QUERY );
     573           4 :             if ( !xInplace.is() )
     574           0 :                 throw uno::RuntimeException();
     575             : 
     576           4 :             if ( m_bResizeNoScale )
     577             :             {
     578             :                 // the resizing should be done without scaling
     579             :                 // set the correct size to the object to avoid the scaling
     580           0 :                 MapMode aObjectMap( VCLUnoHelper::UnoEmbed2VCLMapUnit( m_xObject->getMapUnit( m_nAspect ) ) );
     581           0 :                 MapMode aClientMap( m_pClient->GetEditWin()->GetMapMode().GetMapUnit() );
     582             : 
     583             :                 // convert to logical coordinates of the embedded object
     584           0 :                 Size aNewSize = m_pClient->GetEditWin()->LogicToLogic( m_aObjArea.GetSize(), &aClientMap, &aObjectMap );
     585           0 :                 m_xObject->setVisualAreaSize( m_nAspect, awt::Size( aNewSize.Width(), aNewSize.Height() ) );
     586             :             }
     587             : 
     588           4 :             xInplace->setObjectRectangles( getPlacement(), getClipRectangle() );
     589             :         }
     590             :     }
     591           0 :     catch( uno::Exception& )
     592             :     {
     593             :         // TODO/LATER: handle error
     594             :     }
     595          26 : }
     596             : 
     597             : 
     598          12 : IMPL_LINK_NOARG(SfxInPlaceClient_Impl, TimerHdl)
     599             : {
     600           6 :     if ( m_pClient && m_xObject.is() )
     601           6 :         m_pClient->GetViewShell()->CheckIPClient_Impl( m_pClient, m_pClient->GetViewShell()->GetObjectShell()->GetVisArea() );
     602           6 :     return 0;
     603             : }
     604             : 
     605             : 
     606             : 
     607             : // SfxInPlaceClient
     608             : 
     609             : 
     610          20 : SfxInPlaceClient::SfxInPlaceClient( SfxViewShell* pViewShell, vcl::Window *pDraw, sal_Int64 nAspect ) :
     611          20 :     m_pImp( new SfxInPlaceClient_Impl ),
     612             :     m_pViewSh( pViewShell ),
     613          40 :     m_pEditWin( pDraw )
     614             : {
     615          20 :     m_pImp->acquire();
     616          20 :     m_pImp->m_pClient = this;
     617          20 :     m_pImp->m_nAspect = nAspect;
     618          20 :     m_pImp->m_aScaleWidth = m_pImp->m_aScaleHeight = Fraction(1,1);
     619          20 :     m_pImp->m_xClient = static_cast< embed::XEmbeddedClient* >( m_pImp );
     620          20 :     pViewShell->NewIPClient_Impl(this);
     621          20 :     m_pImp->m_aTimer.SetTimeout( SFX_CLIENTACTIVATE_TIMEOUT );
     622          20 :     m_pImp->m_aTimer.SetTimeoutHdl( LINK( m_pImp, SfxInPlaceClient_Impl, TimerHdl ) );
     623          20 : }
     624             : 
     625             : 
     626             : 
     627          20 : SfxInPlaceClient::~SfxInPlaceClient()
     628             : {
     629          20 :     m_pViewSh->IPClientGone_Impl(this);
     630             : 
     631             :     // deleting the client before storing the object means discarding all changes
     632          20 :     m_pImp->m_bStoreObject = false;
     633          20 :     SetObject(0);
     634             : 
     635          20 :     m_pImp->m_pClient = NULL;
     636             : 
     637             :     // the next call will destroy m_pImp if no other reference to it exists
     638          20 :     m_pImp->m_xClient = uno::Reference < embed::XEmbeddedClient >();
     639          20 :     m_pImp->release();
     640             : 
     641             :     // TODO/LATER:
     642             :     // the class is not intended to be used in multithreaded environment;
     643             :     // if it will this disconnection and all the parts that use the m_pClient
     644             :     // must be guarded with mutex
     645          20 : }
     646             : 
     647             : 
     648          18 : void SfxInPlaceClient::SetObjectState( sal_Int32 nState )
     649             : {
     650          18 :     if ( GetObject().is() )
     651             :     {
     652          18 :         if ( m_pImp->m_nAspect == embed::Aspects::MSOLE_ICON
     653           0 :           && ( nState == embed::EmbedStates::UI_ACTIVE || nState == embed::EmbedStates::INPLACE_ACTIVE ) )
     654             :         {
     655             :             OSL_FAIL( "Iconified object should not be activated inplace!\n" );
     656          18 :             return;
     657             :         }
     658             : 
     659             :         try
     660             :         {
     661          18 :             GetObject()->changeState( nState );
     662             :         }
     663           0 :         catch ( uno::Exception& )
     664             :         {}
     665             :     }
     666             : }
     667             : 
     668             : 
     669          12 : sal_Int64 SfxInPlaceClient::GetObjectMiscStatus() const
     670             : {
     671          12 :     if ( GetObject().is() )
     672          12 :         return GetObject()->getStatus( m_pImp->m_nAspect );
     673           0 :     return 0;
     674             : }
     675             : 
     676             : 
     677         336 : uno::Reference < embed::XEmbeddedObject > SfxInPlaceClient::GetObject() const
     678             : {
     679         336 :     return m_pImp->m_xObject;
     680             : }
     681             : 
     682             : 
     683          40 : void SfxInPlaceClient::SetObject( const uno::Reference < embed::XEmbeddedObject >& rObject )
     684             : {
     685          40 :     if ( m_pImp->m_xObject.is() && rObject != m_pImp->m_xObject )
     686             :     {
     687             :         DBG_ASSERT( GetObject()->getClientSite() == m_pImp->m_xClient, "Wrong ClientSite!" );
     688          20 :         if ( GetObject()->getClientSite() == m_pImp->m_xClient )
     689             :         {
     690          20 :             if ( GetObject()->getCurrentState() != embed::EmbedStates::LOADED )
     691          18 :                 SetObjectState( embed::EmbedStates::RUNNING );
     692          20 :             m_pImp->m_xObject->removeEventListener( uno::Reference < document::XEventListener >( m_pImp->m_xClient, uno::UNO_QUERY ) );
     693          20 :             m_pImp->m_xObject->removeStateChangeListener( uno::Reference < embed::XStateChangeListener >( m_pImp->m_xClient, uno::UNO_QUERY ) );
     694             :             try
     695             :             {
     696          20 :                 m_pImp->m_xObject->setClientSite( 0 );
     697             :             }
     698           0 :             catch( uno::Exception& )
     699             :             {
     700             :                 OSL_FAIL( "Can not clean the client site!\n" );
     701             :             }
     702             :         }
     703             :     }
     704             : 
     705          40 :     if ( m_pViewSh->GetViewFrame()->GetFrame().IsClosing_Impl() )
     706             :         // sometimes applications reconnect clients on shutting down because it happens in their Paint methods
     707          60 :         return;
     708             : 
     709          20 :     m_pImp->m_xObject = rObject;
     710             : 
     711          20 :     if ( rObject.is() )
     712             :     {
     713             :         // as soon as an object was connected to a client it has to be checked whether the object wants
     714             :         // to be activated
     715          20 :         rObject->addStateChangeListener( uno::Reference < embed::XStateChangeListener >( m_pImp->m_xClient, uno::UNO_QUERY ) );
     716          20 :         rObject->addEventListener( uno::Reference < document::XEventListener >( m_pImp->m_xClient, uno::UNO_QUERY ) );
     717             : 
     718             :         try
     719             :         {
     720          20 :             rObject->setClientSite( m_pImp->m_xClient );
     721             :         }
     722           0 :         catch( uno::Exception& )
     723             :         {
     724             :             OSL_FAIL( "Can not set the client site!\n" );
     725             :         }
     726             : 
     727          20 :         m_pImp->m_aTimer.Start();
     728             :     }
     729             :     else
     730           0 :         m_pImp->m_aTimer.Stop();
     731             : }
     732             : 
     733             : 
     734           0 : bool SfxInPlaceClient::SetObjArea( const Rectangle& rArea )
     735             : {
     736           0 :     if( rArea != m_pImp->m_aObjArea )
     737             :     {
     738           0 :         m_pImp->m_aObjArea = rArea;
     739           0 :         m_pImp->SizeHasChanged();
     740             : 
     741           0 :         Invalidate();
     742           0 :         return true;
     743             :     }
     744             : 
     745           0 :     return false;
     746             : }
     747             : 
     748             : 
     749           0 : Rectangle SfxInPlaceClient::GetObjArea() const
     750             : {
     751           0 :     return m_pImp->m_aObjArea;
     752             : }
     753             : 
     754           0 : Rectangle SfxInPlaceClient::GetScaledObjArea() const
     755             : {
     756           0 :     Rectangle aRealObjArea( m_pImp->m_aObjArea );
     757           0 :     aRealObjArea.SetSize( Size( Fraction( aRealObjArea.GetWidth() ) * m_pImp->m_aScaleWidth,
     758           0 :                                 Fraction( aRealObjArea.GetHeight() ) * m_pImp->m_aScaleHeight ) );
     759           0 :     return aRealObjArea;
     760             : }
     761             : 
     762             : 
     763           0 : void SfxInPlaceClient::SetSizeScale( const Fraction & rScaleWidth, const Fraction & rScaleHeight )
     764             : {
     765           0 :     if ( m_pImp->m_aScaleWidth != rScaleWidth || m_pImp->m_aScaleHeight != rScaleHeight )
     766             :     {
     767           0 :         m_pImp->m_aScaleWidth = rScaleWidth;
     768           0 :         m_pImp->m_aScaleHeight = rScaleHeight;
     769             : 
     770           0 :         m_pImp->SizeHasChanged();
     771             : 
     772             :         // TODO/LATER: Invalidate seems to trigger (wrong) recalculations of the ObjArea, so it's better
     773             :         // not to call it here, but maybe it sounds reasonable to do so.
     774             :         //Invalidate();
     775             :     }
     776           0 : }
     777             : 
     778             : 
     779          22 : bool SfxInPlaceClient::SetObjAreaAndScale( const Rectangle& rArea, const Fraction& rScaleWidth, const Fraction& rScaleHeight )
     780             : {
     781          22 :     if( rArea != m_pImp->m_aObjArea || m_pImp->m_aScaleWidth != rScaleWidth || m_pImp->m_aScaleHeight != rScaleHeight )
     782             :     {
     783          22 :         m_pImp->m_aObjArea = rArea;
     784          22 :         m_pImp->m_aScaleWidth = rScaleWidth;
     785          22 :         m_pImp->m_aScaleHeight = rScaleHeight;
     786             : 
     787          22 :         m_pImp->SizeHasChanged();
     788             : 
     789          22 :         Invalidate();
     790          22 :         return true;
     791             :     }
     792             : 
     793           0 :     return false;
     794             : }
     795             : 
     796             : 
     797          84 : const Fraction& SfxInPlaceClient::GetScaleWidth() const
     798             : {
     799          84 :     return m_pImp->m_aScaleWidth;
     800             : }
     801             : 
     802             : 
     803          84 : const Fraction& SfxInPlaceClient::GetScaleHeight() const
     804             : {
     805          84 :     return m_pImp->m_aScaleHeight;
     806             : }
     807             : 
     808             : 
     809          46 : void SfxInPlaceClient::Invalidate()
     810             : {
     811             :     // TODO/LATER: do we need both?
     812             : 
     813             :     // the object area is provided in logical coordinates of the window but without scaling applied
     814          46 :     Rectangle aRealObjArea( m_pImp->m_aObjArea );
     815          92 :     aRealObjArea.SetSize( Size( Fraction( aRealObjArea.GetWidth() ) * m_pImp->m_aScaleWidth,
     816         138 :                                 Fraction( aRealObjArea.GetHeight() ) * m_pImp->m_aScaleHeight ) );
     817          46 :     m_pEditWin->Invalidate( aRealObjArea );
     818             : 
     819          46 :     ViewChanged();
     820          46 : }
     821             : 
     822             : 
     823         830 : bool SfxInPlaceClient::IsObjectUIActive() const
     824             : {
     825             :     try {
     826         830 :         return ( m_pImp->m_xObject.is() && ( m_pImp->m_xObject->getCurrentState() == embed::EmbedStates::UI_ACTIVE ) );
     827             :     }
     828           0 :     catch( uno::Exception& )
     829             :     {}
     830             : 
     831           0 :     return false;
     832             : }
     833             : 
     834             : 
     835          20 : bool SfxInPlaceClient::IsObjectInPlaceActive() const
     836             : {
     837             :     try {
     838             :         return(
     839             :                (
     840          40 :                 m_pImp->m_xObject.is() &&
     841          20 :                 (m_pImp->m_xObject->getCurrentState() == embed::EmbedStates::INPLACE_ACTIVE)
     842          40 :                ) ||
     843             :                (
     844          32 :                 m_pImp->m_xObject.is() &&
     845          16 :                 (m_pImp->m_xObject->getCurrentState() == embed::EmbedStates::UI_ACTIVE)
     846             :                )
     847          20 :               );
     848             :     }
     849           0 :     catch( uno::Exception& )
     850             :     {}
     851             : 
     852           0 :     return false;
     853             : }
     854             : 
     855             : 
     856         438 : SfxInPlaceClient* SfxInPlaceClient::GetClient( SfxObjectShell* pDoc, const com::sun::star::uno::Reference < com::sun::star::embed::XEmbeddedObject >& xObject )
     857             : {
     858         474 :     for ( SfxViewFrame* pFrame = SfxViewFrame::GetFirst(pDoc); pFrame; pFrame=SfxViewFrame::GetNext(*pFrame,pDoc) )
     859             :     {
     860          36 :         if( pFrame->GetViewShell() )
     861             :         {
     862          36 :             SfxInPlaceClient* pClient = pFrame->GetViewShell()->FindIPClient( xObject, NULL );
     863          36 :             if ( pClient )
     864           0 :                 return pClient;
     865             :         }
     866             :     }
     867             : 
     868         438 :     return NULL;
     869             : }
     870             : 
     871         186 : sal_Int64 SfxInPlaceClient::GetAspect() const
     872             : {
     873         186 :     return m_pImp->m_nAspect;
     874             : }
     875             : 
     876           0 : ErrCode SfxInPlaceClient::DoVerb( long nVerb )
     877             : {
     878           0 :     SfxErrorContext aEc( ERRCTX_SO_DOVERB, m_pViewSh->GetWindow(), RID_SO_ERRCTX );
     879           0 :     ErrCode nError = ERRCODE_NONE;
     880             : 
     881           0 :     if ( m_pImp->m_xObject.is() )
     882             :     {
     883           0 :         bool bSaveCopyAs = false;
     884           0 :         if ( nVerb == -8 ) // "Save Copy as..."
     885             :         {
     886           0 :             svt::EmbeddedObjectRef::TryRunningState( m_pImp->m_xObject );
     887             :             // TODO/LATER: this special verb should disappear when outplace activation is completely available
     888           0 :             uno::Reference< frame::XModel > xEmbModel( m_pImp->m_xObject->getComponent(), uno::UNO_QUERY );
     889           0 :             if ( xEmbModel.is() )
     890             :             {
     891           0 :                 bSaveCopyAs = true;
     892             : 
     893             :                 try
     894             :                 {
     895           0 :                     SfxStoringHelper aHelper;
     896           0 :                     uno::Sequence< beans::PropertyValue > aDispatchArgs( 1 );
     897           0 :                     aDispatchArgs[0].Name = "SaveTo";
     898           0 :                     aDispatchArgs[0].Value <<= true;
     899             : 
     900             :                     aHelper.GUIStoreModel( xEmbModel,
     901             :                                             "SaveAs",
     902             :                                             aDispatchArgs,
     903             :                                             false,
     904           0 :                                             "" );
     905             :                 }
     906           0 :                 catch( const task::ErrorCodeIOException& aErrorEx )
     907             :                 {
     908           0 :                     nError = (sal_uInt32)aErrorEx.ErrCode;
     909             :                 }
     910           0 :                 catch( uno::Exception& )
     911             :                 {
     912           0 :                     nError = ERRCODE_IO_GENERAL;
     913             :                     // TODO/LATER: better error handling
     914             :                 }
     915           0 :             }
     916             :         }
     917             : 
     918           0 :         if ( !bSaveCopyAs )
     919             :         {
     920           0 :             if ( m_pImp->m_nAspect == embed::Aspects::MSOLE_ICON )
     921             :             {
     922           0 :                 if ( nVerb == embed::EmbedVerbs::MS_OLEVERB_PRIMARY || nVerb == embed::EmbedVerbs::MS_OLEVERB_SHOW )
     923           0 :                     nVerb = embed::EmbedVerbs::MS_OLEVERB_OPEN; // outplace activation
     924           0 :                 else if ( nVerb == embed::EmbedVerbs::MS_OLEVERB_UIACTIVATE
     925           0 :                        || nVerb == embed::EmbedVerbs::MS_OLEVERB_IPACTIVATE )
     926           0 :                     nError = ERRCODE_SO_GENERALERROR;
     927             :             }
     928             : 
     929           0 :             if ( !nError )
     930             :             {
     931             : 
     932           0 :                 m_pViewSh->GetViewFrame()->GetTopFrame().LockResize_Impl(true);
     933             :                 try
     934             :                 {
     935           0 :                     m_pImp->m_xObject->setClientSite( m_pImp->m_xClient );
     936             : 
     937           0 :                     m_pImp->m_xObject->doVerb( nVerb );
     938             :                 }
     939           0 :                 catch ( embed::UnreachableStateException& )
     940             :                 {
     941           0 :                     if ( nVerb == 0 || nVerb == embed::EmbedVerbs::MS_OLEVERB_OPEN )
     942             :                     {
     943             :                         // a workaround for the default verb, usually makes sence for alien objects
     944             :                         try
     945             :                         {
     946           0 :                             m_pImp->m_xObject->doVerb( -9 ); // open own view, a workaround verb that is not visible
     947             : 
     948           0 :                             if ( m_pImp->m_xObject->getCurrentState() == embed::EmbedStates::UI_ACTIVE )
     949             :                             {
     950             :                                 // the object was converted to OOo object
     951           0 :                                 awt::Size aSize = m_pImp->m_xObject->getVisualAreaSize( m_pImp->m_nAspect );
     952           0 :                                 MapMode aObjectMap( VCLUnoHelper::UnoEmbed2VCLMapUnit( m_pImp->m_xObject->getMapUnit( m_pImp->m_nAspect ) ) );
     953           0 :                                 MapMode aClientMap( GetEditWin()->GetMapMode().GetMapUnit() );
     954           0 :                                 Size aNewSize = GetEditWin()->LogicToLogic( Size( aSize.Width, aSize.Height ), &aObjectMap, &aClientMap );
     955             : 
     956           0 :                                 Rectangle aScaledArea = GetScaledObjArea();
     957           0 :                                 m_pImp->m_aObjArea.SetSize( aNewSize );
     958           0 :                                 m_pImp->m_aScaleWidth = Fraction( aScaledArea.GetWidth(), aNewSize.Width() );
     959           0 :                                 m_pImp->m_aScaleHeight = Fraction( aScaledArea.GetHeight(), aNewSize.Height() );
     960             :                             }
     961             :                         }
     962           0 :                         catch (uno::Exception const& e)
     963             :                         {
     964             :                             SAL_WARN("embeddedobj", "SfxInPlaceClient::DoVerb:"
     965             :                                 " -9 fallback path: exception caught: "
     966             :                                 << e.Message);
     967           0 :                             nError = ERRCODE_SO_GENERALERROR;
     968             :                         }
     969             :                     }
     970             :                 }
     971           0 :                 catch ( embed::StateChangeInProgressException& )
     972             :                 {
     973             :                     // TODO/LATER: it would be nice to be able to provide the current target state outside
     974           0 :                     nError = ERRCODE_SO_CANNOT_DOVERB_NOW;
     975             :                 }
     976           0 :                 catch (uno::Exception const& e)
     977             :                 {
     978             :                     SAL_WARN("embeddedobj", "SfxInPlaceClient::DoVerb:"
     979             :                             " exception caught: " << e.Message);
     980           0 :                     nError = ERRCODE_SO_GENERALERROR;
     981             :                     //TODO/LATER: better error handling
     982             :                 }
     983             : 
     984           0 :                 SfxViewFrame* pFrame = m_pViewSh->GetViewFrame();
     985           0 :                 pFrame->GetTopFrame().LockResize_Impl(false);
     986           0 :                 pFrame->GetTopFrame().Resize();
     987             :             }
     988             :         }
     989             :     }
     990             : 
     991           0 :     if( nError )
     992           0 :         ErrorHandler::HandleError( nError );
     993             : 
     994           0 :     return nError;
     995             : }
     996             : 
     997           4 : void SfxInPlaceClient::VisAreaChanged()
     998             : {
     999           4 :     uno::Reference < embed::XInplaceObject > xObj( m_pImp->m_xObject, uno::UNO_QUERY );
    1000           8 :     uno::Reference < embed::XInplaceClient > xClient( m_pImp->m_xClient, uno::UNO_QUERY );
    1001           4 :     if ( xObj.is() && xClient.is() )
    1002           8 :         m_pImp->SizeHasChanged();
    1003           4 : }
    1004             : 
    1005           0 : void SfxInPlaceClient::ObjectAreaChanged()
    1006             : {
    1007             :     // dummy implementation
    1008           0 : }
    1009             : 
    1010           0 : void SfxInPlaceClient::RequestNewObjectArea( Rectangle& )
    1011             : {
    1012             :     // dummy implementation
    1013           0 : }
    1014             : 
    1015           4 : void SfxInPlaceClient::ViewChanged()
    1016             : {
    1017             :     // dummy implementation
    1018           4 : }
    1019             : 
    1020           0 : void SfxInPlaceClient::MakeVisible()
    1021             : {
    1022             :     // dummy implementation
    1023           0 : }
    1024             : 
    1025           0 : void SfxInPlaceClient::FormatChanged()
    1026             : {
    1027             :     // dummy implementation
    1028           0 : }
    1029             : 
    1030           0 : void SfxInPlaceClient::DeactivateObject()
    1031             : {
    1032           0 :     if ( GetObject().is() )
    1033             :     {
    1034             :         try
    1035             :         {
    1036           0 :             m_pImp->m_bUIActive = false;
    1037           0 :             bool bHasFocus = false;
    1038           0 :             uno::Reference< frame::XModel > xModel( m_pImp->m_xObject->getComponent(), uno::UNO_QUERY );
    1039           0 :             if ( xModel.is() )
    1040             :             {
    1041           0 :                 uno::Reference< frame::XController > xController = xModel->getCurrentController();
    1042           0 :                 if ( xController.is() )
    1043             :                 {
    1044           0 :                     vcl::Window* pWindow = VCLUnoHelper::GetWindow( xController->getFrame()->getContainerWindow() );
    1045           0 :                     bHasFocus = pWindow->HasChildPathFocus( true );
    1046           0 :                 }
    1047             :             }
    1048             : 
    1049           0 :             m_pViewSh->GetViewFrame()->GetTopFrame().LockResize_Impl(true);
    1050             : 
    1051           0 :             if ( (m_pImp->m_xObject->getStatus( m_pImp->m_nAspect ) & embed::EmbedMisc::MS_EMBED_ACTIVATEWHENVISIBLE) ||
    1052           0 :                  svt::EmbeddedObjectRef::IsGLChart(m_pImp->m_xObject) )
    1053             :             {
    1054           0 :                 m_pImp->m_xObject->changeState( embed::EmbedStates::INPLACE_ACTIVE );
    1055           0 :                 if (bHasFocus)
    1056           0 :                     m_pViewSh->GetWindow()->GrabFocus();
    1057             :             }
    1058             :             else
    1059             :             {
    1060             :                 // the links should not stay in running state for long time because of locking
    1061           0 :                 uno::Reference< embed::XLinkageSupport > xLink( m_pImp->m_xObject, uno::UNO_QUERY );
    1062           0 :                 if ( xLink.is() && xLink->isLink() )
    1063           0 :                     m_pImp->m_xObject->changeState( embed::EmbedStates::LOADED );
    1064             :                 else
    1065           0 :                     m_pImp->m_xObject->changeState( embed::EmbedStates::RUNNING );
    1066             :             }
    1067             : 
    1068           0 :             SfxViewFrame* pFrame = m_pViewSh->GetViewFrame();
    1069           0 :             SfxViewFrame::SetViewFrame( pFrame );
    1070           0 :             pFrame->GetTopFrame().LockResize_Impl(false);
    1071           0 :             pFrame->GetTopFrame().Resize();
    1072             :         }
    1073           0 :         catch (com::sun::star::uno::Exception& )
    1074             :         {}
    1075             :     }
    1076           0 : }
    1077             : 
    1078           0 : void SfxInPlaceClient::ResetObject()
    1079             : {
    1080           0 :     if ( GetObject().is() )
    1081             :     {
    1082             :         try
    1083             :         {
    1084           0 :             m_pImp->m_bUIActive = false;
    1085           0 :             if ( (m_pImp->m_xObject->getStatus( m_pImp->m_nAspect ) & embed::EmbedMisc::MS_EMBED_ACTIVATEWHENVISIBLE) ||
    1086           0 :                 svt::EmbeddedObjectRef::IsGLChart(m_pImp->m_xObject) )
    1087           0 :                 m_pImp->m_xObject->changeState( embed::EmbedStates::INPLACE_ACTIVE );
    1088             :             else
    1089             :             {
    1090             :                 // the links should not stay in running state for long time because of locking
    1091           0 :                 uno::Reference< embed::XLinkageSupport > xLink( m_pImp->m_xObject, uno::UNO_QUERY );
    1092           0 :                 if ( xLink.is() && xLink->isLink() )
    1093           0 :                     m_pImp->m_xObject->changeState( embed::EmbedStates::LOADED );
    1094             :                 else
    1095           0 :                     m_pImp->m_xObject->changeState( embed::EmbedStates::RUNNING );
    1096             :             }
    1097             :         }
    1098           0 :         catch (com::sun::star::uno::Exception& )
    1099             :         {}
    1100             :     }
    1101           0 : }
    1102             : 
    1103           4 : bool SfxInPlaceClient::IsUIActive()
    1104             : {
    1105           4 :     return m_pImp->m_bUIActive;
    1106         951 : }
    1107             : 
    1108             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10