1 CAPI Reference Entries

collection

Class

Summary

Acollection collects together a set of items, and provides functionality for accessing and displaying them.

Superclasses

capi-object
callbacks

Subclasses

choice

Slots

items
The items in the collection.

print-function

A function that prints an item.

test-function
A comparison function between two items.

items-count-function

A function which returns the length of items.

items-get-function

A function that returns the nth item.

item-map-function

A function that maps a function over the items.

Accessors

collection-items
collection-print-function
collection-test-function

Readers

collection-items-count-function
collection-items-get-function
collection-items-map-function

Description

The main use ofcollection is as a part of the classchoice, which provides selection capabilities on top of the collection handling, and which is used by list panels, button panels and menus amongst others.

The items in the collection can either be arbitrary Common Lisp objects which can be printed with theprint-function, or can be instances of the CAPI class item in which case they are displayed with the text field of the item. The main difference is that non-CAPI items use the callbacks specified for the collection, whilst the CAPI items will use their callbacks in preference if they are specified.

By default, the items must be a sequence, but this can be changed by specifying anitems-get-function, anitems-count-function, and anitem-map-function. Theitems-get-function should expect the items and an index, and should return the indexed item. Theitems-count-function should expect the items and should return the number of them. Theitem-map-function should expect the items, a function and a flagcollect-results-p, and should call the function on each of the items in return. Ifcollect-results-p is non-nil, then it should also collect the results of these calls together in a list.

Examples

The following code usespush-button-panel, a subclass ofcollection.

(capi:contain (make-instance 'capi:push-button-panel
                             :items '(one two three)))

(capi:contain (make-instance 'capi:push-button-panel :items '(one two three) :print-function 'string-capitalize))

The following example provides a collection with all values from 1 toitems by providing aget-function and acount-function.

(capi:contain (make-instance
               'capi:push-button-panel
               :items 6
               :items-get-function 
                 #'(lambda (items index) (1+ index))
               :items-count-function
                 #'(lambda (items) items)))
Here is an example demonstrating the use of CAPI items in a collections list of items to get more specific callbacks.

(defun specific-callback (data interface)
  (capi:display-message "Specific callback for ~S" 
                        data))
(defun generic-callback (data intereface)
  (capi:display-message "Ordinary callback for ~S"
                        data))

(capi:contain (make-instance 'capi:list-panel :items (list (make-instance 'capi:item :text "Special" :data 1000 :selection-callback 'specific-callback) 2 3 4) :selection-callback 'generic-callback) :min-width 200 :min-height 200)

See Also

item
count-collection-items
get-collection-item
map-collection-items
search-for-item


CAPI Reference Manual, Liquid Common Lisp Version 5.0 - 3 OCT 1997

Generated with Harlequin WebMaker