diff options
author | das <das> | 2006-04-07 06:15:42 (GMT) |
---|---|---|
committer | das <das> | 2006-04-07 06:15:42 (GMT) |
commit | 82780ae1278b1a90e446dc7535ec0c75e87b4a0c (patch) | |
tree | b857b1cd53b4c16c6b24f74944dc43bafdfc4426 /macosx | |
parent | c00d853ea77cacb48ff6fd5c6055c81ab95caad5 (diff) | |
download | tk-82780ae1278b1a90e446dc7535ec0c75e87b4a0c.zip tk-82780ae1278b1a90e446dc7535ec0c75e87b4a0c.tar.gz tk-82780ae1278b1a90e446dc7535ec0c75e87b4a0c.tar.bz2 |
* macosx/tkMacOSXMouseEvent.c (TkMacOSXProcessMouseEvent): fix return
values, implement window dragging & growing in background (with Command
key down) and by fronting clicks, use correct button & modifier state
API when application is in background (also in TkMacOSXButtonKeyState).
* macosx/tkMacOSXWm.c (TkMacOSXGrowToplevel): ensure QD port is set
correctly before using API relying on it.
Diffstat (limited to 'macosx')
-rw-r--r-- | macosx/tkMacOSXMouseEvent.c | 172 | ||||
-rw-r--r-- | macosx/tkMacOSXWm.c | 6 |
2 files changed, 97 insertions, 81 deletions
diff --git a/macosx/tkMacOSXMouseEvent.c b/macosx/tkMacOSXMouseEvent.c index bd1ec12..d06e56b 100644 --- a/macosx/tkMacOSXMouseEvent.c +++ b/macosx/tkMacOSXMouseEvent.c @@ -54,7 +54,7 @@ * software in accordance with the terms specified in this * license. * - * RCS: @(#) $Id: tkMacOSXMouseEvent.c,v 1.19 2006/04/06 22:16:09 vincentdarley Exp $ + * RCS: @(#) $Id: tkMacOSXMouseEvent.c,v 1.20 2006/04/07 06:15:42 das Exp $ */ #include "tkMacOSXInt.h" @@ -126,6 +126,8 @@ TkMacOSXProcessMouseEvent(TkMacOSXEvent *eventPtr, MacEventStatus * statusPtr) TkDisplay * dispPtr; OSStatus status; MouseEventData mouseEventData, * medPtr = &mouseEventData; + ProcessSerialNumber frontPsn, ourPsn = {0, kCurrentProcess}; + Boolean isFrontProcess = true; switch (eventPtr->eKind) { case kEventMouseUp: @@ -135,7 +137,7 @@ TkMacOSXProcessMouseEvent(TkMacOSXEvent *eventPtr, MacEventStatus * statusPtr) case kEventMouseWheelMoved: break; default: - return 0; + return false; break; } status = GetEventParameter(eventPtr->eventRef, @@ -163,28 +165,33 @@ TkMacOSXProcessMouseEvent(TkMacOSXEvent *eventPtr, MacEventStatus * statusPtr) } medPtr->window = TkMacOSXGetXWindow(medPtr->whichWin); if (medPtr->whichWin != NULL && medPtr->window == None) { - return 0; + return false; } if (eventPtr->eKind == kEventMouseDown) { if (IsWindowPathSelectEvent(medPtr->whichWin, eventPtr->eventRef)) { - SInt32 result; - return WindowPathSelect(medPtr->whichWin, NULL, &result); + status = WindowPathSelect(medPtr->whichWin, NULL, NULL); + return false; } if (medPtr->windowPart == inProxyIcon) { - OSStatus status = TrackWindowProxyDrag(medPtr->whichWin, where); - + status = TrackWindowProxyDrag(medPtr->whichWin, where); if (status == errUserWantsToDragWindow) { medPtr->windowPart = inDrag; } else { - if (status == noErr) { - /* drag successful */ - } - return status; + return false; } } } - medPtr->state = ButtonModifiers2State(GetCurrentEventButtonState(), - GetCurrentEventKeyModifiers()); + status = GetFrontProcess(&frontPsn); + if (status == noErr) { + SameProcess(&frontPsn, &ourPsn, &isFrontProcess); + } + if (isFrontProcess) { + medPtr->state = ButtonModifiers2State(GetCurrentEventButtonState(), + GetCurrentEventKeyModifiers()); + } else { + medPtr->state = ButtonModifiers2State(GetCurrentButtonState(), + GetCurrentKeyModifiers()); + } medPtr->global = where; status = GetEventParameter(eventPtr->eventRef, kEventParamWindowMouseLocation, @@ -220,6 +227,9 @@ TkMacOSXProcessMouseEvent(TkMacOSXEvent *eventPtr, MacEventStatus * statusPtr) } return GenerateButtonEvent(medPtr); } + if (eventPtr->eKind == kEventMouseDown) { + TkMacOSXSetEatButtonUp(false); + } if (eventPtr->eKind == kEventMouseWheelMoved) { status = GetEventParameter(eventPtr->eventRef, kEventParamMouseWheelDelta, typeLongInteger, NULL, @@ -270,14 +280,6 @@ TkMacOSXProcessMouseEvent(TkMacOSXEvent *eventPtr, MacEventStatus * statusPtr) * or else it will mess up some Tk scripts. */ - ProcessSerialNumber frontPsn, ourPsn = {0, kCurrentProcess}; - Boolean isFrontProcess = true; - - status = GetFrontProcess(&frontPsn); - if (status == noErr) { - SameProcess(&frontPsn, &ourPsn, &isFrontProcess); - } - if (!(TkpIsWindowFloating(medPtr->whichWin)) && (medPtr->whichWin != medPtr->activeNonFloating || !isFrontProcess)) { @@ -309,70 +311,74 @@ TkMacOSXProcessMouseEvent(TkMacOSXEvent *eventPtr, MacEventStatus * statusPtr) } /* - * Clicks in the stoplights on a MacOS X title bar are processed - * directly even for background windows. Do that here. + * Clicks in the titlebar widgets are handled without bringing the + * window forward. */ if ((result = HandleWindowTitlebarMouseDown(medPtr, tkwin)) != -1) { return result; } else { - TkMacOSXSetEatButtonUp(true); - BringWindowForward(medPtr->whichWin, isFrontProcess); - return false; + /* + * Allow background window dragging & growing with Command down + */ + if (!((medPtr->windowPart == inDrag || + medPtr->windowPart == inGrow) && + medPtr->state & Mod1Mask)) { + TkMacOSXSetEatButtonUp(true); + BringWindowForward(medPtr->whichWin, isFrontProcess); + } + /* + * Allow dragging & growing of windows that were/are in the + * background. + */ + if (!(medPtr->windowPart == inDrag || + medPtr->windowPart == inGrow)) { + return false; + } } - } - } - - if ((result = HandleWindowTitlebarMouseDown(medPtr, tkwin)) != -1) { - return result; - } - switch (medPtr->windowPart) { - case inDrag: { - CGrafPtr saveWorld; - GDHandle saveDevice; - GWorldPtr dstPort; - - GetGWorld(&saveWorld, &saveDevice); - dstPort = TkMacOSXGetDrawablePort(Tk_WindowId(tkwin)); - SetGWorld(dstPort, NULL); - - DragWindow(medPtr->whichWin, where, NULL); - where2.h = where2.v = 0; - LocalToGlobal(&where2); - if (EqualPt(where, where2)) { - SetGWorld (saveWorld, saveDevice); - return false; + } else { + if ((result = HandleWindowTitlebarMouseDown(medPtr, tkwin)) != -1) { + return result; } - TkMacOSXWindowOffset(medPtr->whichWin, &xOffset, &yOffset); - where2.h -= xOffset; - where2.v -= yOffset; - TkGenWMConfigureEvent(tkwin, where2.h, where2.v, - -1, -1, TK_LOCATION_CHANGED); - SetGWorld(saveWorld, saveDevice); - return true; - break; } - case inContent: - return GenerateButtonEvent(medPtr); - break; - case inGrow: - /* - * Generally the content region is the domain of Tk - * sub-windows. However, one exception is the grow - * region. A button down in this area will be handled - * by the window manager. Note: this means that Tk - * may not get button down events in this area! - */ - if (TkMacOSXGrowToplevel(medPtr->whichWin, where) == true) { + switch (medPtr->windowPart) { + case inDrag: + SetPort(GetWindowPort(medPtr->whichWin)); + DragWindow(medPtr->whichWin, where, NULL); + where2.h = where2.v = 0; + LocalToGlobal(&where2); + if (EqualPt(where, where2)) { + return false; + } + TkMacOSXWindowOffset(medPtr->whichWin, &xOffset, &yOffset); + where2.h -= xOffset; + where2.v -= yOffset; + TkGenWMConfigureEvent(tkwin, where2.h, where2.v, + -1, -1, TK_LOCATION_CHANGED); return true; - } else { + break; + case inGrow: + /* + * Generally the content region is the domain of Tk + * sub-windows. However, one exception is the grow + * region. A button down in this area will be handled + * by the window manager. Note: this means that Tk + * may not get button down events in this area! + */ + if (TkMacOSXGrowToplevel(medPtr->whichWin, where) == true) { + return true; + } else { + return GenerateButtonEvent(medPtr); + } + break; + case inContent: return GenerateButtonEvent(medPtr); - } - break; - default: - return false; - break; + break; + default: + return false; + break; + } } - return 0; + return false; } /* @@ -668,12 +674,22 @@ unsigned int TkMacOSXButtonKeyState() { UInt32 buttonState = 0, keyModifiers; - EventRef ev = GetCurrentEvent(); + Boolean isFrontProcess = false; + + if (GetCurrentEvent()) { + ProcessSerialNumber frontPsn, ourPsn = {0, kCurrentProcess}; + OSStatus status = GetFrontProcess(&frontPsn); + if (status == noErr) { + SameProcess(&frontPsn, &ourPsn, &isFrontProcess); + } + } if (!gEatButtonUp) { - buttonState = ev ? GetCurrentEventButtonState() : GetCurrentButtonState(); + buttonState = isFrontProcess ? GetCurrentEventButtonState() : + GetCurrentButtonState(); } - keyModifiers = ev ? GetCurrentEventKeyModifiers() : GetCurrentKeyModifiers(); + keyModifiers = isFrontProcess ? GetCurrentEventKeyModifiers() : + GetCurrentKeyModifiers(); return ButtonModifiers2State(buttonState, keyModifiers); } diff --git a/macosx/tkMacOSXWm.c b/macosx/tkMacOSXWm.c index af42cca..3586d54 100644 --- a/macosx/tkMacOSXWm.c +++ b/macosx/tkMacOSXWm.c @@ -12,7 +12,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkMacOSXWm.c,v 1.25 2006/04/06 09:28:32 das Exp $ + * RCS: @(#) $Id: tkMacOSXWm.c,v 1.26 2006/04/07 06:15:42 das Exp $ */ #include "tkMacOSXInt.h" @@ -4497,6 +4497,7 @@ TkMacOSXGrowToplevel( TkDisplay *dispPtr; Rect portRect; + SetPort(GetWindowPort(whichWindow)); GlobalToLocal(&where); GetPortBounds(GetWindowPort(whichWindow), &portRect ); if (where.h > (portRect.right - 16) && @@ -4535,7 +4536,6 @@ TkMacOSXGrowToplevel( if (growResult != 0) { SizeWindow(whichWindow, LoWord(growResult), HiWord(growResult), true); - SetPort( GetWindowPort(whichWindow)); InvalWindowRect(whichWindow,&portRect); /* TODO: may not be needed */ TkMacOSXInvalClipRgns((Tk_Window) winPtr); TkGenWMConfigureEvent((Tk_Window) winPtr, -1, -1, @@ -4686,7 +4686,7 @@ TkMacOSXZoomToplevel( TkDisplay *dispPtr; Rect portRect; - SetPort( GetWindowPort(whichWindow)); + SetPort(GetWindowPort(whichWindow)); /* * We should now zoom the window (as long as it's one of ours). We |