< prev index next >

src/java.desktop/macosx/native/libawt_lwawt/awt/CMenuItem.m

Print this page


   1 /*
   2  * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #import <JavaNativeFoundation/JavaNativeFoundation.h>
  27 #include <Carbon/Carbon.h>
  28 #import "CMenuItem.h"
  29 #import "CMenu.h"
  30 #import "AWTEvent.h"

  31 #import "ThreadUtilities.h"
  32 
  33 #import "java_awt_Event.h"
  34 #import "java_awt_event_KeyEvent.h"
  35 #import "sun_lwawt_macosx_CMenuItem.h"
  36 
  37 #define NOT_A_CHECKBOXMENU -2
  38 
  39 
  40 @implementation CMenuItem
  41 
  42 - (id) initWithPeer:(jobject)peer asSeparator: (BOOL) asSeparator{
  43     AWT_ASSERT_APPKIT_THREAD;
  44     self = [super initWithPeer:peer];
  45     if (self) {
  46         if (asSeparator) {
  47             fMenuItem = (NSMenuItem*)[NSMenuItem separatorItem];
  48             [fMenuItem retain];
  49         } else {
  50             fMenuItem = [[NSMenuItem alloc] init];


  94         if ([currEvent type] == NSKeyDown) {
  95             // Event available through sender variable hence NSApplication
  96             // not needed for checking the keyboard input sans the modifier keys
  97             // Also, the method used to fetch eventKey earlier would be locale dependent
  98             // With earlier implementation, if MenuKey: e EventKey: ा ; if input method
  99             // is not U.S. (Devanagari in this case)
 100             // With current implementation, EventKey = MenuKey = e irrespective of
 101             // input method
 102             NSString *eventKey = [sender keyEquivalent];
 103             // Apple uses characters from private Unicode range for some of the
 104             // keys, so we need to do the same translation here that we do
 105             // for the regular key down events
 106             if ([eventKey length] == 1) {
 107                 unichar origChar = [eventKey characterAtIndex:0];
 108                 unichar newChar =  NsCharToJavaChar(origChar, 0);
 109                 if (newChar == java_awt_event_KeyEvent_CHAR_UNDEFINED) {
 110                     newChar = origChar;
 111                 }
 112                 eventKey = [NSString stringWithCharacters: &newChar length: 1];
 113             }


 114             NSWindow *keyWindow = [NSApp keyWindow];
 115             if (keyWindow != nil) {
 116                 return;
 117             }
 118                 }
 119                 
 120         static JNF_CLASS_CACHE(jc_CMenuItem, "sun/lwawt/macosx/CMenuItem");
 121         static JNF_MEMBER_CACHE(jm_handleAction, jc_CMenuItem, "handleAction", "(JI)V"); // AWT_THREADING Safe (event)
 122 
 123         NSUInteger modifiers = [currEvent modifierFlags];
 124         jint javaModifiers = NsKeyModifiersToJavaModifiers(modifiers, NO);
 125 
 126         JNFCallVoidMethod(env, fPeer, jm_handleAction, UTC(currEvent), javaModifiers); // AWT_THREADING Safe (event)
 127     }
 128     JNF_COCOA_EXIT(env);
 129         
 130 }
 131 
 132 - (void) setJavaLabel:(NSString *)theLabel shortcut:(NSString *)theKeyEquivalent modifierMask:(jint)modifiers {
 133     
 134     NSUInteger modifierMask = 0;
 135     


   1 /*
   2  * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #import <JavaNativeFoundation/JavaNativeFoundation.h>
  27 #include <Carbon/Carbon.h>
  28 #import "CMenuItem.h"
  29 #import "CMenu.h"
  30 #import "AWTEvent.h"
  31 #import "AWTWindow.h"
  32 #import "ThreadUtilities.h"
  33 
  34 #import "java_awt_Event.h"
  35 #import "java_awt_event_KeyEvent.h"
  36 #import "sun_lwawt_macosx_CMenuItem.h"
  37 
  38 #define NOT_A_CHECKBOXMENU -2
  39 
  40 
  41 @implementation CMenuItem
  42 
  43 - (id) initWithPeer:(jobject)peer asSeparator: (BOOL) asSeparator{
  44     AWT_ASSERT_APPKIT_THREAD;
  45     self = [super initWithPeer:peer];
  46     if (self) {
  47         if (asSeparator) {
  48             fMenuItem = (NSMenuItem*)[NSMenuItem separatorItem];
  49             [fMenuItem retain];
  50         } else {
  51             fMenuItem = [[NSMenuItem alloc] init];


  95         if ([currEvent type] == NSKeyDown) {
  96             // Event available through sender variable hence NSApplication
  97             // not needed for checking the keyboard input sans the modifier keys
  98             // Also, the method used to fetch eventKey earlier would be locale dependent
  99             // With earlier implementation, if MenuKey: e EventKey: ा ; if input method
 100             // is not U.S. (Devanagari in this case)
 101             // With current implementation, EventKey = MenuKey = e irrespective of
 102             // input method
 103             NSString *eventKey = [sender keyEquivalent];
 104             // Apple uses characters from private Unicode range for some of the
 105             // keys, so we need to do the same translation here that we do
 106             // for the regular key down events
 107             if ([eventKey length] == 1) {
 108                 unichar origChar = [eventKey characterAtIndex:0];
 109                 unichar newChar =  NsCharToJavaChar(origChar, 0);
 110                 if (newChar == java_awt_event_KeyEvent_CHAR_UNDEFINED) {
 111                     newChar = origChar;
 112                 }
 113                 eventKey = [NSString stringWithCharacters: &newChar length: 1];
 114             }
 115             // The action event can be ignored only if the key window is an AWT window.
 116             // Otherwise, the action event is the only notification and must be processed.
 117             NSWindow *keyWindow = [NSApp keyWindow];
 118             if (keyWindow != nil && [AWTWindow isAWTWindow: keyWindow]) {
 119                 return;
 120             }
 121         }
 122         
 123         static JNF_CLASS_CACHE(jc_CMenuItem, "sun/lwawt/macosx/CMenuItem");
 124         static JNF_MEMBER_CACHE(jm_handleAction, jc_CMenuItem, "handleAction", "(JI)V"); // AWT_THREADING Safe (event)
 125 
 126         NSUInteger modifiers = [currEvent modifierFlags];
 127         jint javaModifiers = NsKeyModifiersToJavaModifiers(modifiers, NO);
 128 
 129         JNFCallVoidMethod(env, fPeer, jm_handleAction, UTC(currEvent), javaModifiers); // AWT_THREADING Safe (event)
 130     }
 131     JNF_COCOA_EXIT(env);
 132     
 133 }
 134 
 135 - (void) setJavaLabel:(NSString *)theLabel shortcut:(NSString *)theKeyEquivalent modifierMask:(jint)modifiers {
 136     
 137     NSUInteger modifierMask = 0;
 138     


< prev index next >