Update ooo320-m1
[ooovba.git] / sfx2 / source / doc / applet.cxx
bloba1354d2b0fba188dd635ef22358efde5254325a2
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: applet.cxx,v $
10 * $Revision: 1.9 $
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 "applet.hxx"
35 #include <sfx2/sfxdlg.hxx>
36 #include <sfx2/sfxsids.hrc>
38 #include "com/sun/star/uno/XComponentContext.hpp"
39 #include "cppuhelper/factory.hxx"
40 #include <tools/urlobj.hxx>
41 #include <tools/debug.hxx>
42 #include <sj2/sjapplet.hxx>
43 #include <vcl/syschild.hxx>
44 #include <rtl/ustring.hxx>
45 #include <toolkit/helper/vclunohelper.hxx>
46 #include <svtools/javaoptions.hxx>
47 #include <svtools/miscopt.hxx>
48 #include <comphelper/TypeGeneration.hxx>
50 using namespace ::com::sun::star;
51 using namespace ::comphelper;
53 namespace sfx2
55 class AppletWindow_Impl : public SystemChildWindow
57 public:
58 SjApplet2* pApplet;
59 AppletWindow_Impl( Window* pParent, SjApplet2* pApp )
60 : SystemChildWindow( pParent, WB_CLIPCHILDREN )
61 , pApplet(pApp)
64 virtual void Resize();
67 void AppletWindow_Impl::Resize()
69 Size aSize( GetOutputSizePixel() );
70 if ( pApplet )
71 pApplet->setSizePixel( aSize );
74 class AppletWrapper_Impl : public SjApplet2
76 virtual void appletResize( const Size & );
77 virtual void showDocument( const INetURLObject &, const XubString & );
78 virtual void showStatus( const XubString & );
81 void AppletWrapper_Impl::appletResize( const Size & ) {}
82 void AppletWrapper_Impl::showDocument( const INetURLObject &, const XubString & ) {}
83 void AppletWrapper_Impl::showStatus( const XubString & ) {}
85 #define PROPERTY_UNBOUND 0
86 #define PROPERTY_MAYBEVOID ::com::sun::star::beans::PropertyAttribute::MAYBEVOID
88 #define WID_APPLET_CODE 1
89 #define WID_APPLET_CODEBASE 2
90 #define WID_APPLET_COMMANDS 3
91 #define WID_APPLET_DOCBASE 4
92 #define WID_APPLET_ISSCRIPT 5
93 #define WID_APPLET_NAME 6
94 const SfxItemPropertyMapEntry* lcl_GetAppletPropertyMap_Impl()
96 static SfxItemPropertyMapEntry aAppletPropertyMap_Impl[] =
98 { MAP_CHAR_LEN("AppletCode") , WID_APPLET_CODE , CPPU_E2T(CPPUTYPE_OUSTRING), PROPERTY_UNBOUND, 0 },
99 { MAP_CHAR_LEN("AppletCodeBase"), WID_APPLET_CODEBASE , CPPU_E2T(CPPUTYPE_OUSTRING), PROPERTY_UNBOUND, 0 },
100 { MAP_CHAR_LEN("AppletCommands"), WID_APPLET_COMMANDS , CPPU_E2T(CPPUTYPE_PROPERTYVALUE), PROPERTY_UNBOUND, 0 },
101 { MAP_CHAR_LEN("AppletDocBase"), WID_APPLET_DOCBASE , CPPU_E2T(CPPUTYPE_OUSTRING), PROPERTY_UNBOUND, 0 },
102 { MAP_CHAR_LEN("AppletIsScript"), WID_APPLET_ISSCRIPT , CPPU_E2T(CPPUTYPE_BOOLEAN), PROPERTY_UNBOUND, 0 },
103 { MAP_CHAR_LEN("AppletName") , WID_APPLET_NAME , CPPU_E2T(CPPUTYPE_OUSTRING), PROPERTY_UNBOUND, 0 },
104 {0,0,0,0,0,0}
106 return aAppletPropertyMap_Impl;
109 ::rtl::OUString AppletObject::getImplementationName()
110 throw( ::com::sun::star::uno::RuntimeException )
112 return impl_getStaticImplementationName();
115 ::sal_Bool AppletObject::supportsService( const ::rtl::OUString& sServiceName )
116 throw( ::com::sun::star::uno::RuntimeException )
118 ::com::sun::star::uno::Sequence< ::rtl::OUString > seqServiceNames =
119 getSupportedServiceNames();
120 const ::rtl::OUString* pArray = seqServiceNames.getConstArray();
121 for ( ::sal_Int32 nCounter=0; nCounter<seqServiceNames.getLength();
122 nCounter++ )
124 if ( pArray[nCounter] == sServiceName )
126 return sal_True ;
129 return sal_False ;
132 ::com::sun::star::uno::Sequence< ::rtl::OUString >
133 AppletObject::getSupportedServiceNames()
134 throw( ::com::sun::star::uno::RuntimeException )
136 return impl_getStaticSupportedServiceNames();
139 ::com::sun::star::uno::Sequence< ::rtl::OUString >
140 AppletObject::impl_getStaticSupportedServiceNames()
142 ::com::sun::star::uno::Sequence< ::rtl::OUString > seqServiceNames( 1 );
143 seqServiceNames.getArray() [0] = ::rtl::OUString::createFromAscii(
144 "com.sun.star.embed.SpecialEmbeddedObject" );
145 return seqServiceNames ;
148 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
149 AppletObject::impl_createInstance(
150 const ::com::sun::star::uno::Reference<
151 ::com::sun::star::uno::XComponentContext >& xContext )
152 throw( ::com::sun::star::uno::Exception )
154 return static_cast< ::cppu::OWeakObject * >( new AppletObject( xContext ) );
157 ::rtl::OUString AppletObject::impl_getStaticImplementationName()
159 return ::rtl::OUString::createFromAscii(
160 "com.sun.star.comp.sfx2.AppletObject" );
163 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
164 AppletObject::impl_createFactory()
166 return uno::Reference< uno::XInterface >(
167 cppu::createSingleComponentFactory(
168 impl_createInstance, impl_getStaticImplementationName(),
169 impl_getStaticSupportedServiceNames() ),
170 uno::UNO_QUERY_THROW );
173 AppletObject::AppletObject(
174 const uno::Reference < uno::XComponentContext >& rContext )
175 : mxContext( rContext )
176 , maPropMap( lcl_GetAppletPropertyMap_Impl() )
177 , mpApplet( NULL )
178 , mbMayScript( FALSE )
182 AppletObject::~AppletObject()
186 void SAL_CALL AppletObject::initialize( const uno::Sequence< uno::Any >& aArguments ) throw ( uno::Exception, uno::RuntimeException )
188 if ( aArguments.getLength() )
189 aArguments[0] >>= mxObj;
192 sal_Bool SAL_CALL AppletObject::load(
193 const uno::Sequence < com::sun::star::beans::PropertyValue >& /*lDescriptor*/,
194 const uno::Reference < frame::XFrame >& xFrame )
195 throw( uno::RuntimeException )
197 if ( SvtJavaOptions().IsExecuteApplets() && SvtMiscOptions().IsPluginsEnabled() )
199 mpApplet = new AppletWrapper_Impl;
201 Window* pParent = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
202 Window* pWin = new AppletWindow_Impl( pParent, mpApplet );
203 pWin->SetBackground();
204 pWin->Show();
206 // aCmdList.Append( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "width" ) ), String( aPosSize.GetWidth() ) );
207 // aCmdList.Append( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "height" ) ), String( aPosSize.GetHeight() ) );
209 if( maName.getLength() )
210 maCmdList.Append( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "name" ) ), maName );
212 if( maCodeBase.getLength() )
214 for ( sal_uInt32 nParams=0; nParams<maCmdList.Count(); nParams++ )
216 if ( maCmdList[nParams].GetCommand().EqualsAscii("codebase") )
218 maCmdList.Remove(nParams);
219 break;
223 maCmdList.Append( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "codebase" ) ), maCodeBase );
226 if( maClass.getLength() )
227 maCmdList.Append( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "code" ) ), maClass );
229 if( mbMayScript )
230 maCmdList.Append( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "mayscript" ) ), String() );
232 INetURLObject aDocBase( maDocBase );
233 mpApplet->Init( mxContext, pWin, aDocBase, maCmdList );
234 uno::Reference < awt::XWindow > xWindow( pWin->GetComponentInterface(), uno::UNO_QUERY );
236 // we must destroy the applet before the parent is destroyed
237 xWindow->addEventListener( this );
239 xFrame->setComponent( xWindow, uno::Reference < frame::XController >() );
240 return TRUE;
243 return FALSE;
246 void SAL_CALL AppletObject::cancel() throw( com::sun::star::uno::RuntimeException )
248 if ( mpApplet )
250 mpApplet->appletClose(); // reparenting window
251 DELETEZ( mpApplet );
255 void SAL_CALL AppletObject::close( sal_Bool /*bDeliverOwnership*/ ) throw( com::sun::star::util::CloseVetoException, com::sun::star::uno::RuntimeException )
259 void SAL_CALL AppletObject::addCloseListener( const com::sun::star::uno::Reference < com::sun::star::util::XCloseListener >& ) throw( com::sun::star::uno::RuntimeException )
263 void SAL_CALL AppletObject::removeCloseListener( const com::sun::star::uno::Reference < com::sun::star::util::XCloseListener >& ) throw( com::sun::star::uno::RuntimeException )
267 void SAL_CALL AppletObject::disposing( const com::sun::star::lang::EventObject& ) throw (com::sun::star::uno::RuntimeException)
269 cancel();
272 uno::Reference< beans::XPropertySetInfo > SAL_CALL AppletObject::getPropertySetInfo() throw( ::com::sun::star::uno::RuntimeException )
274 static uno::Reference< beans::XPropertySetInfo > xInfo = new SfxItemPropertySetInfo( &maPropMap );
275 return xInfo;
278 void SAL_CALL AppletObject::setPropertyValue(const ::rtl::OUString& aPropertyName, const uno::Any& aAny)
279 throw ( beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
282 const SfxItemPropertySimpleEntry* pEntry = maPropMap.getByName( aPropertyName );
283 if( !pEntry )
284 throw beans::UnknownPropertyException();
285 switch( pEntry->nWID )
287 case WID_APPLET_CODE :
288 aAny >>= maClass;
289 break;
290 case WID_APPLET_CODEBASE :
291 //pImpl->aCodeBase = rURL.GetMainURL( INetURLObject::NO_DECODE );
292 //if( rURL.GetProtocol() == INET_PROT_FILE
293 // && pImpl->aCodeBase.GetChar( 9 ) == INET_ENC_DELIM_TOKEN )
294 // // Laufwerksbuchstabe auf ':' patchen
295 // pImpl->aCodeBase.SetChar( 9, INET_DELIM_TOKEN );
297 aAny >>= maCodeBase;
298 break;
299 case WID_APPLET_COMMANDS :
301 maCmdList.Clear();
302 uno::Sequence < beans::PropertyValue > aCommandSequence;
303 if( aAny >>= aCommandSequence )
304 maCmdList.FillFromSequence( aCommandSequence );
306 break;
307 case WID_APPLET_DOCBASE :
308 aAny >>= maDocBase;
309 break;
310 case WID_APPLET_ISSCRIPT :
311 aAny >>= mbMayScript;
312 break;
313 case WID_APPLET_NAME :
314 aAny >>= maName;
315 break;
316 default:;
321 uno::Any SAL_CALL AppletObject::getPropertyValue(const ::rtl::OUString& aPropertyName) throw ( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
323 uno::Any aAny;
324 const SfxItemPropertySimpleEntry* pEntry = maPropMap.getByName( aPropertyName );
325 if( !pEntry )
326 throw beans::UnknownPropertyException();
327 switch( pEntry->nWID )
329 case WID_APPLET_CODE :
330 aAny <<= maClass;
331 break;
332 case WID_APPLET_CODEBASE :
333 aAny <<= maCodeBase;
334 break;
335 case WID_APPLET_COMMANDS :
337 uno::Sequence< beans::PropertyValue > aCommandSequence;
338 maCmdList.FillSequence( aCommandSequence );
339 aAny <<= aCommandSequence;
341 break;
342 case WID_APPLET_DOCBASE :
343 break;
344 case WID_APPLET_ISSCRIPT :
345 aAny <<= mbMayScript;
346 break;
347 case WID_APPLET_NAME :
348 aAny <<= maName;
349 break;
350 default:;
353 return aAny;
356 void SAL_CALL AppletObject::addPropertyChangeListener(const ::rtl::OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener > & ) throw( ::com::sun::star::uno::RuntimeException )
360 void SAL_CALL AppletObject::removePropertyChangeListener(const ::rtl::OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener > & ) throw( ::com::sun::star::uno::RuntimeException )
364 void SAL_CALL AppletObject::addVetoableChangeListener(const ::rtl::OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener > & ) throw( ::com::sun::star::uno::RuntimeException )
368 void SAL_CALL AppletObject::removeVetoableChangeListener(const ::rtl::OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener > & ) throw( ::com::sun::star::uno::RuntimeException )
372 ::sal_Int16 SAL_CALL AppletObject::execute() throw (::com::sun::star::uno::RuntimeException)
374 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
375 uno::Reference < beans::XPropertySet > xSet( this );
376 VclAbstractDialog* pDlg = pFact->CreateEditObjectDialog( NULL, SID_INSERT_APPLET, mxObj );
377 if ( pDlg )
378 pDlg->Execute();
379 return 0;
382 void SAL_CALL AppletObject::setTitle( const ::rtl::OUString& ) throw (::com::sun::star::uno::RuntimeException)