home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / UNIX / ARCHIE / CLIENTS / XARCHIE2.TAR / dialog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-20  |  2.8 KB  |  111 lines

  1. /*
  2.  * dialog.c : A popup string entry box
  3.  *
  4.  * George Ferguson, ferguson@cs.rochester.edu, 20 Oct 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. char *dialog0();            /* main public routine */
  20. void dialogOk(), dialogCancel();    /* public action procedures */
  21.  
  22. static Widget dialogShell,dialogDialog;
  23. static Boolean dialogDone;
  24. static char *dialogResult;
  25.  
  26. char *
  27. dialog(str,value)
  28. char *str,*value;
  29. {
  30.     Arg args[2];
  31.     XEvent event;
  32.     Window rwin,child;
  33.     int rx,ry,cx,cy,x,y;
  34.     unsigned int but;
  35.     Dimension w,h;
  36.  
  37.     /* Go synchronous or the widgets don't resize properly */
  38.     XSynchronize(XtDisplay(toplevel),True);
  39.     if (dialogShell == NULL) {
  40.     dialogShell = XtCreatePopupShell("dialogShell",
  41.                      transientShellWidgetClass,
  42.                      toplevel,NULL,ZERO);
  43.     dialogDialog = XtCreateManagedWidget("dialogDialog",
  44.                          dialogWidgetClass,
  45.                          dialogShell,NULL,ZERO);
  46.     XawDialogAddButton(dialogDialog,"okButton",dialogOk,NULL);
  47.     XawDialogAddButton(dialogDialog,"cancelButton",dialogCancel,NULL);
  48.     XtRealizeWidget(dialogShell);
  49.     }
  50.     /* Set the label and initial value */
  51.     XtSetArg(args[0],XtNlabel,str);
  52.     XtSetArg(args[1],XtNvalue,(value ? value : ""));
  53.     XtSetValues(dialogDialog,args,TWO);
  54.     /* Center the popup over the mouse */
  55.     XtSetArg(args[0],XtNwidth,&w);
  56.     XtSetArg(args[1],XtNheight,&h);
  57.     XtGetValues(dialogShell,args,TWO);
  58.     XQueryPointer(XtDisplay(toplevel),XtWindow(toplevel),
  59.                     &rwin,&child,&rx,&ry,&cx,&cy,&but);
  60.     x = rx-w/2;
  61.     if (x < 0)
  62.     x = 0;
  63.     else if (x > WidthOfScreen(XtScreen(toplevel))-w)
  64.     x = WidthOfScreen(XtScreen(toplevel))-w;
  65.     y = ry-h/2;
  66.     if (y < 0)
  67.     y = 0;
  68.     else if (y > HeightOfScreen(XtScreen(toplevel))-h)
  69.     y = WidthOfScreen(XtScreen(toplevel))-h;
  70.     XtSetArg(args[0],XtNx,x);
  71.     XtSetArg(args[1],XtNy,y);
  72.     XtSetValues(dialogShell,args,TWO);
  73.     /* Pop it up and block until one of the buttons is clicked */
  74.     dialogDone = False;
  75.     XtPopup(dialogShell,XtGrabExclusive);
  76.     while (!dialogDone) {
  77.     XtAppNextEvent(XtWidgetToApplicationContext(toplevel),&event);
  78.     XtDispatchEvent(&event);
  79.     }
  80.     /* Okay, pop it down */
  81.     XtPopdown(dialogShell);
  82.     /* Back to normal */
  83.     XSynchronize(XtDisplay(toplevel),False);
  84.     /* And here's the entered value */
  85.     return(dialogResult);
  86. }
  87.  
  88. /*ARGSUSED*/
  89. void
  90. dialogOk(w,event,params,num_params)
  91. Widget w;
  92. XEvent *event;
  93. String *params;
  94. Cardinal *num_params;
  95. {
  96.     dialogResult = XawDialogGetValueString(dialogDialog);
  97.     dialogDone = True;
  98. }
  99.  
  100. /*ARGSUSED*/
  101. void
  102. dialogCancel(w,event,params,num_params)
  103. Widget w;
  104. XEvent *event;
  105. String *params;
  106. Cardinal *num_params;
  107. {
  108.     dialogResult = NULL;
  109.     dialogDone = True;
  110. }
  111.