Path: blob/master/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m
66646 views
/*1* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#import "jni_util.h"26#import "CGLGraphicsConfig.h"27#import "AWTView.h"28#import "AWTWindow.h"29#import "a11y/CommonComponentAccessibility.h"30#import "JavaAccessibilityUtilities.h"31#import "GeomUtilities.h"32#import "ThreadUtilities.h"33#import "JNIUtilities.h"3435#import <Carbon/Carbon.h>3637// keyboard layout38static NSString *kbdLayout;3940@interface AWTView()41@property (retain) CDropTarget *_dropTarget;42@property (retain) CDragSource *_dragSource;4344-(void) deliverResize: (NSRect) rect;45-(void) resetTrackingArea;46-(void) deliverJavaKeyEventHelper: (NSEvent*) event;47-(BOOL) isCodePointInUnicodeBlockNeedingIMEvent: (unichar) codePoint;48-(NSMutableString *) parseString : (id) complexString;49@end5051// Uncomment this line to see fprintfs of each InputMethod API being called on this View52//#define IM_DEBUG TRUE53//#define EXTRA_DEBUG5455static BOOL shouldUsePressAndHold() {56return YES;57}5859@implementation AWTView6061@synthesize _dropTarget;62@synthesize _dragSource;63@synthesize cglLayer;64@synthesize mouseIsOver;6566// Note: Must be called on main (AppKit) thread only67- (id) initWithRect: (NSRect) rect68platformView: (jobject) cPlatformView69windowLayer: (CALayer*) windowLayer70{71AWT_ASSERT_APPKIT_THREAD;72// Initialize ourselves73self = [super initWithFrame: rect];74if (self == nil) return self;7576m_cPlatformView = cPlatformView;77fInputMethodLOCKABLE = NULL;78fKeyEventsNeeded = NO;79fProcessingKeystroke = NO;8081fEnablePressAndHold = shouldUsePressAndHold();82fInPressAndHold = NO;83fPAHNeedsToSelect = NO;8485mouseIsOver = NO;86[self resetTrackingArea];87[self setAutoresizesSubviews:NO];8889if (windowLayer != nil) {90self.cglLayer = windowLayer;91//Layer hosting view92[self setLayer: cglLayer];93[self setWantsLayer: YES];94//Layer backed view95//[self.layer addSublayer: (CALayer *)cglLayer];96//[self setLayerContentsRedrawPolicy: NSViewLayerContentsRedrawDuringViewResize];97//[self setLayerContentsPlacement: NSViewLayerContentsPlacementTopLeft];98//[self setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable];99}100101return self;102}103104- (void) dealloc {105AWT_ASSERT_APPKIT_THREAD;106107self.cglLayer = nil;108109JNIEnv *env = [ThreadUtilities getJNIEnvUncached];110(*env)->DeleteWeakGlobalRef(env, m_cPlatformView);111m_cPlatformView = NULL;112113if (fInputMethodLOCKABLE != NULL)114{115JNIEnv *env = [ThreadUtilities getJNIEnvUncached];116117(*env)->DeleteGlobalRef(env, fInputMethodLOCKABLE);118fInputMethodLOCKABLE = NULL;119}120121if (rolloverTrackingArea != nil) {122[self removeTrackingArea:rolloverTrackingArea];123[rolloverTrackingArea release];124rolloverTrackingArea = nil;125}126127[super dealloc];128}129130- (void) viewDidMoveToWindow {131AWT_ASSERT_APPKIT_THREAD;132133[AWTToolkit eventCountPlusPlus];134135[ThreadUtilities performOnMainThreadWaiting:NO block:^() {136[[self window] makeFirstResponder: self];137}];138if ([self window] != NULL) {139[self resetTrackingArea];140}141}142143- (BOOL) acceptsFirstMouse: (NSEvent *)event {144return YES;145}146147- (BOOL) acceptsFirstResponder {148return YES;149}150151- (BOOL) becomeFirstResponder {152return YES;153}154155- (BOOL) preservesContentDuringLiveResize {156return YES;157}158159/*160* Automatically triggered functions.161*/162163- (void)resizeWithOldSuperviewSize:(NSSize)oldBoundsSize {164[super resizeWithOldSuperviewSize: oldBoundsSize];165[self deliverResize: [self frame]];166}167168/*169* MouseEvents support170*/171172- (void) mouseDown: (NSEvent *)event {173NSInputManager *inputManager = [NSInputManager currentInputManager];174if ([inputManager wantsToHandleMouseEvents]) {175#if IM_DEBUG176NSLog(@"-> IM wants to handle event");177#endif178if (![inputManager handleMouseEvent:event]) {179[self deliverJavaMouseEvent: event];180} else {181#if IM_DEBUG182NSLog(@"-> Event was handled.");183#endif184}185} else {186#if IM_DEBUG187NSLog(@"-> IM does not want to handle event");188#endif189[self deliverJavaMouseEvent: event];190}191}192193- (void) mouseUp: (NSEvent *)event {194[self deliverJavaMouseEvent: event];195}196197- (void) rightMouseDown: (NSEvent *)event {198[self deliverJavaMouseEvent: event];199}200201- (void) rightMouseUp: (NSEvent *)event {202[self deliverJavaMouseEvent: event];203}204205- (void) otherMouseDown: (NSEvent *)event {206[self deliverJavaMouseEvent: event];207}208209- (void) otherMouseUp: (NSEvent *)event {210[self deliverJavaMouseEvent: event];211}212213- (void) mouseMoved: (NSEvent *)event {214// TODO: better way to redirect move events to the "under" view215216NSPoint eventLocation = [event locationInWindow];217NSPoint localPoint = [self convertPoint: eventLocation fromView: nil];218219if ([self mouse: localPoint inRect: [self bounds]]) {220[self deliverJavaMouseEvent: event];221} else {222[[self nextResponder] mouseDown:event];223}224}225226- (void) mouseDragged: (NSEvent *)event {227[self deliverJavaMouseEvent: event];228}229230- (void) rightMouseDragged: (NSEvent *)event {231[self deliverJavaMouseEvent: event];232}233234- (void) otherMouseDragged: (NSEvent *)event {235[self deliverJavaMouseEvent: event];236}237238- (void) mouseEntered: (NSEvent *)event {239[[self window] setAcceptsMouseMovedEvents:YES];240//[[self window] makeFirstResponder:self];241[self deliverJavaMouseEvent: event];242}243244- (void) mouseExited: (NSEvent *)event {245[[self window] setAcceptsMouseMovedEvents:NO];246[self deliverJavaMouseEvent: event];247//Restore the cursor back.248//[CCursorManager _setCursor: [NSCursor arrowCursor]];249}250251- (void) scrollWheel: (NSEvent*) event {252[self deliverJavaMouseEvent: event];253}254255/*256* KeyEvents support257*/258259- (void) keyDown: (NSEvent *)event {260fProcessingKeystroke = YES;261fKeyEventsNeeded = YES;262263// Allow TSM to look at the event and potentially send back NSTextInputClient messages.264[self interpretKeyEvents:[NSArray arrayWithObject:event]];265266if (fEnablePressAndHold && [event willBeHandledByComplexInputMethod] &&267fInputMethodLOCKABLE)268{269fProcessingKeystroke = NO;270if (!fInPressAndHold) {271fInPressAndHold = YES;272fPAHNeedsToSelect = YES;273} else {274// Abandon input to reset IM and unblock input after canceling275// input accented symbols276277switch([event keyCode]) {278case kVK_Escape:279case kVK_Delete:280case kVK_Return:281case kVK_ForwardDelete:282case kVK_PageUp:283case kVK_PageDown:284case kVK_DownArrow:285case kVK_UpArrow:286case kVK_Home:287case kVK_End:288[self abandonInput];289break;290}291}292return;293}294295NSString *eventCharacters = [event characters];296BOOL isDeadKey = (eventCharacters != nil && [eventCharacters length] == 0);297298if ((![self hasMarkedText] && fKeyEventsNeeded) || isDeadKey) {299[self deliverJavaKeyEventHelper: event];300}301302fProcessingKeystroke = NO;303}304305- (void) keyUp: (NSEvent *)event {306[self deliverJavaKeyEventHelper: event];307}308309- (void) flagsChanged: (NSEvent *)event {310[self deliverJavaKeyEventHelper: event];311}312313- (BOOL) performKeyEquivalent: (NSEvent *) event {314// if IM is active key events should be ignored315if (![self hasMarkedText] && !fInPressAndHold) {316[self deliverJavaKeyEventHelper: event];317}318319// Workaround for 8020209: special case for "Cmd =" and "Cmd ."320// because Cocoa calls performKeyEquivalent twice for these keystrokes321NSUInteger modFlags = [event modifierFlags] &322(NSCommandKeyMask | NSAlternateKeyMask | NSShiftKeyMask | NSControlKeyMask);323if (modFlags == NSCommandKeyMask) {324NSString *eventChars = [event charactersIgnoringModifiers];325if ([eventChars length] == 1) {326unichar ch = [eventChars characterAtIndex:0];327if (ch == '=' || ch == '.') {328[[NSApp mainMenu] performKeyEquivalent: event];329return YES;330}331}332333}334335return NO;336}337338/**339* Utility methods and accessors340*/341342-(void) deliverJavaMouseEvent: (NSEvent *) event {343BOOL isEnabled = YES;344NSWindow* window = [self window];345if ([window isKindOfClass: [AWTWindow_Panel class]] || [window isKindOfClass: [AWTWindow_Normal class]]) {346isEnabled = [(AWTWindow*)[window delegate] isEnabled];347}348349if (!isEnabled) {350return;351}352353NSEventType type = [event type];354355// check synthesized mouse entered/exited events356if ((type == NSMouseEntered && mouseIsOver) || (type == NSMouseExited && !mouseIsOver)) {357return;358}else if ((type == NSMouseEntered && !mouseIsOver) || (type == NSMouseExited && mouseIsOver)) {359mouseIsOver = !mouseIsOver;360}361362[AWTToolkit eventCountPlusPlus];363364JNIEnv *env = [ThreadUtilities getJNIEnv];365366NSPoint eventLocation = [event locationInWindow];367NSPoint localPoint = [self convertPoint: eventLocation fromView: nil];368NSPoint absP = [NSEvent mouseLocation];369370// Convert global numbers between Cocoa's coordinate system and Java.371// TODO: need consitent way for doing that both with global as well as with local coordinates.372// The reason to do it here is one more native method for getting screen dimension otherwise.373374NSRect screenRect = [[[NSScreen screens] objectAtIndex:0] frame];375absP.y = screenRect.size.height - absP.y;376jint clickCount;377378if (type == NSMouseEntered ||379type == NSMouseExited ||380type == NSScrollWheel ||381type == NSMouseMoved) {382clickCount = 0;383} else {384clickCount = [event clickCount];385}386387jdouble deltaX = [event deltaX];388jdouble deltaY = [event deltaY];389if ([AWTToolkit hasPreciseScrollingDeltas: event]) {390deltaX = [event scrollingDeltaX] * 0.1;391deltaY = [event scrollingDeltaY] * 0.1;392}393394DECLARE_CLASS(jc_NSEvent, "sun/lwawt/macosx/NSEvent");395DECLARE_METHOD(jctor_NSEvent, jc_NSEvent, "<init>", "(IIIIIIIIDDI)V");396jobject jEvent = (*env)->NewObject(env, jc_NSEvent, jctor_NSEvent,397[event type],398[event modifierFlags],399clickCount,400[event buttonNumber],401(jint)localPoint.x, (jint)localPoint.y,402(jint)absP.x, (jint)absP.y,403deltaY,404deltaX,405[AWTToolkit scrollStateWithEvent: event]);406CHECK_NULL(jEvent);407408DECLARE_CLASS(jc_PlatformView, "sun/lwawt/macosx/CPlatformView");409DECLARE_METHOD(jm_deliverMouseEvent, jc_PlatformView, "deliverMouseEvent", "(Lsun/lwawt/macosx/NSEvent;)V");410jobject jlocal = (*env)->NewLocalRef(env, m_cPlatformView);411if (!(*env)->IsSameObject(env, jlocal, NULL)) {412(*env)->CallVoidMethod(env, jlocal, jm_deliverMouseEvent, jEvent);413CHECK_EXCEPTION();414(*env)->DeleteLocalRef(env, jlocal);415}416(*env)->DeleteLocalRef(env, jEvent);417}418419- (void) resetTrackingArea {420if (rolloverTrackingArea != nil) {421[self removeTrackingArea:rolloverTrackingArea];422[rolloverTrackingArea release];423}424425int options = (NSTrackingActiveAlways | NSTrackingMouseEnteredAndExited |426NSTrackingMouseMoved | NSTrackingEnabledDuringMouseDrag);427428rolloverTrackingArea = [[NSTrackingArea alloc] initWithRect:[self visibleRect]429options: options430owner:self431userInfo:nil432];433[self addTrackingArea:rolloverTrackingArea];434}435436- (void)updateTrackingAreas {437[super updateTrackingAreas];438[self resetTrackingArea];439}440441- (void) resetCursorRects {442[super resetCursorRects];443[self resetTrackingArea];444}445446-(void) deliverJavaKeyEventHelper: (NSEvent *) event {447static NSEvent* sLastKeyEvent = nil;448if (event == sLastKeyEvent) {449// The event is repeatedly delivered by keyDown: after performKeyEquivalent:450return;451}452[sLastKeyEvent release];453sLastKeyEvent = [event retain];454455[AWTToolkit eventCountPlusPlus];456JNIEnv *env = [ThreadUtilities getJNIEnv];457458jstring characters = NULL;459jstring charactersIgnoringModifiers = NULL;460if ([event type] != NSFlagsChanged) {461characters = NSStringToJavaString(env, [event characters]);462charactersIgnoringModifiers = NSStringToJavaString(env, [event charactersIgnoringModifiers]);463}464465DECLARE_CLASS(jc_NSEvent, "sun/lwawt/macosx/NSEvent");466DECLARE_METHOD(jctor_NSEvent, jc_NSEvent, "<init>", "(IISLjava/lang/String;Ljava/lang/String;)V");467jobject jEvent = (*env)->NewObject(env, jc_NSEvent, jctor_NSEvent,468[event type],469[event modifierFlags],470[event keyCode],471characters,472charactersIgnoringModifiers);473CHECK_NULL(jEvent);474475DECLARE_CLASS(jc_PlatformView, "sun/lwawt/macosx/CPlatformView");476DECLARE_METHOD(jm_deliverKeyEvent, jc_PlatformView,477"deliverKeyEvent", "(Lsun/lwawt/macosx/NSEvent;)V");478jobject jlocal = (*env)->NewLocalRef(env, m_cPlatformView);479if (!(*env)->IsSameObject(env, jlocal, NULL)) {480(*env)->CallVoidMethod(env, jlocal, jm_deliverKeyEvent, jEvent);481CHECK_EXCEPTION();482(*env)->DeleteLocalRef(env, jlocal);483}484if (characters != NULL) {485(*env)->DeleteLocalRef(env, characters);486}487(*env)->DeleteLocalRef(env, jEvent);488}489490-(void) deliverResize: (NSRect) rect {491jint x = (jint) rect.origin.x;492jint y = (jint) rect.origin.y;493jint w = (jint) rect.size.width;494jint h = (jint) rect.size.height;495JNIEnv *env = [ThreadUtilities getJNIEnv];496DECLARE_CLASS(jc_PlatformView, "sun/lwawt/macosx/CPlatformView");497DECLARE_METHOD(jm_deliverResize, jc_PlatformView, "deliverResize", "(IIII)V");498499jobject jlocal = (*env)->NewLocalRef(env, m_cPlatformView);500if (!(*env)->IsSameObject(env, jlocal, NULL)) {501(*env)->CallVoidMethod(env, jlocal, jm_deliverResize, x,y,w,h);502CHECK_EXCEPTION();503(*env)->DeleteLocalRef(env, jlocal);504}505}506507508- (void) drawRect:(NSRect)dirtyRect {509AWT_ASSERT_APPKIT_THREAD;510511[super drawRect:dirtyRect];512JNIEnv *env = [ThreadUtilities getJNIEnv];513if (env != NULL) {514/*515if ([self inLiveResize]) {516NSRect rs[4];517NSInteger count;518[self getRectsExposedDuringLiveResize:rs count:&count];519for (int i = 0; i < count; i++) {520JNU_CallMethodByName(env, NULL, [m_awtWindow cPlatformView],521"deliverWindowDidExposeEvent", "(FFFF)V",522(jfloat)rs[i].origin.x, (jfloat)rs[i].origin.y,523(jfloat)rs[i].size.width, (jfloat)rs[i].size.height);524if ((*env)->ExceptionOccurred(env)) {525(*env)->ExceptionDescribe(env);526(*env)->ExceptionClear(env);527}528}529} else {530*/531DECLARE_CLASS(jc_CPlatformView, "sun/lwawt/macosx/CPlatformView");532DECLARE_METHOD(jm_deliverWindowDidExposeEvent, jc_CPlatformView, "deliverWindowDidExposeEvent", "()V");533jobject jlocal = (*env)->NewLocalRef(env, m_cPlatformView);534if (!(*env)->IsSameObject(env, jlocal, NULL)) {535(*env)->CallVoidMethod(env, jlocal, jm_deliverWindowDidExposeEvent);536CHECK_EXCEPTION();537(*env)->DeleteLocalRef(env, jlocal);538}539/*540}541*/542}543}544545-(BOOL) isCodePointInUnicodeBlockNeedingIMEvent: (unichar) codePoint {546if ((codePoint == 0x0024) || (codePoint == 0x00A3) ||547(codePoint == 0x00A5) ||548((codePoint >= 0x20A3) && (codePoint <= 0x20BF)) ||549((codePoint >= 0x3000) && (codePoint <= 0x303F)) ||550((codePoint >= 0xFF00) && (codePoint <= 0xFFEF))) {551// Code point is in 'CJK Symbols and Punctuation' or552// 'Halfwidth and Fullwidth Forms' Unicode block or553// currency symbols unicode554return YES;555}556return NO;557}558559-(NSMutableString *) parseString : (id) complexString {560if ([complexString isKindOfClass:[NSString class]]) {561return [complexString mutableCopy];562}563else {564return [complexString mutableString];565}566}567568// NSAccessibility support569- (jobject)awtComponent:(JNIEnv*)env570{571DECLARE_CLASS_RETURN(jc_CPlatformView, "sun/lwawt/macosx/CPlatformView", NULL);572DECLARE_FIELD_RETURN(jf_Peer, jc_CPlatformView, "peer", "Lsun/lwawt/LWWindowPeer;", NULL);573if ((env == NULL) || (m_cPlatformView == NULL)) {574NSLog(@"Apple AWT : Error AWTView:awtComponent given bad parameters.");575NSLog(@"%@",[NSThread callStackSymbols]);576return NULL;577}578579jobject peer = NULL;580jobject jlocal = (*env)->NewLocalRef(env, m_cPlatformView);581if (!(*env)->IsSameObject(env, jlocal, NULL)) {582peer = (*env)->GetObjectField(env, jlocal, jf_Peer);583(*env)->DeleteLocalRef(env, jlocal);584}585DECLARE_CLASS_RETURN(jc_LWWindowPeer, "sun/lwawt/LWWindowPeer", NULL);586DECLARE_FIELD_RETURN(jf_Target, jc_LWWindowPeer, "target", "Ljava/awt/Component;", NULL);587if (peer == NULL) {588NSLog(@"Apple AWT : Error AWTView:awtComponent got null peer from CPlatformView");589NSLog(@"%@",[NSThread callStackSymbols]);590return NULL;591}592jobject comp = (*env)->GetObjectField(env, peer, jf_Target);593(*env)->DeleteLocalRef(env, peer);594return comp;595}596597+ (AWTView *) awtView:(JNIEnv*)env ofAccessible:(jobject)jaccessible598{599DECLARE_CLASS_RETURN(sjc_CAccessibility, "sun/lwawt/macosx/CAccessibility", NULL);600DECLARE_STATIC_METHOD_RETURN(jm_getAWTView, sjc_CAccessibility, "getAWTView", "(Ljavax/accessibility/Accessible;)J", NULL);601602jlong jptr = (*env)->CallStaticLongMethod(env, sjc_CAccessibility, jm_getAWTView, jaccessible);603CHECK_EXCEPTION();604if (jptr == 0) return nil;605606return (AWTView *)jlong_to_ptr(jptr);607}608609- (id)getAxData:(JNIEnv*)env610{611jobject jcomponent = [self awtComponent:env];612id ax = [[[CommonComponentAccessibility alloc] initWithParent:self withEnv:env withAccessible:jcomponent withIndex:-1 withView:self withJavaRole:nil] autorelease];613(*env)->DeleteLocalRef(env, jcomponent);614return ax;615}616617// NSAccessibility messages618- (id)accessibilityChildren619{620AWT_ASSERT_APPKIT_THREAD;621JNIEnv *env = [ThreadUtilities getJNIEnv];622623(*env)->PushLocalFrame(env, 4);624625id result = NSAccessibilityUnignoredChildrenForOnlyChild([self getAxData:env]);626627(*env)->PopLocalFrame(env, NULL);628629return result;630}631632- (BOOL)isAccessibilityElement633{634return NO;635}636637- (id)accessibilityHitTest:(NSPoint)point638{639AWT_ASSERT_APPKIT_THREAD;640JNIEnv *env = [ThreadUtilities getJNIEnv];641642(*env)->PushLocalFrame(env, 4);643644id result = [[self getAxData:env] accessibilityHitTest:point];645646(*env)->PopLocalFrame(env, NULL);647648return result;649}650651- (id)accessibilityFocusedUIElement652{653AWT_ASSERT_APPKIT_THREAD;654655JNIEnv *env = [ThreadUtilities getJNIEnv];656657(*env)->PushLocalFrame(env, 4);658659id result = [[self getAxData:env] accessibilityFocusedUIElement];660661(*env)->PopLocalFrame(env, NULL);662663return result;664}665666// --- Services menu support for lightweights ---667668// finds the focused accessible element, and if it is a text element, obtains the text from it669- (NSString *)accessibilitySelectedText670{671id focused = [self accessibilityFocusedUIElement];672if (![focused respondsToSelector:@selector(accessibilitySelectedText)]) return nil;673return [focused accessibilitySelectedText];674}675676- (void)setAccessibilitySelectedText:(NSString *)accessibilitySelectedText {677id focused = [self accessibilityFocusedUIElement];678if ([focused respondsToSelector:@selector(setAccessibilitySelectedText:)]) {679[focused setAccessibilitySelectedText:accessibilitySelectedText];680}681}682683// same as above, but converts to RTFD684- (NSData *)accessibleSelectedTextAsRTFD685{686NSString *selectedText = [self accessibilitySelectedText];687NSAttributedString *styledText = [[NSAttributedString alloc] initWithString:selectedText];688NSData *rtfdData = [styledText RTFDFromRange:NSMakeRange(0, [styledText length])689documentAttributes:690@{NSDocumentTypeDocumentAttribute: NSRTFTextDocumentType}];691[styledText release];692return rtfdData;693}694695// finds the focused accessible element, and if it is a text element, sets the text in it696- (BOOL)replaceAccessibleTextSelection:(NSString *)text697{698id focused = [self accessibilityFocusedUIElement];699if (![focused respondsToSelector:@selector(setAccessibilitySelectedText)]) return NO;700[focused setAccessibilitySelectedText:text];701return YES;702}703704// called for each service in the Services menu - only handle text for now705- (id)validRequestorForSendType:(NSString *)sendType returnType:(NSString *)returnType706{707if ([[self window] firstResponder] != self) return nil; // let AWT components handle themselves708709if ([sendType isEqual:NSStringPboardType] || [returnType isEqual:NSStringPboardType]) {710NSString *selectedText = [self accessibilitySelectedText];711if (selectedText) return self;712}713714return nil;715}716717// fetch text from Java and hand off to the service718- (BOOL)writeSelectionToPasteboard:(NSPasteboard *)pboard types:(NSArray *)types719{720if ([types containsObject:NSStringPboardType])721{722[pboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];723return [pboard setString:[self accessibilitySelectedText] forType:NSStringPboardType];724}725726if ([types containsObject:NSRTFDPboardType])727{728[pboard declareTypes:[NSArray arrayWithObject:NSRTFDPboardType] owner:nil];729return [pboard setData:[self accessibleSelectedTextAsRTFD] forType:NSRTFDPboardType];730}731732return NO;733}734735// write text back to Java from the service736- (BOOL)readSelectionFromPasteboard:(NSPasteboard *)pboard737{738if ([[pboard types] containsObject:NSStringPboardType])739{740NSString *text = [pboard stringForType:NSStringPboardType];741return [self replaceAccessibleTextSelection:text];742}743744if ([[pboard types] containsObject:NSRTFDPboardType])745{746NSData *rtfdData = [pboard dataForType:NSRTFDPboardType];747NSAttributedString *styledText = [[NSAttributedString alloc] initWithRTFD:rtfdData documentAttributes:NULL];748NSString *text = [styledText string];749[styledText release];750751return [self replaceAccessibleTextSelection:text];752}753754return NO;755}756757758-(void) setDragSource:(CDragSource *)source {759self._dragSource = source;760}761762763- (void) setDropTarget:(CDropTarget *)target {764self._dropTarget = target;765[ThreadUtilities performOnMainThread:@selector(controlModelControlValid) on:self._dropTarget withObject:nil waitUntilDone:YES];766}767768/******************************** BEGIN NSDraggingSource Interface ********************************/769770- (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)flag771{772// If draggingSource is nil route the message to the superclass (if responding to the selector):773CDragSource *dragSource = self._dragSource;774NSDragOperation dragOp = NSDragOperationNone;775776if (dragSource != nil) {777dragOp = [dragSource draggingSourceOperationMaskForLocal:flag];778}779return dragOp;780}781782- (NSArray *)namesOfPromisedFilesDroppedAtDestination:(NSURL *)dropDestination783{784// If draggingSource is nil route the message to the superclass (if responding to the selector):785CDragSource *dragSource = self._dragSource;786NSArray* array = nil;787788if (dragSource != nil) {789array = [dragSource namesOfPromisedFilesDroppedAtDestination:dropDestination];790}791return array;792}793794- (void)draggedImage:(NSImage *)image beganAt:(NSPoint)screenPoint795{796// If draggingSource is nil route the message to the superclass (if responding to the selector):797CDragSource *dragSource = self._dragSource;798799if (dragSource != nil) {800[dragSource draggedImage:image beganAt:screenPoint];801}802}803804- (void)draggedImage:(NSImage *)image endedAt:(NSPoint)screenPoint operation:(NSDragOperation)operation805{806// If draggingSource is nil route the message to the superclass (if responding to the selector):807CDragSource *dragSource = self._dragSource;808809if (dragSource != nil) {810[dragSource draggedImage:image endedAt:screenPoint operation:operation];811}812}813814- (void)draggedImage:(NSImage *)image movedTo:(NSPoint)screenPoint815{816// If draggingSource is nil route the message to the superclass (if responding to the selector):817CDragSource *dragSource = self._dragSource;818819if (dragSource != nil) {820[dragSource draggedImage:image movedTo:screenPoint];821}822}823824- (BOOL)ignoreModifierKeysWhileDragging825{826// If draggingSource is nil route the message to the superclass (if responding to the selector):827CDragSource *dragSource = self._dragSource;828BOOL result = FALSE;829830if (dragSource != nil) {831result = [dragSource ignoreModifierKeysWhileDragging];832}833return result;834}835836/******************************** END NSDraggingSource Interface ********************************/837838/******************************** BEGIN NSDraggingDestination Interface ********************************/839840- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender841{842// If draggingDestination is nil route the message to the superclass:843CDropTarget *dropTarget = self._dropTarget;844NSDragOperation dragOp = NSDragOperationNone;845846if (dropTarget != nil) {847dragOp = [dropTarget draggingEntered:sender];848}849return dragOp;850}851852- (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender853{854// If draggingDestination is nil route the message to the superclass:855CDropTarget *dropTarget = self._dropTarget;856NSDragOperation dragOp = NSDragOperationNone;857858if (dropTarget != nil) {859dragOp = [dropTarget draggingUpdated:sender];860}861return dragOp;862}863864- (void)draggingExited:(id <NSDraggingInfo>)sender865{866// If draggingDestination is nil route the message to the superclass:867CDropTarget *dropTarget = self._dropTarget;868869if (dropTarget != nil) {870[dropTarget draggingExited:sender];871}872}873874- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender875{876// If draggingDestination is nil route the message to the superclass:877CDropTarget *dropTarget = self._dropTarget;878BOOL result = FALSE;879880if (dropTarget != nil) {881result = [dropTarget prepareForDragOperation:sender];882}883return result;884}885886- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender887{888// If draggingDestination is nil route the message to the superclass:889CDropTarget *dropTarget = self._dropTarget;890BOOL result = FALSE;891892if (dropTarget != nil) {893result = [dropTarget performDragOperation:sender];894}895return result;896}897898- (void)concludeDragOperation:(id <NSDraggingInfo>)sender899{900// If draggingDestination is nil route the message to the superclass:901CDropTarget *dropTarget = self._dropTarget;902903if (dropTarget != nil) {904[dropTarget concludeDragOperation:sender];905}906}907908- (void)draggingEnded:(id <NSDraggingInfo>)sender909{910// If draggingDestination is nil route the message to the superclass:911CDropTarget *dropTarget = self._dropTarget;912913if (dropTarget != nil) {914[dropTarget draggingEnded:sender];915}916}917918/******************************** END NSDraggingDestination Interface ********************************/919920/******************************** BEGIN NSTextInputClient Protocol ********************************/921922923static jclass jc_CInputMethod = NULL;924925#define GET_CIM_CLASS() \926GET_CLASS(jc_CInputMethod, "sun/lwawt/macosx/CInputMethod");927928#define GET_CIM_CLASS_RETURN(ret) \929GET_CLASS_RETURN(jc_CInputMethod, "sun/lwawt/macosx/CInputMethod", ret);930931- (void) insertText:(id)aString replacementRange:(NSRange)replacementRange932{933#ifdef IM_DEBUG934fprintf(stderr, "AWTView InputMethod Selector Called : [insertText]: %s\n", [aString UTF8String]);935#endif // IM_DEBUG936937if (fInputMethodLOCKABLE == NULL) {938return;939}940941// Insert happens at the end of PAH942fInPressAndHold = NO;943944// insertText gets called when the user commits text generated from an input method. It also gets945// called during ordinary input as well. We only need to send an input method event when we have marked946// text, or 'text in progress'. We also need to send the event if we get an insert text out of the blue!947// (i.e., when the user uses the Character palette or Inkwell), or when the string to insert is a complex948// Unicode value.949950NSMutableString * useString = [self parseString:aString];951NSUInteger utf16Length = [useString lengthOfBytesUsingEncoding:NSUTF16StringEncoding];952NSUInteger utf8Length = [useString lengthOfBytesUsingEncoding:NSUTF8StringEncoding];953BOOL aStringIsComplex = NO;954955unichar codePoint = [useString characterAtIndex:0];956957#ifdef IM_DEBUG958NSLog(@"insertText kbdlayout %@ ",(NSString *)kbdLayout);959#endif // IM_DEBUG960961if ((utf16Length > 2) ||962((utf8Length > 1) && [self isCodePointInUnicodeBlockNeedingIMEvent:codePoint]) ||963((codePoint == 0x5c) && ([(NSString *)kbdLayout containsString:@"Kotoeri"]))) {964aStringIsComplex = YES;965}966967if ([self hasMarkedText] || !fProcessingKeystroke || aStringIsComplex) {968JNIEnv *env = [ThreadUtilities getJNIEnv];969970GET_CIM_CLASS();971DECLARE_METHOD(jm_selectPreviousGlyph, jc_CInputMethod, "selectPreviousGlyph", "()V");972// We need to select the previous glyph so that it is overwritten.973if (fPAHNeedsToSelect) {974(*env)->CallVoidMethod(env, fInputMethodLOCKABLE, jm_selectPreviousGlyph);975CHECK_EXCEPTION();976fPAHNeedsToSelect = NO;977}978979DECLARE_METHOD(jm_insertText, jc_CInputMethod, "insertText", "(Ljava/lang/String;)V");980jstring insertedText = NSStringToJavaString(env, useString);981(*env)->CallVoidMethod(env, fInputMethodLOCKABLE, jm_insertText, insertedText);982CHECK_EXCEPTION();983(*env)->DeleteLocalRef(env, insertedText);984985// The input method event will create psuedo-key events for each character in the committed string.986// We also don't want to send the character that triggered the insertText, usually a return. [3337563]987fKeyEventsNeeded = NO;988}989else {990// Need to set back the fKeyEventsNeeded flag so that the string following the991// marked text is not ignored by keyDown992if ([useString length] > 0) {993fKeyEventsNeeded = YES;994}995}996fPAHNeedsToSelect = NO;997998// Abandon input to reset IM and unblock input after entering accented999// symbols10001001[self abandonInput];1002}10031004+ (void)keyboardInputSourceChanged:(NSNotification *)notification1005{1006#ifdef IM_DEBUG1007NSLog(@"keyboardInputSourceChangeNotification received");1008#endif1009NSTextInputContext *curContxt = [NSTextInputContext currentInputContext];1010kbdLayout = curContxt.selectedKeyboardInputSource;1011}10121013- (void) doCommandBySelector:(SEL)aSelector1014{1015#ifdef IM_DEBUG1016fprintf(stderr, "AWTView InputMethod Selector Called : [doCommandBySelector]\n");1017NSLog(@"%@", NSStringFromSelector(aSelector));1018#endif // IM_DEBUG1019if (@selector(insertNewline:) == aSelector || @selector(insertTab:) == aSelector || @selector(deleteBackward:) == aSelector)1020{1021fKeyEventsNeeded = YES;1022}1023}10241025// setMarkedText: cannot take a nil first argument. aString can be NSString or NSAttributedString1026- (void) setMarkedText:(id)aString selectedRange:(NSRange)selectionRange replacementRange:(NSRange)replacementRange1027{1028if (!fInputMethodLOCKABLE)1029return;10301031BOOL isAttributedString = [aString isKindOfClass:[NSAttributedString class]];1032NSAttributedString *attrString = (isAttributedString ? (NSAttributedString *)aString : nil);1033NSString *incomingString = (isAttributedString ? [aString string] : aString);1034#ifdef IM_DEBUG1035fprintf(stderr, "AWTView InputMethod Selector Called : [setMarkedText] \"%s\", loc=%lu, length=%lu\n", [incomingString UTF8String], (unsigned long)selectionRange.location, (unsigned long)selectionRange.length);1036#endif // IM_DEBUG1037JNIEnv *env = [ThreadUtilities getJNIEnv];1038GET_CIM_CLASS();1039DECLARE_METHOD(jm_startIMUpdate, jc_CInputMethod, "startIMUpdate", "(Ljava/lang/String;)V");1040DECLARE_METHOD(jm_addAttribute, jc_CInputMethod, "addAttribute", "(ZZII)V");1041DECLARE_METHOD(jm_dispatchText, jc_CInputMethod, "dispatchText", "(IIZ)V");10421043// NSInputContext already did the analysis of the TSM event and created attributes indicating1044// the underlining and color that should be done to the string. We need to look at the underline1045// style and color to determine what kind of Java hilighting needs to be done.1046jstring inProcessText = NSStringToJavaString(env, incomingString);1047(*env)->CallVoidMethod(env, fInputMethodLOCKABLE, jm_startIMUpdate, inProcessText);1048CHECK_EXCEPTION();1049(*env)->DeleteLocalRef(env, inProcessText);10501051if (isAttributedString) {1052NSUInteger length;1053NSRange effectiveRange;1054NSDictionary *attributes;1055length = [attrString length];1056effectiveRange = NSMakeRange(0, 0);1057while (NSMaxRange(effectiveRange) < length) {1058attributes = [attrString attributesAtIndex:NSMaxRange(effectiveRange)1059effectiveRange:&effectiveRange];1060if (attributes) {1061BOOL isThickUnderline, isGray;1062NSNumber *underlineSizeObj =1063(NSNumber *)[attributes objectForKey:NSUnderlineStyleAttributeName];1064NSInteger underlineSize = [underlineSizeObj integerValue];1065isThickUnderline = (underlineSize > 1);10661067NSColor *underlineColorObj =1068(NSColor *)[attributes objectForKey:NSUnderlineColorAttributeName];1069isGray = !([underlineColorObj isEqual:[NSColor blackColor]]);10701071(*env)->CallVoidMethod(env, fInputMethodLOCKABLE, jm_addAttribute, isThickUnderline,1072isGray, effectiveRange.location, effectiveRange.length);1073CHECK_EXCEPTION();1074}1075}1076}10771078DECLARE_METHOD(jm_selectPreviousGlyph, jc_CInputMethod, "selectPreviousGlyph", "()V");1079// We need to select the previous glyph so that it is overwritten.1080if (fPAHNeedsToSelect) {1081(*env)->CallVoidMethod(env, fInputMethodLOCKABLE, jm_selectPreviousGlyph);1082CHECK_EXCEPTION();1083fPAHNeedsToSelect = NO;1084}10851086(*env)->CallVoidMethod(env, fInputMethodLOCKABLE, jm_dispatchText,1087selectionRange.location, selectionRange.length, JNI_FALSE);1088CHECK_EXCEPTION();1089// If the marked text is being cleared (zero-length string) don't handle the key event.1090if ([incomingString length] == 0) {1091fKeyEventsNeeded = NO;1092}1093}10941095- (void) unmarkText1096{1097#ifdef IM_DEBUG1098fprintf(stderr, "AWTView InputMethod Selector Called : [unmarkText]\n");1099#endif // IM_DEBUG11001101if (!fInputMethodLOCKABLE) {1102return;1103}11041105// unmarkText cancels any input in progress and commits it to the text field.1106JNIEnv *env = [ThreadUtilities getJNIEnv];1107GET_CIM_CLASS();1108DECLARE_METHOD(jm_unmarkText, jc_CInputMethod, "unmarkText", "()V");1109(*env)->CallVoidMethod(env, fInputMethodLOCKABLE, jm_unmarkText);1110CHECK_EXCEPTION();1111}11121113- (BOOL) hasMarkedText1114{1115#ifdef IM_DEBUG1116fprintf(stderr, "AWTView InputMethod Selector Called : [hasMarkedText]\n");1117#endif // IM_DEBUG11181119if (!fInputMethodLOCKABLE) {1120return NO;1121}11221123JNIEnv *env = [ThreadUtilities getJNIEnv];1124GET_CIM_CLASS_RETURN(NO);1125DECLARE_FIELD_RETURN(jf_fCurrentText, jc_CInputMethod, "fCurrentText", "Ljava/text/AttributedString;", NO);1126DECLARE_FIELD_RETURN(jf_fCurrentTextLength, jc_CInputMethod, "fCurrentTextLength", "I", NO);1127jobject currentText = (*env)->GetObjectField(env, fInputMethodLOCKABLE, jf_fCurrentText);1128CHECK_EXCEPTION();11291130jint currentTextLength = (*env)->GetIntField(env, fInputMethodLOCKABLE, jf_fCurrentTextLength);1131CHECK_EXCEPTION();11321133BOOL hasMarkedText = (currentText != NULL && currentTextLength > 0);11341135if (currentText != NULL) {1136(*env)->DeleteLocalRef(env, currentText);1137}11381139return hasMarkedText;1140}11411142- (NSInteger) conversationIdentifier1143{1144#ifdef IM_DEBUG1145fprintf(stderr, "AWTView InputMethod Selector Called : [conversationIdentifier]\n");1146#endif // IM_DEBUG11471148return (NSInteger) self;1149}11501151/* Returns attributed string at the range. This allows input mangers to1152query any range in backing-store (Andy's request)1153*/1154- (NSAttributedString *) attributedSubstringForProposedRange:(NSRange)theRange actualRange:(NSRangePointer)actualRange1155{1156#ifdef IM_DEBUG1157fprintf(stderr, "AWTView InputMethod Selector Called : [attributedSubstringFromRange] location=%lu, length=%lu\n", (unsigned long)theRange.location, (unsigned long)theRange.length);1158#endif // IM_DEBUG1159if (!fInputMethodLOCKABLE) {1160return nil;1161}11621163JNIEnv *env = [ThreadUtilities getJNIEnv];1164GET_CIM_CLASS_RETURN(nil);1165DECLARE_METHOD_RETURN(jm_substringFromRange, jc_CInputMethod, "attributedSubstringFromRange", "(II)Ljava/lang/String;", nil);1166jobject theString = (*env)->CallObjectMethod(env, fInputMethodLOCKABLE, jm_substringFromRange, theRange.location, theRange.length);1167CHECK_EXCEPTION_NULL_RETURN(theString, nil);11681169id result = [[[NSAttributedString alloc] initWithString:JavaStringToNSString(env, theString)] autorelease];1170#ifdef IM_DEBUG1171NSLog(@"attributedSubstringFromRange returning \"%@\"", result);1172#endif // IM_DEBUG11731174(*env)->DeleteLocalRef(env, theString);1175return result;1176}11771178/* This method returns the range for marked region. If hasMarkedText == false,1179it'll return NSNotFound location & 0 length range.1180*/1181- (NSRange) markedRange1182{11831184#ifdef IM_DEBUG1185fprintf(stderr, "AWTView InputMethod Selector Called : [markedRange]\n");1186#endif // IM_DEBUG11871188if (!fInputMethodLOCKABLE) {1189return NSMakeRange(NSNotFound, 0);1190}11911192JNIEnv *env = [ThreadUtilities getJNIEnv];1193jarray array;1194jboolean isCopy;1195jint *_array;1196NSRange range = NSMakeRange(NSNotFound, 0);1197GET_CIM_CLASS_RETURN(range);1198DECLARE_METHOD_RETURN(jm_markedRange, jc_CInputMethod, "markedRange", "()[I", range);11991200array = (*env)->CallObjectMethod(env, fInputMethodLOCKABLE, jm_markedRange);1201CHECK_EXCEPTION();12021203if (array) {1204_array = (*env)->GetIntArrayElements(env, array, &isCopy);1205if (_array != NULL) {1206range.location = _array[0];1207range.length = _array[1];1208#ifdef IM_DEBUG1209fprintf(stderr, "markedRange returning (%lu, %lu)\n",1210(unsigned long)range.location, (unsigned long)range.length);1211#endif // IM_DEBUG1212(*env)->ReleaseIntArrayElements(env, array, _array, 0);1213}1214(*env)->DeleteLocalRef(env, array);1215}12161217return range;1218}12191220/* This method returns the range for selected region. Just like markedRange method,1221its location field contains char index from the text beginning.1222*/1223- (NSRange) selectedRange1224{1225if (!fInputMethodLOCKABLE) {1226return NSMakeRange(NSNotFound, 0);1227}12281229JNIEnv *env = [ThreadUtilities getJNIEnv];1230jarray array;1231jboolean isCopy;1232jint *_array;1233NSRange range = NSMakeRange(NSNotFound, 0);1234GET_CIM_CLASS_RETURN(range);1235DECLARE_METHOD_RETURN(jm_selectedRange, jc_CInputMethod, "selectedRange", "()[I", range);12361237#ifdef IM_DEBUG1238fprintf(stderr, "AWTView InputMethod Selector Called : [selectedRange]\n");1239#endif // IM_DEBUG12401241array = (*env)->CallObjectMethod(env, fInputMethodLOCKABLE, jm_selectedRange);1242CHECK_EXCEPTION();1243if (array) {1244_array = (*env)->GetIntArrayElements(env, array, &isCopy);1245if (_array != NULL) {1246range.location = _array[0];1247range.length = _array[1];1248(*env)->ReleaseIntArrayElements(env, array, _array, 0);1249}1250(*env)->DeleteLocalRef(env, array);1251}12521253return range;1254}12551256/* This method returns the first frame of rects for theRange in screen coordindate system.1257*/1258- (NSRect) firstRectForCharacterRange:(NSRange)theRange actualRange:(NSRangePointer)actualRange1259{1260if (!fInputMethodLOCKABLE) {1261return NSZeroRect;1262}12631264JNIEnv *env = [ThreadUtilities getJNIEnv];1265GET_CIM_CLASS_RETURN(NSZeroRect);1266DECLARE_METHOD_RETURN(jm_firstRectForCharacterRange, jc_CInputMethod,1267"firstRectForCharacterRange", "(I)[I", NSZeroRect);1268jarray array;1269jboolean isCopy;1270jint *_array;1271NSRect rect;12721273#ifdef IM_DEBUG1274fprintf(stderr,1275"AWTView InputMethod Selector Called : [firstRectForCharacterRange:] location=%lu, length=%lu\n",1276(unsigned long)theRange.location, (unsigned long)theRange.length);1277#endif // IM_DEBUG12781279array = (*env)->CallObjectMethod(env, fInputMethodLOCKABLE, jm_firstRectForCharacterRange,1280theRange.location);1281CHECK_EXCEPTION();12821283_array = (*env)->GetIntArrayElements(env, array, &isCopy);1284if (_array) {1285rect = ConvertNSScreenRect(env, NSMakeRect(_array[0], _array[1], _array[2], _array[3]));1286(*env)->ReleaseIntArrayElements(env, array, _array, 0);1287} else {1288rect = NSZeroRect;1289}1290(*env)->DeleteLocalRef(env, array);12911292#ifdef IM_DEBUG1293fprintf(stderr,1294"firstRectForCharacterRange returning x=%f, y=%f, width=%f, height=%f\n",1295rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);1296#endif // IM_DEBUG1297return rect;1298}12991300/* This method returns the index for character that is nearest to thePoint. thPoint is in1301screen coordinate system.1302*/1303- (NSUInteger)characterIndexForPoint:(NSPoint)thePoint1304{1305if (!fInputMethodLOCKABLE) {1306return NSNotFound;1307}13081309JNIEnv *env = [ThreadUtilities getJNIEnv];1310GET_CIM_CLASS_RETURN(NSNotFound);1311DECLARE_METHOD_RETURN(jm_characterIndexForPoint, jc_CInputMethod,1312"characterIndexForPoint", "(II)I", NSNotFound);13131314NSPoint flippedLocation = ConvertNSScreenPoint(env, thePoint);13151316#ifdef IM_DEBUG1317fprintf(stderr, "AWTView InputMethod Selector Called : [characterIndexForPoint:(NSPoint)thePoint] x=%f, y=%f\n", flippedLocation.x, flippedLocation.y);1318#endif // IM_DEBUG13191320jint index = (*env)->CallIntMethod(env, fInputMethodLOCKABLE, jm_characterIndexForPoint,1321(jint)flippedLocation.x, (jint)flippedLocation.y);1322CHECK_EXCEPTION();13231324#ifdef IM_DEBUG1325fprintf(stderr, "characterIndexForPoint returning %d\n", index);1326#endif // IM_DEBUG13271328if (index == -1) {1329return NSNotFound;1330} else {1331return (NSUInteger)index;1332}1333}13341335- (NSArray*) validAttributesForMarkedText1336{1337#ifdef IM_DEBUG1338fprintf(stderr, "AWTView InputMethod Selector Called : [validAttributesForMarkedText]\n");1339#endif // IM_DEBUG13401341return [NSArray array];1342}13431344- (void)setInputMethod:(jobject)inputMethod1345{1346#ifdef IM_DEBUG1347fprintf(stderr, "AWTView InputMethod Selector Called : [setInputMethod]\n");1348#endif // IM_DEBUG13491350JNIEnv *env = [ThreadUtilities getJNIEnv];13511352// Get rid of the old one1353if (fInputMethodLOCKABLE) {1354(*env)->DeleteGlobalRef(env, fInputMethodLOCKABLE);1355}13561357fInputMethodLOCKABLE = inputMethod; // input method arg must be a GlobalRef13581359NSTextInputContext *curContxt = [NSTextInputContext currentInputContext];1360kbdLayout = curContxt.selectedKeyboardInputSource;1361[[NSNotificationCenter defaultCenter] addObserver:[AWTView class]1362selector:@selector(keyboardInputSourceChanged:)1363name:NSTextInputContextKeyboardSelectionDidChangeNotification1364object:nil];1365}13661367- (void)abandonInput1368{1369#ifdef IM_DEBUG1370fprintf(stderr, "AWTView InputMethod Selector Called : [abandonInput]\n");1371#endif // IM_DEBUG13721373[ThreadUtilities performOnMainThread:@selector(markedTextAbandoned:) on:[NSInputManager currentInputManager] withObject:self waitUntilDone:YES];1374[self unmarkText];1375}13761377/******************************** END NSTextInputClient Protocol ********************************/13781379138013811382@end // AWTView13831384/*1385* Class: sun_lwawt_macosx_CPlatformView1386* Method: nativeCreateView1387* Signature: (IIII)J1388*/1389JNIEXPORT jlong JNICALL1390Java_sun_lwawt_macosx_CPlatformView_nativeCreateView1391(JNIEnv *env, jobject obj, jint originX, jint originY, jint width, jint height, jlong windowLayerPtr)1392{1393__block AWTView *newView = nil;13941395JNI_COCOA_ENTER(env);13961397NSRect rect = NSMakeRect(originX, originY, width, height);1398jobject cPlatformView = (*env)->NewWeakGlobalRef(env, obj);1399CHECK_EXCEPTION();14001401[ThreadUtilities performOnMainThreadWaiting:YES block:^(){14021403CALayer *windowLayer = jlong_to_ptr(windowLayerPtr);1404newView = [[AWTView alloc] initWithRect:rect1405platformView:cPlatformView1406windowLayer:windowLayer];1407}];14081409JNI_COCOA_EXIT(env);14101411return ptr_to_jlong(newView);1412}14131414/*1415* Class: sun_lwawt_macosx_CPlatformView1416* Method: nativeSetAutoResizable1417* Signature: (JZ)V;1418*/14191420JNIEXPORT void JNICALL1421Java_sun_lwawt_macosx_CPlatformView_nativeSetAutoResizable1422(JNIEnv *env, jclass cls, jlong viewPtr, jboolean toResize)1423{1424JNI_COCOA_ENTER(env);14251426NSView *view = (NSView *)jlong_to_ptr(viewPtr);14271428[ThreadUtilities performOnMainThreadWaiting:NO block:^(){14291430if (toResize) {1431[view setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable];1432} else {1433[view setAutoresizingMask: NSViewMinYMargin | NSViewMaxXMargin];1434}14351436if ([view superview] != nil) {1437[[view superview] setAutoresizesSubviews:(BOOL)toResize];1438}14391440}];1441JNI_COCOA_EXIT(env);1442}14431444/*1445* Class: sun_lwawt_macosx_CPlatformView1446* Method: nativeGetNSViewDisplayID1447* Signature: (J)I;1448*/14491450JNIEXPORT jint JNICALL1451Java_sun_lwawt_macosx_CPlatformView_nativeGetNSViewDisplayID1452(JNIEnv *env, jclass cls, jlong viewPtr)1453{1454__block jint ret; //CGDirectDisplayID14551456JNI_COCOA_ENTER(env);14571458NSView *view = (NSView *)jlong_to_ptr(viewPtr);1459[ThreadUtilities performOnMainThreadWaiting:YES block:^(){1460NSWindow *window = [view window];1461ret = (jint)[[AWTWindow getNSWindowDisplayID_AppKitThread: window] intValue];1462}];14631464JNI_COCOA_EXIT(env);14651466return ret;1467}14681469/*1470* Class: sun_lwawt_macosx_CPlatformView1471* Method: nativeGetLocationOnScreen1472* Signature: (J)Ljava/awt/Rectangle;1473*/14741475JNIEXPORT jobject JNICALL1476Java_sun_lwawt_macosx_CPlatformView_nativeGetLocationOnScreen1477(JNIEnv *env, jclass cls, jlong viewPtr)1478{1479jobject jRect = NULL;14801481JNI_COCOA_ENTER(env);14821483__block NSRect rect = NSZeroRect;14841485NSView *view = (NSView *)jlong_to_ptr(viewPtr);1486[ThreadUtilities performOnMainThreadWaiting:YES block:^(){14871488NSRect viewBounds = [view bounds];1489NSRect frameInWindow = [view convertRect:viewBounds toView:nil];1490rect = [[view window] convertRectToScreen:frameInWindow];1491//Convert coordinates to top-left corner origin1492rect = ConvertNSScreenRect(NULL, rect);14931494}];1495jRect = NSToJavaRect(env, rect);14961497JNI_COCOA_EXIT(env);14981499return jRect;1500}15011502/*1503* Class: sun_lwawt_macosx_CPlatformView1504* Method: nativeIsViewUnderMouse1505* Signature: (J)Z;1506*/15071508JNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_CPlatformView_nativeIsViewUnderMouse1509(JNIEnv *env, jclass clazz, jlong viewPtr)1510{1511__block jboolean underMouse = JNI_FALSE;15121513JNI_COCOA_ENTER(env);15141515NSView *nsView = OBJC(viewPtr);1516[ThreadUtilities performOnMainThreadWaiting:YES block:^(){1517NSPoint ptWindowCoords = [[nsView window] mouseLocationOutsideOfEventStream];1518NSPoint ptViewCoords = [nsView convertPoint:ptWindowCoords fromView:nil];1519underMouse = [nsView hitTest:ptViewCoords] != nil;1520}];15211522JNI_COCOA_EXIT(env);15231524return underMouse;1525}152615271528