Tk Source Code

View Ticket
Login
Ticket UUID: eb29967e8825c8d80ddf1a575a9cc887ce8bcaab
Title: Add horizontal scrolling support for Windows
Type: Patch Version: 8.6.9
Submitter: chrstphrchvz Created on: 2019-04-05 04:52:34
Subsystem: 01. Bindings Assigned To: fvogel
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2019-05-18 15:46:44
Resolution: Fixed Closed By: fvogel
    Closed on: 2019-05-18 15:46:44
Description: (text/x-fossil-wiki)
See [ab046f476f75fc21b7c7] for original RFE. I'm not sure why it was closed as invalid; maybe the suggested implementation was mistaken, but I think the request for functionality was valid, and agree that the implementation is still rather straightforward.

This patch mostly duplicates existing code which handles vertical scrolling from <code>WM_MOUSEWHEEL</code>, and modifies it to instead handle horizontal scrolling from <code>WM_MOUSEHWHEEL</code>. Existing members of tkWinX.c's <code>ThreadSpecificData</code> for handling vertical scrolling have been prefixed with <code>v</code> to distinguish from members added for horizontal scrolling (prefixed with <code>h</code>). I have mirrored the approach used on Aqua (tkMacOSXMouseEvent.c) where horizontal scrolling is somewhat "emulated" where the posted event is equivalent to holding shift while scrolling vertically.

My hope is this can be applied to 8.6.x and not have to wait for 8.7. I am not aware how this might break compatibility with 8.6.9, which silently ignores <code>WM_MOUSEHWHEEL</code> yet supports horizontal scrolling emulation by shift+vertical scrolling.

Tested on core-8-6-branch on Windows 10 1809 x64.

Any suggestions, improvements, etc. are appreciated, as they should certainly be possible (for example, more aggressively combining code duplicated for each case).
User Comments: fvogel added on 2019-05-18 15:46:44:
Merged into core-8-6-branch and trunk.

fvogel added on 2019-04-30 19:45:37: (text/x-fossil-wiki)
Perhaps a more demonstrative/complet example:

<verbatim>
package require Tk
frame .f
text .f.t -wrap none -yscrollcommand {.f.s set} -xscrollcommand {.sh set}
set s [string repeat "abcdefghijklmnopqrstuvwxyz " 50]
for {set i 1} {$i < 100} {incr i} {
    .f.t insert end [string range $s $i end]\n
}
scrollbar .f.s -command {.f.t yview}
scrollbar .sh -orient horizontal -command {.f.t xview}
pack .f.t .f.s -side left -fill y -expand true
pack .f .sh -fill x -expand true
</verbatim>

Scrolling works OK, both horizontally and vertically, and the scrollbars are correctly updated.

I'd appreciate other people testing, thanks!

fvogel added on 2019-04-30 19:15:44: (text/x-fossil-wiki)
I have tested the patch using AutoHotKey with the following script file:

<verbatim>
^l::
Send {WheelLeft}
return

^m::
Send {WheelRight}
return
</verbatim>

and then hitting Ctrl-l (to simulate Mouse Wheel action toward left) or Ctrl-m (to simulate Mouse Wheel action toward right), with the following Tcl/Tk test situation:

<verbatim>
package require Tk
pack [text .t -wrap none]
.t insert end [string repeat "abcdefghijklmnopqrstuvwxyz " 50]
</verbatim>

I can make the text scroll horizontally in each expected direction. So it looks like this patch is working.

Any other testers perhaps?

fvogel added on 2019-04-29 06:22:21: (text/x-fossil-wiki)
Patch committed in branch [https://core.tcl-lang.org/tk/timeline?r=bug-eb29967e88|bug-eb29967e88] so that it can be tested.

(Sorry, I primarily meant: manual tests)

chrstphrchvz added on 2019-04-28 21:48:59: (text/x-fossil-wiki)
<blockquote>My question is: how can the feature be tested, i.e. how can we make the OS trigger <code>WM_MOUSEHWHEEL</code> ?</blockquote>

If there was already code for testing <code>WM_MOUSEWHEEL</code>, I might know. From briefly looking, a test might involve using <code>SendMessage()</code> from tkWinTest.c, in turn used from some script via <code>testwinevent</code>. But I really am not familiar with Tk's unit tests, nor have I been compelled to master Tcl syntax for Tk. I understand it is not ideal to add stuff to Tk without automated tests; my motivation for submitting this patch was the ease of implementing the feature itself, not to try sneaking more stuff in without tests; but a test for this is not something I think I would be able to provide anytime soon.

One option I am aware of for manually testing this without horizontal scrolling hardware would be a software utility such as AutoHotKey which can map something like a keypress to scrolling in a direction by a certain amount.

fvogel added on 2019-04-28 20:00:26: (text/x-fossil-wiki)
I had a quick look at the patch it looks like I can understand it. My question is: how can the feature be tested, i.e. how can we make the OS trigger <code>WM_MOUSEHWHEEL</code> ?

Attachments: