jdk/src/macosx/native/sun/awt/CMenuItem.m
changeset 13781 bf3d53b1fba7
parent 12283 253d9a09f674
child 14312 310bfcd9c932
equal deleted inserted replaced
13780:ae50a0e73148 13781:bf3d53b1fba7
    68 - (void)handleAction:(NSMenuItem *)sender {
    68 - (void)handleAction:(NSMenuItem *)sender {
    69 AWT_ASSERT_APPKIT_THREAD;
    69 AWT_ASSERT_APPKIT_THREAD;
    70     JNIEnv *env = [ThreadUtilities getJNIEnv];
    70     JNIEnv *env = [ThreadUtilities getJNIEnv];
    71 JNF_COCOA_ENTER(env);
    71 JNF_COCOA_ENTER(env);
    72 
    72 
       
    73     // If we are called as a result of user pressing a shorcut, do nothing,
       
    74     // because AVTView has already sent corresponding key event to the Java 
       
    75     // layer from performKeyEquivalent
       
    76     NSEvent *currEvent = [[NSApplication sharedApplication] currentEvent];
       
    77     if ([currEvent type] == NSKeyDown) {
       
    78         NSString *menuKey = [sender keyEquivalent];
       
    79         NSString *eventKey = [currEvent characters];
       
    80         if ([menuKey isEqualToString:eventKey]) {
       
    81             return;
       
    82         }
       
    83     }
       
    84 
    73     if (fIsCheckbox) {
    85     if (fIsCheckbox) {
    74         static JNF_CLASS_CACHE(jc_CCheckboxMenuItem, "sun/lwawt/macosx/CCheckboxMenuItem");
    86         static JNF_CLASS_CACHE(jc_CCheckboxMenuItem, "sun/lwawt/macosx/CCheckboxMenuItem");
    75         static JNF_MEMBER_CACHE(jm_ckHandleAction, jc_CCheckboxMenuItem, "handleAction", "(Z)V");
    87         static JNF_MEMBER_CACHE(jm_ckHandleAction, jc_CCheckboxMenuItem, "handleAction", "(Z)V");
    76 
    88 
    77         // Send the opposite of what's currently checked -- the action
    89         // Send the opposite of what's currently checked -- the action
    81         JNFCallVoidMethod(env, fPeer, jm_ckHandleAction, newState);
    93         JNFCallVoidMethod(env, fPeer, jm_ckHandleAction, newState);
    82     } else {
    94     } else {
    83         static JNF_CLASS_CACHE(jc_CMenuItem, "sun/lwawt/macosx/CMenuItem");
    95         static JNF_CLASS_CACHE(jc_CMenuItem, "sun/lwawt/macosx/CMenuItem");
    84         static JNF_MEMBER_CACHE(jm_handleAction, jc_CMenuItem, "handleAction", "(JI)V"); // AWT_THREADING Safe (event)
    96         static JNF_MEMBER_CACHE(jm_handleAction, jc_CMenuItem, "handleAction", "(JI)V"); // AWT_THREADING Safe (event)
    85 
    97 
    86         NSEvent *currEvent = [[NSApplication sharedApplication] currentEvent];
       
    87         NSUInteger modifiers = [currEvent modifierFlags];
    98         NSUInteger modifiers = [currEvent modifierFlags];
    88         jint javaModifiers = 0;
    99         jint javaModifiers = NsKeyModifiersToJavaModifiers(modifiers, NO);
    89 
       
    90         if ((modifiers & NSCommandKeyMask) != 0)   javaModifiers |= java_awt_Event_META_MASK;
       
    91         if ((modifiers & NSShiftKeyMask) != 0)     javaModifiers |= java_awt_Event_SHIFT_MASK;
       
    92         if ((modifiers & NSControlKeyMask) != 0)   javaModifiers |= java_awt_Event_CTRL_MASK;
       
    93         if ((modifiers & NSAlternateKeyMask) != 0) javaModifiers |= java_awt_Event_ALT_MASK;
       
    94 
   100 
    95         JNFCallVoidMethod(env, fPeer, jm_handleAction, UTC(currEvent), javaModifiers); // AWT_THREADING Safe (event)
   101         JNFCallVoidMethod(env, fPeer, jm_handleAction, UTC(currEvent), javaModifiers); // AWT_THREADING Safe (event)
    96     }
   102     }
    97 JNF_COCOA_EXIT(env);
   103 JNF_COCOA_EXIT(env);
    98 }
   104 }
   115         {
   121         {
   116             theKeyEquivalent = @"?";
   122             theKeyEquivalent = @"?";
   117             modifiers &= ~java_awt_event_KeyEvent_SHIFT_MASK;
   123             modifiers &= ~java_awt_event_KeyEvent_SHIFT_MASK;
   118         }
   124         }
   119 
   125 
   120         if ((modifiers & java_awt_event_KeyEvent_SHIFT_MASK) != 0) modifierMask |= NSShiftKeyMask;
   126         modifierMask = JavaModifiersToNsKeyModifiers(modifiers, NO);
   121         if ((modifiers & java_awt_event_KeyEvent_CTRL_MASK) != 0)  modifierMask |= NSControlKeyMask;
       
   122         if ((modifiers & java_awt_event_KeyEvent_ALT_MASK) != 0)   modifierMask |= NSAlternateKeyMask;
       
   123         if ((modifiers & java_awt_event_KeyEvent_META_MASK) != 0)  modifierMask |= NSCommandKeyMask;
       
   124     }
   127     }
   125 
   128 
   126     [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
   129     [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
   127         AWT_ASSERT_APPKIT_THREAD;
   130         AWT_ASSERT_APPKIT_THREAD;
   128         [fMenuItem setKeyEquivalent:theKeyEquivalent];
   131         [fMenuItem setKeyEquivalent:theKeyEquivalent];