diff options
author | stanton <stanton> | 1999-04-06 03:52:49 (GMT) |
---|---|---|
committer | stanton <stanton> | 1999-04-06 03:52:49 (GMT) |
commit | ce7df6c3cbc816bab020960e8faafbf9187c001f (patch) | |
tree | 8e90eb77e8cc8409b82552aae23c9844046025ae | |
parent | f994e133a8532bc0300ce4895078893a583ea9ca (diff) | |
download | tk-ce7df6c3cbc816bab020960e8faafbf9187c001f.zip tk-ce7df6c3cbc816bab020960e8faafbf9187c001f.tar.gz tk-ce7df6c3cbc816bab020960e8faafbf9187c001f.tar.bz2 |
* library/bgerror.tcl:
* library/button.tcl:
* library/clrpick.tcl:
* library/console.tcl:
* library/dialog.tcl:
* library/entry.tcl:
* library/focus.tcl:
* library/listbox.tcl:
* library/menu.tcl:
* library/msgbox.tcl:
* library/palette.tcl:
* library/scale.tcl:
* library/scrlbar.tcl:
* library/tearoff.tcl:
* library/text.tcl:
* library/tk.tcl: Lots of minor performance improvements
contributed by Jeffrey Hobbs. [Bug: 1118]
-rw-r--r-- | library/bgerror.tcl | 6 | ||||
-rw-r--r-- | library/button.tcl | 70 | ||||
-rw-r--r-- | library/clrpick.tcl | 8 | ||||
-rw-r--r-- | library/console.tcl | 48 | ||||
-rw-r--r-- | library/dialog.tcl | 28 | ||||
-rw-r--r-- | library/entry.tcl | 17 | ||||
-rw-r--r-- | library/focus.tcl | 35 | ||||
-rw-r--r-- | library/listbox.tcl | 36 | ||||
-rw-r--r-- | library/menu.tcl | 248 | ||||
-rw-r--r-- | library/msgbox.tcl | 46 | ||||
-rw-r--r-- | library/palette.tcl | 17 | ||||
-rw-r--r-- | library/scale.tcl | 32 | ||||
-rw-r--r-- | library/scrlbar.tcl | 43 | ||||
-rw-r--r-- | library/tearoff.tcl | 23 | ||||
-rw-r--r-- | library/text.tcl | 47 | ||||
-rw-r--r-- | library/tk.tcl | 56 |
16 files changed, 386 insertions, 374 deletions
diff --git a/library/bgerror.tcl b/library/bgerror.tcl index e16b682..2f66eb8 100644 --- a/library/bgerror.tcl +++ b/library/bgerror.tcl @@ -4,7 +4,7 @@ # posts a dialog box with the error message and gives the user a chance # to see a more detailed stack trace. # -# RCS: @(#) $Id: bgerror.tcl,v 1.1.4.3 1999/01/29 00:34:33 stanton Exp $ +# RCS: @(#) $Id: bgerror.tcl,v 1.1.4.4 1999/04/06 03:52:49 stanton Exp $ # # Copyright (c) 1992-1994 The Regents of the University of California. # Copyright (c) 1994-1996 Sun Microsystems, Inc. @@ -62,7 +62,7 @@ proc bgerror err { wm title $w "Stack Trace for Error" wm iconname $w "Stack Trace" button $w.ok -text OK -command "destroy $w" -default active - if {$tcl_platform(platform) == "macintosh"} { + if {![string compare $tcl_platform(platform) "macintosh"]} { text $w.text -relief flat -bd 2 -highlightthickness 0 -setgrid true \ -yscrollcommand "$w.scroll set" -width 60 -height 20 } else { @@ -94,7 +94,7 @@ proc bgerror err { # screen, since they could make it impossible for the user # to interact with the stack trace. - if {[grab current .] != ""} { + if {[string compare [grab current .] ""]} { grab release [grab current .] } } diff --git a/library/button.tcl b/library/button.tcl index 9f63c52..fd2c9b6 100644 --- a/library/button.tcl +++ b/library/button.tcl @@ -4,7 +4,7 @@ # checkbutton, and radiobutton widgets and provides procedures # that help in implementing those bindings. # -# RCS: @(#) $Id: button.tcl,v 1.1.4.2 1998/09/30 02:17:30 stanton Exp $ +# RCS: @(#) $Id: button.tcl,v 1.1.4.3 1999/04/06 03:52:50 stanton Exp $ # # Copyright (c) 1992-1994 The Regents of the University of California. # Copyright (c) 1994-1996 Sun Microsystems, Inc. @@ -17,7 +17,7 @@ # The code below creates the default class bindings for buttons. #------------------------------------------------------------------------- -if {$tcl_platform(platform) == "macintosh"} { +if {[string match "macintosh" $tcl_platform(platform)]} { bind Radiobutton <Enter> { tkButtonEnter %W } @@ -37,7 +37,7 @@ if {$tcl_platform(platform) == "macintosh"} { tkButtonUp %W } } -if {$tcl_platform(platform) == "windows"} { +if {[string match "windows" $tcl_platform(platform)]} { bind Checkbutton <equal> { tkCheckRadioInvoke %W select } @@ -67,7 +67,7 @@ if {$tcl_platform(platform) == "windows"} { tkCheckRadioEnter %W } } -if {$tcl_platform(platform) == "unix"} { +if {[string match "unix" $tcl_platform(platform)]} { bind Checkbutton <Return> { if {!$tk_strictMotif} { tkCheckRadioInvoke %W @@ -126,7 +126,7 @@ bind Radiobutton <Leave> { tkButtonLeave %W } -if {$tcl_platform(platform) == "windows"} { +if {[string match "windows" $tcl_platform(platform)]} { ######################### # Windows implementation @@ -142,8 +142,8 @@ if {$tcl_platform(platform) == "windows"} { proc tkButtonEnter w { global tkPriv - if {[$w cget -state] != "disabled"} { - if {$tkPriv(buttonWindow) == $w} { + if {[string compare [$w cget -state] "disabled"]} { + if {![string compare $tkPriv(buttonWindow) $w]} { $w configure -state active -relief sunken } } @@ -162,10 +162,10 @@ proc tkButtonEnter w { proc tkButtonLeave w { global tkPriv - if {[$w cget -state] != "disabled"} { + if {[string compare [$w cget -state] "disabled"]} { $w config -state normal } - if {$w == $tkPriv(buttonWindow)} { + if {![string compare $tkPriv(buttonWindow) $w]} { $w configure -relief $tkPriv(relief) } set tkPriv(window) "" @@ -182,8 +182,8 @@ proc tkButtonLeave w { proc tkCheckRadioEnter w { global tkPriv - if {[$w cget -state] != "disabled"} { - if {$tkPriv(buttonWindow) == $w} { + if {[string compare [$w cget -state] "disabled"]} { + if {![string compare $tkPriv(buttonWindow) $w]} { $w configure -state active } } @@ -202,7 +202,7 @@ proc tkCheckRadioEnter w { proc tkButtonDown w { global tkPriv set tkPriv(relief) [lindex [$w conf -relief] 4] - if {[$w cget -state] != "disabled"} { + if {[string compare [$w cget -state] "disabled"]} { set tkPriv(buttonWindow) $w $w config -relief sunken -state active } @@ -220,7 +220,7 @@ proc tkButtonDown w { proc tkCheckRadioDown w { global tkPriv set tkPriv(relief) [lindex [$w conf -relief] 4] - if {[$w cget -state] != "disabled"} { + if {[string compare [$w cget -state] "disabled"]} { set tkPriv(buttonWindow) $w $w config -state active } @@ -236,10 +236,10 @@ proc tkCheckRadioDown w { proc tkButtonUp w { global tkPriv - if {$w == $tkPriv(buttonWindow)} { + if {![string compare $tkPriv(buttonWindow) $w]} { set tkPriv(buttonWindow) "" - if {($w == $tkPriv(window)) - && ([$w cget -state] != "disabled")} { + if {![string compare $tkPriv(window) $w] + && [string compare [$w cget -state] "disabled"]} { $w config -relief $tkPriv(relief) -state normal uplevel #0 [list $w invoke] } @@ -248,7 +248,7 @@ proc tkButtonUp w { } -if {$tcl_platform(platform) == "unix"} { +if {[string match "unix" $tcl_platform(platform)]} { ##################### # Unix implementation @@ -264,9 +264,9 @@ if {$tcl_platform(platform) == "unix"} { proc tkButtonEnter {w} { global tkPriv - if {[$w cget -state] != "disabled"} { + if {[string compare [$w cget -state] "disabled"]} { $w config -state active - if {$tkPriv(buttonWindow) == $w} { + if {![string compare $tkPriv(buttonWindow) $w]} { $w configure -state active -relief sunken } } @@ -285,10 +285,10 @@ proc tkButtonEnter {w} { proc tkButtonLeave w { global tkPriv - if {[$w cget -state] != "disabled"} { + if {[string compare [$w cget -state] "disabled"]} { $w config -state normal } - if {$w == $tkPriv(buttonWindow)} { + if {![string compare $tkPriv(buttonWindow) $w]} { $w configure -relief $tkPriv(relief) } set tkPriv(window) "" @@ -306,7 +306,7 @@ proc tkButtonLeave w { proc tkButtonDown w { global tkPriv set tkPriv(relief) [lindex [$w config -relief] 4] - if {[$w cget -state] != "disabled"} { + if {[string compare [$w cget -state] "disabled"]} { set tkPriv(buttonWindow) $w $w config -relief sunken } @@ -322,11 +322,11 @@ proc tkButtonDown w { proc tkButtonUp w { global tkPriv - if {$w == $tkPriv(buttonWindow)} { + if {![string compare $w $tkPriv(buttonWindow)]} { set tkPriv(buttonWindow) "" $w config -relief $tkPriv(relief) - if {($w == $tkPriv(window)) - && ([$w cget -state] != "disabled")} { + if {![string compare $w $tkPriv(window)] + && [string compare [$w cget -state] "disabled"]} { uplevel #0 [list $w invoke] } } @@ -334,7 +334,7 @@ proc tkButtonUp w { } -if {$tcl_platform(platform) == "macintosh"} { +if {[string match "macintosh" $tcl_platform(platform)]} { #################### # Mac implementation @@ -350,8 +350,8 @@ if {$tcl_platform(platform) == "macintosh"} { proc tkButtonEnter {w} { global tkPriv - if {[$w cget -state] != "disabled"} { - if {$tkPriv(buttonWindow) == $w} { + if {[string compare [$w cget -state] "disabled"]} { + if {![string compare $w $tkPriv(buttonWindow)]} { $w configure -state active } } @@ -370,7 +370,7 @@ proc tkButtonEnter {w} { proc tkButtonLeave w { global tkPriv - if {$w == $tkPriv(buttonWindow)} { + if {![string compare $w $tkPriv(buttonWindow)]} { $w configure -state normal } set tkPriv(window) "" @@ -387,7 +387,7 @@ proc tkButtonLeave w { proc tkButtonDown w { global tkPriv - if {[$w cget -state] != "disabled"} { + if {[string compare [$w cget -state] "disabled"]} { set tkPriv(buttonWindow) $w $w config -state active } @@ -403,11 +403,11 @@ proc tkButtonDown w { proc tkButtonUp w { global tkPriv - if {$w == $tkPriv(buttonWindow)} { + if {![string compare $w $tkPriv(buttonWindow)]} { $w config -state normal set tkPriv(buttonWindow) "" - if {($w == $tkPriv(window)) - && ([$w cget -state] != "disabled")} { + if {![string compare $w $tkPriv(window)] + && [string compare [$w cget -state] "disabled"]} { uplevel #0 [list $w invoke] } } @@ -427,7 +427,7 @@ proc tkButtonUp w { # w - The name of the widget. proc tkButtonInvoke w { - if {[$w cget -state] != "disabled"} { + if {[string compare [$w cget -state] "disabled"]} { set oldRelief [$w cget -relief] set oldState [$w cget -state] $w configure -state active -relief sunken @@ -449,7 +449,7 @@ proc tkButtonInvoke w { # cmd - The subcommand to invoke (one of invoke, select, or deselect). proc tkCheckRadioInvoke {w {cmd invoke}} { - if {[$w cget -state] != "disabled"} { + if {[string compare [$w cget -state] "disabled"]} { uplevel #0 [list $w $cmd] } } diff --git a/library/clrpick.tcl b/library/clrpick.tcl index 2250713..b383e2a 100644 --- a/library/clrpick.tcl +++ b/library/clrpick.tcl @@ -3,7 +3,7 @@ # Color selection dialog for platforms that do not support a # standard color selection dialog. # -# RCS: @(#) $Id: clrpick.tcl,v 1.1.4.2 1998/09/30 02:17:30 stanton Exp $ +# RCS: @(#) $Id: clrpick.tcl,v 1.1.4.3 1999/04/06 03:52:51 stanton Exp $ # # Copyright (c) 1996 Sun Microsystems, Inc. # @@ -84,7 +84,7 @@ proc tkColorDialog {args} { set oldFocus [focus] set oldGrab [grab current $w] - if {$oldGrab != ""} { + if {[string compare $oldGrab ""]} { set grabStatus [grab status $oldGrab] } grab $w @@ -101,8 +101,8 @@ proc tkColorDialog {args} { grab release $w destroy $w unset data - if {$oldGrab != ""} { - if {$grabStatus == "global"} { + if {[string compare $oldGrab ""]} { + if {![string compare $grabStatus "global"]} { grab -global $oldGrab } else { grab $oldGrab diff --git a/library/console.tcl b/library/console.tcl index 12e5ecf..500e56b 100644 --- a/library/console.tcl +++ b/library/console.tcl @@ -4,7 +4,7 @@ # can be used by non-unix systems that do not have built-in support # for shells. # -# RCS: @(#) $Id: console.tcl,v 1.1.4.2 1998/09/30 02:17:31 stanton Exp $ +# RCS: @(#) $Id: console.tcl,v 1.1.4.3 1999/04/06 03:52:51 stanton Exp $ # # Copyright (c) 1995-1997 Sun Microsystems, Inc. # @@ -23,14 +23,14 @@ proc tkConsoleInit {} { global tcl_platform - if {! [consoleinterp eval {set tcl_interactive}]} { + if {![consoleinterp eval {set tcl_interactive}]} { wm withdraw . } - if {"$tcl_platform(platform)" == "macintosh"} { - set mod "Cmd" - } else { + if {[string compare $tcl_platform(platform) "macintosh"]} { set mod "Ctrl" + } else { + set mod "Cmd" } menu .menubar @@ -42,10 +42,10 @@ proc tkConsoleInit {} { -command tkConsoleSource .menubar.file add command -label "Hide Console" -underline 0 \ -command {wm withdraw .} - if {"$tcl_platform(platform)" == "macintosh"} { - .menubar.file add command -label "Quit" -command exit -accel Cmd-Q - } else { + if {[string compare $tcl_platform(platform) "macintosh"]} { .menubar.file add command -label "Exit" -underline 1 -command exit + } else { + .menubar.file add command -label "Quit" -command exit -accel Cmd-Q } menu .menubar.edit -tearoff 0 @@ -56,7 +56,10 @@ proc tkConsoleInit {} { .menubar.edit add command -label "Paste" -underline 1 \ -command { event generate .console <<Paste>> } -accel "$mod+V" - if {"$tcl_platform(platform)" == "windows"} { + if {[string compare $tcl_platform(platform) "windows"]} { + .menubar.edit add command -label "Clear" -underline 2 \ + -command { event generate .console <<Clear>> } + } else { .menubar.edit add command -label "Delete" -underline 0 \ -command { event generate .console <<Clear>> } -accel "Del" @@ -64,9 +67,6 @@ proc tkConsoleInit {} { menu .menubar.help -tearoff 0 .menubar.help add command -label "About..." -underline 0 \ -command tkConsoleAbout - } else { - .menubar.edit add command -label "Clear" -underline 2 \ - -command { event generate .console <<Clear>> } } . conf -menu .menubar @@ -75,7 +75,7 @@ proc tkConsoleInit {} { scrollbar .sb -command ".console yview" pack .sb -side right -fill both pack .console -fill both -expand 1 -side left - if {$tcl_platform(platform) == "macintosh"} { + if {![string compare $tcl_platform(platform) "macintosh"]} { .console configure -font {Monaco 9 normal} -highlightthickness 0 } @@ -106,7 +106,7 @@ proc tkConsoleSource {} { set filename [tk_getOpenFile -defaultextension .tcl -parent . \ -title "Select a file to source" \ -filetypes {{"Tcl Scripts" .tcl} {"All Files" *}}] - if {"$filename" != ""} { + if {[string compare $filename ""]} { set cmd [list source $filename] if {[catch {consoleinterp eval $cmd} result]} { tkConsoleOutput stderr "$result\n" @@ -125,22 +125,22 @@ proc tkConsoleSource {} { proc tkConsoleInvoke {args} { set ranges [.console tag ranges input] set cmd "" - if {$ranges != ""} { + if {[llength $ranges]} { set pos 0 - while {[lindex $ranges $pos] != ""} { + while {[string compare [lindex $ranges $pos] ""]} { set start [lindex $ranges $pos] set end [lindex $ranges [incr pos]] append cmd [.console get $start $end] incr pos } } - if {$cmd == ""} { + if {![string compare $cmd ""]} { tkConsolePrompt } elseif {[info complete $cmd]} { .console mark set output end .console tag delete input set result [consoleinterp record $cmd] - if {$result != ""} { + if {[string compare $result ""]} { puts $result } tkConsoleHistory reset @@ -189,7 +189,7 @@ proc tkConsoleHistory {cmd} { } else { set cmd "history event $histNum" } - if {$cmd != ""} { + if {[string compare $cmd ""]} { catch {consoleinterp eval $cmd} cmd } .console delete promptEnd end @@ -210,7 +210,7 @@ proc tkConsoleHistory {cmd} { # partial - Flag to specify which prompt to print. proc tkConsolePrompt {{partial normal}} { - if {$partial == "normal"} { + if {![string compare $partial "normal"]} { set temp [.console index "end - 1 char"] .console mark set output end if {[consoleinterp eval "info exists tcl_prompt1"]} { @@ -268,7 +268,7 @@ proc tkConsoleBind {win} { break } bind $win <Delete> { - if {[%W tag nextrange sel 1.0 end] != ""} { + if {[string compare [%W tag nextrange sel 1.0 end] ""]} { %W tag remove sel sel.first promptEnd } else { if {[%W compare insert < promptEnd]} { @@ -277,7 +277,7 @@ proc tkConsoleBind {win} { } } bind $win <BackSpace> { - if {[%W tag nextrange sel 1.0 end] != ""} { + if {[string compare [%W tag nextrange sel 1.0 end] ""]} { %W tag remove sel sel.first promptEnd } else { if {[%W compare insert <= promptEnd]} { @@ -368,7 +368,7 @@ proc tkConsoleBind {win} { } bind $win <F9> { eval destroy [winfo child .] - if {$tcl_platform(platform) == "macintosh"} { + if {![string compare $tcl_platform(platform) "macintosh"]} { source -rsrc Console } else { source [file join $tk_library console.tcl] @@ -416,7 +416,7 @@ proc tkConsoleBind {win} { # s - The string to insert (usually just a single character) proc tkConsoleInsert {w s} { - if {$s == ""} { + if {![string compare $s ""]} { return } catch { diff --git a/library/dialog.tcl b/library/dialog.tcl index e3115bb..4170e09 100644 --- a/library/dialog.tcl +++ b/library/dialog.tcl @@ -3,7 +3,7 @@ # This file defines the procedure tk_dialog, which creates a dialog # box containing a bitmap, a message, and one or more buttons. # -# RCS: @(#) $Id: dialog.tcl,v 1.1.4.2 1998/09/30 02:17:32 stanton Exp $ +# RCS: @(#) $Id: dialog.tcl,v 1.1.4.3 1999/04/06 03:52:52 stanton Exp $ # # Copyright (c) 1992-1993 The Regents of the University of California. # Copyright (c) 1994-1997 Sun Microsystems, Inc. @@ -47,13 +47,13 @@ proc tk_dialog {w title text bitmap default args} { # even though its grab keeps the rest of the application from being used. wm transient $w [winfo toplevel [winfo parent $w]] - if {$tcl_platform(platform) == "macintosh"} { + if {![string compare $tcl_platform(platform) "macintosh"]} { unsupported1 style $w dBoxProc } frame $w.bot frame $w.top - if {$tcl_platform(platform) == "unix"} { + if {![string compare $tcl_platform(platform) "unix"]} { $w.bot configure -relief raised -bd 1 $w.top configure -relief raised -bd 1 } @@ -65,7 +65,7 @@ proc tk_dialog {w title text bitmap default args} { # overridden by the caller). option add *Dialog.msg.wrapLength 3i widgetDefault - if {$tcl_platform(platform) == "macintosh"} { + if {![string compare $tcl_platform(platform) "macintosh"]} { option add *Dialog.msg.font system widgetDefault } else { option add *Dialog.msg.font {Times 18} widgetDefault @@ -73,8 +73,8 @@ proc tk_dialog {w title text bitmap default args} { label $w.msg -justify left -text $text pack $w.msg -in $w.top -side right -expand 1 -fill both -padx 3m -pady 3m - if {$bitmap != ""} { - if {($tcl_platform(platform) == "macintosh") && ($bitmap == "error")} { + if {[string compare $bitmap ""]} { + if {![string compare $tcl_platform(platform) "macintosh"] && ![string compare $bitmap "error"]} { set bitmap "stop" } label $w.bitmap -bitmap $bitmap @@ -94,9 +94,9 @@ proc tk_dialog {w title text bitmap default args} { grid $w.button$i -in $w.bot -column $i -row 0 -sticky ew -padx 10 grid columnconfigure $w.bot $i # We boost the size of some Mac buttons for l&f - if {$tcl_platform(platform) == "macintosh"} { + if {![string compare $tcl_platform(platform) "macintosh"]} { set tmp [string tolower $but] - if {($tmp == "ok") || ($tmp == "cancel")} { + if {![string compare $tmp "ok"] || ![string compare $tmp "cancel"]} { grid columnconfigure $w.bot $i -minsize [expr 59 + 20] } } @@ -108,7 +108,7 @@ proc tk_dialog {w title text bitmap default args} { if {$default >= 0} { bind $w <Return> " - $w.button$default configure -state active -relief sunken + [list $w.button$default] configure -state active -relief sunken update idletasks after 100 set tkPriv(button) $default @@ -138,7 +138,7 @@ proc tk_dialog {w title text bitmap default args} { set oldFocus [focus] set oldGrab [grab current $w] - if {$oldGrab != ""} { + if {[string compare $oldGrab ""]} { set grabStatus [grab status $oldGrab] } grab $w @@ -164,11 +164,11 @@ proc tk_dialog {w title text bitmap default args} { bind $w <Destroy> {} destroy $w } - if {$oldGrab != ""} { - if {$grabStatus == "global"} { - grab -global $oldGrab - } else { + if {[string compare $oldGrab ""]} { + if {[string compare $grabStatus "global"]} { grab $oldGrab + } else { + grab -global $oldGrab } } return $tkPriv(button) diff --git a/library/entry.tcl b/library/entry.tcl index 5c6ff70..3ff0d19 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.1.4.3 1999/04/06 03:01:17 stanton Exp $ +# RCS: @(#) $Id: entry.tcl,v 1.1.4.4 1999/04/06 03:52:53 stanton Exp $ # # Copyright (c) 1992-1994 The Regents of the University of California. # Copyright (c) 1994-1997 Sun Microsystems, Inc. @@ -47,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 } @@ -199,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]} } @@ -333,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 -- @@ -403,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 -- @@ -460,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 { @@ -568,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} { @@ -605,7 +605,6 @@ proc tkEntryPreviousWord {w start} { } return $pos } - # tkEntryGetSelection -- # # Returns the selected text of the entry with respect to the -show option. diff --git a/library/focus.tcl b/library/focus.tcl index f45094d..3fbd53e 100644 --- a/library/focus.tcl +++ b/library/focus.tcl @@ -3,7 +3,7 @@ # This file defines several procedures for managing the input # focus. # -# RCS: @(#) $Id: focus.tcl,v 1.1.4.2 1998/09/30 02:17:33 stanton Exp $ +# RCS: @(#) $Id: focus.tcl,v 1.1.4.3 1999/04/06 03:52:54 stanton Exp $ # # Copyright (c) 1994-1995 Sun Microsystems, Inc. # @@ -38,7 +38,7 @@ proc tk_focusNext w { incr i if {$i < [llength $children]} { set cur [lindex $children $i] - if {[winfo toplevel $cur] == $cur} { + if {![string compare [winfo toplevel $cur] $cur]} { continue } else { break @@ -50,14 +50,14 @@ proc tk_focusNext w { # look for its next sibling. set cur $parent - if {[winfo toplevel $cur] == $cur} { + if {![string compare [winfo toplevel $cur] $cur]} { break } set parent [winfo parent $parent] set children [winfo children $parent] set i [lsearch -exact $children $cur] } - if {($cur == $w) || [tkFocusOK $cur]} { + if {![string compare $w $cur] || [tkFocusOK $cur]} { return $cur } } @@ -81,8 +81,8 @@ proc tk_focusPrev w { # Collect information about the current window's position # among its siblings. Also, if the window is a top-level, # then reposition to just after the last child of the window. - - if {[winfo toplevel $cur] == $cur} { + + if {![string compare [winfo toplevel $cur] $cur]} { set parent $cur set children [winfo children $cur] set i [llength $children] @@ -100,7 +100,7 @@ proc tk_focusPrev w { while {$i > 0} { incr i -1 set cur [lindex $children $i] - if {[winfo toplevel $cur] == $cur} { + if {![string compare [winfo toplevel $cur] $cur]} { continue } set parent $cur @@ -108,7 +108,7 @@ proc tk_focusPrev w { set i [llength $children] } set cur $parent - if {($cur == $w) || [tkFocusOK $cur]} { + if {![string compare $w $cur] || [tkFocusOK $cur]} { return $cur } } @@ -130,14 +130,14 @@ proc tk_focusPrev w { proc tkFocusOK w { set code [catch {$w cget -takefocus} value] - if {($code == 0) && ($value != "")} { + if {($code == 0) && [string compare $value ""]} { if {$value == 0} { return 0 } elseif {$value == 1} { return [winfo viewable $w] } else { set value [uplevel #0 $value $w] - if {$value != ""} { + if {[string compare $value ""]} { return $value } } @@ -146,7 +146,7 @@ proc tkFocusOK w { return 0 } set code [catch {$w cget -state} value] - if {($code == 0) && ($value == "disabled")} { + if {($code == 0) && ![string compare $value "disabled"]} { return 0 } regexp Key|Focus "[bind $w] [bind [winfo class $w]]" @@ -165,14 +165,15 @@ proc tkFocusOK w { proc tk_focusFollowsMouse {} { set old [bind all <Enter>] set script { - if {("%d" == "NotifyAncestor") || ("%d" == "NotifyNonlinear") - || ("%d" == "NotifyInferior")} { - if {[tkFocusOK %W]} { - focus %W - } + if {![string compare "%d" "NotifyAncestor"] + || ![string compare "%d" "NotifyNonlinear"] + || ![string compare "%d" "NotifyInferior"]} { + if {[tkFocusOK %W]} { + focus %W + } } } - if {$old != ""} { + if {[string compare $old ""]} { bind all <Enter> "$old; $script" } else { bind all <Enter> $script diff --git a/library/listbox.tcl b/library/listbox.tcl index c19afdc..1e9a31e 100644 --- a/library/listbox.tcl +++ b/library/listbox.tcl @@ -3,7 +3,7 @@ # This file defines the default bindings for Tk listbox widgets # and provides procedures that help in implementing those bindings. # -# RCS: @(#) $Id: listbox.tcl,v 1.1.4.3 1998/11/25 21:16:33 stanton Exp $ +# RCS: @(#) $Id: listbox.tcl,v 1.1.4.4 1999/04/06 03:52:54 stanton Exp $ # # Copyright (c) 1994 The Regents of the University of California. # Copyright (c) 1994-1995 Sun Microsystems, Inc. @@ -120,6 +120,7 @@ bind Listbox <Control-Home> { %W see 0 %W selection clear 0 end %W selection set 0 + event generate %W <<ListboxSelect>> } bind Listbox <Shift-Control-Home> { tkListboxDataExtend %W 0 @@ -129,12 +130,13 @@ bind Listbox <Control-End> { %W see end %W selection clear 0 end %W selection set end + event generate %W <<ListboxSelect>> } bind Listbox <Shift-Control-End> { tkListboxDataExtend %W [%W index end] } bind Listbox <<Copy>> { - if {[selection own -displayof %W] == "%W"} { + if {![string compare [selection own -displayof %W] "%W"]} { clipboard clear -displayof %W clipboard append -displayof %W [selection get -displayof %W] } @@ -158,8 +160,9 @@ bind Listbox <Control-slash> { tkListboxSelectAll %W } bind Listbox <Control-backslash> { - if {[%W cget -selectmode] != "browse"} { + if {[string compare [%W cget -selectmode] "browse"]} { %W selection clear 0 end + event generate %W <<ListboxSelect>> } } @@ -177,7 +180,7 @@ bind Listbox <B2-Motion> { # on other platforms. bind Listbox <MouseWheel> { - %W yview scroll [expr - (%D / 120) * 4] units + %W yview scroll [expr {- (%D / 120) * 4}] units } # tkListboxBeginSelect -- @@ -194,7 +197,7 @@ bind Listbox <MouseWheel> { proc tkListboxBeginSelect {w el} { global tkPriv - if {[$w cget -selectmode] == "multiple"} { + if {![string compare [$w cget -selectmode] "multiple"]} { if {[$w selection includes $el]} { $w selection clear $el } else { @@ -207,6 +210,7 @@ proc tkListboxBeginSelect {w el} { set tkPriv(listboxSelection) {} set tkPriv(listboxPrev) $el } + event generate $w <<ListboxSelect>> } # tkListboxMotion -- @@ -230,6 +234,7 @@ proc tkListboxMotion {w el} { $w selection clear 0 end $w selection set $el set tkPriv(listboxPrev) $el + event generate $w <<ListboxSelect>> } extended { set i $tkPriv(listboxPrev) @@ -253,6 +258,7 @@ proc tkListboxMotion {w el} { incr i -1 } set tkPriv(listboxPrev) $el + event generate $w <<ListboxSelect>> } } } @@ -270,12 +276,11 @@ proc tkListboxMotion {w el} { # one under the pointer). Must be in numerical form. proc tkListboxBeginExtend {w el} { - if {[$w cget -selectmode] == "extended"} { + if {![string compare [$w cget -selectmode] "extended"]} { if {[$w selection includes anchor]} { tkListboxMotion $w $el } else { # No selection yet; simulate the begin-select operation. - tkListboxBeginSelect $w $el } } @@ -295,7 +300,7 @@ proc tkListboxBeginExtend {w el} { proc tkListboxBeginToggle {w el} { global tkPriv - if {[$w cget -selectmode] == "extended"} { + if {![string compare [$w cget -selectmode] "extended"]} { set tkPriv(listboxSelection) [$w curselection] set tkPriv(listboxPrev) $el $w selection anchor $el @@ -304,6 +309,7 @@ proc tkListboxBeginToggle {w el} { } else { $w selection set $el } + event generate $w <<ListboxSelect>> } } @@ -355,6 +361,7 @@ proc tkListboxUpDown {w amount} { browse { $w selection clear 0 end $w selection set active + event generate $w <<ListboxSelect>> } extended { $w selection clear 0 end @@ -362,6 +369,7 @@ proc tkListboxUpDown {w amount} { $w selection anchor active set tkPriv(listboxPrev) [$w index active] set tkPriv(listboxSelection) {} + event generate $w <<ListboxSelect>> } } } @@ -377,7 +385,7 @@ proc tkListboxUpDown {w amount} { # amount - +1 to move down one item, -1 to move back one item. proc tkListboxExtendUpDown {w amount} { - if {[$w cget -selectmode] != "extended"} { + if {[string compare [$w cget -selectmode] "extended"]} { return } $w activate [expr {[$w index active] + $amount}] @@ -398,13 +406,13 @@ proc tkListboxExtendUpDown {w amount} { proc tkListboxDataExtend {w el} { set mode [$w cget -selectmode] - if {$mode == "extended"} { + if {![string compare $mode "extended"]} { $w activate $el $w see $el if {[$w selection includes anchor]} { tkListboxMotion $w $el } - } elseif {$mode == "multiple"} { + } elseif {![string compare $mode "multiple"]} { $w activate $el $w see $el } @@ -422,7 +430,7 @@ proc tkListboxDataExtend {w el} { proc tkListboxCancel w { global tkPriv - if {[$w cget -selectmode] != "extended"} { + if {[string compare [$w cget -selectmode] "extended"]} { return } set first [$w index anchor] @@ -439,6 +447,7 @@ proc tkListboxCancel w { } incr first } + event generate $w <<ListboxSelect>> } # tkListboxSelectAll @@ -452,10 +461,11 @@ proc tkListboxCancel w { proc tkListboxSelectAll w { set mode [$w cget -selectmode] - if {($mode == "single") || ($mode == "browse")} { + if {![string compare $mode "single"] || ![string compare $mode "browse"]} { $w selection clear 0 end $w selection set active } else { $w selection set 0 end } + event generate $w <<ListboxSelect>> } diff --git a/library/menu.tcl b/library/menu.tcl index 7cb8292..0ba6ad0 100644 --- a/library/menu.tcl +++ b/library/menu.tcl @@ -4,7 +4,7 @@ # It also implements keyboard traversal of menus and implements a few # other utility procedures related to menus. # -# RCS: @(#) $Id: menu.tcl,v 1.1.4.5 1999/03/26 20:01:25 surles Exp $ +# RCS: @(#) $Id: menu.tcl,v 1.1.4.6 1999/04/06 03:52:55 stanton Exp $ # # Copyright (c) 1992-1994 The Regents of the University of California. # Copyright (c) 1994-1997 Sun Microsystems, Inc. @@ -90,7 +90,7 @@ bind Menubutton <Leave> { tkMbLeave %W } bind Menubutton <1> { - if {$tkPriv(inMenubutton) != ""} { + if {[string compare $tkPriv(inMenubutton) ""]} { tkMbPost $tkPriv(inMenubutton) %X %Y } } @@ -119,9 +119,9 @@ bind Menu <FocusIn> {} bind Menu <Enter> { set tkPriv(window) %W - if {[%W cget -type] == "tearoff"} { - if {"%m" != "NotifyUngrab"} { - if {$tcl_platform(platform) == "unix"} { + if {![string compare [%W cget -type] "tearoff"]} { + if {[string compare "%m" "NotifyUngrab"]} { + if {![string compare $tcl_platform(platform) "unix"]} { tk_menuSetFocus %W } } @@ -169,7 +169,7 @@ bind Menu <KeyPress> { # The following bindings apply to all windows, and are used to # implement keyboard menu traversal. -if {$tcl_platform(platform) == "unix"} { +if {![string compare $tcl_platform(platform) "unix"]} { bind all <Alt-KeyPress> { tkTraverseToMenu %W %A } @@ -199,11 +199,11 @@ if {$tcl_platform(platform) == "unix"} { proc tkMbEnter w { global tkPriv - if {$tkPriv(inMenubutton) != ""} { + if {[string compare $tkPriv(inMenubutton) ""]} { tkMbLeave $tkPriv(inMenubutton) } set tkPriv(inMenubutton) $w - if {[$w cget -state] != "disabled"} { + if {[string compare [$w cget -state] "disabled"]} { $w configure -state active } } @@ -222,7 +222,7 @@ proc tkMbLeave w { if {![winfo exists $w]} { return } - if {[$w cget -state] == "active"} { + if {![string compare [$w cget -state] "active"]} { $w configure -state normal } } @@ -243,20 +243,21 @@ proc tkMbPost {w {x {}} {y {}}} { global tkPriv errorInfo global tcl_platform - if {([$w cget -state] == "disabled") || ($w == $tkPriv(postedMb))} { + if {![string compare [$w cget -state] "disabled"] || + ![string compare $w $tkPriv(postedMb)]} { return } set menu [$w cget -menu] - if {$menu == ""} { + if {![string compare $menu ""]} { return } - set tearoff [expr {($tcl_platform(platform) == "unix") \ - || ([$menu cget -type] == "tearoff")}] + set tearoff [expr {![string compare $tcl_platform(platform) "unix"] \ + || ![string compare [$menu cget -type] "tearoff"]}] if {[string first $w $menu] != 0} { error "can't post $menu: it isn't a descendant of $w (this is a new requirement in Tk versions 3.0 and later)" } set cur $tkPriv(postedMb) - if {$cur != ""} { + if {[string compare $cur ""]} { tkMenuUnpost {} } set tkPriv(cursor) [$w cget -cursor] @@ -300,7 +301,7 @@ proc tkMbPost {w {x {}} {y {}}} { } } $menu post $x $y - if {($entry != {}) && ([$menu entrycget $entry -state] != "disabled")} { + if {[string compare $entry {}] && [string compare [$menu entrycget $entry -state] "disabled"]} { $menu activate $entry tkGenerateMenuSelect $menu } @@ -319,14 +320,14 @@ proc tkMbPost {w {x {}} {y {}}} { } } $menu post $x $y - if {($entry != {}) && ([$menu entrycget $entry -state] != "disabled")} { + if {[string compare $entry {}] && [string compare [$menu entrycget $entry -state] "disabled"]} { $menu activate $entry tkGenerateMenuSelect $menu } } default { if {[$w cget -indicatoron]} { - if {$y == ""} { + if {![string compare $y {}]} { set x [expr {[winfo rootx $w] + [winfo width $w]/2}] set y [expr {[winfo rooty $w] + [winfo height $w]/2}] } @@ -386,17 +387,17 @@ proc tkMenuUnpost menu { # what was posted. catch { - if {$mb != ""} { + if {[string compare $mb ""]} { set menu [$mb cget -menu] $menu unpost set tkPriv(postedMb) {} $mb configure -cursor $tkPriv(cursor) $mb configure -relief $tkPriv(relief) - } elseif {$tkPriv(popup) != ""} { + } elseif {[string compare $tkPriv(popup) ""]} { $tkPriv(popup) unpost set tkPriv(popup) {} - } elseif {(!([$menu cget -type] == "menubar") - && !([$menu cget -type] == "tearoff"))} { + } elseif {[string compare [$menu cget -type] "menubar"] + && [string compare [$menu cget -type] "tearoff"]} { # We're in a cascaded sub-menu from a torn-off menu or popup. # Unpost all the menus up to the toplevel one (but not # including the top-level torn-off one) and deactivate the @@ -404,7 +405,7 @@ proc tkMenuUnpost menu { while 1 { set parent [winfo parent $menu] - if {([winfo class $parent] != "Menu") + if {[string compare [winfo class $parent] "Menu"] || ![winfo ismapped $parent]} { break } @@ -412,33 +413,33 @@ proc tkMenuUnpost menu { $parent postcascade none tkGenerateMenuSelect $parent set type [$parent cget -type] - if {($type == "menubar")|| ($type == "tearoff")} { + if {![string compare $type "menubar"] || + ![string compare $type "tearoff"]} { break } set menu $parent } - if {[$menu cget -type] != "menubar"} { + if {[string compare [$menu cget -type] "menubar"]} { $menu unpost } } } - if {($tkPriv(tearoff) != 0) || ($tkPriv(menuBar) != "")} { + if {($tkPriv(tearoff) != 0) || [string compare $tkPriv(menuBar) ""]} { # Release grab, if any, and restore the previous grab, if there # was one. - - if {$menu != ""} { + if {[string compare $menu ""]} { set grab [grab current $menu] - if {$grab != ""} { + if {[string compare $grab ""]} { grab release $grab } } tkRestoreOldGrab - if {$tkPriv(menuBar) != ""} { + if {[string compare $tkPriv(menuBar) ""]} { $tkPriv(menuBar) configure -cursor $tkPriv(cursor) set tkPriv(menuBar) {} } - if {$tcl_platform(platform) != "unix"} { + if {[string compare $tcl_platform(platform) "unix"]} { set tkPriv(tearoff) 0 } } @@ -458,19 +459,21 @@ proc tkMenuUnpost menu { proc tkMbMotion {w upDown rootx rooty} { global tkPriv - if {$tkPriv(inMenubutton) == $w} { + if {![string compare $tkPriv(inMenubutton) $w]} { return } set new [winfo containing $rootx $rooty] - if {($new != $tkPriv(inMenubutton)) && (($new == "") - || ([winfo toplevel $new] == [winfo toplevel $w]))} { - if {$tkPriv(inMenubutton) != ""} { + if {[string compare $new $tkPriv(inMenubutton)] + && (![string compare $new ""] + || ![string compare [winfo toplevel $new] [winfo toplevel $w]])} { + if {[string compare $tkPriv(inMenubutton) ""]} { tkMbLeave $tkPriv(inMenubutton) } - if {($new != "") && ([winfo class $new] == "Menubutton") + if {[string compare $new ""] + && ![string compare [winfo class $new] "Menubutton"] && ([$new cget -indicatoron] == 0) && ([$w cget -indicatoron] == 0)} { - if {$upDown == "down"} { + if {![string compare $upDown "down"]} { tkMbPost $new $rootx $rooty } else { tkMbEnter $new @@ -517,10 +520,10 @@ proc tkMbButtonUp w { proc tkMenuMotion {menu x y state} { global tkPriv - if {$menu == $tkPriv(window)} { - if {[$menu cget -type] == "menubar"} { + if {![string compare $menu $tkPriv(window)]} { + if {![string compare [$menu cget -type] "menubar"]} { if {[info exists tkPriv(focus)] && \ - ([string compare $menu $tkPriv(focus)] != 0)} { + [string compare $menu $tkPriv(focus)]} { $menu activate @$x,$y tkGenerateMenuSelect $menu } @@ -553,16 +556,16 @@ proc tkMenuButtonDown menu { global tkPriv global tcl_platform $menu postcascade active - if {$tkPriv(postedMb) != ""} { + if {[string compare $tkPriv(postedMb) ""]} { grab -global $tkPriv(postedMb) } else { - while {([$menu cget -type] == "normal") - && ([winfo class [winfo parent $menu]] == "Menu") + while {![string compare [$menu cget -type] "normal"] + && ![string compare [winfo class [winfo parent $menu]] "Menu"] && [winfo ismapped [winfo parent $menu]]} { set menu [winfo parent $menu] } - if {$tkPriv(menuBar) == {}} { + if {![string compare $tkPriv(menuBar) {}]} { set tkPriv(menuBar) $menu set tkPriv(cursor) [$menu cget -cursor] $menu configure -cursor arrow @@ -573,14 +576,14 @@ proc tkMenuButtonDown menu { # restore the grab, since the old grab window will not be viewable # anymore. - if {$menu != [grab current $menu]} { + if {[string compare $menu [grab current $menu]]} { tkSaveGrabInfo $menu } # Must re-grab even if the grab window hasn't changed, in order # to release the implicit grab from the button press. - if {$tcl_platform(platform) == "unix"} { + if {![string compare $tcl_platform(platform) "unix"]} { grab -global $menu } } @@ -599,12 +602,12 @@ proc tkMenuButtonDown menu { proc tkMenuLeave {menu rootx rooty state} { global tkPriv set tkPriv(window) {} - if {[$menu index active] == "none"} { + if {![string compare [$menu index active] "none"]} { return } - if {([$menu type active] == "cascade") - && ([winfo containing $rootx $rooty] - == [$menu entrycget active -menu])} { + if {![string compare [$menu type active] "cascade"] + && ![string compare [winfo containing $rootx $rooty] \ + [$menu entrycget active -menu]]} { return } $menu activate none @@ -624,7 +627,7 @@ proc tkMenuLeave {menu rootx rooty state} { proc tkMenuInvoke {w buttonRelease} { global tkPriv - if {$buttonRelease && ($tkPriv(window) == "")} { + if {$buttonRelease && ![string compare $tkPriv(window) {}]} { # Mouse was pressed over a menu without a menu button, then # dragged off the menu (possibly with a cascade posted) and # released. Unpost everything and quit. @@ -635,14 +638,14 @@ proc tkMenuInvoke {w buttonRelease} { tkMenuUnpost $w return } - if {[$w type active] == "cascade"} { + if {![string compare [$w type active] "cascade"]} { $w postcascade active set menu [$w entrycget active -menu] tkMenuFirstEntry $menu - } elseif {[$w type active] == "tearoff"} { + } elseif {![string compare [$w type active] "tearoff"]} { tkMenuUnpost $w tkTearOffMenu $w - } elseif {[$w cget -type] == "menubar"} { + } elseif {![string compare [$w cget -type] "menubar"]} { $w postcascade none $w activate none event generate $w <<MenuSelect>> @@ -663,9 +666,9 @@ proc tkMenuInvoke {w buttonRelease} { proc tkMenuEscape menu { set parent [winfo parent $menu] - if {([winfo class $parent] != "Menu")} { + if {[string compare [winfo class $parent] "Menu"]} { tkMenuUnpost $menu - } elseif {([$parent cget -type] == "menubar")} { + } elseif {![string compare [$parent cget -type] "menubar"]} { tkMenuUnpost $menu tkRestoreOldGrab } else { @@ -677,7 +680,7 @@ proc tkMenuEscape menu { # differently depending on whether the menu is a menu bar or not. proc tkMenuUpArrow {menu} { - if {[$menu cget -type] == "menubar"} { + if {![string compare [$menu cget -type] "menubar"]} { tkMenuNextMenu $menu left } else { tkMenuNextEntry $menu -1 @@ -685,7 +688,7 @@ proc tkMenuUpArrow {menu} { } proc tkMenuDownArrow {menu} { - if {[$menu cget -type] == "menubar"} { + if {![string compare [$menu cget -type] "menubar"]} { tkMenuNextMenu $menu right } else { tkMenuNextEntry $menu 1 @@ -693,7 +696,7 @@ proc tkMenuDownArrow {menu} { } proc tkMenuLeftArrow {menu} { - if {[$menu cget -type] == "menubar"} { + if {![string compare [$menu cget -type] "menubar"]} { tkMenuNextEntry $menu -1 } else { tkMenuNextMenu $menu left @@ -701,7 +704,7 @@ proc tkMenuLeftArrow {menu} { } proc tkMenuRightArrow {menu} { - if {[$menu cget -type] == "menubar"} { + if {![string compare [$menu cget -type] "menubar"]} { tkMenuNextEntry $menu 1 } else { tkMenuNextMenu $menu right @@ -723,22 +726,22 @@ proc tkMenuNextMenu {menu direction} { # First handle traversals into and out of cascaded menus. - if {$direction == "right"} { + if {![string compare $direction "right"]} { set count 1 set parent [winfo parent $menu] set class [winfo class $parent] - if {[$menu type active] == "cascade"} { + if {![string compare [$menu type active] "cascade"]} { $menu postcascade active set m2 [$menu entrycget active -menu] - if {$m2 != ""} { + if {[string compare $m2 ""]} { tkMenuFirstEntry $m2 } return } else { set parent [winfo parent $menu] - while {($parent != ".")} { - if {([winfo class $parent] == "Menu") - && ([$parent cget -type] == "menubar")} { + while {[string compare $parent "."]} { + if {![string compare [winfo class $parent] "Menu"] + && ![string compare [$parent cget -type] "menubar"]} { tk_menuSetFocus $parent tkMenuNextEntry $parent 1 return @@ -749,8 +752,8 @@ proc tkMenuNextMenu {menu direction} { } else { set count -1 set m2 [winfo parent $menu] - if {[winfo class $m2] == "Menu"} { - if {[$m2 cget -type] != "menubar"} { + if {![string compare [winfo class $m2] "Menu"]} { + if {[string compare [$m2 cget -type] "menubar"]} { $menu activate none tkGenerateMenuSelect $menu tk_menuSetFocus $m2 @@ -769,8 +772,8 @@ proc tkMenuNextMenu {menu direction} { # or previous menubutton, if that makes sense. set m2 [winfo parent $menu] - if {[winfo class $m2] == "Menu"} { - if {[$m2 cget -type] == "menubar"} { + if {![string compare [winfo class $m2] "Menu"]} { + if {![string compare [$m2 cget -type] "menubar"]} { tk_menuSetFocus $m2 tkMenuNextEntry $m2 -1 return @@ -778,7 +781,7 @@ proc tkMenuNextMenu {menu direction} { } set w $tkPriv(postedMb) - if {$w == ""} { + if {![string compare $w ""]} { return } set buttons [winfo children [winfo parent $w]] @@ -792,13 +795,13 @@ proc tkMenuNextMenu {menu direction} { incr i -$length } set mb [lindex $buttons $i] - if {([winfo class $mb] == "Menubutton") - && ([$mb cget -state] != "disabled") - && ([$mb cget -menu] != "") - && ([[$mb cget -menu] index last] != "none")} { + if {![string compare [winfo class $mb] "Menubutton"] + && [string compare [$mb cget -state] "disabled"] + && [string compare [$mb cget -menu] ""] + && [string compare [[$mb cget -menu] index last] "none"]} { break } - if {$mb == $w} { + if {![string compare $mb $w]} { return } incr i $count @@ -819,13 +822,13 @@ proc tkMenuNextMenu {menu direction} { proc tkMenuNextEntry {menu count} { global tkPriv - if {[$menu index last] == "none"} { + if {![string compare [$menu index last] "none"]} { return } set length [expr {[$menu index last]+1}] set quitAfter $length set active [$menu index active] - if {$active == "none"} { + if {![string compare $active "none"]} { set i 0 } else { set i [expr {$active + $count}] @@ -856,9 +859,9 @@ proc tkMenuNextEntry {menu count} { } $menu activate $i tkGenerateMenuSelect $menu - if {[$menu type $i] == "cascade"} { + if {![string compare [$menu type $i] "cascade"]} { set cascade [$menu entrycget $i -menu] - if {[string compare $cascade ""] != 0} { + if {[string compare $cascade ""]} { $menu postcascade $i tkMenuFirstEntry $cascade } @@ -893,20 +896,20 @@ proc tkMenuFind {w char} { } switch [winfo class $child] { Menu { - if {[$child cget -type] == "menubar"} { - if {$char == ""} { + if {![string compare [$child cget -type] "menubar"]} { + if {![string compare $char ""]} { return $child } set last [$child index last] for {set i [$child cget -tearoff]} {$i <= $last} {incr i} { - if {[$child type $i] == "separator"} { + if {![string compare [$child type $i] "separator"]} { continue } set char2 [string index [$child entrycget $i -label] \ [$child entrycget $i -underline]] - if {([string compare $char [string tolower $char2]] \ - == 0) || ($char == "")} { - if {[$child entrycget $i -state] != "disabled"} { + if {![string compare $char [string tolower $char2]] \ + || ![string compare $char ""]} { + if {[string compare [$child entrycget $i -state] "disabled"]} { return $child } } @@ -925,9 +928,9 @@ proc tkMenuFind {w char} { Menubutton { set char2 [string index [$child cget -text] \ [$child cget -underline]] - if {([string compare $char [string tolower $char2]] == 0) - || ($char == "")} { - if {[$child cget -state] != "disabled"} { + if {![string compare $char [string tolower $char2]] + || ![string compare $char ""]} { + if {[string compare [$child cget $i -state] "disabled"]} { return $child } } @@ -935,7 +938,7 @@ proc tkMenuFind {w char} { default { set match [tkMenuFind $child $char] - if {$match != ""} { + if {[string compare $match ""]} { return $match } } @@ -958,21 +961,22 @@ proc tkMenuFind {w char} { proc tkTraverseToMenu {w char} { global tkPriv - if {$char == ""} { + if {![string compare $char ""]} { return } - while {[winfo class $w] == "Menu"} { - if {([$w cget -type] != "menubar") && ($tkPriv(postedMb) == "")} { + while {![string compare [winfo class $w] "Menu"]} { + if {[string compare [$w cget -type] "menubar"] + && ![string compare $tkPriv(postedMb) ""]} { return } - if {[$w cget -type] == "menubar"} { + if {![string compare [$w cget -type] "menubar"]} { break } set w [winfo parent $w] } set w [tkMenuFind [winfo toplevel $w] $char] - if {$w != ""} { - if {[winfo class $w] == "Menu"} { + if {[string compare $w ""]} { + if {![string compare [winfo class $w] "Menu"]} { tk_menuSetFocus $w set tkPriv(window) $w tkSaveGrabInfo $w @@ -995,8 +999,8 @@ proc tkTraverseToMenu {w char} { proc tkFirstMenu w { set w [tkMenuFind [winfo toplevel $w] ""] - if {$w != ""} { - if {[winfo class $w] == "Menu"} { + if {[string compare $w ""]} { + if {![string compare [winfo class $w] "Menu"]} { tk_menuSetFocus $w set tkPriv(window) $w tkSaveGrabInfo $w @@ -1021,12 +1025,12 @@ proc tkFirstMenu w { # nothing happens. proc tkTraverseWithinMenu {w char} { - if {$char == ""} { + if {![string compare $char ""]} { return } set char [string tolower $char] set last [$w index last] - if {$last == "none"} { + if {![string compare $last "none"]} { return } for {set i 0} {$i <= $last} {incr i} { @@ -1035,13 +1039,13 @@ proc tkTraverseWithinMenu {w char} { [$w entrycget $i -underline]]}]} { continue } - if {[string compare $char [string tolower $char2]] == 0} { - if {[$w type $i] == "cascade"} { + if {![string compare $char [string tolower $char2]]} { + if {![string compare [$w type $i] "cascade"]} { $w activate $i $w postcascade active event generate $w <<MenuSelect>> set m2 [$w entrycget $i -menu] - if {$m2 != ""} { + if {[string compare $m2 ""]} { tkMenuFirstEntry $m2 } } else { @@ -1065,25 +1069,26 @@ proc tkTraverseWithinMenu {w char} { # menu - Name of the menu window (possibly empty). proc tkMenuFirstEntry menu { - if {$menu == ""} { + if {![string compare $menu ""]} { return } tk_menuSetFocus $menu - if {[$menu index active] != "none"} { + if {[string compare [$menu index active] "none"]} { return } set last [$menu index last] - if {$last == "none"} { + if {![string compare $last "none"]} { return } for {set i 0} {$i <= $last} {incr i} { if {([catch {set state [$menu entrycget $i -state]}] == 0) - && ($state != "disabled") && ([$menu type $i] != "tearoff")} { + && [string compare $state "disabled"] + && [string compare [$menu type $i] "tearoff"]} { $menu activate $i tkGenerateMenuSelect $menu - if {[$menu type $i] == "cascade"} { + if {![string compare [$menu type $i] "cascade"]} { set cascade [$menu entrycget $i -menu] - if {[string compare $cascade ""] != 0} { + if {[string compare $cascade ""]} { $menu postcascade $i tkMenuFirstEntry $cascade } @@ -1111,12 +1116,12 @@ proc tkMenuFindName {menu s} { return $i } set last [$menu index last] - if {$last == "none"} { + if {![string compare $last "none"]} { return } for {set i 0} {$i <= $last} {incr i} { if {![catch {$menu entrycget $i -label} label]} { - if {$label == $s} { + if {![string compare $label $s]} { return $i } } @@ -1139,7 +1144,7 @@ proc tkMenuFindName {menu s} { proc tkPostOverPoint {menu x y {entry {}}} { global tcl_platform - if {$entry != {}} { + if {[string compare $entry {}]} { if {$entry == [$menu index last]} { incr y [expr {-([$menu yposition $entry] \ + [winfo reqheight $menu])/2}] @@ -1150,7 +1155,8 @@ proc tkPostOverPoint {menu x y {entry {}}} { incr x [expr {-[winfo reqwidth $menu]/2}] } $menu post $x $y - if {($entry != {}) && ([$menu entrycget $entry -state] != "disabled")} { + if {[string compare $entry {}] + && [string compare [$menu entrycget $entry -state] "disabled"]} { $menu activate $entry tkGenerateMenuSelect $menu } @@ -1167,7 +1173,7 @@ proc tkPostOverPoint {menu x y {entry {}}} { proc tkSaveGrabInfo w { global tkPriv set tkPriv(oldGrab) [grab current $w] - if {$tkPriv(oldGrab) != ""} { + if {[string compare $tkPriv(oldGrab) ""]} { set tkPriv(grabStatus) [grab status $tkPriv(oldGrab)] } } @@ -1179,13 +1185,13 @@ proc tkSaveGrabInfo w { proc tkRestoreOldGrab {} { global tkPriv - if {$tkPriv(oldGrab) != ""} { + if {[string compare $tkPriv(oldGrab) ""]} { # Be careful restoring the old grab, since it's window may not # be visible anymore. catch { - if {$tkPriv(grabStatus) == "global"} { + if {![string compare $tkPriv(grabStatus) "global"]} { grab set -global $tkPriv(oldGrab) } else { grab set $tkPriv(oldGrab) @@ -1197,7 +1203,7 @@ proc tkRestoreOldGrab {} { proc tk_menuSetFocus {menu} { global tkPriv - if {![info exists tkPriv(focus)] || [string length $tkPriv(focus)] == 0} { + if {![info exists tkPriv(focus)] || ![string compare $tkPriv(focus) {}]} { set tkPriv(focus) [focus] } focus $menu @@ -1206,9 +1212,8 @@ proc tk_menuSetFocus {menu} { proc tkGenerateMenuSelect {menu} { global tkPriv - if {([string compare $tkPriv(activeMenu) $menu] == 0) \ - && ([string compare $tkPriv(activeItem) [$menu index active]] \ - == 0)} { + if {![string compare $tkPriv(activeMenu) $menu] \ + && ![string compare $tkPriv(activeItem) [$menu index active]]} { return } @@ -1232,11 +1237,12 @@ proc tkGenerateMenuSelect {menu} { proc tk_popup {menu x y {entry {}}} { global tkPriv global tcl_platform - if {($tkPriv(popup) != "") || ($tkPriv(postedMb) != "")} { + if {[string compare $tkPriv(popup) ""] + || [string compare $tkPriv(postedMb) ""]} { tkMenuUnpost {} } tkPostOverPoint $menu $x $y $entry - if {$tcl_platform(platform) == "unix"} { + if {![string compare $tcl_platform(platform) "unix"]} { tkSaveGrabInfo $menu grab -global $menu set tkPriv(popup) $menu diff --git a/library/msgbox.tcl b/library/msgbox.tcl index 257c7d3..d693a0d 100644 --- a/library/msgbox.tcl +++ b/library/msgbox.tcl @@ -3,7 +3,7 @@ # Implements messageboxes for platforms that do not have native # messagebox support. # -# RCS: @(#) $Id: msgbox.tcl,v 1.1.4.3 1998/11/25 21:16:33 stanton Exp $ +# RCS: @(#) $Id: msgbox.tcl,v 1.1.4.4 1999/04/06 03:52:56 stanton Exp $ # # Copyright (c) 1994-1997 Sun Microsystems, Inc. # @@ -51,13 +51,11 @@ proc tkMessageBox {args} { if {[lsearch {info warning error question} $data(-icon)] == -1} { error "bad -icon value \"$data(-icon)\": must be error, info, question, or warning" } - if {$tcl_platform(platform) == "macintosh"} { - if {$data(-icon) == "error"} { - set data(-icon) "stop" - } elseif {$data(-icon) == "warning"} { - set data(-icon) "caution" - } elseif {$data(-icon) == "info"} { - set data(-icon) "note" + if {![string compare $tcl_platform(platform) "macintosh"]} { + switch -- $data(-icon) { + "error" {set data(-icon) "stop"} + "warning" {set data(-icon) "caution"} + "info" {set data(-icon) "note"} } } @@ -77,7 +75,7 @@ proc tkMessageBox {args} { set buttons { {ok -width 6 -text OK -under 0} } - if {$data(-default) == ""} { + if {![string compare $data(-default) ""]} { set data(-default) "ok" } } @@ -142,7 +140,7 @@ proc tkMessageBox {args} { wm iconname $w Dialog wm protocol $w WM_DELETE_WINDOW { } wm transient $w $data(-parent) - if {$tcl_platform(platform) == "macintosh"} { + if {![string compare $tcl_platform(platform) "macintosh"]} { unsupported1 style $w dBoxProc } @@ -150,7 +148,7 @@ proc tkMessageBox {args} { pack $w.bot -side bottom -fill both frame $w.top pack $w.top -side top -fill both -expand 1 - if {$tcl_platform(platform) != "macintosh"} { + if {[string compare $tcl_platform(platform) "macintosh"]} { $w.bot configure -relief raised -bd 1 $w.top configure -relief raised -bd 1 } @@ -160,7 +158,7 @@ proc tkMessageBox {args} { # overridden by the caller). option add *Dialog.msg.wrapLength 3i widgetDefault - if {$tcl_platform(platform) == "macintosh"} { + if {![string compare $tcl_platform(platform) "macintosh"]} { option add *Dialog.msg.font system widgetDefault } else { option add *Dialog.msg.font {Times 18} widgetDefault @@ -168,7 +166,7 @@ proc tkMessageBox {args} { label $w.msg -justify left -text $data(-message) pack $w.msg -in $w.top -side right -expand 1 -fill both -padx 3m -pady 3m - if {$data(-icon) != ""} { + if {[string compare $data(-icon) ""]} { label $w.bitmap -bitmap $data(-icon) pack $w.bitmap -in $w.top -side left -padx 3m -pady 3m } @@ -179,29 +177,27 @@ proc tkMessageBox {args} { foreach but $buttons { set name [lindex $but 0] set opts [lrange $but 1 end] - if {![string compare $opts {}]} { + if {![llength $opts]} { # Capitalize the first letter of $name - set capName \ - [string toupper \ + set capName [string toupper \ [string index $name 0]][string range $name 1 end] set opts [list -text $capName] } - eval button $w.$name $opts -command [list "set tkPriv(button) $name"] + eval button [list $w.$name] $opts [list -command [list set tkPriv(button) $name]] if {![string compare $name $data(-default)]} { $w.$name configure -default active } - pack $w.$name -in $w.bot -side left -expand 1 \ - -padx 3m -pady 2m + pack $w.$name -in $w.bot -side left -expand 1 -padx 3m -pady 2m # create the binding for the key accelerator, based on the underline # set underIdx [$w.$name cget -under] if {$underIdx >= 0} { set key [string index [$w.$name cget -text] $underIdx] - bind $w <Alt-[string tolower $key]> "$w.$name invoke" - bind $w <Alt-[string toupper $key]> "$w.$name invoke" + bind $w <Alt-[string tolower $key]> [list $w.$name invoke] + bind $w <Alt-[string toupper $key]> [list $w.$name invoke] } incr i } @@ -210,7 +206,7 @@ proc tkMessageBox {args} { # default button. if {[string compare $data(-default) ""]} { - bind $w <Return> "tkButtonInvoke $w.$data(-default)" + bind $w <Return> [list tkButtonInvoke $w.$data(-default)] } # 7. Withdraw the window, then update all the geometry information @@ -230,7 +226,7 @@ proc tkMessageBox {args} { set oldFocus [focus] set oldGrab [grab current $w] - if {$oldGrab != ""} { + if {[string compare $oldGrab ""]} { set grabStatus [grab status $oldGrab] } grab $w @@ -249,8 +245,8 @@ proc tkMessageBox {args} { tkwait variable tkPriv(button) catch {focus $oldFocus} destroy $w - if {$oldGrab != ""} { - if {$grabStatus == "global"} { + if {[string compare $oldGrab ""]} { + if {![string compare $grabStatus "global"]} { grab -global $oldGrab } else { grab $oldGrab diff --git a/library/palette.tcl b/library/palette.tcl index 1afec13..8ddbe6d 100644 --- a/library/palette.tcl +++ b/library/palette.tcl @@ -3,7 +3,7 @@ # This file contains procedures that change the color palette used # by Tk. # -# RCS: @(#) $Id: palette.tcl,v 1.1.4.2 1998/09/30 02:17:35 stanton Exp $ +# RCS: @(#) $Id: palette.tcl,v 1.1.4.3 1999/04/06 03:52:57 stanton Exp $ # # Copyright (c) 1995-1997 Sun Microsystems, Inc. # @@ -187,23 +187,22 @@ proc tkRecolorTree {w colors} { # by 10%. proc tkDarken {color percent} { - set l [winfo rgb . $color] - set red [expr {[lindex $l 0]/256}] - set green [expr {[lindex $l 1]/256}] - set blue [expr {[lindex $l 2]/256}] - set red [expr {($red*$percent)/100}] + foreach {red green blue} [winfo rgb . $color] { + set red [expr {($red/256)*$percent/100}] + set green [expr {($green/256)*$percent/100}] + set blue [expr {($blue/256)*$percent/100}] + break + } if {$red > 255} { set red 255 } - set green [expr {($green*$percent)/100}] if {$green > 255} { set green 255 } - set blue [expr {($blue*$percent)/100}] if {$blue > 255} { set blue 255 } - format #%02x%02x%02x $red $green $blue + return [format "#%02x%02x%02x" $red $green $blue] } # tk_bisque -- diff --git a/library/scale.tcl b/library/scale.tcl index 759662d..06bfb8e 100644 --- a/library/scale.tcl +++ b/library/scale.tcl @@ -3,7 +3,7 @@ # This file defines the default bindings for Tk scale widgets and provides # procedures that help in implementing the bindings. # -# RCS: @(#) $Id: scale.tcl,v 1.1.4.2 1998/09/30 02:17:36 stanton Exp $ +# RCS: @(#) $Id: scale.tcl,v 1.1.4.3 1999/04/06 03:52:57 stanton Exp $ # # Copyright (c) 1994 The Regents of the University of California. # Copyright (c) 1994-1995 Sun Microsystems, Inc. @@ -32,7 +32,7 @@ bind Scale <Leave> { if {$tk_strictMotif} { %W config -activebackground $tkPriv(activeBg) } - if {[%W cget -state] == "active"} { + if {![string compare [%W cget -state] "active"]} { %W configure -state normal } } @@ -107,10 +107,10 @@ bind Scale <End> { proc tkScaleActivate {w x y} { global tkPriv - if {[$w cget -state] == "disabled"} { - return; + if {![string compare [$w cget -state] "disabled"]} { + return } - if {[$w identify $x $y] == "slider"} { + if {![string compare [$w identify $x $y] "slider"]} { $w configure -state active } else { $w configure -state normal @@ -129,11 +129,11 @@ proc tkScaleButtonDown {w x y} { global tkPriv set tkPriv(dragging) 0 set el [$w identify $x $y] - if {$el == "trough1"} { + if {![string compare $el "trough1"]} { tkScaleIncrement $w up little initial - } elseif {$el == "trough2"} { + } elseif {![string compare $el "trough2"]} { tkScaleIncrement $w down little initial - } elseif {$el == "slider"} { + } elseif {![string compare $el "slider"]} { set tkPriv(dragging) 1 set tkPriv(initValue) [$w get] set coords [$w coords] @@ -194,7 +194,7 @@ proc tkScaleEndDrag {w} { proc tkScaleIncrement {w dir big repeat} { global tkPriv if {![winfo exists $w]} return - if {$big == "big"} { + if {![string compare $big "big"]} { set inc [$w cget -bigincrement] if {$inc == 0} { set inc [expr {abs([$w cget -to] - [$w cget -from])/10.0}] @@ -205,15 +205,15 @@ proc tkScaleIncrement {w dir big repeat} { } else { set inc [$w cget -resolution] } - if {([$w cget -from] > [$w cget -to]) ^ ($dir == "up")} { + if {([$w cget -from] > [$w cget -to]) ^ ![string compare $dir "up"]} { set inc [expr {-$inc}] } $w set [expr {[$w get] + $inc}] - if {$repeat == "again"} { + if {![string compare $repeat "again"]} { set tkPriv(afterId) [after [$w cget -repeatinterval] \ tkScaleIncrement $w $dir $big again] - } elseif {$repeat == "initial"} { + } elseif {![string compare $repeat "initial"]} { set delay [$w cget -repeatdelay] if {$delay > 0} { set tkPriv(afterId) [after $delay \ @@ -233,9 +233,9 @@ proc tkScaleIncrement {w dir big repeat} { proc tkScaleControlPress {w x y} { set el [$w identify $x $y] - if {$el == "trough1"} { + if {![string compare $el "trough1"]} { $w set [$w cget -from] - } elseif {$el == "trough2"} { + } elseif {![string compare $el "trough2"]} { $w set [$w cget -to] } } @@ -252,8 +252,8 @@ proc tkScaleControlPress {w x y} { proc tkScaleButton2Down {w x y} { global tkPriv - if {[$w cget -state] == "disabled"} { - return; + if {![string compare [$w cget -state] "disabled"]} { + return } $w configure -state active $w set [$w get $x $y] diff --git a/library/scrlbar.tcl b/library/scrlbar.tcl index 779ddeb..bb8a2c0 100644 --- a/library/scrlbar.tcl +++ b/library/scrlbar.tcl @@ -3,7 +3,7 @@ # This file defines the default bindings for Tk scrollbar widgets. # It also provides procedures that help in implementing the bindings. # -# RCS: @(#) $Id: scrlbar.tcl,v 1.1.4.3 1998/11/25 21:16:33 stanton Exp $ +# RCS: @(#) $Id: scrlbar.tcl,v 1.1.4.4 1999/04/06 03:52:58 stanton Exp $ # # Copyright (c) 1994 The Regents of the University of California. # Copyright (c) 1994-1996 Sun Microsystems, Inc. @@ -17,8 +17,8 @@ #------------------------------------------------------------------------- # Standard Motif bindings: -if {($tcl_platform(platform) != "windows") && - ($tcl_platform(platform) != "macintosh")} { +if {[string compare $tcl_platform(platform) "windows"] && + [string compare $tcl_platform(platform) "macintosh"]} { bind Scrollbar <Enter> { if {$tk_strictMotif} { set tkPriv(activeBg) [%W cget -activebackground] @@ -144,7 +144,7 @@ proc tkScrollButtonDown {w x y} { set tkPriv(relief) [$w cget -activerelief] $w configure -activerelief sunken set element [$w identify $x $y] - if {$element == "slider"} { + if {![string compare $element "slider"]} { tkScrollStartDrag $w $x $y } else { tkScrollSelect $w $element initial @@ -185,21 +185,17 @@ proc tkScrollButtonUp {w x y} { proc tkScrollSelect {w element repeat} { global tkPriv if {![winfo exists $w]} return - if {$element == "arrow1"} { - tkScrollByUnits $w hv -1 - } elseif {$element == "trough1"} { - tkScrollByPages $w hv -1 - } elseif {$element == "trough2"} { - tkScrollByPages $w hv 1 - } elseif {$element == "arrow2"} { - tkScrollByUnits $w hv 1 - } else { - return + switch -- $element { + "arrow1" {tkScrollByUnits $w hv -1} + "trough1" {tkScrollByPages $w hv -1} + "trough2" {tkScrollByPages $w hv 1} + "arrow2" {tkScrollByUnits $w hv 1} + default {return} } - if {$repeat == "again"} { + if {![string compare $repeat "again"]} { set tkPriv(afterId) [after [$w cget -repeatinterval] \ tkScrollSelect $w $element again] - } elseif {$repeat == "initial"} { + } elseif {![string compare $repeat "initial"]} { set delay [$w cget -repeatdelay] if {$delay > 0} { set tkPriv(afterId) [after $delay tkScrollSelect $w $element again] @@ -218,7 +214,7 @@ proc tkScrollSelect {w element repeat} { proc tkScrollStartDrag {w x y} { global tkPriv - if {[$w cget -command] == ""} { + if {![string compare [$w cget -command] ""]} { return } set tkPriv(pressX) $x @@ -250,7 +246,7 @@ proc tkScrollStartDrag {w x y} { proc tkScrollDrag {w x y} { global tkPriv - if {$tkPriv(initPos) == ""} { + if {![string compare $tkPriv(initPos) ""]} { return } set delta [$w delta [expr {$x - $tkPriv(pressX)}] [expr {$y - $tkPriv(pressY)}]] @@ -280,7 +276,7 @@ proc tkScrollDrag {w x y} { proc tkScrollEndDrag {w x y} { global tkPriv - if {$tkPriv(initPos) == ""} { + if {![string compare $tkPriv(initPos) ""]} { return } if {[$w cget -jump]} { @@ -304,7 +300,7 @@ proc tkScrollEndDrag {w x y} { proc tkScrollByUnits {w orient amount} { set cmd [$w cget -command] - if {($cmd == "") || ([string first \ + if {![string compare $cmd ""] || ([string first \ [string index [$w cget -orient] 0] $orient] < 0)} { return } @@ -329,7 +325,7 @@ proc tkScrollByUnits {w orient amount} { proc tkScrollByPages {w orient amount} { set cmd [$w cget -command] - if {($cmd == "") || ([string first \ + if {![string compare $cmd ""] || ([string first \ [string index [$w cget -orient] 0] $orient] < 0)} { return } @@ -353,7 +349,7 @@ proc tkScrollByPages {w orient amount} { proc tkScrollToPos {w pos} { set cmd [$w cget -command] - if {($cmd == "")} { + if {![string compare $cmd ""]} { return } set info [$w get] @@ -399,7 +395,8 @@ proc tkScrollTopBottom {w x y} { proc tkScrollButton2Down {w x y} { global tkPriv set element [$w identify $x $y] - if {($element == "arrow1") || ($element == "arrow2")} { + if {![string compare $element "arrow1"] + || ![string compare $element "arrow2"]} { tkScrollButtonDown $w $x $y return } diff --git a/library/tearoff.tcl b/library/tearoff.tcl index 000fb12..9c3971e 100644 --- a/library/tearoff.tcl +++ b/library/tearoff.tcl @@ -2,7 +2,7 @@ # # This file contains procedures that implement tear-off menus. # -# RCS: @(#) $Id: tearoff.tcl,v 1.1.4.2 1998/09/30 02:17:37 stanton Exp $ +# RCS: @(#) $Id: tearoff.tcl,v 1.1.4.3 1999/04/06 03:52:59 stanton Exp $ # # Copyright (c) 1994 The Regents of the University of California. # Copyright (c) 1994-1997 Sun Microsystems, Inc. @@ -40,11 +40,11 @@ proc tkTearOffMenu {w {x 0} {y 0}} { } set parent [winfo parent $w] - while {([winfo toplevel $parent] != $parent) - || ([winfo class $parent] == "Menu")} { + while {[string compare [winfo toplevel $parent] $parent] + || ![string compare [winfo class $parent] "Menu"]} { set parent [winfo parent $parent] } - if {$parent == "."} { + if {![string compare $parent "."]} { set parent "" } for {set i 1} 1 {incr i} { @@ -61,7 +61,7 @@ proc tkTearOffMenu {w {x 0} {y 0}} { # entry. If it's a menubutton then use its text. set parent [winfo parent $w] - if {[$menu cget -title] != ""} { + if {[string compare [$menu cget -title] ""]} { wm title $menu [$menu cget -title] } else { switch [winfo class $parent] { @@ -92,7 +92,7 @@ proc tkTearOffMenu {w {x 0} {y 0}} { # now. set cmd [$w cget -tearoffcommand] - if {$cmd != ""} { + if {[string compare $cmd ""]} { uplevel #0 $cmd $w $menu } return $menu @@ -121,7 +121,7 @@ proc tkMenuDup {src dst type} { } eval $cmd set last [$src index last] - if {$last == "none"} { + if {![string compare $last "none"]} { return } for {set i [$src cget -tearoff]} {$i <= $last} {incr i} { @@ -140,9 +140,8 @@ proc tkMenuDup {src dst type} { # Copy tags to x, replacing each substring of src with dst. while {[set index [string first $src $tags]] != -1} { - append x [string range $tags 0 [expr $index - 1]] - append x $dst - set tags [string range $tags [expr $index + $srcLen] end] + append x [string range $tags 0 [expr {$index - 1}]]$dst + set tags [string range $tags [expr {$index + $srcLen}] end] } append x $tags @@ -156,9 +155,9 @@ proc tkMenuDup {src dst type} { # Copy script to x, replacing each substring of event with dst. while {[set index [string first $event $script]] != -1} { - append x [string range $script 0 [expr $index - 1]] + append x [string range $script 0 [expr {$index - 1}]] append x $dst - set script [string range $script [expr $index + $eventLen] end] + set script [string range $script [expr {$index + $eventLen}] end] } append x $script diff --git a/library/text.tcl b/library/text.tcl index 50eb437..3aab152 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.1.4.3 1998/11/25 21:16:33 stanton Exp $ +# RCS: @(#) $Id: text.tcl,v 1.1.4.4 1999/04/06 03:53:00 stanton Exp $ # # Copyright (c) 1992-1994 The Regents of the University of California. # Copyright (c) 1994-1997 Sun Microsystems, Inc. @@ -202,7 +202,7 @@ bind Text <Return> { tkTextInsert %W \n } bind Text <Delete> { - if {[%W tag nextrange sel 1.0 end] != ""} { + if {[string compare [%W tag nextrange sel 1.0 end] ""]} { %W delete sel.first sel.last } else { %W delete insert @@ -210,7 +210,7 @@ bind Text <Delete> { } } bind Text <BackSpace> { - if {[%W tag nextrange sel 1.0 end] != ""} { + if {[string compare [%W tag nextrange sel 1.0 end] ""]} { %W delete sel.first sel.last } elseif {[%W compare insert != 1.0]} { %W delete insert-1c @@ -272,7 +272,7 @@ bind Text <Meta-KeyPress> {# nothing} bind Text <Control-KeyPress> {# nothing} bind Text <Escape> {# nothing} bind Text <KP_Enter> {# nothing} -if {$tcl_platform(platform) == "macintosh"} { +if {![string compare $tcl_platform(platform) "macintosh"]} { bind Text <Command-KeyPress> {# nothing} } @@ -334,7 +334,7 @@ bind Text <Control-t> { } } -if {$tcl_platform(platform) != "windows"} { +if {[string compare $tcl_platform(platform) "windows"]} { bind Text <Control-v> { if {!$tk_strictMotif} { tkTextScrollPages %W 1 @@ -381,7 +381,7 @@ bind Text <Meta-Delete> { # Macintosh only bindings: # if text black & highlight black -> text white, other text the same -if {$tcl_platform(platform) == "macintosh"} { +if {![string compare $tcl_platform(platform) "macintosh"]} { bind Text <FocusIn> { %W tag configure sel -borderwidth 0 %W configure -selectbackground systemHighlight -selectforeground systemHighlightText @@ -453,7 +453,7 @@ set tkPriv(prevPos) {} # on other platforms. bind Text <MouseWheel> { - %W yview scroll [expr - (%D / 120) * 4] units + %W yview scroll [expr {- (%D / 120) * 4}] units } # tkTextClosestGap -- @@ -496,7 +496,7 @@ proc tkTextButton1 {w x y} { set tkPriv(pressX) $x $w mark set insert [tkTextClosestGap $w $x $y] $w mark set anchor insert - if {[$w cget -state] == "normal"} {focus $w} + if {![string compare [$w cget -state] "normal"]} {focus $w} } # tkTextSelectTo -- @@ -551,8 +551,9 @@ proc tkTextSelectTo {w x y} { } } } - if {$tkPriv(mouseMoved) || ($tkPriv(selectMode) != "char")} { - if {$tcl_platform(platform) != "unix" && [$w compare $cur < anchor]} { + if {$tkPriv(mouseMoved) || [string compare $tkPriv(selectMode) "char"]} { + if {[string compare $tcl_platform(platform) "unix"] + && [$w compare $cur < anchor]} { $w mark set insert $first } else { $w mark set insert $last @@ -604,7 +605,7 @@ proc tkTextKeyExtend {w index} { proc tkTextPaste {w x y} { $w mark set insert [tkTextClosestGap $w $x $y] catch {$w insert insert [selection get -displayof $w]} - if {[$w cget -state] == "normal"} {focus $w} + if {![string compare [$w cget -state] "normal"]} {focus $w} } # tkTextAutoScan -- @@ -670,7 +671,7 @@ proc tkTextSetCursor {w pos} { proc tkTextKeySelect {w new} { global tkPriv - if {[$w tag nextrange sel 1.0 end] == ""} { + if {![string compare [$w tag nextrange sel 1.0 end] ""]} { if {[$w compare $new < insert]} { $w tag add sel $new insert } else { @@ -711,7 +712,7 @@ proc tkTextKeySelect {w new} { proc tkTextResetAnchor {w index} { global tkPriv - if {[$w tag ranges sel] == ""} { + if {![string compare [$w tag ranges sel] ""]} { $w mark set anchor $index return } @@ -758,7 +759,8 @@ proc tkTextResetAnchor {w index} { # s - The string to insert (usually just a single character) proc tkTextInsert {w s} { - if {($s == "") || ([$w cget -state] == "disabled")} { + if {![string compare $s ""] || + ![string compare [$w cget -state] "disabled"]} { return } catch { @@ -812,13 +814,14 @@ proc tkTextUpDownLine {w n} { proc tkTextPrevPara {w pos} { set pos [$w index "$pos linestart"] while 1 { - if {(([$w get "$pos - 1 line"] == "\n") && ([$w get $pos] != "\n")) - || ($pos == "1.0")} { + if {(![string compare [$w get "$pos - 1 line"] "\n"] + && [string compare [$w get $pos] "\n"]) + || ![string compare $pos "1.0"]} { if {[regexp -indices {^[ ]+(.)} [$w get $pos "$pos lineend"] \ dummy index]} { set pos [$w index "$pos + [lindex $index 0] chars"] } - if {[$w compare $pos != insert] || ($pos == "1.0")} { + if {[$w compare $pos != insert] || ![string compare $pos 1.0]} { return $pos } } @@ -837,13 +840,13 @@ proc tkTextPrevPara {w pos} { proc tkTextNextPara {w start} { set pos [$w index "$start linestart + 1 line"] - while {[$w get $pos] != "\n"} { + while {[string compare [$w get $pos] "\n"]} { if {[$w compare $pos == end]} { return [$w index "end - 1c"] } set pos [$w index "$pos + 1 line"] } - while {[$w get $pos] == "\n"} { + while {![string compare [$w get $pos] "\n"]} { set pos [$w index "$pos + 1 line"] if {[$w compare $pos == end]} { return [$w index "end - 1c"] @@ -871,7 +874,7 @@ proc tkTextNextPara {w start} { proc tkTextScrollPages {w count} { set bbox [$w bbox insert] $w yview scroll $count pages - if {$bbox == ""} { + if {![string compare $bbox ""]} { return [$w index @[expr {[winfo height $w]/2}],0] } return [$w index @[lindex $bbox 0],[lindex $bbox 1]] @@ -941,7 +944,7 @@ proc tk_textCut w { proc tk_textPaste w { global tcl_platform catch { - if {"$tcl_platform(platform)" != "unix"} { + if {[string compare $tcl_platform(platform) "unix"]} { catch { $w delete sel.first sel.last } @@ -960,7 +963,7 @@ proc tk_textPaste w { # w - The text 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 tkTextNextWord {w start} { tkTextNextPos $w [tkTextNextPos $w $start tcl_endOfWord] \ tcl_startOfNextWord diff --git a/library/tk.tcl b/library/tk.tcl index e88bde1..32a4832 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.1.4.4 1999/01/29 00:34:33 stanton Exp $ +# RCS: @(#) $Id: tk.tcl,v 1.1.4.5 1999/04/06 03:53:00 stanton Exp $ # # Copyright (c) 1992-1994 The Regents of the University of California. # Copyright (c) 1994-1996 Sun Microsystems, Inc. @@ -56,27 +56,29 @@ proc tkScreenChanged screen { set tkPriv(screen) $screen return } - set tkPriv(activeMenu) {} - set tkPriv(activeItem) {} - set tkPriv(afterId) {} - set tkPriv(buttons) 0 - set tkPriv(buttonWindow) {} - set tkPriv(dragging) 0 - set tkPriv(focus) {} - set tkPriv(grab) {} - set tkPriv(initPos) {} - set tkPriv(inMenubutton) {} - set tkPriv(listboxPrev) {} - set tkPriv(menuBar) {} - set tkPriv(mouseMoved) 0 - set tkPriv(oldGrab) {} - set tkPriv(popup) {} - set tkPriv(postedMb) {} - set tkPriv(pressX) 0 - set tkPriv(pressY) 0 - set tkPriv(prevPos) 0 + array set tkPriv { + activeMenu {} + activeItem {} + afterId {} + buttons 0 + buttonWindow {} + dragging 0 + focus {} + grab {} + initPos {} + inMenubutton {} + listboxPrev {} + menuBar {} + mouseMoved 0 + oldGrab {} + popup {} + postedMb {} + pressX 0 + pressY 0 + prevPos 0 + selectMode char + } set tkPriv(screen) $screen - set tkPriv(selectMode) char if {[string compare $tcl_platform(platform) "unix"] == 0} { set tkPriv(tearoff) 1 } else { @@ -118,12 +120,12 @@ proc tkEventMotifBindings {n1 dummy dummy} { # using compiled code. #---------------------------------------------------------------------- -if {[info commands tk_chooseColor] == ""} { +if {![string compare [info commands tk_chooseColor] ""]} { proc tk_chooseColor {args} { return [eval tkColorDialog $args] } } -if {[info commands tk_getOpenFile] == ""} { +if {![string compare [info commands tk_getOpenFile] ""]} { proc tk_getOpenFile {args} { if {$::tk_strictMotif} { return [eval tkMotifFDialog open $args] @@ -132,7 +134,7 @@ if {[info commands tk_getOpenFile] == ""} { } } } -if {[info commands tk_getSaveFile] == ""} { +if {![string compare [info commands tk_getSaveFile] ""]} { proc tk_getSaveFile {args} { if {$::tk_strictMotif} { return [eval tkMotifFDialog save $args] @@ -141,7 +143,7 @@ if {[info commands tk_getSaveFile] == ""} { } } } -if {[info commands tk_messageBox] == ""} { +if {![string compare [info commands tk_messageBox] ""]} { proc tk_messageBox {args} { return [eval tkMessageBox $args] } @@ -179,7 +181,7 @@ switch $tcl_platform(platform) { # Read in files that define all of the class bindings. # ---------------------------------------------------------------------- -if {$tcl_platform(platform) != "macintosh"} { +if {[string compare $tcl_platform(platform) "macintosh"]} { source [file join $tk_library button.tcl] source [file join $tk_library entry.tcl] source [file join $tk_library listbox.tcl] @@ -219,7 +221,7 @@ proc tkCancelRepeat {} { # w - Window to which focus should be set. proc tkTabToWindow {w} { - if {"[winfo class $w]" == "Entry"} { + if {![string compare [winfo class $w] Entry]} { $w select range 0 end $w icur end } |