comparison src/macosx/native/sun/awt/AWTView.m @ 6219:c69424f78060

7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame Summary: The new implementation of EmbeddedFrame to support SWT_AWT Bridge Reviewed-by: anthony, serb, leonidr Contributed-by: Petr Pchelko <petr.pchelko@oracle.com>
author serb
date Tue, 11 Dec 2012 19:45:00 +0400
parents 7ead109417f0
children 5309fed435b5
comparison
equal deleted inserted replaced
10:5d7e2de46c82 11:b85636b53580
81 fInPressAndHold = NO; 81 fInPressAndHold = NO;
82 fPAHNeedsToSelect = NO; 82 fPAHNeedsToSelect = NO;
83 83
84 mouseIsOver = NO; 84 mouseIsOver = NO;
85 [self resetTrackingArea]; 85 [self resetTrackingArea];
86 [self setAutoresizesSubviews:NO];
86 87
87 if (windowLayer != nil) { 88 if (windowLayer != nil) {
88 self.cglLayer = windowLayer; 89 self.cglLayer = windowLayer;
89 //Layer hosting view 90 //Layer hosting view
90 [self setLayer: cglLayer]; 91 [self setLayer: cglLayer];
172 173
173 /* 174 /*
174 * Automatically triggered functions. 175 * Automatically triggered functions.
175 */ 176 */
176 177
178 - (void)resizeWithOldSuperviewSize:(NSSize)oldBoundsSize {
179 [super resizeWithOldSuperviewSize: oldBoundsSize];
180 [self deliverResize: [self frame]];
181 }
182
177 /* 183 /*
178 * MouseEvents support 184 * MouseEvents support
179 */ 185 */
180 186
181 - (void) mouseDown: (NSEvent *)event { 187 - (void) mouseDown: (NSEvent *)event {
434 440
435 if (characters != NULL) { 441 if (characters != NULL) {
436 (*env)->DeleteLocalRef(env, characters); 442 (*env)->DeleteLocalRef(env, characters);
437 } 443 }
438 } 444 }
445
446 -(void) deliverResize: (NSRect) rect {
447 jint x = (jint) rect.origin.x;
448 jint y = (jint) rect.origin.y;
449 jint w = (jint) rect.size.width;
450 jint h = (jint) rect.size.height;
451 JNIEnv *env = [ThreadUtilities getJNIEnv];
452 static JNF_CLASS_CACHE(jc_PlatformView, "sun/lwawt/macosx/CPlatformView");
453 static JNF_MEMBER_CACHE(jm_deliverResize, jc_PlatformView, "deliverResize", "(IIII)V");
454 JNFCallVoidMethod(env, m_cPlatformView, jm_deliverResize, x,y,w,h);
455 }
456
439 457
440 - (void) drawRect:(NSRect)dirtyRect { 458 - (void) drawRect:(NSRect)dirtyRect {
441 AWT_ASSERT_APPKIT_THREAD; 459 AWT_ASSERT_APPKIT_THREAD;
442 460
443 [super drawRect:dirtyRect]; 461 [super drawRect:dirtyRect];
1218 (JNIEnv *env, jobject obj, jint originX, jint originY, jint width, jint height, jlong windowLayerPtr) 1236 (JNIEnv *env, jobject obj, jint originX, jint originY, jint width, jint height, jlong windowLayerPtr)
1219 { 1237 {
1220 __block AWTView *newView = nil; 1238 __block AWTView *newView = nil;
1221 1239
1222 JNF_COCOA_ENTER(env); 1240 JNF_COCOA_ENTER(env);
1223 AWT_ASSERT_NOT_APPKIT_THREAD;
1224 1241
1225 NSRect rect = NSMakeRect(originX, originY, width, height); 1242 NSRect rect = NSMakeRect(originX, originY, width, height);
1226 jobject cPlatformView = (*env)->NewGlobalRef(env, obj); 1243 jobject cPlatformView = (*env)->NewGlobalRef(env, obj);
1227 1244
1228 [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){ 1245 [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
1229 AWT_ASSERT_APPKIT_THREAD; 1246 AWT_ASSERT_APPKIT_THREAD;
1230 1247
1231 CALayer *windowLayer = jlong_to_ptr(windowLayerPtr); 1248 CALayer *windowLayer = jlong_to_ptr(windowLayerPtr);
1232 AWTView *view = [[AWTView alloc] initWithRect:rect 1249 AWTView *view = [[AWTView alloc] initWithRect:rect
1233 platformView:cPlatformView 1250 platformView:cPlatformView
1234 windowLayer:windowLayer]; 1251 windowLayer:windowLayer];
1235 CFRetain(view); 1252 CFRetain(view);
1236 [view release]; // GC 1253 [view release]; // GC
1237
1238 newView = view; 1254 newView = view;
1239 }]; 1255 }];
1240 1256
1241 JNF_COCOA_EXIT(env); 1257 JNF_COCOA_EXIT(env);
1242 1258
1243 return ptr_to_jlong(newView); 1259 return ptr_to_jlong(newView);
1244 } 1260 }
1261
1262 /*
1263 * Class: sun_lwawt_macosx_CPlatformView
1264 * Method: nativeSetAutoResizable
1265 * Signature: (JZ)V;
1266 */
1267
1268 JNIEXPORT void JNICALL
1269 Java_sun_lwawt_macosx_CPlatformView_nativeSetAutoResizable
1270 (JNIEnv *env, jclass cls, jlong viewPtr, jboolean toResize)
1271 {
1272 JNF_COCOA_ENTER(env);
1273
1274 NSView *view = (NSView *)jlong_to_ptr(viewPtr);
1275
1276 [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1277 AWT_ASSERT_APPKIT_THREAD;
1278
1279 if (toResize) {
1280 [view setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable];
1281 } else {
1282 [view setAutoresizingMask: NSViewMinYMargin | NSViewMaxXMargin];
1283 }
1284
1285 if ([view superview] != nil) {
1286 [[view superview] setAutoresizesSubviews:(BOOL)toResize];
1287 }
1288
1289 }];
1290 JNF_COCOA_EXIT(env);
1291 }
1292
1293 /*
1294 * Class: sun_lwawt_macosx_CPlatformView
1295 * Method: nativeGetNSViewDisplayID
1296 * Signature: (J)I;
1297 */
1298
1299 JNIEXPORT jint JNICALL
1300 Java_sun_lwawt_macosx_CPlatformView_nativeGetNSViewDisplayID
1301 (JNIEnv *env, jclass cls, jlong viewPtr)
1302 {
1303 __block jint ret; //CGDirectDisplayID
1304
1305 JNF_COCOA_ENTER(env);
1306
1307 NSView *view = (NSView *)jlong_to_ptr(viewPtr);
1308 NSWindow *window = [view window];
1309
1310 [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
1311 AWT_ASSERT_APPKIT_THREAD;
1312
1313 ret = (jint)[[AWTWindow getNSWindowDisplayID_AppKitThread: window] intValue];
1314 }];
1315
1316 JNF_COCOA_EXIT(env);
1317
1318 return ret;
1319 }
1320
1321 /*
1322 * Class: sun_lwawt_macosx_CPlatformView
1323 * Method: nativeGetLocationOnScreen
1324 * Signature: (J)Ljava/awt/Rectangle;
1325 */
1326
1327 JNIEXPORT jobject JNICALL
1328 Java_sun_lwawt_macosx_CPlatformView_nativeGetLocationOnScreen
1329 (JNIEnv *env, jclass cls, jlong viewPtr)
1330 {
1331 jobject jRect = NULL;
1332
1333 JNF_COCOA_ENTER(env);
1334
1335 __block NSRect rect = NSZeroRect;
1336
1337 NSView *view = (NSView *)jlong_to_ptr(viewPtr);
1338 [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
1339 AWT_ASSERT_APPKIT_THREAD;
1340
1341 NSRect viewBounds = [view bounds];
1342 NSRect frameInWindow = [view convertRect:viewBounds toView:nil];
1343 rect = [[view window] convertRectToScreen:frameInWindow];
1344 NSRect screenRect = [[NSScreen mainScreen] frame];
1345 //Convert coordinates to top-left corner origin
1346 rect.origin.y = screenRect.size.height - rect.origin.y - viewBounds.size.height;
1347 }];
1348 jRect = NSToJavaRect(env, rect);
1349
1350 JNF_COCOA_EXIT(env);
1351
1352 return jRect;
1353 }
1354
1355 /*
1356 * Class: sun_lwawt_macosx_CPlatformView
1357 * Method: nativeIsViewUnderMouse
1358 * Signature: (J)Z;
1359 */
1360
1361 JNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_CPlatformView_nativeIsViewUnderMouse
1362 (JNIEnv *env, jclass clazz, jlong viewPtr)
1363 {
1364 __block jboolean underMouse = JNI_FALSE;
1365
1366 JNF_COCOA_ENTER(env);
1367
1368 NSView *nsView = OBJC(viewPtr);
1369 [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
1370 AWT_ASSERT_APPKIT_THREAD;
1371
1372 NSPoint ptWindowCoords = [[nsView window] mouseLocationOutsideOfEventStream];
1373 NSPoint ptViewCoords = [nsView convertPoint:ptWindowCoords fromView:nil];
1374 underMouse = [nsView hitTest:ptViewCoords] != nil;
1375 }];
1376
1377 JNF_COCOA_EXIT(env);
1378
1379 return underMouse;
1380 }
1381
1382