annotate src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m @ 11698:fc76d530de50

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