;; -*- Mode:Common-Lisp; Package:MACTOOLBOX; Base:10; Fonts:(CPTFONT HL10B HL12I CPTFONT CPTFONTB) -*- 

;Ï1;; INSTRUCTIONS for EXAMPLES in this FILE:Ï*
;Ï1;;     * Compile and load this file.  For example, if you are reading this in a Zmacs buffer, then use META-Z.Ï*
;Ï1;;     * Make sure the default TB Server is running, enter Ï*(tb:launch-default-tb-server t)Ï1 in aÏ*
;Ï1;;        listener.  (You will have to click on the microExplorer window to reselect it after the launch.)Ï*
;Ï1;;     * Shrink the microExplorer window until it occupies the lower half of the screen leaving the upper halfÏ*
;Ï1;;        free for the window  some of these examples create. Ï*
;Ï1;;     * Enter a call to the example function in a listenerÏ*
;Ï1;;     * The call should display a dialog box which may be partially obscured by you microExplorer window.Ï*
;Ï1;;       Just click on the dialog box to bring it to the front.Ï*
;Ï1;;     * When you have made your choices in the dialog box and clicked on either OPEN or CANCEL, theÏ*
;Ï1;;       example function returns, but you will have to click once again on the microExplorer window to makeÏ*
;Ï1;;       it active.Ï*


(defun Ï4MacGetFile Ï*(&rest typenames)
  "Ï2Displays a dialog box of available disks, folders, and files for user to choose
from. Argument is zero or more Macintosh file types (see III-9) which are four
character strings.  Note:  these Macintosh `file types' are unrelated to the type
component of Common Lisp pathnames.  If no typenames are specified, then any file
type is acceptable.    If user clicks CANCEL, GOOD-P is false.  Otherwise, GOOD-P
is true and the volume reference number and the file name are returned.Ï*"
  (declare (values Ï3good-p |vRefNum| |fName|Ï*))
  (let ((typename-count (or (length typenames) -1))
	(reply         (make-instance 'SFReply))
	(point (make-instance 'point :h 160 :v 100)))
    (!SFGetFile point           ;Ï1 upper left corner of dialog box in global coordinatesÏ*
		""              ;Ï1 prompt argument is no longer used by the MacintoshÏ*
		!nilptr	        ;Ï1 fileFilter argument not available yet, always use !nilPtrÏ*
		typename-count	;Ï1 count of file type names or -1 to imply all type namesÏ*
		typenames       ;Ï1 list of 0..4 4-character file type name strings, or NIL for all typesÏ*
		!nilptr         ;Ï1 dlgHook argument not available yet, always use !nilPtrÏ*
		reply)          ;Ï1 SFReply instance in which return values will be storedÏ*
    (values reply                  ;Ï1SFReply instanceÏ*
	    (send reply :good) Ï3 Ï*   ;Ï1true=>user clicked on OPEN;  false=>clicked on CANCELÏ*
            (send reply :vRefNum)  ;Ï1volume reference number of disk/diredirectoryÏ*
	    (send reply :fName)))  ;Ï1file name string (includes Lisp name and type components)Ï*
  );Ï1;macgetfileÏ*


(defun Ï4MacPutFile Ï*(prompt-string &optional default-fname)
  "Ï2Prompts the user with a dialog box asking for an output filename.  Returns when
user clicks on CANCEL (GOOD-P false) or when user clicks on OPEN (GOOD-P true)
after having specified a non-lock file which does not yet exist or for which the
user has given permission to replace.Ï*"
  (declare (values reply good-p |Ï3vRefNum|Ï* |Ï3fName|Ï*))
  (check-type prompt-string string)
  (check-type default-fname (or null string))
  (let ((reply (make-instance 'SFReply))
	(point (make-instance 'point :h 160 :v 100)))
    (!SFPutFile point           ;Ï1 upper left corner of dialog box in global coordinatesÏ*
		prompt-string   ;Ï1 a prompt string explaining what the filename is needed forÏ*
		(or default-fname ;Ï1 a default filename for the user to accept or editÏ*
		    "")
		!nilptr         ;Ï1 dlgHook argument not available yet, always use !nilPtrÏ*
		reply)          ;Ï1 SFReply instance in which return values will be storedÏ*
    (values reply                  ;Ï1SFReply instanceÏ*
	    (send reply :good) Ï3 Ï*   ;Ï1true=>user clicked on OPEN;  false=>clicked on CANCELÏ*
	    (send reply :vRefNum)  ;Ï1volume reference number of disk/diredirectoryÏ*
	    (send reply :fName)))  ;Ï1file name string (includes Lisp name and type components)Ï*
  );Ï1;macputfileÏ*


(defun Ï4OpenResFile Ï*()
  (declare (values |Ï3resFile-refNum|Ï*))
  (let ((reply (make-instance 'SFReply))
	(point (make-instance 'point :h 160 :v 100)))
    (!SFGetFile point "" !nilptr -1 () !nilptr reply)
    (!flushevents !everyEvent 0)
    (if (send reply :good)
	(!OpenRFPerm  (send reply :fname) (send reply :vrefnum) !fsCurPerm)
	nil))
  );Ï1;openresfile












