📄 scrolledhtml.itk
字号:
set tags [list $_tag $href_tag] if { $itk_option(-linkcommand)!= {} } { $_hottext tag bind $href_tag <1> \ [list uplevel #0 $itk_option(-linkcommand) $href] } $_hottext tag bind $href_tag <Enter> \ [list $_hottext tag configure $href_tag \ -foreground $_alink] $_hottext tag bind $href_tag <Leave> \ [list $_hottext tag configure $href_tag \ -foreground $_color] } else { set tags $_tag } if {![info exists _tagl($_tag)]} { set _tagfont($_tag) 1 eval $_hottext tag configure $_tag \ -foreground ${_color} \ -lmargin1 ${_left}m \ -lmargin2 ${_left2}m $args if [catch {eval $_hottext tag configure $_tag \ -font $x_font} err] { _definefont $_font * $family $weight $slant * regsub \$foundry $x_font * x_font regsub \$registry $x_font * x_font catch {eval $_hottext tag configure $_tag -font $x_font} } } if [info exists href_tag] { $_hottext tag raise $href_tag $_tag } set _tag $tags}# ------------------------------------------------------------------# PRIVATE METHOD: _reconfig_tags## reconfigure tags following a configuration change# ------------------------------------------------------------------itcl::body iwidgets::Scrolledhtml::_reconfig_tags {} { if $_initialized { foreach tag [$itk_component(text) tag names] { foreach efont $_fontnames { if [regexp "${efont}(B?)(I?)(U?)(\[1-9\]\[0-9\]*)-" $tag t b i u points] { set j -1 set _font $efont foreach var {foundry family weight slant registry} { set $var [lindex $_fontinfo($_font) [incr j]] } set x_font "-$foundry-$family-" if {$b == "B"} { append x_font [lindex $weight 1]- } else { append x_font [lindex $weight 0]- } if {$i == "I"} { append x_font [lindex $slant 1]- } else { append x_font [lindex $slant 0]- } set pts [lindex [set [format \ "_%spoints" $itk_option(-fontsize)]] $points] append x_font "normal-*-*-$pts-*-*-*-*-$registry-*" $itk_component(text) tag config $tag -font $x_font break } } } }}# ------------------------------------------------------------------# PRIVATE METHOD: _push instack value## push value onto stack(instack)# ------------------------------------------------------------------itcl::body iwidgets::Scrolledhtml::_push {instack value} { set _stack($instack) [linsert $_stack($instack) 0 $value]}# ------------------------------------------------------------------# PRIVATE METHOD: _pop instack## pop value from stack(instack)# ------------------------------------------------------------------itcl::body iwidgets::Scrolledhtml::_pop {instack} { if {$_stack($instack) == ""} { error "popping empty _stack $instack" } set val [lindex $_stack($instack) 0] set _stack($instack) [lrange $_stack($instack) 1 end] return $val}# ------------------------------------------------------------------# PRIVATE METHOD: _peek instack## peek at top value on stack(instack)# ------------------------------------------------------------------itcl::body iwidgets::Scrolledhtml::_peek {instack} { return [lindex $_stack($instack) 0]}# ------------------------------------------------------------------# PRIVATE METHOD: _parse_fields array_var string## parse fields from a href or image tag. At the moment, doesn't support# spaces in field values. (e.g. alt="not avaliable")# ------------------------------------------------------------------itcl::body iwidgets::Scrolledhtml::_parse_fields {array_var string} { upvar $array_var array if {$string != "{}" } { regsub -all "( *)=( *)" $string = string regsub -all {\\\"} $string \" string while {$string != ""} { if ![regexp "^ *(\[^ \n\r=\]+)=\"(\[^\"\n\r\t\]*)(.*)" $string \ dummy field value newstring] { if ![regexp "^ *(\[^ \n\r=\]+)=(\[^\n\r\t \]*)(.*)" $string \ dummy field value newstring] { if ![regexp "^ *(\[^ \n\r\]+)(.*)" $string dummy field newstring] { error "malformed command field; field = \"$string\"" continue } set value "" } } set array([string tolower $field]) $value set string "$newstring" } }}# ------------------------------------------------------------------# PRIVATE METHOD: _href_click## process a click on an href# ------------------------------------------------------------------itcl::body iwidgets::Scrolledhtml::_href_click {cmd href} { uplevel #0 $cmd $href}# ------------------------------------------------------------------# PRIVATE METHOD: _set_align## set text alignment# ------------------------------------------------------------------itcl::body iwidgets::Scrolledhtml::_set_align {align} { switch [string tolower $align] { center { set _justify C } left { set _justify L } right { set _justify R } default {} }}# ------------------------------------------------------------------# PRIVATE METHOD: _fixtablewidth## fix table width & height# essentially, with nested tables the outer table must be configured before# the inner table, but the idle tasks get queued up in the opposite order, # so process later idle tasks before sizing yourself.# ------------------------------------------------------------------itcl::body iwidgets::Scrolledhtml::_fixtablewidth {hottext table multiplier} { update idletasks $hottext see $_anchor($table) update idletasks $table configure \ -width [expr {$multiplier * [winfo width $hottext] - \ 2* [$hottext cget -padx] - \ 2* [$hottext cget -borderwidth]} ] \ -height [winfo height $table] grid propagate $table 0} # ------------------------------------------------------------------# PRIVATE METHOD: _header level## generic entity to set state for <hn> tag# Accepts argument of the form ?align=[left,right,center]? ?src=<image pname>?# ------------------------------------------------------------------itcl::body iwidgets::Scrolledhtml::_header {level args} { eval _parse_fields ar $args _push justify $_justify if [info exists ar(align)] { _entity_p align=$ar(align) } else { _entity_p } if [info exists ar(src)] { _entity_img src=$ar(src) } _push pointsndx $_pointsndx set _pointsndx [expr {7-$level}] incr _textweight _set_tag}# ------------------------------------------------------------------# PRIVATE METHOD: _/header level## generic entity to set state for </hn> tag# ------------------------------------------------------------------itcl::body iwidgets::Scrolledhtml::_/header {level} { set _justify [_pop justify] set _pointsndx [_pop pointsndx] incr _textweight -1 _set_tag _entity_p}# ------------------------------------------------------------------# PRIVATE METHOD: _entity_a## add an anchor. Accepts arguments of the form ?href=filename#anchorpoint?# ?name=anchorname?# ------------------------------------------------------------------itcl::body iwidgets::Scrolledhtml::_entity_a {args} { _parse_fields ar $args _push color $_color if [info exists ar(href)] { _push href $ar(href) incr _anchorcount set _color $_link _entity_u } else { _push href {} } if [info exists ar(name)] { set _anchor($ar(name)) [$itk_component(text) index end] } if [info exists ar(id)] { set _anchor($ar(id)) [$itk_component(text) index end] }}# ------------------------------------------------------------------# PRIVATE METHOD: _entity_/a## End anchor# ------------------------------------------------------------------itcl::body iwidgets::Scrolledhtml::_entity_/a {} { set href [_pop href] if {$href != {}} { incr _anchorcount -1 set _color [_pop color] _entity_/u }}# ------------------------------------------------------------------# PRIVATE METHOD: _entity_address## display an address# ------------------------------------------------------------------itcl::body iwidgets::Scrolledhtml::_entity_address {} { _entity_br _entity_i}# ------------------------------------------------------------------# PRIVATE METHOD: _entity_/address## change state back from address display# ------------------------------------------------------------------itcl::body iwidgets::Scrolledhtml::_entity_/address {} { _entity_/i _entity_br}# ------------------------------------------------------------------# PRIVATE METHOD: _entity_b## Change current font to bold# ------------------------------------------------------------------itcl::body iwidgets::Scrolledhtml::_entity_b {} { incr _textweight _set_tag }# ------------------------------------------------------------------# PRIVATE METHOD: _entity_/b## change current font back from bold# ------------------------------------------------------------------itcl::body iwidgets::Scrolledhtml::_entity_/b {} { incr _textweight -1 _set_tag}# ------------------------------------------------------------------# PRIVATE METHOD: _entity_base## set the cwd of the document# ------------------------------------------------------------------itcl::body iwidgets::Scrolledhtml::_entity_base {{args {}}} { _parse_fields ar $args if [info exists ar(href)] { set _cwd [file dirname $ar(href)] }}# ------------------------------------------------------------------# PRIVATE METHOD: _entity_basefont## set base font size# ------------------------------------------------------------------itcl::body iwidgets::Scrolledhtml::_entity_basefont {{args {}}} { _parse_fields ar $args if {[info exists ar(size)]} { set _basefontsize $ar(size) }}# ------------------------------------------------------------------# PRIVATE METHOD: _entity_big## Change current font to a bigger size# ------------------------------------------------------------------itcl::body iwidgets::Scrolledhtml::_entity_big {} { _push pointsndx $_pointsndx if {[incr _pointsndx 2] > 6} { set _pointsndx 6 } _set_tag }# ------------------------------------------------------------------# PRIVATE METHOD: _entity_/big## change current font back from bigger size# ------------------------------------------------------------------itcl::body iwidgets::Scrolledhtml::_entity_/big {} { set _pointsndx [_pop pointsndx] _set_tag}# ------------------------------------------------------------------# PRIVATE METHOD: _entity_blockquote## display a block quote# ------------------------------------------------------------------itcl::body iwidgets::Scrolledhtml::_entity_blockquote {} { _entity_p _push left $_left incr _left $_indentincr _push left2 $_left2 set _left2 $_left _set_tag }# ------------------------------------------------------------------# PRIVATE METHOD: _entity_/blockquote## change back from blockquote# ------------------------------------------------------------------itcl::body iwidgets::Scrolledhtml::_entity_/blockquote {} { _entity_p set _left [_pop left] set _left2 [_pop left2] _set_tag}# ------------------------------------------------------------------# PRIVATE METHOD: _entity_body## begin body text. Takes argument of the form ?bgcolor=<color>? ?text=<color>?# ?link=<color>?# ------------------------------------------------------------------itcl::body iwidgets::Scrolledhtml::_entity_body {{args {}}} { _parse_fields ar $args if [info exists ar(bgcolor)] { set _bgcolor $ar(bgcolor) set temp $itk_option(-textbackground) config -textbackground $_bgcolor set _defaulttextbackground $temp } if [info exists ar(text)] { set _color $ar(text) } if [info exists ar(link)] { set _link $ar(link) } if [info exists ar(alink)] { set _alink $ar(alink) }}# ------------------------------------------------------------------# PRIVATE METHOD: _entity_/body## end body text# ------------------------------------------------------------------itcl::body iwidgets::Scrolledhtml::_entity_/body {} {}# ------------------------------------------------------------------# PRIVATE METHOD: _entity_br#
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -