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