home *** CD-ROM | disk | FTP | other *** search
/ vsiftp.vmssoftware.com / VSIPUBLIC@vsiftp.vmssoftware.com.tar / FREEWARE / FREEWARE40.ZIP / xpaint-247 / dialog.c < prev    next >
C/C++ Source or Header  |  1997-01-03  |  4KB  |  170 lines

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