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

;;; Reason: Fix Clip-By-Children to work when window has a single child but
;;; does not cover an edge.

;;;                           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.

;;; Patch file for X11M version 6.5
;;; Written 06/22/89 17:00:32 by buehring,
;;; while running on Spud from band LOD9
;;; With SYSTEM 6.9, VIRTUAL-MEMORY 6.1, EH 6.3, MAKE-SYSTEM 6.0, MICRONET 6.0, LOCAL-FILE 6.0,
;;;  BASIC-PATHNAME 6.0, NETWORK-SUPPORT-COLD 6.0, BASIC-NAMESPACE 6.1, NETWORK-NAMESPACE 6.0,
;;;  DISK-IO 6.0, DISK-LABEL 6.0, BASIC-FILE 6.2, MAC-PATHNAME 6.0, NETWORK-PATHNAME 6.0,
;;;  COMPILER 6.4, TV 6.11, DATALINK 6.0, CHAOSNET 6.0, GC 6.3, MEMORY-AUX 6.0, NVRAM 6.0,
;;;  SYSLOG 6.1, STREAMER-TAPE 6.3, UCL 6.0, INPUT-EDITOR 6.0, METER 6.0, ZWEI 6.3,
;;;  Experimental DEBUG-TOOLS 6.3, NETWORK-SUPPORT 6.0, NETWORK-SERVICE 6.0, DATALINK-DISPLAYS 6.0,
;;;  FONT-EDITOR 6.1, SERIAL 6.0, PRINTER 6.1, MAC-PRINTER-TYPES 6.1, PRINTER-TYPES 6.0,
;;;  IMAGEN 6.0, SUGGESTIONS 6.0, MAIL-DAEMON 6.2, MAIL-READER 6.0, TELNET 6.0, VT100 6.0,
;;;  NAMESPACE-EDITOR 6.0, PROFILE 6.1, VISIDOC 6.2, TI-CLOS 6.8, CLEH 6.4, IP 3.46,
;;;  Experimental BUG 11.10, CLX 6.0, CLUE 6.0, X11M 6.1,  microcode 429, Band Name: Rel6 5/22+SLE+hacks

#!C
; From file GRAPHICS-PRIMITIVES.LISP#> X11M.SERVER; MR-X:
#10R X11#:
(COMPILER-LET ((*PACKAGE* (FIND-PACKAGE "X11"))
                          (SI:*LISP-MODE* :COMMON-LISP)
                          (*READTABLE* SYS:COMMON-LISP-READTABLE)
                          (SI:*READER-SYMBOL-SUBSTITUTIONS* SYS::*COMMON-LISP-SYMBOL-SUBSTITUTIONS*))
  (COMPILER#:PATCH-SOURCE-FILE "X11M: SERVER; GRAPHICS-PRIMITIVES.#"


(defun clip-for-single-child-on-edge (window drawable-boundaries)
  "Returns T if WINDOW has a child which covers one of its edges completely, and
adjusts drawable-boundaries to exclude the child."
  (let ((child (locate-first-child window)))
    (when (and child ;; Only one child?
	       (eq child (window.last-child window)))
      (let ((child-x (window.x child))
	    (child-y (window.y child))
	    (child-width (window.outside-width child))
	    (child-height (window.outside-height child)))
	(cond 
	  ;; Top edge
	  ((and (zerop child-x)
		(zerop child-y)
		(= child-width (window.width window)))
	   (incf (box.top drawable-boundaries) child-height)
	   t)
	  ;; Bottom edge
	  ((and (zerop child-x)
		(= (+ child-y child-height)
		   (window.height window))
		(= child-width (window.width window)))
	   (decf (box.bottom drawable-boundaries) child-height)
	   t)
	  ;; Left edge
	  ((and (zerop child-x)
		(zerop child-y)
		(= child-height (window.height window)))
	   (incf (box.left drawable-boundaries) child-width)
	   t)
	  ;; Right edge
	  ((and (= (+ child-x child-width)
		   (window.width window))
		(zerop child-y)
		(= child-height (window.height window)))
	   (decf (box.right drawable-boundaries) child-width)
	   t)
	  (t nil))))))

))
