1*d119d52dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*d119d52dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*d119d52dSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*d119d52dSAndrew Rist * distributed with this work for additional information
6*d119d52dSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*d119d52dSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*d119d52dSAndrew Rist * "License"); you may not use this file except in compliance
9*d119d52dSAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11*d119d52dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*d119d52dSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*d119d52dSAndrew Rist * software distributed under the License is distributed on an
15*d119d52dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*d119d52dSAndrew Rist * KIND, either express or implied. See the License for the
17*d119d52dSAndrew Rist * specific language governing permissions and limitations
18*d119d52dSAndrew Rist * under the License.
19cdf0e10cSrcweir *
20*d119d52dSAndrew Rist *************************************************************/
21*d119d52dSAndrew Rist
22*d119d52dSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sfx2.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "plugin.hxx"
28cdf0e10cSrcweir #include <com/sun/star/plugin/XPluginManager.hpp>
29cdf0e10cSrcweir #include <com/sun/star/plugin/PluginMode.hpp>
30cdf0e10cSrcweir #include <com/sun/star/awt/XControl.hpp>
31cdf0e10cSrcweir
32cdf0e10cSrcweir #include <tools/debug.hxx>
33cdf0e10cSrcweir #include <rtl/ustring.hxx>
34cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
35cdf0e10cSrcweir #include <svtools/miscopt.hxx>
36cdf0e10cSrcweir #include <vcl/window.hxx>
37cdf0e10cSrcweir
38cdf0e10cSrcweir using namespace ::com::sun::star;
39cdf0e10cSrcweir
40cdf0e10cSrcweir namespace sfx2
41cdf0e10cSrcweir {
42cdf0e10cSrcweir
43cdf0e10cSrcweir class PluginWindow_Impl : public Window
44cdf0e10cSrcweir {
45cdf0e10cSrcweir public:
46cdf0e10cSrcweir uno::Reference < awt::XWindow > xWindow;
PluginWindow_Impl(Window * pParent)47cdf0e10cSrcweir PluginWindow_Impl( Window* pParent )
48cdf0e10cSrcweir : Window( pParent, WB_CLIPCHILDREN )
49cdf0e10cSrcweir {}
50cdf0e10cSrcweir
51cdf0e10cSrcweir virtual void Resize();
52cdf0e10cSrcweir };
53cdf0e10cSrcweir
Resize()54cdf0e10cSrcweir void PluginWindow_Impl::Resize()
55cdf0e10cSrcweir {
56cdf0e10cSrcweir Size aSize( GetOutputSizePixel() );
57cdf0e10cSrcweir if ( xWindow.is() )
58cdf0e10cSrcweir xWindow->setPosSize( 0, 0, aSize.Width(), aSize.Height(), WINDOW_POSSIZE_SIZE );
59cdf0e10cSrcweir }
60cdf0e10cSrcweir
61cdf0e10cSrcweir #define PROPERTY_UNBOUND 0
62cdf0e10cSrcweir
63cdf0e10cSrcweir #define WID_COMMANDS 1
64cdf0e10cSrcweir #define WID_MIMETYPE 2
65cdf0e10cSrcweir #define WID_URL 3
lcl_GetPluginPropertyMap_Impl()66cdf0e10cSrcweir const SfxItemPropertyMapEntry* lcl_GetPluginPropertyMap_Impl()
67cdf0e10cSrcweir {
68cdf0e10cSrcweir static SfxItemPropertyMapEntry aPluginPropertyMap_Impl[] =
69cdf0e10cSrcweir {
70cdf0e10cSrcweir { MAP_CHAR_LEN("PluginCommands"), WID_COMMANDS, &::getCppuType((::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >*)0), PROPERTY_UNBOUND, 0},
71cdf0e10cSrcweir { MAP_CHAR_LEN("PluginMimeType"), WID_MIMETYPE, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 },
72cdf0e10cSrcweir { MAP_CHAR_LEN("PluginURL"), WID_URL , &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 },
73cdf0e10cSrcweir {0,0,0,0,0,0}
74cdf0e10cSrcweir };
75cdf0e10cSrcweir return aPluginPropertyMap_Impl;
76cdf0e10cSrcweir }
77cdf0e10cSrcweir
78cdf0e10cSrcweir SFX_IMPL_XSERVICEINFO( PluginObject, "com.sun.star.embed.SpecialEmbeddedObject", "com.sun.star.comp.sfx2.PluginObject" )
79cdf0e10cSrcweir SFX_IMPL_SINGLEFACTORY( PluginObject );
80cdf0e10cSrcweir
PluginObject(const uno::Reference<lang::XMultiServiceFactory> & rFact)81cdf0e10cSrcweir PluginObject::PluginObject( const uno::Reference < lang::XMultiServiceFactory >& rFact )
82cdf0e10cSrcweir : mxFact( rFact )
83cdf0e10cSrcweir , maPropMap( lcl_GetPluginPropertyMap_Impl() )
84cdf0e10cSrcweir {
85cdf0e10cSrcweir }
86cdf0e10cSrcweir
~PluginObject()87cdf0e10cSrcweir PluginObject::~PluginObject()
88cdf0e10cSrcweir {
89cdf0e10cSrcweir }
90cdf0e10cSrcweir
initialize(const uno::Sequence<uno::Any> & aArguments)91cdf0e10cSrcweir void SAL_CALL PluginObject::initialize( const uno::Sequence< uno::Any >& aArguments ) throw ( uno::Exception, uno::RuntimeException )
92cdf0e10cSrcweir {
93cdf0e10cSrcweir if ( aArguments.getLength() )
94cdf0e10cSrcweir aArguments[0] >>= mxObj;
95cdf0e10cSrcweir }
96cdf0e10cSrcweir
load(const uno::Sequence<com::sun::star::beans::PropertyValue> &,const uno::Reference<frame::XFrame> & xFrame)97cdf0e10cSrcweir sal_Bool SAL_CALL PluginObject::load(
98cdf0e10cSrcweir const uno::Sequence < com::sun::star::beans::PropertyValue >& /*lDescriptor*/,
99cdf0e10cSrcweir const uno::Reference < frame::XFrame >& xFrame )
100cdf0e10cSrcweir throw( uno::RuntimeException )
101cdf0e10cSrcweir {
102cdf0e10cSrcweir uno::Reference< plugin::XPluginManager > xPMgr( mxFact->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.plugin.PluginManager") ), uno::UNO_QUERY );
103cdf0e10cSrcweir if (!xPMgr.is() )
104cdf0e10cSrcweir return sal_False;
105cdf0e10cSrcweir
106cdf0e10cSrcweir if ( SvtMiscOptions().IsPluginsEnabled() )
107cdf0e10cSrcweir {
108cdf0e10cSrcweir Window* pParent = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
109cdf0e10cSrcweir PluginWindow_Impl* pWin = new PluginWindow_Impl( pParent );
110cdf0e10cSrcweir pWin->SetSizePixel( pParent->GetOutputSizePixel() );
111cdf0e10cSrcweir pWin->SetBackground();
112cdf0e10cSrcweir pWin->Show();
113cdf0e10cSrcweir
114cdf0e10cSrcweir sal_uIntPtr nCount = maCmdList.Count();
115cdf0e10cSrcweir uno::Sequence < ::rtl::OUString > aCmds( nCount ), aArgs( nCount );
116cdf0e10cSrcweir ::rtl::OUString *pCmds = aCmds.getArray(), *pArgs = aArgs.getArray();
117cdf0e10cSrcweir for( sal_uIntPtr i = 0; i < nCount; i++ )
118cdf0e10cSrcweir {
119cdf0e10cSrcweir SvCommand & rCmd = maCmdList.GetObject( i );
120cdf0e10cSrcweir pCmds[i] = rCmd.GetCommand();
121cdf0e10cSrcweir pArgs[i] = rCmd.GetArgument();
122cdf0e10cSrcweir }
123cdf0e10cSrcweir
124cdf0e10cSrcweir mxPlugin = xPMgr->createPluginFromURL(
125cdf0e10cSrcweir xPMgr->createPluginContext(), plugin::PluginMode::EMBED, aCmds, aArgs, uno::Reference< awt::XToolkit >(),
126cdf0e10cSrcweir uno::Reference< awt::XWindowPeer >( pWin->GetComponentInterface() ), maURL );
127cdf0e10cSrcweir
128cdf0e10cSrcweir if ( mxPlugin.is() )
129cdf0e10cSrcweir {
130cdf0e10cSrcweir uno::Reference< awt::XWindow > xWindow( mxPlugin, uno::UNO_QUERY );
131cdf0e10cSrcweir if ( xWindow.is() )
132cdf0e10cSrcweir {
133cdf0e10cSrcweir pWin->xWindow = xWindow;
134cdf0e10cSrcweir pWin->Resize();
135cdf0e10cSrcweir xWindow->setVisible( sal_True );
136cdf0e10cSrcweir }
137cdf0e10cSrcweir
138cdf0e10cSrcweir try
139cdf0e10cSrcweir {
140cdf0e10cSrcweir uno::Reference< awt::XControl > xControl( mxPlugin, uno::UNO_QUERY );
141cdf0e10cSrcweir if( xControl.is() )
142cdf0e10cSrcweir {
143cdf0e10cSrcweir uno::Reference< awt::XControlModel > xModel = xControl->getModel();
144cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xProp( xModel, ::uno::UNO_QUERY );
145cdf0e10cSrcweir if( xProp.is() )
146cdf0e10cSrcweir {
147cdf0e10cSrcweir uno::Any aValue = xProp->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) ) );
148cdf0e10cSrcweir aValue >>= maURL;
149cdf0e10cSrcweir aValue = xProp->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "TYPE" ) ) );
150cdf0e10cSrcweir aValue >>= maMimeType;
151cdf0e10cSrcweir }
152cdf0e10cSrcweir }
153cdf0e10cSrcweir }
154cdf0e10cSrcweir catch( uno::Exception& )
155cdf0e10cSrcweir {
156cdf0e10cSrcweir }
157cdf0e10cSrcweir }
158cdf0e10cSrcweir
159cdf0e10cSrcweir uno::Reference < awt::XWindow > xWindow( pWin->GetComponentInterface(), uno::UNO_QUERY );
160cdf0e10cSrcweir
161cdf0e10cSrcweir // we must destroy the plugin before the parent is destroyed
162cdf0e10cSrcweir xWindow->addEventListener( this );
163cdf0e10cSrcweir xFrame->setComponent( xWindow, uno::Reference < frame::XController >() );
164cdf0e10cSrcweir return mxPlugin.is() ? sal_True : sal_False;
165cdf0e10cSrcweir }
166cdf0e10cSrcweir
167cdf0e10cSrcweir return sal_False;
168cdf0e10cSrcweir }
169cdf0e10cSrcweir
cancel()170cdf0e10cSrcweir void SAL_CALL PluginObject::cancel() throw( com::sun::star::uno::RuntimeException )
171cdf0e10cSrcweir {
172cdf0e10cSrcweir uno::Reference< lang::XComponent > xComp( mxPlugin, uno::UNO_QUERY );
173cdf0e10cSrcweir if (xComp.is())
174cdf0e10cSrcweir xComp->dispose();
175cdf0e10cSrcweir mxPlugin = 0;
176cdf0e10cSrcweir }
177cdf0e10cSrcweir
close(sal_Bool)178cdf0e10cSrcweir void SAL_CALL PluginObject::close( sal_Bool /*bDeliverOwnership*/ ) throw( com::sun::star::util::CloseVetoException, com::sun::star::uno::RuntimeException )
179cdf0e10cSrcweir {
180cdf0e10cSrcweir }
181cdf0e10cSrcweir
addCloseListener(const com::sun::star::uno::Reference<com::sun::star::util::XCloseListener> &)182cdf0e10cSrcweir void SAL_CALL PluginObject::addCloseListener( const com::sun::star::uno::Reference < com::sun::star::util::XCloseListener >& ) throw( com::sun::star::uno::RuntimeException )
183cdf0e10cSrcweir {
184cdf0e10cSrcweir }
185cdf0e10cSrcweir
removeCloseListener(const com::sun::star::uno::Reference<com::sun::star::util::XCloseListener> &)186cdf0e10cSrcweir void SAL_CALL PluginObject::removeCloseListener( const com::sun::star::uno::Reference < com::sun::star::util::XCloseListener >& ) throw( com::sun::star::uno::RuntimeException )
187cdf0e10cSrcweir {
188cdf0e10cSrcweir }
189cdf0e10cSrcweir
disposing(const com::sun::star::lang::EventObject &)190cdf0e10cSrcweir void SAL_CALL PluginObject::disposing( const com::sun::star::lang::EventObject& ) throw (com::sun::star::uno::RuntimeException)
191cdf0e10cSrcweir {
192cdf0e10cSrcweir cancel();
193cdf0e10cSrcweir }
194cdf0e10cSrcweir
getPropertySetInfo()195cdf0e10cSrcweir uno::Reference< beans::XPropertySetInfo > SAL_CALL PluginObject::getPropertySetInfo() throw( ::com::sun::star::uno::RuntimeException )
196cdf0e10cSrcweir {
197cdf0e10cSrcweir static uno::Reference< beans::XPropertySetInfo > xInfo = new SfxItemPropertySetInfo( &maPropMap );
198cdf0e10cSrcweir return xInfo;
199cdf0e10cSrcweir }
200cdf0e10cSrcweir
setPropertyValue(const::rtl::OUString & aPropertyName,const uno::Any & aAny)201cdf0e10cSrcweir void SAL_CALL PluginObject::setPropertyValue(const ::rtl::OUString& aPropertyName, const uno::Any& aAny)
202cdf0e10cSrcweir throw ( beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
203cdf0e10cSrcweir {
204cdf0e10cSrcweir if ( aPropertyName.equalsAscii("PluginURL") )
205cdf0e10cSrcweir {
206cdf0e10cSrcweir aAny >>= maURL;
207cdf0e10cSrcweir }
208cdf0e10cSrcweir else if ( aPropertyName.equalsAscii("PluginMimeType") )
209cdf0e10cSrcweir {
210cdf0e10cSrcweir aAny >>= maMimeType;
211cdf0e10cSrcweir }
212cdf0e10cSrcweir else if ( aPropertyName.equalsAscii("PluginCommands") )
213cdf0e10cSrcweir {
214cdf0e10cSrcweir maCmdList.Clear();
215cdf0e10cSrcweir uno::Sequence < beans::PropertyValue > aCommandSequence;
216cdf0e10cSrcweir if( aAny >>= aCommandSequence )
217cdf0e10cSrcweir maCmdList.FillFromSequence( aCommandSequence );
218cdf0e10cSrcweir }
219cdf0e10cSrcweir else
220cdf0e10cSrcweir throw beans::UnknownPropertyException();
221cdf0e10cSrcweir }
222cdf0e10cSrcweir
getPropertyValue(const::rtl::OUString & aPropertyName)223cdf0e10cSrcweir uno::Any SAL_CALL PluginObject::getPropertyValue(const ::rtl::OUString& aPropertyName)
224cdf0e10cSrcweir throw ( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
225cdf0e10cSrcweir {
226cdf0e10cSrcweir uno::Any aAny;
227cdf0e10cSrcweir if ( aPropertyName.equalsAscii("PluginURL") )
228cdf0e10cSrcweir {
229cdf0e10cSrcweir aAny <<= maURL;
230cdf0e10cSrcweir }
231cdf0e10cSrcweir else if ( aPropertyName.equalsAscii("PluginMimeType") )
232cdf0e10cSrcweir {
233cdf0e10cSrcweir aAny <<= maMimeType;
234cdf0e10cSrcweir }
235cdf0e10cSrcweir else if ( aPropertyName.equalsAscii("PluginCommands") )
236cdf0e10cSrcweir {
237cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aCommandSequence;
238cdf0e10cSrcweir maCmdList.FillSequence( aCommandSequence );
239cdf0e10cSrcweir aAny <<= aCommandSequence;
240cdf0e10cSrcweir }
241cdf0e10cSrcweir else
242cdf0e10cSrcweir throw beans::UnknownPropertyException();
243cdf0e10cSrcweir return aAny;
244cdf0e10cSrcweir }
245cdf0e10cSrcweir
addPropertyChangeListener(const::rtl::OUString &,const::com::sun::star::uno::Reference<::com::sun::star::beans::XPropertyChangeListener> &)246cdf0e10cSrcweir 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 )
247cdf0e10cSrcweir {
248cdf0e10cSrcweir }
249cdf0e10cSrcweir
removePropertyChangeListener(const::rtl::OUString &,const::com::sun::star::uno::Reference<::com::sun::star::beans::XPropertyChangeListener> &)250cdf0e10cSrcweir 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 )
251cdf0e10cSrcweir {
252cdf0e10cSrcweir }
253cdf0e10cSrcweir
addVetoableChangeListener(const::rtl::OUString &,const::com::sun::star::uno::Reference<::com::sun::star::beans::XVetoableChangeListener> &)254cdf0e10cSrcweir 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 )
255cdf0e10cSrcweir {
256cdf0e10cSrcweir }
257cdf0e10cSrcweir
removeVetoableChangeListener(const::rtl::OUString &,const::com::sun::star::uno::Reference<::com::sun::star::beans::XVetoableChangeListener> &)258cdf0e10cSrcweir 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 )
259cdf0e10cSrcweir {
260cdf0e10cSrcweir }
261cdf0e10cSrcweir
262cdf0e10cSrcweir }
263