1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sfx2.hxx" 30 31 #include "plugin.hxx" 32 #include <com/sun/star/plugin/XPluginManager.hpp> 33 #include <com/sun/star/plugin/PluginMode.hpp> 34 #include <com/sun/star/awt/XControl.hpp> 35 36 #include <tools/debug.hxx> 37 #include <rtl/ustring.hxx> 38 #include <toolkit/helper/vclunohelper.hxx> 39 #include <svtools/miscopt.hxx> 40 #include <vcl/window.hxx> 41 42 using namespace ::com::sun::star; 43 44 namespace sfx2 45 { 46 47 class PluginWindow_Impl : public Window 48 { 49 public: 50 uno::Reference < awt::XWindow > xWindow; 51 PluginWindow_Impl( Window* pParent ) 52 : Window( pParent, WB_CLIPCHILDREN ) 53 {} 54 55 virtual void Resize(); 56 }; 57 58 void PluginWindow_Impl::Resize() 59 { 60 Size aSize( GetOutputSizePixel() ); 61 if ( xWindow.is() ) 62 xWindow->setPosSize( 0, 0, aSize.Width(), aSize.Height(), WINDOW_POSSIZE_SIZE ); 63 } 64 65 #define PROPERTY_UNBOUND 0 66 67 #define WID_COMMANDS 1 68 #define WID_MIMETYPE 2 69 #define WID_URL 3 70 const SfxItemPropertyMapEntry* lcl_GetPluginPropertyMap_Impl() 71 { 72 static SfxItemPropertyMapEntry aPluginPropertyMap_Impl[] = 73 { 74 { MAP_CHAR_LEN("PluginCommands"), WID_COMMANDS, &::getCppuType((::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >*)0), PROPERTY_UNBOUND, 0}, 75 { MAP_CHAR_LEN("PluginMimeType"), WID_MIMETYPE, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 }, 76 { MAP_CHAR_LEN("PluginURL"), WID_URL , &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 }, 77 {0,0,0,0,0,0} 78 }; 79 return aPluginPropertyMap_Impl; 80 } 81 82 SFX_IMPL_XSERVICEINFO( PluginObject, "com.sun.star.embed.SpecialEmbeddedObject", "com.sun.star.comp.sfx2.PluginObject" ) 83 SFX_IMPL_SINGLEFACTORY( PluginObject ); 84 85 PluginObject::PluginObject( const uno::Reference < lang::XMultiServiceFactory >& rFact ) 86 : mxFact( rFact ) 87 , maPropMap( lcl_GetPluginPropertyMap_Impl() ) 88 { 89 } 90 91 PluginObject::~PluginObject() 92 { 93 } 94 95 void SAL_CALL PluginObject::initialize( const uno::Sequence< uno::Any >& aArguments ) throw ( uno::Exception, uno::RuntimeException ) 96 { 97 if ( aArguments.getLength() ) 98 aArguments[0] >>= mxObj; 99 } 100 101 sal_Bool SAL_CALL PluginObject::load( 102 const uno::Sequence < com::sun::star::beans::PropertyValue >& /*lDescriptor*/, 103 const uno::Reference < frame::XFrame >& xFrame ) 104 throw( uno::RuntimeException ) 105 { 106 uno::Reference< plugin::XPluginManager > xPMgr( mxFact->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.plugin.PluginManager") ), uno::UNO_QUERY ); 107 if (!xPMgr.is() ) 108 return sal_False; 109 110 if ( SvtMiscOptions().IsPluginsEnabled() ) 111 { 112 Window* pParent = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() ); 113 PluginWindow_Impl* pWin = new PluginWindow_Impl( pParent ); 114 pWin->SetSizePixel( pParent->GetOutputSizePixel() ); 115 pWin->SetBackground(); 116 pWin->Show(); 117 118 sal_uIntPtr nCount = maCmdList.Count(); 119 uno::Sequence < ::rtl::OUString > aCmds( nCount ), aArgs( nCount ); 120 ::rtl::OUString *pCmds = aCmds.getArray(), *pArgs = aArgs.getArray(); 121 for( sal_uIntPtr i = 0; i < nCount; i++ ) 122 { 123 SvCommand & rCmd = maCmdList.GetObject( i ); 124 pCmds[i] = rCmd.GetCommand(); 125 pArgs[i] = rCmd.GetArgument(); 126 } 127 128 mxPlugin = xPMgr->createPluginFromURL( 129 xPMgr->createPluginContext(), plugin::PluginMode::EMBED, aCmds, aArgs, uno::Reference< awt::XToolkit >(), 130 uno::Reference< awt::XWindowPeer >( pWin->GetComponentInterface() ), maURL ); 131 132 if ( mxPlugin.is() ) 133 { 134 uno::Reference< awt::XWindow > xWindow( mxPlugin, uno::UNO_QUERY ); 135 if ( xWindow.is() ) 136 { 137 pWin->xWindow = xWindow; 138 pWin->Resize(); 139 xWindow->setVisible( sal_True ); 140 } 141 142 try 143 { 144 uno::Reference< awt::XControl > xControl( mxPlugin, uno::UNO_QUERY ); 145 if( xControl.is() ) 146 { 147 uno::Reference< awt::XControlModel > xModel = xControl->getModel(); 148 uno::Reference< beans::XPropertySet > xProp( xModel, ::uno::UNO_QUERY ); 149 if( xProp.is() ) 150 { 151 uno::Any aValue = xProp->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) ) ); 152 aValue >>= maURL; 153 aValue = xProp->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "TYPE" ) ) ); 154 aValue >>= maMimeType; 155 } 156 } 157 } 158 catch( uno::Exception& ) 159 { 160 } 161 } 162 163 uno::Reference < awt::XWindow > xWindow( pWin->GetComponentInterface(), uno::UNO_QUERY ); 164 165 // we must destroy the plugin before the parent is destroyed 166 xWindow->addEventListener( this ); 167 xFrame->setComponent( xWindow, uno::Reference < frame::XController >() ); 168 return mxPlugin.is() ? sal_True : sal_False; 169 } 170 171 return sal_False; 172 } 173 174 void SAL_CALL PluginObject::cancel() throw( com::sun::star::uno::RuntimeException ) 175 { 176 uno::Reference< lang::XComponent > xComp( mxPlugin, uno::UNO_QUERY ); 177 if (xComp.is()) 178 xComp->dispose(); 179 mxPlugin = 0; 180 } 181 182 void SAL_CALL PluginObject::close( sal_Bool /*bDeliverOwnership*/ ) throw( com::sun::star::util::CloseVetoException, com::sun::star::uno::RuntimeException ) 183 { 184 } 185 186 void SAL_CALL PluginObject::addCloseListener( const com::sun::star::uno::Reference < com::sun::star::util::XCloseListener >& ) throw( com::sun::star::uno::RuntimeException ) 187 { 188 } 189 190 void SAL_CALL PluginObject::removeCloseListener( const com::sun::star::uno::Reference < com::sun::star::util::XCloseListener >& ) throw( com::sun::star::uno::RuntimeException ) 191 { 192 } 193 194 void SAL_CALL PluginObject::disposing( const com::sun::star::lang::EventObject& ) throw (com::sun::star::uno::RuntimeException) 195 { 196 cancel(); 197 } 198 199 uno::Reference< beans::XPropertySetInfo > SAL_CALL PluginObject::getPropertySetInfo() throw( ::com::sun::star::uno::RuntimeException ) 200 { 201 static uno::Reference< beans::XPropertySetInfo > xInfo = new SfxItemPropertySetInfo( &maPropMap ); 202 return xInfo; 203 } 204 205 void SAL_CALL PluginObject::setPropertyValue(const ::rtl::OUString& aPropertyName, const uno::Any& aAny) 206 throw ( beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException) 207 { 208 if ( aPropertyName.equalsAscii("PluginURL") ) 209 { 210 aAny >>= maURL; 211 } 212 else if ( aPropertyName.equalsAscii("PluginMimeType") ) 213 { 214 aAny >>= maMimeType; 215 } 216 else if ( aPropertyName.equalsAscii("PluginCommands") ) 217 { 218 maCmdList.Clear(); 219 uno::Sequence < beans::PropertyValue > aCommandSequence; 220 if( aAny >>= aCommandSequence ) 221 maCmdList.FillFromSequence( aCommandSequence ); 222 } 223 else 224 throw beans::UnknownPropertyException(); 225 } 226 227 uno::Any SAL_CALL PluginObject::getPropertyValue(const ::rtl::OUString& aPropertyName) 228 throw ( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) 229 { 230 uno::Any aAny; 231 if ( aPropertyName.equalsAscii("PluginURL") ) 232 { 233 aAny <<= maURL; 234 } 235 else if ( aPropertyName.equalsAscii("PluginMimeType") ) 236 { 237 aAny <<= maMimeType; 238 } 239 else if ( aPropertyName.equalsAscii("PluginCommands") ) 240 { 241 uno::Sequence< beans::PropertyValue > aCommandSequence; 242 maCmdList.FillSequence( aCommandSequence ); 243 aAny <<= aCommandSequence; 244 } 245 else 246 throw beans::UnknownPropertyException(); 247 return aAny; 248 } 249 250 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 { 252 } 253 254 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 { 256 } 257 258 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 { 260 } 261 262 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 { 264 } 265 266 } 267