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

specializing CELL-SELECT in sequence dialog items

>In article <C9BnB9.D58@news.claremont.edu> Matthew Haines writes:
>>I'm trying to specialize the cell-select and cell-deselect methods
>>of the sequence-dialog-item.  It seems to me that the following code
>>should print the coordinates when a cell is clicked on.  Unfortunately,
>>it does not.
>>(defclass test-sequence-item (sequence-dialog-item)
>>  ())
>>(defmethod cell-select ((item test-sequence-item) h &optional v)
>>  (call-next-method)
>>  (format t "~S,~S~%" h v))
>>(defvar w)
>>(setq w (make-instance 'window
>>          :view-subviews
>>          (list
>>           (make-instance 'test-sequence-item
>>             :table-sequence '(0 1 2 3 4 5)))))
>This code does, in fact, work in its specialization of cell-select.
>It has no effect when one simply clicks on a cell in the sequence dialog item
>because the view-click-event-handler for table dialog items does not call
>cell-select, but rather deals directly with the Mac List Manager
>through an #_LClick call. (The test-sequence-item above will respond
>as desired, for example, if cell-select is called from the Listener.)

Yes...which is really a pain when one wants to do something every time a
cell is selected.

>To get the coordinates of selected cells reported by a mouse-click in the
>sequence-dialog-item, set the dialog-item action to do that:
>(defclass test-sequence-item (sequence-dialog-item) ()
>  (:default-initargs
>     :dialog-item-action 
>     #'(lambda (item) 
>         (format *standard-output* "~:{~S,~S  ~}~%"
>                 (mapcar #'(lambda (cell) (list (point-h cell) (point-v cell)))
>                         (selected-cells item))))))

This will fail (or rather, not do what the original intended) for
:table-selection :multiple or :disjoint.

The algorithm Bill St. Clair suggested is the only way to really get what
you want, and this is a pain in the ass, since one has to compare before
and after of selected-cells to determine which cells were

Anyway, here's some sample code for Bill's suggestion:

;Untested code follows:

(defmethod my-cell-select ((di test-sequence-item) h &optional v)
  (declare (ignore di h v)))

(defmethod my-cell-deslect ((di test-sequence-item) h &optional v)
  (declare (ignore di h v)))

;Bill suggested using an :around method.  That would work; perhaps better.
(defmethod view-click-event-handler ((di test-sequence-item) where)
  (let ((before (selected-cells di)))
    (let* ((after (selected-cells di))
           (deselecteds (list-difference before after)))
        ;Note that one cannot both select and deselect cells in one
        ;Hence, the pre-computation of deselecteds and the IF below to
        ;save a call to list-difference.
        ;It is possible that this decision should be reversed because
        ;selections may occur more often than multiple deselections.
        ;This would depend on your usage.
        (if deselecteds
          (dolist (deselected deselecteds)
            (my-cell-deselect di deselected))
          (dolist (selected (list-difference after before))
            (my-cell-select di selected))))))

-- "TANSTAAFL" Rich lynch@ils.nwu.edu