CLIM mail archive

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

Re: Variations on a CLIM view



  From: lgm@iexist.att.com
  Date: Tue, 15 Mar 94 13:33:13 CST

  The CLIM documentation doesn't seem to clearly specify the protocol
  between views and gadget panes.  For example, if one has constructed a
  new gadget, how does one create a view that uses that gadget, so that
  "ordinary" programmers can work at the presentation (CLIM:ACCEPT)
  level instead of the gadget-pane (CLIM:MAKE-PANE) level?
  
Take a look at the file custom-gadget.lisp on the clim library.
Such a definition allows you to write accept-values bodies
like this:

  (setf (volume frame)
    (accept 'number
	    :view '(simple-slider-view 
		    :width 300
		    :tick-number 10
		    :min-value 0.0
		    :max-value 5.0)
	    :stream stream
	    :prompt "Volume"
	    :default (volume frame)))

jeff morrill

==================

Here is the relevant passage:

(defclass simple-slider-view (gadget-view) 
	  ((initargs :initarg nil)))

(defmethod initialize-instance :after ((view simple-slider-view)
				       &rest keys &key &allow-other-keys)
  ;; Just stuff all the initargs onto a slot 
  (setf (slot-value view 'initargs) keys))

(define-presentation-method 
    accept-present-default
    ((type t)
     stream
     (view simple-slider-view)
     default default-supplied-p present-p query-identifier &key)
  "Generates a simple-slider gadget for this query."
  (declare (ignore present-p))
  (unless default-supplied-p
    (error "A default must be supplied to a simple-slider-view."))
  (updating-output			
   (stream :unique-id query-identifier :cache-value query-identifier)
   (with-output-as-gadget (stream)
     (apply #'make-pane 
	    'simple-slider
	    :client stream
	    :id query-identifier
	    :presentation-type type
	    :value default
	    :value-changed-callback 
	    #'(lambda (gadget value)
		;; This callback seems absurdly complicated
		(throw-highlighted-presentation
		 (make-instance 'standard-presentation
		   :object `(clim-internals::com-change-query
			     ,(gadget-id gadget)
			     ,value)
		   :type 'command)
		 *input-context*
		 (make-instance 'pointer-button-press-event
		   :sheet (sheet-parent gadget)
		   :x 0 :y 0
		   :button +pointer-left-button+)))
	    ;; Just pass the initargs along unadulterated
	    (slot-value view 'initargs)))))

References:

Main Index | Thread Index