home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / lisp / mcl / 1202 < prev    next >
Encoding:
Text File  |  1992-08-12  |  3.9 KB  |  106 lines

  1. Path: sparky!uunet!olivea!apple!cambridge.apple.com!@explorer.dgp.toronto.edu:markt@dgp.toronto.edu
  2. From: markt@dgp.toronto.edu ("Mark A. Tapia")
  3. Newsgroups: comp.lang.lisp.mcl
  4. Subject: Re:  using Sequence-dialog-items
  5. Message-ID: <92Aug12.212701edt.144112@explorer.dgp.toronto.edu>
  6. Date: 13 Aug 92 01:27:01 GMT
  7. Sender: info-mcl-request@cambridge.apple.com
  8. Lines: 93
  9. Approved: comp.lang.lisp.mcl@Cambridge.Apple.C0M
  10. Original-To: jbk@world.std.com
  11. Original-Cc: info-mcl@cambridge.apple.com
  12.  
  13. Jeffrey B Kane writes:
  14.    I have a quick question, I'm trying to use a "sequence-dialog-item"
  15.    (as provided by the Interface Tool's palette).  The problem comes
  16.    when I try to figure out which cell the user has clicked in (i.e.
  17.    which cell is selected).  While some of the table-dialog-item's
  18.    methods work for this class (i.e. table-dimensions), other very
  19.    important ones (such as  cell-select, cell-selected-p, and
  20.    cell-deselect) don't.  Although the docs indicate that this
  21.    class is derived from table-dimensions, I can't figure out an
  22.    easy way to query it to find which item is selected (let alone
  23.    responding to a double click)
  24.  
  25. Here is some code that may help you, extracted from a much larger
  26. program:
  27.  
  28.  
  29. (defclass  outline-table (sequence-dialog-item) 
  30.   ((cell-correction :initform #@(5 5)))
  31.   (:default-initargs
  32.     :view-position #@(3 3)
  33.     :view-size #@(400 115)
  34.     :dialog-item-text "pictures"
  35.     :dialog-item-action nil
  36.     :view-nick-name 'picts
  37.     :cell-size #@(100 100)
  38.     :table-dimensions (make-point 6 1)
  39.     :table-hscrollp t
  40.     :table-vscrollp nil
  41.     :selection-type :contiguous
  42.     :sequence-order :horizontal
  43.     :table-sequence nil))
  44.  
  45. (defmethod frame-draw ((view outline-table) cell &key rect selected (offset #@(0 0)))
  46.   (let* ((cell-contents (cell-contents view cell))
  47.          rect-top
  48.          rect-size
  49.          (pen-size #@(2 2))
  50.          (view-active (rref (wptr view) :windowRecord.hilited))
  51.          rect-bottom pen-pat)
  52.     (declare (ignorable cell-contents))
  53.     (rlet ((r :rect))
  54.       (if rect
  55.         (progn
  56.           (copy-record rect :rect r)
  57.           (setq rect-top (rref r :rect.topLeft)
  58.                 rect-bottom (rref r :rect.bottomRight)))
  59.         (progn
  60.           (setq selected (cell-selected-p view cell)
  61.                 rect-top (cell-position view cell)
  62.                 rect-size (cell-size view)
  63.                 rect-bottom (add-points rect-top rect-size))
  64.           (rset r :rect.topLeft rect-top)
  65.           (rset r :rect.bottomRight rect-bottom)))
  66.       (oou::with-pen-state () 
  67.         (#_offsetRect :ptr r :long (subtract-points #@(0 0) offset))
  68.         (#_PenSize :long #@(4 4))
  69.         (#_PenPat *white-pattern*)
  70.         (#_FrameRect r)
  71.         (when (and selected (not view-active))
  72.           ; draw a frame around the cell
  73.           (#_PenSize :long #@(1 1))
  74.           (#_PenPat *black-pattern*)
  75.           (#_FrameRect r))
  76.         (setq pen-pat
  77.               (if selected
  78.                 (if view-active
  79.                   *dark-gray-pattern*
  80.                   *light-gray-pattern*)
  81.                 *white-pattern*))
  82.         
  83.         (#_InsetRect :ptr r :long (if selected #@(1 1)
  84.                                       #@(2 2)))
  85.         
  86.         (#_PenPat pen-pat)
  87.         (setq pen-size (if selected #@(3 3)
  88.                            #@(1 1)))
  89.         (#_PenSize :long pen-size)
  90.         (#_FrameRect r)
  91.         (#_PenNormal)))))
  92.  
  93. (defmethod highlight-table-cell ((self outline-table) cell rect selectedp)
  94.   (with-focused-view (view-container self)
  95.     (frame-draw self cell :rect rect :selected selectedp)))
  96.  
  97. (defparameter win (make-instance 'window))
  98. (defparameter table (make-instance 'outline-table))
  99. (set-table-sequence table '(1 2 3 4 5 6 7 8 9 10))
  100. (add-subviews win table)
  101.  
  102. ; this prints the contents of the selected cell(s)
  103. (let ((selected-cells (selected-cells table)))
  104.   (dolist (cell selected-cells)
  105.     (print-db cell (cell-contents table cell))))
  106.