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

Re: Lockable-text-dialog-item

>I would like to have a special text-dialog-item that behave like an
>editable-t-d-i when unlocked and like a static one when locked.
>Is there any dialog item like that somewhere.

Here's a 10 minute hack which should get you started. Figuring this
out yourself would probably be hard since the KEY-HANDLER-MIXIN class
is so badly documented.


; lockable-text-dialog-item.lisp
; an editable-text-dialog-item that can be locked.
; While locked, it behaves more like a static-text-dialog-item.

(in-package :ccl)

(export '(lockable-text-dialog-item locked-p))

(defclass lockable-text-dialog-item (editable-text-dialog-item)
  ((locked-p :initform nil :initarg :locked :reader locked-p)))

; If we're the current-key-handler when we're locked, select another
; key handler.
(defmethod (setf locked-p) (value (self lockable-text-dialog-item))
  (prog1 (setf (slot-value self 'locked-p) value)
    (let ((w (view-window self)))
      (when (and value (eq self (current-key-handler w)))
        (change-key-handler w)))))

; This makes the dialog item unclickable when locked.
; You may prefer to keep it clickable, but override the default
; behavior and do something else when a click happens.
; (see the commented out code below)
(defmethod point-in-click-region-p ((self lockable-text-dialog-item) where)
  (declare (ignore where))
  (if (locked-p self)

(defmethod key-handler-p ((self lockable-text-dialog-item))
  (if (locked-p self)

(defmethod view-cursor ((self lockable-text-dialog-item) point)
  (declare (ignore point))
  (if (locked-p self)

; Do this instead of the POINT-IN-CLICK-REGION-P method above,
; and subclasses will be able to have LOCKED-CLICK methods.
(defmethod view-click-event-handler ((self lockable-text-dialog-item) where)
  (if (locked-p self)
    (locked-click self where)

(defmethod locked-click ((self lockable-text-dialog-item) where)
  (declare (ignore where))

#| ; Test code.
(defparameter *w* (let ((w (front-window)))
                    (prog1 (make-instance 'window)
                      (window-select w))))

(defparameter *e* (make-instance 'editable-text-dialog-item
                    :view-container *w*
                    :dialog-item-text "Not lockable"))

(defparameter *l* (make-instance 'lockable-text-dialog-item
                    :view-container *w*
                    :dialog-item-text "May be locked"))

; Play around with the lockable item after evaluating each of these
; two expressions.
(setf (locked-p *l*) t)
(setf (locked-p *l*) nil)