CLIM mail archive


Style and Design question about presentations

    Date: Thu, 6 Aug 1992 14:06 EDT
    From: Jeff Close <>

    I'm designing an interface for a system that will run parallel to
    another existing system.  My system uses classes defined in the other
    system, but not vice-versa.  The intent is to be able to load either
    in any order and run them separately without them interfering with
    one another.  In System-X I'd like to present objects from System-Y
    differently than they are presented within that system.

    Obviously, I don't want to redefine presentation methods on the
    original System-Y presentations so that they would then be presented
    differently back in System-Y.  Further, if presentation translators
    are defined on those presentations, then I don't want to give the
    original System-Y presentations new behavior.  What's the best way to
    do this?  The essence of this question really begs a pretty basic
    question about presentations and the best way to present the same
    object differently. 

First off, you have to answer the question, what protocol do you intend
to use to communicate between System X and System Y.  This is especially
important since you say that you wish to be able to run them separately.
This has nothing to do with CLIM.

In order to present things differently based on which system you are in,
use the VIEW argument to PRESENT and/or ACCEPT.

For example,

 (define-presentation-type my-integer () :inherit-from 'integer)
 (defclass binary-view (textual-view) ())
 (defvar +binary-view+ (make-instance 'binary-view))
 (defclass octal-view (textual-view) ())
 (defvar +octal-view+ (make-instance 'octal-view))
 (define-presentation-method present (mi (type my-integer) stream (view binary-view) &key) 
   (write mi :base 2 :stream stream))
 (define-presentation-method present (mi (type my-integer) stream (view octal-view) &key) 
   (write mi :base 8 :stream stream))
 (present '10 'my-integer :view +binary-view+) ==> 1010
 (present '10 'my-integer :view +octal-view+) ==> 12

This is the same mechanism used by CLIM 2.0 to hook up presentation
types to gadgets.  For instance, the following method causes booleans to
be displayed as check-boxes inside of a dialog:

 (define-presentation-method accept-present-default 
                             ((type boolean) stream (view toggle-button-view)
                              default default-supplied-p present-p query-identifier
                              &key (prompt t))
   (declare (ignore default-supplied-p present-p))
   (flet ((update-gadget (record gadget button)
            (declare (ignore record gadget))
            (setf (gadget-value button) default)))
     (with-output-as-gadget (stream :cache-value type :update-gadget #'update-gadget)
       (let ((button (make-pane-from-view 'toggle-button view
                       :label (and (stringp prompt) prompt)
                       :value default
                       :client stream :id query-identifier
                           stream query-identifier))))
         (values (outlining () button) button)))))

Follow-Ups: References:

Main Index | Thread Index