home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / UNIX / ARCHIE / CLIENTS / XARCHIE0.TAR / alert.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-21  |  2.6 KB  |  114 lines

  1. /*
  2.  * alert.c : A popup click-to-remove message box.
  3.  *
  4.  * George Ferguson, ferguson@cs.rochester.edu, 21 Aug 1991.
  5.  *
  6.  */
  7.  
  8. #include <X11/Intrinsic.h>
  9. #include <X11/StringDefs.h>
  10. #include <X11/Shell.h>
  11. #include <X11/Xaw/Dialog.h>
  12. #include <X11/Xaw/Cardinals.h>
  13. #include <stdio.h>
  14. extern Widget toplevel;        /* this is the only external */
  15.  
  16. /*
  17.  * Functions defined here
  18.  */
  19. void alert0(),alert1();        /* interface routines */
  20. void alertOk();            /* public action procedure */
  21.  
  22. static Widget alertShell,alertDialog;
  23. static Boolean alertDone;
  24.  
  25. void
  26. alert0(str)
  27. char *str;
  28. {
  29.     Arg args[2];
  30.     XEvent event;
  31.     Window rwin,child;
  32.     int rx,ry,cx,cy,x,y;
  33.     unsigned int but;
  34.     Dimension w,h;
  35.  
  36.     /* Go synchronous or the widgets don't resize properly */
  37.     XSynchronize(XtDisplay(toplevel),True);
  38.     /* If the popup isn't created yet, then create it */
  39.     if (alertShell == NULL) {
  40.     alertShell = XtCreatePopupShell("alertShell",transientShellWidgetClass,
  41.                             toplevel,NULL,ZERO);
  42.     alertDialog = XtCreateManagedWidget("alertDialog",dialogWidgetClass,
  43.                             alertShell,NULL,ZERO);
  44.     XawDialogAddButton(alertDialog,"okButton",alertOk,NULL);
  45.     XtRealizeWidget(alertShell);
  46.     }
  47.     /* Set the label */
  48.     XtSetArg(args[0],XtNlabel,str);
  49.     XtSetValues(alertDialog,args,ONE);
  50.     /* Center the popup over the mouse */
  51.     XtSetArg(args[0],XtNwidth,&w);
  52.     XtSetArg(args[1],XtNheight,&h);
  53.     XtGetValues(alertShell,args,TWO);
  54.     XQueryPointer(XtDisplay(toplevel),XtWindow(toplevel),
  55.                     &rwin,&child,&rx,&ry,&cx,&cy,&but);
  56.     x = rx-w/2;
  57.     if (x < 0)
  58.     x = 0;
  59.     else if (x > WidthOfScreen(XtScreen(toplevel))-w)
  60.     x = WidthOfScreen(XtScreen(toplevel))-w;
  61.     y = ry-h/2;
  62.     if (y < 0)
  63.     y = 0;
  64.     else if (y > HeightOfScreen(XtScreen(toplevel))-h)
  65.     y = WidthOfScreen(XtScreen(toplevel))-h;
  66.     XtSetArg(args[0],XtNx,x);
  67.     XtSetArg(args[1],XtNy,y);
  68.     XtSetValues(alertShell,args,TWO);
  69.     /* Beep */
  70.     XBell(XtDisplay(toplevel),0);
  71.     /* Pop it up and block until one of the buttons is clicked */
  72.     alertDone = False;
  73.     XtPopup(alertShell,XtGrabExclusive);
  74.     while (!alertDone) {
  75.     XtAppNextEvent(XtWidgetToApplicationContext(toplevel),&event);
  76.     XtDispatchEvent(&event);
  77.     }
  78.     /* Okay, pop it down */
  79.     XtPopdown(alertShell);
  80.     /* Back to normal */
  81.     XSynchronize(XtDisplay(toplevel),False);
  82. }
  83.  
  84. void
  85. alert1(fmt,arg)
  86. char *fmt,*arg;
  87. {
  88.     char buf[256];
  89.  
  90.     sprintf(buf,fmt,arg);
  91.     alert0(buf);
  92. }
  93.  
  94. void
  95. alert2(fmt,arg1,arg2)
  96. char *fmt,*arg1,*arg2;
  97. {
  98.     char buf[256];
  99.  
  100.     sprintf(buf,fmt,arg1,arg2);
  101.     alert0(buf);
  102. }
  103.  
  104. /*ARGSUSED*/
  105. void
  106. alertOk(w,event,params,num_params)
  107. Widget w;
  108. XEvent *event;
  109. String *params;
  110. Cardinal *num_params;
  111. {
  112.     alertDone = True;
  113. }
  114.