home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / drdobbs / 1990 / 06 / swaine.lst < prev    next >
File List  |  1990-05-02  |  3KB  |  107 lines

  1. _PROGRAMMING PARADIGMS_
  2. by Michael Swaine
  3.  
  4. [LISTING ONE] 
  5.  
  6. on mousewithin
  7.   --
  8.   --hypertext technique by Steve Drazga, AnalytX
  9.   --if you use this in your scripts please include these 2 lines.
  10.   --
  11.     if the locktext of the target is true then    
  12.       set locktext of target to false --unlock the field if it is 
  13. locked
  14.    end if
  15.  
  16.    if selection is not empty then --something was selected
  17.       put selection into SelectedWord
  18.       if space is in SelectedWord then --user selected > 1 word
  19.          click at loc of target --so we will clear the selection
  20.          exit mousewithin --and exit to wait for another 
  21. selection
  22.       end if
  23.     --
  24.     --this is the section where you do something with the 
  25. selection
  26.     --You can bring up a pop up note or you can go to another 
  27. card.  
  28.     --
  29.     end if
  30. end mousewithin
  31.  
  32.  
  33.  
  34. [LISTING TWO]
  35.  
  36. on mouseUp
  37.  
  38.   -- This code, placed in a button script, implements
  39.   -- Harvey Chang's hypertext trick.  The user selects
  40.   -- any text in a field and clicks on the button.
  41.   -- The script first tries to use the selected text as a
  42.   -- hypertext link, then falls back to simple search.
  43.  
  44.   doMenu Copy Text
  45.   put "Montreal Hypertext, Harvey Y Chang MD, 1988 Jan 16"
  46.   push card
  47.   go to Montreal Hypertext Demo
  48.   doMenu Find...
  49.   doMenu Paste Text
  50.   put " in field " & quote & "Title" & quote after message
  51.   do message
  52.   if the result is "not found" then
  53.     answer "not found in Titles:  search text?" with "OK" or "No"
  54.     if it is "No" then
  55.       pop card
  56.       exit mouseUp
  57.     else
  58.       doMenu Find...
  59.       doMenu Paste Text
  60.       put " in field " & quote & "Text" & quote after message
  61.       do message
  62.     end if
  63.   end if
  64. end mouseUp
  65.  
  66.  
  67. [LISTING THREE]
  68.  
  69. on mouseUp
  70.   
  71.   -- This is a scrolling field script.  Its field must be locked.
  72.   -- It implements an index field, to be placed on the first
  73.   -- card of the stack to be indexed.  This is the index card.
  74.   -- When the mouse is clicked inside the field, this script causes
  75.   -- a jump to the card corresponding to the line clicked on.
  76.   -- The line commented out uses the text in the line,
  77.   -- rather than its number, as the link.
  78.  
  79.   go to card getLineNum(the mouseV)
  80.   -- find line getLineNum(the mouseV) of me in field keyword
  81.   
  82. end mouseUp
  83.  
  84. function getLineNum mouseVert
  85.   
  86.   -- Returns the number of the line clicked on.
  87.   
  88.   -- It works like this:
  89.   -- Subtracting the top of the field and its scroll from
  90.   -- the mouse's vertical location gives the
  91.   -- mouse's vertical location within the field.
  92.   -- Dividing this by the textHeight of the field & adding 0.5
  93.   -- converts pixel counts to line counts.
  94.   -- Rounding gives a value acceptable as a card number.
  95.   
  96.   -- Note: although this technique should work with any font size,
  97.   -- turning on WideMargins will confuse the count.
  98.   -- To adapt this script to a non-scrolling field,
  99.   -- remove "+ the scroll of me" from the computation.
  100.   
  101.   return round(((mouseVert - the top of me + the scroll of me) / 
  102. (the textHeight of me)) + 0.5)
  103.   
  104. end getLineNum
  105.  
  106.  
  107.