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 31*cdf0e10cSrcweir #include "plugin.hxx" 32*cdf0e10cSrcweir #include <com/sun/star/plugin/XPluginManager.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/plugin/PluginMode.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/awt/XControl.hpp> 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir #include <tools/debug.hxx> 37*cdf0e10cSrcweir #include <rtl/ustring.hxx> 38*cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx> 39*cdf0e10cSrcweir #include <svtools/miscopt.hxx> 40*cdf0e10cSrcweir #include <vcl/window.hxx> 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir using namespace ::com::sun::star; 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir namespace sfx2 45*cdf0e10cSrcweir { 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir class PluginWindow_Impl : public Window 48*cdf0e10cSrcweir { 49*cdf0e10cSrcweir public: 50*cdf0e10cSrcweir uno::Reference < awt::XWindow > xWindow; 51*cdf0e10cSrcweir PluginWindow_Impl( Window* pParent ) 52*cdf0e10cSrcweir : Window( pParent, WB_CLIPCHILDREN ) 53*cdf0e10cSrcweir {} 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir virtual void Resize(); 56*cdf0e10cSrcweir }; 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir void PluginWindow_Impl::Resize() 59*cdf0e10cSrcweir { 60*cdf0e10cSrcweir Size aSize( GetOutputSizePixel() ); 61*cdf0e10cSrcweir if ( xWindow.is() ) 62*cdf0e10cSrcweir xWindow->setPosSize( 0, 0, aSize.Width(), aSize.Height(), WINDOW_POSSIZE_SIZE ); 63*cdf0e10cSrcweir } 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir #define PROPERTY_UNBOUND 0 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir #define WID_COMMANDS 1 68*cdf0e10cSrcweir #define WID_MIMETYPE 2 69*cdf0e10cSrcweir #define WID_URL 3 70*cdf0e10cSrcweir const SfxItemPropertyMapEntry* lcl_GetPluginPropertyMap_Impl() 71*cdf0e10cSrcweir { 72*cdf0e10cSrcweir static SfxItemPropertyMapEntry aPluginPropertyMap_Impl[] = 73*cdf0e10cSrcweir { 74*cdf0e10cSrcweir { MAP_CHAR_LEN("PluginCommands"), WID_COMMANDS, &::getCppuType((::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >*)0), PROPERTY_UNBOUND, 0}, 75*cdf0e10cSrcweir { MAP_CHAR_LEN("PluginMimeType"), WID_MIMETYPE, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 }, 76*cdf0e10cSrcweir { MAP_CHAR_LEN("PluginURL"), WID_URL , &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 }, 77*cdf0e10cSrcweir {0,0,0,0,0,0} 78*cdf0e10cSrcweir }; 79*cdf0e10cSrcweir return aPluginPropertyMap_Impl; 80*cdf0e10cSrcweir } 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir SFX_IMPL_XSERVICEINFO( PluginObject, "com.sun.star.embed.SpecialEmbeddedObject", "com.sun.star.comp.sfx2.PluginObject" ) 83*cdf0e10cSrcweir SFX_IMPL_SINGLEFACTORY( PluginObject ); 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir PluginObject::PluginObject( const uno::Reference < lang::XMultiServiceFactory >& rFact ) 86*cdf0e10cSrcweir : mxFact( rFact ) 87*cdf0e10cSrcweir , maPropMap( lcl_GetPluginPropertyMap_Impl() ) 88*cdf0e10cSrcweir { 89*cdf0e10cSrcweir } 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir PluginObject::~PluginObject() 92*cdf0e10cSrcweir { 93*cdf0e10cSrcweir } 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir void SAL_CALL PluginObject::initialize( const uno::Sequence< uno::Any >& aArguments ) throw ( uno::Exception, uno::RuntimeException ) 96*cdf0e10cSrcweir { 97*cdf0e10cSrcweir if ( aArguments.getLength() ) 98*cdf0e10cSrcweir aArguments[0] >>= mxObj; 99*cdf0e10cSrcweir } 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir sal_Bool SAL_CALL PluginObject::load( 102*cdf0e10cSrcweir const uno::Sequence < com::sun::star::beans::PropertyValue >& /*lDescriptor*/, 103*cdf0e10cSrcweir const uno::Reference < frame::XFrame >& xFrame ) 104*cdf0e10cSrcweir throw( uno::RuntimeException ) 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir uno::Reference< plugin::XPluginManager > xPMgr( mxFact->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.plugin.PluginManager") ), uno::UNO_QUERY ); 107*cdf0e10cSrcweir if (!xPMgr.is() ) 108*cdf0e10cSrcweir return sal_False; 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir if ( SvtMiscOptions().IsPluginsEnabled() ) 111*cdf0e10cSrcweir { 112*cdf0e10cSrcweir Window* pParent = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() ); 113*cdf0e10cSrcweir PluginWindow_Impl* pWin = new PluginWindow_Impl( pParent ); 114*cdf0e10cSrcweir pWin->SetSizePixel( pParent->GetOutputSizePixel() ); 115*cdf0e10cSrcweir pWin->SetBackground(); 116*cdf0e10cSrcweir pWin->Show(); 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir sal_uIntPtr nCount = maCmdList.Count(); 119*cdf0e10cSrcweir uno::Sequence < ::rtl::OUString > aCmds( nCount ), aArgs( nCount ); 120*cdf0e10cSrcweir ::rtl::OUString *pCmds = aCmds.getArray(), *pArgs = aArgs.getArray(); 121*cdf0e10cSrcweir for( sal_uIntPtr i = 0; i < nCount; i++ ) 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir SvCommand & rCmd = maCmdList.GetObject( i ); 124*cdf0e10cSrcweir pCmds[i] = rCmd.GetCommand(); 125*cdf0e10cSrcweir pArgs[i] = rCmd.GetArgument(); 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir mxPlugin = xPMgr->createPluginFromURL( 129*cdf0e10cSrcweir xPMgr->createPluginContext(), plugin::PluginMode::EMBED, aCmds, aArgs, uno::Reference< awt::XToolkit >(), 130*cdf0e10cSrcweir uno::Reference< awt::XWindowPeer >( pWin->GetComponentInterface() ), maURL ); 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir if ( mxPlugin.is() ) 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir uno::Reference< awt::XWindow > xWindow( mxPlugin, uno::UNO_QUERY ); 135*cdf0e10cSrcweir if ( xWindow.is() ) 136*cdf0e10cSrcweir { 137*cdf0e10cSrcweir pWin->xWindow = xWindow; 138*cdf0e10cSrcweir pWin->Resize(); 139*cdf0e10cSrcweir xWindow->setVisible( sal_True ); 140*cdf0e10cSrcweir } 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir try 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir uno::Reference< awt::XControl > xControl( mxPlugin, uno::UNO_QUERY ); 145*cdf0e10cSrcweir if( xControl.is() ) 146*cdf0e10cSrcweir { 147*cdf0e10cSrcweir uno::Reference< awt::XControlModel > xModel = xControl->getModel(); 148*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xProp( xModel, ::uno::UNO_QUERY ); 149*cdf0e10cSrcweir if( xProp.is() ) 150*cdf0e10cSrcweir { 151*cdf0e10cSrcweir uno::Any aValue = xProp->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) ) ); 152*cdf0e10cSrcweir aValue >>= maURL; 153*cdf0e10cSrcweir aValue = xProp->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "TYPE" ) ) ); 154*cdf0e10cSrcweir aValue >>= maMimeType; 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir } 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir catch( uno::Exception& ) 159*cdf0e10cSrcweir { 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir uno::Reference < awt::XWindow > xWindow( pWin->GetComponentInterface(), uno::UNO_QUERY ); 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir // we must destroy the plugin before the parent is destroyed 166*cdf0e10cSrcweir xWindow->addEventListener( this ); 167*cdf0e10cSrcweir xFrame->setComponent( xWindow, uno::Reference < frame::XController >() ); 168*cdf0e10cSrcweir return mxPlugin.is() ? sal_True : sal_False; 169*cdf0e10cSrcweir } 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir return sal_False; 172*cdf0e10cSrcweir } 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir void SAL_CALL PluginObject::cancel() throw( com::sun::star::uno::RuntimeException ) 175*cdf0e10cSrcweir { 176*cdf0e10cSrcweir uno::Reference< lang::XComponent > xComp( mxPlugin, uno::UNO_QUERY ); 177*cdf0e10cSrcweir if (xComp.is()) 178*cdf0e10cSrcweir xComp->dispose(); 179*cdf0e10cSrcweir mxPlugin = 0; 180*cdf0e10cSrcweir } 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir void SAL_CALL PluginObject::close( sal_Bool /*bDeliverOwnership*/ ) throw( com::sun::star::util::CloseVetoException, com::sun::star::uno::RuntimeException ) 183*cdf0e10cSrcweir { 184*cdf0e10cSrcweir } 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir void SAL_CALL PluginObject::addCloseListener( const com::sun::star::uno::Reference < com::sun::star::util::XCloseListener >& ) throw( com::sun::star::uno::RuntimeException ) 187*cdf0e10cSrcweir { 188*cdf0e10cSrcweir } 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir void SAL_CALL PluginObject::removeCloseListener( const com::sun::star::uno::Reference < com::sun::star::util::XCloseListener >& ) throw( com::sun::star::uno::RuntimeException ) 191*cdf0e10cSrcweir { 192*cdf0e10cSrcweir } 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir void SAL_CALL PluginObject::disposing( const com::sun::star::lang::EventObject& ) throw (com::sun::star::uno::RuntimeException) 195*cdf0e10cSrcweir { 196*cdf0e10cSrcweir cancel(); 197*cdf0e10cSrcweir } 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir uno::Reference< beans::XPropertySetInfo > SAL_CALL PluginObject::getPropertySetInfo() throw( ::com::sun::star::uno::RuntimeException ) 200*cdf0e10cSrcweir { 201*cdf0e10cSrcweir static uno::Reference< beans::XPropertySetInfo > xInfo = new SfxItemPropertySetInfo( &maPropMap ); 202*cdf0e10cSrcweir return xInfo; 203*cdf0e10cSrcweir } 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir void SAL_CALL PluginObject::setPropertyValue(const ::rtl::OUString& aPropertyName, const uno::Any& aAny) 206*cdf0e10cSrcweir throw ( beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException) 207*cdf0e10cSrcweir { 208*cdf0e10cSrcweir if ( aPropertyName.equalsAscii("PluginURL") ) 209*cdf0e10cSrcweir { 210*cdf0e10cSrcweir aAny >>= maURL; 211*cdf0e10cSrcweir } 212*cdf0e10cSrcweir else if ( aPropertyName.equalsAscii("PluginMimeType") ) 213*cdf0e10cSrcweir { 214*cdf0e10cSrcweir aAny >>= maMimeType; 215*cdf0e10cSrcweir } 216*cdf0e10cSrcweir else if ( aPropertyName.equalsAscii("PluginCommands") ) 217*cdf0e10cSrcweir { 218*cdf0e10cSrcweir maCmdList.Clear(); 219*cdf0e10cSrcweir uno::Sequence < beans::PropertyValue > aCommandSequence; 220*cdf0e10cSrcweir if( aAny >>= aCommandSequence ) 221*cdf0e10cSrcweir maCmdList.FillFromSequence( aCommandSequence ); 222*cdf0e10cSrcweir } 223*cdf0e10cSrcweir else 224*cdf0e10cSrcweir throw beans::UnknownPropertyException(); 225*cdf0e10cSrcweir } 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir uno::Any SAL_CALL PluginObject::getPropertyValue(const ::rtl::OUString& aPropertyName) 228*cdf0e10cSrcweir throw ( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) 229*cdf0e10cSrcweir { 230*cdf0e10cSrcweir uno::Any aAny; 231*cdf0e10cSrcweir if ( aPropertyName.equalsAscii("PluginURL") ) 232*cdf0e10cSrcweir { 233*cdf0e10cSrcweir aAny <<= maURL; 234*cdf0e10cSrcweir } 235*cdf0e10cSrcweir else if ( aPropertyName.equalsAscii("PluginMimeType") ) 236*cdf0e10cSrcweir { 237*cdf0e10cSrcweir aAny <<= maMimeType; 238*cdf0e10cSrcweir } 239*cdf0e10cSrcweir else if ( aPropertyName.equalsAscii("PluginCommands") ) 240*cdf0e10cSrcweir { 241*cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aCommandSequence; 242*cdf0e10cSrcweir maCmdList.FillSequence( aCommandSequence ); 243*cdf0e10cSrcweir aAny <<= aCommandSequence; 244*cdf0e10cSrcweir } 245*cdf0e10cSrcweir else 246*cdf0e10cSrcweir throw beans::UnknownPropertyException(); 247*cdf0e10cSrcweir return aAny; 248*cdf0e10cSrcweir } 249*cdf0e10cSrcweir 250*cdf0e10cSrcweir void SAL_CALL PluginObject::addPropertyChangeListener(const ::rtl::OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener > & ) throw( ::com::sun::star::uno::RuntimeException ) 251*cdf0e10cSrcweir { 252*cdf0e10cSrcweir } 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir void SAL_CALL PluginObject::removePropertyChangeListener(const ::rtl::OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener > & ) throw( ::com::sun::star::uno::RuntimeException ) 255*cdf0e10cSrcweir { 256*cdf0e10cSrcweir } 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir void SAL_CALL PluginObject::addVetoableChangeListener(const ::rtl::OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener > & ) throw( ::com::sun::star::uno::RuntimeException ) 259*cdf0e10cSrcweir { 260*cdf0e10cSrcweir } 261*cdf0e10cSrcweir 262*cdf0e10cSrcweir void SAL_CALL PluginObject::removeVetoableChangeListener(const ::rtl::OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener > & ) throw( ::com::sun::star::uno::RuntimeException ) 263*cdf0e10cSrcweir { 264*cdf0e10cSrcweir } 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir } 267