[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

*text-restricted-dialog-item*



I can't begin to thank everyone enough for all the wonderful code that
is located on the cambridge ftp site.  As I convert my 1.3.2 code to
2.0 code, I hope I'll be able to contribute something useful.

I'm working on a Pascal programming environment.  This class of
dialog items is useful in a variety of situations.	


(defclass *text-restricted-dialog-item* (editable-text-dialog-item)
  ((max-length :initarg :max-length :accessor max-length)
   (char-set   :initarg :char-set   :accessor char-set))
  (:default-initargs
    :max-length nil
    :char-set   nil))


(defmethod length-ok? ((self *text-restricted-dialog-item*) char)
  (cond ((max-length self)
         (or (> (max-length self) 
                (length (dialog-item-text self))) 
             (not (graphic-char-p char))))
        (t 
         t)))
         
(defmethod char-in-char-set? ((self *text-restricted-dialog-item*) char)
  (cond ((char-set self) 
         (find char (char-set self))) 
        (t 
         t)))


(defmethod view-key-event-handler ((self *text-restricted-dialog-item*) char)
  (if (and (length-ok? self char)
           (char-in-char-set? self char))
    (call-next-method)))
 

;; here is some sample code showing a very simple use of this dialog-item
;;
;;-> get-student-name -----------------------------------------------------
;;
;;   DESCRiPTiON:
;;     sends the modal-dialog message to a small dialog window that 
;;     asks the user for their name.
;;
;;   RETURNS:
;;     The name of the student as a string.
;;
(defun get-student-name ()
  (modal-dialog
   (make-instance 'dialog
     :window-type    :document
     :window-title   "Student Name Dialog"
     :view-position  #@(40 50)
     :view-size      #@(202 88)
     :window-show    nil
     :close-box-p    nil
     :view-subviews
     (list (make-instance 'static-text-dialog-item
             :view-position    #@(5 8)
             :dialog-item-text "What is Your name?"
             :view-font        '("Monaco" 9 :plain)
             :view-nick-name   'student-name-prompt)

           (make-instance    '*text-restricted-dialog-item*
             :view-position   #@(8 24)
             :view-size       #@(188 10)
             :view-nick-name  'student-name
             :max-length      30
             :view-font       '("Monaco" 9 :plain)
             :allow-returns   nil)
             
           (make-instance 'button-dialog-item
             :view-position       #@(139 70)
             :view-size           #@(58 13)
             :dialog-item-text    "OK"
             :default-button      t
             :view-font           '("Monaco" 9 :bold)
             :dialog-item-action
             #'(lambda (self)
                 (let ((the-name (dialog-item-text (find-named-sibling self 'student-name))))
                   (cond ((string-equal the-name "")
                          (ed-beep)
                          (message-dialog "You must enter your name."))
                         (t
                          (return-from-modal-dialog the-name))))))))))