summaryrefslogtreecommitdiffstats
path: root/library/entry.tcl
diff options
context:
space:
mode:
Diffstat (limited to 'library/entry.tcl')
-rw-r--r--library/entry.tcl36
1 files changed, 24 insertions, 12 deletions
diff --git a/library/entry.tcl b/library/entry.tcl
index 1b817f4..e7141b1 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.5 1998/09/14 18:23:23 stanton Exp $
+# RCS: @(#) $Id: entry.tcl,v 1.6 1999/04/16 01:51:26 stanton Exp $
#
# Copyright (c) 1992-1994 The Regents of the University of California.
# Copyright (c) 1994-1997 Sun Microsystems, Inc.
@@ -32,16 +32,14 @@
# The code below creates the default class bindings for entries.
#-------------------------------------------------------------------------
bind Entry <<Cut>> {
- if {![catch {set data [string range [%W get] [%W index sel.first]\
- [expr {[%W index sel.last] - 1}]]}]} {
+ if {![catch {set data [tkEntryGetSelection %W]}]} {
clipboard clear -displayof %W
clipboard append -displayof %W $data
%W delete sel.first sel.last
}
}
bind Entry <<Copy>> {
- if {![catch {set data [string range [%W get] [%W index sel.first]\
- [expr {[%W index sel.last] - 1}]]}]} {
+ if {![catch {set data [tkEntryGetSelection %W]}]} {
clipboard clear -displayof %W
clipboard append -displayof %W $data
}
@@ -49,7 +47,7 @@ bind Entry <<Copy>> {
bind Entry <<Paste>> {
global tcl_platform
catch {
- if {"$tcl_platform(platform)" != "unix"} {
+ if {[string compare $tcl_platform(platform) "unix"]} {
catch {
%W delete sel.first sel.last
}
@@ -201,13 +199,13 @@ bind Entry <Escape> {# nothing}
bind Entry <Return> {# nothing}
bind Entry <KP_Enter> {# nothing}
bind Entry <Tab> {# nothing}
-if {$tcl_platform(platform) == "macintosh"} {
+if {![string compare $tcl_platform(platform) "macintosh"]} {
bind Entry <Command-KeyPress> {# nothing}
}
# On Windows, paste is done using Shift-Insert. Shift-Insert already
# generates the <<Paste>> event, so we don't need to do anything here.
-if {$tcl_platform(platform) != "windows"} {
+if {[string compare $tcl_platform(platform) "windows"]} {
bind Entry <Insert> {
catch {tkEntryInsert %W [selection get -displayof %W]}
}
@@ -335,7 +333,7 @@ proc tkEntryButton1 {w x} {
set tkPriv(pressX) $x
$w icursor [tkEntryClosestGap $w $x]
$w selection from insert
- if {[lindex [$w configure -state] 4] == "normal"} {focus $w}
+ if {![string compare [$w cget -state] "normal"]} {focus $w}
}
# tkEntryMouseSelect --
@@ -405,7 +403,7 @@ proc tkEntryPaste {w x} {
$w icursor [tkEntryClosestGap $w $x]
catch {$w insert insert [selection get -displayof $w]}
- if {[lindex [$w configure -state] 4] == "normal"} {focus $w}
+ if {![string compare [$w cget -state] "normal"]} {focus $w}
}
# tkEntryAutoScan --
@@ -462,7 +460,7 @@ proc tkEntryKeySelect {w new} {
# s - The string to insert (usually just a single character)
proc tkEntryInsert {w s} {
- if {$s == ""} {
+ if {![string compare $s ""]} {
return
}
catch {
@@ -570,7 +568,7 @@ proc tkEntryTranspose w {
# w - The entry window in which the cursor is to move.
# start - Position at which to start search.
-if {$tcl_platform(platform) == "windows"} {
+if {![string compare $tcl_platform(platform) "windows"]} {
proc tkEntryNextWord {w start} {
set pos [tcl_endOfWord [$w get] [$w index $start]]
if {$pos >= 0} {
@@ -607,4 +605,18 @@ proc tkEntryPreviousWord {w start} {
}
return $pos
}
+# tkEntryGetSelection --
+#
+# Returns the selected text of the entry with respect to the -show option.
+#
+# Arguments:
+# w - The entry window from which the text to get
+proc tkEntryGetSelection {w} {
+ set entryString [string range [$w get] [$w index sel.first] \
+ [expr [$w index sel.last] - 1]]
+ if {[$w cget -show] != ""} {
+ regsub -all . $entryString [string index [$w cget -show] 0] entryString
+ }
+ return $entryString
+}