Tk Library Source Code

Check-in [9282d3aaae]
Login

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

Overview
Comment:Tsw: Added/updated a few comments in toggleswitch.tcl.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 9282d3aaae932a0435bbedc1e127d7cbc83cc880edbb0484f7c6a4b4b72556f4
User & Date: csaba 2025-07-16 11:16:29.611
Context
2025-07-16
16:36
Removed superfluous close-brace. check-in: c7ec0962c1 user: clif tags: trunk
11:16
Tsw: Added/updated a few comments in toggleswitch.tcl. check-in: 9282d3aaae user: csaba tags: trunk
2025-07-07
19:43
Tsw: Guarded against a bug in the ttk::scale widget's "get x y" command. check-in: bf07168387 user: csaba tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to modules/tsw/scripts/toggleswitch.tcl.
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
	    if {$var eq $data(-onvalue)} {
		$scl state selected
		$scl set [$scl cget -to]
	    } else {
		$scl state !selected
		$scl set [$scl cget -from]
	    }
	    $scl state $stateSpec
	}

	unset {
	    #
	    # Recreate the variable $varName by setting it according to
	    # the widget's switch state, and set the trace on it again
	    #







|







469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
	    if {$var eq $data(-onvalue)} {
		$scl state selected
		$scl set [$scl cget -to]
	    } else {
		$scl state !selected
		$scl set [$scl cget -from]
	    }
	    $scl state $stateSpec			;# restores the state
	}

	unset {
	    #
	    # Recreate the variable $varName by setting it according to
	    # the widget's switch state, and set the trace on it again
	    #
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
    if {$w eq "."} {
	condMakeLayouts
    } else {
	set scl $w.scl
	set stateSpec [$scl state !disabled]		;# needed for $scl set
	$scl set [expr {[$scl instate selected] ?
			[$scl cget -to] : [$scl cget -from]}]
	$scl state $stateSpec
    }
}

#------------------------------------------------------------------------------
# tsw::onButton1
#------------------------------------------------------------------------------
proc tsw::onButton1 {w x y} {







|







673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
    if {$w eq "."} {
	condMakeLayouts
    } else {
	set scl $w.scl
	set stateSpec [$scl state !disabled]		;# needed for $scl set
	$scl set [expr {[$scl instate selected] ?
			[$scl cget -to] : [$scl cget -from]}]
	$scl state $stateSpec				;# restores the state
    }
}

#------------------------------------------------------------------------------
# tsw::onButton1
#------------------------------------------------------------------------------
proc tsw::onButton1 {w x y} {
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
	    set stateArr(dragging) 1
	}
	if {!$stateArr(dragging)} {
	    return ""
	}

	#
	# Guard against a bug in the ttk::scale widget's
	# "get x y" command (open as of July 2025)
	#
	lassign [$w coords [$w cget -from]] fromX fromY
	lassign [$w coords [$w cget -to]] toX toY
	if {$fromX < $toX} {
	    lassign [$w coords] curX curY
	    set newX [expr {$curX + $x - $stateArr(prevX)}]
	    $w set [$w get $newX $curY]







|
|







733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
	    set stateArr(dragging) 1
	}
	if {!$stateArr(dragging)} {
	    return ""
	}

	#
	# Guard against a bug in the ttk::scale widget's "get x y"
	# command (fixed in July 2025 for Tk 9.1a0, 9.0.3, and 8.6.17)
	#
	lassign [$w coords [$w cget -from]] fromX fromY
	lassign [$w coords [$w cget -to]] toX toY
	if {$fromX < $toX} {
	    lassign [$w coords] curX curY
	    set newX [expr {$curX + $x - $stateArr(prevX)}]
	    $w set [$w get $newX $curY]