Arguments: class-name &rest properties
Defines a set of properties for a class. A property is an attribute of an object that defines a high-level means of accessing the attribute value. Properties are largely used by the inspector for editing objects that have properties, though they are useful programmatically as well mostly because a property defines how to cause any appropriate side effects when the property value is modified. A property for a CLOS object is typically based on a slot of the object, but properties are generally independent of any internal representation and can be defined for any lisp type. Properties are defined with define-property. The various property initargs are described on that page.
As an example, below is a part of the defproperties expression for the
existing control class header-control
. Here the properties
are defined with define-property.
(defproperties header-control (define-property available :type boolean :editor-mode :toggle) (define-property header-width :type positive-integer :reader default-header-width :writer (setf default-header-width) :editor-mode :short-expression) (define-property header-justification :type justification :editor-mode :multiple-choice :reader default-header-justification :writer (setf default-header-justification) :choices cg::justification-values) (define-property button-style :type boolean :editor-mode :toggle :remake t) (define-property on-range-change :type event-handler :editor-mode :function) (define-property on-set-focus :type event-handler :editor-mode :function) )
Reader and writer examples. This includes examples of calls to defcomponent.
;; This example shows the typical case of defining properties ;; for a standard-class, where the accessor methods that ;; are automatically created for the size slot are also ;; used by default as the reader and writer of the associated ;; size property. This technique of sharing ;; the name is recommended wherever it is feasible. (defcomponent foo () ((size :initarg :size :initform nil :accessor size)) (:default-initargs :size :big) (:properties (size :help-string "How big it is." :type (member :big :medium :little nil) :editor-mode :multiple-choice :choices '(:big :medium :little)))) (setq f (make-instance 'foo :size :little)) (inspect f) ;; ------------------------------------------------------ ;; This example defines a property that computes its ;; value each time it is read rather than reading a ;; cached value from a slot. (defcomponent yellow-item-list (single-item-list) () (:default-initargs :background-color yellow) (:properties (how-many :read-only t))) (defmethod how-many ((control yellow-item-list)) (length (range control))) (setq c (make-instance 'yellow-item-list :range '(a b c d))) (inspect c) ;; ----------------------------------------------------------- ;; This example does the same thing for an existing class, using ;; defproperties instead of defcomponent (defproperties single-item-list (define-property how-many :read-only t)) (defmethod how-many ((control single-item-list)) (length (range control))) (setq d (make-instance 'single-item-list :range '(a b c d e))) (inspect d) ;; ----------------------------------------------------------- ;; This example demonstrates defining a property ;; on a non-standard class, using an arbitrary place ;; to hold the property values (since there is ;; no slot for the property). (defproperties integer (define-property roundness)) (defparameter *integer-roundness* (make-hash-table)) (defmethod roundness ((integer integer)) (gethash integer *integer-roundness* :unknown)) (defmethod (setf roundness)(value (integer integer)) (setf (gethash integer *integer-roundness*) value)) (setf (roundness 6) :quite) (inspect 5) (inspect 6)
Common Graphics and IDE documentation is described in About Common Graphics and IDE documentation in cgide.htm.
The documentation is described in introduction.htm and the index is in index.htm.
Copyright (c) 1998-2000, Franz Inc. Berkeley, CA., USA. All rights reserved.
Created 2000.10.5.