Check-in [dc7b228b2b]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Improvements to the download manager. (CVS 1255)
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:dc7b228b2b4af0890e901eb8c0eb8de27a4968a8
User & Date: danielk1977 2008-02-02 17:15:02
Context
2008-02-02
17:17
Add the new download manager. (CVS 1256) check-in: 57f52b84c9 user: danielk1977 tags: trunk
17:15
Improvements to the download manager. (CVS 1255) check-in: dc7b228b2b user: danielk1977 tags: trunk
16:10
makefile change. (CVS 1254) check-in: fb4d056189 user: danielk1977 tags: trunk
Changes

Changes to hv/hv3_browser.tcl.

14
15
16
17
18
19
20

21
22
23
24
25
26
27
..
63
64
65
66
67
68
69

70
71
72
73
74
75
76
..
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
...
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167

168
169
170
171
172
173
174
175
176
177
178
179
180
...
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544

545
546
547
548
549
550
551
...
590
591
592
593
594
595
596



597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
...
656
657
658
659
660
661
662


663
664
665
666
667
668
669
670
671
672
673
674
675
676
677

678
679
680
681
682
683
684
685
686
687
688




689
690
691
692
693
694
695
...
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
...
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
source [sourcefile hv3_notebook.tcl]
source [sourcefile hv3_db.tcl]
source [sourcefile hv3_home.tcl]
source [sourcefile hv3.tcl]
source [sourcefile hv3_prop.tcl]
source [sourcefile hv3_log.tcl]
source [sourcefile hv3_http.tcl]

source [sourcefile hv3_frameset.tcl]
source [sourcefile hv3_polipo.tcl]
source [sourcefile hv3_icons.tcl]
source [sourcefile hv3_history.tcl]
source [sourcefile hv3_string.tcl]
source [sourcefile hv3_bookmarks.tcl]
source [sourcefile hv3_bugreport.tcl]
................................................................................

  proc new {me browser args} {
    upvar #0 $me O

    # The name of this frame (as specified by the "name" attribute of 
    # the <frame> element).
    set O(-name) ""


    # If this [::hv3::browser_frame] is used as a replacement object
    # for an <iframe> element, then this option is set to the Tkhtml3
    # node-handle for that <iframe> element.
    #
    set O(-iframe) ""

................................................................................
    #set O(myHv3)      [::hv3::hv3 $O(win).hv3]
    #pack $O(myHv3) -expand true -fill both
    set O(myHv3) $O(hull)

    ::hv3::the_visited_db init $O(myHv3)

    catch {$O(myHv3) configure -fonttable $::hv3::fontsize_table}
    $O(myHv3) configure -downloadcmd {::hv3::the_download_manager savehandle}

    # Create bindings for motion, right-click and middle-click.
    $O(myHv3) Subscribe motion [list $me motion]
    bind $O(win) <3>       [list $me rightclick %x %y %X %Y]
    #bind $O(win) <2>       [list $me goto_selection]
    bind $O(win) <2>       [list $me middleclick %x %y]

................................................................................
    ::hv3::menu $O(win).hyperlinkmenu
    selection handle $O(win).hyperlinkmenu [list $me GetCopiedLinkLocation]
  }
  proc destroy {me} {
    upvar #0 $me O
    catch {$me ConfigureName -name ""}
    # Remove this object from the $theFrames list.
    catch {$O(myBrowser) del_frame $O(win)}
    catch {::destroy $O(win).hyperlinkmenu}
  }

  proc set_browser {me browser} {
    upvar #0 $me O
    if {$O(myBrowser) ne ""} {
      error "Invalid call to set_browser"
    }
    set O(myBrowser) $browser
    $O(myBrowser) add_frame $O(win)
  }

  proc configure-name {me} {
    upvar #0 $me O
puts "TODODODODODOD"
return

    # This method is called when the "name" of attribute of this
    # frame is modified. If javascript is enabled we have to update
    # the properties on the parent window object (if any).
    set dom [$me cget -dom]
    if {$dom ne "" && [$dom cget -enable]} {
      set parent [$me parent_frame]
      if {$parent ne ""} {
        set parent_window [list ::hv3::DOM::Window $dom [$parent hv3]]
        set this_win [list ::hv3::DOM::Window $dom $O(myHv3)]
        if {$O(-name) ne ""} {
          $dom set_object_property $parent_window $O(-name) undefined
        }
        if {$value ne ""} {

          $dom set_object_property $parent_window $value [list object $this_win]
        }
      }
    }

    set O(-name) $value
  }

  proc Targetcmd {me node} {
    upvar #0 $me O
    set target [$node attr -default "" target]
    if {$target eq ""} {
      # If there is no target frame specified, see if a default
................................................................................
    if {[llength $slaves]>0} {
      set isFrameset [expr {[winfo class [lindex $slaves 0]] eq "Frameset"}]
    }
    return $isFrameset
  }

  set DelegateOption(-forcefontmetrics) myHv3
  set DelegateOption(-fonttable) myHv3
  set DelegateOption(-fontscale) myHv3
  set DelegateOption(-zoom) myHv3
  set DelegateOption(-enableimages) myHv3
  set DelegateOption(-dom) myHv3
  set DelegateOption(-width) myHv3
  set DelegateOption(-height) myHv3
  set DelegateOption(-requestcmd) myHv3
  set DelegateOption(-resetcmd) myHv3


  proc stop {me args} {
    upvar #0 $me O
    eval $O(myHv3) stop $args
  }
  proc titlevar {me args} {
    upvar #0 $me O
................................................................................

    # List of all ::hv3::browser_frame objects using this object as
    # their toplevel browser. 
    set O(myFrames) [list]

    set O(myDom) [::hv3::dom %AUTO% $me]




    # The main browser frame (always present).
    set O(myHistory) ""
    set O(myMainFrame) [::hv3::browser_frame $O(win).frame $me]
    #set O(myMainFrame) $O(hull)

    # Create the protocol object.
    set O(myProtocol) [::hv3::protocol %AUTO%]

    # The history sub-system.
    set hv3 [$O(myMainFrame) hv3]
    set O(myHistory) [::hv3::history %AUTO% $hv3 $O(myProtocol) $me]

    # The widget may be in one of two states - "pending" or "not pending".
    # "pending" state is when the browser is still waiting for one or more
    # downloads to finish before the document is correctly displayed. In
................................................................................
    eval $O(myMainFrame) titlevar $args
  }

  # This method is called to activate the download-manager to download
  # the specified URI ($uri) to the local file-system.
  #
  proc saveuri {me uri} {


    set handle [::hv3::request %AUTO%              \
        -uri         $uri                           \
        -mimetype    application/gzip               \
    ]
    $handle configure \
        -incrscript [list ::hv3::the_download_manager savehandle $handle] \
        -finscript  [list ::hv3::the_download_manager savehandle $handle]

    $O(myProtocol) requestcmd $handle
  }

  # Interface used by code in class ::hv3::browser_frame for frame management.
  #
  proc add_frame {me frame} {
    upvar #0 $me O

    lappend O(myFrames) $frame
    if {$O(myHistory) ne ""} {
      $O(myHistory) add_hv3 [$frame hv3]
    }
    set HTML [[$frame hv3] html]
    bind $HTML <1>               [list focus %W]
    bind $HTML <KeyPress-slash>  [list $me Find]
    bindtags $HTML [concat Hv3HotKeys $me [bindtags $HTML]]
    if {[$O(myDom) cget -enable]} {
      $frame configure -dom $O(myDom)
    }




    catch {$::hv3::G(config) configureframe $frame}
  }
  proc del_frame {me frame} {
    upvar #0 $me O
    set idx [lsearch $O(myFrames) $frame]
    if {$idx >= 0} {
      set O(myFrames) [lreplace $O(myFrames) $idx $idx]
................................................................................
        $O(-stopbutton) configure        \
            -command [list $O(myMainFrame) stop]  \
            -image hv3_stopimg                 \
            -tooltip "Stop Current Download"
      } else {
        $O(hull) configure -cursor ""
        $O(-stopbutton) configure        \
            -command [list gui_current reload] \
            -image hv3_reloadimg               \
            -tooltip "Reload Current Document"
      }
    }
    set O(myIsPending) $isPending
  }

................................................................................
  proc reload {me } {
    upvar #0 $me O
    $O(myHistory) reload
  }

  proc configure-enablejavascript {me} {
    upvar #0 $me O
    $O(myDom) configure -enable $value
    set dom ""
    if {$value} { set dom $O(myDom) }
    foreach f $O(myFrames) {
      $f configure -dom $dom
    }
  }

  proc populate_history_menu {me args} {
    upvar #0 $me O







>







 







>







 







<







 







|



<
<
<
<
<
<
<
<
<


<
<










|
|

|
>
|




|







 







|
|
|
|
|
|
|
|
|
>







 







>
>
>





<
<
<







 







>
>





|
|








>











>
>
>
>







 







|







 







|

|







14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
..
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
..
94
95
96
97
98
99
100

101
102
103
104
105
106
107
...
131
132
133
134
135
136
137
138
139
140
141









142
143


144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
...
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
...
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596



597
598
599
600
601
602
603
...
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
...
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
...
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
source [sourcefile hv3_notebook.tcl]
source [sourcefile hv3_db.tcl]
source [sourcefile hv3_home.tcl]
source [sourcefile hv3.tcl]
source [sourcefile hv3_prop.tcl]
source [sourcefile hv3_log.tcl]
source [sourcefile hv3_http.tcl]
source [sourcefile hv3_download.tcl]
source [sourcefile hv3_frameset.tcl]
source [sourcefile hv3_polipo.tcl]
source [sourcefile hv3_icons.tcl]
source [sourcefile hv3_history.tcl]
source [sourcefile hv3_string.tcl]
source [sourcefile hv3_bookmarks.tcl]
source [sourcefile hv3_bugreport.tcl]
................................................................................

  proc new {me browser args} {
    upvar #0 $me O

    # The name of this frame (as specified by the "name" attribute of 
    # the <frame> element).
    set O(-name) ""
    set O(oldname) ""

    # If this [::hv3::browser_frame] is used as a replacement object
    # for an <iframe> element, then this option is set to the Tkhtml3
    # node-handle for that <iframe> element.
    #
    set O(-iframe) ""

................................................................................
    #set O(myHv3)      [::hv3::hv3 $O(win).hv3]
    #pack $O(myHv3) -expand true -fill both
    set O(myHv3) $O(hull)

    ::hv3::the_visited_db init $O(myHv3)

    catch {$O(myHv3) configure -fonttable $::hv3::fontsize_table}


    # Create bindings for motion, right-click and middle-click.
    $O(myHv3) Subscribe motion [list $me motion]
    bind $O(win) <3>       [list $me rightclick %x %y %X %Y]
    #bind $O(win) <2>       [list $me goto_selection]
    bind $O(win) <2>       [list $me middleclick %x %y]

................................................................................
    ::hv3::menu $O(win).hyperlinkmenu
    selection handle $O(win).hyperlinkmenu [list $me GetCopiedLinkLocation]
  }
  proc destroy {me} {
    upvar #0 $me O
    catch {$me ConfigureName -name ""}
    # Remove this object from the $theFrames list.
    catch {$O(myBrowser) del_frame $O(win)} msg
    catch {::destroy $O(win).hyperlinkmenu}
  }










  proc configure-name {me} {
    upvar #0 $me O



    # This method is called when the "name" of attribute of this
    # frame is modified. If javascript is enabled we have to update
    # the properties on the parent window object (if any).
    set dom [$me cget -dom]
    if {$dom ne "" && [$dom cget -enable]} {
      set parent [$me parent_frame]
      if {$parent ne ""} {
        set parent_window [list ::hv3::DOM::Window $dom [$parent hv3]]
        set this_win [list ::hv3::DOM::Window $dom $O(myHv3)]
        if {$O(oldname) ne ""} {
          $dom set_object_property $parent_window $O(oldname) undefined
        }
        if {$O(-name) ne ""} {
          set val [list object $this_win]
          $dom set_object_property $parent_window $O(-name) $val
        }
      }
    }

    set O(oldname) $O(-name)
  }

  proc Targetcmd {me node} {
    upvar #0 $me O
    set target [$node attr -default "" target]
    if {$target eq ""} {
      # If there is no target frame specified, see if a default
................................................................................
    if {[llength $slaves]>0} {
      set isFrameset [expr {[winfo class [lindex $slaves 0]] eq "Frameset"}]
    }
    return $isFrameset
  }

  set DelegateOption(-forcefontmetrics) myHv3
  set DelegateOption(-fonttable)        myHv3
  set DelegateOption(-fontscale)        myHv3
  set DelegateOption(-zoom)             myHv3
  set DelegateOption(-enableimages)     myHv3
  set DelegateOption(-dom)              myHv3
  set DelegateOption(-width)            myHv3
  set DelegateOption(-height)           myHv3
  set DelegateOption(-requestcmd)       myHv3
  set DelegateOption(-resetcmd)         myHv3
  set DelegateOption(-downloadcmd)      myHv3

  proc stop {me args} {
    upvar #0 $me O
    eval $O(myHv3) stop $args
  }
  proc titlevar {me args} {
    upvar #0 $me O
................................................................................

    # List of all ::hv3::browser_frame objects using this object as
    # their toplevel browser. 
    set O(myFrames) [list]

    set O(myDom) [::hv3::dom %AUTO% $me]

    # Create the protocol object.
    set O(myProtocol) [::hv3::protocol %AUTO%]

    # The main browser frame (always present).
    set O(myHistory) ""
    set O(myMainFrame) [::hv3::browser_frame $O(win).frame $me]
    #set O(myMainFrame) $O(hull)




    # The history sub-system.
    set hv3 [$O(myMainFrame) hv3]
    set O(myHistory) [::hv3::history %AUTO% $hv3 $O(myProtocol) $me]

    # The widget may be in one of two states - "pending" or "not pending".
    # "pending" state is when the browser is still waiting for one or more
    # downloads to finish before the document is correctly displayed. In
................................................................................
    eval $O(myMainFrame) titlevar $args
  }

  # This method is called to activate the download-manager to download
  # the specified URI ($uri) to the local file-system.
  #
  proc saveuri {me uri} {
    upvar #0 $me O

    set handle [::hv3::request %AUTO%              \
        -uri         $uri                           \
        -mimetype    application/gzip               \
    ]
    $handle configure \
        -incrscript [list ::hv3::the_download_manager savehandle "" $handle] \
        -finscript  [list ::hv3::the_download_manager savehandle "" $handle]

    $O(myProtocol) requestcmd $handle
  }

  # Interface used by code in class ::hv3::browser_frame for frame management.
  #
  proc add_frame {me frame} {
    upvar #0 $me O

    lappend O(myFrames) $frame
    if {$O(myHistory) ne ""} {
      $O(myHistory) add_hv3 [$frame hv3]
    }
    set HTML [[$frame hv3] html]
    bind $HTML <1>               [list focus %W]
    bind $HTML <KeyPress-slash>  [list $me Find]
    bindtags $HTML [concat Hv3HotKeys $me [bindtags $HTML]]
    if {[$O(myDom) cget -enable]} {
      $frame configure -dom $O(myDom)
    }

    set cmd [list ::hv3::the_download_manager savehandle $O(myProtocol)]
    $frame configure -downloadcmd $cmd

    catch {$::hv3::G(config) configureframe $frame}
  }
  proc del_frame {me frame} {
    upvar #0 $me O
    set idx [lsearch $O(myFrames) $frame]
    if {$idx >= 0} {
      set O(myFrames) [lreplace $O(myFrames) $idx $idx]
................................................................................
        $O(-stopbutton) configure        \
            -command [list $O(myMainFrame) stop]  \
            -image hv3_stopimg                 \
            -tooltip "Stop Current Download"
      } else {
        $O(hull) configure -cursor ""
        $O(-stopbutton) configure        \
            -command [list $me reload] \
            -image hv3_reloadimg               \
            -tooltip "Reload Current Document"
      }
    }
    set O(myIsPending) $isPending
  }

................................................................................
  proc reload {me } {
    upvar #0 $me O
    $O(myHistory) reload
  }

  proc configure-enablejavascript {me} {
    upvar #0 $me O
    $O(myDom) configure -enable $O(-enablejavascript)
    set dom ""
    if {$O(-enablejavascript)} { set dom $O(myDom) }
    foreach f $O(myFrames) {
      $f configure -dom $dom
    }
  }

  proc populate_history_menu {me args} {
    upvar #0 $me O

Changes to hv/hv3_debug.tcl.

1
2
3
4
5
6
7
8
...
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
namespace eval hv3 { set {version($Id: hv3_debug.tcl,v 1.13 2008/01/24 10:29:21 danielk1977 Exp $)} 1 }

namespace eval ::hv3 {
  ::snit::widget console {

    # Entry field for typing commands (entry widget):
    variable myEntryField 

................................................................................
  proc images {{all_tabs 0}} {
    set nPix 0
    set nImg 0

    if {$all_tabs} {
      set data [list]
      foreach browser [.notebook tabs] {
        eval lappend data [[$browser hv3] _images]
      }
    } else {
      set data [hv3 _images]
    }

    set header [list URL "Tk image" pixmap width height alpha references]
    foreach record [concat [list $header] $data] {
      foreach $header $record break
      if {[string length $URL] > 15} {
        set URL "...[string range $URL [expr [string length $URL]-12] end]"
|







 







|


|







1
2
3
4
5
6
7
8
...
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
namespace eval hv3 { set {version($Id: hv3_debug.tcl,v 1.14 2008/02/02 17:15:02 danielk1977 Exp $)} 1 }

namespace eval ::hv3 {
  ::snit::widget console {

    # Entry field for typing commands (entry widget):
    variable myEntryField 

................................................................................
  proc images {{all_tabs 0}} {
    set nPix 0
    set nImg 0

    if {$all_tabs} {
      set data [list]
      foreach browser [.notebook tabs] {
        eval lappend data [[$browser hv3] html _images]
      }
    } else {
      set data [hv3 html _images]
    }

    set header [list URL "Tk image" pixmap width height alpha references]
    foreach record [concat [list $header] $data] {
      foreach $header $record break
      if {[string length $URL] > 15} {
        set URL "...[string range $URL [expr [string length $URL]-12] end]"

Changes to hv/hv3_frameset.tcl.

1
2
3
4
5
6
7
8
..
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
..
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
..
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
...
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
namespace eval hv3 { set {version($Id: hv3_frameset.tcl,v 1.17 2007/11/11 11:00:47 danielk1977 Exp $)} 1 }

# This file contains code for implementing HTML frameset documents in Hv3. 
#
# Each <frameset> element is implemented by a single ::hv3::frameset
# widget. 
#

................................................................................
  # Set this global variable to true to enable frameset-related
  # debugging output on stderr.
  set FRAMESET_DEBUG 0

  # Create a window name to use for a replaced object for node $node.
  # The first argument is the name of an ::hv3::browser_frame widget.
  #
  proc create_widget_name {browser_frame node} {
    return [[$browser_frame hv3] html].[string map {: _} $node]
  }

  proc multilength_to_list {multilength} {
    set ret [list]
    foreach elem [split $multilength ,] {
      lappend ret [string trim $elem]
    }
................................................................................

    # Make sure this is not a nested <frameset> element. If it is, ignore
    # it. Only the outer <frameset> is managed by the hv3 widget.
    for {set N [$node parent]} {$N ne ""} {set N [$N parent]} {
      if {[$N tag] eq "frameset"} return
    }

    set win [create_widget_name $browser_frame $node]
    ::hv3::frameset $win $browser_frame $node

    # The 'display' property of <frameset> elements is set to "none" by
    # the default stylesheet. So replacing the <frameset> node with the new
    # ::hv3::frameset widget does not cause the html widget to map the
    # frameset widget. Instead we use standard Tk [grid] to put our
    # widget on top of the html widget.
................................................................................
  #     argument is the name of an ::hv3::browser_frame widget. The
  #     second argument is the <iframe> node.
  #
  proc iframe_handler {browser_frame node} {
    set hv3 [$browser_frame hv3]

    # Create an ::hv3::browser_frame to display the resource.
    set panel [create_widget_name $browser_frame $node]
    ::hv3::browser_frame $panel [$browser_frame browser]
    [[$panel hv3] html] configure -shrink 1

    # TODO: Should be properly configured...
    $panel configure -requestcmd [$browser_frame cget -requestcmd]
    $panel configure -statusvar  [$browser_frame cget -statusvar]
    $panel configure -name [$node attr -default "" name]
................................................................................
          }
          $pframe configure -name [$pnode attr -default "" name]
        }
        frameset {
	  # For a frameset, we need to create the equivalent HTML document.
          set doc "<html>[::hv3::get_markup $pnode]</html>"
          $phv3 seturi [$myHv3 resolve_uri "internal"]
          $phv3 parse -final $doc
        }
      }
    }

    foreach pan [array names divwidth] {
      switch $divwidth($pan) {
        0 {
|







 







|
|







 







|







 







|







 







|







1
2
3
4
5
6
7
8
..
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
..
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
..
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
...
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
namespace eval hv3 { set {version($Id: hv3_frameset.tcl,v 1.18 2008/02/02 17:15:02 danielk1977 Exp $)} 1 }

# This file contains code for implementing HTML frameset documents in Hv3. 
#
# Each <frameset> element is implemented by a single ::hv3::frameset
# widget. 
#

................................................................................
  # Set this global variable to true to enable frameset-related
  # debugging output on stderr.
  set FRAMESET_DEBUG 0

  # Create a window name to use for a replaced object for node $node.
  # The first argument is the name of an ::hv3::browser_frame widget.
  #
  proc create_widget_name {node} {
    return [$node html].[string map {: _} $node]
  }

  proc multilength_to_list {multilength} {
    set ret [list]
    foreach elem [split $multilength ,] {
      lappend ret [string trim $elem]
    }
................................................................................

    # Make sure this is not a nested <frameset> element. If it is, ignore
    # it. Only the outer <frameset> is managed by the hv3 widget.
    for {set N [$node parent]} {$N ne ""} {set N [$N parent]} {
      if {[$N tag] eq "frameset"} return
    }

    set win [create_widget_name $node]
    ::hv3::frameset $win $browser_frame $node

    # The 'display' property of <frameset> elements is set to "none" by
    # the default stylesheet. So replacing the <frameset> node with the new
    # ::hv3::frameset widget does not cause the html widget to map the
    # frameset widget. Instead we use standard Tk [grid] to put our
    # widget on top of the html widget.
................................................................................
  #     argument is the name of an ::hv3::browser_frame widget. The
  #     second argument is the <iframe> node.
  #
  proc iframe_handler {browser_frame node} {
    set hv3 [$browser_frame hv3]

    # Create an ::hv3::browser_frame to display the resource.
    set panel [create_widget_name $node]
    ::hv3::browser_frame $panel [$browser_frame browser]
    [[$panel hv3] html] configure -shrink 1

    # TODO: Should be properly configured...
    $panel configure -requestcmd [$browser_frame cget -requestcmd]
    $panel configure -statusvar  [$browser_frame cget -statusvar]
    $panel configure -name [$node attr -default "" name]
................................................................................
          }
          $pframe configure -name [$pnode attr -default "" name]
        }
        frameset {
	  # For a frameset, we need to create the equivalent HTML document.
          set doc "<html>[::hv3::get_markup $pnode]</html>"
          $phv3 seturi [$myHv3 resolve_uri "internal"]
          $phv3 html parse -final $doc
        }
      }
    }

    foreach pan [array names divwidth] {
      switch $divwidth($pan) {
        0 {

Changes to hv/hv3_history.tcl.

1
2
3
4
5
6
7
8
...
470
471
472
473
474
475
476


477
478
479
480
481
482
483
484
...
645
646
647
648
649
650
651

652






653
654
655
656
657
658
659
namespace eval hv3 { set {version($Id: hv3_history.tcl,v 1.31 2008/01/31 06:49:53 danielk1977 Exp $)} 1 }

package require snit

# History state for a single browser window.
#
snit::type ::hv3::history_state {

................................................................................
    $myEntry configure -borderwidth 0 -highlightthickness 0
    $myButton configure -borderwidth 1 -highlightthickness 0
    $hull configure -borderwidth 1 -relief sunken -background white

    # Create the listbox for the drop-down list. This is a child of
    # the same top-level as the ::hv3::locationentry widget...
    #


    set myListbox [winfo toplevel $win][string map {. _} ${win}]
    ::hv3::scrolledlistbox $myListbox -takefocus 0

    # Any button-press anywhere in the GUI folds up the drop-down menu.
    bind [winfo toplevel $win] <ButtonPress> +[list $self AnyButtonPress %W]

    bind $myEntry <KeyPress>        +[list $self KeyPress]
    bind $myEntry <KeyPress-Return> +[list $self KeyPressReturn]
................................................................................
    }
    rename $me ""
    unset $me
  }
  proc add {me handle} {
    upvar #0 $me O
    lappend O(handles) $handle

    set O(cache.[$handle cget -uri]) $handle






    $handle reference
    if {[llength $O(handles)]>=25} {
      foreach h [lrange $O(handles) 0 4] {
        unset O(cache.[$h cget -uri])
        $h release
      }
      set O(handles) [lrange $O(handles) 5 end]
|







 







>
>
|







 







>
|
>
>
>
>
>
>







1
2
3
4
5
6
7
8
...
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
...
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
namespace eval hv3 { set {version($Id: hv3_history.tcl,v 1.32 2008/02/02 17:15:02 danielk1977 Exp $)} 1 }

package require snit

# History state for a single browser window.
#
snit::type ::hv3::history_state {

................................................................................
    $myEntry configure -borderwidth 0 -highlightthickness 0
    $myButton configure -borderwidth 1 -highlightthickness 0
    $hull configure -borderwidth 1 -relief sunken -background white

    # Create the listbox for the drop-down list. This is a child of
    # the same top-level as the ::hv3::locationentry widget...
    #
    set top [winfo toplevel $win]
    if {$top eq "."} {set top ""}
    set myListbox $top.[string map {. _} ${win}]
    ::hv3::scrolledlistbox $myListbox -takefocus 0

    # Any button-press anywhere in the GUI folds up the drop-down menu.
    bind [winfo toplevel $win] <ButtonPress> +[list $self AnyButtonPress %W]

    bind $myEntry <KeyPress>        +[list $self KeyPress]
    bind $myEntry <KeyPress-Return> +[list $self KeyPressReturn]
................................................................................
    }
    rename $me ""
    unset $me
  }
  proc add {me handle} {
    upvar #0 $me O
    lappend O(handles) $handle

    set key catch.[$handle cget -uri]
    if {[info exists O($key)]} {
      set idx [lsearch $O(handles) $O($key)]
      set O(handles) [lreplace $O(handles) $idx $idx]
    }
    set O($key) $handle

    $handle reference
    if {[llength $O(handles)]>=25} {
      foreach h [lrange $O(handles) 0 4] {
        unset O(cache.[$h cget -uri])
        $h release
      }
      set O(handles) [lrange $O(handles) 5 end]

Changes to hv/hv3_home.tcl.

1
2
3
4
5
6
7
8
..
73
74
75
76
77
78
79





80
81
82
83
84
85
86
namespace eval hv3 { set {version($Id: hv3_home.tcl,v 1.40 2007/10/29 14:49:42 danielk1977 Exp $)} 1 }

# Register the home: scheme handler with ::hv3::protocol $protocol.
#
proc ::hv3::home_scheme_init {hv3 protocol} {
  set dir $::hv3::maindir
  $protocol schemehandler home [list ::hv3::home_request $protocol $hv3 $dir]
}
................................................................................
          }
        }
      } else {
        set obj [string range $path 1 end]
        set data [::hv3::DOM::docs::${obj}]
      }
    }






    bookmarks_left { }
    bookmarks {
      if {$path eq "" || $path eq "/"} {
        $downloadHandle append {
          <FRAMESET cols="33%,*">
            <FRAME src="home://bookmarks_left">
|







 







>
>
>
>
>







1
2
3
4
5
6
7
8
..
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
namespace eval hv3 { set {version($Id: hv3_home.tcl,v 1.41 2008/02/02 17:15:02 danielk1977 Exp $)} 1 }

# Register the home: scheme handler with ::hv3::protocol $protocol.
#
proc ::hv3::home_scheme_init {hv3 protocol} {
  set dir $::hv3::maindir
  $protocol schemehandler home [list ::hv3::home_request $protocol $hv3 $dir]
}
................................................................................
          }
        }
      } else {
        set obj [string range $path 1 end]
        set data [::hv3::DOM::docs::${obj}]
      }
    }

    downloads {
      ::hv3::the_download_manager request $downloadHandle
      return
    }

    bookmarks_left { }
    bookmarks {
      if {$path eq "" || $path eq "/"} {
        $downloadHandle append {
          <FRAMESET cols="33%,*">
            <FRAME src="home://bookmarks_left">

Changes to hv/hv3_http.tcl.

1
2
3
4
5
6
7
8
...
463
464
465
466
467
468
469
470
471
472

473
474
475
476
477
478
479
...
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
namespace eval hv3 { set {version($Id: hv3_http.tcl,v 1.64 2008/01/31 05:57:46 danielk1977 Exp $)} 1 }

#
# This file contains implementations of the -requestcmd script used with 
# the hv3 widget for the browser. Supported functions are:
#
#     * http:// (including cookies)
#     * file:// (code for this is now in hv3_file.tcl)
................................................................................
      [lsearch $O(myInProgressHandles) $downloadHandle] >= 0 ||
      [lsearch $O(myWaitingHandles) $downloadHandle] >= 0
    } {
      catch {$O(myGui) uri_done [$downloadHandle cget -uri]}
      if {[$downloadHandle cget -cacheable]} {
        ::hv3::the_httpcache add $downloadHandle
      }
      $downloadHandle finish
    }


    ::http::cleanup $token
  }

  proc debug_cookies {me} {
    upvar $me O
    $O(myCookieManager) debug
  }
................................................................................
    if {$n > [${win}.text.widget cget -height]} {
      ${win}.text.widget configure -height $n
    }
    ${win}.text yview moveto $yview
  }
}

#
# ::hv3::filedownload
#
# Each currently downloading file is managed by an instance of the
# following object type. All instances in the application are managed
# by the [::hv3::the_download_manager] object, an instance of
# class ::hv3::downloadmanager (see below).
#
# SYNOPSIS:
#
#     set obj [::hv3::filedownload %AUTO% ?OPTIONS?]
#
#     $obj set_destination $PATH
#     $obj append $DATA
#     $obj finish
#
# Options are:
#
#     Option        Default   Summary
#     -------------------------------------
#     -source       ""        Source of download (for display only)
#     -cancelcmd    ""        Script to invoke to cancel the download
#
snit::type ::hv3::filedownload {

  # The destination path (in the local filesystem) and the corresponding
  # tcl channel (if it is open). These two variables also define the 
  # three states that this object can be in:
  #
  # INITIAL:
  #     No destination path has been provided yet. Both myDestination and
  #     myChannel are set to an empty string.
  #
  # STREAMING:
  #     A destination path has been provided and the destination file is
  #     open. But the download is still in progress. Neither myDestination
  #     nor myChannel are set to an empty string.
  #
  # FINISHED:
  #     A destination path is provided and the entire download has been
  #     saved into the file. We're just waiting for the user to dismiss
  #     the GUI. In this state, myChannel is set to an empty string but
  #     myDestination is not.
  #
  variable myDestination ""
  variable myChannel ""

  # Buffer for data while waiting for a file-name. This is used only in the
  # state named INITIAL in the above description. The $myIsFinished flag
  # is set to true if the download is finished (i.e. [finish] has been 
  # called).
  variable myBuffer ""
  variable myIsFinished 0

  option -source    -default ""
  option -cancelcmd -default ""
  option -updateguicmd -default ""

  # Total bytes downloaded so far.
  variable myDownloaded 0

  # Total bytes expected (i.e. size of the download)
  variable myExpected 0

  constructor {args} {
    $self configurelist $args
  }

  method set_destination {dest isFinished} {
    if {$isFinished} {
      set myIsFinished 1
    }

    # It is an error if this method has been called before.
    if {$myDestination ne ""} {
      error "This ::hv3::filedownloader already has a destination!"
    }

    if {$dest eq ""} {
      # Passing an empty string to this method cancels the download.
      # This is for conveniance, because [tk_getSaveFile] returns an 
      # empty string when the user selects "Cancel".
      $self Cancel
      destroy $self
    } else {
      # Set the myDestination variable and open the channel to the
      # file to write. Todo: An error could occur opening the file.
      set myDestination $dest
      set myChannel [open $myDestination w]
      fconfigure $myChannel -encoding binary -translation binary

      # If a buffer has accumulated, write it to the new channel.
      puts -nonewline $myChannel $myBuffer
      set myBuffer ""

      # If the myIsFinished flag is set, then the entire download
      # was already in the buffer. We're finished.
      if {$myIsFinished} {
        $self finish {} {}
      }

      ::hv3::the_download_manager manage $self
    }
  }

  # This internal method is called to cancel the download. When this
  # returns the object will have been destroyed.
  #
  method Cancel {} {
    # Evaluate the -cancelcmd script and destroy the object.
    eval $options(-cancelcmd)
    if {$myDestination ne ""} {
      catch {close $myChannel}
      catch {file delete $myDestination}
    }
  }

  # Update the GUI to match the internal state of this object.
  #
  method Updategui {} {
    if {$options(-updateguicmd) ne ""} {
      eval $options(-updateguicmd)
    }
  }

  method append {handle data} {
    set myExpected [$handle cget -expectedsize]
    if {$myChannel ne ""} {
      puts -nonewline $myChannel $data
      set myDownloaded [file size $myDestination]
    } else {
      append myBuffer $data
      set myDownloaded [string length $myBuffer]
    }
    $self Updategui
  }

  # Called by the driver download-handle when the download is 
  # complete. All the data will have been already passed to [append].
  #
  method finish {handle data} {
    if {$data ne ""} {
      $self append $handle $data
    }

    # If the channel is open, close it. Also set the button to say "Ok".
    if {$myChannel ne ""} {
      close $myChannel
      set myChannel ""
    }

    # If myIsFinished flag is not set, set it and then set myElapsed to
    # indicate the time taken by the download.
    if {!$myIsFinished} {
      set myIsFinished 1
    }

    # Update the GUI.
    $self Updategui

    # Delete the download request.
    if {$handle ne ""} {
      $handle destroy
    }
  }

  destructor {
    catch { close $myChannel }
  }

  # Query interface used by ::hv3::downloadmanager GUI. It cares about
  # four things: 
  #
  #     * the percentage of the download has been completed, and
  #     * the state of the download (either "Downloading" or "Finished").
  #     * the source URI
  #     * the destination file
  #
  method state {} {
    if {$myIsFinished} {return "Finished"}
    return "Downloading"
  }
  method percentage {} {
    if {$myIsFinished} {return 100}
    if {$myExpected eq "" || $myExpected == 0} {
      return [expr {$myDownloaded > 0 ? 50 : 0}]
    }
    return [expr double($myDownloaded) / double($myExpected) * 100]
  }
  method bytes {} {
    return $myDownloaded
  }
  method source {} {
    return $options(-source)
  }
  method destination {} {
    return $myDestination
  }
}

# ::hv3::downloadmanager
#
# SYNOPSIS
#
#     set obj [::hv3::downloadmanager %AUTO%]
#
#     $obj show
#     $obj manage FILE-DOWNLOAD
#
#     destroy $obj
#
snit::type ::hv3::downloadmanager {
  variable myDownloads [list]
  variable myHv3List [list]

  method manage {filedownload} {
    $filedownload configure -updateguicmd [list $self UpdateGui $filedownload]
    lappend myDownloads $filedownload
    $self CheckGuiList
    foreach hv3 $myHv3List {
      $hv3 goto download: -cachecontrol no-cache
    }
  }

  # This is a helper proc for method [savehandle] to extract any
  # filename-parameter from the value of an HTTP Content-Disposition
  # header. If one exists, the value of the filename parameter is
  # returned. Otherwise, an empty string.
  # 
  # Refer to RFC1806 for the complete format of a Content-Disposition 
  # header. An example is:
  #
  #     {inline ; filename="src.tar.gz"}
  #
  proc ParseContentDisposition {value} {
    set tokens [::hv3::string::tokenise $value]

    set filename ""
    for {set ii 0} {$ii < [llength $tokens]} {incr ii} {
      set t [lindex $tokens $ii]
      set t2 [lindex $tokens [expr $ii+1]]

      if {[string match -nocase $t "filename"] && $t2 eq "="} {
        set filename [lindex $tokens [expr $ii+2]]
        set filename [::hv3::string::dequote $filename]
        break
      }
    }

    return $filename
  }

  # Activate the download manager to save the resource targeted by the
  # ::hv3::request passed as an argument ($handle) to the local 
  # file-system. It is the responsbility of the caller to configure 
  # the download-handle and pass it to the protocol object. The second
  # argument, $data, contains an initial segment of the resource that has
  # already been downloaded. 
  #
  method savehandle {handle data {isFinished 0}} {

    # Create a GUI to handle this download
    set dler [::hv3::filedownload %AUTO%                   \
        -source    [$handle cget -uri]                     \
        -cancelcmd [list catch [list $handle destroy]]     \
    ]
    ::hv3::the_download_manager show

    # Redirect the -incrscript and -finscript commands to the download GUI.
    $handle configure -finscript  [list $dler finish $handle]
    $handle configure -incrscript [list $dler append $handle]
    $dler append $handle $data

    # Figure out a default file-name to suggest to the user. This
    # is one of the following (in order of preference):
    #
    # 1. The "filename" field from a Content-Disposition header. The
    #    content disposition header is described in RFC 1806 (and 
    #    later RFC 2183). A Content-Disposition header looks like
    #    this:
    #
    # 2. By extracting the tail of the URI.
    #
    set suggested ""
    foreach {key value} [$handle cget -header] {
      if {[string equal -nocase $key Content-Disposition]} {
        set suggested [ParseContentDisposition $value]
      }
    }
    if {$suggested eq ""} {
      regexp {/([^/]*)$} [$handle cget -uri] -> suggested
    }

    # Pop up a GUI to select a "Save as..." filename. Schedule this as 
    # a background job to avoid any recursive entry to our event handles.
    set cmd [subst -nocommands {
      $dler set_destination [file normal [
          tk_getSaveFile -initialfile {$suggested}
      ]] $isFinished
    }]
    after idle $cmd
  }

  method CheckGuiList {} {
    # Make sure the list of GUI's is up to date.
    set newlist [list]
    foreach hv3 $myHv3List {
      if {[info commands $hv3] eq ""} continue
      if {[string match download* [$hv3 location]] && [$hv3 pending] == 0} {
        lappend newlist $hv3
      } 
    }
    set myHv3List $newlist
  }

  method UpdateGui {{fdownload ""}} {
# puts "UPDATE $fdownload"

    $self CheckGuiList

    set dl_list $fdownload
    if {[llength $dl_list] == 0} {
      set dl_list $myDownloads
    } 
    foreach filedownload $dl_list {
      set id [string map {: _} $filedownload]
      foreach hv3 $myHv3List {

        set search "#$id .progressbar"
        foreach N [$hv3 html search $search] {
          $N override [list width [$filedownload percentage]%]
        }

        set search "#$id .downloading"
        set val visible
        if {[$filedownload state] eq "Finished"} {
          set val hidden
        }
        foreach N [$hv3 html search $search] { 
          $N override [list visibility $val] 
        }

        set val hidden
        if {[$filedownload state] eq "Finished"} {
          set val visible
        }
        set search "#$id .finished"
        foreach N [$hv3 html search $search] { 
          $N override [list visibility $val] 
        }

        set search "#$id .button"
        foreach N [$hv3 html search $search] { 
          set a(Finished)    Dismiss
          set a(Downloading) Cancel
          $N attr value $a([$filedownload state])
        }

        set search "#$id .status span"
        foreach N [$hv3 html search $search] { 
          set percent [format %.2f%s [$filedownload percentage] %]
          set bytes [$filedownload bytes]
          switch -- [$filedownload state] {
            Downloading { set status "Downloaded $bytes bytes ($percent)" }
            Finished    { set status "Finished ($bytes bytes)" }
          }
          $N attr spancontent $status
        }
      }
    }
  }

  method request {hv3 handle} {

    set uri [$handle cget -uri]
    if {[regexp {.*delete=([^=&]*)} $uri -> delete]} {
      set dl [string map {__ ::} $delete]
      set newlist [list]
      foreach download $myDownloads {
        if {$download ne $dl} {lappend newlist $download}
      }
      set myDownloads $newlist
      catch {
        if {[$dl state] ne "Finished"} {
          $dl Cancel
        }
        $dl destroy
      }
      $handle append ""
      $handle finish
      $self CheckGuiList
      foreach hv3 $myHv3List {
        after idle [list $hv3 goto download: -cachecontrol no-cache]
      }
      return
    }

    set document {
      <html><head>
        <style>
          .download { border:solid black 1px; width:90%; margin: 1em auto; }
          .download td { padding: 0px 5px; } 
          .source { width:99%; }
          .progress .progressbarwrapper { border:solid black 1px; width:100%; }
          .progress .progressbar { background-color: navy; height: 1em; }
          .buttons { display:block;width:12ex }
          input { float:right; }
        </style>
        <title>Downloads</title>
        </head>
        <body>
          <h1 align=center>Downloads</h1>
    }
 
    append document "<p>There are [llength $myDownloads] downloads.</p>"

    foreach download $myDownloads {
      set id [string map {: _} $download]
      append document [subst {
        <table class="download" id="$id">
          <tr><td>Source:      
              <td class="source">[$download source]
              <td rowspan=4 valign=bottom>
                 <div class="buttons">
                      <form method=get action=download:///>
                      <input class="button"      type=submit value=Cancel>
                      <input name="delete"       type=hidden value=$id>
                      </form>
          <tr><td>Destination: 
              <td class="destination">[$download destination]
          <tr><td>Status:      
              <td class="status">
                <span spancontent="Waiting (0%)">
              </td>
          <tr><td>Progress:    
              <td class="progress">
                 <div class="progressbarwrapper">
                 <div class="progressbar">
        </table>
      }]
    }

    if {[lsearch $myHv3List $hv3] < 0} {
      lappend myHv3List $hv3
    }

    $handle append $document
    $handle finish

    after idle [list $self UpdateGui]
  }

  method show {} {
    $self CheckGuiList
    if {[llength $myHv3List] > 0} {
      set hv3 [lindex $myHv3List 0]
      set win [winfo parent [winfo parent $hv3]]
      .notebook.notebook select $win
    } else {
      .notebook add download:
    }
  }
}

proc ::hv3::download_scheme_init {hv3 protocol} {
  $protocol schemehandler download [
    list ::hv3::the_download_manager request $hv3
  ]
}

#-----------------------------------------------------------------------
# Work around a bug in http::Finish
#

# First, make sure the http package is actually loaded. Do this by 
# invoking ::http::geturl. The call will fail, since the arguments (none)
# passed to ::http::geturl are invalid.
|







 







<


>







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







1
2
3
4
5
6
7
8
...
463
464
465
466
467
468
469

470
471
472
473
474
475
476
477
478
479
...
550
551
552
553
554
555
556






















































































































































































































































































































































































































































































557
558
559
560
561
562
563
namespace eval hv3 { set {version($Id: hv3_http.tcl,v 1.65 2008/02/02 17:15:02 danielk1977 Exp $)} 1 }

#
# This file contains implementations of the -requestcmd script used with 
# the hv3 widget for the browser. Supported functions are:
#
#     * http:// (including cookies)
#     * file:// (code for this is now in hv3_file.tcl)
................................................................................
      [lsearch $O(myInProgressHandles) $downloadHandle] >= 0 ||
      [lsearch $O(myWaitingHandles) $downloadHandle] >= 0
    } {
      catch {$O(myGui) uri_done [$downloadHandle cget -uri]}
      if {[$downloadHandle cget -cacheable]} {
        ::hv3::the_httpcache add $downloadHandle
      }

    }

    catch { $downloadHandle finish }
    ::http::cleanup $token
  }

  proc debug_cookies {me} {
    upvar $me O
    $O(myCookieManager) debug
  }
................................................................................
    if {$n > [${win}.text.widget cget -height]} {
      ${win}.text.widget configure -height $n
    }
    ${win}.text yview moveto $yview
  }
}























































































































































































































































































































































































































































































#-----------------------------------------------------------------------
# Work around a bug in http::Finish
#

# First, make sure the http package is actually loaded. Do this by 
# invoking ::http::geturl. The call will fail, since the arguments (none)
# passed to ::http::geturl are invalid.

Changes to hv/hv3_main.tcl.

1
2
3
4
5
6
7
8
..
30
31
32
33
34
35
36





























































































37
38
39
40
41
42
43
...
420
421
422
423
424
425
426
427
428
429

430
431
432
433
434
435
436
...
483
484
485
486
487
488
489

490
491
492
493
494
495
496
...
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
...
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
...
961
962
963
964
965
966
967











968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
namespace eval hv3 { set {version($Id: hv3_main.tcl,v 1.185 2008/01/27 14:39:24 danielk1977 Exp $)} 1 }

catch {memory init on}

proc sourcefile {file} [string map              \
  [list %HV3_DIR% [file dirname [info script]]] \
{ 
  return [file join {%HV3_DIR%} $file] 
................................................................................
#     source [sourcefile hv3_console.tcl]
# }

namespace eval ::hv3 {
  set log_source_option 0
  set reformat_scripts_option 0
}






























































































# ::hv3::config
#
#     An instance of this class manages the application "View" menu, 
#     which contains all the runtime configuration options (font size, 
#     image loading etc.).
#
................................................................................

  constructor {} {
    set MENU [list \
      "Open File..."  [list gui_openfile $::hv3::G(notebook)]           o  \
      "Open Tab"      [list $::hv3::G(notebook) add]                    t  \
      "Open Location" [list gui_openlocation $::hv3::G(location_entry)] l  \
      "-----"         ""                                                "" \
      "Bookmark Page" [list ::hv3::gui_bookmark]                        b  \
      "-----"         ""                                                "" \
      "Downloads..."  [list ::hv3::the_download_manager show]           "" \

      "-----"         ""                                                "" \
      "Close Tab"     [list $::hv3::G(notebook) close]                  "" \
      "Exit"          exit                                              q  \
    ]
  }

  method populate_menu {path} {
................................................................................
      "About"                [list $::hv3::G(notebook) add home://about]  "" \
      "Polipo..."            [list ::hv3::polipo::popup]                  "" \
      "Events..."            [list gui_log_window $::hv3::G(notebook)]    "" \
      "-----"                [list]                                       "" \
      "Tree Browser..."      [list gui_current browse]                    "" \
      "Debugging Console..." [list ::hv3::launch_console]                 d  \
      "-----"                [list]                                       "" \

      "Exec firefox -remote" [list gui_firefox_remote]                    "" \
      "-----"                   [list]                                    "" \
      "Reset Profiling Data..." [list ::hv3::profile::zero]               "" \
      "Save Profiling Data..."  [list ::hv3::profile::report_to_file]     "" \
    ]
  }

................................................................................

#--------------------------------------------------------------------------
# The following functions are all called during startup to construct the
# static components of the web browser gui:
#
#     gui_build
#     gui_menu
#       gui_load_tkcon
#       create_fontsize_menu
#       create_fontscale_menu
#

# gui_build --
#
#     This procedure is called once at the start of the script to build
................................................................................
}

proc goto_gui_location {browser entry args} {
  set location [$entry get]
  $browser goto $location
}

# A helper function for gui_menu.
#
# This procedure attempts to load the tkcon package. An error is raised
# if the package cannot be loaded. On success, an empty string is returned.
#
proc gui_load_tkcon {} {
  foreach f [list \
    [file join $::tcl_library .. .. bin tkcon] \
    [file join $::tcl_library .. .. bin tkcon.tcl]
  ] {
    if {[file exists $f]} {
      uplevel #0 "source $f"
      package require tkcon
      return 
    }
  }
  error "Failed to load Tkcon"
  return ""
}

proc gui_openlocation {location_entry} {
  $location_entry selection range 0 end
  $location_entry OpenDropdown *
  focus ${location_entry}.entry
}

proc gui_populate_menu {eMenu menu_widget} {
................................................................................
      append status "          Tcl Heap: ${nBytes} in $nAllocs allocs"
    }

    $G(status_label) configure -text $status
    after 2000 [list gui_set_memstatus $widget_array]
  }
}












# Override the [exit] command to check if the widget code leaked memory
# or not before exiting.
#
rename exit tcl_exit
proc exit {args} {
  destroy .notebook
  catch {destroy .prop.hv3}
  catch {::tkhtml::htmlalloc}
  eval [concat tcl_exit $args]
}

proc JS {args} {
  set script [join $args " "]
  [[gui_current hv3] dom] javascript $script
}

#--------------------------------------------------------------------------
# main URI
#
#     The main() program for the application. This proc handles
#     parsing of command line arguments.
#
proc main {args} {
|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|


>







 







>







 







<







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







>
>
>
>
>
>
>
>
>
>
>












<
<
<
<
<







1
2
3
4
5
6
7
8
..
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
...
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
...
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
...
650
651
652
653
654
655
656

657
658
659
660
661
662
663
...
759
760
761
762
763
764
765




















766
767
768
769
770
771
772
....
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064





1065
1066
1067
1068
1069
1070
1071
namespace eval hv3 { set {version($Id: hv3_main.tcl,v 1.186 2008/02/02 17:15:02 danielk1977 Exp $)} 1 }

catch {memory init on}

proc sourcefile {file} [string map              \
  [list %HV3_DIR% [file dirname [info script]]] \
{ 
  return [file join {%HV3_DIR%} $file] 
................................................................................
#     source [sourcefile hv3_console.tcl]
# }

namespace eval ::hv3 {
  set log_source_option 0
  set reformat_scripts_option 0
}

# This class is used to create toplevel "sub-window" widgets. Sub-windows
# are toplevel windows that contain a single [::hv3::browser] object.
#
# Sub-windows are different from the main window in several ways:
#
#   * There is no menubar.
#   * There is no "new tab", "home" or "bug report button on the toolbar.
#   * It is not possible to open new tabs in a sub-window.
#
# These restrictions are because Hv3 is a tabbed browser. New views are
# supposed to live in tabs, not separate toplevel windows. If the user 
# really wants more than one window, more than one copy of the browser
# should be started. Sub-windows are provided purely for the benefit of
# those javascript applications that have UIs that require multiple 
# windows.
#
namespace eval ::hv3::subwindow {

  set counter 1

  proc new {me args} {
    upvar #0 $me O

    set O(browser)  [::hv3::browser $O(win).browser]
    set O(label)    [::hv3::label $O(win).label -anchor w -width 1]
    set O(location) [::hv3::locationentry $O(win).location]

    set O(stop_button) $O(win).stop
    set O(back_button) $O(win).back
    set O(next_button) $O(win).next

    ::hv3::toolbutton $O(stop_button) -text {Stop} -tooltip "Stop"
    ::hv3::toolbutton $O(next_button) -text {Forward} -tooltip "Go Forward"
    ::hv3::toolbutton $O(back_button) -text {Back} -tooltip "Go Back"
   
    grid $O(back_button) $O(next_button) $O(stop_button) 
    grid $O(location)    -column 3 -row 0 -sticky ew
    grid $O(browser)     -column 0 -row 1 -sticky nsew -columnspan 4
    grid $O(label)       -column 0 -row 2 -sticky nsew -columnspan 4

    grid columnconfigure $O(win) 3 -weight 1
    grid rowconfigure    $O(win) 1 -weight 1

    $O(back_button) configure -image hv3_previmg
    $O(next_button) configure -image hv3_nextimg
    $O(stop_button) configure -image hv3_reloadimg

    $O(label)    configure -textvar       [$O(browser) statusvar] 
    $O(browser)  configure -stopbutton    $O(stop_button)
    $O(browser)  configure -forwardbutton $O(next_button)
    $O(browser)  configure -backbutton    $O(back_button)
    $O(browser)  configure -locationentry $O(location)
    $O(location) configure -command       [list $me GotoLocation]

    $O(browser) configure -width 600 -height 400

    set O(titlevarname)    [$O(browser) titlevar]
    set O(locationvarname) [$O(browser) locationvar]

    # Set up traces on the browser title and location. Use these to
    # set the title of the toplevel window.
    trace add variable $O(titlevarname)    write [list $me SetTitle]
    trace add variable $O(locationvarname) write [list $me SetTitle]
  }

  proc SetTitle {me args} {
    upvar #0 $me O
    set T [set [$O(browser) titlevar]]
    if {$T eq ""} {
      set T [set [$O(browser) locationvar]]
    }
    wm title $O(win) $T
  }

  proc destroy {me} {
    upvar #0 $me O
    trace remove variable $O(titlevarname)    write [list $me SetTitle]
    trace remove variable $O(locationvarname) write [list $me SetTitle]
  }

  proc goto {me uri} {
    upvar #0 $me O
    $O(browser) goto $uri
  }

  proc GotoLocation {me} {
    upvar #0 $me O
    set uri [$O(location) get]
    $O(browser) goto $uri
  }
}
::hv3::make_constructor ::hv3::subwindow toplevel

# ::hv3::config
#
#     An instance of this class manages the application "View" menu, 
#     which contains all the runtime configuration options (font size, 
#     image loading etc.).
#
................................................................................

  constructor {} {
    set MENU [list \
      "Open File..."  [list gui_openfile $::hv3::G(notebook)]           o  \
      "Open Tab"      [list $::hv3::G(notebook) add]                    t  \
      "Open Location" [list gui_openlocation $::hv3::G(location_entry)] l  \
      "-----"         ""                                                "" \
      "Bookmark This Page" [list ::hv3::gui_bookmark]                   b  \
      "-----"         ""                                                "" \
      "Downloads..."  [list ::hv3::the_download_manager show]           "" \
      "Bookmarks..."  [list gui_current goto home://bookmarks/]         "" \
      "-----"         ""                                                "" \
      "Close Tab"     [list $::hv3::G(notebook) close]                  "" \
      "Exit"          exit                                              q  \
    ]
  }

  method populate_menu {path} {
................................................................................
      "About"                [list $::hv3::G(notebook) add home://about]  "" \
      "Polipo..."            [list ::hv3::polipo::popup]                  "" \
      "Events..."            [list gui_log_window $::hv3::G(notebook)]    "" \
      "-----"                [list]                                       "" \
      "Tree Browser..."      [list gui_current browse]                    "" \
      "Debugging Console..." [list ::hv3::launch_console]                 d  \
      "-----"                [list]                                       "" \
      "Sub-Window..."        gui_subwindow                                "" \
      "Exec firefox -remote" [list gui_firefox_remote]                    "" \
      "-----"                   [list]                                    "" \
      "Reset Profiling Data..." [list ::hv3::profile::zero]               "" \
      "Save Profiling Data..."  [list ::hv3::profile::report_to_file]     "" \
    ]
  }

................................................................................

#--------------------------------------------------------------------------
# The following functions are all called during startup to construct the
# static components of the web browser gui:
#
#     gui_build
#     gui_menu

#       create_fontsize_menu
#       create_fontscale_menu
#

# gui_build --
#
#     This procedure is called once at the start of the script to build
................................................................................
}

proc goto_gui_location {browser entry args} {
  set location [$entry get]
  $browser goto $location
}





















proc gui_openlocation {location_entry} {
  $location_entry selection range 0 end
  $location_entry OpenDropdown *
  focus ${location_entry}.entry
}

proc gui_populate_menu {eMenu menu_widget} {
................................................................................
      append status "          Tcl Heap: ${nBytes} in $nAllocs allocs"
    }

    $G(status_label) configure -text $status
    after 2000 [list gui_set_memstatus $widget_array]
  }
}

# Launch a new sub-window.
#
proc gui_subwindow {{uri ""}} {
  set name ".subwindow_[incr ::hv3::subwindow::counter]"
  ::hv3::subwindow $name
  if {$uri eq ""} {
    set uri [[gui_current hv3] uri get]
  }
  $name goto $uri
}

# Override the [exit] command to check if the widget code leaked memory
# or not before exiting.
#
rename exit tcl_exit
proc exit {args} {
  destroy .notebook
  catch {destroy .prop.hv3}
  catch {::tkhtml::htmlalloc}
  eval [concat tcl_exit $args]
}






#--------------------------------------------------------------------------
# main URI
#
#     The main() program for the application. This proc handles
#     parsing of command line arguments.
#
proc main {args} {

Changes to hv/hv3_notebook.tcl.

1
2
3
4
5
6
7
8
...
498
499
500
501
502
503
504
505


namespace eval hv3 { set {version($Id: hv3_notebook.tcl,v 1.8 2008/01/20 05:59:13 danielk1977 Exp $)} 1 }

# This file contains the implementation of three snit widgets:
#
#     ::hv3::notebook_header
#     ::hv3::notebook
#     ::hv3::tabset
#
................................................................................
      set title $myPendingTitle
    }
    return $title
  }

  method current {} { $hull select }
  method tabs    {} { $hull tabs }
}


|







 







|
>
>
1
2
3
4
5
6
7
8
...
498
499
500
501
502
503
504
505
506
507
namespace eval hv3 { set {version($Id: hv3_notebook.tcl,v 1.9 2008/02/02 17:15:02 danielk1977 Exp $)} 1 }

# This file contains the implementation of three snit widgets:
#
#     ::hv3::notebook_header
#     ::hv3::notebook
#     ::hv3::tabset
#
................................................................................
      set title $myPendingTitle
    }
    return $title
  }

  method current {} { $hull select }
  method tabs    {} { $hull tabs }

  delegate method select to hull
}

Changes to hv/hv3_request.tcl.

1
2
3
4
5
6
7
8
...
164
165
166
167
168
169
170

171
172
173
174
175
176
177
...
205
206
207
208
209
210
211





212
213
214
215
216
217
218
...
284
285
286
287
288
289
290






291
292
293
294
295

296
297
298
299
300
301
302
...
318
319
320
321
322
323
324









325
326
327
328
329
330
331
namespace eval hv3 { set {version($Id: hv3_request.tcl,v 1.26 2008/01/27 07:30:46 danielk1977 Exp $)} 1 }

#--------------------------------------------------------------------------
# This file contains the implementation of two types used by hv3:
#
#     ::hv3::request
#

................................................................................
    #----------------------------

    set O(chunksize) 2048
  
    # The binary data returned by the protocol implementation is 
    # accumulated in this variable.
    set O(myRaw) {}

  
    # If this variable is non-zero, then the first $myRawPos bytes of
    # $myRaw have already been passed to Hv3 via the -incrscript 
    # callback.
    set O(myRawPos) 0
  
    # These objects are referenced counted. Initially the reference count
................................................................................
      return [::encoding convertfrom [encoding $me] $raw]
    }
    return $raw
  }
  proc rawdata {me} {
    upvar $me O
    return $O(myRaw)





  }

  # Increment the object refcount.
  #
  proc reference {me} {
    upvar $me O
    incr O(myRefCount)
................................................................................
    $obj destroy
    return $authority
  }

  # Interface for returning data.
  proc append {me raw} {
    upvar $me O






    ::append O(myRaw) $raw

    if {$O(-incrscript) != ""} {
      # There is an -incrscript callback configured. If enough data is 
      # available, invoke it.

      set nLast 0
      foreach zWhite [list " " "\n" "\t"] {
        set n [string last $zWhite $O(myRaw)]
        if {$n>$nLast} {set nLast $n ; break}
      }
      set nAvailable [expr {$nLast-$O(myRawPos)}]
      if {$nAvailable > $O(chunksize)} {
................................................................................
  # Called after all data has been passed to [append].
  #
  proc finish {me {raw ""}} {
    upvar $me O

    if {$O(myIsFinished)} {error "finish called twice on $me"}
    set O(myIsFinished) 1









    ::append O(myRaw) $raw

    set zDecoded [string range $O(myRaw) $O(myRawPos) end]
    if {$O(myIsText)} {
      set zDecoded [::encoding convertfrom [encoding $me] $zDecoded]
    }

|







 







>







 







>
>
>
>
>







 







>
>
>
>
>
>





>







 







>
>
>
>
>
>
>
>
>







1
2
3
4
5
6
7
8
...
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
...
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
...
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
...
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
namespace eval hv3 { set {version($Id: hv3_request.tcl,v 1.27 2008/02/02 17:15:02 danielk1977 Exp $)} 1 }

#--------------------------------------------------------------------------
# This file contains the implementation of two types used by hv3:
#
#     ::hv3::request
#

................................................................................
    #----------------------------

    set O(chunksize) 2048
  
    # The binary data returned by the protocol implementation is 
    # accumulated in this variable.
    set O(myRaw) {}
    set O(myRawMode) 0
  
    # If this variable is non-zero, then the first $myRawPos bytes of
    # $myRaw have already been passed to Hv3 via the -incrscript 
    # callback.
    set O(myRawPos) 0
  
    # These objects are referenced counted. Initially the reference count
................................................................................
      return [::encoding convertfrom [encoding $me] $raw]
    }
    return $raw
  }
  proc rawdata {me} {
    upvar $me O
    return $O(myRaw)
  }
  proc set_rawmode {me} {
    upvar $me O
    set O(myRawMode) 1
    set O(myRaw) ""
  }

  # Increment the object refcount.
  #
  proc reference {me} {
    upvar $me O
    incr O(myRefCount)
................................................................................
    $obj destroy
    return $authority
  }

  # Interface for returning data.
  proc append {me raw} {
    upvar $me O

    if {$O(myRawMode)} {
      eval [linsert $O(-incrscript) end $raw]
      return
    }

    ::append O(myRaw) $raw

    if {$O(-incrscript) != ""} {
      # There is an -incrscript callback configured. If enough data is 
      # available, invoke it.

      set nLast 0
      foreach zWhite [list " " "\n" "\t"] {
        set n [string last $zWhite $O(myRaw)]
        if {$n>$nLast} {set nLast $n ; break}
      }
      set nAvailable [expr {$nLast-$O(myRawPos)}]
      if {$nAvailable > $O(chunksize)} {
................................................................................
  # Called after all data has been passed to [append].
  #
  proc finish {me {raw ""}} {
    upvar $me O

    if {$O(myIsFinished)} {error "finish called twice on $me"}
    set O(myIsFinished) 1

    if {$O(myRawMode)} {
      foreach hook $O(myFinishHookList) {
        eval $hook
      }
      eval [linsert $O(-finscript) end $raw]
     return
    }

    ::append O(myRaw) $raw

    set zDecoded [string range $O(myRaw) $O(myRawPos) end]
    if {$O(myIsText)} {
      set zDecoded [::encoding convertfrom [encoding $me] $zDecoded]
    }

Changes to hv/hv3_util.tcl.

1
2
3
4
5
6
7
8
...
430
431
432
433
434
435
436
437
438

439
440
441
442
443
444
445
namespace eval hv3 { set {version($Id: hv3_util.tcl,v 1.8 2008/01/27 14:39:24 danielk1977 Exp $)} 1 }


namespace eval hv3 {

  proc ReturnWithArgs {retval args} {
    return $retval
  }
................................................................................
namespace eval ::hv3 {

  variable Counter 1

  proc handle_destroy {me obj win} {
    if {$obj eq $win} {
      upvar #0 $me O
      rename $O(cmd) ""
      $me destroy

    }
  }
  proc handle_rename {me oldname newname op} {
    upvar #0 $me O
    set O(cmd) $newname
  }

|







 







|

>







1
2
3
4
5
6
7
8
...
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
namespace eval hv3 { set {version($Id: hv3_util.tcl,v 1.9 2008/02/02 17:15:02 danielk1977 Exp $)} 1 }


namespace eval hv3 {

  proc ReturnWithArgs {retval args} {
    return $retval
  }
................................................................................
namespace eval ::hv3 {

  variable Counter 1

  proc handle_destroy {me obj win} {
    if {$obj eq $win} {
      upvar #0 $me O
      set cmd $O(cmd)
      $me destroy
      rename $cmd ""
    }
  }
  proc handle_rename {me oldname newname op} {
    upvar #0 $me O
    set O(cmd) $newname
  }

Changes to hv/hv3_widgets.tcl.

1
2
3
4
5
6
7
8
...
109
110
111
112
113
114
115

116
117
118
119
120
121
122
123
...
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
namespace eval hv3 { set {version($Id: hv3_widgets.tcl,v 1.57 2008/01/27 08:00:28 danielk1977 Exp $)} 1 }

package require snit
package require Tk

set ::hv3::toolkit Tk
catch {
#  package require tile
................................................................................

      # Configure Tk presentation options not required for Tile here.
      $myButton configure -highlightthickness 0
      $myButton configure -borderwidth 1
      $myButton configure -relief flat -overrelief raised
    }
    set top [winfo toplevel $myButton]

    set myPopup ${top}[string map {. _} $myButton]
    set myPopupLabel ${myPopup}.label
    frame $myPopup -bg black
    ::label $myPopupLabel -fg black -bg white
    ::hv3::UseHv3Font $myPopupLabel

    pack $myButton -expand true -fill both
    pack $myPopup.label -padx 1 -pady 1 -fill both -expand true
................................................................................
    set docbbox  [$hv3 html bbox]

    set docheight "[lindex $docbbox 3].0"

    set ntop    [expr ([lindex $nodebbox 1].0 - 30.0) / $docheight]
    set nbottom [expr ([lindex $nodebbox 3].0 + 30.0) / $docheight]
 
    set sheight [expr [winfo height $hv3].0 / $docheight]
    set stop    [lindex [$hv3 yview] 0]
    set sbottom [expr $stop + $sheight]


    if {$ntop < $stop} {
      $hv3 yview moveto $ntop
    } elseif {$nbottom > $sbottom} {
|







 







>
|







 







|







1
2
3
4
5
6
7
8
...
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
...
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
namespace eval hv3 { set {version($Id: hv3_widgets.tcl,v 1.58 2008/02/02 17:15:02 danielk1977 Exp $)} 1 }

package require snit
package require Tk

set ::hv3::toolkit Tk
catch {
#  package require tile
................................................................................

      # Configure Tk presentation options not required for Tile here.
      $myButton configure -highlightthickness 0
      $myButton configure -borderwidth 1
      $myButton configure -relief flat -overrelief raised
    }
    set top [winfo toplevel $myButton]
    if {$top eq "."} {set top ""}
    set myPopup ${top}.[string map {. _} $myButton]
    set myPopupLabel ${myPopup}.label
    frame $myPopup -bg black
    ::label $myPopupLabel -fg black -bg white
    ::hv3::UseHv3Font $myPopupLabel

    pack $myButton -expand true -fill both
    pack $myPopup.label -padx 1 -pady 1 -fill both -expand true
................................................................................
    set docbbox  [$hv3 html bbox]

    set docheight "[lindex $docbbox 3].0"

    set ntop    [expr ([lindex $nodebbox 1].0 - 30.0) / $docheight]
    set nbottom [expr ([lindex $nodebbox 3].0 + 30.0) / $docheight]
 
    set sheight [expr [winfo height [$hv3 html]].0 / $docheight]
    set stop    [lindex [$hv3 yview] 0]
    set sbottom [expr $stop + $sheight]


    if {$ntop < $stop} {
      $hv3 yview moveto $ntop
    } elseif {$nbottom > $sbottom} {

Changes to src/htmldraw.c.

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
....
4413
4414
4415
4416
4417
4418
4419


4420
4421
4422
4423
4424
4425
4426
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
*/
static const char rcsid[] = "$Id: htmldraw.c,v 1.206 2008/01/12 14:23:05 danielk1977 Exp $";

#include "html.h"
#include <assert.h>
#include <X11/Xutil.h>


/*-------------------------------------------------------------------------
................................................................................
    HtmlTree *pTree;
    int x;
    int y;
    int w;
    int h;
    int windowsrepair;
{


    /* Make sure the widget main window exists before painting anything */
    Tk_MakeWindowExist(pTree->tkwin);
    Tk_MakeWindowExist(pTree->docwin);

    widgetRepair(pTree, x, y, w, h, windowsrepair);
    if (windowsrepair) {
        windowsRepair(pTree, &pTree->canvas);







|







 







>
>







26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
....
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
*/
static const char rcsid[] = "$Id: htmldraw.c,v 1.207 2008/02/02 17:15:02 danielk1977 Exp $";

#include "html.h"
#include <assert.h>
#include <X11/Xutil.h>


/*-------------------------------------------------------------------------
................................................................................
    HtmlTree *pTree;
    int x;
    int y;
    int w;
    int h;
    int windowsrepair;
{
    /* if( !pTree->options.enablelayout ) return; */

    /* Make sure the widget main window exists before painting anything */
    Tk_MakeWindowExist(pTree->tkwin);
    Tk_MakeWindowExist(pTree->docwin);

    widgetRepair(pTree, x, y, w, h, windowsrepair);
    if (windowsrepair) {
        windowsRepair(pTree, &pTree->canvas);