From: Matthew_Haine

Subject: Re: Custom event handling of a widget

Date: 1996-12-31 18:20

> I have tried to define a custome single-item-list class as follows, but > to no avail:
> (defclass tm-single-item-list (single-item-list) nil)
> (defmethod event > ((dialog-item tm-single-item-list) > (event (eql mouse-left-double-click)) > (shift t) (data t) (time t)) > (print "Left button double clicked."))
There is probably nothing more frustrating than trying to figure out how to capture events on widgets. The problem is that you have to use different techniques depending on the widget and the event. Here is an example of four different techniques used on the same widget. I think there is a fifth technique, but I can't think of what it might be, and I can't figure out any way to find it. Also note: I think that you simply can't capture some events on some widgets. I think this happens when Windows catches and processes the event. Does anyone know how to capture events (a mouse-left-down event, for example) on a static-text widget? Programming Allegro would be much, much easier if there were a uniform event-handling approach that worked for all widgets. The documentation is a bit scattered. As an exercise, think of a widget and an event. Now go to the online documentation and count how many different screens you have to read to figure out how to capture the event on the widget. Capturing events on widgets is a pretty basic operation, and it should be covered explicitly. I'd like to see a grid, with events on one axis, widget classes on the other, and an explanation of how to capture the event at the intersections. --Matthew ;; ========================== ;; Example follows ;; ========================== (defvar *w*) (setq *W* (open-dialog NIL 'dialog *lisp-main-window* :pop-up-p NIL)) (defclass tm-single-item-list (single-item-list) nil) (defclass tm-single-item-list-pane (pc::single-item-list-pane) ()) (defmethod widget-device ((widget tm-single-item-list) dialog) 'tm-single-item-list-pane) (add-widget (setq *item* (make-dialog-item :widget 'tm-single-item-list :box (make-box 10 10 100 100) :range '(1 2 34 4 5 6 7))) *w*) ;; #1 (setf (dialog-item-mouse-in-fn *item*) 'enter-fn) (defun enter-fn (widget button-state hit-test-code message-time) (format t "tm-single-item-list entered~%")) ;; #2 (defmethod dialog-item-double-click (dialog (widg tm-single-item-list)) (format t "Double clicked on tm-single-item-list~%")) ;; #3 {Capturing event on widget itself} (defmethod event ((dialog-item tm-single-item-list) (event (eql mouse-right-down)) button-state data time) (format t "Mouse right down on tm-single-item-list~%")) ;; #4 {Capturing event on widget's pane} (defmethod event ((pane tm-single-item-list-pane) (event (eql null-event)) button-state data time) (format t "Nothing happened in tm-single-item-list-pane~%"))