src/macosx/native/sun/awt/AWTEvent.m

Print this page




 291         54,
 292         java_awt_event_InputEvent_META_DOWN_MASK,
 293         java_awt_event_KeyEvent_VK_META
 294     },
 295     // NSNumericPadKeyMask
 296     {
 297         NSHelpKeyMask,
 298         0,
 299         0,
 300         0, // no Java equivalent
 301         java_awt_event_KeyEvent_VK_HELP
 302     },
 303     // NSFunctionKeyMask
 304     {0, 0, 0, 0, 0}
 305 };
 306 
 307 /*
 308  * Almost all unicode characters just go from NS to Java with no translation.
 309  *  For the few exceptions, we handle it here with this small table.
 310  */



 311 static struct _char {
 312     NSUInteger modifier;
 313     unichar nsChar;
 314     unichar javaChar;
 315 }
 316 const charTable[] = {
 317     // map enter on keypad to same as return key
 318     {0,              NSEnterCharacter,          NSNewlineCharacter},
 319 
 320     // [3134616] return newline instead of carriage return
 321     {0,              NSCarriageReturnCharacter, NSNewlineCharacter},
 322 
 323     // "delete" means backspace in Java
 324     {0,              NSDeleteCharacter,         NSBackspaceCharacter},
 325     {0,              NSDeleteFunctionKey,     NSDeleteCharacter},
 326 
 327     // back-tab is only differentiated from tab by Shift flag
 328     {NSShiftKeyMask, NSBackTabCharacter,     NSTabCharacter},
 329 
 330     {0, 0, 0}
 331 };
 332 
 333 static unichar
 334 NsCharToJavaChar(unichar nsChar, NSUInteger modifiers)
 335 {
 336     const struct _char *cur;
 337     NSUInteger keyModifierFlags =
 338         NSShiftKeyMask | NSControlKeyMask |
 339         NSAlternateKeyMask | NSCommandKeyMask;
 340 
 341     // Mask off just the keyboard modifiers from the event modifier mask.
 342     NSUInteger testableFlags = (modifiers & keyModifierFlags);
 343 
 344     // walk through table & find the match
 345     for (cur = charTable; cur->nsChar != 0 ; cur++) {
 346         // <rdar://Problem/3476426> Need to determine if we are looking at
 347         // a plain keypress or a modified keypress.  Don't adjust the
 348         // character of a keypress with a modifier.
 349         if (cur->nsChar == nsChar) {
 350             if (cur->modifier == 0 && testableFlags == 0) {
 351                 // If the modifier field is 0, that means to transform
 352                 // this character if no additional keyboard modifiers are set.
 353                 // This lets ctrl-C be reported as ctrl-C and not transformed
 354                 // into Newline.
 355                 return cur->javaChar;
 356             } else if (cur->modifier != 0 &&
 357                        (testableFlags & cur->modifier) == testableFlags)
 358             {
 359                 // Likewise, if the modifier field is nonzero, that means
 360                 // transform this character if only these modifiers are
 361                 // set in the testable flags.
 362                 return cur->javaChar;


1052 
1053     jint jkeyCode = java_awt_event_KeyEvent_VK_UNDEFINED;
1054     jint jkeyLocation = java_awt_event_KeyEvent_KEY_LOCATION_UNKNOWN;
1055     jint jkeyType = java_awt_event_KeyEvent_KEY_PRESSED;
1056 
1057     NsKeyModifiersToJavaKeyInfo(modifierFlags,
1058                                 keyCode,
1059                                 &jkeyCode,
1060                                 &jkeyLocation,
1061                                 &jkeyType);
1062 
1063     // out = [jkeyCode, jkeyLocation, jkeyType];
1064     (*env)->SetIntArrayRegion(env, outData, 0, 1, &jkeyCode);
1065     (*env)->SetIntArrayRegion(env, outData, 1, 1, &jkeyLocation);
1066     (*env)->SetIntArrayRegion(env, outData, 2, 1, &jkeyType);
1067 
1068     (*env)->ReleaseIntArrayElements(env, inData, data, 0);
1069 
1070 JNF_COCOA_EXIT(env);
1071 }






















 291         54,
 292         java_awt_event_InputEvent_META_DOWN_MASK,
 293         java_awt_event_KeyEvent_VK_META
 294     },
 295     // NSNumericPadKeyMask
 296     {
 297         NSHelpKeyMask,
 298         0,
 299         0,
 300         0, // no Java equivalent
 301         java_awt_event_KeyEvent_VK_HELP
 302     },
 303     // NSFunctionKeyMask
 304     {0, 0, 0, 0, 0}
 305 };
 306 
 307 /*
 308  * Almost all unicode characters just go from NS to Java with no translation.
 309  *  For the few exceptions, we handle it here with this small table.
 310  */
 311 #define ALL_NS_KEY_MODIFIERS_MASK \
 312     (NSShiftKeyMask | NSControlKeyMask | NSAlternateKeyMask | NSCommandKeyMask)
 313 
 314 static struct _char {
 315     NSUInteger modifier;
 316     unichar nsChar;
 317     unichar javaChar;
 318 }
 319 const charTable[] = {
 320     // map enter on keypad to same as return key
 321     {0,                         NSEnterCharacter,          NSNewlineCharacter},
 322 
 323     // [3134616] return newline instead of carriage return
 324     {0,                         NSCarriageReturnCharacter, NSNewlineCharacter},
 325 
 326     // "delete" means backspace in Java
 327     {ALL_NS_KEY_MODIFIERS_MASK, NSDeleteCharacter,         NSBackspaceCharacter},
 328     {ALL_NS_KEY_MODIFIERS_MASK, NSDeleteFunctionKey,       NSDeleteCharacter},
 329 
 330     // back-tab is only differentiated from tab by Shift flag
 331     {NSShiftKeyMask,            NSBackTabCharacter,        NSTabCharacter},
 332 
 333     {0, 0, 0}
 334 };
 335 
 336 static unichar
 337 NsCharToJavaChar(unichar nsChar, NSUInteger modifiers)
 338 {
 339     const struct _char *cur;




 340     // Mask off just the keyboard modifiers from the event modifier mask.
 341     NSUInteger testableFlags = (modifiers & ALL_NS_KEY_MODIFIERS_MASK);
 342 
 343     // walk through table & find the match
 344     for (cur = charTable; cur->nsChar != 0 ; cur++) {
 345         // <rdar://Problem/3476426> Need to determine if we are looking at
 346         // a plain keypress or a modified keypress.  Don't adjust the
 347         // character of a keypress with a modifier.
 348         if (cur->nsChar == nsChar) {
 349             if (cur->modifier == 0 && testableFlags == 0) {
 350                 // If the modifier field is 0, that means to transform
 351                 // this character if no additional keyboard modifiers are set.
 352                 // This lets ctrl-C be reported as ctrl-C and not transformed
 353                 // into Newline.
 354                 return cur->javaChar;
 355             } else if (cur->modifier != 0 &&
 356                        (testableFlags & cur->modifier) == testableFlags)
 357             {
 358                 // Likewise, if the modifier field is nonzero, that means
 359                 // transform this character if only these modifiers are
 360                 // set in the testable flags.
 361                 return cur->javaChar;


1051 
1052     jint jkeyCode = java_awt_event_KeyEvent_VK_UNDEFINED;
1053     jint jkeyLocation = java_awt_event_KeyEvent_KEY_LOCATION_UNKNOWN;
1054     jint jkeyType = java_awt_event_KeyEvent_KEY_PRESSED;
1055 
1056     NsKeyModifiersToJavaKeyInfo(modifierFlags,
1057                                 keyCode,
1058                                 &jkeyCode,
1059                                 &jkeyLocation,
1060                                 &jkeyType);
1061 
1062     // out = [jkeyCode, jkeyLocation, jkeyType];
1063     (*env)->SetIntArrayRegion(env, outData, 0, 1, &jkeyCode);
1064     (*env)->SetIntArrayRegion(env, outData, 1, 1, &jkeyLocation);
1065     (*env)->SetIntArrayRegion(env, outData, 2, 1, &jkeyType);
1066 
1067     (*env)->ReleaseIntArrayElements(env, inData, data, 0);
1068 
1069 JNF_COCOA_EXIT(env);
1070 }
1071 
1072 /*
1073  * Class:     sun_lwawt_macosx_event_NSEvent
1074  * Method:    nsToJavaChar
1075  * Signature: (CI)C
1076  */
1077 JNIEXPORT jint JNICALL
1078 Java_sun_lwawt_macosx_event_NSEvent_nsToJavaChar
1079 (JNIEnv *env, jclass cls, char nsChar, jint modifierFlags)
1080 {
1081     jchar javaChar = 0;
1082     
1083 JNF_COCOA_ENTER(env);
1084     
1085     javaChar = NsCharToJavaChar(nsChar, modifierFlags);
1086 
1087 JNF_COCOA_EXIT(env);
1088     
1089     return javaChar;
1090 }