home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / me34src.zip / me3 / mutt / package / mouse.mut < prev    next >
Text File  |  1995-01-14  |  9KB  |  306 lines

  1. ;; mouse.mut - mouse support.
  2.  
  3. ;; WARNINGS
  4. ;;   DO NOT bind any keys in this file!  If it is autoloaded, binding keys
  5. ;;     may be put in the wrong keymap (eg popup menus).
  6.  
  7. ;; This code generates mouse events
  8. ;; Mouse driver (in ME) else handles motion compression
  9.  
  10. ;; MouseInfo
  11. ;;   button: 1, 2, 3, ... 5
  12. ;;   r,c: row and column of the current (abs) location of the mouse
  13. ;;        ??? deltas?
  14. ;;        Motion is character resolution
  15. ;;        Motion is compressed?  Will this mess up D&D?  Maybe don't care
  16. ;;          if only generate motion while a button is down.
  17. ;;        r == row, c == col
  18. ;;        Origin?
  19. ;;   state: 
  20. ;;     If button != 0, 0 is button is up, 1 if button is down, 2 is both
  21. ;;       (ie button click, not a drag).
  22. ;;   motion: 1 if mouse motion else 0
  23. ;; No MouseInfo generated without a button
  24.  
  25. ;; Generated MouseInfo:
  26. ;;   Button click:
  27. ;;     Button 1 clicked:  (1, -1,0, C)
  28. ;;   Drag:
  29. ;;     Move mouse while button 1 is down:
  30. ;;     Button 1 pressed:  nothing
  31. ;;     Mouse moved:      (1,  <start r,c>, D), (1, r,c, D)
  32. ;;     Get motion event when mouse moves more than 1 character.
  33. ;;     Button 1 released: (1,  r,c, U)
  34. ;;   Double click:
  35. ;;     ???
  36.  
  37. ;; Generated mouse events:
  38. ;;   Button  Motion  D/U/C    Event
  39. ;;    1,2,3   no      C        S-<x> where x is 1,2 or 3 
  40. ;;    1,2,3   yes     D        S-<x> where x is 3 + 1,2 or 3 
  41.  
  42. ;; Mouse keys:
  43. ;;   S-m : what ME sends for all mouse events.  Use (mouse-info) to find
  44. ;;         out more about the event.
  45. ;;   This code converts the mouse event into ME keys that can be bound.
  46. ;;     They are:
  47. ;;       S-1 ... S-5 : Mouse click on button 1 ... 5
  48.  
  49. ;;       S-! : Shift mouse click button 1
  50. ;;       S-@ : Shift mouse click button 2
  51. ;;       S-# : Shift mouse click button 3
  52. ;;       S-$ : Shift mouse click button 4
  53. ;;       S-% : Shift mouse click button 5
  54.  
  55. ;;       C-S-1 ... C-S-5 : Control Shift mouse click button 1 ... 5
  56. ;;       M-S-1 ... M-S-5 : Meta Shift mouse click button 1 ... 5
  57. ;;       M-C-S-1 ... M-C-S-5 : Meta Control Shift mouse click button 1 ... 5
  58.  
  59. ;;   For mouse motion (holding down a mouse button while moving the mouse),
  60. ;;     S-6 ... S-0 (^&*() for shifted) keys are generated.
  61.  
  62.  
  63. (include me.mh)
  64.  
  65. (defun
  66.   MAIN
  67.   {
  68.     (bind-key GLOBAL-KEYMAP
  69.     "do-mouse"        "S-m"
  70.     "mouse-move-point"    "S-1"
  71.     "mouse-1"        "S-2"
  72.     "mouse-set-mark"    "S-3"    ;;       button 3
  73.     "mouse-copy-region"    "S-#"    ;; shift   button 3
  74.     "yank"            "C-S-3"    ;; control button 3
  75.     "mouse-drag"        "S-a"
  76.     "previous-page"        "S-!"    ;; shift   button 1
  77.     "next-page"        "S-@"    ;; shift   button 2
  78.     "scroll-up"        "C-S-1"    ;; control button 1
  79.     "scroll-down"        "C-S-2"    ;; control button 2
  80.     )
  81.   }
  82.   mouse-move-point { (point-to-mouse) }
  83.   mouse-set-mark   { (if (point-to-mouse) (set-the-mark)) }
  84.   mouse-copy-region
  85.   {
  86.     (if (copy-region) (msg "Region copied."))
  87.   }
  88.   mouse-1
  89.   {
  90.     (int where-is-mouse window row-in-window)
  91.     (small-int button row col state modifiers)    ;; MouseInfo
  92.  
  93.     (mouse-info (loc button))
  94.     (where-is-mouse (mouse-window row (loc window)(loc row-in-window)))
  95.     (cond
  96.       (== 0 where-is-mouse)     ;; mouse in a window
  97.     {
  98.       (if (== col (screen-width))
  99.         {
  100.           (cond
  101.             (== 1 row-in-window)           (previous-page)
  102.             (== (window-length) row-in-window) (next-page)
  103.         TRUE    { (arg-prefix 1)(refresh-screen) }
  104.           )
  105.         }
  106.         (point-to-mouse))
  107.     }
  108.       (== 1 where-is-mouse) (free-window window) ;; mouse on a modeline
  109.     )
  110.   }
  111. )
  112.  
  113. (bool mouse-drag-in-progress mouse-drag-no-good)
  114.  
  115. (defun
  116.   mouse-drag
  117.   {
  118.     (small-int button row col mouse-state modifiers)    ;; MouseInfo
  119.  
  120.     (mouse-info (loc button))
  121.     (if mouse-drag-no-good
  122.       {
  123.     (if (== mouse-state BUTTON-UP)    ;; done dragging
  124.       {
  125.         (mouse-drag-no-good FALSE)
  126.         (mouse-drag-in-progress FALSE)
  127.       })
  128.           (done)
  129.       })
  130.  
  131.     (if mouse-drag-in-progress
  132.       {
  133.     (floc "mouse-dragging"())
  134.     
  135.     (if (== mouse-state BUTTON-UP)    ;; done dragging
  136.       {
  137.         (floc "mouse-drag-done"())
  138.         (mouse-drag-in-progress FALSE)
  139.       })
  140.       }
  141.       {
  142.     (mouse-drag-no-good (not (floc "mouse-drag-start"())))
  143.     (mouse-drag-in-progress TRUE)
  144.       })
  145.   }
  146. )
  147.  
  148. (defun
  149.   mouse-drag-start
  150.   {
  151.     (small-int button row col state modifiers)    ;; MouseInfo
  152.  
  153.     (mouse-info (loc button))
  154.     (msg "Mouse drag start: (" row "," col ")") 
  155.     TRUE
  156.   }
  157.   mouse-dragging
  158.   {
  159.     (small-int button row col state modifiers)    ;; MouseInfo
  160.  
  161.     (mouse-info (loc button))
  162.     (msg "Mouse drag in progess: (" row "," col ")") 
  163.   }
  164.   mouse-drag-done
  165.   {
  166.     (small-int button row col state modifiers)    ;; MouseInfo
  167.  
  168.     (mouse-info (loc button))
  169.     (msg "Done dragging: (" row "," col ")")
  170.   }
  171. )
  172.  
  173. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  174. ;;;;;;;;;;;;;;;;;;;;;;;; ME Support Routines ;;;;;;;;;;;;;;;;;;;;;;;;;
  175. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  176.  
  177. ;; !!!!!!!!!!!!!???????????????
  178. ;; modify (window-row) to:
  179. ;;   (window-row)   : same
  180. ;;   (window-row 0) : same as (window-row)
  181. ;;   (window-row 1) : screen row
  182.  
  183.  
  184. (defun screen-row
  185. {
  186.   (int n row)
  187.  
  188.   (row (window-row))
  189.   (n (- (current-window) 1))
  190.   (while (!= -1 n)
  191.     {
  192.       (+= row (window-length n) 1)
  193.       (-= n 1)
  194.     })
  195.   row
  196. })
  197.  
  198.     ;; Find the window the mouse is in
  199.     ;; Returns:
  200.     ;;   0: Mouse is in a window
  201.     ;;   1: Mouse is on a modeline
  202.     ;;   2: Mouse is mini buffer
  203.     ;;   window: id of window mouse is in
  204.     ;;   mouse-row-in-window: 
  205. (defun mouse-window (int mouse-row)(pointer int window mouse-row-in-window)
  206. {
  207.   (int n rows)
  208.  
  209.   (n 0)(rows 0)
  210.   (while (!= n (windows))
  211.     {
  212.       (if (<= mouse-row (+= rows (window-length n) 1))
  213.         {
  214.       (window n)
  215.       (mouse-row-in-window
  216.         (+ (- mouse-row rows) 1 (window-length n)))
  217.       (if (== mouse-row rows) 1 0)
  218.       (done)
  219.     })
  220.       (+= n 1)
  221.     })
  222.     2
  223. })
  224.  
  225.     ;; Move the point to where the mouse cursor is.
  226.     ;; This only works right after a mouse event
  227. (defun point-to-mouse
  228. {
  229.   (int sr where-is-mouse window row-in-window)
  230.   (small-int button mouse-row mouse-col state modifiers)    ;; MouseInfo
  231.  
  232.   (mouse-info (loc button))
  233.   (where-is-mouse (mouse-window mouse-row (loc window)(loc row-in-window)))
  234.   (if (!= 0 where-is-mouse) { FALSE (done) })  ;; in minibuffer or on modeline
  235.   (current-window window)(update)
  236. ;(msg ">>" window "  " row-in-window "  " (window-row))
  237.   (forward-line (- row-in-window (window-row)))
  238.   (current-column mouse-col)
  239.   TRUE
  240. })
  241.  
  242. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  243. ;;;;;;;;;;;;;;;;;;;;;;;;;;;; Gory Details ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  244. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  245.  
  246. ;; This code converts the mouse key (from the driver) multiple mouse keys.
  247.  
  248. ;; No MouseInfo generated without a button
  249.  
  250. ;; Generated MouseInfo:
  251. ;;   Button click:
  252. ;;     Button 1 clicked:  (1, -1,0, C)
  253. ;;   Drag:
  254. ;;     Move mouse while button 1 is down:
  255. ;;     Button 1 pressed:  nothing
  256. ;;     Mouse moved:      (1,  <start r,c>, D), (1, r,c, D)
  257. ;;     Get motion event when mouse moves more than 1 character.
  258. ;;     Button 1 released: (1,  r,c, U)
  259. ;;   Double click:
  260. ;;     ???
  261.  
  262. ;; Generated mouse events:
  263. ;;   Button  Motion  D/U/C    Event
  264. ;;    1,2,3   no      C        S-<x> where x is 1,2 or 3 
  265. ;;    1,2,3   yes     D        S-<x> where x is 3 + 1,2 or 3 
  266.  
  267. ;; Mouse keys:
  268. ;;   S-m : what ME sends for all mouse events.  Use (mouse-info) to find
  269. ;;         out more about the event.
  270. ;;   This code converts the mouse event into ME keys that can be bound.
  271. ;;     They are:
  272. ;;       S-1 ... S-5 : Mouse click on button 1 ... 5
  273.  
  274. ;;       S-! : Shift mouse click button 1
  275. ;;       S-@ : Shift mouse click button 2
  276. ;;       S-# : Shift mouse click button 3
  277. ;;       S-$ : Shift mouse click button 4
  278. ;;       S-% : Shift mouse click button 5
  279.  
  280. ;;       C-S-1 ... C-S-5 : Control Shift mouse click button 1 ... 5
  281. ;;       M-S-1 ... M-S-5 : Meta Shift mouse click button 1 ... 5
  282. ;;       M-C-S-1 ... M-C-S-5 : Meta Control Shift mouse click button 1 ... 5
  283.  
  284. ;;   For mouse motion (holding down a mouse button while moving the mouse),
  285. ;;     S-6 ... S-0 (^&*() for shifted) keys are generated.
  286.  
  287. (defun
  288.   do-mouse
  289.   {
  290.     (small-int button r c state modifiers)    ;; MouseInfo
  291.     (int b)
  292.  
  293.     (mouse-info (loc button))
  294. ;(msg "do-mouse: " button " " r " " c " " state)(get-key)
  295.  
  296.     (b button)
  297.     (if (== BUTTON-DOWN state)         (+= b 5))    ;; mouse motion
  298.     (if (!= 0 (bit-and SHIFT modifiers)) (+= b 10))    ;; Shift modifier
  299.     (exe-key
  300.       (bit-or        ;; "S-<modifiers><special key>
  301.     SHIFT
  302.     modifiers
  303.     (convert-to CHARACTER (extract-element " 1234567890!@#$%^&*()" b))))
  304.   }
  305. )
  306.