summaryrefslogtreecommitdiffstats
path: root/macosx/tkMacOSXMouseEvent.c
diff options
context:
space:
mode:
Diffstat (limited to 'macosx/tkMacOSXMouseEvent.c')
-rw-r--r--macosx/tkMacOSXMouseEvent.c73
1 files changed, 53 insertions, 20 deletions
diff --git a/macosx/tkMacOSXMouseEvent.c b/macosx/tkMacOSXMouseEvent.c
index 6481fbd..2b9d0bf 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
@@ -51,8 +92,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;
@@ -61,7 +102,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:
@@ -93,31 +140,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???*/