From 078fd483b608ea19f2d47f36f5a6a8a3a1c04405 Mon Sep 17 00:00:00 2001 From: dkf Date: Wed, 6 Jan 2010 18:37:35 +0000 Subject: Centralize the definitions of what keys do particular types of left and right movements in entries and text widgets. They vary between platforms! --- ChangeLog | 8 +++++++ doc/event.n | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++- library/entry.tcl | 28 +++++++++++----------- library/spinbox.tcl | 28 +++++++++++----------- library/text.tcl | 26 ++++++++++----------- library/tk.tcl | 45 ++++++++++++++++++++++++++++++++++- library/ttk/entry.tcl | 28 +++++++++++----------- 7 files changed, 173 insertions(+), 55 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2ec6e79..91a8270 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2010-01-06 Donal K. Fellows + * library/tk.tcl: Centralize the definition of keys that + * library/entry.tcl: do common movement in entry and text + * library/spinbox.tcl: widgets. This is because they are + * library/text.tcl: subtlely different on the different + * library/ttk/entry.tcl: platforms. Lets Tk code work more + * doc/event.n (PREDEFINED VIRTUAL EVENTS): correctly with platform + conventions "out of the box". + * generic/tkBind.c (HandleEventGenerate, DoWarp): [Bug 2926819]: * generic/tkInt.h (TkDisplay): Factor out the pointer * generic/tkWindow.c (GetScreen): warping code a bit diff --git a/doc/event.n b/doc/event.n index 01b1208..c47a5fc 100644 --- a/doc/event.n +++ b/doc/event.n @@ -5,7 +5,7 @@ '\" See the file "license.terms" for information on usage and redistribution '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. '\" -'\" RCS: @(#) $Id: event.n,v 1.22 2009/03/10 11:13:53 dkf Exp $ +'\" RCS: @(#) $Id: event.n,v 1.23 2010/01/06 18:37:36 dkf Exp $ '\" .so man.macros .TH event n 8.3 Tk "Tk Built-In Commands" @@ -360,6 +360,26 @@ Copy the currently selected widget contents to the clipboard. \fB<>\fR Move the currently selected widget contents to the clipboard. .TP +\fB<>\fR +. +Move to the end of the line in the current widget while deselecting any +selected contents. +.TP +\fB<>\fR +. +Move to the start of the line in the current widget while deselecting any +selected contents. +.TP +\fB<>\fR +. +Move to the next item (i.e., visible character) in the current widget while +deselecting any selected contents. +.TP +\fB<>\fR +. +Move to the next group of items (i.e., visible word) in the current widget +while deselecting any selected contents. +.TP \fB<>\fR Replace the currently selected widget contents with the contents of the clipboard. @@ -368,12 +388,52 @@ the clipboard. Insert the contents of the selection at the mouse location. (This event has meaningful \fB%x\fR and \fB%y\fR substitutions). .TP +\fB<>\fR +. +Move to the previous item (i.e., visible character) in the current widget +while deselecting any selected contents. +.TP \fB<>\fR Traverse to the previous window. .TP +\fB<>\fR +. +Move to the previous group of items (i.e., visible word) in the current widget +while deselecting any selected contents. +.TP \fB<>\fR Redo one undone action. .TP +\fB<>\fR +. +Move to the end of the line in the current widget while extending the range +of selected contents. +.TP +\fB<>\fR +. +Move to the start of the line in the current widget while extending the range +of selected contents. +.TP +\fB<>\fR +. +Move to the next item (i.e., visible character) in the current widget while +extending the range of selected contents. +.TP +\fB<>\fR +. +Move to the next group of items (i.e., visible word) in the current widget +while extending the range of selected contents. +.TP +\fB<>\fR +. +Move to the previous item (i.e., visible character) in the current widget +while extending the range of selected contents. +.TP +\fB<>\fR +. +Move to the previous group of items (i.e., visible word) in the current widget +while extending the range of selected contents. +.TP \fB<>\fR Undo the last action. .SH EXAMPLES @@ -390,6 +450,9 @@ Consider the following virtual event definitions: \fBevent add\fR <> \fBevent add\fR <> \fBevent add\fR <> +if {[tk windowingsystem] eq "aqua"} { + \fBevent add\fR <> +} .CE .PP In the \fBbind\fR command, a virtual event can be bound like any other diff --git a/library/entry.tcl b/library/entry.tcl index 9d93a24..b92f8b9 100644 --- a/library/entry.tcl +++ b/library/entry.tcl @@ -3,7 +3,7 @@ # This file defines the default bindings for Tk entry widgets and provides # procedures that help in implementing those bindings. # -# RCS: @(#) $Id: entry.tcl,v 1.26 2007/12/13 15:26:27 dgp Exp $ +# RCS: @(#) $Id: entry.tcl,v 1.27 2010/01/06 18:37:36 dkf Exp $ # # Copyright (c) 1992-1994 The Regents of the University of California. # Copyright (c) 1994-1997 Sun Microsystems, Inc. @@ -121,45 +121,45 @@ bind Entry { %W icursor @%x } -bind Entry { +bind Entry <> { tk::EntrySetCursor %W [expr {[%W index insert] - 1}] } -bind Entry { +bind Entry <> { tk::EntrySetCursor %W [expr {[%W index insert] + 1}] } -bind Entry { +bind Entry <> { tk::EntryKeySelect %W [expr {[%W index insert] - 1}] tk::EntrySeeInsert %W } -bind Entry { +bind Entry <> { tk::EntryKeySelect %W [expr {[%W index insert] + 1}] tk::EntrySeeInsert %W } -bind Entry { +bind Entry <> { tk::EntrySetCursor %W [tk::EntryPreviousWord %W insert] } -bind Entry { +bind Entry <> { tk::EntrySetCursor %W [tk::EntryNextWord %W insert] } -bind Entry { +bind Entry <> { tk::EntryKeySelect %W [tk::EntryPreviousWord %W insert] tk::EntrySeeInsert %W } -bind Entry { +bind Entry <> { tk::EntryKeySelect %W [tk::EntryNextWord %W insert] tk::EntrySeeInsert %W } -bind Entry { +bind Entry <> { tk::EntrySetCursor %W 0 } -bind Entry { +bind Entry <> { tk::EntryKeySelect %W 0 tk::EntrySeeInsert %W } -bind Entry { +bind Entry <> { tk::EntrySetCursor %W end } -bind Entry { +bind Entry <> { tk::EntryKeySelect %W end tk::EntrySeeInsert %W } @@ -210,6 +210,8 @@ bind Entry {# nothing} bind Entry {# nothing} bind Entry {# nothing} bind Entry {# nothing} +bind Entry {# nothing} +bind Entry {# nothing} if {[tk windowingsystem] eq "aqua"} { bind Entry {# nothing} } diff --git a/library/spinbox.tcl b/library/spinbox.tcl index f470888..4df106f 100644 --- a/library/spinbox.tcl +++ b/library/spinbox.tcl @@ -4,7 +4,7 @@ # procedures that help in implementing those bindings. The spinbox builds # off the entry widget, so it can reuse Entry bindings and procedures. # -# RCS: @(#) $Id: spinbox.tcl,v 1.9 2005/07/25 09:06:00 dkf Exp $ +# RCS: @(#) $Id: spinbox.tcl,v 1.10 2010/01/06 18:37:36 dkf Exp $ # # Copyright (c) 1992-1994 The Regents of the University of California. # Copyright (c) 1994-1997 Sun Microsystems, Inc. @@ -129,45 +129,45 @@ bind Spinbox { %W invoke buttondown } -bind Spinbox { +bind Spinbox <> { ::tk::EntrySetCursor %W [expr {[%W index insert] - 1}] } -bind Spinbox { +bind Spinbox <> { ::tk::EntrySetCursor %W [expr {[%W index insert] + 1}] } -bind Spinbox { +bind Spinbox <> { ::tk::EntryKeySelect %W [expr {[%W index insert] - 1}] ::tk::EntrySeeInsert %W } -bind Spinbox { +bind Spinbox <> { ::tk::EntryKeySelect %W [expr {[%W index insert] + 1}] ::tk::EntrySeeInsert %W } -bind Spinbox { +bind Spinbox <> { ::tk::EntrySetCursor %W [::tk::EntryPreviousWord %W insert] } -bind Spinbox { +bind Spinbox <> { ::tk::EntrySetCursor %W [::tk::EntryNextWord %W insert] } -bind Spinbox { +bind Spinbox <> { ::tk::EntryKeySelect %W [::tk::EntryPreviousWord %W insert] ::tk::EntrySeeInsert %W } -bind Spinbox { +bind Spinbox <> { ::tk::EntryKeySelect %W [::tk::EntryNextWord %W insert] ::tk::EntrySeeInsert %W } -bind Spinbox { +bind Spinbox <> { ::tk::EntrySetCursor %W 0 } -bind Spinbox { +bind Spinbox <> { ::tk::EntryKeySelect %W 0 ::tk::EntrySeeInsert %W } -bind Spinbox { +bind Spinbox <> { ::tk::EntrySetCursor %W end } -bind Spinbox { +bind Spinbox <> { ::tk::EntryKeySelect %W end ::tk::EntrySeeInsert %W } @@ -217,6 +217,8 @@ bind Spinbox {# nothing} bind Spinbox {# nothing} bind Spinbox {# nothing} bind Spinbox {# nothing} +bind Spinbox {# nothing} +bind Spinbox {# nothing} if {[tk windowingsystem] eq "aqua"} { bind Spinbox {# nothing} } diff --git a/library/text.tcl b/library/text.tcl index 509d425..74a8d6b 100644 --- a/library/text.tcl +++ b/library/text.tcl @@ -3,7 +3,7 @@ # This file defines the default bindings for Tk text widgets and provides # procedures that help in implementing the bindings. # -# RCS: @(#) $Id: text.tcl,v 1.44 2009/10/25 13:47:16 dkf Exp $ +# RCS: @(#) $Id: text.tcl,v 1.45 2010/01/06 18:37:36 dkf Exp $ # # Copyright (c) 1992-1994 The Regents of the University of California. # Copyright (c) 1994-1997 Sun Microsystems, Inc. @@ -88,10 +88,10 @@ bind Text { bind Text { %W mark set insert @%x,%y } -bind Text { +bind Text <> { tk::TextSetCursor %W insert-1displayindices } -bind Text { +bind Text <> { tk::TextSetCursor %W insert+1displayindices } bind Text { @@ -100,10 +100,10 @@ bind Text { bind Text { tk::TextSetCursor %W [tk::TextUpDownLine %W 1] } -bind Text { +bind Text <> { tk::TextKeySelect %W [%W index {insert - 1displayindices}] } -bind Text { +bind Text <> { tk::TextKeySelect %W [%W index {insert + 1displayindices}] } bind Text { @@ -112,10 +112,10 @@ bind Text { bind Text { tk::TextKeySelect %W [tk::TextUpDownLine %W 1] } -bind Text { +bind Text <> { tk::TextSetCursor %W [tk::TextPrevPos %W insert tcl_startOfPreviousWord] } -bind Text { +bind Text <> { tk::TextSetCursor %W [tk::TextNextWord %W insert] } bind Text { @@ -124,10 +124,10 @@ bind Text { bind Text { tk::TextSetCursor %W [tk::TextNextPara %W insert] } -bind Text { +bind Text <> { tk::TextKeySelect %W [tk::TextPrevPos %W insert tcl_startOfPreviousWord] } -bind Text { +bind Text <> { tk::TextKeySelect %W [tk::TextNextWord %W insert] } bind Text { @@ -155,16 +155,16 @@ bind Text { %W xview scroll 1 page } -bind Text { +bind Text <> { tk::TextSetCursor %W {insert display linestart} } -bind Text { +bind Text <> { tk::TextKeySelect %W {insert display linestart} } -bind Text { +bind Text <> { tk::TextSetCursor %W {insert display lineend} } -bind Text { +bind Text <> { tk::TextKeySelect %W {insert display lineend} } bind Text { diff --git a/library/tk.tcl b/library/tk.tcl index d80feb0..c73d110 100644 --- a/library/tk.tcl +++ b/library/tk.tcl @@ -3,7 +3,7 @@ # Initialization script normally executed in the interpreter for each Tk-based # application. Arranges class bindings for widgets. # -# RCS: @(#) $Id: tk.tcl,v 1.89 2010/01/04 01:36:14 patthoyts Exp $ +# RCS: @(#) $Id: tk.tcl,v 1.90 2010/01/06 18:37:37 dkf Exp $ # # Copyright (c) 1992-1994 The Regents of the University of California. # Copyright (c) 1994-1996 Sun Microsystems, Inc. @@ -374,6 +374,19 @@ switch -exact -- [tk windowingsystem] { event add <> } + event add <> + event add <> + event add <> + event add <> + event add <> + event add <> + event add <> + event add <> + event add <> + event add <> + event add <> + event add <> + # Some OS's define a goofy (as in, not ) keysym that is # returned when the user presses . In order for tab # traversal to work, we have to add these keysyms to the PrevWindow @@ -401,6 +414,19 @@ switch -exact -- [tk windowingsystem] { event add <> event add <> event add <> + + event add <> + event add <> + event add <> + event add <> + event add <> + event add <> + event add <> + event add <> + event add <> + event add <> + event add <> + event add <> } "aqua" { event add <> @@ -411,6 +437,23 @@ switch -exact -- [tk windowingsystem] { event add <> event add <> event add <> + + # Official bindings + # See http://support.apple.com/kb/HT1343 + event add <> + event add <> + event add <> + event add <> + event add <> + event add <> + event add <> + event add <> + event add <> + event add <> + # Not official, but logical extensions of above. Also derived from + # bindings present in MS Word on OSX. + event add <> + event add <> } } diff --git a/library/ttk/entry.tcl b/library/ttk/entry.tcl index d54328a..a3a81a3 100644 --- a/library/ttk/entry.tcl +++ b/library/ttk/entry.tcl @@ -1,5 +1,5 @@ # -# $Id: entry.tcl,v 1.6 2008/11/01 15:34:24 patthoyts Exp $ +# $Id: entry.tcl,v 1.7 2010/01/06 18:37:37 dkf Exp $ # # DERIVED FROM: tk/library/entry.tcl r1.22 # @@ -95,19 +95,19 @@ bind TEntry <> { ttk::entry::ScanRelease %W %x } ## Keyboard navigation bindings: # -bind TEntry { ttk::entry::Move %W prevchar } -bind TEntry { ttk::entry::Move %W nextchar } -bind TEntry { ttk::entry::Move %W prevword } -bind TEntry { ttk::entry::Move %W nextword } -bind TEntry { ttk::entry::Move %W home } -bind TEntry { ttk::entry::Move %W end } - -bind TEntry { ttk::entry::Extend %W prevchar } -bind TEntry { ttk::entry::Extend %W nextchar } -bind TEntry { ttk::entry::Extend %W prevword } -bind TEntry { ttk::entry::Extend %W nextword } -bind TEntry { ttk::entry::Extend %W home } -bind TEntry { ttk::entry::Extend %W end } +bind TEntry <> { ttk::entry::Move %W prevchar } +bind TEntry <> { ttk::entry::Move %W nextchar } +bind TEntry <> { ttk::entry::Move %W prevword } +bind TEntry <> { ttk::entry::Move %W nextword } +bind TEntry <> { ttk::entry::Move %W home } +bind TEntry <> { ttk::entry::Move %W end } + +bind TEntry <> { ttk::entry::Extend %W prevchar } +bind TEntry <> { ttk::entry::Extend %W nextchar } +bind TEntry <> { ttk::entry::Extend %W prevword } +bind TEntry <> { ttk::entry::Extend %W nextword } +bind TEntry <> { ttk::entry::Extend %W home } +bind TEntry <> { ttk::entry::Extend %W end } bind TEntry { %W selection range 0 end } bind TEntry { %W selection clear } -- cgit v0.12