+ if {[string length $xabbrev]} {
+ report-set xabbrev "Notes flags: $xabbrev"
+ } else {
+ report-set xabbrev "No flags in notes"
+ }
+ }
+}
+
+#---------- common to smashing and filtering ----------
+
+proc make-control {parent ctrl label ekind} {
+ debug "MAKE-CONTROL [list $parent $ctrl $label $ekind]"
+ label $parent.lab_$ctrl -text $label -justify left
+ $ekind $parent.$ctrl
+ manyset [grid size $parent] dummy row
+ incr row
+ grid configure $parent.lab_$ctrl -row $row -column 0 -sticky nw -pady 4
+ grid configure $parent.$ctrl -row $row -column 1 -sticky w -pady 3
+ return $parent.$ctrl
+}
+
+proc begin-control-grid {cw count rows inrow} {
+ if {!$inrow} { set inrow [expr {($count + $rows) / $rows}] }
+ upvar #0 control_grid_properties($cw) props
+ set props [list $rows $inrow]
+ return $cw
+}
+
+proc make-control-grid-elem {cw kind ix ekind args} {
+ upvar #0 control_grid_properties($cw) props
+ manyset $props rows inrow
+
+ set ew $cw.$ix
+
+ debug "MAKE-CONTROL-GRID-ELEM $cw $kind $ix $ekind $rows $inrow $ew"
+
+ eval [list $ekind $ew] $args
+
+ switch -exact $kind {
+ ix {
+ grid configure $ew -sticky sw \
+ -row [expr {$ix / $inrow}] \
+ -column [expr {$ix % $inrow}]
+ }
+ final {
+ grid configure $ew -sticky se \
+ -row [expr {$rows-1}] \
+ -column [expr {$inrow-1}]
+ }
+ default {
+ error "$kind ?"
+ }
+ }
+ return $ew
+}
+
+proc control-tickbox-flip {varsvn values onflip} {
+ upvar #0 $varsvn vars
+ foreach val $values {
+ set vars($val) [expr {!$vars($val)}]
+ }
+ $onflip c.-tickbox-flip $varsvn $values
+}
+
+proc populate-control-grid-tickboxes {cw rows inrow varsvn values flipvalues
+ label_kind valvn default_get label_get onflip} {
+ debug "POPULATE-CONTROL-GRID-TICKBOXES $cw $rows $inrow $varsvn\
+ [list $values] $label_kind $valvn"
+
+ upvar #0 $varsvn vars
+ upvar 1 $valvn val
+ set count [llength $values]
+
+ begin-control-grid $cw $count $rows $inrow
+
+ for {set ix 0} {$ix < $count} {incr ix} {
+ set val [lindex $values $ix]
+ set vars($val) [uplevel 1 $default_get]
+ set ew [make-control-grid-elem $cw ix $ix checkbutton \
+ -variable ${varsvn}($val) \
+ -font fixed \
+ -command [list $onflip c.-g.-tickbox $cw $val]]
+ $ew configure -$label_kind [uplevel 1 $label_get]
+ switch -exact $label_kind {
+ image { $ew configure -height 16 }
+ }
+ }
+ [make-control-grid-elem $cw final invert button] \
+ configure \
+ -text flip -padx 0 -pady 0 \
+ -command [list control-tickbox-flip $varsvn $flipvalues $onflip]
+}
+
+#---------- smashing ----------
+
+proc smash-code {code} {
+ manyset [split $code _] inport size subclass lockown xabbrev
+
+ upvar #0 smash_sizemap($size) smsize
+
+ global smash_subclass
+ if {$smash_subclass > 1} {
+ set subclass {}
+ } elseif {$smash_subclass && [string length $subclass]} {
+ set subclass !
+ }
+
+ global smash_owner
+ switch $smash_owner {
+ 0 { }
+ 1 { regsub {[12]$} $lockown 5 lockown }
+ 2 {
+ if {[regexp {^0.} $lockown]} {
+ # battle ready / all lock states
+ set lockown 03
+ } elseif {[regexp {^.0} $lockown]} {
+ # not battle ready / yours
+ set lockown 40
+ } else {
+ # state (not battle ready) / not known to be yours
+ regsub {.$} $lockown 4 lockown
+ }
+ }
+ 3 { regsub {.$} $lockown {3} lockown }
+ 4 { set lockown 33 }
+ }
+
+ global smash_xabbrev_map
+ set xabbrev [string map $smash_xabbrev_map $xabbrev]
+
+ return [join [list $inport $smsize $subclass $lockown $xabbrev] _]
+}
+
+proc smash-prepare {} {
+ global vc_codes smash_sizemap smash_size smash_sizeinexact
+ set mapto {}
+ catch { unset smash_sizeinexact }
+ foreach size $vc_codes {
+ if {!$smash_size($size)} {
+ set mapto $size
+ } else {
+ set smash_sizeinexact($mapto) 1
+ }
+ set smash_sizemap($size) $mapto
+ }
+
+ global smash_xabbrev_a smash_xabbrev_b smash_xabbrev_map
+ set smash_xabbrev_map {}
+ foreach a [split $smash_xabbrev_a ""] b [split $smash_xabbrev_b ""] {
+ if {![string length $a]} continue
+ lappend smash_xabbrev_map $a $b
+ }
+ debug "SMASH-PREPAE xabbrev_map=[list $smash_xabbrev_map]"
+}
+
+proc make-smasher {sma label ekind} {
+ return [make-control .smash $sma $label $ekind]
+}
+
+proc make-radio-smasher {sma label variable descs rows inrow} {
+ set w [make-smasher $sma $label frame]
+ begin-control-grid $w [llength $descs] $rows $inrow
+ for {set i 0} {$i < [llength $descs]} {incr i} {
+ make-control-grid-elem $w ix $i \
+ radiobutton \
+ -variable $variable -value $i \
+ -command [list redraw-needed radio-smasher $sma] \
+ -text [lindex $descs $i]
+ }
+ return $w
+}
+
+proc make-smashers {} {
+ global vc_codes vc_code2abbrev
+ set cw [make-smasher size "Size\n round\n down" frame]
+ populate-control-grid-tickboxes $cw 2 0 smash_size \
+ $vc_codes [lrange $vc_codes 1 end] \
+ image val { expr 0 } { expr {"icon/$vc_code2abbrev($val)"} } \
+ redraw-needed
+ $cw.0 configure -state disabled
+
+ glset smash_subclass 0
+ make-radio-smasher subclass Class smash_subclass \
+ {Show Normal/LE Hide} 1 0
+
+ glset smash_owner [expr {[have-ownership] ? 0 : 3}]
+ set cw [make-radio-smasher owner "Lock/\nowner" smash_owner \
+ {Show Yours? {For you} Lock Hide} 2 3]
+ if {![have-notes]} { $cw.0 configure -state disabled }
+ if {![have-ownership]} {
+ foreach ix {1 2} { $cw.$ix configure -state disabled }