home *** CD-ROM | disk | FTP | other *** search
- (in-package :oou)
- (oou-provide :te-blob)
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; te-blob.lisp
- ;;
- ;; Copyright ⌐ 1992 Northwestern University Institute for the Learning Sciences
- ;; All Rights Reserved
- ;;
- ;; author: Michael S. Engber
- ;;
- ;; styled text edit object
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- (oou-dependencies :QuickDraw-u
- :records-u)
-
- ;;currently I haven't documented and exported this thing. I'm reserving the
- ;; right to make signicant changes.
- ;;te-svm makes use of it.
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- (defCcallable te-clik-loop (:word)
- (declare (special *te-current-blob*))
- (declare (special *te-view-rect*))
- (te-click-loop *te-current-blob*)
- (#_ClipRect *te-view-rect*))
-
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- (defclass te-blob ()
- ((te-hTE :accessor te-hTE)
- (te-max-v-scroll :accessor te-max-v-scroll)
- (te-max-h-scroll :accessor te-max-h-scroll
- :initform 1000)
- (te-v-scroll-p :initarg :te-v-scroll-p
- :accessor te-v-scroll-p)
- (te-h-scroll-p :initarg :te-h-scroll-p
- :accessor te-h-scroll-p)
- (te-scroll-value-fn :initarg :te-scroll-value-fn
- :accessor te-scroll-value-fn)
- (te-scroll-limit-fn :initarg :te-scroll-limit-fn
- :accessor te-scroll-limit-fn)
- )
- (:default-initargs
- :te-topLeft #@(0 0)
- :te-botRight #@(100 100)
- :te-just :default
- :te-word-wrap-p nil
- :te-v-scroll-p nil
- :te-h-scroll-p nil
- ))
-
-
- (defmethod initialize-instance :after ((te te-blob) &rest initargs
- &key
- te-port
- te-topLeft
- te-botRight
- te-just
- te-word-wrap-p)
- (declare (ignore initargs))
- (rlet ((r :Rect
- :topLeft te-topLeft
- :bottomRight te-botRight))
- (with-port te-port
- (setf (te-hTE te) (#_TEStylNew r r))))
- (#_TEAutoView t (te-hTE te))
- (hset (te-hTE te) :TERec.clikLoop te-clik-loop)
- (#_TESetJust (ecase te-just
- (:default #$teFlushDefault)
- (:center #$teCenter)
- (:right #$teFlushRight)
- (:left #$teFlushLeft))
- (te-hTE te))
- (hset (te-hTE te) :TERec.crOnly (if te-word-wrap-p 0 -1)))
-
- (defmethod te-free ((te te-blob))
- (#_TEDispose (te-hTE te))
- (slot-makunbound te 'te-hTE))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- (defmethod te-draw ((te te-blob))
- (multiple-value-bind (topLeft botRight) (te-corners te)
- (rlet ((r :Rect
- :topLeft topLeft
- :bottomRight botRight))
- (#_TEUpdate r (te-hTE te)))))
-
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;vertical scrolling
-
- (defmethod te-calc-max-v-scroll ((te te-blob))
- (with-macptrs ((hTE (te-hTE te)))
- (setf (te-max-v-scroll te)
- (- (#_TEGetHeight 1 65535 hTE)
- (- (href hTE :TERec.viewRect.bottom) (href hTE :TERec.viewRect.top))))))
-
- (defmethod te-v-scroll-value ((te te-blob))
- (with-macptrs ((hTE (te-hTE te)))
- (- (href hTE :TERec.viewRect.top) (href hTE :TERec.destRect.top))))
-
- (defmethod (setf te-v-scroll-value) (new-scroll-value (te te-blob))
- (prog1
- (setf new-scroll-value (max 0 (min new-scroll-value (te-max-v-scroll te))))
- (#_TEScroll 0 (- (te-v-scroll-value te) new-scroll-value) (te-hTE te))
- (te-update-scroll-value te :vertical)))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;horizontal scrolling
-
- (defmethod te-calc-max-h-scroll ((te te-blob))
- (te-max-h-scroll te))
-
- (defmethod te-h-scroll-value ((te te-blob))
- (with-macptrs ((hTE (te-hTE te)))
- (- (href hTE :TERec.viewRect.left) (href hTE :TERec.destRect.left))))
-
- (defmethod (setf te-h-scroll-value) (new-scroll-value (te te-blob))
- (prog1
- (setf new-scroll-value (max 0 (min new-scroll-value (te-max-h-scroll te))))
- (#_TEScroll (- (te-h-scroll-value te) new-scroll-value) 0 (te-hTE te))
- (te-update-scroll-value te :horizontal)))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- (defmethod te-update-scroll-value ((te te-blob) direction)
- (when (slot-boundp te 'te-scroll-value-fn)
- (ecase direction
- (:vertical
- (funcall (te-scroll-value-fn te) :vertical (te-v-scroll-value te)))
- (:horizontal
- (funcall (te-scroll-value-fn te) :horizontal (te-h-scroll-value te))))))
-
- (defmethod te-update-scroll-limit ((te te-blob) direction)
- (when (slot-boundp te 'te-scroll-limit-fn)
- (ecase direction
- (:vertical
- (te-calc-max-v-scroll te)
- (funcall (te-scroll-limit-fn te) :vertical (te-max-v-scroll te)))
- (:horizontal
- (te-calc-max-h-scroll te)
- (funcall (te-scroll-limit-fn te) :horizontal (te-max-h-scroll te))))))
-
- (defmethod te-update ((te te-blob))
- (#_TECalText (te-hTE te))
- (te-update-scroll-limit te :vertical)
- (te-update-scroll-value te :vertical)
- (te-update-scroll-limit te :horizontal)
- (te-update-scroll-value te :horizontal))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;text position
-
- (defmethod te-corners ((te te-blob))
- (with-macptrs ((hTE (te-hTE te)))
- (values (href hTE :TERec.viewRect.topLeft) (href hTE :TERec.viewRect.botRight))))
-
- (defmethod set-te-corners ((te te-blob) topLeft botRight)
- (with-macptrs ((hTE (te-hTE te)))
- (multiple-value-bind (old-tl old-br) (te-corners te)
- (let ((d-tl (subtract-points (href hTE :TERec.destRect.topLeft) old-tl))
- (d-br (subtract-points (href hTE :TERec.destRect.botRight) old-br)))
- (hset hTE :TERec.viewRect.topLeft topLeft)
- (hset hTE :TERec.viewRect.botRight botRight)
- (hset hTE :TERec.destRect.topLeft (add-points topLeft d-tl))
- (hset hTE :TERec.destRect.botRight (add-points botRight d-br)))
- (te-update te)
- (values topLeft botRight))))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;text font
-
- (defmethod te-set-font ((te te-blob) font-spec &key (font-color *black-color*) (mode #$doAll))
- (multiple-value-bind (ff ms) (font-codes font-spec)
- (rlet ((ts :TextStyle
- :tsFont (#_HiWord ff)
- :tsFace (ash (#_LoWord ff) -8)
- :tsSize (#_LoWord ms)
- :tsColor.red (color-red font-color)
- :tsColor.green (color-green font-color)
- :tsColor.blue (color-blue font-color)))
- (#_TESetStyle mode ts t (te-hTE te))
- (#_TESelView (te-hTE te))))
- (te-update te)
- font-spec)
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;text justification
-
- (defmethod te-just ((te te-blob))
- (ecase (href (te-hTE te) :TERec.just)
- (#.#$teFlushDefault :default)
- (#.#$teCenter :center)
- (#.#$teFlushRight :right)
- (#.#$teFlushLeft :left)))
-
- (defmethod (setf te-just) (new-te-just (te te-blob))
- (#_TESetJust
- (ecase new-te-just
- (:default #$teFlushDefault)
- (:center #$teCenter)
- (:right #$teFlushRight)
- (:left #$teFlushLeft))
- (te-hTE te))
- (te-update te)
- new-te-just)
-
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;word wrap
-
- (defmethod te-word-wrap-p ((te te-blob))
- (ecase (href (te-hTE te) :TERec.crOnly)
- (-1 nil)
- ( 0 t)))
-
- (defmethod (setf te-word-wrap-p) (wrap-p (te te-blob))
- (hset (te-hTE te) :TERec.crOnly (if wrap-p 0 -1))
- (te-update te)
- wrap-p)
-
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; event handlers
-
- (defmethod te-click-handler ((te te-blob) where &key (extend-p (shift-key-p)))
- (let ((*te-current-blob* te))
- (declare (special *te-current-blob*))
- (rlet ((*te-view-rect* :Rect))
- (declare (special *te-view-rect*))
- (multiple-value-bind (topLeft botRight) (te-corners te)
- (pset *te-view-rect* :Rect.topLeft topLeft)
- (pset *te-view-rect* :Rect.botRight botRight)
- (with-clip-rect *te-view-rect*
- (#_TEClick where extend-p (te-hTE te)))))))
-
- (defmethod te-key ((te te-blob) char)
- (#_TESelView (te-hTE te))
- (#_TEKey char (te-hTE te))
- (te-update te))
-
- (defmethod te-idle ((te te-blob))
- (#_TEIdle (te-hTE te)))
-
- (defmethod te-activate ((te te-blob))
- (#_TEActivate (te-hTE te)))
-
- (defmethod te-deactivate ((te te-blob))
- (#_TEDeactivate (te-hTE te)))
-
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; editing commands
-
- (defmethod te-cut ((te te-blob))
- (#_TESelView (te-hTE te))
- (#_TECut (te-hTE te))
- (te-update te))
-
- (defmethod te-copy ((te te-blob))
- (#_TESelView (te-hTE te))
- (#_TECopy (te-hTE te)))
-
- (defmethod te-paste ((te te-blob))
- (#_TESelView (te-hTE te))
- (#_TEStylPaste (te-hTE te))
- (te-update te))
-
- (defmethod te-clear ((te te-blob))
- (#_TESelView (te-hTE te))
- (#_TEDelete (te-hTE te))
- (te-update te))
-
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; selection commands
-
- (defmethod te-select-all ((te te-blob))
- (#_TESetSelect 0 65535 (te-hTE te)))
-
- (defmethod te-selection ((te te-blob))
- (with-macptrs ((hTE (te-hTE te)))
- (values (href hTE :TERec.selStart) (href hTE :TERec.selEnd))))
-
- (defmethod te-set-selection ((te te-blob) sel-start sel-end)
- (#_TESetSelect sel-start sel-end (te-hTE te))
- (values sel-start sel-end))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;setting text via LISP strings
-
- (defmethod te-string ((te te-blob))
- (with-macptrs ((hTE (te-hTE te)))
- (with-dereferenced-handles ((text-ptr (#_TEGetText hTE)))
- (ccl::%str-from-ptr text-ptr (href hTE :TERec.teLength)))))
-
- (defmethod (setf te-string) (new-string (te te-blob))
- (with-cstrs ((cstr new-string))
- (#_TESetText cstr (length new-string) (te-hTE te)))
- (te-set-selection te 0 0)
- (te-update-scroll-limit te :vertical)
- (te-update-scroll-limit te :horizontal)
- (setf (te-v-scroll-value te) 0)
- (setf (te-h-scroll-value te) 0)
- (te-draw te)
- new-string)
-
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;setting text via TEXT and styl handles
-
- (defmethod te-text-handle ((te te-blob))
- (rlet ((handle-ptr :handle (href (te-hTE te) :TERec.hText)))
- (#_HandToHand handle-ptr)
- (%get-ptr handle-ptr)))
-
- (defmethod te-style-handle ((te te-blob))
- (with-macptrs ((hTE (te-hTE te)))
- (multiple-value-bind (start end) (te-selection te)
- (te-deactivate te)
- (te-select-all te)
- (prog1
- (#_GetStylScrap hTE)
- (te-set-selection te start end)
- (te-activate te)))))
-
- (defmethod te-handles ((te te-blob))
- (values (te-text-handle te) (te-style-handle te)))
-
- (defmethod (setf te-text-handle) (text-handle (te te-blob))
- (with-dereferenced-handles ((text-ptr text-handle))
- (#_TESetText text-ptr (#_GetHandleSize text-handle) (te-hTE te)))
- (te-set-selection te 0 0)
- (te-update te)
- text-handle)
-
- (defmethod (setf te-style-handle) (style-handle (te te-blob))
- (with-macptrs ((hTE (te-hTE te)))
- (#_SetStylScrap 0 (href hTE :TERec.teLength) style-handle nil hTE))
- (te-set-selection te 0 0)
- (te-update te)
- style-handle)
-
- (defmethod set-te-handles ((te te-blob) text-handle style-handle)
- (with-macptrs ((hTE (te-hTE te)))
- (when text-handle
- (with-dereferenced-handles ((text-ptr text-handle))
- (#_TESetText text-ptr (#_GetHandleSize text-handle) hTE)))
- (when style-handle
- (#_SetStylScrap 0 (href hTE :TERec.teLength) style-handle nil hTE))
- (te-set-selection te 0 0)
- (te-update te)
- (values text-handle style-handle)))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; scrolling
-
- (defmethod te-click-loop ((te te-blob))
- (rlet ((pt_p :point))
- (#_GetMouse pt_p)
- (let ((v (%get-signed-word pt_p))
- (h (%get-signed-word pt_p 2)))
- (with-dereferenced-handles ((pTE (te-hTE te)))
- (when (te-v-scroll-p te)
- (if (< v (pref pTE :TERec.viewRect.top))
- (te-line-down te)
- (when (> v (pref pTE :TERec.viewRect.bottom))
- (te-line-up te))))
- (when (te-h-scroll-p te)
- (if (< h (pref pTE :TERec.viewRect.left))
- (te-line-right te)
- (when (> h (pref pTE :TERec.viewRect.right))
- (te-line-left te))))))))
-
- (defmethod te-line-up ((te te-blob))
- (incf (te-v-scroll-value te) 5))
-
- (defmethod te-line-down ((te te-blob))
- (decf (te-v-scroll-value te) 5))
-
- (defmethod te-v-page-size ((te te-blob))
- (with-macptrs ((hTE (te-hTE te)))
- (- (href hTE :TERec.viewRect.bottom) (href hTE :TERec.viewRect.top))))
-
- (defmethod te-page-up ((te te-blob))
- (incf (te-v-scroll-value te) (te-v-page-size te)))
-
- (defmethod te-page-down ((te te-blob))
- (decf (te-v-scroll-value te) (te-v-page-size te)))
-
-
- (defmethod te-line-left ((te te-blob))
- (incf (te-h-scroll-value te) 5))
-
- (defmethod te-line-right ((te te-blob))
- (decf (te-h-scroll-value te) 5))
-
- (defmethod te-h-page-size ((te te-blob))
- (with-macptrs ((hTE (te-hTE te)))
- (- (href hTE :TERec.viewRect.right) (href hTE :TERec.viewRect.left))))
-
- (defmethod te-page-left ((te te-blob))
- (incf (te-h-scroll-value te) (te-h-page-size te)))
-
- (defmethod te-page-right ((te te-blob))
- (decf (te-h-scroll-value te) (te-h-page-size te)))