[Openmcl-devel] keyDown events

Gary Byers gb at clozure.com
Tue Nov 6 12:56:09 PST 2007


Aside from what Matt said:

The bridge supports an older syntax (define-objc-method, send, slet)
as well as newer stuff (objc:defmethod, #/functionName, etc.)  The
older stuff still mostly works, but there are subtle reasons for
advocating the newer syntax.

There are lower-level concerns as well, but:

- typing:

(#/someMessageName:withArg:

followed by a space in the IDE shows some approximation of the
function's arglist.  It's reasonable to assume that Meta-.
could do something with the function name as well (show you
your own method definitions, try to find an ObjC declaration
in the header files, look it up in AppKido ...)

- #'#/someMessageName:withArg:

is a function; you can do most of the things with that function
that you could do with other functions.  (TRACE doesn't work,
but it should ...)

- it's kind of, if you squint, a little like a generic function,
and it might be desirable to make it more like a generic function
than it currently is.  (That might eventually lead to replacing
OBJC:DEFMETHOD with just DEFMETHOD, but this is all a bit handwavy.)

- it's not as good as it could be, but the fact that we go through
a few lisp function calls on the way to the ObjC runtime when using
#/function means that those functions show up in backtraces.

The low-level concerns have to do with the fact that SEND is a macro
that expands into what's ultimately a foreign function call into
the ObjC runtime, and needs to know (at macroexpand time) what
the message's arguments and return type will be.  Since ObjC methods
can be introduced dynamically, this can Get Weird Fast; SEND exposes
things like structure-return conventions, but can get confused
if some methods defined on a message return structures and others
don't.  This happens in practice: #/size of an NSImage or an NSImageRep
or an NSAttributedString (being drawn somewhere) returns an NSSize;
if the WebKit framework is loaded, #/size of (some Webkit class)
returns a number (don't remember if it's an integer or a float, but
it's not an NSSize.)  At some level, something has to know what
argument and result types are appropriate for the method that'll
be applicable to the receiver, but it seems better to let #'#/size
worry about that and just return a lisp object (of type INTEGER
or FLOAT or NS:NS-SIZE or whatever ...)

Like I said, the old stuff should mostly work and there are no
short-term plans to break/remove it; somewhere down the road,
it would probably be good to remove it, and in practice the
newer stuff is more likely to be worked on/improved.  (Matt
made a change to the #/-dispatch stuff a few weeks ago to
handle CGFloats (which are either 32-bit or 64-bit depending
on the CPU) more transparently; neither of us thought about
doing the same thing in SEND.)



On Tue, 6 Nov 2007, Ron Garret wrote:

> This works:
>
> (defclass scribble-view (ns:ns-view)
>   ()
>   (:metaclass ns:+ns-object))
>
> (ccl::define-objc-method ((:void :mouse-down (:id event)) scribble-view)
>   (ccl::slet* ((event-location (ccl::send event 'location-In-Window))
> 	       (view-location (ccl::send self :convert-Point event-
> location :from-View nil)))
>     (with-focused-view self
>       (#/drawAtPoint:withAttributes: #@"x" view-location +null-ptr+))))
>
> I can stick a scribble-view in a window and click on it to paint
> little x's all over.  But when I try this:
>
> (ccl::define-objc-method ((:void :key-down (:id event)) scribble-view)
>   [do-something...]
>
> it doesn't work.  I activate the window, press some keys, and as far
> as I can tell the key-down method is not invoked at all.  From
> everything that I've read this ought to work.  What am I doing wrong?
>
> rg
>
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel
>
>



More information about the Openmcl-devel mailing list