annotate src/macosx/native/sun/awt/AWTView.m @ 5526:3226f1968e77

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