(in-package "COMMON-LISP-USER")

;;; File: application-starter.lisp
;;; 
;;; This provides a wraparound startup function for a standalone
;;; KPML image using CLIM as the interface implementation. Necessary
;;; work like binding those nonexistent streams is done here...

(defvar *help-window* nil)
(defvar *trash-all-extra-messages-p* nil)
(defvar *reload-kpml-configuration-file* nil
  "When set, reloads configuration file following patch loading.")

;;; First version here is for PC use only, and only under
;;; Franz ACL3.0 pc  at that...

(defun START-KPML-APPLICATION ()
  (let* ((*terminal-io* (if *trash-all-extra-messages-p*
			    (make-broadcast-stream)
			  #+acl3.0
			  (progn
			    (first 
			     (windows 
			      (open-stream 'te:text-edit-window 
					   cg:*screen* :io
					   :title "KPML background messages"
					   :window-exterior
					   (make-box 100 200 500 275)))))
			  #-acl3.0
			  (make-broadcast-stream)))
	 (*error-output* *terminal-io*))
    #+acl3.0(unless *trash-all-extra-messages-p*
		    (te:beginning-of-file *terminal-io*))

    (setf kpml::*standalone* T)

    (kpml::load-kpml-configuration-file)
    (kpml::load-compiled-kpml-patches-only)

    (kpml-i::set-window-sizes :small)

    (setf kpml-i::*color-pilot-palette* 
	  (clim:frame-palette 
	   (clim:make-application-frame 'kpml-i::color-pilot)))
    (setf kpml::window-interface-flag T)

    (kpml-i::color)

    (when *reload-kpml-configuration-file* 
      (kpml::load-kpml-configuration-file))

    (when kpml::*editing-protocol* (kpml::open-and-start-editing-log))
    (kpml-i::protected-window-startup)))


#+acl3.0
(defun common-lisp-user::about-application ()
  (if (windowp *help-window*) *help-window* 
    (setq *help-window* (make-help-window))))
 
#+acl3.0
(defun make-help-window (&key (parent *lisp-main-window*) 
                      (window-interior (make-box 311 152 624 285)) 
                      (name :help-window) (title "Help window"))
   (setq *loaded-but-uncreated-windows* 
      (delete 'help-window *loaded-but-uncreated-windows*))
   (let (window-0 window-1 window-2 window-3 window-4)
      (setq window-0 
         (open-dialog 
            (list 
               (make-dialog-item 
                  :widget 'static-text 
                  :name :static-text-4 
                  :title (delete #\Newline "Static Text 4") 
                  :value 
                  (delete #\Newline 
"This is the KPML linguistic resource development environment for PCs.")
                  :box (make-box 20 18 289 119) 
                  :tabstop nil 
                  :groupstart t 
                  :font (make-font-ex nil :arial 13 '(:bold))))
            'dialog parent 
            :name name 
            :title title 
            :font (make-font :swiss :system 16 '(:bold)) 
            :window-state :shrunk 
            :window-border :frame 
            :left-attachment nil 
            :top-attachment nil 
            :right-attachment nil 
            :bottom-attachment nil 
            :user-movable t 
            :user-resizable t 
            :user-closable t 
            :user-shrinkable t 
            :user-scrollable nil 
            :overlapped nil 
            :background-color light-gray 
            :pop-up-p nil 
            :window-interior window-interior))
      (setf (window-editable-p window-0) t)
      (setf (getf (stream-plist window-0) :path) "")
      (setf (getf (stream-plist window-0) :startup-state) nil)
      (setf (getf (stream-plist window-0) :top-level-p) nil)
      (setf (help-string window-0) (delete #\Newline nil))
      (setf (getf (stream-plist window-0) :package) nil)
      nil
      (let* ((box (getf *window-exteriors* (object-name window-0))))
         (when box (reshape-window-exterior window-0 box)))
      (show-window window-0 nil)
      window-0))

#+acl3.0
(unless (windowp *help-window*) 
   (pushnew 'help-window *loaded-but-uncreated-windows*))




