< prev index next >

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

Print this page
rev 54094 : 8257853: Remove dependencies on JNF's JNI utility functions in AWT and 2D code
rev 54096 : 8259651: [macOS] Replace JNF_COCOA_ENTER/EXIT macros
rev 54098 : 8260616: Removing remaining JNF dependencies in the java.desktop module
8259729: Missed JNFInstanceOf -> IsInstanceOf conversion


   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];
  52             [fMenuItem setAction:@selector(handleAction:)];
  53             [fMenuItem setTarget:self];
  54         }
  55         fIsCheckbox = NO;
  56         fIsEnabled = YES;
  57     }
  58     return self;
  59 }
  60 
  61 // This is because NSApplication doesn't check the target's window when sending
  62 // actions; they only check the target itself.  We always return YES,
  63 // since we shouldn't even be installed unless our window is active.
  64 - (BOOL) worksWhenModal {
  65     return YES;
  66 }
  67 
  68 // Events
  69 - (void)handleAction:(NSMenuItem *)sender {
  70     AWT_ASSERT_APPKIT_THREAD;
  71     JNIEnv *env = [ThreadUtilities getJNIEnv];
  72     JNF_COCOA_ENTER(env);
  73     
  74     // If we are called as a result of user pressing a shortcut, do nothing,
  75     // because AVTView has already sent corresponding key event to the Java
  76     // layer from performKeyEquivalent.
  77     // There is an exception from the rule above, though: if a window with
  78     // a menu gets minimized by user and there are no other windows to take
  79     // focus, the window's menu won't be removed from the global menu bar.
  80     // However, the Java layer won't handle invocation by a shortcut coming
  81     // from this "frameless" menu, because there are no active windows. This
  82     // means we have to handle it here.
  83     NSEvent *currEvent = [[NSApplication sharedApplication] currentEvent];
  84     if (fIsCheckbox) {
  85         static JNF_CLASS_CACHE(jc_CCheckboxMenuItem, "sun/lwawt/macosx/CCheckboxMenuItem");
  86         static JNF_MEMBER_CACHE(jm_ckHandleAction, jc_CCheckboxMenuItem, "handleAction", "(Z)V");
  87         
  88         // Send the opposite of what's currently checked -- the action
  89         // indicates what state we're going to.
  90         NSInteger state = [sender state];
  91         jboolean newState = (state == NSOnState ? JNI_FALSE : JNI_TRUE);
  92         JNFCallVoidMethod(env, fPeer, jm_ckHandleAction, newState);
  93     }
  94     else {
  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 
 139     if (![theKeyEquivalent isEqualToString:@""]) {
 140         // Force the key equivalent to lower case if not using the shift key.
 141         // Otherwise AppKit will draw a Shift glyph in the menu.
 142         if ((modifiers & java_awt_event_KeyEvent_SHIFT_MASK) == 0) {
 143             theKeyEquivalent = [theKeyEquivalent lowercaseString];
 144         }
 145 
 146         // Hack for the question mark -- SHIFT and / means use the question mark.
 147         if ((modifiers & java_awt_event_KeyEvent_SHIFT_MASK) != 0 &&
 148             [theKeyEquivalent isEqualToString:@"/"])
 149         {
 150             theKeyEquivalent = @"?";
 151             modifiers &= ~java_awt_event_KeyEvent_SHIFT_MASK;


 313             case java_awt_event_KeyEvent_VK_NUMBER_SIGN     : macKey = '#'; break;
 314             case java_awt_event_KeyEvent_VK_PLUS            : macKey = '+'; break;
 315             case java_awt_event_KeyEvent_VK_RIGHT_PARENTHESIS: macKey = ')'; break;
 316             case java_awt_event_KeyEvent_VK_UNDERSCORE      : macKey = '_'; break;
 317         }
 318     }
 319     return macKey;
 320 }
 321 
 322 /*
 323  * Class:     sun_lwawt_macosx_CMenuItem
 324  * Method:    nativeSetLabel
 325  * Signature: (JLjava/lang/String;CII)V
 326  */
 327 JNIEXPORT void JNICALL
 328 Java_sun_lwawt_macosx_CMenuItem_nativeSetLabel
 329 (JNIEnv *env, jobject peer,
 330  jlong menuItemObj, jstring label,
 331  jchar shortcutKey, jint shortcutKeyCode, jint mods)
 332 {
 333     JNF_COCOA_ENTER(env);
 334     NSString *theLabel = JNFJavaToNSString(env, label);
 335     NSString *theKeyEquivalent = nil;
 336     unichar macKey = shortcutKey;
 337 
 338     if (macKey == 0) {
 339         macKey = AWTKeyToMacShortcut(shortcutKeyCode, (mods & java_awt_event_KeyEvent_SHIFT_MASK) != 0);
 340     }
 341 
 342     if (macKey != 0) {
 343         unichar equivalent[1] = {macKey};
 344         theKeyEquivalent = [NSString stringWithCharacters:equivalent length:1];
 345     } else {
 346         theKeyEquivalent = @"";
 347     }
 348 
 349     [((CMenuItem *)jlong_to_ptr(menuItemObj)) setJavaLabel:theLabel shortcut:theKeyEquivalent modifierMask:mods];
 350     JNF_COCOA_EXIT(env);
 351 }
 352 
 353 /*
 354  * Class:     sun_lwawt_macosx_CMenuItem
 355  * Method:    nativeSetTooltip
 356  * Signature: (JLjava/lang/String;)V
 357  */
 358 JNIEXPORT void JNICALL
 359 Java_sun_lwawt_macosx_CMenuItem_nativeSetTooltip
 360 (JNIEnv *env, jobject peer, jlong menuItemObj, jstring tooltip)
 361 {
 362     JNF_COCOA_ENTER(env);
 363     NSString *theTooltip = JNFJavaToNSString(env, tooltip);
 364     [((CMenuItem *)jlong_to_ptr(menuItemObj)) setJavaToolTipText:theTooltip];
 365     JNF_COCOA_EXIT(env);
 366 }
 367 
 368 /*
 369  * Class:     sun_lwawt_macosx_CMenuItem
 370  * Method:    nativeSetImage
 371  * Signature: (JJ)V
 372  */
 373 JNIEXPORT void JNICALL
 374 Java_sun_lwawt_macosx_CMenuItem_nativeSetImage
 375 (JNIEnv *env, jobject peer, jlong menuItemObj, jlong image)
 376 {
 377     JNF_COCOA_ENTER(env);
 378     [((CMenuItem *)jlong_to_ptr(menuItemObj)) setJavaImage:(NSImage*)jlong_to_ptr(image)];
 379     JNF_COCOA_EXIT(env);
 380 }
 381 
 382 /*
 383  * Class:     sun_lwawt_macosx_CMenuItem
 384  * Method:    nativeCreate
 385  * Signature: (JZ)J
 386  */
 387 JNIEXPORT jlong JNICALL
 388 Java_sun_lwawt_macosx_CMenuItem_nativeCreate
 389 (JNIEnv *env, jobject peer, jlong parentCMenuObj, jboolean isSeparator)
 390 {
 391 
 392     __block CMenuItem *aCMenuItem = nil;
 393     BOOL asSeparator = (isSeparator == JNI_TRUE) ? YES: NO;
 394     CMenu *parentCMenu = (CMenu *)jlong_to_ptr(parentCMenuObj);
 395     JNF_COCOA_ENTER(env);
 396 
 397     jobject cPeerObjGlobal = (*env)->NewGlobalRef(env, peer);
 398 
 399     [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
 400         aCMenuItem = [[CMenuItem alloc] initWithPeer: cPeerObjGlobal
 401                                          asSeparator: asSeparator];
 402         // the CMenuItem is released in CMenuComponent.dispose()
 403     }];
 404 
 405     if (aCMenuItem == nil) {
 406         return 0L;
 407     }
 408 
 409     // and add it to the parent item.
 410     [parentCMenu addJavaMenuItem: aCMenuItem];
 411 
 412     // setLabel will be called after creation completes.
 413 
 414     JNF_COCOA_EXIT(env);
 415     return ptr_to_jlong(aCMenuItem);
 416 }
 417 
 418 /*
 419  * Class:     sun_lwawt_macosx_CMenuItem
 420  * Method:    nativeSetEnabled
 421  * Signature: (JZ)V
 422  */
 423 JNIEXPORT void JNICALL
 424 Java_sun_lwawt_macosx_CMenuItem_nativeSetEnabled
 425 (JNIEnv *env, jobject peer, jlong menuItemObj, jboolean enable)
 426 {
 427     JNF_COCOA_ENTER(env);
 428     CMenuItem *item = (CMenuItem *)jlong_to_ptr(menuItemObj);
 429     [item setJavaEnabled: (enable == JNI_TRUE)];
 430     JNF_COCOA_EXIT(env);
 431 }
 432 
 433 /*
 434  * Class:     sun_lwawt_macosx_CCheckboxMenuItem
 435  * Method:    nativeSetState
 436  * Signature: (IZ)V
 437  */
 438 JNIEXPORT void JNICALL
 439 Java_sun_lwawt_macosx_CCheckboxMenuItem_nativeSetState
 440 (JNIEnv *env, jobject peer, jlong menuItemObj, jboolean state)
 441 {
 442     JNF_COCOA_ENTER(env);
 443     CMenuItem *item = (CMenuItem *)jlong_to_ptr(menuItemObj);
 444     [item setJavaState: (state == JNI_TRUE)];
 445     JNF_COCOA_EXIT(env);
 446 }
 447 
 448 /*
 449  * Class:     sun_lwawt_macosx_CCheckboxMenuItem
 450  * Method:    nativeSetState
 451  * Signature: (IZ)V
 452  */
 453 JNIEXPORT void JNICALL
 454 Java_sun_lwawt_macosx_CCheckboxMenuItem_nativeSetIsCheckbox
 455 (JNIEnv *env, jobject peer, jlong menuItemObj)
 456 {
 457     JNF_COCOA_ENTER(env);
 458     CMenuItem *item = (CMenuItem *)jlong_to_ptr(menuItemObj);
 459     [item setIsCheckbox];
 460     JNF_COCOA_EXIT(env);
 461 }


   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 #include <Carbon/Carbon.h>
  27 #import "CMenuItem.h"
  28 #import "CMenu.h"
  29 #import "AWTEvent.h"
  30 #import "AWTWindow.h"
  31 #import "ThreadUtilities.h"
  32 #import "JNIUtilities.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];
  52             [fMenuItem setAction:@selector(handleAction:)];
  53             [fMenuItem setTarget:self];
  54         }
  55         fIsCheckbox = NO;
  56         fIsEnabled = YES;
  57     }
  58     return self;
  59 }
  60 
  61 // This is because NSApplication doesn't check the target's window when sending
  62 // actions; they only check the target itself.  We always return YES,
  63 // since we shouldn't even be installed unless our window is active.
  64 - (BOOL) worksWhenModal {
  65     return YES;
  66 }
  67 
  68 // Events
  69 - (void)handleAction:(NSMenuItem *)sender {
  70     AWT_ASSERT_APPKIT_THREAD;
  71     JNIEnv *env = [ThreadUtilities getJNIEnv];
  72     JNI_COCOA_ENTER(env);
  73     
  74     // If we are called as a result of user pressing a shortcut, do nothing,
  75     // because AVTView has already sent corresponding key event to the Java
  76     // layer from performKeyEquivalent.
  77     // There is an exception from the rule above, though: if a window with
  78     // a menu gets minimized by user and there are no other windows to take
  79     // focus, the window's menu won't be removed from the global menu bar.
  80     // However, the Java layer won't handle invocation by a shortcut coming
  81     // from this "frameless" menu, because there are no active windows. This
  82     // means we have to handle it here.
  83     NSEvent *currEvent = [[NSApplication sharedApplication] currentEvent];
  84     if (fIsCheckbox) {
  85         DECLARE_CLASS(jc_CCheckboxMenuItem, "sun/lwawt/macosx/CCheckboxMenuItem");
  86         DECLARE_METHOD(jm_ckHandleAction, jc_CCheckboxMenuItem, "handleAction", "(Z)V");
  87         
  88         // Send the opposite of what's currently checked -- the action
  89         // indicates what state we're going to.
  90         NSInteger state = [sender state];
  91         jboolean newState = (state == NSOnState ? JNI_FALSE : JNI_TRUE);
  92         (*env)->CallVoidMethod(env, fPeer, jm_ckHandleAction, newState);
  93     }
  94     else {
  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         DECLARE_CLASS(jc_CMenuItem, "sun/lwawt/macosx/CMenuItem");
 124         DECLARE_METHOD(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         (*env)->CallVoidMethod(env, fPeer, jm_handleAction, UTC(currEvent), javaModifiers); // AWT_THREADING Safe (event)
 130     }
 131     CHECK_EXCEPTION();
 132     JNI_COCOA_EXIT(env);
 133     
 134 }
 135 
 136 - (void) setJavaLabel:(NSString *)theLabel shortcut:(NSString *)theKeyEquivalent modifierMask:(jint)modifiers {
 137 
 138     NSUInteger modifierMask = 0;
 139 
 140     if (![theKeyEquivalent isEqualToString:@""]) {
 141         // Force the key equivalent to lower case if not using the shift key.
 142         // Otherwise AppKit will draw a Shift glyph in the menu.
 143         if ((modifiers & java_awt_event_KeyEvent_SHIFT_MASK) == 0) {
 144             theKeyEquivalent = [theKeyEquivalent lowercaseString];
 145         }
 146 
 147         // Hack for the question mark -- SHIFT and / means use the question mark.
 148         if ((modifiers & java_awt_event_KeyEvent_SHIFT_MASK) != 0 &&
 149             [theKeyEquivalent isEqualToString:@"/"])
 150         {
 151             theKeyEquivalent = @"?";
 152             modifiers &= ~java_awt_event_KeyEvent_SHIFT_MASK;


 314             case java_awt_event_KeyEvent_VK_NUMBER_SIGN     : macKey = '#'; break;
 315             case java_awt_event_KeyEvent_VK_PLUS            : macKey = '+'; break;
 316             case java_awt_event_KeyEvent_VK_RIGHT_PARENTHESIS: macKey = ')'; break;
 317             case java_awt_event_KeyEvent_VK_UNDERSCORE      : macKey = '_'; break;
 318         }
 319     }
 320     return macKey;
 321 }
 322 
 323 /*
 324  * Class:     sun_lwawt_macosx_CMenuItem
 325  * Method:    nativeSetLabel
 326  * Signature: (JLjava/lang/String;CII)V
 327  */
 328 JNIEXPORT void JNICALL
 329 Java_sun_lwawt_macosx_CMenuItem_nativeSetLabel
 330 (JNIEnv *env, jobject peer,
 331  jlong menuItemObj, jstring label,
 332  jchar shortcutKey, jint shortcutKeyCode, jint mods)
 333 {
 334     JNI_COCOA_ENTER(env);
 335     NSString *theLabel = JavaStringToNSString(env, label);
 336     NSString *theKeyEquivalent = nil;
 337     unichar macKey = shortcutKey;
 338 
 339     if (macKey == 0) {
 340         macKey = AWTKeyToMacShortcut(shortcutKeyCode, (mods & java_awt_event_KeyEvent_SHIFT_MASK) != 0);
 341     }
 342 
 343     if (macKey != 0) {
 344         unichar equivalent[1] = {macKey};
 345         theKeyEquivalent = [NSString stringWithCharacters:equivalent length:1];
 346     } else {
 347         theKeyEquivalent = @"";
 348     }
 349 
 350     [((CMenuItem *)jlong_to_ptr(menuItemObj)) setJavaLabel:theLabel shortcut:theKeyEquivalent modifierMask:mods];
 351     JNI_COCOA_EXIT(env);
 352 }
 353 
 354 /*
 355  * Class:     sun_lwawt_macosx_CMenuItem
 356  * Method:    nativeSetTooltip
 357  * Signature: (JLjava/lang/String;)V
 358  */
 359 JNIEXPORT void JNICALL
 360 Java_sun_lwawt_macosx_CMenuItem_nativeSetTooltip
 361 (JNIEnv *env, jobject peer, jlong menuItemObj, jstring tooltip)
 362 {
 363     JNI_COCOA_ENTER(env);
 364     NSString *theTooltip = JavaStringToNSString(env, tooltip);
 365     [((CMenuItem *)jlong_to_ptr(menuItemObj)) setJavaToolTipText:theTooltip];
 366     JNI_COCOA_EXIT(env);
 367 }
 368 
 369 /*
 370  * Class:     sun_lwawt_macosx_CMenuItem
 371  * Method:    nativeSetImage
 372  * Signature: (JJ)V
 373  */
 374 JNIEXPORT void JNICALL
 375 Java_sun_lwawt_macosx_CMenuItem_nativeSetImage
 376 (JNIEnv *env, jobject peer, jlong menuItemObj, jlong image)
 377 {
 378     JNI_COCOA_ENTER(env);
 379     [((CMenuItem *)jlong_to_ptr(menuItemObj)) setJavaImage:(NSImage*)jlong_to_ptr(image)];
 380     JNI_COCOA_EXIT(env);
 381 }
 382 
 383 /*
 384  * Class:     sun_lwawt_macosx_CMenuItem
 385  * Method:    nativeCreate
 386  * Signature: (JZ)J
 387  */
 388 JNIEXPORT jlong JNICALL
 389 Java_sun_lwawt_macosx_CMenuItem_nativeCreate
 390 (JNIEnv *env, jobject peer, jlong parentCMenuObj, jboolean isSeparator)
 391 {
 392 
 393     __block CMenuItem *aCMenuItem = nil;
 394     BOOL asSeparator = (isSeparator == JNI_TRUE) ? YES: NO;
 395     CMenu *parentCMenu = (CMenu *)jlong_to_ptr(parentCMenuObj);
 396     JNI_COCOA_ENTER(env);
 397 
 398     jobject cPeerObjGlobal = (*env)->NewGlobalRef(env, peer);
 399 
 400     [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
 401         aCMenuItem = [[CMenuItem alloc] initWithPeer: cPeerObjGlobal
 402                                          asSeparator: asSeparator];
 403         // the CMenuItem is released in CMenuComponent.dispose()
 404     }];
 405 
 406     if (aCMenuItem == nil) {
 407         return 0L;
 408     }
 409 
 410     // and add it to the parent item.
 411     [parentCMenu addJavaMenuItem: aCMenuItem];
 412 
 413     // setLabel will be called after creation completes.
 414 
 415     JNI_COCOA_EXIT(env);
 416     return ptr_to_jlong(aCMenuItem);
 417 }
 418 
 419 /*
 420  * Class:     sun_lwawt_macosx_CMenuItem
 421  * Method:    nativeSetEnabled
 422  * Signature: (JZ)V
 423  */
 424 JNIEXPORT void JNICALL
 425 Java_sun_lwawt_macosx_CMenuItem_nativeSetEnabled
 426 (JNIEnv *env, jobject peer, jlong menuItemObj, jboolean enable)
 427 {
 428     JNI_COCOA_ENTER(env);
 429     CMenuItem *item = (CMenuItem *)jlong_to_ptr(menuItemObj);
 430     [item setJavaEnabled: (enable == JNI_TRUE)];
 431     JNI_COCOA_EXIT(env);
 432 }
 433 
 434 /*
 435  * Class:     sun_lwawt_macosx_CCheckboxMenuItem
 436  * Method:    nativeSetState
 437  * Signature: (IZ)V
 438  */
 439 JNIEXPORT void JNICALL
 440 Java_sun_lwawt_macosx_CCheckboxMenuItem_nativeSetState
 441 (JNIEnv *env, jobject peer, jlong menuItemObj, jboolean state)
 442 {
 443     JNI_COCOA_ENTER(env);
 444     CMenuItem *item = (CMenuItem *)jlong_to_ptr(menuItemObj);
 445     [item setJavaState: (state == JNI_TRUE)];
 446     JNI_COCOA_EXIT(env);
 447 }
 448 
 449 /*
 450  * Class:     sun_lwawt_macosx_CCheckboxMenuItem
 451  * Method:    nativeSetState
 452  * Signature: (IZ)V
 453  */
 454 JNIEXPORT void JNICALL
 455 Java_sun_lwawt_macosx_CCheckboxMenuItem_nativeSetIsCheckbox
 456 (JNIEnv *env, jobject peer, jlong menuItemObj)
 457 {
 458     JNI_COCOA_ENTER(env);
 459     CMenuItem *item = (CMenuItem *)jlong_to_ptr(menuItemObj);
 460     [item setIsCheckbox];
 461     JNI_COCOA_EXIT(env);
 462 }
< prev index next >