javauis/eswt_qt/s60utils/native/s60utils.cpp
changeset 35 85266cc22c7f
parent 26 dc7c549001d5
child 40 c6043ea9b06a
child 44 0105bdca6f9c
child 47 f40128debb5d
child 49 35baca0e7a2e
equal deleted inserted replaced
26:dc7c549001d5 35:85266cc22c7f
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 #include <e32debug.h>
       
    18 #include <e32base.h>
       
    19 #include <e32event.h>
       
    20 #include <eikenv.h>
       
    21 #include <coemain.h>
       
    22 #include <e32property.h>
       
    23 #include <screensaverinternalpskeys.h>
       
    24 #include <e32keys.h>
       
    25 
       
    26 //#include <QApplication>
       
    27 
       
    28 #include "s60utils.h"
       
    29 // Note following modifilers are from X11 instead of Symbian
       
    30 static const TInt Shift                           = (1<<0);
       
    31 static const TInt CapsLock                        = (1<<1);
       
    32 static const TInt Control                         = (1<<2);
       
    33 static const TInt Alt                             = (1<<3);
       
    34 static const TInt NumLock                         = (1<<4);
       
    35 static const TInt ScrllLock                       = (1<<4);
       
    36 static const TInt AltGr                           = (1<<7);
       
    37 
       
    38 
       
    39 static TInt symbianKeyCode(TInt aX11Modifier)
       
    40     {
       
    41     TInt keyCode(0);
       
    42     if( (aX11Modifier & Shift) > 0 )
       
    43         {
       
    44         keyCode = EStdKeyLeftShift;
       
    45         }
       
    46     else if( (aX11Modifier & CapsLock) > 0 )
       
    47         {
       
    48         keyCode = EStdKeyCapsLock;
       
    49         }
       
    50     else if( (aX11Modifier & Control) > 0 )
       
    51         {
       
    52         keyCode = EStdKeyLeftCtrl;
       
    53         }
       
    54     else if( (aX11Modifier & Alt) > 0 )
       
    55         {
       
    56         keyCode = EStdKeyLeftAlt;
       
    57         }
       
    58     else if( (aX11Modifier & NumLock) > 0 )
       
    59         {
       
    60         keyCode = EStdKeyNumLock;
       
    61         }
       
    62     else if( (aX11Modifier & ScrllLock) > 0 )
       
    63         {
       
    64         keyCode = EStdKeyScrollLock;
       
    65         }
       
    66     else if( (aX11Modifier & AltGr) > 0 )
       
    67         {
       
    68         keyCode = EStdKeyRightAlt;
       
    69         }
       
    70     return keyCode;
       
    71     }
       
    72 
       
    73 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_uitestutils_S60Utils_S60SendKeyToFocusWindow
       
    74   (JNIEnv *, jclass, jint aKeyCode, jint aModifier, jint aPressOrRelease)
       
    75     {
       
    76     RDebug::Print(_L("S60UITestUtils : S60SendKeyToFocusWindow, keycode=%d"), aKeyCode);
       
    77     
       
    78     User::ResetInactivityTime();// Reset user inactivity timers
       
    79 
       
    80     if(aModifier > 0 && aPressOrRelease == com_nokia_mj_impl_uitestutils_S60Utils_PRESS)
       
    81         {
       
    82         TRawEvent mevent;
       
    83         TInt keyCode = symbianKeyCode( aModifier);
       
    84         mevent.Set(TRawEvent::EKeyDown, keyCode);
       
    85         UserSvr::AddEvent(mevent);
       
    86         User::After(100000);
       
    87         }
       
    88     
       
    89 	TRawEvent event;
       
    90 	
       
    91 	if (aPressOrRelease == com_nokia_mj_impl_uitestutils_S60Utils_PRESS)
       
    92 	    {
       
    93 	    event.Set(TRawEvent::EKeyDown, aKeyCode);
       
    94 	    }
       
    95 	else
       
    96 	    {
       
    97 	    event.Set(TRawEvent::EKeyUp, aKeyCode);
       
    98 	    }
       
    99 	
       
   100 	UserSvr::AddEvent(event);
       
   101     User::After(100000);
       
   102     if(aModifier > 0 && aPressOrRelease == com_nokia_mj_impl_uitestutils_S60Utils_RELEASE)
       
   103         {
       
   104         TRawEvent mevent;
       
   105         TInt keyCode = symbianKeyCode(aModifier);
       
   106         mevent.Set(TRawEvent::EKeyUp, keyCode);
       
   107         UserSvr::AddEvent(mevent);
       
   108         User::After(100000);
       
   109         }
       
   110 
       
   111 	return 0;
       
   112     }
       
   113 
       
   114 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_uitestutils_S60Utils_S60KeysymToKeycode
       
   115   (JNIEnv *, jclass, jint)
       
   116     {
       
   117     return 0;
       
   118     }
       
   119 
       
   120 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_uitestutils_S60Utils_S60SendPointerEvent
       
   121   (JNIEnv *, jclass, jint aX, jint aY, jint /*aButton*/, jint aPressOrRelease)
       
   122     {
       
   123     User::ResetInactivityTime();// Reset user inactivity timers
       
   124 	
       
   125 	TRawEvent event;
       
   126 	
       
   127 	if (aPressOrRelease == com_nokia_mj_impl_uitestutils_S60Utils_PRESS) {
       
   128 	    event.Set(TRawEvent::EButton1Down, aX, aY);
       
   129 	} else {
       
   130 	    event.Set(TRawEvent::EButton1Up, aX, aY);
       
   131     }   
       
   132 	UserSvr::AddEvent(event);
       
   133 	return 0;
       
   134     }
       
   135 
       
   136 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_uitestutils_S60Utils_S60SendPointerMoveEvent
       
   137   (JNIEnv *, jclass, jint aX, jint aY, jint)
       
   138     {
       
   139     User::ResetInactivityTime();// Reset user inactivity timers
       
   140 	TRawEvent event;
       
   141 	event.Set(TRawEvent::EPointerMove, aX, aY);
       
   142 	UserSvr::AddEvent(event);
       
   143     return 0;
       
   144     }
       
   145 
       
   146 JNIEXPORT void JNICALL Java_com_nokia_mj_impl_uitestutils_S60Utils_S60DisableScreensaver
       
   147   (JNIEnv *, jclass)
       
   148     {
       
   149     RProperty::Set( KPSUidScreenSaver, KScreenSaverAllowScreenSaver, 1 );
       
   150     }
       
   151     
       
   152 JNIEXPORT void JNICALL Java_com_nokia_mj_impl_uitestutils_S60Utils_S60SetDoubleclickInterval
       
   153   (JNIEnv *, jclass, jint aInterval)
       
   154     {
       
   155     // Commented out for now. This can be taken into use once Qt doesn't need WSD to be allowed
       
   156     /*QApplication* app = static_cast<QApplication*>(QCoreApplication::instance());
       
   157     if ( app )
       
   158         {
       
   159         app->setDoubleClickInterval( aInterval );
       
   160         }*/
       
   161     }
       
   162