LCOV - code coverage report
Current view: top level - vcl/source/window - syschild.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 132 0.0 %
Date: 2012-08-25 Functions: 0 11 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 210 0.0 %

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

Generated by: LCOV version 1.10