1*bfd08df8SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*bfd08df8SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*bfd08df8SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*bfd08df8SAndrew Rist * distributed with this work for additional information 6*bfd08df8SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*bfd08df8SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*bfd08df8SAndrew Rist * "License"); you may not use this file except in compliance 9*bfd08df8SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*bfd08df8SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*bfd08df8SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*bfd08df8SAndrew Rist * software distributed under the License is distributed on an 15*bfd08df8SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*bfd08df8SAndrew Rist * KIND, either express or implied. See the License for the 17*bfd08df8SAndrew Rist * specific language governing permissions and limitations 18*bfd08df8SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*bfd08df8SAndrew Rist *************************************************************/ 21*bfd08df8SAndrew Rist 22*bfd08df8SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_embeddedobj.hxx" 26cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp> 27cdf0e10cSrcweir #include <com/sun/star/embed/EmbedStates.hpp> 28cdf0e10cSrcweir #include <com/sun/star/embed/EmbedVerbs.hpp> 29cdf0e10cSrcweir #include <com/sun/star/embed/EmbedUpdateModes.hpp> 30cdf0e10cSrcweir #include <com/sun/star/embed/XEmbeddedClient.hpp> 31cdf0e10cSrcweir #include <com/sun/star/embed/XInplaceClient.hpp> 32cdf0e10cSrcweir #include <com/sun/star/embed/XWindowSupplier.hpp> 33cdf0e10cSrcweir #include <com/sun/star/embed/Aspects.hpp> 34cdf0e10cSrcweir #include <com/sun/star/awt/XWindowPeer.hpp> 35cdf0e10cSrcweir #include <com/sun/star/util/XCloseBroadcaster.hpp> 36cdf0e10cSrcweir #include <com/sun/star/util/XCloseable.hpp> 37cdf0e10cSrcweir #include <com/sun/star/util/XModifiable.hpp> 38cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp> 39cdf0e10cSrcweir #include <com/sun/star/frame/XComponentLoader.hpp> 40cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProviderInterception.hpp> 41cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp> 42cdf0e10cSrcweir #include <com/sun/star/embed/EmbedMapUnits.hpp> 43cdf0e10cSrcweir 44cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx> 45cdf0e10cSrcweir 46cdf0e10cSrcweir #include "specialobject.hxx" 47cdf0e10cSrcweir #include "intercept.hxx" 48cdf0e10cSrcweir 49cdf0e10cSrcweir using namespace ::com::sun::star; 50cdf0e10cSrcweir 51cdf0e10cSrcweir 52cdf0e10cSrcweir OSpecialEmbeddedObject::OSpecialEmbeddedObject( const uno::Reference< lang::XMultiServiceFactory >& xFactory, const uno::Sequence< beans::NamedValue >& aObjectProps ) 53cdf0e10cSrcweir : OCommonEmbeddedObject( xFactory, aObjectProps ) 54cdf0e10cSrcweir { 55cdf0e10cSrcweir maSize.Width = maSize.Height = 10000; 56cdf0e10cSrcweir m_nObjectState = embed::EmbedStates::LOADED; 57cdf0e10cSrcweir } 58cdf0e10cSrcweir 59cdf0e10cSrcweir //------------------------------------------------------ 60cdf0e10cSrcweir uno::Any SAL_CALL OSpecialEmbeddedObject::queryInterface( const uno::Type& rType ) 61cdf0e10cSrcweir throw( uno::RuntimeException ) 62cdf0e10cSrcweir { 63cdf0e10cSrcweir uno::Any aReturn; 64cdf0e10cSrcweir 65cdf0e10cSrcweir aReturn <<= ::cppu::queryInterface( rType, 66cdf0e10cSrcweir static_cast< embed::XEmbeddedObject* >( this ), 67cdf0e10cSrcweir static_cast< embed::XInplaceObject* >( this ), 68cdf0e10cSrcweir static_cast< embed::XVisualObject* >( this ), 69cdf0e10cSrcweir static_cast< embed::XClassifiedObject* >( this ), 70cdf0e10cSrcweir static_cast< embed::XComponentSupplier* >( this ), 71cdf0e10cSrcweir static_cast< util::XCloseable* >( this ), 72cdf0e10cSrcweir static_cast< document::XEventBroadcaster* >( this ) ); 73cdf0e10cSrcweir if ( aReturn.hasValue() ) 74cdf0e10cSrcweir return aReturn; 75cdf0e10cSrcweir else 76cdf0e10cSrcweir return ::cppu::OWeakObject::queryInterface( rType ) ; 77cdf0e10cSrcweir 78cdf0e10cSrcweir } 79cdf0e10cSrcweir 80cdf0e10cSrcweir //------------------------------------------------------ 81cdf0e10cSrcweir uno::Sequence< uno::Type > SAL_CALL OSpecialEmbeddedObject::getTypes() 82cdf0e10cSrcweir throw( uno::RuntimeException ) 83cdf0e10cSrcweir { 84cdf0e10cSrcweir static ::cppu::OTypeCollection* pTypeCollection = NULL; 85cdf0e10cSrcweir 86cdf0e10cSrcweir if ( !pTypeCollection ) 87cdf0e10cSrcweir { 88cdf0e10cSrcweir ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); 89cdf0e10cSrcweir if ( !pTypeCollection ) 90cdf0e10cSrcweir { 91cdf0e10cSrcweir static ::cppu::OTypeCollection aTypeCollection( 92cdf0e10cSrcweir ::getCppuType( (const uno::Reference< lang::XTypeProvider >*)NULL ), 93cdf0e10cSrcweir ::getCppuType( (const uno::Reference< embed::XEmbeddedObject >*)NULL ), 94cdf0e10cSrcweir ::getCppuType( (const uno::Reference< embed::XInplaceObject >*)NULL ) ); 95cdf0e10cSrcweir 96cdf0e10cSrcweir pTypeCollection = &aTypeCollection ; 97cdf0e10cSrcweir } 98cdf0e10cSrcweir } 99cdf0e10cSrcweir 100cdf0e10cSrcweir return pTypeCollection->getTypes() ; 101cdf0e10cSrcweir 102cdf0e10cSrcweir } 103cdf0e10cSrcweir 104cdf0e10cSrcweir embed::VisualRepresentation SAL_CALL OSpecialEmbeddedObject::getPreferredVisualRepresentation( sal_Int64 nAspect ) 105cdf0e10cSrcweir throw ( lang::IllegalArgumentException, 106cdf0e10cSrcweir embed::WrongStateException, 107cdf0e10cSrcweir uno::Exception, 108cdf0e10cSrcweir uno::RuntimeException ) 109cdf0e10cSrcweir { 110cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 111cdf0e10cSrcweir if ( m_bDisposed ) 112cdf0e10cSrcweir throw lang::DisposedException(); // TODO 113cdf0e10cSrcweir 114cdf0e10cSrcweir // TODO: if object is in loaded state it should switch itself to the running state 115cdf0e10cSrcweir if ( m_nObjectState == -1 || m_nObjectState == embed::EmbedStates::LOADED ) 116cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The own object has no model!\n" ), 117cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 118cdf0e10cSrcweir 119cdf0e10cSrcweir OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" ); 120cdf0e10cSrcweir if ( nAspect == embed::Aspects::MSOLE_ICON ) 121cdf0e10cSrcweir // no representation can be retrieved 122cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ), 123cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 124cdf0e10cSrcweir 125cdf0e10cSrcweir // TODO: return for the aspect of the document 126cdf0e10cSrcweir embed::VisualRepresentation aVisualRepresentation; 127cdf0e10cSrcweir /* 128cdf0e10cSrcweir OSL_ENSURE( m_pDocHolder->GetComponent().is(), "Running or Active object has no component!\n" ); 129cdf0e10cSrcweir uno::Reference< datatransfer::XTransferable > xTransferable( m_pDocHolder->GetComponent(), uno::UNO_QUERY ); 130cdf0e10cSrcweir if ( !xTransferable.is() ) 131cdf0e10cSrcweir throw uno::RuntimeException(); 132cdf0e10cSrcweir 133cdf0e10cSrcweir datatransfer::DataFlavor aDataFlavor( 134cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" ), 135cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "GDIMetaFile" ), 136cdf0e10cSrcweir ::getCppuType( (const uno::Sequence< sal_Int8 >*) NULL ) ); 137cdf0e10cSrcweir 138cdf0e10cSrcweir aVisualRepresentation.Data = xTransferable->getTransferData( aDataFlavor ); 139cdf0e10cSrcweir aVisualRepresentation.Flavor = aDataFlavor;*/ 140cdf0e10cSrcweir return aVisualRepresentation; 141cdf0e10cSrcweir } 142cdf0e10cSrcweir 143cdf0e10cSrcweir void SAL_CALL OSpecialEmbeddedObject::setVisualAreaSize( sal_Int64 nAspect, const awt::Size& aSize ) 144cdf0e10cSrcweir throw ( lang::IllegalArgumentException, 145cdf0e10cSrcweir embed::WrongStateException, 146cdf0e10cSrcweir uno::Exception, 147cdf0e10cSrcweir uno::RuntimeException ) 148cdf0e10cSrcweir { 149cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 150cdf0e10cSrcweir if ( m_bDisposed ) 151cdf0e10cSrcweir throw lang::DisposedException(); // TODO 152cdf0e10cSrcweir 153cdf0e10cSrcweir OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" ); 154cdf0e10cSrcweir if ( nAspect == embed::Aspects::MSOLE_ICON ) 155cdf0e10cSrcweir // no representation can be retrieved 156cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ), 157cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 158cdf0e10cSrcweir 159cdf0e10cSrcweir maSize = aSize; 160cdf0e10cSrcweir } 161cdf0e10cSrcweir 162cdf0e10cSrcweir awt::Size SAL_CALL OSpecialEmbeddedObject::getVisualAreaSize( sal_Int64 nAspect ) 163cdf0e10cSrcweir throw ( lang::IllegalArgumentException, 164cdf0e10cSrcweir embed::WrongStateException, 165cdf0e10cSrcweir uno::Exception, 166cdf0e10cSrcweir uno::RuntimeException ) 167cdf0e10cSrcweir { 168cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 169cdf0e10cSrcweir if ( m_bDisposed ) 170cdf0e10cSrcweir throw lang::DisposedException(); // TODO 171cdf0e10cSrcweir 172cdf0e10cSrcweir OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" ); 173cdf0e10cSrcweir if ( nAspect == embed::Aspects::MSOLE_ICON ) 174cdf0e10cSrcweir // no representation can be retrieved 175cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ), 176cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 177cdf0e10cSrcweir 178cdf0e10cSrcweir if ( m_nObjectState == -1 ) 179cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The own object has no model!\n" ), 180cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 181cdf0e10cSrcweir 182cdf0e10cSrcweir awt::Size aResult; 183cdf0e10cSrcweir return maSize; 184cdf0e10cSrcweir } 185cdf0e10cSrcweir 186cdf0e10cSrcweir sal_Int32 SAL_CALL OSpecialEmbeddedObject::getMapUnit( sal_Int64 nAspect ) 187cdf0e10cSrcweir throw ( uno::Exception, 188cdf0e10cSrcweir uno::RuntimeException) 189cdf0e10cSrcweir { 190cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 191cdf0e10cSrcweir if ( m_bDisposed ) 192cdf0e10cSrcweir throw lang::DisposedException(); // TODO 193cdf0e10cSrcweir 194cdf0e10cSrcweir OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" ); 195cdf0e10cSrcweir if ( nAspect == embed::Aspects::MSOLE_ICON ) 196cdf0e10cSrcweir // no representation can be retrieved 197cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ), 198cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 199cdf0e10cSrcweir 200cdf0e10cSrcweir return embed::EmbedMapUnits::ONE_100TH_MM; 201cdf0e10cSrcweir } 202cdf0e10cSrcweir 203cdf0e10cSrcweir void SAL_CALL OSpecialEmbeddedObject::changeState( sal_Int32 nNewState ) 204cdf0e10cSrcweir throw ( ::com::sun::star::embed::UnreachableStateException, 205cdf0e10cSrcweir ::com::sun::star::embed::WrongStateException, 206cdf0e10cSrcweir ::com::sun::star::uno::Exception, 207cdf0e10cSrcweir ::com::sun::star::uno::RuntimeException ) 208cdf0e10cSrcweir { 209cdf0e10cSrcweir if ( nNewState == embed::EmbedStates::UI_ACTIVE ) 210cdf0e10cSrcweir nNewState = embed::EmbedStates::INPLACE_ACTIVE; 211cdf0e10cSrcweir OCommonEmbeddedObject::changeState( nNewState ); 212cdf0e10cSrcweir } 213cdf0e10cSrcweir 214cdf0e10cSrcweir void SAL_CALL OSpecialEmbeddedObject::doVerb( sal_Int32 nVerbID ) 215cdf0e10cSrcweir throw ( lang::IllegalArgumentException, 216cdf0e10cSrcweir embed::WrongStateException, 217cdf0e10cSrcweir embed::UnreachableStateException, 218cdf0e10cSrcweir uno::Exception, 219cdf0e10cSrcweir uno::RuntimeException ) 220cdf0e10cSrcweir { 221cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 222cdf0e10cSrcweir if ( m_bDisposed ) 223cdf0e10cSrcweir throw lang::DisposedException(); // TODO 224cdf0e10cSrcweir 225cdf0e10cSrcweir if ( m_nObjectState == -1 ) 226cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ), 227cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 228cdf0e10cSrcweir 229cdf0e10cSrcweir if ( nVerbID == -7 ) 230cdf0e10cSrcweir { 231cdf0e10cSrcweir 232cdf0e10cSrcweir uno::Reference < ui::dialogs::XExecutableDialog > xDlg( m_pDocHolder->GetComponent(), uno::UNO_QUERY ); 233cdf0e10cSrcweir if ( xDlg.is() ) 234cdf0e10cSrcweir xDlg->execute(); 235cdf0e10cSrcweir else 236cdf0e10cSrcweir throw embed::UnreachableStateException(); 237cdf0e10cSrcweir } 238cdf0e10cSrcweir else 239cdf0e10cSrcweir OCommonEmbeddedObject::doVerb( nVerbID ); 240cdf0e10cSrcweir } 241cdf0e10cSrcweir 242