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

Another Text edit ?

I seem to be one of the throngs needing the "advanced" text edit
functions not provided directly in MACL. Most everything works ok
except for my accessing of the lineStarts array. My IM Vol 1 says
lineStarts is an ARRAY of INTEGER but inspecting the TERec record in
MACL says it's a single longint. Anyway, the following code fragment
bombs and I'm not sure what to try next. I would appreciate any
comments or fixes concerning what I'm doing wrong or what a better
approach would be. Also, if anyone has a text-edit.lisp they're
willing to share, I'd appreciate getting a copy (and I'll share mine
once this last feature is done). Thanks!

(require :records)
(require :traps)

(defobfun (te-get-line-of-offset *editable-text-dialog-item*) (offset)
  "Returns the line corresponding to the character at <offset> into the text."
  (let* ((me (self))
         (te-handle (ask my-dialog (te-handle me)))
         (line-starts-offset 96)	;96 = byte offset of LineStarts array of word's (or is it longint's?)
         (num-lines (te-num-lines))
    (cond ((>= offset num-lines)	;
           (error "offset (~s) >= num-lines (~s)" offset num-lines))
          (t (with-dereferenced-handles ((te-ptr te-handle)
               (%get-long te-ptr (+ line-starts-offset offset))))))

(defobfun (te-handle *dialog*) (editable-text-dialog-item)
  "Returns a handle to the TextEdit records corresponding to
  (declare (object-variable TE-HANDLE))
  ;; make sure te-handle is legit (s/save/restore prev current? <- mangles te-handle?)
  (set-current-editable-text editable-text-dialog-item)

(defobfun (te-num-lines *editable-text-dialog-item*) ()
  "Returns the number of lines (incl. word wrapping) in this item's text."
  (let* ((me (self))
         (te-handle (ask my-dialog (te-handle me)))
    (rref te-handle :TERec.nLines)


(setf item (oneof *editable-text-dialog-item*
                  :dialog-item-text "This is a test1. And this is a test2. And this is a test3. And this is a test4. And this is a test5."
                  :dialog-item-size #@(100 100)))

(setf dial (oneof *dialog* :dialog-items (list item)))

(ask item (print (te-get-line-of-offset 1)))	;<- breaks!