diff options
author | Kay Ramme <kr@openoffice.org> | 2001-04-10 12:56:23 +0000 |
---|---|---|
committer | Kay Ramme <kr@openoffice.org> | 2001-04-10 12:56:23 +0000 |
commit | c0b053b12d5b51978118cef5c38ce06b81e955de (patch) | |
tree | 3701d0f00a4d07bfb5349c489d03dbc86c37e007 /sj2 | |
parent | 87bdb0268575bcd3d80b4246c2ed865e827e03a9 (diff) |
extracted appletviewer code and bug 79689
Diffstat (limited to 'sj2')
-rw-r--r-- | sj2/inc/sjapplet.hxx | 20 | ||||
-rw-r--r-- | sj2/source/jscpp/makefile.mk | 6 | ||||
-rw-r--r-- | sj2/source/jscpp/sjapplet.cxx | 240 | ||||
-rw-r--r-- | sj2/stardiv/applet/AppletExecutionContext.java | 28 |
4 files changed, 48 insertions, 246 deletions
diff --git a/sj2/inc/sjapplet.hxx b/sj2/inc/sjapplet.hxx index 6f7a5ec7012a..e8f510a534fd 100644 --- a/sj2/inc/sjapplet.hxx +++ b/sj2/inc/sjapplet.hxx @@ -2,9 +2,9 @@ * * $RCSfile: sjapplet.hxx,v $ * - * $Revision: 1.1.1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: hr $ $Date: 2000-09-18 16:54:02 $ + * last change: $Author: kr $ $Date: 2001-04-10 13:56:22 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -64,24 +64,13 @@ #include <tools/string.hxx> -// ************************************************************** -//class stardiv_applet_AppletViewerPanel; -// class stardiv_applet_AppletExecutionContext; -// class java_awt_Frame; -// class com_sun_star_comp_jawt_peer_EmbeddedFrame; -// class java_awt_Window; -// class XubString; -// class SjJSbxObject; - -//#include <jni.h> - class INetURLObject; class Size; class SjJScriptAppletObject; class SvCommandList; class Window; -struct SjApplet2ImplStruct; +struct SjApplet2_Impl; enum SjNetAccess { @@ -90,8 +79,7 @@ enum SjNetAccess class SjApplet2 { - Window * _pParentWin; - SjApplet2ImplStruct * _pImpl; + SjApplet2_Impl * _pImpl; public: static void settingsChanged(void); diff --git a/sj2/source/jscpp/makefile.mk b/sj2/source/jscpp/makefile.mk index 9b2d65e9ea44..a813e1dbb14b 100644 --- a/sj2/source/jscpp/makefile.mk +++ b/sj2/source/jscpp/makefile.mk @@ -2,9 +2,9 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.1.1.1 $ +# $Revision: 1.2 $ # -# last change: $Author: hr $ $Date: 2000-09-18 16:54:03 $ +# last change: $Author: kr $ $Date: 2001-04-10 13:56:22 $ # # The Contents of this file are made available subject to the terms of # either of the following licenses @@ -86,10 +86,12 @@ UNOTYPES= \ CXXFILES= \ sjapplet.cxx \ + sjapplet_impl.cxx SLOFILES= \ $(SLO)$/sjapplet.obj \ + $(SLO)$/sjapplet_impl.obj # .IF "$(GUI)"=="WNT" # SLOFILES += $(SLO)$/sun_awt_windows_package.obj diff --git a/sj2/source/jscpp/sjapplet.cxx b/sj2/source/jscpp/sjapplet.cxx index 45279a4b234c..e2f2ccd64478 100644 --- a/sj2/source/jscpp/sjapplet.cxx +++ b/sj2/source/jscpp/sjapplet.cxx @@ -2,9 +2,9 @@ * * $RCSfile: sjapplet.cxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: kr $ $Date: 2001-01-23 08:49:40 $ + * last change: $Author: kr $ $Date: 2001-04-10 13:56:22 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -71,58 +71,22 @@ #include <rtl/process.h> -#include <jni.h> - -using namespace ::rtl; -using namespace ::com::sun::star::lang; -using namespace ::utl; - -#include <tools/urlobj.hxx> #include <tools/debug.hxx> #include <svtools/ownlist.hxx> -#include <vcl/svapp.hxx> -#include <vcl/window.hxx> -#include <vcl/wrkwin.hxx> -#include <vcl/syschild.hxx> - -using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::java; -using namespace ::sj2; -#include <com/sun/star/java/XJavaVM.hpp> -struct SjApplet2ImplStruct { - JavaVM * _pJVM; - jobject _joAppletExecutionContext; - jobject _joFrame; - jclass _jcAppletExecutionContext; +#include "sjapplet_impl.hxx" - Reference<XJavaVM> _xJavaVM; - Reference<XJavaThreadRegister_11> _xJavaThreadRegister_11; - - SjApplet2ImplStruct() : - _pJVM(NULL), - _joAppletExecutionContext(0), - _joFrame(0), - _jcAppletExecutionContext(0) - {} - - - - ~SjApplet2ImplStruct() { - if (_joAppletExecutionContext) { - TKTThreadAttach jenv(_pJVM, _xJavaThreadRegister_11.get()); +using namespace ::rtl; +using namespace ::utl; +using namespace ::sj2; - jenv.pEnv->DeleteGlobalRef(_joAppletExecutionContext); - jenv.pEnv->DeleteGlobalRef(_joFrame); - jenv.pEnv->DeleteGlobalRef(_jcAppletExecutionContext); - } - } -}; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::java; SjApplet2::SjApplet2() - : _pParentWin(NULL), - _pImpl(new SjApplet2ImplStruct()) + : _pImpl(new SjApplet2_Impl()) { } @@ -132,212 +96,46 @@ SjApplet2::~SjApplet2() } //========================================================================= -void SjApplet2::Init( Window * pParentWin, const INetURLObject & rDocBase, const SvCommandList & rCmdList ) +void SjApplet2::Init(Window * pParentWin, const INetURLObject & rDocBase, const SvCommandList & rCmdList) { - fprintf(stderr, "---------------- SjApplet2::Init %p\n", pParentWin); - - return; - Reference<XMultiServiceFactory> serviceManager(getProcessServiceFactory()); - - _pImpl->_xJavaVM = Reference<XJavaVM> (serviceManager->createInstance(OUString::createFromAscii("com.sun.star.java.JavaVirtualMachine")), UNO_QUERY); - _pImpl->_xJavaThreadRegister_11 = Reference<XJavaThreadRegister_11>(_pImpl->_xJavaVM, UNO_QUERY); - - Sequence<sal_Int8> processID(16); - rtl_getGlobalProcessId((sal_uInt8 *)processID.getArray()); - Any aVMPtr = _pImpl->_xJavaVM->getJavaVM(processID); - if( sizeof( _pImpl->_pJVM ) == sizeof( sal_Int32 ) ) - { - // 32 bit system - sal_Int32 nP = 0; - aVMPtr >>= nP; - _pImpl->_pJVM = (JavaVM*)nP; - } - else if( sizeof( _pImpl->_pJVM ) == sizeof( sal_Int64 ) ) - { - // 64 bit system - sal_Int64 nP = 0; - aVMPtr >>= nP; - _pImpl->_pJVM = (JavaVM*)nP; - } - - TKTThreadAttach jenv(_pImpl->_pJVM, _pImpl->_xJavaThreadRegister_11.get()); - - // Java URL erzeugen - String aURL = rDocBase.GetMainURL(); - if ( aURL.Len() ) - { - //WorkAround, weil Java mit dem | nicht zurecht kommt - if( rDocBase.GetProtocol() == INET_PROT_FILE - && aURL.GetChar( (xub_StrLen)9 ) == INET_ENC_DELIM_TOKEN ) - aURL = aURL.Insert( INET_DELIM_TOKEN, (xub_StrLen)9 ); - } - - _pParentWin = pParentWin; - - - RuntimeException javaException(OUString::createFromAscii("java"), Reference<XInterface>()); - - try { - jclass jcURL = jenv.pEnv->FindClass("java/net/URL"); if(jenv.pEnv->ExceptionOccurred()) throw javaException; - jmethodID jmURL_rinit = jenv.pEnv->GetMethodID(jcURL, "<init>", "(Ljava/lang/String;)V"); if(jenv.pEnv->ExceptionOccurred()) throw javaException; - jobject joDocBase = jenv.pEnv->AllocObject(jcURL); if(jenv.pEnv->ExceptionOccurred()) throw javaException; - jstring jsURL = jenv.pEnv->NewString( aURL.GetBuffer(), aURL.Len() ); if(jenv.pEnv->ExceptionOccurred()) throw javaException; - jenv.pEnv->CallVoidMethod(joDocBase, jmURL_rinit, jsURL); if(jenv.pEnv->ExceptionOccurred()) throw javaException; - - jclass jcHashtable = jenv.pEnv->FindClass("java/util/Hashtable"); if(jenv.pEnv->ExceptionOccurred()) throw javaException; - jmethodID jmHashtable_rinit = jenv.pEnv->GetMethodID(jcHashtable, "<init>", "()V"); if(jenv.pEnv->ExceptionOccurred()) throw javaException; - jmethodID jmHashtable_put = jenv.pEnv->GetMethodID(jcHashtable, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); if(jenv.pEnv->ExceptionOccurred()) throw javaException; - jobject joParameters = jenv.pEnv->AllocObject(jcHashtable); if(jenv.pEnv->ExceptionOccurred()) throw javaException; - jenv.pEnv->CallVoidMethod(joParameters, jmHashtable_rinit); if(jenv.pEnv->ExceptionOccurred()) throw javaException; - - for( ULONG i = 0; i < rCmdList.Count(); i++ ) { - const SvCommand & rCmd = rCmdList[i]; - String aCmd = rCmd.GetCommand(); - String aLoweredCmd = aCmd.ToLowerAscii(); - jstring jsCommand = jenv.pEnv->NewString( aLoweredCmd.GetBuffer(), aLoweredCmd.Len() ); if(jenv.pEnv->ExceptionOccurred()) throw javaException; - jstring jsArg = jenv.pEnv->NewString( rCmd.GetArgument().GetBuffer(), rCmd.GetArgument().Len() ); if(jenv.pEnv->ExceptionOccurred()) throw javaException; - jenv.pEnv->CallVoidMethod(joParameters, jmHashtable_put, jsCommand, jsArg); if(jenv.pEnv->ExceptionOccurred()) throw javaException; - } - - -#if defined(WNT) && defined(blblblblblblb) - if (WINDOW_SYSTEMCHILDWINDOW == pParentWin->GetType()) - { - const SystemChildData* pCD = ((SystemChildWindow*) pParentWin)->GetSystemData(); - if ( pCD ) - // hier wird das C++-Wrapper-Objekt fuer ein Java-Objekt erzeugt - pWindow = new sun_awt_windows_WEmbeddedFrame((INT32)pCD->hWnd); - } - if (!pWindow) - pWindow = new sun_awt_windows_WEmbeddedFrame(); -#else - jclass jcFrame = jenv.pEnv->FindClass("java/awt/Frame"); if(jenv.pEnv->ExceptionOccurred()) throw javaException; - jmethodID jmFrame_rinit = jenv.pEnv->GetMethodID(jcFrame, "<init>", "()V"); if(jenv.pEnv->ExceptionOccurred()) throw javaException; - _pImpl->_joFrame = jenv.pEnv->AllocObject(jcFrame); if(jenv.pEnv->ExceptionOccurred()) throw javaException; - _pImpl->_joFrame = jenv.pEnv->NewGlobalRef(_pImpl->_joFrame); if(jenv.pEnv->ExceptionOccurred()) throw javaException; - jenv.pEnv->CallVoidMethod(_pImpl->_joFrame, jmFrame_rinit); if(jenv.pEnv->ExceptionOccurred()) throw javaException; -#endif - - jmethodID jmFrame_show = jenv.pEnv->GetMethodID(jcFrame, "show", "()V"); if(jenv.pEnv->ExceptionOccurred()) throw javaException; - jenv.pEnv->CallVoidMethod(_pImpl->_joFrame, jmFrame_show); if(jenv.pEnv->ExceptionOccurred()) throw javaException; - - _pImpl->_jcAppletExecutionContext = jenv.pEnv->FindClass("stardiv/applet/AppletExecutionContext"); if(jenv.pEnv->ExceptionOccurred()) throw javaException; - _pImpl->_jcAppletExecutionContext = (jclass)jenv.pEnv->NewGlobalRef( _pImpl->_jcAppletExecutionContext ); if(jenv.pEnv->ExceptionOccurred()) throw javaException; - jmethodID jmAppletExecutionContext_rinit = jenv.pEnv->GetMethodID(_pImpl->_jcAppletExecutionContext, "<init>", "(Ljava/net/URL;Ljava/util/Hashtable;Ljava/awt/Container;J)V"); if(jenv.pEnv->ExceptionOccurred()) throw javaException; - jmethodID jmAppletExecutionContext_init = jenv.pEnv->GetMethodID(_pImpl->_jcAppletExecutionContext, "init", "()V"); if(jenv.pEnv->ExceptionOccurred()) throw javaException; - jmethodID jmAppletExecutionContext_startUp = jenv.pEnv->GetMethodID(_pImpl->_jcAppletExecutionContext, "startUp", "()V"); if(jenv.pEnv->ExceptionOccurred()) throw javaException; - - _pImpl->_joAppletExecutionContext = jenv.pEnv->AllocObject(_pImpl->_jcAppletExecutionContext); if(jenv.pEnv->ExceptionOccurred()) throw javaException; - _pImpl->_joAppletExecutionContext = jenv.pEnv->NewGlobalRef(_pImpl->_joAppletExecutionContext); if(jenv.pEnv->ExceptionOccurred()) throw javaException; - jenv.pEnv->CallVoidMethod(_pImpl->_joAppletExecutionContext, jmAppletExecutionContext_rinit, joDocBase, joParameters, _pImpl->_joFrame, (jlong)0); if(jenv.pEnv->ExceptionOccurred()) throw javaException; - jenv.pEnv->CallVoidMethod(_pImpl->_joAppletExecutionContext, jmAppletExecutionContext_init); if(jenv.pEnv->ExceptionOccurred()) throw javaException; - jenv.pEnv->CallVoidMethod(_pImpl->_joAppletExecutionContext, jmAppletExecutionContext_startUp); if(jenv.pEnv->ExceptionOccurred()) throw javaException; - } - catch(RuntimeException runtimeException) { - jthrowable jtThrowable = jenv.pEnv->ExceptionOccurred(); - if(jtThrowable) { // is it a java exception ? - jenv.pEnv->ExceptionDescribe(); - jenv.pEnv->ExceptionClear(); - -// jclass jcThrowable = jenv.pEnv->FindClass("java/lang/Throwable"); if(jenv.pEnv->ExceptionOccurred()) throw javaException; -// jmethodID jmThrowable_getMessage = jenv.pEnv->GetMethodID(jcThrowable, "getMessage", "()V"); if(jenv.pEnv->ExceptionOccurred()) throw javaException; - -// jstring jsMessage = (jstring)jenv.pEnv->CallObjectMethod(jtThrowable, jmThrowable_getMessage); if(jenv.pEnv->ExceptionOccurred()) throw javaException; - -// const jchar * jcMessage = jenv.pEnv->GetStringChars(jsMessage, NULL); -// OUString ouMessage(jcMessage); -// jenv.pEnv->ReleaseStringChars(jsMessage, jcMessage); - -// throw RuntimeException(ouMessage, Reference<XInterface>()); - } - else - throw; - } -// pWindow->setVisible(TRUE); - -// pAppletExecutionContext = new stardiv_applet_AppletExecutionContext_Impl(&aDocBase, &aHashtable, pWindow, this); -// pAppletExecutionContext->init(); - -// pAppletExecutionContext->startUp(); + _pImpl->init(pParentWin, getProcessServiceFactory(), rDocBase, rCmdList); } //========================================================================= void SjApplet2::setSizePixel( const Size & rSize ) { - fprintf(stderr, "----------------setSizePixel: %i %i\n", rSize.Width(), rSize.Height()); -// _pParentWin->SetSizePixel(rSize); - -// pWindow->setSize(rSize.Width(), rSize.Height()); + _pImpl->setSize(rSize); } void SjApplet2::appletRestart() { - if(_pImpl->_joAppletExecutionContext) { - TKTThreadAttach jenv(_pImpl->_pJVM, _pImpl->_xJavaThreadRegister_11.get()); - jmethodID jmAppletExecutionContext_restart = jenv.pEnv->GetMethodID(_pImpl->_jcAppletExecutionContext, "restart", "()V"); - jenv.pEnv->CallVoidMethod(_pImpl->_joAppletExecutionContext, jmAppletExecutionContext_restart); - } + _pImpl->restart(); } void SjApplet2::appletReload() { - if(_pImpl->_joAppletExecutionContext) { - TKTThreadAttach jenv(_pImpl->_pJVM, _pImpl->_xJavaThreadRegister_11.get()); - jmethodID jmAppletExecutionContext_reload = jenv.pEnv->GetMethodID(_pImpl->_jcAppletExecutionContext, "reload", "()V"); - jenv.pEnv->CallVoidMethod(_pImpl->_joAppletExecutionContext, jmAppletExecutionContext_reload); - } + _pImpl->reload(); } void SjApplet2::appletStart() { - if(_pImpl->_joAppletExecutionContext) { - TKTThreadAttach jenv(_pImpl->_pJVM, _pImpl->_xJavaThreadRegister_11.get()); - jmethodID jmAppletExecutionContext_sendStart = jenv.pEnv->GetMethodID(_pImpl->_jcAppletExecutionContext, "sendStart", "()V"); - jenv.pEnv->CallVoidMethod(_pImpl->_joAppletExecutionContext, jmAppletExecutionContext_sendStart); - } + _pImpl->start(); } void SjApplet2::appletStop() { - if(_pImpl->_joAppletExecutionContext) { - TKTThreadAttach jenv(_pImpl->_pJVM, _pImpl->_xJavaThreadRegister_11.get()); - jmethodID jmAppletExecutionContext_sendStop = jenv.pEnv->GetMethodID(_pImpl->_jcAppletExecutionContext, "sendStop", "()V"); - jenv.pEnv->CallVoidMethod(_pImpl->_joAppletExecutionContext, jmAppletExecutionContext_sendStop); - } + _pImpl->stop(); } void SjApplet2::appletClose() { - if(_pImpl->_joAppletExecutionContext) { - TKTThreadAttach jenv(_pImpl->_pJVM, _pImpl->_xJavaThreadRegister_11.get()); - jmethodID jmAppletExecutionContext_shutdown = jenv.pEnv->GetMethodID(_pImpl->_jcAppletExecutionContext, "shutdown", "()V"); - jenv.pEnv->CallVoidMethod(_pImpl->_joAppletExecutionContext, jmAppletExecutionContext_shutdown); - } - -// pWindow->dispose(); - - if( _pParentWin ) - { - WorkWindow* pAppWin = Application::GetAppWindow(); - if(pAppWin) - { - while(_pParentWin->GetChildCount()) - { - Window* pChild = _pParentWin->GetChild(0); - pChild->Show( FALSE ); - pChild->SetParent( pAppWin ); - } - } - } - -// delete pWindow; -// pWindow = NULL; + _pImpl->close(); } // Fuer SO3, Wrapper fuer Applet liefern SjJScriptAppletObject * SjApplet2::GetJScriptApplet() { - fprintf(stderr, "----------------GetJScriptApplet\n"); + OSL_TRACE("SjApplet2::GetJScriptApplet\n"); return NULL; } diff --git a/sj2/stardiv/applet/AppletExecutionContext.java b/sj2/stardiv/applet/AppletExecutionContext.java index 189504c5aec4..0f8e1fbdb950 100644 --- a/sj2/stardiv/applet/AppletExecutionContext.java +++ b/sj2/stardiv/applet/AppletExecutionContext.java @@ -2,9 +2,9 @@ * * $RCSfile: AppletExecutionContext.java,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: kr $ $Date: 2001-03-09 11:50:39 $ + * last change: $Author: kr $ $Date: 2001-04-10 13:56:23 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -71,6 +71,7 @@ import java.awt.Container; import java.awt.Dimension; import java.awt.Panel; import java.awt.Toolkit; +import java.awt.Window; import java.io.IOException; import java.io.InputStream; @@ -95,7 +96,7 @@ import com.sun.star.lib.sandbox.CodeSource; public final class AppletExecutionContext extends ExecutionContext implements AppletStub, LiveConnectable { - private static final boolean DEBUG = true; // Enable / disable debug output + private static final boolean DEBUG = false; // Enable / disable debug output private Applet _applet; private Container _container; @@ -143,8 +144,6 @@ public final class AppletExecutionContext extends ExecutionContext } public void init() { - if(DEBUG) System.err.println("#####" + getClass().getName() + ".init()"); - _baseURL = null; try { @@ -194,6 +193,8 @@ public final class AppletExecutionContext extends ExecutionContext _documentProxy.addExecutionContext(this, _className); super.init(nm, ClassContextProxy.create(_baseURL, null, null)); + + if(DEBUG) System.err.println("#####" + getClass().getName() + ".init: _className=" + _className + " _baseURL=" + _baseURL); } void sDispose(long timeout) { @@ -273,6 +274,9 @@ public final class AppletExecutionContext extends ExecutionContext synchronized(_className) { _applet = (Applet)appletClass.newInstance(); _applet.setStub(this); + + appletResize(_container.getSize().width, _container.getSize().height); + _className.notifyAll(); } } @@ -309,6 +313,8 @@ public final class AppletExecutionContext extends ExecutionContext } protected void xdestroy() { + if(DEBUG) System.err.println("##### " + getClass().getName() + ".xdestroy"); + _applet.destroy(); _applet.setVisible(false); _applet.setStub(null); @@ -317,9 +323,15 @@ public final class AppletExecutionContext extends ExecutionContext } protected void xdispose() { - if(_container != null) + if(DEBUG) System.err.println("##### " + getClass().getName() + ".xdispose"); + + if(_container != null) { _container.remove(_applet); + if(_container instanceof Window) + ((Window)_container).dispose(); + } + _applet = null; } @@ -349,7 +361,9 @@ public final class AppletExecutionContext extends ExecutionContext * Methods for AppletStub interface */ public void appletResize(int width, int height) { - _applet.setSize(new java.awt.Dimension(width, height)); + _container.setSize(width, height); + if(_applet != null) + _applet.setSize(width, height); } public AppletContext getAppletContext() { |