Files
libreoffice/sj2/source/jscpp/sjapplet_impl.cxx
2001-08-15 10:21:55 +00:00

640 lines
27 KiB
C++

/*************************************************************************
*
* $RCSfile: sjapplet_impl.cxx,v $
*
* $Revision: 1.7 $
*
* last change: $Author: pl $ $Date: 2001-08-15 11:21:55 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc., October, 2000
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2000 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://www.openoffice.org/license.html.
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2000 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): _______________________________________
*
*
************************************************************************/
#ifdef UNX
#include <cstdarg>
#include <jni.h>
#define String XLIB_String
#define Window XLIB_Window
#define Time XLIB_Time
#define Font XLIB_Font
#define KeyCode XLIB_KeyCode
#define Region XLIB_Region
#define Cursor XLIB_Cursor
#include <jawt_md.h>
#include <X11/Xatom.h>
#undef String
#undef Window
#undef Time
#undef Font
#undef KeyCode
#undef Region
#undef Cursor
#endif
#include "sjapplet_impl.hxx"
#define HWND int
#include <rtl/ustring>
#include <rtl/process.h>
#include <osl/module.hxx>
#include <osl/mutex.hxx>
#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>
#include <vcl/sysdata.hxx>
#include <jnihelp.hxx>
using namespace ::rtl;
using namespace ::osl;
using namespace ::sj2;
using namespace ::utl;
using namespace ::com::sun::star::java;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::uno;
static void testJavaException(JNIEnv * pEnv) throw(com::sun::star::uno::RuntimeException)
{
jthrowable jtThrowable = pEnv->ExceptionOccurred();
if(jtThrowable) { // is it a java exception ?
#ifdef DEBUG
pEnv->ExceptionDescribe();
#endif
pEnv->ExceptionClear();
jclass jcThrowable = pEnv->FindClass("java/lang/Throwable");
jmethodID jmThrowable_getMessage = pEnv->GetMethodID(jcThrowable, "getMessage", "()Ljava/lang/String;");
jstring jsMessage = (jstring)pEnv->CallObjectMethod(jtThrowable, jmThrowable_getMessage);
const jchar * jcMessage = pEnv->GetStringChars(jsMessage, NULL);
OUString ouMessage(jcMessage);
pEnv->ReleaseStringChars(jsMessage, jcMessage);
throw RuntimeException(ouMessage, Reference<XInterface>());
}
}
#ifdef UNX
struct EmbeddedWindow {
jobject _joWindow;
::osl::Module _jawt;
EmbeddedWindow(JNIEnv * pEnv, SystemEnvData const * pEnvData) throw(com::sun::star::uno::RuntimeException);
void dispose(JNIEnv * pEnv);
};
static Atom getStateAtom(Display* pDisplay)
{
static Atom nWM_State = XInternAtom (pDisplay, "WM_STATE", False);
return nWM_State;
}
static Widget getAppletWidget(Widget widget) {
/* Find the shell widget to reparent.
* Normally you would just have to go up in the hierarchy
* to the widget that has no parent. But the java created
* widget hierarchy ends sometimes with a widget with no window.
* Why ? Just to anger us ?
*/
sal_Bool found = sal_False;
Display* pDisplay = XtDisplay(widget);
do
{
XLIB_Window nWindow = XtWindow(widget);
int nCount;
Atom *pAtom = XListProperties(pDisplay, nWindow, &nCount);
for (int i = 0; i < nCount && !found; ++i)
found = (pAtom[i] == XA_WM_HINTS);
XFree(pAtom);
if(found)
break;
widget = XtParent(widget);
}
while (widget);
return widget;
}
#ifdef DEBUG
static void spaces(int count) {
for(int i = 0; i < count; ++ i)
fprintf(stderr, " ");
}
static void displayTree(Display * display, XLIB_Window window, int dp) {
XLIB_Window root_return, parent_return, * children_return;
unsigned int nchildren_returnw;
XQueryTree(display, window,
&root_return, &parent_return, &children_return, &nchildren_returnw);
spaces(dp); fprintf(stderr, "RootWindow %x\n", root_return);
spaces(dp); fprintf(stderr, "ParentWindow %x\n", parent_return);
for(int i = 0; i < nchildren_returnw; ++ i) {
spaces(dp); fprintf(stderr, " child #%i %x\n", i, children_return[i]);
displayTree(display, children_return[i], dp + 1);
}
}
#endif
extern "C" {
static Bool withdrawPredicate( Display* pDisplay, XEvent* pEvent, XPointer arg )
{
Bool bRet = False;
if( pEvent->type == PropertyNotify
&& pEvent->xproperty.window == (XLIB_Window)arg
&& pEvent->xproperty.atom == getStateAtom( pDisplay )
)
{
if( pEvent->xproperty.state == PropertyDelete )
{
#ifdef DEBUG
fprintf( stderr, "window 0x%x changed to WithdrawnState (WM_STATE deleted)\n", (XLIB_Window)arg );
#endif
bRet = True;
}
else
{
Atom aType;
int format;
unsigned long items, bytes;
unsigned char* prop = NULL;
if( XGetWindowProperty( pDisplay, (XLIB_Window)arg, getStateAtom(pDisplay),
0, 1, False, getStateAtom(pDisplay),
&aType, &format, &items, &bytes, &prop ) == 0
&& prop
&& format == 32
)
{
#ifdef DEBUG
const char* pState = "<unknown>";
switch( *(sal_uInt32*)prop )
{
case 0: pState = "Withdrawn";break;
case 1: pState = "Normal";break;
case 2: pState = "Iconic";break;
}
fprintf( stderr, "window 0x%x changed to %sState\n",
(XLIB_Window)arg,
pState );
#endif
if( *(sal_uInt32*)prop == 0 )
bRet = True;
XFree( prop );
}
}
}
return bRet;
}
}
EmbeddedWindow::EmbeddedWindow(JNIEnv * pEnv, SystemEnvData const * pEnvData) throw(com::sun::star::uno::RuntimeException)
{
// create a canvas
jclass jcCanvas = pEnv->FindClass("java/awt/Canvas"); testJavaException(pEnv);
jmethodID jmCanvas_rinit = pEnv->GetMethodID(jcCanvas, "<init>", "()V" ); testJavaException(pEnv);
jobject joCanvas = pEnv->AllocObject(jcCanvas); testJavaException(pEnv);
pEnv->CallVoidMethod(joCanvas, jmCanvas_rinit); testJavaException(pEnv);
jmethodID jmCanvas_setSize = pEnv->GetMethodID(jcCanvas, "setSize", "(II)V" ); testJavaException(pEnv);
pEnv->CallVoidMethod(joCanvas, jmCanvas_setSize, 50, 50); testJavaException(pEnv);
jmethodID jmCanvas_show = pEnv->GetMethodID(jcCanvas, "show", "()V" ); testJavaException(pEnv);
pEnv->CallVoidMethod(joCanvas, jmCanvas_show); testJavaException(pEnv);
// create window and add the canvas
jclass jcFrame = pEnv->FindClass("java/awt/Frame"); testJavaException(pEnv);
jmethodID jmFrame_rinit = pEnv->GetMethodID(jcFrame, "<init>", "()V" ); testJavaException(pEnv);
jobject joFrame = pEnv->AllocObject(jcFrame); testJavaException(pEnv);
pEnv->CallVoidMethod(joFrame, jmFrame_rinit); testJavaException(pEnv);
jclass jcWindow = pEnv->FindClass("java/awt/Window"); testJavaException(pEnv);
jmethodID jmWindow_rinit = pEnv->GetMethodID(jcWindow, "<init>", "(Ljava/awt/Frame;)V" ); testJavaException(pEnv);
jobject joWindow = pEnv->AllocObject(jcWindow); testJavaException(pEnv);
pEnv->CallVoidMethod(joWindow, jmWindow_rinit, joFrame); testJavaException(pEnv);
// joWindow = joFrame;
jmethodID jmWindow_setLayout = pEnv->GetMethodID(jcWindow, "setLayout", "(Ljava/awt/LayoutManager;)V"); testJavaException(pEnv);
pEnv->CallVoidMethod(joWindow, jmWindow_setLayout, 0); testJavaException(pEnv);
jmethodID jmWindow_setSize = pEnv->GetMethodID(jcWindow, "setSize", "(II)V"); testJavaException(pEnv);
pEnv->CallVoidMethod(joWindow, jmWindow_setSize, 1, 1); testJavaException(pEnv);
jmethodID jmWindow_add = pEnv->GetMethodID(jcWindow, "add", "(Ljava/awt/Component;)Ljava/awt/Component;"); testJavaException(pEnv);
pEnv->CallObjectMethod(joWindow, jmWindow_add, joCanvas); testJavaException(pEnv);
jmethodID jmWindow_show = pEnv->GetMethodID(jcWindow, "show", "()V"); testJavaException(pEnv);
pEnv->CallVoidMethod(joWindow, jmWindow_show); testJavaException(pEnv);
typedef jboolean (JNICALL * fptr_JAWT_GetAWT)( JNIEnv * env, JAWT * awt );
fptr_JAWT_GetAWT s_fGetAWT = 0;
_jawt.load(OUString(RTL_CONSTASCII_USTRINGPARAM("libjawt.so")));
OUString aSymName( RTL_CONSTASCII_USTRINGPARAM("JAWT_GetAWT") );
s_fGetAWT = (fptr_JAWT_GetAWT)_jawt.getSymbol(aSymName);
if(!s_fGetAWT) throw RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM("EmbeddedWindow::EmbeddedWindow - JAWT_GetAWT not found")), Reference<XInterface>());
JAWT awt;
awt.version = JAWT_VERSION_1_3;
if ((*s_fGetAWT)(pEnv, &awt) == JNI_FALSE)
throw RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM("EmbeddedWindow::EmbeddedWindow - wrong awt version")), Reference<XInterface>());
// get the drawing surface
JAWT_DrawingSurface * ds = (*awt.GetDrawingSurface)(pEnv, joCanvas);
if (!ds)
throw RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM("EmbeddedWindow::EmbeddedWindow - couldn't get DrawingSurface")), Reference<XInterface>());
jint lock = 0;
JAWT_DrawingSurfaceInfo * dsi = NULL;
JAWT_X11DrawingSurfaceInfo * dsi_x11 = NULL;
try {
lock = ds->Lock(ds); // lock the drawing surface
if ((lock & JAWT_LOCK_ERROR))
throw RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM("EmbeddedWindow::EmbeddedWindow - couldn't lock DrawingSurface")), Reference<XInterface>());
dsi = ds->GetDrawingSurfaceInfo(ds); // get the drawing surface info
if (!dsi)
throw RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM("EmbeddedWindow::EmbeddedWindow - couldn't get DrawingSurfaceInfo")), Reference<XInterface>());
// get the platform-specific drawing info and reparent
JAWT_X11DrawingSurfaceInfo * dsi_x11 = (JAWT_X11DrawingSurfaceInfo *)dsi->platformInfo;
Widget widget = XtWindowToWidget(dsi_x11->display, dsi_x11->drawable);
if (!widget)
throw RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM("EmbeddedWindow::EmbeddedWindow - couldn't get DrawingSurface widget")), Reference<XInterface>());
Widget appletWidget = getAppletWidget(widget);
if(!appletWidget)
throw RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM("EmbeddedWindow::EmbeddedWindow - can't find AppletWidget")), Reference<XInterface>());
#ifdef DEBUG
fprintf(stderr, "+++++++++++++ the parent %x\n", pEnvData->aWindow);
displayTree(dsi_x11->display, pEnvData->aWindow, 0);
fprintf(stderr, "+++++++++++++ the child %x\n", XtWindow(appletWidget));
displayTree(dsi_x11->display, XtWindow(appletWidget), 0);
#endif
XWithdrawWindow( dsi_x11->display, XtWindow(appletWidget), DefaultScreen( dsi_x11->display ) );
#ifdef DEBUG
fprintf( stderr, "enter wait (Withdraw)\n" );
#endif
XEvent aEvent;
XIfEvent( dsi_x11->display, &aEvent, withdrawPredicate, (XPointer)XtWindow(appletWidget) );
#ifdef DEBUG
fprintf( stderr, "leave wait (Withdraw)\n" );
#endif
XReparentWindow(dsi_x11->display, XtWindow(appletWidget), pEnvData->aWindow, 0, 0);
XtMapWidget( appletWidget );
#ifdef DEBUG
fprintf(stderr, "------------- the child %x\n", XtWindow(appletWidget));
displayTree(dsi_x11->display, XtWindow(appletWidget), 0);
#endif
ds->FreeDrawingSurfaceInfo(dsi);
ds->Unlock(ds);
awt.FreeDrawingSurface(ds);
}
catch(...) {
if(dsi)
ds->FreeDrawingSurfaceInfo(dsi);
if (!(lock & JAWT_LOCK_ERROR))
ds->Unlock(ds);
awt.FreeDrawingSurface(ds);
throw;
}
jmethodID jmWindow_removeAll = pEnv->GetMethodID(jcWindow, "removeAll", "()V"); testJavaException(pEnv);
pEnv->CallVoidMethod(joWindow, jmWindow_removeAll); testJavaException(pEnv);
_joWindow = pEnv->NewGlobalRef(joWindow);
}
#else
struct EmbeddedWindow {
jobject _joWindow;
EmbeddedWindow(JNIEnv * pEnv, SystemEnvData const * pEnvData) throw(com::sun::star::uno::RuntimeException);
void dispose(JNIEnv * pEnv);
};
#ifdef WNT
EmbeddedWindow::EmbeddedWindow(JNIEnv * pEnv, SystemEnvData const * pEnvData) throw(com::sun::star::uno::RuntimeException)
{
jclass jcFrame = pEnv->FindClass("sun/awt/windows/WEmbeddedFrame"); testJavaException(pEnv);
jmethodID jmFrame_rinit = pEnv->GetMethodID(jcFrame, "<init>", "(I)V"); testJavaException(pEnv);
jobject joFrame = pEnv->AllocObject(jcFrame); testJavaException(pEnv);
pEnv->CallVoidMethod(joFrame, jmFrame_rinit, (jint)pEnvData->hWnd); testJavaException(pEnv);
_joWindow = pEnv->NewGlobalRef(joFrame);
}
#else
EmbeddedWindow::EmbeddedWindow(JNIEnv * pEnv, SystemEnvData const * pEnvData) throw(com::sun::star::uno::RuntimeException)
{
jclass jcFrame = pEnv->FindClass("java/awt/Frame"); testJavaException(pEnv);
jmethodID jmFrame_rinit = pEnv->GetMethodID(jcFrame, "<init>", "()V"); testJavaException(pEnv);
joFrame = pEnv->AllocObject(jcFrame); testJavaException(pEnv);
pEnv->CallVoidMethod(joFrame, jmFrame_rinit); testJavaException(pEnv);
_joWindow = pEnv->NewGlobalRef(joFrame);
}
#endif
#endif
void EmbeddedWindow::dispose(JNIEnv * pEnv)
{
jclass jcWindow = pEnv->FindClass("java/awt/Window"); testJavaException(pEnv);
jmethodID jmWindow_dispose = pEnv->GetMethodID(jcWindow, "dispose", "()V" ); testJavaException(pEnv);
pEnv->CallVoidMethod(_joWindow, jmWindow_dispose); testJavaException(pEnv);
pEnv->DeleteGlobalRef(_joWindow);
_joWindow = 0;
}
SjApplet2_Impl::SjApplet2_Impl() throw(com::sun::star::uno::RuntimeException)
: _pJVM(NULL),
_joAppletExecutionContext(0),
_jcAppletExecutionContext(0)
{}
SjApplet2_Impl::~SjApplet2_Impl() throw() {
if (_joAppletExecutionContext) {
TKTThreadAttach jenv(_pJVM, _xJavaThreadRegister_11.get());
_pEmbeddedWindow->dispose(jenv.pEnv);
delete _pEmbeddedWindow;
jenv.pEnv->DeleteGlobalRef(_joAppletExecutionContext);
jenv.pEnv->DeleteGlobalRef(_jcAppletExecutionContext);
}
}
void SjApplet2_Impl::init(Window * pParentWin,
const Reference<XMultiServiceFactory> & smgr,
const INetURLObject & rDocBase,
const SvCommandList & rCmdList)
throw(com::sun::star::uno::RuntimeException)
{
_pParentWin = pParentWin;
// Java URL erzeugen
OUString url = rDocBase.GetMainURL();
if(!url.getLength())
url = OUString(RTL_CONSTASCII_USTRINGPARAM("file:///"));
if (url.getLength()) {
//WorkAround, weil Java mit dem | nicht zurecht kommt
if(rDocBase.GetProtocol() == INET_PROT_FILE && url.pData->buffer[9] == INET_ENC_DELIM_TOKEN) {
OUString tmp = url.copy(0, 9);
tmp += OUString(INET_DELIM_TOKEN);
tmp += url.copy(10);
url = tmp;
}
}
#ifdef DEBUG
OString tmp = OUStringToOString(url, RTL_TEXTENCODING_ASCII_US);
OSL_TRACE("SjApplet2_Impl::init - mainUrl: %s\n", tmp.getStr());
#endif
_xJavaVM = Reference<XJavaVM>(smgr->createInstance(OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.java.JavaVirtualMachine"))), UNO_QUERY);
_xJavaThreadRegister_11 = Reference<XJavaThreadRegister_11>(_xJavaVM, UNO_QUERY);
Sequence<sal_Int8> processID(16);
rtl_getGlobalProcessId((sal_uInt8 *)processID.getArray());
Any aVMPtr = _xJavaVM->getJavaVM(processID);
if( sizeof(_pJVM) == sizeof(sal_Int32))
{
// 32 bit system
sal_Int32 nP = 0;
aVMPtr >>= nP;
_pJVM = (JavaVM*)nP;
}
else if(sizeof(_pJVM) == sizeof(sal_Int64))
{
// 64 bit system
sal_Int64 nP = 0;
aVMPtr >>= nP;
_pJVM = (JavaVM*)nP;
}
if(!_pJVM) // did we get a vm?
throw RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM("sjapplet_impl.cxx: couldn't get a java vm")), Reference<XInterface>());
TKTThreadAttach jenv(_pJVM, _xJavaThreadRegister_11.get());
_jcAppletExecutionContext = jenv.pEnv->FindClass("stardiv/applet/AppletExecutionContext"); testJavaException(jenv.pEnv);
_jcAppletExecutionContext = (jclass)jenv.pEnv->NewGlobalRef(_jcAppletExecutionContext ); testJavaException(jenv.pEnv);
jclass jcURL = jenv.pEnv->FindClass("java/net/URL"); testJavaException(jenv.pEnv);
jmethodID jmURL_rinit = jenv.pEnv->GetMethodID(jcURL, "<init>", "(Ljava/lang/String;)V"); testJavaException(jenv.pEnv);
jobject joDocBase = jenv.pEnv->AllocObject(jcURL); testJavaException(jenv.pEnv);
jstring jsURL = jenv.pEnv->NewString(url.getStr(), url.getLength()); testJavaException(jenv.pEnv);
jenv.pEnv->CallVoidMethod(joDocBase, jmURL_rinit, jsURL); testJavaException(jenv.pEnv);
jclass jcHashtable = jenv.pEnv->FindClass("java/util/Hashtable"); testJavaException(jenv.pEnv);
jmethodID jmHashtable_rinit = jenv.pEnv->GetMethodID(jcHashtable, "<init>", "()V"); testJavaException(jenv.pEnv);
jmethodID jmHashtable_put = jenv.pEnv->GetMethodID(jcHashtable, "put",
"(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); testJavaException(jenv.pEnv);
jobject joParameters = jenv.pEnv->AllocObject(jcHashtable); testJavaException(jenv.pEnv);
jenv.pEnv->CallVoidMethod(joParameters, jmHashtable_rinit); testJavaException(jenv.pEnv);
for(sal_Int64 i = 0; i < rCmdList.Count(); ++i) {
const SvCommand & rCmd = rCmdList[i];
String aCmd = rCmd.GetCommand();
String aLoweredCmd = aCmd.ToLowerAscii();
#ifdef DEBUG
OUString command = aCmd;
OUString value = rCmd.GetArgument();
OString cmd_tmp = OUStringToOString(command, RTL_TEXTENCODING_ASCII_US);
OString value_tmp = OUStringToOString(value, RTL_TEXTENCODING_ASCII_US);
OSL_TRACE("command: %s=%s", cmd_tmp.getStr(), value_tmp.getStr());
#endif
jstring jsCommand = jenv.pEnv->NewString(aLoweredCmd.GetBuffer(), aLoweredCmd.Len()); testJavaException(jenv.pEnv);
jstring jsArg = jenv.pEnv->NewString(rCmd.GetArgument().GetBuffer(), rCmd.GetArgument().Len()); testJavaException(jenv.pEnv);
jenv.pEnv->CallObjectMethod(joParameters, jmHashtable_put, jsCommand, jsArg); testJavaException(jenv.pEnv);
}
SystemEnvData const * pEnvData = ((SystemChildWindow *)pParentWin)->GetSystemData();
_pEmbeddedWindow = new EmbeddedWindow(jenv.pEnv, pEnvData);
jmethodID jmAppletExecutionContext_rinit = jenv.pEnv->GetMethodID(_jcAppletExecutionContext, "<init>",
"(Ljava/net/URL;Ljava/util/Hashtable;Ljava/awt/Container;J)V"); testJavaException(jenv.pEnv);
jmethodID jmAppletExecutionContext_init = jenv.pEnv->GetMethodID(_jcAppletExecutionContext, "init", "()V"); testJavaException(jenv.pEnv);
jmethodID jmAppletExecutionContext_startUp = jenv.pEnv->GetMethodID(_jcAppletExecutionContext, "startUp", "()V"); testJavaException(jenv.pEnv);
_joAppletExecutionContext = jenv.pEnv->AllocObject(_jcAppletExecutionContext); testJavaException(jenv.pEnv);
_joAppletExecutionContext = jenv.pEnv->NewGlobalRef(_joAppletExecutionContext); testJavaException(jenv.pEnv);
jenv.pEnv->CallVoidMethod(_joAppletExecutionContext, jmAppletExecutionContext_rinit,
joDocBase, joParameters, _pEmbeddedWindow->_joWindow, (jlong)0); testJavaException(jenv.pEnv);
jenv.pEnv->CallVoidMethod(_joAppletExecutionContext, jmAppletExecutionContext_init); testJavaException(jenv.pEnv);
jenv.pEnv->CallVoidMethod(_joAppletExecutionContext, jmAppletExecutionContext_startUp); testJavaException(jenv.pEnv);
}
void SjApplet2_Impl::setSize(const Size & rSize) throw(com::sun::star::uno::RuntimeException)
{
TKTThreadAttach jenv(_pJVM, _xJavaThreadRegister_11.get());
_pParentWin->SetSizePixel(rSize);
jmethodID jmAppletExecutionContext_resize = jenv.pEnv->GetMethodID(_jcAppletExecutionContext, "appletResize", "(II)V"); testJavaException(jenv.pEnv);
jenv.pEnv->CallVoidMethod(_joAppletExecutionContext, jmAppletExecutionContext_resize, (jint)rSize.Width(),
(jint)rSize.Height()); testJavaException(jenv.pEnv);
}
void SjApplet2_Impl::restart() throw(com::sun::star::uno::RuntimeException)
{
TKTThreadAttach jenv(_pJVM, _xJavaThreadRegister_11.get());
jmethodID jmAppletExecutionContext_restart = jenv.pEnv->GetMethodID(_jcAppletExecutionContext, "restart", "()V"); testJavaException(jenv.pEnv);
jenv.pEnv->CallVoidMethod(_joAppletExecutionContext, jmAppletExecutionContext_restart); testJavaException(jenv.pEnv);
}
void SjApplet2_Impl::reload() throw(com::sun::star::uno::RuntimeException)
{
TKTThreadAttach jenv(_pJVM, _xJavaThreadRegister_11.get());
jmethodID jmAppletExecutionContext_reload = jenv.pEnv->GetMethodID(_jcAppletExecutionContext, "reload", "()V"); testJavaException(jenv.pEnv);
jenv.pEnv->CallVoidMethod(_joAppletExecutionContext, jmAppletExecutionContext_reload); testJavaException(jenv.pEnv);
}
void SjApplet2_Impl::start() throw(com::sun::star::uno::RuntimeException)
{
TKTThreadAttach jenv(_pJVM, _xJavaThreadRegister_11.get());
jmethodID jmAppletExecutionContext_sendStart = jenv.pEnv->GetMethodID(_jcAppletExecutionContext, "sendStart", "()V"); testJavaException(jenv.pEnv);
jenv.pEnv->CallVoidMethod(_joAppletExecutionContext, jmAppletExecutionContext_sendStart); testJavaException(jenv.pEnv);
}
void SjApplet2_Impl::stop() throw(com::sun::star::uno::RuntimeException)
{
TKTThreadAttach jenv(_pJVM, _xJavaThreadRegister_11.get());
jmethodID jmAppletExecutionContext_sendStop = jenv.pEnv->GetMethodID(_jcAppletExecutionContext, "sendStop", "()V"); testJavaException(jenv.pEnv);
jenv.pEnv->CallVoidMethod(_joAppletExecutionContext, jmAppletExecutionContext_sendStop); testJavaException(jenv.pEnv);
}
void SjApplet2_Impl::close() throw(com::sun::star::uno::RuntimeException)
{
TKTThreadAttach jenv(_pJVM, _xJavaThreadRegister_11.get());
jmethodID jmAppletExecutionContext_shutdown = jenv.pEnv->GetMethodID(_jcAppletExecutionContext, "shutdown", "()V"); testJavaException(jenv.pEnv);
jenv.pEnv->CallVoidMethod(_joAppletExecutionContext, jmAppletExecutionContext_shutdown); testJavaException(jenv.pEnv);
if( _pParentWin )
{
WorkWindow* pAppWin = Application::GetAppWindow();
if(pAppWin)
{
while(_pParentWin->GetChildCount())
{
Window* pChild = _pParentWin->GetChild(0);
pChild->Show( FALSE );
pChild->SetParent( pAppWin );
}
}
}
}