25
26 #import "jni_util.h"
27 #import "CGLGraphicsConfig.h"
28 #import "AWTView.h"
29 #import "AWTWindow.h"
30 #import "JavaComponentAccessibility.h"
31 #import "JavaTextAccessibility.h"
32 #import "GeomUtilities.h"
33 #import "OSVersion.h"
34 #import "ThreadUtilities.h"
35
36 #import <JavaNativeFoundation/JavaNativeFoundation.h>
37
38 @interface AWTView()
39 @property (retain) CDropTarget *_dropTarget;
40 @property (retain) CDragSource *_dragSource;
41
42 -(void) deliverResize: (NSRect) rect;
43 -(void) resetTrackingArea;
44 -(void) deliverJavaKeyEventHelper: (NSEvent*) event;
45 @end
46
47 // Uncomment this line to see fprintfs of each InputMethod API being called on this View
48 //#define IM_DEBUG TRUE
49 //#define EXTRA_DEBUG
50
51 static BOOL shouldUsePressAndHold() {
52 static int shouldUsePressAndHold = -1;
53 if (shouldUsePressAndHold != -1) return shouldUsePressAndHold;
54 shouldUsePressAndHold = !isSnowLeopardOrLower();
55 return shouldUsePressAndHold;
56 }
57
58 @implementation AWTView
59
60 @synthesize _dropTarget;
61 @synthesize _dragSource;
62 @synthesize cglLayer;
63 @synthesize mouseIsOver;
64
492 JNU_CallMethodByName(env, NULL, [m_awtWindow cPlatformView],
493 "deliverWindowDidExposeEvent", "(FFFF)V",
494 (jfloat)rs[i].origin.x, (jfloat)rs[i].origin.y,
495 (jfloat)rs[i].size.width, (jfloat)rs[i].size.height);
496 if ((*env)->ExceptionOccurred(env)) {
497 (*env)->ExceptionDescribe(env);
498 (*env)->ExceptionClear(env);
499 }
500 }
501 } else {
502 */
503 static JNF_CLASS_CACHE(jc_CPlatformView, "sun/lwawt/macosx/CPlatformView");
504 static JNF_MEMBER_CACHE(jm_deliverWindowDidExposeEvent, jc_CPlatformView, "deliverWindowDidExposeEvent", "()V");
505 JNFCallVoidMethod(env, m_cPlatformView, jm_deliverWindowDidExposeEvent);
506 /*
507 }
508 */
509 }
510 }
511
512 // NSAccessibility support
513 - (jobject)awtComponent:(JNIEnv*)env
514 {
515 static JNF_CLASS_CACHE(jc_CPlatformView, "sun/lwawt/macosx/CPlatformView");
516 static JNF_MEMBER_CACHE(jf_Peer, jc_CPlatformView, "peer", "Lsun/lwawt/LWWindowPeer;");
517 if ((env == NULL) || (m_cPlatformView == NULL)) {
518 NSLog(@"Apple AWT : Error AWTView:awtComponent given bad parameters.");
519 if (env != NULL)
520 {
521 JNFDumpJavaStack(env);
522 }
523 return NULL;
524 }
525 jobject peer = JNFGetObjectField(env, m_cPlatformView, jf_Peer);
526 static JNF_CLASS_CACHE(jc_LWWindowPeer, "sun/lwawt/LWWindowPeer");
527 static JNF_MEMBER_CACHE(jf_Target, jc_LWWindowPeer, "target", "Ljava/awt/Component;");
528 if (peer == NULL) {
529 NSLog(@"Apple AWT : Error AWTView:awtComponent got null peer from CPlatformView");
530 JNFDumpJavaStack(env);
531 return NULL;
872
873 - (void) insertText:(id)aString replacementRange:(NSRange)replacementRange
874 {
875 #ifdef IM_DEBUG
876 fprintf(stderr, "AWTView InputMethod Selector Called : [insertText]: %s\n", [aString UTF8String]);
877 #endif // IM_DEBUG
878
879 if (fInputMethodLOCKABLE == NULL) {
880 return;
881 }
882
883 // Insert happens at the end of PAH
884 fInPressAndHold = NO;
885
886 // insertText gets called when the user commits text generated from an input method. It also gets
887 // called during ordinary input as well. We only need to send an input method event when we have marked
888 // text, or 'text in progress'. We also need to send the event if we get an insert text out of the blue!
889 // (i.e., when the user uses the Character palette or Inkwell), or when the string to insert is a complex
890 // Unicode value.
891 NSUInteger utf16Length = [aString lengthOfBytesUsingEncoding:NSUTF16StringEncoding];
892
893 if ([self hasMarkedText] || !fProcessingKeystroke || (utf16Length > 2)) {
894 JNIEnv *env = [ThreadUtilities getJNIEnv];
895
896 static JNF_MEMBER_CACHE(jm_selectPreviousGlyph, jc_CInputMethod, "selectPreviousGlyph", "()V");
897 // We need to select the previous glyph so that it is overwritten.
898 if (fPAHNeedsToSelect) {
899 JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_selectPreviousGlyph);
900 fPAHNeedsToSelect = NO;
901 }
902
903 static JNF_MEMBER_CACHE(jm_insertText, jc_CInputMethod, "insertText", "(Ljava/lang/String;)V");
904 jstring insertedText = JNFNSToJavaString(env, aString);
905 JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_insertText, insertedText); // AWT_THREADING Safe (AWTRunLoopMode)
906 (*env)->DeleteLocalRef(env, insertedText);
907
908 // The input method event will create psuedo-key events for each character in the committed string.
909 // We also don't want to send the character that triggered the insertText, usually a return. [3337563]
910 fKeyEventsNeeded = NO;
911 }
912
913 fPAHNeedsToSelect = NO;
|
25
26 #import "jni_util.h"
27 #import "CGLGraphicsConfig.h"
28 #import "AWTView.h"
29 #import "AWTWindow.h"
30 #import "JavaComponentAccessibility.h"
31 #import "JavaTextAccessibility.h"
32 #import "GeomUtilities.h"
33 #import "OSVersion.h"
34 #import "ThreadUtilities.h"
35
36 #import <JavaNativeFoundation/JavaNativeFoundation.h>
37
38 @interface AWTView()
39 @property (retain) CDropTarget *_dropTarget;
40 @property (retain) CDragSource *_dragSource;
41
42 -(void) deliverResize: (NSRect) rect;
43 -(void) resetTrackingArea;
44 -(void) deliverJavaKeyEventHelper: (NSEvent*) event;
45 -(BOOL) isCodePointInUnicodeBlockNeedingIMEvent: (unichar) codePoint;
46 @end
47
48 // Uncomment this line to see fprintfs of each InputMethod API being called on this View
49 //#define IM_DEBUG TRUE
50 //#define EXTRA_DEBUG
51
52 static BOOL shouldUsePressAndHold() {
53 static int shouldUsePressAndHold = -1;
54 if (shouldUsePressAndHold != -1) return shouldUsePressAndHold;
55 shouldUsePressAndHold = !isSnowLeopardOrLower();
56 return shouldUsePressAndHold;
57 }
58
59 @implementation AWTView
60
61 @synthesize _dropTarget;
62 @synthesize _dragSource;
63 @synthesize cglLayer;
64 @synthesize mouseIsOver;
65
493 JNU_CallMethodByName(env, NULL, [m_awtWindow cPlatformView],
494 "deliverWindowDidExposeEvent", "(FFFF)V",
495 (jfloat)rs[i].origin.x, (jfloat)rs[i].origin.y,
496 (jfloat)rs[i].size.width, (jfloat)rs[i].size.height);
497 if ((*env)->ExceptionOccurred(env)) {
498 (*env)->ExceptionDescribe(env);
499 (*env)->ExceptionClear(env);
500 }
501 }
502 } else {
503 */
504 static JNF_CLASS_CACHE(jc_CPlatformView, "sun/lwawt/macosx/CPlatformView");
505 static JNF_MEMBER_CACHE(jm_deliverWindowDidExposeEvent, jc_CPlatformView, "deliverWindowDidExposeEvent", "()V");
506 JNFCallVoidMethod(env, m_cPlatformView, jm_deliverWindowDidExposeEvent);
507 /*
508 }
509 */
510 }
511 }
512
513 -(BOOL) isCodePointInUnicodeBlockNeedingIMEvent: (unichar) codePoint {
514 if ((codePoint >= 0x3000) && (codePoint <= 0x303F)) {
515 // Code point is in 'CJK Symbols and Punctuation' Unicode block.
516 return YES;
517 }
518 return NO;
519 }
520
521 // NSAccessibility support
522 - (jobject)awtComponent:(JNIEnv*)env
523 {
524 static JNF_CLASS_CACHE(jc_CPlatformView, "sun/lwawt/macosx/CPlatformView");
525 static JNF_MEMBER_CACHE(jf_Peer, jc_CPlatformView, "peer", "Lsun/lwawt/LWWindowPeer;");
526 if ((env == NULL) || (m_cPlatformView == NULL)) {
527 NSLog(@"Apple AWT : Error AWTView:awtComponent given bad parameters.");
528 if (env != NULL)
529 {
530 JNFDumpJavaStack(env);
531 }
532 return NULL;
533 }
534 jobject peer = JNFGetObjectField(env, m_cPlatformView, jf_Peer);
535 static JNF_CLASS_CACHE(jc_LWWindowPeer, "sun/lwawt/LWWindowPeer");
536 static JNF_MEMBER_CACHE(jf_Target, jc_LWWindowPeer, "target", "Ljava/awt/Component;");
537 if (peer == NULL) {
538 NSLog(@"Apple AWT : Error AWTView:awtComponent got null peer from CPlatformView");
539 JNFDumpJavaStack(env);
540 return NULL;
881
882 - (void) insertText:(id)aString replacementRange:(NSRange)replacementRange
883 {
884 #ifdef IM_DEBUG
885 fprintf(stderr, "AWTView InputMethod Selector Called : [insertText]: %s\n", [aString UTF8String]);
886 #endif // IM_DEBUG
887
888 if (fInputMethodLOCKABLE == NULL) {
889 return;
890 }
891
892 // Insert happens at the end of PAH
893 fInPressAndHold = NO;
894
895 // insertText gets called when the user commits text generated from an input method. It also gets
896 // called during ordinary input as well. We only need to send an input method event when we have marked
897 // text, or 'text in progress'. We also need to send the event if we get an insert text out of the blue!
898 // (i.e., when the user uses the Character palette or Inkwell), or when the string to insert is a complex
899 // Unicode value.
900 NSUInteger utf16Length = [aString lengthOfBytesUsingEncoding:NSUTF16StringEncoding];
901 NSUInteger utf8Length = [aString lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
902 BOOL aStringIsComplex = NO;
903 if ((utf16Length > 2) ||
904 ((utf8Length > 1) && [self isCodePointInUnicodeBlockNeedingIMEvent:[aString characterAtIndex:0]])) {
905 aStringIsComplex = YES;
906 }
907
908 if ([self hasMarkedText] || !fProcessingKeystroke || aStringIsComplex) {
909 JNIEnv *env = [ThreadUtilities getJNIEnv];
910
911 static JNF_MEMBER_CACHE(jm_selectPreviousGlyph, jc_CInputMethod, "selectPreviousGlyph", "()V");
912 // We need to select the previous glyph so that it is overwritten.
913 if (fPAHNeedsToSelect) {
914 JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_selectPreviousGlyph);
915 fPAHNeedsToSelect = NO;
916 }
917
918 static JNF_MEMBER_CACHE(jm_insertText, jc_CInputMethod, "insertText", "(Ljava/lang/String;)V");
919 jstring insertedText = JNFNSToJavaString(env, aString);
920 JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_insertText, insertedText); // AWT_THREADING Safe (AWTRunLoopMode)
921 (*env)->DeleteLocalRef(env, insertedText);
922
923 // The input method event will create psuedo-key events for each character in the committed string.
924 // We also don't want to send the character that triggered the insertText, usually a return. [3337563]
925 fKeyEventsNeeded = NO;
926 }
927
928 fPAHNeedsToSelect = NO;
|