annotate src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m @ 15037:9c3c78efdf6d

8148984: [macosx] Chinese Comma cannot be entered using Pinyin Input Method on OS X Reviewed-by: alexp
author dmarkov
date Mon, 04 Jul 2016 11:04:18 +0300
parents 909c7db6c47d
children ff61a6fd0349
rev   line source
michaelm@5116 1 /*
aniyogi@14038 2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
michaelm@5116 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
michaelm@5116 4 *
michaelm@5116 5 * This code is free software; you can redistribute it and/or modify it
michaelm@5116 6 * under the terms of the GNU General Public License version 2 only, as
michaelm@5116 7 * published by the Free Software Foundation. Oracle designates this
michaelm@5116 8 * particular file as subject to the "Classpath" exception as provided
michaelm@5116 9 * by Oracle in the LICENSE file that accompanied this code.
michaelm@5116 10 *
michaelm@5116 11 * This code is distributed in the hope that it will be useful, but WITHOUT
michaelm@5116 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
michaelm@5116 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
michaelm@5116 14 * version 2 for more details (a copy is included in the LICENSE file that
michaelm@5116 15 * accompanied this code).
michaelm@5116 16 *
michaelm@5116 17 * You should have received a copy of the GNU General Public License version
michaelm@5116 18 * 2 along with this work; if not, write to the Free Software Foundation,
michaelm@5116 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
michaelm@5116 20 *
michaelm@5116 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
michaelm@5116 22 * or visit www.oracle.com if you need additional information or have any
michaelm@5116 23 * questions.
michaelm@5116 24 */
michaelm@5116 25
serb@12846 26 #import "jni_util.h"
michaelm@5116 27 #import "CGLGraphicsConfig.h"
michaelm@5116 28 #import "AWTView.h"
michaelm@5116 29 #import "AWTWindow.h"
michaelm@5116 30 #import "JavaComponentAccessibility.h"
michaelm@5116 31 #import "JavaTextAccessibility.h"
ant@14365 32 #import "JavaAccessibilityUtilities.h"
michaelm@5116 33 #import "GeomUtilities.h"
michaelm@5116 34 #import "OSVersion.h"
serb@12846 35 #import "ThreadUtilities.h"
serb@12846 36
serb@12846 37 #import <JavaNativeFoundation/JavaNativeFoundation.h>
michaelm@5116 38
michaelm@5116 39 @interface AWTView()
michaelm@5116 40 @property (retain) CDropTarget *_dropTarget;
michaelm@5116 41 @property (retain) CDragSource *_dragSource;
pchelko@9407 42
pchelko@9407 43 -(void) deliverResize: (NSRect) rect;
pchelko@9407 44 -(void) resetTrackingArea;
pchelko@9407 45 -(void) deliverJavaKeyEventHelper: (NSEvent*) event;
alitvinov@13095 46 -(BOOL) isCodePointInUnicodeBlockNeedingIMEvent: (unichar) codePoint;
aniyogi@14038 47 -(NSMutableString *) parseString : (id) complexString;
michaelm@5116 48 @end
michaelm@5116 49
michaelm@5116 50 // Uncomment this line to see fprintfs of each InputMethod API being called on this View
michaelm@5116 51 //#define IM_DEBUG TRUE
michaelm@5116 52 //#define EXTRA_DEBUG
michaelm@5116 53
michaelm@5116 54 static BOOL shouldUsePressAndHold() {
michaelm@5116 55 static int shouldUsePressAndHold = -1;
michaelm@5116 56 if (shouldUsePressAndHold != -1) return shouldUsePressAndHold;
michaelm@5116 57 shouldUsePressAndHold = !isSnowLeopardOrLower();
michaelm@5116 58 return shouldUsePressAndHold;
michaelm@5116 59 }
michaelm@5116 60
michaelm@5116 61 @implementation AWTView
michaelm@5116 62
michaelm@5116 63 @synthesize _dropTarget;
michaelm@5116 64 @synthesize _dragSource;
michaelm@5116 65 @synthesize cglLayer;
alexsch@5312 66 @synthesize mouseIsOver;
michaelm@5116 67
michaelm@5116 68 // Note: Must be called on main (AppKit) thread only
michaelm@5116 69 - (id) initWithRect: (NSRect) rect
michaelm@5116 70 platformView: (jobject) cPlatformView
aniyogi@14038 71 windowLayer: (CALayer*) windowLayer
michaelm@5116 72 {
aniyogi@14038 73 AWT_ASSERT_APPKIT_THREAD;
michaelm@5116 74 // Initialize ourselves
michaelm@5116 75 self = [super initWithFrame: rect];
michaelm@5116 76 if (self == nil) return self;
aniyogi@14038 77
michaelm@5116 78 m_cPlatformView = cPlatformView;
michaelm@5116 79 fInputMethodLOCKABLE = NULL;
michaelm@5116 80 fKeyEventsNeeded = NO;
michaelm@5116 81 fProcessingKeystroke = NO;
aniyogi@14038 82
michaelm@5116 83 fEnablePressAndHold = shouldUsePressAndHold();
michaelm@5116 84 fInPressAndHold = NO;
michaelm@5116 85 fPAHNeedsToSelect = NO;
aniyogi@14038 86
alexsch@5312 87 mouseIsOver = NO;
alexsch@5784 88 [self resetTrackingArea];
serb@6219 89 [self setAutoresizesSubviews:NO];
aniyogi@14038 90
michaelm@5116 91 if (windowLayer != nil) {
michaelm@5116 92 self.cglLayer = windowLayer;
serb@6037 93 //Layer hosting view
serb@6037 94 [self setLayer: cglLayer];
michaelm@5116 95 [self setWantsLayer: YES];
serb@6037 96 //Layer backed view
serb@6037 97 //[self.layer addSublayer: (CALayer *)cglLayer];
serb@6037 98 //[self setLayerContentsRedrawPolicy: NSViewLayerContentsRedrawDuringViewResize];
serb@6037 99 //[self setLayerContentsPlacement: NSViewLayerContentsPlacementTopLeft];
serb@6037 100 //[self setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable];
aniyogi@14038 101
michaelm@5116 102 #ifdef REMOTELAYER
michaelm@5116 103 CGLLayer *parentLayer = (CGLLayer*)self.cglLayer;
michaelm@5116 104 parentLayer.parentLayer = NULL;
michaelm@5116 105 parentLayer.remoteLayer = NULL;
michaelm@5116 106 if (JRSRemotePort != 0 && remoteSocketFD > 0) {
michaelm@5116 107 CGLLayer *remoteLayer = [[CGLLayer alloc] initWithJavaLayer: parentLayer.javaLayer];
michaelm@5116 108 remoteLayer.target = GL_TEXTURE_2D;
michaelm@5116 109 NSLog(@"Creating Parent=%p, Remote=%p", parentLayer, remoteLayer);
michaelm@5116 110 parentLayer.remoteLayer = remoteLayer;
michaelm@5116 111 remoteLayer.parentLayer = parentLayer;
michaelm@5116 112 remoteLayer.remoteLayer = NULL;
michaelm@5116 113 remoteLayer.jrsRemoteLayer = [remoteLayer createRemoteLayerBoundTo:JRSRemotePort];
pchelko@9614 114 [remoteLayer retain]; // REMIND
michaelm@5116 115 remoteLayer.frame = CGRectMake(0, 0, 720, 500); // REMIND
pchelko@9614 116 [remoteLayer.jrsRemoteLayer retain]; // REMIND
michaelm@5116 117 int layerID = [remoteLayer.jrsRemoteLayer layerID];
michaelm@5116 118 NSLog(@"layer id to send = %d", layerID);
michaelm@5116 119 sendLayerID(layerID);
michaelm@5116 120 }
michaelm@5116 121 #endif /* REMOTELAYER */
michaelm@5116 122 }
aniyogi@14038 123
michaelm@5116 124 return self;
michaelm@5116 125 }
michaelm@5116 126
michaelm@5116 127 - (void) dealloc {
aniyogi@14038 128 AWT_ASSERT_APPKIT_THREAD;
aniyogi@14038 129
michaelm@5116 130 self.cglLayer = nil;
aniyogi@14038 131
pchelko@8125 132 JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
ant@14365 133 (*env)->DeleteWeakGlobalRef(env, m_cPlatformView);
michaelm@5116 134 m_cPlatformView = NULL;
aniyogi@14038 135
michaelm@5116 136 if (fInputMethodLOCKABLE != NULL)
michaelm@5116 137 {
michaelm@5116 138 JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
aniyogi@14038 139
michaelm@5116 140 JNFDeleteGlobalRef(env, fInputMethodLOCKABLE);
michaelm@5116 141 fInputMethodLOCKABLE = NULL;
michaelm@5116 142 }
aniyogi@14038 143
aniyogi@14038 144
michaelm@5116 145 [super dealloc];
michaelm@5116 146 }
michaelm@5116 147
michaelm@5116 148 - (void) viewDidMoveToWindow {
aniyogi@14038 149 AWT_ASSERT_APPKIT_THREAD;
aniyogi@14038 150
michaelm@5116 151 [AWTToolkit eventCountPlusPlus];
aniyogi@14038 152
michaelm@5116 153 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^() {
michaelm@5116 154 [[self window] makeFirstResponder: self];
michaelm@5116 155 }];
michaelm@5116 156 if ([self window] != NULL) {
alexsch@5784 157 [self resetTrackingArea];
michaelm@5116 158 }
michaelm@5116 159 }
michaelm@5116 160
michaelm@5116 161 - (BOOL) acceptsFirstMouse: (NSEvent *)event {
michaelm@5116 162 return YES;
michaelm@5116 163 }
michaelm@5116 164
michaelm@5116 165 - (BOOL) acceptsFirstResponder {
michaelm@5116 166 return YES;
michaelm@5116 167 }
michaelm@5116 168
michaelm@5116 169 - (BOOL) becomeFirstResponder {
michaelm@5116 170 return YES;
michaelm@5116 171 }
michaelm@5116 172
michaelm@5116 173 - (BOOL) preservesContentDuringLiveResize {
michaelm@5116 174 return YES;
michaelm@5116 175 }
michaelm@5116 176
michaelm@5116 177 /*
michaelm@5116 178 * Automatically triggered functions.
michaelm@5116 179 */
michaelm@5116 180
serb@6219 181 - (void)resizeWithOldSuperviewSize:(NSSize)oldBoundsSize {
serb@6219 182 [super resizeWithOldSuperviewSize: oldBoundsSize];
serb@6219 183 [self deliverResize: [self frame]];
serb@6219 184 }
serb@6219 185
michaelm@5116 186 /*
michaelm@5116 187 * MouseEvents support
michaelm@5116 188 */
michaelm@5116 189
michaelm@5116 190 - (void) mouseDown: (NSEvent *)event {
michaelm@5116 191 NSInputManager *inputManager = [NSInputManager currentInputManager];
michaelm@5116 192 if ([inputManager wantsToHandleMouseEvents]) {
michaelm@5116 193 #if IM_DEBUG
michaelm@5116 194 NSLog(@"-> IM wants to handle event");
michaelm@5116 195 #endif
michaelm@5116 196 if (![inputManager handleMouseEvent:event]) {
michaelm@5116 197 [self deliverJavaMouseEvent: event];
michaelm@5116 198 } else {
michaelm@5116 199 #if IM_DEBUG
michaelm@5116 200 NSLog(@"-> Event was handled.");
michaelm@5116 201 #endif
michaelm@5116 202 }
michaelm@5116 203 } else {
kizune@5526 204 #if IM_DEBUG
michaelm@5116 205 NSLog(@"-> IM does not want to handle event");
kizune@5526 206 #endif
michaelm@5116 207 [self deliverJavaMouseEvent: event];
michaelm@5116 208 }
michaelm@5116 209 }
michaelm@5116 210
michaelm@5116 211 - (void) mouseUp: (NSEvent *)event {
michaelm@5116 212 [self deliverJavaMouseEvent: event];
michaelm@5116 213 }
michaelm@5116 214
michaelm@5116 215 - (void) rightMouseDown: (NSEvent *)event {
michaelm@5116 216 [self deliverJavaMouseEvent: event];
michaelm@5116 217 }
michaelm@5116 218
michaelm@5116 219 - (void) rightMouseUp: (NSEvent *)event {
michaelm@5116 220 [self deliverJavaMouseEvent: event];
michaelm@5116 221 }
michaelm@5116 222
michaelm@5116 223 - (void) otherMouseDown: (NSEvent *)event {
michaelm@5116 224 [self deliverJavaMouseEvent: event];
michaelm@5116 225 }
michaelm@5116 226
michaelm@5116 227 - (void) otherMouseUp: (NSEvent *)event {
michaelm@5116 228 [self deliverJavaMouseEvent: event];
michaelm@5116 229 }
michaelm@5116 230
michaelm@5116 231 - (void) mouseMoved: (NSEvent *)event {
michaelm@5116 232 // TODO: better way to redirect move events to the "under" view
pchelko@6623 233
michaelm@5116 234 NSPoint eventLocation = [event locationInWindow];
michaelm@5116 235 NSPoint localPoint = [self convertPoint: eventLocation fromView: nil];
aniyogi@14038 236
michaelm@5116 237 if ([self mouse: localPoint inRect: [self bounds]]) {
michaelm@5116 238 [self deliverJavaMouseEvent: event];
michaelm@5116 239 } else {
michaelm@5116 240 [[self nextResponder] mouseDown:event];
michaelm@5116 241 }
michaelm@5116 242 }
michaelm@5116 243
michaelm@5116 244 - (void) mouseDragged: (NSEvent *)event {
michaelm@5116 245 [self deliverJavaMouseEvent: event];
michaelm@5116 246 }
michaelm@5116 247
michaelm@5116 248 - (void) rightMouseDragged: (NSEvent *)event {
michaelm@5116 249 [self deliverJavaMouseEvent: event];
michaelm@5116 250 }
michaelm@5116 251
michaelm@5116 252 - (void) otherMouseDragged: (NSEvent *)event {
michaelm@5116 253 [self deliverJavaMouseEvent: event];
michaelm@5116 254 }
michaelm@5116 255
michaelm@5116 256 - (void) mouseEntered: (NSEvent *)event {
michaelm@5116 257 [[self window] setAcceptsMouseMovedEvents:YES];
michaelm@5116 258 //[[self window] makeFirstResponder:self];
michaelm@5116 259 [self deliverJavaMouseEvent: event];
michaelm@5116 260 }
michaelm@5116 261
michaelm@5116 262 - (void) mouseExited: (NSEvent *)event {
michaelm@5116 263 [[self window] setAcceptsMouseMovedEvents:NO];
michaelm@5116 264 [self deliverJavaMouseEvent: event];
michaelm@5116 265 //Restore the cursor back.
michaelm@5116 266 //[CCursorManager _setCursor: [NSCursor arrowCursor]];
michaelm@5116 267 }
michaelm@5116 268
michaelm@5116 269 - (void) scrollWheel: (NSEvent*) event {
michaelm@5116 270 [self deliverJavaMouseEvent: event];
michaelm@5116 271 }
michaelm@5116 272
michaelm@5116 273 /*
michaelm@5116 274 * KeyEvents support
michaelm@5116 275 */
michaelm@5116 276
michaelm@5116 277 - (void) keyDown: (NSEvent *)event {
michaelm@5116 278 fProcessingKeystroke = YES;
michaelm@5116 279 fKeyEventsNeeded = YES;
aniyogi@14038 280
michaelm@5116 281 // Allow TSM to look at the event and potentially send back NSTextInputClient messages.
michaelm@5116 282 [self interpretKeyEvents:[NSArray arrayWithObject:event]];
aniyogi@14038 283
michaelm@5116 284 if (fEnablePressAndHold && [event willBeHandledByComplexInputMethod]) {
michaelm@5116 285 fProcessingKeystroke = NO;
michaelm@5116 286 if (!fInPressAndHold) {
michaelm@5116 287 fInPressAndHold = YES;
michaelm@5116 288 fPAHNeedsToSelect = YES;
michaelm@5116 289 }
michaelm@5116 290 return;
michaelm@5116 291 }
aniyogi@14038 292
alexsch@5899 293 NSString *eventCharacters = [event characters];
alexsch@5899 294 BOOL isDeadKey = (eventCharacters != nil && [eventCharacters length] == 0);
aniyogi@14038 295
alexsch@5899 296 if ((![self hasMarkedText] && fKeyEventsNeeded) || isDeadKey) {
michaelm@5116 297 [self deliverJavaKeyEventHelper: event];
michaelm@5116 298 }
aniyogi@14038 299
michaelm@5116 300 fProcessingKeystroke = NO;
michaelm@5116 301 }
michaelm@5116 302
michaelm@5116 303 - (void) keyUp: (NSEvent *)event {
michaelm@5116 304 [self deliverJavaKeyEventHelper: event];
michaelm@5116 305 }
michaelm@5116 306
michaelm@5116 307 - (void) flagsChanged: (NSEvent *)event {
michaelm@5116 308 [self deliverJavaKeyEventHelper: event];
michaelm@5116 309 }
michaelm@5116 310
michaelm@5116 311 - (BOOL) performKeyEquivalent: (NSEvent *) event {
aniyogi@14038 312 // if IM is active key events should be ignored
anashaty@11698 313 if (![self hasMarkedText] && !fInPressAndHold) {
anashaty@11698 314 [self deliverJavaKeyEventHelper: event];
anashaty@11698 315 }
aniyogi@14038 316
aniyogi@14038 317 // Workaround for 8020209: special case for "Cmd =" and "Cmd ."
aniyogi@14038 318 // because Cocoa calls performKeyEquivalent twice for these keystrokes
aniyogi@14038 319 NSUInteger modFlags = [event modifierFlags] &
aniyogi@14038 320 (NSCommandKeyMask | NSAlternateKeyMask | NSShiftKeyMask | NSControlKeyMask);
leonidr@8555 321 if (modFlags == NSCommandKeyMask) {
leonidr@8555 322 NSString *eventChars = [event charactersIgnoringModifiers];
leonidr@8555 323 if ([eventChars length] == 1) {
leonidr@8555 324 unichar ch = [eventChars characterAtIndex:0];
leonidr@8555 325 if (ch == '=' || ch == '.') {
leonidr@8555 326 [[NSApp mainMenu] performKeyEquivalent: event];
leonidr@8555 327 return YES;
leonidr@8555 328 }
leonidr@8555 329 }
aniyogi@14038 330
leonidr@8555 331 }
aniyogi@14038 332
michaelm@5116 333 return NO;
michaelm@5116 334 }
michaelm@5116 335
michaelm@5116 336 /**
michaelm@5116 337 * Utility methods and accessors
michaelm@5116 338 */
michaelm@5116 339
michaelm@5116 340 -(void) deliverJavaMouseEvent: (NSEvent *) event {
leonidr@5351 341 BOOL isEnabled = YES;
leonidr@5351 342 NSWindow* window = [self window];
anthony@5359 343 if ([window isKindOfClass: [AWTWindow_Panel class]] || [window isKindOfClass: [AWTWindow_Normal class]]) {
anthony@5359 344 isEnabled = [(AWTWindow*)[window delegate] isEnabled];
leonidr@5351 345 }
aniyogi@14038 346
leonidr@5351 347 if (!isEnabled) {
leonidr@5351 348 return;
leonidr@5351 349 }
aniyogi@14038 350
leonidr@5351 351 NSEventType type = [event type];
aniyogi@14038 352
alexsch@5312 353 // check synthesized mouse entered/exited events
alexsch@5312 354 if ((type == NSMouseEntered && mouseIsOver) || (type == NSMouseExited && !mouseIsOver)) {
alexsch@5312 355 return;
alexsch@5312 356 }else if ((type == NSMouseEntered && !mouseIsOver) || (type == NSMouseExited && mouseIsOver)) {
alexsch@5312 357 mouseIsOver = !mouseIsOver;
alexsch@5312 358 }
aniyogi@14038 359
michaelm@5116 360 [AWTToolkit eventCountPlusPlus];
aniyogi@14038 361
michaelm@5116 362 JNIEnv *env = [ThreadUtilities getJNIEnv];
aniyogi@14038 363
michaelm@5116 364 NSPoint eventLocation = [event locationInWindow];
michaelm@5116 365 NSPoint localPoint = [self convertPoint: eventLocation fromView: nil];
michaelm@5116 366 NSPoint absP = [NSEvent mouseLocation];
aniyogi@14038 367
michaelm@5116 368 // Convert global numbers between Cocoa's coordinate system and Java.
michaelm@5116 369 // TODO: need consitent way for doing that both with global as well as with local coordinates.
michaelm@5116 370 // The reason to do it here is one more native method for getting screen dimension otherwise.
aniyogi@14038 371
azvegint@9468 372 NSRect screenRect = [[[NSScreen screens] objectAtIndex:0] frame];
michaelm@5116 373 absP.y = screenRect.size.height - absP.y;
michaelm@5116 374 jint clickCount;
aniyogi@14038 375
michaelm@5116 376 if (type == NSMouseEntered ||
michaelm@5116 377 type == NSMouseExited ||
michaelm@5116 378 type == NSScrollWheel ||
michaelm@5116 379 type == NSMouseMoved) {
michaelm@5116 380 clickCount = 0;
michaelm@5116 381 } else {
michaelm@5116 382 clickCount = [event clickCount];
michaelm@5116 383 }
aniyogi@14038 384
pchelko@9420 385 static JNF_CLASS_CACHE(jc_NSEvent, "sun/lwawt/macosx/NSEvent");
michaelm@5116 386 static JNF_CTOR_CACHE(jctor_NSEvent, jc_NSEvent, "(IIIIIIIIDD)V");
michaelm@5116 387 jobject jEvent = JNFNewObject(env, jctor_NSEvent,
michaelm@5116 388 [event type],
michaelm@5116 389 [event modifierFlags],
michaelm@5116 390 clickCount,
michaelm@5116 391 [event buttonNumber],
michaelm@5116 392 (jint)localPoint.x, (jint)localPoint.y,
michaelm@5116 393 (jint)absP.x, (jint)absP.y,
michaelm@5116 394 [event deltaY],
michaelm@5116 395 [event deltaX]);
pchelko@9987 396 CHECK_NULL(jEvent);
aniyogi@14038 397
michaelm@5116 398 static JNF_CLASS_CACHE(jc_PlatformView, "sun/lwawt/macosx/CPlatformView");
pchelko@9420 399 static JNF_MEMBER_CACHE(jm_deliverMouseEvent, jc_PlatformView, "deliverMouseEvent", "(Lsun/lwawt/macosx/NSEvent;)V");
ant@14365 400 jobject jlocal = (*env)->NewLocalRef(env, m_cPlatformView);
ant@14365 401 if (!(*env)->IsSameObject(env, jlocal, NULL)) {
ant@14365 402 JNFCallVoidMethod(env, jlocal, jm_deliverMouseEvent, jEvent);
ant@14365 403 (*env)->DeleteLocalRef(env, jlocal);
ant@14365 404 }
pchelko@9987 405 (*env)->DeleteLocalRef(env, jEvent);
michaelm@5116 406 }
michaelm@5116 407
alexsch@5784 408 - (void) resetTrackingArea {
alexsch@5784 409 if (rolloverTrackingArea != nil) {
alexsch@5784 410 [self removeTrackingArea:rolloverTrackingArea];
alexsch@5784 411 [rolloverTrackingArea release];
alexsch@5784 412 }
aniyogi@14038 413
pchelko@8120 414 int options = (NSTrackingActiveAlways | NSTrackingMouseEnteredAndExited |
alexsch@5784 415 NSTrackingMouseMoved | NSTrackingEnabledDuringMouseDrag);
aniyogi@14038 416
alexsch@5784 417 rolloverTrackingArea = [[NSTrackingArea alloc] initWithRect:[self visibleRect]
alexsch@5784 418 options: options
alexsch@5784 419 owner:self
alexsch@5784 420 userInfo:nil
alexsch@5784 421 ];
alexsch@5784 422 [self addTrackingArea:rolloverTrackingArea];
michaelm@5116 423 }
michaelm@5116 424
michaelm@5116 425 - (void)updateTrackingAreas {
michaelm@5116 426 [super updateTrackingAreas];
alexsch@5784 427 [self resetTrackingArea];
michaelm@5116 428 }
michaelm@5116 429
michaelm@5116 430 - (void) resetCursorRects {
michaelm@5116 431 [super resetCursorRects];
alexsch@5784 432 [self resetTrackingArea];
michaelm@5116 433 }
michaelm@5116 434
michaelm@5116 435 -(void) deliverJavaKeyEventHelper: (NSEvent *) event {
ant@5371 436 static NSEvent* sLastKeyEvent = nil;
ant@5371 437 if (event == sLastKeyEvent) {
ant@5370 438 // The event is repeatedly delivered by keyDown: after performKeyEquivalent:
ant@5370 439 return;
ant@5370 440 }
ant@5371 441 [sLastKeyEvent release];
ant@5371 442 sLastKeyEvent = [event retain];
aniyogi@14038 443
michaelm@5116 444 [AWTToolkit eventCountPlusPlus];
michaelm@5116 445 JNIEnv *env = [ThreadUtilities getJNIEnv];
aniyogi@14038 446
michaelm@5116 447 jstring characters = NULL;
anashaty@10139 448 jstring charactersIgnoringModifiers = NULL;
michaelm@5116 449 if ([event type] != NSFlagsChanged) {
michaelm@5116 450 characters = JNFNSToJavaString(env, [event characters]);
anashaty@10139 451 charactersIgnoringModifiers = JNFNSToJavaString(env, [event charactersIgnoringModifiers]);
michaelm@5116 452 }
aniyogi@14038 453
pchelko@9420 454 static JNF_CLASS_CACHE(jc_NSEvent, "sun/lwawt/macosx/NSEvent");
anashaty@10139 455 static JNF_CTOR_CACHE(jctor_NSEvent, jc_NSEvent, "(IISLjava/lang/String;Ljava/lang/String;)V");
pchelko@9987 456 jobject jEvent = JNFNewObject(env, jctor_NSEvent,
michaelm@5116 457 [event type],
michaelm@5116 458 [event modifierFlags],
michaelm@5116 459 [event keyCode],
anashaty@10139 460 characters,
anashaty@10139 461 charactersIgnoringModifiers);
pchelko@9987 462 CHECK_NULL(jEvent);
aniyogi@14038 463
michaelm@5116 464 static JNF_CLASS_CACHE(jc_PlatformView, "sun/lwawt/macosx/CPlatformView");
michaelm@5116 465 static JNF_MEMBER_CACHE(jm_deliverKeyEvent, jc_PlatformView,
pchelko@9420 466 "deliverKeyEvent", "(Lsun/lwawt/macosx/NSEvent;)V");
ant@14365 467 jobject jlocal = (*env)->NewLocalRef(env, m_cPlatformView);
ant@14365 468 if (!(*env)->IsSameObject(env, jlocal, NULL)) {
ant@14365 469 JNFCallVoidMethod(env, jlocal, jm_deliverKeyEvent, jEvent);
ant@14365 470 (*env)->DeleteLocalRef(env, jlocal);
ant@14365 471 }
michaelm@5116 472 if (characters != NULL) {
michaelm@5116 473 (*env)->DeleteLocalRef(env, characters);
michaelm@5116 474 }
pchelko@9987 475 (*env)->DeleteLocalRef(env, jEvent);
michaelm@5116 476 }
michaelm@5116 477
serb@6219 478 -(void) deliverResize: (NSRect) rect {
serb@6219 479 jint x = (jint) rect.origin.x;
serb@6219 480 jint y = (jint) rect.origin.y;
serb@6219 481 jint w = (jint) rect.size.width;
serb@6219 482 jint h = (jint) rect.size.height;
serb@6219 483 JNIEnv *env = [ThreadUtilities getJNIEnv];
serb@6219 484 static JNF_CLASS_CACHE(jc_PlatformView, "sun/lwawt/macosx/CPlatformView");
serb@6219 485 static JNF_MEMBER_CACHE(jm_deliverResize, jc_PlatformView, "deliverResize", "(IIII)V");
ant@14365 486
ant@14365 487 jobject jlocal = (*env)->NewLocalRef(env, m_cPlatformView);
ant@14365 488 if (!(*env)->IsSameObject(env, jlocal, NULL)) {
ant@14365 489 JNFCallVoidMethod(env, jlocal, jm_deliverResize, x,y,w,h);
ant@14365 490 (*env)->DeleteLocalRef(env, jlocal);
ant@14365 491 }
serb@6219 492 }
serb@6219 493
serb@6219 494
michaelm@5116 495 - (void) drawRect:(NSRect)dirtyRect {
aniyogi@14038 496 AWT_ASSERT_APPKIT_THREAD;
aniyogi@14038 497
michaelm@5116 498 [super drawRect:dirtyRect];
michaelm@5116 499 JNIEnv *env = [ThreadUtilities getJNIEnv];
michaelm@5116 500 if (env != NULL) {
aniyogi@14038 501 /*
aniyogi@14038 502 if ([self inLiveResize]) {
aniyogi@14038 503 NSRect rs[4];
aniyogi@14038 504 NSInteger count;
aniyogi@14038 505 [self getRectsExposedDuringLiveResize:rs count:&count];
aniyogi@14038 506 for (int i = 0; i < count; i++) {
aniyogi@14038 507 JNU_CallMethodByName(env, NULL, [m_awtWindow cPlatformView],
aniyogi@14038 508 "deliverWindowDidExposeEvent", "(FFFF)V",
aniyogi@14038 509 (jfloat)rs[i].origin.x, (jfloat)rs[i].origin.y,
aniyogi@14038 510 (jfloat)rs[i].size.width, (jfloat)rs[i].size.height);
aniyogi@14038 511 if ((*env)->ExceptionOccurred(env)) {
aniyogi@14038 512 (*env)->ExceptionDescribe(env);
aniyogi@14038 513 (*env)->ExceptionClear(env);
aniyogi@14038 514 }
aniyogi@14038 515 }
aniyogi@14038 516 } else {
aniyogi@14038 517 */
michaelm@5116 518 static JNF_CLASS_CACHE(jc_CPlatformView, "sun/lwawt/macosx/CPlatformView");
michaelm@5116 519 static JNF_MEMBER_CACHE(jm_deliverWindowDidExposeEvent, jc_CPlatformView, "deliverWindowDidExposeEvent", "()V");
ant@14365 520 jobject jlocal = (*env)->NewLocalRef(env, m_cPlatformView);
ant@14365 521 if (!(*env)->IsSameObject(env, jlocal, NULL)) {
ant@14365 522 JNFCallVoidMethod(env, jlocal, jm_deliverWindowDidExposeEvent);
ant@14365 523 (*env)->DeleteLocalRef(env, jlocal);
ant@14365 524 }
aniyogi@14038 525 /*
aniyogi@14038 526 }
aniyogi@14038 527 */
michaelm@5116 528 }
michaelm@5116 529 }
michaelm@5116 530
alitvinov@13095 531 -(BOOL) isCodePointInUnicodeBlockNeedingIMEvent: (unichar) codePoint {
dmarkov@15037 532 if (((codePoint >= 0x3000) && (codePoint <= 0x303F)) ||
dmarkov@15037 533 ((codePoint >= 0xFF00) && (codePoint <= 0xFFEF))) {
dmarkov@15037 534 // Code point is in 'CJK Symbols and Punctuation' or
dmarkov@15037 535 // 'Halfwidth and Fullwidth Forms' Unicode block.
alitvinov@13095 536 return YES;
alitvinov@13095 537 }
alitvinov@13095 538 return NO;
alitvinov@13095 539 }
alitvinov@13095 540
aniyogi@14038 541 -(NSMutableString *) parseString : (id) complexString {
aniyogi@14038 542 if ([complexString isKindOfClass:[NSString class]]) {
aniyogi@14038 543 return [complexString mutableCopy];
aniyogi@14038 544 }
aniyogi@14038 545 else {
aniyogi@14038 546 return [complexString mutableString];
aniyogi@14038 547 }
aniyogi@14038 548 }
aniyogi@14038 549
michaelm@5116 550 // NSAccessibility support
michaelm@5116 551 - (jobject)awtComponent:(JNIEnv*)env
michaelm@5116 552 {
michaelm@5116 553 static JNF_CLASS_CACHE(jc_CPlatformView, "sun/lwawt/macosx/CPlatformView");
michaelm@5116 554 static JNF_MEMBER_CACHE(jf_Peer, jc_CPlatformView, "peer", "Lsun/lwawt/LWWindowPeer;");
michaelm@5116 555 if ((env == NULL) || (m_cPlatformView == NULL)) {
michaelm@5116 556 NSLog(@"Apple AWT : Error AWTView:awtComponent given bad parameters.");
michaelm@5116 557 if (env != NULL)
michaelm@5116 558 {
michaelm@5116 559 JNFDumpJavaStack(env);
michaelm@5116 560 }
michaelm@5116 561 return NULL;
michaelm@5116 562 }
ant@14365 563
ant@14365 564 jobject peer = NULL;
ant@14365 565 jobject jlocal = (*env)->NewLocalRef(env, m_cPlatformView);
ant@14365 566 if (!(*env)->IsSameObject(env, jlocal, NULL)) {
ant@14365 567 peer = JNFGetObjectField(env, jlocal, jf_Peer);
ant@14365 568 (*env)->DeleteLocalRef(env, jlocal);
ant@14365 569 }
michaelm@5116 570 static JNF_CLASS_CACHE(jc_LWWindowPeer, "sun/lwawt/LWWindowPeer");
michaelm@5116 571 static JNF_MEMBER_CACHE(jf_Target, jc_LWWindowPeer, "target", "Ljava/awt/Component;");
michaelm@5116 572 if (peer == NULL) {
michaelm@5116 573 NSLog(@"Apple AWT : Error AWTView:awtComponent got null peer from CPlatformView");
michaelm@5116 574 JNFDumpJavaStack(env);
michaelm@5116 575 return NULL;
michaelm@5116 576 }
ant@14365 577 jobject comp = JNFGetObjectField(env, peer, jf_Target);
ant@14365 578 (*env)->DeleteLocalRef(env, peer);
ant@14365 579 return comp;
ant@14365 580 }
ant@14365 581
ant@14365 582 + (AWTView *) awtView:(JNIEnv*)env ofAccessible:(jobject)jaccessible
ant@14365 583 {
ant@14365 584 static JNF_STATIC_MEMBER_CACHE(jm_getAWTView, sjc_CAccessibility, "getAWTView", "(Ljavax/accessibility/Accessible;)J");
ant@14365 585
ant@14365 586 jlong jptr = JNFCallStaticLongMethod(env, jm_getAWTView, jaccessible);
ant@14365 587 if (jptr == 0) return nil;
ant@14365 588
ant@14365 589 return (AWTView *)jlong_to_ptr(jptr);
michaelm@5116 590 }
michaelm@5116 591
michaelm@5116 592 - (id)getAxData:(JNIEnv*)env
michaelm@5116 593 {
ant@14365 594 jobject jcomponent = [self awtComponent:env];
ant@14365 595 id ax = [[[JavaComponentAccessibility alloc] initWithParent:self withEnv:env withAccessible:jcomponent withIndex:-1 withView:self withJavaRole:nil] autorelease];
ant@14365 596 (*env)->DeleteLocalRef(env, jcomponent);
ant@14365 597 return ax;
michaelm@5116 598 }
michaelm@5116 599
michaelm@5116 600 - (NSArray *)accessibilityAttributeNames
michaelm@5116 601 {
michaelm@5116 602 return [[super accessibilityAttributeNames] arrayByAddingObject:NSAccessibilityChildrenAttribute];
michaelm@5116 603 }
michaelm@5116 604
michaelm@5116 605 // NSAccessibility messages
michaelm@5116 606 // attribute methods
michaelm@5116 607 - (id)accessibilityAttributeValue:(NSString *)attribute
michaelm@5116 608 {
michaelm@5116 609 AWT_ASSERT_APPKIT_THREAD;
aniyogi@14038 610
michaelm@5116 611 if ([attribute isEqualToString:NSAccessibilityChildrenAttribute])
michaelm@5116 612 {
michaelm@5116 613 JNIEnv *env = [ThreadUtilities getJNIEnv];
aniyogi@14038 614
michaelm@5116 615 (*env)->PushLocalFrame(env, 4);
aniyogi@14038 616
michaelm@5116 617 id result = NSAccessibilityUnignoredChildrenForOnlyChild([self getAxData:env]);
aniyogi@14038 618
michaelm@5116 619 (*env)->PopLocalFrame(env, NULL);
aniyogi@14038 620
michaelm@5116 621 return result;
michaelm@5116 622 }
michaelm@5116 623 else
michaelm@5116 624 {
michaelm@5116 625 return [super accessibilityAttributeValue:attribute];
michaelm@5116 626 }
michaelm@5116 627 }
michaelm@5116 628 - (BOOL)accessibilityIsIgnored
michaelm@5116 629 {
michaelm@5116 630 return YES;
michaelm@5116 631 }
michaelm@5116 632
michaelm@5116 633 - (id)accessibilityHitTest:(NSPoint)point
michaelm@5116 634 {
michaelm@5116 635 AWT_ASSERT_APPKIT_THREAD;
michaelm@5116 636 JNIEnv *env = [ThreadUtilities getJNIEnv];
aniyogi@14038 637
michaelm@5116 638 (*env)->PushLocalFrame(env, 4);
aniyogi@14038 639
michaelm@5116 640 id result = [[self getAxData:env] accessibilityHitTest:point withEnv:env];
aniyogi@14038 641
michaelm@5116 642 (*env)->PopLocalFrame(env, NULL);
aniyogi@14038 643
michaelm@5116 644 return result;
michaelm@5116 645 }
michaelm@5116 646
michaelm@5116 647 - (id)accessibilityFocusedUIElement
michaelm@5116 648 {
michaelm@5116 649 AWT_ASSERT_APPKIT_THREAD;
aniyogi@14038 650
michaelm@5116 651 JNIEnv *env = [ThreadUtilities getJNIEnv];
aniyogi@14038 652
michaelm@5116 653 (*env)->PushLocalFrame(env, 4);
aniyogi@14038 654
michaelm@5116 655 id result = [[self getAxData:env] accessibilityFocusedUIElement];
aniyogi@14038 656
michaelm@5116 657 (*env)->PopLocalFrame(env, NULL);
aniyogi@14038 658
michaelm@5116 659 return result;
michaelm@5116 660 }
michaelm@5116 661
michaelm@5116 662 // --- Services menu support for lightweights ---
michaelm@5116 663
malenkov@8565 664 // finds the focused accessible element, and if it is a text element, obtains the text from it
michaelm@5116 665 - (NSString *)accessibleSelectedText
michaelm@5116 666 {
michaelm@5116 667 id focused = [self accessibilityFocusedUIElement];
michaelm@5116 668 if (![focused isKindOfClass:[JavaTextAccessibility class]]) return nil;
michaelm@5116 669 return [(JavaTextAccessibility *)focused accessibilitySelectedTextAttribute];
michaelm@5116 670 }
michaelm@5116 671
michaelm@5116 672 // same as above, but converts to RTFD
michaelm@5116 673 - (NSData *)accessibleSelectedTextAsRTFD
michaelm@5116 674 {
michaelm@5116 675 NSString *selectedText = [self accessibleSelectedText];
michaelm@5116 676 NSAttributedString *styledText = [[NSAttributedString alloc] initWithString:selectedText];
serb@13887 677 NSData *rtfdData = [styledText RTFDFromRange:NSMakeRange(0, [styledText length])
aniyogi@14038 678 documentAttributes:
aniyogi@14038 679 @{NSDocumentTypeDocumentAttribute: NSRTFTextDocumentType}];
michaelm@5116 680 [styledText release];
michaelm@5116 681 return rtfdData;
michaelm@5116 682 }
michaelm@5116 683
malenkov@8565 684 // finds the focused accessible element, and if it is a text element, sets the text in it
michaelm@5116 685 - (BOOL)replaceAccessibleTextSelection:(NSString *)text
michaelm@5116 686 {
michaelm@5116 687 id focused = [self accessibilityFocusedUIElement];
michaelm@5116 688 if (![focused isKindOfClass:[JavaTextAccessibility class]]) return NO;
michaelm@5116 689 [(JavaTextAccessibility *)focused accessibilitySetSelectedTextAttribute:text];
michaelm@5116 690 return YES;
michaelm@5116 691 }
michaelm@5116 692
michaelm@5116 693 // called for each service in the Services menu - only handle text for now
michaelm@5116 694 - (id)validRequestorForSendType:(NSString *)sendType returnType:(NSString *)returnType
michaelm@5116 695 {
michaelm@5116 696 if ([[self window] firstResponder] != self) return nil; // let AWT components handle themselves
aniyogi@14038 697
michaelm@5116 698 if ([sendType isEqual:NSStringPboardType] || [returnType isEqual:NSStringPboardType]) {
michaelm@5116 699 NSString *selectedText = [self accessibleSelectedText];
michaelm@5116 700 if (selectedText) return self;
michaelm@5116 701 }
aniyogi@14038 702
michaelm@5116 703 return nil;
michaelm@5116 704 }
michaelm@5116 705
michaelm@5116 706 // fetch text from Java and hand off to the service
michaelm@5116 707 - (BOOL)writeSelectionToPasteboard:(NSPasteboard *)pboard types:(NSArray *)types
michaelm@5116 708 {
michaelm@5116 709 if ([types containsObject:NSStringPboardType])
michaelm@5116 710 {
michaelm@5116 711 [pboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
michaelm@5116 712 return [pboard setString:[self accessibleSelectedText] forType:NSStringPboardType];
michaelm@5116 713 }
aniyogi@14038 714
michaelm@5116 715 if ([types containsObject:NSRTFDPboardType])
michaelm@5116 716 {
michaelm@5116 717 [pboard declareTypes:[NSArray arrayWithObject:NSRTFDPboardType] owner:nil];
michaelm@5116 718 return [pboard setData:[self accessibleSelectedTextAsRTFD] forType:NSRTFDPboardType];
michaelm@5116 719 }
aniyogi@14038 720
michaelm@5116 721 return NO;
michaelm@5116 722 }
michaelm@5116 723
michaelm@5116 724 // write text back to Java from the service
michaelm@5116 725 - (BOOL)readSelectionFromPasteboard:(NSPasteboard *)pboard
michaelm@5116 726 {
michaelm@5116 727 if ([[pboard types] containsObject:NSStringPboardType])
michaelm@5116 728 {
michaelm@5116 729 NSString *text = [pboard stringForType:NSStringPboardType];
michaelm@5116 730 return [self replaceAccessibleTextSelection:text];
michaelm@5116 731 }
aniyogi@14038 732
michaelm@5116 733 if ([[pboard types] containsObject:NSRTFDPboardType])
michaelm@5116 734 {
michaelm@5116 735 NSData *rtfdData = [pboard dataForType:NSRTFDPboardType];
serb@13887 736 NSAttributedString *styledText = [[NSAttributedString alloc] initWithRTFD:rtfdData documentAttributes:NULL];
michaelm@5116 737 NSString *text = [styledText string];
michaelm@5116 738 [styledText release];
aniyogi@14038 739
michaelm@5116 740 return [self replaceAccessibleTextSelection:text];
michaelm@5116 741 }
aniyogi@14038 742
michaelm@5116 743 return NO;
michaelm@5116 744 }
michaelm@5116 745
michaelm@5116 746
michaelm@5116 747 -(void) setDragSource:(CDragSource *)source {
michaelm@5116 748 self._dragSource = source;
michaelm@5116 749 }
michaelm@5116 750
michaelm@5116 751
michaelm@5116 752 - (void) setDropTarget:(CDropTarget *)target {
michaelm@5116 753 self._dropTarget = target;
pchelko@6623 754 [ThreadUtilities performOnMainThread:@selector(controlModelControlValid) on:self._dropTarget withObject:nil waitUntilDone:YES];
michaelm@5116 755 }
michaelm@5116 756
michaelm@5116 757 /******************************** BEGIN NSDraggingSource Interface ********************************/
michaelm@5116 758
michaelm@5116 759 - (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)flag
michaelm@5116 760 {
michaelm@5116 761 // If draggingSource is nil route the message to the superclass (if responding to the selector):
michaelm@5116 762 CDragSource *dragSource = self._dragSource;
michaelm@5116 763 NSDragOperation dragOp = NSDragOperationNone;
aniyogi@14038 764
michaelm@5116 765 if (dragSource != nil)
michaelm@5116 766 dragOp = [dragSource draggingSourceOperationMaskForLocal:flag];
michaelm@5116 767 else if ([super respondsToSelector:@selector(draggingSourceOperationMaskForLocal:)])
michaelm@5116 768 dragOp = [super draggingSourceOperationMaskForLocal:flag];
aniyogi@14038 769
michaelm@5116 770 return dragOp;
michaelm@5116 771 }
michaelm@5116 772
michaelm@5116 773 - (NSArray *)namesOfPromisedFilesDroppedAtDestination:(NSURL *)dropDestination
michaelm@5116 774 {
michaelm@5116 775 // If draggingSource is nil route the message to the superclass (if responding to the selector):
michaelm@5116 776 CDragSource *dragSource = self._dragSource;
michaelm@5116 777 NSArray* array = nil;
aniyogi@14038 778
michaelm@5116 779 if (dragSource != nil)
michaelm@5116 780 array = [dragSource namesOfPromisedFilesDroppedAtDestination:dropDestination];
michaelm@5116 781 else if ([super respondsToSelector:@selector(namesOfPromisedFilesDroppedAtDestination:)])
michaelm@5116 782 array = [super namesOfPromisedFilesDroppedAtDestination:dropDestination];
aniyogi@14038 783
michaelm@5116 784 return array;
michaelm@5116 785 }
michaelm@5116 786
michaelm@5116 787 - (void)draggedImage:(NSImage *)image beganAt:(NSPoint)screenPoint
michaelm@5116 788 {
michaelm@5116 789 // If draggingSource is nil route the message to the superclass (if responding to the selector):
michaelm@5116 790 CDragSource *dragSource = self._dragSource;
aniyogi@14038 791
michaelm@5116 792 if (dragSource != nil)
michaelm@5116 793 [dragSource draggedImage:image beganAt:screenPoint];
michaelm@5116 794 else if ([super respondsToSelector:@selector(draggedImage::)])
michaelm@5116 795 [super draggedImage:image beganAt:screenPoint];
michaelm@5116 796 }
michaelm@5116 797
michaelm@5116 798 - (void)draggedImage:(NSImage *)image endedAt:(NSPoint)screenPoint operation:(NSDragOperation)operation
michaelm@5116 799 {
michaelm@5116 800 // If draggingSource is nil route the message to the superclass (if responding to the selector):
michaelm@5116 801 CDragSource *dragSource = self._dragSource;
aniyogi@14038 802
michaelm@5116 803 if (dragSource != nil)
michaelm@5116 804 [dragSource draggedImage:image endedAt:screenPoint operation:operation];
michaelm@5116 805 else if ([super respondsToSelector:@selector(draggedImage:::)])
michaelm@5116 806 [super draggedImage:image endedAt:screenPoint operation:operation];
michaelm@5116 807 }
michaelm@5116 808
michaelm@5116 809 - (void)draggedImage:(NSImage *)image movedTo:(NSPoint)screenPoint
michaelm@5116 810 {
michaelm@5116 811 // If draggingSource is nil route the message to the superclass (if responding to the selector):
michaelm@5116 812 CDragSource *dragSource = self._dragSource;
aniyogi@14038 813
michaelm@5116 814 if (dragSource != nil)
michaelm@5116 815 [dragSource draggedImage:image movedTo:screenPoint];
michaelm@5116 816 else if ([super respondsToSelector:@selector(draggedImage::)])
michaelm@5116 817 [super draggedImage:image movedTo:screenPoint];
michaelm@5116 818 }
michaelm@5116 819
michaelm@5116 820 - (BOOL)ignoreModifierKeysWhileDragging
michaelm@5116 821 {
michaelm@5116 822 // If draggingSource is nil route the message to the superclass (if responding to the selector):
michaelm@5116 823 CDragSource *dragSource = self._dragSource;
michaelm@5116 824 BOOL result = FALSE;
aniyogi@14038 825
michaelm@5116 826 if (dragSource != nil)
michaelm@5116 827 result = [dragSource ignoreModifierKeysWhileDragging];
michaelm@5116 828 else if ([super respondsToSelector:@selector(ignoreModifierKeysWhileDragging)])
michaelm@5116 829 result = [super ignoreModifierKeysWhileDragging];
aniyogi@14038 830
michaelm@5116 831 return result;
michaelm@5116 832 }
michaelm@5116 833
michaelm@5116 834 /******************************** END NSDraggingSource Interface ********************************/
michaelm@5116 835
michaelm@5116 836 /******************************** BEGIN NSDraggingDestination Interface ********************************/
michaelm@5116 837
michaelm@5116 838 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
michaelm@5116 839 {
michaelm@5116 840 // If draggingDestination is nil route the message to the superclass:
michaelm@5116 841 CDropTarget *dropTarget = self._dropTarget;
michaelm@5116 842 NSDragOperation dragOp = NSDragOperationNone;
aniyogi@14038 843
michaelm@5116 844 if (dropTarget != nil)
michaelm@5116 845 dragOp = [dropTarget draggingEntered:sender];
michaelm@5116 846 else if ([super respondsToSelector:@selector(draggingEntered:)])
michaelm@5116 847 dragOp = [super draggingEntered:sender];
aniyogi@14038 848
michaelm@5116 849 return dragOp;
michaelm@5116 850 }
michaelm@5116 851
michaelm@5116 852 - (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender
michaelm@5116 853 {
michaelm@5116 854 // If draggingDestination is nil route the message to the superclass:
michaelm@5116 855 CDropTarget *dropTarget = self._dropTarget;
michaelm@5116 856 NSDragOperation dragOp = NSDragOperationNone;
aniyogi@14038 857
michaelm@5116 858 if (dropTarget != nil)
michaelm@5116 859 dragOp = [dropTarget draggingUpdated:sender];
michaelm@5116 860 else if ([super respondsToSelector:@selector(draggingUpdated:)])
michaelm@5116 861 dragOp = [super draggingUpdated:sender];
aniyogi@14038 862
michaelm@5116 863 return dragOp;
michaelm@5116 864 }
michaelm@5116 865
michaelm@5116 866 - (void)draggingExited:(id <NSDraggingInfo>)sender
michaelm@5116 867 {
michaelm@5116 868 // If draggingDestination is nil route the message to the superclass:
michaelm@5116 869 CDropTarget *dropTarget = self._dropTarget;
aniyogi@14038 870
michaelm@5116 871 if (dropTarget != nil)
michaelm@5116 872 [dropTarget draggingExited:sender];
michaelm@5116 873 else if ([super respondsToSelector:@selector(draggingExited:)])
michaelm@5116 874 [super draggingExited:sender];
michaelm@5116 875 }
michaelm@5116 876
michaelm@5116 877 - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
michaelm@5116 878 {
michaelm@5116 879 // If draggingDestination is nil route the message to the superclass:
michaelm@5116 880 CDropTarget *dropTarget = self._dropTarget;
michaelm@5116 881 BOOL result = FALSE;
aniyogi@14038 882
michaelm@5116 883 if (dropTarget != nil)
michaelm@5116 884 result = [dropTarget prepareForDragOperation:sender];
michaelm@5116 885 else if ([super respondsToSelector:@selector(prepareForDragOperation:)])
michaelm@5116 886 result = [super prepareForDragOperation:sender];
aniyogi@14038 887
michaelm@5116 888 return result;
michaelm@5116 889 }
michaelm@5116 890
michaelm@5116 891 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
michaelm@5116 892 {
michaelm@5116 893 // If draggingDestination is nil route the message to the superclass:
michaelm@5116 894 CDropTarget *dropTarget = self._dropTarget;
michaelm@5116 895 BOOL result = FALSE;
aniyogi@14038 896
michaelm@5116 897 if (dropTarget != nil)
michaelm@5116 898 result = [dropTarget performDragOperation:sender];
michaelm@5116 899 else if ([super respondsToSelector:@selector(performDragOperation:)])
michaelm@5116 900 result = [super performDragOperation:sender];
aniyogi@14038 901
michaelm@5116 902 return result;
michaelm@5116 903 }
michaelm@5116 904
michaelm@5116 905 - (void)concludeDragOperation:(id <NSDraggingInfo>)sender
michaelm@5116 906 {
michaelm@5116 907 // If draggingDestination is nil route the message to the superclass:
michaelm@5116 908 CDropTarget *dropTarget = self._dropTarget;
aniyogi@14038 909
michaelm@5116 910 if (dropTarget != nil)
michaelm@5116 911 [dropTarget concludeDragOperation:sender];
michaelm@5116 912 else if ([super respondsToSelector:@selector(concludeDragOperation:)])
michaelm@5116 913 [super concludeDragOperation:sender];
michaelm@5116 914 }
michaelm@5116 915
michaelm@5116 916 - (void)draggingEnded:(id <NSDraggingInfo>)sender
michaelm@5116 917 {
michaelm@5116 918 // If draggingDestination is nil route the message to the superclass:
michaelm@5116 919 CDropTarget *dropTarget = self._dropTarget;
aniyogi@14038 920
michaelm@5116 921 if (dropTarget != nil)
michaelm@5116 922 [dropTarget draggingEnded:sender];
michaelm@5116 923 else if ([super respondsToSelector:@selector(draggingEnded:)])
michaelm@5116 924 [super draggingEnded:sender];
michaelm@5116 925 }
michaelm@5116 926
michaelm@5116 927 /******************************** END NSDraggingDestination Interface ********************************/
michaelm@5116 928
michaelm@5116 929 /******************************** BEGIN NSTextInputClient Protocol ********************************/
michaelm@5116 930
michaelm@5116 931
michaelm@5116 932 JNF_CLASS_CACHE(jc_CInputMethod, "sun/lwawt/macosx/CInputMethod");
michaelm@5116 933
michaelm@5116 934 - (void) insertText:(id)aString replacementRange:(NSRange)replacementRange
michaelm@5116 935 {
michaelm@5116 936 #ifdef IM_DEBUG
michaelm@5116 937 fprintf(stderr, "AWTView InputMethod Selector Called : [insertText]: %s\n", [aString UTF8String]);
michaelm@5116 938 #endif // IM_DEBUG
aniyogi@14038 939
michaelm@5116 940 if (fInputMethodLOCKABLE == NULL) {
michaelm@5116 941 return;
michaelm@5116 942 }
aniyogi@14038 943
michaelm@5116 944 // Insert happens at the end of PAH
michaelm@5116 945 fInPressAndHold = NO;
aniyogi@14038 946
michaelm@5116 947 // insertText gets called when the user commits text generated from an input method. It also gets
michaelm@5116 948 // called during ordinary input as well. We only need to send an input method event when we have marked
michaelm@5116 949 // text, or 'text in progress'. We also need to send the event if we get an insert text out of the blue!
michaelm@5116 950 // (i.e., when the user uses the Character palette or Inkwell), or when the string to insert is a complex
michaelm@5116 951 // Unicode value.
aniyogi@14038 952
aniyogi@14038 953 NSMutableString * useString = [self parseString:aString];
aniyogi@14038 954 NSUInteger utf16Length = [useString lengthOfBytesUsingEncoding:NSUTF16StringEncoding];
aniyogi@14038 955 NSUInteger utf8Length = [useString lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
alitvinov@13095 956 BOOL aStringIsComplex = NO;
alitvinov@13095 957 if ((utf16Length > 2) ||
aniyogi@14038 958 ((utf8Length > 1) && [self isCodePointInUnicodeBlockNeedingIMEvent:[useString characterAtIndex:0]])) {
alitvinov@13095 959 aStringIsComplex = YES;
alitvinov@13095 960 }
aniyogi@14038 961
alitvinov@13095 962 if ([self hasMarkedText] || !fProcessingKeystroke || aStringIsComplex) {
michaelm@5116 963 JNIEnv *env = [ThreadUtilities getJNIEnv];
aniyogi@14038 964
michaelm@5116 965 static JNF_MEMBER_CACHE(jm_selectPreviousGlyph, jc_CInputMethod, "selectPreviousGlyph", "()V");
michaelm@5116 966 // We need to select the previous glyph so that it is overwritten.
michaelm@5116 967 if (fPAHNeedsToSelect) {
michaelm@5116 968 JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_selectPreviousGlyph);
michaelm@5116 969 fPAHNeedsToSelect = NO;
michaelm@5116 970 }
aniyogi@14038 971
michaelm@5116 972 static JNF_MEMBER_CACHE(jm_insertText, jc_CInputMethod, "insertText", "(Ljava/lang/String;)V");
aniyogi@14038 973 jstring insertedText = JNFNSToJavaString(env, useString);
michaelm@5116 974 JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_insertText, insertedText); // AWT_THREADING Safe (AWTRunLoopMode)
michaelm@5116 975 (*env)->DeleteLocalRef(env, insertedText);
aniyogi@14038 976
michaelm@5116 977 // The input method event will create psuedo-key events for each character in the committed string.
michaelm@5116 978 // We also don't want to send the character that triggered the insertText, usually a return. [3337563]
michaelm@5116 979 fKeyEventsNeeded = NO;
michaelm@5116 980 }
michaelm@5116 981 fPAHNeedsToSelect = NO;
michaelm@5116 982 }
michaelm@5116 983
michaelm@5116 984 - (void) doCommandBySelector:(SEL)aSelector
michaelm@5116 985 {
michaelm@5116 986 #ifdef IM_DEBUG
michaelm@5116 987 fprintf(stderr, "AWTView InputMethod Selector Called : [doCommandBySelector]\n");
michaelm@5116 988 NSLog(@"%@", NSStringFromSelector(aSelector));
michaelm@5116 989 #endif // IM_DEBUG
michaelm@5116 990 if (@selector(insertNewline:) == aSelector || @selector(insertTab:) == aSelector || @selector(deleteBackward:) == aSelector)
michaelm@5116 991 {
michaelm@5116 992 fKeyEventsNeeded = YES;
michaelm@5116 993 }
michaelm@5116 994 }
michaelm@5116 995
michaelm@5116 996 // setMarkedText: cannot take a nil first argument. aString can be NSString or NSAttributedString
michaelm@5116 997 - (void) setMarkedText:(id)aString selectedRange:(NSRange)selectionRange replacementRange:(NSRange)replacementRange
michaelm@5116 998 {
michaelm@5116 999 if (!fInputMethodLOCKABLE)
michaelm@5116 1000 return;
aniyogi@14038 1001
michaelm@5116 1002 BOOL isAttributedString = [aString isKindOfClass:[NSAttributedString class]];
michaelm@5116 1003 NSAttributedString *attrString = (isAttributedString ? (NSAttributedString *)aString : nil);
michaelm@5116 1004 NSString *incomingString = (isAttributedString ? [aString string] : aString);
michaelm@5116 1005 #ifdef IM_DEBUG
michaelm@5116 1006 fprintf(stderr, "AWTView InputMethod Selector Called : [setMarkedText] \"%s\", loc=%lu, length=%lu\n", [incomingString UTF8String], (unsigned long)selectionRange.location, (unsigned long)selectionRange.length);
michaelm@5116 1007 #endif // IM_DEBUG
michaelm@5116 1008 static JNF_MEMBER_CACHE(jm_startIMUpdate, jc_CInputMethod, "startIMUpdate", "(Ljava/lang/String;)V");
michaelm@5116 1009 static JNF_MEMBER_CACHE(jm_addAttribute, jc_CInputMethod, "addAttribute", "(ZZII)V");
michaelm@5116 1010 static JNF_MEMBER_CACHE(jm_dispatchText, jc_CInputMethod, "dispatchText", "(IIZ)V");
michaelm@5116 1011 JNIEnv *env = [ThreadUtilities getJNIEnv];
aniyogi@14038 1012
michaelm@5116 1013 // NSInputContext already did the analysis of the TSM event and created attributes indicating
michaelm@5116 1014 // the underlining and color that should be done to the string. We need to look at the underline
michaelm@5116 1015 // style and color to determine what kind of Java hilighting needs to be done.
michaelm@5116 1016 jstring inProcessText = JNFNSToJavaString(env, incomingString);
michaelm@5116 1017 JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_startIMUpdate, inProcessText); // AWT_THREADING Safe (AWTRunLoopMode)
michaelm@5116 1018 (*env)->DeleteLocalRef(env, inProcessText);
aniyogi@14038 1019
michaelm@5116 1020 if (isAttributedString) {
michaelm@5116 1021 NSUInteger length;
michaelm@5116 1022 NSRange effectiveRange;
michaelm@5116 1023 NSDictionary *attributes;
michaelm@5116 1024 length = [attrString length];
michaelm@5116 1025 effectiveRange = NSMakeRange(0, 0);
michaelm@5116 1026 while (NSMaxRange(effectiveRange) < length) {
michaelm@5116 1027 attributes = [attrString attributesAtIndex:NSMaxRange(effectiveRange)
michaelm@5116 1028 effectiveRange:&effectiveRange];
michaelm@5116 1029 if (attributes) {
michaelm@5116 1030 BOOL isThickUnderline, isGray;
michaelm@5116 1031 NSNumber *underlineSizeObj =
michaelm@5116 1032 (NSNumber *)[attributes objectForKey:NSUnderlineStyleAttributeName];
michaelm@5116 1033 NSInteger underlineSize = [underlineSizeObj integerValue];
michaelm@5116 1034 isThickUnderline = (underlineSize > 1);
aniyogi@14038 1035
michaelm@5116 1036 NSColor *underlineColorObj =
michaelm@5116 1037 (NSColor *)[attributes objectForKey:NSUnderlineColorAttributeName];
michaelm@5116 1038 isGray = !([underlineColorObj isEqual:[NSColor blackColor]]);
aniyogi@14038 1039
michaelm@5116 1040 JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_addAttribute, isThickUnderline, isGray, effectiveRange.location, effectiveRange.length); // AWT_THREADING Safe (AWTRunLoopMode)
michaelm@5116 1041 }
michaelm@5116 1042 }
michaelm@5116 1043 }
aniyogi@14038 1044
michaelm@5116 1045 static JNF_MEMBER_CACHE(jm_selectPreviousGlyph, jc_CInputMethod, "selectPreviousGlyph", "()V");
michaelm@5116 1046 // We need to select the previous glyph so that it is overwritten.
michaelm@5116 1047 if (fPAHNeedsToSelect) {
michaelm@5116 1048 JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_selectPreviousGlyph);
michaelm@5116 1049 fPAHNeedsToSelect = NO;
michaelm@5116 1050 }
aniyogi@14038 1051
michaelm@5116 1052 JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_dispatchText, selectionRange.location, selectionRange.length, JNI_FALSE); // AWT_THREADING Safe (AWTRunLoopMode)
aniyogi@14038 1053
michaelm@5116 1054 // If the marked text is being cleared (zero-length string) don't handle the key event.
michaelm@5116 1055 if ([incomingString length] == 0) {
michaelm@5116 1056 fKeyEventsNeeded = NO;
michaelm@5116 1057 }
michaelm@5116 1058 }
michaelm@5116 1059
michaelm@5116 1060 - (void) unmarkText
michaelm@5116 1061 {
michaelm@5116 1062 #ifdef IM_DEBUG
michaelm@5116 1063 fprintf(stderr, "AWTView InputMethod Selector Called : [unmarkText]\n");
michaelm@5116 1064 #endif // IM_DEBUG
aniyogi@14038 1065
michaelm@5116 1066 if (!fInputMethodLOCKABLE) {
michaelm@5116 1067 return;
michaelm@5116 1068 }
aniyogi@14038 1069
michaelm@5116 1070 // unmarkText cancels any input in progress and commits it to the text field.
michaelm@5116 1071 static JNF_MEMBER_CACHE(jm_unmarkText, jc_CInputMethod, "unmarkText", "()V");
michaelm@5116 1072 JNIEnv *env = [ThreadUtilities getJNIEnv];
michaelm@5116 1073 JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_unmarkText); // AWT_THREADING Safe (AWTRunLoopMode)
aniyogi@14038 1074
michaelm@5116 1075 }
michaelm@5116 1076
michaelm@5116 1077 - (BOOL) hasMarkedText
michaelm@5116 1078 {
michaelm@5116 1079 #ifdef IM_DEBUG
michaelm@5116 1080 fprintf(stderr, "AWTView InputMethod Selector Called : [hasMarkedText]\n");
michaelm@5116 1081 #endif // IM_DEBUG
aniyogi@14038 1082
michaelm@5116 1083 if (!fInputMethodLOCKABLE) {
michaelm@5116 1084 return NO;
michaelm@5116 1085 }
aniyogi@14038 1086
michaelm@5116 1087 static JNF_MEMBER_CACHE(jf_fCurrentText, jc_CInputMethod, "fCurrentText", "Ljava/text/AttributedString;");
michaelm@5116 1088 static JNF_MEMBER_CACHE(jf_fCurrentTextLength, jc_CInputMethod, "fCurrentTextLength", "I");
michaelm@5116 1089 JNIEnv *env = [ThreadUtilities getJNIEnv];
michaelm@5116 1090 jobject currentText = JNFGetObjectField(env, fInputMethodLOCKABLE, jf_fCurrentText);
aniyogi@14038 1091
michaelm@5116 1092 jint currentTextLength = JNFGetIntField(env, fInputMethodLOCKABLE, jf_fCurrentTextLength);
aniyogi@14038 1093
michaelm@5116 1094 BOOL hasMarkedText = (currentText != NULL && currentTextLength > 0);
aniyogi@14038 1095
michaelm@5116 1096 if (currentText != NULL) {
michaelm@5116 1097 (*env)->DeleteLocalRef(env, currentText);
michaelm@5116 1098 }
aniyogi@14038 1099
michaelm@5116 1100 return hasMarkedText;
michaelm@5116 1101 }
michaelm@5116 1102
michaelm@5116 1103 - (NSInteger) conversationIdentifier
michaelm@5116 1104 {
michaelm@5116 1105 #ifdef IM_DEBUG
michaelm@5116 1106 fprintf(stderr, "AWTView InputMethod Selector Called : [conversationIdentifier]\n");
michaelm@5116 1107 #endif // IM_DEBUG
aniyogi@14038 1108
michaelm@5116 1109 return (NSInteger) self;
michaelm@5116 1110 }
michaelm@5116 1111
michaelm@5116 1112 /* Returns attributed string at the range. This allows input mangers to
michaelm@5116 1113 query any range in backing-store (Andy's request)
michaelm@5116 1114 */
michaelm@5116 1115 - (NSAttributedString *) attributedSubstringForProposedRange:(NSRange)theRange actualRange:(NSRangePointer)actualRange
michaelm@5116 1116 {
michaelm@5116 1117 #ifdef IM_DEBUG
michaelm@5116 1118 fprintf(stderr, "AWTView InputMethod Selector Called : [attributedSubstringFromRange] location=%lu, length=%lu\n", (unsigned long)theRange.location, (unsigned long)theRange.length);
michaelm@5116 1119 #endif // IM_DEBUG
aniyogi@14038 1120
michaelm@5116 1121 static JNF_MEMBER_CACHE(jm_substringFromRange, jc_CInputMethod, "attributedSubstringFromRange", "(II)Ljava/lang/String;");
michaelm@5116 1122 JNIEnv *env = [ThreadUtilities getJNIEnv];
michaelm@5116 1123 jobject theString = JNFCallObjectMethod(env, fInputMethodLOCKABLE, jm_substringFromRange, theRange.location, theRange.length); // AWT_THREADING Safe (AWTRunLoopMode)
aniyogi@14038 1124
michaelm@5116 1125 id result = [[[NSAttributedString alloc] initWithString:JNFJavaToNSString(env, theString)] autorelease];
michaelm@5116 1126 #ifdef IM_DEBUG
michaelm@5116 1127 NSLog(@"attributedSubstringFromRange returning \"%@\"", result);
michaelm@5116 1128 #endif // IM_DEBUG
aniyogi@14038 1129
michaelm@5116 1130 (*env)->DeleteLocalRef(env, theString);
michaelm@5116 1131 return result;
michaelm@5116 1132 }
michaelm@5116 1133
michaelm@5116 1134 /* This method returns the range for marked region. If hasMarkedText == false,
michaelm@5116 1135 it'll return NSNotFound location & 0 length range.
michaelm@5116 1136 */
michaelm@5116 1137 - (NSRange) markedRange
michaelm@5116 1138 {
aniyogi@14038 1139
michaelm@5116 1140 #ifdef IM_DEBUG
michaelm@5116 1141 fprintf(stderr, "AWTView InputMethod Selector Called : [markedRange]\n");
michaelm@5116 1142 #endif // IM_DEBUG
aniyogi@14038 1143
michaelm@5116 1144 if (!fInputMethodLOCKABLE) {
michaelm@5116 1145 return NSMakeRange(NSNotFound, 0);
michaelm@5116 1146 }
aniyogi@14038 1147
michaelm@5116 1148 static JNF_MEMBER_CACHE(jm_markedRange, jc_CInputMethod, "markedRange", "()[I");
michaelm@5116 1149 JNIEnv *env = [ThreadUtilities getJNIEnv];
michaelm@5116 1150 jarray array;
michaelm@5116 1151 jboolean isCopy;
michaelm@5116 1152 jint *_array;
serb@9588 1153 NSRange range = NSMakeRange(NSNotFound, 0);
aniyogi@14038 1154
michaelm@5116 1155 array = JNFCallObjectMethod(env, fInputMethodLOCKABLE, jm_markedRange); // AWT_THREADING Safe (AWTRunLoopMode)
aniyogi@14038 1156
michaelm@5116 1157 if (array) {
michaelm@5116 1158 _array = (*env)->GetIntArrayElements(env, array, &isCopy);
serb@9588 1159 if (_array != NULL) {
serb@9588 1160 range.location = _array[0];
serb@9588 1161 range.length = _array[1];
michaelm@5116 1162 #ifdef IM_DEBUG
serb@9588 1163 fprintf(stderr, "markedRange returning (%lu, %lu)\n",
serb@9588 1164 (unsigned long)range.location, (unsigned long)range.length);
michaelm@5116 1165 #endif // IM_DEBUG
serb@9588 1166 (*env)->ReleaseIntArrayElements(env, array, _array, 0);
serb@9588 1167 }
michaelm@5116 1168 (*env)->DeleteLocalRef(env, array);
michaelm@5116 1169 }
aniyogi@14038 1170
michaelm@5116 1171 return range;
michaelm@5116 1172 }
michaelm@5116 1173
michaelm@5116 1174 /* This method returns the range for selected region. Just like markedRange method,
michaelm@5116 1175 its location field contains char index from the text beginning.
michaelm@5116 1176 */
michaelm@5116 1177 - (NSRange) selectedRange
michaelm@5116 1178 {
michaelm@5116 1179 if (!fInputMethodLOCKABLE) {
michaelm@5116 1180 return NSMakeRange(NSNotFound, 0);
michaelm@5116 1181 }
aniyogi@14038 1182
michaelm@5116 1183 static JNF_MEMBER_CACHE(jm_selectedRange, jc_CInputMethod, "selectedRange", "()[I");
michaelm@5116 1184 JNIEnv *env = [ThreadUtilities getJNIEnv];
michaelm@5116 1185 jarray array;
michaelm@5116 1186 jboolean isCopy;
michaelm@5116 1187 jint *_array;
serb@9588 1188 NSRange range = NSMakeRange(NSNotFound, 0);
aniyogi@14038 1189
michaelm@5116 1190 #ifdef IM_DEBUG
michaelm@5116 1191 fprintf(stderr, "AWTView InputMethod Selector Called : [selectedRange]\n");
michaelm@5116 1192 #endif // IM_DEBUG
aniyogi@14038 1193
michaelm@5116 1194 array = JNFCallObjectMethod(env, fInputMethodLOCKABLE, jm_selectedRange); // AWT_THREADING Safe (AWTRunLoopMode)
michaelm@5116 1195 if (array) {
michaelm@5116 1196 _array = (*env)->GetIntArrayElements(env, array, &isCopy);
serb@9588 1197 if (_array != NULL) {
serb@9588 1198 range.location = _array[0];
serb@9588 1199 range.length = _array[1];
serb@9588 1200 (*env)->ReleaseIntArrayElements(env, array, _array, 0);
serb@9588 1201 }
michaelm@5116 1202 (*env)->DeleteLocalRef(env, array);
michaelm@5116 1203 }
aniyogi@14038 1204
michaelm@5116 1205 return range;
michaelm@5116 1206 }
michaelm@5116 1207
michaelm@5116 1208 /* This method returns the first frame of rects for theRange in screen coordindate system.
michaelm@5116 1209 */
michaelm@5116 1210 - (NSRect) firstRectForCharacterRange:(NSRange)theRange actualRange:(NSRangePointer)actualRange
michaelm@5116 1211 {
michaelm@5116 1212 if (!fInputMethodLOCKABLE) {
serb@9588 1213 return NSZeroRect;
michaelm@5116 1214 }
aniyogi@14038 1215
michaelm@5116 1216 static JNF_MEMBER_CACHE(jm_firstRectForCharacterRange, jc_CInputMethod,
michaelm@5116 1217 "firstRectForCharacterRange", "(I)[I");
michaelm@5116 1218 JNIEnv *env = [ThreadUtilities getJNIEnv];
michaelm@5116 1219 jarray array;
michaelm@5116 1220 jboolean isCopy;
michaelm@5116 1221 jint *_array;
michaelm@5116 1222 NSRect rect;
aniyogi@14038 1223
michaelm@5116 1224 #ifdef IM_DEBUG
serb@9588 1225 fprintf(stderr,
serb@9588 1226 "AWTView InputMethod Selector Called : [firstRectForCharacterRange:] location=%lu, length=%lu\n",
serb@9588 1227 (unsigned long)theRange.location, (unsigned long)theRange.length);
michaelm@5116 1228 #endif // IM_DEBUG
aniyogi@14038 1229
serb@9588 1230 array = JNFCallObjectMethod(env, fInputMethodLOCKABLE, jm_firstRectForCharacterRange,
serb@9588 1231 theRange.location); // AWT_THREADING Safe (AWTRunLoopMode)
aniyogi@14038 1232
michaelm@5116 1233 _array = (*env)->GetIntArrayElements(env, array, &isCopy);
serb@9588 1234 if (_array) {
serb@9588 1235 rect = ConvertNSScreenRect(env, NSMakeRect(_array[0], _array[1], _array[2], _array[3]));
serb@9588 1236 (*env)->ReleaseIntArrayElements(env, array, _array, 0);
serb@9588 1237 } else {
serb@9588 1238 rect = NSZeroRect;
serb@9588 1239 }
michaelm@5116 1240 (*env)->DeleteLocalRef(env, array);
aniyogi@14038 1241
michaelm@5116 1242 #ifdef IM_DEBUG
serb@9588 1243 fprintf(stderr,
serb@9588 1244 "firstRectForCharacterRange returning x=%f, y=%f, width=%f, height=%f\n",
serb@9588 1245 rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
michaelm@5116 1246 #endif // IM_DEBUG
michaelm@5116 1247 return rect;
michaelm@5116 1248 }
michaelm@5116 1249
michaelm@5116 1250 /* This method returns the index for character that is nearest to thePoint. thPoint is in
michaelm@5116 1251 screen coordinate system.
michaelm@5116 1252 */
michaelm@5116 1253 - (NSUInteger)characterIndexForPoint:(NSPoint)thePoint
michaelm@5116 1254 {
michaelm@5116 1255 if (!fInputMethodLOCKABLE) {
michaelm@5116 1256 return NSNotFound;
michaelm@5116 1257 }
aniyogi@14038 1258
michaelm@5116 1259 static JNF_MEMBER_CACHE(jm_characterIndexForPoint, jc_CInputMethod,
michaelm@5116 1260 "characterIndexForPoint", "(II)I");
michaelm@5116 1261 JNIEnv *env = [ThreadUtilities getJNIEnv];
aniyogi@14038 1262
michaelm@5116 1263 NSPoint flippedLocation = ConvertNSScreenPoint(env, thePoint);
aniyogi@14038 1264
michaelm@5116 1265 #ifdef IM_DEBUG
michaelm@5116 1266 fprintf(stderr, "AWTView InputMethod Selector Called : [characterIndexForPoint:(NSPoint)thePoint] x=%f, y=%f\n", flippedLocation.x, flippedLocation.y);
michaelm@5116 1267 #endif // IM_DEBUG
aniyogi@14038 1268
michaelm@5116 1269 jint index = JNFCallIntMethod(env, fInputMethodLOCKABLE, jm_characterIndexForPoint, (jint)flippedLocation.x, (jint)flippedLocation.y); // AWT_THREADING Safe (AWTRunLoopMode)
aniyogi@14038 1270
michaelm@5116 1271 #ifdef IM_DEBUG
michaelm@5116 1272 fprintf(stderr, "characterIndexForPoint returning %ld\n", index);
michaelm@5116 1273 #endif // IM_DEBUG
aniyogi@14038 1274
michaelm@5116 1275 if (index == -1) {
michaelm@5116 1276 return NSNotFound;
michaelm@5116 1277 } else {
michaelm@5116 1278 return (NSUInteger)index;
michaelm@5116 1279 }
michaelm@5116 1280 }
michaelm@5116 1281
michaelm@5116 1282 - (NSArray*) validAttributesForMarkedText
michaelm@5116 1283 {
michaelm@5116 1284 #ifdef IM_DEBUG
michaelm@5116 1285 fprintf(stderr, "AWTView InputMethod Selector Called : [validAttributesForMarkedText]\n");
michaelm@5116 1286 #endif // IM_DEBUG
aniyogi@14038 1287
michaelm@5116 1288 return [NSArray array];
michaelm@5116 1289 }
michaelm@5116 1290
michaelm@5116 1291 - (void)setInputMethod:(jobject)inputMethod
michaelm@5116 1292 {
michaelm@5116 1293 #ifdef IM_DEBUG
michaelm@5116 1294 fprintf(stderr, "AWTView InputMethod Selector Called : [setInputMethod]\n");
michaelm@5116 1295 #endif // IM_DEBUG
aniyogi@14038 1296
michaelm@5116 1297 JNIEnv *env = [ThreadUtilities getJNIEnv];
aniyogi@14038 1298
michaelm@5116 1299 // Get rid of the old one
michaelm@5116 1300 if (fInputMethodLOCKABLE) {
michaelm@5116 1301 JNFDeleteGlobalRef(env, fInputMethodLOCKABLE);
michaelm@5116 1302 }
aniyogi@14038 1303
michaelm@5116 1304 // Save a global ref to the new input method.
michaelm@5116 1305 if (inputMethod != NULL)
michaelm@5116 1306 fInputMethodLOCKABLE = JNFNewGlobalRef(env, inputMethod);
michaelm@5116 1307 else
michaelm@5116 1308 fInputMethodLOCKABLE = NULL;
michaelm@5116 1309 }
michaelm@5116 1310
michaelm@5116 1311 - (void)abandonInput
michaelm@5116 1312 {
michaelm@5116 1313 #ifdef IM_DEBUG
michaelm@5116 1314 fprintf(stderr, "AWTView InputMethod Selector Called : [abandonInput]\n");
michaelm@5116 1315 #endif // IM_DEBUG
aniyogi@14038 1316
pchelko@6623 1317 [ThreadUtilities performOnMainThread:@selector(markedTextAbandoned:) on:[NSInputManager currentInputManager] withObject:self waitUntilDone:YES];
michaelm@5116 1318 [self unmarkText];
michaelm@5116 1319 }
michaelm@5116 1320
michaelm@5116 1321 /******************************** END NSTextInputClient Protocol ********************************/
michaelm@5116 1322
michaelm@5116 1323
michaelm@5116 1324
michaelm@5116 1325
michaelm@5116 1326 @end // AWTView
michaelm@5116 1327
michaelm@5116 1328 /*
michaelm@5116 1329 * Class: sun_lwawt_macosx_CPlatformView
michaelm@5116 1330 * Method: nativeCreateView
michaelm@5116 1331 * Signature: (IIII)J
michaelm@5116 1332 */
michaelm@5116 1333 JNIEXPORT jlong JNICALL
michaelm@5116 1334 Java_sun_lwawt_macosx_CPlatformView_nativeCreateView
michaelm@5116 1335 (JNIEnv *env, jobject obj, jint originX, jint originY, jint width, jint height, jlong windowLayerPtr)
michaelm@5116 1336 {
michaelm@5116 1337 __block AWTView *newView = nil;
aniyogi@14038 1338
aniyogi@14038 1339 JNF_COCOA_ENTER(env);
aniyogi@14038 1340
michaelm@5116 1341 NSRect rect = NSMakeRect(originX, originY, width, height);
ant@14365 1342 jobject cPlatformView = (*env)->NewWeakGlobalRef(env, obj);
aniyogi@14038 1343
serb@6219 1344 [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
aniyogi@14038 1345
michaelm@5116 1346 CALayer *windowLayer = jlong_to_ptr(windowLayerPtr);
pchelko@9614 1347 newView = [[AWTView alloc] initWithRect:rect
pchelko@9614 1348 platformView:cPlatformView
pchelko@9614 1349 windowLayer:windowLayer];
michaelm@5116 1350 }];
aniyogi@14038 1351
aniyogi@14038 1352 JNF_COCOA_EXIT(env);
aniyogi@14038 1353
michaelm@5116 1354 return ptr_to_jlong(newView);
michaelm@5116 1355 }
serb@6219 1356
serb@6219 1357 /*
serb@6219 1358 * Class: sun_lwawt_macosx_CPlatformView
serb@6219 1359 * Method: nativeSetAutoResizable
serb@6219 1360 * Signature: (JZ)V;
serb@6219 1361 */
serb@6219 1362
serb@6219 1363 JNIEXPORT void JNICALL
serb@6219 1364 Java_sun_lwawt_macosx_CPlatformView_nativeSetAutoResizable
serb@6219 1365 (JNIEnv *env, jclass cls, jlong viewPtr, jboolean toResize)
serb@6219 1366 {
aniyogi@14038 1367 JNF_COCOA_ENTER(env);
serb@6219 1368
aniyogi@14038 1369 NSView *view = (NSView *)jlong_to_ptr(viewPtr);
aniyogi@14038 1370
aniyogi@14038 1371 [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
aniyogi@14038 1372
aniyogi@14038 1373 if (toResize) {
aniyogi@14038 1374 [view setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable];
aniyogi@14038 1375 } else {
aniyogi@14038 1376 [view setAutoresizingMask: NSViewMinYMargin | NSViewMaxXMargin];
aniyogi@14038 1377 }
aniyogi@14038 1378
aniyogi@14038 1379 if ([view superview] != nil) {
aniyogi@14038 1380 [[view superview] setAutoresizesSubviews:(BOOL)toResize];
aniyogi@14038 1381 }
aniyogi@14038 1382
serb@6219 1383 }];
aniyogi@14038 1384 JNF_COCOA_EXIT(env);
serb@6219 1385 }
serb@6219 1386
serb@6219 1387 /*
serb@6219 1388 * Class: sun_lwawt_macosx_CPlatformView
serb@6219 1389 * Method: nativeGetNSViewDisplayID
serb@6219 1390 * Signature: (J)I;
serb@6219 1391 */
serb@6219 1392
serb@6219 1393 JNIEXPORT jint JNICALL
serb@6219 1394 Java_sun_lwawt_macosx_CPlatformView_nativeGetNSViewDisplayID
serb@6219 1395 (JNIEnv *env, jclass cls, jlong viewPtr)
serb@6219 1396 {
serb@6219 1397 __block jint ret; //CGDirectDisplayID
serb@6219 1398
aniyogi@14038 1399 JNF_COCOA_ENTER(env);
serb@6219 1400
aniyogi@14038 1401 NSView *view = (NSView *)jlong_to_ptr(viewPtr);
serb@6219 1402 NSWindow *window = [view window];
serb@6219 1403
serb@6219 1404 [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
aniyogi@14038 1405
aniyogi@14038 1406 ret = (jint)[[AWTWindow getNSWindowDisplayID_AppKitThread: window] intValue];
serb@6219 1407 }];
serb@6219 1408
aniyogi@14038 1409 JNF_COCOA_EXIT(env);
serb@6219 1410
serb@6219 1411 return ret;
serb@6219 1412 }
serb@6219 1413
serb@6219 1414 /*
serb@6219 1415 * Class: sun_lwawt_macosx_CPlatformView
serb@6219 1416 * Method: nativeGetLocationOnScreen
serb@6219 1417 * Signature: (J)Ljava/awt/Rectangle;
serb@6219 1418 */
serb@6219 1419
serb@6219 1420 JNIEXPORT jobject JNICALL
serb@6219 1421 Java_sun_lwawt_macosx_CPlatformView_nativeGetLocationOnScreen
serb@6219 1422 (JNIEnv *env, jclass cls, jlong viewPtr)
serb@6219 1423 {
serb@6219 1424 jobject jRect = NULL;
serb@6219 1425
aniyogi@14038 1426 JNF_COCOA_ENTER(env);
serb@6219 1427
serb@6219 1428 __block NSRect rect = NSZeroRect;
serb@6219 1429
aniyogi@14038 1430 NSView *view = (NSView *)jlong_to_ptr(viewPtr);
serb@6219 1431 [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
aniyogi@14038 1432
serb@6219 1433 NSRect viewBounds = [view bounds];
serb@6219 1434 NSRect frameInWindow = [view convertRect:viewBounds toView:nil];
serb@6219 1435 rect = [[view window] convertRectToScreen:frameInWindow];
serb@6219 1436 NSRect screenRect = [[NSScreen mainScreen] frame];
serb@6219 1437 //Convert coordinates to top-left corner origin
serb@6219 1438 rect.origin.y = screenRect.size.height - rect.origin.y - viewBounds.size.height;
serb@6219 1439 }];
serb@6219 1440 jRect = NSToJavaRect(env, rect);
serb@6219 1441
aniyogi@14038 1442 JNF_COCOA_EXIT(env);
serb@6219 1443
serb@6219 1444 return jRect;
serb@6219 1445 }
serb@6219 1446
serb@6219 1447 /*
serb@6219 1448 * Class: sun_lwawt_macosx_CPlatformView
serb@6219 1449 * Method: nativeIsViewUnderMouse
serb@6219 1450 * Signature: (J)Z;
serb@6219 1451 */
serb@6219 1452
serb@6219 1453 JNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_CPlatformView_nativeIsViewUnderMouse
serb@6219 1454 (JNIEnv *env, jclass clazz, jlong viewPtr)
serb@6219 1455 {
serb@6219 1456 __block jboolean underMouse = JNI_FALSE;
serb@6219 1457
aniyogi@14038 1458 JNF_COCOA_ENTER(env);
serb@6219 1459
serb@6219 1460 NSView *nsView = OBJC(viewPtr);
aniyogi@14038 1461 [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
aniyogi@14038 1462 NSPoint ptWindowCoords = [[nsView window] mouseLocationOutsideOfEventStream];
aniyogi@14038 1463 NSPoint ptViewCoords = [nsView convertPoint:ptWindowCoords fromView:nil];
aniyogi@14038 1464 underMouse = [nsView hitTest:ptViewCoords] != nil;
serb@6219 1465 }];
serb@6219 1466
aniyogi@14038 1467 JNF_COCOA_EXIT(env);
serb@6219 1468
serb@6219 1469 return underMouse;
serb@6219 1470 }