OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [start/] [insight/] [itcl/] [iwidgets3.0.0/] [generic/] [scrolledhtml.itk] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
# Scrolledhtml
2
# ----------------------------------------------------------------------
3
# Implements a scrolled html text widget by inheritance from scrolledtext
4
# Import reads from an html file, while export still writes plain text
5
# Also provides a render command, to display html text passed in as an
6
# argument.
7
#
8
# This widget is HTML3.2 compliant, with the following exceptions:
9
#   a) nothing requiring a connection to an HTTP server is supported
10
#   b) some of the image alignments aren't supported, because they're not
11
#      supported by the text widget
12
#   c) the br attributes that go with the image alignments aren't implemented
13
#   d) background images are not supported, because they're not supported
14
#      by the text widget
15
#   e) automatic table/table cell sizing doesn't work very well.
16
#
17
# WISH LIST:
18
#   This section lists possible future enhancements.
19
#
20
#   1) size tables better using dlineinfo.
21
#   2) make images scroll smoothly off top like they do off bottom. (limitation
22
#      of text widget?)
23
#   3) add ability to get non-local URLs
24
#       a) support forms
25
#       b) support imagemaps
26
#   4) keep track of visited links
27
#   5) add tclets support
28
#
29
# BUGS:
30
#   Cells in a table can be caused to overlap. ex:
31
#      
32
#      
cell1cell2
33
#      
cell3 w/ overlap
34
#      
35
#   It hasn't been fixed because 1) it's a pain to fix, 2) the fix would slow
36
#   tables down by a significant amount, and 3) netscape has the same
37
#   bug, as of V3.01, and no one seems to care.
38
#
39
#   In order to size tables properly, they must be visible, which causes an
40
#   annoying jump from table to table through the document at render time.
41
#
42
# ----------------------------------------------------------------------
43
#  AUTHOR: Kris Raney                    EMAIL: kraney@spd.dsccc.com
44
#
45
#  @(#) $Id: scrolledhtml.itk,v 1.1.1.1 2002-01-16 10:24:50 markom Exp $
46
# ----------------------------------------------------------------------
47
#            Copyright (c) 1996 DSC Technologies Corporation
48
# ======================================================================
49
# Permission to use, copy, modify, distribute and license this software
50
# and its documentation for any purpose, and without fee or written
51
# agreement with DSC, is hereby granted, provided that the above copyright
52
# notice appears in all copies and that both the copyright notice and
53
# warranty disclaimer below appear in supporting documentation, and that
54
# the names of DSC Technologies Corporation or DSC Communications
55
# Corporation not be used in advertising or publicity pertaining to the
56
# software without specific, written prior permission.
57
#
58
# DSC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
59
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, AND NON-
60
# INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND THE
61
# AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE MAINTENANCE,
62
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. IN NO EVENT SHALL
63
# DSC BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
64
# ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
65
# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTUOUS ACTION,
66
# ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
67
# SOFTWARE.
68
# ======================================================================
69
 
70
# Acknowledgements:
71
#
72
# Special thanks go to Sam Shen(SLShen@lbl.gov), as this code is based on his
73
# tkhtml.tcl code from tk inspect. The original code is copyright 1995
74
# Lawrence Berkeley Laboratory.
75
#
76
# This software is copyright (C) 1995 by the Lawrence Berkeley Laboratory.
77
#
78
# Redistribution and use in source and binary forms, with or without
79
# modification, are permitted provided that: (1) source code distributions
80
# retain the above copyright notice and this paragraph in its entirety, (2)
81
# distributions including binary code include the above copyright notice and
82
# this paragraph in its entirety in the documentation or other materials
83
# provided with the distribution, and (3) all advertising materials mentioning
84
# features or use of this software display the following acknowledgement:
85
# ``This product includes software developed by the University of California,
86
# Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
87
# the University nor the names of its contributors may be used to endorse
88
# or promote products derived from this software without specific prior
89
# written permission.
90
#
91
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
92
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
93
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
94
#
95
# This code is based on Angel Li's (angel@flipper.rsmas.miami.edu) HTML
96
 
97
 
98
#
99
# Default resources.
100
#
101
option add *Scrolledhtml.borderWidth 2 widgetDefault
102
option add *Scrolledhtml.relief sunken widgetDefault
103
option add *Scrolledhtml.scrollMargin 3 widgetDefault
104
option add *Scrolledhtml.width 500 widgetDefault
105
option add *Scrolledhtml.height 600 widgetDefault
106
option add *Scrolledhtml.visibleItems 80x24 widgetDefault
107
option add *Scrolledhtml.vscrollMode static widgetDefault
108
option add *Scrolledhtml.hscrollMode static widgetDefault
109
option add *Scrolledhtml.labelPos n widgetDefault
110
option add *Scrolledhtml.wrap word widgetDefault
111
 
112
#
113
# Usual options.
114
#
115
itk::usual Scrolledhtml {
116
    keep -fontname -fontsize -fixedfont -link -alink -linkhighlight \
117
         -activebackground -activerelief -background -borderwidth -cursor \
118
         -elementborderwidth -foreground -highlightcolor -highlightthickness \
119
         -insertbackground -insertborderwidth -insertofftime -insertontime \
120
         -insertwidth -jump -labelfont -selectbackground -selectborderwidth \
121
         -selectforeground -textbackground -textfont -troughcolor -unknownimage
122
}
123
 
124
# ------------------------------------------------------------------
125
#                           SCROLLEDHTML
126
# ------------------------------------------------------------------
127
class iwidgets::Scrolledhtml {
128
  inherit iwidgets::Scrolledtext
129
 
130
  constructor {args} {}
131
  destructor {}
132
 
133
  itk_option define -feedback feedBack FeedBack {}
134
  itk_option define -linkcommand linkCommand LinkCommand {}
135
  itk_option define -fontname fontname FontName times
136
  itk_option define -fixedfont fixedFont FixedFont courier
137
  itk_option define -fontsize fontSize FontSize medium
138
  itk_option define -link link Link blue
139
  itk_option define -alink alink ALink red
140
  itk_option define -linkhighlight alink ALink red
141
  itk_option define -unknownimage unknownimage File {}
142
  itk_option define -textbackground textBackground Background {}
143
  itk_option define -update update Update 1
144
 
145
  public method import {args}
146
  public method clear {}
147
  public method render {html {wd .}}
148
  public method title {} {return $_title}
149
  public method pwd {} {return $_cwd}
150
 
151
  protected method _setup {}
152
  protected method _set_tag {}
153
  protected method _reconfig_tags {}
154
  protected method _append_text {text}
155
  protected method _do {text}
156
  protected method _definefont {name foundry family weight slant registry}
157
  protected method _peek {instack}
158
  protected method _push {instack value}
159
  protected method _pop {instack}
160
  protected method _parse_fields {array_var string}
161
  protected method _href_click {cmd href}
162
  protected method _set_align {align}
163
  protected method _fixtablewidth {hottext table multiplier}
164
 
165
  protected method _header {level args}
166
  protected method _/header {level}
167
 
168
  protected method _entity_a {args}
169
  protected method _entity_/a {}
170
  protected method _entity_address {}
171
  protected method _entity_/address {}
172
  protected method _entity_b {}
173
  protected method _entity_/b {}
174
  protected method _entity_base {{args {}}}
175
  protected method _entity_basefont {{args {}}}
176
  protected method _entity_big {}
177
  protected method _entity_/big {}
178
  protected method _entity_blockquote {}
179
  protected method _entity_/blockquote {}
180
  protected method _entity_body {{args {}}}
181
  protected method _entity_/body {}
182
  protected method _entity_br {{args {}}}
183
  protected method _entity_center {}
184
  protected method _entity_/center {}
185
  protected method _entity_cite {}
186
  protected method _entity_/cite {}
187
  protected method _entity_code {}
188
  protected method _entity_/code {}
189
  protected method _entity_dir {{args {}}}
190
  protected method _entity_/dir {}
191
  protected method _entity_div {{args {}}}
192
  protected method _entity_dl {{args {}}}
193
  protected method _entity_/dl {}
194
  protected method _entity_dt {}
195
  protected method _entity_dd {}
196
  protected method _entity_dfn {}
197
  protected method _entity_/dfn {}
198
  protected method _entity_em {}
199
  protected method _entity_/em {}
200
  protected method _entity_font {{args {}}}
201
  protected method _entity_/font {}
202
  protected method _entity_h1 {{args {}}}
203
  protected method _entity_/h1 {}
204
  protected method _entity_h2 {{args {}}}
205
  protected method _entity_/h2 {}
206
  protected method _entity_h3 {{args {}}}
207
  protected method _entity_/h3 {}
208
  protected method _entity_h4 {{args {}}}
209
  protected method _entity_/h4 {}
210
  protected method _entity_h5 {{args {}}}
211
  protected method _entity_/h5 {}
212
  protected method _entity_h6 {{args {}}}
213
  protected method _entity_/h6 {}
214
  protected method _entity_hr {{args {}}}
215
  protected method _entity_i {}
216
  protected method _entity_/i {}
217
  protected method _entity_img {{args {}}}
218
  protected method _entity_kbd {}
219
  protected method _entity_/kbd {}
220
  protected method _entity_li {{args {}}}
221
  protected method _entity_listing {}
222
  protected method _entity_/listing {}
223
  protected method _entity_menu {{args {}}}
224
  protected method _entity_/menu {}
225
  protected method _entity_ol {{args {}}}
226
  protected method _entity_/ol {}
227
  protected method _entity_p {{args {}}}
228
  protected method _entity_pre {{args {}}}
229
  protected method _entity_/pre {}
230
  protected method _entity_samp {}
231
  protected method _entity_/samp {}
232
  protected method _entity_small {}
233
  protected method _entity_/small {}
234
  protected method _entity_sub {}
235
  protected method _entity_/sub {}
236
  protected method _entity_sup {}
237
  protected method _entity_/sup {}
238
  protected method _entity_strong {}
239
  protected method _entity_/strong {}
240
  protected method _entity_table {{args {}}}
241
  protected method _entity_/table {}
242
  protected method _entity_td {{args {}}}
243
  protected method _entity_/td {}
244
  protected method _entity_th {{args {}}}
245
  protected method _entity_/th {}
246
  protected method _entity_title {}
247
  protected method _entity_/title {}
248
  protected method _entity_tr {{args {}}}
249
  protected method _entity_/tr {}
250
  protected method _entity_tt {}
251
  protected method _entity_/tt {}
252
  protected method _entity_u {}
253
  protected method _entity_/u {}
254
  protected method _entity_ul {{args {}}}
255
  protected method _entity_/ul {}
256
  protected method _entity_var {}
257
  protected method _entity_/var {}
258
 
259
  protected variable _title {}             ;# The title of the html document
260
  protected variable _licount 1            ;# list element count
261
  protected variable _listyle bullet       ;# list element style
262
  protected variable _lipic {}             ;# picture to use as bullet
263
  protected variable _color black          ;# current text color
264
  protected variable _bgcolor #d9d9d9      ;# current background color
265
  protected variable _link blue            ;# current link color
266
  protected variable _alink red            ;# current highlight link color
267
  protected variable _smallpoints "60 80 100 120 140 180 240"   ;# font point
268
  protected variable _mediumpoints "80 100 120 140 180 240 360" ;# sizes for
269
  protected variable _largepoints "100 120 140 180 240 360 480" ;# various
270
  protected variable _hugepoints "120 140 180 240 360 480 640"  ;# fontsizes
271
  protected variable _font times           ;# name of current font
272
  protected variable _rulerheight 6        ;#
273
  protected variable _indentincr 4         ;# increment to indent by
274
  protected variable _counter -1           ;# counter to give unique numbers
275
  protected variable _left 0               ;# initial left margin
276
  protected variable _left2 0              ;# subsequent left margin
277
  protected variable _right 0              ;# right margin
278
  protected variable _justify L            ;# text justification
279
  protected variable _offset 0             ;# text offset (super/subscript)
280
  protected variable _textweight 0         ;# boldness of text
281
  protected variable _textslant 0          ;# whether to use italics
282
  protected variable _underline 0          ;# whether to use underline
283
  protected variable _verbatim 0           ;# whether to skip formatting
284
  protected variable _pre 0                ;# preformatted text
285
  protected variable _intitle 0            ;# in ...
286
  protected variable _anchorcount 0        ;# number of anchors
287
  protected variable _stack                ;# array of stacks
288
  protected variable _pointsndx 2          ;#
289
  protected variable _fontnames            ;# list of accepted font names
290
  protected variable _fontinfo             ;# array of font info given font name
291
  protected variable _tag                  ;#
292
  protected variable _tagl                 ;#
293
  protected variable _tagfont              ;#
294
  protected variable _cwd .                ;# base directory of current page
295
  protected variable _anchor               ;# array of indexes by anchorname
296
  protected variable _defaulttextbackground;# default text background
297
  protected variable _intable 0            ;# whether we are in a table now
298
  protected variable _hottext              ;# widget where text currently goes
299
  protected variable _basefontsize 2       ;# as named
300
  protected variable _unknownimg {}        ;# name of unknown image
301
  protected variable _images {}            ;# list of images we created
302
  protected variable _prevpos {}           ;# temporary used for table updates
303
  protected variable _prevtext {}          ;# temporary used for table updates
304
 
305
  private variable _initialized 0
306
 
307
  private variable _defUnknownImg [image create photo -data {
308
R0lGODdhHwAgAPQAAP///wAAAMzMzC9PT76+vvnTogCR/1WRVaoAVf//qvT09OKdcWlcx19f
309
X9/f339/f8vN/J2d/aq2qoKCggAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
310
ACwAAAAAHwAgAAAF/iAgjqRDnmiKmqOkqsTaToDjvudTttLjOITJbTQhGI+iQE0xMvZqQIDw
311
NAEiAcqRVdKAGh0NyVCkuyqZBEmwofgRrFIxSaI0JmuA9KTrthIicWMTAQ8xWHgSe15AVgcJ
312
eVMjDwECOkome22Mb0cHCzEPOiQPgwGXCjomakedA0VgY1IPDZcuP3l5YkcRDwMHqDQoEzq2
313
Pz8IQkK7Bw8HDg+xO26PCAgRDcpGswEK2Dh9ItUMDdirPYUKwTKMjwDV1gHlR2oCkSmcI9UE
314
BabYrGnQoolgBCGckX7yWJWDYaUMAYSRFECAwMXeiU1BHpKTB4CBR4+oBOb5By1UNgUfXj0C
315
8HaP079sBCCkZIAKWst/OGPOhNBNHQmXOeftJBASRVCcEiIojQDBwIOeRo+SpGXKFFGbP6Xi
316
nLWxEMsmWpEOC9XDYtigYtKSwsH2xdq2cEfRmFS1rt27eE09CAEAOw==
317
}]
318
}
319
 
320
#
321
# Provide a lowercased access method for the Scrolledhtml class.
322
#
323
proc ::iwidgets::scrolledhtml {pathName args} {
324
    uplevel ::iwidgets::Scrolledhtml $pathName $args
325
}
326
 
327
# ------------------------------------------------------------------
328
#                        CONSTRUCTOR
329
# ------------------------------------------------------------------
330
body iwidgets::Scrolledhtml::constructor {args} {
331
  # define the fonts we're going to use
332
  set _fontnames ""
333
  _definefont helvetica adobe helvetica "medium bold" "r o" iso8859
334
  _definefont courier adobe courier "medium bold" "r o" iso8859
335
  _definefont times adobe times "medium bold" "r i" iso8859
336
  _definefont symbol adobe symbol "medium medium" "r r" adobe
337
 
338
  $itk_component(text) configure -state disabled
339
 
340
  eval itk_initialize $args
341
  if {[lsearch -exact $args -linkcommand] == -1} {
342
    configure -linkcommand [code $this import -link]
343
  }
344
  set _initialized 1
345
}
346
 
347
# ------------------------------------------------------------------
348
#                        DESTRUCTOR
349
# ------------------------------------------------------------------
350
body iwidgets::Scrolledhtml::destructor {} {
351
    foreach x $_images {
352
      image delete $x
353
    }
354
    if {$_unknownimg != $_defUnknownImg} {
355
      image delete $_unknownimg
356
    }
357
}
358
 
359
# ------------------------------------------------------------------
360
#                             OPTIONS
361
# ------------------------------------------------------------------
362
 
363
# ------------------------------------------------------------------
364
# OPTION: -fontsize
365
#
366
# Set the general size of the font.
367
# ------------------------------------------------------------------
368
configbody iwidgets::Scrolledhtml::fontsize {
369
    switch $itk_option(-fontsize) {
370
        small { }
371
        medium { }
372
        large { }
373
        huge { }
374
        default {
375
            error "bad fontsize option\
376
                   \"$itk_option(-fontsize)\": should\
377
                   be small, medium, large, or huge"
378
        }
379
    }
380
    _reconfig_tags
381
}
382
 
383
# ------------------------------------------------------------------
384
# OPTION: -fixedfont
385
#
386
# Set the fixed font name
387
# ------------------------------------------------------------------
388
configbody iwidgets::Scrolledhtml::fixedfont {
389
   if {[lsearch -exact $_fontnames $itk_option(-fixedfont)] == -1} {
390
     error "Invalid font name \"$itk_option(-fixedfont)\". Must be one of \
391
         $_fontnames"
392
  }
393
}
394
 
395
# ------------------------------------------------------------------
396
# OPTION: -fontname
397
#
398
# Set the default font name
399
# ------------------------------------------------------------------
400
configbody iwidgets::Scrolledhtml::fontname {
401
   if {[lsearch -exact $_fontnames $itk_option(-fontname)] == -1} {
402
     error "Invalid font name \"$itk_option(-fontname)\". Must be one of \
403
         $_fontnames"
404
  }
405
}
406
 
407
# ------------------------------------------------------------------
408
# OPTION: -textbackground
409
#
410
# Set the default text background
411
# ------------------------------------------------------------------
412
configbody iwidgets::Scrolledhtml::textbackground {
413
  set _defaulttextbackground $itk_option(-textbackground)
414
}
415
 
416
# ------------------------------------------------------------------
417
# OPTION: -linkhighlight
418
#
419
# same as alink
420
# ------------------------------------------------------------------
421
configbody iwidgets::Scrolledhtml::linkhighlight {
422
  configure -alink $itk_option(-linkhighlight)
423
}
424
 
425
# ------------------------------------------------------------------
426
# OPTION: -unknownimage
427
#
428
# set image to use as substitute for images that aren't found
429
# ------------------------------------------------------------------
430
configbody iwidgets::Scrolledhtml::unknownimage {
431
   set oldimage $_unknownimg
432
   if {$itk_option(-unknownimage) != {}} {
433
      set uki $itk_option(-unknownimage)
434
      if [catch { set _unknownimg [image create photo -file $uki] } err] {
435
         error "Couldn't create image $uki:\n$err\nUnknown image not found"
436
      }
437
   } else {
438
      set _unknownimg $_defUnknownImg
439
   }
440
   if {$oldimage != {} && $oldimage != $_defUnknownImg} {
441
      image delete $oldimage
442
   }
443
}
444
 
445
# ------------------------------------------------------------------
446
# OPTION: -update
447
#
448
# boolean indicating whether to update during rendering
449
# ------------------------------------------------------------------
450
configbody iwidgets::Scrolledhtml::update {
451
   switch -- $itk_option(-update) {
452
 
453
     1 {}
454
     true {
455
       configure -update 1
456
     }
457
     yes {
458
       configure -update 1
459
     }
460
     false {
461
       configure -update 0
462
     }
463
     yes {
464
       configure -update 0
465
     }
466
     default {
467
       error "invalid -update; must be boolean"
468
     }
469
   }
470
}
471
 
472
# ------------------------------------------------------------------
473
#                            METHODS
474
# ------------------------------------------------------------------
475
 
476
# ------------------------------------------------------------------
477
# METHOD: clear
478
#
479
# Clears the text out
480
# ------------------------------------------------------------------
481
body iwidgets::Scrolledhtml::clear {} {
482
    $itk_component(text) config -state normal
483
    $itk_component(text) delete 1.0 end
484
    foreach x $_images {
485
      image delete $x
486
    }
487
    set _images {}
488
    _setup
489
    $itk_component(text) config -state disabled
490
}
491
 
492
# ------------------------------------------------------------------
493
# METHOD import ?-link? filename?#anchorname?
494
#
495
# read html text from a file (import filename) if the keyword link is present,
496
# pathname is relative to last page, otherwise it is relative to current
497
# directory. This allows the user to use a linkcommand of
498
# " import -link"
499
#
500
# if '#anchorname' is appended to the filename, the page is displayed starting
501
# at the anchor named 'anchorname' If an anchor is specified without a filename,
502
# the current page is assumed.
503
# ------------------------------------------------------------------
504
body iwidgets::Scrolledhtml::import {args} {
505
  set len [llength $args]
506
  if {$len != 1 && $len != 2} {
507
      error "wrong # args: should be \
508
              \"$itk_component(hull) import ?-link? filename\""
509
  }
510
  set linkname [lindex $args [expr $len - 1]]
511
 
512
  #
513
  # Seperate filename#anchorname
514
  #
515
  if ![regexp {(.*)#(.*)} $linkname dummy filename anchorname] {
516
    set filename $linkname
517
  }
518
  if {$filename!=""} {
519
    #
520
    # Check for -link option
521
    #
522
    switch -- $len {
523
      1 {
524
        #
525
        # open file & set cwd to that file's directory
526
        #
527
        set f [open $filename r]
528
        set _cwd [file dirname $filename]
529
      }
530
      2 {
531
        switch -- [lindex $args 0] {
532
          -link {
533
              #
534
              # got -link, so set path relative to current locale, if path
535
              # is a relative pathname
536
              #
537
              if {[string compare "." [file dirname $filename]] == 0} {
538
                set f [open $_cwd/$filename r]
539
              } else {
540
                if {[string index [file dirname $filename] 0] != "/" &&\
541
                    [string index [file dirname $filename] 0] != "~"} {
542
                  set f [open $_cwd/$filename r]
543
                  append _cwd /
544
                  append _cwd [file dirname $filename]
545
                } else {
546
                  set f [open $filename r]
547
g                  set _cwd [file dirname $filename]
548
                }
549
              }
550
          }
551
          default {
552
            # got something other than -link
553
            error "invalid format: should be \
554
                  \"$itk_component(hull) import ?-link? filename\""
555
          }
556
        }
557
      }
558
    }
559
    set txt [read $f]
560
    close $f
561
    render $txt $_cwd
562
  }
563
 
564
  #
565
  # if an anchor was requested, move that anchor into view
566
  #
567
  if [ info exists anchorname] {
568
    if {$anchorname!=""} {
569
      if [info exists _anchor($anchorname)] {
570
        $itk_component(text) see end
571
        $itk_component(text) see $_anchor($anchorname)
572
      }
573
    } else {
574
      $itk_component(text) see 0.0
575
    }
576
  }
577
}
578
 
579
# ------------------------------------------------------------------
580
# METHOD: render text ?wd?
581
#
582
# Clear the text, then render html formatted text. Optional wd argument
583
# sets the base directory for any links or images.
584
# ------------------------------------------------------------------
585
body iwidgets::Scrolledhtml::render {html {wd .}} {
586
    #
587
    # blank text and reset all state variables
588
    #
589
    clear
590
    set _cwd $wd
591
 
592
    #
593
    # make text writable
594
    #
595
    $itk_component(text) config -state normal
596
    set continuerendering 1
597
    _set_tag
598
    while {$continuerendering} {
599
        # normal state
600
        while {[set len [string length $html]]} {
601
            # look for text up to the next <> element
602
            if [regexp -indices "^\[^<\]+" $html match] {
603
                set text [string range $html 0 [lindex $match 1]]
604
                _append_text "$text"
605
                set html \
606
                    [string range $html [expr [lindex $match 1]+1] end]
607
            }
608
            # we're either at a <>, or at the eot
609
            if [regexp -indices "^<((\[^>\"\]+|(\"\[^\"\]*\"))*)>" $html match entity] {
610
                regsub -all "\n" [string range $html [lindex $entity 0] \
611
                            [lindex $entity 1]] "" entity
612
                set cmd [string tolower [lindex $entity 0]]
613
                if {[info command _entity_$cmd]!=""} {
614
                    catch {eval _entity_$cmd [lrange $entity 1 end]}
615
                }
616
                set html \
617
                    [string range $html [expr [lindex $match 1]+1] end]
618
            }
619
            if {$itk_option(-feedback) != {} } {
620
              eval $itk_option(-feedback) $len
621
            }
622
            if $_verbatim break
623
        }
624
        # we reach here if html is empty, or _verbatim is 1
625
        if !$len break
626
        # _verbatim must be 1
627
        # append text until next tag is reached
628
        if [regexp -indices "<.*>" $html match] {
629
            set text [string range $html 0 [expr [lindex $match 0]-1]]
630
            set html [string range $html [expr [lindex $match 0]] end]
631
        } else {
632
            set text $html
633
            set html ""
634
        }
635
        _append_text "$text"
636
    }
637
    $itk_component(text) config -state disabled
638
}
639
 
640
# ------------------------------------------------------------------
641
# PRIVATE METHOD: _setup
642
#
643
# Reset all state variables to prepare for a new page.
644
# ------------------------------------------------------------------
645
body iwidgets::Scrolledhtml::_setup {} {
646
    set _font $itk_option(-fontname)
647
    set _left 0
648
    set _left2 0
649
    set _right 0
650
    set _justify L
651
    set _textweight 0
652
    set _textslant 0
653
    set _underline 0
654
    set _verbatim 0
655
    set _pre 0
656
    set _title {}
657
    set _intitle 0
658
    set _anchorcount 0
659
    set _intable 0
660
    set _hottext $itk_component(text)
661
    set _stack(font) {}
662
    set _stack(color) {}
663
    set _stack(bgcolor) {}
664
    set _stack(link) {}
665
    set _stack(alink) {}
666
    set _stack(justify) {}
667
    set _stack(listyle) {}
668
    set _stack(lipic) {}
669
    set _stack(href) {}
670
    set _stack(pointsndx) {}
671
    set _stack(left) {}
672
    set _stack(left2) {}
673
    set _stack(offset) {}
674
    set _stack(table) {}
675
    set _stack(tablewidth) {}
676
    set _stack(row) {}
677
    set _stack(column) {}
678
    set _stack(hottext) {}
679
    set _stack(tableborder) {}
680
    set _stack(cellpadding) {}
681
    set _stack(cellspacing) {}
682
    set _stack(licount) {}
683
    set _basefontsize 2
684
    set _pointsndx 2
685
    set _counter -1
686
    set _bgcolor $_defaulttextbackground
687
    set _color $itk_option(-foreground)
688
    set _link $itk_option(-link)
689
    set _alink $itk_option(-alink)
690
    config -textbackground $_bgcolor
691
    foreach x [array names _anchor] { unset _anchor($x) }
692
    $itk_component(text) tag config hr -relief sunken -borderwidth 2 \
693
            -font -*-*-*-*-*-*-$_rulerheight-*-*-*-*-*-*-*
694
}
695
 
696
# ------------------------------------------------------------------
697
# PRIVATE METHOD: _definefont name foundry family weight slant registry
698
#
699
# define font information used to generate font value from font name
700
# ------------------------------------------------------------------
701
body iwidgets::Scrolledhtml::_definefont \
702
            {name foundry family weight slant registry} {
703
    if {[lsearch -exact $_fontnames $name] == -1 } {
704
      lappend _fontnames $name
705
    }
706
    set _fontinfo($name) \
707
        [list $foundry $family $weight $slant $registry]
708
}
709
 
710
# ------------------------------------------------------------------
711
# PRIVATE METHOD: _append_text text
712
#
713
# append text in the format described by the state variables
714
# ------------------------------------------------------------------
715
body iwidgets::Scrolledhtml::_append_text {text} {
716
    if {!$_intable && $itk_option(-update)} {update}
717
    if {[string first "&" $text] != -1} {
718
       regsub -nocase -all "&" $text {\&} text
719
       regsub -nocase -all "<" $text "<" text
720
       regsub -nocase -all ">" $text ">" text
721
       regsub -nocase -all """ $text "\"" text
722
    }
723
    if !$_verbatim {
724
        if !$_pre {
725
            set text [string trim $text "\n\r"]
726
            regsub -all "\[ \n\r\t\]+" $text " " text
727
        }
728
        if ![string length $text] return
729
    }
730
    if {!$_pre && !$_intitle} {
731
        set p [$_hottext get "end - 2c"]
732
        set n [string index $text 0]
733
        if {$n == " " && $p == " "} {
734
          set text [string range $text 1 end]
735
        }
736
        $_hottext insert end $text $_tag
737
        return
738
    }
739
    if {$_pre && !$_intitle} {
740
        $_hottext insert end $text $_tag
741
        return
742
    }
743
    append _title $text
744
}
745
 
746
# ------------------------------------------------------------------
747
# PRIVATE METHOD: _set_tag
748
#
749
# generate a tag
750
# ------------------------------------------------------------------
751
# a tag is constructed as: font?B?I?U?Points-LeftLeft2RightColorJustify
752
body iwidgets::Scrolledhtml::_set_tag {} {
753
    set i -1
754
    foreach var {foundry family weight slant registry} {
755
        set $var [lindex $_fontinfo($_font) \
756
               [incr i]]
757
    }
758
    set x_font "-$foundry-$family-"
759
    set _tag $_font
760
    set args {}
761
    if {$_textweight > 0} {
762
        append _tag "B"
763
        append x_font [lindex $weight 1]-
764
    } else {
765
        append x_font [lindex $weight 0]-
766
    }
767
    if {$_textslant > 0} {
768
        append _tag "I"
769
        append x_font [lindex $slant 1]-
770
    } else {
771
        append x_font [lindex $slant 0]-
772
    }
773
    if {$_underline > 0} {
774
        append _tag "U"
775
        append args " -underline 1"
776
    }
777
    switch $_justify {
778
        L { append args " -justify left" }
779
        R { append args " -justify right" }
780
        C { append args " -justify center" }
781
    }
782
    append args " -offset $_offset"
783
 
784
    set pts [lindex [set [format "_%spoints" $itk_option(-fontsize)]] \
785
                  $_pointsndx]
786
    append _tag $_pointsndx - $_left \
787
        $_left2 $_right \
788
        $_color $_justify
789
    append x_font "normal-*-*-$pts-*-*-*-*-$registry-*"
790
    if $_anchorcount {
791
        set href [_peek href]
792
        set href_tag href[incr _counter]
793
        set tags [list $_tag $href_tag]
794
        if { $itk_option(-linkcommand)!= {} } {
795
            $_hottext tag bind $href_tag <1> \
796
                [list uplevel #0 $itk_option(-linkcommand) $href]
797
        }
798
        $_hottext tag bind $href_tag  \
799
            [list $_hottext tag configure $href_tag \
800
                  -foreground $_alink]
801
        $_hottext tag bind $href_tag  \
802
            [list $_hottext tag configure $href_tag \
803
             -foreground $_color]
804
    } else {
805
        set tags $_tag
806
    }
807
    if {![info exists _tagl($_tag)]} {
808
        set _tagfont($_tag) 1
809
        eval $_hottext tag configure $_tag \
810
            -foreground $_color \
811
            -lmargin1 ${_left}m \
812
            -lmargin2 ${_left2}m $args
813
        if [catch {eval $_hottext tag configure $_tag \
814
            -font $x_font} err] {
815
          _definefont $_font * $family $weight $slant *
816
          regsub \$foundry $x_font * x_font
817
          regsub \$registry $x_font * x_font
818
          catch {eval $_hottext tag configure $_tag -font $x_font}
819
        }
820
    }
821
    if [info exists href_tag] {
822
        $_hottext tag raise $href_tag $_tag
823
    }
824
    set _tag $tags
825
}
826
 
827
# ------------------------------------------------------------------
828
# PRIVATE METHOD: _reconfig_tags
829
#
830
# reconfigure tags following a configuration change
831
# ------------------------------------------------------------------
832
body iwidgets::Scrolledhtml::_reconfig_tags {} {
833
  if $_initialized {
834
    foreach tag [$itk_component(text) tag names] {
835
        foreach efont $_fontnames {
836
            if [regexp "${efont}(B?)(I?)(U?)(\[1-9\]\[0-9\]*)-" $tag t b i u points] {
837
                set j -1
838
                set _font $efont
839
                foreach var {foundry family weight slant registry} {
840
                    set $var [lindex $_fontinfo($_font) [incr j]]
841
                }
842
                set x_font "-$foundry-$family-"
843
                if {$b == "B"} {
844
                    append x_font [lindex $weight 1]-
845
                } else {
846
                    append x_font [lindex $weight 0]-
847
                }
848
                if {$i == "I"} {
849
                    append x_font [lindex $slant 1]-
850
                } else {
851
                    append x_font [lindex $slant 0]-
852
                }
853
                set pts [lindex [set [format \
854
                     "_%spoints" $itk_option(-fontsize)]] $points]
855
                append x_font "normal-*-*-$pts-*-*-*-*-$registry-*"
856
                $itk_component(text) tag config $tag -font $x_font
857
                break
858
            }
859
        }
860
    }
861
  }
862
}
863
 
864
# ------------------------------------------------------------------
865
# PRIVATE METHOD: _push instack value
866
#
867
# push value onto stack(instack)
868
# ------------------------------------------------------------------
869
body iwidgets::Scrolledhtml::_push {instack value} {
870
    set _stack($instack) [linsert $_stack($instack) 0 $value]
871
}
872
 
873
# ------------------------------------------------------------------
874
# PRIVATE METHOD: _pop instack
875
#
876
# pop value from stack(instack)
877
# ------------------------------------------------------------------
878
body iwidgets::Scrolledhtml::_pop {instack} {
879
    if {$_stack($instack) == ""} {
880
        error "popping empty _stack $instack"
881
    }
882
    set val [lindex $_stack($instack) 0]
883
    set _stack($instack) [lrange $_stack($instack) 1 end]
884
    return $val
885
}
886
 
887
# ------------------------------------------------------------------
888
# PRIVATE METHOD: _peek instack
889
#
890
# peek at top value on stack(instack)
891
# ------------------------------------------------------------------
892
body iwidgets::Scrolledhtml::_peek {instack} {
893
    return [lindex $_stack($instack) 0]
894
}
895
 
896
# ------------------------------------------------------------------
897
# PRIVATE METHOD: _parse_fields array_var string
898
#
899
# parse fields from a href or image tag. At the moment, doesn't support
900
# spaces in field values. (e.g. alt="not avaliable")
901
# ------------------------------------------------------------------
902
body iwidgets::Scrolledhtml::_parse_fields {array_var string} {
903
  upvar $array_var array
904
  if {$string != "{}" } {
905
    regsub -all "( *)=( *)" $string = string
906
    regsub -all {\\\"} $string \" string
907
    while {$string != ""} {
908
      if ![regexp "^ *(\[^ \n\r=\]+)=\"(\[^\"\n\r\t\]*)(.*)" $string \
909
                      dummy field value newstring] {
910
        if ![regexp "^ *(\[^ \n\r=\]+)=(\[^\n\r\t \]*)(.*)" $string \
911
                      dummy field value newstring] {
912
          if ![regexp "^ *(\[^ \n\r\]+)(.*)" $string dummy field newstring] {
913
            error "malformed command field; field = \"$string\""
914
            continue
915
          }
916
          set value ""
917
        }
918
      }
919
      set array([string tolower $field]) $value
920
      set string "$newstring"
921
    }
922
  }
923
}
924
 
925
# ------------------------------------------------------------------
926
# PRIVATE METHOD: _href_click
927
#
928
# process a click on an href
929
# ------------------------------------------------------------------
930
body iwidgets::Scrolledhtml::_href_click {cmd href} {
931
  uplevel #0 $cmd $href
932
}
933
 
934
# ------------------------------------------------------------------
935
# PRIVATE METHOD: _set_align
936
#
937
# set text alignment
938
# ------------------------------------------------------------------
939
body iwidgets::Scrolledhtml::_set_align {align} {
940
      switch [string tolower $align] {
941
        center {
942
          set _justify C
943
        }
944
        left {
945
          set _justify L
946
        }
947
        right {
948
          set _justify R
949
        }
950
        default {}
951
      }
952
}
953
 
954
# ------------------------------------------------------------------
955
# PRIVATE METHOD: _fixtablewidth
956
#
957
# fix table width & height
958
# essentially, with nested tables the outer table must be configured before
959
# the inner table, but the idle tasks get queued up in the opposite order,
960
# so process later idle tasks before sizing yourself.
961
# ------------------------------------------------------------------
962
body iwidgets::Scrolledhtml::_fixtablewidth {hottext table multiplier} {
963
  update idletasks
964
  $hottext see $_anchor($table)
965
  update idletasks
966
  $table configure  \
967
           -width [expr $multiplier * [winfo width $hottext] - \
968
                        2* [$hottext cget -padx] - \
969
                        2* [$hottext cget -borderwidth] ] \
970
           -height [winfo height $table]
971
  grid propagate $table 0
972
}
973
 
974
 
975
# ------------------------------------------------------------------
976
# PRIVATE METHOD: _header level
977
#
978
# generic entity to set state for  tag
979
# Accepts argument of the form ?align=[left,right,center]? ?src=?
980
# ------------------------------------------------------------------
981
body iwidgets::Scrolledhtml::_header {level args} {
982
    eval _parse_fields ar $args
983
    _push justify $_justify
984
    if [info exists ar(align)] {
985
      _entity_p align=$ar(align)
986
    } else {
987
      _entity_p
988
    }
989
    if [info exists ar(src)] {
990
        _entity_img src=$ar(src)
991
    }
992
    _push pointsndx $_pointsndx
993
    set _pointsndx [expr 7-$level]
994
    incr _textweight
995
    _set_tag
996
}
997
 
998
# ------------------------------------------------------------------
999
# PRIVATE METHOD: _/header level
1000
#
1001
# generic entity to set state for  tag
1002
# ------------------------------------------------------------------
1003
body iwidgets::Scrolledhtml::_/header {level} {
1004
    set _justify [_pop justify]
1005
    set _pointsndx [_pop pointsndx]
1006
    incr _textweight -1
1007
    _set_tag
1008
    _entity_p
1009
}
1010
 
1011
# ------------------------------------------------------------------
1012
# PRIVATE METHOD: _entity_a
1013
#
1014
# add an anchor. Accepts arguments of the form ?href=filename#anchorpoint?
1015
# ?name=anchorname?
1016
# ------------------------------------------------------------------
1017
body iwidgets::Scrolledhtml::_entity_a {args} {
1018
    _parse_fields ar $args
1019
    _push color $_color
1020
    if [info exists ar(href)] {
1021
      _push href $ar(href)
1022
      incr _anchorcount
1023
      set _color $_link
1024
      _entity_u
1025
    } else {
1026
      _push href {}
1027
    }
1028
    if [info exists ar(name)] {
1029
      set _anchor($ar(name)) [$itk_component(text) index end]
1030
    }
1031
    if [info exists ar(id)] {
1032
      set _anchor($ar(id)) [$itk_component(text) index end]
1033
    }
1034
}
1035
 
1036
# ------------------------------------------------------------------
1037
# PRIVATE METHOD: _entity_/a
1038
#
1039
# End anchor
1040
# ------------------------------------------------------------------
1041
body iwidgets::Scrolledhtml::_entity_/a {} {
1042
  set href [_pop href]
1043
  if {$href != {}} {
1044
    incr _anchorcount -1
1045
    set _color [_pop color]
1046
    _entity_/u
1047
  }
1048
}
1049
 
1050
# ------------------------------------------------------------------
1051
# PRIVATE METHOD: _entity_address
1052
#
1053
# display an address
1054
# ------------------------------------------------------------------
1055
body iwidgets::Scrolledhtml::_entity_address {} {
1056
    _entity_br
1057
    _entity_i
1058
}
1059
 
1060
# ------------------------------------------------------------------
1061
# PRIVATE METHOD: _entity_/address
1062
#
1063
# change state back from address display
1064
# ------------------------------------------------------------------
1065
body iwidgets::Scrolledhtml::_entity_/address {} {
1066
  _entity_/i
1067
  _entity_br
1068
}
1069
 
1070
# ------------------------------------------------------------------
1071
# PRIVATE METHOD: _entity_b
1072
#
1073
# Change current font to bold
1074
# ------------------------------------------------------------------
1075
body iwidgets::Scrolledhtml::_entity_b {} {
1076
    incr _textweight
1077
    _set_tag
1078
}
1079
 
1080
# ------------------------------------------------------------------
1081
# PRIVATE METHOD: _entity_/b
1082
#
1083
# change current font back from bold
1084
# ------------------------------------------------------------------
1085
body iwidgets::Scrolledhtml::_entity_/b {} {
1086
    incr _textweight -1
1087
    _set_tag
1088
}
1089
 
1090
# ------------------------------------------------------------------
1091
# PRIVATE METHOD: _entity_base
1092
#
1093
# set the cwd of the document
1094
# ------------------------------------------------------------------
1095
body iwidgets::Scrolledhtml::_entity_base {{args {}}} {
1096
    _parse_fields ar $args
1097
    if [info exists ar(href)] {
1098
      set _cwd [file dirname $ar(href)]
1099
    }
1100
}
1101
 
1102
# ------------------------------------------------------------------
1103
# PRIVATE METHOD: _entity_basefont
1104
#
1105
# set base font size
1106
# ------------------------------------------------------------------
1107
body iwidgets::Scrolledhtml::_entity_basefont {{args {}}} {
1108
    _parse_fields ar $args
1109
    if {[info exists ar(size)]} {
1110
      set _basefontsize $ar(size)
1111
    }
1112
}
1113
 
1114
# ------------------------------------------------------------------
1115
# PRIVATE METHOD: _entity_big
1116
#
1117
# Change current font to a bigger size
1118
# ------------------------------------------------------------------
1119
body iwidgets::Scrolledhtml::_entity_big {} {
1120
    _push pointsndx $_pointsndx
1121
    if {[incr _pointsndx 2] > 6} {
1122
       set _pointsndx 6
1123
    }
1124
    _set_tag
1125
}
1126
 
1127
# ------------------------------------------------------------------
1128
# PRIVATE METHOD: _entity_/big
1129
#
1130
# change current font back from bigger size
1131
# ------------------------------------------------------------------
1132
body iwidgets::Scrolledhtml::_entity_/big {} {
1133
    set _pointsndx [_pop pointsndx]
1134
    _set_tag
1135
}
1136
 
1137
# ------------------------------------------------------------------
1138
# PRIVATE METHOD: _entity_blockquote
1139
#
1140
# display a block quote
1141
# ------------------------------------------------------------------
1142
body iwidgets::Scrolledhtml::_entity_blockquote {} {
1143
    _entity_p
1144
    _push left $_left
1145
    incr _left $_indentincr
1146
    _push left2 $_left2
1147
    set _left2 $_left
1148
    _set_tag
1149
}
1150
 
1151
# ------------------------------------------------------------------
1152
# PRIVATE METHOD: _entity_/blockquote
1153
#
1154
# change back from blockquote
1155
# ------------------------------------------------------------------
1156
body iwidgets::Scrolledhtml::_entity_/blockquote {} {
1157
    _entity_p
1158
    set _left [_pop left]
1159
    set _left2 [_pop left2]
1160
    _set_tag
1161
}
1162
 
1163
# ------------------------------------------------------------------
1164
# PRIVATE METHOD: _entity_body
1165
#
1166
# begin body text. Takes argument of the form ?bgcolor=? ?text=?
1167
# ?link=?
1168
# ------------------------------------------------------------------
1169
body iwidgets::Scrolledhtml::_entity_body {{args {}}} {
1170
    _parse_fields ar $args
1171
    if [info exists ar(bgcolor)] {
1172
       set _bgcolor $ar(bgcolor)
1173
       set temp $itk_option(-textbackground)
1174
       config -textbackground $_bgcolor
1175
       set _defaulttextbackground $temp
1176
    }
1177
    if [info exists ar(text)] {
1178
       set _color $ar(text)
1179
    }
1180
    if [info exists ar(link)] {
1181
       set _link $ar(link)
1182
    }
1183
    if [info exists ar(alink)] {
1184
       set _alink $ar(alink)
1185
    }
1186
}
1187
 
1188
# ------------------------------------------------------------------
1189
# PRIVATE METHOD: _entity_/body
1190
#
1191
# end body text
1192
# ------------------------------------------------------------------
1193
body iwidgets::Scrolledhtml::_entity_/body {} {
1194
}
1195
 
1196
# ------------------------------------------------------------------
1197
# PRIVATE METHOD: _entity_br
1198
#
1199
# line break
1200
# ------------------------------------------------------------------
1201
body iwidgets::Scrolledhtml::_entity_br {{args {}}} {
1202
    $_hottext insert end "\n"
1203
}
1204
 
1205
# ------------------------------------------------------------------
1206
# PRIVATE METHOD: _entity_center
1207
#
1208
# change justification to center
1209
# ------------------------------------------------------------------
1210
body iwidgets::Scrolledhtml::_entity_center {} {
1211
    _push justify $_justify
1212
    set _justify C
1213
    _set_tag
1214
}
1215
 
1216
# ------------------------------------------------------------------
1217
# PRIVATE METHOD: _entity_/center
1218
#
1219
# change state back from center
1220
# ------------------------------------------------------------------
1221
body iwidgets::Scrolledhtml::_entity_/center {} {
1222
  set _justify [_pop justify]
1223
  _set_tag
1224
}
1225
 
1226
# ------------------------------------------------------------------
1227
# PRIVATE METHOD: _entity_cite
1228
#
1229
# display citation
1230
# ------------------------------------------------------------------
1231
body iwidgets::Scrolledhtml::_entity_cite {} {
1232
    _entity_i
1233
}
1234
 
1235
# ------------------------------------------------------------------
1236
# PRIVATE METHOD: _entity_/cite
1237
#
1238
# change state back from citation
1239
# ------------------------------------------------------------------
1240
body iwidgets::Scrolledhtml::_entity_/cite {} {
1241
    _entity_/i
1242
}
1243
 
1244
# ------------------------------------------------------------------
1245
# PRIVATE METHOD: _entity_code
1246
#
1247
# display code listing
1248
# ------------------------------------------------------------------
1249
body iwidgets::Scrolledhtml::_entity_code {} {
1250
    _entity_pre
1251
}
1252
 
1253
# ------------------------------------------------------------------
1254
# PRIVATE METHOD: _entity_/code
1255
#
1256
# end code listing
1257
# ------------------------------------------------------------------
1258
body iwidgets::Scrolledhtml::_entity_/code {} {
1259
    _entity_/pre
1260
}
1261
 
1262
# ------------------------------------------------------------------
1263
# PRIVATE METHOD: _entity_dir
1264
#
1265
# display dir list
1266
# ------------------------------------------------------------------
1267
body iwidgets::Scrolledhtml::_entity_dir {{args {}}} {
1268
    _entity_ul plain $args
1269
}
1270
 
1271
# ------------------------------------------------------------------
1272
# PRIVATE METHOD: _entity_/dir
1273
#
1274
# end dir list
1275
# ------------------------------------------------------------------
1276
body iwidgets::Scrolledhtml::_entity_/dir {} {
1277
    _entity_/ul
1278
}
1279
 
1280
# ------------------------------------------------------------------
1281
# PRIVATE METHOD: _entity_div
1282
#
1283
# divide text. same as 

1284
# ------------------------------------------------------------------
1285
body iwidgets::Scrolledhtml::_entity_div {{args {}}} {
1286
    _entity_p $args
1287
}
1288
 
1289
# ------------------------------------------------------------------
1290
# PRIVATE METHOD: _entity_dl
1291
#
1292
# begin definition list
1293
# ------------------------------------------------------------------
1294
body iwidgets::Scrolledhtml::_entity_dl {{args {}}} {
1295
    if {$_left == 0} {
1296
      _entity_p
1297
    }
1298
    _push left $_left
1299
    _push left2 $_left2
1300
    if {$_left2 == $_left } {
1301
      incr _left2 [expr $_indentincr+3]
1302
    } else {
1303
      incr _left2 $_indentincr
1304
    }
1305
    incr _left $_indentincr
1306
    _push listyle $_listyle
1307
    _push licount $_licount
1308
    set _listyle none
1309
    _set_tag
1310
}
1311
 
1312
# ------------------------------------------------------------------
1313
# PRIVATE METHOD: _entity_/dl
1314
#
1315
# end definition list
1316
# ------------------------------------------------------------------
1317
body iwidgets::Scrolledhtml::_entity_/dl {} {
1318
    set _left [_pop left]
1319
    set _left2 [_pop left2]
1320
    set _listyle [_pop listyle]
1321
    set _licount [_pop licount]
1322
    _set_tag
1323
    if {$_left == 0} {
1324
      _entity_p
1325
    }
1326
}
1327
 
1328
# ------------------------------------------------------------------
1329
# PRIVATE METHOD: _entity_dt
1330
#
1331
# definition term
1332
# ------------------------------------------------------------------
1333
body iwidgets::Scrolledhtml::_entity_dt {} {
1334
  set _left [expr $_left2 - 3]
1335
  _set_tag
1336
  _entity_p
1337
}
1338
 
1339
# ------------------------------------------------------------------
1340
# PRIVATE METHOD: _entity_dd
1341
#
1342
# definition definition
1343
# ------------------------------------------------------------------
1344
body iwidgets::Scrolledhtml::_entity_dd {} {
1345
  set _left $_left2
1346
  _set_tag
1347
   _entity_br
1348
}
1349
 
1350
# ------------------------------------------------------------------
1351
# PRIVATE METHOD: _entity_dfn
1352
#
1353
# display defining instance of a term
1354
# ------------------------------------------------------------------
1355
body iwidgets::Scrolledhtml::_entity_dfn {} {
1356
    _entity_i
1357
    _entity_b
1358
}
1359
 
1360
# ------------------------------------------------------------------
1361
# PRIVATE METHOD: _entity_/dfn
1362
#
1363
# change state back from defining instance of term
1364
# ------------------------------------------------------------------
1365
body iwidgets::Scrolledhtml::_entity_/dfn {} {
1366
    _entity_/b
1367
    _entity_/i
1368
}
1369
 
1370
# ------------------------------------------------------------------
1371
# PRIVATE METHOD: _entity_em
1372
#
1373
# display emphasized text
1374
# ------------------------------------------------------------------
1375
body iwidgets::Scrolledhtml::_entity_em {} {
1376
    _entity_i
1377
}
1378
 
1379
# ------------------------------------------------------------------
1380
# PRIVATE METHOD: _entity_/em
1381
#
1382
# change state back from emphasized text
1383
# ------------------------------------------------------------------
1384
body iwidgets::Scrolledhtml::_entity_/em {} {
1385
    _entity_/i
1386
}
1387
 
1388
# ------------------------------------------------------------------
1389
# PRIVATE METHOD: _entity_font
1390
#
1391
# set font size and color
1392
# ------------------------------------------------------------------
1393
body iwidgets::Scrolledhtml::_entity_font {{args {}}} {
1394
    _parse_fields ar $args
1395
    _push pointsndx $_pointsndx
1396
    _push color $_color
1397
    if [info exists ar(size)] {
1398
      if {![regexp {^[+-].*} $ar(size)]} {
1399
         set _pointsndx $ar(size)
1400
      } else {
1401
        set _pointsndx [expr $_basefontsize $ar(size)]
1402
      }
1403
      if { $_pointsndx > 6 } {
1404
       set _pointsndx 6
1405
      } else {
1406
        if { $_pointsndx < 0 } {
1407
          set _pointsndx 0
1408
        }
1409
      }
1410
    }
1411
    if {[info exists ar(color)]} {
1412
      set _color $ar(color)
1413
    }
1414
    _set_tag
1415
}
1416
 
1417
# ------------------------------------------------------------------
1418
# PRIVATE METHOD: _entity_/font
1419
#
1420
# close current font size
1421
# ------------------------------------------------------------------
1422
body iwidgets::Scrolledhtml::_entity_/font {} {
1423
  set _pointsndx [_pop pointsndx]
1424
  set _color [_pop color]
1425
  _set_tag
1426
}
1427
 
1428
# ------------------------------------------------------------------
1429
# PRIVATE METHOD: _entity_h1
1430
#
1431
# display header level 1.
1432
# Accepts argument of the form ?align=[left,right,center]? ?src=?
1433
# ------------------------------------------------------------------
1434
body iwidgets::Scrolledhtml::_entity_h1 {{args {}}} {
1435
    _header 1 $args
1436
}
1437
 
1438
# ------------------------------------------------------------------
1439
# PRIVATE METHOD: _entity_/h1
1440
#
1441
# change state back from header 1
1442
# ------------------------------------------------------------------
1443
body iwidgets::Scrolledhtml::_entity_/h1 {} {
1444
    _/header 1
1445
}
1446
 
1447
# ------------------------------------------------------------------
1448
# PRIVATE METHOD: _entity_h2
1449
#
1450
# display header level 2
1451
# Accepts argument of the form ?align=[left,right,center]? ?src=?
1452
# ------------------------------------------------------------------
1453
body iwidgets::Scrolledhtml::_entity_h2 {{args {}}} {
1454
    _header 2 $args
1455
}
1456
 
1457
# ------------------------------------------------------------------
1458
# PRIVATE METHOD: _entity_/h2
1459
#
1460
# change state back from header 2
1461
# ------------------------------------------------------------------
1462
body iwidgets::Scrolledhtml::_entity_/h2 {} {
1463
    _/header 2
1464
}
1465
 
1466
# ------------------------------------------------------------------
1467
# PRIVATE METHOD: _entity_h3
1468
#
1469
# display header level 3
1470
# Accepts argument of the form ?align=[left,right,center]? ?src=?
1471
# ------------------------------------------------------------------
1472
body iwidgets::Scrolledhtml::_entity_h3 {{args {}}} {
1473
    _header 3 $args
1474
}
1475
 
1476
# ------------------------------------------------------------------
1477
# PRIVATE METHOD: _entity_/h3
1478
#
1479
# change state back from header 3
1480
# ------------------------------------------------------------------
1481
body iwidgets::Scrolledhtml::_entity_/h3 {} {
1482
    _/header 3
1483
}
1484
 
1485
# ------------------------------------------------------------------
1486
# PRIVATE METHOD: _entity_h4
1487
#
1488
# display header level 4
1489
# Accepts argument of the form ?align=[left,right,center]? ?src=?
1490
# ------------------------------------------------------------------
1491
body iwidgets::Scrolledhtml::_entity_h4 {{args {}}} {
1492
    _header 4 $args
1493
}
1494
 
1495
# ------------------------------------------------------------------
1496
# PRIVATE METHOD: _entity_/h4
1497
#
1498
# change state back from header 4
1499
# ------------------------------------------------------------------
1500
body iwidgets::Scrolledhtml::_entity_/h4 {} {
1501
    _/header 4
1502
}
1503
 
1504
# ------------------------------------------------------------------
1505
# PRIVATE METHOD: _entity_h5
1506
#
1507
# display header level 5
1508
# Accepts argument of the form ?align=[left,right,center]? ?src=?
1509
# ------------------------------------------------------------------
1510
body iwidgets::Scrolledhtml::_entity_h5 {{args {}}} {
1511
    _header 5 $args
1512
}
1513
 
1514
# ------------------------------------------------------------------
1515
# PRIVATE METHOD: _entity_/h5
1516
#
1517
# change state back from header 5
1518
# ------------------------------------------------------------------
1519
body iwidgets::Scrolledhtml::_entity_/h5 {} {
1520
    _/header 5
1521
}
1522
 
1523
# ------------------------------------------------------------------
1524
# PRIVATE METHOD: _entity_h6
1525
#
1526
# display header level 6
1527
# ------------------------------------------------------------------
1528
body iwidgets::Scrolledhtml::_entity_h6 {{args {}}} {
1529
    _header 6 $args
1530
}
1531
 
1532
# ------------------------------------------------------------------
1533
# PRIVATE METHOD: _entity_/h6
1534
#
1535
# change state back from header 6
1536
# ------------------------------------------------------------------
1537
body iwidgets::Scrolledhtml::_entity_/h6 {} {
1538
    _/header 6
1539
}
1540
 
1541
# ------------------------------------------------------------------
1542
# PRIVATE METHOD: _entity_hr
1543
#
1544
# Add a horizontal rule
1545
# ------------------------------------------------------------------
1546
body iwidgets::Scrolledhtml::_entity_hr {{args {}}} {
1547
    _parse_fields ar $args
1548
    if [info exists ar(size)] {
1549
       set font "-font -*-*-*-*-*-*-$ar(size)-*-*-*-*-*-*-*"
1550
    } else {
1551
       set font "-font -*-*-*-*-*-*-2-*-*-*-*-*-*-*"
1552
    }
1553
    if [info exists ar(width)] {
1554
    }
1555
    if [info exists ar(noshade)] {
1556
      set relief "-relief flat"
1557
      set background "-background black"
1558
    } else {
1559
      set relief "-relief sunken"
1560
      set background ""
1561
    }
1562
#    if [info exists ar(align)] {
1563
#       $_hottext tag config hr$_counter -justify $ar(align)
1564
#       set justify -justify $ar(align)
1565
#    } else {
1566
#       set justify ""
1567
#    }
1568
    eval $_hottext tag config hr[incr _counter] $relief $background $font \
1569
            -borderwidth 2
1570
    _entity_p
1571
    $_hottext insert end " \n" hr$_counter
1572
}
1573
 
1574
# ------------------------------------------------------------------
1575
# PRIVATE METHOD: _entity_i
1576
#
1577
# display italicized text
1578
# ------------------------------------------------------------------
1579
body iwidgets::Scrolledhtml::_entity_i {} {
1580
    incr _textslant
1581
    _set_tag
1582
}
1583
 
1584
# ------------------------------------------------------------------
1585
# PRIVATE METHOD: _entity_/i
1586
#
1587
# change state back from italicized text
1588
# ------------------------------------------------------------------
1589
body iwidgets::Scrolledhtml::_entity_/i {} {
1590
    incr _textslant -1
1591
    _set_tag
1592
}
1593
 
1594
# ------------------------------------------------------------------
1595
# PRIVATE METHOD: _entity_img
1596
#
1597
# display an image. takes argument of the form img=
1598
# ------------------------------------------------------------------
1599
body iwidgets::Scrolledhtml::_entity_img {{args {}}} {
1600
  _parse_fields ar $args
1601
  set alttext ""
1602
 
1603
  #
1604
  # If proper argument exists
1605
  #
1606
  if [info exists ar(src)] {
1607
    set imgframe $_hottext.img[incr _counter]
1608
    #
1609
    # if this is an anchor
1610
    #
1611
    if $_anchorcount {
1612
      # create link colored border
1613
      frame $imgframe -borderwidth 2 -background $_link
1614
      bind $imgframe  \
1615
            [list $imgframe configure -background $_alink]
1616
      bind $imgframe  \
1617
            [list $imgframe configure -background $_link]
1618
    } else {
1619
      # create plain frame
1620
      frame $imgframe -borderwidth 0 -background $_color
1621
    }
1622
 
1623
    #
1624
    # try to load image
1625
    #
1626
    if {[string index $ar(src) 0] == "/" || [string index $ar(src) 0] == "~"} {
1627
       set file $ar(src)
1628
    } else {
1629
       set file $_cwd/$ar(src)
1630
    }
1631
    if [catch {set img [image create photo -file $file]} err] {
1632
      if {[info exists ar(width)] && [info exists ar(height)] } {
1633
        # suggestions exist, so make frame appropriate size and add a border
1634
        $imgframe configure -width $ar(width) -height $ar(height) -borderwidth 2
1635
        pack propagate $imgframe false
1636
      }
1637
 
1638
      #
1639
      # If alt text is specified, display that
1640
      #
1641
      if [info exists ar(alt)] {
1642
        # add a border
1643
        $imgframe configure -borderwidth 2
1644
        set win $imgframe.text
1645
        label $win -text "$ar(alt)" -background $_bgcolor \
1646
               -foreground $_color
1647
      } else {
1648
        #
1649
        # use 'unknown image'
1650
        set win $imgframe.image#auto
1651
        #
1652
        # make label containing image
1653
        #
1654
        label $win -image $_unknownimg -borderwidth 0 -background $_bgcolor
1655
      }
1656
      pack $win -fill both -expand true
1657
 
1658
    } else {   ;# no error loading image
1659
      lappend _images $img
1660
      set win $imgframe.$img
1661
 
1662
      #
1663
      # make label containing image
1664
      #
1665
      label $win -image $img -borderwidth 0
1666
    }
1667
    pack $win
1668
 
1669
    #
1670
    # set alignment
1671
    #
1672
    set align bottom
1673
    if [info exists ar(align)] {
1674
      switch $ar(align) {
1675
        middle {
1676
          set align center
1677
        }
1678
        right {
1679
          set align center
1680
        }
1681
        default {
1682
          set align [string tolower $ar(align)]
1683
        }
1684
      }
1685
    }
1686
 
1687
    #
1688
    # create window in text to display image
1689
    #
1690
    $_hottext window create end -window \
1691
            $imgframe -align $align
1692
 
1693
    #
1694
    # set tag for window
1695
    #
1696
    $_hottext tag add $_tag $imgframe
1697
    if $_anchorcount {
1698
        set href [_peek href]
1699
        set href_tag href[incr _counter]
1700
        set tags [list $_tag $href_tag]
1701
        if { $itk_option(-linkcommand)!= {} } {
1702
          bind $win <1> [list uplevel #0 $itk_option(-linkcommand) $href]
1703
        }
1704
    }
1705
  }
1706
}
1707
 
1708
# ------------------------------------------------------------------
1709
# PRIVATE METHOD: _entity_kbd
1710
#
1711
# Display keyboard input
1712
# ------------------------------------------------------------------
1713
body iwidgets::Scrolledhtml::_entity_kbd {} {
1714
    incr _textweight
1715
    _entity_tt
1716
    _set_tag
1717
}
1718
 
1719
# ------------------------------------------------------------------
1720
# PRIVATE METHOD: _entity_/kbd
1721
#
1722
# change state back from displaying keyboard input
1723
# ------------------------------------------------------------------
1724
body iwidgets::Scrolledhtml::_entity_/kbd {} {
1725
    _entity_/tt
1726
    incr _textweight -1
1727
    _set_tag
1728
}
1729
 
1730
# ------------------------------------------------------------------
1731
# PRIVATE METHOD: _entity_li
1732
#
1733
# begin new list entry
1734
# ------------------------------------------------------------------
1735
body iwidgets::Scrolledhtml::_entity_li {{args {}}} {
1736
    _parse_fields ar $args
1737
    if [info exists ar(value)] {
1738
       set _licount $ar(value)
1739
    }
1740
    _entity_br
1741
    switch -exact $_listyle {
1742
      bullet {
1743
        set old_font $_font
1744
        set _font symbol
1745
        _set_tag
1746
        $_hottext insert end "\xb7" $_tag
1747
        set _font $old_font
1748
        _set_tag
1749
      }
1750
      none {
1751
      }
1752
      picture {
1753
        _entity_img src="$_lipic" width=4 height=4 align=middle
1754
      }
1755
      A {
1756
          _entity_b
1757
          $_hottext insert end [format "%c) " [expr $_licount + 0x40]] $_tag
1758
          _entity_/b
1759
          incr _licount
1760
      }
1761
      a {
1762
          _entity_b
1763
          $_hottext insert end [format "%c) " [expr $_licount + 0x60]] $_tag
1764
          _entity_/b
1765
          incr _licount
1766
      }
1767
      I {
1768
        _entity_b
1769
        $_hottext insert end "[::iwidgets::roman $_licount]) " $_tag
1770
        _entity_/b
1771
        incr _licount
1772
      }
1773
      i {
1774
        _entity_b
1775
        $_hottext insert end "[::iwidgets::roman $_licount lower])] " $_tag
1776
        _entity_/b
1777
        incr _licount
1778
      }
1779
      default {
1780
        _entity_b
1781
        $_hottext insert end "$_licount) " $_tag
1782
        _entity_/b
1783
        incr _licount
1784
      }
1785
    }
1786
}
1787
 
1788
# ------------------------------------------------------------------
1789
# PRIVATE METHOD: _entity_listing
1790
#
1791
# diplay code listing
1792
# ------------------------------------------------------------------
1793
body iwidgets::Scrolledhtml::_entity_listing {} {
1794
    _entity_pre
1795
}
1796
 
1797
# ------------------------------------------------------------------
1798
# PRIVATE METHOD: _entity_/listing
1799
#
1800
# end code listing
1801
# ------------------------------------------------------------------
1802
body iwidgets::Scrolledhtml::_entity_/listing {} {
1803
    _entity_/pre
1804
}
1805
 
1806
# ------------------------------------------------------------------
1807
# PRIVATE METHOD: _entity_menu
1808
#
1809
# diplay menu list
1810
# ------------------------------------------------------------------
1811
body iwidgets::Scrolledhtml::_entity_menu {{args {}}} {
1812
    _entity_ul plain $args
1813
}
1814
 
1815
# ------------------------------------------------------------------
1816
# PRIVATE METHOD: _entity_/menu
1817
#
1818
# end menu list
1819
# ------------------------------------------------------------------
1820
body iwidgets::Scrolledhtml::_entity_/menu {} {
1821
    _entity_/ul
1822
}
1823
 
1824
# ------------------------------------------------------------------
1825
# PRIVATE METHOD: _entity_ol
1826
#
1827
# begin ordered list
1828
# ------------------------------------------------------------------
1829
body iwidgets::Scrolledhtml::_entity_ol {{args {}}} {
1830
    _parse_fields ar $args
1831
    if $_left {
1832
      _entity_br
1833
    } else {
1834
      _entity_p
1835
    }
1836
    if {![info exists ar(type)]} {
1837
       set ar(type) 1
1838
    }
1839
    _push licount $_licount
1840
    if [info exists ar(start)] {
1841
       set _licount $ar(start)
1842
    } else {
1843
       set _licount 1
1844
    }
1845
    _push left $_left
1846
    _push left2 $_left2
1847
    if {$_left2 == $_left } {
1848
      incr _left2 [expr $_indentincr+3]
1849
    } else {
1850
      incr _left2 $_indentincr
1851
    }
1852
    incr _left $_indentincr
1853
    _push listyle $_listyle
1854
    set _listyle $ar(type)
1855
    _set_tag
1856
}
1857
 
1858
# ------------------------------------------------------------------
1859
# PRIVATE METHOD: _entity_/ol
1860
#
1861
# end ordered list
1862
# ------------------------------------------------------------------
1863
body iwidgets::Scrolledhtml::_entity_/ol {} {
1864
    set _left [_pop left]
1865
    set _left2 [_pop left2]
1866
    set _listyle [_pop listyle]
1867
    set _licount [_pop licount]
1868
    _set_tag
1869
    _entity_p
1870
}
1871
 
1872
# ------------------------------------------------------------------
1873
# PRIVATE METHOD: _entity_p
1874
#
1875
# paragraph break
1876
# ------------------------------------------------------------------
1877
body iwidgets::Scrolledhtml::_entity_p {{args {}}} {
1878
  _parse_fields ar $args
1879
  if [info exists ar(align)] {
1880
     _set_align $ar(align)
1881
  } else {
1882
     set _justify L
1883
  }
1884
  _set_tag
1885
  if [info exists ar(id)] {
1886
    set _anchor($ar(id)) [$itk_component(text) index end]
1887
  }
1888
  set x [$_hottext get end-3c]
1889
  set y [$_hottext get end-2c]
1890
  if {$x == "" && $y == ""} return
1891
  if {$y == ""} {
1892
    $_hottext insert end "\n\n"
1893
    return
1894
  }
1895
  if {$x == "\n" && $y == "\n"} return
1896
  if {$y == "\n"} {
1897
    $_hottext insert end "\n"
1898
  return
1899
  }
1900
  $_hottext insert end "\n\n"
1901
}
1902
 
1903
# ------------------------------------------------------------------
1904
# PRIVATE METHOD: _entity_pre
1905
#
1906
# display preformatted text
1907
# ------------------------------------------------------------------
1908
body iwidgets::Scrolledhtml::_entity_pre {{args {}}} {
1909
    _entity_tt
1910
    _entity_br
1911
    incr _pre
1912
}
1913
 
1914
# ------------------------------------------------------------------
1915
# PRIVATE METHOD: _entity_/pre
1916
#
1917
# change state back from preformatted text
1918
# ------------------------------------------------------------------
1919
body iwidgets::Scrolledhtml::_entity_/pre {} {
1920
    _entity_/tt
1921
    set _pre 0
1922
    _entity_p
1923
}
1924
 
1925
# ------------------------------------------------------------------
1926
# PRIVATE METHOD: _entity_samp
1927
#
1928
# display sample text.
1929
# ------------------------------------------------------------------
1930
body iwidgets::Scrolledhtml::_entity_samp {} {
1931
    _entity_kbd
1932
}
1933
 
1934
# ------------------------------------------------------------------
1935
# PRIVATE METHOD: _entity_/samp
1936
#
1937
# switch back to non-sample text
1938
# ------------------------------------------------------------------
1939
body iwidgets::Scrolledhtml::_entity_/samp {} {
1940
   _entity_/kbd
1941
}
1942
 
1943
# ------------------------------------------------------------------
1944
# PRIVATE METHOD: _entity_small
1945
#
1946
# Change current font to a smaller size
1947
# ------------------------------------------------------------------
1948
body iwidgets::Scrolledhtml::_entity_small {} {
1949
    _push pointsndx $_pointsndx
1950
    if {[incr _pointsndx -2] < 0} {
1951
       set _pointsndx 0
1952
    }
1953
    _set_tag
1954
}
1955
 
1956
# ------------------------------------------------------------------
1957
# PRIVATE METHOD: _entity_/small
1958
#
1959
# change current font back from smaller size
1960
# ------------------------------------------------------------------
1961
body iwidgets::Scrolledhtml::_entity_/small {} {
1962
    set _pointsndx [_pop pointsndx]
1963
    _set_tag
1964
}
1965
 
1966
# ------------------------------------------------------------------
1967
# PRIVATE METHOD: _entity_sub
1968
#
1969
# display subscript
1970
# ------------------------------------------------------------------
1971
body iwidgets::Scrolledhtml::_entity_sub {} {
1972
    _push offset $_offset
1973
    incr _offset -2
1974
    _entity_small
1975
}
1976
 
1977
# ------------------------------------------------------------------
1978
# PRIVATE METHOD: _entity_/sub
1979
#
1980
# switch back to non-subscript
1981
# ------------------------------------------------------------------
1982
body iwidgets::Scrolledhtml::_entity_/sub {} {
1983
   set _offset [_pop offset]
1984
   _entity_/small
1985
}
1986
 
1987
# ------------------------------------------------------------------
1988
# PRIVATE METHOD: _entity_sup
1989
#
1990
# display superscript
1991
# ------------------------------------------------------------------
1992
body iwidgets::Scrolledhtml::_entity_sup {} {
1993
    _push offset $_offset
1994
    incr _offset 4
1995
    _entity_small
1996
}
1997
 
1998
# ------------------------------------------------------------------
1999
# PRIVATE METHOD: _entity_/sup
2000
#
2001
# switch back to non-superscript
2002
# ------------------------------------------------------------------
2003
body iwidgets::Scrolledhtml::_entity_/sup {} {
2004
   set _offset [_pop offset]
2005
   _entity_/small
2006
}
2007
 
2008
# ------------------------------------------------------------------
2009
# PRIVATE METHOD: _entity_strong
2010
#
2011
# display strong text. (i.e. make font bold)
2012
# ------------------------------------------------------------------
2013
body iwidgets::Scrolledhtml::_entity_strong {} {
2014
    incr _textweight
2015
    _set_tag
2016
}
2017
 
2018
# ------------------------------------------------------------------
2019
# PRIVATE METHOD: _entity_/strong
2020
#
2021
# switch back to non-strong text
2022
# ------------------------------------------------------------------
2023
body iwidgets::Scrolledhtml::_entity_/strong {} {
2024
    incr _textweight -1
2025
    _set_tag
2026
}
2027
 
2028
# ------------------------------------------------------------------
2029
# PRIVATE METHOD: _entity_table
2030
#
2031
# display a table.
2032
# ------------------------------------------------------------------
2033
body iwidgets::Scrolledhtml::_entity_table {{args {}}} {
2034
    _parse_fields ar $args
2035
    _entity_p
2036
    set _intable 1
2037
 
2038
    _push row -1
2039
    _push column 0
2040
    _push hottext $_hottext
2041
    _push justify $_justify
2042
    _push justify L
2043
    # push color information for master of table, then push info for table
2044
    _push color $_color
2045
    _push bgcolor $_bgcolor
2046
    _push link $_link
2047
    _push alink $_alink
2048
    if [info exists ar(bgcolor)] {
2049
       set _bgcolor $ar(bgcolor)
2050
    }
2051
    if [info exists ar(text)] {
2052
       set _color $ar(text)
2053
    }
2054
    if [info exists ar(link)] {
2055
       set _link $ar(link)
2056
    }
2057
    if [info exists ar(alink)] {
2058
       set _alink $ar(alink)
2059
    }
2060
    _push color $_color
2061
    _push bgcolor $_bgcolor
2062
    _push link $_link
2063
    _push alink $_alink
2064
    # push fake first row to avoid using optional /tr tag
2065
    _push color {}
2066
    _push bgcolor {}
2067
    _push link {}
2068
    _push alink {}
2069
 
2070
    if {[info exists ar(align)]} {
2071
      _set_align $ar(align)
2072
      _set_tag
2073
      _append_text " "
2074
    }
2075
    set _justify L
2076
 
2077
    if [info exists ar(id)] {
2078
       set _anchor($ar(id)) [$itk_component(text) index end]
2079
    }
2080
    if [info exists ar(cellpadding)] {
2081
       _push cellpadding $ar(cellpadding)
2082
    } else {
2083
       _push cellpadding 0
2084
    }
2085
    if [info exists ar(cellspacing)] {
2086
       _push cellspacing $ar(cellspacing)
2087
    } else {
2088
       _push cellspacing 0
2089
    }
2090
    if {[info exists ar(border)]} {
2091
       _push tableborder 1
2092
       set relief raised
2093
       if {$ar(border)==""} {
2094
          set ar(border) 2
2095
       }
2096
    } else {
2097
       _push tableborder 0
2098
       set relief flat
2099
       set ar(border) 2
2100
    }
2101
    _push table [set table $_hottext.table[incr _counter]]
2102
    iwidgets::labeledwidget $table -foreground $_color -background $_bgcolor -labelpos n
2103
    if {[info exists ar(title)]} {
2104
      $table configure -labeltext $ar(title)
2105
    }
2106
    #
2107
    # create window in text to display table
2108
    #
2109
    $_hottext window create end -window $table
2110
 
2111
    set table [$table childsite]
2112
    set _anchor($table) [$_hottext index "end - 1 line"]
2113
    $table configure -borderwidth $ar(border) -relief $relief
2114
 
2115
    if {[info exists ar(width)]} {
2116
        _push tablewidth $ar(width)
2117
    } else {
2118
        _push tablewidth 0
2119
    }
2120
}
2121
 
2122
# ------------------------------------------------------------------
2123
# PRIVATE METHOD: _entity_/table
2124
#
2125
# end table
2126
# ------------------------------------------------------------------
2127
body iwidgets::Scrolledhtml::_entity_/table {} {
2128
  if $_intable {
2129
    _pop tableborder
2130
    set table [[_pop table] childsite]
2131
    _pop row
2132
    _pop column
2133
    _pop cellspacing
2134
    _pop cellpadding
2135
    # pop last row's defaults
2136
    _pop color
2137
    _pop bgcolor
2138
    _pop link
2139
    _pop alink
2140
    # pop table defaults
2141
    _pop color
2142
    _pop bgcolor
2143
    _pop link
2144
    _pop alink
2145
    # restore table master defaults
2146
    set _color [_pop color]
2147
    set _bgcolor [_pop bgcolor]
2148
    set _link [_pop link]
2149
    set _alink [_pop alink]
2150
      foreach x [grid slaves $table] {
2151
          if {[$x cget -height] == 1} {
2152
              $x configure -height [lindex [split [$x index "end - 1 chars"] "."] 0]
2153
          }
2154
      }
2155
    $_hottext configure -state disabled
2156
    set _hottext [_pop hottext]
2157
    $_hottext configure -state normal
2158
      if {[set tablewidth [_pop tablewidth]]!="0"} {
2159
        if {[string index $tablewidth \
2160
                 [expr [string length $tablewidth] -1]] == "%"} {
2161
          set multiplier [expr [string trimright $tablewidth "%"] / 100.0]
2162
            set idletask [after idle [code "$this _fixtablewidth $_hottext $table $multiplier"]]
2163
        } else {
2164
          $table configure -width $tablewidth
2165
          grid propagate $table 0
2166
        }
2167
      }
2168
    _pop justify
2169
    set _justify [_pop justify]
2170
    _entity_br
2171
  }
2172
}
2173
 
2174
# ------------------------------------------------------------------
2175
# PRIVATE METHOD: _entity_td
2176
#
2177
# start table data cell
2178
# ------------------------------------------------------------------
2179
body iwidgets::Scrolledhtml::_entity_td {{args {}}} {
2180
  if $_intable {
2181
    _parse_fields ar $args
2182
    set table [[_peek table] childsite]
2183
    if {![info exists ar(colspan)]} {
2184
        set ar(colspan) 1
2185
    }
2186
    if {![info exists ar(rowspan)]} {
2187
        set ar(rowspan) 1
2188
    }
2189
    if {![info exists ar(width)]} {
2190
        set ar(width) 10
2191
    }
2192
    if {![info exists ar(height)]} {
2193
        set ar(height) 0
2194
    }
2195
    if [info exists ar(bgcolor)] {
2196
       set _bgcolor $ar(bgcolor)
2197
    } else {
2198
       set _bgcolor [_peek bgcolor]
2199
    }
2200
    if [info exists ar(text)] {
2201
       set _color $ar(text)
2202
    } else {
2203
       set _color [_peek color]
2204
    }
2205
    if [info exists ar(link)] {
2206
       set _link $ar(link)
2207
    } else {
2208
       set _link [_peek link]
2209
    }
2210
    if [info exists ar(alink)] {
2211
       set _alink $ar(alink)
2212
    } else {
2213
       set _alink [_peek alink]
2214
    }
2215
    $_hottext configure -state disabled
2216
      set cellpadding [_peek cellpadding]
2217
      set cellspacing [_peek cellspacing]
2218
    set _hottext $table.cell[incr _counter]
2219
    text $_hottext -relief flat -width $ar(width) -height $ar(height) \
2220
             -foreground $_color -background $_bgcolor -highlightthickness 0 \
2221
             -wrap word -cursor $itk_option(-cursor) \
2222
             -padx $cellpadding -pady $cellpadding
2223
      if [info exists ar(nowrap)] {
2224
          $_hottext configure -wrap none
2225
      }
2226
    if [_peek tableborder] {
2227
       $_hottext configure -relief sunken
2228
    }
2229
    set row [_peek row]
2230
    set column [_pop column]
2231
    while {[grid slaves $table -row $row -column $column] != ""} {
2232
      incr column
2233
    }
2234
    grid $_hottext -sticky nsew -row $row -column $column \
2235
            -columnspan $ar(colspan) -rowspan $ar(rowspan) \
2236
              -padx $cellspacing -pady $cellspacing
2237
   grid columnconfigure $table $column -weight 1
2238
    _push column [expr $column + $ar(colspan)]
2239
  if [info exists ar(align)] {
2240
     _set_align $ar(align)
2241
  } else {
2242
      set _justify [_peek justify]
2243
  }
2244
  _set_tag
2245
  }
2246
}
2247
 
2248
# ------------------------------------------------------------------
2249
# PRIVATE METHOD: _entity_/td
2250
#
2251
# end table data cell
2252
# ------------------------------------------------------------------
2253
body iwidgets::Scrolledhtml::_entity_/td {} {
2254
}
2255
 
2256
# ------------------------------------------------------------------
2257
# PRIVATE METHOD: _entity_th
2258
#
2259
# start table header
2260
# ------------------------------------------------------------------
2261
body iwidgets::Scrolledhtml::_entity_th {{args {}}} {
2262
    if $_intable {
2263
      _parse_fields ar $args
2264
      if [info exists ar(align)] {
2265
         _entity_td $args
2266
      } else {
2267
         _entity_td align=center $args
2268
      }
2269
      _entity_b
2270
    }
2271
}
2272
 
2273
# ------------------------------------------------------------------
2274
# PRIVATE METHOD: _entity_/th
2275
#
2276
# end table data cell
2277
# ------------------------------------------------------------------
2278
body iwidgets::Scrolledhtml::_entity_/th {} {
2279
  _entity_/td
2280
}
2281
 
2282
# ------------------------------------------------------------------
2283
# PRIVATE METHOD: _entity_title
2284
#
2285
# begin title of document
2286
# ------------------------------------------------------------------
2287
body iwidgets::Scrolledhtml::_entity_title {} {
2288
    set _intitle 1
2289
}
2290
 
2291
# ------------------------------------------------------------------
2292
# PRIVATE METHOD: _entity_/title
2293
#
2294
# end title
2295
# ------------------------------------------------------------------
2296
body iwidgets::Scrolledhtml::_entity_/title {} {
2297
    set _intitle 0
2298
}
2299
 
2300
# ------------------------------------------------------------------
2301
# PRIVATE METHOD: _entity_tr
2302
#
2303
# start table row
2304
# ------------------------------------------------------------------
2305
body iwidgets::Scrolledhtml::_entity_tr {{args {}}} {
2306
  if $_intable {
2307
    _parse_fields ar $args
2308
      _pop justify
2309
      if [info exists ar(align)] {
2310
         _set_align $ar(align)
2311
         _push justify $_justify
2312
      } else {
2313
         _push justify L
2314
      }
2315
    # pop last row's colors
2316
    _pop color
2317
    _pop bgcolor
2318
    _pop link
2319
    _pop alink
2320
    if [info exists ar(bgcolor)] {
2321
       set _bgcolor $ar(bgcolor)
2322
    } else {
2323
       set _bgcolor [_peek bgcolor]
2324
    }
2325
    if [info exists ar(text)] {
2326
       set _color $ar(text)
2327
    } else {
2328
       set _color [_peek color]
2329
    }
2330
    if [info exists ar(link)] {
2331
       set _link $ar(link)
2332
    } else {
2333
       set _link [_peek link]
2334
    }
2335
    if [info exists ar(alink)] {
2336
       set _alink $ar(alink)
2337
    } else {
2338
       set _alink [_peek alink]
2339
    }
2340
    # push this row's defaults
2341
    _push color $_color
2342
    _push bgcolor $_bgcolor
2343
    _push link $_link
2344
    _push alink $_alink
2345
    $_hottext configure -state disabled
2346
    _push row [expr [_pop row] + 1]
2347
    _pop column
2348
    _push column 0
2349
  }
2350
}
2351
 
2352
# ------------------------------------------------------------------
2353
# PRIVATE METHOD: _entity_/tr
2354
#
2355
# end table row
2356
# ------------------------------------------------------------------
2357
body iwidgets::Scrolledhtml::_entity_/tr {} {
2358
}
2359
 
2360
# ------------------------------------------------------------------
2361
# PRIVATE METHOD: _entity_tt
2362
#
2363
# Show typewriter text, using the font given by -fixedfont
2364
# ------------------------------------------------------------------
2365
body iwidgets::Scrolledhtml::_entity_tt {} {
2366
    _push font $_font
2367
    set _font $itk_option(-fixedfont)
2368
    set _verbatim 1
2369
    _set_tag
2370
}
2371
 
2372
# ------------------------------------------------------------------
2373
# PRIVATE METHOD: _entity_/tt
2374
#
2375
# Change back to non-typewriter mode to display text
2376
# ------------------------------------------------------------------
2377
body iwidgets::Scrolledhtml::_entity_/tt {} {
2378
    set _font [_pop font]
2379
    set _verbatim 0
2380
    _set_tag
2381
}
2382
 
2383
# ------------------------------------------------------------------
2384
# PRIVATE METHOD: _entity_u
2385
#
2386
# display underlined text
2387
# ------------------------------------------------------------------
2388
body iwidgets::Scrolledhtml::_entity_u {} {
2389
    incr _underline
2390
    _set_tag
2391
}
2392
 
2393
# ------------------------------------------------------------------
2394
# PRIVATE METHOD: _entity_/u
2395
#
2396
# change back from underlined text
2397
# ------------------------------------------------------------------
2398
body iwidgets::Scrolledhtml::_entity_/u {} {
2399
    incr _underline -1
2400
    _set_tag
2401
}
2402
 
2403
# ------------------------------------------------------------------
2404
# PRIVATE METHOD: _entity_ul
2405
#
2406
# begin unordered list
2407
# ------------------------------------------------------------------
2408
body iwidgets::Scrolledhtml::_entity_ul {{args {}}} {
2409
    _parse_fields ar $args
2410
    if $_left {
2411
      _entity_br
2412
    } else {
2413
      _entity_p
2414
    }
2415
    if [info exists ar(id)] {
2416
      set _anchor($ar(id)) [$itk_component(text) index end]
2417
    }
2418
    _push left $_left
2419
    _push left2 $_left2
2420
    if {$_left2 == $_left } {
2421
      incr _left2 [expr $_indentincr+3]
2422
    } else {
2423
      incr _left2 $_indentincr
2424
    }
2425
    incr _left $_indentincr
2426
    _push listyle $_listyle
2427
    _push licount $_licount
2428
    if [info exists ar(plain)] {
2429
      set _listyle none
2430
    } {
2431
      set _listyle bullet
2432
    }
2433
    if [info exists ar(dingbat)] {
2434
      set ar(src) $ar(dingbat)
2435
    }
2436
    _push lipic $_lipic
2437
    if [info exists ar(src)] {
2438
        set _listyle picture
2439
        set _lipic $ar(src)
2440
    }
2441
    _set_tag
2442
}
2443
 
2444
# ------------------------------------------------------------------
2445
# PRIVATE METHOD: _entity_/ul
2446
#
2447
# end unordered list
2448
# ------------------------------------------------------------------
2449
body iwidgets::Scrolledhtml::_entity_/ul {} {
2450
    set _left [_pop left]
2451
    set _left2 [_pop left2]
2452
    set _listyle [_pop listyle]
2453
    set _licount [_pop licount]
2454
    set _lipic [_pop lipic]
2455
    _set_tag
2456
    _entity_p
2457
}
2458
 
2459
# ------------------------------------------------------------------
2460
# PRIVATE METHOD: _entity_var
2461
#
2462
# Display variable
2463
# ------------------------------------------------------------------
2464
body iwidgets::Scrolledhtml::_entity_var {} {
2465
    _entity_i
2466
}
2467
 
2468
# ------------------------------------------------------------------
2469
# PRIVATE METHOD: _entity_/var
2470
#
2471
# change state back from variable display
2472
# ------------------------------------------------------------------
2473
body iwidgets::Scrolledhtml::_entity_/var {} {
2474
    _entity_/i
2475
}
2476
 
2477
namespace eval iwidgets {
2478
  variable romand
2479
  set romand(val)   {1000 900 500 400 100 90 50 40 10  9 5  4 1}
2480
  set romand(upper) {   M  CM   D  CD   C XC  L XL  X IX V IV I}
2481
  set romand(lower) {   m  cm   d  cd   c xc  l xl  x ix v iv i}
2482
 
2483
  proc roman2 {n {case upper}} {
2484
      variable romand
2485
      set r ""
2486
      foreach val $romand(val) sym $romand($case) {
2487
          while {$n >= $val} {
2488
              set r "$r$sym"
2489
              incr n -$val
2490
          }
2491
      }
2492
      return $r
2493
  }
2494
 
2495
  proc roman {n {case upper}} {
2496
      variable romand
2497
      set r ""
2498
      foreach val $romand(val) sym $romand($case) {
2499
          for {} {$n >= $val} {incr n -$val} {
2500
              set r "$r$sym"
2501
          }
2502
      }
2503
      return $r
2504
  }
2505
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.