Re: capi:menu-items don't know their item or choice?
>>>>> On Mon, 22 Mar 2010 00:43:41 -0400, Joshua TAYLOR said:
>
> I'm getting a rather strange error on LW6 (Windows). I'm defining
> some interfaces with menus whose items are computed dynamically, and
> the menu items behave just fine if they're selected with the mouse,
> but have problems when invoked via an accelerator. E.g.,
>
> (in-package "CL-USER")
>
> (capi:define-interface testing () ()
> (:menus
> (foo "Foo" () :items-function 'foo-menu-items))
> (:menu-bar foo))
>
> (defun foo-menu-items (&rest args)
> (list (make-instance
> 'capi:menu-item
> :text "Bar" :accelerator #\N
> :callback #'(lambda (&rest cargs)
> (capi:display-message "~A ~A" args cargs)))))
>
> (capi:display (make-instance 'testing))
>
> If I display the interface and press Control-Shift-N (before clicking
> on the "Foo" menu), the callback happens without a problem. If I then
> click on the "Foo" menu, or click on it first, and select the "Bar"
> item, the callback happens just fine. But if I press Control-Shift-N
> after having shown the menu by clicking on "Foo", I get an error
> "Callback with both item and choice not capi objects : NIL / NIL". Is
> there some other argument I should have been passing to the
> items-function? I know that there's a setup-callback-argument, but I
> don't see any convenient way to pass it the choice (the menu, I
> assume), and I'm just not clear why the item isn't the menu item (and
> hence a capi object).
>
> The same code works without a hitch on OS X.
>
> Anyone know what's going on here? I'd really like to be able to use
> accelerators in LW in my application…
In general, dynamic menu items can't have accelerators because the accelerator
gesture has to be connected to the item before the parent menu pops up.
Likewise, the end user has to know what the accelerator will do without seeing
the menu.
The only case where it is allowed is when you return the same capi:menu-item
objects each time the :items-function is called. That works because the
accelerator is still connected to that item.
--
Martin Simmons
LispWorks Ltd
http://www.lispworks.com/