v08i078: chaos, Part02/10

Ken Marks x2425 balr!panasun!ken at uunet.UU.NET
Tue Aug 21 04:03:21 AEST 1990


Submitted-by: balr!panasun!ken at uunet.UU.NET (Ken Marks (x2425))
Posting-number: Volume 8, Issue 78
Archive-name: chaos/part02

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 2 (of 10)."
# Contents:  common/showEvent.c gencmap/Imakefile gencmap/gencmap.c
#   widgets/List.c
# Wrapped by ken at panasun on Mon Jul 30 14:59:47 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'common/showEvent.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'common/showEvent.c'\"
else
echo shar: Extracting \"'common/showEvent.c'\" \(23550 characters\)
sed "s/^X//" >'common/showEvent.c' <<'END_OF_FILE'
X/*
X * Copyright (c) Ken W. Marks 1989, 1990.
X */
X
X#include <stdio.h>
X#include <X11/Intrinsic.h>
X#include <X11/Xproto.h>
X#include <Chaos.h>
X
XBoolean use_separate_lines = True;
Xstatic char *sep;
X
X/******************************************************************************/
X/**** Miscellaneous routines to convert values to their string equivalents ****/
X/******************************************************************************/
X
X/* Returns the string equivalent of a boolean parameter */
Xstatic char *TorF(bool)
Xint bool;
X{
X    switch (bool)
X    {
X    case True:
X	return ("True");
X
X    case False:
X	return ("False");
X
X    default:
X	return ("?");
X    }
X}
X
X/* Returns the string equivalent of a property notify state */
Xstatic char *PropertyState(state)
Xint state;
X{
X    switch (state)
X    {
X    case PropertyNewValue:
X	return ("PropertyNewValue");
X
X    case PropertyDelete:
X	return ("PropertyDelete");
X
X    default:
X	return ("?");
X    }
X}
X
X/* Returns the string equivalent of a visibility notify state */
Xstatic char *VisibilityState(state)
Xint state;
X{
X    switch (state)
X    {
X    case VisibilityUnobscured:
X	return ("VisibilityUnobscured");
X
X    case VisibilityPartiallyObscured:
X	return ("VisibilityPartiallyObscured");
X
X    case VisibilityFullyObscured:
X	return ("VisibilityFullyObscured");
X
X    default:
X	return ("?");
X    }
X}
X
X/* Returns the string equivalent of a timestamp */
Xstatic char *ServerTime(time)
XTime time;
X{
X    unsigned long msec;
X    unsigned long sec;
X    unsigned long min;
X    unsigned long hr;
X    unsigned long day;
X    static char buffer[32];
X
X    msec = time % 1000;
X    time /= 1000;
X    sec = time % 60;
X    time /= 60;
X    min = time % 60;
X    time /= 60;
X    hr = time % 24;
X    time /= 24;
X    day = time;
X
X    (void) sprintf(buffer, "%d day%s %02d:%02d:%02d.%03d",
X      day, day == 1 ? "" : "(s)", hr, min, sec, msec);
X    return (buffer);
X}
X
X/* Simple structure to ease the interpretation of masks */
Xtypedef struct _MaskType
X{
X    unsigned int value;
X    char *string;
X} MaskType;
X
X/* Returns the string equivalent of a mask of buttons and modifier keys */
Xstatic char *ButtonOrModifierState(state)
Xunsigned int state;
X{
X    static char buffer[256];
X    static MaskType masks[] = {
X	{ShiftMask, "ShiftMask"},
X	{LockMask, "LockMask"},
X	{ControlMask, "ControlMask"},
X	{Mod1Mask, "Mod1Mask"},
X	{Mod2Mask, "Mod2Mask"},
X	{Mod3Mask, "Mod3Mask"},
X	{Mod4Mask, "Mod4Mask"},
X	{Mod5Mask, "Mod5Mask"},
X	{Button1Mask, "Button1Mask"},
X	{Button2Mask, "Button2Mask"},
X	{Button3Mask, "Button3Mask"},
X	{Button4Mask, "Button4Mask"},
X	{Button5Mask, "Button5Mask"},
X    };
X    int num_masks = sizeof(masks) / sizeof(MaskType);
X    int ii;
X    Boolean first = True;
X
X    buffer[0] = NULL;
X
X    if (state == 0)
X	return (buffer);
X
X    for (ii = 0; ii < num_masks; ii++)
X	if (state & masks[ii].value)
X	    if (first)
X	    {
X		first = False;
X		(void) strcat(buffer, masks[ii].string);
X	    }
X	    else
X	    {
X		(void) strcat(buffer, " | ");
X		(void) strcat(buffer, masks[ii].string);
X	    }
X    return (buffer);
X}
X
X/* Returns the string equivalent of a mask of configure window values */
Xstatic char *ConfigureValueMask(valuemask)
Xunsigned long valuemask;
X{
X    static char buffer[256];
X    static MaskType masks[] = {
X	{CWX, "CWX"},
X	{CWY, "CWY"},
X	{CWWidth, "CWWidth"},
X	{CWHeight, "CWHeight"},
X	{CWBorderWidth, "CWBorderWidth"},
X	{CWSibling, "CWSibling"},
X	{CWStackMode, "CWStackMode"},
X    };
X    int num_masks = sizeof(masks) / sizeof(MaskType);
X    int ii;
X    Boolean first = True;
X
X    buffer[0] = NULL;
X
X    if (valuemask == 0)
X	return (buffer);
X
X    for (ii = 0; ii < num_masks; ii++)
X	if (valuemask & masks[ii].value)
X	    if (first)
X	    {
X		first = False;
X		(void) strcat(buffer, masks[ii].string);
X	    }
X	    else
X	    {
X		(void) strcat(buffer, " | ");
X		(void) strcat(buffer, masks[ii].string);
X	    }
X
X    return (buffer);
X}
X
X/* Returns the string equivalent of a motion hint */
Xstatic char *IsHint(is_hint)
Xchar is_hint;
X{
X    switch (is_hint)
X    {
X    case NotifyNormal:
X	return ("NotifyNormal");
X
X    case NotifyHint:
X	return ("NotifyHint");
X
X    default:
X	return ("?");
X    }
X}
X
X/* Returns the string equivalent of an id or the value "None" */
Xstatic char *MaybeNone(value)
Xint value;
X{
X    static char buffer[16];
X
X    if (value == None)
X	return ("None");
X    else
X    {
X	(void) sprintf(buffer, "0x%x", value);
X	return (buffer);
X    }
X}
X
X/* Returns the string equivalent of a colormap state */
Xstatic char *ColormapState(state)
Xint state;
X{
X    switch (state)
X    {
X    case ColormapInstalled:
X	return ("ColormapInstalled");
X
X    case ColormapUninstalled:
X	return ("ColormapUninstalled");
X
X    default:
X	return ("?");
X    }
X}
X
X/* Returns the string equivalent of a crossing detail */
Xstatic char *CrossingDetail(detail)
Xint detail;
X{
X    switch (detail)
X    {
X    case NotifyAncestor:
X	return ("NotifyAncestor");
X
X    case NotifyInferior:
X	return ("NotifyInferior");
X
X    case NotifyVirtual:
X	return ("NotifyVirtual");
X
X    case NotifyNonlinear:
X	return ("NotifyNonlinear");
X
X    case NotifyNonlinearVirtual:
X	return ("NotifyNonlinearVirtual");
X
X    default:
X	return ("?");
X    }
X}
X
X/* Returns the string equivalent of a focus change detail */
Xstatic char *FocusChangeDetail(detail)
Xint detail;
X{
X    switch (detail)
X    {
X    case NotifyAncestor:
X	return ("NotifyAncestor");
X
X    case NotifyInferior:
X	return ("NotifyInferior");
X
X    case NotifyVirtual:
X	return ("NotifyVirtual");
X
X    case NotifyNonlinear:
X	return ("NotifyNonlinear");
X
X    case NotifyNonlinearVirtual:
X	return ("NotifyNonlinearVirtual");
X
X    case NotifyPointer:
X	return ("NotifyPointer");
X
X    case NotifyPointerRoot:
X	return ("NotifyPointerRoot");
X
X    case NotifyDetailNone:
X	return ("NotifyDetailNone");
X
X    default:
X	return ("?");
X    }
X}
X
X/* Returns the string equivalent of a configure detail */
Xstatic char *ConfigureDetail(detail)
Xint detail;
X{
X    switch (detail)
X    {
X    case Above:
X	return ("Above");
X
X    case Below:
X	return ("Below");
X
X    case TopIf:
X	return ("TopIf");
X
X    case BottomIf:
X	return ("BottomIf");
X
X    case Opposite:
X	return ("Opposite");
X
X    default:
X	return ("?");
X    }
X}
X
X/* Returns the string equivalent of a grab mode */
Xstatic char *GrabMode(mode)
Xint mode;
X{
X    switch (mode)
X    {
X    case NotifyNormal:
X	return ("NotifyNormal");
X
X    case NotifyGrab:
X	return ("NotifyGrab");
X
X    case NotifyUngrab:
X	return ("NotifyUngrab");
X
X    case NotifyWhileGrabbed:
X	return ("NotifyWhileGrabbed");
X
X    default:
X	return ("?");
X    }
X}
X
X/* Returns the string equivalent of a mapping request */
Xstatic char *MappingRequest(request)
Xint request;
X{
X    switch (request)
X    {
X    case MappingModifier:
X	return ("MappingModifier");
X
X    case MappingKeyboard:
X	return ("MappingKeyboard");
X
X    case MappingPointer:
X	return ("MappingPointer");
X
X    default:
X	return ("?");
X    }
X}
X
X/* Returns the string equivalent of a stacking order place */
Xstatic char *Place(place)
Xint place;
X{
X    switch (place)
X    {
X    case PlaceOnTop:
X	return ("PlaceOnTop");
X
X    case PlaceOnBottom:
X	return ("PlaceOnBottom");
X
X    default:
X	return ("?");
X    }
X}
X
X/* Returns the string equivalent of a major code */
Xstatic char *MajorCode(code)
Xint code;
X{
X    static char buffer[32];
X
X    switch (code)
X    {
X    case X_CopyArea:
X	return ("X_CopyArea");
X
X    case X_CopyPlane:
X	return ("X_CopyPlane");
X
X    default:
X	(void) sprintf(buffer, "0x%x", code);
X	return (buffer);
X    }
X}
X
X/* Returns the string equivalent the keycode contained in the key event */
Xstatic char *Keycode(ev)
XXKeyEvent *ev;
X{
X    static char buffer[256];
X    KeySym keysym_str;
X    char *keysym_name;
X    char string[256];
X
X    XLookupString(ev, string, 64, &keysym_str, NULL);
X
X    if (keysym_str == NoSymbol)
X	keysym_name = "NoSymbol";
X    else if (!(keysym_name = XKeysymToString(keysym_str)))
X	keysym_name = "(no name)";
X    (void) sprintf(buffer, "%u (keysym 0x%x \"%s\")",
X      ev->keycode, keysym_str, keysym_name);
X    return (buffer);
X}
X
X/* Returns the string equivalent of an atom or "None"*/
Xstatic char *AtomName(dpy, atom)
XDisplay *dpy;
XAtom atom;
X{
X    static char buffer[256];
X    char *atom_name;
X
X    if (atom == None)
X	return ("None");
X
X    atom_name = XGetAtomName(dpy, atom);
X    (void) strncpy(buffer, atom_name, 256);
X    free(atom_name);
X
X    return (buffer);
X}
X
X/******************************************************************************/
X/**** Routines to print out readable values for the field of various events ***/
X/******************************************************************************/
X
Xstatic void VerbMotion(ev)
XXMotionEvent *ev;
X{
X    (void) printf("window = 0x%x%s", ev->window, sep);
X    (void) printf("root = 0x%x%s", ev->root, sep);
X    (void) printf("subwindow = 0x%x%s", ev->subwindow, sep);
X    (void) printf("time = %s%s", ServerTime(ev->time), sep);
X    (void) printf("x = %d  y = %d%s", ev->x, ev->y, sep);
X    (void) printf("x_root = %d  y_root = %d%s", ev->x_root, ev->y_root, sep);
X    (void) printf("state = %s%s", ButtonOrModifierState(ev->state), sep);
X    (void) printf("is_hint = %s%s", IsHint(ev->is_hint), sep);
X    (void) printf("same_screen = %s\n", TorF(ev->same_screen));
X}
X
Xstatic void VerbButton(ev)
XXButtonEvent *ev;
X{
X    (void) printf("window = 0x%x%s", ev->window, sep);
X    (void) printf("root = 0x%x%s", ev->root, sep);
X    (void) printf("subwindow = 0x%x%s", ev->subwindow, sep);
X    (void) printf("time = %s%s", ServerTime(ev->time), sep);
X    (void) printf("x = %d  y = %d%s", ev->x, ev->y, sep);
X    (void) printf("x_root = %d  y_root = %d%s", ev->x_root, ev->y_root, sep);
X    (void) printf("state = %s%s", ButtonOrModifierState(ev->state), sep);
X    (void) printf("button = Button%d%s", ev->button, sep);
X    (void) printf("same_screen = %s\n", TorF(ev->same_screen));
X}
X
Xstatic void VerbColormap(ev)
XXColormapEvent *ev;
X{
X    (void) printf("window = 0x%x%s", ev->window, sep);
X    (void) printf("colormap = %s%s", MaybeNone((int) (ev->colormap)), sep);
X    (void) printf("new = %s%s", TorF(ev->new), sep);
X    (void) printf("state = %s\n", ColormapState(ev->state));
X}
X
Xstatic void VerbCrossing(ev)
XXCrossingEvent *ev;
X{
X    (void) printf("window = 0x%x%s", ev->window, sep);
X    (void) printf("root = 0x%x%s", ev->root, sep);
X    (void) printf("subwindow = 0x%x%s", ev->subwindow, sep);
X    (void) printf("time = %s%s", ServerTime(ev->time), sep);
X    (void) printf("x = %d  y = %d%s", ev->x, ev->y, sep);
X    (void) printf("x_root = %d  y_root = %d%s", ev->x_root, ev->y_root, sep);
X    (void) printf("mode = %s%s", GrabMode(ev->mode), sep);
X    (void) printf("detail = %s%s", CrossingDetail(ev->detail), sep);
X    (void) printf("same_screen = %s%s", TorF(ev->same_screen), sep);
X    (void) printf("focus = %s%s", TorF(ev->focus), sep);
X    (void) printf("state = %s\n", ButtonOrModifierState(ev->state));
X}
X
Xstatic void VerbExpose(ev)
XXExposeEvent *ev;
X{
X    (void) printf("window = 0x%x%s", ev->window, sep);
X    (void) printf("x = %d  y = %d%s", ev->x, ev->y, sep);
X    (void) printf("width = %d height = %d%s", ev->width, ev->height, sep);
X    (void) printf("count = %d\n", ev->count);
X}
X
Xstatic void VerbGraphicsExpose(ev)
XXGraphicsExposeEvent *ev;
X{
X    (void) printf("drawable = 0x%x%s", ev->drawable, sep);
X    (void) printf("x = %d  y = %d%s", ev->x, ev->y, sep);
X    (void) printf("width = %d height = %d%s", ev->width, ev->height, sep);
X    (void) printf("major_code = %s%s", MajorCode(ev->major_code), sep);
X    (void) printf("minor_code = %d\n", ev->minor_code);
X}
X
Xstatic void VerbNoExpose(ev)
XXNoExposeEvent *ev;
X{
X    (void) printf("drawable = 0x%x%s", ev->drawable, sep);
X    (void) printf("major_code = %s%s", MajorCode(ev->major_code), sep);
X    (void) printf("minor_code = %d\n", ev->minor_code);
X}
X
Xstatic void VerbFocus(ev)
XXFocusChangeEvent *ev;
X{
X    (void) printf("window = 0x%x%s", ev->window, sep);
X    (void) printf("mode = %s%s", GrabMode(ev->mode), sep);
X    (void) printf("detail = %s\n", FocusChangeDetail(ev->detail));
X}
X
Xstatic void VerbKeymap(ev)
XXKeymapEvent *ev;
X{
X    int ii;
X
X    (void) printf("window = 0x%x%s", ev->window, sep);
X    (void) printf("key_vector = ");
X    for (ii = 0; ii < 32; ii++)
X	(void) printf("%02x", ev->key_vector[ii]);
X    (void) printf("\n");
X}
X
Xstatic void VerbKey(ev)
XXKeyEvent *ev;
X{
X    (void) printf("window = 0x%x%s", ev->window, sep);
X    (void) printf("root = 0x%x%s", ev->root, sep);
X    (void) printf("subwindow = 0x%x%s", ev->subwindow, sep);
X    (void) printf("time = %s%s", ServerTime(ev->time), sep);
X    (void) printf("x = %d  y = %d%s", ev->x, ev->y, sep);
X    (void) printf("x_root = %d  y_root = %d%s", ev->x_root, ev->y_root, sep);
X    (void) printf("state = %s%s", ButtonOrModifierState(ev->state), sep);
X    (void) printf("keycode = %s%s", Keycode(ev), sep);
X    (void) printf("same_screen = %s\n", TorF(ev->same_screen));
X}
X
Xstatic void VerbProperty(ev)
XXPropertyEvent *ev;
X{
X    (void) printf("window = 0x%x%s", ev->window, sep);
X    (void) printf("atom = %s%s", AtomName(ev->display, ev->atom), sep);
X    (void) printf("time = %s%s", ServerTime(ev->time), sep);
X    (void) printf("state = %s\n", PropertyState(ev->state));
X}
X
Xstatic void VerbResizeRequest(ev)
XXResizeRequestEvent *ev;
X{
X    (void) printf("window = 0x%x%s", ev->window, sep);
X    (void) printf("width = %d height = %d\n", ev->width, ev->height);
X}
X
Xstatic void VerbCirculate(ev)
XXCirculateEvent *ev;
X{
X    (void) printf("event = 0x%x%s", ev->event, sep);
X    (void) printf("window = 0x%x%s", ev->window, sep);
X    (void) printf("place = %s\n", Place(ev->place));
X}
X
Xstatic void VerbConfigure(ev)
XXConfigureEvent *ev;
X{
X    (void) printf("event = 0x%x%s", ev->event, sep);
X    (void) printf("window = 0x%x%s", ev->window, sep);
X    (void) printf("x = %d  y = %d%s", ev->x, ev->y, sep);
X    (void) printf("width = %d height = %d%s", ev->width, ev->height, sep);
X    (void) printf("border_width = %d%s", ev->border_width, sep);
X    (void) printf("above = %s%s", MaybeNone((int) (ev->above)), sep);
X    (void) printf("override_redirect = %s\n", TorF(ev->override_redirect));
X}
X
Xstatic void VerbCreateWindow(ev)
XXCreateWindowEvent *ev;
X{
X    (void) printf("parent = 0x%x%s", ev->parent, sep);
X    (void) printf("window = 0x%x%s", ev->window, sep);
X    (void) printf("x = %d  y = %d%s", ev->x, ev->y, sep);
X    (void) printf("width = %d height = %d%s", ev->width, ev->height, sep);
X    (void) printf("border_width = %d%s", ev->border_width, sep);
X    (void) printf("override_redirect = %s\n", TorF(ev->override_redirect));
X}
X
Xstatic void VerbDestroyWindow(ev)
XXDestroyWindowEvent *ev;
X{
X    (void) printf("event = 0x%x%s", ev->event, sep);
X    (void) printf("window = 0x%x\n", ev->window);
X}
X
Xstatic void VerbGravity(ev)
XXGravityEvent *ev;
X{
X    (void) printf("event = 0x%x%s", ev->event, sep);
X    (void) printf("window = 0x%x%s", ev->window, sep);
X    (void) printf("x = %d  y = %d\n", ev->x, ev->y);
X}
X
Xstatic void VerbMap(ev)
XXMapEvent *ev;
X{
X    (void) printf("event = 0x%x%s", ev->event, sep);
X    (void) printf("window = 0x%x%s", ev->window, sep);
X    (void) printf("override_redirect = %s\n", TorF(ev->override_redirect));
X}
X
Xstatic void VerbReparent(ev)
XXReparentEvent *ev;
X{
X    (void) printf("event = 0x%x%s", ev->event, sep);
X    (void) printf("window = 0x%x%s", ev->window, sep);
X    (void) printf("parent = 0x%x%s", ev->parent, sep);
X    (void) printf("x = %d  y = %d%s", ev->x, ev->y, sep);
X    (void) printf("override_redirect = %s\n", TorF(ev->override_redirect));
X}
X
Xstatic void VerbUnmap(ev)
XXUnmapEvent *ev;
X{
X    (void) printf("event = 0x%x%s", ev->event, sep);
X    (void) printf("window = 0x%x%s", ev->window, sep);
X    (void) printf("from_configure = %s\n", TorF(ev->from_configure));
X}
X
Xstatic void VerbCirculateRequest(ev)
XXCirculateRequestEvent *ev;
X{
X    (void) printf("parent = 0x%x%s", ev->parent, sep);
X    (void) printf("window = 0x%x%s", ev->window, sep);
X    (void) printf("place = %s\n", Place(ev->place));
X}
X
Xstatic void VerbConfigureRequest(ev)
XXConfigureRequestEvent *ev;
X{
X    (void) printf("parent = 0x%x%s", ev->parent, sep);
X    (void) printf("window = 0x%x%s", ev->window, sep);
X    (void) printf("x = %d  y = %d%s", ev->x, ev->y, sep);
X    (void) printf("width = %d height = %d%s", ev->width, ev->height, sep);
X    (void) printf("border_width = %d%s", ev->border_width, sep);
X    (void) printf("above = %s%s", MaybeNone((int) (ev->above)), sep);
X    (void) printf("detail = 0x%x%s", ConfigureDetail(ev->detail), sep);
X    (void) printf("value_mask = %s\n", ConfigureValueMask(ev->value_mask));
X}
X
Xstatic void VerbMapRequest(ev)
XXMapRequestEvent *ev;
X{
X    (void) printf("parent = 0x%x%s", ev->parent, sep);
X    (void) printf("window = 0x%x\n", ev->window);
X}
X
Xstatic void VerbClient(ev)
XXClientMessageEvent *ev;
X{
X    int ii;
X
X    (void) printf("window = 0x%x%s", ev->window, sep);
X    (void) printf("message_type = %s%s", AtomName(ev->display,
X	ev->message_type), sep);
X    (void) printf("format = %d\n", ev->format);
X    (void) printf("data (shown as longs) = ");
X    for (ii = 0; ii < 5; ii++)
X	(void) printf(" 0x%08x", ev->data.l[ii]);
X    (void) printf("\n");
X}
X
Xstatic void VerbMapping(ev)
XXMappingEvent *ev;
X{
X    (void) printf("window = 0x%x%s", ev->window, sep);
X    (void) printf("request = 0x%x%s", MappingRequest(ev->request), sep);
X    (void) printf("first_keycode = 0x%x%s", ev->first_keycode, sep);
X    (void) printf("count = 0x%x\n", ev->count);
X}
X
Xstatic void VerbSelectionClear(ev)
XXSelectionClearEvent *ev;
X{
X    (void) printf("window = 0x%x%s", ev->window, sep);
X    (void) printf("selection = %s%s", AtomName(ev->display, ev->selection),
X      sep);
X    (void) printf("time = %s\n", ServerTime(ev->time));
X}
X
Xstatic void VerbSelection(ev)
XXSelectionEvent *ev;
X{
X    (void) printf("requestor = 0x%x%s", ev->requestor, sep);
X    (void) printf("selection = %s%s", AtomName(ev->display, ev->selection),
X      sep);
X    (void) printf("target = %s%s", AtomName(ev->display, ev->target), sep);
X    (void) printf("property = %s%s", AtomName(ev->display, ev->property), sep);
X    (void) printf("time = %s\n", ServerTime(ev->time));
X}
X
Xstatic void VerbSelectionRequest(ev)
XXSelectionRequestEvent *ev;
X{
X    (void) printf("owner = 0x%x%s", ev->owner, sep);
X    (void) printf("requestor = 0x%x%s", ev->requestor, sep);
X    (void) printf("selection = %s%s", AtomName(ev->display, ev->selection),
X      sep);
X    (void) printf("target = %s%s", AtomName(ev->display, ev->target), sep);
X    (void) printf("property = %s%s", AtomName(ev->display, ev->property), sep);
X    (void) printf("time = %s\n", ServerTime(ev->time));
X}
X
Xstatic void VerbVisibility(ev)
XXVisibilityEvent *ev;
X{
X    (void) printf("window = 0x%x%s", ev->window, sep);
X    (void) printf("state = %s\n", VisibilityState(ev->state));
X}
X
X/******************************************************************************/
X/************ Return the string representation for type of an event ***********/
X/******************************************************************************/
X
Xchar *GetEventType(ev)
XXEvent *ev;
X{
X    switch (ev->type)
X    {
X    case KeyPress:
X	return ("KeyPress");
X    case KeyRelease:
X	return ("KeyRelease");
X    case ButtonPress:
X	return ("ButtonPress");
X    case ButtonRelease:
X	return ("ButtonRelease");
X    case MotionNotify:
X	return ("MotionNotify");
X    case EnterNotify:
X	return ("EnterNotify");
X    case LeaveNotify:
X	return ("LeaveNotify");
X    case FocusIn:
X	return ("FocusIn");
X    case FocusOut:
X	return ("FocusOut");
X    case KeymapNotify:
X	return ("KeymapNotify");
X    case Expose:
X	return ("Expose");
X    case GraphicsExpose:
X	return ("GraphicsExpose");
X    case NoExpose:
X	return ("NoExpose");
X    case VisibilityNotify:
X	return ("VisibilityNotify");
X    case CreateNotify:
X	return ("CreateNotify");
X    case DestroyNotify:
X	return ("DestroyNotify");
X    case UnmapNotify:
X	return ("UnmapNotify");
X    case MapNotify:
X	return ("MapNotify");
X    case MapRequest:
X	return ("MapRequest");
X    case ReparentNotify:
X	return ("ReparentNotify");
X    case ConfigureNotify:
X	return ("ConfigureNotify");
X    case ConfigureRequest:
X	return ("ConfigureRequest");
X    case GravityNotify:
X	return ("GravityNotify");
X    case ResizeRequest:
X	return ("ResizeRequest");
X    case CirculateNotify:
X	return ("CirculateNotify");
X    case CirculateRequest:
X	return ("CirculateRequest");
X    case PropertyNotify:
X	return ("PropertyNotify");
X    case SelectionClear:
X	return ("SelectionClear");
X    case SelectionRequest:
X	return ("SelectionRequest");
X    case SelectionNotify:
X	return ("SelectionNotify");
X    case ColormapNotify:
X	return ("ColormapNotify");
X    case ClientMessage:
X	return ("ClientMessage");
X    case MappingNotify:
X	return ("MappingNotify");
X    }
X    return (NULL);		/* this makes lint happy */
X}
X
X/******************************************************************************/
X/**************** Print the values of all fields for any event ****************/
X/******************************************************************************/
X
Xvoid ShowEvent(ev)
XXAnyEvent *ev;
X{
X    /* determine which field separator to use */
X    if (use_separate_lines)
X	sep = "\n";
X    else
X	sep = " ";
X
X    (void) printf("type = %s%s", GetEventType((XEvent *) ev), sep);
X    (void) printf("serial = %d%s", ev->serial, sep);
X    (void) printf("send_event = %s%s", TorF(ev->send_event), sep);
X    (void) printf("display = 0x%x%s", ev->display, sep);
X
X    switch (ev->type)
X    {
X    case MotionNotify:
X	VerbMotion((XMotionEvent *) ev);
X	break;
X
X    case ButtonPress:
X    case ButtonRelease:
X	VerbButton((XButtonEvent *) ev);
X	break;
X
X    case ColormapNotify:
X	VerbColormap((XColormapEvent *) ev);
X	break;
X
X    case EnterNotify:
X    case LeaveNotify:
X	VerbCrossing((XCrossingEvent *) ev);
X	break;
X
X    case Expose:
X	VerbExpose((XExposeEvent *) ev);
X	break;
X
X    case GraphicsExpose:
X	VerbGraphicsExpose((XGraphicsExposeEvent *) ev);
X	break;
X
X    case NoExpose:
X	VerbNoExpose((XNoExposeEvent *) ev);
X	break;
X
X    case FocusIn:
X    case FocusOut:
X	VerbFocus((XFocusChangeEvent *) ev);
X	break;
X
X    case KeymapNotify:
X	VerbKeymap((XKeymapEvent *) ev);
X	break;
X
X    case KeyPress:
X    case KeyRelease:
X	VerbKey((XKeyEvent *) ev);
X	break;
X
X    case PropertyNotify:
X	VerbProperty((XPropertyEvent *) ev);
X	break;
X
X    case ResizeRequest:
X	VerbResizeRequest((XResizeRequestEvent *) ev);
X	break;
X
X    case CirculateNotify:
X	VerbCirculate((XCirculateEvent *) ev);
X	break;
X
X    case ConfigureNotify:
X	VerbConfigure((XConfigureEvent *) ev);
X	break;
X
X    case CreateNotify:
X	VerbCreateWindow((XCreateWindowEvent *) ev);
X	break;
X
X    case DestroyNotify:
X	VerbDestroyWindow((XDestroyWindowEvent *) ev);
X	break;
X
X    case GravityNotify:
X	VerbGravity((XGravityEvent *) ev);
X	break;
X
X    case MapNotify:
X	VerbMap((XMapEvent *) ev);
X	break;
X
X    case ReparentNotify:
X	VerbReparent((XReparentEvent *) ev);
X	break;
X
X    case UnmapNotify:
X	VerbUnmap((XUnmapEvent *) ev);
X	break;
X
X    case CirculateRequest:
X	VerbCirculateRequest((XCirculateRequestEvent *) ev);
X	break;
X
X    case ConfigureRequest:
X	VerbConfigureRequest((XConfigureRequestEvent *) ev);
X	break;
X
X    case MapRequest:
X	VerbMapRequest((XMapRequestEvent *) ev);
X	break;
X
X    case ClientMessage:
X	VerbClient((XClientMessageEvent *) ev);
X	break;
X
X    case MappingNotify:
X	VerbMapping((XMappingEvent *) ev);
X	break;
X
X    case SelectionClear:
X	VerbSelectionClear((XSelectionClearEvent *) ev);
X	break;
X
X    case SelectionNotify:
X	VerbSelection((XSelectionEvent *) ev);
X	break;
X
X    case SelectionRequest:
X	VerbSelectionRequest((XSelectionRequestEvent *) ev);
X	break;
X
X    case VisibilityNotify:
X	VerbVisibility((XVisibilityEvent *) ev);
X	break;
X
X    }
X}
END_OF_FILE
if test 23550 -ne `wc -c <'common/showEvent.c'`; then
    echo shar: \"'common/showEvent.c'\" unpacked with wrong size!
fi
# end of 'common/showEvent.c'
fi
if test -f 'gencmap/Imakefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'gencmap/Imakefile'\"
else
echo shar: Extracting \"'gencmap/Imakefile'\" \(394 characters\)
sed "s/^X//" >'gencmap/Imakefile' <<'END_OF_FILE'
X       INCLUDES = -I../headers
X      COMMONLIB = ../common/libcommon.a
X        DEPLIBS = $(COMMONLIB) $(DEPXLIB)
X  SYS_LIBRARIES = -lm
X
X#ifdef UltrixArchitecture
XLOCAL_LIBRARIES = $(DEPLIBS)
X#else
XLOCAL_LIBRARIES = $(COMMONLIB) $(XLIB)
X#endif
X
XSRCS = \
X	gencmap.c
X
XOBJS = \
X	gencmap.o
X
XComplexProgramTarget(gencmap)
X
Xsaber_src:
X	#cd ../common
X	#make saber
X	#cd ../gencmap
X	#make saber_gencmap
X
END_OF_FILE
if test 394 -ne `wc -c <'gencmap/Imakefile'`; then
    echo shar: \"'gencmap/Imakefile'\" unpacked with wrong size!
fi
# end of 'gencmap/Imakefile'
fi
if test -f 'gencmap/gencmap.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'gencmap/gencmap.c'\"
else
echo shar: Extracting \"'gencmap/gencmap.c'\" \(3267 characters\)
sed "s/^X//" >'gencmap/gencmap.c' <<'END_OF_FILE'
X/*
X * Copyright (c) Ken W. Marks 1989, 1990.
X */
X
X#include <stdio.h>
X#include <ctype.h>
X#include <math.h>
X#include <values.h>
X#include <X11/Intrinsic.h>
X#include <Colormap.h>
X
X#ifndef M_PI
X#define M_PI    3.14159265358979323846
X#endif
X
Xchar *map_dir = ".";
X
X
Xvoid SineFunc(n, red, green, blue, closure)
Xint n;
Xunsigned char *red;
Xunsigned char *green;
Xunsigned char *blue;
Xcaddr_t closure;
X{
X    double radians;
X    int reps = (int) closure;
X
X    radians = (double) (n - NUM_RESERVED) / (double) (NUM_COLORS -
X      NUM_RESERVED) * 2.0 * M_PI * (double) reps;
X
X    *red = (unsigned char) (fabs(sin(radians)) *
X      (double) MAX_INTENSITY);
X
X    *green = (unsigned char) (fabs(sin(radians + 2.0 / 3.0 * M_PI)) *
X      (double) MAX_INTENSITY);
X
X    *blue = (unsigned char) (fabs(sin(radians + 4.0 / 3.0 * M_PI)) *
X      (double) MAX_INTENSITY);
X}
X
X
Xvoid ZebraFunc(n, red, green, blue)
Xint n;
Xunsigned char *red;
Xunsigned char *green;
Xunsigned char *blue;
X{
X    double radians;
X    double hue, sat, bright;
X    double r, g, b;
X
X    radians = (double) (n - NUM_RESERVED) / (double) (NUM_COLORS -
X      NUM_RESERVED) * 2.0 * M_PI;
X
X    *red = (unsigned char) (fabs(sin(radians)) *
X      (double) MAX_INTENSITY);
X
X    *green = (unsigned char) (fabs(sin(radians + 2.0 / 3.0 * M_PI)) *
X      (double) MAX_INTENSITY);
X
X    *blue = (unsigned char) (fabs(sin(radians + 4.0 / 3.0 * M_PI)) *
X      (double) MAX_INTENSITY);
X
X    RGB2HSB((double) *red / 255.0, (double) *green / 255.0,
X      (double) *blue / 255.0, &hue, &sat, &bright);
X
X    switch (n % 4)
X    {
X    case 0:
X	bright *= 0.70;
X	break;
X
X    case 1:
X	bright *= 0.90;
X	break;
X
X    case 2:
X	bright *= 0.80;
X	break;
X
X    case 3:
X	bright *= 1.00;
X	break;
X    }
X
X
X    HSB2RGB(hue, sat, bright, &r, &g, &b);
X
X    *red = (unsigned char) (r * 255.0);
X    *green = (unsigned char) (g * 255.0);
X    *blue = (unsigned char) (b * 255.0);
X}
X
X
Xusage(cmd)
Xchar *cmd;
X{
X    (void) fprintf(stderr, "usage: %s [ -ghorstz ] filename\n", cmd);
X    exit(1);
X}
X
X
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X{
X    char *cmd = argv[0];
X    char *value;
X    int reps;
X    extern char *getenv();
X
X    if (argc != 3)
X	usage(cmd);
X
X    if (value = getenv("MAPDIR"))
X	map_dir = value;
X
X    if (strncmp(argv[1], "-g", 2) == 0)
X    {
X	/* Store gray-scale colormap */
X	reps = (int) (isdigit(argv[1][2]) ? argv[1][2] - '0' : 1);
X	StoreGray(reps);
X    }
X    else if (strncmp(argv[1], "-h", 2) == 0)
X    {
X	/* Store Hue-Saturation-Brightness colormap */
X	reps = (int) (isdigit(argv[1][2]) ? argv[1][2] - '0' : 1);
X	StoreHSB(reps);
X    }
X    else if (strncmp(argv[1], "-o", 2) == 0)
X    {
X	/* Store 8 color (octo) colormap */
X	StoreOctoColor();
X    }
X    else if (strncmp(argv[1], "-r", 2) == 0)
X    {
X	/* Store random colormap */
X	StoreRandom();
X    }
X    else if (strncmp(argv[1], "-s", 2) == 0)
X    {
X	/* Store sine colormap */
X	reps = (int) (isdigit(argv[1][2]) ? argv[1][2] - '0' : 1);
X	StoreColors(SineFunc, (caddr_t) reps);
X    }
X    else if (strncmp(argv[1], "-t", 2) == 0)
X    {
X	/* Store 3 color (RGB) colormap */
X	StoreTriColor();
X    }
X    else if (strncmp(argv[1], "-z", 2) == 0)
X    {
X	/* Store funky zebra colormap */
X	StoreColors(ZebraFunc, (caddr_t) NULL);
X    }
X    else
X	usage(cmd);
X
X    (void) WriteColors(".", argv[2]);
X    exit(0);
X}
END_OF_FILE
if test 3267 -ne `wc -c <'gencmap/gencmap.c'`; then
    echo shar: \"'gencmap/gencmap.c'\" unpacked with wrong size!
fi
# end of 'gencmap/gencmap.c'
fi
if test -f 'widgets/List.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'widgets/List.c'\"
else
echo shar: Extracting \"'widgets/List.c'\" \(23630 characters\)
sed "s/^X//" >'widgets/List.c' <<'END_OF_FILE'
X/*
X * Copyright (c) Ken W. Marks 1989, 1990.
X */
X
X#include <stdio.h>
X#include <X11/IntrinsicP.h>
X#include <X11/StringDefs.h>
X#include <Chaos.h>
X#include <LocalDefs.h>
X#include <ListP.h>
X#include <Colormap.h>
X#include <DlgShell.h>
X
X#define IN_UP_ARROW(w, x, y)	(((x) >= (w)->list.item_width && \
X				(x) < (w)->core.width && \
X				(y) >= 0 && \
X				(y) < (w)->list.char_height) ? True : False)
X
X#define IN_DOWN_ARROW(w, x, y)	(((x) >= (w)->list.item_width && \
X				(x) < (w)->core.width && \
X				(y) > (w)->core.height - (w)->list.char_height \
X				&& (y) < (w)->core.height) ? True : False)
X
X#define IN_SCROLLBAR(w, x, y)	(((x) >= (w)->list.item_width && \
X				(x) < (w)->core.width && \
X				(y) >= (w)->list.char_height && \
X				(y) <= (w)->core.height - \
X				(w)->list.char_height) ? True : False)
X
X#define GET_ITEM(w, x, y)	(((x) >= (w)->list.item_width || \
X				(x) < 0 || \
X				(y) < 0 || \
X				(y) >= (w)->core.height) ? NO_ITEM : \
X				(y) / (w)->list.item_height + \
X				(w)->list.first_visible_item)
X
X#define NEAREST_ITEM(w, y)	(((y) - (w)->list.char_height) * \
X				(w)->list.num_stops / (w)->list.bar_height)
X
X#define ITEM_POS(w, item)	((short) (item * (w)->list.bar_height / \
X				(w)->list.num_stops + 3 * \
X				(w)->list.char_height / 2))
X
X#define BEFORE_VIEW(w, item)	((item < (w)->list.first_visible_item) ? \
X				True : False)
X
X#define AFTER_VIEW(w, item)	((item >= (w)->list.first_visible_item + \
X				(w)->list.num_visible) ? True : False)
X
X/* internal padding for items in list buttons */
X#define VERTICAL_PAD		2
X#define HORIZONTAL_PAD		2
X
X/* default number of items visible */
X#define DEFAULT_VISIBLE		5
X
X#define UP_ARROW_STRING		"\016\017"
X#define DOWN_ARROW_STRING	"\020\021"
X#define SLOT_STRING		"\022\023"
X#define KNOB_STRING		"\024\025"
X
X#define ARROW			'\037'
X#define BLANK			'\036'
X
Xstatic void ListInitialize();
Xstatic void ListRealize();
Xstatic void ListRedisplay();
Xstatic void ListDestroy();
Xstatic void ListDrawItem();
Xstatic void ListDrawItems();
Xstatic void ListDrawBar();
Xstatic void ListDrawAll();
Xstatic void ListMoveKnob();
Xstatic void ListUnselectIfUnseen();
Xstatic void ListScrollBackward();
Xstatic void ListScrollForward();
Xstatic void ListNotify();
Xstatic void ListMark();
Xstatic void ListGoto();
Xstatic void ListFocusIn();
Xstatic void ListFocusOut();
Xstatic void ListBtnUp();
Xstatic void ListMotion();
X
X#define offset(field) XtOffset(ListWidget, list.field)
X#define goffset(field) XtOffset(Widget,core.field)
X
Xstatic XtResource list_resources[] = {
X    {XtNlistDefault, XtCDefault, XtRInt, sizeof(int),
X    offset(selected_item), XtRImmediate, (caddr_t) 0},
X    {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel),
X    offset(foreground), XtRString, "Black"},
X    {XtNbackground, XtCBackground, XtRPixel, sizeof(Pixel),
X    goffset(background_pixel), XtRString, "White"},
X    {XtNfont, XtCFont, XtRFontStruct, sizeof(XFontStruct *),
X    offset(font), XtRString, "chaos-bold"},
X    {XtNlistItems, XtCList, XtRPointer, sizeof(char **),
X    offset(list_items), XtRString, NULL},
X    {XtNhorizPad, XtCMargin, XtRDimension, sizeof(Dimension),
X    offset(h_pad), XtRImmediate, (caddr_t) HORIZONTAL_PAD},
X    {XtNvertPad, XtCMargin, XtRDimension, sizeof(Dimension),
X    offset(v_pad), XtRImmediate, (caddr_t) VERTICAL_PAD},
X    {XtNcallback, XtCCallback, XtRCallback, sizeof(caddr_t),
X    offset(callbacks), XtRCallback, (caddr_t) NULL},
X    {XtNdialogbox, XtCWidget, XtRWidget, sizeof(Widget),
X    offset(dialogbox), XtRWidget, (caddr_t) NULL},
X    {XtNnumberVisible, XtCDefault, XtRInt, sizeof(int),
X    offset(num_visible), XtRImmediate, (caddr_t) DEFAULT_VISIBLE},
X    {XtNcharsWide, XtCDefault, XtRInt, sizeof(int),
X    offset(chars_wide), XtRImmediate, (caddr_t) 0},
X};
X
Xstatic XtActionsRec list_actions[] =
X{
X    {"notify", ListNotify},
X    {"mark", ListMark},
X    {"goto", ListGoto},
X    {"focus_in", ListFocusIn},
X    {"focus_out", ListFocusOut},
X    {"release", ListBtnUp},
X    {"move", ListMotion},
X};
X
Xstatic char list_translations[] =
X"<BtnDown>:		mark(BUTTON) notify(BUTTON)\n\
X <BtnUp>:		release()\n\
X <Motion>:		move()\n\
X <Key>Return:		notify(KEY)\n\
X <Key>Up:		mark(PREV)\n\
X <Key>Down:		mark(NEXT)\n\
X Shift<Key>Tab:		goto(PREV)\n\
X <Key>Tab:		goto(NEXT)\n\
X <FocusIn>:		focus_in()\n\
X <FocusOut>:		focus_out()\n\
X";
X
X#define superclass		(&simpleClassRec)
X
XListClassRec listClassRec = {
X    {
X	/* core fields 		 */
X	 /* superclass		 */ (WidgetClass) superclass,
X	 /* class_name		 */ "List",
X	 /* widget_size		 */ sizeof(ListRec),
X	 /* class_initialize	 */ NULL,
X	 /* class_part_initialize */ NULL,
X	 /* class_inited	 */ FALSE,
X	 /* initialize		 */ ListInitialize,
X	 /* initialize_hook	 */ NULL,
X	 /* realize		 */ ListRealize,
X	 /* actions		 */ list_actions,
X	 /* num_actions		 */ XtNumber(list_actions),
X	 /* resources		 */ list_resources,
X	 /* resource_count	 */ XtNumber(list_resources),
X	 /* xrm_class		 */ NULLQUARK,
X	 /* compress_motion	 */ TRUE,
X	 /* compress_exposure	 */ TRUE,
X	 /* compress_enterleave	 */ TRUE,
X	 /* visible_interest	 */ FALSE,
X	 /* destroy		 */ ListDestroy,
X	 /* resize		 */ NULL,
X	 /* expose		 */ ListRedisplay,
X	 /* set_values		 */ NULL,
X	 /* set_values_hook	 */ NULL,
X	 /* set_values_almost	 */ XtInheritSetValuesAlmost,
X	 /* get_values_hook	 */ NULL,
X	 /* accept_focus	 */ NULL,
X	 /* version		 */ XtVersion,
X	 /* callback_private	 */ NULL,
X	 /* tm_table		 */ list_translations,
X	 /* query_geometry       */ NULL,
X	 /* display_accelerator	 */ XtInheritDisplayAccelerator,
X	 /* extension		 */ NULL
X    },
X    {
X	/* Simple class fields initialization */
X	 /* change_sensitive	 */ XtInheritChangeSensitive
X    }
X};
X
X
XWidgetClass listWidgetClass = (WidgetClass) & listClassRec;
X
X
X/************************************************************/
X/******************** Private Procedures ********************/
X/************************************************************/
X
X
Xstatic void ListCopyItems(w)
XListWidget w;
X{
X    int ii;
X    char *label;
X
X    if (w->list.list_items == NULL)
X    {
X	w->list.list_items = (ListItem *) malloc(sizeof(ListItem));
X	w->list.list_items[0].label = NULL;
X	w->list.num_items = 0;
X	return;
X    }
X
X    /* SUPPRESS 530 */
X    for (ii = 0; w->list.list_items[ii].label != NULL; ++ii);
X
X    w->list.num_items = ii;
X
X    /* Allocate a private copy of the list structure so that it doesn't change
X     * from under us. */
X
X    w->list.list_items = (ListItem *) COPY(w->list.list_items, (ii + 1) *
X      sizeof(ListItem));
X
X    /* And don't forget to make private copies of all the labels in the
X     * structures (with space for 1 special leading char). */
X
X    while (--ii >= 0)
X    {
X	label = w->list.list_items[ii].label;
X	w->list.list_items[ii].label = malloc((unsigned) (strlen(label) + 2));
X	w->list.list_items[ii].label[0] = BLANK;
X	(void) strcpy(&(w->list.list_items[ii].label[1]), label);
X    }
X}
X
X
Xstatic void ListFreeItems(w)
XListWidget w;
X{
X    ListItem *ptr = w->list.list_items;
X
X    while (ptr->label != NULL)
X    {
X	free(ptr->label);
X	++ptr;
X    }
X    free((char *) w->list.list_items);
X}
X
X
Xstatic void ListGetGC(w)
XListWidget w;
X{
X    XGCValues values;
X
X    values.foreground = w->list.foreground;
X    values.background = w->core.background_pixel;
X    values.font = w->list.font->fid;
X
X    w->list.normal_gc = XtGetGC((Widget) w, (unsigned) GCForeground |
X      GCBackground | GCFont, &values);
X
X    values.foreground = w->core.background_pixel;
X    values.background = w->list.foreground;
X
X    w->list.reverse_gc = XtGetGC((Widget) w, (unsigned) GCForeground |
X      GCBackground | GCFont, &values);
X}
X
X
Xstatic void ListSetSize(w)
XListWidget w;
X{
X    XtWidgetGeometry my_request;
X    XFontStruct *fs = w->list.font;
X    ListItem *item;
X    Cardinal height = fs->max_bounds.ascent + fs->max_bounds.descent;
X    Cardinal width = fs->max_bounds.width;
X    Cardinal label_width;
X    char *label;
X    int ii;
X
X    item = w->list.list_items;
X    for (ii = 0; ii < w->list.num_items; ++ii)
X    {
X	label = item->label;
X	label_width = STRLEN(label);
X	if (label == NULL)
X	    break;
X	w->list.chars_wide = MAX(w->list.chars_wide, label_width);
X	++item;
X    }
X
X    w->list.item_width = w->list.chars_wide * width + 2 * w->list.h_pad;
X    w->list.baseline = fs->max_bounds.ascent;
X    w->list.baseline_to_center = height / 2 - w->list.baseline;
X    w->list.char_width = width;
X    w->list.char_height = height;
X    w->list.item_height = height + 2 * w->list.v_pad;
X
X    my_request.request_mode = CWWidth | CWHeight | CWBorderWidth;
X    my_request.width = w->list.item_width + 2 * width;
X    my_request.height = w->list.item_height * w->list.num_visible;
X    my_request.border_width = 1;
X
X    XtMakeGeometryRequest((Widget) w, &my_request, NULL);
X
X    w->list.bar_min_y = height + fs->max_bounds.ascent;
X    w->list.bar_max_y = w->core.height - (height + fs->max_bounds.descent);
X}
X
X
X/*ARGSUSED*/
Xstatic void ListInitialize(request, new)
XWidget request;			/* unused */
XWidget new;
X{
X    ListWidget w = (ListWidget) new;
X
X    if (w->list.dialogbox == NULL)
X    {
X	eprintf("XtNdialogbox not set\n");
X	abort();
X    }
X
X    if (w->list.num_visible < DEFAULT_VISIBLE)
X    {
X	eprintf("XtNnumberVisible must be at least %d\n", DEFAULT_VISIBLE);
X	abort();
X    }
X    ListGetGC(w);
X    ListCopyItems(w);
X    ListSetSize(w);
X
X    w->list.active_item = NO_ITEM;
X    w->list.first_visible_item = 0;
X    w->list.num_stops = w->list.num_items - w->list.num_visible + 1;
X    if (w->list.num_stops < 1)
X	w->list.num_stops = 1;
X    w->list.bar_height = w->core.height - 2 * w->list.char_height;
X    w->list.bar_offset = w->list.char_height + w->list.baseline +
X      w->list.baseline_to_center;
X    w->list.knob_y = w->list.bar_min_y;
X    w->list.scrolling = False;
X}
X
X
Xstatic void ListRealize(widget, valueMask, attrs)
XWidget widget;
XXtValueMask *valueMask;
XXSetWindowAttributes *attrs;
X{
X    ListWidget w = (ListWidget) widget;
X    Display *dpy = XtDisplay(w);
X    Window window;
X    Position y;
X
X    XtCreateWindow(widget, InputOutput, (Visual *) CopyFromParent,
X      *valueMask, attrs);
X
X    window = XtWindow(w);
X
X    w->list.pixmap = XCreatePixmap(dpy, window, w->list.char_width * 2,
X      w->core.height, w->core.depth);
X
X    if (!w->list.pixmap)
X    {
X	eprintf("Insufficient space for pixmap\n");
X	abort();
X    }
X
X    y = w->list.baseline;
X    XDrawImageString(dpy, w->list.pixmap, w->list.normal_gc, 0, y,
X      UP_ARROW_STRING, 2);
X
X    for (y = w->list.char_height + w->list.baseline;
X      y < w->core.height - w->list.char_height + w->list.baseline;
X      y += w->list.char_height)
X	XDrawImageString(dpy, w->list.pixmap, w->list.normal_gc, 0, y,
X	  SLOT_STRING, 2);
X
X    y = w->core.height - w->list.char_height + w->list.baseline;
X    XDrawImageString(dpy, w->list.pixmap, w->list.normal_gc, 0, y,
X      DOWN_ARROW_STRING, 2);
X
X    XDrawImageString(dpy, w->list.pixmap, w->list.normal_gc, 0, w->list.knob_y,
X      KNOB_STRING, 2);
X}
X
X
X/*ARGSUSED*/
Xstatic void ListRedisplay(widget, event, region)
XWidget widget;
XXEvent *event;			/* unused */
XRegion region;			/* unused */
X{
X    if (XtIsRealized(widget) == False)
X	return;
X
X    ListDrawAll(widget);
X}
X
X
Xstatic void ListDestroy(widget)
XWidget widget;
X{
X    ListWidget w = (ListWidget) widget;
X
X    XtReleaseGC(widget, w->list.normal_gc);
X    XtReleaseGC(widget, w->list.reverse_gc);
X}
X
X
Xstatic void ListDrawItem(widget, item)
XWidget widget;
Xint item;
X{
X    ListWidget w = (ListWidget) widget;
X    Display *dpy = XtDisplay(w);
X    Window window = XtWindow(w);
X    int absolute_item;
X    char *label;
X    Position x, y;
X    int label_len;
X    GC fill_gc;
X    GC draw_gc;
X
X    if (item <= NO_ITEM || item > w->list.num_visible)
X	return;
X
X    absolute_item = item + w->list.first_visible_item;
X
X    if (absolute_item >= w->list.num_items)
X	label = NULL;
X    else
X    {
X	label = w->list.list_items[absolute_item].label;
X
X	if (absolute_item == w->list.active_item)
X	    label[0] = ARROW;
X	else
X	    label[0] = BLANK;
X    }
X
X    x = (Position) w->list.h_pad;
X    y = (Position) w->list.item_height * item + w->list.v_pad +
X      w->list.baseline;
X
X    if (XtIsRealized(widget))
X    {
X
X	if (absolute_item == w->list.selected_item)
X	{
X	    fill_gc = w->list.normal_gc;
X	    draw_gc = w->list.reverse_gc;
X	}
X	else
X	{
X	    fill_gc = w->list.reverse_gc;
X	    draw_gc = w->list.normal_gc;
X	}
X
X	label_len = STRLEN(label);
X
X	if (label_len != 0)
X	    XDrawImageString(dpy, window, draw_gc, x, y, label, label_len);
X
X	XFillRectangle(dpy, window, fill_gc, x + label_len *
X	  w->list.char_width, y - w->list.baseline, (w->list.chars_wide -
X	    label_len) * w->list.char_width, w->list.char_height);
X    }
X}
X
X
Xstatic void ListDrawItems(widget)
XWidget widget;
X{
X    ListWidget w = (ListWidget) widget;
X    int ii;
X
X    for (ii = 0; ii < w->list.num_visible; ++ii)
X	ListDrawItem(widget, ii);
X}
X
X
Xstatic void ListDrawBar(widget)
XWidget widget;
X{
X    ListWidget w = (ListWidget) widget;
X    Display *dpy = XtDisplay(w);
X    Window window = XtWindow(w);
X
X    if (XtIsRealized(widget))
X	XCopyArea(dpy, w->list.pixmap, window, w->list.normal_gc,
X	  0, 0, w->list.char_width * 2, w->core.height, w->list.item_width, 0);
X}
X
X
Xstatic void ListDrawAll(widget)
XWidget widget;
X{
X    ListDrawItems(widget);
X    ListDrawBar(widget);
X}
X
X
Xstatic void ListMoveKnob(widget, y)
XWidget widget;
XPosition y;
X{
X    ListWidget w = (ListWidget) widget;
X    Display *dpy = XtDisplay(w);
X
X    y -= w->list.baseline_to_center;
X
X    if (y < w->list.bar_min_y)
X	y = w->list.bar_min_y;
X    else if (y > w->list.bar_max_y)
X	y = w->list.bar_max_y;
X
X    if (y == w->list.knob_y)
X	return;
X
X    /* Erase the old knob */
X    XDrawImageString(dpy, w->list.pixmap, w->list.normal_gc, 0, w->list.knob_y,
X      SLOT_STRING, 2);
X
X    w->list.knob_y = y;
X
X    /* Draw new knob */
X    XDrawImageString(dpy, w->list.pixmap, w->list.normal_gc, 0, w->list.knob_y,
X      KNOB_STRING, 2);
X
X    ListDrawBar(widget);
X}
X
X
Xstatic void ListUnselectIfUnseen(widget)
XWidget widget;
X{
X    ListWidget w = (ListWidget) widget;
X
X    if (BEFORE_VIEW(w, w->list.selected_item) ||
X      AFTER_VIEW(w, w->list.selected_item))
X	w->list.selected_item = NO_ITEM;
X}
X
X
Xstatic void ListScrollBackward(widget)
XWidget widget;
X{
X    ListWidget w = (ListWidget) widget;
X
X    if (w->list.first_visible_item == 0)
X	return;
X
X    --w->list.first_visible_item;
X
X    if (AFTER_VIEW(w, w->list.active_item))
X	--w->list.active_item;
X
X    /* If the selected item becomes unseen, unselect it */
X    ListUnselectIfUnseen(widget);
X    ListDrawItems(widget);
X    ListMoveKnob(widget, ITEM_POS(w, w->list.first_visible_item));
X}
X
X
Xstatic void ListScrollForward(widget)
XWidget widget;
X{
X    ListWidget w = (ListWidget) widget;
X
X    if (w->list.first_visible_item >= w->list.num_stops - 1)
X	return;
X
X    ++w->list.first_visible_item;
X
X    if (BEFORE_VIEW(w, w->list.active_item))
X	++w->list.active_item;
X
X    /* If the selected item becomes unseen, unselect it */
X    ListUnselectIfUnseen(widget);
X    ListDrawItems(widget);
X    ListMoveKnob(widget, ITEM_POS(w, w->list.first_visible_item));
X}
X
X
Xstatic void ListScrollTo(widget, y)
XWidget widget;
Xint y;
X{
X    ListWidget w = (ListWidget) widget;
X    int item;
X
X    ListMoveKnob(widget, y);
X
X    item = NEAREST_ITEM(w, y);
X    if (item == w->list.first_visible_item)
X	return;
X
X    w->list.first_visible_item = item;
X
X    if (BEFORE_VIEW(w, w->list.active_item) ||
X      AFTER_VIEW(w, w->list.active_item))
X	w->list.active_item = w->list.first_visible_item;
X
X    /* If the selected item becomes unseen, unselect it */
X    ListUnselectIfUnseen(widget);
X    ListDrawItems(widget);
X}
X
X
Xstatic void ListStartScroll(widget, y)
XWidget widget;
Xint y;
X{
X    ListWidget w = (ListWidget) widget;
X
X    w->list.scrolling = True;
X
X    ListScrollTo(widget, y);
X}
X
X
X/***********************************************************/
X/******************** Action Procedures ********************/
X/***********************************************************/
X
X
X/*ARGSUSED*/
Xstatic void ListFocusIn(widget, event, params, num_params)
XWidget widget;
XXEvent *event;
XString *params;
XCardinal *num_params;		/* unused */
X{
X    ListWidget w = (ListWidget) widget;
X    XFocusInEvent *ev = (XFocusInEvent *) & event->xfocus;
X
X    if (ev->mode != NotifyGrab)
X        return;
X
X    if (w->list.active_item == NO_ITEM)
X	w->list.active_item = w->list.first_visible_item;
X
X    ListDrawAll(widget);
X}
X
X
X/*ARGSUSED*/
Xstatic void ListFocusOut(widget, event, params, num_params)
XWidget widget;
XXEvent *event;
XString *params;
XCardinal *num_params;		/* unused */
X{
X    ListWidget w = (ListWidget) widget;
X    int last_active_item = w->list.active_item;
X    XFocusOutEvent *ev = (XFocusOutEvent *) & event->xfocus;
X
X    if (ev->mode != NotifyUngrab)
X        return;
X
X    if (w->list.active_item != NO_ITEM)
X    {
X	w->list.active_item = NO_ITEM;
X	ListDrawItem(widget, last_active_item - w->list.first_visible_item);
X    }
X}
X
X
X/*ARGSUSED*/
Xstatic void ListNotify(widget, event, params, num_params)
XWidget widget;
XXEvent *event;
XString *params;
XCardinal *num_params;		/* unused */
X{
X    ListWidget w = (ListWidget) widget;
X    XButtonEvent *ev = (XButtonEvent *) & event->xbutton;
X    int item;
X    int last_selected_item;
X
X    if (params[0][0] == 'B')
X	item = GET_ITEM(w, ev->x, ev->y);
X    else
X	item = w->list.active_item;
X
X    if (item == NO_ITEM)
X	return;
X
X    last_selected_item = w->list.selected_item;
X    w->list.selected_item = item;
X
X    ListDrawItem(widget, last_selected_item - w->list.first_visible_item);
X
X    ListDrawItem(widget, item - w->list.first_visible_item);
X
X    XtCallCallbacks(widget, XtNcallback, (XtPointer) item);
X}
X
X
X/*ARGSUSED*/
Xstatic void ListMark(widget, event, params, num_params)
XWidget widget;
XXEvent *event;
XString *params;			/* unused */
XCardinal *num_params;		/* unused */
X{
X    ListWidget w = (ListWidget) widget;
X    XButtonEvent *ev = (XButtonEvent *) & event->xbutton;
X    int item;
X    int last_item = w->list.active_item;
X
X    switch (params[0][0])
X    {
X    case 'B':
X	item = GET_ITEM(w, ev->x, ev->y);
X	if (item != NO_ITEM)
X	{
X	    DialogSetNewFocus(w->list.dialogbox, widget);
X	    w->list.active_item = item;
X	    break;
X	}
X	if (IN_UP_ARROW(w, ev->x, ev->y))
X	{
X	    if (w->list.active_item == NO_ITEM)
X	    {
X		DialogSetNewFocus(w->list.dialogbox, widget);
X		w->list.active_item = w->list.first_visible_item - 1;
X	    }
X	    ListScrollBackward(widget);
X	}
X	else if (IN_DOWN_ARROW(w, ev->x, ev->y))
X	{
X	    if (w->list.active_item == NO_ITEM)
X	    {
X		DialogSetNewFocus(w->list.dialogbox, widget);
X		w->list.active_item = w->list.first_visible_item;
X	    }
X	    ListScrollForward(widget);
X	}
X	else if (IN_SCROLLBAR(w, ev->x, ev->y))
X	{
X	    if (w->list.active_item == NO_ITEM)
X	    {
X		DialogSetNewFocus(w->list.dialogbox, widget);
X		w->list.active_item = w->list.first_visible_item;
X	    }
X	    ListStartScroll(widget, ev->y);
X	}
X	break;
X
X    case 'P':
X	item = w->list.active_item - 1;
X	if (item < 0)
X	    item = 0;
X	w->list.active_item = item;
X	if (BEFORE_VIEW(w, item))
X	{
X	    ListScrollBackward(widget);
X	    return;
X	}
X	break;
X
X    case 'N':
X	item = w->list.active_item + 1;
X	if (item >= w->list.num_items)
X	    item = w->list.num_items - 1;
X	w->list.active_item = item;
X	if (AFTER_VIEW(w, item))
X	{
X	    ListScrollForward(widget);
X	    return;
X	}
X	break;
X    }
X
X    ListDrawItem(widget, last_item - w->list.first_visible_item);
X    ListDrawItem(widget, item - w->list.first_visible_item);
X}
X
X
X/*ARGSUSED*/
Xstatic void ListGoto(widget, event, params, num_params)
XWidget widget;
XXEvent *event;			/* unused */
XString *params;			/* unused */
XCardinal *num_params;		/* unused */
X{
X    ListWidget w = (ListWidget) widget;
X    int item = w->list.active_item - w->list.first_visible_item;
X
X    w->list.active_item = NO_ITEM;
X    ListDrawItem(widget, item);
X
X    switch (params[0][0])
X    {
X    case 'P':
X	DialogSetPrevFocus(w->list.dialogbox);
X	break;
X
X    case 'N':
X	DialogSetNextFocus(w->list.dialogbox);
X	break;
X    }
X}
X
X
X/*ARGSUSED*/
Xstatic void ListBtnUp(widget, event, params, num_params)
XWidget widget;
XXEvent *event;
XString *params;			/* unused */
XCardinal *num_params;		/* unused */
X{
X    ListWidget w = (ListWidget) widget;
X    XButtonEvent *ev = (XButtonEvent *) & event->xbutton;
X
X    if (w->list.scrolling == False)
X	return;
X
X    w->list.scrolling = False;
X
X    if (ev->x <= w->list.item_width || ev->x >= w->core.width ||
X      ev->y < w->list.char_height ||
X      ev->y >= w->core.height - w->list.char_height)
X	return;
X
X    ListScrollTo(widget, ev->y);
X}
X
X
X/*ARGSUSED*/
Xstatic void ListMotion(widget, event, params, num_params)
XWidget widget;
XXEvent *event;
XString *params;			/* unused */
XCardinal *num_params;		/* unused */
X{
X    ListWidget w = (ListWidget) widget;
X    XMotionEvent *ev = (XMotionEvent *) & event->xmotion;
X
X    if (w->list.scrolling == False)
X	return;
X
X    if (ev->x <= w->list.item_width || ev->x >= w->core.width ||
X      ev->y < w->list.char_height ||
X      ev->y >= w->core.height - w->list.char_height)
X	return;
X
X    ListScrollTo(widget, ev->y);
X}
X
X
X/***********************************************************/
X/******************** Public Procedures ********************/
X/***********************************************************/
X
X
XBoolean ListChangeLabel(widget, item, label)
XWidget widget;
XCardinal item;
XString label;
X{
X    ListWidget w = (ListWidget) widget;
X    ListItem *list_item;
X
X    if (item >= w->list.num_items || label == NULL)
X	return (False);
X
X    list_item = &(w->list.list_items[item]);
X    if (strcmp(&(list_item->label[1]), label) == SAME)
X	return (True);
X    free(list_item->label);
X    list_item->label = malloc((unsigned) (strlen(label) + 2));
X    (void) strcpy(&(list_item->label[1]), label);
X
X    ListDrawItem(widget, (int) (item - w->list.first_visible_item));
X    return (True);
X}
X
X
XBoolean ListChangeSelected(widget, item)
XWidget widget;
Xint item;
X{
X    ListWidget w = (ListWidget) widget;
X    int last_item = w->list.selected_item;
X
X    if (item >= (int) w->list.num_items)
X	return (False);
X
X    if (item == last_item)
X	return (True);
X
X    w->list.selected_item = item;
X
X    if (item == NO_ITEM)
X    {
X	/* Scroll viewport to start */
X	w->list.first_visible_item = 0;
X	ListMoveKnob(widget, 0);
X	ListDrawAll(widget);
X	return (True);
X    }
X
X    if (BEFORE_VIEW(w, item))
X    {
X	/* Scroll viewport down so item is just visible */
X	w->list.first_visible_item = item;
X	ListMoveKnob(widget, ITEM_POS(w, w->list.first_visible_item));
X	ListDrawAll(widget);
X    }
X    else if (AFTER_VIEW(w, item))
X    {
X	/* Scroll viewport up so item is just visible */
X	w->list.first_visible_item = item - w->list.num_visible + 1;
X	ListMoveKnob(widget, ITEM_POS(w, w->list.first_visible_item));
X	ListDrawAll(widget);
X    }
X    else
X    {
X	/* Item was previously visible - just change selection */
X	ListDrawItem(widget, last_item - w->list.first_visible_item);
X	ListDrawItem(widget, (int) (item - w->list.first_visible_item));
X    }
X
X    return (True);
X}
X
X
XBoolean ListChangeItems(widget, new_items)
XWidget widget;
XListItem *new_items;
X{
X    ListWidget w = (ListWidget) widget;
X    int ii = 0;
X
X    while (w->list.list_items[ii].label != NULL && new_items[ii].label != NULL)
X    {
X	if (strcmp(&w->list.list_items[ii].label[1], new_items[ii].label)
X	  != SAME)
X	    break;
X	++ii;
X    }
X
X    /* just return if the list has not changed */
X    if (w->list.list_items[ii].label == NULL && new_items[ii].label == NULL)
X	return (True);
X
X    ListFreeItems(w);
X
X    w->list.list_items = new_items;
X    ListCopyItems(w);
X
X    w->list.selected_item = NO_ITEM;
X    w->list.first_visible_item = 0;
X    w->list.num_stops = w->list.num_items - w->list.num_visible + 1;
X    if (w->list.num_stops < 1)
X	w->list.num_stops = 1;
X    ListDrawItems(widget);
X    ListMoveKnob(widget, 0);
X    return (True);
X}
END_OF_FILE
if test 23630 -ne `wc -c <'widgets/List.c'`; then
    echo shar: \"'widgets/List.c'\" unpacked with wrong size!
fi
# end of 'widgets/List.c'
fi
echo shar: End of archive 2 \(of 10\).
cp /dev/null ark2isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 9 10 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 10 archives.
    rm -f ark[1-9]isdone ark[1-9][0-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0

dan
----------------------------------------------------
O'Reilly && Associates   argv at sun.com / argv at ora.com
Opinions expressed reflect those of the author only.



More information about the Comp.sources.x mailing list