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

Generated by: LCOV version 1.10