Annotation of researchv9/X11/src/X.V11R1/lib/oldXtk/Dialog.c, revision 1.1.1.1

1.1       root        1: /* $Header: Dialog.c,v 1.1 87/09/11 07:57:23 toddb Exp $ */
                      2: #ifndef lint
                      3: static char *sccsid = "@(#)Dialog.c    1.26    5/18/87";
                      4: #endif lint
                      5: /*
                      6:  * Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
                      7:  * 
                      8:  *                         All Rights Reserved
                      9:  * 
                     10:  * Permission to use, copy, modify, and distribute this software and its 
                     11:  * documentation for any purpose and without fee is hereby granted, 
                     12:  * provided that the above copyright notice appear in all copies and that
                     13:  * both that copyright notice and this permission notice appear in 
                     14:  * supporting documentation, and that the name of Digital Equipment
                     15:  * Corporation not be used in advertising or publicity pertaining to
                     16:  * distribution of the software without specific, written prior permission.  
                     17:  * 
                     18:  * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
                     19:  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
                     20:  * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
                     21:  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
                     22:  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
                     23:  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
                     24:  * SOFTWARE.
                     25:  */
                     26: 
                     27: 
                     28: /* NOTE: THIS IS NOT A WIDGET!  Rather, this is an interface to a widget.
                     29:    It implements policy, and gives a (hopefully) easier-to-use interface
                     30:    than just directly making your own form. */
                     31: 
                     32: 
                     33: #include <strings.h>
                     34: #include "Xlib.h"
                     35: #include "Intrinsic.h"
                     36: #include "Form.h"
                     37: #include "Dialog.h"
                     38: #include "Text.h"
                     39: #include "Command.h"
                     40: #include "Label.h"
                     41: #include "Atoms.h"
                     42: 
                     43: 
                     44: /* Private Definitions. */
                     45: 
                     46: typedef struct {
                     47:     Display    *dpy;           /* Form window display connection */
                     48:     Window     mywin;          /* Form window. */
                     49:     int                width, height;  /* Size of form window. */
                     50:     Window     label;          /* Window containing description of dialog. */
                     51:     Window     value;          /* Window for entering user response. */
                     52:     int                numbuttons;     /* How many buttons currently in window. */
                     53:     Window     *button;        /* Array of buttons. */
                     54:     char       *labelstring;   /* String containing data in label. */
                     55:     char       *valuestring;   /* String containing data in value. */
                     56: } WidgetDataRec, *WidgetData;
                     57: 
                     58: static XContext dialogContext = NULL;
                     59: 
                     60: 
                     61: 
                     62: static WidgetData DataFromWindow(dpy, window)
                     63: Display *dpy;
                     64: Window window;
                     65: {
                     66:     WidgetData result;
                     67:     if (XFindContext(dpy, window, dialogContext, (caddr_t *)&result))
                     68:        return NULL;
                     69:     return result;
                     70: }
                     71: 
                     72: 
                     73: static XtGeometryReturnCode DialogGeometryHandler(dpy, window, request,
                     74:                                                  reqBox, replBox)
                     75: Display *dpy;
                     76: Window window;
                     77: XtGeometryRequest request;
                     78: WindowBox *reqBox, *replBox;
                     79: {
                     80:     WidgetData data;
                     81:     data = DataFromWindow(dpy, window);
                     82:     if (data && request == XtgeometryResize) {
                     83:        data->width = reqBox->width;
                     84:        data->height = reqBox->height;
                     85:        XResizeWindow(data->dpy, window, reqBox->width, reqBox->height);
                     86:        *replBox = *reqBox;
                     87:        return XtgeometryYes;
                     88:     }
                     89:     return XtgeometryNo;
                     90: }
                     91: 
                     92: 
                     93: static XtEventReturnCode DialogEventHandler(event, data)
                     94: XEvent *event;
                     95: WidgetData data;
                     96: {
                     97:     if (event->type == DestroyNotify) {
                     98:        XtFree(data->labelstring);
                     99:        if (data->valuestring) XtFree(data->valuestring);
                    100:        XtFree((char *)data->button);
                    101:        XtFree((char *)data);
                    102:        return XteventHandled;
                    103:     }
                    104:     return XteventNotHandled;
                    105: }
                    106: 
                    107: 
                    108: /* Public definitions. */
                    109: 
                    110: Window XtDialogCreate(dpy, parent, description, valueinit, args, argCount)
                    111: Display *dpy;                  /* Display connection for the form */
                    112: Window parent;                 /* Window to put the form in. */
                    113: char *description;             /* Title for this dialog box. */
                    114: char *valueinit;               /* Initial string for value field (use NULL
                    115:                                   if you don't want a value field) */
                    116: ArgList args;                  /* Args to pass on to form (if any). */
                    117: int argCount;
                    118: {
                    119:     WidgetData data;
                    120:     static Arg arglist1[] = {
                    121:        {XtNlabel, (XtArgVal)NULL},
                    122:        {XtNborderWidth, (XtArgVal) 0}
                    123:     };
                    124:     static Arg arglist2[] = {
                    125:        {XtNwidth, (XtArgVal)NULL},
                    126:        {XtNstring, (XtArgVal)NULL},
                    127:        {XtNlength, (XtArgVal)1000},
                    128:        {XtNtextOptions, (XtArgVal) (resizeWidth | resizeHeight)},
                    129:        {XtNeditType, (XtArgVal) XttextEdit}
                    130:     };
                    131:     static Arg arglist3[] = {
                    132:        {XtNfromVert, (XtArgVal)NULL},
                    133:        {XtNresizable, (XtArgVal)TRUE}
                    134:     };
                    135:     if (dialogContext == NULL) dialogContext = XUniqueContext();
                    136:     data = (WidgetData) XtMalloc(sizeof(WidgetDataRec));
                    137:     data->dpy = dpy;
                    138:     data->numbuttons = 0;
                    139:     data->button = (Window *) XtMalloc(sizeof(Window));
                    140:     data->mywin = XtFormCreate(dpy, parent, args, argCount);
                    141:     (void)XSaveContext(data->dpy, data->mywin, dialogContext, (caddr_t) data);
                    142:     (void)XtSetGeometryHandler(
                    143:        data->dpy, data->mywin, (XtGeometryHandler) DialogGeometryHandler);
                    144:     data->labelstring = XtMalloc((unsigned) strlen(description) + 1);
                    145:     (void) strcpy(data->labelstring, description);
                    146:     arglist1[0].value = (XtArgVal) data->labelstring;
                    147:     data->label = XtLabelCreate(
                    148:        data->dpy, data->mywin, arglist1, XtNumber(arglist1));
                    149:     XtFormAddWidget(data->dpy, data->mywin, data->label, (ArgList) NULL, 0);
                    150:     if (valueinit) {
                    151:        static int grabfocus;
                    152:        static Resource resources[] = {
                    153:            {XtNgrabFocus, XtCGrabFocus, XrmRBoolean, sizeof(int),
                    154:                 (caddr_t)&grabfocus, (caddr_t)NULL}
                    155:        };
                    156:        XrmNameList names;
                    157:        XrmClassList classes;
                    158:        grabfocus = FALSE;
                    159:        XtGetResources(dpy, resources, XtNumber(resources), args, argCount,
                    160:                       parent, "dialog", "Dialog", &names, &classes);
                    161:        XrmFreeNameList(names);
                    162:        XrmFreeClassList(classes);
                    163:        data->valuestring = XtMalloc(1010);
                    164:        (void) strcpy(data->valuestring, valueinit);
                    165:        arglist2[0].value = (XtArgVal) data->width;
                    166:        arglist2[1].value = (XtArgVal) data->valuestring;
                    167:        data->value = XtTextStringCreate(
                    168:                data->dpy, data->mywin, arglist2, XtNumber(arglist2));
                    169:        arglist3[0].value = (XtArgVal) data->label;
                    170:        if (grabfocus) XSetInputFocus(dpy, data->value, RevertToParent,
                    171:                                      CurrentTime); /* !!! Hackish. |||*/
                    172:        XtFormAddWidget(
                    173:                data->dpy, data->mywin, data->value,
                    174:                arglist3, XtNumber(arglist3));
                    175:     } else {
                    176:        data->valuestring = NULL;
                    177:        data->value = NULL;
                    178:     }
                    179:     XtSetEventHandler(data->dpy, data->mywin, (XtEventHandler) DialogEventHandler,
                    180:                      StructureNotifyMask, (caddr_t)data);
                    181:     return data->mywin;
                    182: }
                    183: 
                    184: 
                    185: void XtDialogAddButton(dpy, window, name, function, param)
                    186: Display *dpy;
                    187: Window window;
                    188: char *name;
                    189: void (*function)();
                    190: caddr_t param;
                    191: {
                    192:     WidgetData data;
                    193:     static Arg arglist1[] = {
                    194:        {XtNname, (XtArgVal) NULL},
                    195:        {XtNfunction, (XtArgVal) NULL},
                    196:        {XtNparameter, (XtArgVal) NULL}
                    197:     };
                    198:     static Arg arglist2[] = {
                    199:        {XtNfromHoriz, (XtArgVal) NULL},
                    200:        {XtNfromVert, (XtArgVal) NULL},
                    201:        {XtNleft, (XtArgVal) XtChainLeft},
                    202:        {XtNright, (XtArgVal) XtChainLeft}
                    203:     };
                    204:     data = DataFromWindow(dpy, window);
                    205:     if (data == NULL) return;
                    206:     arglist1[0].value = (XtArgVal) name;
                    207:     arglist1[1].value = (XtArgVal) function;
                    208:     arglist1[2].value = (XtArgVal) param;
                    209:     data->button = (Window *)
                    210:        XtRealloc((char *)data->button,
                    211:                  (unsigned) ++data->numbuttons * sizeof(Window));
                    212:     data->button[data->numbuttons - 1] =
                    213:        XtCommandCreate(data->dpy, window, arglist1, XtNumber(arglist1));
                    214:     if (data->numbuttons > 1)
                    215:        arglist2[0].value = (XtArgVal) data->button[data->numbuttons - 2];
                    216:     else
                    217:        arglist2[0].value = (XtArgVal) NULL;
                    218:     if (data->value) arglist2[1].value = (XtArgVal) data->value;
                    219:     else arglist2[1].value = (XtArgVal) data->label;
                    220:     XtFormAddWidget(data->dpy, data->mywin, data->button[data->numbuttons - 1],
                    221:                    arglist2, XtNumber(arglist2));
                    222: }
                    223: 
                    224: 
                    225: char *XtDialogGetValueString(dpy, window)
                    226: Display *dpy;
                    227: Window window;
                    228: {
                    229:     WidgetData data;
                    230:     data = DataFromWindow(dpy, window);
                    231:     if (data) return data->valuestring;
                    232:     else return NULL;
                    233: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.