tk8.6.1/0000755003604700454610000000000012216045053010460 5ustar dgp771divtk8.6.1/generic/0000755003604700454610000000000012216045052012073 5ustar dgp771divtk8.6.1/generic/tk.h0000644003604700454610000016056212211355622012676 0ustar dgp771div/* * tk.h -- * * Declarations for Tk-related things that are visible outside of the Tk * module itself. * * Copyright (c) 1989-1994 The Regents of the University of California. * Copyright (c) 1994 The Australian National University. * Copyright (c) 1994-1998 Sun Microsystems, Inc. * Copyright (c) 1998-2000 Ajuba Solutions. * * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. */ #ifndef _TK #define _TK #include #if (TCL_MAJOR_VERSION != 8) || (TCL_MINOR_VERSION < 6) # error Tk 8.6 must be compiled with tcl.h from Tcl 8.6 or better #endif #ifndef CONST84 # define CONST84 const # define CONST84_RETURN const #endif #ifndef CONST86 # define CONST86 CONST84 #endif #ifndef EXTERN # define EXTERN extern TCL_STORAGE_CLASS #endif /* * Utility macros: STRINGIFY takes an argument and wraps it in "" (double * quotation marks), JOIN joins two arguments. */ #ifndef STRINGIFY # define STRINGIFY(x) STRINGIFY1(x) # define STRINGIFY1(x) #x #endif #ifndef JOIN # define JOIN(a,b) JOIN1(a,b) # define JOIN1(a,b) a##b #endif /* * For C++ compilers, use extern "C" */ #ifdef __cplusplus extern "C" { #endif /* * When version numbers change here, you must also go into the following files * and update the version numbers: * * library/tk.tcl (1 LOC patch) * unix/configure.in (2 LOC Major, 2 LOC minor, 1 LOC patch) * win/configure.in (as above) * README (sections 0 and 1) * macosx/Tk-Common.xcconfig (not patchlevel) 1 LOC * win/README (not patchlevel) * unix/README (not patchlevel) * unix/tk.spec (1 LOC patch) * win/tcl.m4 (not patchlevel) * * You may also need to update some of these files when the numbers change for * the version of Tcl that this release of Tk is compiled against. */ #define TK_MAJOR_VERSION 8 #define TK_MINOR_VERSION 6 #define TK_RELEASE_LEVEL TCL_FINAL_RELEASE #define TK_RELEASE_SERIAL 0 #define TK_VERSION "8.6" #define TK_PATCH_LEVEL "8.6.1" /* * A special definition used to allow this header file to be included from * windows or mac resource files so that they can obtain version information. * RC_INVOKED is defined by default by the windows RC tool and manually set * for macintosh. * * Resource compilers don't like all the C stuff, like typedefs and procedure * declarations, that occur below, so block them out. */ #ifndef RC_INVOKED #ifndef _XLIB_H # include # ifdef MAC_OSX_TK # include # endif #endif #ifdef __STDC__ # include #endif #ifdef BUILD_tk #undef TCL_STORAGE_CLASS #define TCL_STORAGE_CLASS DLLEXPORT #endif /* *---------------------------------------------------------------------- * * Decide whether or not to use input methods. */ #ifdef XNQueryInputStyle #define TK_USE_INPUT_METHODS #endif /* * Dummy types that are used by clients: */ typedef struct Tk_BindingTable_ *Tk_BindingTable; typedef struct Tk_Canvas_ *Tk_Canvas; typedef struct Tk_Cursor_ *Tk_Cursor; typedef struct Tk_ErrorHandler_ *Tk_ErrorHandler; typedef struct Tk_Font_ *Tk_Font; typedef struct Tk_Image__ *Tk_Image; typedef struct Tk_ImageMaster_ *Tk_ImageMaster; typedef struct Tk_OptionTable_ *Tk_OptionTable; typedef struct Tk_PostscriptInfo_ *Tk_PostscriptInfo; typedef struct Tk_TextLayout_ *Tk_TextLayout; typedef struct Tk_Window_ *Tk_Window; typedef struct Tk_3DBorder_ *Tk_3DBorder; typedef struct Tk_Style_ *Tk_Style; typedef struct Tk_StyleEngine_ *Tk_StyleEngine; typedef struct Tk_StyledElement_ *Tk_StyledElement; /* * Additional types exported to clients. */ typedef const char *Tk_Uid; /* *---------------------------------------------------------------------- * * The enum below defines the valid types for Tk configuration options as * implemented by Tk_InitOptions, Tk_SetOptions, etc. */ typedef enum { TK_OPTION_BOOLEAN, TK_OPTION_INT, TK_OPTION_DOUBLE, TK_OPTION_STRING, TK_OPTION_STRING_TABLE, TK_OPTION_COLOR, TK_OPTION_FONT, TK_OPTION_BITMAP, TK_OPTION_BORDER, TK_OPTION_RELIEF, TK_OPTION_CURSOR, TK_OPTION_JUSTIFY, TK_OPTION_ANCHOR, TK_OPTION_SYNONYM, TK_OPTION_PIXELS, TK_OPTION_WINDOW, TK_OPTION_END, TK_OPTION_CUSTOM, TK_OPTION_STYLE } Tk_OptionType; /* * Structures of the following type are used by widgets to specify their * configuration options. Typically each widget has a static array of these * structures, where each element of the array describes a single * configuration option. The array is passed to Tk_CreateOptionTable. */ typedef struct Tk_OptionSpec { Tk_OptionType type; /* Type of option, such as TK_OPTION_COLOR; * see definitions above. Last option in table * must have type TK_OPTION_END. */ const char *optionName; /* Name used to specify option in Tcl * commands. */ const char *dbName; /* Name for option in option database. */ const char *dbClass; /* Class for option in database. */ const char *defValue; /* Default value for option if not specified * in command line, the option database, or * the system. */ int objOffset; /* Where in record to store a Tcl_Obj * that * holds the value of this option, specified * as an offset in bytes from the start of the * record. Use the Tk_Offset macro to generate * values for this. -1 means don't store the * Tcl_Obj in the record. */ int internalOffset; /* Where in record to store the internal * representation of the value of this option, * such as an int or XColor *. This field is * specified as an offset in bytes from the * start of the record. Use the Tk_Offset * macro to generate values for it. -1 means * don't store the internal representation in * the record. */ int flags; /* Any combination of the values defined * below. */ const void *clientData; /* An alternate place to put option-specific * data. Used for the monochrome default value * for colors, etc. */ int typeMask; /* An arbitrary bit mask defined by the class * manager; typically bits correspond to * certain kinds of options such as all those * that require a redisplay when they change. * Tk_SetOptions returns the bit-wise OR of * the typeMasks of all options that were * changed. */ } Tk_OptionSpec; /* * Flag values for Tk_OptionSpec structures. These flags are shared by * Tk_ConfigSpec structures, so be sure to coordinate any changes carefully. */ #define TK_OPTION_NULL_OK (1 << 0) #define TK_OPTION_DONT_SET_DEFAULT (1 << 3) /* * The following structure and function types are used by TK_OPTION_CUSTOM * options; the structure holds pointers to the functions needed by the Tk * option config code to handle a custom option. */ typedef int (Tk_CustomOptionSetProc) (ClientData clientData, Tcl_Interp *interp, Tk_Window tkwin, Tcl_Obj **value, char *widgRec, int offset, char *saveInternalPtr, int flags); typedef Tcl_Obj *(Tk_CustomOptionGetProc) (ClientData clientData, Tk_Window tkwin, char *widgRec, int offset); typedef void (Tk_CustomOptionRestoreProc) (ClientData clientData, Tk_Window tkwin, char *internalPtr, char *saveInternalPtr); typedef void (Tk_CustomOptionFreeProc) (ClientData clientData, Tk_Window tkwin, char *internalPtr); typedef struct Tk_ObjCustomOption { const char *name; /* Name of the custom option. */ Tk_CustomOptionSetProc *setProc; /* Function to use to set a record's option * value from a Tcl_Obj */ Tk_CustomOptionGetProc *getProc; /* Function to use to get a Tcl_Obj * representation from an internal * representation of an option. */ Tk_CustomOptionRestoreProc *restoreProc; /* Function to use to restore a saved value * for the internal representation. */ Tk_CustomOptionFreeProc *freeProc; /* Function to use to free the internal * representation of an option. */ ClientData clientData; /* Arbitrary one-word value passed to the * handling procs. */ } Tk_ObjCustomOption; /* * Macro to use to fill in "offset" fields of the Tk_OptionSpec structure. * Computes number of bytes from beginning of structure to a given field. */ #ifdef offsetof #define Tk_Offset(type, field) ((int) offsetof(type, field)) #else #define Tk_Offset(type, field) ((int) ((char *) &((type *) 0)->field)) #endif /* * The following two structures are used for error handling. When config * options are being modified, the old values are saved in a Tk_SavedOptions * structure. If an error occurs, then the contents of the structure can be * used to restore all of the old values. The contents of this structure are * for the private use Tk. No-one outside Tk should ever read or write any of * the fields of these structures. */ typedef struct Tk_SavedOption { struct TkOption *optionPtr; /* Points to information that describes the * option. */ Tcl_Obj *valuePtr; /* The old value of the option, in the form of * a Tcl object; may be NULL if the value was * not saved as an object. */ double internalForm; /* The old value of the option, in some * internal representation such as an int or * (XColor *). Valid only if the field * optionPtr->specPtr->objOffset is < 0. The * space must be large enough to accommodate a * double, a long, or a pointer; right now it * looks like a double (i.e., 8 bytes) is big * enough. Also, using a double guarantees * that the field is properly aligned for * storing large values. */ } Tk_SavedOption; #ifdef TCL_MEM_DEBUG # define TK_NUM_SAVED_OPTIONS 2 #else # define TK_NUM_SAVED_OPTIONS 20 #endif typedef struct Tk_SavedOptions { char *recordPtr; /* The data structure in which to restore * configuration options. */ Tk_Window tkwin; /* Window associated with recordPtr; needed to * restore certain options. */ int numItems; /* The number of valid items in items field. */ Tk_SavedOption items[TK_NUM_SAVED_OPTIONS]; /* Items used to hold old values. */ struct Tk_SavedOptions *nextPtr; /* Points to next structure in list; needed if * too many options changed to hold all the * old values in a single structure. NULL * means no more structures. */ } Tk_SavedOptions; /* * Structure used to describe application-specific configuration options: * indicates procedures to call to parse an option and to return a text string * describing an option. THESE ARE DEPRECATED; PLEASE USE THE NEW STRUCTURES * LISTED ABOVE. */ /* * This is a temporary flag used while tkObjConfig and new widgets are in * development. */ #ifndef __NO_OLD_CONFIG typedef int (Tk_OptionParseProc) (ClientData clientData, Tcl_Interp *interp, Tk_Window tkwin, CONST84 char *value, char *widgRec, int offset); typedef CONST86 char *(Tk_OptionPrintProc) (ClientData clientData, Tk_Window tkwin, char *widgRec, int offset, Tcl_FreeProc **freeProcPtr); typedef struct Tk_CustomOption { Tk_OptionParseProc *parseProc; /* Procedure to call to parse an option and * store it in converted form. */ Tk_OptionPrintProc *printProc; /* Procedure to return a printable string * describing an existing option. */ ClientData clientData; /* Arbitrary one-word value used by option * parser: passed to parseProc and * printProc. */ } Tk_CustomOption; /* * Structure used to specify information for Tk_ConfigureWidget. Each * structure gives complete information for one option, including how the * option is specified on the command line, where it appears in the option * database, etc. */ typedef struct Tk_ConfigSpec { int type; /* Type of option, such as TK_CONFIG_COLOR; * see definitions below. Last option in table * must have type TK_CONFIG_END. */ CONST86 char *argvName; /* Switch used to specify option in argv. NULL * means this spec is part of a group. */ Tk_Uid dbName; /* Name for option in option database. */ Tk_Uid dbClass; /* Class for option in database. */ Tk_Uid defValue; /* Default value for option if not specified * in command line or database. */ int offset; /* Where in widget record to store value; use * Tk_Offset macro to generate values for * this. */ int specFlags; /* Any combination of the values defined * below; other bits are used internally by * tkConfig.c. */ CONST86 Tk_CustomOption *customPtr; /* If type is TK_CONFIG_CUSTOM then this is a * pointer to info about how to parse and * print the option. Otherwise it is * irrelevant. */ } Tk_ConfigSpec; /* * Type values for Tk_ConfigSpec structures. See the user documentation for * details. */ typedef enum { TK_CONFIG_BOOLEAN, TK_CONFIG_INT, TK_CONFIG_DOUBLE, TK_CONFIG_STRING, TK_CONFIG_UID, TK_CONFIG_COLOR, TK_CONFIG_FONT, TK_CONFIG_BITMAP, TK_CONFIG_BORDER, TK_CONFIG_RELIEF, TK_CONFIG_CURSOR, TK_CONFIG_ACTIVE_CURSOR, TK_CONFIG_JUSTIFY, TK_CONFIG_ANCHOR, TK_CONFIG_SYNONYM, TK_CONFIG_CAP_STYLE, TK_CONFIG_JOIN_STYLE, TK_CONFIG_PIXELS, TK_CONFIG_MM, TK_CONFIG_WINDOW, TK_CONFIG_CUSTOM, TK_CONFIG_END } Tk_ConfigTypes; /* * Possible values for flags argument to Tk_ConfigureWidget: */ #define TK_CONFIG_ARGV_ONLY 1 #define TK_CONFIG_OBJS 0x80 /* * Possible flag values for Tk_ConfigSpec structures. Any bits at or above * TK_CONFIG_USER_BIT may be used by clients for selecting certain entries. * Before changing any values here, coordinate with tkOldConfig.c * (internal-use-only flags are defined there). */ #define TK_CONFIG_NULL_OK (1 << 0) #define TK_CONFIG_COLOR_ONLY (1 << 1) #define TK_CONFIG_MONO_ONLY (1 << 2) #define TK_CONFIG_DONT_SET_DEFAULT (1 << 3) #define TK_CONFIG_OPTION_SPECIFIED (1 << 4) #define TK_CONFIG_USER_BIT 0x100 #endif /* __NO_OLD_CONFIG */ /* * Structure used to specify how to handle argv options. */ typedef struct { CONST86 char *key; /* The key string that flags the option in the * argv array. */ int type; /* Indicates option type; see below. */ char *src; /* Value to be used in setting dst; usage * depends on type. */ char *dst; /* Address of value to be modified; usage * depends on type. */ CONST86 char *help; /* Documentation message describing this * option. */ } Tk_ArgvInfo; /* * Legal values for the type field of a Tk_ArgvInfo: see the user * documentation for details. */ #define TK_ARGV_CONSTANT 15 #define TK_ARGV_INT 16 #define TK_ARGV_STRING 17 #define TK_ARGV_UID 18 #define TK_ARGV_REST 19 #define TK_ARGV_FLOAT 20 #define TK_ARGV_FUNC 21 #define TK_ARGV_GENFUNC 22 #define TK_ARGV_HELP 23 #define TK_ARGV_CONST_OPTION 24 #define TK_ARGV_OPTION_VALUE 25 #define TK_ARGV_OPTION_NAME_VALUE 26 #define TK_ARGV_END 27 /* * Flag bits for passing to Tk_ParseArgv: */ #define TK_ARGV_NO_DEFAULTS 0x1 #define TK_ARGV_NO_LEFTOVERS 0x2 #define TK_ARGV_NO_ABBREV 0x4 #define TK_ARGV_DONT_SKIP_FIRST_ARG 0x8 /* * Enumerated type for describing actions to be taken in response to a * restrictProc established by Tk_RestrictEvents. */ typedef enum { TK_DEFER_EVENT, TK_PROCESS_EVENT, TK_DISCARD_EVENT } Tk_RestrictAction; /* * Priority levels to pass to Tk_AddOption: */ #define TK_WIDGET_DEFAULT_PRIO 20 #define TK_STARTUP_FILE_PRIO 40 #define TK_USER_DEFAULT_PRIO 60 #define TK_INTERACTIVE_PRIO 80 #define TK_MAX_PRIO 100 /* * Relief values returned by Tk_GetRelief: */ #define TK_RELIEF_NULL -1 #define TK_RELIEF_FLAT 0 #define TK_RELIEF_GROOVE 1 #define TK_RELIEF_RAISED 2 #define TK_RELIEF_RIDGE 3 #define TK_RELIEF_SOLID 4 #define TK_RELIEF_SUNKEN 5 /* * "Which" argument values for Tk_3DBorderGC: */ #define TK_3D_FLAT_GC 1 #define TK_3D_LIGHT_GC 2 #define TK_3D_DARK_GC 3 /* * Special EnterNotify/LeaveNotify "mode" for use in events generated by * tkShare.c. Pick a high enough value that it's unlikely to conflict with * existing values (like NotifyNormal) or any new values defined in the * future. */ #define TK_NOTIFY_SHARE 20 /* * Enumerated type for describing a point by which to anchor something: */ typedef enum { TK_ANCHOR_N, TK_ANCHOR_NE, TK_ANCHOR_E, TK_ANCHOR_SE, TK_ANCHOR_S, TK_ANCHOR_SW, TK_ANCHOR_W, TK_ANCHOR_NW, TK_ANCHOR_CENTER } Tk_Anchor; /* * Enumerated type for describing a style of justification: */ typedef enum { TK_JUSTIFY_LEFT, TK_JUSTIFY_RIGHT, TK_JUSTIFY_CENTER } Tk_Justify; /* * The following structure is used by Tk_GetFontMetrics() to return * information about the properties of a Tk_Font. */ typedef struct Tk_FontMetrics { int ascent; /* The amount in pixels that the tallest * letter sticks up above the baseline, plus * any extra blank space added by the designer * of the font. */ int descent; /* The largest amount in pixels that any * letter sticks below the baseline, plus any * extra blank space added by the designer of * the font. */ int linespace; /* The sum of the ascent and descent. How far * apart two lines of text in the same font * should be placed so that none of the * characters in one line overlap any of the * characters in the other line. */ } Tk_FontMetrics; /* * Flags passed to Tk_MeasureChars: */ #define TK_WHOLE_WORDS 1 #define TK_AT_LEAST_ONE 2 #define TK_PARTIAL_OK 4 /* * Flags passed to Tk_ComputeTextLayout: */ #define TK_IGNORE_TABS 8 #define TK_IGNORE_NEWLINES 16 /* * Widget class procedures used to implement platform specific widget * behavior. */ typedef Window (Tk_ClassCreateProc) (Tk_Window tkwin, Window parent, ClientData instanceData); typedef void (Tk_ClassWorldChangedProc) (ClientData instanceData); typedef void (Tk_ClassModalProc) (Tk_Window tkwin, XEvent *eventPtr); typedef struct Tk_ClassProcs { unsigned int size; Tk_ClassWorldChangedProc *worldChangedProc; /* Procedure to invoke when the widget needs * to respond in some way to a change in the * world (font changes, etc.) */ Tk_ClassCreateProc *createProc; /* Procedure to invoke when the platform- * dependent window needs to be created. */ Tk_ClassModalProc *modalProc; /* Procedure to invoke after all bindings on a * widget have been triggered in order to * handle a modal loop. */ } Tk_ClassProcs; /* * Simple accessor for Tk_ClassProcs structure. Checks that the structure is * not NULL, then checks the size field and returns either the requested * field, if present, or NULL if the structure is too small to have the field * (or NULL if the structure is NULL). * * A more general version of this function may be useful if other * size-versioned structure pop up in the future: * * #define Tk_GetField(name, who, which) \ * (((who) == NULL) ? NULL : * (((who)->size <= Tk_Offset(name, which)) ? NULL :(name)->which)) */ #define Tk_GetClassProc(procs, which) \ (((procs) == NULL) ? NULL : \ (((procs)->size <= Tk_Offset(Tk_ClassProcs, which)) ? NULL:(procs)->which)) /* * Each geometry manager (the packer, the placer, etc.) is represented by a * structure of the following form, which indicates procedures to invoke in * the geometry manager to carry out certain functions. */ typedef void (Tk_GeomRequestProc) (ClientData clientData, Tk_Window tkwin); typedef void (Tk_GeomLostSlaveProc) (ClientData clientData, Tk_Window tkwin); typedef struct Tk_GeomMgr { const char *name; /* Name of the geometry manager (command used * to invoke it, or name of widget class that * allows embedded widgets). */ Tk_GeomRequestProc *requestProc; /* Procedure to invoke when a slave's * requested geometry changes. */ Tk_GeomLostSlaveProc *lostSlaveProc; /* Procedure to invoke when a slave is taken * away from one geometry manager by another. * NULL means geometry manager doesn't care * when slaves are lost. */ } Tk_GeomMgr; /* * Result values returned by Tk_GetScrollInfo: */ #define TK_SCROLL_MOVETO 1 #define TK_SCROLL_PAGES 2 #define TK_SCROLL_UNITS 3 #define TK_SCROLL_ERROR 4 /* *---------------------------------------------------------------------- * * Extensions to the X event set * *---------------------------------------------------------------------- */ #define VirtualEvent (MappingNotify + 1) #define ActivateNotify (MappingNotify + 2) #define DeactivateNotify (MappingNotify + 3) #define MouseWheelEvent (MappingNotify + 4) #define TK_LASTEVENT (MappingNotify + 5) #define MouseWheelMask (1L << 28) #define ActivateMask (1L << 29) #define VirtualEventMask (1L << 30) /* * A virtual event shares most of its fields with the XKeyEvent and * XButtonEvent structures. 99% of the time a virtual event will be an * abstraction of a key or button event, so this structure provides the most * information to the user. The only difference is the changing of the detail * field for a virtual event so that it holds the name of the virtual event * being triggered. * * When using this structure, you should ensure that you zero out all the * fields first using memset() or bzero(). */ typedef struct { int type; unsigned long serial; /* # of last request processed by server. */ Bool send_event; /* True if this came from a SendEvent * request. */ Display *display; /* Display the event was read from. */ Window event; /* Window on which event was requested. */ Window root; /* Root window that the event occured on. */ Window subwindow; /* Child window. */ Time time; /* Milliseconds. */ int x, y; /* Pointer x, y coordinates in event * window. */ int x_root, y_root; /* Coordinates relative to root. */ unsigned int state; /* Key or button mask */ Tk_Uid name; /* Name of virtual event. */ Bool same_screen; /* Same screen flag. */ Tcl_Obj *user_data; /* Application-specific data reference; Tk * will decrement the reference count *once* * when it has finished processing the * event. */ } XVirtualEvent; typedef struct { int type; unsigned long serial; /* # of last request processed by server. */ Bool send_event; /* True if this came from a SendEvent * request. */ Display *display; /* Display the event was read from. */ Window window; /* Window in which event occurred. */ } XActivateDeactivateEvent; typedef XActivateDeactivateEvent XActivateEvent; typedef XActivateDeactivateEvent XDeactivateEvent; /* *---------------------------------------------------------------------- * * Macros for querying Tk_Window structures. See the manual entries for * documentation. * *---------------------------------------------------------------------- */ #define Tk_Display(tkwin) (((Tk_FakeWin *) (tkwin))->display) #define Tk_ScreenNumber(tkwin) (((Tk_FakeWin *) (tkwin))->screenNum) #define Tk_Screen(tkwin) \ (ScreenOfDisplay(Tk_Display(tkwin), Tk_ScreenNumber(tkwin))) #define Tk_Depth(tkwin) (((Tk_FakeWin *) (tkwin))->depth) #define Tk_Visual(tkwin) (((Tk_FakeWin *) (tkwin))->visual) #define Tk_WindowId(tkwin) (((Tk_FakeWin *) (tkwin))->window) #define Tk_PathName(tkwin) (((Tk_FakeWin *) (tkwin))->pathName) #define Tk_Name(tkwin) (((Tk_FakeWin *) (tkwin))->nameUid) #define Tk_Class(tkwin) (((Tk_FakeWin *) (tkwin))->classUid) #define Tk_X(tkwin) (((Tk_FakeWin *) (tkwin))->changes.x) #define Tk_Y(tkwin) (((Tk_FakeWin *) (tkwin))->changes.y) #define Tk_Width(tkwin) (((Tk_FakeWin *) (tkwin))->changes.width) #define Tk_Height(tkwin) \ (((Tk_FakeWin *) (tkwin))->changes.height) #define Tk_Changes(tkwin) (&((Tk_FakeWin *) (tkwin))->changes) #define Tk_Attributes(tkwin) (&((Tk_FakeWin *) (tkwin))->atts) #define Tk_IsEmbedded(tkwin) \ (((Tk_FakeWin *) (tkwin))->flags & TK_EMBEDDED) #define Tk_IsContainer(tkwin) \ (((Tk_FakeWin *) (tkwin))->flags & TK_CONTAINER) #define Tk_IsMapped(tkwin) \ (((Tk_FakeWin *) (tkwin))->flags & TK_MAPPED) #define Tk_IsTopLevel(tkwin) \ (((Tk_FakeWin *) (tkwin))->flags & TK_TOP_LEVEL) #define Tk_HasWrapper(tkwin) \ (((Tk_FakeWin *) (tkwin))->flags & TK_HAS_WRAPPER) #define Tk_WinManaged(tkwin) \ (((Tk_FakeWin *) (tkwin))->flags & TK_WIN_MANAGED) #define Tk_TopWinHierarchy(tkwin) \ (((Tk_FakeWin *) (tkwin))->flags & TK_TOP_HIERARCHY) #define Tk_IsManageable(tkwin) \ (((Tk_FakeWin *) (tkwin))->flags & TK_WM_MANAGEABLE) #define Tk_ReqWidth(tkwin) (((Tk_FakeWin *) (tkwin))->reqWidth) #define Tk_ReqHeight(tkwin) (((Tk_FakeWin *) (tkwin))->reqHeight) /* Tk_InternalBorderWidth is deprecated */ #define Tk_InternalBorderWidth(tkwin) \ (((Tk_FakeWin *) (tkwin))->internalBorderLeft) #define Tk_InternalBorderLeft(tkwin) \ (((Tk_FakeWin *) (tkwin))->internalBorderLeft) #define Tk_InternalBorderRight(tkwin) \ (((Tk_FakeWin *) (tkwin))->internalBorderRight) #define Tk_InternalBorderTop(tkwin) \ (((Tk_FakeWin *) (tkwin))->internalBorderTop) #define Tk_InternalBorderBottom(tkwin) \ (((Tk_FakeWin *) (tkwin))->internalBorderBottom) #define Tk_MinReqWidth(tkwin) (((Tk_FakeWin *) (tkwin))->minReqWidth) #define Tk_MinReqHeight(tkwin) (((Tk_FakeWin *) (tkwin))->minReqHeight) #define Tk_Parent(tkwin) (((Tk_FakeWin *) (tkwin))->parentPtr) #define Tk_Colormap(tkwin) (((Tk_FakeWin *) (tkwin))->atts.colormap) /* * The structure below is needed by the macros above so that they can access * the fields of a Tk_Window. The fields not needed by the macros are declared * as "dummyX". The structure has its own type in order to prevent apps from * accessing Tk_Window fields except using official macros. WARNING!! The * structure definition must be kept consistent with the TkWindow structure in * tkInt.h. If you change one, then change the other. See the declaration in * tkInt.h for documentation on what the fields are used for internally. */ typedef struct Tk_FakeWin { Display *display; char *dummy1; /* dispPtr */ int screenNum; Visual *visual; int depth; Window window; char *dummy2; /* childList */ char *dummy3; /* lastChildPtr */ Tk_Window parentPtr; /* parentPtr */ char *dummy4; /* nextPtr */ char *dummy5; /* mainPtr */ char *pathName; Tk_Uid nameUid; Tk_Uid classUid; XWindowChanges changes; unsigned int dummy6; /* dirtyChanges */ XSetWindowAttributes atts; unsigned long dummy7; /* dirtyAtts */ unsigned int flags; char *dummy8; /* handlerList */ #ifdef TK_USE_INPUT_METHODS XIC dummy9; /* inputContext */ #endif /* TK_USE_INPUT_METHODS */ ClientData *dummy10; /* tagPtr */ int dummy11; /* numTags */ int dummy12; /* optionLevel */ char *dummy13; /* selHandlerList */ char *dummy14; /* geomMgrPtr */ ClientData dummy15; /* geomData */ int reqWidth, reqHeight; int internalBorderLeft; char *dummy16; /* wmInfoPtr */ char *dummy17; /* classProcPtr */ ClientData dummy18; /* instanceData */ char *dummy19; /* privatePtr */ int internalBorderRight; int internalBorderTop; int internalBorderBottom; int minReqWidth; int minReqHeight; char *dummy20; /* geometryMaster */ } Tk_FakeWin; /* * Flag values for TkWindow (and Tk_FakeWin) structures are: * * TK_MAPPED: 1 means window is currently mapped, * 0 means unmapped. * TK_TOP_LEVEL: 1 means this is a top-level widget. * TK_ALREADY_DEAD: 1 means the window is in the process of * being destroyed already. * TK_NEED_CONFIG_NOTIFY: 1 means that the window has been reconfigured * before it was made to exist. At the time of * making it exist a ConfigureNotify event needs * to be generated. * TK_GRAB_FLAG: Used to manage grabs. See tkGrab.c for details * TK_CHECKED_IC: 1 means we've already tried to get an input * context for this window; if the ic field is * NULL it means that there isn't a context for * the field. * TK_DONT_DESTROY_WINDOW: 1 means that Tk_DestroyWindow should not * invoke XDestroyWindow to destroy this widget's * X window. The flag is set when the window has * already been destroyed elsewhere (e.g. by * another application) or when it will be * destroyed later (e.g. by destroying its parent) * TK_WM_COLORMAP_WINDOW: 1 means that this window has at some time * appeared in the WM_COLORMAP_WINDOWS property * for its toplevel, so we have to remove it from * that property if the window is deleted and the * toplevel isn't. * TK_EMBEDDED: 1 means that this window (which must be a * toplevel) is not a free-standing window but * rather is embedded in some other application. * TK_CONTAINER: 1 means that this window is a container, and * that some other application (either in this * process or elsewhere) may be embedding itself * inside the window. * TK_BOTH_HALVES: 1 means that this window is used for * application embedding (either as container or * embedded application), and both the containing * and embedded halves are associated with * windows in this particular process. * TK_WRAPPER: 1 means that this window is the extra wrapper * window created around a toplevel to hold the * menubar under Unix. See tkUnixWm.c for more * information. * TK_REPARENTED: 1 means that this window has been reparented * so that as far as the window system is * concerned it isn't a child of its Tk parent. * Initially this is used only for special Unix * menubar windows. * TK_ANONYMOUS_WINDOW: 1 means that this window has no name, and is * thus not accessible from Tk. * TK_HAS_WRAPPER 1 means that this window has a wrapper window * TK_WIN_MANAGED 1 means that this window is a child of the root * window, and is managed by the window manager. * TK_TOP_HIERARCHY 1 means this window is at the top of a physical * window hierarchy within this process, i.e. the * window's parent either doesn't exist or is not * owned by this Tk application. * TK_PROP_PROPCHANGE 1 means that PropertyNotify events in the * window's children should propagate up to this * window. * TK_WM_MANAGEABLE 1 marks a window as capable of being converted * into a toplevel using [wm manage]. */ #define TK_MAPPED 1 #define TK_TOP_LEVEL 2 #define TK_ALREADY_DEAD 4 #define TK_NEED_CONFIG_NOTIFY 8 #define TK_GRAB_FLAG 0x10 #define TK_CHECKED_IC 0x20 #define TK_DONT_DESTROY_WINDOW 0x40 #define TK_WM_COLORMAP_WINDOW 0x80 #define TK_EMBEDDED 0x100 #define TK_CONTAINER 0x200 #define TK_BOTH_HALVES 0x400 #define TK_WRAPPER 0x1000 #define TK_REPARENTED 0x2000 #define TK_ANONYMOUS_WINDOW 0x4000 #define TK_HAS_WRAPPER 0x8000 #define TK_WIN_MANAGED 0x10000 #define TK_TOP_HIERARCHY 0x20000 #define TK_PROP_PROPCHANGE 0x40000 #define TK_WM_MANAGEABLE 0x80000 /* *---------------------------------------------------------------------- * * Procedure prototypes and structures used for defining new canvas items: * *---------------------------------------------------------------------- */ typedef enum { TK_STATE_NULL = -1, TK_STATE_ACTIVE, TK_STATE_DISABLED, TK_STATE_NORMAL, TK_STATE_HIDDEN } Tk_State; typedef struct Tk_SmoothMethod { CONST86 char *name; int (*coordProc) (Tk_Canvas canvas, double *pointPtr, int numPoints, int numSteps, XPoint xPoints[], double dblPoints[]); void (*postscriptProc) (Tcl_Interp *interp, Tk_Canvas canvas, double *coordPtr, int numPoints, int numSteps); } Tk_SmoothMethod; /* * For each item in a canvas widget there exists one record with the following * structure. Each actual item is represented by a record with the following * stuff at its beginning, plus additional type-specific stuff after that. */ #define TK_TAG_SPACE 3 typedef struct Tk_Item { int id; /* Unique identifier for this item (also * serves as first tag for item). */ struct Tk_Item *nextPtr; /* Next in display list of all items in this * canvas. Later items in list are drawn on * top of earlier ones. */ Tk_Uid staticTagSpace[TK_TAG_SPACE]; /* Built-in space for limited # of tags. */ Tk_Uid *tagPtr; /* Pointer to array of tags. Usually points to * staticTagSpace, but may point to malloc-ed * space if there are lots of tags. */ int tagSpace; /* Total amount of tag space available at * tagPtr. */ int numTags; /* Number of tag slots actually used at * *tagPtr. */ struct Tk_ItemType *typePtr;/* Table of procedures that implement this * type of item. */ int x1, y1, x2, y2; /* Bounding box for item, in integer canvas * units. Set by item-specific code and * guaranteed to contain every pixel drawn in * item. Item area includes x1 and y1 but not * x2 and y2. */ struct Tk_Item *prevPtr; /* Previous in display list of all items in * this canvas. Later items in list are drawn * just below earlier ones. */ Tk_State state; /* State of item. */ char *reserved1; /* reserved for future use */ int redraw_flags; /* Some flags used in the canvas */ /* *------------------------------------------------------------------ * Starting here is additional type-specific stuff; see the declarations * for individual types to see what is part of each type. The actual space * below is determined by the "itemInfoSize" of the type's Tk_ItemType * record. *------------------------------------------------------------------ */ } Tk_Item; /* * Flag bits for canvases (redraw_flags): * * TK_ITEM_STATE_DEPENDANT - 1 means that object needs to be redrawn if the * canvas state changes. * TK_ITEM_DONT_REDRAW - 1 means that the object redraw is already been * prepared, so the general canvas code doesn't * need to do that any more. */ #define TK_ITEM_STATE_DEPENDANT 1 #define TK_ITEM_DONT_REDRAW 2 /* * Records of the following type are used to describe a type of item (e.g. * lines, circles, etc.) that can form part of a canvas widget. */ #ifdef USE_OLD_CANVAS typedef int (Tk_ItemCreateProc)(Tcl_Interp *interp, Tk_Canvas canvas, Tk_Item *itemPtr, int argc, char **argv); typedef int (Tk_ItemConfigureProc)(Tcl_Interp *interp, Tk_Canvas canvas, Tk_Item *itemPtr, int argc, char **argv, int flags); typedef int (Tk_ItemCoordProc)(Tcl_Interp *interp, Tk_Canvas canvas, Tk_Item *itemPtr, int argc, char **argv); #else typedef int (Tk_ItemCreateProc)(Tcl_Interp *interp, Tk_Canvas canvas, Tk_Item *itemPtr, int argc, Tcl_Obj *const objv[]); typedef int (Tk_ItemConfigureProc)(Tcl_Interp *interp, Tk_Canvas canvas, Tk_Item *itemPtr, int argc, Tcl_Obj *const objv[], int flags); typedef int (Tk_ItemCoordProc)(Tcl_Interp *interp, Tk_Canvas canvas, Tk_Item *itemPtr, int argc, Tcl_Obj *const argv[]); #endif /* USE_OLD_CANVAS */ typedef void (Tk_ItemDeleteProc)(Tk_Canvas canvas, Tk_Item *itemPtr, Display *display); typedef void (Tk_ItemDisplayProc)(Tk_Canvas canvas, Tk_Item *itemPtr, Display *display, Drawable dst, int x, int y, int width, int height); typedef double (Tk_ItemPointProc)(Tk_Canvas canvas, Tk_Item *itemPtr, double *pointPtr); typedef int (Tk_ItemAreaProc)(Tk_Canvas canvas, Tk_Item *itemPtr, double *rectPtr); typedef int (Tk_ItemPostscriptProc)(Tcl_Interp *interp, Tk_Canvas canvas, Tk_Item *itemPtr, int prepass); typedef void (Tk_ItemScaleProc)(Tk_Canvas canvas, Tk_Item *itemPtr, double originX, double originY, double scaleX, double scaleY); typedef void (Tk_ItemTranslateProc)(Tk_Canvas canvas, Tk_Item *itemPtr, double deltaX, double deltaY); #ifdef USE_OLD_CANVAS typedef int (Tk_ItemIndexProc)(Tcl_Interp *interp, Tk_Canvas canvas, Tk_Item *itemPtr, char *indexString, int *indexPtr); #else typedef int (Tk_ItemIndexProc)(Tcl_Interp *interp, Tk_Canvas canvas, Tk_Item *itemPtr, Tcl_Obj *indexString, int *indexPtr); #endif /* USE_OLD_CANVAS */ typedef void (Tk_ItemCursorProc)(Tk_Canvas canvas, Tk_Item *itemPtr, int index); typedef int (Tk_ItemSelectionProc)(Tk_Canvas canvas, Tk_Item *itemPtr, int offset, char *buffer, int maxBytes); #ifdef USE_OLD_CANVAS typedef void (Tk_ItemInsertProc)(Tk_Canvas canvas, Tk_Item *itemPtr, int beforeThis, char *string); #else typedef void (Tk_ItemInsertProc)(Tk_Canvas canvas, Tk_Item *itemPtr, int beforeThis, Tcl_Obj *string); #endif /* USE_OLD_CANVAS */ typedef void (Tk_ItemDCharsProc)(Tk_Canvas canvas, Tk_Item *itemPtr, int first, int last); #ifndef __NO_OLD_CONFIG typedef struct Tk_ItemType { CONST86 char *name; /* The name of this type of item, such as * "line". */ int itemSize; /* Total amount of space needed for item's * record. */ Tk_ItemCreateProc *createProc; /* Procedure to create a new item of this * type. */ CONST86 Tk_ConfigSpec *configSpecs; /* Pointer to array of configuration specs for * this type. Used for returning configuration * info. */ Tk_ItemConfigureProc *configProc; /* Procedure to call to change configuration * options. */ Tk_ItemCoordProc *coordProc;/* Procedure to call to get and set the item's * coordinates. */ Tk_ItemDeleteProc *deleteProc; /* Procedure to delete existing item of this * type. */ Tk_ItemDisplayProc *displayProc; /* Procedure to display items of this type. */ int alwaysRedraw; /* Non-zero means displayProc should be called * even when the item has been moved * off-screen. */ Tk_ItemPointProc *pointProc;/* Computes distance from item to a given * point. */ Tk_ItemAreaProc *areaProc; /* Computes whether item is inside, outside, * or overlapping an area. */ Tk_ItemPostscriptProc *postscriptProc; /* Procedure to write a Postscript description * for items of this type. */ Tk_ItemScaleProc *scaleProc;/* Procedure to rescale items of this type. */ Tk_ItemTranslateProc *translateProc; /* Procedure to translate items of this * type. */ Tk_ItemIndexProc *indexProc;/* Procedure to determine index of indicated * character. NULL if item doesn't support * indexing. */ Tk_ItemCursorProc *icursorProc; /* Procedure to set insert cursor posn to just * before a given position. */ Tk_ItemSelectionProc *selectionProc; /* Procedure to return selection (in STRING * format) when it is in this item. */ Tk_ItemInsertProc *insertProc; /* Procedure to insert something into an * item. */ Tk_ItemDCharsProc *dCharsProc; /* Procedure to delete characters from an * item. */ struct Tk_ItemType *nextPtr;/* Used to link types together into a list. */ char *reserved1; /* Reserved for future extension. */ int reserved2; /* Carefully compatible with */ char *reserved3; /* Jan Nijtmans dash patch */ char *reserved4; } Tk_ItemType; /* * Flag (used in the alwaysRedraw field) to say whether an item supports * point-level manipulation like the line and polygon items. */ #define TK_MOVABLE_POINTS 2 #endif /* __NO_OLD_CONFIG */ /* * The following structure provides information about the selection and the * insertion cursor. It is needed by only a few items, such as those that * display text. It is shared by the generic canvas code and the item-specific * code, but most of the fields should be written only by the canvas generic * code. */ typedef struct Tk_CanvasTextInfo { Tk_3DBorder selBorder; /* Border and background for selected * characters. Read-only to items.*/ int selBorderWidth; /* Width of border around selection. Read-only * to items. */ XColor *selFgColorPtr; /* Foreground color for selected text. * Read-only to items. */ Tk_Item *selItemPtr; /* Pointer to selected item. NULL means * selection isn't in this canvas. Writable by * items. */ int selectFirst; /* Character index of first selected * character. Writable by items. */ int selectLast; /* Character index of last selected character. * Writable by items. */ Tk_Item *anchorItemPtr; /* Item corresponding to "selectAnchor": not * necessarily selItemPtr. Read-only to * items. */ int selectAnchor; /* Character index of fixed end of selection * (i.e. "select to" operation will use this * as one end of the selection). Writable by * items. */ Tk_3DBorder insertBorder; /* Used to draw vertical bar for insertion * cursor. Read-only to items. */ int insertWidth; /* Total width of insertion cursor. Read-only * to items. */ int insertBorderWidth; /* Width of 3-D border around insert cursor. * Read-only to items. */ Tk_Item *focusItemPtr; /* Item that currently has the input focus, or * NULL if no such item. Read-only to items. */ int gotFocus; /* Non-zero means that the canvas widget has * the input focus. Read-only to items.*/ int cursorOn; /* Non-zero means that an insertion cursor * should be displayed in focusItemPtr. * Read-only to items.*/ } Tk_CanvasTextInfo; /* * Structures used for Dashing and Outline. */ typedef struct Tk_Dash { int number; union { char *pt; char array[sizeof(char *)]; } pattern; } Tk_Dash; typedef struct Tk_TSOffset { int flags; /* Flags; see below for possible values */ int xoffset; /* x offset */ int yoffset; /* y offset */ } Tk_TSOffset; /* * Bit fields in Tk_Offset->flags: */ #define TK_OFFSET_INDEX 1 #define TK_OFFSET_RELATIVE 2 #define TK_OFFSET_LEFT 4 #define TK_OFFSET_CENTER 8 #define TK_OFFSET_RIGHT 16 #define TK_OFFSET_TOP 32 #define TK_OFFSET_MIDDLE 64 #define TK_OFFSET_BOTTOM 128 typedef struct Tk_Outline { GC gc; /* Graphics context. */ double width; /* Width of outline. */ double activeWidth; /* Width of outline. */ double disabledWidth; /* Width of outline. */ int offset; /* Dash offset. */ Tk_Dash dash; /* Dash pattern. */ Tk_Dash activeDash; /* Dash pattern if state is active. */ Tk_Dash disabledDash; /* Dash pattern if state is disabled. */ void *reserved1; /* Reserved for future expansion. */ void *reserved2; void *reserved3; Tk_TSOffset tsoffset; /* Stipple offset for outline. */ XColor *color; /* Outline color. */ XColor *activeColor; /* Outline color if state is active. */ XColor *disabledColor; /* Outline color if state is disabled. */ Pixmap stipple; /* Outline Stipple pattern. */ Pixmap activeStipple; /* Outline Stipple pattern if state is * active. */ Pixmap disabledStipple; /* Outline Stipple pattern if state is * disabled. */ } Tk_Outline; /* *---------------------------------------------------------------------- * * Procedure prototypes and structures used for managing images: * *---------------------------------------------------------------------- */ typedef struct Tk_ImageType Tk_ImageType; #ifdef USE_OLD_IMAGE typedef int (Tk_ImageCreateProc) (Tcl_Interp *interp, char *name, int argc, char **argv, Tk_ImageType *typePtr, Tk_ImageMaster master, ClientData *masterDataPtr); #else typedef int (Tk_ImageCreateProc) (Tcl_Interp *interp, CONST86 char *name, int objc, Tcl_Obj *const objv[], CONST86 Tk_ImageType *typePtr, Tk_ImageMaster master, ClientData *masterDataPtr); #endif /* USE_OLD_IMAGE */ typedef ClientData (Tk_ImageGetProc) (Tk_Window tkwin, ClientData masterData); typedef void (Tk_ImageDisplayProc) (ClientData instanceData, Display *display, Drawable drawable, int imageX, int imageY, int width, int height, int drawableX, int drawableY); typedef void (Tk_ImageFreeProc) (ClientData instanceData, Display *display); typedef void (Tk_ImageDeleteProc) (ClientData masterData); typedef void (Tk_ImageChangedProc) (ClientData clientData, int x, int y, int width, int height, int imageWidth, int imageHeight); typedef int (Tk_ImagePostscriptProc) (ClientData clientData, Tcl_Interp *interp, Tk_Window tkwin, Tk_PostscriptInfo psinfo, int x, int y, int width, int height, int prepass); /* * The following structure represents a particular type of image (bitmap, xpm * image, etc.). It provides information common to all images of that type, * such as the type name and a collection of procedures in the image manager * that respond to various events. Each image manager is represented by one of * these structures. */ struct Tk_ImageType { CONST86 char *name; /* Name of image type. */ Tk_ImageCreateProc *createProc; /* Procedure to call to create a new image of * this type. */ Tk_ImageGetProc *getProc; /* Procedure to call the first time * Tk_GetImage is called in a new way (new * visual or screen). */ Tk_ImageDisplayProc *displayProc; /* Call to draw image, in response to * Tk_RedrawImage calls. */ Tk_ImageFreeProc *freeProc; /* Procedure to call whenever Tk_FreeImage is * called to release an instance of an * image. */ Tk_ImageDeleteProc *deleteProc; /* Procedure to call to delete image. It will * not be called until after freeProc has been * called for each instance of the image. */ Tk_ImagePostscriptProc *postscriptProc; /* Procedure to call to produce postscript * output for the image. */ struct Tk_ImageType *nextPtr; /* Next in list of all image types currently * known. Filled in by Tk, not by image * manager. */ char *reserved; /* reserved for future expansion */ }; /* *---------------------------------------------------------------------- * * Additional definitions used to manage images of type "photo". * *---------------------------------------------------------------------- */ /* * The following type is used to identify a particular photo image to be * manipulated: */ typedef void *Tk_PhotoHandle; /* * The following structure describes a block of pixels in memory: */ typedef struct Tk_PhotoImageBlock { unsigned char *pixelPtr; /* Pointer to the first pixel. */ int width; /* Width of block, in pixels. */ int height; /* Height of block, in pixels. */ int pitch; /* Address difference between corresponding * pixels in successive lines. */ int pixelSize; /* Address difference between successive * pixels in the same line. */ int offset[4]; /* Address differences between the red, green, * blue and alpha components of the pixel and * the pixel as a whole. */ } Tk_PhotoImageBlock; /* * The following values control how blocks are combined into photo images when * the alpha component of a pixel is not 255, a.k.a. the compositing rule. */ #define TK_PHOTO_COMPOSITE_OVERLAY 0 #define TK_PHOTO_COMPOSITE_SET 1 /* * Procedure prototypes and structures used in reading and writing photo * images: */ typedef struct Tk_PhotoImageFormat Tk_PhotoImageFormat; #ifdef USE_OLD_IMAGE typedef int (Tk_ImageFileMatchProc) (Tcl_Channel chan, char *fileName, char *formatString, int *widthPtr, int *heightPtr); typedef int (Tk_ImageStringMatchProc) (char *string, char *formatString, int *widthPtr, int *heightPtr); typedef int (Tk_ImageFileReadProc) (Tcl_Interp *interp, Tcl_Channel chan, char *fileName, char *formatString, Tk_PhotoHandle imageHandle, int destX, int destY, int width, int height, int srcX, int srcY); typedef int (Tk_ImageStringReadProc) (Tcl_Interp *interp, char *string, char *formatString, Tk_PhotoHandle imageHandle, int destX, int destY, int width, int height, int srcX, int srcY); typedef int (Tk_ImageFileWriteProc) (Tcl_Interp *interp, char *fileName, char *formatString, Tk_PhotoImageBlock *blockPtr); typedef int (Tk_ImageStringWriteProc) (Tcl_Interp *interp, Tcl_DString *dataPtr, char *formatString, Tk_PhotoImageBlock *blockPtr); #else typedef int (Tk_ImageFileMatchProc) (Tcl_Channel chan, const char *fileName, Tcl_Obj *format, int *widthPtr, int *heightPtr, Tcl_Interp *interp); typedef int (Tk_ImageStringMatchProc) (Tcl_Obj *dataObj, Tcl_Obj *format, int *widthPtr, int *heightPtr, Tcl_Interp *interp); typedef int (Tk_ImageFileReadProc) (Tcl_Interp *interp, Tcl_Channel chan, const char *fileName, Tcl_Obj *format, Tk_PhotoHandle imageHandle, int destX, int destY, int width, int height, int srcX, int srcY); typedef int (Tk_ImageStringReadProc) (Tcl_Interp *interp, Tcl_Obj *dataObj, Tcl_Obj *format, Tk_PhotoHandle imageHandle, int destX, int destY, int width, int height, int srcX, int srcY); typedef int (Tk_ImageFileWriteProc) (Tcl_Interp *interp, const char *fileName, Tcl_Obj *format, Tk_PhotoImageBlock *blockPtr); typedef int (Tk_ImageStringWriteProc) (Tcl_Interp *interp, Tcl_Obj *format, Tk_PhotoImageBlock *blockPtr); #endif /* USE_OLD_IMAGE */ /* * The following structure represents a particular file format for storing * images (e.g., PPM, GIF, JPEG, etc.). It provides information to allow image * files of that format to be recognized and read into a photo image. */ struct Tk_PhotoImageFormat { CONST86 char *name; /* Name of image file format */ Tk_ImageFileMatchProc *fileMatchProc; /* Procedure to call to determine whether an * image file matches this format. */ Tk_ImageStringMatchProc *stringMatchProc; /* Procedure to call to determine whether the * data in a string matches this format. */ Tk_ImageFileReadProc *fileReadProc; /* Procedure to call to read data from an * image file into a photo image. */ Tk_ImageStringReadProc *stringReadProc; /* Procedure to call to read data from a * string into a photo image. */ Tk_ImageFileWriteProc *fileWriteProc; /* Procedure to call to write data from a * photo image to a file. */ Tk_ImageStringWriteProc *stringWriteProc; /* Procedure to call to obtain a string * representation of the data in a photo * image.*/ struct Tk_PhotoImageFormat *nextPtr; /* Next in list of all photo image formats * currently known. Filled in by Tk, not by * image format handler. */ }; /* *---------------------------------------------------------------------- * * Procedure prototypes and structures used for managing styles: * *---------------------------------------------------------------------- */ /* * Style support version tag. */ #define TK_STYLE_VERSION_1 0x1 #define TK_STYLE_VERSION TK_STYLE_VERSION_1 /* * The following structures and prototypes are used as static templates to * declare widget elements. */ typedef void (Tk_GetElementSizeProc) (ClientData clientData, char *recordPtr, const Tk_OptionSpec **optionsPtr, Tk_Window tkwin, int width, int height, int inner, int *widthPtr, int *heightPtr); typedef void (Tk_GetElementBoxProc) (ClientData clientData, char *recordPtr, const Tk_OptionSpec **optionsPtr, Tk_Window tkwin, int x, int y, int width, int height, int inner, int *xPtr, int *yPtr, int *widthPtr, int *heightPtr); typedef int (Tk_GetElementBorderWidthProc) (ClientData clientData, char *recordPtr, const Tk_OptionSpec **optionsPtr, Tk_Window tkwin); typedef void (Tk_DrawElementProc) (ClientData clientData, char *recordPtr, const Tk_OptionSpec **optionsPtr, Tk_Window tkwin, Drawable d, int x, int y, int width, int height, int state); typedef struct Tk_ElementOptionSpec { char *name; /* Name of the required option. */ Tk_OptionType type; /* Accepted option type. TK_OPTION_END means * any. */ } Tk_ElementOptionSpec; typedef struct Tk_ElementSpec { int version; /* Version of the style support. */ char *name; /* Name of element. */ Tk_ElementOptionSpec *options; /* List of required options. Last one's name * must be NULL. */ Tk_GetElementSizeProc *getSize; /* Compute the external (resp. internal) size * of the element from its desired internal * (resp. external) size. */ Tk_GetElementBoxProc *getBox; /* Compute the inscribed or bounding boxes * within a given area. */ Tk_GetElementBorderWidthProc *getBorderWidth; /* Return the element's internal border width. * Mostly useful for widgets. */ Tk_DrawElementProc *draw; /* Draw the element in the given bounding * box. */ } Tk_ElementSpec; /* * Element state flags. Can be OR'ed. */ #define TK_ELEMENT_STATE_ACTIVE 1<<0 #define TK_ELEMENT_STATE_DISABLED 1<<1 #define TK_ELEMENT_STATE_FOCUS 1<<2 #define TK_ELEMENT_STATE_PRESSED 1<<3 /* *---------------------------------------------------------------------- * * The definitions below provide backward compatibility for functions and * types related to event handling that used to be in Tk but have moved to * Tcl. * *---------------------------------------------------------------------- */ #define TK_READABLE TCL_READABLE #define TK_WRITABLE TCL_WRITABLE #define TK_EXCEPTION TCL_EXCEPTION #define TK_DONT_WAIT TCL_DONT_WAIT #define TK_X_EVENTS TCL_WINDOW_EVENTS #define TK_WINDOW_EVENTS TCL_WINDOW_EVENTS #define TK_FILE_EVENTS TCL_FILE_EVENTS #define TK_TIMER_EVENTS TCL_TIMER_EVENTS #define TK_IDLE_EVENTS TCL_IDLE_EVENTS #define TK_ALL_EVENTS TCL_ALL_EVENTS #define Tk_IdleProc Tcl_IdleProc #define Tk_FileProc Tcl_FileProc #define Tk_TimerProc Tcl_TimerProc #define Tk_TimerToken Tcl_TimerToken #define Tk_BackgroundError Tcl_BackgroundError #define Tk_CancelIdleCall Tcl_CancelIdleCall #define Tk_CreateFileHandler Tcl_CreateFileHandler #define Tk_CreateTimerHandler Tcl_CreateTimerHandler #define Tk_DeleteFileHandler Tcl_DeleteFileHandler #define Tk_DeleteTimerHandler Tcl_DeleteTimerHandler #define Tk_DoOneEvent Tcl_DoOneEvent #define Tk_DoWhenIdle Tcl_DoWhenIdle #define Tk_Sleep Tcl_Sleep /* Additional stuff that has moved to Tcl: */ #define Tk_EventuallyFree Tcl_EventuallyFree #define Tk_FreeProc Tcl_FreeProc #define Tk_Preserve Tcl_Preserve #define Tk_Release Tcl_Release /* Removed Tk_Main, use macro instead */ #if defined(__WIN32__) || defined(__CYGWIN__) #define Tk_Main(argc, argv, proc) Tk_MainEx(argc, argv, proc, \ (Tcl_FindExecutable(0), (Tcl_CreateInterp)())) #else #define Tk_Main(argc, argv, proc) Tk_MainEx(argc, argv, proc, \ (Tcl_FindExecutable(argv[0]), (Tcl_CreateInterp)())) #endif const char * Tk_InitStubs(Tcl_Interp *interp, const char *version, int exact); EXTERN const char * Tk_PkgInitStubsCheck(Tcl_Interp *interp, const char *version, int exact); #ifndef USE_TK_STUBS #define Tk_InitStubs(interp, version, exact) \ Tk_PkgInitStubsCheck(interp, version, exact) #endif /* USE_TK_STUBS */ #define Tk_InitImageArgs(interp, argc, argv) /**/ /* *---------------------------------------------------------------------- * * Additional procedure types defined by Tk. * *---------------------------------------------------------------------- */ typedef int (Tk_ErrorProc) (ClientData clientData, XErrorEvent *errEventPtr); typedef void (Tk_EventProc) (ClientData clientData, XEvent *eventPtr); typedef int (Tk_GenericProc) (ClientData clientData, XEvent *eventPtr); typedef int (Tk_ClientMessageProc) (Tk_Window tkwin, XEvent *eventPtr); typedef int (Tk_GetSelProc) (ClientData clientData, Tcl_Interp *interp, CONST86 char *portion); typedef void (Tk_LostSelProc) (ClientData clientData); typedef Tk_RestrictAction (Tk_RestrictProc) (ClientData clientData, XEvent *eventPtr); typedef int (Tk_SelectionProc) (ClientData clientData, int offset, char *buffer, int maxBytes); /* *---------------------------------------------------------------------- * * Platform independent exported procedures and variables. * *---------------------------------------------------------------------- */ #include "tkDecls.h" #ifdef USE_OLD_IMAGE #undef Tk_CreateImageType #define Tk_CreateImageType Tk_CreateOldImageType #undef Tk_CreatePhotoImageFormat #define Tk_CreatePhotoImageFormat Tk_CreateOldPhotoImageFormat #endif /* USE_OLD_IMAGE */ /* *---------------------------------------------------------------------- * * Allow users to say that they don't want to alter their source to add extra * arguments to Tk_PhotoPutBlock() et al; DO NOT DEFINE THIS WHEN BUILDING TK. * * This goes after the inclusion of the stubbed-decls so that the declarations * of what is actually there can be correct. */ #ifdef USE_COMPOSITELESS_PHOTO_PUT_BLOCK # ifdef Tk_PhotoPutBlock # undef Tk_PhotoPutBlock # endif # define Tk_PhotoPutBlock Tk_PhotoPutBlock_NoComposite # ifdef Tk_PhotoPutZoomedBlock # undef Tk_PhotoPutZoomedBlock # endif # define Tk_PhotoPutZoomedBlock Tk_PhotoPutZoomedBlock_NoComposite # define USE_PANIC_ON_PHOTO_ALLOC_FAILURE #else /* !USE_COMPOSITELESS_PHOTO_PUT_BLOCK */ # ifdef USE_PANIC_ON_PHOTO_ALLOC_FAILURE # ifdef Tk_PhotoPutBlock # undef Tk_PhotoPutBlock # endif # define Tk_PhotoPutBlock Tk_PhotoPutBlock_Panic # ifdef Tk_PhotoPutZoomedBlock # undef Tk_PhotoPutZoomedBlock # endif # define Tk_PhotoPutZoomedBlock Tk_PhotoPutZoomedBlock_Panic # endif /* USE_PANIC_ON_PHOTO_ALLOC_FAILURE */ #endif /* USE_COMPOSITELESS_PHOTO_PUT_BLOCK */ #ifdef USE_PANIC_ON_PHOTO_ALLOC_FAILURE # ifdef Tk_PhotoExpand # undef Tk_PhotoExpand # endif # define Tk_PhotoExpand Tk_PhotoExpand_Panic # ifdef Tk_PhotoSetSize # undef Tk_PhotoSetSize # endif # define Tk_PhotoSetSize Tk_PhotoSetSize_Panic #endif /* USE_PANIC_ON_PHOTO_ALLOC_FAILURE */ #undef TCL_STORAGE_CLASS #define TCL_STORAGE_CLASS DLLIMPORT #endif /* RC_INVOKED */ /* * end block for C++ */ #ifdef __cplusplus } #endif #endif /* _TK */ /* * Local Variables: * mode: c * c-basic-offset: 4 * fill-column: 78 * End: */ tk8.6.1/generic/tkBind.c0000644003604700454610000036110412211355622013461 0ustar dgp771div/* * tkBind.c -- * * This file provides functions 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-1997 Sun Microsystems, Inc. * Copyright (c) 1998 by Scriptics Corporation. * * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. */ #include "tkInt.h" #ifdef __WIN32__ #include "tkWinInt.h" #endif #if !(defined(__WIN32__) || defined(MAC_OSX_TK)) /* UNIX */ #include "tkUnixInt.h" #endif /* * File structure: * * Structure definitions and static variables. * * Init/Free this package. * * Tcl "bind" command (actually located in tkCmds.c) core implementation, plus * helpers. * * Tcl "event" command implementation, plus 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; /* * 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 Tk_BindingTable_ { XEvent eventRing[EVENT_BUFFER_SIZE]; /* Circular queue of recent events (higher * indices are for more recent events). */ Detail detailRing[EVENT_BUFFER_SIZE]; /* "Detail" information (keySym, button, * Tk_Uid, or 0) for each entry in * eventRing. */ int curEvent; /* Index in eventRing of most recent event. * Newer events have higher indices. */ Tcl_HashTable patternTable; /* Used to map from an event to a list of * patterns that may match that event. Keys * are PatternTableKey structs, values are * (PatSeq *). */ Tcl_HashTable objectTable; /* Used to map from an object to a list of * patterns associated with that object. Keys * are ClientData, values are (PatSeq *). */ Tcl_Interp *interp; /* Interpreter in which commands are * 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 <>, * <>, or <>. * * 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 commands. 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 { 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. */ typedef struct { 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. */ int type; /* Type of event (from X). */ Detail detail; /* Additional information, such as keysym, * button, Tk_Uid, or 0 if nothing * additional. */ } PatternTableKey; /* * 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 { int eventType; /* Type of X event, e.g. ButtonPress. */ int needMods; /* Mask of modifiers that must be present (0 * means no modifiers are required). */ Detail detail; /* Additional information that must 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 { int numPats; /* Number of patterns in sequence (usually * 1). */ char *script; /* Binding script to evaluate when sequence * matches (ckalloc()ed) */ int flags; /* Miscellaneous flag values; see below for * definitions. */ 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. */ } 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. */ #define PAT_NEARBY 0x1 /* * 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 /* * 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 { 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; /* * 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 * command can be invoked whenever the display/screen changes (the command does * things like point tk::Priv at a display-specific structure). */ typedef struct { 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; /* * The following structure keeps track of all the information local to the * binding package on a per interpreter basis. */ typedef struct TkBindInfo_ { 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. */ int deleted; /* 1 the application has been deleted but the * structure has been preserved. */ } BindInfo; /* * 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 { const char *name; /* Name of keysym. */ KeySym value; /* Numeric identifier for keysym. */ } KeySymInfo; static const KeySymInfo keyArray[] = { #ifndef lint #include "ks_names.h" #endif {NULL, 0} }; static Tcl_HashTable keySymTable; /* keyArray hashed by keysym value. */ static Tcl_HashTable nameTable; /* keyArray hashed by keysym name. */ #endif /* REDO_KEYSYM_LOOKUP */ /* * Set to non-zero when the package-wide static variables have been * initialized. */ static int initialized = 0; TCL_DECLARE_MUTEX(bindMutex) /* * 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 { const 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. * QUADRUPLE - Non-zero means quadruple this event, * e.g. for 4-fold-clicks. * MULT_CLICKS - Combination of all of above. */ #define DOUBLE 1 #define TRIPLE 2 #define QUADRUPLE 4 #define MULT_CLICKS 7 static const ModInfo modArray[] = { {"Control", ControlMask, 0}, {"Shift", ShiftMask, 0}, {"Lock", LockMask, 0}, {"Meta", META_MASK, 0}, {"M", META_MASK, 0}, {"Alt", ALT_MASK, 0}, {"Extended", EXTENDED_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}, {"Quadruple", 0, QUADRUPLE}, {"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 { const 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 const EventInfo eventArray[] = { {"Key", KeyPress, KeyPressMask}, {"KeyPress", KeyPress, KeyPressMask}, {"KeyRelease", KeyRelease, KeyPressMask|KeyReleaseMask}, {"Button", ButtonPress, ButtonPressMask}, {"ButtonPress", ButtonPress, ButtonPressMask}, {"ButtonRelease", ButtonRelease, ButtonPressMask|ButtonReleaseMask}, {"Motion", MotionNotify, ButtonPressMask|PointerMotionMask}, {"Enter", EnterNotify, EnterWindowMask}, {"Leave", LeaveNotify, LeaveWindowMask}, {"FocusIn", FocusIn, FocusChangeMask}, {"FocusOut", FocusOut, FocusChangeMask}, {"Expose", Expose, ExposureMask}, {"Visibility", VisibilityNotify, VisibilityChangeMask}, {"Destroy", DestroyNotify, StructureNotifyMask}, {"Unmap", UnmapNotify, StructureNotifyMask}, {"Map", MapNotify, StructureNotifyMask}, {"Reparent", ReparentNotify, StructureNotifyMask}, {"Configure", ConfigureNotify, StructureNotifyMask}, {"Gravity", GravityNotify, StructureNotifyMask}, {"Circulate", CirculateNotify, StructureNotifyMask}, {"Property", PropertyNotify, PropertyChangeMask}, {"Colormap", ColormapNotify, ColormapChangeMask}, {"Activate", ActivateNotify, ActivateMask}, {"Deactivate", DeactivateNotify, ActivateMask}, {"MouseWheel", MouseWheelEvent, MouseWheelMask}, {"CirculateRequest", CirculateRequest, SubstructureRedirectMask}, {"ConfigureRequest", ConfigureRequest, SubstructureRedirectMask}, {"Create", CreateNotify, SubstructureNotifyMask}, {"MapRequest", MapRequest, SubstructureRedirectMask}, {"ResizeRequest", ResizeRequest, ResizeRedirectMask}, {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. */ #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 #define COLORMAP 0x10000 #define VIRTUAL 0x20000 #define ACTIVATE 0x40000 #define MAPREQ 0x80000 #define CONFIGREQ 0x100000 #define RESIZEREQ 0x200000 #define CIRCREQ 0x400000 #define KEY_BUTTON_MOTION_VIRTUAL (KEY|BUTTON|MOTION|VIRTUAL) #define KEY_BUTTON_MOTION_CROSSING (KEY|BUTTON|MOTION|VIRTUAL|CROSSING) static const int flagArray[TK_LASTEVENT] = { /* 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 */ MAPREQ, /* ReparentNotify */ REPARENT, /* ConfigureNotify */ CONFIG, /* ConfigureRequest */ CONFIGREQ, /* GravityNotify */ GRAVITY, /* ResizeRequest */ RESIZEREQ, /* CirculateNotify */ CIRC, /* CirculateRequest */ 0, /* PropertyNotify */ PROP, /* SelectionClear */ 0, /* SelectionRequest */ 0, /* SelectionNotify */ 0, /* ColormapNotify */ COLORMAP, /* ClientMessage */ 0, /* MappingNotify */ 0, /* VirtualEvent */ VIRTUAL, /* Activate */ ACTIVATE, /* Deactivate */ ACTIVATE, /* MouseWheel */ KEY }; /* * The following table is used to map between the location where an generated * event should be queued and the string used to specify the location. */ static const TkStateMap queuePosition[] = { {-1, "now"}, {TCL_QUEUE_HEAD, "head"}, {TCL_QUEUE_MARK, "mark"}, {TCL_QUEUE_TAIL, "tail"}, {-2, NULL} }; /* * 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 const TkStateMap notifyMode[] = { {NotifyNormal, "NotifyNormal"}, {NotifyGrab, "NotifyGrab"}, {NotifyUngrab, "NotifyUngrab"}, {NotifyWhileGrabbed, "NotifyWhileGrabbed"}, {-1, NULL} }; static const TkStateMap notifyDetail[] = { {NotifyAncestor, "NotifyAncestor"}, {NotifyVirtual, "NotifyVirtual"}, {NotifyInferior, "NotifyInferior"}, {NotifyNonlinear, "NotifyNonlinear"}, {NotifyNonlinearVirtual, "NotifyNonlinearVirtual"}, {NotifyPointer, "NotifyPointer"}, {NotifyPointerRoot, "NotifyPointerRoot"}, {NotifyDetailNone, "NotifyDetailNone"}, {-1, NULL} }; static const TkStateMap circPlace[] = { {PlaceOnTop, "PlaceOnTop"}, {PlaceOnBottom, "PlaceOnBottom"}, {-1, NULL} }; static const TkStateMap visNotify[] = { {VisibilityUnobscured, "VisibilityUnobscured"}, {VisibilityPartiallyObscured, "VisibilityPartiallyObscured"}, {VisibilityFullyObscured, "VisibilityFullyObscured"}, {-1, NULL} }; static const TkStateMap configureRequestDetail[] = { {None, "None"}, {Above, "Above"}, {Below, "Below"}, {BottomIf, "BottomIf"}, {TopIf, "TopIf"}, {Opposite, "Opposite"}, {-1, NULL} }; static const TkStateMap propNotify[] = { {PropertyNewValue, "NewValue"}, {PropertyDelete, "Delete"}, {-1, NULL} }; /* * Prototypes for local functions defined in this file: */ static void ChangeScreen(Tcl_Interp *interp, char *dispName, int screenIndex); static int CreateVirtualEvent(Tcl_Interp *interp, VirtualEventTable *vetPtr, char *virtString, const char *eventString); static int DeleteVirtualEvent(Tcl_Interp *interp, VirtualEventTable *vetPtr, char *virtString, const char *eventString); static void DeleteVirtualEventTable(VirtualEventTable *vetPtr); static void ExpandPercents(TkWindow *winPtr, const char *before, XEvent *eventPtr,KeySym keySym,Tcl_DString *dsPtr); static PatSeq * FindSequence(Tcl_Interp *interp, Tcl_HashTable *patternTablePtr, ClientData object, const char *eventString, int create, int allowVirtual, unsigned long *maskPtr); static void GetAllVirtualEvents(Tcl_Interp *interp, VirtualEventTable *vetPtr); static char * GetField(char *p, char *copy, int size); static Tcl_Obj * GetPatternObj(PatSeq *psPtr); static int GetVirtualEvent(Tcl_Interp *interp, VirtualEventTable *vetPtr, Tcl_Obj *virtName); static Tk_Uid GetVirtualEventUid(Tcl_Interp *interp, char *virtString); static int HandleEventGenerate(Tcl_Interp *interp, Tk_Window main, int objc, Tcl_Obj *const objv[]); static void InitVirtualEventTable(VirtualEventTable *vetPtr); static PatSeq * MatchPatterns(TkDisplay *dispPtr, BindingTable *bindPtr, PatSeq *psPtr, PatSeq *bestPtr, ClientData *objectPtr, PatSeq **sourcePtrPtr); static int NameToWindow(Tcl_Interp *interp, Tk_Window main, Tcl_Obj *objPtr, Tk_Window *tkwinPtr); static int ParseEventDescription(Tcl_Interp *interp, const char **eventStringPtr, Pattern *patPtr, unsigned long *eventMaskPtr); static void DoWarp(ClientData clientData); /* *--------------------------------------------------------------------------- * * TkBindInit -- * * This function 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. * * Results: * None. * * Side effects: * Memory allocated. * *--------------------------------------------------------------------------- */ void TkBindInit( TkMainInfo *mainPtr) /* The newly created application. */ { BindInfo *bindInfoPtr; if (sizeof(XEvent) < sizeof(XVirtualEvent)) { Tcl_Panic("TkBindInit: virtual events can't be supported"); } /* * Initialize the static data structures used by the binding package. They * are only initialized once, no matter how many interps are created. */ if (!initialized) { Tcl_MutexLock(&bindMutex); if (!initialized) { Tcl_HashEntry *hPtr; const ModInfo *modPtr; const EventInfo *eiPtr; int newEntry; #ifdef REDO_KEYSYM_LOOKUP const KeySymInfo *kPtr; 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, &newEntry); Tcl_SetHashValue(hPtr, kPtr->value); hPtr = Tcl_CreateHashEntry(&nameTable, (char *) kPtr->value, &newEntry); if (newEntry) { 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, &newEntry); Tcl_SetHashValue(hPtr, modPtr); } Tcl_InitHashTable(&eventTable, TCL_STRING_KEYS); for (eiPtr = eventArray; eiPtr->name != NULL; eiPtr++) { hPtr = Tcl_CreateHashEntry(&eventTable, eiPtr->name, &newEntry); Tcl_SetHashValue(hPtr, eiPtr); } initialized = 1; } Tcl_MutexUnlock(&bindMutex); } mainPtr->bindingTable = Tk_CreateBindingTable(mainPtr->interp); bindInfoPtr = ckalloc(sizeof(BindInfo)); InitVirtualEventTable(&bindInfoPtr->virtualEventTable); bindInfoPtr->screenInfo.curDispPtr = NULL; bindInfoPtr->screenInfo.curScreenIndex = -1; bindInfoPtr->screenInfo.bindingDepth = 0; bindInfoPtr->deleted = 0; mainPtr->bindInfo = bindInfoPtr; TkpInitializeMenuBindings(mainPtr->interp, mainPtr->bindingTable); } /* *--------------------------------------------------------------------------- * * TkBindFree -- * * This function 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( TkMainInfo *mainPtr) /* The newly created application. */ { BindInfo *bindInfoPtr; Tk_DeleteBindingTable(mainPtr->bindingTable); mainPtr->bindingTable = NULL; bindInfoPtr = mainPtr->bindInfo; DeleteVirtualEventTable(&bindInfoPtr->virtualEventTable); bindInfoPtr->deleted = 1; Tcl_EventuallyFree(bindInfoPtr, TCL_DYNAMIC); 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 * functions like Tk_CreateBinding. * * Side effects: * Memory is allocated for the new table. * *-------------------------------------------------------------- */ Tk_BindingTable Tk_CreateBindingTable( Tcl_Interp *interp) /* Interpreter to associate with the binding * table: commands are executed in this * interpreter. */ { BindingTable *bindPtr = ckalloc(sizeof(BindingTable)); int i; /* * Create and initialize a new binding table. */ 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 bindPtr; } /* *-------------------------------------------------------------- * * Tk_DeleteBindingTable -- * * Destroy a binding table and free up all its memory. The caller should * not use bindingTable again after this function returns. * * Results: * None. * * Side effects: * Memory is freed. * *-------------------------------------------------------------- */ void Tk_DeleteBindingTable( Tk_BindingTable bindPtr) /* Token for the binding table to destroy. */ { 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 = Tcl_GetHashValue(hPtr); psPtr != NULL; psPtr = nextPtr) { nextPtr = psPtr->nextSeqPtr; ckfree(psPtr->script); ckfree(psPtr); } } /* * Clean up the rest of the information associated with the binding table. */ Tcl_DeleteHashTable(&bindPtr->patternTable); Tcl_DeleteHashTable(&bindPtr->objectTable); ckfree(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 the interp's * 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: * An existing binding on the same event sequence may be replaced. The * new binding may cause future calls to Tk_BindEvent to behave * differently than they did previously. * *-------------------------------------------------------------- */ unsigned long Tk_CreateBinding( Tcl_Interp *interp, /* Used for error reporting. */ Tk_BindingTable bindPtr, /* Table in which to create binding. */ ClientData object, /* Token for object with which binding is * associated. */ const char *eventString, /* String describing event sequence that * triggers binding. */ const char *script, /* Contains Tcl script 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. */ { PatSeq *psPtr; unsigned long eventMask; char *newStr, *oldStr; if (!*script) { /* Silently ignore empty scripts -- see SF#3006842 */ return 1; } psPtr = FindSequence(interp, &bindPtr->patternTable, object, eventString, 1, 1, &eventMask); if (psPtr == NULL) { return 0; } if (psPtr->script == NULL) { int isNew; Tcl_HashEntry *hPtr; /* * This pattern sequence was just created. Link the pattern into the * list associated with the object, so that if the object goes away, * these bindings will all automatically be deleted. */ hPtr = Tcl_CreateHashEntry(&bindPtr->objectTable, (char *) object, &isNew); if (isNew) { psPtr->nextObjPtr = NULL; } else { psPtr->nextObjPtr = Tcl_GetHashValue(hPtr); } Tcl_SetHashValue(hPtr, psPtr); } oldStr = psPtr->script; if ((append != 0) && (oldStr != NULL)) { size_t length1 = strlen(oldStr), length2 = strlen(script); newStr = ckalloc(length1 + length2 + 2); memcpy(newStr, oldStr, length1); newStr[length1] = '\n'; memcpy(newStr+length1+1, script, length2+1); } else { size_t length = strlen(script); newStr = ckalloc(length + 1); memcpy(newStr, script, length+1); } if (oldStr != NULL) { ckfree(oldStr); } psPtr->script = newStr; 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 the * interp's result will contain an error message. * * Side effects: * The binding given by object and eventString is removed from * bindingTable. * *-------------------------------------------------------------- */ int Tk_DeleteBinding( Tcl_Interp *interp, /* Used for error reporting. */ Tk_BindingTable bindPtr, /* Table in which to delete binding. */ ClientData object, /* Token for object with which binding is * associated. */ const char *eventString) /* String describing event sequence that * triggers binding. */ { PatSeq *psPtr, *prevPtr; unsigned long eventMask; Tcl_HashEntry *hPtr; psPtr = FindSequence(interp, &bindPtr->patternTable, object, eventString, 0, 1, &eventMask); if (psPtr == NULL) { Tcl_ResetResult(interp); return TCL_OK; } /* * Unlink the binding from the list for its object, then from the list for * its pattern. */ hPtr = Tcl_FindHashEntry(&bindPtr->objectTable, (char *) object); if (hPtr == NULL) { Tcl_Panic("Tk_DeleteBinding couldn't find object table entry"); } prevPtr = Tcl_GetHashValue(hPtr); if (prevPtr == psPtr) { Tcl_SetHashValue(hPtr, psPtr->nextObjPtr); } else { for ( ; ; prevPtr = prevPtr->nextObjPtr) { if (prevPtr == NULL) { Tcl_Panic("Tk_DeleteBinding couldn't find on object list"); } if (prevPtr->nextObjPtr == psPtr) { prevPtr->nextObjPtr = psPtr->nextObjPtr; break; } } } prevPtr = Tcl_GetHashValue(psPtr->hPtr); if (prevPtr == psPtr) { if (psPtr->nextSeqPtr == NULL) { Tcl_DeleteHashEntry(psPtr->hPtr); } else { Tcl_SetHashValue(psPtr->hPtr, psPtr->nextSeqPtr); } } else { for ( ; ; prevPtr = prevPtr->nextSeqPtr) { if (prevPtr == NULL) { Tcl_Panic("Tk_DeleteBinding couldn't find on hash chain"); } if (prevPtr->nextSeqPtr == psPtr) { prevPtr->nextSeqPtr = psPtr->nextSeqPtr; break; } } } ckfree(psPtr->script); ckfree(psPtr); return TCL_OK; } /* *-------------------------------------------------------------- * * Tk_GetBinding -- * * Return the script associated with a given event string. * * Results: * The return value is a pointer to the script 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 the interp's * result. The return value is semi-static: it will persist until the * binding is changed or deleted. * * Side effects: * None. * *-------------------------------------------------------------- */ const char * Tk_GetBinding( Tcl_Interp *interp, /* Interpreter for error reporting. */ Tk_BindingTable bindPtr, /* Table in which to look for binding. */ ClientData object, /* Token for object with which binding is * associated. */ const char *eventString) /* String describing event sequence that * triggers binding. */ { PatSeq *psPtr; unsigned long eventMask; psPtr = FindSequence(interp, &bindPtr->patternTable, object, eventString, 0, 1, &eventMask); if (psPtr == NULL) { return NULL; } return psPtr->script; } /* *-------------------------------------------------------------- * * Tk_GetAllBindings -- * * Return a list of event strings for all the bindings associated with a * given object. * * Results: * There is no return value. The interp's 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 Tk_GetAllBindings( Tcl_Interp *interp, /* Interpreter returning result or error. */ Tk_BindingTable bindPtr, /* Table in which to look for bindings. */ ClientData object) /* Token for object. */ { PatSeq *psPtr; Tcl_HashEntry *hPtr; Tcl_Obj *resultObj; hPtr = Tcl_FindHashEntry(&bindPtr->objectTable, (char *) object); if (hPtr == NULL) { return; } resultObj = Tcl_NewObj(); for (psPtr = Tcl_GetHashValue(hPtr); psPtr != NULL; psPtr = psPtr->nextObjPtr) { /* * For each binding, output information about each of the patterns in * its sequence. */ Tcl_ListObjAppendElement(NULL, resultObj, GetPatternObj(psPtr)); } Tcl_SetObjResult(interp, resultObj); } /* *-------------------------------------------------------------- * * 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 Tk_DeleteAllBindings( Tk_BindingTable bindPtr, /* Table in which to delete bindings. */ ClientData object) /* Token for object. */ { PatSeq *psPtr, *prevPtr; PatSeq *nextPtr; Tcl_HashEntry *hPtr; hPtr = Tcl_FindHashEntry(&bindPtr->objectTable, (char *) object); if (hPtr == NULL) { return; } for (psPtr = Tcl_GetHashValue(hPtr); psPtr != NULL; psPtr = nextPtr) { nextPtr = psPtr->nextObjPtr; /* * 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. */ prevPtr = Tcl_GetHashValue(psPtr->hPtr); if (prevPtr == psPtr) { if (psPtr->nextSeqPtr == NULL) { Tcl_DeleteHashEntry(psPtr->hPtr); } else { Tcl_SetHashValue(psPtr->hPtr, psPtr->nextSeqPtr); } } else { for ( ; ; prevPtr = prevPtr->nextSeqPtr) { if (prevPtr == NULL) { Tcl_Panic("Tk_DeleteAllBindings couldn't find on hash chain"); } if (prevPtr->nextSeqPtr == psPtr) { prevPtr->nextSeqPtr = psPtr->nextSeqPtr; break; } } } ckfree(psPtr->script); ckfree(psPtr); } Tcl_DeleteHashEntry(hPtr); } /* *--------------------------------------------------------------------------- * * Tk_BindEvent -- * * This function 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 script associated with the matching binding. * * All Tcl binding scripts for each object are accumulated before the * first binding is evaluated. If the action of a Tcl binding is to * change or delete a binding, or delete the window associated with the * binding, all the original Tcl binding scripts will still fire. * *--------------------------------------------------------------------------- */ void Tk_BindEvent( Tk_BindingTable bindPtr, /* Table in which to look for bindings. */ XEvent *eventPtr, /* What actually happened. */ Tk_Window tkwin, /* Window on display where event occurred * (needed in order to locate display * information). */ int numObjects, /* Number of objects at *objectPtr. */ ClientData *objectPtr) /* Array of one or more objects to check for a * matching binding. */ { TkDisplay *dispPtr; ScreenInfo *screenPtr; BindInfo *bindInfoPtr; TkDisplay *oldDispPtr; XEvent *ringPtr; PatSeq *vMatchDetailList, *vMatchNoDetailList; int flags, oldScreen; Tcl_Interp *interp; Tcl_DString scripts; Tcl_InterpState interpState; Detail detail; char *p, *end; TkWindow *winPtr = (TkWindow *) tkwin; PatternTableKey key; /* * Ignore events on windows that don't have names: these are windows like * wrapper windows that shouldn't be visible to the application. */ if (winPtr->pathName == NULL) { return; } /* * 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. */ if ((eventPtr->type == EnterNotify) || (eventPtr->type == LeaveNotify)) { if (eventPtr->xcrossing.detail == NotifyInferior) { return; } } if ((eventPtr->type == FocusIn) || (eventPtr->type == FocusOut)) { if (eventPtr->xfocus.detail == NotifyInferior) { return; } } dispPtr = ((TkWindow *) tkwin)->dispPtr; bindInfoPtr = winPtr->mainPtr->bindInfo; /* * 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). */ if ((eventPtr->type == MotionNotify) && (bindPtr->eventRing[bindPtr->curEvent].type == MotionNotify)) { /* * Don't advance the ring pointer. */ } else if (eventPtr->type == KeyPress) { int i; for (i = 0; ; i++) { if (i >= dispPtr->numModKeyCodes) { goto advanceRingPointer; } if (dispPtr->modKeyCodes[i] == eventPtr->xkey.keycode) { break; } } ringPtr = &bindPtr->eventRing[bindPtr->curEvent]; if ((ringPtr->type != KeyRelease) || (ringPtr->xkey.keycode != eventPtr->xkey.keycode)) { goto advanceRingPointer; } if (bindPtr->curEvent <= 0) { i = EVENT_BUFFER_SIZE - 1; } else { i = bindPtr->curEvent - 1; } ringPtr = &bindPtr->eventRing[i]; if ((ringPtr->type != KeyPress) || (ringPtr->xkey.keycode != eventPtr->xkey.keycode)) { goto advanceRingPointer; } bindPtr->eventRing[bindPtr->curEvent].type = -1; bindPtr->curEvent = i; } else { advanceRingPointer: bindPtr->curEvent++; if (bindPtr->curEvent >= EVENT_BUFFER_SIZE) { bindPtr->curEvent = 0; } } ringPtr = &bindPtr->eventRing[bindPtr->curEvent]; memcpy(ringPtr, eventPtr, sizeof(XEvent)); detail.clientData = 0; flags = flagArray[ringPtr->type]; if (flags & KEY) { detail.keySym = TkpGetKeySym(dispPtr, ringPtr); if (detail.keySym == NoSymbol) { detail.keySym = 0; } } else if (flags & BUTTON) { detail.button = ringPtr->xbutton.button; } else if (flags & VIRTUAL) { detail.name = ((XVirtualEvent *) ringPtr)->name; } bindPtr->detailRing[bindPtr->curEvent] = detail; /* * Find out if there are any virtual events that correspond to this * physical event (or sequence of physical events). */ vMatchDetailList = NULL; vMatchNoDetailList = NULL; memset(&key, 0, sizeof(key)); if (ringPtr->type != VirtualEvent) { Tcl_HashTable *veptPtr = &bindInfoPtr->virtualEventTable.patternTable; Tcl_HashEntry *hPtr; key.object = NULL; key.type = ringPtr->type; key.detail = detail; hPtr = Tcl_FindHashEntry(veptPtr, (char *) &key); if (hPtr != NULL) { vMatchDetailList = Tcl_GetHashValue(hPtr); } if (key.detail.clientData != 0) { key.detail.clientData = 0; hPtr = Tcl_FindHashEntry(veptPtr, (char *) &key); if (hPtr != NULL) { vMatchNoDetailList = Tcl_GetHashValue(hPtr); } } } /* * Loop over all the binding tags, finding the binding script or callback * for each one. Append all of the binding scripts, with %-sequences * expanded, to "scripts", with null characters separating the scripts for * each object. */ Tcl_DStringInit(&scripts); for ( ; numObjects > 0; numObjects--, objectPtr++) { PatSeq *matchPtr = NULL, *sourcePtr = NULL; Tcl_HashEntry *hPtr; /* * 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. */ key.object = *objectPtr; key.type = ringPtr->type; key.detail = detail; hPtr = Tcl_FindHashEntry(&bindPtr->patternTable, (char *) &key); if (hPtr != NULL) { matchPtr = MatchPatterns(dispPtr, bindPtr, Tcl_GetHashValue(hPtr), matchPtr, NULL, &sourcePtr); } if (vMatchDetailList != NULL) { matchPtr = MatchPatterns(dispPtr, bindPtr, vMatchDetailList, matchPtr, objectPtr, &sourcePtr); } /* * If no match was found, look for a binding for all keys or buttons * (detail of 0). Again, first match on a virtual event. */ if ((detail.clientData != 0) && (matchPtr == NULL)) { key.detail.clientData = 0; hPtr = Tcl_FindHashEntry(&bindPtr->patternTable, (char *) &key); if (hPtr != NULL) { matchPtr = MatchPatterns(dispPtr, bindPtr, Tcl_GetHashValue(hPtr), matchPtr, NULL, &sourcePtr); } if (vMatchNoDetailList != NULL) { matchPtr = MatchPatterns(dispPtr, bindPtr, vMatchNoDetailList, matchPtr, objectPtr, &sourcePtr); } } if (matchPtr != NULL) { ExpandPercents(winPtr, sourcePtr->script, eventPtr, detail.keySym, &scripts); /* * A "" is added to the scripts string to separate the various * scripts that should be invoked. */ Tcl_DStringAppend(&scripts, "", 1); } } if (Tcl_DStringLength(&scripts) == 0) { return; } /* * Now go back through and evaluate the binding 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 * the interp's 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. */ interp = bindPtr->interp; /* * Save information about the current screen, then invoke a script if the * screen has changed. */ interpState = Tcl_SaveInterpState(interp, TCL_OK); screenPtr = &bindInfoPtr->screenInfo; oldDispPtr = screenPtr->curDispPtr; oldScreen = screenPtr->curScreenIndex; if ((dispPtr != screenPtr->curDispPtr) || (Tk_ScreenNumber(tkwin) != screenPtr->curScreenIndex)) { screenPtr->curDispPtr = dispPtr; screenPtr->curScreenIndex = Tk_ScreenNumber(tkwin); ChangeScreen(interp, dispPtr->name, screenPtr->curScreenIndex); } p = Tcl_DStringValue(&scripts); end = p + Tcl_DStringLength(&scripts); /* * Be careful when dereferencing screenPtr or bindInfoPtr. If we evaluate * something that destroys ".", bindInfoPtr would have been freed, but we * can tell that by first checking to see if winPtr->mainPtr == NULL. */ Tcl_Preserve(bindInfoPtr); while (p < end) { int len = (int) strlen(p); int code; if (!bindInfoPtr->deleted) { screenPtr->bindingDepth++; } Tcl_AllowExceptions(interp); code = Tcl_EvalEx(interp, p, len, TCL_EVAL_GLOBAL); p += len + 1; if (!bindInfoPtr->deleted) { screenPtr->bindingDepth--; } if (code != TCL_OK) { if (code == TCL_CONTINUE) { /* * Do nothing: just go on to the next command. */ } else if (code == TCL_BREAK) { break; } else { Tcl_AddErrorInfo(interp, "\n (command bound to event)"); Tcl_BackgroundException(interp, code); break; } } } if (!bindInfoPtr->deleted && (screenPtr->bindingDepth != 0) && ((oldDispPtr != screenPtr->curDispPtr) || (oldScreen != screenPtr->curScreenIndex))) { /* * Some other binding script is currently executing, but its screen is * no longer current. Change the current display back again. */ screenPtr->curDispPtr = oldDispPtr; screenPtr->curScreenIndex = oldScreen; ChangeScreen(interp, oldDispPtr->name, oldScreen); } (void) Tcl_RestoreInterpState(interp, interpState); Tcl_DStringFree(&scripts); Tcl_Release(bindInfoPtr); } /* *---------------------------------------------------------------------- * * 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 function 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 function finds the * pattern sequences that match the event list and returns the most * specific 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 * MatchPatterns( TkDisplay *dispPtr, /* Display from which the event came. */ BindingTable *bindPtr, /* Information about binding table, such as * ring of recent events. */ PatSeq *psPtr, /* List of pattern sequences. */ PatSeq *bestPtr, /* The best match seen so far, from a previous * call to this function. NULL means no prior * best match. */ ClientData *objectPtr, /* If NULL, the sequences at psPtr 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. */ PatSeq **sourcePtrPtr) /* Filled with the pattern sequence that * contains the eventProc and clientData * associated with the best match. If this * differs from the return value, it is the * virtual event that most closely matched the * return value (a physical event). Not * modified unless a result other than bestPtr * is returned. */ { PatSeq *matchPtr, *bestSourcePtr, *sourcePtr; bestSourcePtr = *sourcePtrPtr; /* * Iterate over all the pattern sequences. */ for ( ; psPtr != NULL; psPtr = psPtr->nextSeqPtr) { XEvent *eventPtr = &bindPtr->eventRing[bindPtr->curEvent]; Detail *detailPtr = &bindPtr->detailRing[bindPtr->curEvent]; Pattern *patPtr = psPtr->pats; Window window = eventPtr->xany.window; int patCount, ringCount, flags, state, modMask, i; /* * Iterate over all the patterns in a sequence to be sure that they * all match. */ patCount = psPtr->numPats; ringCount = EVENT_BUFFER_SIZE; while (patCount > 0) { if (ringCount <= 0) { goto nextSequence; } if (eventPtr->xany.type != patPtr->eventType) { /* * 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. */ if ((patPtr->eventType == KeyPress) || (patPtr->eventType == KeyRelease)) { if ((eventPtr->xany.type == ButtonPress) || (eventPtr->xany.type == ButtonRelease)) { goto nextSequence; } } else if ((patPtr->eventType == ButtonPress) || (patPtr->eventType == ButtonRelease)) { if ((eventPtr->xany.type == KeyPress) || (eventPtr->xany.type == KeyRelease)) { /* * Ignore key events if they are modifier keys. */ for (i = 0; i < dispPtr->numModKeyCodes; i++) { if (dispPtr->modKeyCodes[i] == eventPtr->xkey.keycode) { /* * This key is a modifier key, so ignore it. */ goto nextEvent; } } goto nextSequence; } } goto nextEvent; } if (eventPtr->xany.type == CreateNotify && eventPtr->xcreatewindow.parent != window) { goto nextSequence; } else if (eventPtr->xany.window != window) { 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. */ if ((patPtr->detail.clientData != 0) && (patPtr->detail.clientData != detailPtr->clientData)) { /* * 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". */ if (eventPtr->xany.type == KeyPress) { for (i = 0; i < dispPtr->numModKeyCodes; i++) { if (dispPtr->modKeyCodes[i] == eventPtr->xkey.keycode) { goto nextEvent; } } } goto nextSequence; } flags = flagArray[eventPtr->type]; if (flags & KEY_BUTTON_MOTION_VIRTUAL) { state = eventPtr->xkey.state; } else if (flags & CROSSING) { state = eventPtr->xcrossing.state; } else { state = 0; } if (patPtr->needMods != 0) { modMask = patPtr->needMods; if ((modMask & META_MASK) && (dispPtr->metaModMask != 0)) { modMask = (modMask & ~META_MASK) | dispPtr->metaModMask; } if ((modMask & ALT_MASK) && (dispPtr->altModMask != 0)) { modMask = (modMask & ~ALT_MASK) | dispPtr->altModMask; } if ((state & META_MASK) && (dispPtr->metaModMask != 0)) { state = (state & ~META_MASK) | dispPtr->metaModMask; } if ((state & ALT_MASK) && (dispPtr->altModMask != 0)) { state = (state & ~ALT_MASK) | dispPtr->altModMask; } if ((state & modMask) != modMask) { goto nextSequence; } } if (psPtr->flags & PAT_NEARBY) { XEvent *firstPtr = &bindPtr->eventRing[bindPtr->curEvent]; int timeDiff; timeDiff = (Time) firstPtr->xkey.time - eventPtr->xkey.time; if ((firstPtr->xkey.x_root < (eventPtr->xkey.x_root - NEARBY_PIXELS)) || (firstPtr->xkey.x_root > (eventPtr->xkey.x_root + NEARBY_PIXELS)) || (firstPtr->xkey.y_root < (eventPtr->xkey.y_root - NEARBY_PIXELS)) || (firstPtr->xkey.y_root > (eventPtr->xkey.y_root + NEARBY_PIXELS)) || (timeDiff > NEARBY_MS)) { goto nextSequence; } } patPtr++; patCount--; nextEvent: if (eventPtr == bindPtr->eventRing) { eventPtr = &bindPtr->eventRing[EVENT_BUFFER_SIZE-1]; detailPtr = &bindPtr->detailRing[EVENT_BUFFER_SIZE-1]; } else { eventPtr--; detailPtr--; } ringCount--; } matchPtr = psPtr; sourcePtr = psPtr; if (objectPtr != NULL) { int iVirt; VirtualOwners *voPtr; PatternTableKey key; /* * The sequence matches the physical constraints. Is this object * interested in any of the virtual events that correspond to this * sequence? */ voPtr = psPtr->voPtr; memset(&key, 0, sizeof(key)); key.object = *objectPtr; key.type = VirtualEvent; key.detail.clientData = 0; for (iVirt = 0; iVirt < voPtr->numOwners; iVirt++) { Tcl_HashEntry *hPtr = voPtr->owners[iVirt]; key.detail.name = (Tk_Uid) Tcl_GetHashKey(hPtr->tablePtr, hPtr); hPtr = Tcl_FindHashEntry(&bindPtr->patternTable, (char *) &key); if (hPtr != NULL) { /* * This tag is interested in this virtual event and its * corresponding physical event is a good match with the * virtual event's definition. */ PatSeq *virtMatchPtr = Tcl_GetHashValue(hPtr); if ((virtMatchPtr->numPats != 1) || (virtMatchPtr->nextSeqPtr != NULL)) { Tcl_Panic("MatchPattern: badly constructed virtual event"); } sourcePtr = virtMatchPtr; goto match; } } /* * The physical event matches a virtual event's definition, but * the tag isn't interested in it. */ goto nextSequence; } match: /* * This sequence matches. If we've already got another match, pick * whichever is most specific. Detail is most important, then * needMods. */ if (bestPtr != NULL) { Pattern *patPtr2; if (matchPtr->numPats != bestPtr->numPats) { if (bestPtr->numPats > matchPtr->numPats) { goto nextSequence; } else { goto newBest; } } for (i = 0, patPtr = matchPtr->pats, patPtr2 = bestPtr->pats; i < matchPtr->numPats; i++, patPtr++, patPtr2++) { if (patPtr->detail.clientData != patPtr2->detail.clientData) { if (patPtr->detail.clientData == 0) { goto nextSequence; } else { goto newBest; } } if (patPtr->needMods != patPtr2->needMods) { if ((patPtr->needMods & patPtr2->needMods) == patPtr->needMods) { goto nextSequence; } else if ((patPtr->needMods & patPtr2->needMods) == patPtr2->needMods) { 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; } newBest: bestPtr = matchPtr; bestSourcePtr = sourcePtr; nextSequence: continue; } *sourcePtrPtr = bestSourcePtr; 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 ExpandPercents( TkWindow *winPtr, /* Window where event occurred: needed to get * input context. */ const char *before, /* Command containing percent expressions to * be replaced. */ XEvent *eventPtr, /* X event containing information to be used * in % replacements. */ KeySym keySym, /* KeySym: only relevant for KeyPress and * KeyRelease events). */ Tcl_DString *dsPtr) /* Dynamic string in which to append new * command. */ { int spaceNeeded, cvtFlags; /* Used to substitute string as proper Tcl * list element. */ int number, flags, length; #define NUM_SIZE 40 const char *string; Tcl_DString buf; char numStorage[NUM_SIZE+1]; Tcl_DStringInit(&buf); if (eventPtr->type < TK_LASTEVENT) { flags = flagArray[eventPtr->type]; } else { flags = 0; } while (1) { /* * Find everything up to the next % character and append it to the * result string. */ for (string = before; (*string != 0) && (*string != '%'); string++) { /* Empty loop body. */ } if (string != before) { Tcl_DStringAppend(dsPtr, before, (int) (string-before)); before = string; } if (*before == 0) { break; } /* * There's a percent sequence here. Process it. */ number = 0; string = "??"; switch (before[1]) { case '#': number = eventPtr->xany.serial; goto doNumber; case 'a': if (flags & CONFIG) { TkpPrintWindowId(numStorage, eventPtr->xconfigure.above); string = numStorage; } goto doString; case 'b': if (flags & BUTTON) { number = eventPtr->xbutton.button; goto doNumber; } goto doString; case 'c': if (flags & EXPOSE) { number = eventPtr->xexpose.count; goto doNumber; } goto doString; case 'd': if (flags & (CROSSING|FOCUS)) { if (flags & FOCUS) { number = eventPtr->xfocus.detail; } else { number = eventPtr->xcrossing.detail; } string = TkFindStateString(notifyDetail, number); } else if (flags & CONFIGREQ) { if (eventPtr->xconfigurerequest.value_mask & CWStackMode) { string = TkFindStateString(configureRequestDetail, eventPtr->xconfigurerequest.detail); } else { string = ""; } } else if (flags & VIRTUAL) { XVirtualEvent *vePtr = (XVirtualEvent *) eventPtr; if (vePtr->user_data != NULL) { string = Tcl_GetString(vePtr->user_data); } else { string = ""; } } goto doString; case 'f': if (flags & CROSSING) { number = eventPtr->xcrossing.focus; goto doNumber; } goto doString; case 'h': if (flags & EXPOSE) { number = eventPtr->xexpose.height; } else if (flags & CONFIG) { number = eventPtr->xconfigure.height; } else if (flags & CREATE) { number = eventPtr->xcreatewindow.height; } else if (flags & CONFIGREQ) { number = eventPtr->xconfigurerequest.height; } else if (flags & RESIZEREQ) { number = eventPtr->xresizerequest.height; } else { goto doString; } goto doNumber; case 'i': if (flags & CREATE) { TkpPrintWindowId(numStorage, eventPtr->xcreatewindow.window); } else if (flags & CONFIGREQ) { TkpPrintWindowId(numStorage, eventPtr->xconfigurerequest.window); } else if (flags & MAPREQ) { TkpPrintWindowId(numStorage, eventPtr->xmaprequest.window); } else { TkpPrintWindowId(numStorage, eventPtr->xany.window); } string = numStorage; goto doString; case 'k': if ((flags & KEY) && (eventPtr->type != MouseWheelEvent)) { number = eventPtr->xkey.keycode; goto doNumber; } goto doString; case 'm': if (flags & CROSSING) { number = eventPtr->xcrossing.mode; string = TkFindStateString(notifyMode, number); } else if (flags & FOCUS) { number = eventPtr->xfocus.mode; string = TkFindStateString(notifyMode, number); } goto doString; case 'o': if (flags & CREATE) { number = eventPtr->xcreatewindow.override_redirect; } else if (flags & MAP) { number = eventPtr->xmap.override_redirect; } else if (flags & REPARENT) { number = eventPtr->xreparent.override_redirect; } else if (flags & CONFIG) { number = eventPtr->xconfigure.override_redirect; } else { goto doString; } goto doNumber; case 'p': if (flags & CIRC) { string = TkFindStateString(circPlace, eventPtr->xcirculate.place); } else if (flags & CIRCREQ) { string = TkFindStateString(circPlace, eventPtr->xcirculaterequest.place); } goto doString; case 's': if (flags & KEY_BUTTON_MOTION_VIRTUAL) { number = eventPtr->xkey.state; goto doNumber; } else if (flags & CROSSING) { number = eventPtr->xcrossing.state; goto doNumber; } else if (flags & PROP) { string = TkFindStateString(propNotify, eventPtr->xproperty.state); } else if (flags & VISIBILITY) { string = TkFindStateString(visNotify, eventPtr->xvisibility.state); } goto doString; case 't': if (flags & KEY_BUTTON_MOTION_VIRTUAL) { number = (int) eventPtr->xkey.time; } else if (flags & CROSSING) { number = (int) eventPtr->xcrossing.time; } else if (flags & PROP) { number = (int) eventPtr->xproperty.time; } else { goto doString; } goto doNumber; case 'v': number = eventPtr->xconfigurerequest.value_mask; goto doNumber; case 'w': if (flags & EXPOSE) { number = eventPtr->xexpose.width; } else if (flags & CONFIG) { number = eventPtr->xconfigure.width; } else if (flags & CREATE) { number = eventPtr->xcreatewindow.width; } else if (flags & CONFIGREQ) { number = eventPtr->xconfigurerequest.width; } else if (flags & RESIZEREQ) { number = eventPtr->xresizerequest.width; } else { goto doString; } goto doNumber; case 'x': if (flags & KEY_BUTTON_MOTION_VIRTUAL) { number = eventPtr->xkey.x; } else if (flags & CROSSING) { number = eventPtr->xcrossing.x; } else if (flags & EXPOSE) { number = eventPtr->xexpose.x; } else if (flags & (CREATE|CONFIG|GRAVITY)) { number = eventPtr->xcreatewindow.x; } else if (flags & REPARENT) { number = eventPtr->xreparent.x; } else if (flags & CREATE) { number = eventPtr->xcreatewindow.x; } else if (flags & CONFIGREQ) { number = eventPtr->xconfigurerequest.x; } else { goto doString; } goto doNumber; case 'y': if (flags & KEY_BUTTON_MOTION_VIRTUAL) { number = eventPtr->xkey.y; } else if (flags & EXPOSE) { number = eventPtr->xexpose.y; } else if (flags & (CREATE|CONFIG|GRAVITY)) { number = eventPtr->xcreatewindow.y; } else if (flags & REPARENT) { number = eventPtr->xreparent.y; } else if (flags & CROSSING) { number = eventPtr->xcrossing.y; } else if (flags & CREATE) { number = eventPtr->xcreatewindow.y; } else if (flags & CONFIGREQ) { number = eventPtr->xconfigurerequest.y; } else { goto doString; } goto doNumber; case 'A': if ((flags & KEY) && (eventPtr->type != MouseWheelEvent)) { Tcl_DStringFree(&buf); string = TkpGetString(winPtr, eventPtr, &buf); } goto doString; case 'B': if (flags & CREATE) { number = eventPtr->xcreatewindow.border_width; } else if (flags & CONFIGREQ) { number = eventPtr->xconfigurerequest.border_width; } else if (flags & CONFIG) { number = eventPtr->xconfigure.border_width; } else { goto doString; } goto doNumber; case 'D': /* * This is used only by the MouseWheel event. */ if ((flags & KEY) && (eventPtr->type == MouseWheelEvent)) { number = eventPtr->xkey.keycode; goto doNumber; } goto doString; case 'E': number = (int) eventPtr->xany.send_event; goto doNumber; case 'K': if ((flags & KEY) && (eventPtr->type != MouseWheelEvent)) { const char *name = TkKeysymToString(keySym); if (name != NULL) { string = name; } } goto doString; case 'N': if ((flags & KEY) && (eventPtr->type != MouseWheelEvent)) { number = (int) keySym; goto doNumber; } goto doString; case 'P': if (flags & PROP) { string = Tk_GetAtomName((Tk_Window) winPtr, eventPtr->xproperty.atom); } goto doString; case 'R': if (flags & KEY_BUTTON_MOTION_CROSSING) { TkpPrintWindowId(numStorage, eventPtr->xkey.root); string = numStorage; } goto doString; case 'S': if (flags & KEY_BUTTON_MOTION_CROSSING) { TkpPrintWindowId(numStorage, eventPtr->xkey.subwindow); string = numStorage; } goto doString; case 'T': number = eventPtr->type; goto doNumber; case 'W': { Tk_Window tkwin; tkwin = Tk_IdToWindow(eventPtr->xany.display, eventPtr->xany.window); if (tkwin != NULL) { string = Tk_PathName(tkwin); } else { string = "??"; } goto doString; } case 'X': if (flags & KEY_BUTTON_MOTION_CROSSING) { number = eventPtr->xkey.x_root; Tk_IdToWindow(eventPtr->xany.display, eventPtr->xany.window); goto doNumber; } goto doString; case 'Y': if (flags & KEY_BUTTON_MOTION_CROSSING) { number = eventPtr->xkey.y_root; Tk_IdToWindow(eventPtr->xany.display, eventPtr->xany.window); goto doNumber; } goto doString; default: numStorage[0] = before[1]; numStorage[1] = '\0'; string = numStorage; goto doString; } doNumber: sprintf(numStorage, "%d", number); string = numStorage; doString: spaceNeeded = Tcl_ScanElement(string, &cvtFlags); length = Tcl_DStringLength(dsPtr); Tcl_DStringSetLength(dsPtr, length + spaceNeeded); spaceNeeded = Tcl_ConvertElement(string, Tcl_DStringValue(dsPtr) + length, cvtFlags | TCL_DONT_USE_BRACES); Tcl_DStringSetLength(dsPtr, length + spaceNeeded); before += 2; } Tcl_DStringFree(&buf); } /* *---------------------------------------------------------------------- * * ChangeScreen -- * * This function is invoked whenever the current screen changes in an * application. It invokes a Tcl command named "tk::ScreenChanged", * passing it the screen name as argument. tk::ScreenChanged does things * like making the tk::Priv variable point to an array for the current * display. * * Results: * None. * * Side effects: * Depends on what tk::ScreenChanged does. If an error occurs then * bgerror will be invoked. * *---------------------------------------------------------------------- */ static void ChangeScreen( Tcl_Interp *interp, /* Interpreter in which to invoke command. */ char *dispName, /* Name of new display. */ int screenIndex) /* Index of new screen. */ { Tcl_Obj *cmdObj = Tcl_ObjPrintf("::tk::ScreenChanged %s.%d", dispName, screenIndex); int code; Tcl_IncrRefCount(cmdObj); code = Tcl_EvalObjEx(interp, cmdObj, TCL_EVAL_GLOBAL); if (code != TCL_OK) { Tcl_AddErrorInfo(interp, "\n (changing screen in event binding)"); Tcl_BackgroundException(interp, code); } Tcl_DecrRefCount(cmdObj); } /* *---------------------------------------------------------------------- * * Tk_EventCmd -- * * This function 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 Tk_EventObjCmd( ClientData clientData, /* Main window associated with interpreter. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument objects. */ { int index, i; char *name; const char *event; Tk_Window tkwin = clientData; TkBindInfo bindInfo = ((TkWindow *) tkwin)->mainPtr->bindInfo; VirtualEventTable *vetPtr = &bindInfo->virtualEventTable; static const char *const optionStrings[] = { "add", "delete", "generate", "info", NULL }; enum options { EVENT_ADD, EVENT_DELETE, EVENT_GENERATE, EVENT_INFO }; if (objc < 2) { Tcl_WrongNumArgs(interp, 1, objv, "option ?arg?"); return TCL_ERROR; } if (Tcl_GetIndexFromObjStruct(interp, objv[1], optionStrings, sizeof(char *), "option", 0, &index) != TCL_OK) { return TCL_ERROR; } switch ((enum options) index) { case EVENT_ADD: if (objc < 4) { Tcl_WrongNumArgs(interp, 2, objv, "virtual sequence ?sequence ...?"); return TCL_ERROR; } name = Tcl_GetString(objv[2]); for (i = 3; i < objc; i++) { event = Tcl_GetString(objv[i]); if (CreateVirtualEvent(interp, vetPtr, name, event) != TCL_OK) { return TCL_ERROR; } } break; case EVENT_DELETE: if (objc < 3) { Tcl_WrongNumArgs(interp, 2, objv, "virtual ?sequence ...?"); return TCL_ERROR; } name = Tcl_GetString(objv[2]); if (objc == 3) { return DeleteVirtualEvent(interp, vetPtr, name, NULL); } for (i = 3; i < objc; i++) { event = Tcl_GetString(objv[i]); if (DeleteVirtualEvent(interp, vetPtr, name, event) != TCL_OK) { return TCL_ERROR; } } break; case EVENT_GENERATE: if (objc < 4) { Tcl_WrongNumArgs(interp, 2, objv, "window event ?-option value ...?"); return TCL_ERROR; } return HandleEventGenerate(interp, tkwin, objc - 2, objv + 2); case EVENT_INFO: if (objc == 2) { GetAllVirtualEvents(interp, vetPtr); return TCL_OK; } else if (objc == 3) { return GetVirtualEvent(interp, vetPtr, objv[2]); } else { Tcl_WrongNumArgs(interp, 2, objv, "?virtual?"); return TCL_ERROR; } } return TCL_OK; } /* *--------------------------------------------------------------------------- * * InitVirtualEventTable -- * * Given storage for a virtual event table, set up the fields to prepare * a new domain in which virtual events may be defined. * * Results: * None. * * Side effects: * *vetPtr is now initialized. * *--------------------------------------------------------------------------- */ static void InitVirtualEventTable( VirtualEventTable *vetPtr) /* Pointer to virtual event table. Memory is * supplied by the caller. */ { Tcl_InitHashTable(&vetPtr->patternTable, sizeof(PatternTableKey) / sizeof(int)); Tcl_InitHashTable(&vetPtr->nameTable, TCL_ONE_WORD_KEYS); } /* *--------------------------------------------------------------------------- * * DeleteVirtualEventTable -- * * Delete the contents of a virtual event table. The caller is * responsible for freeing any memory used by the table itself. * * Results: * None. * * Side effects: * Memory is freed. * *--------------------------------------------------------------------------- */ static void DeleteVirtualEventTable( VirtualEventTable *vetPtr) /* The virtual event table to delete. */ { Tcl_HashEntry *hPtr; Tcl_HashSearch search; PatSeq *psPtr, *nextPtr; hPtr = Tcl_FirstHashEntry(&vetPtr->patternTable, &search); for ( ; hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) { psPtr = Tcl_GetHashValue(hPtr); for ( ; psPtr != NULL; psPtr = nextPtr) { nextPtr = psPtr->nextSeqPtr; ckfree(psPtr->voPtr); ckfree(psPtr); } } Tcl_DeleteHashTable(&vetPtr->patternTable); hPtr = Tcl_FirstHashEntry(&vetPtr->nameTable, &search); for ( ; hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) { ckfree(Tcl_GetHashValue(hPtr)); } Tcl_DeleteHashTable(&vetPtr->nameTable); } /* *---------------------------------------------------------------------- * * 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 the * interp's 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 CreateVirtualEvent( Tcl_Interp *interp, /* Used for error reporting. */ VirtualEventTable *vetPtr, /* Table in which to augment virtual event. */ char *virtString, /* Name of new virtual event. */ const char *eventString) /* String describing physical event that * triggers virtual event. */ { PatSeq *psPtr; int dummy; Tcl_HashEntry *vhPtr; unsigned long eventMask; PhysicalsOwned *poPtr; VirtualOwners *voPtr; Tk_Uid virtUid; virtUid = GetVirtualEventUid(interp, virtString); if (virtUid == NULL) { return TCL_ERROR; } /* * Find/create physical event */ psPtr = FindSequence(interp, &vetPtr->patternTable, NULL, eventString, 1, 0, &eventMask); if (psPtr == NULL) { return TCL_ERROR; } /* * Find/create virtual event. */ vhPtr = Tcl_CreateHashEntry(&vetPtr->nameTable, virtUid, &dummy); /* * Make virtual event own the physical event. */ poPtr = Tcl_GetHashValue(vhPtr); if (poPtr == NULL) { poPtr = ckalloc(sizeof(PhysicalsOwned)); poPtr->numOwned = 0; } else { /* * See if this virtual event is already defined for this physical * event and just return if it is. */ int i; for (i = 0; i < poPtr->numOwned; i++) { if (poPtr->patSeqs[i] == psPtr) { return TCL_OK; } } poPtr = ckrealloc(poPtr, sizeof(PhysicalsOwned) + poPtr->numOwned * sizeof(PatSeq *)); } Tcl_SetHashValue(vhPtr, poPtr); poPtr->patSeqs[poPtr->numOwned] = psPtr; poPtr->numOwned++; /* * Make physical event so it can trigger the virtual event. */ voPtr = psPtr->voPtr; if (voPtr == NULL) { voPtr = ckalloc(sizeof(VirtualOwners)); voPtr->numOwners = 0; } else { voPtr = ckrealloc(voPtr, sizeof(VirtualOwners) + voPtr->numOwners * sizeof(Tcl_HashEntry *)); } psPtr->voPtr = voPtr; voPtr->owners[voPtr->numOwners] = vhPtr; voPtr->numOwners++; 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 the * interp's 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 DeleteVirtualEvent( Tcl_Interp *interp, /* Used for error reporting. */ VirtualEventTable *vetPtr, /* Table in which to delete event. */ char *virtString, /* String describing event sequence that * triggers binding. */ const char *eventString) /* The event sequence that should be deleted, * or NULL to delete all event sequences for * the entire virtual event. */ { int iPhys; Tk_Uid virtUid; Tcl_HashEntry *vhPtr; PhysicalsOwned *poPtr; PatSeq *eventPSPtr; virtUid = GetVirtualEventUid(interp, virtString); if (virtUid == NULL) { return TCL_ERROR; } vhPtr = Tcl_FindHashEntry(&vetPtr->nameTable, virtUid); if (vhPtr == NULL) { return TCL_OK; } poPtr = Tcl_GetHashValue(vhPtr); 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. */ eventPSPtr = FindSequence(interp, &vetPtr->patternTable, NULL, eventString, 0, 0, &eventMask); if (eventPSPtr == NULL) { const char *string = Tcl_GetString(Tcl_GetObjResult(interp)); return (string[0] != '\0') ? TCL_ERROR : TCL_OK; } } for (iPhys = poPtr->numOwned; --iPhys >= 0; ) { PatSeq *psPtr = poPtr->patSeqs[iPhys]; if ((eventPSPtr == NULL) || (psPtr == eventPSPtr)) { int iVirt; VirtualOwners *voPtr; /* * Remove association between this physical event and the given * virtual event that it triggers. */ voPtr = psPtr->voPtr; for (iVirt = 0; iVirt < voPtr->numOwners; iVirt++) { if (voPtr->owners[iVirt] == vhPtr) { break; } } if (iVirt == voPtr->numOwners) { Tcl_Panic("DeleteVirtualEvent: couldn't find owner"); } voPtr->numOwners--; if (voPtr->numOwners == 0) { /* * Removed last reference to this physical event, so remove it * from physical->virtual map. */ PatSeq *prevPtr = Tcl_GetHashValue(psPtr->hPtr); if (prevPtr == psPtr) { if (psPtr->nextSeqPtr == NULL) { Tcl_DeleteHashEntry(psPtr->hPtr); } else { Tcl_SetHashValue(psPtr->hPtr, psPtr->nextSeqPtr); } } else { for ( ; ; prevPtr = prevPtr->nextSeqPtr) { if (prevPtr == NULL) { Tcl_Panic("DeleteVirtualEvent couldn't find on hash chain"); } if (prevPtr->nextSeqPtr == psPtr) { prevPtr->nextSeqPtr = psPtr->nextSeqPtr; break; } } } ckfree(psPtr->voPtr); ckfree(psPtr); } 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. */ voPtr->owners[iVirt] = voPtr->owners[voPtr->numOwners]; } /* * Now delete the virtual event's reference to the physical event. */ poPtr->numOwned--; if (eventPSPtr != NULL && poPtr->numOwned != 0) { /* * Just deleting this one physical event. Consolidate list of * owned physical events and return. */ poPtr->patSeqs[iPhys] = poPtr->patSeqs[poPtr->numOwned]; return TCL_OK; } } } if (poPtr->numOwned == 0) { /* * 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. */ ckfree(poPtr); Tcl_DeleteHashEntry(vhPtr); } 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 the interp's 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, the interp's 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 the interp's result. * * Side effects: * None. * *--------------------------------------------------------------------------- */ static int GetVirtualEvent( Tcl_Interp *interp, /* Interpreter for reporting. */ VirtualEventTable *vetPtr, /* Table in which to look for event. */ Tcl_Obj *virtName) /* String describing virtual event. */ { Tcl_HashEntry *vhPtr; int iPhys; PhysicalsOwned *poPtr; Tk_Uid virtUid; Tcl_Obj *resultObj; virtUid = GetVirtualEventUid(interp, Tcl_GetString(virtName)); if (virtUid == NULL) { return TCL_ERROR; } vhPtr = Tcl_FindHashEntry(&vetPtr->nameTable, virtUid); if (vhPtr == NULL) { return TCL_OK; } resultObj = Tcl_NewObj(); poPtr = Tcl_GetHashValue(vhPtr); for (iPhys = 0; iPhys < poPtr->numOwned; iPhys++) { Tcl_ListObjAppendElement(NULL, resultObj, GetPatternObj(poPtr->patSeqs[iPhys])); } Tcl_SetObjResult(interp, resultObj); return TCL_OK; } /* *-------------------------------------------------------------- * * GetAllVirtualEvents -- * * Return a list that contains the names of all the virtual event * defined. * * Results: * There is no return value. The interp's result is modified to hold a * Tcl list with one entry for each virtual event in nameTable. * * Side effects: * None. * *-------------------------------------------------------------- */ static void GetAllVirtualEvents( Tcl_Interp *interp, /* Interpreter returning result. */ VirtualEventTable *vetPtr) /* Table containing events. */ { Tcl_HashEntry *hPtr; Tcl_HashSearch search; Tcl_Obj *resultObj; resultObj = Tcl_NewObj(); hPtr = Tcl_FirstHashEntry(&vetPtr->nameTable, &search); for ( ; hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) { Tcl_ListObjAppendElement(NULL, resultObj, Tcl_ObjPrintf( "<<%s>>", (char *) Tcl_GetHashKey(hPtr->tablePtr, hPtr))); } Tcl_SetObjResult(interp, resultObj); } /* *--------------------------------------------------------------------------- * * 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, ). * argv[2..argc-1] contains -field/option pairs for specifying 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 HandleEventGenerate( Tcl_Interp *interp, /* Interp for errors return and name lookup. */ Tk_Window mainWin, /* Main window associated with interp. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument objects. */ { union {XEvent general; XVirtualEvent virtual;} event; const char *p; const char *name, *windowName; int count, flags, synch, i, number, warp; Tcl_QueuePosition pos; Pattern pat; Tk_Window tkwin, tkwin2; TkWindow *mainPtr; unsigned long eventMask; Tcl_Obj *userDataObj; static const char *const fieldStrings[] = { "-when", "-above", "-borderwidth", "-button", "-count", "-data", "-delta", "-detail", "-focus", "-height", "-keycode", "-keysym", "-mode", "-override", "-place", "-root", "-rootx", "-rooty", "-sendevent", "-serial", "-state", "-subwindow", "-time", "-warp", "-width", "-window", "-x", "-y", NULL }; enum field { EVENT_WHEN, EVENT_ABOVE, EVENT_BORDER, EVENT_BUTTON, EVENT_COUNT, EVENT_DATA, EVENT_DELTA, EVENT_DETAIL, EVENT_FOCUS, EVENT_HEIGHT, EVENT_KEYCODE, EVENT_KEYSYM, EVENT_MODE, EVENT_OVERRIDE, EVENT_PLACE, EVENT_ROOT, EVENT_ROOTX, EVENT_ROOTY, EVENT_SEND, EVENT_SERIAL, EVENT_STATE, EVENT_SUBWINDOW, EVENT_TIME, EVENT_WARP, EVENT_WIDTH, EVENT_WINDOW, EVENT_X, EVENT_Y }; windowName = Tcl_GetString(objv[0]); if (!windowName[0]) { tkwin = mainWin; } else if (NameToWindow(interp, mainWin, objv[0], &tkwin) != TCL_OK) { return TCL_ERROR; } mainPtr = (TkWindow *) mainWin; if ((tkwin == NULL) || (mainPtr->mainPtr != ((TkWindow *) tkwin)->mainPtr)) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "window id \"%s\" doesn't exist in this application", Tcl_GetString(objv[0]))); Tcl_SetErrorCode(interp, "TK", "LOOKUP", "WINDOW", Tcl_GetString(objv[0]), NULL); return TCL_ERROR; } name = Tcl_GetString(objv[1]); p = name; eventMask = 0; userDataObj = NULL; count = ParseEventDescription(interp, &p, &pat, &eventMask); if (count == 0) { return TCL_ERROR; } if (count != 1) { Tcl_SetObjResult(interp, Tcl_NewStringObj( "Double or Triple modifier not allowed", -1)); Tcl_SetErrorCode(interp, "TK", "EVENT", "BAD_MODIFIER", NULL); return TCL_ERROR; } if (*p != '\0') { Tcl_SetObjResult(interp, Tcl_NewStringObj( "only one event specification allowed", -1)); Tcl_SetErrorCode(interp, "TK", "EVENT", "MULTIPLE", NULL); return TCL_ERROR; } memset(&event, 0, sizeof(event)); event.general.xany.type = pat.eventType; event.general.xany.serial = NextRequest(Tk_Display(tkwin)); event.general.xany.send_event = False; if (windowName[0]) { event.general.xany.window = Tk_WindowId(tkwin); } else { event.general.xany.window = RootWindow(Tk_Display(tkwin), Tk_ScreenNumber(tkwin)); } event.general.xany.display = Tk_Display(tkwin); flags = flagArray[event.general.xany.type]; if (flags & DESTROY) { /* * Event DestroyNotify should be generated by destroying the window. */ Tk_DestroyWindow(tkwin); return TCL_OK; } if (flags & KEY_BUTTON_MOTION_VIRTUAL) { event.general.xkey.state = pat.needMods; if ((flags & KEY) && (event.general.xany.type != MouseWheelEvent)) { TkpSetKeycodeAndState(tkwin, pat.detail.keySym, &event.general); } else if (flags & BUTTON) { event.general.xbutton.button = pat.detail.button; } else if (flags & VIRTUAL) { event.virtual.name = pat.detail.name; } } if (flags & (CREATE|UNMAP|MAP|REPARENT|CONFIG|GRAVITY|CIRC)) { event.general.xcreatewindow.window = event.general.xany.window; } if (flags & KEY_BUTTON_MOTION_CROSSING) { event.general.xkey.x_root = -1; event.general.xkey.y_root = -1; } if (event.general.xany.type == FocusIn || event.general.xany.type == FocusOut) { event.general.xany.send_event = GENERATED_FOCUS_EVENT_MAGIC; } /* * Process the remaining arguments to fill in additional fields of the * event. */ synch = 1; warp = 0; pos = TCL_QUEUE_TAIL; for (i = 2; i < objc; i += 2) { Tcl_Obj *optionPtr, *valuePtr; int index; optionPtr = objv[i]; valuePtr = objv[i + 1]; if (Tcl_GetIndexFromObjStruct(interp, optionPtr, fieldStrings, sizeof(char *), "option", TCL_EXACT, &index) != TCL_OK) { return TCL_ERROR; } if (objc & 1) { /* * This test occurs after Tcl_GetIndexFromObj() so that "event * generate