annotate src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m @ 14365:909c7db6c47d

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