FunctionPackage: cgToCDocOverviewCGDocRelNotesFAQIndexPermutedIndex
Allegro CL version 10.0
Unrevised from 9.0 to 10.0.
9.0 version

set-event-function

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:

Example 1

This example adds a command to the current editor comtab to make the gesture alt-shift-C scroll the current text line to the top of the editor pane. See *text-edit-comtab*.

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

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

Example 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 it uses a lambda expression rather than a named function. This example will do nothing if the window does not have enough lines of text to turn on the vertical scrollbar, and the window will not scroll upward past the starting scroll position where the first line of text is at the top.

(set-event-function *text-edit-comtab*
                    (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))))

Example 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)))
(foo)

Copyright (c) 1998-2019, Franz Inc. Oakland, CA., USA. All rights reserved.
This page was not revised from the 9.0 page.
Created 2015.5.21.

ToCDocOverviewCGDocRelNotesFAQIndexPermutedIndex
Allegro CL version 10.0
Unrevised from 9.0 to 10.0.
9.0 version