set-event-function

Function

Package: common-graphics

Arguments: comtab events function

Adds a command to comtab for handling events, which may be either a single event or a list of events. If more than one event is given, function will be called if they occur sequentially, separated only by null events. function must take one argument, the stream in which the comtab event occurred.

The function argument may be either a function object (that accepts one argument), or a symbol that names a function that accepts one argument, or nil. Note that if a function object is used, then comtab-report will not include the binding in its report, since it does not have a function name to report for the binding.

If function is nil, the effect is to remove any existing binding for the specified events from the comtab.

Each event in the events list is of the same form as a menu-item event-synonym. Refer to event-synonym for some examples of individual events.

Here are several of complete set-event-function examples:

1. This example adds a command to the current editor comtab to make the gesture alt-shift-H scroll the current text line to the top of the editor pane.

(defun scroll-line-to-top (window)
  (setf (first-visible-line window)
    (current-line-number window)))

(set-event-function (text-edit-comtab *system*)
                    (list alt-key shift-key #\H)
                    'scroll-line-to-top)

2. This example adds a command to the current editor comtab to make the gesture alt-shift-comma scroll the current text line to the bottom of the editor pane. Unlike the first example, it uses a closure rather than a separately-defined function.

(set-event-function (text-edit-comtab *system*)
                    (list alt-key shift-key vk-comma)
                    #'(lambda (window)
                        (setf (first-visible-line window)
                          (- (current-line-number window)
                             (floor (interior-height window)
                                    (line-height window))
                             -1))))

3. This more complete example includes creating a comtab and attaching it to a custom window. Since the window is not a text-edit-pane, where comtab-mixin is mixed in already, we must mix this class in ourselves.

We have used the plain "J" key here to draw a filled circle at the mouse, since we are not using a text window that would otherwise enter text. And F8 draws a circle outline at the mouse.

(in-package :cg-user)
(defclass my-window (comtab-mixin frame-window)())
(defun foo ()
  (let* ((my-window (make-window :my-window
                      :device 'my-window
                      :parent (screen *system*)
                      :title "Press the F8 and J Keys"))
         (my-comtab (make-instance 'comtab
                      :name :my-comtab
                      :inherit-from nil)))
    (set-event-function
     my-comtab vk-f8
     #'(lambda (window)
         (draw-circle window (cursor-position window) 12)))
    (set-event-function
     my-comtab #\J
     #'(lambda (window)
         (fill-circle window (cursor-position window) 12)))
    (setf (comtab my-window) my-comtab)
    (select-window my-window)))

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.