File: html.tcl

package info (click to toggle)
moodss 19.7-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 6,136 kB
  • ctags: 3,149
  • sloc: tcl: 49,048; ansic: 187; perl: 178; makefile: 166; sh: 109; python: 65
file content (104 lines) | stat: -rw-r--r-- 5,484 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
# copyright (C) 1997-2005 Jean-Luc Fontaine (mailto:jfontain@free.fr)
# this program is free software: please read the COPYRIGHT file enclosed in this package or use the Help Copyright menu

# $Id: html.tcl,v 1.55 2005/01/02 00:45:07 jfontain Exp $


set global::fileCloseImage [image create photo -data {
    R0lGODlhFgAWAMYAALGxuYmJmYmJmIiImLCwuM/P0YqKmkREYTw8XEFBYEdHZkZGZT8/Xzk5WEBAXIeHls7O0Lu7wVlZcz4+XnNzkcLC0uvr8PX198zM2oaG
    oVNTbLm5v0VFY05Obr+/0Obm7cnJ11xcfD09WU1Nbb29ztbW4dPT383N2lhYeFFRaZ+ft8XF1Lm5y/Pz9rq6y/7+/9zc5bS0xz09XYSEk2Jigbe3yeTk7LOz
    xnJykDk5VYWFoKKiudvb5d7e566uwn5+mmNjglJScjIyUK6utYuLppCQqtXV4ODg6F1dfTg4V4ODks7O24KCkWtripmZscDA0IKCkFlZeZKSrDU1U4GBkFNT
    c1RUdI+PqS0tS62ttEpKaldXd+Hh6ZiYsDQ0UDo6WWBgf2Rkg6Cgt+Pj625ujMfH1oGBj1NTa3Bwjp+ftnp6l6iovUREY0pKYc3Nz3h4lX19mXd3lElJaTQ0
    T7e3vTs7WmdnhomJo2VlhDY2VEhIaGFhgP///////////////yH5BAEKAH8ALAAAAAAWABYAAAf+gH+Cg4SFhoeCAAECAgMEiIUFBgcICQoLDA0ODxCQERIT
    FBUWF6UYGQ0aG4cRHB0eH7GysSAhIquEBRIjJCUmJcDBvycoKZ2DBhMqKywtFivQKy4vMCsxMjOEBzQxNS0vLzYxMTfgLxgxODmDAAg6Ozs85j0+5jY/QEFC
    Q4IBCURFAhoxZ+4IkiAIkygRJGDBj4cPlxA0iBBhAiaCBixowpGjE4JPKiJkACUjgygoo0ghCC5kxSlUBBFoUMWKlSsFn5h7UqUnliyDHGjZ0sQcFxpbKpjr
    skWBF0IPvoAJI+bFGDJhspZ5USYMGCFmCEE4owUNmjRqzKpdY5ZNGzc5hTaI6PAGjt27duPImUPn0IYUdezcGUwYT542fRFBmJEjj549YBYI8WIGLqRBQ5Qw
    oUIF6OXPiAIBADs=
}]

proc displayHelpWindow {topLevelName name title} {
    upvar 1 $topLevelName toplevel

    # child of common parent so that user interaction can be limited to 2 windows (print dialog box and main help for example)
    set toplevel .grabber.help${name}
    if {[winfo exists $toplevel]} {
        wm deiconify $toplevel
        raise $toplevel
        return 0
    }
    toplevel $toplevel
    wm group $toplevel .                                             ;# for proper window manager (windowmaker for example) behavior
    wm title $toplevel $title
    frame $toplevel.bound                     ;# create a frame for bindings that otherwise would propagate to all toplevel children
    return 1
}

proc generalHelpWindow {{url {}}} {
    static bottom 0

    if {[displayHelpWindow toplevel moodss [mc {moodss: Global help}]]} {
        loadHelpData
        set bottom [helpWindow $toplevel $::htmlHelpContents $::htmlHelpData]
    }
    if {([string length $url] > 0) && ![catch {classof $bottom}]} {                          ;# viewer may not have been created yet
        htmlViewer::goTo $bottom $url
    }
}

proc formulasHelpWindow {{url {}}} {
    static bottom 0

    if {[displayHelpWindow toplevel formulas [mc {moodss: Formulas help}]]} {
        loadHelpData
        set bottom [helpWindow $toplevel $::htmlFormulasHelpContents $::htmlFormulasHelpData]
    }
    if {([string length $url] > 0) && ![catch {classof $bottom}]} {                          ;# viewer may not have been created yet
        htmlViewer::goTo $bottom $url
    }
}

proc loadHelpData {} {                                                                       ;# load huge HTML data only when needed
    if {\
        ([info exists ::env(LC_ALL)] && [string match ja* $::env(LC_ALL)]) ||\
        ([info exists ::env(LANG)] && [string match ja* $::env(LANG)])\
    } {
        package require moodsshelp-ja
    } else {
        package require moodsshelp
    }
}

proc helpWindow {toplevel htmlContents htmlData} {
    set panes [new panner $toplevel -panes 2]                                        ;# split window in 2 for contents and help data
    pack $widget::($panes,path) -fill both -expand 1
    set top [new htmlViewer $panner::($panes,frame1)]
    composite::configure $top base -height 100 -width 500
    pack $widget::($top,path) -fill both -expand 1
    set bottom [new htmlViewer $panner::($panes,frame2)]
    composite::configure $top -linkto $bottom
    composite::configure $bottom base -height 400
    focus $htmlViewer::($bottom,textPath)                                 ;# so that scrolling with keyboard is immediately possible
    pack $widget::($bottom,path) -fill both -expand 1
    bind $toplevel.bound <Destroy> "delete $bottom $top $panes"
    set button [button $toplevel.close -image $global::fileCloseImage -command "destroy $toplevel"]
    place $button -in $htmlViewer::($top,textPath) -relx 1 -anchor ne      ;# place inside text area so as not to obstruct scrollbar
    busy 1 $htmlViewer::($top,textPath)                                ;# force busy cursor on contents while bottom pane is loading
    composite::configure $top -data $htmlContents
    if {![winfo exists $toplevel]} {                                ;# user may have destroyed the window through the window manager
        return 0
    }
    composite::configure $bottom -data $htmlData
    catch {busy 0 $htmlViewer::($top,textPath)}                                            ;# window may have been destroyed by user
    return $bottom
}

proc moduleHelpWindow {name text} {
    if {![displayHelpWindow toplevel $name [format [mc {moodss: %s module help}] $name]]} return
    set viewer [new htmlViewer $toplevel]
    composite::configure $viewer base -height 300 -width 500
    pack $widget::($viewer,path) -fill both -expand 1
    bind $toplevel.bound <Destroy> "delete $viewer"
    composite::configure $viewer -data $text
    set button [button $toplevel.close -image $global::fileCloseImage -command "destroy $toplevel"]
    place $button -in $htmlViewer::($viewer,textPath) -relx 1 -anchor ne   ;# place inside text area so as not to obstruct scrollbar
}