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

Re: view-draw-contents

>I'm trying to produce a formatted table in a window.  I create a
>subclass of VIEW for my table and subclasses of SIMPLE-VIEW for the
>cells of the table.  My tables inherit the subview recording directly
>from VIEW without alteration.  The cells know which row and column they
>are in and the table maps through all the cells and computes and sets
>their sizes and positions.  The cells specialize VIEW-DRAW-CONTENTS
>based on the kind of information displayed in them.  A typical example
>would be
>    (defmethod view-draw-contents ((view numeric-cell))
>      (format view "~d" (cell-value view)))
>My problem is that nothing gets displayed.  
>I have verified that the VIEW-DRAW-CONTENTS methods of the cells do get
>I have verified that the table is a subview of the window and that the
>cells are subviews of it.
>What's going wrong?

Mark Tapia understood your question as being about TABLE-DIALOG-ITEM's.
I understand it as being about avoiding the use of TABLE-DIALOG-ITEM's
by rolling your own.

You may be able to solve your problem by using a TABLE-DIALOG-ITEM.

If you want or need to do it yourself, the problem is that FOCUS-VIEW
does not move the pen. Hence, you must move it yourself before calling
format. The following should be a start, though it will probably need
to be twiddled up or down by a pixel or two, and you may find that
you need to precompute some of the offsets and store them in a slot
somewhere. I have not tested this code other than to ensure that it
compiles in MCL 2.0b1p3.

(defmethod view-draw-contents ((view numeric-cell))
  (let* ((size-v (point-v (view-size view))))
    (multiple-value-bind (ff ms) (view-font-codes view)
      (multiple-value-bind (ascent descent max-width leading)
                           (font-codes-info ff ms)
      (declare (ignore max-width leading))
      (let ((whitespace (max 0 (- size-v ascent descent))))
         3                              ; may want to paremeterize this
         (- size-v (ash whitespace -1)))
        (format view "~d" (cell-contents view)))))))

This code may be too slow, largely because FORMAT does FOCUS-VIEW each
time it's called. The reason that a SIMPLE-VIEW is drawn focused on its
parent is so that less focusing will be necessary. TABLE-DIALOG-ITEM's
take advantage of this.

If you decide to continue to roll your own instead of using a
TABLE-DIALOG-ITEM, and you find the code above too slow, ask
again and I'll say a bit more about how to speed it up (the inspector
does all its own drawing. You've got source. It may or may not help).