[Openmcl-devel] Accessing objc slots query...

Duncan Rose duncan at robotcat.demon.co.uk
Sat Jun 26 05:11:48 PDT 2004


Hi all; I have a Cocoa (bridge?) query....

I have defined a class in the following way:

(defclass lisp-view (ns:ns-view)
   ((trckrect :foreign-type :id :accessor tracking-rect))
   (:metaclass ns:+ns-object))


My query is how I actually use the 'tracking-rect' accessor (assuming 
this is defined properly in the first place, of course - it may well 
not be). I have the following method defined:

(define-objc-method ((:void establish-tracking-rect) lisp-view)
   ;; If the view already has a tracking rectangle (each view should 
have a single tracking
   ;; rectangle, or none) remove it.
   (when (not (eql (send self 'tracking-rectangle) (%null-ptr)))
     (send self :remove-tracking-rect (tracking-rectangle self)))
   ;; Establish a new tracking rectangle for the view's current bounds
   (setf (tracking-rectangle self) (send self :add-tracking-rect (send 
self 'bounds)
					     :owner self
					     :user-data (%null-ptr)
					     :assume-inside #$NO)))

Note that the '(when ...)' originally attempted to invoke the accessor 
the same way the '(setf ...)' does later on in the method - I left both 
in to show the different approaches I've tried. This fails with the 
following error:

 > Error in process Listener(3): Unknown message: "trackingRectangle"
 > While executing: CCL::MAKE-OPTIMIZED-SEND
 > Type :POP to abort.
Type :? for other options.
1 >

When the '(when ...)' line used (tracking-rectangle self) instead of 
(send ...), there isn't an error, but I'm warned:

;   Undefined function SETF::|CLIM-COCOA::TRACKING-RECTANGLE|, in 
CLIM-COCOA::|-[LispView establishTrackingRect]|.
;   Undefined function CLIM-COCOA::TRACKING-RECTANGLE (2 references), 
in CLIM-COCOA::|-[LispView establishTrackingRect]|.

Whilst playing around with this, I also noticed that if I define an 
objc method on lisp-view and try to compile another method in the same 
source file that references this first method the compiler complains, 
but it seems fine to invoke it from a different source file altogether; 
for example:

(define-objc-method ((:void :fill-path path :in-colour colour) 
lisp-view)
   (when (send self 'lock-focus-if-can-draw)
     (send (the ns-color colour) 'set)      ; colour for current 
graphics context
     (send path 'fill)
     (send (send self 'window) 'flush-window)
     (send self 'unlock-focus)))

(define-objc-method ((:void noop) lisp-view)
   (send self fill-path (%null-ptr) :in-colour (%null-ptr)))

in the same (lisp-view) source file leads to:

 > Error in process Listener(3): Unknown message: "fillPath:inColour:"
 > While executing: CCL::MAKE-OPTIMIZED-SEND
 > Type :POP to abort.
Type :? for other options.
1 >

but works fine when invoked from a different source file altogether. 
This may be a clue; but can I define an "instance" method of LISP-VIEW, 
and invoke another "instance" method (also defined by me) from within 
the later definition? For example, I am attempting to override the 
setBounds: and setFrame: methods so the 'establish-tracking-rect' (as 
defined at the top of this mail) method is invoked:

(define-objc-method ((:void :set-bounds (:<NSR>ect bounds)) lisp-view)
   (nslog (format nil "Entered set-bounds with bounds: ~S" bounds))
   (send-super :set-bounds bounds)
   (send self 'establish-tracking-rect))

(define-objc-method ((:void :set-frame (:<NSR>ect frame)) lisp-view)
   (nslog (format nil "Entered set-frame with frame: ~S" frame))
   (send-super :set-frame frame)
   (send self 'establish-tracking-rect))

and get the following:

 > Error in process Listener(3): Unknown message: "establishTrackingRect"
 > While executing: CCL::MAKE-OPTIMIZED-SEND
 > Type :POP to abort.
Type :? for other options.
1 >


I must be missing something here, but I'm not sure what...

Thanks,

-Duncan




More information about the Openmcl-devel mailing list