From: Koen D. <ko...@re...> - 2008-12-17 09:06:38
|
Joe English wrote: > Kevin Kenny wrote: >> Donal K. Fellows wrote: >>> * TIP#171 should be easy to act on; I've not done it yet because I'm >>> not the relevant maintainer. >> Didn't we do these changes already? Why not? Jeff?? > > I (for one) still have unanswered questions about the > proposed TIP#171 implementation. Specifically: > > | instead of going through all sorts of rigamarole at > | the scripting level to redirect MouseWheel events > | to the widget under the pointer on Windows, wouldn't > | it make more sense to simply not redirect them to > | the focus window in the first place (see tkEvent.c, > | InvokeFocusHandlers)? That's how it's currently done > | on OSX. I suspect it also interferes with some of > | the ttk::* widgets. > > I agree with the TIP#171 Rationale (paraphrased: "On > Windows, mouse wheel scrolling should affect the widget > under the pointer [just like it does on X11 and OSX] > instead of the widget with keyboard focus.") But the > proposed implementation smells really bad to me. > > (The proposed implementation looks like a usable stopgap > solution for Tk <= 8.5, but long-term it is -- I suspect -- > something we're just going to have to undo later.) In case anyone is interested in it, I use the C patch below to achieve basically the same as TIP 171, but whithout all the [focus] voodoo going on in that TIP's implementation. Index: generic/tkEvent.c =================================================================== RCS file: /cvsroot/tktoolkit/tk/generic/tkEvent.c,v retrieving revision 1.37 diff -u -r1.37 tkEvent.c --- generic/tkEvent.c 8 Nov 2008 18:44:39 -0000 1.37 +++ generic/tkEvent.c 25 Nov 2008 11:34:05 -0000 @@ -246,17 +246,7 @@ return 1; } - /* - * MouseWheel events are not focus specific on Mac OS X. - */ - -#ifdef MAC_OSX_TK -#define FOCUS_DIRECTED_EVENT_MASK (KeyPressMask|KeyReleaseMask) -#else -#define FOCUS_DIRECTED_EVENT_MASK (KeyPressMask|KeyReleaseMask|MouseWheelMask) -#endif - - if (mask & FOCUS_DIRECTED_EVENT_MASK) { + if (mask & (KeyPressMask|KeyReleaseMask)) { (*winPtrPtr)->dispPtr->lastEventTime = eventPtr->xkey.time; *winPtrPtr = TkFocusKeyEvent(*winPtrPtr, eventPtr); if (*winPtrPtr == NULL) { Index: win/tkWinX.c =================================================================== RCS file: /cvsroot/tktoolkit/tk/win/tkWinX.c,v retrieving revision 1.58 diff -u -r1.58 tkWinX.c --- win/tkWinX.c 27 Apr 2008 22:39:17 -0000 1.58 +++ win/tkWinX.c 25 Nov 2008 11:34:08 -0000 @@ -1006,6 +1006,16 @@ ThreadSpecificData *tsdPtr = (ThreadSpecificData *) Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); + /* Redirect mousewheel events to the window containing the cursor. */ + if (message == WM_MOUSEWHEEL) { + POINTS rootPoint = MAKEPOINTS(lParam); + POINT pos; + pos.x = rootPoint.x; + pos.y = rootPoint.y; + hwnd = WindowFromPoint(pos); + winPtr = (TkWindow *) Tk_HWNDToWindow(hwnd); + } + if (!winPtr || winPtr->window == None) { return; } @@ -1103,11 +1113,6 @@ break; case WM_MOUSEWHEEL: - /* - * The mouse wheel event is closer to a key event than a mouse event - * in that the message is sent to the window that has focus. - */ - case WM_CHAR: case WM_UNICHAR: case WM_SYSKEYDOWN: |