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