< prev index next >

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

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

*** 31,43 **** #import "JavaTextAccessibility.h" #import "JavaAccessibilityUtilities.h" #import "GeomUtilities.h" #import "OSVersion.h" #import "ThreadUtilities.h" #import <Carbon/Carbon.h> - #import <JavaNativeFoundation/JavaNativeFoundation.h> // keyboard layout static NSString *kbdLayout; @interface AWTView() --- 31,43 ---- #import "JavaTextAccessibility.h" #import "JavaAccessibilityUtilities.h" #import "GeomUtilities.h" #import "OSVersion.h" #import "ThreadUtilities.h" + #import "JNIUtilities.h" #import <Carbon/Carbon.h> // keyboard layout static NSString *kbdLayout; @interface AWTView()
*** 139,149 **** if (fInputMethodLOCKABLE != NULL) { JNIEnv *env = [ThreadUtilities getJNIEnvUncached]; ! JNFDeleteGlobalRef(env, fInputMethodLOCKABLE); fInputMethodLOCKABLE = NULL; } if (rolloverTrackingArea != nil) { [self removeTrackingArea:rolloverTrackingArea]; --- 139,149 ---- if (fInputMethodLOCKABLE != NULL) { JNIEnv *env = [ThreadUtilities getJNIEnvUncached]; ! (*env)->DeleteGlobalRef(env, fInputMethodLOCKABLE); fInputMethodLOCKABLE = NULL; } if (rolloverTrackingArea != nil) { [self removeTrackingArea:rolloverTrackingArea];
*** 157,167 **** - (void) viewDidMoveToWindow { AWT_ASSERT_APPKIT_THREAD; [AWTToolkit eventCountPlusPlus]; ! [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^() { [[self window] makeFirstResponder: self]; }]; if ([self window] != NULL) { [self resetTrackingArea]; } --- 157,167 ---- - (void) viewDidMoveToWindow { AWT_ASSERT_APPKIT_THREAD; [AWTToolkit eventCountPlusPlus]; ! [ThreadUtilities performOnMainThreadWaiting:NO block:^() { [[self window] makeFirstResponder: self]; }]; if ([self window] != NULL) { [self resetTrackingArea]; }
*** 416,428 **** if ([AWTToolkit hasPreciseScrollingDeltas: event]) { deltaX = [event scrollingDeltaX] * 0.1; deltaY = [event scrollingDeltaY] * 0.1; } ! static JNF_CLASS_CACHE(jc_NSEvent, "sun/lwawt/macosx/NSEvent"); ! static JNF_CTOR_CACHE(jctor_NSEvent, jc_NSEvent, "(IIIIIIIIDDI)V"); ! jobject jEvent = JNFNewObject(env, jctor_NSEvent, [event type], [event modifierFlags], clickCount, [event buttonNumber], (jint)localPoint.x, (jint)localPoint.y, --- 416,428 ---- if ([AWTToolkit hasPreciseScrollingDeltas: event]) { deltaX = [event scrollingDeltaX] * 0.1; deltaY = [event scrollingDeltaY] * 0.1; } ! DECLARE_CLASS(jc_NSEvent, "sun/lwawt/macosx/NSEvent"); ! DECLARE_METHOD(jctor_NSEvent, jc_NSEvent, "<init>", "(IIIIIIIIDDI)V"); ! jobject jEvent = (*env)->NewObject(env, jc_NSEvent, jctor_NSEvent, [event type], [event modifierFlags], clickCount, [event buttonNumber], (jint)localPoint.x, (jint)localPoint.y,
*** 430,444 **** deltaY, deltaX, [AWTToolkit scrollStateWithEvent: event]); CHECK_NULL(jEvent); ! static JNF_CLASS_CACHE(jc_PlatformView, "sun/lwawt/macosx/CPlatformView"); ! static JNF_MEMBER_CACHE(jm_deliverMouseEvent, jc_PlatformView, "deliverMouseEvent", "(Lsun/lwawt/macosx/NSEvent;)V"); jobject jlocal = (*env)->NewLocalRef(env, m_cPlatformView); if (!(*env)->IsSameObject(env, jlocal, NULL)) { ! JNFCallVoidMethod(env, jlocal, jm_deliverMouseEvent, jEvent); (*env)->DeleteLocalRef(env, jlocal); } (*env)->DeleteLocalRef(env, jEvent); } --- 430,445 ---- deltaY, deltaX, [AWTToolkit scrollStateWithEvent: event]); CHECK_NULL(jEvent); ! DECLARE_CLASS(jc_PlatformView, "sun/lwawt/macosx/CPlatformView"); ! DECLARE_METHOD(jm_deliverMouseEvent, jc_PlatformView, "deliverMouseEvent", "(Lsun/lwawt/macosx/NSEvent;)V"); jobject jlocal = (*env)->NewLocalRef(env, m_cPlatformView); if (!(*env)->IsSameObject(env, jlocal, NULL)) { ! (*env)->CallVoidMethod(env, jlocal, jm_deliverMouseEvent, jEvent); ! CHECK_EXCEPTION(); (*env)->DeleteLocalRef(env, jlocal); } (*env)->DeleteLocalRef(env, jEvent); }
*** 482,511 **** JNIEnv *env = [ThreadUtilities getJNIEnv]; jstring characters = NULL; jstring charactersIgnoringModifiers = NULL; if ([event type] != NSFlagsChanged) { ! characters = JNFNSToJavaString(env, [event characters]); ! charactersIgnoringModifiers = JNFNSToJavaString(env, [event charactersIgnoringModifiers]); } ! static JNF_CLASS_CACHE(jc_NSEvent, "sun/lwawt/macosx/NSEvent"); ! static JNF_CTOR_CACHE(jctor_NSEvent, jc_NSEvent, "(IISLjava/lang/String;Ljava/lang/String;)V"); ! jobject jEvent = JNFNewObject(env, jctor_NSEvent, [event type], [event modifierFlags], [event keyCode], characters, charactersIgnoringModifiers); CHECK_NULL(jEvent); ! static JNF_CLASS_CACHE(jc_PlatformView, "sun/lwawt/macosx/CPlatformView"); ! static JNF_MEMBER_CACHE(jm_deliverKeyEvent, jc_PlatformView, "deliverKeyEvent", "(Lsun/lwawt/macosx/NSEvent;)V"); jobject jlocal = (*env)->NewLocalRef(env, m_cPlatformView); if (!(*env)->IsSameObject(env, jlocal, NULL)) { ! JNFCallVoidMethod(env, jlocal, jm_deliverKeyEvent, jEvent); (*env)->DeleteLocalRef(env, jlocal); } if (characters != NULL) { (*env)->DeleteLocalRef(env, characters); } --- 483,513 ---- JNIEnv *env = [ThreadUtilities getJNIEnv]; jstring characters = NULL; jstring charactersIgnoringModifiers = NULL; if ([event type] != NSFlagsChanged) { ! characters = NSStringToJavaString(env, [event characters]); ! charactersIgnoringModifiers = NSStringToJavaString(env, [event charactersIgnoringModifiers]); } ! DECLARE_CLASS(jc_NSEvent, "sun/lwawt/macosx/NSEvent"); ! DECLARE_METHOD(jctor_NSEvent, jc_NSEvent, "<init>", "(IISLjava/lang/String;Ljava/lang/String;)V"); ! jobject jEvent = (*env)->NewObject(env, jc_NSEvent, jctor_NSEvent, [event type], [event modifierFlags], [event keyCode], characters, charactersIgnoringModifiers); CHECK_NULL(jEvent); ! DECLARE_CLASS(jc_PlatformView, "sun/lwawt/macosx/CPlatformView"); ! DECLARE_METHOD(jm_deliverKeyEvent, jc_PlatformView, "deliverKeyEvent", "(Lsun/lwawt/macosx/NSEvent;)V"); jobject jlocal = (*env)->NewLocalRef(env, m_cPlatformView); if (!(*env)->IsSameObject(env, jlocal, NULL)) { ! (*env)->CallVoidMethod(env, jlocal, jm_deliverKeyEvent, jEvent); ! CHECK_EXCEPTION(); (*env)->DeleteLocalRef(env, jlocal); } if (characters != NULL) { (*env)->DeleteLocalRef(env, characters); }
*** 516,531 **** jint x = (jint) rect.origin.x; jint y = (jint) rect.origin.y; jint w = (jint) rect.size.width; jint h = (jint) rect.size.height; JNIEnv *env = [ThreadUtilities getJNIEnv]; ! static JNF_CLASS_CACHE(jc_PlatformView, "sun/lwawt/macosx/CPlatformView"); ! static JNF_MEMBER_CACHE(jm_deliverResize, jc_PlatformView, "deliverResize", "(IIII)V"); jobject jlocal = (*env)->NewLocalRef(env, m_cPlatformView); if (!(*env)->IsSameObject(env, jlocal, NULL)) { ! JNFCallVoidMethod(env, jlocal, jm_deliverResize, x,y,w,h); (*env)->DeleteLocalRef(env, jlocal); } } --- 518,534 ---- jint x = (jint) rect.origin.x; jint y = (jint) rect.origin.y; jint w = (jint) rect.size.width; jint h = (jint) rect.size.height; JNIEnv *env = [ThreadUtilities getJNIEnv]; ! DECLARE_CLASS(jc_PlatformView, "sun/lwawt/macosx/CPlatformView"); ! DECLARE_METHOD(jm_deliverResize, jc_PlatformView, "deliverResize", "(IIII)V"); jobject jlocal = (*env)->NewLocalRef(env, m_cPlatformView); if (!(*env)->IsSameObject(env, jlocal, NULL)) { ! (*env)->CallVoidMethod(env, jlocal, jm_deliverResize, x,y,w,h); ! CHECK_EXCEPTION(); (*env)->DeleteLocalRef(env, jlocal); } }
*** 550,564 **** (*env)->ExceptionClear(env); } } } else { */ ! static JNF_CLASS_CACHE(jc_CPlatformView, "sun/lwawt/macosx/CPlatformView"); ! static JNF_MEMBER_CACHE(jm_deliverWindowDidExposeEvent, jc_CPlatformView, "deliverWindowDidExposeEvent", "()V"); jobject jlocal = (*env)->NewLocalRef(env, m_cPlatformView); if (!(*env)->IsSameObject(env, jlocal, NULL)) { ! JNFCallVoidMethod(env, jlocal, jm_deliverWindowDidExposeEvent); (*env)->DeleteLocalRef(env, jlocal); } /* } */ --- 553,568 ---- (*env)->ExceptionClear(env); } } } else { */ ! DECLARE_CLASS(jc_CPlatformView, "sun/lwawt/macosx/CPlatformView"); ! DECLARE_METHOD(jm_deliverWindowDidExposeEvent, jc_CPlatformView, "deliverWindowDidExposeEvent", "()V"); jobject jlocal = (*env)->NewLocalRef(env, m_cPlatformView); if (!(*env)->IsSameObject(env, jlocal, NULL)) { ! (*env)->CallVoidMethod(env, jlocal, jm_deliverWindowDidExposeEvent); ! CHECK_EXCEPTION(); (*env)->DeleteLocalRef(env, jlocal); } /* } */
*** 589,632 **** } // NSAccessibility support - (jobject)awtComponent:(JNIEnv*)env { ! static JNF_CLASS_CACHE(jc_CPlatformView, "sun/lwawt/macosx/CPlatformView"); ! static JNF_MEMBER_CACHE(jf_Peer, jc_CPlatformView, "peer", "Lsun/lwawt/LWWindowPeer;"); if ((env == NULL) || (m_cPlatformView == NULL)) { NSLog(@"Apple AWT : Error AWTView:awtComponent given bad parameters."); ! if (env != NULL) ! { ! JNFDumpJavaStack(env); ! } return NULL; } jobject peer = NULL; jobject jlocal = (*env)->NewLocalRef(env, m_cPlatformView); if (!(*env)->IsSameObject(env, jlocal, NULL)) { ! peer = JNFGetObjectField(env, jlocal, jf_Peer); (*env)->DeleteLocalRef(env, jlocal); } ! static JNF_CLASS_CACHE(jc_LWWindowPeer, "sun/lwawt/LWWindowPeer"); ! static JNF_MEMBER_CACHE(jf_Target, jc_LWWindowPeer, "target", "Ljava/awt/Component;"); if (peer == NULL) { NSLog(@"Apple AWT : Error AWTView:awtComponent got null peer from CPlatformView"); ! JNFDumpJavaStack(env); return NULL; } ! jobject comp = JNFGetObjectField(env, peer, jf_Target); (*env)->DeleteLocalRef(env, peer); return comp; } + (AWTView *) awtView:(JNIEnv*)env ofAccessible:(jobject)jaccessible { ! static JNF_STATIC_MEMBER_CACHE(jm_getAWTView, sjc_CAccessibility, "getAWTView", "(Ljavax/accessibility/Accessible;)J"); ! jlong jptr = JNFCallStaticLongMethod(env, jm_getAWTView, jaccessible); if (jptr == 0) return nil; return (AWTView *)jlong_to_ptr(jptr); } --- 593,635 ---- } // NSAccessibility support - (jobject)awtComponent:(JNIEnv*)env { ! DECLARE_CLASS_RETURN(jc_CPlatformView, "sun/lwawt/macosx/CPlatformView", NULL); ! DECLARE_FIELD_RETURN(jf_Peer, jc_CPlatformView, "peer", "Lsun/lwawt/LWWindowPeer;", NULL); if ((env == NULL) || (m_cPlatformView == NULL)) { NSLog(@"Apple AWT : Error AWTView:awtComponent given bad parameters."); ! NSLog(@"%@",[NSThread callStackSymbols]); return NULL; } jobject peer = NULL; jobject jlocal = (*env)->NewLocalRef(env, m_cPlatformView); if (!(*env)->IsSameObject(env, jlocal, NULL)) { ! peer = (*env)->GetObjectField(env, jlocal, jf_Peer); (*env)->DeleteLocalRef(env, jlocal); } ! DECLARE_CLASS_RETURN(jc_LWWindowPeer, "sun/lwawt/LWWindowPeer", NULL); ! DECLARE_FIELD_RETURN(jf_Target, jc_LWWindowPeer, "target", "Ljava/awt/Component;", NULL); if (peer == NULL) { NSLog(@"Apple AWT : Error AWTView:awtComponent got null peer from CPlatformView"); ! NSLog(@"%@",[NSThread callStackSymbols]); return NULL; } ! jobject comp = (*env)->GetObjectField(env, peer, jf_Target); (*env)->DeleteLocalRef(env, peer); return comp; } + (AWTView *) awtView:(JNIEnv*)env ofAccessible:(jobject)jaccessible { ! DECLARE_CLASS_RETURN(sjc_CAccessibility, "sun/lwawt/macosx/CAccessibility", NULL); ! DECLARE_STATIC_METHOD_RETURN(jm_getAWTView, sjc_CAccessibility, "getAWTView", "(Ljavax/accessibility/Accessible;)J", NULL); ! jlong jptr = (*env)->CallStaticLongMethod(env, sjc_CAccessibility, jm_getAWTView, jaccessible); ! CHECK_EXCEPTION(); if (jptr == 0) return nil; return (AWTView *)jlong_to_ptr(jptr); }
*** 948,958 **** /******************************** END NSDraggingDestination Interface ********************************/ /******************************** BEGIN NSTextInputClient Protocol ********************************/ ! JNF_CLASS_CACHE(jc_CInputMethod, "sun/lwawt/macosx/CInputMethod"); - (void) insertText:(id)aString replacementRange:(NSRange)replacementRange { #ifdef IM_DEBUG fprintf(stderr, "AWTView InputMethod Selector Called : [insertText]: %s\n", [aString UTF8String]); --- 951,967 ---- /******************************** END NSDraggingDestination Interface ********************************/ /******************************** BEGIN NSTextInputClient Protocol ********************************/ ! static jclass jc_CInputMethod = NULL; ! ! #define GET_CIM_CLASS() \ ! GET_CLASS(jc_CInputMethod, "sun/lwawt/macosx/CInputMethod"); ! ! #define GET_CIM_CLASS_RETURN(ret) \ ! GET_CLASS_RETURN(jc_CInputMethod, "sun/lwawt/macosx/CInputMethod", ret); - (void) insertText:(id)aString replacementRange:(NSRange)replacementRange { #ifdef IM_DEBUG fprintf(stderr, "AWTView InputMethod Selector Called : [insertText]: %s\n", [aString UTF8String]);
*** 989,1008 **** } if ([self hasMarkedText] || !fProcessingKeystroke || aStringIsComplex) { JNIEnv *env = [ThreadUtilities getJNIEnv]; ! static JNF_MEMBER_CACHE(jm_selectPreviousGlyph, jc_CInputMethod, "selectPreviousGlyph", "()V"); // We need to select the previous glyph so that it is overwritten. if (fPAHNeedsToSelect) { ! JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_selectPreviousGlyph); fPAHNeedsToSelect = NO; } ! static JNF_MEMBER_CACHE(jm_insertText, jc_CInputMethod, "insertText", "(Ljava/lang/String;)V"); ! jstring insertedText = JNFNSToJavaString(env, useString); ! JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_insertText, insertedText); // AWT_THREADING Safe (AWTRunLoopMode) (*env)->DeleteLocalRef(env, insertedText); // The input method event will create psuedo-key events for each character in the committed string. // We also don't want to send the character that triggered the insertText, usually a return. [3337563] fKeyEventsNeeded = NO; --- 998,1020 ---- } if ([self hasMarkedText] || !fProcessingKeystroke || aStringIsComplex) { JNIEnv *env = [ThreadUtilities getJNIEnv]; ! GET_CIM_CLASS(); ! DECLARE_METHOD(jm_selectPreviousGlyph, jc_CInputMethod, "selectPreviousGlyph", "()V"); // We need to select the previous glyph so that it is overwritten. if (fPAHNeedsToSelect) { ! (*env)->CallVoidMethod(env, fInputMethodLOCKABLE, jm_selectPreviousGlyph); ! CHECK_EXCEPTION(); fPAHNeedsToSelect = NO; } ! DECLARE_METHOD(jm_insertText, jc_CInputMethod, "insertText", "(Ljava/lang/String;)V"); ! jstring insertedText = NSStringToJavaString(env, useString); ! (*env)->CallVoidMethod(env, fInputMethodLOCKABLE, jm_insertText, insertedText); ! CHECK_EXCEPTION(); (*env)->DeleteLocalRef(env, insertedText); // The input method event will create psuedo-key events for each character in the committed string. // We also don't want to send the character that triggered the insertText, usually a return. [3337563] fKeyEventsNeeded = NO;
*** 1053,1072 **** NSAttributedString *attrString = (isAttributedString ? (NSAttributedString *)aString : nil); NSString *incomingString = (isAttributedString ? [aString string] : aString); #ifdef IM_DEBUG fprintf(stderr, "AWTView InputMethod Selector Called : [setMarkedText] \"%s\", loc=%lu, length=%lu\n", [incomingString UTF8String], (unsigned long)selectionRange.location, (unsigned long)selectionRange.length); #endif // IM_DEBUG - static JNF_MEMBER_CACHE(jm_startIMUpdate, jc_CInputMethod, "startIMUpdate", "(Ljava/lang/String;)V"); - static JNF_MEMBER_CACHE(jm_addAttribute, jc_CInputMethod, "addAttribute", "(ZZII)V"); - static JNF_MEMBER_CACHE(jm_dispatchText, jc_CInputMethod, "dispatchText", "(IIZ)V"); JNIEnv *env = [ThreadUtilities getJNIEnv]; // NSInputContext already did the analysis of the TSM event and created attributes indicating // the underlining and color that should be done to the string. We need to look at the underline // style and color to determine what kind of Java hilighting needs to be done. ! jstring inProcessText = JNFNSToJavaString(env, incomingString); ! JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_startIMUpdate, inProcessText); // AWT_THREADING Safe (AWTRunLoopMode) (*env)->DeleteLocalRef(env, inProcessText); if (isAttributedString) { NSUInteger length; NSRange effectiveRange; --- 1065,1086 ---- NSAttributedString *attrString = (isAttributedString ? (NSAttributedString *)aString : nil); NSString *incomingString = (isAttributedString ? [aString string] : aString); #ifdef IM_DEBUG fprintf(stderr, "AWTView InputMethod Selector Called : [setMarkedText] \"%s\", loc=%lu, length=%lu\n", [incomingString UTF8String], (unsigned long)selectionRange.location, (unsigned long)selectionRange.length); #endif // IM_DEBUG JNIEnv *env = [ThreadUtilities getJNIEnv]; + GET_CIM_CLASS(); + DECLARE_METHOD(jm_startIMUpdate, jc_CInputMethod, "startIMUpdate", "(Ljava/lang/String;)V"); + DECLARE_METHOD(jm_addAttribute, jc_CInputMethod, "addAttribute", "(ZZII)V"); + DECLARE_METHOD(jm_dispatchText, jc_CInputMethod, "dispatchText", "(IIZ)V"); // NSInputContext already did the analysis of the TSM event and created attributes indicating // the underlining and color that should be done to the string. We need to look at the underline // style and color to determine what kind of Java hilighting needs to be done. ! jstring inProcessText = NSStringToJavaString(env, incomingString); ! (*env)->CallVoidMethod(env, fInputMethodLOCKABLE, jm_startIMUpdate, inProcessText); ! CHECK_EXCEPTION(); (*env)->DeleteLocalRef(env, inProcessText); if (isAttributedString) { NSUInteger length; NSRange effectiveRange;
*** 1085,1108 **** NSColor *underlineColorObj = (NSColor *)[attributes objectForKey:NSUnderlineColorAttributeName]; isGray = !([underlineColorObj isEqual:[NSColor blackColor]]); ! JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_addAttribute, isThickUnderline, isGray, effectiveRange.location, effectiveRange.length); // AWT_THREADING Safe (AWTRunLoopMode) } } } ! static JNF_MEMBER_CACHE(jm_selectPreviousGlyph, jc_CInputMethod, "selectPreviousGlyph", "()V"); // We need to select the previous glyph so that it is overwritten. if (fPAHNeedsToSelect) { ! JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_selectPreviousGlyph); fPAHNeedsToSelect = NO; } ! JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_dispatchText, selectionRange.location, selectionRange.length, JNI_FALSE); // AWT_THREADING Safe (AWTRunLoopMode) ! // If the marked text is being cleared (zero-length string) don't handle the key event. if ([incomingString length] == 0) { fKeyEventsNeeded = NO; } } --- 1099,1126 ---- NSColor *underlineColorObj = (NSColor *)[attributes objectForKey:NSUnderlineColorAttributeName]; isGray = !([underlineColorObj isEqual:[NSColor blackColor]]); ! (*env)->CallVoidMethod(env, fInputMethodLOCKABLE, jm_addAttribute, isThickUnderline, ! isGray, effectiveRange.location, effectiveRange.length); ! CHECK_EXCEPTION(); } } } ! DECLARE_METHOD(jm_selectPreviousGlyph, jc_CInputMethod, "selectPreviousGlyph", "()V"); // We need to select the previous glyph so that it is overwritten. if (fPAHNeedsToSelect) { ! (*env)->CallVoidMethod(env, fInputMethodLOCKABLE, jm_selectPreviousGlyph); ! CHECK_EXCEPTION(); fPAHNeedsToSelect = NO; } ! (*env)->CallVoidMethod(env, fInputMethodLOCKABLE, jm_dispatchText, ! selectionRange.location, selectionRange.length, JNI_FALSE); ! CHECK_EXCEPTION(); // If the marked text is being cleared (zero-length string) don't handle the key event. if ([incomingString length] == 0) { fKeyEventsNeeded = NO; } }
*** 1116,1129 **** if (!fInputMethodLOCKABLE) { return; } // unmarkText cancels any input in progress and commits it to the text field. - static JNF_MEMBER_CACHE(jm_unmarkText, jc_CInputMethod, "unmarkText", "()V"); JNIEnv *env = [ThreadUtilities getJNIEnv]; ! JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_unmarkText); // AWT_THREADING Safe (AWTRunLoopMode) ! } - (BOOL) hasMarkedText { #ifdef IM_DEBUG --- 1134,1148 ---- if (!fInputMethodLOCKABLE) { return; } // unmarkText cancels any input in progress and commits it to the text field. JNIEnv *env = [ThreadUtilities getJNIEnv]; ! GET_CIM_CLASS(); ! DECLARE_METHOD(jm_unmarkText, jc_CInputMethod, "unmarkText", "()V"); ! (*env)->CallVoidMethod(env, fInputMethodLOCKABLE, jm_unmarkText); ! CHECK_EXCEPTION(); } - (BOOL) hasMarkedText { #ifdef IM_DEBUG
*** 1132,1147 **** if (!fInputMethodLOCKABLE) { return NO; } - static JNF_MEMBER_CACHE(jf_fCurrentText, jc_CInputMethod, "fCurrentText", "Ljava/text/AttributedString;"); - static JNF_MEMBER_CACHE(jf_fCurrentTextLength, jc_CInputMethod, "fCurrentTextLength", "I"); JNIEnv *env = [ThreadUtilities getJNIEnv]; ! jobject currentText = JNFGetObjectField(env, fInputMethodLOCKABLE, jf_fCurrentText); ! jint currentTextLength = JNFGetIntField(env, fInputMethodLOCKABLE, jf_fCurrentTextLength); BOOL hasMarkedText = (currentText != NULL && currentTextLength > 0); if (currentText != NULL) { (*env)->DeleteLocalRef(env, currentText); --- 1151,1169 ---- if (!fInputMethodLOCKABLE) { return NO; } JNIEnv *env = [ThreadUtilities getJNIEnv]; ! GET_CIM_CLASS_RETURN(NO); ! DECLARE_FIELD_RETURN(jf_fCurrentText, jc_CInputMethod, "fCurrentText", "Ljava/text/AttributedString;", NO); ! DECLARE_FIELD_RETURN(jf_fCurrentTextLength, jc_CInputMethod, "fCurrentTextLength", "I", NO); ! jobject currentText = (*env)->GetObjectField(env, fInputMethodLOCKABLE, jf_fCurrentText); ! CHECK_EXCEPTION(); ! jint currentTextLength = (*env)->GetIntField(env, fInputMethodLOCKABLE, jf_fCurrentTextLength); ! CHECK_EXCEPTION(); BOOL hasMarkedText = (currentText != NULL && currentTextLength > 0); if (currentText != NULL) { (*env)->DeleteLocalRef(env, currentText);
*** 1166,1180 **** { #ifdef IM_DEBUG fprintf(stderr, "AWTView InputMethod Selector Called : [attributedSubstringFromRange] location=%lu, length=%lu\n", (unsigned long)theRange.location, (unsigned long)theRange.length); #endif // IM_DEBUG - static JNF_MEMBER_CACHE(jm_substringFromRange, jc_CInputMethod, "attributedSubstringFromRange", "(II)Ljava/lang/String;"); JNIEnv *env = [ThreadUtilities getJNIEnv]; ! jobject theString = JNFCallObjectMethod(env, fInputMethodLOCKABLE, jm_substringFromRange, theRange.location, theRange.length); // AWT_THREADING Safe (AWTRunLoopMode) ! id result = [[[NSAttributedString alloc] initWithString:JNFJavaToNSString(env, theString)] autorelease]; #ifdef IM_DEBUG NSLog(@"attributedSubstringFromRange returning \"%@\"", result); #endif // IM_DEBUG (*env)->DeleteLocalRef(env, theString); --- 1188,1203 ---- { #ifdef IM_DEBUG fprintf(stderr, "AWTView InputMethod Selector Called : [attributedSubstringFromRange] location=%lu, length=%lu\n", (unsigned long)theRange.location, (unsigned long)theRange.length); #endif // IM_DEBUG JNIEnv *env = [ThreadUtilities getJNIEnv]; ! DECLARE_METHOD_RETURN(jm_substringFromRange, jc_CInputMethod, "attributedSubstringFromRange", "(II)Ljava/lang/String;", nil); ! jobject theString = (*env)->CallObjectMethod(env, fInputMethodLOCKABLE, jm_substringFromRange, theRange.location, theRange.length); ! CHECK_EXCEPTION_NULL_RETURN(theString, nil); ! id result = [[[NSAttributedString alloc] initWithString:JavaStringToNSString(env, theString)] autorelease]; #ifdef IM_DEBUG NSLog(@"attributedSubstringFromRange returning \"%@\"", result); #endif // IM_DEBUG (*env)->DeleteLocalRef(env, theString);
*** 1193,1210 **** if (!fInputMethodLOCKABLE) { return NSMakeRange(NSNotFound, 0); } - static JNF_MEMBER_CACHE(jm_markedRange, jc_CInputMethod, "markedRange", "()[I"); JNIEnv *env = [ThreadUtilities getJNIEnv]; jarray array; jboolean isCopy; jint *_array; NSRange range = NSMakeRange(NSNotFound, 0); ! array = JNFCallObjectMethod(env, fInputMethodLOCKABLE, jm_markedRange); // AWT_THREADING Safe (AWTRunLoopMode) if (array) { _array = (*env)->GetIntArrayElements(env, array, &isCopy); if (_array != NULL) { range.location = _array[0]; --- 1216,1235 ---- if (!fInputMethodLOCKABLE) { return NSMakeRange(NSNotFound, 0); } JNIEnv *env = [ThreadUtilities getJNIEnv]; jarray array; jboolean isCopy; jint *_array; NSRange range = NSMakeRange(NSNotFound, 0); + GET_CIM_CLASS_RETURN(range); + DECLARE_METHOD_RETURN(jm_markedRange, jc_CInputMethod, "markedRange", "()[I", range); ! array = (*env)->CallObjectMethod(env, fInputMethodLOCKABLE, jm_markedRange); ! CHECK_EXCEPTION(); if (array) { _array = (*env)->GetIntArrayElements(env, array, &isCopy); if (_array != NULL) { range.location = _array[0];
*** 1228,1249 **** { if (!fInputMethodLOCKABLE) { return NSMakeRange(NSNotFound, 0); } - static JNF_MEMBER_CACHE(jm_selectedRange, jc_CInputMethod, "selectedRange", "()[I"); JNIEnv *env = [ThreadUtilities getJNIEnv]; jarray array; jboolean isCopy; jint *_array; NSRange range = NSMakeRange(NSNotFound, 0); #ifdef IM_DEBUG fprintf(stderr, "AWTView InputMethod Selector Called : [selectedRange]\n"); #endif // IM_DEBUG ! array = JNFCallObjectMethod(env, fInputMethodLOCKABLE, jm_selectedRange); // AWT_THREADING Safe (AWTRunLoopMode) if (array) { _array = (*env)->GetIntArrayElements(env, array, &isCopy); if (_array != NULL) { range.location = _array[0]; range.length = _array[1]; --- 1253,1276 ---- { if (!fInputMethodLOCKABLE) { return NSMakeRange(NSNotFound, 0); } JNIEnv *env = [ThreadUtilities getJNIEnv]; jarray array; jboolean isCopy; jint *_array; NSRange range = NSMakeRange(NSNotFound, 0); + GET_CIM_CLASS_RETURN(range); + DECLARE_METHOD_RETURN(jm_selectedRange, jc_CInputMethod, "selectedRange", "()[I", range); #ifdef IM_DEBUG fprintf(stderr, "AWTView InputMethod Selector Called : [selectedRange]\n"); #endif // IM_DEBUG ! array = (*env)->CallObjectMethod(env, fInputMethodLOCKABLE, jm_selectedRange); ! CHECK_EXCEPTION(); if (array) { _array = (*env)->GetIntArrayElements(env, array, &isCopy); if (_array != NULL) { range.location = _array[0]; range.length = _array[1];
*** 1261,1273 **** { if (!fInputMethodLOCKABLE) { return NSZeroRect; } - static JNF_MEMBER_CACHE(jm_firstRectForCharacterRange, jc_CInputMethod, - "firstRectForCharacterRange", "(I)[I"); JNIEnv *env = [ThreadUtilities getJNIEnv]; jarray array; jboolean isCopy; jint *_array; NSRect rect; --- 1288,1301 ---- { if (!fInputMethodLOCKABLE) { return NSZeroRect; } JNIEnv *env = [ThreadUtilities getJNIEnv]; + GET_CIM_CLASS_RETURN(NSZeroRect); + DECLARE_METHOD_RETURN(jm_firstRectForCharacterRange, jc_CInputMethod, + "firstRectForCharacterRange", "(I)[I", NSZeroRect); jarray array; jboolean isCopy; jint *_array; NSRect rect;
*** 1275,1286 **** fprintf(stderr, "AWTView InputMethod Selector Called : [firstRectForCharacterRange:] location=%lu, length=%lu\n", (unsigned long)theRange.location, (unsigned long)theRange.length); #endif // IM_DEBUG ! array = JNFCallObjectMethod(env, fInputMethodLOCKABLE, jm_firstRectForCharacterRange, ! theRange.location); // AWT_THREADING Safe (AWTRunLoopMode) _array = (*env)->GetIntArrayElements(env, array, &isCopy); if (_array) { rect = ConvertNSScreenRect(env, NSMakeRect(_array[0], _array[1], _array[2], _array[3])); (*env)->ReleaseIntArrayElements(env, array, _array, 0); --- 1303,1315 ---- fprintf(stderr, "AWTView InputMethod Selector Called : [firstRectForCharacterRange:] location=%lu, length=%lu\n", (unsigned long)theRange.location, (unsigned long)theRange.length); #endif // IM_DEBUG ! array = (*env)->CallObjectMethod(env, fInputMethodLOCKABLE, jm_firstRectForCharacterRange, ! theRange.location); ! CHECK_EXCEPTION(); _array = (*env)->GetIntArrayElements(env, array, &isCopy); if (_array) { rect = ConvertNSScreenRect(env, NSMakeRect(_array[0], _array[1], _array[2], _array[3])); (*env)->ReleaseIntArrayElements(env, array, _array, 0);
*** 1304,1324 **** { if (!fInputMethodLOCKABLE) { return NSNotFound; } - static JNF_MEMBER_CACHE(jm_characterIndexForPoint, jc_CInputMethod, - "characterIndexForPoint", "(II)I"); JNIEnv *env = [ThreadUtilities getJNIEnv]; NSPoint flippedLocation = ConvertNSScreenPoint(env, thePoint); #ifdef IM_DEBUG fprintf(stderr, "AWTView InputMethod Selector Called : [characterIndexForPoint:(NSPoint)thePoint] x=%f, y=%f\n", flippedLocation.x, flippedLocation.y); #endif // IM_DEBUG ! jint index = JNFCallIntMethod(env, fInputMethodLOCKABLE, jm_characterIndexForPoint, (jint)flippedLocation.x, (jint)flippedLocation.y); // AWT_THREADING Safe (AWTRunLoopMode) #ifdef IM_DEBUG fprintf(stderr, "characterIndexForPoint returning %d\n", index); #endif // IM_DEBUG --- 1333,1356 ---- { if (!fInputMethodLOCKABLE) { return NSNotFound; } JNIEnv *env = [ThreadUtilities getJNIEnv]; + GET_CIM_CLASS_RETURN(NSNotFound); + DECLARE_METHOD_RETURN(jm_characterIndexForPoint, jc_CInputMethod, + "characterIndexForPoint", "(II)I", NSNotFound); NSPoint flippedLocation = ConvertNSScreenPoint(env, thePoint); #ifdef IM_DEBUG fprintf(stderr, "AWTView InputMethod Selector Called : [characterIndexForPoint:(NSPoint)thePoint] x=%f, y=%f\n", flippedLocation.x, flippedLocation.y); #endif // IM_DEBUG ! jint index = (*env)->CallIntMethod(env, fInputMethodLOCKABLE, jm_characterIndexForPoint, ! (jint)flippedLocation.x, (jint)flippedLocation.y); ! CHECK_EXCEPTION(); #ifdef IM_DEBUG fprintf(stderr, "characterIndexForPoint returning %d\n", index); #endif // IM_DEBUG
*** 1346,1363 **** JNIEnv *env = [ThreadUtilities getJNIEnv]; // Get rid of the old one if (fInputMethodLOCKABLE) { ! JNFDeleteGlobalRef(env, fInputMethodLOCKABLE); } ! // Save a global ref to the new input method. ! if (inputMethod != NULL) ! fInputMethodLOCKABLE = JNFNewGlobalRef(env, inputMethod); ! else ! fInputMethodLOCKABLE = NULL; NSTextInputContext *curContxt = [NSTextInputContext currentInputContext]; kbdLayout = curContxt.selectedKeyboardInputSource; [[NSNotificationCenter defaultCenter] addObserver:[AWTView class] selector:@selector(keyboardInputSourceChanged:) --- 1378,1391 ---- JNIEnv *env = [ThreadUtilities getJNIEnv]; // Get rid of the old one if (fInputMethodLOCKABLE) { ! (*env)->DeleteGlobalRef(env, fInputMethodLOCKABLE); } ! fInputMethodLOCKABLE = inputMethod; // input method arg must be a GlobalRef NSTextInputContext *curContxt = [NSTextInputContext currentInputContext]; kbdLayout = curContxt.selectedKeyboardInputSource; [[NSNotificationCenter defaultCenter] addObserver:[AWTView class] selector:@selector(keyboardInputSourceChanged:)
*** 1391,1414 **** Java_sun_lwawt_macosx_CPlatformView_nativeCreateView (JNIEnv *env, jobject obj, jint originX, jint originY, jint width, jint height, jlong windowLayerPtr) { __block AWTView *newView = nil; ! JNF_COCOA_ENTER(env); NSRect rect = NSMakeRect(originX, originY, width, height); jobject cPlatformView = (*env)->NewWeakGlobalRef(env, obj); [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ CALayer *windowLayer = jlong_to_ptr(windowLayerPtr); newView = [[AWTView alloc] initWithRect:rect platformView:cPlatformView windowLayer:windowLayer]; }]; ! JNF_COCOA_EXIT(env); return ptr_to_jlong(newView); } /* --- 1419,1443 ---- Java_sun_lwawt_macosx_CPlatformView_nativeCreateView (JNIEnv *env, jobject obj, jint originX, jint originY, jint width, jint height, jlong windowLayerPtr) { __block AWTView *newView = nil; ! JNI_COCOA_ENTER(env); NSRect rect = NSMakeRect(originX, originY, width, height); jobject cPlatformView = (*env)->NewWeakGlobalRef(env, obj); + CHECK_EXCEPTION(); [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ CALayer *windowLayer = jlong_to_ptr(windowLayerPtr); newView = [[AWTView alloc] initWithRect:rect platformView:cPlatformView windowLayer:windowLayer]; }]; ! JNI_COCOA_EXIT(env); return ptr_to_jlong(newView); } /*
*** 1419,1429 **** JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformView_nativeSetAutoResizable (JNIEnv *env, jclass cls, jlong viewPtr, jboolean toResize) { ! JNF_COCOA_ENTER(env); NSView *view = (NSView *)jlong_to_ptr(viewPtr); [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ --- 1448,1458 ---- JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformView_nativeSetAutoResizable (JNIEnv *env, jclass cls, jlong viewPtr, jboolean toResize) { ! JNI_COCOA_ENTER(env); NSView *view = (NSView *)jlong_to_ptr(viewPtr); [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
*** 1436,1446 **** if ([view superview] != nil) { [[view superview] setAutoresizesSubviews:(BOOL)toResize]; } }]; ! JNF_COCOA_EXIT(env); } /* * Class: sun_lwawt_macosx_CPlatformView * Method: nativeGetNSViewDisplayID --- 1465,1475 ---- if ([view superview] != nil) { [[view superview] setAutoresizesSubviews:(BOOL)toResize]; } }]; ! JNI_COCOA_EXIT(env); } /* * Class: sun_lwawt_macosx_CPlatformView * Method: nativeGetNSViewDisplayID
*** 1451,1469 **** Java_sun_lwawt_macosx_CPlatformView_nativeGetNSViewDisplayID (JNIEnv *env, jclass cls, jlong viewPtr) { __block jint ret; //CGDirectDisplayID ! JNF_COCOA_ENTER(env); NSView *view = (NSView *)jlong_to_ptr(viewPtr); [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ NSWindow *window = [view window]; ret = (jint)[[AWTWindow getNSWindowDisplayID_AppKitThread: window] intValue]; }]; ! JNF_COCOA_EXIT(env); return ret; } /* --- 1480,1498 ---- Java_sun_lwawt_macosx_CPlatformView_nativeGetNSViewDisplayID (JNIEnv *env, jclass cls, jlong viewPtr) { __block jint ret; //CGDirectDisplayID ! JNI_COCOA_ENTER(env); NSView *view = (NSView *)jlong_to_ptr(viewPtr); [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ NSWindow *window = [view window]; ret = (jint)[[AWTWindow getNSWindowDisplayID_AppKitThread: window] intValue]; }]; ! JNI_COCOA_EXIT(env); return ret; } /*
*** 1476,1486 **** Java_sun_lwawt_macosx_CPlatformView_nativeGetLocationOnScreen (JNIEnv *env, jclass cls, jlong viewPtr) { jobject jRect = NULL; ! JNF_COCOA_ENTER(env); __block NSRect rect = NSZeroRect; NSView *view = (NSView *)jlong_to_ptr(viewPtr); [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ --- 1505,1515 ---- Java_sun_lwawt_macosx_CPlatformView_nativeGetLocationOnScreen (JNIEnv *env, jclass cls, jlong viewPtr) { jobject jRect = NULL; ! JNI_COCOA_ENTER(env); __block NSRect rect = NSZeroRect; NSView *view = (NSView *)jlong_to_ptr(viewPtr); [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
*** 1492,1502 **** rect = ConvertNSScreenRect(NULL, rect); }]; jRect = NSToJavaRect(env, rect); ! JNF_COCOA_EXIT(env); return jRect; } /* --- 1521,1531 ---- rect = ConvertNSScreenRect(NULL, rect); }]; jRect = NSToJavaRect(env, rect); ! JNI_COCOA_EXIT(env); return jRect; } /*
*** 1508,1525 **** JNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_CPlatformView_nativeIsViewUnderMouse (JNIEnv *env, jclass clazz, jlong viewPtr) { __block jboolean underMouse = JNI_FALSE; ! JNF_COCOA_ENTER(env); NSView *nsView = OBJC(viewPtr); [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ NSPoint ptWindowCoords = [[nsView window] mouseLocationOutsideOfEventStream]; NSPoint ptViewCoords = [nsView convertPoint:ptWindowCoords fromView:nil]; underMouse = [nsView hitTest:ptViewCoords] != nil; }]; ! JNF_COCOA_EXIT(env); return underMouse; } --- 1537,1554 ---- JNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_CPlatformView_nativeIsViewUnderMouse (JNIEnv *env, jclass clazz, jlong viewPtr) { __block jboolean underMouse = JNI_FALSE; ! JNI_COCOA_ENTER(env); NSView *nsView = OBJC(viewPtr); [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ NSPoint ptWindowCoords = [[nsView window] mouseLocationOutsideOfEventStream]; NSPoint ptViewCoords = [nsView convertPoint:ptWindowCoords fromView:nil]; underMouse = [nsView hitTest:ptViewCoords] != nil; }]; ! JNI_COCOA_EXIT(env); return underMouse; }
< prev index next >