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_embeddedobj.hxx" 30*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp> 31*cdf0e10cSrcweir #include <com/sun/star/embed/EmbedStates.hpp> 32*cdf0e10cSrcweir #include <com/sun/star/embed/EmbedVerbs.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/embed/EmbedUpdateModes.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/embed/XEmbeddedClient.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/embed/XInplaceClient.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/embed/XWindowSupplier.hpp> 37*cdf0e10cSrcweir #include <com/sun/star/embed/Aspects.hpp> 38*cdf0e10cSrcweir #include <com/sun/star/awt/XWindowPeer.hpp> 39*cdf0e10cSrcweir #include <com/sun/star/util/XCloseBroadcaster.hpp> 40*cdf0e10cSrcweir #include <com/sun/star/util/XCloseable.hpp> 41*cdf0e10cSrcweir #include <com/sun/star/util/XModifiable.hpp> 42*cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp> 43*cdf0e10cSrcweir #include <com/sun/star/frame/XComponentLoader.hpp> 44*cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProviderInterception.hpp> 45*cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp> 46*cdf0e10cSrcweir #include <com/sun/star/embed/EmbedMapUnits.hpp> 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx> 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir #include "specialobject.hxx" 51*cdf0e10cSrcweir #include "intercept.hxx" 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir using namespace ::com::sun::star; 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir OSpecialEmbeddedObject::OSpecialEmbeddedObject( const uno::Reference< lang::XMultiServiceFactory >& xFactory, const uno::Sequence< beans::NamedValue >& aObjectProps ) 57*cdf0e10cSrcweir : OCommonEmbeddedObject( xFactory, aObjectProps ) 58*cdf0e10cSrcweir { 59*cdf0e10cSrcweir maSize.Width = maSize.Height = 10000; 60*cdf0e10cSrcweir m_nObjectState = embed::EmbedStates::LOADED; 61*cdf0e10cSrcweir } 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir //------------------------------------------------------ 64*cdf0e10cSrcweir uno::Any SAL_CALL OSpecialEmbeddedObject::queryInterface( const uno::Type& rType ) 65*cdf0e10cSrcweir throw( uno::RuntimeException ) 66*cdf0e10cSrcweir { 67*cdf0e10cSrcweir uno::Any aReturn; 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir aReturn <<= ::cppu::queryInterface( rType, 70*cdf0e10cSrcweir static_cast< embed::XEmbeddedObject* >( this ), 71*cdf0e10cSrcweir static_cast< embed::XInplaceObject* >( this ), 72*cdf0e10cSrcweir static_cast< embed::XVisualObject* >( this ), 73*cdf0e10cSrcweir static_cast< embed::XClassifiedObject* >( this ), 74*cdf0e10cSrcweir static_cast< embed::XComponentSupplier* >( this ), 75*cdf0e10cSrcweir static_cast< util::XCloseable* >( this ), 76*cdf0e10cSrcweir static_cast< document::XEventBroadcaster* >( this ) ); 77*cdf0e10cSrcweir if ( aReturn.hasValue() ) 78*cdf0e10cSrcweir return aReturn; 79*cdf0e10cSrcweir else 80*cdf0e10cSrcweir return ::cppu::OWeakObject::queryInterface( rType ) ; 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir } 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir //------------------------------------------------------ 85*cdf0e10cSrcweir uno::Sequence< uno::Type > SAL_CALL OSpecialEmbeddedObject::getTypes() 86*cdf0e10cSrcweir throw( uno::RuntimeException ) 87*cdf0e10cSrcweir { 88*cdf0e10cSrcweir static ::cppu::OTypeCollection* pTypeCollection = NULL; 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir if ( !pTypeCollection ) 91*cdf0e10cSrcweir { 92*cdf0e10cSrcweir ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); 93*cdf0e10cSrcweir if ( !pTypeCollection ) 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir static ::cppu::OTypeCollection aTypeCollection( 96*cdf0e10cSrcweir ::getCppuType( (const uno::Reference< lang::XTypeProvider >*)NULL ), 97*cdf0e10cSrcweir ::getCppuType( (const uno::Reference< embed::XEmbeddedObject >*)NULL ), 98*cdf0e10cSrcweir ::getCppuType( (const uno::Reference< embed::XInplaceObject >*)NULL ) ); 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir pTypeCollection = &aTypeCollection ; 101*cdf0e10cSrcweir } 102*cdf0e10cSrcweir } 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir return pTypeCollection->getTypes() ; 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir } 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir embed::VisualRepresentation SAL_CALL OSpecialEmbeddedObject::getPreferredVisualRepresentation( sal_Int64 nAspect ) 109*cdf0e10cSrcweir throw ( lang::IllegalArgumentException, 110*cdf0e10cSrcweir embed::WrongStateException, 111*cdf0e10cSrcweir uno::Exception, 112*cdf0e10cSrcweir uno::RuntimeException ) 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 115*cdf0e10cSrcweir if ( m_bDisposed ) 116*cdf0e10cSrcweir throw lang::DisposedException(); // TODO 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir // TODO: if object is in loaded state it should switch itself to the running state 119*cdf0e10cSrcweir if ( m_nObjectState == -1 || m_nObjectState == embed::EmbedStates::LOADED ) 120*cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The own object has no model!\n" ), 121*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" ); 124*cdf0e10cSrcweir if ( nAspect == embed::Aspects::MSOLE_ICON ) 125*cdf0e10cSrcweir // no representation can be retrieved 126*cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ), 127*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir // TODO: return for the aspect of the document 130*cdf0e10cSrcweir embed::VisualRepresentation aVisualRepresentation; 131*cdf0e10cSrcweir /* 132*cdf0e10cSrcweir OSL_ENSURE( m_pDocHolder->GetComponent().is(), "Running or Active object has no component!\n" ); 133*cdf0e10cSrcweir uno::Reference< datatransfer::XTransferable > xTransferable( m_pDocHolder->GetComponent(), uno::UNO_QUERY ); 134*cdf0e10cSrcweir if ( !xTransferable.is() ) 135*cdf0e10cSrcweir throw uno::RuntimeException(); 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir datatransfer::DataFlavor aDataFlavor( 138*cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" ), 139*cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "GDIMetaFile" ), 140*cdf0e10cSrcweir ::getCppuType( (const uno::Sequence< sal_Int8 >*) NULL ) ); 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir aVisualRepresentation.Data = xTransferable->getTransferData( aDataFlavor ); 143*cdf0e10cSrcweir aVisualRepresentation.Flavor = aDataFlavor;*/ 144*cdf0e10cSrcweir return aVisualRepresentation; 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir void SAL_CALL OSpecialEmbeddedObject::setVisualAreaSize( sal_Int64 nAspect, const awt::Size& aSize ) 148*cdf0e10cSrcweir throw ( lang::IllegalArgumentException, 149*cdf0e10cSrcweir embed::WrongStateException, 150*cdf0e10cSrcweir uno::Exception, 151*cdf0e10cSrcweir uno::RuntimeException ) 152*cdf0e10cSrcweir { 153*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 154*cdf0e10cSrcweir if ( m_bDisposed ) 155*cdf0e10cSrcweir throw lang::DisposedException(); // TODO 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" ); 158*cdf0e10cSrcweir if ( nAspect == embed::Aspects::MSOLE_ICON ) 159*cdf0e10cSrcweir // no representation can be retrieved 160*cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ), 161*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir maSize = aSize; 164*cdf0e10cSrcweir } 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir awt::Size SAL_CALL OSpecialEmbeddedObject::getVisualAreaSize( sal_Int64 nAspect ) 167*cdf0e10cSrcweir throw ( lang::IllegalArgumentException, 168*cdf0e10cSrcweir embed::WrongStateException, 169*cdf0e10cSrcweir uno::Exception, 170*cdf0e10cSrcweir uno::RuntimeException ) 171*cdf0e10cSrcweir { 172*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 173*cdf0e10cSrcweir if ( m_bDisposed ) 174*cdf0e10cSrcweir throw lang::DisposedException(); // TODO 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" ); 177*cdf0e10cSrcweir if ( nAspect == embed::Aspects::MSOLE_ICON ) 178*cdf0e10cSrcweir // no representation can be retrieved 179*cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ), 180*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir if ( m_nObjectState == -1 ) 183*cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The own object has no model!\n" ), 184*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir awt::Size aResult; 187*cdf0e10cSrcweir return maSize; 188*cdf0e10cSrcweir } 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir sal_Int32 SAL_CALL OSpecialEmbeddedObject::getMapUnit( sal_Int64 nAspect ) 191*cdf0e10cSrcweir throw ( uno::Exception, 192*cdf0e10cSrcweir uno::RuntimeException) 193*cdf0e10cSrcweir { 194*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 195*cdf0e10cSrcweir if ( m_bDisposed ) 196*cdf0e10cSrcweir throw lang::DisposedException(); // TODO 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" ); 199*cdf0e10cSrcweir if ( nAspect == embed::Aspects::MSOLE_ICON ) 200*cdf0e10cSrcweir // no representation can be retrieved 201*cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ), 202*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir return embed::EmbedMapUnits::ONE_100TH_MM; 205*cdf0e10cSrcweir } 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir void SAL_CALL OSpecialEmbeddedObject::changeState( sal_Int32 nNewState ) 208*cdf0e10cSrcweir throw ( ::com::sun::star::embed::UnreachableStateException, 209*cdf0e10cSrcweir ::com::sun::star::embed::WrongStateException, 210*cdf0e10cSrcweir ::com::sun::star::uno::Exception, 211*cdf0e10cSrcweir ::com::sun::star::uno::RuntimeException ) 212*cdf0e10cSrcweir { 213*cdf0e10cSrcweir if ( nNewState == embed::EmbedStates::UI_ACTIVE ) 214*cdf0e10cSrcweir nNewState = embed::EmbedStates::INPLACE_ACTIVE; 215*cdf0e10cSrcweir OCommonEmbeddedObject::changeState( nNewState ); 216*cdf0e10cSrcweir } 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir void SAL_CALL OSpecialEmbeddedObject::doVerb( sal_Int32 nVerbID ) 219*cdf0e10cSrcweir throw ( lang::IllegalArgumentException, 220*cdf0e10cSrcweir embed::WrongStateException, 221*cdf0e10cSrcweir embed::UnreachableStateException, 222*cdf0e10cSrcweir uno::Exception, 223*cdf0e10cSrcweir uno::RuntimeException ) 224*cdf0e10cSrcweir { 225*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 226*cdf0e10cSrcweir if ( m_bDisposed ) 227*cdf0e10cSrcweir throw lang::DisposedException(); // TODO 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir if ( m_nObjectState == -1 ) 230*cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ), 231*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 232*cdf0e10cSrcweir 233*cdf0e10cSrcweir if ( nVerbID == -7 ) 234*cdf0e10cSrcweir { 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir uno::Reference < ui::dialogs::XExecutableDialog > xDlg( m_pDocHolder->GetComponent(), uno::UNO_QUERY ); 237*cdf0e10cSrcweir if ( xDlg.is() ) 238*cdf0e10cSrcweir xDlg->execute(); 239*cdf0e10cSrcweir else 240*cdf0e10cSrcweir throw embed::UnreachableStateException(); 241*cdf0e10cSrcweir } 242*cdf0e10cSrcweir else 243*cdf0e10cSrcweir OCommonEmbeddedObject::doVerb( nVerbID ); 244*cdf0e10cSrcweir } 245*cdf0e10cSrcweir 246