home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / database / pk4pak.zip / POPHELP.SC < prev    next >
Text File  |  1993-01-15  |  17KB  |  536 lines

  1. ;==============================================================================
  2. ; (c) Copyright Elect Software International Inc., 1992, Toronto. Anyone can
  3. ; use this code for anything as long as it is not resold as a software
  4. ; development resource, as long as the copyright notice isn't removed, as
  5. ; long as changes are clearly marked as to authorship, and as long as users
  6. ; indemnify Elect from any liability.
  7. ; Comments welcome. Henrik Bechmann, CIS:72701,3717; Tel:416-534-8176.
  8. ;==============================================================================
  9.  
  10. ;==============================================================================
  11. ;                             Hypertext INTERFACE
  12. ;==============================================================================
  13.  
  14. ; Methods:
  15. ; HyperMemo.Constructor()
  16. ; HyperMemo.LoadTables()
  17. ; HyperMemo.HideWindow()
  18. ; HyperMemo.ShowPanel(PanelName)
  19. ; HyperMemo.UnloadTables()
  20. ; HyperMemo.Destructor()
  21. ;
  22. ; Properties:
  23. ; HyperMemo.HelpListTabName
  24. ; HyperMemo.HelpSpecTabName
  25. ; HyperMemo.Directory
  26. ; HyperMemo.ColorBag[]
  27. ; HyperMemo.WindowBag[]
  28. ; HyperMemo.HypertextKey
  29. ; HyperMemo.Prompt
  30.  
  31. ;==============================================================================
  32. ;                         Hypertext IMPLEMENTATION
  33. ;==============================================================================
  34.  
  35. Proc HyperMemo.Constructor()
  36.    HyperMemo.HelpListTabName = "helplist"
  37.    HyperMemo.HelpSpecTabName = "helpspec"
  38.    HyperMemo.Directory = "Generic\\helpman\\data\\"
  39.    Dynarray HyperMemo.ColorBag[]
  40.    HyperMemo.ColorBag[0] = 8 + 32
  41.    HyperMemo.ColorBag[1] = 8 + 32
  42.    HyperMemo.ColorBag[2] = 8 + 32
  43.    HyperMemo.ColorBag[3] = 8 + 32
  44.    HyperMemo.ColorBag[4] = 8 + 32
  45.    Dynarray HyperMemo.WindowBag[]
  46.    HyperMemo.HypertextKey = Asc("Enter")
  47.    HyperMemo.SetFocusProc = "HyperMemo!SetFocus"
  48.    HyperMemo.Prompt =
  49.       "[Tab/ShiftTab] for next/prev hotspot; [Enter] to select hypertext"
  50.    HyperMemo.LoadTables()
  51. EndProc ; HyperMemo.Constructor
  52.  
  53. Proc HyperMemo.Destructor()
  54.    HyperMemo.UnloadTables()
  55.    Release Vars
  56.       HyperMemo.HelpText,
  57.       HyperMemo.nHotSpots,
  58.       HyperMemo.HelpDepth,
  59.       HyperMemo.HotSpotLeft,
  60.       HyperMemo.HotSpotRight,
  61.       HyperMemo.HotSpotString,
  62.       HyperMemo.HotSpotStackLeft,
  63.       HyperMemo.HotSpotStackRight,
  64.       HyperMemo.HotSpotStackName,
  65.       HyperMemo.HelpListTabName,
  66.       HyperMemo.HelpListWindowHandle,
  67.       HyperMemo.HelpSpecTabName,
  68.       HyperMemo.HelpSpecWindowHandle,
  69.       HyperMemo.Directory,
  70.       HyperMemo.ColorBag,
  71.       HyperMemo.WindowBag,
  72.       HyperMemo.HypertextKey,
  73.       HyperMemo.SetFocusProc,
  74.       HyperMemo.Prompt,
  75.       HyperMemo_PanelName
  76. EndProc ; HyperMemo.Destructor
  77.  
  78. ;--------------------------- SHOW HELP Panel -------------------------------
  79.  
  80. Proc HyperMemo.LoadTables()
  81.    View HyperMemo.Directory + HyperMemo.HelpSpecTabName
  82.    HyperMemo.HelpSpecWindowHandle = GetWindow()
  83.    HyperMemo.HideWindow()
  84.    View HyperMemo.Directory + HyperMemo.HelpListTabName
  85.    HyperMemo.HelpListWindowHandle = GetWindow()
  86.    HyperMemo.HideWindow()
  87. EndProc ; HyperMemo.LoadTables
  88.  
  89. Proc HyperMemo.HideWindow()
  90.    Window Move GetWindow() To 500,500
  91. EndProc ; HyperMemo.HideWindow
  92.  
  93. Proc HyperMemo.UnloadTables()
  94.    Moveto HyperMemo.Directory + HyperMemo.HelpListTabName
  95.    ClearImage
  96.    Moveto HyperMemo.Directory + HyperMemo.HelpSpecTabName
  97.    ClearImage
  98. EndProc ; HyperMemo.UnloadTables
  99.  
  100. Proc HyperMemo.ShowPanel(PanelName)
  101.  
  102.    Echo off
  103.    ShowPullDown
  104.       "NextHotSpot":"Moveto next HotSpot":"NextHotSpot",
  105.       "PrevHotSpot":"Moveto previous HotSpot":"PrevHotSpot",
  106.       "SelectHotSpot":"Select current HotSpot":"SelectHotSpot",
  107.       "P~r~evPanel":"Move back to parent panel, or quit":"ParentPanel",
  108.       "Quit":"Leave help panel":"QuitPanel"
  109.    EndMenu
  110.    Prompt HyperMemo.Prompt
  111.    HyperMemo_PanelName = Upper(PanelName)
  112.    HyperMemo.SetStack()
  113.    Moveto HyperMemo.Directory + HyperMemo.HelpListTabName
  114.    Moveto [Help Panel name]
  115.    Locate Indexorder HyperMemo_PanelName
  116.    If Not Retval Then
  117.       Return False
  118.    Endif
  119.    HyperMemo!SetFocus()
  120.    HyperMemo!BrowseText()
  121.    Return True
  122. EndProc ; HyperMemo.ShowPanel
  123.  
  124. Proc HyperMemo.SetStack()
  125.    HyperMemo.HelpDepth = 0
  126.    Dynarray HyperMemo.HotSpotStackLeft[]
  127.    Dynarray HyperMemo.HotSpotStackRight[]
  128.    Dynarray HyperMemo.HotSpotStackName[]
  129. EndProc ; HyperMemo.SetStack
  130.  
  131. Proc HyperMemo!SetFocus()
  132.    Private
  133.       WindowHandle
  134.    Echo off
  135.    HyperMemo.CollectHotSpots()
  136.    Moveto [Help text]
  137.    HyperMemo!ShowWindow()
  138.    Echo Normal
  139. EndProc ; HyperMemo!SetFocus
  140.  
  141. Proc HyperMemo!ShowWindow()
  142.    FieldView
  143.    If [Wordwrap] = "Y" Then
  144.       Menu {Options}{WordWrap}{Set}
  145.    Else
  146.       Menu {Options}{WordWrap}{Clear}
  147.    Endif
  148.    WindowHandle = GetWindow()
  149.    HyperMemo.WindowBag["Title"] = StrVal(HyperMemo.HelpDepth + 1) +
  150.       ":" + [Help title]
  151.    If Not IsBlank([Origin row]) Then
  152.       HyperMemo.WindowBag["OriginRow"] = [Origin row]
  153.    Else
  154.       Release Vars HyperMemo.WindowBag["OriginRow"]
  155.    Endif
  156.    If Not IsBlank([Origin col]) Then
  157.       HyperMemo.WindowBag["OriginCol"] = [Origin col]
  158.    Else
  159.       Release Vars HyperMemo.WindowBag["OriginCol"]
  160.    Endif
  161.    If Not IsBlank([Height]) Then
  162.       HyperMemo.WindowBag["Height"] = [Height]
  163.    Else
  164.       Release Vars HyperMemo.WindowBag["Height"]
  165.    Endif
  166.    If Not IsBlank([Width]) Then
  167.       HyperMemo.WindowBag["Width"] = [Width]
  168.    Else
  169.       Release Vars HyperMemo.WindowBag["Width"]
  170.    Endif
  171.    Window SetAttributes WindowHandle From HyperMemo.WindowBag
  172.    Window SetColors WindowHandle From HyperMemo.ColorBag
  173. EndProc ; HyperMemo!ShowWindow
  174.  
  175. Proc HyperMemo.CollectHotSpots()
  176.    Private
  177.       ScanPos,
  178.       Scanning,
  179.       LeftMarkPos,
  180.       RightMarkPos,
  181.       Found,
  182.       WorkString,
  183.       Length,
  184.       OK
  185.  
  186.    HyperMemo.HelpText = [Help text]
  187.    HyperMemo.nHotSpots = 0
  188.  
  189.    DynArray HyperMemo.HotSpotLeft[]
  190.    DynArray HyperMemo.HotSpotRight[]
  191.    DynArray HyperMemo.HotSpotString[]
  192.  
  193.    ScanPos = 1
  194.    Scanning = True
  195.    While Scanning
  196.       LeftMarkPos = SearchFrom("»",HyperMemo.HelpText,ScanPos)
  197.       Found = (LeftMarkPos <> 0)
  198.       Scanning = Found
  199.       If Found Then
  200.          ScanPos = LeftMarkPos
  201.          RightMarkPos = SearchFrom("«",HyperMemo.HelpText,ScanPos)
  202.          Found = (RightMarkPos <> 0)
  203.          If Found Then
  204.             Length = RightMarkPos - LeftMarkPos + 1 - 2
  205.             OK = (Length <= 32 And Length > 0)
  206.             If OK Then
  207.                WorkString = Substr(HyperMemo.HelpText,LeftMarkPos + 1,Length)
  208.                OK = (Substr(WorkString,1,1) <> " ")
  209.                If OK Then
  210.                   OK = (Substr(WorkString,Length,1) <> " ")
  211.                   If OK Then
  212.                      OK = (Search("\010",WorkString) = 0)
  213.                   Endif
  214.                Endif
  215.             Endif
  216.             If OK Then
  217.                HyperMemo.nHotSpots = HyperMemo.nHotSpots + 1
  218.                HyperMemo.HotSpotLeft[HyperMemo.nHotSpots] = LeftMarkPos
  219.                HyperMemo.HotSpotRight[HyperMemo.nHotSpots] = RightMarkPos
  220.                HyperMemo.HotSpotString[HyperMemo.nHotSpots] = WorkString
  221.                ScanPos = RightMarkPos + 1
  222.             Else
  223.                ScanPos = LeftMarkPos + 1
  224.             Endif
  225.          Endif ; Found
  226.       Else
  227.          Scanning = False
  228.       Endif
  229.    EndWhile
  230. EndProc ; HyperMemo.CollectHotSpots
  231.  
  232. Proc HyperMemo!BrowseText()
  233.    Private
  234.       Browsing,
  235.       LeftMarkPos,
  236.       RightMarkPos,
  237.       EventBag,
  238.       Keycode,
  239.       MessageTag,
  240.       MenuTag
  241.    Browsing = True
  242.    While Browsing
  243.       GetEvent To EventBag
  244.       Switch
  245.          Case EventBag["Type"] = "KEY":
  246.             Keycode = EventBag["Keycode"]
  247.             Switch
  248.                Case KeyCode = Asc("F2"):
  249.                   Do_It!
  250.                   Browsing = False
  251.                Case KeyCode = Asc("Esc"):
  252.                   If Not HyperMemo.PrevPanel() Then
  253.                      Do_It!
  254.                      Browsing = False
  255.                      Echo normal
  256.                   Endif
  257.                Case KeyCode = Asc("Tab"):
  258.                   HyperMemo.GotoNextHotSpot()
  259.                Case KeyCode = Asc("ReverseTab"):
  260.                   HyperMemo.GotoPrevHotSpot()
  261.                Case KeyCode = HyperMemo.HypertextKey:
  262.                   HyperMemo.SelectHotSpot()
  263.                Case KeyCode = Asc("WinMax"):
  264.                   WinMax
  265.                Case KeyCode = Asc("WinResize"):
  266.                   WinResize
  267.                Case Keycode = Asc("Home") or
  268.                   Keycode = Asc("End") or
  269.                   Keycode = Asc("PgUp") or
  270.                   Keycode = Asc("PgDn") or
  271.                   Keycode = Asc("Left") or
  272.                   Keycode = Asc("Right") or
  273.                   Keycode = Asc("Up") or
  274.                   Keycode = Asc("Down") or
  275.                   Keycode = Asc("CtrlPgUp") or
  276.                   Keycode = Asc("CtrlPgDn") or
  277.                   Keycode = Asc("CtrlLeft") or
  278.                   Keycode = Asc("CtrlRight"):
  279.                   ExecEvent EventBag
  280.                OtherWise:
  281.                   ; do nothing... suppress the keystroke.
  282.             EndSwitch
  283.          Case EventBag["Type"] = "MESSAGE":
  284.             MessageTag = EventBag["Message"]
  285.             Switch
  286.                Case MessageTag = "CLOSE":
  287.                   Do_It!
  288.                   Browsing = False
  289.                Case MessageTag = "MENUSELECT":
  290.                   MenuTag = EventBag["MenuTag"]
  291.                   Switch
  292.                      Case MenuTag = "NextHotSpot":
  293.                         HyperMemo.GotoNextHotSpot()
  294.                      Case MenuTag = "PrevHotSpot":
  295.                         HyperMemo.GotoPrevHotSpot()
  296.                      Case MenuTag = "SelectHotSpot":
  297.                         HyperMemo.SelectHotSpot()
  298.                      Case MenuTag = "ParentPanel":
  299.                         If Not HyperMemo.PrevPanel() Then
  300.                            Do_It!
  301.                            Browsing = False
  302.                            Echo normal
  303.                         Endif
  304.                      Case MenuTag = "QuitPanel":
  305.                         Do_It!
  306.                         Browsing = False
  307.                   EndSwitch
  308.                OtherWise:
  309.                   ExecEvent EventBag
  310.             EndSwitch
  311.          Case EventBag["Type"] = "MOUSE":
  312.             EventTag = EventBag["Buttons"] +
  313.                  IIf(EventBag["Doubleclick"],"DOUBLE","") +
  314.                  EventBag["Action"]
  315.             Switch
  316.                Case WindowAt(EventBag["Row"],EventBag["Col"]) <>
  317.                   GetWindow(): ; do nothing
  318.                Case EventTag = "LEFTDOUBLEDOWN":
  319.                   HyperMemo.SelectHotSpot()
  320.                Case EventTag = "RIGHTDOWN":
  321.                   If Not HyperMemo.PrevPanel() Then
  322.                      Do_It!
  323.                      Browsing = False
  324.                      Echo normal
  325.                   Endif
  326.                Case EventBag["DoubleClick"]:
  327.                   ; suppress this
  328.             OtherWise:
  329.                ExecEvent EventBag
  330.             EndSwitch
  331.          OtherWise:
  332.             ExecEvent EventBag
  333.       EndSwitch
  334.    EndWhile ; Browsing
  335. EndProc ; HyperMemo!BrowseText
  336.  
  337. Proc HyperMemo.SelectHotSpot()
  338.    Private
  339.       LeftMarkPos,
  340.       RightMarkPos,
  341.       EditorBag,
  342.       ReferenceText,
  343.       PanelName
  344.  
  345.    HyperMemo!MarkCurrentHotSpot()
  346.    Editor Info To EditorBag
  347.    If EditorBag["SelStart"] = 0 Then
  348.       Message "No hotspot selected"
  349.    Else
  350.       Echo off
  351.       Message "Working..."
  352.       Editor Extract to ReferenceText
  353.       ReferenceText = Substr(ReferenceText,2,len(ReferenceText) - 2)
  354.       HyperMemo.HelpDepth = HyperMemo.HelpDepth + 1
  355.       HyperMemo.HotSpotStackLeft[HyperMemo.HelpDepth] = EditorBag["SelStart"]
  356.       HyperMemo.HotSpotStackRight[HyperMemo.HelpDepth] = EditorBag["SelEnd"]
  357.       FieldView ; Do_It!
  358.       PanelName = [Help panel name]
  359.       HyperMemo.HotSpotStackName[HyperMemo.HelpDepth] = PanelName
  360.       Moveto HyperMemo.Directory + HyperMemo.HelpSpecTabName
  361.       Locate IndexOrder PanelName,ReferenceText
  362.       If Not RetVal Then
  363.          Moveto HyperMemo.Directory + HyperMemo.HelpListTabName
  364.          PanelName = HyperMemo.HotSpotStackName[HyperMemo.HelpDepth]
  365.          LeftMarkPos = HyperMemo.HotSpotStackLeft[HyperMemo.HelpDepth]
  366.          RightMarkPos = HyperMemo.HotSpotStackRight[HyperMemo.HelpDepth]
  367.          Release Vars
  368.             HyperMemo.HotSpotStackName[HyperMemo.HelpDepth],
  369.             HyperMemo.HotSpotStackLeft[HyperMemo.HelpDepth],
  370.             HyperMemo.HotSpotStackRight[HyperMemo.HelpDepth]
  371.          HyperMemo.HelpDepth = HyperMemo.HelpDepth - 1
  372.          FieldView
  373.          ; HyperMemo!SetFocus()
  374.          Editor Select LeftMarkPos RightMarkPos
  375.          Message "No reference for hotspot"
  376.       Else
  377.          PanelName = [Referenced help Panel]
  378.          Moveto HyperMemo.Directory + HyperMemo.HelpListTabName
  379.          Moveto [Help Panel name]
  380.          Locate IndexOrder PanelName
  381.          Moveto [Help text]
  382.          ExecProc HyperMemo.SetFocusProc
  383.       Endif
  384.       Message ""
  385.    Endif
  386.    Return 1
  387. EndProc ; HyperMemo.SelectHotSpot
  388.  
  389. Proc HyperMemo!MarkCurrentHotSpot()
  390.    Private
  391.       EditorBag,
  392.       ScanPos,
  393.       LeftMarkPos,
  394.       RightMarkPos,
  395.       Found,
  396.       i
  397.  
  398.    If HyperMemo.nHotSpots = 0 Then
  399.       Return
  400.    Endif
  401.    Editor Info To EditorBag
  402.    If EditorBag["SelStart"] = 0 Then
  403.       ScanPos = EditorBag["CharPos"]
  404.    Else
  405.       Return
  406.    Endif
  407.    Found = False
  408.    For i From 1 to HyperMemo.nHotSpots
  409.       Found = HyperMemo.HotSpotLeft[i] <= ScanPos And HyperMemo.HotSpotRight[i] >= ScanPos
  410.       If Found Then
  411.          LeftMarkPos = HyperMemo.HotSpotLeft[i]
  412.          RightMarkPos = HyperMemo.HotSpotRight[i]
  413.          QuitLoop
  414.       Endif
  415.    EndFor
  416.    If Found Then
  417.       Editor Select LeftmarkPos RightMarkPos
  418.    Endif
  419. EndProc ; HyperMemo!MarkCurrentHotSpot
  420.  
  421. Proc HyperMemo.PrevPanel()
  422.    Private
  423.       LeftMarkPos,
  424.       RightMarkPos
  425.    Echo off
  426.    If HyperMemo.HelpDepth = 0 Then
  427.       Return False
  428.    Else
  429.       FieldView
  430.       Message "Working..."
  431.       HyperMemo_PanelName = HyperMemo.HotSpotStackName[HyperMemo.HelpDepth]
  432.       LeftMarkPos = HyperMemo.HotSpotStackLeft[HyperMemo.HelpDepth]
  433.       RightMarkPos = HyperMemo.HotSpotStackRight[HyperMemo.HelpDepth]
  434.       Release Vars
  435.          HyperMemo.HotSpotStackName[HyperMemo.HelpDepth],
  436.          HyperMemo.HotSpotStackLeft[HyperMemo.HelpDepth],
  437.          HyperMemo.HotSpotStackRight[HyperMemo.HelpDepth]
  438.       HyperMemo.HelpDepth = HyperMemo.HelpDepth - 1
  439.       Moveto [Help Panel name]
  440.       Locate IndexOrder HyperMemo_PanelName
  441.       Moveto [Help text]
  442.       Execproc HyperMemo.SetFocusProc
  443.       Editor Select LeftMarkPos RightMarkPos
  444.       Message ""
  445.       Echo normal
  446.       Return True
  447.    Endif
  448. EndProc ; HyperMemo.PrevPanel
  449.  
  450. Proc HyperMemo.GotoNextHotSpot()
  451.    Private
  452.       EditorBag,
  453.       ScanPos,
  454.       LeftMarkPos,
  455.       RightMarkPos,
  456.       Found,
  457.       i
  458.  
  459.    If HyperMemo.nHotSpots = 0 Then
  460.       Return 1
  461.    Endif
  462.    Editor Info To EditorBag
  463.    ScanPos = EditorBag["CharPos"]
  464.    Found = False
  465.    For i From 1 to HyperMemo.nHotSpots
  466.       HyperMemo!FindNextHotSpot()
  467.       If Found Then
  468.          QuitLoop
  469.       Endif
  470.    EndFor
  471.    If Not Found Then
  472.       ScanPos = 1
  473.       For i From 1 To HyperMemo.nHotSpots
  474.          HyperMemo!FindNextHotSpot()
  475.          If Found Then
  476.             QuitLoop
  477.          Endif
  478.       EndFor
  479.    Endif
  480.    Editor Select LeftmarkPos RightMarkPos
  481.    Return 1
  482. EndProc ; HyperMemo.GotoNextHotSpot
  483.  
  484. Proc HyperMemo!FindNextHotSpot()
  485.    If ScanPos <= HyperMemo.HotSpotRight[i] Then
  486.       Found = True
  487.       LeftmarkPos = HyperMemo.HotSpotLeft[i]
  488.       RightMarkPos = HyperMemo.HotSpotRight[i]
  489.    Endif
  490. EndProc ; HyperMemo!FindNextHotSpot
  491.  
  492. Proc HyperMemo.GotoPrevHotSpot()
  493.    Private
  494.       EditorBag,
  495.       ScanPos,
  496.       LeftMarkPos,
  497.       RightMarkPos,
  498.       Found,
  499.       i
  500.  
  501.    If HyperMemo.nHotSpots = 0 Then
  502.       Return 1
  503.    Endif
  504.    Editor Info To EditorBag
  505.    If EditorBag["SelStart"] = 0 Then
  506.       ScanPos = EditorBag["CharPos"]
  507.    Else
  508.       ScanPos = EditorBag["Selstart"] - 1
  509.    Endif
  510.    Found = False
  511.    For i From HyperMemo.nHotSpots to 1 Step -1
  512.       HyperMemo!FindPrevHotSpot()
  513.       If Found Then
  514.          QuitLoop
  515.       Endif
  516.    EndFor
  517.    If Not Found Then
  518.       ScanPos = Len(HyperMemo.HelpText)
  519.       For i From HyperMemo.nHotSpots To 1 Step -1
  520.          HyperMemo!FindPrevHotSpot()
  521.          If Found Then
  522.             QuitLoop
  523.          Endif
  524.       EndFor
  525.    Endif
  526.    Editor Select LeftmarkPos RightMarkPos
  527.    Return 1
  528. EndProc ; HyperMemo.GotoPrevHotSpot
  529.  
  530. Proc HyperMemo!FindPrevHotSpot()
  531.    If ScanPos >= HyperMemo.HotSpotLeft[i] Then
  532.       Found = True
  533.       LeftmarkPos = HyperMemo.HotSpotLeft[i]
  534.       RightMarkPos = HyperMemo.HotSpotRight[i]
  535.    Endif
  536. EndProc ; HyperMemo!FindPrevHotSpot