diff options
-rw-r--r-- | macosx/tkMacOSXInit.c | 1 | ||||
-rw-r--r-- | macosx/tkMacOSXMouseEvent.c | 39 | ||||
-rw-r--r-- | macosx/tkMacOSXPrivate.h | 7 | ||||
-rw-r--r-- | macosx/tkMacOSXWm.c | 32 |
4 files changed, 62 insertions, 17 deletions
diff --git a/macosx/tkMacOSXInit.c b/macosx/tkMacOSXInit.c index dfdde24..278c729 100644 --- a/macosx/tkMacOSXInit.c +++ b/macosx/tkMacOSXInit.c @@ -47,6 +47,7 @@ static int TkMacOSXGetAppPathCmd(ClientData cd, Tcl_Interp *ip, @synthesize tkLiveResizeEnded = _tkLiveResizeEnded; @synthesize tkPointerWindow = _tkPointerWindow; @synthesize tkEventTarget = _tkEventTarget; +@synthesize tkDragTarget = _tkDragTarget; @synthesize tkButtonState = _tkButtonState; @end diff --git a/macosx/tkMacOSXMouseEvent.c b/macosx/tkMacOSXMouseEvent.c index accb1c6..fcbce34 100644 --- a/macosx/tkMacOSXMouseEvent.c +++ b/macosx/tkMacOSXMouseEvent.c @@ -90,8 +90,7 @@ enum { NSPoint location = [theEvent locationInWindow]; NSPoint viewLocation = [contentView convertPoint:location fromView:nil]; TkWindow *winPtr = NULL, *grabWinPtr, *scrollTarget = NULL; - Tk_Window tkwin = NULL, capture; - static Tk_Window target = NULL, dragTarget = NULL; + Tk_Window tkwin = NULL, capture, target; NSPoint local, global; NSInteger button; TkWindow *newFocus = NULL; @@ -100,7 +99,6 @@ enum { Bool isTestingEvent = NO; Bool isMotionEvent = NO; Bool isOutside = NO; - static Bool isDragging = NO; static Bool ignoreDrags = NO; static Bool ignoreUpDown = NO; static NSTimeInterval timestamp = 0; @@ -144,14 +142,14 @@ enum { buttonState &= ~Tk_GetButtonMask(button); break; case NSLeftMouseDragged: - if (isOutside && !isDragging) { + if (isOutside && ![NSApp tkDragTarget]) { ignoreDrags = YES; } if (ignoreDrags) { return theEvent; } - isDragging = YES; - dragTarget = target; + [NSApp setTkDragTarget: [NSApp tkEventTarget]]; + break; case NSRightMouseDragged: case NSOtherMouseDragged: isMotionEvent = YES; @@ -173,8 +171,7 @@ enum { [NSApp setTkPointerWindow:nil]; break; case NSLeftMouseUp: - isDragging = NO; - dragTarget = NULL; + [NSApp setTkDragTarget: nil]; if ([theEvent clickCount] == 2) { ignoreUpDown = NO; } @@ -210,7 +207,6 @@ enum { if ([theEvent timestamp] - timestamp > 1) { ignoreUpDown = NO; } - if ([theEvent clickCount] == 2) { if (ignoreUpDown == YES) { return theEvent; @@ -301,8 +297,19 @@ enum { return theEvent; } } else { - if (isDragging) { - winPtr = TkMacOSXGetHostToplevel((TkWindow *)dragTarget)->winPtr; + if ([NSApp tkDragTarget]) { + TkWindow *dragPtr = (TkWindow *) [NSApp tkDragTarget]; + TKWindow *dragWindow = nil; + if (dragPtr) { + dragWindow = (TKWindow *)TkMacOSXGetNSWindowForDrawable( + dragPtr->window); + } + if (!dragWindow) { + [NSApp setTkDragTarget: nil]; + target = NULL; + return theEvent; + } + winPtr = TkMacOSXGetHostToplevel((TkWindow *) [NSApp tkDragTarget])->winPtr; } else if (eventType == NSScrollWheel) { winPtr = scrollTarget; } else { @@ -365,8 +372,8 @@ enum { * when the mouse is outside of the focused toplevel. */ - if (isDragging) { - TkWindow *w = (TkWindow *) dragTarget; + if ([NSApp tkDragTarget]) { + TkWindow *w = (TkWindow *) [NSApp tkDragTarget]; win_x = global.x; win_y = global.y; for (; w != NULL; w = w->parentPtr) { @@ -383,7 +390,7 @@ enum { break; } } - target = dragTarget; + target = (Tk_Window) [NSApp tkDragTarget]; } else { target = Tk_TopCoordsToWindow(tkwin, local.x, local.y, &win_x, &win_y); } @@ -449,7 +456,7 @@ enum { */ if (eventType != NSScrollWheel) { - if (isDragging) { + if ([NSApp tkDragTarget]) { /* * When dragging the mouse into the resize area Apple shows the @@ -464,7 +471,7 @@ enum { Tk_UpdatePointer((Tk_Window) [NSApp tkPointerWindow], global.x, global.y, state); } else if (eventType == NSMouseExited) { - if (isDragging) { + if ([NSApp tkDragTarget]) { Tk_UpdatePointer((Tk_Window) [NSApp tkPointerWindow], global.x, global.y, state); } else { diff --git a/macosx/tkMacOSXPrivate.h b/macosx/tkMacOSXPrivate.h index d546c49..ead6a71 100644 --- a/macosx/tkMacOSXPrivate.h +++ b/macosx/tkMacOSXPrivate.h @@ -343,6 +343,7 @@ VISIBILITY_HIDDEN Bool _tkLiveResizeEnded; TkWindow *_tkPointerWindow; TkWindow *_tkEventTarget; + TkWindow *_tkDragTarget; unsigned int _tkButtonState; #endif @@ -353,8 +354,14 @@ VISIBILITY_HIDDEN @property Bool needsToDraw; @property Bool isSigned; @property Bool tkLiveResizeEnded; + +/* + * Persistent state variables used by processMouseEvent. + */ + @property TkWindow *tkPointerWindow; @property TkWindow *tkEventTarget; +@property TkWindow *tkDragTarget; @property unsigned int tkButtonState; @end diff --git a/macosx/tkMacOSXWm.c b/macosx/tkMacOSXWm.c index b8b4b2f..2931763 100644 --- a/macosx/tkMacOSXWm.c +++ b/macosx/tkMacOSXWm.c @@ -1053,13 +1053,41 @@ TkWmDeadWindow( ckfree(transientPtr); } + deadNSWindow = (TKWindow *)wmPtr->window; + + /* + * Remove references to the Tk window from the mouse event processing + * state which is recorded in the NSApplication object. + */ + + if (winPtr == [NSApp tkDragTarget]) { + [NSApp setTkDragTarget:nil]; + } + if (winPtr == [NSApp tkPointerWindow]) { + NSWindow *w; + NSPoint mouse = [NSEvent mouseLocation]; + [NSApp setTkPointerWindow:nil]; + for (w in [NSApp orderedWindows]) { + if (w == deadNSWindow) { + continue; + } + if (NSPointInRect(mouse, [w frame])) { + TkWindow *winPtr2 = TkMacOSXGetTkWindow(w); + int x = mouse.x, y = TkMacOSXZeroScreenHeight() - mouse.y; + [NSApp setTkPointerWindow:winPtr2]; + Tk_UpdatePointer((Tk_Window) winPtr2, x, y, + [NSApp tkButtonState]); + break; + } + } + } + /* * Unregister the NSWindow and remove all references to it from the Tk * data structures. If the NSWindow is a child, disassociate it from * the parent. Then close and release the NSWindow. */ - deadNSWindow = (TKWindow *)wmPtr->window; if (deadNSWindow && !Tk_IsEmbedded(winPtr)) { NSWindow *parent = [deadNSWindow parentWindow]; [deadNSWindow setTkWindow:None]; @@ -1108,6 +1136,7 @@ TkWmDeadWindow( wmPtr2->hints.initial_state != WithdrawnState); if (w != deadNSWindow && isOnScreen && [w canBecomeKeyWindow]) { [w makeKeyAndOrderFront:NSApp]; + [NSApp setTkEventTarget:TkMacOSXGetTkWindow(w)]; break; } } @@ -6705,6 +6734,7 @@ TkpChangeFocus( } if (win && [win canBecomeKeyWindow]) { [win makeKeyAndOrderFront:NSApp]; + [NSApp setTkEventTarget:TkMacOSXGetTkWindow(win)]; } } |