📄 scrolledhtml.itk
字号:
# Scrolledhtml# ----------------------------------------------------------------------# Implements a scrolled html text widget by inheritance from scrolledtext# Import reads from an html file, while export still writes plain text# Also provides a render command, to display html text passed in as an# argument.## This widget is HTML3.2 compliant, with the following exceptions:# a) nothing requiring a connection to an HTTP server is supported# b) some of the image alignments aren't supported, because they're not# supported by the text widget# c) the br attributes that go with the image alignments aren't implemented# d) background images are not supported, because they're not supported# by the text widget# e) automatic table/table cell sizing doesn't work very well.## WISH LIST:# This section lists possible future enhancements.## 1) size tables better using dlineinfo.# 2) make images scroll smoothly off top like they do off bottom. (limitation# of text widget?)# 3) add ability to get non-local URLs# a) support forms# b) support imagemaps# 4) keep track of visited links# 5) add tclets support## BUGS:# Cells in a table can be caused to overlap. ex:# <table border width="100%"># <tr><td>cell1</td><td align=right rowspan=2>cell2</td></tr># <tr><td colspan=2>cell3 w/ overlap</td># </table># It hasn't been fixed because 1) it's a pain to fix, 2) the fix would slow# tables down by a significant amount, and 3) netscape has the same# bug, as of V3.01, and no one seems to care.## In order to size tables properly, they must be visible, which causes an# annoying jump from table to table through the document at render time.## ----------------------------------------------------------------------# AUTHOR: Kris Raney EMAIL: kraney@spd.dsccc.com## @(#) $Id: scrolledhtml.itk 144 2003-02-05 10:56:26Z mdejong $# ----------------------------------------------------------------------# Copyright (c) 1996 DSC Technologies Corporation# ======================================================================# Permission to use, copy, modify, distribute and license this software# and its documentation for any purpose, and without fee or written# agreement with DSC, is hereby granted, provided that the above copyright# notice appears in all copies and that both the copyright notice and# warranty disclaimer below appear in supporting documentation, and that# the names of DSC Technologies Corporation or DSC Communications# Corporation not be used in advertising or publicity pertaining to the# software without specific, written prior permission.## DSC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, AND NON-# INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND THE# AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE MAINTENANCE,# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. IN NO EVENT SHALL# DSC BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR# ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTUOUS ACTION,# ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS# SOFTWARE.# ======================================================================# Acknowledgements:## Special thanks go to Sam Shen(SLShen@lbl.gov), as this code is based on his# tkhtml.tcl code from tk inspect. The original code is copyright 1995# Lawrence Berkeley Laboratory.## This software is copyright (C) 1995 by the Lawrence Berkeley Laboratory.## Redistribution and use in source and binary forms, with or without# modification, are permitted provided that: (1) source code distributions# retain the above copyright notice and this paragraph in its entirety, (2)# distributions including binary code include the above copyright notice and# this paragraph in its entirety in the documentation or other materials# provided with the distribution, and (3) all advertising materials mentioning# features or use of this software display the following acknowledgement:# ``This product includes software developed by the University of California,# Lawrence Berkeley Laboratory and its contributors.'' Neither the name of# the University nor the names of its contributors may be used to endorse# or promote products derived from this software without specific prior# written permission.## THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.## This code is based on Angel Li's (angel@flipper.rsmas.miami.edu) HTML ## Default resources.#option add *Scrolledhtml.borderWidth 2 widgetDefaultoption add *Scrolledhtml.relief sunken widgetDefaultoption add *Scrolledhtml.scrollMargin 3 widgetDefaultoption add *Scrolledhtml.width 500 widgetDefaultoption add *Scrolledhtml.height 600 widgetDefaultoption add *Scrolledhtml.visibleItems 80x24 widgetDefaultoption add *Scrolledhtml.vscrollMode static widgetDefaultoption add *Scrolledhtml.hscrollMode static widgetDefaultoption add *Scrolledhtml.labelPos n widgetDefaultoption add *Scrolledhtml.wrap word widgetDefault## Usual options.#itk::usual Scrolledhtml { keep -fontname -fontsize -fixedfont -link -alink -linkhighlight \ -activebackground -activerelief -background -borderwidth -cursor \ -elementborderwidth -foreground -highlightcolor -highlightthickness \ -insertbackground -insertborderwidth -insertofftime -insertontime \ -insertwidth -jump -labelfont -selectbackground -selectborderwidth \ -selectforeground -textbackground -textfont -troughcolor -unknownimage}# ------------------------------------------------------------------# SCROLLEDHTML# ------------------------------------------------------------------class iwidgets::Scrolledhtml { inherit iwidgets::Scrolledtext constructor {args} {} destructor {} itk_option define -feedback feedBack FeedBack {} itk_option define -linkcommand linkCommand LinkCommand {} itk_option define -fontname fontname FontName times itk_option define -fixedfont fixedFont FixedFont courier itk_option define -fontsize fontSize FontSize medium itk_option define -link link Link blue itk_option define -alink alink ALink red itk_option define -linkhighlight alink ALink red itk_option define -unknownimage unknownimage File {} itk_option define -textbackground textBackground Background {} itk_option define -update update Update 1 itk_option define -debug debug Debug 0 public method import {args} public method clear {} public method render {html {wd .}} public method title {} {return $_title} public method pwd {} {return $_cwd} protected method _setup {} protected method _set_tag {} protected method _reconfig_tags {} protected method _append_text {text} protected method _do {text} protected method _definefont {name foundry family weight slant registry} protected method _peek {instack} protected method _push {instack value} protected method _pop {instack} protected method _parse_fields {array_var string} protected method _href_click {cmd href} protected method _set_align {align} protected method _fixtablewidth {hottext table multiplier} protected method _header {level args} protected method _/header {level} protected method _entity_a {args} protected method _entity_/a {} protected method _entity_address {} protected method _entity_/address {} protected method _entity_b {} protected method _entity_/b {} protected method _entity_base {{args {}}} protected method _entity_basefont {{args {}}} protected method _entity_big {} protected method _entity_/big {} protected method _entity_blockquote {} protected method _entity_/blockquote {} protected method _entity_body {{args {}}} protected method _entity_/body {} protected method _entity_br {{args {}}} protected method _entity_center {} protected method _entity_/center {} protected method _entity_cite {} protected method _entity_/cite {} protected method _entity_code {} protected method _entity_/code {} protected method _entity_dir {{args {}}} protected method _entity_/dir {} protected method _entity_div {{args {}}} protected method _entity_dl {{args {}}} protected method _entity_/dl {} protected method _entity_dt {} protected method _entity_dd {} protected method _entity_dfn {} protected method _entity_/dfn {} protected method _entity_em {} protected method _entity_/em {} protected method _entity_font {{args {}}} protected method _entity_/font {} protected method _entity_h1 {{args {}}} protected method _entity_/h1 {} protected method _entity_h2 {{args {}}} protected method _entity_/h2 {} protected method _entity_h3 {{args {}}} protected method _entity_/h3 {} protected method _entity_h4 {{args {}}} protected method _entity_/h4 {} protected method _entity_h5 {{args {}}} protected method _entity_/h5 {} protected method _entity_h6 {{args {}}} protected method _entity_/h6 {} protected method _entity_hr {{args {}}} protected method _entity_i {} protected method _entity_/i {} protected method _entity_img {{args {}}} protected method _entity_kbd {} protected method _entity_/kbd {} protected method _entity_li {{args {}}} protected method _entity_listing {} protected method _entity_/listing {} protected method _entity_menu {{args {}}} protected method _entity_/menu {} protected method _entity_ol {{args {}}} protected method _entity_/ol {} protected method _entity_p {{args {}}} protected method _entity_pre {{args {}}} protected method _entity_/pre {} protected method _entity_samp {} protected method _entity_/samp {} protected method _entity_small {} protected method _entity_/small {} protected method _entity_sub {} protected method _entity_/sub {} protected method _entity_sup {} protected method _entity_/sup {} protected method _entity_strong {} protected method _entity_/strong {} protected method _entity_table {{args {}}} protected method _entity_/table {} protected method _entity_td {{args {}}} protected method _entity_/td {} protected method _entity_th {{args {}}} protected method _entity_/th {} protected method _entity_title {} protected method _entity_/title {} protected method _entity_tr {{args {}}} protected method _entity_/tr {} protected method _entity_tt {} protected method _entity_/tt {} protected method _entity_u {} protected method _entity_/u {} protected method _entity_ul {{args {}}} protected method _entity_/ul {} protected method _entity_var {} protected method _entity_/var {} protected variable _title {} ;# The title of the html document protected variable _licount 1 ;# list element count protected variable _listyle bullet ;# list element style protected variable _lipic {} ;# picture to use as bullet protected variable _color black ;# current text color protected variable _bgcolor #d9d9d9 ;# current background color protected variable _link blue ;# current link color protected variable _alink red ;# current highlight link color protected variable _smallpoints "60 80 100 120 140 180 240" ;# font point protected variable _mediumpoints "80 100 120 140 180 240 360" ;# sizes for protected variable _largepoints "100 120 140 180 240 360 480" ;# various protected variable _hugepoints "120 140 180 240 360 480 640" ;# fontsizes protected variable _font times ;# name of current font protected variable _rulerheight 6 ;# protected variable _indentincr 4 ;# increment to indent by protected variable _counter -1 ;# counter to give unique numbers protected variable _left 0 ;# initial left margin protected variable _left2 0 ;# subsequent left margin protected variable _right 0 ;# right margin protected variable _justify L ;# text justification protected variable _offset 0 ;# text offset (super/subscript) protected variable _textweight 0 ;# boldness of text protected variable _textslant 0 ;# whether to use italics protected variable _underline 0 ;# whether to use underline protected variable _verbatim 0 ;# whether to skip formatting protected variable _pre 0 ;# preformatted text protected variable _intitle 0 ;# in <title>...</title> protected variable _anchorcount 0 ;# number of anchors protected variable _stack ;# array of stacks protected variable _pointsndx 2 ;# protected variable _fontnames ;# list of accepted font names protected variable _fontinfo ;# array of font info given font name protected variable _tag ;# protected variable _tagl ;# protected variable _tagfont ;# protected variable _cwd . ;# base directory of current page protected variable _anchor ;# array of indexes by anchorname protected variable _defaulttextbackground;# default text background protected variable _intable 0 ;# whether we are in a table now protected variable _hottext ;# widget where text currently goes protected variable _basefontsize 2 ;# as named protected variable _unknownimg {} ;# name of unknown image protected variable _images {} ;# list of images we created protected variable _prevpos {} ;# temporary used for table updates protected variable _prevtext {} ;# temporary used for table updates private variable _initialized 0 private variable _defUnknownImg [::image create photo -data {R0lGODdhHwAgAPQAAP///wAAAMzMzC9PT76+vvnTogCR/1WRVaoAVf//qvT09OKdcWlcx19fX9/f339/f8vN/J2d/aq2qoKCggAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACwAAAAAHwAgAAAF/iAgjqRDnmiKmqOkqsTaToDjvudTttLjOITJbTQhGI+iQE0xMvZqQIDwNAEiAcqRVdKAGh0NyVCkuyqZBEmwofgRrFIxSaI0JmuA9KTrthIicWMTAQ8xWHgSe15AVgcJeVMjDwECOkome22Mb0cHCzEPOiQPgwGXCjomakedA0VgY1IPDZcuP3l5YkcRDwMHqDQoEzq2Pz8IQkK7Bw8HDg+xO26PCAgRDcpGswEK2Dh9ItUMDdirPYUKwTKMjwDV1gHlR2oCkSmcI9UEBabYrGnQoolgBCGckX7yWJWDYaUMAYSRFECAwMXeiU1BHpKTB4CBR4+oBOb5By1UNgUfXj0C8HaP079sBCCkZIAKWst/OGPOhNBNHQmXOeftJBASRVCcEiIojQDBwIOeRo+SpGXKFFGbP6XinLWxEMsmWpEOC9XDYtigYtKSwsH2xdq2cEfRmFS1rt27eE09CAEAOw==}]}## Provide a lowercased access method for the Scrolledhtml class.#proc ::iwidgets::scrolledhtml {pathName args} { uplevel ::iwidgets::Scrolledhtml $pathName $args}# ------------------------------------------------------------------# CONSTRUCTOR# ------------------------------------------------------------------body iwidgets::Scrolledhtml::constructor {args} { # define the fonts we're going to use set _fontnames "" _definefont helvetica adobe helvetica "medium bold" "r o" iso8859 _definefont courier adobe courier "medium bold" "r o" iso8859 _definefont times adobe times "medium bold" "r i" iso8859 _definefont symbol adobe symbol "medium medium" "r r" adobe $itk_component(text) configure -state disabled eval itk_initialize $args if {[lsearch -exact $args -linkcommand] == -1} { configure -linkcommand [code $this import -link] } set _initialized 1}# ------------------------------------------------------------------# DESTRUCTOR# ------------------------------------------------------------------body iwidgets::Scrolledhtml::destructor {} { foreach x $_images { ::image delete $x } if {$_unknownimg != $_defUnknownImg} { ::image delete $_unknownimg }}# ------------------------------------------------------------------# OPTIONS# ------------------------------------------------------------------ # ------------------------------------------------------------------# OPTION: -fontsize## Set the general size of the font.# ------------------------------------------------------------------configbody iwidgets::Scrolledhtml::fontsize { switch $itk_option(-fontsize) { small { } medium { } large { } huge { } default { error "bad fontsize option\ \"$itk_option(-fontsize)\": should\ be small, medium, large, or huge" } } _reconfig_tags}# ------------------------------------------------------------------# OPTION: -fixedfont## Set the fixed font name# ------------------------------------------------------------------configbody iwidgets::Scrolledhtml::fixedfont { if {[lsearch -exact $_fontnames $itk_option(-fixedfont)] == -1} { error "Invalid font name \"$itk_option(-fixedfont)\". Must be one of \ $_fontnames" }}# ------------------------------------------------------------------# OPTION: -fontname## Set the default font name# ------------------------------------------------------------------configbody iwidgets::Scrolledhtml::fontname { if {[lsearch -exact $_fontnames $itk_option(-fontname)] == -1} { error "Invalid font name \"$itk_option(-fontname)\". Must be one of \ $_fontnames" }}# ------------------------------------------------------------------# OPTION: -textbackground#
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -