1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
/* +-------------------------------------------------------------------+ */
/* | Copyright 1993, David Koblas (koblas@netcom.com) | */
/* | Copyright 1995, 1996 Torsten Martinsen (bullestock@dk-online.dk) | */
/* | | */
/* | Permission to use, copy, modify, and to distribute this software | */
/* | and its documentation for any purpose is hereby granted without | */
/* | fee, provided that the above copyright notice appear in all | */
/* | copies and that both that copyright notice and this permission | */
/* | notice appear in supporting documentation. There is no | */
/* | representations about the suitability of this software for | */
/* | any purpose. this software is provided "as is" without express | */
/* | or implied warranty. | */
/* | | */
/* +-------------------------------------------------------------------+ */
/* $Id: dialog.c,v 1.4 1997/09/03 19:31:07 torsten Exp $ */
#include <X11/Intrinsic.h>
#include <X11/Shell.h>
#include <X11/Xaw/Command.h>
#include <X11/Xaw/Toggle.h>
#include <X11/Xaw/Form.h>
#include <X11/Xaw/Label.h>
#include <X11/StringDefs.h>
#include <stdio.h>
#ifdef MISSING_STDARG_H
#include <varargs.h>
#else
#include <stdarg.h>
#endif
#include "misc.h"
#include "xpaint.h"
#include "protocol.h"
/*
** One standard generic dialog alert box.
*/
typedef struct {
XtCallbackProc okFunc, cancelFunc;
void *data;
Widget parent, shell;
} arg_t;
static void
commonCallback(XtCallbackProc f, arg_t * arg)
{
void *d = arg->data;
Widget p = arg->parent;
XtDestroyWidget(arg->shell);
XtFree((XtPointer) arg);
if (f != NULL)
f(p, d, NULL);
}
static void
cancelCallback(Widget w, XtPointer argArg, XtPointer junk2)
{
arg_t *arg = (arg_t *) argArg;
commonCallback(arg->cancelFunc, arg);
}
static void
okCallback(Widget w, XtPointer argArg, XtPointer junk2)
{
arg_t *arg = (arg_t *) argArg;
commonCallback(arg->okFunc, arg);
}
void
AlertBox(Widget parent, char *msg, XtCallbackProc okProc,
XtCallbackProc nokProc, void *data)
{
Position x, y;
Widget shell;
Widget form, title, okButton = None, cancelButton = None;
arg_t *arg = XtNew(arg_t);
int nargs = 0;
Arg args[5];
XtVaGetValues(GetShell(parent), XtNx, &x, XtNy, &y, NULL);
XtSetArg(args[nargs], XtNx, x); nargs++;
XtSetArg(args[nargs], XtNy, y); nargs++;
shell = XtVisCreatePopupShell("alert",
transientShellWidgetClass, GetShell(parent),
args, nargs);
form = XtVaCreateManagedWidget(NULL,
formWidgetClass, shell,
XtNborderWidth, 0,
NULL);
title = XtVaCreateManagedWidget("title",
labelWidgetClass, form,
XtNlabel, msg,
XtNborderWidth, 0,
NULL);
arg->shell = shell;
arg->okFunc = okProc;
arg->cancelFunc = nokProc;
arg->parent = parent;
arg->data = data;
okButton = XtVaCreateManagedWidget("ok",
commandWidgetClass, form,
XtNfromVert, title,
XtNlabel, "OK",
/* XtNaccelerators, accel, */
NULL);
XtAddCallback(okButton, XtNcallback, okCallback, (XtPointer) arg);
if (nokProc != NULL) {
cancelButton = XtVaCreateManagedWidget("cancel",
commandWidgetClass, form,
XtNfromVert, title,
XtNfromHoriz, okButton,
XtNlabel, "Cancel",
NULL);
XtAddCallback(cancelButton, XtNcallback, cancelCallback, (XtPointer) arg);
}
AddDestroyCallback(shell, (DestroyCallbackFunc) cancelCallback,
NULL);
XtPopup(shell, XtGrabExclusive);
}
#ifdef MISSING_STDARG_H
void
Notice(va_alist)
va_dcl
{
static char msg[512];
va_list ap;
char *fmt;
Widget w;
va_start(ap);
w = va_arg(ap, Widget);
fmt = va_arg(ap, char *);
vsprintf(msg, fmt, ap);
AlertBox(GetShell(w), msg, NULL, NULL, NULL);
}
#else
void
Notice(Widget w,...)
{
static char msg[512];
va_list ap;
char *fmt;
va_start(ap, w);
fmt = va_arg(ap, char *);
vsprintf(msg, fmt, ap);
AlertBox(GetShell(w), msg, NULL, NULL, NULL);
}
#endif
|