Tk Source Code

Check-in [361f2173]
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Create a derivated version of TIP #532 targeting trunk (8.7), with PREFER_MOST_SPECIALIZED_EVENT=1 and SUPPORT_ADDITIONAL_MOTION_SYNTAX=1
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | bug6e8afe516d-87
Files: files | file ages | folders
SHA3-256:361f21736c54c133f8d400e2a289a1d1c85a62327dae86baf46af12453117687
User & Date: fvogel 2019-02-03 17:23:15
Context
2019-02-03
17:28
rebase to trunk check-in: 2788c9d4 user: fvogel tags: bug6e8afe516d-87
17:23
Create a derivated version of TIP #532 targeting trunk (8.7), with PREFER_MOST_SPECIALIZED_EVENT=1 and SUPPORT_ADDITIONAL_MOTION_SYNTAX=1 check-in: 361f2173 user: fvogel tags: bug6e8afe516d-87
17:18
Tweaked comments check-in: 263b9cde user: fvogel tags: bug6e8afe516d
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to doc/bind.n.

629
630
631
632
633
634
635
636
637

638
639
640
641
642
643
644
The following tests are applied, in order, to determine which of
several matching sequences is more specific:
.RS
.IP (a)
an event pattern that specifies a specific button or key is more specific
than one that does not;
.IP (b)
a longer sequence (in terms of number
of events matched) is more specific than a shorter sequence;

.IP (c)
if the modifiers specified in one pattern are a subset of the
modifiers in another pattern, then the pattern with more modifiers
is more specific;
.IP (d)
a virtual event whose physical pattern matches the sequence is less
specific than the same physical pattern that is not associated with a






|
|
>







629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
The following tests are applied, in order, to determine which of
several matching sequences is more specific:
.RS
.IP (a)
an event pattern that specifies a specific button or key is more specific
than one that does not;
.IP (b)
a sequence with the most highest-ordered patterns (in term of highest
repetition count) is more specific than a sequence with less
highest-ordered patterns;
.IP (c)
if the modifiers specified in one pattern are a subset of the
modifiers in another pattern, then the pattern with more modifiers
is more specific;
.IP (d)
a virtual event whose physical pattern matches the sequence is less
specific than the same physical pattern that is not associated with a

Changes to generic/tkBind.c.

70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
 *
 * Non-package-specific helpers.
 */

/*
 * In old implementation (the one that used an event ring), <Double-1> and <1><1> were
 * equivalent sequences. However it is logical to give <Double-1> higher precedence.
 * This can be achieved by setting PREFER_MOST_SPECIALIZED_EVENT to 1.
 */

#ifndef PREFER_MOST_SPECIALIZED_EVENT
# define PREFER_MOST_SPECIALIZED_EVENT 0
#endif

/*
 * Traditionally motion events can be combined with buttons in this way: <B1-B2-Motion>.
 * However it should be allowed to express this as <Motion-1-2> in addition. This can be
 * achieved by setting SUPPORT_ADDITIONAL_MOTION_SYNTAX to 1.
 */

#ifndef SUPPORT_ADDITIONAL_MOTION_SYNTAX
# define SUPPORT_ADDITIONAL_MOTION_SYNTAX 0 /* set to 1 if wanted */
#endif

/*
 * The output for motion events is of the type <B1-Motion>. This can be changed to become
 * <Motion-1> instead by setting PRINT_SHORT_MOTION_SYNTAX to 1, however this would be a
 * backwards incompatibility.
 */






|



|




|
|



|







70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
 *
 * Non-package-specific helpers.
 */

/*
 * In old implementation (the one that used an event ring), <Double-1> and <1><1> were
 * equivalent sequences. However it is logical to give <Double-1> higher precedence.
 * This is achieved by setting PREFER_MOST_SPECIALIZED_EVENT to 1.
 */

#ifndef PREFER_MOST_SPECIALIZED_EVENT
# define PREFER_MOST_SPECIALIZED_EVENT 1
#endif

/*
 * Traditionally motion events can be combined with buttons in this way: <B1-B2-Motion>.
 * However it should be allowed to express this as <Motion-1-2> in addition. This is achieved
 * by setting SUPPORT_ADDITIONAL_MOTION_SYNTAX to 1.
 */

#ifndef SUPPORT_ADDITIONAL_MOTION_SYNTAX
# define SUPPORT_ADDITIONAL_MOTION_SYNTAX 1
#endif

/*
 * The output for motion events is of the type <B1-Motion>. This can be changed to become
 * <Motion-1> instead by setting PRINT_SHORT_MOTION_SYNTAX to 1, however this would be a
 * backwards incompatibility.
 */

Changes to tests/bind.test.

6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
....
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
....
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
    event generate .t.f <a>
    event generate .t.f <1>
    event generate .t.f <1>
    set x
} -cleanup {
    destroy .t.f
} -result {a11}
test bind-33.2 {should prefer most specific event} -setup {
    pack [frame .t.f]
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Double-1> { lappend x "Double" }
    bind .t.f <1><1> { lappend x "11" }
    event generate .t.f <1>
    event generate .t.f <1>
    set x
} -cleanup {
    destroy .t.f
    # This test case shows that old implementation has an issue, because
    # it is expected that <Double-1> is matching, this binding
    # is more specific. But new implementation will be conform to old,
    # and so "11" is the expected result.
} -result {11}
test bind-33.3 {should prefer most specific event} -setup {
    pack [frame .t.f]
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <a><Double-1><a> { lappend x "Double" }
    bind .t.f <a><1><1><a> { lappend x "11" }
................................................................................
    event generate .t.f <a>
    event generate .t.f <1>
    event generate .t.f <1>
    event generate .t.f <a>
    set x
} -cleanup {
    destroy .t.f
    # Also this test case shows that old implementation has an issue, it is
    # expected that <a><Double-1><a> is matching, because <Double-1> is more
    # specific than <1><1>. But new implementation will be conform to old,
    # and so "11" is the expected result.
} -result {11}
test bind-33.4 {prefer most specific event} -setup {
    pack [frame .t.f]
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <1><1> { lappend x "11" }
................................................................................
    event generate .t.f <1>
    event generate .t.f <1>
    event generate .t.f <2>
    event generate .t.f <2>
    set x
} -cleanup {
    destroy .t.f
    # This test case shows that old implementation has an issue, because
    # it is expected that first one is matching, this binding
    # is more specific. But new implementation will be conform to old,
    # and so "last" is the expected result.
} -result {last}
test bind-33.12 {prefer last in case of homogeneous equal patterns} -setup {
    pack [frame .t.f]
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Control-1><1> { lappend x "first" }






|












<
<
<
<
|
|







 







<
<
<
<
|







 







<
<
<
<
|







6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373




6374
6375
6376
6377
6378
6379
6380
6381
6382
....
6383
6384
6385
6386
6387
6388
6389




6390
6391
6392
6393
6394
6395
6396
6397
....
6513
6514
6515
6516
6517
6518
6519




6520
6521
6522
6523
6524
6525
6526
6527
    event generate .t.f <a>
    event generate .t.f <1>
    event generate .t.f <1>
    set x
} -cleanup {
    destroy .t.f
} -result {a11}
test bind-33.2 {prefer most specific event} -setup {
    pack [frame .t.f]
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Double-1> { lappend x "Double" }
    bind .t.f <1><1> { lappend x "11" }
    event generate .t.f <1>
    event generate .t.f <1>
    set x
} -cleanup {
    destroy .t.f




} -result {Double}
test bind-33.3 {prefer most specific event} -setup {
    pack [frame .t.f]
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <a><Double-1><a> { lappend x "Double" }
    bind .t.f <a><1><1><a> { lappend x "11" }
................................................................................
    event generate .t.f <a>
    event generate .t.f <1>
    event generate .t.f <1>
    event generate .t.f <a>
    set x
} -cleanup {
    destroy .t.f




} -result {Double}
test bind-33.4 {prefer most specific event} -setup {
    pack [frame .t.f]
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <1><1> { lappend x "11" }
................................................................................
    event generate .t.f <1>
    event generate .t.f <1>
    event generate .t.f <2>
    event generate .t.f <2>
    set x
} -cleanup {
    destroy .t.f




} -result {first}
test bind-33.12 {prefer last in case of homogeneous equal patterns} -setup {
    pack [frame .t.f]
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Control-1><1> { lappend x "first" }