summaryrefslogtreecommitdiffstats
path: root/src/newt/native/NewtMacWindow.m
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2012-01-17 12:01:51 +0100
committerSven Gothel <[email protected]>2012-01-17 12:01:51 +0100
commitd25c25339d8878980c5f45cd1ee602767ffe0f33 (patch)
tree8e23e84c6e88c68f3b1ce87d3520e81497fa503f /src/newt/native/NewtMacWindow.m
parent7c83b3d24dc376c9b3566f3d774c7ac4c7f1cb5a (diff)
NEWT/OSX: Cleanup NewtMacWindow header (sort, fix and add declarations); Remove warning of unused var
Diffstat (limited to 'src/newt/native/NewtMacWindow.m')
-rw-r--r--src/newt/native/NewtMacWindow.m224
1 files changed, 112 insertions, 112 deletions
diff --git a/src/newt/native/NewtMacWindow.m b/src/newt/native/NewtMacWindow.m
index 204feeef7..539672f2b 100644
--- a/src/newt/native/NewtMacWindow.m
+++ b/src/newt/native/NewtMacWindow.m
@@ -476,11 +476,47 @@ static jmethodID windowRepaintID = NULL;
viewFrame.origin.y <= l0.y && l0.y < (viewFrame.origin.y+viewFrame.size.height) ;
}
-- (BOOL) canBecomeKeyWindow
+- (void) setMouseVisible:(BOOL)v hasFocus:(BOOL)focus
{
- // Even if the window is borderless, we still want it to be able
- // to become the key window to receive keyboard events
- return YES;
+ mouseVisible = v;
+ mouseInside = [self isMouseInside];
+ DBG_PRINT( "setMouseVisible: confined %d, visible %d (current: %d), mouseInside %d, hasFocus %d\n",
+ mouseConfined, mouseVisible, !cursorIsHidden, mouseInside, focus);
+ if(YES == focus && YES == mouseInside) {
+ [self cursorHide: !mouseVisible];
+ }
+}
+
+- (void) cursorHide:(BOOL)v
+{
+ DBG_PRINT( "cursorHide: %d -> %d\n", cursorIsHidden, v);
+ if(v) {
+ if(!cursorIsHidden) {
+ [NSCursor hide];
+ cursorIsHidden = YES;
+ }
+ } else {
+ if(cursorIsHidden) {
+ [NSCursor unhide];
+ cursorIsHidden = NO;
+ }
+ }
+}
+
+- (void) setMouseConfined:(BOOL)v
+{
+ mouseConfined = v;
+ DBG_PRINT( "setMouseConfined: confined %d, visible %d\n", mouseConfined, mouseVisible);
+}
+
+- (void) setMousePosition:(NSPoint)p
+{
+ NSScreen* screen = [self screen];
+ NSRect screenRect = [screen frame];
+
+ CGPoint pt = { p.x, screenRect.size.height - p.y }; // y-flip (CG is top-left origin)
+ CGEventRef ev = CGEventCreateMouseEvent (NULL, kCGEventMouseMoved, pt, kCGMouseButtonLeft);
+ CGEventPost (kCGHIDEventTap, ev);
}
static jint mods2JavaMods(NSUInteger mods)
@@ -547,17 +583,6 @@ static jint mods2JavaMods(NSUInteger mods)
}
}
-- (void) keyDown: (NSEvent*) theEvent
-{
- [self sendKeyEvent: theEvent eventType: EVENT_KEY_PRESSED];
-}
-
-- (void) keyUp: (NSEvent*) theEvent
-{
- [self sendKeyEvent: theEvent eventType: EVENT_KEY_RELEASED];
- [self sendKeyEvent: theEvent eventType: EVENT_KEY_TYPED];
-}
-
- (void) sendMouseEvent: (NSEvent*) event eventType: (jint) evType
{
NSView* nsview = [self contentView];
@@ -633,47 +658,91 @@ static jint mods2JavaMods(NSUInteger mods)
}
}
-- (void) setMouseVisible:(BOOL)v hasFocus:(BOOL)focus
+- (void) focusChanged: (BOOL) gained
{
- mouseVisible = v;
- mouseInside = [self isMouseInside];
- DBG_PRINT( "setMouseVisible: confined %d, visible %d (current: %d), mouseInside %d, hasFocus %d\n",
- mouseConfined, mouseVisible, !cursorIsHidden, mouseInside, focus);
- if(YES == focus && YES == mouseInside) {
- [self cursorHide: !mouseVisible];
+ DBG_PRINT( "focusChanged: gained %d\n", gained);
+ NSView* nsview = [self contentView];
+ if( ! [nsview isMemberOfClass:[NewtView class]] ) {
+ return;
+ }
+ NewtView* view = (NewtView *) nsview;
+ jobject javaWindowObject = [view getJavaWindowObject];
+ if (javaWindowObject == NULL) {
+ DBG_PRINT("focusChanged: null javaWindowObject\n");
+ return;
+ }
+ int shallBeDetached = 0;
+ JavaVM *jvmHandle = [view getJVMHandle];
+ JNIEnv* env = NewtCommon_GetJNIEnv(jvmHandle, [view getJVMVersion], &shallBeDetached);
+ if(NULL==env) {
+ DBG_PRINT("focusChanged: null JNIEnv\n");
+ return;
+ }
+
+ (*env)->CallVoidMethod(env, javaWindowObject, focusChangedID, JNI_FALSE, (gained == YES) ? JNI_TRUE : JNI_FALSE);
+
+ if (shallBeDetached) {
+ (*jvmHandle)->DetachCurrentThread(jvmHandle);
}
}
-- (void) cursorHide:(BOOL)v
+- (BOOL) becomeFirstResponder
{
- DBG_PRINT( "cursorHide: %d -> %d\n", cursorIsHidden, v);
- if(v) {
- if(!cursorIsHidden) {
- [NSCursor hide];
- cursorIsHidden = YES;
- }
- } else {
- if(cursorIsHidden) {
- [NSCursor unhide];
- cursorIsHidden = NO;
- }
+ DBG_PRINT( "*************** becomeFirstResponder\n");
+ return [super becomeFirstResponder];
+}
+
+- (BOOL) resignFirstResponder
+{
+ DBG_PRINT( "*************** resignFirstResponder\n");
+ return [super resignFirstResponder];
+}
+
+- (BOOL) canBecomeKeyWindow
+{
+ // Even if the window is borderless, we still want it to be able
+ // to become the key window to receive keyboard events
+ return YES;
+}
+
+- (void) becomeKeyWindow
+{
+ DBG_PRINT( "*************** becomeKeyWindow\n");
+ [super becomeKeyWindow];
+}
+
+- (void) resignKeyWindow
+{
+ DBG_PRINT( "*************** resignKeyWindow\n");
+ [super resignKeyWindow];
+}
+
+- (void) windowDidBecomeKey: (NSNotification *) notification
+{
+ DBG_PRINT( "*************** windowDidBecomeKey\n");
+ mouseInside = [self isMouseInside];
+ if(YES == mouseInside) {
+ [self cursorHide: !mouseVisible];
}
+ [self focusChanged: YES];
}
-- (void) setMouseConfined:(BOOL)v
+- (void) windowDidResignKey: (NSNotification *) notification
{
- mouseConfined = v;
- DBG_PRINT( "setMouseConfined: confined %d, visible %d\n", mouseConfined, mouseVisible);
+ DBG_PRINT( "*************** windowDidResignKey\n");
+ // Implicit mouse exit by OS X
+ [self focusChanged: NO];
}
-- (void) setMousePosition:(NSPoint)p
+- (void) keyDown: (NSEvent*) theEvent
{
- NSScreen* screen = [self screen];
- NSRect screenRect = [screen frame];
+ [self sendKeyEvent: theEvent eventType: EVENT_KEY_PRESSED];
+}
- CGPoint pt = { p.x, screenRect.size.height - p.y }; // y-flip (CG is top-left origin)
- CGEventRef ev = CGEventCreateMouseEvent (NULL, kCGEventMouseMoved, pt, kCGMouseButtonLeft);
- CGEventPost (kCGHIDEventTap, ev);
+- (void) keyUp: (NSEvent*) theEvent
+{
+ [self sendKeyEvent: theEvent eventType: EVENT_KEY_RELEASED];
+ [self sendKeyEvent: theEvent eventType: EVENT_KEY_TYPED];
}
- (void) mouseEntered: (NSEvent*) theEvent
@@ -869,73 +938,4 @@ static jint mods2JavaMods(NSUInteger mods)
[pool release];
}
-- (BOOL) becomeFirstResponder
-{
- DBG_PRINT( "*************** becomeFirstResponder\n");
- return [super becomeFirstResponder];
-}
-
-- (BOOL) resignFirstResponder
-{
- DBG_PRINT( "*************** resignFirstResponder\n");
- return [super resignFirstResponder];
-}
-
-- (void) becomeKeyWindow
-{
- DBG_PRINT( "*************** becomeKeyWindow\n");
- [super becomeKeyWindow];
-}
-
-- (void) resignKeyWindow
-{
- DBG_PRINT( "*************** resignKeyWindow\n");
- [super resignKeyWindow];
-}
-
-- (void) windowDidBecomeKey: (NSNotification *) notification
-{
- DBG_PRINT( "*************** windowDidBecomeKey\n");
- mouseInside = [self isMouseInside];
- if(YES == mouseInside) {
- [self cursorHide: !mouseVisible];
- }
- [self focusChanged: YES];
-}
-
-- (void) windowDidResignKey: (NSNotification *) notification
-{
- DBG_PRINT( "*************** windowDidResignKey\n");
- // Implicit mouse exit by OS X
- [self focusChanged: NO];
-}
-
-- (void) focusChanged: (BOOL) gained
-{
- DBG_PRINT( "focusChanged: gained %d\n", gained);
- NSView* nsview = [self contentView];
- if( ! [nsview isMemberOfClass:[NewtView class]] ) {
- return;
- }
- NewtView* view = (NewtView *) nsview;
- jobject javaWindowObject = [view getJavaWindowObject];
- if (javaWindowObject == NULL) {
- DBG_PRINT("focusChanged: null javaWindowObject\n");
- return;
- }
- int shallBeDetached = 0;
- JavaVM *jvmHandle = [view getJVMHandle];
- JNIEnv* env = NewtCommon_GetJNIEnv(jvmHandle, [view getJVMVersion], &shallBeDetached);
- if(NULL==env) {
- DBG_PRINT("focusChanged: null JNIEnv\n");
- return;
- }
-
- (*env)->CallVoidMethod(env, javaWindowObject, focusChangedID, JNI_FALSE, (gained == YES) ? JNI_TRUE : JNI_FALSE);
-
- if (shallBeDetached) {
- (*jvmHandle)->DetachCurrentThread(jvmHandle);
- }
-}
-
@end