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