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

bug in text-edit-dialog-item



There is a bug in text-edit-dialog-item which shows
up in the following situation:
If a window has two possible key handlers, one of which
is a text-edit-dialog item(TEDI), one of which isn't.
If you add the TEDI to the window, then remove, and later
add it again, the dialog-te-handle doesn't get updated
properly, so the TEDI will end up editing some handle
in random memory somewhere.  The following new definition
of dialog-te-handle fixes the problem.

(defmethod dialog-te-handle ((w window) &optional select)
  (without-interrupts
   (let* ((hTE (get-*te-handle*))
          (item *te-handle-dialog-item*)
          (current-text (current-key-handler w)))
     (cond ((typep current-text 'text-edit-dialog-item)   ; ignore fred-dialog-items
            (unless (eq current-text item)
              (let ((wptr (wptr w)))         ; generate error if there is none.
                (when item
                  (setf (slot-value item 'sel-start) (rref hTE TERec.selstart)
                        (slot-value item 'sel-end) (rref hTE TERec.selend))
                  (with-focused-view (view-container item)
                    (_TEDeactivate :ptr hTE)))
                (if (null current-text)
                  (progn
                    (rset hTE TERec.hText *null-text-handle*)
                    (rset hTE TERec.inport %temp-port%))
                  (with-focused-view (view-container current-text)
                    (rset hTE terec.inport wptr)
                    (with-slot-values (dialog-item-handle line-height font-ascent) current-text
                      (rset hTE TERec.hText dialog-item-handle)
                      (rset hTE TERec.LineHeight line-height)
                      (rset hTE TERec.FontAscent font-ascent))
                    (with-item-rect (rect current-text)
                      ;could change this to copy-record for clarity ***
                      (rset hTE TERec.destrect.topleft (rref rect :rect.topleft))
                      (rset hTE TERec.destrect.bottomright (rref rect :rect.bottomright))
                      (rset hTE TERec.viewrect.topleft (rref rect :rect.topleft))
                      (rset hTE TERec.viewrect.bottomright (rref rect :rect.bottomright)))
                    (rset hTE TERec.clickloc -1)
                    (multiple-value-bind (ff ms) (view-font-codes current-text)
                      (%hput-long hTE ff 74)
                      (%hput-long hTE ms 78)
                      (with-font-codes ff ms
                        (_TEAutoView :word -1 :ptr hTE)
                        (_TECalText :ptr hTE)
                        (if select
                          (progn
                            (rset hTE TERec.selstart 0)
                            (rset hTE TERec.selend 32000))
                          (progn
                            (rset hTE TERec.selstart (slot-value current-text 'sel-start))
                            (rset hTE TERec.selend  (slot-value current-text 'sel-end))))
                        (if (rref wptr window.hilited)
                          (_TEActivate :ptr hTE))))))
                (setq *te-handle-dialog-item* current-text)))
            hTE)
           ;;; Here is the fix.  If the new current-key-handler isn't a text-edit-dialog-item, then
           ;;; set the *te-handle-dialog-item* to nil, so that the next time around, the *te-handle*
           ;;; will get updated correctly.
           (t (setq *te-handle-dialog-item* nil)))
     )))

Blake Meike
TERC
2067 Mass Ave.
Cambridge MA 02140