home *** CD-ROM | disk | FTP | other *** search
- /* general purpose way to ask a question, in X.
- */
-
- #include <stdio.h>
- #include <X11/Xlib.h>
- #include <Xm/Xm.h>
- #include <Xm/MessageB.h>
-
- #if defined(__STDC__) || defined(__cplusplus)
- #define P_(s) s
- #else
- #define P_(s) ()
- #endif
-
- extern void prompt_map_cb P_((Widget w, XtPointer client, XtPointer call));
-
- void query P_((Widget tw, char *msg, char *label1, char *label2, char *label3, void (*func1)(), void (*func2)(), void (*func3)()));
- static void query_cb P_((Widget w, XtPointer client, XtPointer call));
-
- #undef P_
-
-
- /* put up a query message with up to three buttons.
- * all args can safely be NULL; buttons without labels will be turned off.
- */
- void
- query (tw, msg, label1, label2, label3, func1, func2, func3)
- Widget tw; /* toplevel widget */
- char *msg; /* query message */
- char *label1; /* label for button 1 */
- char *label2; /* label for button 2 */
- char *label3; /* label for button 3 */
- void (*func1)(); /* func to call if button 1 is pushed */
- void (*func2)(); /* func to call if button 2 is pushed */
- void (*func3)(); /* func to call if button 3 is pushed */
- {
- Widget qw;
- XmString strm, str1, str2, str3;
- Arg args[20];
- int n;
-
- n = 0;
- if (label1) {
- str1 = XmStringCreate (label1, XmSTRING_DEFAULT_CHARSET);
- XtSetArg(args[n], XmNokLabelString, str1); n++;
- }
- if (label2) {
- str2 = XmStringCreate (label2, XmSTRING_DEFAULT_CHARSET);
- XtSetArg(args[n], XmNcancelLabelString, str2); n++;
- }
- if (label3) {
- str3 = XmStringCreate (label3, XmSTRING_DEFAULT_CHARSET);
- XtSetArg(args[n], XmNhelpLabelString, str3); n++;
- }
- if (msg) {
- strm = XmStringCreate (msg, XmSTRING_DEFAULT_CHARSET);
- XtSetArg(args[n], XmNmessageString, strm); n++;
- }
-
- XtSetArg(args[n], XmNdefaultPosition, False); n++;
- XtSetArg(args[n], XmNdialogStyle, XmDIALOG_APPLICATION_MODAL); n++;
- XtSetArg(args[n], XmNtitle, "xephem Query"); n++;
- qw = XmCreateQuestionDialog(tw, "Query", args, n);
- XtAddCallback (qw, XmNokCallback, query_cb, (XtPointer)func1);
- XtAddCallback (qw, XmNcancelCallback, query_cb, (XtPointer)func2);
- XtAddCallback (qw, XmNhelpCallback, query_cb, (XtPointer)func3);
- XtAddCallback (qw, XmNmapCallback, prompt_map_cb, NULL);
- XtManageChild (qw);
-
- if (label1)
- XmStringFree (str1);
- else
- XtUnmanageChild (XmMessageBoxGetChild (qw, XmDIALOG_OK_BUTTON));
- if (label2)
- XmStringFree (str2);
- else
- XtUnmanageChild (XmMessageBoxGetChild (qw, XmDIALOG_CANCEL_BUTTON));
- if (label3)
- XmStringFree (str3);
- else
- XtUnmanageChild (XmMessageBoxGetChild (qw, XmDIALOG_HELP_BUTTON));
- if (msg)
- XmStringFree (strm);
- }
-
- /* ARGSUSED */
- static void
- query_cb (w, client, call)
- Widget w;
- XtPointer client;
- XtPointer call;
- {
- void (*f)() = (void (*)()) client;
- if (f)
- (*f)();
- XtDestroyWidget(w);
-
- }
-