Tk Source Code

Artifact [aaf8cbc1]
Login

Artifact aaf8cbc1f429c6df1f6930cb4448ec99f9694fdf275a97c673837dcea1c4d8c6:

Attachment "04.patch" to ticket [87bd2b89] added by anonymous 2026-10-03 17:36:49. (unpublished)
--- a/library/accessibility.tcl
+++ b/library/accessibility.tcl
@@ -653,15 +653,14 @@
 	    }
 	}
 
-	# Set initial accessible attributes and add binding to <Map> event.
-	# If the accessibility role is already set, return because
-	# we only want these to fire once.
+	# Set the class default accessible attributes; runs on every <Map>
+	# (and <<NotebookTabChanged>>), so defaults such as the current text
+	# are refreshed. An attribute the application has set itself is left
+	# alone: _init overwrites only attributes that are unset or still hold
+	# the value _init set last time.
+	variable _initValues
 	proc _init {w role name description value state action} {
-	    if {[catch {::tk::accessible::get_acc_role $w} msg]} {
-		if {$msg == $role} {
-		    return
-		}
-	    }
+	    variable _initValues
 	    if {[tk windowingsystem] ne "aqua"} {
 		# This is necessary to ensure correct accessible keyboard navigation
 		if [winfo exists $w] {
@@ -669,14 +668,19 @@
 		}
 	    }
 
-	    ::tk::accessible::set_acc_role $w $role
-	    ::tk::accessible::set_acc_name $w $name
-	    ::tk::accessible::set_acc_description $w $description
-	    ::tk::accessible::set_acc_value $w $value
-	    ::tk::accessible::set_acc_state $w $state
-	    ::tk::accessible::set_acc_action $w $action
-
+	    # Role first: the other set_acc_* commands require it.
+	    foreach {attr new} [list role $role name $name \
+		    description $description value $value \
+		    state $state action $action] {
+		if {[catch {::tk::accessible::get_acc_$attr $w} current]
+			|| ([info exists _initValues($w,$attr)]
+			&& $current eq $_initValues($w,$attr))} {
+		    ::tk::accessible::set_acc_$attr $w $new
+		    set _initValues($w,$attr) $new
+		}
+	    }
 	}
+	bind all <Destroy> {+array unset ::tk::accessible::_initValues [string map {* \\* ? \\? [ \\[ ] \\]} %W],*}
 
 	# Toplevel bindings.
 	bind Toplevel <Map> {+::tk::accessible::_init \