summaryrefslogtreecommitdiffstats
path: root/macosx/tkMacOSXMouseEvent.c
diff options
context:
space:
mode:
authorKevin Walzer <kw@codebykevin.com>2015-11-08 22:01:01 (GMT)
committerKevin Walzer <kw@codebykevin.com>2015-11-08 22:01:01 (GMT)
commita7dfb1b21893c1ab01d02b00e7f9e1b7ebd0198c (patch)
tree853c345562af0dafffc1638132f56e7cbf04f35b /macosx/tkMacOSXMouseEvent.c
parent8e14ee04b3964bb9118b78ee62722fbf9f2129cb (diff)
downloadtk-a7dfb1b21893c1ab01d02b00e7f9e1b7ebd0198c.zip
tk-a7dfb1b21893c1ab01d02b00e7f9e1b7ebd0198c.tar.gz
tk-a7dfb1b21893c1ab01d02b00e7f9e1b7ebd0198c.tar.bz2
Cleanup of last patch to Tk-Cocoa
Diffstat (limited to 'macosx/tkMacOSXMouseEvent.c')
-rw-r--r--macosx/tkMacOSXMouseEvent.c94
1 files changed, 63 insertions, 31 deletions
diff --git a/macosx/tkMacOSXMouseEvent.c b/macosx/tkMacOSXMouseEvent.c
index 31038b5..4046359 100644
--- a/macosx/tkMacOSXMouseEvent.c
+++ b/macosx/tkMacOSXMouseEvent.c
@@ -28,12 +28,53 @@ static int GenerateButtonEvent(MouseEventData *medPtr);
static unsigned int ButtonModifiers2State(UInt32 buttonState,
UInt32 keyModifiers);
+#pragma mark NSWindow(TKMouseEvent)
+
+/* Conversion of coordinates between window and screen */
+@interface NSWindow(TKWm)
+- (NSPoint) convertPointToScreen:(NSPoint)point;
+- (NSPoint) convertPointFromScreen:(NSPoint)point;
+@end
+
+@implementation NSWindow(TKMouseEvent)
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+- (NSPoint) convertPointToScreen: (NSPoint) point
+{
+ return [self convertBaseToScreen:point];
+}
+- (NSPoint) convertPointFromScreen: (NSPoint)point
+{
+ return [self convertScreenToBase:point];
+}
+@end
+#else
+- (NSPoint) convertPointToScreen: (NSPoint) point
+{
+ NSRect pointrect;
+ pointrect.origin = point;
+ pointrect.size.width = 0;
+ pointrect.size.height = 0;
+ return [self convertRectToScreen:pointrect].origin;
+}
+- (NSPoint) convertPointFromScreen: (NSPoint)point
+{
+ NSRect pointrect;
+ pointrect.origin = point;
+ pointrect.size.width = 0;
+ pointrect.size.height = 0;
+ return [self convertRectFromScreen:pointrect].origin;
+}
+@end
+#endif
+
+#pragma mark -
+
+
#pragma mark TKApplication(TKMouseEvent)
enum {
NSWindowWillMoveEventType = 20
};
-
/*
* In OS X 10.6 an NSEvent of type NSMouseMoved would always have a non-Nil
* window attribute when the mouse was inside a window. As of 10.8 this
@@ -52,8 +93,8 @@ enum {
#ifdef TK_MAC_DEBUG_EVENTS
TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd, theEvent);
#endif
- id win;
- NSEventType type = [theEvent type];
+ id win;
+ NSEventType type = [theEvent type];
#if 0
NSTrackingArea *trackingArea = nil;
NSInteger eventNumber, clickCount, buttonNumber;
@@ -62,7 +103,13 @@ enum {
switch (type) {
case NSMouseEntered:
/* Remember which window has the mouse. */
+ if (_windowWithMouse) {
+ [_windowWithMouse release];
+ }
_windowWithMouse = [theEvent window];
+ if (_windowWithMouse) {
+ [_windowWithMouse retain];
+ }
break;
case NSMouseExited:
case NSCursorUpdate:
@@ -87,31 +134,17 @@ enum {
/* Create an Xevent to add to the Tk queue. */
win = [theEvent window];
+ NSWindow *nswindow = (NSWindow *)win;
NSPoint global, local = [theEvent locationInWindow];
-#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
- /* convertBaseToScreen and convertScreenToBase were deprecated in 10.7. */
- NSRect pointrect;
- pointrect.origin = local;
- pointrect.size.width = 0;
- pointrect.size.height = 0;
-#endif
if (win) { /* local will be in window coordinates. */
-#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
- global = [win convertRectToScreen:pointrect].origin;
-#else
- global = [win convertBaseToScreen:local];
-#endif
+ global = [nswindow convertPointToScreen: local];
local.y = [win frame].size.height - local.y;
global.y = tkMacOSXZeroScreenHeight - global.y;
} else { /* local will be in screen coordinates. */
if (_windowWithMouse ) {
win = _windowWithMouse;
global = local;
-#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
- local = [win convertRectFromScreen:pointrect].origin;
-#else
- local = [win convertScreenToBase:local];
-#endif
+ local = [nswindow convertPointFromScreen: local];
local.y = [win frame].size.height - local.y;
global.y = tkMacOSXZeroScreenHeight - global.y;
} else { /* We have no window. Use the screen???*/
@@ -569,19 +602,18 @@ TkpWarpPointer(
}
/*
- * Tell the OSX core to generate the events to make it happen. This is
- * fairly ugly, but means that under most circumstances we'll register all
- * the events that would normally be generated correctly. If we use
- * CGWarpMouseCursorPosition instead, strange things happen.
+ * Tell the OSX core to generate the events to make it happen.
*/
- buttonState = (GetCurrentEvent() && Tk_MacOSXIsAppInFront())
- ? GetCurrentEventButtonState() : GetCurrentButtonState();
-
- CGPostMouseEvent(pt, 1 /* generate motion events */, 5,
- buttonState&1 ? 1 : 0, buttonState&2 ? 1 : 0,
- buttonState&4 ? 1 : 0, buttonState&8 ? 1 : 0,
- buttonState&16 ? 1 : 0);
+ buttonState = [NSEvent pressedMouseButtons];
+ CGEventType type = kCGEventMouseMoved;
+ CGEventRef theEvent = CGEventCreateMouseEvent(NULL,
+ type,
+ pt,
+ buttonState);
+ CGWarpMouseCursorPosition(pt);
+ CGEventPost(kCGHIDEventTap, theEvent);
+ CFRelease(theEvent);
}
/*