66 - (id) initWithRect: (NSRect) rect 67 platformView: (jobject) cPlatformView 68 windowLayer: (CALayer*) windowLayer 69 { 70 AWT_ASSERT_APPKIT_THREAD; 71 // Initialize ourselves 72 self = [super initWithFrame: rect]; 73 if (self == nil) return self; 74 75 m_cPlatformView = cPlatformView; 76 fInputMethodLOCKABLE = NULL; 77 fKeyEventsNeeded = NO; 78 fProcessingKeystroke = NO; 79 80 fEnablePressAndHold = shouldUsePressAndHold(); 81 fInPressAndHold = NO; 82 fPAHNeedsToSelect = NO; 83 84 mouseIsOver = NO; 85 86 if (windowLayer != nil) { 87 self.cglLayer = windowLayer; 88 [self setWantsLayer: YES]; 89 [self.layer addSublayer: (CALayer *)cglLayer]; 90 [self setLayerContentsRedrawPolicy: NSViewLayerContentsRedrawDuringViewResize]; 91 [self setLayerContentsPlacement: NSViewLayerContentsPlacementTopLeft]; 92 [self setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable]; 93 94 #ifdef REMOTELAYER 95 CGLLayer *parentLayer = (CGLLayer*)self.cglLayer; 96 parentLayer.parentLayer = NULL; 97 parentLayer.remoteLayer = NULL; 98 if (JRSRemotePort != 0 && remoteSocketFD > 0) { 99 CGLLayer *remoteLayer = [[CGLLayer alloc] initWithJavaLayer: parentLayer.javaLayer]; 100 remoteLayer.target = GL_TEXTURE_2D; 101 NSLog(@"Creating Parent=%p, Remote=%p", parentLayer, remoteLayer); 102 parentLayer.remoteLayer = remoteLayer; 103 remoteLayer.parentLayer = parentLayer; 104 remoteLayer.remoteLayer = NULL; 105 remoteLayer.jrsRemoteLayer = [remoteLayer createRemoteLayerBoundTo:JRSRemotePort]; 153 - (BOOL) acceptsFirstMouse: (NSEvent *)event { 154 return YES; 155 } 156 157 - (BOOL) acceptsFirstResponder { 158 return YES; 159 } 160 161 - (BOOL) becomeFirstResponder { 162 return YES; 163 } 164 165 - (BOOL) preservesContentDuringLiveResize { 166 return YES; 167 } 168 169 /* 170 * Automatically triggered functions. 171 */ 172 173 /* 174 * MouseEvents support 175 */ 176 177 - (void) mouseDown: (NSEvent *)event { 178 NSInputManager *inputManager = [NSInputManager currentInputManager]; 179 if ([inputManager wantsToHandleMouseEvents]) { 180 #if IM_DEBUG 181 NSLog(@"-> IM wants to handle event"); 182 #endif 183 if (![inputManager handleMouseEvent:event]) { 184 [self deliverJavaMouseEvent: event]; 185 } else { 186 #if IM_DEBUG 187 NSLog(@"-> Event was handled."); 188 #endif 189 } 190 } else { 191 #if IM_DEBUG 192 NSLog(@"-> IM does not want to handle event"); 416 } 417 418 static JNF_CLASS_CACHE(jc_NSEvent, "sun/lwawt/macosx/event/NSEvent"); 419 static JNF_CTOR_CACHE(jctor_NSEvent, jc_NSEvent, "(IISLjava/lang/String;)V"); 420 jobject jevent = JNFNewObject(env, jctor_NSEvent, 421 [event type], 422 [event modifierFlags], 423 [event keyCode], 424 characters); 425 426 static JNF_CLASS_CACHE(jc_PlatformView, "sun/lwawt/macosx/CPlatformView"); 427 static JNF_MEMBER_CACHE(jm_deliverKeyEvent, jc_PlatformView, 428 "deliverKeyEvent", "(Lsun/lwawt/macosx/event/NSEvent;)V"); 429 JNFCallVoidMethod(env, m_cPlatformView, jm_deliverKeyEvent, jevent); 430 431 if (characters != NULL) { 432 (*env)->DeleteLocalRef(env, characters); 433 } 434 } 435 436 - (void) drawRect:(NSRect)dirtyRect { 437 AWT_ASSERT_APPKIT_THREAD; 438 439 [super drawRect:dirtyRect]; 440 JNIEnv *env = [ThreadUtilities getJNIEnv]; 441 if (env != NULL) { 442 /* 443 if ([self inLiveResize]) { 444 NSRect rs[4]; 445 NSInteger count; 446 [self getRectsExposedDuringLiveResize:rs count:&count]; 447 for (int i = 0; i < count; i++) { 448 JNU_CallMethodByName(env, NULL, [m_awtWindow cPlatformView], 449 "deliverWindowDidExposeEvent", "(FFFF)V", 450 (jfloat)rs[i].origin.x, (jfloat)rs[i].origin.y, 451 (jfloat)rs[i].size.width, (jfloat)rs[i].size.height); 452 if ((*env)->ExceptionOccurred(env)) { 453 (*env)->ExceptionDescribe(env); 454 (*env)->ExceptionClear(env); 455 } 1199 1200 /******************************** END NSTextInputClient Protocol ********************************/ 1201 1202 1203 1204 1205 @end // AWTView 1206 1207 /* 1208 * Class: sun_lwawt_macosx_CPlatformView 1209 * Method: nativeCreateView 1210 * Signature: (IIII)J 1211 */ 1212 JNIEXPORT jlong JNICALL 1213 Java_sun_lwawt_macosx_CPlatformView_nativeCreateView 1214 (JNIEnv *env, jobject obj, jint originX, jint originY, jint width, jint height, jlong windowLayerPtr) 1215 { 1216 __block AWTView *newView = nil; 1217 1218 JNF_COCOA_ENTER(env); 1219 AWT_ASSERT_NOT_APPKIT_THREAD; 1220 1221 NSRect rect = NSMakeRect(originX, originY, width, height); 1222 jobject cPlatformView = (*env)->NewGlobalRef(env, obj); 1223 1224 [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){ 1225 AWT_ASSERT_APPKIT_THREAD; 1226 1227 CALayer *windowLayer = jlong_to_ptr(windowLayerPtr); 1228 AWTView *view = [[AWTView alloc] initWithRect:rect 1229 platformView:cPlatformView 1230 windowLayer:windowLayer]; 1231 CFRetain(view); 1232 [view release]; // GC 1233 1234 newView = view; 1235 }]; 1236 1237 JNF_COCOA_EXIT(env); 1238 1239 return ptr_to_jlong(newView); 1240 } | 66 - (id) initWithRect: (NSRect) rect 67 platformView: (jobject) cPlatformView 68 windowLayer: (CALayer*) windowLayer 69 { 70 AWT_ASSERT_APPKIT_THREAD; 71 // Initialize ourselves 72 self = [super initWithFrame: rect]; 73 if (self == nil) return self; 74 75 m_cPlatformView = cPlatformView; 76 fInputMethodLOCKABLE = NULL; 77 fKeyEventsNeeded = NO; 78 fProcessingKeystroke = NO; 79 80 fEnablePressAndHold = shouldUsePressAndHold(); 81 fInPressAndHold = NO; 82 fPAHNeedsToSelect = NO; 83 84 mouseIsOver = NO; 85 86 [self setAutoresizesSubviews:NO]; 87 88 if (windowLayer != nil) { 89 self.cglLayer = windowLayer; 90 [self setWantsLayer: YES]; 91 [self.layer addSublayer: (CALayer *)cglLayer]; 92 [self setLayerContentsRedrawPolicy: NSViewLayerContentsRedrawDuringViewResize]; 93 [self setLayerContentsPlacement: NSViewLayerContentsPlacementTopLeft]; 94 [self setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable]; 95 96 #ifdef REMOTELAYER 97 CGLLayer *parentLayer = (CGLLayer*)self.cglLayer; 98 parentLayer.parentLayer = NULL; 99 parentLayer.remoteLayer = NULL; 100 if (JRSRemotePort != 0 && remoteSocketFD > 0) { 101 CGLLayer *remoteLayer = [[CGLLayer alloc] initWithJavaLayer: parentLayer.javaLayer]; 102 remoteLayer.target = GL_TEXTURE_2D; 103 NSLog(@"Creating Parent=%p, Remote=%p", parentLayer, remoteLayer); 104 parentLayer.remoteLayer = remoteLayer; 105 remoteLayer.parentLayer = parentLayer; 106 remoteLayer.remoteLayer = NULL; 107 remoteLayer.jrsRemoteLayer = [remoteLayer createRemoteLayerBoundTo:JRSRemotePort]; 155 - (BOOL) acceptsFirstMouse: (NSEvent *)event { 156 return YES; 157 } 158 159 - (BOOL) acceptsFirstResponder { 160 return YES; 161 } 162 163 - (BOOL) becomeFirstResponder { 164 return YES; 165 } 166 167 - (BOOL) preservesContentDuringLiveResize { 168 return YES; 169 } 170 171 /* 172 * Automatically triggered functions. 173 */ 174 175 - (void)resizeWithOldSuperviewSize:(NSSize)oldBoundsSize { 176 [super resizeWithOldSuperviewSize: oldBoundsSize]; 177 [self deliverResize: [self frame]]; 178 } 179 180 /* 181 * MouseEvents support 182 */ 183 184 - (void) mouseDown: (NSEvent *)event { 185 NSInputManager *inputManager = [NSInputManager currentInputManager]; 186 if ([inputManager wantsToHandleMouseEvents]) { 187 #if IM_DEBUG 188 NSLog(@"-> IM wants to handle event"); 189 #endif 190 if (![inputManager handleMouseEvent:event]) { 191 [self deliverJavaMouseEvent: event]; 192 } else { 193 #if IM_DEBUG 194 NSLog(@"-> Event was handled."); 195 #endif 196 } 197 } else { 198 #if IM_DEBUG 199 NSLog(@"-> IM does not want to handle event"); 423 } 424 425 static JNF_CLASS_CACHE(jc_NSEvent, "sun/lwawt/macosx/event/NSEvent"); 426 static JNF_CTOR_CACHE(jctor_NSEvent, jc_NSEvent, "(IISLjava/lang/String;)V"); 427 jobject jevent = JNFNewObject(env, jctor_NSEvent, 428 [event type], 429 [event modifierFlags], 430 [event keyCode], 431 characters); 432 433 static JNF_CLASS_CACHE(jc_PlatformView, "sun/lwawt/macosx/CPlatformView"); 434 static JNF_MEMBER_CACHE(jm_deliverKeyEvent, jc_PlatformView, 435 "deliverKeyEvent", "(Lsun/lwawt/macosx/event/NSEvent;)V"); 436 JNFCallVoidMethod(env, m_cPlatformView, jm_deliverKeyEvent, jevent); 437 438 if (characters != NULL) { 439 (*env)->DeleteLocalRef(env, characters); 440 } 441 } 442 443 -(void) deliverResize: (NSRect) rect { 444 jint x = (jint) rect.origin.x; 445 jint y = (jint) rect.origin.y; 446 jint w = (jint) rect.size.width; 447 jint h = (jint) rect.size.height; 448 JNIEnv *env = [ThreadUtilities getJNIEnv]; 449 static JNF_CLASS_CACHE(jc_PlatformView, "sun/lwawt/macosx/CPlatformView"); 450 static JNF_MEMBER_CACHE(jm_deliverResize, jc_PlatformView, "deliverResize", "(IIII)V"); 451 JNFCallVoidMethod(env, m_cPlatformView, jm_deliverResize, x,y,w,h); 452 } 453 454 455 - (void) drawRect:(NSRect)dirtyRect { 456 AWT_ASSERT_APPKIT_THREAD; 457 458 [super drawRect:dirtyRect]; 459 JNIEnv *env = [ThreadUtilities getJNIEnv]; 460 if (env != NULL) { 461 /* 462 if ([self inLiveResize]) { 463 NSRect rs[4]; 464 NSInteger count; 465 [self getRectsExposedDuringLiveResize:rs count:&count]; 466 for (int i = 0; i < count; i++) { 467 JNU_CallMethodByName(env, NULL, [m_awtWindow cPlatformView], 468 "deliverWindowDidExposeEvent", "(FFFF)V", 469 (jfloat)rs[i].origin.x, (jfloat)rs[i].origin.y, 470 (jfloat)rs[i].size.width, (jfloat)rs[i].size.height); 471 if ((*env)->ExceptionOccurred(env)) { 472 (*env)->ExceptionDescribe(env); 473 (*env)->ExceptionClear(env); 474 } 1218 1219 /******************************** END NSTextInputClient Protocol ********************************/ 1220 1221 1222 1223 1224 @end // AWTView 1225 1226 /* 1227 * Class: sun_lwawt_macosx_CPlatformView 1228 * Method: nativeCreateView 1229 * Signature: (IIII)J 1230 */ 1231 JNIEXPORT jlong JNICALL 1232 Java_sun_lwawt_macosx_CPlatformView_nativeCreateView 1233 (JNIEnv *env, jobject obj, jint originX, jint originY, jint width, jint height, jlong windowLayerPtr) 1234 { 1235 __block AWTView *newView = nil; 1236 1237 JNF_COCOA_ENTER(env); 1238 1239 NSRect rect = NSMakeRect(originX, originY, width, height); 1240 jobject cPlatformView = (*env)->NewGlobalRef(env, obj); 1241 1242 [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ 1243 AWT_ASSERT_APPKIT_THREAD; 1244 1245 CALayer *windowLayer = jlong_to_ptr(windowLayerPtr); 1246 AWTView *view = [[AWTView alloc] initWithRect:rect 1247 platformView:cPlatformView 1248 windowLayer:windowLayer]; 1249 CFRetain(view); 1250 [view release]; // GC 1251 newView = view; 1252 }]; 1253 1254 JNF_COCOA_EXIT(env); 1255 1256 return ptr_to_jlong(newView); 1257 } 1258 1259 /* 1260 * Class: sun_lwawt_macosx_CPlatformView 1261 * Method: nativeSetAutoResizable 1262 * Signature: (JZ)V; 1263 */ 1264 1265 JNIEXPORT void JNICALL 1266 Java_sun_lwawt_macosx_CPlatformView_nativeSetAutoResizable 1267 (JNIEnv *env, jclass cls, jlong viewPtr, jboolean toResize) 1268 { 1269 JNF_COCOA_ENTER(env); 1270 1271 NSView *view = (NSView *)jlong_to_ptr(viewPtr); 1272 1273 [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ 1274 AWT_ASSERT_APPKIT_THREAD; 1275 1276 if (toResize) { 1277 [view setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable]; 1278 } else { 1279 [view setAutoresizingMask: NSViewMinYMargin | NSViewMaxXMargin]; 1280 } 1281 1282 if ([view superview] != nil) { 1283 [[view superview] setAutoresizesSubviews:(BOOL)toResize]; 1284 } 1285 }]; 1286 JNF_COCOA_EXIT(env); 1287 } 1288 1289 /* 1290 * Class: sun_lwawt_macosx_CPlatformView 1291 * Method: nativeGetNSViewDisplayID 1292 * Signature: (J)I; 1293 */ 1294 1295 JNIEXPORT jint JNICALL 1296 Java_sun_lwawt_macosx_CPlatformView_nativeGetNSViewDisplayID 1297 (JNIEnv *env, jclass cls, jlong viewPtr) 1298 { 1299 __block jint ret; //CGDirectDisplayID 1300 1301 JNF_COCOA_ENTER(env); 1302 1303 NSView *view = (NSView *)jlong_to_ptr(viewPtr); 1304 NSWindow *window = [view window]; 1305 1306 [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ 1307 AWT_ASSERT_APPKIT_THREAD; 1308 1309 ret = (jint)[[AWTWindow getNSWindowDisplayID_AppKitThread: window] intValue]; 1310 }]; 1311 1312 JNF_COCOA_EXIT(env); 1313 1314 return ret; 1315 } 1316 1317 /* 1318 * Class: sun_lwawt_macosx_CPlatformView 1319 * Method: nativeGetLocationOnScreen 1320 * Signature: (J)Ljava/awt/Rectangle; 1321 */ 1322 1323 JNIEXPORT jobject JNICALL 1324 Java_sun_lwawt_macosx_CPlatformView_nativeGetLocationOnScreen 1325 (JNIEnv *env, jclass cls, jlong viewPtr) 1326 { 1327 jobject jRect = NULL; 1328 1329 JNF_COCOA_ENTER(env); 1330 1331 __block NSRect rect = NSZeroRect; 1332 1333 NSView *view = (NSView *)jlong_to_ptr(viewPtr); 1334 [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ 1335 AWT_ASSERT_APPKIT_THREAD; 1336 1337 NSRect viewBounds = [view bounds]; 1338 NSRect frameInWindow = [view convertRect:viewBounds toView:nil]; 1339 rect = [[view window] convertRectToScreen:frameInWindow]; 1340 NSRect screenRect = [[NSScreen mainScreen] frame]; 1341 //Convert coordinates to top-left corner origin 1342 rect.origin.y = screenRect.size.height - rect.origin.y - viewBounds.size.height; 1343 }]; 1344 jRect = NSToJavaRect(env, rect); 1345 1346 JNF_COCOA_EXIT(env); 1347 1348 return jRect; 1349 } 1350 1351 /* 1352 * Class: sun_lwawt_macosx_CPlatformView 1353 * Method: nativeIsViewUnderMouse 1354 * Signature: (J)Z; 1355 */ 1356 1357 JNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_CPlatformView_nativeIsViewUnderMouse 1358 (JNIEnv *env, jclass clazz, jlong viewPtr) 1359 { 1360 __block jboolean underMouse = JNI_FALSE; 1361 1362 JNF_COCOA_ENTER(env); 1363 1364 NSView *nsView = OBJC(viewPtr); 1365 [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ 1366 AWT_ASSERT_APPKIT_THREAD; 1367 1368 NSPoint ptWindowCoords = [[nsView window] mouseLocationOutsideOfEventStream]; 1369 NSPoint ptViewCoords = [nsView convertPoint:ptWindowCoords fromView:nil]; 1370 underMouse = [nsView hitTest:ptViewCoords] != nil; 1371 }]; 1372 1373 JNF_COCOA_EXIT(env); 1374 1375 return underMouse; 1376 } 1377 1378 |