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

Print this page




  65 }
  66 
  67 // Events
  68 - (void)handleAction:(NSMenuItem *)sender {
  69 AWT_ASSERT_APPKIT_THREAD;
  70     JNIEnv *env = [ThreadUtilities getJNIEnv];
  71 JNF_COCOA_ENTER(env);
  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 charactersIgnoringModifiers];
  80 
  81         // Apple uses characters from private Unicode range for some of the
  82         // keys, so we need to do the same translation here that we do
  83         // for the regular key down events
  84         if ([eventKey length] == 1) {
  85             unichar ch =  NsCharToJavaChar([eventKey characterAtIndex:0], 0);
  86             eventKey = [NSString stringWithCharacters: &ch length: 1];





  87         }
  88 
  89         if ([menuKey isEqualToString:eventKey]) {
  90             return;
  91         }
  92     }
  93 
  94     if (fIsCheckbox) {
  95         static JNF_CLASS_CACHE(jc_CCheckboxMenuItem, "sun/lwawt/macosx/CCheckboxMenuItem");
  96         static JNF_MEMBER_CACHE(jm_ckHandleAction, jc_CCheckboxMenuItem, "handleAction", "(Z)V");
  97 
  98         // Send the opposite of what's currently checked -- the action
  99         // indicates what state we're going to.
 100         NSInteger state = [sender state];
 101         jboolean newState = (state == NSOnState ? JNI_FALSE : JNI_TRUE);
 102         JNFCallVoidMethod(env, fPeer, jm_ckHandleAction, newState);
 103     } else {
 104         static JNF_CLASS_CACHE(jc_CMenuItem, "sun/lwawt/macosx/CMenuItem");
 105         static JNF_MEMBER_CACHE(jm_handleAction, jc_CMenuItem, "handleAction", "(JI)V"); // AWT_THREADING Safe (event)
 106 




  65 }
  66 
  67 // Events
  68 - (void)handleAction:(NSMenuItem *)sender {
  69 AWT_ASSERT_APPKIT_THREAD;
  70     JNIEnv *env = [ThreadUtilities getJNIEnv];
  71 JNF_COCOA_ENTER(env);
  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 charactersIgnoringModifiers];
  80 
  81         // Apple uses characters from private Unicode range for some of the
  82         // keys, so we need to do the same translation here that we do
  83         // for the regular key down events
  84         if ([eventKey length] == 1) {
  85             unichar origChar = [eventKey characterAtIndex:0];
  86             unichar newChar =  NsCharToJavaChar(origChar, 0);
  87             if (newChar == java_awt_event_KeyEvent_CHAR_UNDEFINED) {
  88                 newChar = origChar;
  89             }
  90 
  91             eventKey = [NSString stringWithCharacters: &newChar length: 1];
  92         }
  93 
  94         if ([menuKey isEqualToString:eventKey]) {
  95             return;
  96         }
  97     }
  98 
  99     if (fIsCheckbox) {
 100         static JNF_CLASS_CACHE(jc_CCheckboxMenuItem, "sun/lwawt/macosx/CCheckboxMenuItem");
 101         static JNF_MEMBER_CACHE(jm_ckHandleAction, jc_CCheckboxMenuItem, "handleAction", "(Z)V");
 102 
 103         // Send the opposite of what's currently checked -- the action
 104         // indicates what state we're going to.
 105         NSInteger state = [sender state];
 106         jboolean newState = (state == NSOnState ? JNI_FALSE : JNI_TRUE);
 107         JNFCallVoidMethod(env, fPeer, jm_ckHandleAction, newState);
 108     } else {
 109         static JNF_CLASS_CACHE(jc_CMenuItem, "sun/lwawt/macosx/CMenuItem");
 110         static JNF_MEMBER_CACHE(jm_handleAction, jc_CMenuItem, "handleAction", "(JI)V"); // AWT_THREADING Safe (event)
 111