Update ooo320-m1
[ooovba.git] / sfx2 / source / doc / plugin.cxx
blob4a8a7e3d777547fa4e3325627fb0813280a6f71a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: plugin.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sfx2.hxx"
34 #include "plugin.hxx"
35 #include <com/sun/star/plugin/XPluginManager.hpp>
36 #include <com/sun/star/plugin/PluginMode.hpp>
37 #include <com/sun/star/awt/XControl.hpp>
39 #include <tools/debug.hxx>
40 #include <rtl/ustring.hxx>
41 #include <toolkit/helper/vclunohelper.hxx>
42 #include <svtools/miscopt.hxx>
43 #include <vcl/window.hxx>
45 using namespace ::com::sun::star;
47 namespace sfx2
50 class PluginWindow_Impl : public Window
52 public:
53 uno::Reference < awt::XWindow > xWindow;
54 PluginWindow_Impl( Window* pParent )
55 : Window( pParent, WB_CLIPCHILDREN )
58 virtual void Resize();
61 void PluginWindow_Impl::Resize()
63 Size aSize( GetOutputSizePixel() );
64 if ( xWindow.is() )
65 xWindow->setPosSize( 0, 0, aSize.Width(), aSize.Height(), WINDOW_POSSIZE_SIZE );
68 #define PROPERTY_UNBOUND 0
70 #define WID_COMMANDS 1
71 #define WID_MIMETYPE 2
72 #define WID_URL 3
73 const SfxItemPropertyMapEntry* lcl_GetPluginPropertyMap_Impl()
75 static SfxItemPropertyMapEntry aPluginPropertyMap_Impl[] =
77 { MAP_CHAR_LEN("PluginCommands"), WID_COMMANDS, &::getCppuType((::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >*)0), PROPERTY_UNBOUND, 0},
78 { MAP_CHAR_LEN("PluginMimeType"), WID_MIMETYPE, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 },
79 { MAP_CHAR_LEN("PluginURL"), WID_URL , &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 },
80 {0,0,0,0,0,0}
82 return aPluginPropertyMap_Impl;
85 SFX_IMPL_XSERVICEINFO( PluginObject, "com.sun.star.embed.SpecialEmbeddedObject", "com.sun.star.comp.sfx2.PluginObject" )
86 SFX_IMPL_SINGLEFACTORY( PluginObject );
88 PluginObject::PluginObject( const uno::Reference < lang::XMultiServiceFactory >& rFact )
89 : mxFact( rFact )
90 , maPropMap( lcl_GetPluginPropertyMap_Impl() )
94 PluginObject::~PluginObject()
98 void SAL_CALL PluginObject::initialize( const uno::Sequence< uno::Any >& aArguments ) throw ( uno::Exception, uno::RuntimeException )
100 if ( aArguments.getLength() )
101 aArguments[0] >>= mxObj;
104 sal_Bool SAL_CALL PluginObject::load(
105 const uno::Sequence < com::sun::star::beans::PropertyValue >& /*lDescriptor*/,
106 const uno::Reference < frame::XFrame >& xFrame )
107 throw( uno::RuntimeException )
109 uno::Reference< plugin::XPluginManager > xPMgr( mxFact->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.plugin.PluginManager") ), uno::UNO_QUERY );
110 if (!xPMgr.is() )
111 return FALSE;
113 if ( SvtMiscOptions().IsPluginsEnabled() )
115 Window* pParent = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
116 PluginWindow_Impl* pWin = new PluginWindow_Impl( pParent );
117 pWin->SetSizePixel( pParent->GetOutputSizePixel() );
118 pWin->SetBackground();
119 pWin->Show();
121 ULONG nCount = maCmdList.Count();
122 uno::Sequence < ::rtl::OUString > aCmds( nCount ), aArgs( nCount );
123 ::rtl::OUString *pCmds = aCmds.getArray(), *pArgs = aArgs.getArray();
124 for( ULONG i = 0; i < nCount; i++ )
126 SvCommand & rCmd = maCmdList.GetObject( i );
127 pCmds[i] = rCmd.GetCommand();
128 pArgs[i] = rCmd.GetArgument();
131 mxPlugin = xPMgr->createPluginFromURL(
132 xPMgr->createPluginContext(), plugin::PluginMode::EMBED, aCmds, aArgs, uno::Reference< awt::XToolkit >(),
133 uno::Reference< awt::XWindowPeer >( pWin->GetComponentInterface() ), maURL );
135 if ( mxPlugin.is() )
137 uno::Reference< awt::XWindow > xWindow( mxPlugin, uno::UNO_QUERY );
138 if ( xWindow.is() )
140 pWin->xWindow = xWindow;
141 pWin->Resize();
142 xWindow->setVisible( TRUE );
147 uno::Reference< awt::XControl > xControl( mxPlugin, uno::UNO_QUERY );
148 if( xControl.is() )
150 uno::Reference< awt::XControlModel > xModel = xControl->getModel();
151 uno::Reference< beans::XPropertySet > xProp( xModel, ::uno::UNO_QUERY );
152 if( xProp.is() )
154 uno::Any aValue = xProp->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) ) );
155 aValue >>= maURL;
156 aValue = xProp->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "TYPE" ) ) );
157 aValue >>= maMimeType;
161 catch( uno::Exception& )
166 uno::Reference < awt::XWindow > xWindow( pWin->GetComponentInterface(), uno::UNO_QUERY );
168 // we must destroy the plugin before the parent is destroyed
169 xWindow->addEventListener( this );
170 xFrame->setComponent( xWindow, uno::Reference < frame::XController >() );
171 return mxPlugin.is() ? TRUE : FALSE;
174 return FALSE;
177 void SAL_CALL PluginObject::cancel() throw( com::sun::star::uno::RuntimeException )
179 uno::Reference< lang::XComponent > xComp( mxPlugin, uno::UNO_QUERY );
180 if (xComp.is())
181 xComp->dispose();
182 mxPlugin = 0;
185 void SAL_CALL PluginObject::close( sal_Bool /*bDeliverOwnership*/ ) throw( com::sun::star::util::CloseVetoException, com::sun::star::uno::RuntimeException )
189 void SAL_CALL PluginObject::addCloseListener( const com::sun::star::uno::Reference < com::sun::star::util::XCloseListener >& ) throw( com::sun::star::uno::RuntimeException )
193 void SAL_CALL PluginObject::removeCloseListener( const com::sun::star::uno::Reference < com::sun::star::util::XCloseListener >& ) throw( com::sun::star::uno::RuntimeException )
197 void SAL_CALL PluginObject::disposing( const com::sun::star::lang::EventObject& ) throw (com::sun::star::uno::RuntimeException)
199 cancel();
202 uno::Reference< beans::XPropertySetInfo > SAL_CALL PluginObject::getPropertySetInfo() throw( ::com::sun::star::uno::RuntimeException )
204 static uno::Reference< beans::XPropertySetInfo > xInfo = new SfxItemPropertySetInfo( &maPropMap );
205 return xInfo;
208 void SAL_CALL PluginObject::setPropertyValue(const ::rtl::OUString& aPropertyName, const uno::Any& aAny)
209 throw ( beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
211 if ( aPropertyName.equalsAscii("PluginURL") )
213 aAny >>= maURL;
215 else if ( aPropertyName.equalsAscii("PluginMimeType") )
217 aAny >>= maMimeType;
219 else if ( aPropertyName.equalsAscii("PluginCommands") )
221 maCmdList.Clear();
222 uno::Sequence < beans::PropertyValue > aCommandSequence;
223 if( aAny >>= aCommandSequence )
224 maCmdList.FillFromSequence( aCommandSequence );
226 else
227 throw beans::UnknownPropertyException();
230 uno::Any SAL_CALL PluginObject::getPropertyValue(const ::rtl::OUString& aPropertyName)
231 throw ( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
233 uno::Any aAny;
234 if ( aPropertyName.equalsAscii("PluginURL") )
236 aAny <<= maURL;
238 else if ( aPropertyName.equalsAscii("PluginMimeType") )
240 aAny <<= maMimeType;
242 else if ( aPropertyName.equalsAscii("PluginCommands") )
244 uno::Sequence< beans::PropertyValue > aCommandSequence;
245 maCmdList.FillSequence( aCommandSequence );
246 aAny <<= aCommandSequence;
248 else
249 throw beans::UnknownPropertyException();
250 return aAny;
253 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 )
257 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 )
261 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 )
265 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 )