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 [self resetTrackingArea];
86
87 if (windowLayer != nil) {
88 self.cglLayer = windowLayer;
89 //Layer hosting view
90 [self setLayer: cglLayer];
91 [self setWantsLayer: YES];
92 //Layer backed view
93 //[self.layer addSublayer: (CALayer *)cglLayer];
94 //[self setLayerContentsRedrawPolicy: NSViewLayerContentsRedrawDuringViewResize];
95 //[self setLayerContentsPlacement: NSViewLayerContentsPlacementTopLeft];
96 //[self setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable];
97
98 #ifdef REMOTELAYER
99 CGLLayer *parentLayer = (CGLLayer*)self.cglLayer;
100 parentLayer.parentLayer = NULL;
101 parentLayer.remoteLayer = NULL;
102 if (JRSRemotePort != 0 && remoteSocketFD > 0) {
103 CGLLayer *remoteLayer = [[CGLLayer alloc] initWithJavaLayer: parentLayer.javaLayer];
104 remoteLayer.target = GL_TEXTURE_2D;
105 NSLog(@"Creating Parent=%p, Remote=%p", parentLayer, remoteLayer);
157 - (BOOL) acceptsFirstMouse: (NSEvent *)event {
158 return YES;
159 }
160
161 - (BOOL) acceptsFirstResponder {
162 return YES;
163 }
164
165 - (BOOL) becomeFirstResponder {
166 return YES;
167 }
168
169 - (BOOL) preservesContentDuringLiveResize {
170 return YES;
171 }
172
173 /*
174 * Automatically triggered functions.
175 */
176
177 /*
178 * MouseEvents support
179 */
180
181 - (void) mouseDown: (NSEvent *)event {
182 NSInputManager *inputManager = [NSInputManager currentInputManager];
183 if ([inputManager wantsToHandleMouseEvents]) {
184 #if IM_DEBUG
185 NSLog(@"-> IM wants to handle event");
186 #endif
187 if (![inputManager handleMouseEvent:event]) {
188 [self deliverJavaMouseEvent: event];
189 } else {
190 #if IM_DEBUG
191 NSLog(@"-> Event was handled.");
192 #endif
193 }
194 } else {
195 #if IM_DEBUG
196 NSLog(@"-> IM does not want to handle event");
420 }
421
422 static JNF_CLASS_CACHE(jc_NSEvent, "sun/lwawt/macosx/event/NSEvent");
423 static JNF_CTOR_CACHE(jctor_NSEvent, jc_NSEvent, "(IISLjava/lang/String;)V");
424 jobject jevent = JNFNewObject(env, jctor_NSEvent,
425 [event type],
426 [event modifierFlags],
427 [event keyCode],
428 characters);
429
430 static JNF_CLASS_CACHE(jc_PlatformView, "sun/lwawt/macosx/CPlatformView");
431 static JNF_MEMBER_CACHE(jm_deliverKeyEvent, jc_PlatformView,
432 "deliverKeyEvent", "(Lsun/lwawt/macosx/event/NSEvent;)V");
433 JNFCallVoidMethod(env, m_cPlatformView, jm_deliverKeyEvent, jevent);
434
435 if (characters != NULL) {
436 (*env)->DeleteLocalRef(env, characters);
437 }
438 }
439
440 - (void) drawRect:(NSRect)dirtyRect {
441 AWT_ASSERT_APPKIT_THREAD;
442
443 [super drawRect:dirtyRect];
444 JNIEnv *env = [ThreadUtilities getJNIEnv];
445 if (env != NULL) {
446 /*
447 if ([self inLiveResize]) {
448 NSRect rs[4];
449 NSInteger count;
450 [self getRectsExposedDuringLiveResize:rs count:&count];
451 for (int i = 0; i < count; i++) {
452 JNU_CallMethodByName(env, NULL, [m_awtWindow cPlatformView],
453 "deliverWindowDidExposeEvent", "(FFFF)V",
454 (jfloat)rs[i].origin.x, (jfloat)rs[i].origin.y,
455 (jfloat)rs[i].size.width, (jfloat)rs[i].size.height);
456 if ((*env)->ExceptionOccurred(env)) {
457 (*env)->ExceptionDescribe(env);
458 (*env)->ExceptionClear(env);
459 }
1203
1204 /******************************** END NSTextInputClient Protocol ********************************/
1205
1206
1207
1208
1209 @end // AWTView
1210
1211 /*
1212 * Class: sun_lwawt_macosx_CPlatformView
1213 * Method: nativeCreateView
1214 * Signature: (IIII)J
1215 */
1216 JNIEXPORT jlong JNICALL
1217 Java_sun_lwawt_macosx_CPlatformView_nativeCreateView
1218 (JNIEnv *env, jobject obj, jint originX, jint originY, jint width, jint height, jlong windowLayerPtr)
1219 {
1220 __block AWTView *newView = nil;
1221
1222 JNF_COCOA_ENTER(env);
1223 AWT_ASSERT_NOT_APPKIT_THREAD;
1224
1225 NSRect rect = NSMakeRect(originX, originY, width, height);
1226 jobject cPlatformView = (*env)->NewGlobalRef(env, obj);
1227
1228 [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
1229 AWT_ASSERT_APPKIT_THREAD;
1230
1231 CALayer *windowLayer = jlong_to_ptr(windowLayerPtr);
1232 AWTView *view = [[AWTView alloc] initWithRect:rect
1233 platformView:cPlatformView
1234 windowLayer:windowLayer];
1235 CFRetain(view);
1236 [view release]; // GC
1237
1238 newView = view;
1239 }];
1240
1241 JNF_COCOA_EXIT(env);
1242
1243 return ptr_to_jlong(newView);
1244 }
|
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 [self resetTrackingArea];
86 [self setAutoresizesSubviews:NO];
87
88 if (windowLayer != nil) {
89 self.cglLayer = windowLayer;
90 //Layer hosting view
91 [self setLayer: cglLayer];
92 [self setWantsLayer: YES];
93 //Layer backed view
94 //[self.layer addSublayer: (CALayer *)cglLayer];
95 //[self setLayerContentsRedrawPolicy: NSViewLayerContentsRedrawDuringViewResize];
96 //[self setLayerContentsPlacement: NSViewLayerContentsPlacementTopLeft];
97 //[self setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable];
98
99 #ifdef REMOTELAYER
100 CGLLayer *parentLayer = (CGLLayer*)self.cglLayer;
101 parentLayer.parentLayer = NULL;
102 parentLayer.remoteLayer = NULL;
103 if (JRSRemotePort != 0 && remoteSocketFD > 0) {
104 CGLLayer *remoteLayer = [[CGLLayer alloc] initWithJavaLayer: parentLayer.javaLayer];
105 remoteLayer.target = GL_TEXTURE_2D;
106 NSLog(@"Creating Parent=%p, Remote=%p", parentLayer, remoteLayer);
158 - (BOOL) acceptsFirstMouse: (NSEvent *)event {
159 return YES;
160 }
161
162 - (BOOL) acceptsFirstResponder {
163 return YES;
164 }
165
166 - (BOOL) becomeFirstResponder {
167 return YES;
168 }
169
170 - (BOOL) preservesContentDuringLiveResize {
171 return YES;
172 }
173
174 /*
175 * Automatically triggered functions.
176 */
177
178 - (void)resizeWithOldSuperviewSize:(NSSize)oldBoundsSize {
179 [super resizeWithOldSuperviewSize: oldBoundsSize];
180 [self deliverResize: [self frame]];
181 }
182
183 /*
184 * MouseEvents support
185 */
186
187 - (void) mouseDown: (NSEvent *)event {
188 NSInputManager *inputManager = [NSInputManager currentInputManager];
189 if ([inputManager wantsToHandleMouseEvents]) {
190 #if IM_DEBUG
191 NSLog(@"-> IM wants to handle event");
192 #endif
193 if (![inputManager handleMouseEvent:event]) {
194 [self deliverJavaMouseEvent: event];
195 } else {
196 #if IM_DEBUG
197 NSLog(@"-> Event was handled.");
198 #endif
199 }
200 } else {
201 #if IM_DEBUG
202 NSLog(@"-> IM does not want to handle event");
426 }
427
428 static JNF_CLASS_CACHE(jc_NSEvent, "sun/lwawt/macosx/event/NSEvent");
429 static JNF_CTOR_CACHE(jctor_NSEvent, jc_NSEvent, "(IISLjava/lang/String;)V");
430 jobject jevent = JNFNewObject(env, jctor_NSEvent,
431 [event type],
432 [event modifierFlags],
433 [event keyCode],
434 characters);
435
436 static JNF_CLASS_CACHE(jc_PlatformView, "sun/lwawt/macosx/CPlatformView");
437 static JNF_MEMBER_CACHE(jm_deliverKeyEvent, jc_PlatformView,
438 "deliverKeyEvent", "(Lsun/lwawt/macosx/event/NSEvent;)V");
439 JNFCallVoidMethod(env, m_cPlatformView, jm_deliverKeyEvent, jevent);
440
441 if (characters != NULL) {
442 (*env)->DeleteLocalRef(env, characters);
443 }
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
457
458 - (void) drawRect:(NSRect)dirtyRect {
459 AWT_ASSERT_APPKIT_THREAD;
460
461 [super drawRect:dirtyRect];
462 JNIEnv *env = [ThreadUtilities getJNIEnv];
463 if (env != NULL) {
464 /*
465 if ([self inLiveResize]) {
466 NSRect rs[4];
467 NSInteger count;
468 [self getRectsExposedDuringLiveResize:rs count:&count];
469 for (int i = 0; i < count; i++) {
470 JNU_CallMethodByName(env, NULL, [m_awtWindow cPlatformView],
471 "deliverWindowDidExposeEvent", "(FFFF)V",
472 (jfloat)rs[i].origin.x, (jfloat)rs[i].origin.y,
473 (jfloat)rs[i].size.width, (jfloat)rs[i].size.height);
474 if ((*env)->ExceptionOccurred(env)) {
475 (*env)->ExceptionDescribe(env);
476 (*env)->ExceptionClear(env);
477 }
1221
1222 /******************************** END NSTextInputClient Protocol ********************************/
1223
1224
1225
1226
1227 @end // AWTView
1228
1229 /*
1230 * Class: sun_lwawt_macosx_CPlatformView
1231 * Method: nativeCreateView
1232 * Signature: (IIII)J
1233 */
1234 JNIEXPORT jlong JNICALL
1235 Java_sun_lwawt_macosx_CPlatformView_nativeCreateView
1236 (JNIEnv *env, jobject obj, jint originX, jint originY, jint width, jint height, jlong windowLayerPtr)
1237 {
1238 __block AWTView *newView = nil;
1239
1240 JNF_COCOA_ENTER(env);
1241
1242 NSRect rect = NSMakeRect(originX, originY, width, height);
1243 jobject cPlatformView = (*env)->NewGlobalRef(env, obj);
1244
1245 [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
1246 AWT_ASSERT_APPKIT_THREAD;
1247
1248 CALayer *windowLayer = jlong_to_ptr(windowLayerPtr);
1249 AWTView *view = [[AWTView alloc] initWithRect:rect
1250 platformView:cPlatformView
1251 windowLayer:windowLayer];
1252 CFRetain(view);
1253 [view release]; // GC
1254 newView = view;
1255 }];
1256
1257 JNF_COCOA_EXIT(env);
1258
1259 return ptr_to_jlong(newView);
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
|