LCOV - code coverage report
Current view: top level - sfx2/source/view - ipclient.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 190 436 43.6 %
Date: 2012-08-25 Functions: 39 58 67.2 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 191 939 20.3 %

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

Generated by: LCOV version 1.10