stk/Tk/generic/tkBind.c

4744 lines
134 KiB
C
Raw Permalink Normal View History

1996-09-27 06:29:02 -04:00
/*
* 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.
1998-04-10 06:59:06 -04:00
* Copyright (c) 1994-1996 Sun Microsystems, Inc.
1996-09-27 06:29:02 -04:00
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
1998-04-10 06:59:06 -04:00
* SCCS: @(#) tkBind.c 1.133 97/07/01 17:59:53
1996-09-27 06:29:02 -04:00
*/
#include "tkPort.h"
#include "tkInt.h"
1999-09-05 07:16:41 -04:00
#ifdef BGLk_CODE
# define STk_add_callback SCM_add_callback
#endif
1998-04-10 06:59:06 -04:00
/*
* File structure:
*
* Structure definitions and static variables.
*
* Init/Free this package.
*
* 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 {
KeySym keySym; /* KeySym that corresponds to xkey.keycode. */
int button; /* Button that was pressed (xbutton.button). */
Tk_Uid name; /* Tk_Uid of virtual event. */
ClientData clientData; /* Used when type of Detail is unknown, and to
* ensure that all bytes of Detail are initialized
* when this structure is used in a hash key. */
} Detail;
1996-09-27 06:29:02 -04:00
/*
* 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.
*
*/
#define EVENT_BUFFER_SIZE 30
typedef struct BindingTable {
XEvent eventRing[EVENT_BUFFER_SIZE];/* Circular queue of recent events
* (higher indices are for more recent
* events). */
1998-04-10 06:59:06 -04:00
Detail detailRing[EVENT_BUFFER_SIZE];/* "Detail" information (keySym,
* button, Tk_Uid, or 0) for each
* entry in eventRing. */
1996-09-27 06:29:02 -04:00
int curEvent; /* Index in eventRing of most recent
* event. Newer events have higher
* indices. */
1998-04-10 06:59:06 -04:00
Tcl_HashTable patternTable; /* Used to map from an event to a
* list of patterns that may match that
1996-09-27 06:29:02 -04:00
* event. Keys are PatternTableKey
* structs, values are (PatSeq *). */
1998-04-10 06:59:06 -04:00
Tcl_HashTable objectTable; /* Used to map from an object to a
* list of patterns associated with
* that object. Keys are ClientData,
1996-09-27 06:29:02 -04:00
* values are (PatSeq *). */
Tcl_Interp *interp; /* Interpreter in which commands are
* executed. */
} BindingTable;
/*
1998-04-10 06:59:06 -04:00
* 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.
1996-09-27 06:29:02 -04:00
*/
1998-04-10 06:59:06 -04:00
typedef struct VirtualEventTable {
Tcl_HashTable patternTable; /* Used to map from a physical event to
* a list of patterns that may match that
* event. Keys are PatternTableKey
* structs, values are (PatSeq *). */
Tcl_HashTable nameTable; /* Used to map a virtual event name to
* the array of physical events that can
* trigger it. Keys are the Tk_Uid names
* of the virtual events, values are
* PhysicalsOwned structs. */
} VirtualEventTable;
/*
* 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.
*/
1996-09-27 06:29:02 -04:00
typedef struct PatternTableKey {
1998-04-10 06:59:06 -04:00
ClientData object; /* For binding table, identifies the binding
* tag of the object (or class of objects)
* relative to which the event occurred.
* For virtual event table, always NULL. */
1996-09-27 06:29:02 -04:00
int type; /* Type of event (from X). */
1998-04-10 06:59:06 -04:00
Detail detail; /* Additional information, such as keysym,
* button, Tk_Uid, or 0 if nothing
* additional. */
1996-09-27 06:29:02 -04:00
} PatternTableKey;
/*
1998-04-10 06:59:06 -04:00
* The following structure defines a pattern, which is matched against X
* events as part of the process of converting X events into Tcl commands.
1996-09-27 06:29:02 -04:00
*/
typedef struct Pattern {
int eventType; /* Type of X event, e.g. ButtonPress. */
int needMods; /* Mask of modifiers that must be
* present (0 means no modifiers are
* required). */
1998-04-10 06:59:06 -04:00
Detail detail; /* Additional information that must
1996-09-27 06:29:02 -04:00
* 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
1998-04-10 06:59:06 -04:00
* means any buttons are OK). For virtual
* events, specifies the Tk_Uid of the
* virtual event name (never 0). */
1996-09-27 06:29:02 -04:00
} Pattern;
/*
1998-04-10 06:59:06 -04:00
* 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.
1996-09-27 06:29:02 -04:00
*/
typedef struct PatSeq {
1998-04-10 06:59:06 -04:00
int numPats; /* Number of patterns in sequence (usually
* 1). */
TkBindEvalProc *eventProc; /* The procedure that will be invoked on
* the clientData when this pattern sequence
* matches. */
TkBindFreeProc *freeProc; /* The procedure that will be invoked to
* release the clientData when this pattern
* sequence is freed. */
ClientData clientData; /* Arbitray data passed to eventProc and
* freeProc when sequence matches. */
int flags; /* Miscellaneous flag values; see below for
* definitions. */
int refCount; /* Number of times that this binding is in
* the midst of executing. If greater than 1,
* then a recursive invocation is happening.
* Only when this is zero can the binding
* actually be freed. */
struct PatSeq *nextSeqPtr; /* Next in list of all pattern sequences
* that have the same initial pattern. NULL
* means end of list. */
Tcl_HashEntry *hPtr; /* Pointer to hash table entry for the
* initial pattern. This is the head of the
* list of which nextSeqPtr forms a part. */
struct VirtualOwners *voPtr;/* In a binding table, always NULL. In a
* virtual event table, identifies the array
* of virtual events that can be triggered by
* this event. */
struct PatSeq *nextObjPtr; /* In a binding table, next in list of all
* pattern sequences for the same object (NULL
* for end of list). Needed to implement
* Tk_DeleteAllBindings. In a virtual event
* table, always NULL. */
Pattern pats[1]; /* Array of "numPats" patterns. Only one
* 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.
*/
1996-09-27 06:29:02 -04:00
} 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.
1998-04-10 06:59:06 -04:00
* MARKED_DELETED 1 means that this binding has been marked as deleted
* and removed from the binding table, but its memory
* could not be released because it was already queued for
* execution. When the binding is actually about to be
* executed, this flag will be checked and the binding
* skipped if set.
1996-09-27 06:29:02 -04:00
*/
1998-04-10 06:59:06 -04:00
#define PAT_NEARBY 0x1
#define MARKED_DELETED 0x2
1996-09-27 06:29:02 -04:00
/*
* Constants that define how close together two events must be
* in milliseconds or pixels to meet the PAT_NEARBY constraint:
*/
#define NEARBY_PIXELS 5
#define NEARBY_MS 500
1998-04-10 06:59:06 -04:00
/*
* 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 {
int numOwners; /* Number of virtual events to trigger. */
Tcl_HashEntry *owners[1]; /* Array of pointers to entries in
* nameTable. Enough space will
* actually be allocated for numOwners
* hash entries. */
} VirtualOwners;
/*
* The following structure is used in the nameTable of a virtual event
* table to associate a virtual event with all the physical events that can
* trigger it.
*/
typedef struct PhysicalsOwned {
int numOwned; /* Number of physical events owned. */
PatSeq *patSeqs[1]; /* Array of pointers to physical event
* patterns. Enough space will actually
* be allocated to hold numOwned. */
} PhysicalsOwned;
1996-09-27 06:29:02 -04:00
/*
1998-04-10 06:59:06 -04:00
* One of the following structures exists for each interpreter. This
* structure keeps track of the current display and screen in the
* interpreter, so that a script can be invoked whenever the display/screen
* changes (the script does things like point tkPriv at a display-specific
1996-09-27 06:29:02 -04:00
* structure).
*/
1998-04-10 06:59:06 -04:00
typedef struct {
1996-09-27 06:29:02 -04:00
TkDisplay *curDispPtr; /* Display for last binding command invoked
* in this application. */
int curScreenIndex; /* Index of screen for last binding command. */
int bindingDepth; /* Number of active instances of Tk_BindEvent
* in this application. */
} ScreenInfo;
1998-04-10 06:59:06 -04:00
/*
* The following structure is used to keep track of all the C bindings that
* are awaiting invocation and whether the window they refer to has been
* destroyed. If the window is destroyed, then all pending callbacks for
* that window will be cancelled. The Tcl bindings will still all be
* invoked, however.
*/
typedef struct PendingBinding {
struct PendingBinding *nextPtr;
/* Next in chain of pending bindings, in
* case a recursive binding evaluation is in
* progress. */
Tk_Window tkwin; /* The window that the following bindings
* depend upon. */
int deleted; /* Set to non-zero by window cleanup code
* if tkwin is deleted. */
PatSeq *matchArray[5]; /* Array of pending C bindings. The actual
* size of this depends on how many C bindings
* matched the event passed to Tk_BindEvent.
* THIS FIELD MUST BE THE LAST IN THE
* STRUCTURE. */
} PendingBinding;
/*
* The following structure keeps track of all the information local to
* the binding package on a per interpreter basis.
*/
typedef struct BindInfo {
VirtualEventTable virtualEventTable;
/* The virtual events that exist in this
* interpreter. */
ScreenInfo screenInfo; /* Keeps track of the current display and
* screen, so it can be restored after
* a binding has executed. */
PendingBinding *pendingList;/* The list of pending C bindings, kept in
* case a C or Tcl binding causes the target
* window to be deleted. */
} BindInfo;
1996-09-27 06:29:02 -04:00
/*
* 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 {
char *name; /* Name of keysym. */
KeySym value; /* Numeric identifier for keysym. */
} KeySymInfo;
static KeySymInfo keyArray[] = {
#ifndef lint
#include "ks_names.h"
#endif
{(char *) NULL, 0}
};
static Tcl_HashTable keySymTable; /* keyArray hashed by keysym value. */
static Tcl_HashTable nameTable; /* keyArray hashed by keysym name. */
#endif /* REDO_KEYSYM_LOOKUP */
1998-04-10 06:59:06 -04:00
/*
* Set to non-zero when the package-wide static variables have been
* initialized.
*/
1996-09-27 06:29:02 -04:00
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 {
char *name; /* Name of modifier. */
int mask; /* Button/modifier mask value, * such as Button1Mask. */
int flags; /* Various flags; see below for
* 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.
*/
#define DOUBLE 1
#define TRIPLE 2
/*
* 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.
*/
#define META_MASK (AnyModifier<<1)
#define ALT_MASK (AnyModifier<<2)
static ModInfo modArray[] = {
{"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}
};
static Tcl_HashTable modTable;
/*
* 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 {
char *name; /* Name of event. */
int type; /* Event type for X, such as
* ButtonPress. */
int eventMask; /* Mask bits (for XSelectInput)
* 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.
*/
static EventInfo eventArray[] = {
1998-04-10 06:59:06 -04:00
{"Key", KeyPress, KeyPressMask},
{"KeyPress", KeyPress, KeyPressMask},
{"KeyRelease", KeyRelease, KeyPressMask|KeyReleaseMask},
1996-09-27 06:29:02 -04:00
{"Button", ButtonPress, ButtonPressMask},
{"ButtonPress", ButtonPress, ButtonPressMask},
{"ButtonRelease", ButtonRelease,
ButtonPressMask|ButtonReleaseMask},
1998-04-10 06:59:06 -04:00
{"Motion", MotionNotify,
ButtonPressMask|PointerMotionMask},
1996-09-27 06:29:02 -04:00
{"Enter", EnterNotify, EnterWindowMask},
{"Leave", LeaveNotify, LeaveWindowMask},
{"FocusIn", FocusIn, FocusChangeMask},
{"FocusOut", FocusOut, FocusChangeMask},
1998-04-10 06:59:06 -04:00
{"Expose", Expose, ExposureMask},
{"Visibility", VisibilityNotify, VisibilityChangeMask},
1996-09-27 06:29:02 -04:00
{"Destroy", DestroyNotify, StructureNotifyMask},
1998-04-10 06:59:06 -04:00
{"Unmap", UnmapNotify, StructureNotifyMask},
1996-09-27 06:29:02 -04:00
{"Map", MapNotify, StructureNotifyMask},
{"Reparent", ReparentNotify, StructureNotifyMask},
1998-04-10 06:59:06 -04:00
{"Configure", ConfigureNotify, StructureNotifyMask},
{"Gravity", GravityNotify, StructureNotifyMask},
{"Circulate", CirculateNotify, StructureNotifyMask},
{"Property", PropertyNotify, PropertyChangeMask},
{"Colormap", ColormapNotify, ColormapChangeMask},
1996-09-27 06:29:02 -04:00
{"Activate", ActivateNotify, ActivateMask},
{"Deactivate", DeactivateNotify, ActivateMask},
{(char *) NULL, 0, 0}
};
static Tcl_HashTable eventTable;
/*
* 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.
*/
1998-04-10 06:59:06 -04:00
#define KEY 0x1
#define BUTTON 0x2
#define MOTION 0x4
#define CROSSING 0x8
#define FOCUS 0x10
#define EXPOSE 0x20
#define VISIBILITY 0x40
#define CREATE 0x80
#define DESTROY 0x100
#define UNMAP 0x200
#define MAP 0x400
#define REPARENT 0x800
#define CONFIG 0x1000
#define GRAVITY 0x2000
#define CIRC 0x4000
#define PROP 0x8000
1996-09-27 06:29:02 -04:00
#define COLORMAP 0x10000
1998-04-10 06:59:06 -04:00
#define VIRTUAL 0x20000
1996-09-27 06:29:02 -04:00
#define ACTIVATE 0x40000
1998-04-10 06:59:06 -04:00
#define KEY_BUTTON_MOTION_VIRTUAL (KEY|BUTTON|MOTION|VIRTUAL)
1996-09-27 06:29:02 -04:00
static int flagArray[TK_LASTEVENT] = {
/* Not used */ 0,
/* Not used */ 0,
1998-04-10 06:59:06 -04:00
/* KeyPress */ KEY,
/* KeyRelease */ KEY,
/* ButtonPress */ BUTTON,
/* ButtonRelease */ BUTTON,
/* MotionNotify */ MOTION,
1996-09-27 06:29:02 -04:00
/* EnterNotify */ CROSSING,
/* LeaveNotify */ CROSSING,
/* FocusIn */ FOCUS,
/* FocusOut */ FOCUS,
/* KeymapNotify */ 0,
/* Expose */ EXPOSE,
/* GraphicsExpose */ EXPOSE,
/* NoExpose */ 0,
/* VisibilityNotify */ VISIBILITY,
/* CreateNotify */ CREATE,
1998-04-10 06:59:06 -04:00
/* DestroyNotify */ DESTROY,
/* UnmapNotify */ UNMAP,
1996-09-27 06:29:02 -04:00
/* MapNotify */ MAP,
/* MapRequest */ 0,
/* ReparentNotify */ REPARENT,
/* ConfigureNotify */ CONFIG,
1998-04-10 06:59:06 -04:00
/* ConfigureRequest */ 0,
/* GravityNotify */ GRAVITY,
/* ResizeRequest */ 0,
/* CirculateNotify */ CIRC,
1996-09-27 06:29:02 -04:00
/* CirculateRequest */ 0,
/* PropertyNotify */ PROP,
1998-04-10 06:59:06 -04:00
/* SelectionClear */ 0,
/* SelectionRequest */ 0,
/* SelectionNotify */ 0,
1996-09-27 06:29:02 -04:00
/* ColormapNotify */ COLORMAP,
/* ClientMessage */ 0,
1998-04-10 06:59:06 -04:00
/* MappingNotify */ 0,
/* VirtualEvent */ VIRTUAL,
1996-09-27 06:29:02 -04:00
/* Activate */ ACTIVATE,
/* Deactivate */ ACTIVATE
};
1998-04-10 06:59:06 -04:00
/*
* 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.
*/
static TkStateMap notifyMode[] = {
{NotifyNormal, "NotifyNormal"},
{NotifyGrab, "NotifyGrab"},
{NotifyUngrab, "NotifyUngrab"},
{NotifyWhileGrabbed, "NotifyWhileGrabbed"},
{-1, NULL}
};
static TkStateMap notifyDetail[] = {
{NotifyAncestor, "NotifyAncestor"},
{NotifyVirtual, "NotifyVirtual"},
{NotifyInferior, "NotifyInferior"},
{NotifyNonlinear, "NotifyNonlinear"},
{NotifyNonlinearVirtual, "NotifyNonlinearVirtual"},
{NotifyPointer, "NotifyPointer"},
{NotifyPointerRoot, "NotifyPointerRoot"},
{NotifyDetailNone, "NotifyDetailNone"},
{-1, NULL}
};
static TkStateMap circPlace[] = {
{PlaceOnTop, "PlaceOnTop"},
{PlaceOnBottom, "PlaceOnBottom"},
{-1, NULL}
};
static TkStateMap visNotify[] = {
{VisibilityUnobscured, "VisibilityUnobscured"},
{VisibilityPartiallyObscured, "VisibilityPartiallyObscured"},
{VisibilityFullyObscured, "VisibilityFullyObscured"},
{-1, NULL}
};
1996-09-27 06:29:02 -04:00
/*
* Prototypes for local procedures defined in this file:
*/
static void ChangeScreen _ANSI_ARGS_((Tcl_Interp *interp,
char *dispName, int screenIndex));
1998-04-10 06:59:06 -04:00
static int CreateVirtualEvent _ANSI_ARGS_((Tcl_Interp *interp,
VirtualEventTable *vetPtr, char *virtString,
char *eventString));
static int DeleteVirtualEvent _ANSI_ARGS_((Tcl_Interp *interp,
VirtualEventTable *vetPtr, char *virtString,
char *eventString));
static void DeleteVirtualEventTable _ANSI_ARGS_((
VirtualEventTable *vetPtr));
1996-09-27 06:29:02 -04:00
static void ExpandPercents _ANSI_ARGS_((TkWindow *winPtr,
char *before, XEvent *eventPtr, KeySym keySym,
Tcl_DString *dsPtr));
1998-04-10 06:59:06 -04:00
static void FreeTclBinding _ANSI_ARGS_((ClientData clientData));
1996-09-27 06:29:02 -04:00
static PatSeq * FindSequence _ANSI_ARGS_((Tcl_Interp *interp,
1998-04-10 06:59:06 -04:00
Tcl_HashTable *patternTablePtr, ClientData object,
char *eventString, int create, int allowVirtual,
1996-09-27 06:29:02 -04:00
unsigned long *maskPtr));
1998-04-10 06:59:06 -04:00
static void GetAllVirtualEvents _ANSI_ARGS_((Tcl_Interp *interp,
VirtualEventTable *vetPtr));
1996-09-27 06:29:02 -04:00
static char * GetField _ANSI_ARGS_((char *p, char *copy, int size));
static KeySym GetKeySym _ANSI_ARGS_((TkDisplay *dispPtr,
XEvent *eventPtr));
1998-04-10 06:59:06 -04:00
static void GetPatternString _ANSI_ARGS_((PatSeq *psPtr,
Tcl_DString *dsPtr));
static int GetVirtualEvent _ANSI_ARGS_((Tcl_Interp *interp,
VirtualEventTable *vetPtr, char *virtString));
static Tk_Uid GetVirtualEventUid _ANSI_ARGS_((Tcl_Interp *interp,
char *virtString));
static int HandleEventGenerate _ANSI_ARGS_((Tcl_Interp *interp,
Tk_Window main, int argc, char **argv));
1996-09-27 06:29:02 -04:00
static void InitKeymapInfo _ANSI_ARGS_((TkDisplay *dispPtr));
1998-04-10 06:59:06 -04:00
static void InitVirtualEventTable _ANSI_ARGS_((
VirtualEventTable *vetPtr));
1996-09-27 06:29:02 -04:00
static PatSeq * MatchPatterns _ANSI_ARGS_((TkDisplay *dispPtr,
1998-04-10 06:59:06 -04:00
BindingTable *bindPtr, PatSeq *psPtr,
PatSeq *bestPtr, ClientData *objectPtr,
PatSeq **sourcePtrPtr));
static int ParseEventDescription _ANSI_ARGS_((Tcl_Interp *interp,
char **eventStringPtr, Pattern *patPtr,
unsigned long *eventMaskPtr));
/*
* The following define is used as a short circuit for the callback
* procedure to evaluate a TclBinding. The actual evaluation of the
* binding is handled inline, because special things have to be done
* with a Tcl binding before evaluation time.
*/
#define EvalTclBinding ((TkBindEvalProc *) 1)
1996-09-27 06:29:02 -04:00
/*
1998-04-10 06:59:06 -04:00
*---------------------------------------------------------------------------
1996-09-27 06:29:02 -04:00
*
1998-04-10 06:59:06 -04:00
* TkBindInit --
1996-09-27 06:29:02 -04:00
*
1998-04-10 06:59:06 -04:00
* This procedure is called when an application is created. It
* initializes all the structures used by bindings and virtual
* events. It must be called before any other functions in this
* file are called.
1996-09-27 06:29:02 -04:00
*
* Results:
1998-04-10 06:59:06 -04:00
* None.
1996-09-27 06:29:02 -04:00
*
* Side effects:
1998-04-10 06:59:06 -04:00
* Memory allocated.
1996-09-27 06:29:02 -04:00
*
1998-04-10 06:59:06 -04:00
*---------------------------------------------------------------------------
1996-09-27 06:29:02 -04:00
*/
1998-04-10 06:59:06 -04:00
void
TkBindInit(mainPtr)
TkMainInfo *mainPtr; /* The newly created application. */
1996-09-27 06:29:02 -04:00
{
1998-04-10 06:59:06 -04:00
BindInfo *bindInfoPtr;
if (sizeof(XEvent) < sizeof(XVirtualEvent)) {
panic("TkBindInit: virtual events can't be supported");
}
1996-09-27 06:29:02 -04:00
/*
1998-04-10 06:59:06 -04:00
* Initialize the static data structures used by the binding package.
* They are only initialized once, no matter how many interps are
* created.
1996-09-27 06:29:02 -04:00
*/
if (!initialized) {
1998-04-10 06:59:06 -04:00
Tcl_HashEntry *hPtr;
ModInfo *modPtr;
EventInfo *eiPtr;
1996-09-27 06:29:02 -04:00
int dummy;
#ifdef REDO_KEYSYM_LOOKUP
1998-04-10 06:59:06 -04:00
KeySymInfo *kPtr;
1996-09-27 06:29:02 -04:00
Tcl_InitHashTable(&keySymTable, TCL_STRING_KEYS);
Tcl_InitHashTable(&nameTable, TCL_ONE_WORD_KEYS);
for (kPtr = keyArray; kPtr->name != NULL; kPtr++) {
hPtr = Tcl_CreateHashEntry(&keySymTable, kPtr->name, &dummy);
Tcl_SetHashValue(hPtr, kPtr->value);
hPtr = Tcl_CreateHashEntry(&nameTable, (char *) kPtr->value,
&dummy);
Tcl_SetHashValue(hPtr, kPtr->name);
}
#endif /* REDO_KEYSYM_LOOKUP */
Tcl_InitHashTable(&modTable, TCL_STRING_KEYS);
for (modPtr = modArray; modPtr->name != NULL; modPtr++) {
hPtr = Tcl_CreateHashEntry(&modTable, modPtr->name, &dummy);
Tcl_SetHashValue(hPtr, modPtr);
}
Tcl_InitHashTable(&eventTable, TCL_STRING_KEYS);
for (eiPtr = eventArray; eiPtr->name != NULL; eiPtr++) {
hPtr = Tcl_CreateHashEntry(&eventTable, eiPtr->name, &dummy);
Tcl_SetHashValue(hPtr, eiPtr);
}
1998-04-10 06:59:06 -04:00
initialized = 1;
1996-09-27 06:29:02 -04:00
}
1998-04-10 06:59:06 -04:00
mainPtr->bindingTable = Tk_CreateBindingTable(mainPtr->interp);
bindInfoPtr = (BindInfo *) ckalloc(sizeof(BindInfo));
InitVirtualEventTable(&bindInfoPtr->virtualEventTable);
bindInfoPtr->screenInfo.curDispPtr = NULL;
bindInfoPtr->screenInfo.curScreenIndex = -1;
bindInfoPtr->screenInfo.bindingDepth = 0;
bindInfoPtr->pendingList = NULL;
mainPtr->bindInfo = (TkBindInfo) bindInfoPtr;
TkpInitializeMenuBindings(mainPtr->interp, mainPtr->bindingTable);
}
/*
*---------------------------------------------------------------------------
*
* 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
TkBindFree(mainPtr)
TkMainInfo *mainPtr; /* The newly created application. */
{
BindInfo *bindInfoPtr;
Tk_DeleteBindingTable(mainPtr->bindingTable);
mainPtr->bindingTable = NULL;
bindInfoPtr = (BindInfo *) mainPtr->bindInfo;
DeleteVirtualEventTable(&bindInfoPtr->virtualEventTable);
mainPtr->bindInfo = NULL;
}
/*
*--------------------------------------------------------------
*
* 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.
*
*--------------------------------------------------------------
*/
Tk_BindingTable
Tk_CreateBindingTable(interp)
Tcl_Interp *interp; /* Interpreter to associate with the binding
* table: commands are executed in this
* interpreter. */
{
BindingTable *bindPtr;
int i;
1996-09-27 06:29:02 -04:00
/*
* Create and initialize a new binding table.
*/
bindPtr = (BindingTable *) ckalloc(sizeof(BindingTable));
for (i = 0; i < EVENT_BUFFER_SIZE; i++) {
bindPtr->eventRing[i].type = -1;
}
bindPtr->curEvent = 0;
Tcl_InitHashTable(&bindPtr->patternTable,
sizeof(PatternTableKey)/sizeof(int));
Tcl_InitHashTable(&bindPtr->objectTable, TCL_ONE_WORD_KEYS);
bindPtr->interp = interp;
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
Tk_DeleteBindingTable(bindingTable)
Tk_BindingTable bindingTable; /* Token for the binding table to
* destroy. */
{
BindingTable *bindPtr = (BindingTable *) bindingTable;
PatSeq *psPtr, *nextPtr;
Tcl_HashEntry *hPtr;
Tcl_HashSearch search;
/*
* Find and delete all of the patterns associated with the binding
* table.
*/
for (hPtr = Tcl_FirstHashEntry(&bindPtr->patternTable, &search);
hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) {
for (psPtr = (PatSeq *) Tcl_GetHashValue(hPtr);
psPtr != NULL; psPtr = nextPtr) {
nextPtr = psPtr->nextSeqPtr;
1998-04-10 06:59:06 -04:00
psPtr->flags |= MARKED_DELETED;
if (psPtr->refCount == 0) {
if (psPtr->freeProc != NULL) {
(*psPtr->freeProc)(psPtr->clientData);
}
ckfree((char *) psPtr);
}
1996-09-27 06:29:02 -04:00
}
}
/*
* Clean up the rest of the information associated with the
* binding table.
*/
Tcl_DeleteHashTable(&bindPtr->patternTable);
Tcl_DeleteHashTable(&bindPtr->objectTable);
ckfree((char *) bindPtr);
}
/*
*--------------------------------------------------------------
*
* 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:
1998-04-10 06:59:06 -04:00
* An existing binding on the same event sequence may be
* replaced.
1996-09-27 06:29:02 -04:00
* The new binding may cause future calls to Tk_BindEvent to
* behave differently than they did previously.
*
*--------------------------------------------------------------
*/
1999-09-05 07:16:41 -04:00
#ifdef SCM_CODE
unsigned long
Tk_CreateBinding(interp, bindingTable, object, eventString, command, key1, key3)
Tcl_Interp *interp; /* Used for error reporting. */
Tk_BindingTable bindingTable;
/* Table in which to create binding. */
ClientData object; /* Token for object with which binding is
* associated. */
char *eventString; /* String describing event sequence that
* triggers binding. */
char *command; /* Contains Tcl command to execute when
* binding triggers. */
char *key1; /* Widget's name */
char *key3; /* Inset ID */
#else
1996-09-27 06:29:02 -04:00
unsigned long
Tk_CreateBinding(interp, bindingTable, object, eventString, command, append)
1998-04-10 06:59:06 -04:00
Tcl_Interp *interp; /* Used for error reporting. */
Tk_BindingTable bindingTable;
/* Table in which to create binding. */
ClientData object; /* Token for object with which binding 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. If the existing binding is for a
* callback function and not a Tcl command
* string, the existing binding will always be
* replaced. */
1999-09-05 07:16:41 -04:00
#endif