annotate src/macosx/native/sun/awt/AWTView.m @ 7518:7cc7125f42f6

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