LCOV - code coverage report
Current view: top level - vcl/source/window - syschild.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 25 136 18.4 %
Date: 2015-06-13 12:38:46 Functions: 6 12 50.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             : #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 = static_cast<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( ToTopFlags::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 ), NULL, true );
      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( ToTopFlags::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          17 : void SystemChildWindow::ImplInitSysChild( vcl::Window* pParent, WinBits nStyle, SystemWindowData *pData, bool bShow )
     108             : {
     109          17 :     mpWindowImpl->mpSysObj = ImplGetSVData()->mpDefInst->CreateObject( pParent->ImplGetFrame(), pData, bShow );
     110             : 
     111          17 :     Window::ImplInit( pParent, nStyle, NULL );
     112             : 
     113             :     // we do not paint if it is the right SysChild
     114          17 :     if ( GetSystemData() )
     115             :     {
     116          17 :         mpWindowImpl->mpSysObj->SetCallback( this, ImplSysChildProc );
     117          17 :         SetParentClipMode( ParentClipMode::Clip );
     118          17 :         SetBackground();
     119             :     }
     120          17 : }
     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          17 : SystemChildWindow::SystemChildWindow( vcl::Window* pParent, WinBits nStyle, SystemWindowData *pData, bool bShow ) :
     129          17 :     Window( WINDOW_SYSTEMCHILDWINDOW )
     130             : {
     131          17 :     ImplInitSysChild( pParent, nStyle, pData, bShow );
     132          17 : }
     133             : 
     134          51 : SystemChildWindow::~SystemChildWindow()
     135             : {
     136          17 :     disposeOnce();
     137          34 : }
     138             : 
     139          17 : void SystemChildWindow::dispose()
     140             : {
     141          17 :     Hide();
     142          17 :     if ( mpWindowImpl && mpWindowImpl->mpSysObj )
     143             :     {
     144          17 :         ImplGetSVData()->mpDefInst->DestroyObject( mpWindowImpl->mpSysObj );
     145          17 :         mpWindowImpl->mpSysObj = NULL;
     146             :     }
     147          17 :     Window::dispose();
     148          17 : }
     149             : 
     150          17 : const SystemEnvData* SystemChildWindow::GetSystemData() const
     151             : {
     152          17 :     if ( mpWindowImpl->mpSysObj )
     153          17 :         return mpWindowImpl->mpSysObj->GetSystemData();
     154             :     else
     155           0 :         return NULL;
     156             : }
     157             : 
     158           0 : void SystemChildWindow::EnableEraseBackground( bool bEnable )
     159             : {
     160           0 :     if ( mpWindowImpl->mpSysObj )
     161           0 :         mpWindowImpl->mpSysObj->EnableEraseBackground( bEnable );
     162           0 : }
     163             : 
     164           0 : void SystemChildWindow::ImplTestJavaException( void* pEnv )
     165             : {
     166             : #if HAVE_FEATURE_JAVA
     167           0 :     JNIEnv*     pJavaEnv = static_cast< JNIEnv* >( pEnv );
     168           0 :     jthrowable  jtThrowable = pJavaEnv->ExceptionOccurred();
     169             : 
     170           0 :     if( jtThrowable )
     171             :     { // is it a java exception ?
     172             : #if OSL_DEBUG_LEVEL > 1
     173             :         pJavaEnv->ExceptionDescribe();
     174             : #endif // OSL_DEBUG_LEVEL > 1
     175           0 :         pJavaEnv->ExceptionClear();
     176             : 
     177           0 :         jclass          jcThrowable = pJavaEnv->FindClass("java/lang/Throwable");
     178           0 :         jmethodID       jmThrowable_getMessage = pJavaEnv->GetMethodID(jcThrowable, "getMessage", "()Ljava/lang/String;");
     179           0 :         jstring         jsMessage = static_cast<jstring>( pJavaEnv->CallObjectMethod(jtThrowable, jmThrowable_getMessage) );
     180           0 :         OUString        ouMessage;
     181             : 
     182           0 :         if(jsMessage)
     183             :         {
     184           0 :             const jchar * jcMessage = pJavaEnv->GetStringChars(jsMessage, NULL);
     185           0 :             ouMessage = OUString(jcMessage);
     186           0 :             pJavaEnv->ReleaseStringChars(jsMessage, jcMessage);
     187             :         }
     188             : 
     189           0 :         throw uno::RuntimeException(ouMessage);
     190             :     }
     191             : #else
     192             :     (void)pEnv;
     193             : #endif // HAVE_FEATURE_JAVA
     194           0 : }
     195             : 
     196           0 : void SystemChildWindow::SetForwardKey( bool bEnable )
     197             : {
     198           0 :     if ( mpWindowImpl->mpSysObj )
     199           0 :         mpWindowImpl->mpSysObj->SetForwardKey( bEnable );
     200           0 : }
     201             : 
     202           0 : sal_IntPtr SystemChildWindow::GetParentWindowHandle( bool bUseJava )
     203             : {
     204           0 :     sal_IntPtr nRet = 0;
     205             : 
     206             :     (void)bUseJava;
     207             : #if defined WNT
     208             :     nRet = reinterpret_cast< sal_IntPtr >( GetSystemData()->hWnd );
     209             : #elif defined MACOSX
     210             :     // FIXME: this is wrong
     211             :     nRet = reinterpret_cast< sal_IntPtr >( GetSystemData()->mpNSView );
     212             : #elif defined ANDROID
     213             :     // Nothing
     214             : #elif defined IOS
     215             :     // Nothing
     216             : #elif defined UNX
     217           0 :     if( !bUseJava )
     218             :     {
     219           0 :         nRet = (sal_IntPtr) GetSystemData()->aWindow;
     220             :     }
     221             : #if HAVE_FEATURE_JAVA
     222             :     else
     223             :     {
     224           0 :         uno::Reference< uno::XComponentContext > xContext( comphelper::getProcessComponentContext() );
     225             : 
     226           0 :         if( GetSystemData()->aWindow > 0 )
     227             :         {
     228             :             try
     229             :             {
     230           0 :                     ::rtl::Reference< ::jvmaccess::VirtualMachine > xVM;
     231           0 :                     uno::Reference< java::XJavaVM >                 xJavaVM = java::JavaVirtualMachine::create(xContext);;
     232           0 :                     uno::Sequence< sal_Int8 >                       aProcessID( 17 );
     233             : 
     234           0 :                     rtl_getGlobalProcessId( reinterpret_cast<sal_uInt8*>(aProcessID.getArray()) );
     235           0 :                     aProcessID[ 16 ] = 0;
     236             :                     OSL_ENSURE(sizeof (sal_Int64) >= sizeof (jvmaccess::VirtualMachine *), "Pointer cannot be represented as sal_Int64");
     237           0 :                     sal_Int64 nPointer = reinterpret_cast< sal_Int64 >( static_cast< jvmaccess::VirtualMachine * >(0));
     238           0 :                     xJavaVM->getJavaVM(aProcessID) >>= nPointer;
     239           0 :                     xVM = reinterpret_cast< jvmaccess::VirtualMachine * >(nPointer);
     240             : 
     241           0 :                     if( xVM.is() )
     242             :                     {
     243             :                         try
     244             :                         {
     245           0 :                                 ::jvmaccess::VirtualMachine::AttachGuard    aVMAttachGuard( xVM );
     246           0 :                                 JNIEnv*                                     pEnv = aVMAttachGuard.getEnvironment();
     247             : 
     248           0 :                                 jclass jcToolkit = pEnv->FindClass("java/awt/Toolkit");
     249           0 :                                 ImplTestJavaException(pEnv);
     250             : 
     251           0 :                                 jmethodID jmToolkit_getDefaultToolkit = pEnv->GetStaticMethodID( jcToolkit, "getDefaultToolkit", "()Ljava/awt/Toolkit;" );
     252           0 :                                 ImplTestJavaException(pEnv);
     253             : 
     254           0 :                                 pEnv->CallStaticObjectMethod(jcToolkit, jmToolkit_getDefaultToolkit);
     255           0 :                                 ImplTestJavaException(pEnv);
     256             : 
     257           0 :                                 jclass jcMotifAppletViewer = pEnv->FindClass("sun/plugin/navig/motif/MotifAppletViewer");
     258           0 :                                 if( pEnv->ExceptionOccurred() )
     259             :                                 {
     260           0 :                                     pEnv->ExceptionClear();
     261             : 
     262           0 :                                     jcMotifAppletViewer = pEnv->FindClass( "sun/plugin/viewer/MNetscapePluginContext");
     263           0 :                                     ImplTestJavaException(pEnv);
     264             :                                 }
     265             : 
     266           0 :                                 jclass jcClassLoader = pEnv->FindClass("java/lang/ClassLoader");
     267           0 :                                 ImplTestJavaException(pEnv);
     268             : 
     269           0 :                                 jmethodID jmClassLoader_loadLibrary = pEnv->GetStaticMethodID( jcClassLoader, "loadLibrary", "(Ljava/lang/Class;Ljava/lang/String;Z)V");
     270           0 :                                 ImplTestJavaException(pEnv);
     271             : 
     272           0 :                                 jstring jsplugin = pEnv->NewStringUTF("javaplugin_jni");
     273           0 :                                 ImplTestJavaException(pEnv);
     274             : 
     275           0 :                                 pEnv->CallStaticVoidMethod(jcClassLoader, jmClassLoader_loadLibrary, jcMotifAppletViewer, jsplugin, JNI_FALSE);
     276           0 :                                 ImplTestJavaException(pEnv);
     277             : 
     278           0 :                                 jmethodID jmMotifAppletViewer_getWidget = pEnv->GetStaticMethodID( jcMotifAppletViewer, "getWidget", "(IIIII)I" );
     279           0 :                                 ImplTestJavaException(pEnv);
     280             : 
     281           0 :                                 const Size aSize( GetOutputSizePixel() );
     282             :                                 jint ji_widget = pEnv->CallStaticIntMethod( jcMotifAppletViewer, jmMotifAppletViewer_getWidget,
     283           0 :                                         GetSystemData()->aWindow, 0, 0, aSize.Width(), aSize.Height() );
     284           0 :                                 ImplTestJavaException(pEnv);
     285             : 
     286           0 :                                 nRet = static_cast< sal_IntPtr >( ji_widget );
     287             :                         }
     288           0 :                         catch( uno::RuntimeException& )
     289             :                         {
     290             :                         }
     291             : 
     292           0 :                         if( !nRet )
     293           0 :                             nRet = static_cast< sal_IntPtr >( GetSystemData()->aWindow );
     294           0 :                     }
     295             :             }
     296           0 :             catch( ... )
     297             :             {
     298             :             }
     299           0 :         }
     300             :     }
     301             : #endif // HAVE_FEATURE_JAVA
     302             : #endif
     303             : 
     304           0 :     return nRet;
     305             : }
     306             : 
     307             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11