LCOV - code coverage report
Current view: top level - vcl/source/window - syschild.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 132 0.0 %
Date: 2014-04-14 Functions: 0 11 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <config_features.h>
      21             : 
      22             : #include <rtl/process.h>
      23             : #include <rtl/ref.hxx>
      24             : 
      25             : #include <tools/rc.h>
      26             : 
      27             : // declare system types in sysdata.hxx
      28             : #include <svsys.h>
      29             : 
      30             : #include <vcl/window.hxx>
      31             : #include <vcl/sysdata.hxx>
      32             : #include <vcl/svapp.hxx>
      33             : #include <vcl/syschild.hxx>
      34             : 
      35             : #include <window.h>
      36             : #include <salinst.hxx>
      37             : #include <salframe.hxx>
      38             : #include <salobj.hxx>
      39             : #include <svdata.hxx>
      40             : 
      41             : #if HAVE_FEATURE_JAVA
      42             : #include <jni.h>
      43             : #endif
      44             : 
      45             : #include <comphelper/processfactory.hxx>
      46             : 
      47             : #if HAVE_FEATURE_JAVA
      48             : #include <jvmaccess/virtualmachine.hxx>
      49             : #include <com/sun/star/java/JavaVirtualMachine.hpp>
      50             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      51             : #endif
      52             : 
      53             : using namespace ::com::sun::star;
      54             : 
      55           0 : long ImplSysChildProc( void* pInst, SalObject* /* pObject */,
      56             :                        sal_uInt16 nEvent, const void* /* pEvent */ )
      57             : {
      58           0 :     SystemChildWindow* pWindow = (SystemChildWindow*)pInst;
      59           0 :     long nRet = 0;
      60             : 
      61           0 :     ImplDelData aDogTag( pWindow );
      62           0 :     switch ( nEvent )
      63             :     {
      64             :         case SALOBJ_EVENT_GETFOCUS:
      65             :             // get focus, such that all handlers are called,
      66             :             // as if this window gets the focus assuring
      67             :             // that the frame does not steal it
      68           0 :             pWindow->ImplGetFrameData()->mbSysObjFocus = true;
      69           0 :             pWindow->ImplGetFrameData()->mbInSysObjToTopHdl = true;
      70           0 :             pWindow->ToTop( TOTOP_NOGRABFOCUS );
      71           0 :             if( aDogTag.IsDead() )
      72           0 :                 break;
      73           0 :             pWindow->ImplGetFrameData()->mbInSysObjToTopHdl = false;
      74           0 :             pWindow->ImplGetFrameData()->mbInSysObjFocusHdl = true;
      75           0 :             pWindow->GrabFocus();
      76           0 :             if( aDogTag.IsDead() )
      77           0 :                 break;
      78           0 :             pWindow->ImplGetFrameData()->mbInSysObjFocusHdl = false;
      79           0 :             break;
      80             : 
      81             :         case SALOBJ_EVENT_LOSEFOCUS:
      82             :             // trigger a LoseFocus which matches the status
      83             :             // of the window with matching Activate-Status
      84           0 :             pWindow->ImplGetFrameData()->mbSysObjFocus = false;
      85           0 :             if ( !pWindow->ImplGetFrameData()->mnFocusId )
      86             :             {
      87           0 :                 pWindow->ImplGetFrameData()->mbStartFocusState = true;
      88           0 :                 Application::PostUserEvent( pWindow->ImplGetFrameData()->mnFocusId, LINK( pWindow->ImplGetFrameWindow(), Window, ImplAsyncFocusHdl ) );
      89             :             }
      90           0 :             break;
      91             : 
      92             :         case SALOBJ_EVENT_TOTOP:
      93           0 :             pWindow->ImplGetFrameData()->mbInSysObjToTopHdl = true;
      94           0 :             if ( !Application::GetFocusWindow() || pWindow->HasChildPathFocus() )
      95           0 :                 pWindow->ToTop( TOTOP_NOGRABFOCUS );
      96             :             else
      97           0 :                 pWindow->ToTop();
      98           0 :             if( aDogTag.IsDead() )
      99           0 :                 break;
     100           0 :             pWindow->GrabFocus();
     101           0 :             if( aDogTag.IsDead() )
     102           0 :                 break;
     103           0 :             pWindow->ImplGetFrameData()->mbInSysObjToTopHdl = false;
     104           0 :             break;
     105             :     }
     106             : 
     107           0 :     return nRet;
     108             : }
     109             : 
     110           0 : void SystemChildWindow::ImplInitSysChild( Window* pParent, WinBits nStyle, SystemWindowData *pData, bool bShow )
     111             : {
     112           0 :     mpWindowImpl->mpSysObj = ImplGetSVData()->mpDefInst->CreateObject( pParent->ImplGetFrame(), pData, bShow );
     113             : 
     114           0 :     Window::ImplInit( pParent, nStyle, NULL );
     115             : 
     116             :     // we do not paint if it is the right SysChild
     117           0 :     if ( GetSystemData() )
     118             :     {
     119           0 :         mpWindowImpl->mpSysObj->SetCallback( this, ImplSysChildProc );
     120           0 :         SetParentClipMode( PARENTCLIPMODE_CLIP );
     121           0 :         SetBackground();
     122             :     }
     123           0 : }
     124             : 
     125           0 : SystemChildWindow::SystemChildWindow( Window* pParent, WinBits nStyle ) :
     126           0 :     Window( WINDOW_SYSTEMCHILDWINDOW )
     127             : {
     128           0 :     ImplInitSysChild( pParent, nStyle, NULL );
     129           0 : }
     130             : 
     131           0 : SystemChildWindow::SystemChildWindow( Window* pParent, WinBits nStyle, SystemWindowData *pData, bool bShow ) :
     132           0 :     Window( WINDOW_SYSTEMCHILDWINDOW )
     133             : {
     134           0 :     ImplInitSysChild( pParent, nStyle, pData, bShow );
     135           0 : }
     136             : 
     137           0 : SystemChildWindow::~SystemChildWindow()
     138             : {
     139           0 :     Hide();
     140           0 :     if ( mpWindowImpl->mpSysObj )
     141             :     {
     142           0 :         ImplGetSVData()->mpDefInst->DestroyObject( mpWindowImpl->mpSysObj );
     143           0 :         mpWindowImpl->mpSysObj = NULL;
     144             :     }
     145           0 : }
     146             : 
     147           0 : const SystemEnvData* SystemChildWindow::GetSystemData() const
     148             : {
     149           0 :     if ( mpWindowImpl->mpSysObj )
     150           0 :         return mpWindowImpl->mpSysObj->GetSystemData();
     151             :     else
     152           0 :         return NULL;
     153             : }
     154             : 
     155           0 : void SystemChildWindow::EnableEraseBackground( bool bEnable )
     156             : {
     157           0 :     if ( mpWindowImpl->mpSysObj )
     158           0 :         mpWindowImpl->mpSysObj->EnableEraseBackground( bEnable );
     159           0 : }
     160             : 
     161           0 : void SystemChildWindow::ImplTestJavaException( void* pEnv )
     162             : {
     163             : #if HAVE_FEATURE_JAVA
     164           0 :     JNIEnv*     pJavaEnv = reinterpret_cast< JNIEnv* >( pEnv );
     165           0 :     jthrowable  jtThrowable = pJavaEnv->ExceptionOccurred();
     166             : 
     167           0 :     if( jtThrowable )
     168             :     { // is it a java exception ?
     169             : #if OSL_DEBUG_LEVEL > 1
     170             :         pJavaEnv->ExceptionDescribe();
     171             : #endif // OSL_DEBUG_LEVEL > 1
     172           0 :         pJavaEnv->ExceptionClear();
     173             : 
     174           0 :         jclass          jcThrowable = pJavaEnv->FindClass("java/lang/Throwable");
     175           0 :         jmethodID       jmThrowable_getMessage = pJavaEnv->GetMethodID(jcThrowable, "getMessage", "()Ljava/lang/String;");
     176           0 :         jstring         jsMessage = (jstring) pJavaEnv->CallObjectMethod(jtThrowable, jmThrowable_getMessage);
     177           0 :             OUString ouMessage;
     178             : 
     179           0 :             if(jsMessage)
     180             :             {
     181           0 :                 const jchar * jcMessage = pJavaEnv->GetStringChars(jsMessage, NULL);
     182           0 :                 ouMessage = OUString(jcMessage);
     183           0 :                 pJavaEnv->ReleaseStringChars(jsMessage, jcMessage);
     184             :             }
     185             : 
     186           0 :             throw uno::RuntimeException(ouMessage, uno::Reference<uno::XInterface>());
     187             :     }
     188             : #else
     189             :     (void)pEnv;
     190             : #endif // HAVE_FEATURE_JAVA
     191           0 : }
     192             : 
     193           0 : void SystemChildWindow::SetForwardKey( bool bEnable )
     194             : {
     195           0 :     if ( mpWindowImpl->mpSysObj )
     196           0 :         mpWindowImpl->mpSysObj->SetForwardKey( bEnable );
     197           0 : }
     198             : 
     199           0 : sal_IntPtr SystemChildWindow::GetParentWindowHandle( bool bUseJava )
     200             : {
     201           0 :     sal_IntPtr nRet = 0;
     202             : 
     203             :     (void)bUseJava;
     204             : #if defined WNT
     205             :     nRet = reinterpret_cast< sal_IntPtr >( GetSystemData()->hWnd );
     206             : #elif defined MACOSX
     207             :     // FIXME: this is wrong
     208             :     nRet = reinterpret_cast< sal_IntPtr >( GetSystemData()->mpNSView );
     209             : #elif defined ANDROID
     210             :     // Nothing
     211             : #elif defined IOS
     212             :     // Nothing
     213             : #elif defined UNX
     214           0 :     if( !bUseJava )
     215             :     {
     216           0 :         nRet = (sal_IntPtr) GetSystemData()->aWindow;
     217             :     }
     218             : #if HAVE_FEATURE_JAVA
     219             :     else
     220             :     {
     221           0 :         uno::Reference< uno::XComponentContext > xContext( comphelper::getProcessComponentContext() );
     222             : 
     223           0 :         if( GetSystemData()->aWindow > 0 )
     224             :         {
     225             :             try
     226             :             {
     227           0 :                     ::rtl::Reference< ::jvmaccess::VirtualMachine > xVM;
     228           0 :                     uno::Reference< java::XJavaVM >                 xJavaVM = java::JavaVirtualMachine::create(xContext);;
     229           0 :                     uno::Sequence< sal_Int8 >                       aProcessID( 17 );
     230             : 
     231           0 :                     rtl_getGlobalProcessId( (sal_uInt8*) aProcessID.getArray() );
     232           0 :                     aProcessID[ 16 ] = 0;
     233             :                     OSL_ENSURE(sizeof (sal_Int64) >= sizeof (jvmaccess::VirtualMachine *), "Pointer cannot be represented as sal_Int64");
     234           0 :                     sal_Int64 nPointer = reinterpret_cast< sal_Int64 >( static_cast< jvmaccess::VirtualMachine * >(0));
     235           0 :                     xJavaVM->getJavaVM(aProcessID) >>= nPointer;
     236           0 :                     xVM = reinterpret_cast< jvmaccess::VirtualMachine * >(nPointer);
     237             : 
     238           0 :                     if( xVM.is() )
     239             :                     {
     240             :                         try
     241             :                         {
     242           0 :                                 ::jvmaccess::VirtualMachine::AttachGuard    aVMAttachGuard( xVM );
     243           0 :                                 JNIEnv*                                     pEnv = aVMAttachGuard.getEnvironment();
     244             : 
     245           0 :                                 jclass jcToolkit = pEnv->FindClass("java/awt/Toolkit");
     246           0 :                                 ImplTestJavaException(pEnv);
     247             : 
     248           0 :                                 jmethodID jmToolkit_getDefaultToolkit = pEnv->GetStaticMethodID( jcToolkit, "getDefaultToolkit", "()Ljava/awt/Toolkit;" );
     249           0 :                                 ImplTestJavaException(pEnv);
     250             : 
     251           0 :                                 pEnv->CallStaticObjectMethod(jcToolkit, jmToolkit_getDefaultToolkit);
     252           0 :                                 ImplTestJavaException(pEnv);
     253             : 
     254           0 :                                 jclass jcMotifAppletViewer = pEnv->FindClass("sun/plugin/navig/motif/MotifAppletViewer");
     255           0 :                                 if( pEnv->ExceptionOccurred() )
     256             :                                 {
     257           0 :                                     pEnv->ExceptionClear();
     258             : 
     259           0 :                                     jcMotifAppletViewer = pEnv->FindClass( "sun/plugin/viewer/MNetscapePluginContext");
     260           0 :                                     ImplTestJavaException(pEnv);
     261             :                                 }
     262             : 
     263           0 :                                 jclass jcClassLoader = pEnv->FindClass("java/lang/ClassLoader");
     264           0 :                                 ImplTestJavaException(pEnv);
     265             : 
     266           0 :                                 jmethodID jmClassLoader_loadLibrary = pEnv->GetStaticMethodID( jcClassLoader, "loadLibrary", "(Ljava/lang/Class;Ljava/lang/String;Z)V");
     267           0 :                                 ImplTestJavaException(pEnv);
     268             : 
     269           0 :                                 jstring jsplugin = pEnv->NewStringUTF("javaplugin_jni");
     270           0 :                                 ImplTestJavaException(pEnv);
     271             : 
     272           0 :                                 pEnv->CallStaticVoidMethod(jcClassLoader, jmClassLoader_loadLibrary, jcMotifAppletViewer, jsplugin, JNI_FALSE);
     273           0 :                                 ImplTestJavaException(pEnv);
     274             : 
     275           0 :                                 jmethodID jmMotifAppletViewer_getWidget = pEnv->GetStaticMethodID( jcMotifAppletViewer, "getWidget", "(IIIII)I" );
     276           0 :                                 ImplTestJavaException(pEnv);
     277             : 
     278           0 :                                 const Size aSize( GetOutputSizePixel() );
     279             :                                 jint ji_widget = pEnv->CallStaticIntMethod( jcMotifAppletViewer, jmMotifAppletViewer_getWidget,
     280           0 :                                         GetSystemData()->aWindow, 0, 0, aSize.Width(), aSize.Height() );
     281           0 :                                 ImplTestJavaException(pEnv);
     282             : 
     283           0 :                                 nRet = static_cast< sal_IntPtr >( ji_widget );
     284             :                         }
     285           0 :                         catch( uno::RuntimeException& )
     286             :                         {
     287             :                         }
     288             : 
     289           0 :                         if( !nRet )
     290           0 :                             nRet = static_cast< sal_IntPtr >( GetSystemData()->aWindow );
     291           0 :                     }
     292             :             }
     293           0 :             catch( ... )
     294             :             {
     295             :             }
     296           0 :         }
     297             :     }
     298             : #endif // HAVE_FEATURE_JAVA
     299             : #endif
     300             : 
     301           0 :     return nRet;
     302             : }
     303             : 
     304             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10