home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume19 / xephem / part09 / query.c < prev   
Encoding:
C/C++ Source or Header  |  1993-05-15  |  2.7 KB  |  99 lines

  1. /* general purpose way to ask a question, in X.
  2.  */
  3.  
  4. #include <stdio.h>
  5. #include <X11/Xlib.h>
  6. #include <Xm/Xm.h>
  7. #include <Xm/MessageB.h>
  8.  
  9. #if defined(__STDC__) || defined(__cplusplus)
  10. #define P_(s) s
  11. #else
  12. #define P_(s) ()
  13. #endif
  14.  
  15. extern void prompt_map_cb P_((Widget w, XtPointer client, XtPointer call));
  16.  
  17. void query P_((Widget tw, char *msg, char *label1, char *label2, char *label3, void (*func1)(), void (*func2)(), void (*func3)()));
  18. static void query_cb P_((Widget w, XtPointer client, XtPointer call));
  19.  
  20. #undef P_
  21.  
  22.  
  23. /* put up a query message with up to three buttons.
  24.  * all args can safely be NULL; buttons without labels will be turned off.
  25.  */
  26. void
  27. query (tw, msg, label1, label2, label3, func1, func2, func3)
  28. Widget tw;        /* toplevel widget */
  29. char *msg;        /* query message */
  30. char *label1;        /* label for button 1 */
  31. char *label2;        /* label for button 2 */
  32. char *label3;        /* label for button 3 */
  33. void (*func1)();    /* func to call if button 1 is pushed */
  34. void (*func2)();    /* func to call if button 2 is pushed */
  35. void (*func3)();    /* func to call if button 3 is pushed */
  36. {
  37.     Widget qw;
  38.     XmString strm, str1, str2, str3;
  39.     Arg args[20];
  40.     int n;
  41.  
  42.     n = 0;
  43.     if (label1) {
  44.         str1 = XmStringCreate (label1, XmSTRING_DEFAULT_CHARSET);
  45.         XtSetArg(args[n], XmNokLabelString, str1);  n++;
  46.     }
  47.     if (label2) {
  48.         str2 = XmStringCreate (label2, XmSTRING_DEFAULT_CHARSET);
  49.         XtSetArg(args[n], XmNcancelLabelString, str2);  n++;
  50.     }
  51.     if (label3) {
  52.         str3 = XmStringCreate (label3, XmSTRING_DEFAULT_CHARSET);
  53.         XtSetArg(args[n], XmNhelpLabelString, str3);  n++;
  54.     }
  55.     if (msg) {
  56.         strm = XmStringCreate (msg, XmSTRING_DEFAULT_CHARSET);
  57.         XtSetArg(args[n], XmNmessageString, strm);  n++;
  58.     }
  59.  
  60.     XtSetArg(args[n], XmNdefaultPosition, False);  n++;
  61.     XtSetArg(args[n], XmNdialogStyle, XmDIALOG_APPLICATION_MODAL);  n++;
  62.     XtSetArg(args[n], XmNtitle, "xephem Query");  n++;
  63.     qw = XmCreateQuestionDialog(tw, "Query", args, n);
  64.     XtAddCallback (qw, XmNokCallback, query_cb, (XtPointer)func1);
  65.     XtAddCallback (qw, XmNcancelCallback, query_cb, (XtPointer)func2);
  66.     XtAddCallback (qw, XmNhelpCallback, query_cb, (XtPointer)func3);
  67.     XtAddCallback (qw, XmNmapCallback, prompt_map_cb, NULL);
  68.     XtManageChild (qw);
  69.  
  70.     if (label1)
  71.         XmStringFree (str1);
  72.     else
  73.         XtUnmanageChild (XmMessageBoxGetChild (qw, XmDIALOG_OK_BUTTON));
  74.     if (label2)
  75.         XmStringFree (str2);
  76.     else
  77.         XtUnmanageChild (XmMessageBoxGetChild (qw, XmDIALOG_CANCEL_BUTTON));
  78.     if (label3)
  79.         XmStringFree (str3);
  80.     else
  81.         XtUnmanageChild (XmMessageBoxGetChild (qw, XmDIALOG_HELP_BUTTON));
  82.     if (msg)
  83.         XmStringFree (strm);
  84. }
  85.  
  86. /* ARGSUSED */
  87. static void
  88. query_cb (w, client, call)
  89. Widget w;
  90. XtPointer client;
  91. XtPointer call;
  92. {
  93.     void (*f)() = (void (*)()) client;
  94.     if (f)
  95.         (*f)();
  96.     XtDestroyWidget(w);
  97.  
  98. }
  99.