From: markt@dgp.toronto.edu ("Mark A. Tapia")
Newsgroups: comp.lang.lisp.mcl
Subject: Re:  using Sequence-dialog-items
Date: 13 Aug 92 01:27:01 GMT
Original-To: jbk@world.std.com
Original-Cc: info-mcl@cambridge.apple.com

Jeffrey B Kane writes:
   I have a quick question, I'm trying to use a "sequence-dialog-item"
   (as provided by the Interface Tool's palette).  The problem comes
   when I try to figure out which cell the user has clicked in (i.e.
   which cell is selected).  While some of the table-dialog-item's
   methods work for this class (i.e. table-dimensions), other very
   important ones (such as  cell-select, cell-selected-p, and
   cell-deselect) don't.  Although the docs indicate that this
   class is derived from table-dimensions, I can't figure out an
   easy way to query it to find which item is selected (let alone
   responding to a double click)

Here is some code that may help you, extracted from a much larger
program:


(defclass  outline-table (sequence-dialog-item) 
  ((cell-correction :initform #@(5 5)))
  (:default-initargs
    :view-position #@(3 3)
    :view-size #@(400 115)
    :dialog-item-text "pictures"
    :dialog-item-action nil
    :view-nick-name 'picts
    :cell-size #@(100 100)
    :table-dimensions (make-point 6 1)
    :table-hscrollp t
    :table-vscrollp nil
    :selection-type :contiguous
    :sequence-order :horizontal
    :table-sequence nil))

(defmethod frame-draw ((view outline-table) cell &key rect selected (offset #@(0 0)))
  (let* ((cell-contents (cell-contents view cell))
         rect-top
         rect-size
         (pen-size #@(2 2))
         (view-active (rref (wptr view) :windowRecord.hilited))
         rect-bottom pen-pat)
    (declare (ignorable cell-contents))
    (rlet ((r :rect))
      (if rect
        (progn
          (copy-record rect :rect r)
          (setq rect-top (rref r :rect.topLeft)
                rect-bottom (rref r :rect.bottomRight)))
        (progn
          (setq selected (cell-selected-p view cell)
                rect-top (cell-position view cell)
                rect-size (cell-size view)
                rect-bottom (add-points rect-top rect-size))
          (rset r :rect.topLeft rect-top)
          (rset r :rect.bottomRight rect-bottom)))
      (oou::with-pen-state () 
        (#_offsetRect :ptr r :long (subtract-points #@(0 0) offset))
        (#_PenSize :long #@(4 4))
        (#_PenPat *white-pattern*)
        (#_FrameRect r)
        (when (and selected (not view-active))
          ; draw a frame around the cell
          (#_PenSize :long #@(1 1))
          (#_PenPat *black-pattern*)
          (#_FrameRect r))
        (setq pen-pat
              (if selected
                (if view-active
                  *dark-gray-pattern*
                  *light-gray-pattern*)
                *white-pattern*))
        
        (#_InsetRect :ptr r :long (if selected #@(1 1)
                                      #@(2 2)))
        
        (#_PenPat pen-pat)
        (setq pen-size (if selected #@(3 3)
                           #@(1 1)))
        (#_PenSize :long pen-size)
        (#_FrameRect r)
        (#_PenNormal)))))

(defmethod highlight-table-cell ((self outline-table) cell rect selectedp)
  (with-focused-view (view-container self)
    (frame-draw self cell :rect rect :selected selectedp)))

(defparameter win (make-instance 'window))
(defparameter table (make-instance 'outline-table))
(set-table-sequence table '(1 2 3 4 5 6 7 8 9 10))
(add-subviews win table)

; this prints the contents of the selected cell(s)
(let ((selected-cells (selected-cells table)))
  (dolist (cell selected-cells)
    (print-db cell (cell-contents table cell))))