1 /*
2 * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
65 // Note: Must be called on main (AppKit) thread only
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 //Layer hosting view
89 [self setLayer: cglLayer];
90 [self setWantsLayer: YES];
91 //Layer backed view
92 //[self.layer addSublayer: (CALayer *)cglLayer];
93 //[self setLayerContentsRedrawPolicy: NSViewLayerContentsRedrawDuringViewResize];
94 //[self setLayerContentsPlacement: NSViewLayerContentsPlacementTopLeft];
95 //[self setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable];
96
97 #ifdef REMOTELAYER
98 CGLLayer *parentLayer = (CGLLayer*)self.cglLayer;
99 parentLayer.parentLayer = NULL;
100 parentLayer.remoteLayer = NULL;
101 if (JRSRemotePort != 0 && remoteSocketFD > 0) {
102 CGLLayer *remoteLayer = [[CGLLayer alloc] initWithJavaLayer: parentLayer.javaLayer];
103 remoteLayer.target = GL_TEXTURE_2D;
104 NSLog(@"Creating Parent=%p, Remote=%p", parentLayer, remoteLayer);
132 {
133 JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
134
135 JNFDeleteGlobalRef(env, fInputMethodLOCKABLE);
136 fInputMethodLOCKABLE = NULL;
137 }
138
139
140 [super dealloc];
141 }
142
143 - (void) viewDidMoveToWindow {
144 AWT_ASSERT_APPKIT_THREAD;
145
146 [AWTToolkit eventCountPlusPlus];
147
148 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^() {
149 [[self window] makeFirstResponder: self];
150 }];
151 if ([self window] != NULL) {
152 [self resetTrackingRect];
153 }
154 }
155
156 - (BOOL) acceptsFirstMouse: (NSEvent *)event {
157 return YES;
158 }
159
160 - (BOOL) acceptsFirstResponder {
161 return YES;
162 }
163
164 - (BOOL) becomeFirstResponder {
165 return YES;
166 }
167
168 - (BOOL) preservesContentDuringLiveResize {
169 return YES;
170 }
171
172 /*
363 static JNF_CTOR_CACHE(jctor_NSEvent, jc_NSEvent, "(IIIIIIIIDD)V");
364 jobject jEvent = JNFNewObject(env, jctor_NSEvent,
365 [event type],
366 [event modifierFlags],
367 clickCount,
368 [event buttonNumber],
369 (jint)localPoint.x, (jint)localPoint.y,
370 (jint)absP.x, (jint)absP.y,
371 [event deltaY],
372 [event deltaX]);
373 if (jEvent == nil) {
374 // Unable to create event by some reason.
375 return;
376 }
377
378 static JNF_CLASS_CACHE(jc_PlatformView, "sun/lwawt/macosx/CPlatformView");
379 static JNF_MEMBER_CACHE(jm_deliverMouseEvent, jc_PlatformView, "deliverMouseEvent", "(Lsun/lwawt/macosx/event/NSEvent;)V");
380 JNFCallVoidMethod(env, m_cPlatformView, jm_deliverMouseEvent, jEvent);
381 }
382
383
384 - (void) clearTrackingRect {
385 if (rolloverTrackingRectTag > 0) {
386 [self removeTrackingRect:rolloverTrackingRectTag];
387 rolloverTrackingRectTag = 0;
388 }
389 }
390
391 - (void) resetTrackingRect {
392 [self clearTrackingRect];
393 rolloverTrackingRectTag = [self addTrackingRect:[self visibleRect]
394 owner:self
395 userData:NULL
396 assumeInside:NO];
397 }
398
399 - (void)updateTrackingAreas {
400 [super updateTrackingAreas];
401 [self resetTrackingRect];
402 }
403
404 - (void) resetCursorRects {
405 [super resetCursorRects];
406 [self resetTrackingRect];
407 }
408
409 -(void) deliverJavaKeyEventHelper: (NSEvent *) event {
410 static NSEvent* sLastKeyEvent = nil;
411 if (event == sLastKeyEvent) {
412 // The event is repeatedly delivered by keyDown: after performKeyEquivalent:
413 return;
414 }
415 [sLastKeyEvent release];
416 sLastKeyEvent = [event retain];
417
418 [AWTToolkit eventCountPlusPlus];
419 JNIEnv *env = [ThreadUtilities getJNIEnv];
420
421 jstring characters = NULL;
422 if ([event type] != NSFlagsChanged) {
423 characters = JNFNSToJavaString(env, [event characters]);
424 }
425
426 static JNF_CLASS_CACHE(jc_NSEvent, "sun/lwawt/macosx/event/NSEvent");
|
1 /*
2 * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
65 // Note: Must be called on main (AppKit) thread only
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);
133 {
134 JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
135
136 JNFDeleteGlobalRef(env, fInputMethodLOCKABLE);
137 fInputMethodLOCKABLE = NULL;
138 }
139
140
141 [super dealloc];
142 }
143
144 - (void) viewDidMoveToWindow {
145 AWT_ASSERT_APPKIT_THREAD;
146
147 [AWTToolkit eventCountPlusPlus];
148
149 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^() {
150 [[self window] makeFirstResponder: self];
151 }];
152 if ([self window] != NULL) {
153 [self resetTrackingArea];
154 }
155 }
156
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 /*
364 static JNF_CTOR_CACHE(jctor_NSEvent, jc_NSEvent, "(IIIIIIIIDD)V");
365 jobject jEvent = JNFNewObject(env, jctor_NSEvent,
366 [event type],
367 [event modifierFlags],
368 clickCount,
369 [event buttonNumber],
370 (jint)localPoint.x, (jint)localPoint.y,
371 (jint)absP.x, (jint)absP.y,
372 [event deltaY],
373 [event deltaX]);
374 if (jEvent == nil) {
375 // Unable to create event by some reason.
376 return;
377 }
378
379 static JNF_CLASS_CACHE(jc_PlatformView, "sun/lwawt/macosx/CPlatformView");
380 static JNF_MEMBER_CACHE(jm_deliverMouseEvent, jc_PlatformView, "deliverMouseEvent", "(Lsun/lwawt/macosx/event/NSEvent;)V");
381 JNFCallVoidMethod(env, m_cPlatformView, jm_deliverMouseEvent, jEvent);
382 }
383
384 - (void) resetTrackingArea {
385 if (rolloverTrackingArea != nil) {
386 [self removeTrackingArea:rolloverTrackingArea];
387 [rolloverTrackingArea release];
388 }
389
390 int options = (NSTrackingActiveInActiveApp | NSTrackingMouseEnteredAndExited |
391 NSTrackingMouseMoved | NSTrackingEnabledDuringMouseDrag);
392
393 rolloverTrackingArea = [[NSTrackingArea alloc] initWithRect:[self visibleRect]
394 options:options
395 owner:self
396 userInfo:nil
397 ];
398 [self addTrackingArea:rolloverTrackingArea];
399 }
400
401 - (void)updateTrackingAreas {
402 [super updateTrackingAreas];
403 [self resetTrackingArea];
404 }
405
406 - (void) resetCursorRects {
407 [super resetCursorRects];
408 [self resetTrackingArea];
409 }
410
411 -(void) deliverJavaKeyEventHelper: (NSEvent *) event {
412 static NSEvent* sLastKeyEvent = nil;
413 if (event == sLastKeyEvent) {
414 // The event is repeatedly delivered by keyDown: after performKeyEquivalent:
415 return;
416 }
417 [sLastKeyEvent release];
418 sLastKeyEvent = [event retain];
419
420 [AWTToolkit eventCountPlusPlus];
421 JNIEnv *env = [ThreadUtilities getJNIEnv];
422
423 jstring characters = NULL;
424 if ([event type] != NSFlagsChanged) {
425 characters = JNFNSToJavaString(env, [event characters]);
426 }
427
428 static JNF_CLASS_CACHE(jc_NSEvent, "sun/lwawt/macosx/event/NSEvent");
|