4  *      Declarations for things used internally by the Tk 
   5  *      procedures but not exported outside the module. 
   7  * Copyright 1990-1992 Regents of the University of California. 
   8  * Permission to use, copy, modify, and distribute this 
   9  * software and its documentation for any purpose and without 
  10  * fee is hereby granted, provided that the above copyright 
  11  * notice appear in all copies.  The University of California 
  12  * makes no representations about the suitability of this 
  13  * software for any purpose.  It is provided "as is" without 
  14  * express or implied warranty. 
  16  * $Header: /user6/ouster/wish/RCS/tkInt.h,v 1.65 92/08/21 11:42:27 ouster Exp $ SPRITE (Berkeley) 
  25 #include <X11/Xlibint.h> 
  29 #include <X11/Xutil.h> 
  41 #define META_MASK       (AnyModifier<<1) 
  42 #define ALT_MASK        (AnyModifier<<2) 
  45  * One of the following structures is maintained for each display 
  46  * containing a window managed by Tk: 
  49 typedef struct TkDisplay 
{ 
  50     Display 
*display
;           /* Xlib's info about display. */ 
  51     struct TkDisplay 
*nextPtr
;  /* Next in list of all displays. */ 
  52     char *name
;                 /* Name of display (with any screen 
  53                                  * identifier removed).  Malloc-ed. */ 
  54     Time lastEventTime
;         /* Time of last event received for this 
  58      * Information used by tkEvent.c only: 
  61     struct TkWindow 
*mouseMainPtr
; 
  62                                 /* Pointer to the main window of this 
  63                                  * display that currently contains the 
  64                                  * mouse pointer.  NULL means the pointer 
  65                                  * isn't in a main window managed by 
  69      * Information used by tkBind.c only: 
  72     int firstKeycode
;           /* First keycode supported by 
  74     int lastKeycode
;            /* Last keycode supported by 
  76     int symsPerCode
;            /* Number of KeySyms in "keySyms" 
  77                                  * for each keycode.  0 means the 
  78                                  * keysym information hasn't been 
  79                                  * retrieved from the server yet. */ 
  80     KeySym 
*keySyms
;            /* Array of KeySyms, returned by 
  81                                  * XGetKeyboardMapping. */ 
  82     unsigned int modeModMask
; 
  83     unsigned int metaModMask
; 
  84     unsigned int altModMask
; 
  87      * Information used by tkError.c only: 
  90     struct TkErrorHandler 
*errorPtr
; 
  91                                 /* First in list of error handlers 
  92                                  * for this display.  NULL means 
  93                                  * no handlers exist at present. */ 
  94     int deleteCount
;            /* Counts # of handlers deleted since 
  95                                  * last time inactive handlers were 
  96                                  * garbage-collected.  When this number 
  97                                  * gets big, handlers get cleaned up. */ 
 100      * Information used by tkSend.c only: 
 103     Tk_Window commWindow
;       /* Window used for communication 
 104                                  * between interpreters during "send" 
 105                                  * commands.  NULL means send info hasn't 
 106                                  * been initialized yet. */ 
 107     Atom commProperty
;          /* X's name for comm property. */ 
 108     Atom registryProperty
;      /* X's name for property containing 
 109                                  * registry of interpreter names. */ 
 112      * Information used by tkSelect.c only: 
 115     Tk_Window selectionOwner
;   /* Current owner of selection, or 
 116                                  * NULL if selection isn't owned by 
 117                                  * a window in this process.  */ 
 118     int selectionSerial
;        /* Serial number of last XSelectionSetOwner 
 119                                  * request we made to server (used to 
 120                                  * filter out redundant SelectionClear 
 122     Time selectionTime
;         /* Timestamp used to acquire selection. */ 
 123     Atom multipleAtom
;          /* Atom for MULTIPLE.  None means 
 124                                  * selection stuff isn't initialized. */ 
 125     Atom incrAtom
;              /* Atom for INCR. */ 
 126     Atom targetsAtom
;           /* Atom for TARGETS. */ 
 127     Atom timestampAtom
;         /* Atom for TIMESTAMP. */ 
 128     Atom textAtom
;              /* Atom for TEXT. */ 
 129     Atom compoundTextAtom
;      /* Atom for COMPOUND_TEXT. */ 
 132      * Information used by tkAtom.c only: 
 135     int atomInit
;               /* 0 means stuff below hasn't been 
 136                                  * initialized yet. */ 
 137     Tcl_HashTable nameTable
;    /* Maps from names to Atom's. */ 
 138     Tcl_HashTable atomTable
;    /* Maps from Atom's back to names. */ 
 141      * Information used by tkCursor.c only: 
 144     Font cursorFont
;            /* Font to use for standard cursors. 
 145                                  * None means font not loaded yet. */ 
 148      * Information used by tkGrab.c only: 
 151     struct TkWindow 
*grabWinPtr
; 
 152                                 /* Window in which the pointer is currently 
 153                                  * grabbed, or NULL if none. */ 
 154     struct TkWindow 
*ungrabWinPtr
; 
 155                                 /* Window to which pointer should be returned 
 156                                  * when the current grab ends (i.e. the 
 157                                  * window that the mouse is really on top 
 159     struct TkWindow 
*buttonWinPtr
; 
 160                                 /* Window in which first mouse button was 
 161                                  * pressed while grab was in effect, or NULL 
 162                                  * if no such press in effect. */ 
 163     struct TkWindow 
*pointerWinPtr
; 
 164                                 /* The window that officially contains the 
 165                                  * pointer, as far as this application is 
 166                                  * concerned.  If a grab is in effect then 
 167                                  * this may not be the window that's underneath 
 168                                  * the pointer.  NULL means the application 
 169                                  * doesn't consider the pointer to be in any 
 171     struct TkWindow 
*serverWinPtr
; 
 172                                 /* The window that contains the pointer, as 
 173                                  * far as the X server is concerned.  This 
 174                                  * field gets set on every Enter or Leave 
 175                                  * event even if the grab code eventually 
 176                                  * discards the event.  NULL means the server 
 177                                  * thinks the pointer is outside any window 
 178                                  * of any application on this screen. */ 
 179     int grabFlags
;              /* Miscellaneous flag values.  See definitions 
 182     struct TkWindow 
*focusPtr
;  /* Identifies window that currently has the 
 183                                  * focus (or that will get the focus the next 
 184                                  * time the pointer enters any of the top-level 
 185                                  * windows associated with this display). 
 186                                  * NULL means nobody has the focus. 
 187                                  * Managed by tkEvent.c. */ 
 191  * One of the following structures exists for each error handler 
 192  * created by a call to Tk_CreateErrorHandler.  The structure 
 193  * is managed by tkError.c. 
 196 typedef struct TkErrorHandler 
{ 
 197     TkDisplay 
*dispPtr
;         /* Display to which handler applies. */ 
 198     unsigned long firstRequest
; /* Only errors with serial numbers 
 199                                  * >= to this are considered. */ 
 200     unsigned long lastRequest
;  /* Only errors with serial numbers 
 201                                  * <= to this are considered.  This 
 202                                  * field is filled in when XUnhandle 
 203                                  * is called.  -1 means XUnhandle 
 204                                  * hasn't been called yet. */ 
 205     int error
;                  /* Consider only errors with this 
 206                                  * error_code (-1 means consider 
 208     int request
;                /* Consider only errors with this 
 209                                  * major request code (-1 means 
 210                                  * consider all major codes). */ 
 211     int minorCode
;              /* Consider only errors with this 
 212                                  * minor request code (-1 means 
 213                                  * consider all minor codes). */ 
 214     Tk_ErrorProc 
*errorProc
;    /* Procedure to invoke when a matching 
 215                                  * error occurs.  NULL means just ignore 
 217     ClientData clientData
;      /* Arbitrary value to pass to 
 219     struct TkErrorHandler 
*nextPtr
; 
 220                                 /* Pointer to next older handler for 
 221                                  * this display, or NULL for end of 
 226  * One of the following structures exists for each event handler 
 227  * created by calling Tk_CreateEventHandler.  This information 
 228  * is used by tkEvent.c only. 
 231 typedef struct TkEventHandler 
{ 
 232     unsigned long mask
;         /* Events for which to invoke 
 234     Tk_EventProc 
*proc
;         /* Procedure to invoke when an event 
 236     ClientData clientData
;      /* Argument to pass to proc. */ 
 237     struct TkEventHandler 
*nextPtr
; 
 238                                 /* Next in list of handlers 
 239                                  * associated with window (NULL means 
 244  * One of the following structures exists for each selection 
 245  * handler created by calling Tk_CreateSelHandler.  This 
 246  * information is used by tkSelect.c only. 
 249 typedef struct TkSelHandler 
{ 
 250     Atom target
;                /* Target type for selection 
 251                                  * conversion, such as TARGETS or 
 253     Atom format
;                /* Format in which selection 
 254                                  * info will be returned, such 
 255                                  * as STRING or ATOM. */ 
 256     Tk_SelectionProc 
*proc
;     /* Procedure to generate selection 
 258     ClientData clientData
;      /* Argument to pass to proc. */ 
 259     int size
;                   /* Size of units returned by proc 
 260                                  * (8 for STRING, 32 for almost 
 262     struct TkSelHandler 
*nextPtr
; 
 263                                 /* Next selection handler associated 
 264                                  * with same window (NULL for end of 
 269  * Tk keeps one of the following data structures for each main 
 270  * window (created by a call to Tk_CreateMainWindow).  It stores 
 271  * information that is shared by all of the windows associated 
 272  * with a particular main window. 
 275 typedef struct TkMainInfo 
{ 
 276     struct TkWindow 
*winPtr
;    /* Pointer to main window. */ 
 277     Tcl_Interp 
*interp
;         /* Interpreter associated with application. */ 
 278     Tcl_HashTable nameTable
;    /* Hash table mapping path names to TkWindow 
 279                                  * structs for all windows related to this 
 280                                  * main window.  Managed by tkWindow.c. */ 
 281     Tk_BindingTable bindingTable
; 
 282                                 /* Used in conjunction with "bind" command 
 283                                  * to bind events to Tcl commands. */ 
 285 /*    struct TkWindow *focusPtr; */     /* Identifies window that currently has the 
 286                                  * focus (or that will get the focus the next 
 287                                  * time the pointer enters any of the top-level 
 288                                  * windows associated with this display). 
 289                                  * NULL means nobody has the focus. 
 290                                  * Managed by tkEvent.c. */ 
 291     struct ElArray 
*optionRootPtr
; 
 292                                 /* Top level of option hierarchy for this 
 293                                  * main window.  NULL means uninitialized. 
 294                                  * Managed by tkOption.c. */ 
 298  * Tk keeps one of the following structures for each window. 
 299  * Some of the information (like size and location) is a shadow 
 300  * of information managed by the X server, and some is special 
 301  * information used here, such as event and geometry management 
 302  * information.  This information is (mostly) managed by tkWindow.c. 
 303  * WARNING: the declaration below must be kept consistent with the 
 304  * Tk_ClientWindow structure in tk.h.  If you change one, be sure to 
 308 typedef struct TkWindow 
{ 
 311      * Structural information: 
 314     Display 
*display
;           /* Display containing window. */ 
 315     TkDisplay 
*dispPtr
;         /* Tk's information about display 
 317     int screenNum
;              /* Index of screen for window, among all 
 318                                  * those for dispPtr. */ 
 319     Window window
;              /* X's id for window.   NULL means window 
 320                                  * hasn't actually been created yet, or it's 
 322     struct TkWindow 
*childList
; /* First in list of child windows, 
 323                                  * or NULL if no children. */ 
 324     struct TkWindow 
*parentPtr
; /* Pointer to parent window (logical 
 325                                  * parent, not necessarily X parent), or 
 326                                  * NULL if this is a main window. */ 
 327     struct TkWindow 
*nextPtr
;   /* Next in list of children with 
 328                                  * same parent (NULL if end of 
 330     TkMainInfo 
*mainPtr
;        /* Information shared by all windows 
 331                                  * associated with a particular main 
 332                                  * window.  NULL means this window is 
 333                                  * a rogue that isn't associated with 
 334                                  * any application (at present, there 
 335                                  * should never be any rogues).  */ 
 338      * Name and type information for the window: 
 341     char *pathName
;             /* Path name of window (concatenation 
 342                                  * of all names between this window and 
 343                                  * its top-level ancestor).  This is a 
 344                                  * pointer into an entry in 
 345                                  * mainPtr->nameTable or NULL if mainPtr 
 347     Tk_Uid nameUid
;             /* Name of the window within its parent 
 348                                  * (unique within the parent). */ 
 349     Tk_Uid classUid
;            /* Class of the window.  NULL means window 
 350                                  * hasn't been given a class yet. */ 
 353      * Geometry and other attributes of window.  This information 
 354      * may not be updated on the server immediately;  stuff that 
 355      * hasn't been reflected in the server yet is called "dirty". 
 356      * At present, information can be dirty only if the window 
 357      * hasn't yet been created. 
 360     XWindowChanges changes
;     /* Geometry and other info about 
 362     unsigned int dirtyChanges
;  /* Bits indicate fields of "changes" 
 364     XSetWindowAttributes atts
;  /* Current attributes of window. */ 
 365     unsigned long dirtyAtts
;    /* Bits indicate fields of "atts" 
 368     unsigned int flags
;         /* Various flag values:  these are all 
 369                                  * defined in tk.h (confusing, but they're 
 370                                  * needed there for some query macros). */ 
 373      * Information kept by the event manager (tkEvent.c): 
 376     TkEventHandler 
*handlerList
;/* First in list of event handlers 
 377                                  * declared for this window, or 
 380      * Information related to input focussing (tkEvent.c): 
 383     Tk_FocusProc 
*focusProc
;    /* Procedure to invoke when this window 
 384                                  * gets or loses the input focus.  NULL 
 385                                  * means this window is not prepared to 
 386                                  * receive the focus. */ 
 387     ClientData focusData
;       /* Arbitrary value to pass to focusProc. */ 
 390      * Information used by tkOption.c to manage options for the 
 394     int optionLevel
;            /* -1 means no option information is 
 395                                  * currently cached for this window. 
 396                                  * Otherwise this gives the level in 
 397                                  * the option stack at which info is 
 400      * Information used by tkSelect.c to manage the selection. 
 403     TkSelHandler 
*selHandlerList
; 
 404                                 /* First in list of handlers for 
 405                                  * returning the selection in various 
 407     Tk_LostSelProc 
*selClearProc
; 
 408     ClientData selClearData
;    /* Info to pass to selClearProc. */ 
 411      * Information used by tkGeometry.c for geometry management. 
 414     Tk_GeometryProc 
*geomProc
;  /* Procedure to handle geometry 
 415                                  * requests (NULL means no window is 
 417     ClientData geomData
;        /* Argument for geomProc. */ 
 418     int reqWidth
, reqHeight
;    /* Arguments from last call to 
 419                                  * Tk_GeometryRequest, or 0's if 
 420                                  * Tk_GeometryRequest hasn't been 
 422     int internalBorderWidth
;    /* Width of internal border of window 
 423                                  * (0 means no internal border).  Geom. 
 424                                  * mgr. should not place children on top 
 428      * Information maintained by tkWm.c for window manager communication. 
 431     struct TkWmInfo 
*wmInfoPtr
; /* For top-level windows, points to 
 432                                  * structure with wm-related info (see 
 433                                  * tkWm.c).  For other windows, this 
 438  * The context below is used to map from an X window id to 
 439  * the TkWindow structure associated with the window. 
 442 extern XContext tkWindowContext
; 
 445  * Pointer to first entry in list of all displays currently known. 
 448 extern TkDisplay 
*tkDisplayList
; 
 451  * Flags passed to TkMeasureChars: 
 454 #define TK_WHOLE_WORDS          1 
 455 #define TK_AT_LEAST_ONE         2 
 456 #define TK_PARTIAL_OK           4 
 457 #define TK_NEWLINES_NOT_SPECIAL 8 
 460  * Location of library directory containing Tk scripts.  This value 
 461  * is put in the $tkLibrary variable for each application. 
 466 #define TK_LIBRARY "res/tk" 
 468 #define TK_LIBRARY "/usr/local/lib/tk" 
 473  * See tkShare.c for explanation of following disgusting variable: 
 476 extern XEvent 
*tkShareEventPtr
; 
 479  * Secret way to inhibit event collapsing.  -deh 
 482 extern int              tkCollapseMotion
; 
 485  * Secret way to break out to Tk_MainLoop.  -deh 
 488 extern int              tkMustExit
; 
 491  * Miscellaneous variables shared among Tk modules but not exported 
 492  * to the outside world: 
 495 extern Tk_Uid           tkActiveUid
; 
 496 extern Tk_Uid           tkDisabledUid
; 
 497 extern Tk_Uid           tkNormalUid
; 
 500  * Internal procedures shared among Tk modules but not exported 
 501  * to the outside world: 
 504 extern int              TkAreaToPolygon 
_ANSI_ARGS_((double *polyPtr
, 
 505                             int numPoints
, double *rectPtr
)); 
 506 extern void             TkBezierPoints 
_ANSI_ARGS_((double control
[], 
 507                             int numSteps
, double *coordPtr
)); 
 508 extern void             TkBindError 
_ANSI_ARGS_((Tcl_Interp 
*interp
)); 
 509 extern void             TkBindEventProc 
_ANSI_ARGS_((TkWindow 
*winPtr
, 
 511 extern Time             TkCurrentTime 
_ANSI_ARGS_((TkDisplay 
*dispPtr
)); 
 512 extern int              TkDeadAppCmd 
_ANSI_ARGS_((ClientData clientData
, 
 513                             Tcl_Interp 
*interp
, int argc
, char **argv
)); 
 514 extern void             TkDisplayChars 
_ANSI_ARGS_((Display 
*display
, 
 515                             Drawable drawable
, GC gc
, 
 516                             XFontStruct 
*fontStructPtr
, char *string
, 
 517                             int numChars
, int x
, int y
, int flags
)); 
 518 extern void             TkEventDeadWindow 
_ANSI_ARGS_((TkWindow 
*winPtr
)); 
 519 extern void             TkFocusEventProc 
_ANSI_ARGS_((TkWindow 
*winPtr
, 
 521 extern void             TkGetButtPoints 
_ANSI_ARGS_((double p1
[], double p2
[], 
 522                             double width
, int project
, double m1
[], 
 524 extern int              TkGetInterpNames 
_ANSI_ARGS_((Tcl_Interp 
*interp
, 
 526 extern int              TkGetMiterPoints 
_ANSI_ARGS_((double p1
[], double p2
[], 
 527                             double p3
[], double width
, double m1
[], 
 529 extern void             TkGrabDeadWindow 
_ANSI_ARGS_((TkWindow 
*winPtr
)); 
 530 extern int              TkLineToArea 
_ANSI_ARGS_((double end1Ptr
[2], 
 531                             double end2Ptr
[2], double rectPtr
[4])); 
 532 extern double           TkLineToPoint 
_ANSI_ARGS_((double end1Ptr
[2], 
 533                             double end2Ptr
[2], double pointPtr
[2])); 
 534 extern int              TkMeasureChars 
_ANSI_ARGS_((XFontStruct 
*fontStructPtr
, 
 535                             char *source
, int maxChars
, int startX
, int maxX
, 
 536                             int flags
, int *nextXPtr
)); 
 537 extern void             TkOptionDeadWindow 
_ANSI_ARGS_((TkWindow 
*winPtr
)); 
 538 extern int              TkOvalToArea 
_ANSI_ARGS_((double *ovalPtr
, 
 540 extern double           TkOvalToPoint 
_ANSI_ARGS_((double ovalPtr
[4], 
 541                             double width
, int filled
, double pointPtr
[2])); 
 542 extern int              TkPointerEvent 
_ANSI_ARGS_((XEvent 
*eventPtr
, 
 544 extern int              TkPolygonToArea 
_ANSI_ARGS_((double *polyPtr
, 
 545                             int numPoints
, double *rectPtr
)); 
 546 extern double           TkPolygonToPoint 
_ANSI_ARGS_((double *polyPtr
, 
 547                             int numPoints
, double *pointPtr
)); 
 548 extern void             TkSelDeadWindow 
_ANSI_ARGS_((TkWindow 
*winPtr
)); 
 549 extern void             TkSelEventProc 
_ANSI_ARGS_((Tk_Window tkwin
, 
 551 extern void             TkSelPropProc 
_ANSI_ARGS_((XEvent 
*eventPtr
)); 
 552 extern void             TkUnderlineChars 
_ANSI_ARGS_((Display 
*display
, 
 553                             Drawable drawable
, GC gc
, 
 554                             XFontStruct 
*fontStructPtr
, char *string
, 
 555                             int x
, int y
, int flags
, int firstChar
, 
 557 extern void             TkWmDeadWindow 
_ANSI_ARGS_((TkWindow 
*winPtr
)); 
 558 extern int              TkWmMapWindow 
_ANSI_ARGS_((TkWindow 
*winPtr
)); 
 559 extern void             TkWmSetClass 
_ANSI_ARGS_((TkWindow 
*winPtr
)); 
 560 extern void             TkWmNewWindow 
_ANSI_ARGS_((TkWindow 
*winPtr
));