global B V N me in \ PicMinw PicMaxw \ Tf2c Tl2n Tcol Tcols Trow Trows Tn2f \ Txt TxtLen txtlvl TxtMin TxtMaxw TxtMinW TxtMaxw TxtMinW #trace variable TxtLen w pvar trace variable txtlvl w pvar set in(TABLE) 0; # Depth in tables. set in(TR) 0; # Depth in table rows. set in(TD) 0; # Depth in table cells. set N(TABLE) 0; # Count of tables. set N(tkTable) 0; # Count of tkTable objects. set Tcol(0) 0; # Table number -> current table column. set Tcols(0) 0; # Table number -> table column count. set Trow(0) 0; # Table number -> current table row. set Trows(0) 0; # Table number -> table row count. set Tn2b(0) 0; # Table number -> table border width set Tn2f(0) {}; # Table number -> table frame. set Tl2n(0) 0; # Table level -> table number. #et Tn2f(0) .t; # Table frame for each table. #et Tn2t(0) $curD; # Text widget for each table. #et Tf2c($curD) {}; # Table children of text widgets. set txtlvl 0; # Current text nesting level. #et curD $curD; # Current text widget. #et Txt(0) $curD; # Text widget for each txtlvl. #et TxtLen($curD) 0; # Text size (char count) #et TxtMin($curD) 0; # Text min width (chars) #et TxtMinw($curD) 0; # Text min width (pixels) #et TxtMinW($curD) 0; # Text min width (pixels) #et TxtMaxw($curD) 0; # Text max width (pixels) #et TxtMaxW($curD) 0; # Text max width (pixels) #et PicMinw($curD) 0; # Embedded picture min width (pixels) #et PicMaxw($curD) 0; # Embedded picture max width (pixels) #et TxtFnt0($curD) 6; # Text font char width. #if {$V>2} {puts "$me: Cell $curD now contains $TxtLen($curD) chars."} # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # When we encounter a TABLE tag, we create a frame widget to contain the # # table, and bump up the in(TABLE) level indicator and the N(TABLE) counter. # # We then return, and hope that the following data is a table-related tag. # # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # proc tagTABLE {w TAG att} { global B C V R bd me in opt N curD Tn2b Tn2f Trow Tcol Tcols Trow Trows \ Tf2c Tn2f Tl2n Txt TxtLen TxtMin TxtMaxw TxtMaxW TxtMinw TxtMinW TxtFnt0 txtlvl table set id "$me/tagTABLE" set tl [incr in(TABLE)] if {$V>4} {puts "$id: We now have levels: TD=$in(TD) TR=$in(TR) TABLE=$in(TABLE)."} if {$V>4} {puts "$id: w=$w curD=$curD TAG=$TAG att={$att} level $tl."} DoSP switch $opt(TABLE) { 2 { if {$V>1} {puts "$id: tkTable level $tl is ..."} if {[string match {} [info commands table]]} { if {$V>1} {puts "$id: table command not defined; load Tktable ,,."} if [catch {package require Tktable} err] { if {$V>1} {puts "$id: Tktable module not loaded ($err)"} if {[catch {load [file join [pwd] .. $table(library)]} err] && [catch {load [file join [pwd] $table(library)]} err]} { if {$V>0} {puts "$id: Tktable module not loaded by 2nd try ($err)"} error $err } else { if {$V>1} {puts "$id: Tktable module loaded by 2nd try."} } } else { if {$V>1} {puts "$id: Tktable module loaded."} } } Msg "$id: ### not implemented yet for tkTable ###" ListEnter $curD $TAG $att } 1 { set tn [incr N(TABLE)] if {$V>1} {puts "$id: Table $tn level $tl is
..."} set Tn2f($tn) {} set Tl2n($tl) $tn set bd($tl) 0 if {$V>4} {puts "$id: curD=\"$curD\" level $tl table $tn."} set Tcol($tn) 0 set Trow($tn) 0 set Tcols($tn) 0 set Trows($tn) 0 if [regexp {border="*([0-9]+)"*} $att {} b] { set Tn2b($tn) [Max $bd(T1) $b]; # Border width from the HTML. if {$V>2} {puts "$id: Border width b=$b used for $tn."} } elseif [regexp {border} $att {} b] { set Tn2b($tn) [Max $bd(T1) 1]; # Default border without width. if {$V>2} {puts "$id: Border width bd(T1)=$bd(T1) default used for $tn."} } elseif [info exists bd(T1)] { set Tn2b($tn) $bd(T1); # Default border without width. if {$V>2} {puts "$id: Border width bd(T1)=$bd(T1) used for $tn."} } else { set Tn2b($tn) $B; # No border, use debug border width. if {$V>2} {puts "$id: Border width B=$B used for $tn."} } if {$V>2} {puts "$id: Border width $Tn2b($tn) for table $tn."} BR $curD set tframe $curD.t$tn if [winfo exists $tframe] {destroy $tframe} set Tn2f($tn) [frame $tframe -bd $Tn2b($tn) -bg $C(T1) -relief raised] if {$V>4} {puts "$id: Frame $Tn2f($tn) created for table $tn."} if {$V>1} {puts "$id: Frame Tn2f($tn)={$Tn2f($tn)} txtlvl=$txtlvl Txt($txtlvl)={$Txt($txtlvl)}"} if {$V>4} {puts "$id: $curD window create insert -window \"$tframe\""} $curD window create insert -window $tframe if {$V>2} {puts "$id: Text $curD now contains insert \"$tframe\""} if {$V>4} {puts "$id: $curD insert end \"\\n\" (TABLE)"} $curD insert end \n if {$V>4} {puts "$id: Frame $Tn2f($tn) inserted."} lappend Tf2c($curD) $tn if {$V>1} {puts "$id: Text $curD contains tables {$Tf2c($curD)}"} if {$V>1} {puts "$id: Table $tn level $tl initialized."} } default - 0 { if {$V>4} {puts "$id: Table $tl Suppressed."} ListEnter $curD $TAG $att } } } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # proc endTABLE {w TAG att} { global B V R me docLines in opt N opt curD Tn2f Tl2n Txt txtlvl Winw set id "$me/endTABLE" # chkT0 {endTABLE start} if {$V>4} {puts "$id: curD=\"$curD\" TAG=\"$TAG\" att=\"$att\""} if {$V>4} {puts "$id: We now have levels: TD=$in(TD) TR=$in(TR) TABLE=$in(TABLE)."} while {$in(TR) >= $in(TABLE)} { while {$in(TD) >= $in(TR)} { if {$V>1} {puts "$id: Unclosed at table level $in(TABLE) in line $docLines."} endTR $w {} } if {[set tl $in(TABLE)] < 1} { if {$V>1} {puts "$id: Extra /TABLE tag ignored."} return } switch $opt(TABLE) { 2 { if {$V>4} {puts "$id: tkTable $N(TABLE) ..."} Msg "$id:
at table level $in(TABLE) in line $docLines."} endTD $w {} } if {$V>1} {puts "$id: Unclosed
not implemented yet for tkTable." ListExit $curD $TAG } 1 { if {$V>4} {puts "$id: tk $N(TABLE) ..."} set tn $Tl2n($tl) if {$V>1} {puts "$id: We are in table level $tl number $tn text level $txtlvl."} } default - 0 { ListExit $curD $TAG } } set curD $Txt($txtlvl) if {$V>1} {puts "$id: Set curD to Txt($txtlvl)={$curD}"} if {$tl == 1} { if {$V>1} {puts "$id: Resize top-level $tl table $tn."} GetWinfo $curD ResizeTbl $tn $Winw($curD) } BR $curD # chkT0 {endTABLE end} if {[incr in(TABLE) -1] < 0} {set in(TABLE) 0} } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # The outside
tag creates a special table cell that can be shown at the top # or bottom of the table. It should span the entire table's width, but we # probably don't know that yet. proc tagCAPTION {w TAG att} { global V me in N set id "$me/tagCAPTION" # chkT0 {tagCAPTION start} set tn $N(TABLE) ;# Current table ndx. if {$tn < 1} { puts "$id: ### Called with N(TABLE)=\"$tn\" ###" return } if {$V>1} {puts "$id: Table $tn w={$w} TAG={$TAG} att={$att}"} tblcell $tn $w.t$tn.caption 0 1 # chkT0 {tagCAPTION end} } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # proc endCAPTION {w TAG att} { global V me N set id "$me/endCAPTION" set tn $N(TABLE) ;# Current table ndx. } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # Ensure that the table library extension is loaded. Used only with tkTable. proc tkTableLib {} { global V me N set id "$me/tkTableLib" if {$V>1} {puts "$id: Loading Tktable library ..."} if {[string match {} [info commands table]] && \ [catch {package require Tktable} err]} { if {[catch {load [file join [pwd] .. Tktable]} err] && \ [catch {load [file join [pwd] Tktable]} err]} { error $err } } if [string match {} [info commands table]] { Msg "### $id: WARNING: table command not defined ###" } incr N(tkTable) if {$V>1} {puts "$id: Loaded Tktable library."} } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # A bit of debug sanity checking for the top-level text widget. proc chkT0 {where} { global V me curD in txtlvl Txt if {$Txt(0) != "$curD"} { puts "$me/chkT0: ### Txt(0)=\"$Txt(0)\" curD=\"$curD\" ($where)" # set Txt(0) $curD } } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # Handle a
(table datum) tag. Here is where we create the table cell's # # frame. We also must update assorted global info about the table's shape. # # Note that we call tblcell to create the text widget for the cell. This is # # done so that the
tag can use the same call to create its text # # widget. If we aren't doing tables, we create a list item instead. # # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # proc tagTD {w att} { global B V R me in N opt curD docLines Tn2f Tl2n Tcol Tcols Trow Txt txtlvl set id "$me/tagTD" if {$V>4} {puts "$id: w=$w curD=$curD att=\"$att\""} set tl $in(TABLE); # Table level. while {$in(TD) >= $tl} { if {$V>1} {puts "$id: Unclosed
at table level $tl in line $docLines."} endTD $w {} } if {$in(TD) < 0} {set in(TD) 0} set rl $in(TR) set dl [incr in(TD)] if {$dl > $tl} { if {$V>0} {puts "$id: ### TABLE level $tl TR level $rl TD level $dl ###"} while {$dl > $tl} { endTD $w {} set dl $in(TD) set rl $in(TR) set tl $in(TABLE) if {$V>0} {puts "$id: New TABLE level $tl TR level $rl TD level $dl."} } } if {$V>4} {puts "$id: We now have levels: TD=$in(TD) TR=$in(TR) TABLE=$in(TABLE)."} switch $opt(TABLE) { 2 { if {$V>4} {puts "$id: tkTable $tl ..."} Msg "$id: not implemented yet for tkTable." BR $curD; litab $curD } 1 { if {$V>4} {puts "$id: Table $tl using tk grid."} set tu [expr {$tl-1}] if ![info exists Tl2n($tl)] { if {$V>4} {puts "$id: ### Tl2n($tl) does not exist ###"} return } set tn $Tl2n($tl); # Table number. if {$V>4} {puts "$id: Create text widget for table tl=$tl tu=$tu."} incr Tcol($tn); # Bump the column counter. set r $Trow($tn); # Current table row. set c $Tcol($tn); # Current table col. if {$c > $Tcols($tn)} {set Tcols($tn) $c} if {$V>4} {puts "$id: w=$w curD=$curD tl=$tl tu=$tu tn=$tn r=$r c=$c Trow=$r Tcol=$c"} set TT $Tn2f($tn) # if {$TT == {}} {set TT .t} set cell $TT.r${r}c${c} if {$V>1} {puts "$id: Cell \"$cell\""} if [winfo exists $cell] {destroy $cell} tblcell $tn $cell $r $c } default - 0 { BR $curD; litab $curD } } } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # proc endTD {w att} { global B V R curD in me opt Tl2n Tn2f Txt txtlvl set id "$me/endTD" if {$V>4} {puts "$id: w={$w} att={$att} curD={$curD} txtlvl=$txtlvl."} if {[set tblvl $in(TABLE)] < 1} { Msg "$id: ###
ignored." return } if {[set trlvl $in(TR)] < 1} { Msg "$id: ### outside ignored." return } if {[set tdlvl [incr in(TD) -1]] < 0} { Msg "$id: ### without at table level $tl."} endTR $w {} } incr in(TR) if {$V>4} {puts "$id: We now have levels: TD=$in(TD) TR=$in(TR) TABLE=$in(TABLE)."} switch $opt(TABLE) { 2 { if {$V>4} {puts "$id: tkTable $tn ..."} Msg "$id: not implemented yet for tkTable." Hnl 2; lltab $w } 1 { if {$V>4} {puts "$me/tagTR: w=$w tn=$tn Trow=$Trow($tn) Tcol=$Tcol($tn)"} set r [incr Trow($tn)] set c [set Tcol($tn) 0] if {$V>4} {puts "$me/tagTR: w=$w tn=$tn r=$r c=$c Trows($tn)=$Trows($tn)."} if {$r > $Trows($tn)} { set Trows($tn) $r if {$V>4} {puts "$id: w=$w Trows($tn)=$Trows($tn)."} } } default - 0 { Hnl 2; lltab $w } } }
ignored." return } $curD insert end \n if {[incr in(TD) -1] < 0} {set in(TD) 0} if {$V>4} {puts "$id: We now have levels: TD=$in(TD) TR=$in(TR) TABLE=$in(TABLE)."} switch $opt(TABLE) { 1 { if {[set tl $in(TABLE)] > 0} { if {$V>1} {puts "$id: We are now in table level $tl."} set tn $Tl2n($tl) if {$V>1} {puts "$id: We are now in table level $tl number $tn."} } else { if {$V>1} {puts "$id: We are no longer inside a table."} set tn 0 } if {[incr txtlvl -1] < 0} {set txtlvl 0} set curD $Txt($txtlvl) if {$V>1} {puts "$id: Text level is $txtlvl Tn2f($tn)=$Tn2f($tn) curD=Txt($txtlvl)=$curD"} } default - 2 - 0 {} } } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # proc endTR {w att} { global B V R curD docLines me in txtlvl set id "$me/endTR" if {$V>4} {puts "$id: w={$w} att={$att} curD={$curD} txtlvl=$txtlvl."} while {$in(TD) >= $in(TR)} { if {$V>1} {puts "$id: Unclosed at table level $in(TABLE) in line $docLines."} endTD $w {} } if {[incr in(TR) -1] < 0} {set in(TR) 0} if {$V>4} {puts "$id: We now have levels: TD=$in(TD) TR=$in(TR) TABLE=$in(TABLE)."} } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # This creates a "cell" in a table. We are passed the the cell's name, which # # we use to create a frame, and pack a text widget inside. Both have debug # # borders, so we have to account for 4 border widths when resizing. If any # # args are passed, they are used for the initial text in the cell. This is # # sometimes useful for debugging. # # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # proc tblcell {tn cell r c} { global B bd C V me LC N R SP Src Ftag URLt PicMinw PicMaxw \ curD Tn2b Tf2c Tn2f Tn2t Txt TxtMin TxtMaxw TxtMaxW TxtMinw TxtMinW TxtLen txtlvl set id "$me/tblcell" if {[incr txtlvl] < 1} { Msg "$id: ### Attempt to define $cell at txtlvl $txtlvl ###" return } # chkT0 {$id start} if {$V>4} {puts "$id: Table $tn cell $cell row $r col $c"} if ![info exists Tn2f($tn)] {set Tn2f($tn) {}} if ![info exists Txt($txtlvl)] {set Txt($txtlvl) {}} if {$V>4} {puts "$id: Tn2f($tn)={$Tn2f($tn)} curD=Txt($txtlvl)={$Txt($txtlvl)}"} if {$V>4} {puts "$id: Table $tn curD={$curD}"} if ![info exists Tn2f($tn)] {Msg "$id: Tn2f($tn) not defined."; return} set tf $Tn2f($tn); if {$V>4} {puts "$id: Table frame Tn2f($tn)={$tf}"} if ![info exists Tn2b($tn)] {set Tn2b($tn) $bd(T1)} set tb $Tn2b($tn); if {$V>4} {puts "$id: Table border Tn2b($tn)=$tb"} if [catch {frame $cell -bd $bd(T2) -relief flat -bg $C(T2)} x] { Msg $x return } set curD [set Txt($txtlvl) $cell.d] set URLt($curD) $URLt($Txt(0)) text $curD -height 1 -width 1 -wrap word -bd $bd(T3) -bg $C(T3) -relief sunken \ -highlightthickness 0 -font F$Ftag if {$V>4} {puts "$id: Table $tn cell curD={$curD} created."} HSP $curD {} set Tn2t($tn) $curD set TxtLen($curD) 0 set TxtMin($curD) 0 set TxtMinw($curD) 0 set TxtMinW($curD) 0 set TxtMaxw($curD) 0 set TxtMaxW($curD) 0 set PicMinw($curD) 0 set PicMaxw($curD) 0 if {$V>2} {puts "$id: Cell $curD now has TxtLen=$TxtLen($curD) TxtMin=$TxtMin($curD) TxtMinW=$TxtMinW($curD) TxtMaxW=$TxtMaxW($curD) PicMinw=$PicMinw($curD) PicMaxw=$PicMaxw($curD)."} if {$V>4} {puts "$id: Created cell $cell text $Tn2t($tn)"} if {$V>4} {puts "$id: Grid $cell -in $tf -row $r -column $c -sticky news"} grid $cell -in $tf -row $r -column $c -sticky news grid columnconfigure $tf $c -weight 1 grid propagate $tf Hnl 0 set LC {} set Tf2c($curD) {} pack $curD -in $cell -expand 1 -fill both # chkT0 {$id end} bind $curD { if {$V>4} {puts "KP_Up"} set h [lindex [%W config -height] 4] incr h -1 if {$V>4} {puts "KP_Up: %W config -height $h"} %W config -height $h } bind $curD { if {$V>4} {puts "KP_Down"} set h [lindex [%W config -height] 4] incr h if {$V>4} {puts "KP_Down: %W config -height $h"} %W config -height $h } bind $curD { if {$V>4} {puts "KP_Left"} set w [lindex [%W config -width] 4] incr w -1 if {$V>4} {puts "KP_Left: %W config -width $w"} %W config -width $w } bind $curD { if {$V>4} {puts "KP_Right"} set w [lindex [%W config -width] 4] incr w if {$V>4} {puts "KP_Right: %W config -width $w"} %W config -width $w } if {$V>1} {puts "$id: Created cell Txt($txtlvl)={$Txt($txtlvl)} Tn2f($tn)={$Tn2f($tn)}"} } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # proc tagTR {w att} { global B V me in N Trow Tcol Trows opt set id "$me/tagTR" set tl $in(TABLE); # Current table level. set tn $N(TABLE); # Current table number. if {$V>4} {puts "$me/tagTR: w=$w att=\"$att\" tn=$tn"} while {$in(TR) >= $tl} { if {$V>1} {puts "$id: Unclosed