;;; -*- Mode: Common-Lisp; Package: User; Base: 10.; Patch-File: T -*-

;;; Reason: Make mouse-warp a complete no-op on an mX.  In hysteretic-window-mixin's 
;;; :handle-mouse method, use unglitched mouse position only on mmon systems, use
;;; mouse-x/mouse-y on mX and single-monitor Explorers.  Fixes SPRs 9909, 9910,
;;; 9959, 9961, and 9985.

;;;                           RESTRICTED RIGHTS LEGEND
;;;
;;; Use, duplication, or disclosure by the Government is subject to
;;; restrictions as set forth in subdivision (c)(1)(ii) of the Rights in
;;; Technical Data and Computer Software clause at 52.227-7013.
;;;
;;;   TEXAS INSTRUMENTS INCORPORATED      
;;;   P.O. BOX 2909, M/S 2151             
;;;   AUSTIN, TEXAS 78769                 
;;;
;;; Copyright (C) 1989 Texas Instruments Incorporated.
;;; All rights reserved.

;;; Written 06/13/89 13:21:52 by GRENINGER,
;;; while running on MX23 from band P526
;;; With SYSTEM 6.5, GC 6.2, VIRTUAL-MEMORY 6.1, MICRONET 6.0, MICRONET-COMM 6.1,
;;;  DISK-IO 6.0, DISK-LABEL 6.0, BASIC-PATHNAME 6.0, MAC-PATHNAME 6.0, NETWORK-SUPPORT-COLD 6.0,
;;;  BASIC-NAMESPACE 6.0, BASIC-FILE 6.1, RPC 6.1, NFS 6.0, EH 6.1, MAKE-SYSTEM 6.0,
;;;  MEMORY-AUX 6.0, COMPILER 6.2, TV 6.6, NVRAM 6.0, UCL 6.0, INPUT-EDITOR 6.0, MACTOOLBOX 2.0,
;;;  METER 6.0, ZWEI 6.0, DEBUG-TOOLS 6.0, WINDOW-MX 6.2, PRINTER 6.1, MAC-PRINTER-TYPES 6.1,
;;;  CLIPBOARD 6.0, NETWORK-PATHNAME 6.0, NETWORK-NAMESPACE 6.0, DATALINK 6.0, CHAOSNET 6.0,
;;;  NETWORK-SUPPORT 6.0, NETWORK-SERVICE 6.0, DATALINK-DISPLAYS 6.0, MX-DATALINK 6.0,
;;;  NAMESPACE-EDITOR 6.0, IP 3.46, NFS-SERVER 6.0, MX-SERIAL 6.0, PRINTER-TYPES 6.0,
;;;  IMAGEN 6.0, MAIL-DAEMON 6.2, MAIL-READER 6.0, TELNET 6.0, VT100 6.0, STREAMER-TAPE 6.1,
;;;  DECNET 1.67, VISIDOC 6.1, PROFILE 6.1, TI-CLOS 6.5, CLEH 6.3, CLX 6.0, CLUE 6.0,
;;;  Experimental BUG 11.5,  microcode 138, Band Name: Release 6.0 mx 5/26

#!C
; From file MOUSE.LISP#> WINDOW; SYS:
#10R TV#:
(COMPILER-LET ((*PACKAGE* (FIND-PACKAGE "TV"))
                          (SI:*LISP-MODE* :COMMON-LISP)
                          (*READTABLE* COMMON-LISP-READTABLE)
                          (SI:*READER-SYMBOL-SUBSTITUTIONS* SYS::*COMMON-LISP-SYMBOL-SUBSTITUTIONS*))
  (COMPILER#:PATCH-SOURCE-FILE "SYS: WINDOW; MOUSE.#"


(DEFUN MOUSE-WARP (X Y &OPTIONAL (RELATIVE NIL))
  "Sets mouse position on MOUSE-SHEET to X and Y.  If RELATIVE is
T then the mouse moves relative to its current position.  If RELATIVE
is NIL then the mouse moves to the specified (X,Y) position."
  (UNLESS (OR (AND (= MOUSE-X X) (= MOUSE-Y Y))
	      (mac-window-p mouse-sheet))
    (SETQ MOUSE-WARP T)
    (WITHOUT-INTERRUPTS
      (%OPEN-MOUSE-CURSOR)
      ;; Also update the *unglitched-...* variables.
      ;; This ensures mouse-transport stops in case mouse-overseer gets called before mouse-input after a mouse-transport.
      ;; Added for mouse-transport support.  CJJ 06/06/88.
      ;;; Added by KJF for CJJ on 08/16/88 for Multiple Monitor (MMON) support.
      (SETQ *unglitched-mouse-x*
	    (SETQ MOUSE-LAST-X
		  (SETQ MOUSE-X (MAX 0
				     (MIN (1- (SHEET-WIDTH MOUSE-SHEET))
					  (IF RELATIVE (+ MOUSE-X X) X))))))
      (SETQ *unglitched-mouse-y*
	    (SETQ MOUSE-LAST-Y
		  (SETQ MOUSE-Y (MAX 0
				     (MIN (1- (SHEET-HEIGHT MOUSE-SHEET))
					  (IF RELATIVE (+ MOUSE-Y Y) Y))))))
      (SETQ MOUSE-CURSOR-STATE MOUSE-CURSOR-CLOSED-STATE
	    PREPARED-SHEET NIL
	    ;;; Added by KJF for CJJ on 08/16/88 for Multiple Monitor (MMON) support.
	    *unglitched-mouse-x-speed* 0
	    *unglitched-mouse-y-speed* 0))
    (MOUSE-SET-BLINKER-CURSORPOS)
    ;; Make sure the mouse tracker process notices.
    (SETQ MOUSE-WAKEUP T)))

))

#!C
; From file MOUSE.LISP#> WINDOW; SYS:
#10R TV#:
(COMPILER-LET ((*PACKAGE* (FIND-PACKAGE "TV"))
                          (SI:*LISP-MODE* :COMMON-LISP)
                          (*READTABLE* COMMON-LISP-READTABLE)
                          (SI:*READER-SYMBOL-SUBSTITUTIONS* SYS::*COMMON-LISP-SYMBOL-SUBSTITUTIONS*))
  (COMPILER#:PATCH-SOURCE-FILE "SYS: WINDOW; MOUSE.#"


(DEFMETHOD (HYSTERETIC-WINDOW-MIXIN :HANDLE-MOUSE) ()
  (LET (LEFT-LIM  TOP-LIM
        RIGHT-LIM BOTTOM-LIM
	current-mouse-x current-mouse-y)
    ;;  Using *unglitched-mouse-x* and -y* is dangerous, as they can make us think
    ;;  the mouse has left our window, but when the mouse-overseer calls
    ;;  window-owning-mouse (which calls window-under-mouse which uses mouse-x
    ;;  and mouse-y) it sees a more current mouse position that may be within our
    ;;  window, resulting in an infinite loop in the mouse process.  The following code
    ;;  isolates this danger to mmon systems only.   LG  6-13-89

    (MULTIPLE-VALUE-SETQ (LEFT-LIM TOP-LIM)
      (SHEET-CALCULATE-OFFSETS SELF MOUSE-SHEET))
    (SETQ RIGHT-LIM  (+ LEFT-LIM WIDTH  HYSTERESIS)
          BOTTOM-LIM (+ TOP-LIM  HEIGHT HYSTERESIS)
          LEFT-LIM   (- LEFT-LIM HYSTERESIS)
          TOP-LIM    (- TOP-LIM  HYSTERESIS))
    (DO (W) (())
      ;; Let the mouse out of the window only if it moves more than <hysteresis> away
      (IF (mmon-p)
	  (SETF current-mouse-x *unglitched-mouse-x*
		current-mouse-y *unglitched-mouse-y*)
	(SETF current-mouse-x mouse-x
	      current-mouse-y mouse-y))
      (WHEN (OR MOUSE-RECONSIDER
		;; Also leave if mouse fell into inferior
		(AND (NEQ SELF (SETQ W (LOWEST-SHEET-UNDER-POINT MOUSE-SHEET
								 current-mouse-x current-mouse-y
								 NIL :EXPOSED)))
		     (SHEET-ME-OR-MY-KID-P W SELF))
		;; or if mouse is outside our window's hysteresis region
		(< current-mouse-x left-lim)
		(> current-mouse-x right-lim)
		(< current-mouse-y top-lim)
		(> current-mouse-y bottom-lim))
	(RETURN T))
      ;;  If mouse is still inside our window, 
      (MOUSE-STANDARD-BLINKER SELF)
      (MOUSE-DEFAULT-HANDLER SELF (SEND SELF :ENABLE-SCROLLING-P)))))

))
