home *** CD-ROM | disk | FTP | other *** search
/ PC World 1997 November / PCWorld_1997-11_cd.bin / software / programy / komix / DATA.Z / helptool.tcl < prev    next >
Text File  |  1996-11-28  |  7KB  |  357 lines

  1. #---------------------------------------------------------------------------
  2. #
  3. #      (c)     Cayenne Software Inc.    1996
  4. #
  5. #      File:           @(#)helptool.tcl    /main/hindenburg/6
  6. #      Author:         <generated>
  7. #      Description:
  8. #---------------------------------------------------------------------------
  9. # SccsId = @(#)helptool.tcl    /main/hindenburg/6   28 Nov 1996 Copyright 1996 Cayenne Software Inc.
  10.  
  11. # Start user added include file section
  12.  
  13. require helpdialog.tcl
  14. require tooloption.tcl
  15. require m4vardescr.tcl
  16. require showversio.tcl
  17.  
  18. # End user added include file section
  19.  
  20. require "wmttool.tcl"
  21.  
  22. Class HelpTool : {WmtTool MainWindow} {
  23.     method destructor
  24.     constructor
  25.     method updateToolBar
  26.     method gotoURL
  27.     method gotoPrevious
  28.     method showToc
  29.     method showIndex
  30.     method firstPageURL
  31.     method tocFile
  32.     method indexFile
  33.     method print
  34.     method exit
  35.     method dialog
  36.     attribute hyperStack
  37.     attribute root
  38.     attribute _firstPageURL
  39.     attribute _tocFile
  40.     attribute _indexFile
  41.     attribute viewer
  42.     attribute _dialog
  43.     attribute m4VarDes
  44.     attribute options
  45. }
  46.  
  47. method HelpTool::destructor {this} {
  48.     set ref [$this _dialog]
  49.     if {$ref != ""} {
  50.         $ref __tool ""
  51.     }
  52.     # Start destructor user section
  53.  
  54.     $this saveToolBarPresence helptool
  55.     $this saveMessageAreaPresence helptool
  56.     $this saveWindowGeometry helptool
  57.     [$this options] delete
  58.  
  59.     # End destructor user section
  60.     $this WmtTool::destructor
  61. }
  62.  
  63. constructor HelpTool {class this name} {
  64.     set this [MainWindow::constructor $class $this $name]
  65.     WmtTool::constructor $class $this $name
  66.  
  67.     $this config -title help -icon help_64 -iconTitle help
  68.  
  69.     $this hyperStack [List new]
  70.     $this closed {%this exit}
  71.  
  72.     # Global Setup
  73.     #
  74.     interface MenuBar $this.bar {
  75.         MenuBarButton file {
  76.             label File
  77.             mnemonic F
  78.         }
  79.         MenuBarButton navigate {
  80.             label Navigate
  81.             mnemonic N
  82.         }
  83.         MenuBarButton view {
  84.             label View
  85.             mnemonic V
  86.         }
  87.         MenuBarButton options {
  88.             label Options
  89.             mnemonic O
  90.         }
  91.         MenuBarButton help {
  92.             label Help
  93.             mnemonic H
  94.         }
  95.     }
  96.  
  97.     [$this menuBar] helpEntry [$this menuBar].help
  98.  
  99.     # Menus
  100.     #
  101.  
  102.     # File Menu
  103.     #
  104.     interface Menu [$this menuBar].file.menu {
  105.         MenuPushButton open {
  106.             label "Open File..."
  107.             mnemonic O
  108.             accelerator Ctrl+F
  109.             activated {
  110.                 if {![isCommand .main.open]} {
  111.                     FileChooser new .main.open -okPressed {
  112.                         .main gotoURL \
  113.                             [.main.open selectedSet]
  114.                     }
  115.                     .main.open delHelpButton
  116.                 }
  117.                 .main.open popUp
  118.             }
  119.         }
  120.         MenuPushButton print {
  121.             label "Print"
  122.             mnemonic P
  123.             activated {
  124.                 .main print
  125.             }
  126.         }
  127.         MenuSeparator sep {
  128.         }
  129.         MenuPushButton exit {
  130.             label "Exit"
  131.             mnemonic E
  132.             activated {
  133.                 .main exit
  134.             }
  135.         }
  136.     }
  137.  
  138.     # Navigation Menu
  139.     #
  140.     interface Menu [$this menuBar].navigate.menu {
  141.         pinnable 1
  142.         MenuPushButton contents {
  143.             label "Contents..."
  144.             mnemonic C
  145.             accelerator Ctrl+C
  146.             toolBarPixmap toc
  147.             activated {
  148.                 .main showToc
  149.             }
  150.         }
  151.         MenuPushButton index {
  152.             label "Index..."
  153.             mnemonic I
  154.             accelerator Ctrl+I
  155.             toolBarPixmap index
  156.             activated {
  157.                 .main showIndex
  158.             }
  159.         }
  160.         MenuPushButton back {
  161.             label "Previous Entry"
  162.             sensitive 0
  163.             mnemonic P
  164.             accelerator Ctrl+P
  165.             toolBarPixmap back
  166.             activated {
  167.                 .main gotoPrevious
  168.             }
  169.         }
  170.     }
  171.  
  172.     # View Menu
  173.     #
  174.     interface Menu [$this menuBar].view.menu {
  175.         MenuCheckButton toolbar {
  176.             hintText "Shows or hides the toolbar."
  177.             label "ToolBar"
  178.             mnemonic T
  179.             state 1
  180.             stateChanged {
  181.                 .main toolBarPresent [[.main menuBar].view.menu.toolbar state]
  182.             }
  183.         }
  184.         MenuCheckButton messagearea {
  185.             hintText "Shows or hides the message area."
  186.             label "Message Area"
  187.             mnemonic M
  188.             state 1
  189.             stateChanged {
  190.                 .main messageAreaPresent [[.main menuBar].view.menu.messagearea state]
  191.             }
  192.         }
  193.     }
  194.  
  195.     # Options Menu
  196.     #
  197.     $this options [ToolOptions new $this.options]
  198.     $this m4VarDes [M4VarDescription new $this.m4VarDes]
  199.     interface Menu [$this menuBar].options.menu {
  200.         MenuPushButton printerSetup {
  201.             label "Printer Setup..."
  202.             mnemonic P
  203.             activated {
  204.                 [.main options] psPrinterSetup
  205.             }
  206.         }
  207.     }
  208.  
  209.     # Help Menu
  210.     #
  211.     interface Menu [$this menuBar].help.menu {
  212.         MenuPushButton abouthelptool {
  213.             label "About Help Tool"
  214.             mnemonic A
  215.             activated {
  216.                 showVersionDialog [%this label]
  217.             }
  218.         }
  219.     }
  220.  
  221.     $this setToolBarPresence helptool
  222.     if {[$this toolBar] != ""} {
  223.         $this updateToolBar
  224.     }
  225.  
  226.     # Other stuff
  227.     #
  228.  
  229.     $this viewer [HTMLViewer new $this.viewer -panX 0 -panY 0]
  230.     [$this viewer] setSize 550 500
  231.     [$this viewer] hotSpotClicked \
  232.         "$this gotoURL \[[$this viewer] currentHotSpot\]"
  233.  
  234.     $this setMessageAreaPresence helptool
  235.     HelpDialog new $this.help -tool $this
  236.     $this setWindowGeometry helptool
  237.  
  238.     return $this
  239. }
  240.  
  241. method HelpTool::updateToolBar {this} {
  242.     [$this toolBar] entrySet "
  243.         [$this menuBar].navigate.menu.contents
  244.         [$this menuBar].navigate.menu.index
  245.         [$this menuBar].navigate.menu.back
  246.     "
  247. }
  248.  
  249. method HelpTool::gotoURL {this url} {
  250.     # Special url to show toc dialog.
  251.     if {$url == "helptool://showtoc"} {
  252.         $this showToc
  253.         return
  254.     }
  255.     if [catch {
  256.         if [regexp {^#} $url] {
  257.             # Make relative url absolute.
  258.             set url "[[$this viewer] currentFile]$url"
  259.         } elseif {![regexp {^/} $url]} {
  260.             set url \
  261.                   "[file dirname [[$this viewer] currentFile]]/$url"
  262.         }
  263.         [$this viewer] gotoURL $url
  264.         [$this hyperStack] insert $url
  265.         if {[llength [[$this hyperStack] contents]] > 1} {
  266.             .main.bar.navigate.menu.back sensitive 1
  267.         }
  268.     } msg] {
  269.         wmtkerror $msg
  270.     }
  271. }
  272.  
  273. method HelpTool::gotoPrevious {this} {
  274.     if {[llength [[$this hyperStack] contents]] == 1} {
  275.         wmtkerror "There is no previous help topic"
  276.         return
  277.     }
  278.     if [catch {
  279.         [$this hyperStack] remove 0
  280.         [$this viewer] gotoURL [[$this hyperStack] index 0]
  281.     } msg] {
  282.         wmtkerror $msg
  283.     }
  284.     if {[llength [[$this hyperStack] contents]] == 1} {
  285.         .main.bar.navigate.menu.back sensitive 0
  286.     }
  287. }
  288.  
  289. method HelpTool::showToc {this} {
  290.     [$this dialog] showToc
  291. }
  292.  
  293. method HelpTool::showIndex {this} {
  294.     [$this dialog] showIndex
  295. }
  296.  
  297. method HelpTool::firstPageURL {this {url -}} {
  298.     if {$url == "-"} {
  299.         return [$this _firstPageURL]
  300.     }
  301.     if {[$this _firstPageURL] == ""} {
  302.         $this gotoURL $url
  303.     }
  304.     $this _firstPageURL $url
  305. }
  306.  
  307. method HelpTool::tocFile {this {file -}} {
  308.     if {$file == ""} {
  309.         return [$this _tocFile]
  310.     }
  311.     .main.help loadToc $file
  312.     $this _tocFile $file
  313. }
  314.  
  315. method HelpTool::indexFile {this {file -}} {
  316.     if {$file == ""} {
  317.         return [$this _indexFile]
  318.     }
  319.     .main.help loadIndex $file
  320.     $this _indexFile $file
  321. }
  322.  
  323. method HelpTool::print {this} {
  324.     wmtkmessage "Printing..."
  325.     set printer [Printer new]
  326.     $printer openPrinter html-print
  327.     set printOut [HTMLPrintOut new -url [[$this viewer] currentFile]]
  328.     $printer print $printOut
  329.     $printOut delete
  330.     $printer close
  331.     wmtkmessage "Done"
  332. }
  333.  
  334. method HelpTool::exit {this} {
  335.     $this delete
  336.     GCControl collect
  337.     exit
  338. }
  339.  
  340. # Do not delete this line -- regeneration end marker
  341.  
  342. method HelpTool::dialog {this args} {
  343.     if {$args == ""} {
  344.         return [$this _dialog]
  345.     }
  346.     set ref [$this _dialog]
  347.     if {$ref != ""} {
  348.         $ref __tool ""
  349.     }
  350.     set obj [lindex $args 0]
  351.     if {$obj != ""} {
  352.         $obj __tool $this
  353.     }
  354.     $this _dialog $obj
  355. }
  356.  
  357.