1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_vcl.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <rtl/process.h> 32*cdf0e10cSrcweir #include <rtl/ref.hxx> 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir #include <tools/rc.h> 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir // declare system types in sysdata.hxx 37*cdf0e10cSrcweir #include <svsys.h> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir #include <vcl/window.hxx> 40*cdf0e10cSrcweir #include <vcl/sysdata.hxx> 41*cdf0e10cSrcweir #include <vcl/svapp.hxx> 42*cdf0e10cSrcweir #include <vcl/syschild.hxx> 43*cdf0e10cSrcweir #include <vcl/unohelp.hxx> 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir #include <window.h> 46*cdf0e10cSrcweir #include <salinst.hxx> 47*cdf0e10cSrcweir #include <salframe.hxx> 48*cdf0e10cSrcweir #include <salobj.hxx> 49*cdf0e10cSrcweir #include <svdata.hxx> 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir #ifdef SOLAR_JAVA 52*cdf0e10cSrcweir #include <jni.h> 53*cdf0e10cSrcweir #endif 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 56*cdf0e10cSrcweir #include <jvmaccess/virtualmachine.hxx> 57*cdf0e10cSrcweir #include <com/sun/star/java/XJavaVM.hpp> 58*cdf0e10cSrcweir #include <com/sun/star/java/XJavaThreadRegister_11.hpp> 59*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir using namespace ::com::sun::star; 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir // ======================================================================= 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir long ImplSysChildProc( void* pInst, SalObject* /* pObject */, 66*cdf0e10cSrcweir sal_uInt16 nEvent, const void* /* pEvent */ ) 67*cdf0e10cSrcweir { 68*cdf0e10cSrcweir SystemChildWindow* pWindow = (SystemChildWindow*)pInst; 69*cdf0e10cSrcweir long nRet = 0; 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir ImplDelData aDogTag( pWindow ); 72*cdf0e10cSrcweir switch ( nEvent ) 73*cdf0e10cSrcweir { 74*cdf0e10cSrcweir case SALOBJ_EVENT_GETFOCUS: 75*cdf0e10cSrcweir // Focus holen und zwar so, das alle Handler gerufen 76*cdf0e10cSrcweir // werden, als ob dieses Fenster den Focus bekommt, 77*cdf0e10cSrcweir // ohne das der Frame den Focus wieder klaut 78*cdf0e10cSrcweir pWindow->ImplGetFrameData()->mbSysObjFocus = sal_True; 79*cdf0e10cSrcweir pWindow->ImplGetFrameData()->mbInSysObjToTopHdl = sal_True; 80*cdf0e10cSrcweir pWindow->ToTop( TOTOP_NOGRABFOCUS ); 81*cdf0e10cSrcweir if( aDogTag.IsDead() ) 82*cdf0e10cSrcweir break; 83*cdf0e10cSrcweir pWindow->ImplGetFrameData()->mbInSysObjToTopHdl = sal_False; 84*cdf0e10cSrcweir pWindow->ImplGetFrameData()->mbInSysObjFocusHdl = sal_True; 85*cdf0e10cSrcweir pWindow->GrabFocus(); 86*cdf0e10cSrcweir if( aDogTag.IsDead() ) 87*cdf0e10cSrcweir break; 88*cdf0e10cSrcweir pWindow->ImplGetFrameData()->mbInSysObjFocusHdl = sal_False; 89*cdf0e10cSrcweir break; 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir case SALOBJ_EVENT_LOSEFOCUS: 92*cdf0e10cSrcweir // Hintenrum einen LoseFocus ausloesen, das der Status 93*cdf0e10cSrcweir // der Fenster dem entsprechenden Activate-Status 94*cdf0e10cSrcweir // entspricht 95*cdf0e10cSrcweir pWindow->ImplGetFrameData()->mbSysObjFocus = sal_False; 96*cdf0e10cSrcweir if ( !pWindow->ImplGetFrameData()->mnFocusId ) 97*cdf0e10cSrcweir { 98*cdf0e10cSrcweir pWindow->ImplGetFrameData()->mbStartFocusState = sal_True; 99*cdf0e10cSrcweir Application::PostUserEvent( pWindow->ImplGetFrameData()->mnFocusId, LINK( pWindow->ImplGetFrameWindow(), Window, ImplAsyncFocusHdl ) ); 100*cdf0e10cSrcweir } 101*cdf0e10cSrcweir break; 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir case SALOBJ_EVENT_TOTOP: 104*cdf0e10cSrcweir pWindow->ImplGetFrameData()->mbInSysObjToTopHdl = sal_True; 105*cdf0e10cSrcweir if ( !Application::GetFocusWindow() || pWindow->HasChildPathFocus() ) 106*cdf0e10cSrcweir pWindow->ToTop( TOTOP_NOGRABFOCUS ); 107*cdf0e10cSrcweir else 108*cdf0e10cSrcweir pWindow->ToTop(); 109*cdf0e10cSrcweir if( aDogTag.IsDead() ) 110*cdf0e10cSrcweir break; 111*cdf0e10cSrcweir pWindow->GrabFocus(); 112*cdf0e10cSrcweir if( aDogTag.IsDead() ) 113*cdf0e10cSrcweir break; 114*cdf0e10cSrcweir pWindow->ImplGetFrameData()->mbInSysObjToTopHdl = sal_False; 115*cdf0e10cSrcweir break; 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir return nRet; 119*cdf0e10cSrcweir } 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir // ======================================================================= 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir void SystemChildWindow::ImplInitSysChild( Window* pParent, WinBits nStyle, SystemWindowData *pData, sal_Bool bShow ) 124*cdf0e10cSrcweir { 125*cdf0e10cSrcweir mpWindowImpl->mpSysObj = ImplGetSVData()->mpDefInst->CreateObject( pParent->ImplGetFrame(), pData, bShow ); 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir Window::ImplInit( pParent, nStyle, NULL ); 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir // Wenn es ein richtiges SysChild ist, dann painten wir auch nicht 130*cdf0e10cSrcweir if ( GetSystemData() ) 131*cdf0e10cSrcweir { 132*cdf0e10cSrcweir mpWindowImpl->mpSysObj->SetCallback( this, ImplSysChildProc ); 133*cdf0e10cSrcweir SetParentClipMode( PARENTCLIPMODE_CLIP ); 134*cdf0e10cSrcweir SetBackground(); 135*cdf0e10cSrcweir } 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir // ----------------------------------------------------------------------- 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir SystemChildWindow::SystemChildWindow( Window* pParent, WinBits nStyle ) : 141*cdf0e10cSrcweir Window( WINDOW_SYSTEMCHILDWINDOW ) 142*cdf0e10cSrcweir { 143*cdf0e10cSrcweir ImplInitSysChild( pParent, nStyle, NULL ); 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir // ----------------------------------------------------------------------- 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir SystemChildWindow::SystemChildWindow( Window* pParent, WinBits nStyle, SystemWindowData *pData, sal_Bool bShow ) : 149*cdf0e10cSrcweir Window( WINDOW_SYSTEMCHILDWINDOW ) 150*cdf0e10cSrcweir { 151*cdf0e10cSrcweir ImplInitSysChild( pParent, nStyle, pData, bShow ); 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir // ----------------------------------------------------------------------- 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir SystemChildWindow::SystemChildWindow( Window* pParent, const ResId& rResId ) : 157*cdf0e10cSrcweir Window( WINDOW_SYSTEMCHILDWINDOW ) 158*cdf0e10cSrcweir { 159*cdf0e10cSrcweir rResId.SetRT( RSC_WINDOW ); 160*cdf0e10cSrcweir WinBits nStyle = ImplInitRes( rResId ); 161*cdf0e10cSrcweir ImplInitSysChild( pParent, nStyle, NULL ); 162*cdf0e10cSrcweir ImplLoadRes( rResId ); 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir if ( !(nStyle & WB_HIDE) ) 165*cdf0e10cSrcweir Show(); 166*cdf0e10cSrcweir } 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir // ----------------------------------------------------------------------- 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir SystemChildWindow::~SystemChildWindow() 171*cdf0e10cSrcweir { 172*cdf0e10cSrcweir Hide(); 173*cdf0e10cSrcweir if ( mpWindowImpl->mpSysObj ) 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir ImplGetSVData()->mpDefInst->DestroyObject( mpWindowImpl->mpSysObj ); 176*cdf0e10cSrcweir mpWindowImpl->mpSysObj = NULL; 177*cdf0e10cSrcweir } 178*cdf0e10cSrcweir } 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir // ----------------------------------------------------------------------- 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir const SystemEnvData* SystemChildWindow::GetSystemData() const 183*cdf0e10cSrcweir { 184*cdf0e10cSrcweir if ( mpWindowImpl->mpSysObj ) 185*cdf0e10cSrcweir return mpWindowImpl->mpSysObj->GetSystemData(); 186*cdf0e10cSrcweir else 187*cdf0e10cSrcweir return NULL; 188*cdf0e10cSrcweir } 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir // ----------------------------------------------------------------------- 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir void SystemChildWindow::EnableEraseBackground( sal_Bool bEnable ) 193*cdf0e10cSrcweir { 194*cdf0e10cSrcweir if ( mpWindowImpl->mpSysObj ) 195*cdf0e10cSrcweir mpWindowImpl->mpSysObj->EnableEraseBackground( bEnable ); 196*cdf0e10cSrcweir } 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir // ----------------------------------------------------------------------- 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir sal_Bool SystemChildWindow::IsEraseBackgroundEnabled() 201*cdf0e10cSrcweir { 202*cdf0e10cSrcweir if ( mpWindowImpl->mpSysObj ) 203*cdf0e10cSrcweir return mpWindowImpl->mpSysObj->IsEraseBackgroundEnabled(); 204*cdf0e10cSrcweir else 205*cdf0e10cSrcweir return sal_False; 206*cdf0e10cSrcweir } 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir // ----------------------------------------------------------------------- 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir void SystemChildWindow::ImplTestJavaException( void* pEnv ) 211*cdf0e10cSrcweir { 212*cdf0e10cSrcweir #ifdef SOLAR_JAVA 213*cdf0e10cSrcweir JNIEnv* pJavaEnv = reinterpret_cast< JNIEnv* >( pEnv ); 214*cdf0e10cSrcweir jthrowable jtThrowable = pJavaEnv->ExceptionOccurred(); 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir if( jtThrowable ) 217*cdf0e10cSrcweir { // is it a java exception ? 218*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 219*cdf0e10cSrcweir pJavaEnv->ExceptionDescribe(); 220*cdf0e10cSrcweir #endif // OSL_DEBUG_LEVEL > 1 221*cdf0e10cSrcweir pJavaEnv->ExceptionClear(); 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir jclass jcThrowable = pJavaEnv->FindClass("java/lang/Throwable"); 224*cdf0e10cSrcweir jmethodID jmThrowable_getMessage = pJavaEnv->GetMethodID(jcThrowable, "getMessage", "()Ljava/lang/String;"); 225*cdf0e10cSrcweir jstring jsMessage = (jstring) pJavaEnv->CallObjectMethod(jtThrowable, jmThrowable_getMessage); 226*cdf0e10cSrcweir ::rtl::OUString ouMessage; 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir if(jsMessage) 229*cdf0e10cSrcweir { 230*cdf0e10cSrcweir const jchar * jcMessage = pJavaEnv->GetStringChars(jsMessage, NULL); 231*cdf0e10cSrcweir ouMessage = ::rtl::OUString(jcMessage); 232*cdf0e10cSrcweir pJavaEnv->ReleaseStringChars(jsMessage, jcMessage); 233*cdf0e10cSrcweir } 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir throw uno::RuntimeException(ouMessage, uno::Reference<uno::XInterface>()); 236*cdf0e10cSrcweir } 237*cdf0e10cSrcweir #endif // SOLAR_JAVA 238*cdf0e10cSrcweir } 239*cdf0e10cSrcweir 240*cdf0e10cSrcweir // ----------------------------------------------------------------------- 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir sal_IntPtr SystemChildWindow::GetParentWindowHandle( sal_Bool bUseJava ) 243*cdf0e10cSrcweir { 244*cdf0e10cSrcweir sal_IntPtr nRet = 0; 245*cdf0e10cSrcweir 246*cdf0e10cSrcweir (void)bUseJava; 247*cdf0e10cSrcweir #if defined WNT 248*cdf0e10cSrcweir nRet = reinterpret_cast< sal_IntPtr >( GetSystemData()->hWnd ); 249*cdf0e10cSrcweir #elif defined QUARTZ 250*cdf0e10cSrcweir // FIXME: this is wrong 251*cdf0e10cSrcweir nRet = reinterpret_cast< sal_IntPtr >( GetSystemData()->pView ); 252*cdf0e10cSrcweir #elif defined UNX 253*cdf0e10cSrcweir if( !bUseJava ) 254*cdf0e10cSrcweir { 255*cdf0e10cSrcweir nRet = (sal_IntPtr) GetSystemData()->aWindow; 256*cdf0e10cSrcweir } 257*cdf0e10cSrcweir #ifdef SOLAR_JAVA 258*cdf0e10cSrcweir else 259*cdf0e10cSrcweir { 260*cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xFactory( vcl::unohelper::GetMultiServiceFactory() ); 261*cdf0e10cSrcweir 262*cdf0e10cSrcweir if( xFactory.is() && ( GetSystemData()->aWindow > 0 ) ) 263*cdf0e10cSrcweir { 264*cdf0e10cSrcweir try 265*cdf0e10cSrcweir { 266*cdf0e10cSrcweir ::rtl::Reference< ::jvmaccess::VirtualMachine > xVM; 267*cdf0e10cSrcweir uno::Reference< java::XJavaVM > xJavaVM( xFactory->createInstance( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.java.JavaVirtualMachine") ) ), uno::UNO_QUERY ); 268*cdf0e10cSrcweir uno::Sequence< sal_Int8 > aProcessID( 17 ); 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir rtl_getGlobalProcessId( (sal_uInt8*) aProcessID.getArray() ); 271*cdf0e10cSrcweir aProcessID[ 16 ] = 0; 272*cdf0e10cSrcweir OSL_ENSURE(sizeof (sal_Int64) >= sizeof (jvmaccess::VirtualMachine *), "Pointer cannot be represented as sal_Int64"); 273*cdf0e10cSrcweir sal_Int64 nPointer = reinterpret_cast< sal_Int64 >( static_cast< jvmaccess::VirtualMachine * >(0)); 274*cdf0e10cSrcweir xJavaVM->getJavaVM(aProcessID) >>= nPointer; 275*cdf0e10cSrcweir xVM = reinterpret_cast< jvmaccess::VirtualMachine * >(nPointer); 276*cdf0e10cSrcweir 277*cdf0e10cSrcweir if( xVM.is() ) 278*cdf0e10cSrcweir { 279*cdf0e10cSrcweir try 280*cdf0e10cSrcweir { 281*cdf0e10cSrcweir ::jvmaccess::VirtualMachine::AttachGuard aVMAttachGuard( xVM ); 282*cdf0e10cSrcweir JNIEnv* pEnv = aVMAttachGuard.getEnvironment(); 283*cdf0e10cSrcweir 284*cdf0e10cSrcweir jclass jcToolkit = pEnv->FindClass("java/awt/Toolkit"); 285*cdf0e10cSrcweir ImplTestJavaException(pEnv); 286*cdf0e10cSrcweir 287*cdf0e10cSrcweir jmethodID jmToolkit_getDefaultToolkit = pEnv->GetStaticMethodID( jcToolkit, "getDefaultToolkit", "()Ljava/awt/Toolkit;" ); 288*cdf0e10cSrcweir ImplTestJavaException(pEnv); 289*cdf0e10cSrcweir 290*cdf0e10cSrcweir pEnv->CallStaticObjectMethod(jcToolkit, jmToolkit_getDefaultToolkit); 291*cdf0e10cSrcweir ImplTestJavaException(pEnv); 292*cdf0e10cSrcweir 293*cdf0e10cSrcweir jclass jcMotifAppletViewer = pEnv->FindClass("sun/plugin/navig/motif/MotifAppletViewer"); 294*cdf0e10cSrcweir if( pEnv->ExceptionOccurred() ) 295*cdf0e10cSrcweir { 296*cdf0e10cSrcweir pEnv->ExceptionClear(); 297*cdf0e10cSrcweir 298*cdf0e10cSrcweir jcMotifAppletViewer = pEnv->FindClass( "sun/plugin/viewer/MNetscapePluginContext"); 299*cdf0e10cSrcweir ImplTestJavaException(pEnv); 300*cdf0e10cSrcweir } 301*cdf0e10cSrcweir 302*cdf0e10cSrcweir jclass jcClassLoader = pEnv->FindClass("java/lang/ClassLoader"); 303*cdf0e10cSrcweir ImplTestJavaException(pEnv); 304*cdf0e10cSrcweir 305*cdf0e10cSrcweir jmethodID jmClassLoader_loadLibrary = pEnv->GetStaticMethodID( jcClassLoader, "loadLibrary", "(Ljava/lang/Class;Ljava/lang/String;Z)V"); 306*cdf0e10cSrcweir ImplTestJavaException(pEnv); 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir jstring jsplugin = pEnv->NewStringUTF("javaplugin_jni"); 309*cdf0e10cSrcweir ImplTestJavaException(pEnv); 310*cdf0e10cSrcweir 311*cdf0e10cSrcweir pEnv->CallStaticVoidMethod(jcClassLoader, jmClassLoader_loadLibrary, jcMotifAppletViewer, jsplugin, JNI_FALSE); 312*cdf0e10cSrcweir ImplTestJavaException(pEnv); 313*cdf0e10cSrcweir 314*cdf0e10cSrcweir jmethodID jmMotifAppletViewer_getWidget = pEnv->GetStaticMethodID( jcMotifAppletViewer, "getWidget", "(IIIII)I" ); 315*cdf0e10cSrcweir ImplTestJavaException(pEnv); 316*cdf0e10cSrcweir 317*cdf0e10cSrcweir const Size aSize( GetOutputSizePixel() ); 318*cdf0e10cSrcweir jint ji_widget = pEnv->CallStaticIntMethod( jcMotifAppletViewer, jmMotifAppletViewer_getWidget, 319*cdf0e10cSrcweir GetSystemData()->aWindow, 0, 0, aSize.Width(), aSize.Height() ); 320*cdf0e10cSrcweir ImplTestJavaException(pEnv); 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir nRet = static_cast< sal_IntPtr >( ji_widget ); 323*cdf0e10cSrcweir } 324*cdf0e10cSrcweir catch( uno::RuntimeException& ) 325*cdf0e10cSrcweir { 326*cdf0e10cSrcweir } 327*cdf0e10cSrcweir 328*cdf0e10cSrcweir if( !nRet ) 329*cdf0e10cSrcweir nRet = static_cast< sal_IntPtr >( GetSystemData()->aWindow ); 330*cdf0e10cSrcweir } 331*cdf0e10cSrcweir } 332*cdf0e10cSrcweir catch( ... ) 333*cdf0e10cSrcweir { 334*cdf0e10cSrcweir } 335*cdf0e10cSrcweir } 336*cdf0e10cSrcweir } 337*cdf0e10cSrcweir #endif // SOLAR_JAVA 338*cdf0e10cSrcweir #else // WNT || QUARTZ || UNX 339*cdf0e10cSrcweir #endif 340*cdf0e10cSrcweir 341*cdf0e10cSrcweir return nRet; 342*cdf0e10cSrcweir } 343