1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: applet.cxx,v $
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"
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
;
55 class AppletWindow_Impl
: public SystemChildWindow
59 AppletWindow_Impl( Window
* pParent
, SjApplet2
* pApp
)
60 : SystemChildWindow( pParent
, WB_CLIPCHILDREN
)
64 virtual void Resize();
67 void AppletWindow_Impl::Resize()
69 Size
aSize( GetOutputSizePixel() );
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 },
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();
124 if ( pArray
[nCounter
] == sServiceName
)
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() )
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();
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
);
223 maCmdList
.Append( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "codebase" ) ), maCodeBase
);
226 if( maClass
.getLength() )
227 maCmdList
.Append( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "code" ) ), maClass
);
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
>() );
246 void SAL_CALL
AppletObject::cancel() throw( com::sun::star::uno::RuntimeException
)
250 mpApplet
->appletClose(); // reparenting window
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
)
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
);
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
);
284 throw beans::UnknownPropertyException();
285 switch( pEntry
->nWID
)
287 case WID_APPLET_CODE
:
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 );
299 case WID_APPLET_COMMANDS
:
302 uno::Sequence
< beans::PropertyValue
> aCommandSequence
;
303 if( aAny
>>= aCommandSequence
)
304 maCmdList
.FillFromSequence( aCommandSequence
);
307 case WID_APPLET_DOCBASE
:
310 case WID_APPLET_ISSCRIPT
:
311 aAny
>>= mbMayScript
;
313 case WID_APPLET_NAME
:
321 uno::Any SAL_CALL
AppletObject::getPropertyValue(const ::rtl::OUString
& aPropertyName
) throw ( beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
324 const SfxItemPropertySimpleEntry
* pEntry
= maPropMap
.getByName( aPropertyName
);
326 throw beans::UnknownPropertyException();
327 switch( pEntry
->nWID
)
329 case WID_APPLET_CODE
:
332 case WID_APPLET_CODEBASE
:
335 case WID_APPLET_COMMANDS
:
337 uno::Sequence
< beans::PropertyValue
> aCommandSequence
;
338 maCmdList
.FillSequence( aCommandSequence
);
339 aAny
<<= aCommandSequence
;
342 case WID_APPLET_DOCBASE
:
344 case WID_APPLET_ISSCRIPT
:
345 aAny
<<= mbMayScript
;
347 case WID_APPLET_NAME
:
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
);
382 void SAL_CALL
AppletObject::setTitle( const ::rtl::OUString
& ) throw (::com::sun::star::uno::RuntimeException
)