;;; -*- Mode:Common-Lisp; Package:TICLOS; Base:10; Patch-file:T -*-

;;; Reason: Fix printing of FONT and ICON objects.  [SPR 10142]


;;;                           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 149149, M/S 2151             
;;;   AUSTIN, TEXAS 78714
;;;
;;; Copyright (C) 1989 Texas Instruments Incorporated.
;;; All rights reserved.

;;; Written 07/03/89 15:36:17 by GRAY,
;;; while running on Kelvin from band LOD2
;;; With SYSTEM 6.10, 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.6, TV 6.11, DATALINK 6.0, CHAOSNET 6.0, GC 6.3, MEMORY-AUX 6.0, NVRAM 6.1,
;;;  SYSLOG 6.1, STREAMER-TAPE 6.3, UCL 6.0, INPUT-EDITOR 6.0, Inconsistent METER 6.1,
;;;  ZWEI 6.3, DEBUG-TOOLS 6.3, NETWORK-SUPPORT 6.0, NETWORK-SERVICE 6.1, DATALINK-DISPLAYS 6.0,
;;;  FONT-EDITOR 6.1, SERIAL 6.0, PRINTER 6.2, 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, Inconsistent TI-CLOS 6.11, CLEH 6.4,
;;;  IP 3.47, Experimental BUG 11.10, Experimental CLX 6.2, CLUE 6.5, X11M 6.1, Experimental DOCUMENTER 619.0,
;;;  Experimental GRAPHICS-WINDOW 6.0, Experimental GED 6.1,  microcode 429, Band Name: 6.0 SLE 6/5 + u429 6/8

;;; BUG REPORT NUMBER:  10142
;;;
;;; PROBLEM:  Cannot print or describe instances of structure W::ICON; get "no 
;;;	applicable method" error in PRINT-OBJECT and DESCRIBE-OBJECT.
;;;
;;; DIAGNOSIS:  This is a consequence of the fact that FONT is defined as 
;;;	both a structure and a flavor [see SPR 9423], which is causing CLOS to 
;;;	think that structure W::ICON is a subclass of flavor FONT instead of 
;;;	structure FONT, producing an incorrect class precedence list that does not 
;;;	include classes STRUCTURE-OBJECT or T.
;;;
;;; SOLUTION:  The proper solution will be to fix SPR 9423 by changing the 
;;;	name of flavor FONT, but for now, this patch works around the problem by 
;;;	adding code to (:METHOD STRUCTURE-CLASS :COMPOSE-CLASS) to produce a more 
;;;	nearly correct class precedence list for this special case.

#!C
; From file STRUCTURE-METACLASS.LISP#> CLOS; MR-X:
#10R TICLOS#:
(COMPILER-LET ((*PACKAGE* (FIND-PACKAGE "TICLOS"))
	       (SI:*LISP-MODE* :COMMON-LISP)
	       (*READTABLE* SYS:COMMON-LISP-READTABLE)
	       (SI:*READER-SYMBOL-SUBSTITUTIONS* SYS::*COMMON-LISP-SYMBOL-SUBSTITUTIONS*))
  (COMPILER#:PATCH-SOURCE-FILE "SYS: CLOS; STRUCTURE-METACLASS.#"


;;  7/03/89 DNG - Add special handling for when SUPER is not a structure-class.  [SPR 10142]
(defmethod (structure-class :compose-class)()
  (let* ((environment (class-description-environment class-description))
	 (super (class-named (car (class-direct-supers self)) nil environment)))
    (setf (class-description-class-precedence-list class-description)
	  (cons self (if (or (typep super 'structure-class)
			     (eq super '#,(find-class 'structure-object))) ; it ought to be
			 (or (internal-class-precedence-list super)
			     (progn (compose-class super)
				    (internal-class-precedence-list super)))
		       ;; Else something funny is happening; try to minimize the damage.
		       ;; We can get here for structure W:ICON which inherits from structure 
		       ;; W:FONT, but class W:FONT is a flavor -- see SPR 9423 and 10142.
		       ;; After SPR 9423 is fixed, we should probably signal an error here.
		       (cons super '#,(class-precedence-list (find-class 'structure-object)))))))
  (values))

))

;; Now fix up the ICON class by using the modified method above.
(compose-class (find-class 'w:icon))

;; In case these generic functions have already been called on an ICON, need 
;; to remove the "no applicable method" handler from the method hash table.
(let ((key (class-hash-key (find-class 'w:icon))))
  (remhash key (generic-function-method-hash-table (generic-function-named 'print-object)))
  (when (generic-function-p 'describe)
    (let ((table (generic-function-method-hash-table (generic-function-named 'describe))))
      (unless (null table) ; might not have been built yet
	(remhash key table)))))


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


;;  7/03/89 DNG - Added this method as a temporary work-around for SPR 9423.
(defmethod describe-object ((object w:font) stream)
  (let ((*standard-output* stream))
    (if (instancep object)
	(send object :describe)
      (describe-defstruct object))))
))
