30.5 Integrating Gadgets and Output Records

In addition to gadget panes, CLIM allows gadgets to be used inside of CLIM stream panes. For instance, an accepting-values whose fields consist of gadgets may appear in an ordinary CLIM stream pane. [annotate]

Note that many of the functions in the output record protocol must correctly manage the case where there are gadgets contained within output records. For example, (setf* output-record-position) may need to notify the host window system that the toolkit object representing the gadget has moved, window-clear needs to deactive any gadgets, and so forth. [annotate]

gadget-output-record   [Class]
          

The instantiable class the represents an output record class that contains a gadget. This is a subclass of output-record. [annotate]

[annotate]

with-output-as-gadget  (stream &rest options) &body body [Macro]
          

Invokes body to create a gadget, and then creates a gadget output record that contains the gadget and install's it into the output history of the output recording stream stream. The returned value of body must be the gadget. [annotate]

The options in options are passed as initargs to the call to invoke-with-new-output-record that is used to create the gadget output record. [annotate]

The stream argument is not evaluated, and must be a symbol that is bound to an output recording stream. If stream is t, *standard-output* is used. body may have zero or more declarations as its first forms. [annotate]

For example, the following could be used to create an output record containing a radio box that itself contains several toggle buttons: [annotate]

(with-output-as-gadget (stream)
  (let* ((radio-box
           (make-pane 'radio-box 
             :client stream :id 'radio-box)))
    (dolist (item sequence)
      (make-pane 'toggle-button 
        :label (princ-to-string (item-name item))
        :value (item-value item)
        :id item :parent radio-box))
    radio-box))

A more complex (and somewhat contrived) example of a push button that calls back into the presentation type system to execute a command might be as follows: [annotate]

(with-output-as-gadget (stream)
  (make-pane 'push-button
    :label "Click here to exit"
    :activate-callback
      #'(lambda (button)
          (declare (ignore button))
          (throw-highlighted-presentation
            (make-instance 'standard-presentation
              :object `(com-exit ,*application-frame*)
              :type 'command)
            *input-context*
            (make-instance 'pointer-button-press-event
              :sheet (sheet-parent button)
              :x 0 :y 0
              :modifiers 0
              :button +pointer-left-button+)))))

[annotate]