/*
* tkBind.c --
*
* This file provides procedures that associate Tcl commands
* with X events or sequences of X events.
*
* Copyright (c) 1989-1994 The Regents of the University of California.
* Copyright (c) 1994-1996 Sun Microsystems, Inc.
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* SCCS: @(#) tkBind.c 1.124 96/12/05 14:47:40
*/
#include "tkInt.h"
/*
* File structure:
*
* Structure definitions and static variables.
*
*
* Tcl "bind" command (actually located in tkCmds.c).
* "bind" command implementation.
* "bind" implementation helpers.
*
* Tcl "event" command.
* "event" command implementation.
* "event" implementation helpers.
*
* Package-specific common helpers.
*
* Non-package-specific helpers.
*/
/*
* The following union is used to hold the detail information from an
* XEvent (including Tk's XVirtualEvent extension).
*/
typedef union {
* ensure that all bytes of Detail are initialized
* when this structure is used in a hash key. */
} Detail;
/*
* The structure below represents a binding table. A binding table
* represents a domain in which event bindings may occur. It includes
* a space of objects relative to which events occur (usually windows,
* but not always), a history of recent events in the domain, and
* a set of mappings that associate particular Tcl commands with sequences
* of events in the domain. Multiple binding tables may exist at once,
* either because there are multiple applications open, or because there
* are multiple domains within an application with separate event
* bindings for each (for example, each canvas widget has a separate
* binding table for associating events with the items in the canvas).
*
* Note: it is probably a bad idea to reduce EVENT_BUFFER_SIZE much
* below 30. To see this, consider a triple mouse button click while
* the Shift key is down (and auto-repeating). There may be as many
* as 3 auto-repeat events after each mouse button press or release
* (see the first large comment block within Tk_BindEvent for more on
* this), for a total of 20 events to cover the three button presses
* and two intervening releases. If you reduce EVENT_BUFFER_SIZE too
* much, shift multi-clicks will be lost.
*
*/
typedef struct BindingTable {
* (higher indices are for more recent
* events). */
* button, Tk_Uid, or 0) for each
* entry in eventRing. */
* event. Newer events have higher
* indices. */
* list of patterns that may match that
* event. Keys are PatternTableKey
* structs, values are (PatSeq *). */
* list of patterns associated with
* that object. Keys are ClientData,
* values are (PatSeq *). */
* executed. */
} BindingTable;
/*
* The following structure represents virtual event table. A virtual event
* table provides a way to map from platform-specific physical events such
* as button clicks or key presses to virtual events such as <<Paste>>,
* <<Close>>, or <<ScrollWindow>>.
*
* A virtual event is usually never part of the event stream, but instead is
* synthesized inline by matching low-level events. However, a virtual
* event may be generated by platform-specific code or by Tcl scripts. In
* that case, no lookup of the virtual event will need to be done using
* this table, because the virtual event is actually in the event stream.
*/
typedef struct TkVirtualEventTable {
* a list of patterns that may match that
* event. Keys PatternTableKey structs,
* values are (PatSeq *). */
* array of physical events that can
* trigger it. Keys are the Tk_Uid names
* of the virtual events, values are
* PhysicalsOwned structs. */
/*
* The following structure is used as a key in a patternTable for both
* binding tables and a virtual event tables.
*
* In a binding table, the object field corresponds to the binding tag
* for the widget whose bindings are being accessed.
*
* In a virtual event table, the object field is always NULL. Virtual
* events are a global definiton and are not tied to a particular
* binding tag.
*
* The same key is used for both types of pattern tables so that the
* helper functions that traverse and match patterns will work for both
* binding tables and virtual event tables.
*/
typedef struct PatternTableKey {
* tag of the object (or class of objects)
* relative to which the event occurred.
* For virtual event table, always NULL. */
* button, Tk_Uid, or 0 if nothing
* additional. */
/*
* The following structure defines a pattern, which is matched against X
* events as part of the process of converting X events into Tcl commands.
*/
typedef struct Pattern {
* present (0 means no modifiers are
* required). */
* match event. Normally this is 0,
* meaning no additional information
* must match. For KeyPress and
* KeyRelease events, a keySym may
* be specified to select a
* particular keystroke (0 means any
* keystrokes). For button events,
* specifies a particular button (0
* means any buttons are OK). For virtual
* events, specifies the Tk_Uid of the
* virtual event name (never 0). */
} Pattern;
/*
* The following structure defines a pattern sequence, which consists of one
* or more patterns. In order to trigger, a pattern sequence must match
* the most recent X events (first pattern to most recent event, next
* pattern to next event, and so on). It is used as the hash value in a
* patternTable for both binding tables and virtual event tables.
*
* In a binding table, it is the sequence of physical events that make up
* a binding for an object.
*
* In a virtual event table, it is the sequence of physical events that
* define a virtual event.
*
* The same structure is used for both types of pattern tables so that the
* helper functions that traverse and match patterns will work for both
* binding tables and virtual event tables.
*/
typedef struct PatSeq {
* 1). */
* sequence matches (malloc-ed). */
* definitions. */
* that have the same initial pattern. NULL
* means end of list. */
* initial pattern. This is the head of the
* list of which nextSeqPtr forms a part. */
* virtual event table, identifies the array
* of virtual events that can be triggered by
* this event. */
* pattern sequences for the same object (NULL
* for end of list). Needed to implement
* Tk_DeleteAllBindings. In a virtual event
* table, always NULL. */
* element is declared here but in actuality
* enough space will be allocated for "numPats"
* patterns. To match, pats[0] must match
* event n, pats[1] must match event n-1, etc.
*/
} PatSeq;
/*
* Flag values for PatSeq structures:
*
* PAT_NEARBY 1 means that all of the events matching
* this sequence must occur with nearby X
* and Y mouse coordinates and close in time.
* This is typically used to restrict multiple
* button presses.
*/
/*
* Constants that define how close together two events must be
* in milliseconds or pixels to meet the PAT_NEARBY constraint:
*/
/*
* The following structure keeps track of all the virtual events that are
* associated with a particular physical event. It is pointed to by the
* voPtr field in a PatSeq in the patternTable of a virtual event table.
*/
typedef struct VirtualOwners {
* virtualTable. Enough space will
* actually be allocated for numOwners
* hash entries. */
/*
* The following structure is used in the virtualTable of a virtual event
* table to associate a virtual event with all the physical events that can
* trigger it.
*/
typedef struct PhysicalsOwned {
* patterns. Enough space will actually
* be allocated to hold numOwned. */
/*
* One of the following structures exists for each interpreter,
* associated with the key "tkBind". This structure keeps track
* of the current display and screen in the interpreter, so that
* (the script does things like point tkPriv at a display-specific
* structure).
*/
typedef struct ScreenInfo {
* in this application. */
* in this application. */
} ScreenInfo;
/*
* In X11R4 and earlier versions, XStringToKeysym is ridiculously
* slow. The data structure and hash table below, along with the
* code that uses them, implement a fast mapping from strings to
* keysyms. In X11R5 and later releases XStringToKeysym is plenty
* fast so this stuff isn't needed. The #define REDO_KEYSYM_LOOKUP
* is normally undefined, so that XStringToKeysym gets used. It
* can be set in the Makefile to enable the use of the hash table
* below.
*/
#ifdef REDO_KEYSYM_LOOKUP
typedef struct {
} KeySymInfo;
#ifndef lint
#include "tkNames.h"
#endif
{(char *) NULL, 0}
};
#endif /* REDO_KEYSYM_LOOKUP */
static int initialized = 0;
/*
* A hash table is kept to map from the string names of event
* modifiers to information about those modifiers. The structure
* for storing this information, and the hash table built at
* initialization time, are defined below.
*/
typedef struct {
* definitions. */
} ModInfo;
/*
* Flags for ModInfo structures:
*
* DOUBLE - Non-zero means duplicate this event,
* e.g. for double-clicks.
* TRIPLE - Non-zero means triplicate this event,
* e.g. for triple-clicks.
*/
/*
* The following special modifier mask bits are defined, to indicate
* logical modifiers such as Meta and Alt that may float among the
* actual modifier bits.
*/
{"Control", ControlMask, 0},
{"Shift", ShiftMask, 0},
{"Lock", LockMask, 0},
{"Meta", META_MASK, 0},
{"M", META_MASK, 0},
{"Alt", ALT_MASK, 0},
{"B1", Button1Mask, 0},
{"Button1", Button1Mask, 0},
{"B2", Button2Mask, 0},
{"Button2", Button2Mask, 0},
{"B3", Button3Mask, 0},
{"Button3", Button3Mask, 0},
{"B4", Button4Mask, 0},
{"Button4", Button4Mask, 0},
{"B5", Button5Mask, 0},
{"Button5", Button5Mask, 0},
{"Mod1", Mod1Mask, 0},
{"M1", Mod1Mask, 0},
{"Command", Mod1Mask, 0},
{"Mod2", Mod2Mask, 0},
{"M2", Mod2Mask, 0},
{"Option", Mod2Mask, 0},
{"Mod3", Mod3Mask, 0},
{"M3", Mod3Mask, 0},
{"Mod4", Mod4Mask, 0},
{"M4", Mod4Mask, 0},
{"Mod5", Mod5Mask, 0},
{"M5", Mod5Mask, 0},
{"Double", 0, DOUBLE},
{"Triple", 0, TRIPLE},
{"Any", 0, 0}, /* Ignored: historical relic. */
{NULL, 0, 0}
};
/*
* This module also keeps a hash table mapping from event names
* to information about those events. The structure, an array
* to use to initialize the hash table, and the hash table are
* all defined below.
*/
typedef struct {
* ButtonPress. */
* for this event type. */
} EventInfo;
/*
* Note: some of the masks below are an OR-ed combination of
* several masks. This is necessary because X doesn't report
* up events unless you also ask for down events. Also, X
* doesn't report button state in motion events unless you've
* asked about button events.
*/
{"ButtonRelease", ButtonRelease,
{"Motion", MotionNotify,
{(char *) NULL, 0, 0}
};
/*
* The defines and table below are used to classify events into
* various groups. The reason for this is that logically identical
* fields (e.g. "state") appear at different places in different
* types of events. The classification masks can be used to figure
* out quickly where to extract information from events.
*/
/* Not used */ 0,
/* Not used */ 0,
/* KeyPress */ KEY,
/* KeyRelease */ KEY,
/* ButtonPress */ BUTTON,
/* ButtonRelease */ BUTTON,
/* MotionNotify */ MOTION,
/* EnterNotify */ CROSSING,
/* LeaveNotify */ CROSSING,
/* FocusIn */ FOCUS,
/* FocusOut */ FOCUS,
/* KeymapNotify */ 0,
/* Expose */ EXPOSE,
/* GraphicsExpose */ EXPOSE,
/* NoExpose */ 0,
/* VisibilityNotify */ VISIBILITY,
/* CreateNotify */ CREATE,
/* DestroyNotify */ DESTROY,
/* UnmapNotify */ UNMAP,
/* MapNotify */ MAP,
/* MapRequest */ 0,
/* ReparentNotify */ REPARENT,
/* ConfigureNotify */ CONFIG,
/* ConfigureRequest */ 0,
/* GravityNotify */ GRAVITY,
/* ResizeRequest */ 0,
/* CirculateNotify */ CIRC,
/* CirculateRequest */ 0,
/* PropertyNotify */ PROP,
/* SelectionClear */ 0,
/* SelectionRequest */ 0,
/* SelectionNotify */ 0,
/* ColormapNotify */ COLORMAP,
/* ClientMessage */ 0,
/* MappingNotify */ 0,
/* VirtualEvent */ VIRTUAL,
/* Activate */ ACTIVATE,
/* Deactivate */ ACTIVATE
};
/*
* The following tables are used as a two-way map between X's internal
* numeric values for fields in an XEvent and the strings used in Tcl. The
* tables are used both when constructing an XEvent from user input and
* when providing data from an XEvent to the user.
*/
{NotifyNormal, "NotifyNormal"},
{NotifyGrab, "NotifyGrab"},
{NotifyUngrab, "NotifyUngrab"},
{NotifyWhileGrabbed, "NotifyWhileGrabbed"},
{-1, NULL}
};
{NotifyAncestor, "NotifyAncestor"},
{NotifyVirtual, "NotifyVirtual"},
{NotifyInferior, "NotifyInferior"},
{NotifyNonlinear, "NotifyNonlinear"},
{NotifyNonlinearVirtual,"NotifyNonlinearVirtual"},
{NotifyPointer, "NotifyPointer"},
{NotifyPointerRoot, "NotifyPointerRoot"},
{NotifyDetailNone, "NotifyDetailNone"},
{-1, NULL}
};
{PlaceOnTop, "PlaceOnTop"},
{PlaceOnBottom, "PlaceOnBottom"},
{-1, NULL}
};
{VisibilityUnobscured, "VisibilityUnobscured"},
{VisibilityPartiallyObscured, "VisibilityPartiallyObscured"},
{VisibilityFullyObscured, "VisibilityFullyObscured"},
{-1, NULL}
};
/*
* Prototypes for local procedures defined in this file:
*/
char *dispName, int screenIndex));
char *eventString));
char *eventString));
static void DeleteVirtualEventTable _ANSI_ARGS_((
Tcl_DString *dsPtr));
unsigned long *maskPtr));
Tcl_Interp *interp));
Tcl_DString *dsPtr));
char *virtString));
char **bestCommandPtr));
unsigned long *eventMaskPtr));
/*
*---------------------------------------------------------------------------
*
* TkBindInit --
*
* This procedure is called when an application is created. It
* initializes all the structures used by bindings and virtual
* events.
*
* Results:
* None.
*
* Side effects:
* Memory allocated.
*
*---------------------------------------------------------------------------
*/
void
{
if (sizeof(XEvent) < sizeof(XVirtualEvent)) {
panic("TkBindInit: virtual events can't be supported");
}
}
/*
*---------------------------------------------------------------------------
*
* TkBindFree --
*
* This procedure is called when an application is deleted. It
* deletes all the structures used by bindings and virtual events.
*
* Results:
* None.
*
* Side effects:
* Memory freed.
*
*---------------------------------------------------------------------------
*/
void
{
}
/*
*--------------------------------------------------------------
*
* Tk_CreateBindingTable --
*
* Set up a new domain in which event bindings may be created.
*
* Results:
* The return value is a token for the new table, which must
* be passed to procedures like Tk_CreatBinding.
*
* Side effects:
* Memory is allocated for the new table.
*
*--------------------------------------------------------------
*/
* table: commands are executed in this
* interpreter. */
{
int i;
/*
* If this is the first time a binding table has been created,
* initialize the global data structures.
*/
if (!initialized) {
int dummy;
#ifdef REDO_KEYSYM_LOOKUP
&dummy);
}
#endif /* REDO_KEYSYM_LOOKUP */
initialized = 1;
}
}
}
/*
* Create and initialize a new binding table.
*/
for (i = 0; i < EVENT_BUFFER_SIZE; i++) {
}
sizeof(PatternTableKey)/sizeof(int));
return (Tk_BindingTable) bindPtr;
}
/*
*--------------------------------------------------------------
*
* Tk_DeleteBindingTable --
*
* Destroy a binding table and free up all its memory.
* The caller should not use bindingTable again after
* this procedure returns.
*
* Results:
* None.
*
* Side effects:
* Memory is freed.
*
*--------------------------------------------------------------
*/
void
* destroy. */
{
/*
* Find and delete all of the patterns associated with the binding
* table.
*/
}
}
/*
* Clean up the rest of the information associated with the
* binding table.
*/
}
/*
*--------------------------------------------------------------
*
* Tk_CreateBinding --
*
* Add a binding to a binding table, so that future calls to
* Tk_BindEvent may execute the command in the binding.
*
* Results:
* The return value is 0 if an error occurred while setting
* up the binding. In this case, an error message will be
* left in interp->result. If all went well then the return
* value is a mask of the event types that must be made
* available to Tk_BindEvent in order to properly detect when
* this binding triggers. This value can be used to determine
* what events to select for in a window, for example.
*
* Side effects:
* The new binding may cause future calls to Tk_BindEvent to
* behave differently than they did previously.
*
*--------------------------------------------------------------
*/
unsigned long
* is associated. */
char *eventString; /* String describing event sequence
* that triggers binding. */
char *command; /* Contains Tcl command to execute
* when binding triggers. */
int append; /* 0 means replace any existing
* binding for eventString; 1 means
* append to that binding. */
{
unsigned long eventMask;
return 0;
}
int new;
/*
* This pattern sequence was just created.
* Link the pattern into the list associated with the object.
*/
&new);
if (new) {
} else {
}
}
int length;
char *new;
} else {
}
}
return eventMask;
}
/*
*--------------------------------------------------------------
*
* Tk_DeleteBinding --
*
* Remove an event binding from a binding table.
*
* Results:
* The result is a standard Tcl return value. If an error
* occurs then interp->result will contain an error message.
*
* Side effects:
* The binding given by object and eventString is removed
* from bindingTable.
*
*--------------------------------------------------------------
*/
int
* is associated. */
char *eventString; /* String describing event sequence
* that triggers binding. */
{
unsigned long eventMask;
0, 1, &eventMask);
return TCL_OK;
}
/*
* Unlink the binding from the list for its object, then from the
* list for its pattern.
*/
panic("Tk_DeleteBinding couldn't find object table entry");
}
} else {
panic("Tk_DeleteBinding couldn't find on object list");
}
break;
}
}
}
} else {
}
} else {
panic("Tk_DeleteBinding couldn't find on hash chain");
}
break;
}
}
}
return TCL_OK;
}
/*
*--------------------------------------------------------------
*
* Tk_GetBinding --
*
* Return the command associated with a given event string.
*
* Results:
* The return value is a pointer to the command string
* associated with eventString for object in the domain
* given by bindingTable. If there is no binding for
* eventString, or if eventString is improperly formed,
* then NULL is returned and an error message is left in
* interp->result. The return value is semi-static: it
* will persist until the binding is changed or deleted.
*
* Side effects:
* None.
*
*--------------------------------------------------------------
*/
char *
* binding. */
* is associated. */
char *eventString; /* String describing event sequence
* that triggers binding. */
{
unsigned long eventMask;
0, 1, &eventMask);
return NULL;
}
}
/*
*--------------------------------------------------------------
*
* Tk_GetAllBindings --
*
* Return a list of event strings for all the bindings
* associated with a given object.
*
* Results:
* There is no return value. Interp->result is modified to
* hold a Tcl list with one entry for each binding associated
* with object in bindingTable. Each entry in the list
* contains the event string associated with one binding.
*
* Side effects:
* None.
*
*--------------------------------------------------------------
*/
void
* error. */
* bindings. */
{
return;
}
/*
* For each binding, output information about each of the
* patterns in its sequence.
*/
Tcl_DStringSetLength(&ds, 0);
}
}
/*
*--------------------------------------------------------------
*
* Tk_DeleteAllBindings --
*
* Remove all bindings associated with a given object in a
* given binding table.
*
* Results:
* All bindings associated with object are removed from
* bindingTable.
*
* Side effects:
* None.
*
*--------------------------------------------------------------
*/
void
* bindings. */
{
return;
}
/*
* Be sure to remove each binding from its hash chain in the
* pattern table. If this is the last pattern in the chain,
* then delete the hash entry too.
*/
} else {
}
} else {
panic("Tk_DeleteAllBindings couldn't find on hash chain");
}
break;
}
}
}
}
}
/*
*--------------------------------------------------------------
*
* Tk_BindEvent --
*
* This procedure is invoked to process an X event. The
* event is added to those recorded for the binding table.
* Then each of the objects at *objectPtr is checked in
* order to see if it has a binding that matches the recent
* events. If so, the most specific binding is invoked for
* each object.
*
* Results:
* None.
*
* Side effects:
* Depends on the command associated with the matching
* binding.
*
*--------------------------------------------------------------
*/
void
* bindings. */
* occurred (needed in order to
* locate display information). */
int numObjects; /* Number of objects at *objectPtr. */
* to check for a matching binding. */
{
char *p, *end;
/*
* Ignore the event completely if it is an Enter, Leave, FocusIn,
* or FocusOut event with detail NotifyInferior. The reason for
* ignoring these events is that we don't want transitions between
* a window and its children to visible to bindings on the parent:
* this would cause problems for mega-widgets, since the internal
* structure of a mega-widget isn't supposed to be visible to
* people watching the parent.
*/
return;
}
}
return;
}
}
/*
* Add the new event to the ring of saved events for the
* binding table. Two tricky points:
*
* 1. Combine consecutive MotionNotify events. Do this by putting
* the new event *on top* of the previous event.
* 2. If a modifier key is held down, it auto-repeats to generate
* continuous KeyPress and KeyRelease events. These can flush
* the event ring so that valuable information is lost (such
* as repeated button clicks). To handle this, check for the
* special case of a modifier KeyPress arriving when the previous
* two events are a KeyRelease and KeyPress of the same key.
* If this happens, mark the most recent event (the KeyRelease)
* invalid and put the new event on top of the event before that
* (the KeyPress).
*/
/*
* Don't advance the ring pointer.
*/
int i;
for (i = 0; ; i++) {
if (i >= dispPtr->numModKeyCodes) {
goto advanceRingPointer;
}
break;
}
}
goto advanceRingPointer;
}
i = EVENT_BUFFER_SIZE - 1;
} else {
}
goto advanceRingPointer;
}
} else {
}
}
detail.clientData = 0;
}
}
/*
* Find out if there are any virtual events that correspond to this
* physical event (or sequence of physical events).
*/
}
}
}
}
/*
* Loop over all the objects, finding the binding script for each
* one. Append all of the binding scripts, with %-sequences expanded,
* to "scripts", with null characters separating the scripts for
* each object.
*/
char *command;
/*
* Match the new event against those recorded in the pattern table,
* saving the longest matching pattern. For events with details
* (button and key events), look for a binding for the specific
* key or button. First see if the event matches a physical event
* that the object is interested in, then look for a virtual event.
*/
&command);
}
if (vMatchDetailList != NULL) {
}
/*
* If no match was found, look for a binding for all keys or buttons
* (detail of 0). Again, first match on a virtual event.
*/
&command);
}
if (vMatchNoDetailList != NULL) {
}
}
panic("Tk_BindEvent: missing command");
}
}
}
if (Tcl_DStringLength(&scripts) == 0) {
return;
}
/*
* Now go back through and evaluate the script for each object,
* in order, dealing with "break" and "continue" exceptions
* appropriately.
*
* There are two tricks here:
* 1. Bindings can be invoked from in the middle of Tcl commands,
* where interp->result is significant (for example, a widget
* might be deleted because of an error in creating it, so the
* result contains an error message that is eventually going to
* be returned by the creating command). To preserve the result,
* we save it in a dynamic string.
* 2. The binding's action can potentially delete the binding,
* so bindPtr may not point to anything valid once the action
* completes. Thus we have to save bindPtr->interp in a
* local variable in order to restore the result.
*/
/*
* Save information about the current screen, then invoke a script
* if the screen has changed.
*/
(Tcl_InterpDeleteProc **) NULL);
screenPtr->bindingDepth = 0;
(ClientData) screenPtr);
}
}
p = Tcl_DStringValue(&scripts);
while (p != end) {
if (code == TCL_CONTINUE) {
/*
* Do nothing: just go on to the next script.
*/
break;
} else {
break;
}
}
/*
* Skip over the current script and its terminating null character.
*/
while (*p != 0) {
p++;
}
p++;
}
if ((screenPtr->bindingDepth != 0) &&
/*
* Some other binding script is currently executing, but its
* screen is no longer current. Change the current display
* back again.
*/
}
}
/*
*----------------------------------------------------------------------
*
* MatchPatterns --
*
* Given a list of pattern sequences and a list of recent events,
* return the pattern sequence that best matches the event list,
* if there is one.
*
* This procedure is used in two different ways. In the simplest
* use, "object" is NULL and psPtr is a list of pattern sequences,
* each of which corresponds to a binding. In this case, the
* procedure finds the pattern sequences that match the event list
* and returns the most specify of those, if there is more than one.
*
* In the second case, psPtr is a list of pattern sequences, each
* of which corresponds to a definition for a virtual binding.
* In order for one of these sequences to "match", it must match
* the events (as above) but in addition there must be a binding
* for its associated virtual event on the current object. The
* "object" argument indicates which object the binding must be for.
*
* Results:
* The return value is NULL if bestPtr is NULL and no pattern matches
* the recent events from bindPtr. Otherwise the return value is
* the most specific pattern sequence among bestPtr and all those
* at psPtr that match the event list and object. If a pattern
* sequence other than bestPtr is returned, then *bestCommandPtr
* is filled in with a pointer to the command from the best sequence.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
static PatSeq *
* ring of recent events. */
* previous call to this procedure. NULL
* means no prior best match. */
* correspond to "normal" bindings. If
* non-NULL, the sequences at psPtr correspond
* to virtual bindings; in order to match each
* sequence must correspond to a virtual
* binding for which a binding exists for
* object in bindPtr. */
char **bestCommandPtr; /* Returns the command associated with the
* best match. Not modified unless a result
* other than bestPtr is returned. */
{
/*
* Iterate over all the pattern sequences.
*/
int modMask;
/*
* Iterate over all the patterns in a sequence to be
* sure that they all match.
*/
while (patCount > 0) {
if (ringCount <= 0) {
goto nextSequence;
}
/*
* Most of the event types are considered superfluous
* in that they are ignored if they occur in the middle
* of a pattern sequence and have mismatching types. The
* only ones that cannot be ignored are ButtonPress and
* ButtonRelease events (if the next event in the pattern
* is a KeyPress or KeyRelease) and KeyPress and KeyRelease
* events (if the next pattern event is a ButtonPress or
* ButtonRelease). Here are some tricky cases to consider:
* 1. Double-Button or Double-Key events.
* 2. Double-ButtonRelease or Double-KeyRelease events.
* 3. The arrival of various events like Enter and Leave
* and FocusIn and GraphicsExpose between two button
* presses or key presses.
* 4. Modifier keys like Shift and Control shouldn't
* generate conflicts with button events.
*/
goto nextSequence;
}
int i;
/*
* Ignore key events if they are modifier keys.
*/
for (i = 0; i < dispPtr->numModKeyCodes; i++) {
if (dispPtr->modKeyCodes[i]
/*
* This key is a modifier key, so ignore it.
*/
goto nextEvent;
}
}
goto nextSequence;
}
}
goto nextEvent;
}
goto nextSequence;
}
/*
* Note: it's important for the keysym check to go before
* the modifier check, so we can ignore unwanted modifier
* keys before choking on the modifier check.
*/
/*
* The detail appears not to match. However, if the event
* is a KeyPress for a modifier key then just ignore the
* event. Otherwise event sequences like "aD" never match
* because the shift key goes down between the "a" and the
* "D".
*/
int i;
for (i = 0; i < dispPtr->numModKeyCodes; i++) {
goto nextEvent;
}
}
}
goto nextSequence;
}
if (flags & (KEY_BUTTON_MOTION_VIRTUAL)) {
} else {
state = 0;
}
}
}
goto nextSequence;
}
}
int timeDiff;
goto nextSequence;
}
}
patPtr++;
patCount--;
} else {
eventPtr--;
detailPtr--;
}
ringCount--;
}
int iVirt;
/*
* The sequence matches the physical constraints.
* Is this object interested in any of the virtual events
* that correspond to this sequence?
*/
hPtr);
(char *) &key);
/*
* This tag is interested in this virtual event and its
* corresponding physical event is a good match with the
* virtual event's definition.
*/
panic("MatchPattern: badly constructed virtual event");
}
goto match;
}
}
/*
* The physical event matches a virtual event's definition, but
* the tag isn't interested in it.
*/
goto nextSequence;
}
/*
* This sequence matches. If we've already got another match,
* pick whichever is most specific. Detail is most important,
* then needMods.
*/
int i;
goto nextSequence;
} else {
goto newBest;
}
}
goto nextSequence;
} else {
goto newBest;
}
}
goto nextSequence;
goto newBest;
}
}
}
/*
* Tie goes to current best pattern.
*
* (1) For virtual vs. virtual, the least recently defined
* virtual wins, because virtuals are examined in order of
* definition. This order is _not_ guaranteed in the
* documentation.
*
* (2) For virtual vs. physical, the physical wins because all
* the physicals are examined before the virtuals. This order
* is guaranteed in the documentation.
*
* (3) For physical vs. physical pattern, the most recently
* defined physical wins, because physicals are examined in
* reverse order of definition. This order is guaranteed in
* the documentation.
*/
goto nextSequence;
}
nextSequence: continue;
}
return bestPtr;
}
/*
*--------------------------------------------------------------
*
* ExpandPercents --
*
* Given a command and an event, produce a new command
* by replacing % constructs in the original command
* with information from the X event.
*
* Results:
* The new expanded command is appended to the dynamic string
* given by dsPtr.
*
* Side effects:
* None.
*
*--------------------------------------------------------------
*/
static void
* get input context. */
char *before; /* Command containing percent expressions
* to be replaced. */
* used in % replacements. */
* KeyRelease events). */
* command. */
{
* list element. */
char *string;
} else {
flags = 0;
}
while (1) {
/*
* Find everything up to the next % character and append it
* to the result string.
*/
/* Empty loop body. */
}
}
if (*before == 0) {
break;
}
/*
* There's a percent sequence here. Process it.
*/
number = 0;
string = "??";
switch (before[1]) {
case '#':
goto doNumber;
case 'a':
string = numStorage;
goto doString;
case 'b':
goto doNumber;
case 'c':
}
goto doNumber;
case 'd':
} else {
}
}
goto doString;
case 'f':
goto doNumber;
case 'h':
}
goto doNumber;
case 'k':
goto doNumber;
case 'm':
}
goto doString;
case 'o':
}
goto doNumber;
case 'p':
goto doString;
case 's':
if (flags & (KEY_BUTTON_MOTION_VIRTUAL)) {
} else if (flags & VISIBILITY) {
goto doString;
}
goto doNumber;
case 't':
if (flags & (KEY_BUTTON_MOTION_VIRTUAL)) {
}
goto doNumber;
case 'v':
goto doNumber;
case 'w':
}
goto doNumber;
case 'x':
if (flags & (KEY_BUTTON_MOTION_VIRTUAL)) {
}
goto doNumber;
case 'y':
if (flags & (KEY_BUTTON_MOTION_VIRTUAL)) {
}
goto doNumber;
case 'A':
int numChars;
/*
* If we're using input methods and this is a keypress
* event, invoke XmbTkFindStateString. Otherwise just use
* the older XTkFindStateString.
*/
#ifdef TK_USE_INPUT_METHODS
if ((status != XLookupChars)
&& (status != XLookupBoth)) {
numChars = 0;
}
} else {
(XComposeStatus *) NULL);
}
#else /* TK_USE_INPUT_METHODS */
(XComposeStatus *) NULL);
#endif /* TK_USE_INPUT_METHODS */
string = numStorage;
}
goto doString;
case 'B':
goto doNumber;
case 'E':
goto doNumber;
case 'K':
char *name;
}
}
goto doString;
case 'N':
goto doNumber;
case 'R':
goto doNumber;
case 'S':
string = numStorage;
goto doString;
case 'T':
goto doNumber;
case 'W': {
} else {
string = "??";
}
goto doString;
}
case 'X': {
int x, y;
number -= x;
}
goto doNumber;
}
case 'Y': {
int x, y;
number -= y;
}
goto doNumber;
}
default:
string = numStorage;
goto doString;
}
string = numStorage;
before += 2;
}
}
/*
*----------------------------------------------------------------------
*
* FreeScreenInfo --
*
* This procedure is invoked when an interpreter is deleted in
* order to free the ScreenInfo structure associated with the
* "tkBind" AssocData.
*
* Results:
* None.
*
* Side effects:
* Storage is freed.
*
*----------------------------------------------------------------------
*/
static void
{
ckfree((char *) clientData);
}
/*
*----------------------------------------------------------------------
*
* ChangeScreen --
*
* This procedure is invoked whenever the current screen changes
* in an application. It invokes a Tcl procedure named
* "tkScreenChanged", passing it the screen name as argument.
* tkScreenChanged does things like making the tkPriv variable
* point to an array for the current display.
*
* Results:
* None.
*
* Side effects:
* Depends on what tkScreenChanged does. If an error occurs
* them tkError will be invoked.
*
*----------------------------------------------------------------------
*/
static void
* command. */
char *dispName; /* Name of new display. */
int screenIndex; /* Index of new screen. */
{
int code;
"\n (changing screen in event binding)");
}
}
/*
*----------------------------------------------------------------------
*
* Tk_EventCmd --
*
* This procedure is invoked to process the "event" Tcl command.
* It is used to define and generate events.
*
* Results:
* A standard Tcl result.
*
* Side effects:
* See the user documentation.
*
*----------------------------------------------------------------------
*/
int
* interpreter. */
int argc; /* Number of arguments. */
char **argv; /* Argument strings. */
{
int i;
char *option;
if (argc < 2) {
return TCL_ERROR;
}
if (length == 0) {
goto badopt;
}
if (argc < 4) {
" add virtual sequence ?sequence ...?\"", (char *) NULL);
return TCL_ERROR;
}
for (i = 3; i < argc; i++) {
!= TCL_OK) {
return TCL_ERROR;
}
}
if (argc < 3) {
" delete virtual ?sequence sequence ...?\"",
(char *) NULL);
return TCL_ERROR;
}
if (argc == 3) {
}
for (i = 3; i < argc; i++) {
!= TCL_OK) {
return TCL_ERROR;
}
}
if (argc < 4) {
" generate window event ?options?\"", (char *) NULL);
return TCL_ERROR;
}
if (argc == 2) {
return TCL_OK;
} else if (argc == 3) {
} else {
" info ?virtual?\"", (char *) NULL);
return TCL_ERROR;
}
} else {
"\": should be add, delete, generate, info", (char *) NULL);
return TCL_ERROR;
}
return TCL_OK;
}
/*
*--------------------------------------------------------------
*
* CreateVirtualEventTable --
*
* Set up a new domain in which virtual events may be defined.
*
* Results:
* The return value is a token for the new table, which must
* be passed to procedures like Tk_CreateVirtualEvent().
*
* Side effects:
* The caller must have already called Tk_CreateBindingTable() to
* properly set up memory used by the entire event-handling subsystem.
* Memory is allocated for the new table.
*
*--------------------------------------------------------------
*/
static TkVirtualEventTable *
{
if (!initialized) {
panic("CreateVirtualEvent: Tk_CreateBindingTable never called");
}
sizeof(PatternTableKey)/sizeof(int));
return vetPtr;
}
/*
*--------------------------------------------------------------
*
* DeleteVirtualEventTable --
*
* Destroy a virtual event table and free up all its memory.
* The caller should not use virtualEventTable again after
* this procedure returns.
*
* Results:
* None.
*
* Side effects:
* Memory is freed.
*
*--------------------------------------------------------------
*/
static void
{
}
}
}
}
/*
*----------------------------------------------------------------------
*
* CreateVirtualEvent --
*
* Add a new definition for a virtual event. If the virtual event
* is already defined, the new definition augments those that
* already exist.
*
* Results:
* The return value is TCL_ERROR if an error occured while
* creating the virtual binding. In this case, an error message
* will be left in interp->result. If all went well then the return
* value is TCL_OK.
*
* Side effects:
* The virtual event may cause future calls to Tk_BindEvent to
* behave differently than they did previously.
*
*----------------------------------------------------------------------
*/
static int
char *virtString; /* Name of new virtual event. */
char *eventString; /* String describing physical event that
* triggers virtual event. */
{
int dummy;
unsigned long eventMask;
return TCL_ERROR;
}
/*
*/
1, 0, &eventMask);
return TCL_ERROR;
}
/*
*/
/*
* Make virtual event own the physical event.
*/
} else {
/*
* See if this virtual event is already defined for this physical
* event and just return if it is.
*/
int i;
return TCL_OK;
}
}
}
/*
* Make physical event so it can trigger the virtual event.
*/
} else {
sizeof(VirtualOwners)
}
return TCL_OK;
}
/*
*--------------------------------------------------------------
*
* DeleteVirtualEvent --
*
* Remove the definition of a given virtual event. If the
* event string is NULL, all definitions of the virtual event
* will be removed. Otherwise, just the specified definition
* of the virtual event will be removed.
*
* Results:
* The result is a standard Tcl return value. If an error
* occurs then interp->result will contain an error message.
* It is not an error to attempt to delete a virtual event that
* does not exist or a definition that does not exist.
*
* Side effects:
* The virtual event given by virtString may be removed from the
* virtual event table.
*
*--------------------------------------------------------------
*/
static int
char *virtString; /* String describing event sequence that
* triggers binding. */
char *eventString; /* The event sequence that should be deleted,
* or NULL to delete all event sequences for
* the entire virtual event. */
{
int iPhys;
return TCL_ERROR;
}
return TCL_OK;
}
eventPSPtr = NULL;
if (eventString != NULL) {
unsigned long eventMask;
/*
* Delete only the specific physical event associated with the
* virtual event. If the physical event doesn't already exist, or
* the virtual event doesn't own that physical event, return w/o
* doing anything.
*/
eventString, 0, 0, &eventMask);
if (eventPSPtr == NULL) {
}
}
int iVirt;
/*
* Remove association between this physical event and the given
* virtual event that it triggers.
*/
break;
}
}
panic("DeleteVirtualEvent: couldn't find owner");
}
/*
* Removed last reference to this physical event, so
* remove it from physical->virtual map.
*/
} else {
psPtr->nextSeqPtr);
}
} else {
panic("Tk_DeleteVirtualEvent couldn't find on hash chain");
}
break;
}
}
}
} else {
/*
* This physical event still triggers some other virtual
* event(s). Consolidate the list of virtual owners for
* this physical event so it no longer triggers the
* given virtual event.
*/
}
/*
* Now delete the virtual event's reference to the physical
* event.
*/
/*
* Just deleting this one physical event. Consolidate list
* of owned physical events and return.
*/
return TCL_OK;
}
}
}
/*
* All the physical events for this virtual event were deleted,
* either because there was only one associated physical event or
* because the caller was deleting the entire virtual event. Now
* the virtual event itself should be deleted.
*/
}
return TCL_OK;
}
/*
*---------------------------------------------------------------------------
*
* GetVirtualEvent --
*
* Return the list of physical events that can invoke the
* given virtual event.
*
* Results:
* The return value is TCL_OK and interp->result is filled with the
* string representation of the physical events associated with the
* virtual event; if there are no physical events for the given virtual
* event, interp->result is filled with and empty string. If the
* virtual event string is improperly formed, then TCL_ERROR is
* returned and an error message is left in interp->result.
*
* Side effects:
* None.
*
*---------------------------------------------------------------------------
*/
static int
char *virtString; /* String describing virtual event. */
{
int iPhys;
return TCL_ERROR;
}
return TCL_OK;
}
Tcl_DStringSetLength(&ds, 0);
}
return TCL_OK;
}
/*
*--------------------------------------------------------------
*
* GetAllVirtualEvents --
*
* Return a list that contains the names of all the virtual
* event defined.
*
* Results:
* There is no return value. Interp->result is modified to
* hold a Tcl list with one entry for each virtual event in
* virtualTable.
*
* Side effects:
* None.
*
*--------------------------------------------------------------
*/
static void
{
Tcl_DStringSetLength(&ds, 0);
}
}
/*
*---------------------------------------------------------------------------
*
* HandleEventGenerate --
*
* Helper function for the "event generate" command. Generate and
* process an XEvent, constructed from information parsed from the
* event description string and its optional arguments.
*
* argv[0] contains name of the target window.
* argv[1] contains pattern string for one event (e.g, <Control-v>).
* additional detail in the generated event.
*
* Either virtual or physical events can be generated this way.
* The event description string must contain the specification
* for only one event.
*
* Results:
* None.
*
* Side effects:
* When constructing the event,
* event.xany.serial is filled with the current X serial number.
* event.xany.window is filled with the target window.
* event.xany.display is filled with the target window's display.
* Any other fields in eventPtr which are not specified by the pattern
* string or the optional arguments, are set to 0.
*
* The event may be handled sychronously or asynchronously, depending
* on the value specified by the optional "-when" option. The
* default setting is synchronous.
*
*---------------------------------------------------------------------------
*/
static int
int argc; /* Number of arguments. */
char **argv; /* Argument strings. */
{
char *p;
unsigned long eventMask;
union
{
XEvent E;
} event;
return TCL_ERROR;
}
p = argv[1];
if (count == 0) {
return TCL_ERROR;
}
if (count != 1) {
return TCL_ERROR;
}
if (*p != '\0') {
return TCL_ERROR;
}
if (argc & 1) {
"\" missing", (char *) NULL);
return TCL_ERROR;
}
if (flags & (KEY_BUTTON_MOTION_VIRTUAL)) {
/*
* When mapping from a keysym to a keycode, need information about
* the modifier state that should be used so that when they call
* XKeycodeToKeysym taking into account the xkey.state, they will
* get back the original keysym.
*/
} else {
}
if (state & 1) {
}
if (state & 2) {
}
break;
}
}
}
}
}
}
/*
* Process the remaining arguments to fill in additional fields
* of the event.
*/
synch = 1;
int number;
synch = 1;
synch = 0;
synch = 0;
synch = 0;
} else {
"\": should be now, head, mark, tail", (char *) NULL);
return TCL_ERROR;
}
if (value[0] == '.') {
return TCL_ERROR;
}
return TCL_ERROR;
}
} else {
goto badopt;
}
return TCL_ERROR;
}
} else {
goto badopt;
}
return TCL_ERROR;
}
} else {
goto badopt;
}
return TCL_ERROR;
}
} else {
goto badopt;
}
if (number < 0) {
return TCL_ERROR;
}
} else {
goto badopt;
}
return TCL_ERROR;
}
} else {
goto badopt;
}
return TCL_ERROR;
}
} else {
goto badopt;
}
return TCL_ERROR;
}
} else {
goto badopt;
}
"\"", (char *) NULL);
return TCL_ERROR;
}
/*
* When mapping from a keysym to a keycode, need information about
* the modifier state that should be used so that when they call
* XKeycodeToKeysym taking into account the xkey.state, they will
* get back the original keysym.
*/
if (number == 0) {
"\"", (char *) NULL);
return TCL_ERROR;
}
if (state & 1) {
}
if (state & 2) {
}
break;
}
}
} else {
goto badopt;
}
if (number < 0) {
return TCL_ERROR;
}
} else {
goto badopt;
}
return TCL_ERROR;
}
} else {
goto badopt;
}
if (number < 0) {
return TCL_ERROR;
}
} else {
goto badopt;
}
if (value[0] == '.') {
return TCL_ERROR;
}
return TCL_ERROR;
}
} else {
goto badopt;
}
return TCL_ERROR;
}
} else {
goto badopt;
}
return TCL_ERROR;
}
} else {
goto badopt;
}
return TCL_ERROR;
}
return TCL_ERROR;
}
return TCL_ERROR;
}
if (flags & (KEY_BUTTON_MOTION_VIRTUAL)) {
} else {
}
} else if (flags & VISIBILITY) {
if (number < 0) {
return TCL_ERROR;
}
} else {
goto badopt;
}
if (value[0] == '.') {
return TCL_ERROR;
}
return TCL_ERROR;
}
} else {
goto badopt;
}
return TCL_ERROR;
}
} else {
goto badopt;
}
return TCL_ERROR;
}
} else {
goto badopt;
}
if (value[0] == '.') {
return TCL_ERROR;
}
return TCL_ERROR;
}
} else {
goto badopt;
}
return TCL_ERROR;
}
} else {
goto badopt;
}
return TCL_ERROR;
}
} else {
goto badopt;
}
} else {
return TCL_ERROR;
}
}
if (synch != 0) {
Tk_HandleEvent(&event.E);
} else {
}
return TCL_OK;
}
/*
*-------------------------------------------------------------------------
*
* GetVirtualEventUid --
*
* Determine if the given string is in the proper format for a
* virtual event.
*
* Results:
* The return value is NULL if the virtual event string was
* not in the proper format. In this case, an error message
* will be left in interp->result. Otherwise the return
* value is a Tk_Uid that represents the virtual event.
*
* Side effects:
* None.
*
*-------------------------------------------------------------------------
*/
static Tk_Uid
char *virtString;
{
int length;
"\" is badly formed", (char *) NULL);
return NULL;
}
return uid;
}
/*
*----------------------------------------------------------------------
*
* FindSequence --
*
* Find the entry in the pattern table that corresponds to a
* particular pattern string, and return a pointer to that
* entry.
*
* Results:
* The return value is normally a pointer to the PatSeq
* in patternTable that corresponds to eventString. If an error
* was found while parsing eventString, or if "create" is 0 and
* no pattern sequence previously existed, then NULL is returned
* and interp->result contains a message describing the problem.
* If no pattern sequence previously existed for eventString, then
* a new one is created with a NULL command field. In a successful
* return, *maskPtr is filled in with a mask of the event types
* on which the pattern sequence depends.
*
* Side effects:
* A new pattern sequence may be allocated.
*
*----------------------------------------------------------------------
*/
static PatSeq *
* reporting. */
* which binding is associated.
* For virtual event table, NULL. */
char *eventString; /* String description of pattern to
* match on. See user documentation
* for details. */
int create; /* 0 means don't create the entry if
* it doesn't already exist. Non-zero
* means create. */
int allowVirtual; /* 0 means that virtual events are not
* allowed in the sequence. Non-zero
* otherwise. */
unsigned long *maskPtr; /* *maskPtr is filled in with the event
* types on which this pattern sequence
* depends. */
{
char *p;
unsigned long eventMask;
/*
*-------------------------------------------------------------
* Step 1: parse the pattern string to produce an array
* of Patterns. The array is generated backwards, so
* that the lowest-indexed pattern corresponds to the last
* event that must occur.
*-------------------------------------------------------------
*/
p = eventString;
flags = 0;
eventMask = 0;
virtualFound = 0;
p++;
}
if (*p == '\0') {
break;
}
if (count == 0) {
return NULL;
}
if (eventMask & VirtualEventMask) {
if (allowVirtual == 0) {
"virtual event not allowed in definition of another virtual event";
return NULL;
}
virtualFound = 1;
}
/*
* Replicate events for DOUBLE and TRIPLE.
*/
flags |= PAT_NEARBY;
patPtr--;
numPats++;
patPtr--;
numPats++;
}
}
}
/*
*-------------------------------------------------------------
* Step 2: find the sequence in the binding table if it exists,
* and add a new sequence to the table if it doesn't.
*-------------------------------------------------------------
*/
if (numPats == 0) {
return NULL;
}
return NULL;
}
if (!new) {
sequenceSize) == 0)) {
goto done;
}
}
}
if (!create) {
if (new) {
}
/* Tcl_AppendResult(interp, "no binding exists for \"",
eventString, "\"", (char *) NULL);*/
return NULL;
}
done:
return psPtr;
}
/*
*---------------------------------------------------------------------------
*
* ParseEventDescription --
*
* Fill Pattern buffer with information about event from
* event string.
*
* Results:
* Leaves error message in interp and returns 0 if there was an
* error due to a badly formed event string. Returns 1 if proper
* event was specified, 2 if Double modifier was used in event
* string, or 3 if Triple was used.
*
* Side effects:
* On exit, eventStringPtr points to rest of event string (after the
* closing '>', so that this procedure can be called repeatedly to
* parse all the events in the entire sequence.
*
*---------------------------------------------------------------------------
*/
static int
char **eventStringPtr; /* On input, holds a pointer to start of
* event string. On exit, gets pointer to
* rest of string after parsed event. */
* event string. */
unsigned long *eventMaskPtr;/* Filled with event mask of matched event. */
{
char *p;
unsigned long eventMask;
p = *eventStringPtr;
eventMask = 0;
count = 1;
/*
* Handle simple ASCII characters.
*/
if (*p != '<') {
string[0] = *p;
string[1] = 0;
} else {
"bad ASCII character 0x%x", (unsigned char) *p);
return 0;
}
}
p++;
goto end;
}
/*
* A fancier event description. This can be either a virtual event
* or a physical event.
*
* A virtual event description consists of:
*
* 1. double open angle brackets.
* 2. virtual event name.
* 3. double close angle brackets.
*
* A physical event description consists of:
*
* 1. open angle bracket.
* 2. any number of modifiers, each followed by spaces
* or dashes.
* 3. an optional event name.
* 4. an option button or keysym name. Either this or
* item 3 *must* be present; if both are present
* then they are separated by spaces or dashes.
* 5. a close angle bracket.
*/
p++;
if (*p == '<') {
/*
* This is a virtual event: soak up all the characters up to
* the next '>'.
*/
if (p == field) {
return 0;
}
return 0;
}
*p = '\0';
*p = '>';
p += 2;
goto end;
}
while (1) {
break;
}
count = 2;
} else {
count = 3;
}
}
p++;
}
}
eventFlags = 0;
p++;
}
}
if (*field != '\0') {
if (eventFlags == 0) {
} else if (eventFlags & KEY) {
goto getKeysym;
} else if ((eventFlags & BUTTON) == 0) {
"\" for non-button event", (char *) NULL);
return 0;
}
} else {
return 0;
}
if (eventFlags == 0) {
} else if ((eventFlags & KEY) == 0) {
"\" for non-key event", (char *) NULL);
return 0;
}
}
} else if (eventFlags == 0) {
return 0;
}
p++;
}
if (*p != '>') {
while (*p != '\0') {
p++;
if (*p == '>') {
return 0;
}
}
return 0;
}
p++;
end:
*eventStringPtr = p;
*eventMaskPtr |= eventMask;
return count;
}
/*
*----------------------------------------------------------------------
*
* GetField --
*
* Used to parse pattern descriptions. Copies up to
* size characters from p to copy, stopping at end of
* string, space, "-", ">", or whenever size is
* exceeded.
*
* Results:
* The return value is a pointer to the character just
* after the last one copied (usually "-" or space or
* ">", but could be anything if size was exceeded).
* Also places NULL-terminated string (up to size
* character, including NULL), at copy.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
static char *
char *p; /* Pointer to part of pattern. */
char *copy; /* Place to copy field. */
int size; /* Maximum number of characters to
* copy. */
{
*copy = *p;
p++;
copy++;
size--;
}
*copy = '\0';
return p;
}
/*
*---------------------------------------------------------------------------
*
* GetPatternString --
*
* Produce a string version of the given event, for displaying to
* the user.
*
* Results:
* The string is left in dsPtr.
*
* Side effects:
* It is the caller's responsibility to initialize the DString before
* and to free it after calling this procedure.
*
*---------------------------------------------------------------------------
*/
static void
{
/*
* The order of the patterns in the sequence is backwards from the order
* in which they must be output.
*/
/*
* Check for simple case of an ASCII character.
*/
continue;
}
/*
* Check for virtual event.
*/
continue;
}
/*
* It's a more general event specification. First check
* for "Double" or "Triple", then modifiers, then event type,
* then keysym or button detail.
*/
sizeof(Pattern)) == 0)) {
patsLeft--;
patPtr--;
patsLeft--;
patPtr--;
} else {
}
}
}
}
}
break;
}
}
char *string;
}
} else {
}
}
}
}
/*
*----------------------------------------------------------------------
*
* GetKeySym --
*
* Given an X KeyPress or KeyRelease event, map the
* keycode in the event into a KeySym.
*
* Results:
* The return value is the KeySym corresponding to
* eventPtr, or NoSymbol if no matching Keysym could be
* found.
*
* Side effects:
* In the first call for a given display, keycode-to-
* KeySym maps get loaded.
*
*----------------------------------------------------------------------
*/
static KeySym
* map keycode. */
{
int index;
/*
* Refresh the mapping information if it's stale
*/
if (dispPtr->bindInfoStale) {
}
/*
* Figure out which of the four slots in the keymap vector to
* use for this key. Refer to Xlib documentation for more info
* on how this computation works.
*/
index = 0;
index = 2;
}
index += 1;
}
/*
* Special handling: if the key was shifted because of Lock, but
* lock is only caps lock, not shift lock, and the shifted keysym
* isn't upper-case alphabetic, then switch back to the unshifted
* keysym.
*/
index &= ~1;
index);
}
}
/*
* Another bit of special handling: if this is a shifted key and there
* is no keysym defined, then use the keysym for the unshifted key.
*/
index & ~1);
}
return sym;
}
/*
*--------------------------------------------------------------
*
* InitKeymapInfo --
*
* This procedure is invoked to scan keymap information
* to recompute stuff that's important for binding, such
* as the modifier key (if any) that corresponds to "mode
* switch".
*
* Results:
* None.
*
* Side effects:
* Keymap-related information in dispPtr is updated.
*
*--------------------------------------------------------------
*/
static void
* information. */
{
dispPtr->bindInfoStale = 0;
/*
* Check the keycodes associated with the Lock modifier. If
* any of them is associated with the XK_Shift_Lock modifier,
* then Lock has to be interpreted as Shift Lock, not Caps Lock.
*/
if (*codePtr == 0) {
continue;
}
if (keysym == XK_Shift_Lock) {
break;
}
if (keysym == XK_Caps_Lock) {
break;
}
}
/*
* Look through the keycodes associated with modifiers to see if
* the the "mode switch", "meta", or "alt" keysyms are associated
* with any modifiers. If so, remember their modifier mask bits.
*/
dispPtr->modeModMask = 0;
dispPtr->metaModMask = 0;
dispPtr->altModMask = 0;
if (*codePtr == 0) {
continue;
}
if (keysym == XK_Mode_switch) {
}
}
}
}
/*
* Create an array of the keycodes for all modifier keys.
*/
}
dispPtr->numModKeyCodes = 0;
(KEYCODE_ARRAY_SIZE * sizeof(KeyCode)));
if (*codePtr == 0) {
continue;
}
/*
* Make sure that the keycode isn't already in the array.
*/
for (j = 0; j < dispPtr->numModKeyCodes; j++) {
goto nextModCode;
}
}
/*
* Ran out of space in the array; grow it.
*/
arraySize *= 2;
}
nextModCode: continue;
}
}
/*
*----------------------------------------------------------------------
*
* TkStringToKeysym --
*
* This procedure finds the keysym associated with a given keysym
* name.
*
* Results:
* The return value is the keysym that corresponds to name, or
* NoSymbol if there is no such keysym.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
char *name; /* Name of a keysym. */
{
#ifdef REDO_KEYSYM_LOOKUP
}
return keysym;
}
}
#endif /* REDO_KEYSYM_LOOKUP */
return XStringToKeysym(name);
}
/*
*----------------------------------------------------------------------
*
* TkKeysymToString --
*
* This procedure finds the keysym name associated with a given
* keysym.
*
* Results:
* The return value is a pointer to a static string containing
* the name of the given keysym, or NULL if there is no known name.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
char *
{
#ifdef REDO_KEYSYM_LOOKUP
return (char *) Tcl_GetHashValue(hPtr);
}
#endif /* REDO_KEYSYM_LOOKUP */
return XKeysymToString(keysym);
}
/*
*----------------------------------------------------------------------
*
* TkCopyAndGlobalEval --
*
* This procedure makes a copy of a script then calls Tcl_GlobalEval
* to evaluate it. It's used in situations where the execution of
* a command may cause the original command string to be reallocated.
*
* Results:
* Returns the result of evaluating script, including both a standard
* Tcl completion code and a string in interp->result.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
int
* script. */
char *script; /* Script to evaluate. */
{
int code;
return code;
}