< 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
*** 21,37 ****
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
- #import <JavaNativeFoundation/JavaNativeFoundation.h>
#include <Carbon/Carbon.h>
#import "CMenuItem.h"
#import "CMenu.h"
#import "AWTEvent.h"
#import "AWTWindow.h"
#import "ThreadUtilities.h"
#import "java_awt_Event.h"
#import "java_awt_event_KeyEvent.h"
#import "sun_lwawt_macosx_CMenuItem.h"
--- 21,37 ----
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#include <Carbon/Carbon.h>
#import "CMenuItem.h"
#import "CMenu.h"
#import "AWTEvent.h"
#import "AWTWindow.h"
#import "ThreadUtilities.h"
+ #import "JNIUtilities.h"
#import "java_awt_Event.h"
#import "java_awt_event_KeyEvent.h"
#import "sun_lwawt_macosx_CMenuItem.h"
*** 67,77 ****
// Events
- (void)handleAction:(NSMenuItem *)sender {
AWT_ASSERT_APPKIT_THREAD;
JNIEnv *env = [ThreadUtilities getJNIEnv];
! JNF_COCOA_ENTER(env);
// If we are called as a result of user pressing a shortcut, do nothing,
// because AVTView has already sent corresponding key event to the Java
// layer from performKeyEquivalent.
// There is an exception from the rule above, though: if a window with
--- 67,77 ----
// Events
- (void)handleAction:(NSMenuItem *)sender {
AWT_ASSERT_APPKIT_THREAD;
JNIEnv *env = [ThreadUtilities getJNIEnv];
! JNI_COCOA_ENTER(env);
// If we are called as a result of user pressing a shortcut, do nothing,
// because AVTView has already sent corresponding key event to the Java
// layer from performKeyEquivalent.
// There is an exception from the rule above, though: if a window with
*** 80,97 ****
// However, the Java layer won't handle invocation by a shortcut coming
// from this "frameless" menu, because there are no active windows. This
// means we have to handle it here.
NSEvent *currEvent = [[NSApplication sharedApplication] currentEvent];
if (fIsCheckbox) {
! static JNF_CLASS_CACHE(jc_CCheckboxMenuItem, "sun/lwawt/macosx/CCheckboxMenuItem");
! static JNF_MEMBER_CACHE(jm_ckHandleAction, jc_CCheckboxMenuItem, "handleAction", "(Z)V");
// Send the opposite of what's currently checked -- the action
// indicates what state we're going to.
NSInteger state = [sender state];
jboolean newState = (state == NSOnState ? JNI_FALSE : JNI_TRUE);
! JNFCallVoidMethod(env, fPeer, jm_ckHandleAction, newState);
}
else {
if ([currEvent type] == NSKeyDown) {
// Event available through sender variable hence NSApplication
// not needed for checking the keyboard input sans the modifier keys
--- 80,97 ----
// However, the Java layer won't handle invocation by a shortcut coming
// from this "frameless" menu, because there are no active windows. This
// means we have to handle it here.
NSEvent *currEvent = [[NSApplication sharedApplication] currentEvent];
if (fIsCheckbox) {
! DECLARE_CLASS(jc_CCheckboxMenuItem, "sun/lwawt/macosx/CCheckboxMenuItem");
! DECLARE_METHOD(jm_ckHandleAction, jc_CCheckboxMenuItem, "handleAction", "(Z)V");
// Send the opposite of what's currently checked -- the action
// indicates what state we're going to.
NSInteger state = [sender state];
jboolean newState = (state == NSOnState ? JNI_FALSE : JNI_TRUE);
! (*env)->CallVoidMethod(env, fPeer, jm_ckHandleAction, newState);
}
else {
if ([currEvent type] == NSKeyDown) {
// Event available through sender variable hence NSApplication
// not needed for checking the keyboard input sans the modifier keys
*** 118,136 ****
if (keyWindow != nil && [AWTWindow isAWTWindow: keyWindow]) {
return;
}
}
! static JNF_CLASS_CACHE(jc_CMenuItem, "sun/lwawt/macosx/CMenuItem");
! static JNF_MEMBER_CACHE(jm_handleAction, jc_CMenuItem, "handleAction", "(JI)V"); // AWT_THREADING Safe (event)
NSUInteger modifiers = [currEvent modifierFlags];
jint javaModifiers = NsKeyModifiersToJavaModifiers(modifiers, NO);
! JNFCallVoidMethod(env, fPeer, jm_handleAction, UTC(currEvent), javaModifiers); // AWT_THREADING Safe (event)
}
! JNF_COCOA_EXIT(env);
}
- (void) setJavaLabel:(NSString *)theLabel shortcut:(NSString *)theKeyEquivalent modifierMask:(jint)modifiers {
--- 118,137 ----
if (keyWindow != nil && [AWTWindow isAWTWindow: keyWindow]) {
return;
}
}
! DECLARE_CLASS(jc_CMenuItem, "sun/lwawt/macosx/CMenuItem");
! DECLARE_METHOD(jm_handleAction, jc_CMenuItem, "handleAction", "(JI)V"); // AWT_THREADING Safe (event)
NSUInteger modifiers = [currEvent modifierFlags];
jint javaModifiers = NsKeyModifiersToJavaModifiers(modifiers, NO);
! (*env)->CallVoidMethod(env, fPeer, jm_handleAction, UTC(currEvent), javaModifiers); // AWT_THREADING Safe (event)
}
! CHECK_EXCEPTION();
! JNI_COCOA_EXIT(env);
}
- (void) setJavaLabel:(NSString *)theLabel shortcut:(NSString *)theKeyEquivalent modifierMask:(jint)modifiers {
*** 328,339 ****
Java_sun_lwawt_macosx_CMenuItem_nativeSetLabel
(JNIEnv *env, jobject peer,
jlong menuItemObj, jstring label,
jchar shortcutKey, jint shortcutKeyCode, jint mods)
{
! JNF_COCOA_ENTER(env);
! NSString *theLabel = JNFJavaToNSString(env, label);
NSString *theKeyEquivalent = nil;
unichar macKey = shortcutKey;
if (macKey == 0) {
macKey = AWTKeyToMacShortcut(shortcutKeyCode, (mods & java_awt_event_KeyEvent_SHIFT_MASK) != 0);
--- 329,340 ----
Java_sun_lwawt_macosx_CMenuItem_nativeSetLabel
(JNIEnv *env, jobject peer,
jlong menuItemObj, jstring label,
jchar shortcutKey, jint shortcutKeyCode, jint mods)
{
! JNI_COCOA_ENTER(env);
! NSString *theLabel = JavaStringToNSString(env, label);
NSString *theKeyEquivalent = nil;
unichar macKey = shortcutKey;
if (macKey == 0) {
macKey = AWTKeyToMacShortcut(shortcutKeyCode, (mods & java_awt_event_KeyEvent_SHIFT_MASK) != 0);
*** 345,355 ****
} else {
theKeyEquivalent = @"";
}
[((CMenuItem *)jlong_to_ptr(menuItemObj)) setJavaLabel:theLabel shortcut:theKeyEquivalent modifierMask:mods];
! JNF_COCOA_EXIT(env);
}
/*
* Class: sun_lwawt_macosx_CMenuItem
* Method: nativeSetTooltip
--- 346,356 ----
} else {
theKeyEquivalent = @"";
}
[((CMenuItem *)jlong_to_ptr(menuItemObj)) setJavaLabel:theLabel shortcut:theKeyEquivalent modifierMask:mods];
! JNI_COCOA_EXIT(env);
}
/*
* Class: sun_lwawt_macosx_CMenuItem
* Method: nativeSetTooltip
*** 357,370 ****
*/
JNIEXPORT void JNICALL
Java_sun_lwawt_macosx_CMenuItem_nativeSetTooltip
(JNIEnv *env, jobject peer, jlong menuItemObj, jstring tooltip)
{
! JNF_COCOA_ENTER(env);
! NSString *theTooltip = JNFJavaToNSString(env, tooltip);
[((CMenuItem *)jlong_to_ptr(menuItemObj)) setJavaToolTipText:theTooltip];
! JNF_COCOA_EXIT(env);
}
/*
* Class: sun_lwawt_macosx_CMenuItem
* Method: nativeSetImage
--- 358,371 ----
*/
JNIEXPORT void JNICALL
Java_sun_lwawt_macosx_CMenuItem_nativeSetTooltip
(JNIEnv *env, jobject peer, jlong menuItemObj, jstring tooltip)
{
! JNI_COCOA_ENTER(env);
! NSString *theTooltip = JavaStringToNSString(env, tooltip);
[((CMenuItem *)jlong_to_ptr(menuItemObj)) setJavaToolTipText:theTooltip];
! JNI_COCOA_EXIT(env);
}
/*
* Class: sun_lwawt_macosx_CMenuItem
* Method: nativeSetImage
*** 372,384 ****
*/
JNIEXPORT void JNICALL
Java_sun_lwawt_macosx_CMenuItem_nativeSetImage
(JNIEnv *env, jobject peer, jlong menuItemObj, jlong image)
{
! JNF_COCOA_ENTER(env);
[((CMenuItem *)jlong_to_ptr(menuItemObj)) setJavaImage:(NSImage*)jlong_to_ptr(image)];
! JNF_COCOA_EXIT(env);
}
/*
* Class: sun_lwawt_macosx_CMenuItem
* Method: nativeCreate
--- 373,385 ----
*/
JNIEXPORT void JNICALL
Java_sun_lwawt_macosx_CMenuItem_nativeSetImage
(JNIEnv *env, jobject peer, jlong menuItemObj, jlong image)
{
! JNI_COCOA_ENTER(env);
[((CMenuItem *)jlong_to_ptr(menuItemObj)) setJavaImage:(NSImage*)jlong_to_ptr(image)];
! JNI_COCOA_EXIT(env);
}
/*
* Class: sun_lwawt_macosx_CMenuItem
* Method: nativeCreate
*** 390,400 ****
{
__block CMenuItem *aCMenuItem = nil;
BOOL asSeparator = (isSeparator == JNI_TRUE) ? YES: NO;
CMenu *parentCMenu = (CMenu *)jlong_to_ptr(parentCMenuObj);
! JNF_COCOA_ENTER(env);
jobject cPeerObjGlobal = (*env)->NewGlobalRef(env, peer);
[ThreadUtilities performOnMainThreadWaiting:YES block:^(){
aCMenuItem = [[CMenuItem alloc] initWithPeer: cPeerObjGlobal
--- 391,401 ----
{
__block CMenuItem *aCMenuItem = nil;
BOOL asSeparator = (isSeparator == JNI_TRUE) ? YES: NO;
CMenu *parentCMenu = (CMenu *)jlong_to_ptr(parentCMenuObj);
! JNI_COCOA_ENTER(env);
jobject cPeerObjGlobal = (*env)->NewGlobalRef(env, peer);
[ThreadUtilities performOnMainThreadWaiting:YES block:^(){
aCMenuItem = [[CMenuItem alloc] initWithPeer: cPeerObjGlobal
*** 409,419 ****
// and add it to the parent item.
[parentCMenu addJavaMenuItem: aCMenuItem];
// setLabel will be called after creation completes.
! JNF_COCOA_EXIT(env);
return ptr_to_jlong(aCMenuItem);
}
/*
* Class: sun_lwawt_macosx_CMenuItem
--- 410,420 ----
// and add it to the parent item.
[parentCMenu addJavaMenuItem: aCMenuItem];
// setLabel will be called after creation completes.
! JNI_COCOA_EXIT(env);
return ptr_to_jlong(aCMenuItem);
}
/*
* Class: sun_lwawt_macosx_CMenuItem
*** 422,435 ****
*/
JNIEXPORT void JNICALL
Java_sun_lwawt_macosx_CMenuItem_nativeSetEnabled
(JNIEnv *env, jobject peer, jlong menuItemObj, jboolean enable)
{
! JNF_COCOA_ENTER(env);
CMenuItem *item = (CMenuItem *)jlong_to_ptr(menuItemObj);
[item setJavaEnabled: (enable == JNI_TRUE)];
! JNF_COCOA_EXIT(env);
}
/*
* Class: sun_lwawt_macosx_CCheckboxMenuItem
* Method: nativeSetState
--- 423,436 ----
*/
JNIEXPORT void JNICALL
Java_sun_lwawt_macosx_CMenuItem_nativeSetEnabled
(JNIEnv *env, jobject peer, jlong menuItemObj, jboolean enable)
{
! JNI_COCOA_ENTER(env);
CMenuItem *item = (CMenuItem *)jlong_to_ptr(menuItemObj);
[item setJavaEnabled: (enable == JNI_TRUE)];
! JNI_COCOA_EXIT(env);
}
/*
* Class: sun_lwawt_macosx_CCheckboxMenuItem
* Method: nativeSetState
*** 437,450 ****
*/
JNIEXPORT void JNICALL
Java_sun_lwawt_macosx_CCheckboxMenuItem_nativeSetState
(JNIEnv *env, jobject peer, jlong menuItemObj, jboolean state)
{
! JNF_COCOA_ENTER(env);
CMenuItem *item = (CMenuItem *)jlong_to_ptr(menuItemObj);
[item setJavaState: (state == JNI_TRUE)];
! JNF_COCOA_EXIT(env);
}
/*
* Class: sun_lwawt_macosx_CCheckboxMenuItem
* Method: nativeSetState
--- 438,451 ----
*/
JNIEXPORT void JNICALL
Java_sun_lwawt_macosx_CCheckboxMenuItem_nativeSetState
(JNIEnv *env, jobject peer, jlong menuItemObj, jboolean state)
{
! JNI_COCOA_ENTER(env);
CMenuItem *item = (CMenuItem *)jlong_to_ptr(menuItemObj);
[item setJavaState: (state == JNI_TRUE)];
! JNI_COCOA_EXIT(env);
}
/*
* Class: sun_lwawt_macosx_CCheckboxMenuItem
* Method: nativeSetState
*** 452,461 ****
*/
JNIEXPORT void JNICALL
Java_sun_lwawt_macosx_CCheckboxMenuItem_nativeSetIsCheckbox
(JNIEnv *env, jobject peer, jlong menuItemObj)
{
! JNF_COCOA_ENTER(env);
CMenuItem *item = (CMenuItem *)jlong_to_ptr(menuItemObj);
[item setIsCheckbox];
! JNF_COCOA_EXIT(env);
}
--- 453,462 ----
*/
JNIEXPORT void JNICALL
Java_sun_lwawt_macosx_CCheckboxMenuItem_nativeSetIsCheckbox
(JNIEnv *env, jobject peer, jlong menuItemObj)
{
! JNI_COCOA_ENTER(env);
CMenuItem *item = (CMenuItem *)jlong_to_ptr(menuItemObj);
[item setIsCheckbox];
! JNI_COCOA_EXIT(env);
}
< prev index next >