# text.tcl -- # # This file defines the default bindings for Tk text widgets and provides # procedures that help in implementing the bindings. # # @(#) text.tcl 1.36 95/06/28 10:24:23 # # Copyright (c) 1992-1994 The Regents of the University of California. # Copyright (c) 1994-1995 Sun Microsystems, Inc. # # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # #------------------------------------------------------------------------- # Elements of tkPriv that are used in this file: # # afterId - If non-null, it means that auto-scanning is underway # and it gives the "after" id for the next auto-scan # command to be executed. # char - Character position on the line; kept in order # to allow moving up or down past short lines while # still remembering the desired position. # mouseMoved - Non-zero means the mouse has moved a significant # amount since the button went down (so, for example, # start dragging out a selection). # prevPos - Used when moving up or down lines via the keyboard. # Keeps track of the previous insert position, so # we can distinguish a series of ups and downs, all # in a row, from a new up or down. # selectMode - The style of selection currently underway: # char, word, or line. # x, y - Last known mouse coordinates for scanning # and auto-scanning. #------------------------------------------------------------------------- # tkTextClipboardKeysyms -- # This procedure is invoked to identify the keys that correspond to # the "copy", "cut", and "paste" functions for the clipboard. # # Arguments: # copy - Name of the key (keysym name plus modifiers, if any, # such as "Meta-y") used for the copy operation. # cut - Name of the key used for the cut operation. # paste - Name of the key used for the paste operation. proc tkTextClipboardKeysyms {copy cut paste} { bind Text <$copy> { if {[selection own -displayof %W] == "%W"} { clipboard clear -displayof %W catch { clipboard append -displayof %W [selection get -displayof %W] } } } bind Text <$cut> { if {[selection own -displayof %W] == "%W"} { clipboard clear -displayof %W catch { clipboard append -displayof %W [selection get -displayof %W] %W delete sel.first sel.last } } } bind Text <$paste> { catch { %W insert insert [selection get -displayof %W \ -selection CLIPBOARD] } } } #------------------------------------------------------------------------- # The code below creates the default class bindings for entries. #------------------------------------------------------------------------- # Standard Motif bindings: bind Text <1> { tkTextButton1 %W %x %y %W tag remove sel 0.0 end } bind Text { set tkPriv(x) %x set tkPriv(y) %y tkTextSelectTo %W %x %y } bind Text { set tkPriv(selectMode) word tkTextSelectTo %W %x %y catch {%W mark set insert sel.first} } bind Text { set tkPriv(selectMode) line tkTextSelectTo %W %x %y catch {%W mark set insert sel.first} } bind Text { tkTextResetAnchor %W @%x,%y set tkPriv(selectMode) char tkTextSelectTo %W %x %y } bind Text { set tkPriv(selectMode) word tkTextSelectTo %W %x %y } bind Text { set tkPriv(selectMode) line tkTextSelectTo %W %x %y } bind Text { set tkPriv(x) %x set tkPriv(y) %y tkTextAutoScan %W } bind Text { tkCancelRepeat } bind Text { tkCancelRepeat } bind Text { %W mark set insert @%x,%y } bind Text { tkTextSetCursor %W [%W index {insert - 1c}] } bind Text { tkTextSetCursor %W [%W index {insert + 1c}] } bind Text { tkTextSetCursor %W [tkTextUpDownLine %W -1] } bind Text { tkTextSetCursor %W [tkTextUpDownLine %W 1] } bind Text { tkTextKeySelect %W [%W index {insert - 1c}] } bind Text { tkTextKeySelect %W [%W index {insert + 1c}] } bind Text { tkTextKeySelect %W [tkTextUpDownLine %W -1] } bind Text { tkTextKeySelect %W [tkTextUpDownLine %W 1] } bind Text { tkTextSetCursor %W [%W index {insert - 1c wordstart}] } bind Text { tkTextSetCursor %W [%W index {insert wordend}] } bind Text { tkTextSetCursor %W [tkTextPrevPara %W insert] } bind Text { tkTextSetCursor %W [tkTextNextPara %W insert] } bind Text { tkTextKeySelect %W [%W index {insert - 1c wordstart}] } bind Text { tkTextKeySelect %W [%W index {insert wordend}] } bind Text { tkTextKeySelect %W [tkTextPrevPara %W insert] } bind Text { tkTextKeySelect %W [tkTextNextPara %W insert] } bind Text { tkTextSetCursor %W [tkTextScrollPages %W -1] } bind Text { tkTextKeySelect %W [tkTextScrollPages %W -1] } bind Text { tkTextSetCursor %W [tkTextScrollPages %W 1] } bind Text { tkTextKeySelect %W [tkTextScrollPages %W 1] } bind Text { %W xview scroll -1 page } bind Text { %W xview scroll 1 page } bind Text { tkTextSetCursor %W {insert linestart} } bind Text { tkTextKeySelect %W {insert linestart} } bind Text { tkTextSetCursor %W {insert lineend} } bind Text { tkTextKeySelect %W {insert lineend} } bind Text { tkTextSetCursor %W 1.0 } bind Text { tkTextKeySelect %W 1.0 } bind Text { tkTextSetCursor %W {end - 1 char} } bind Text { tkTextKeySelect %W {end - 1 char} } bind Text { tkTextInsert %W \t focus %W break } bind Text { # Needed only to keep binding from triggering; doesn't # have to actually do anything. } bind Text { focus [tk_focusNext %W] } bind Text { focus [tk_focusPrev %W] } bind Text { tkTextInsert %W \t } bind Text { tkTextInsert %W \n } bind Text { if {[%W tag nextrange sel 1.0 end] != ""} { %W delete sel.first sel.last } else { %W delete insert %W see insert } } bind Text { if {[%W tag nextrange sel 1.0 end] != ""} { %W delete sel.first sel.last } elseif [%W compare insert != 1.0] { %W delete insert-1c %W see insert } } bind Text { %W mark set anchor insert } bind Text