annotate src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m @ 15920:ff61a6fd0349

8166591: [macos 10.12] Trackpad scrolling of text on OS X 10.12 Sierra is very fast (Trackpad, Retina only) Reviewed-by: malenkov, serb
author alexsch
date Wed, 05 Oct 2016 18:29:18 +0400
parents 9c3c78efdf6d
children ba316e40c19b
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");
alexsch@15920 386 static JNF_CTOR_CACHE(jctor_NSEvent, jc_NSEvent, "(IIIIIIIIDDI)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],
alexsch@15920 395 [event deltaX],
alexsch@15920 396 [AWTToolkit scrollStateWithEvent: event]);
pchelko@9987 397 CHECK_NULL(jEvent);
aniyogi@14038 398
michaelm@5116 399 static JNF_CLASS_CACHE(jc_PlatformView, "sun/lwawt/macosx/CPlatformView");
pchelko@9420 400 static JNF_MEMBER_CACHE(jm_deliverMouseEvent, jc_PlatformView, "deliverMouseEvent", "(Lsun/lwawt/macosx/NSEvent;)V");
ant@14365 401 jobject jlocal = (*env)->NewLocalRef(env, m_cPlatformView);
ant@14365 402 if (!(*env)->IsSameObject(env, jlocal, NULL)) {
ant@14365 403 JNFCallVoidMethod(env, jlocal, jm_deliverMouseEvent, jEvent);
ant@14365 404 (*env)->DeleteLocalRef(env, jlocal);
ant@14365 405 }
pchelko@9987 406 (*env)->DeleteLocalRef(env, jEvent);
michaelm@5116 407 }
michaelm@5116 408
alexsch@5784 409 - (void) resetTrackingArea {
alexsch@5784 410 if (rolloverTrackingArea != nil) {
alexsch@5784 411 [self removeTrackingArea:rolloverTrackingArea];
alexsch@5784 412 [rolloverTrackingArea release];
alexsch@5784 413 }
aniyogi@14038 414
pchelko@8120 415 int options = (NSTrackingActiveAlways | NSTrackingMouseEnteredAndExited |
alexsch@5784 416 NSTrackingMouseMoved | NSTrackingEnabledDuringMouseDrag);
aniyogi@14038 417
alexsch@5784 418 rolloverTrackingArea = [[NSTrackingArea alloc] initWithRect:[self visibleRect]
alexsch@5784 419 options: options
alexsch@5784 420 owner:self
alexsch@5784 421 userInfo:nil
alexsch@5784 422 ];
alexsch@5784 423 [self addTrackingArea:rolloverTrackingArea];
michaelm@5116 424 }
michaelm@5116 425
michaelm@5116 426 - (void)updateTrackingAreas {
michaelm@5116 427 [super updateTrackingAreas];
alexsch@5784 428 [self resetTrackingArea];
michaelm@5116 429 }
michaelm@5116 430
michaelm@5116 431 - (void) resetCursorRects {
michaelm@5116 432 [super resetCursorRects];
alexsch@5784 433 [self resetTrackingArea];
michaelm@5116 434 }
michaelm@5116 435
michaelm@5116 436 -(void) deliverJavaKeyEventHelper: (NSEvent *) event {
ant@5371 437 static NSEvent* sLastKeyEvent = nil;
ant@5371 438 if (event == sLastKeyEvent) {
ant@5370 439 // The event is repeatedly delivered by keyDown: after performKeyEquivalent:
ant@5370 440 return;
ant@5370 441 }
ant@5371 442 [sLastKeyEvent release];
ant@5371 443 sLastKeyEvent = [event retain];
aniyogi@14038 444
michaelm@5116 445 [AWTToolkit eventCountPlusPlus];
michaelm@5116 446 JNIEnv *env = [ThreadUtilities getJNIEnv];
aniyogi@14038 447
michaelm@5116 448 jstring characters = NULL;
anashaty@10139 449 jstring charactersIgnoringModifiers = NULL;
michaelm@5116 450 if ([event type] != NSFlagsChanged) {
michaelm@5116 451 characters = JNFNSToJavaString(env, [event characters]);
anashaty@10139 452 charactersIgnoringModifiers = JNFNSToJavaString(env, [event charactersIgnoringModifiers]);
michaelm@5116 453 }
aniyogi@14038 454
pchelko@9420 455 static JNF_CLASS_CACHE(jc_NSEvent, "sun/lwawt/macosx/NSEvent");
anashaty@10139 456 static JNF_CTOR_CACHE(jctor_NSEvent, jc_NSEvent, "(IISLjava/lang/String;Ljava/lang/String;)V");
pchelko@9987 457 jobject jEvent = JNFNewObject(env, jctor_NSEvent,
michaelm@5116 458 [event type],
michaelm@5116 459 [event modifierFlags],
michaelm@5116 460 [event keyCode],
anashaty@10139 461 characters,
anashaty@10139 462 charactersIgnoringModifiers);
pchelko@9987 463 CHECK_NULL(jEvent);
aniyogi@14038 464
michaelm@5116 465 static JNF_CLASS_CACHE(jc_PlatformView, "sun/lwawt/macosx/CPlatformView");
michaelm@5116 466 static JNF_MEMBER_CACHE(jm_deliverKeyEvent, jc_PlatformView,
pchelko@9420 467 "deliverKeyEvent", "(Lsun/lwawt/macosx/NSEvent;)V");
ant@14365 468 jobject jlocal = (*env)->NewLocalRef(env, m_cPlatformView);
ant@14365 469 if (!(*env)->IsSameObject(env, jlocal, NULL)) {
ant@14365 470 JNFCallVoidMethod(env, jlocal, jm_deliverKeyEvent, jEvent);
ant@14365 471 (*env)->DeleteLocalRef(env, jlocal);
ant@14365 472 }
michaelm@5116 473 if (characters != NULL) {
michaelm@5116 474 (*env)->DeleteLocalRef(env, characters);
michaelm@5116 475 }
pchelko@9987 476 (*env)->DeleteLocalRef(env, jEvent);
michaelm@5116 477 }
michaelm@5116 478
serb@6219 479 -(void) deliverResize: (NSRect) rect {
serb@6219 480 jint x = (jint) rect.origin.x;
serb@6219 481 jint y = (jint) rect.origin.y;
serb@6219 482 jint w = (jint) rect.size.width;
serb@6219 483 jint h = (jint) rect.size.height;
serb@6219 484 JNIEnv *env = [ThreadUtilities getJNIEnv];
serb@6219 485 static JNF_CLASS_CACHE(jc_PlatformView, "sun/lwawt/macosx/CPlatformView");
serb@6219 486 static JNF_MEMBER_CACHE(jm_deliverResize, jc_PlatformView, "deliverResize", "(IIII)V");
ant@14365 487
ant@14365 488 jobject jlocal = (*env)->NewLocalRef(env, m_cPlatformView);
ant@14365 489 if (!(*env)->IsSameObject(env, jlocal, NULL)) {
ant@14365 490 JNFCallVoidMethod(env, jlocal, jm_deliverResize, x,y,w,h);
ant@14365 491 (*env)->DeleteLocalRef(env, jlocal);
ant@14365 492 }
serb@6219 493 }
serb@6219 494
serb@6219 495
michaelm@5116 496 - (void) drawRect:(NSRect)dirtyRect {
aniyogi@14038 497 AWT_ASSERT_APPKIT_THREAD;
aniyogi@14038 498
michaelm@5116 499 [super drawRect:dirtyRect];
michaelm@5116 500 JNIEnv *env = [ThreadUtilities getJNIEnv];
michaelm@5116 501 if (env != NULL) {
aniyogi@14038 502 /*
aniyogi@14038 503 if ([self inLiveResize]) {
aniyogi@14038 504 NSRect rs[4];
aniyogi@14038 505 NSInteger count;
aniyogi@14038 506 [self getRectsExposedDuringLiveResize:rs count:&count];
aniyogi@14038 507 for (int i = 0; i < count; i++) {
aniyogi@14038 508 JNU_CallMethodByName(env, NULL, [m_awtWindow cPlatformView],
aniyogi@14038 509 "deliverWindowDidExposeEvent", "(FFFF)V",
aniyogi@14038 510 (jfloat)rs[i].origin.x, (jfloat)rs[i].origin.y,
aniyogi@14038 511 (jfloat)rs[i].size.width, (jfloat)rs[i].size.height);
aniyogi@14038 512 if ((*env)->ExceptionOccurred(env)) {
aniyogi@14038 513 (*env)->ExceptionDescribe(env);
aniyogi@14038 514 (*env)->ExceptionClear(env);
aniyogi@14038 515 }
aniyogi@14038 516 }
aniyogi@14038 517 } else {
aniyogi@14038 518 */
michaelm@5116 519 static JNF_CLASS_CACHE(jc_CPlatformView, "sun/lwawt/macosx/CPlatformView");
michaelm@5116 520 static JNF_MEMBER_CACHE(jm_deliverWindowDidExposeEvent, jc_CPlatformView, "deliverWindowDidExposeEvent", "()V");
ant@14365 521 jobject jlocal = (*env)->NewLocalRef(env, m_cPlatformView);
ant@14365 522 if (!(*env)->IsSameObject(env, jlocal, NULL)) {
ant@14365 523 JNFCallVoidMethod(env, jlocal, jm_deliverWindowDidExposeEvent);
ant@14365 524 (*env)->DeleteLocalRef(env, jlocal);
ant@14365 525 }
aniyogi@14038 526 /*
aniyogi@14038 527 }
aniyogi@14038 528 */
michaelm@5116 529 }
michaelm@5116 530 }
michaelm@5116 531
alitvinov@13095 532 -(BOOL) isCodePointInUnicodeBlockNeedingIMEvent: (unichar) codePoint {
dmarkov@15037 533 if (((codePoint >= 0x3000) && (codePoint <= 0x303F)) ||
dmarkov@15037 534 ((codePoint >= 0xFF00) && (codePoint <= 0xFFEF))) {
dmarkov@15037 535 // Code point is in 'CJK Symbols and Punctuation' or
dmarkov@15037 536 // 'Halfwidth and Fullwidth Forms' Unicode block.
alitvinov@13095 537 return YES;
alitvinov@13095 538 }
alitvinov@13095 539 return NO;
alitvinov@13095 540 }
alitvinov@13095 541
aniyogi@14038 542 -(NSMutableString *) parseString : (id) complexString {
aniyogi@14038 543 if ([complexString isKindOfClass:[NSString class]]) {
aniyogi@14038 544 return [complexString mutableCopy];
aniyogi@14038 545 }
aniyogi@14038 546 else {
aniyogi@14038 547 return [complexString mutableString];
aniyogi@14038 548 }
aniyogi@14038 549 }
aniyogi@14038 550
michaelm@5116 551 // NSAccessibility support
michaelm@5116 552 - (jobject)awtComponent:(JNIEnv*)env
michaelm@5116 553 {
michaelm@5116 554 static JNF_CLASS_CACHE(jc_CPlatformView, "sun/lwawt/macosx/CPlatformView");
michaelm@5116 555 static JNF_MEMBER_CACHE(jf_Peer, jc_CPlatformView, "peer", "Lsun/lwawt/LWWindowPeer;");
michaelm@5116 556 if ((env == NULL) || (m_cPlatformView == NULL)) {
michaelm@5116 557 NSLog(@"Apple AWT : Error AWTView:awtComponent given bad parameters.");
michaelm@5116 558 if (env != NULL)
michaelm@5116 559 {
michaelm@5116 560 JNFDumpJavaStack(env);
michaelm@5116 561 }
michaelm@5116 562 return NULL;
michaelm@5116 563 }
ant@14365 564
ant@14365 565 jobject peer = NULL;
ant@14365 566 jobject jlocal = (*env)->NewLocalRef(env, m_cPlatformView);
ant@14365 567 if (!(*env)->IsSameObject(env, jlocal, NULL)) {
ant@14365 568 peer = JNFGetObjectField(env, jlocal, jf_Peer);
ant@14365 569 (*env)->DeleteLocalRef(env, jlocal);
ant@14365 570 }
michaelm@5116 571 static JNF_CLASS_CACHE(jc_LWWindowPeer, "sun/lwawt/LWWindowPeer");
michaelm@5116 572 static JNF_MEMBER_CACHE(jf_Target, jc_LWWindowPeer, "target", "Ljava/awt/Component;");
michaelm@5116 573 if (peer == NULL) {
michaelm@5116 574 NSLog(@"Apple AWT : Error AWTView:awtComponent got null peer from CPlatformView");
michaelm@5116 575 JNFDumpJavaStack(env);
michaelm@5116 576 return NULL;
michaelm@5116 577 }
ant@14365 578 jobject comp = JNFGetObjectField(env, peer, jf_Target);
ant@14365 579 (*env)->DeleteLocalRef(env, peer);
ant@14365 580 return comp;
ant@14365 581 }
ant@14365 582
ant@14365 583 + (AWTView *) awtView:(JNIEnv*)env ofAccessible:(jobject)jaccessible
ant@14365 584 {
ant@14365 585 static JNF_STATIC_MEMBER_CACHE(jm_getAWTView, sjc_CAccessibility, "getAWTView", "(Ljavax/accessibility/Accessible;)J");
ant@14365 586
ant@14365 587 jlong jptr = JNFCallStaticLongMethod(env, jm_getAWTView, jaccessible);
ant@14365 588 if (jptr == 0) return nil;
ant@14365 589
ant@14365 590 return (AWTView *)jlong_to_ptr(jptr);
michaelm@5116 591 }
michaelm@5116 592
michaelm@5116 593 - (id)getAxData:(JNIEnv*)env
michaelm@5116 594 {
ant@14365 595 jobject jcomponent = [self awtComponent:env];
ant@14365 596 id ax = [[[JavaComponentAccessibility alloc] initWithParent:self withEnv:env withAccessible:jcomponent withIndex:-1 withView:self withJavaRole:nil] autorelease];
ant@14365 597 (*env)->DeleteLocalRef(env, jcomponent);
ant@14365 598 return ax;
michaelm@5116 599 }
michaelm@5116 600
michaelm@5116 601 - (NSArray *)accessibilityAttributeNames
michaelm@5116 602 {
michaelm@5116 603 return [[super accessibilityAttributeNames] arrayByAddingObject:NSAccessibilityChildrenAttribute];
michaelm@5116 604 }
michaelm@5116 605
michaelm@5116 606 // NSAccessibility messages
michaelm@5116 607 // attribute methods
michaelm@5116 608 - (id)accessibilityAttributeValue:(NSString *)attribute
michaelm@5116 609 {
michaelm@5116 610 AWT_ASSERT_APPKIT_THREAD;
aniyogi@14038 611
michaelm@5116 612 if ([attribute isEqualToString:NSAccessibilityChildrenAttribute])
michaelm@5116 613 {
michaelm@5116 614 JNIEnv *env = [ThreadUtilities getJNIEnv];
aniyogi@14038 615
michaelm@5116 616 (*env)->PushLocalFrame(env, 4);
aniyogi@14038 617
michaelm@5116 618 id result = NSAccessibilityUnignoredChildrenForOnlyChild([self getAxData:env]);
aniyogi@14038 619
michaelm@5116 620 (*env)->PopLocalFrame(env, NULL);
aniyogi@14038 621
michaelm@5116 622 return result;
michaelm@5116 623 }
michaelm@5116 624 else
michaelm@5116 625 {
michaelm@5116 626 return [super accessibilityAttributeValue:attribute];
michaelm@5116 627 }
michaelm@5116 628 }
michaelm@5116 629 - (BOOL)accessibilityIsIgnored
michaelm@5116 630 {
michaelm@5116 631 return YES;
michaelm@5116 632 }
michaelm@5116 633
michaelm@5116 634 - (id)accessibilityHitTest:(NSPoint)point
michaelm@5116 635 {
michaelm@5116 636 AWT_ASSERT_APPKIT_THREAD;
michaelm@5116 637 JNIEnv *env = [ThreadUtilities getJNIEnv];
aniyogi@14038 638
michaelm@5116 639 (*env)->PushLocalFrame(env, 4);
aniyogi@14038 640
michaelm@5116 641 id result = [[self getAxData:env] accessibilityHitTest:point withEnv:env];
aniyogi@14038 642
michaelm@5116 643 (*env)->PopLocalFrame(env, NULL);
aniyogi@14038 644
michaelm@5116 645 return result;
michaelm@5116 646 }
michaelm@5116 647
michaelm@5116 648 - (id)accessibilityFocusedUIElement
michaelm@5116 649 {
michaelm@5116 650 AWT_ASSERT_APPKIT_THREAD;
aniyogi@14038 651
michaelm@5116 652 JNIEnv *env = [ThreadUtilities getJNIEnv];
aniyogi@14038 653
michaelm@5116 654 (*env)->PushLocalFrame(env, 4);
aniyogi@14038 655
michaelm@5116 656 id result = [[self getAxData:env] accessibilityFocusedUIElement];
aniyogi@14038 657
michaelm@5116 658 (*env)->PopLocalFrame(env, NULL);
aniyogi@14038 659
michaelm@5116 660 return result;
michaelm@5116 661 }
michaelm@5116 662
michaelm@5116 663 // --- Services menu support for lightweights ---
michaelm@5116 664
malenkov@8565 665 // finds the focused accessible element, and if it is a text element, obtains the text from it
michaelm@5116 666 - (NSString *)accessibleSelectedText
michaelm@5116 667 {
michaelm@5116 668 id focused = [self accessibilityFocusedUIElement];
michaelm@5116 669 if (![focused isKindOfClass:[JavaTextAccessibility class]]) return nil;
michaelm@5116 670 return [(JavaTextAccessibility *)focused accessibilitySelectedTextAttribute];
michaelm@5116 671 }
michaelm@5116 672
michaelm@5116 673 // same as above, but converts to RTFD
michaelm@5116 674 - (NSData *)accessibleSelectedTextAsRTFD
michaelm@5116 675 {
michaelm@5116 676 NSString *selectedText = [self accessibleSelectedText];
michaelm@5116 677 NSAttributedString *styledText = [[NSAttributedString alloc] initWithString:selectedText];
serb@13887 678 NSData *rtfdData = [styledText RTFDFromRange:NSMakeRange(0, [styledText length])
aniyogi@14038 679 documentAttributes:
aniyogi@14038 680 @{NSDocumentTypeDocumentAttribute: NSRTFTextDocumentType}];
michaelm@5116 681 [styledText release];
michaelm@5116 682 return rtfdData;
michaelm@5116 683 }
michaelm@5116 684
malenkov@8565 685 // finds the focused accessible element, and if it is a text element, sets the text in it
michaelm@5116 686 - (BOOL)replaceAccessibleTextSelection:(NSString *)text
michaelm@5116 687 {
michaelm@5116 688 id focused = [self accessibilityFocusedUIElement];
michaelm@5116 689 if (![focused isKindOfClass:[JavaTextAccessibility class]]) return NO;
michaelm@5116 690 [(JavaTextAccessibility *)focused accessibilitySetSelectedTextAttribute:text];
michaelm@5116 691 return YES;
michaelm@5116 692 }
michaelm@5116 693
michaelm@5116 694 // called for each service in the Services menu - only handle text for now
michaelm@5116 695 - (id)validRequestorForSendType:(NSString *)sendType returnType:(NSString *)returnType
michaelm@5116 696 {
michaelm@5116 697 if ([[self window] firstResponder] != self) return nil; // let AWT components handle themselves
aniyogi@14038 698
michaelm@5116 699 if ([sendType isEqual:NSStringPboardType] || [returnType isEqual:NSStringPboardType]) {
michaelm@5116 700 NSString *selectedText = [self accessibleSelectedText];
michaelm@5116 701 if (selectedText) return self;
michaelm@5116 702 }
aniyogi@14038 703
michaelm@5116 704 return nil;
michaelm@5116 705 }
michaelm@5116 706
michaelm@5116 707 // fetch text from Java and hand off to the service
michaelm@5116 708 - (BOOL)writeSelectionToPasteboard:(NSPasteboard *)pboard types:(NSArray *)types
michaelm@5116 709 {
michaelm@5116 710 if ([types containsObject:NSStringPboardType])
michaelm@5116 711 {
michaelm@5116 712 [pboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
michaelm@5116 713 return [pboard setString:[self accessibleSelectedText] forType:NSStringPboardType];
michaelm@5116 714 }
aniyogi@14038 715
michaelm@5116 716 if ([types containsObject:NSRTFDPboardType])
michaelm@5116 717 {
michaelm@5116 718 [pboard declareTypes:[NSArray arrayWithObject:NSRTFDPboardType] owner:nil];
michaelm@5116 719 return [pboard setData:[self accessibleSelectedTextAsRTFD] forType:NSRTFDPboardType];
michaelm@5116 720 }
aniyogi@14038 721
michaelm@5116 722 return NO;
michaelm@5116 723 }
michaelm@5116 724
michaelm@5116 725 // write text back to Java from the service
michaelm@5116 726 - (BOOL)readSelectionFromPasteboard:(NSPasteboard *)pboard
michaelm@5116 727 {
michaelm@5116 728 if ([[pboard types] containsObject:NSStringPboardType])
michaelm@5116 729 {
michaelm@5116 730 NSString *text = [pboard stringForType:NSStringPboardType];
michaelm@5116 731 return [self replaceAccessibleTextSelection:text];
michaelm@5116 732 }
aniyogi@14038 733
michaelm@5116 734 if ([[pboard types] containsObject:NSRTFDPboardType])
michaelm@5116 735 {
michaelm@5116 736 NSData *rtfdData = [pboard dataForType:NSRTFDPboardType];
serb@13887 737 NSAttributedString *styledText = [[NSAttributedString alloc] initWithRTFD:rtfdData documentAttributes:NULL];
michaelm@5116 738 NSString *text = [styledText string];
michaelm@5116 739 [styledText release];
aniyogi@14038 740
michaelm@5116 741 return [self replaceAccessibleTextSelection:text];
michaelm@5116 742 }
aniyogi@14038 743
michaelm@5116 744 return NO;
michaelm@5116 745 }
michaelm@5116 746
michaelm@5116 747
michaelm@5116 748 -(void) setDragSource:(CDragSource *)source {
michaelm@5116 749 self._dragSource = source;
michaelm@5116 750 }
michaelm@5116 751
michaelm@5116 752
michaelm@5116 753 - (void) setDropTarget:(CDropTarget *)target {
michaelm@5116 754 self._dropTarget = target;
pchelko@6623 755 [ThreadUtilities performOnMainThread:@selector(controlModelControlValid) on:self._dropTarget withObject:nil waitUntilDone:YES];
michaelm@5116 756 }
michaelm@5116 757
michaelm@5116 758 /******************************** BEGIN NSDraggingSource Interface ********************************/
michaelm@5116 759
michaelm@5116 760 - (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)flag
michaelm@5116 761 {
michaelm@5116 762 // If draggingSource is nil route the message to the superclass (if responding to the selector):
michaelm@5116 763 CDragSource *dragSource = self._dragSource;
michaelm@5116 764 NSDragOperation dragOp = NSDragOperationNone;
aniyogi@14038 765
michaelm@5116 766 if (dragSource != nil)
michaelm@5116 767 dragOp = [dragSource draggingSourceOperationMaskForLocal:flag];
michaelm@5116 768 else if ([super respondsToSelector:@selector(draggingSourceOperationMaskForLocal:)])
michaelm@5116 769 dragOp = [super draggingSourceOperationMaskForLocal:flag];
aniyogi@14038 770
michaelm@5116 771 return dragOp;
michaelm@5116 772 }
michaelm@5116 773
michaelm@5116 774 - (NSArray *)namesOfPromisedFilesDroppedAtDestination:(NSURL *)dropDestination
michaelm@5116 775 {
michaelm@5116 776 // If draggingSource is nil route the message to the superclass (if responding to the selector):
michaelm@5116 777 CDragSource *dragSource = self._dragSource;
michaelm@5116 778 NSArray* array = nil;
aniyogi@14038 779
michaelm@5116 780 if (dragSource != nil)
michaelm@5116 781 array = [dragSource namesOfPromisedFilesDroppedAtDestination:dropDestination];
michaelm@5116 782 else if ([super respondsToSelector:@selector(namesOfPromisedFilesDroppedAtDestination:)])
michaelm@5116 783 array = [super namesOfPromisedFilesDroppedAtDestination:dropDestination];
aniyogi@14038 784
michaelm@5116 785 return array;
michaelm@5116 786 }
michaelm@5116 787
michaelm@5116 788 - (void)draggedImage:(NSImage *)image beganAt:(NSPoint)screenPoint
michaelm@5116 789 {
michaelm@5116 790 // If draggingSource is nil route the message to the superclass (if responding to the selector):
michaelm@5116 791 CDragSource *dragSource = self._dragSource;
aniyogi@14038 792
michaelm@5116 793 if (dragSource != nil)
michaelm@5116 794 [dragSource draggedImage:image beganAt:screenPoint];
michaelm@5116 795 else if ([super respondsToSelector:@selector(draggedImage::)])
michaelm@5116 796 [super draggedImage:image beganAt:screenPoint];
michaelm@5116 797 }
michaelm@5116 798
michaelm@5116 799 - (void)draggedImage:(NSImage *)image endedAt:(NSPoint)screenPoint operation:(NSDragOperation)operation
michaelm@5116 800 {
michaelm@5116 801 // If draggingSource is nil route the message to the superclass (if responding to the selector):
michaelm@5116 802 CDragSource *dragSource = self._dragSource;
aniyogi@14038 803
michaelm@5116 804 if (dragSource != nil)
michaelm@5116 805 [dragSource draggedImage:image endedAt:screenPoint operation:operation];
michaelm@5116 806 else if ([super respondsToSelector:@selector(draggedImage:::)])
michaelm@5116 807 [super draggedImage:image endedAt:screenPoint operation:operation];
michaelm@5116 808 }
michaelm@5116 809
michaelm@5116 810 - (void)draggedImage:(NSImage *)image movedTo:(NSPoint)screenPoint
michaelm@5116 811 {
michaelm@5116 812 // If draggingSource is nil route the message to the superclass (if responding to the selector):
michaelm@5116 813 CDragSource *dragSource = self._dragSource;
aniyogi@14038 814
michaelm@5116 815 if (dragSource != nil)
michaelm@5116 816 [dragSource draggedImage:image movedTo:screenPoint];
michaelm@5116 817 else if ([super respondsToSelector:@selector(draggedImage::)])
michaelm@5116 818 [super draggedImage:image movedTo:screenPoint];
michaelm@5116 819 }
michaelm@5116 820
michaelm@5116 821 - (BOOL)ignoreModifierKeysWhileDragging
michaelm@5116 822 {
michaelm@5116 823 // If draggingSource is nil route the message to the superclass (if responding to the selector):
michaelm@5116 824 CDragSource *dragSource = self._dragSource;
michaelm@5116 825 BOOL result = FALSE;
aniyogi@14038 826
michaelm@5116 827 if (dragSource != nil)
michaelm@5116 828 result = [dragSource ignoreModifierKeysWhileDragging];
michaelm@5116 829 else if ([super respondsToSelector:@selector(ignoreModifierKeysWhileDragging)])
michaelm@5116 830 result = [super ignoreModifierKeysWhileDragging];
aniyogi@14038 831
michaelm@5116 832 return result;
michaelm@5116 833 }
michaelm@5116 834
michaelm@5116 835 /******************************** END NSDraggingSource Interface ********************************/
michaelm@5116 836
michaelm@5116 837 /******************************** BEGIN NSDraggingDestination Interface ********************************/
michaelm@5116 838
michaelm@5116 839 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
michaelm@5116 840 {
michaelm@5116 841 // If draggingDestination is nil route the message to the superclass:
michaelm@5116 842 CDropTarget *dropTarget = self._dropTarget;
michaelm@5116 843 NSDragOperation dragOp = NSDragOperationNone;
aniyogi@14038 844
michaelm@5116 845 if (dropTarget != nil)
michaelm@5116 846 dragOp = [dropTarget draggingEntered:sender];
michaelm@5116 847 else if ([super respondsToSelector:@selector(draggingEntered:)])
michaelm@5116 848 dragOp = [super draggingEntered:sender];
aniyogi@14038 849
michaelm@5116 850 return dragOp;
michaelm@5116 851 }
michaelm@5116 852
michaelm@5116 853 - (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender
michaelm@5116 854 {
michaelm@5116 855 // If draggingDestination is nil route the message to the superclass:
michaelm@5116 856 CDropTarget *dropTarget = self._dropTarget;
michaelm@5116 857 NSDragOperation dragOp = NSDragOperationNone;
aniyogi@14038 858
michaelm@5116 859 if (dropTarget != nil)
michaelm@5116 860 dragOp = [dropTarget draggingUpdated:sender];
michaelm@5116 861 else if ([super respondsToSelector:@selector(draggingUpdated:)])
michaelm@5116 862 dragOp = [super draggingUpdated:sender];
aniyogi@14038 863
michaelm@5116 864 return dragOp;
michaelm@5116 865 }
michaelm@5116 866
michaelm@5116 867 - (void)draggingExited:(id <NSDraggingInfo>)sender
michaelm@5116 868 {
michaelm@5116 869 // If draggingDestination is nil route the message to the superclass:
michaelm@5116 870 CDropTarget *dropTarget = self._dropTarget;
aniyogi@14038 871
michaelm@5116 872 if (dropTarget != nil)
michaelm@5116 873 [dropTarget draggingExited:sender];
michaelm@5116 874 else if ([super respondsToSelector:@selector(draggingExited:)])
michaelm@5116 875 [super draggingExited:sender];
michaelm@5116 876 }
michaelm@5116 877
michaelm@5116 878 - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
michaelm@5116 879 {
michaelm@5116 880 // If draggingDestination is nil route the message to the superclass:
michaelm@5116 881 CDropTarget *dropTarget = self._dropTarget;
michaelm@5116 882 BOOL result = FALSE;
aniyogi@14038 883
michaelm@5116 884 if (dropTarget != nil)
michaelm@5116 885 result = [dropTarget prepareForDragOperation:sender];
michaelm@5116 886 else if ([super respondsToSelector:@selector(prepareForDragOperation:)])
michaelm@5116 887 result = [super prepareForDragOperation:sender];
aniyogi@14038 888
michaelm@5116 889 return result;
michaelm@5116 890 }
michaelm@5116 891
michaelm@5116 892 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
michaelm@5116 893 {
michaelm@5116 894 // If draggingDestination is nil route the message to the superclass:
michaelm@5116 895 CDropTarget *dropTarget = self._dropTarget;
michaelm@5116 896 BOOL result = FALSE;
aniyogi@14038 897
michaelm@5116 898 if (dropTarget != nil)
michaelm@5116 899 result = [dropTarget performDragOperation:sender];
michaelm@5116 900 else if ([super respondsToSelector:@selector(performDragOperation:)])
michaelm@5116 901 result = [super performDragOperation:sender];
aniyogi@14038 902
michaelm@5116 903 return result;
michaelm@5116 904 }
michaelm@5116 905
michaelm@5116 906 - (void)concludeDragOperation:(id <NSDraggingInfo>)sender
michaelm@5116 907 {
michaelm@5116 908 // If draggingDestination is nil route the message to the superclass:
michaelm@5116 909 CDropTarget *dropTarget = self._dropTarget;
aniyogi@14038 910
michaelm@5116 911 if (dropTarget != nil)
michaelm@5116 912 [dropTarget concludeDragOperation:sender];
michaelm@5116 913 else if ([super respondsToSelector:@selector(concludeDragOperation:)])
michaelm@5116 914 [super concludeDragOperation:sender];
michaelm@5116 915 }
michaelm@5116 916
michaelm@5116 917 - (void)draggingEnded:(id <NSDraggingInfo>)sender
michaelm@5116 918 {
michaelm@5116 919 // If draggingDestination is nil route the message to the superclass:
michaelm@5116 920 CDropTarget *dropTarget = self._dropTarget;
aniyogi@14038 921
michaelm@5116 922 if (dropTarget != nil)
michaelm@5116 923 [dropTarget draggingEnded:sender];
michaelm@5116 924 else if ([super respondsToSelector:@selector(draggingEnded:)])
michaelm@5116 925 [super draggingEnded:sender];
michaelm@5116 926 }
michaelm@5116 927
michaelm@5116 928 /******************************** END NSDraggingDestination Interface ********************************/
michaelm@5116 929
michaelm@5116 930 /******************************** BEGIN NSTextInputClient Protocol ********************************/
michaelm@5116 931
michaelm@5116 932
michaelm@5116 933 JNF_CLASS_CACHE(jc_CInputMethod, "sun/lwawt/macosx/CInputMethod");
michaelm@5116 934
michaelm@5116 935 - (void) insertText:(id)aString replacementRange:(NSRange)replacementRange
michaelm@5116 936 {
michaelm@5116 937 #ifdef IM_DEBUG
michaelm@5116 938 fprintf(stderr, "AWTView InputMethod Selector Called : [insertText]: %s\n", [aString UTF8String]);
michaelm@5116 939 #endif // IM_DEBUG
aniyogi@14038 940
michaelm@5116 941 if (fInputMethodLOCKABLE == NULL) {
michaelm@5116 942 return;
michaelm@5116 943 }
aniyogi@14038 944
michaelm@5116 945 // Insert happens at the end of PAH
michaelm@5116 946 fInPressAndHold = NO;
aniyogi@14038 947
michaelm@5116 948 // insertText gets called when the user commits text generated from an input method. It also gets
michaelm@5116 949 // called during ordinary input as well. We only need to send an input method event when we have marked
michaelm@5116 950 // text, or 'text in progress'. We also need to send the event if we get an insert text out of the blue!
michaelm@5116 951 // (i.e., when the user uses the Character palette or Inkwell), or when the string to insert is a complex
michaelm@5116 952 // Unicode value.
aniyogi@14038 953
aniyogi@14038 954 NSMutableString * useString = [self parseString:aString];
aniyogi@14038 955 NSUInteger utf16Length = [useString lengthOfBytesUsingEncoding:NSUTF16StringEncoding];
aniyogi@14038 956 NSUInteger utf8Length = [useString lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
alitvinov@13095 957 BOOL aStringIsComplex = NO;
alitvinov@13095 958 if ((utf16Length > 2) ||
aniyogi@14038 959 ((utf8Length > 1) && [self isCodePointInUnicodeBlockNeedingIMEvent:[useString characterAtIndex:0]])) {
alitvinov@13095 960 aStringIsComplex = YES;
alitvinov@13095 961 }
aniyogi@14038 962
alitvinov@13095 963 if ([self hasMarkedText] || !fProcessingKeystroke || aStringIsComplex) {
michaelm@5116 964 JNIEnv *env = [ThreadUtilities getJNIEnv];
aniyogi@14038 965
michaelm@5116 966 static JNF_MEMBER_CACHE(jm_selectPreviousGlyph, jc_CInputMethod, "selectPreviousGlyph", "()V");
michaelm@5116 967 // We need to select the previous glyph so that it is overwritten.
michaelm@5116 968 if (fPAHNeedsToSelect) {
michaelm@5116 969 JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_selectPreviousGlyph);
michaelm@5116 970 fPAHNeedsToSelect = NO;
michaelm@5116 971 }
aniyogi@14038 972
michaelm@5116 973 static JNF_MEMBER_CACHE(jm_insertText, jc_CInputMethod, "insertText", "(Ljava/lang/String;)V");
aniyogi@14038 974 jstring insertedText = JNFNSToJavaString(env, useString);
michaelm@5116 975 JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_insertText, insertedText); // AWT_THREADING Safe (AWTRunLoopMode)
michaelm@5116 976 (*env)->DeleteLocalRef(env, insertedText);
aniyogi@14038 977
michaelm@5116 978 // The input method event will create psuedo-key events for each character in the committed string.
michaelm@5116 979 // We also don't want to send the character that triggered the insertText, usually a return. [3337563]
michaelm@5116 980 fKeyEventsNeeded = NO;
michaelm@5116 981 }
michaelm@5116 982 fPAHNeedsToSelect = NO;
michaelm@5116 983 }
michaelm@5116 984
michaelm@5116 985 - (void) doCommandBySelector:(SEL)aSelector
michaelm@5116 986 {
michaelm@5116 987 #ifdef IM_DEBUG
michaelm@5116 988 fprintf(stderr, "AWTView InputMethod Selector Called : [doCommandBySelector]\n");
michaelm@5116 989 NSLog(@"%@", NSStringFromSelector(aSelector));
michaelm@5116 990 #endif // IM_DEBUG
michaelm@5116 991 if (@selector(insertNewline:) == aSelector || @selector(insertTab:) == aSelector || @selector(deleteBackward:) == aSelector)
michaelm@5116 992 {
michaelm@5116 993 fKeyEventsNeeded = YES;
michaelm@5116 994 }
michaelm@5116 995 }
michaelm@5116 996
michaelm@5116 997 // setMarkedText: cannot take a nil first argument. aString can be NSString or NSAttributedString
michaelm@5116 998 - (void) setMarkedText:(id)aString selectedRange:(NSRange)selectionRange replacementRange:(NSRange)replacementRange
michaelm@5116 999 {
michaelm@5116 1000 if (!fInputMethodLOCKABLE)
michaelm@5116 1001 return;
aniyogi@14038 1002
michaelm@5116 1003 BOOL isAttributedString = [aString isKindOfClass:[NSAttributedString class]];
michaelm@5116 1004 NSAttributedString *attrString = (isAttributedString ? (NSAttributedString *)aString : nil);
michaelm@5116 1005 NSString *incomingString = (isAttributedString ? [aString string] : aString);
michaelm@5116 1006 #ifdef IM_DEBUG
michaelm@5116 1007 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 1008 #endif // IM_DEBUG
michaelm@5116 1009 static JNF_MEMBER_CACHE(jm_startIMUpdate, jc_CInputMethod, "startIMUpdate", "(Ljava/lang/String;)V");
michaelm@5116 1010 static JNF_MEMBER_CACHE(jm_addAttribute, jc_CInputMethod, "addAttribute", "(ZZII)V");
michaelm@5116 1011 static JNF_MEMBER_CACHE(jm_dispatchText, jc_CInputMethod, "dispatchText", "(IIZ)V");
michaelm@5116 1012 JNIEnv *env = [ThreadUtilities getJNIEnv];
aniyogi@14038 1013
michaelm@5116 1014 // NSInputContext already did the analysis of the TSM event and created attributes indicating
michaelm@5116 1015 // the underlining and color that should be done to the string. We need to look at the underline
michaelm@5116 1016 // style and color to determine what kind of Java hilighting needs to be done.
michaelm@5116 1017 jstring inProcessText = JNFNSToJavaString(env, incomingString);
michaelm@5116 1018 JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_startIMUpdate, inProcessText); // AWT_THREADING Safe (AWTRunLoopMode)
michaelm@5116 1019 (*env)->DeleteLocalRef(env, inProcessText);
aniyogi@14038 1020
michaelm@5116 1021 if (isAttributedString) {
michaelm@5116 1022 NSUInteger length;
michaelm@5116 1023 NSRange effectiveRange;
michaelm@5116 1024 NSDictionary *attributes;
michaelm@5116 1025 length = [attrString length];
michaelm@5116 1026 effectiveRange = NSMakeRange(0, 0);
michaelm@5116 1027 while (NSMaxRange(effectiveRange) < length) {
michaelm@5116 1028 attributes = [attrString attributesAtIndex:NSMaxRange(effectiveRange)
michaelm@5116 1029 effectiveRange:&effectiveRange];
michaelm@5116 1030 if (attributes) {
michaelm@5116 1031 BOOL isThickUnderline, isGray;
michaelm@5116 1032 NSNumber *underlineSizeObj =
michaelm@5116 1033 (NSNumber *)[attributes objectForKey:NSUnderlineStyleAttributeName];
michaelm@5116 1034 NSInteger underlineSize = [underlineSizeObj integerValue];
michaelm@5116 1035 isThickUnderline = (underlineSize > 1);
aniyogi@14038 1036
michaelm@5116 1037 NSColor *underlineColorObj =
michaelm@5116 1038 (NSColor *)[attributes objectForKey:NSUnderlineColorAttributeName];
michaelm@5116 1039 isGray = !([underlineColorObj isEqual:[NSColor blackColor]]);
aniyogi@14038 1040
michaelm@5116 1041 JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_addAttribute, isThickUnderline, isGray, effectiveRange.location, effectiveRange.length); // AWT_THREADING Safe (AWTRunLoopMode)
michaelm@5116 1042 }
michaelm@5116 1043 }
michaelm@5116 1044 }
aniyogi@14038 1045
michaelm@5116 1046 static JNF_MEMBER_CACHE(jm_selectPreviousGlyph, jc_CInputMethod, "selectPreviousGlyph", "()V");
michaelm@5116 1047 // We need to select the previous glyph so that it is overwritten.
michaelm@5116 1048 if (fPAHNeedsToSelect) {
michaelm@5116 1049 JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_selectPreviousGlyph);
michaelm@5116 1050 fPAHNeedsToSelect = NO;
michaelm@5116 1051 }
aniyogi@14038 1052
michaelm@5116 1053 JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_dispatchText, selectionRange.location, selectionRange.length, JNI_FALSE); // AWT_THREADING Safe (AWTRunLoopMode)
aniyogi@14038 1054
michaelm@5116 1055 // If the marked text is being cleared (zero-length string) don't handle the key event.
michaelm@5116 1056 if ([incomingString length] == 0) {
michaelm@5116 1057 fKeyEventsNeeded = NO;
michaelm@5116 1058 }
michaelm@5116 1059 }
michaelm@5116 1060
michaelm@5116 1061 - (void) unmarkText
michaelm@5116 1062 {
michaelm@5116 1063 #ifdef IM_DEBUG
michaelm@5116 1064 fprintf(stderr, "AWTView InputMethod Selector Called : [unmarkText]\n");
michaelm@5116 1065 #endif // IM_DEBUG
aniyogi@14038 1066
michaelm@5116 1067 if (!fInputMethodLOCKABLE) {
michaelm@5116 1068 return;
michaelm@5116 1069 }
aniyogi@14038 1070
michaelm@5116 1071 // unmarkText cancels any input in progress and commits it to the text field.
michaelm@5116 1072 static JNF_MEMBER_CACHE(jm_unmarkText, jc_CInputMethod, "unmarkText", "()V");
michaelm@5116 1073 JNIEnv *env = [ThreadUtilities getJNIEnv];
michaelm@5116 1074 JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_unmarkText); // AWT_THREADING Safe (AWTRunLoopMode)
aniyogi@14038 1075
michaelm@5116 1076 }
michaelm@5116 1077
michaelm@5116 1078 - (BOOL) hasMarkedText
michaelm@5116 1079 {
michaelm@5116 1080 #ifdef IM_DEBUG
michaelm@5116 1081 fprintf(stderr, "AWTView InputMethod Selector Called : [hasMarkedText]\n");
michaelm@5116 1082 #endif // IM_DEBUG
aniyogi@14038 1083
michaelm@5116 1084 if (!fInputMethodLOCKABLE) {
michaelm@5116 1085 return NO;
michaelm@5116 1086 }
aniyogi@14038 1087
michaelm@5116 1088 static JNF_MEMBER_CACHE(jf_fCurrentText, jc_CInputMethod, "fCurrentText", "Ljava/text/AttributedString;");
michaelm@5116 1089 static JNF_MEMBER_CACHE(jf_fCurrentTextLength, jc_CInputMethod, "fCurrentTextLength", "I");
michaelm@5116 1090 JNIEnv *env = [ThreadUtilities getJNIEnv];
michaelm@5116 1091 jobject currentText = JNFGetObjectField(env, fInputMethodLOCKABLE, jf_fCurrentText);
aniyogi@14038 1092
michaelm@5116 1093 jint currentTextLength = JNFGetIntField(env, fInputMethodLOCKABLE, jf_fCurrentTextLength);
aniyogi@14038 1094
michaelm@5116 1095 BOOL hasMarkedText = (currentText != NULL && currentTextLength > 0);
aniyogi@14038 1096
michaelm@5116 1097 if (currentText != NULL) {
michaelm@5116 1098 (*env)->DeleteLocalRef(env, currentText);
michaelm@5116 1099 }
aniyogi@14038 1100
michaelm@5116 1101 return hasMarkedText;
michaelm@5116 1102 }
michaelm@5116 1103
michaelm@5116 1104 - (NSInteger) conversationIdentifier
michaelm@5116 1105 {
michaelm@5116 1106 #ifdef IM_DEBUG
michaelm@5116 1107 fprintf(stderr, "AWTView InputMethod Selector Called : [conversationIdentifier]\n");
michaelm@5116 1108 #endif // IM_DEBUG
aniyogi@14038 1109
michaelm@5116 1110 return (NSInteger) self;
michaelm@5116 1111 }
michaelm@5116 1112
michaelm@5116 1113 /* Returns attributed string at the range. This allows input mangers to
michaelm@5116 1114 query any range in backing-store (Andy's request)
michaelm@5116 1115 */
michaelm@5116 1116 - (NSAttributedString *) attributedSubstringForProposedRange:(NSRange)theRange actualRange:(NSRangePointer)actualRange
michaelm@5116 1117 {
michaelm@5116 1118 #ifdef IM_DEBUG
michaelm@5116 1119 fprintf(stderr, "AWTView InputMethod Selector Called : [attributedSubstringFromRange] location=%lu, length=%lu\n", (unsigned long)theRange.location, (unsigned long)theRange.length);
michaelm@5116 1120 #endif // IM_DEBUG
aniyogi@14038 1121
michaelm@5116 1122 static JNF_MEMBER_CACHE(jm_substringFromRange, jc_CInputMethod, "attributedSubstringFromRange", "(II)Ljava/lang/String;");
michaelm@5116 1123 JNIEnv *env = [ThreadUtilities getJNIEnv];
michaelm@5116 1124 jobject theString = JNFCallObjectMethod(env, fInputMethodLOCKABLE, jm_substringFromRange, theRange.location, theRange.length); // AWT_THREADING Safe (AWTRunLoopMode)
aniyogi@14038 1125
michaelm@5116 1126 id result = [[[NSAttributedString alloc] initWithString:JNFJavaToNSString(env, theString)] autorelease];
michaelm@5116 1127 #ifdef IM_DEBUG
michaelm@5116 1128 NSLog(@"attributedSubstringFromRange returning \"%@\"", result);
michaelm@5116 1129 #endif // IM_DEBUG
aniyogi@14038 1130
michaelm@5116 1131 (*env)->DeleteLocalRef(env, theString);
michaelm@5116 1132 return result;
michaelm@5116 1133 }
michaelm@5116 1134
michaelm@5116 1135 /* This method returns the range for marked region. If hasMarkedText == false,
michaelm@5116 1136 it'll return NSNotFound location & 0 length range.
michaelm@5116 1137 */
michaelm@5116 1138 - (NSRange) markedRange
michaelm@5116 1139 {
aniyogi@14038 1140
michaelm@5116 1141 #ifdef IM_DEBUG
michaelm@5116 1142 fprintf(stderr, "AWTView InputMethod Selector Called : [markedRange]\n");
michaelm@5116 1143 #endif // IM_DEBUG
aniyogi@14038 1144
michaelm@5116 1145 if (!fInputMethodLOCKABLE) {
michaelm@5116 1146 return NSMakeRange(NSNotFound, 0);
michaelm@5116 1147 }
aniyogi@14038 1148
michaelm@5116 1149 static JNF_MEMBER_CACHE(jm_markedRange, jc_CInputMethod, "markedRange", "()[I");
michaelm@5116 1150 JNIEnv *env = [ThreadUtilities getJNIEnv];
michaelm@5116 1151 jarray array;
michaelm@5116 1152 jboolean isCopy;
michaelm@5116 1153 jint *_array;
serb@9588 1154 NSRange range = NSMakeRange(NSNotFound, 0);
aniyogi@14038 1155
michaelm@5116 1156 array = JNFCallObjectMethod(env, fInputMethodLOCKABLE, jm_markedRange); // AWT_THREADING Safe (AWTRunLoopMode)
aniyogi@14038 1157
michaelm@5116 1158 if (array) {
michaelm@5116 1159 _array = (*env)->GetIntArrayElements(env, array, &isCopy);
serb@9588 1160 if (_array != NULL) {
serb@9588 1161 range.location = _array[0];
serb@9588 1162 range.length = _array[1];
michaelm@5116 1163 #ifdef IM_DEBUG
serb@9588 1164 fprintf(stderr, "markedRange returning (%lu, %lu)\n",
serb@9588 1165 (unsigned long)range.location, (unsigned long)range.length);
michaelm@5116 1166 #endif // IM_DEBUG
serb@9588 1167 (*env)->ReleaseIntArrayElements(env, array, _array, 0);
serb@9588 1168 }
michaelm@5116 1169 (*env)->DeleteLocalRef(env, array);
michaelm@5116 1170 }
aniyogi@14038 1171
michaelm@5116 1172 return range;
michaelm@5116 1173 }
michaelm@5116 1174
michaelm@5116 1175 /* This method returns the range for selected region. Just like markedRange method,
michaelm@5116 1176 its location field contains char index from the text beginning.
michaelm@5116 1177 */
michaelm@5116 1178 - (NSRange) selectedRange
michaelm@5116 1179 {
michaelm@5116 1180 if (!fInputMethodLOCKABLE) {
michaelm@5116 1181 return NSMakeRange(NSNotFound, 0);
michaelm@5116 1182 }
aniyogi@14038 1183
michaelm@5116 1184 static JNF_MEMBER_CACHE(jm_selectedRange, jc_CInputMethod, "selectedRange", "()[I");
michaelm@5116 1185 JNIEnv *env = [ThreadUtilities getJNIEnv];
michaelm@5116 1186 jarray array;
michaelm@5116 1187 jboolean isCopy;
michaelm@5116 1188 jint *_array;
serb@9588 1189 NSRange range = NSMakeRange(NSNotFound, 0);
aniyogi@14038 1190
michaelm@5116 1191 #ifdef IM_DEBUG
michaelm@5116 1192 fprintf(stderr, "AWTView InputMethod Selector Called : [selectedRange]\n");
michaelm@5116 1193 #endif // IM_DEBUG
aniyogi@14038 1194
michaelm@5116 1195 array = JNFCallObjectMethod(env, fInputMethodLOCKABLE, jm_selectedRange); // AWT_THREADING Safe (AWTRunLoopMode)
michaelm@5116 1196 if (array) {
michaelm@5116 1197 _array = (*env)->GetIntArrayElements(env, array, &isCopy);
serb@9588 1198 if (_array != NULL) {
serb@9588 1199 range.location = _array[0];
serb@9588 1200 range.length = _array[1];
serb@9588 1201 (*env)->ReleaseIntArrayElements(env, array, _array, 0);
serb@9588 1202 }
michaelm@5116 1203 (*env)->DeleteLocalRef(env, array);
michaelm@5116 1204 }
aniyogi@14038 1205
michaelm@5116 1206 return range;
michaelm@5116 1207 }
michaelm@5116 1208
michaelm@5116 1209 /* This method returns the first frame of rects for theRange in screen coordindate system.
michaelm@5116 1210 */
michaelm@5116 1211 - (NSRect) firstRectForCharacterRange:(NSRange)theRange actualRange:(NSRangePointer)actualRange
michaelm@5116 1212 {
michaelm@5116 1213 if (!fInputMethodLOCKABLE) {
serb@9588 1214 return NSZeroRect;
michaelm@5116 1215 }
aniyogi@14038 1216
michaelm@5116 1217 static JNF_MEMBER_CACHE(jm_firstRectForCharacterRange, jc_CInputMethod,
michaelm@5116 1218 "firstRectForCharacterRange", "(I)[I");
michaelm@5116 1219 JNIEnv *env = [ThreadUtilities getJNIEnv];
michaelm@5116 1220 jarray array;
michaelm@5116 1221 jboolean isCopy;
michaelm@5116 1222 jint *_array;
michaelm@5116 1223 NSRect rect;
aniyogi@14038 1224
michaelm@5116 1225 #ifdef IM_DEBUG
serb@9588 1226 fprintf(stderr,
serb@9588 1227 "AWTView InputMethod Selector Called : [firstRectForCharacterRange:] location=%lu, length=%lu\n",
serb@9588 1228 (unsigned long)theRange.location, (unsigned long)theRange.length);
michaelm@5116 1229 #endif // IM_DEBUG
aniyogi@14038 1230
serb@9588 1231 array = JNFCallObjectMethod(env, fInputMethodLOCKABLE, jm_firstRectForCharacterRange,
serb@9588 1232 theRange.location); // AWT_THREADING Safe (AWTRunLoopMode)
aniyogi@14038 1233
michaelm@5116 1234 _array = (*env)->GetIntArrayElements(env, array, &isCopy);
serb@9588 1235 if (_array) {
serb@9588 1236 rect = ConvertNSScreenRect(env, NSMakeRect(_array[0], _array[1], _array[2], _array[3]));
serb@9588 1237 (*env)->ReleaseIntArrayElements(env, array, _array, 0);
serb@9588 1238 } else {
serb@9588 1239 rect = NSZeroRect;
serb@9588 1240 }
michaelm@5116 1241 (*env)->DeleteLocalRef(env, array);
aniyogi@14038 1242
michaelm@5116 1243 #ifdef IM_DEBUG
serb@9588 1244 fprintf(stderr,
serb@9588 1245 "firstRectForCharacterRange returning x=%f, y=%f, width=%f, height=%f\n",
serb@9588 1246 rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
michaelm@5116 1247 #endif // IM_DEBUG
michaelm@5116 1248 return rect;
michaelm@5116 1249 }
michaelm@5116 1250
michaelm@5116 1251 /* This method returns the index for character that is nearest to thePoint. thPoint is in
michaelm@5116 1252 screen coordinate system.
michaelm@5116 1253 */
michaelm@5116 1254 - (NSUInteger)characterIndexForPoint:(NSPoint)thePoint
michaelm@5116 1255 {
michaelm@5116 1256 if (!fInputMethodLOCKABLE) {
michaelm@5116 1257 return NSNotFound;
michaelm@5116 1258 }
aniyogi@14038 1259
michaelm@5116 1260 static JNF_MEMBER_CACHE(jm_characterIndexForPoint, jc_CInputMethod,
michaelm@5116 1261 "characterIndexForPoint", "(II)I");
michaelm@5116 1262 JNIEnv *env = [ThreadUtilities getJNIEnv];
aniyogi@14038 1263
michaelm@5116 1264 NSPoint flippedLocation = ConvertNSScreenPoint(env, thePoint);
aniyogi@14038 1265
michaelm@5116 1266 #ifdef IM_DEBUG
michaelm@5116 1267 fprintf(stderr, "AWTView InputMethod Selector Called : [characterIndexForPoint:(NSPoint)thePoint] x=%f, y=%f\n", flippedLocation.x, flippedLocation.y);
michaelm@5116 1268 #endif // IM_DEBUG
aniyogi@14038 1269
michaelm@5116 1270 jint index = JNFCallIntMethod(env, fInputMethodLOCKABLE, jm_characterIndexForPoint, (jint)flippedLocation.x, (jint)flippedLocation.y); // AWT_THREADING Safe (AWTRunLoopMode)
aniyogi@14038 1271
michaelm@5116 1272 #ifdef IM_DEBUG
michaelm@5116 1273 fprintf(stderr, "characterIndexForPoint returning %ld\n", index);
michaelm@5116 1274 #endif // IM_DEBUG
aniyogi@14038 1275
michaelm@5116 1276 if (index == -1) {
michaelm@5116 1277 return NSNotFound;
michaelm@5116 1278 } else {
michaelm@5116 1279 return (NSUInteger)index;
michaelm@5116 1280 }
michaelm@5116 1281 }
michaelm@5116 1282
michaelm@5116 1283 - (NSArray*) validAttributesForMarkedText
michaelm@5116 1284 {
michaelm@5116 1285 #ifdef IM_DEBUG
michaelm@5116 1286 fprintf(stderr, "AWTView InputMethod Selector Called : [validAttributesForMarkedText]\n");
michaelm@5116 1287 #endif // IM_DEBUG
aniyogi@14038 1288
michaelm@5116 1289 return [NSArray array];
michaelm@5116 1290 }
michaelm@5116 1291
michaelm@5116 1292 - (void)setInputMethod:(jobject)inputMethod
michaelm@5116 1293 {
michaelm@5116 1294 #ifdef IM_DEBUG
michaelm@5116 1295 fprintf(stderr, "AWTView InputMethod Selector Called : [setInputMethod]\n");
michaelm@5116 1296 #endif // IM_DEBUG
aniyogi@14038 1297
michaelm@5116 1298 JNIEnv *env = [ThreadUtilities getJNIEnv];
aniyogi@14038 1299
michaelm@5116 1300 // Get rid of the old one
michaelm@5116 1301 if (fInputMethodLOCKABLE) {
michaelm@5116 1302 JNFDeleteGlobalRef(env, fInputMethodLOCKABLE);
michaelm@5116 1303 }
aniyogi@14038 1304
michaelm@5116 1305 // Save a global ref to the new input method.
michaelm@5116 1306 if (inputMethod != NULL)
michaelm@5116 1307 fInputMethodLOCKABLE = JNFNewGlobalRef(env, inputMethod);
michaelm@5116 1308 else
michaelm@5116 1309 fInputMethodLOCKABLE = NULL;
michaelm@5116 1310 }
michaelm@5116 1311
michaelm@5116 1312 - (void)abandonInput
michaelm@5116 1313 {
michaelm@5116 1314 #ifdef IM_DEBUG
michaelm@5116 1315 fprintf(stderr, "AWTView InputMethod Selector Called : [abandonInput]\n");
michaelm@5116 1316 #endif // IM_DEBUG
aniyogi@14038 1317
pchelko@6623 1318 [ThreadUtilities performOnMainThread:@selector(markedTextAbandoned:) on:[NSInputManager currentInputManager] withObject:self waitUntilDone:YES];
michaelm@5116 1319 [self unmarkText];
michaelm@5116 1320 }
michaelm@5116 1321
michaelm@5116 1322 /******************************** END NSTextInputClient Protocol ********************************/
michaelm@5116 1323
michaelm@5116 1324
michaelm@5116 1325
michaelm@5116 1326
michaelm@5116 1327 @end // AWTView
michaelm@5116 1328
michaelm@5116 1329 /*
michaelm@5116 1330 * Class: sun_lwawt_macosx_CPlatformView
michaelm@5116 1331 * Method: nativeCreateView
michaelm@5116 1332 * Signature: (IIII)J
michaelm@5116 1333 */
michaelm@5116 1334 JNIEXPORT jlong JNICALL
michaelm@5116 1335 Java_sun_lwawt_macosx_CPlatformView_nativeCreateView
michaelm@5116 1336 (JNIEnv *env, jobject obj, jint originX, jint originY, jint width, jint height, jlong windowLayerPtr)
michaelm@5116 1337 {
michaelm@5116 1338 __block AWTView *newView = nil;
aniyogi@14038 1339
aniyogi@14038 1340 JNF_COCOA_ENTER(env);
aniyogi@14038 1341
michaelm@5116 1342 NSRect rect = NSMakeRect(originX, originY, width, height);
ant@14365 1343 jobject cPlatformView = (*env)->NewWeakGlobalRef(env, obj);
aniyogi@14038 1344
serb@6219 1345 [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
aniyogi@14038 1346
michaelm@5116 1347 CALayer *windowLayer = jlong_to_ptr(windowLayerPtr);
pchelko@9614 1348 newView = [[AWTView alloc] initWithRect:rect
pchelko@9614 1349 platformView:cPlatformView
pchelko@9614 1350 windowLayer:windowLayer];
michaelm@5116 1351 }];
aniyogi@14038 1352
aniyogi@14038 1353 JNF_COCOA_EXIT(env);
aniyogi@14038 1354
michaelm@5116 1355 return ptr_to_jlong(newView);
michaelm@5116 1356 }
serb@6219 1357
serb@6219 1358 /*
serb@6219 1359 * Class: sun_lwawt_macosx_CPlatformView
serb@6219 1360 * Method: nativeSetAutoResizable
serb@6219 1361 * Signature: (JZ)V;
serb@6219 1362 */
serb@6219 1363
serb@6219 1364 JNIEXPORT void JNICALL
serb@6219 1365 Java_sun_lwawt_macosx_CPlatformView_nativeSetAutoResizable
serb@6219 1366 (JNIEnv *env, jclass cls, jlong viewPtr, jboolean toResize)
serb@6219 1367 {
aniyogi@14038 1368 JNF_COCOA_ENTER(env);
serb@6219 1369
aniyogi@14038 1370 NSView *view = (NSView *)jlong_to_ptr(viewPtr);
aniyogi@14038 1371
aniyogi@14038 1372 [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
aniyogi@14038 1373
aniyogi@14038 1374 if (toResize) {
aniyogi@14038 1375 [view setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable];
aniyogi@14038 1376 } else {
aniyogi@14038 1377 [view setAutoresizingMask: NSViewMinYMargin | NSViewMaxXMargin];
aniyogi@14038 1378 }
aniyogi@14038 1379
aniyogi@14038 1380 if ([view superview] != nil) {
aniyogi@14038 1381 [[view superview] setAutoresizesSubviews:(BOOL)toResize];
aniyogi@14038 1382 }
aniyogi@14038 1383
serb@6219 1384 }];
aniyogi@14038 1385 JNF_COCOA_EXIT(env);
serb@6219 1386 }
serb@6219 1387
serb@6219 1388 /*
serb@6219 1389 * Class: sun_lwawt_macosx_CPlatformView
serb@6219 1390 * Method: nativeGetNSViewDisplayID
serb@6219 1391 * Signature: (J)I;
serb@6219 1392 */
serb@6219 1393
serb@6219 1394 JNIEXPORT jint JNICALL
serb@6219 1395 Java_sun_lwawt_macosx_CPlatformView_nativeGetNSViewDisplayID
serb@6219 1396 (JNIEnv *env, jclass cls, jlong viewPtr)
serb@6219 1397 {
serb@6219 1398 __block jint ret; //CGDirectDisplayID
serb@6219 1399
aniyogi@14038 1400 JNF_COCOA_ENTER(env);
serb@6219 1401
aniyogi@14038 1402 NSView *view = (NSView *)jlong_to_ptr(viewPtr);
serb@6219 1403 NSWindow *window = [view window];
serb@6219 1404
serb@6219 1405 [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
aniyogi@14038 1406
aniyogi@14038 1407 ret = (jint)[[AWTWindow getNSWindowDisplayID_AppKitThread: window] intValue];
serb@6219 1408 }];
serb@6219 1409
aniyogi@14038 1410 JNF_COCOA_EXIT(env);
serb@6219 1411
serb@6219 1412 return ret;
serb@6219 1413 }
serb@6219 1414
serb@6219 1415 /*
serb@6219 1416 * Class: sun_lwawt_macosx_CPlatformView
serb@6219 1417 * Method: nativeGetLocationOnScreen
serb@6219 1418 * Signature: (J)Ljava/awt/Rectangle;
serb@6219 1419 */
serb@6219 1420
serb@6219 1421 JNIEXPORT jobject JNICALL
serb@6219 1422 Java_sun_lwawt_macosx_CPlatformView_nativeGetLocationOnScreen
serb@6219 1423 (JNIEnv *env, jclass cls, jlong viewPtr)
serb@6219 1424 {
serb@6219 1425 jobject jRect = NULL;
serb@6219 1426
aniyogi@14038 1427 JNF_COCOA_ENTER(env);
serb@6219 1428
serb@6219 1429 __block NSRect rect = NSZeroRect;
serb@6219 1430
aniyogi@14038 1431 NSView *view = (NSView *)jlong_to_ptr(viewPtr);
serb@6219 1432 [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
aniyogi@14038 1433
serb@6219 1434 NSRect viewBounds = [view bounds];
serb@6219 1435 NSRect frameInWindow = [view convertRect:viewBounds toView:nil];
serb@6219 1436 rect = [[view window] convertRectToScreen:frameInWindow];
serb@6219 1437 NSRect screenRect = [[NSScreen mainScreen] frame];
serb@6219 1438 //Convert coordinates to top-left corner origin
serb@6219 1439 rect.origin.y = screenRect.size.height - rect.origin.y - viewBounds.size.height;
serb@6219 1440 }];
serb@6219 1441 jRect = NSToJavaRect(env, rect);
serb@6219 1442
aniyogi@14038 1443 JNF_COCOA_EXIT(env);
serb@6219 1444
serb@6219 1445 return jRect;
serb@6219 1446 }
serb@6219 1447
serb@6219 1448 /*
serb@6219 1449 * Class: sun_lwawt_macosx_CPlatformView
serb@6219 1450 * Method: nativeIsViewUnderMouse
serb@6219 1451 * Signature: (J)Z;
serb@6219 1452 */
serb@6219 1453
serb@6219 1454 JNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_CPlatformView_nativeIsViewUnderMouse
serb@6219 1455 (JNIEnv *env, jclass clazz, jlong viewPtr)
serb@6219 1456 {
serb@6219 1457 __block jboolean underMouse = JNI_FALSE;
serb@6219 1458
aniyogi@14038 1459 JNF_COCOA_ENTER(env);
serb@6219 1460
serb@6219 1461 NSView *nsView = OBJC(viewPtr);
aniyogi@14038 1462 [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
aniyogi@14038 1463 NSPoint ptWindowCoords = [[nsView window] mouseLocationOutsideOfEventStream];
aniyogi@14038 1464 NSPoint ptViewCoords = [nsView convertPoint:ptWindowCoords fromView:nil];
aniyogi@14038 1465 underMouse = [nsView hitTest:ptViewCoords] != nil;
serb@6219 1466 }];
serb@6219 1467
aniyogi@14038 1468 JNF_COCOA_EXIT(env);
serb@6219 1469
serb@6219 1470 return underMouse;
serb@6219 1471 }