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

carethook, and uploaded my code from MCL CD to cambridge archive.



In article <korcuska-1002950912530001@korcuska.ils.nwu.edu> korcuska@ils.nwu.edu (Michael Korcuska) writes:

   From: korcuska@ils.nwu.edu (Michael Korcuska)

   In article <april-0902951453130001@april.ils.nwu.edu>, april@ils.nwu.edu
   (David S. April) wrote:

   > How can I change the shape of the insertion point (not the cursor...) to,
   > say, a horizontal bar instead of a vertical bar?
   > 

   More complicated than you think. In mac lingo the insertion bar is called
   a "caret".  There's a "carethook" field in all textedit records which can
   contain a pointer to a user supplied procedure for drawing the caret.  I
   tried to use this the other day and crashed my mac badly.  And it isn't
   entirely clear to me that you can change the bounding rectangle of the
   caret easily without clobbering adjacent text.

Maybe this can help you get started. It is some code I used to prevent
the cursor from showing. The bottom line is that you have to write the
cursor code in lap. The te-basic class has a slot called
textedit-handle, which contains the terec. The code is taken from
textedit.lisp (a largish lisp interface to textedit), which is on the
MCL 2.0 CD under "alanr's contributions".  I've just uploaded my CD
code to cambridge.apple.com in mcl2/contrib/alanr-mcl2.0cd-contribs.sit.hqx.

About that code: Some of it has been updated/fixed since the CD
release, but I haven't taken the time to submit a new version of my
tools.  If you are interested in actually using some of it, drop me a
note and I'll send you more current versions, if they exist. 

Here's the excerpt showing an alternative carethook.

(def-load-pointers *null-caret-hook* ()
  (setq *null-caret-hook*
        (let ((words (%lap-words '((add ($ 4) sp) (rts)))))
          (let ((r (#_newptr (* 2 (length words)))))
            (loop for w in words 
                  for offset from 0 by 2
                  do (%put-word r w offset))
            r))))

;; always lock the sucker down when using. It *will* move out from
;; under you.

(defmacro with-terec (p &body body)
  `(let ((terec (textedit-handle ,p)))
     (#_hlock terec)
     (unwind-protect (progn ,@body)
       (#_hunlock terec)
       )))

(defmethod cursor-on ((p te-basic))
  (with-terec p  ; (%null-ptr) means use the default carethook.
    (setf (href terec terec.carethook) (%null-ptr))))

(defmethod cursor-off ((p te-basic))
  (with-terec p
    (setf (href terec terec.carethook) *null-caret-hook*)))

-alan