diff options
Diffstat (limited to 'src/newt/native/NewtMacWindow.m')
-rw-r--r-- | src/newt/native/NewtMacWindow.m | 89 |
1 files changed, 55 insertions, 34 deletions
diff --git a/src/newt/native/NewtMacWindow.m b/src/newt/native/NewtMacWindow.m index 5b826566b..282c13fd3 100644 --- a/src/newt/native/NewtMacWindow.m +++ b/src/newt/native/NewtMacWindow.m @@ -107,6 +107,7 @@ static jmethodID windowRepaintID = NULL; - (id)initWithFrame:(NSRect)frameRect { + id res = [super initWithFrame:frameRect]; javaWindowObject = NULL; jvmHandle = NULL; @@ -129,28 +130,35 @@ static jmethodID windowRepaintID = NULL; */ myCursor = NULL; - return [super initWithFrame:frameRect]; + DBG_PRINT("NewtView::create: %p (refcnt %d)\n", res, (int)[res retainCount]); + return res; } - (void) release { + DBG_PRINT("NewtView::release.0: %p (refcnt %d)\n", self, (int)[self retainCount]); #ifdef VERBOSE_ON - NSLog(@"NewtView::release\n"); - NSLog(@"%@",[NSThread callStackSymbols]); + // NSLog(@"%@",[NSThread callStackSymbols]); #endif [super release]; } - (void) dealloc { + DBG_PRINT("NewtView::dealloc.0: %p (refcnt %d), ptrTrackingTag %d\n", self, (int)[self retainCount], (int)ptrTrackingTag); if(softLocked) { NSLog(@"NewtView::dealloc: softLock still hold @ dealloc!\n"); } + if(0 != ptrTrackingTag) { + // [self removeCursorRect: ptrRect cursor: myCursor]; + [self removeTrackingRect: ptrTrackingTag]; + ptrTrackingTag = 0; + } pthread_mutex_destroy(&softLockSync); #ifdef VERBOSE_ON - NSLog(@"NewtView::dealloc\n"); - NSLog(@"%@",[NSThread callStackSymbols]); + //NSLog(@"%@",[NSThread callStackSymbols]); #endif + DBG_PRINT("NewtView::dealloc.X: %p\n", self); [super dealloc]; } @@ -341,14 +349,14 @@ static jmethodID windowRepaintID = NULL; + (BOOL) initNatives: (JNIEnv*) env forClass: (jclass) clazz { - enqueueMouseEventID = (*env)->GetMethodID(env, clazz, "enqueueMouseEvent", "(ZIIIIIF)V"); - sendMouseEventID = (*env)->GetMethodID(env, clazz, "sendMouseEvent", "(IIIIIF)V"); - enqueueKeyEventID = (*env)->GetMethodID(env, clazz, "enqueueKeyEvent", "(ZIIIC)V"); - sendKeyEventID = (*env)->GetMethodID(env, clazz, "sendKeyEvent", "(IIIC)V"); + enqueueMouseEventID = (*env)->GetMethodID(env, clazz, "enqueueMouseEvent", "(ZSIIISF)V"); + sendMouseEventID = (*env)->GetMethodID(env, clazz, "sendMouseEvent", "(SIIISF)V"); + enqueueKeyEventID = (*env)->GetMethodID(env, clazz, "enqueueKeyEvent", "(ZSISSC)V"); + sendKeyEventID = (*env)->GetMethodID(env, clazz, "sendKeyEvent", "(SISSC)V"); sizeChangedID = (*env)->GetMethodID(env, clazz, "sizeChanged", "(ZIIZ)V"); visibleChangedID = (*env)->GetMethodID(env, clazz, "visibleChanged", "(ZZ)V"); insetsChangedID = (*env)->GetMethodID(env, clazz, "insetsChanged", "(ZIIII)V"); - positionChangedID = (*env)->GetMethodID(env, clazz, "positionChanged", "(ZII)V"); + positionChangedID = (*env)->GetMethodID(env, clazz, "screenPositionChanged", "(ZII)V"); focusChangedID = (*env)->GetMethodID(env, clazz, "focusChanged", "(ZZ)V"); windowDestroyNotifyID = (*env)->GetMethodID(env, clazz, "windowDestroyNotify", "(Z)Z"); windowRepaintID = (*env)->GetMethodID(env, clazz, "windowRepaint", "(ZIIII)V"); @@ -390,25 +398,31 @@ static jmethodID windowRepaintID = NULL; mouseInside = NO; cursorIsHidden = NO; realized = YES; + DBG_PRINT("NewtWindow::create: %p (refcnt %d)\n", res, (int)[res retainCount]); return res; } - (void) release { + DBG_PRINT("NewtWindow::release.0: %p (refcnt %d)\n", self, (int)[self retainCount]); #ifdef VERBOSE_ON - NSLog(@"NewtWindow::release\n"); - NSLog(@"%@",[NSThread callStackSymbols]); + // NSLog(@"%@",[NSThread callStackSymbols]); #endif [super release]; } - (void) dealloc { + DBG_PRINT("NewtWindow::dealloc.0: %p (refcnt %d)\n", self, (int)[self retainCount]); #ifdef VERBOSE_ON - NSLog(@"NewtWindow::dealloc\n"); - NSLog(@"%@",[NSThread callStackSymbols]); + // NSLog(@"%@",[NSThread callStackSymbols]); #endif + NewtView* mView = (NewtView *)[self contentView]; + if( NULL != mView ) { + [mView release]; + } [super dealloc]; + DBG_PRINT("NewtWindow::dealloc.X: %p\n", self); } - (void) setUnrealized @@ -470,19 +484,28 @@ static jmethodID windowRepaintID = NULL; } /** - * p abs screen position w/ top-left origin + * p abs screen position of client-area pos w/ top-left origin, using contentView's client NSSize * returns: abs screen position w/ bottom-left origin */ -- (NSPoint) newtScreenWinPos2OSXScreenPos: (NSPoint) p +- (NSPoint) newtAbsClientTLWinPos2AbsBLScreenPos: (NSPoint) p { NSView* mView = [self contentView]; NSRect mViewFrame = [mView frame]; - int totalHeight = mViewFrame.size.height + cachedInsets[2] + cachedInsets[3]; // height + insets[top+bottom] + return [self newtAbsClientTLWinPos2AbsBLScreenPos: p size: mViewFrame.size]; +} + +/** + * p abs screen position of client-area pos w/ top-left origin, using given client NSSize + * returns: abs screen position w/ bottom-left origin + */ +- (NSPoint) newtAbsClientTLWinPos2AbsBLScreenPos: (NSPoint) p size: (NSSize) nsz +{ + int totalHeight = nsz.height + cachedInsets[3]; // height + insets.bottom NSScreen* screen = [self screen]; NSRect screenFrame = [screen frame]; - return NSMakePoint(screenFrame.origin.x + p.x + cachedInsets[0], + return NSMakePoint(screenFrame.origin.x + p.x, screenFrame.origin.y + screenFrame.size.height - p.y - totalHeight); } @@ -490,7 +513,7 @@ static jmethodID windowRepaintID = NULL; * p rel client window position w/ top-left origin * returns: abs screen position w/ bottom-left origin */ -- (NSPoint) newtClientWinPos2OSXScreenPos: (NSPoint) p +- (NSPoint) newtRelClientTLWinPos2AbsBLScreenPos: (NSPoint) p { NSRect winFrame = [self frame]; @@ -612,15 +635,15 @@ static jint mods2JavaMods(NSUInteger mods) return javaMods; } -- (void) sendKeyEvent: (NSEvent*) event eventType: (jint) evType +- (void) sendKeyEvent: (NSEvent*) event eventType: (jshort) evType { - jint keyCode = (jint) [event keyCode]; + jshort keyCode = (jshort) [event keyCode]; NSString* chars = [event charactersIgnoringModifiers]; NSUInteger mods = [event modifierFlags]; [self sendKeyEvent: keyCode characters: chars modifiers: mods eventType: evType]; } -- (void) sendKeyEvent: (jint) keyCode characters: (NSString*) chars modifiers: (NSUInteger)mods eventType: (jint) evType +- (void) sendKeyEvent: (jshort) keyCode characters: (NSString*) chars modifiers: (NSUInteger)mods eventType: (jshort) evType { NSView* nsview = [self contentView]; if( ! [nsview isMemberOfClass:[NewtView class]] ) { @@ -654,10 +677,10 @@ static jint mods2JavaMods(NSUInteger mods) #ifdef USE_SENDIO_DIRECT (*env)->CallVoidMethod(env, javaWindowObject, sendKeyEventID, - evType, javaMods, keyCode, keyChar); + evType, javaMods, keyCode, keyCode, keyChar); #else (*env)->CallVoidMethod(env, javaWindowObject, enqueueKeyEventID, JNI_FALSE, - evType, javaMods, keyCode, keyChar); + evType, javaMods, keyCode, keyCode, keyChar); #endif } } else { @@ -668,10 +691,10 @@ static jint mods2JavaMods(NSUInteger mods) #ifdef USE_SENDIO_DIRECT (*env)->CallVoidMethod(env, javaWindowObject, sendKeyEventID, - evType, javaMods, keyCode, keyChar); + evType, javaMods, keyCode, keyCode, keyChar); #else (*env)->CallVoidMethod(env, javaWindowObject, enqueueKeyEventID, JNI_FALSE, - evType, javaMods, keyCode, keyChar); + evType, javaMods, keyCode, keyCode, keyChar); #endif } @@ -680,7 +703,7 @@ static jint mods2JavaMods(NSUInteger mods) } } -- (void) sendMouseEvent: (NSEvent*) event eventType: (jint) evType +- (void) sendMouseEvent: (NSEvent*) event eventType: (jshort) evType { NSView* nsview = [self contentView]; if( ! [nsview isMemberOfClass:[NewtView class]] ) { @@ -704,7 +727,7 @@ static jint mods2JavaMods(NSUInteger mods) // convert to 1-based button number (or use zero if no button is involved) // TODO: detect mouse button when mouse wheel scrolled - jint javaButtonNum = 0; + jshort javaButtonNum = 0; jfloat scrollDeltaY = 0.0f; switch ([event type]) { case NSScrollWheel: { @@ -836,13 +859,12 @@ static jint mods2JavaMods(NSUInteger mods) - (void) keyDown: (NSEvent*) theEvent { - [self sendKeyEvent: theEvent eventType: EVENT_KEY_PRESSED]; + [self sendKeyEvent: theEvent eventType: (jshort)EVENT_KEY_PRESSED]; } - (void) keyUp: (NSEvent*) theEvent { - [self sendKeyEvent: theEvent eventType: EVENT_KEY_RELEASED]; - [self sendKeyEvent: theEvent eventType: EVENT_KEY_TYPED]; + [self sendKeyEvent: theEvent eventType: (jshort)EVENT_KEY_RELEASED]; } #define kVK_Shift 0x38 @@ -854,11 +876,10 @@ static jint mods2JavaMods(NSUInteger mods) { if ( NO == modsDown[keyIdx] && 0 != ( mods & keyMask ) ) { modsDown[keyIdx] = YES; - [self sendKeyEvent: keyCode characters: NULL modifiers: mods|keyMask eventType: EVENT_KEY_PRESSED]; + [self sendKeyEvent: (jshort)keyCode characters: NULL modifiers: mods|keyMask eventType: (jshort)EVENT_KEY_PRESSED]; } else if ( YES == modsDown[keyIdx] && 0 == ( mods & keyMask ) ) { modsDown[keyIdx] = NO; - [self sendKeyEvent: keyCode characters: NULL modifiers: mods|keyMask eventType: EVENT_KEY_RELEASED]; - [self sendKeyEvent: keyCode characters: NULL modifiers: mods|keyMask eventType: EVENT_KEY_TYPED]; + [self sendKeyEvent: (jshort)keyCode characters: NULL modifiers: mods|keyMask eventType: (jshort)EVENT_KEY_RELEASED]; } } |