home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / UNIX / ARCHIE / CLIENTS / XARCHIE-.1 / ABOUT.C next >
Encoding:
C/C++ Source or Header  |  1993-04-22  |  5.0 KB  |  199 lines

  1. /*
  2.  * about.c : The "About xarchie" panel, with goofy display
  3.  *
  4.  * George Ferguson, ferguson@cs.rochester.edu, 23 Apr 1993.
  5.  *
  6.  * If either HAVE_RANDOM or HAVE_RAND are defined (config.h), the display
  7.  * is animated randomly, otherwise it just sits there.
  8.  */
  9. #include <stdio.h>
  10. #include <X11/Intrinsic.h>
  11. #include <X11/Shell.h>
  12. #include <X11/StringDefs.h>
  13. #include <X11/Xaw/Form.h>
  14. #include <X11/Xaw/Label.h>
  15. #include <X11/Xaw/Command.h>
  16. #include "xarchie.h"
  17. #include "patchlevel.h"
  18. #include "about.xbm"
  19. #include "config.h"
  20.  
  21. #define TIMER_LENGTH 250    /* msec */
  22.  
  23. /*
  24.  * Functions defined here
  25.  */
  26. void initAboutActions();
  27. void popupAboutPanel();
  28. void setAboutShellState();
  29.  
  30. static void initAboutWidgets();
  31. static void aboutAction(),aboutDoneAction();
  32. static void timeoutProc();
  33.  
  34. /*
  35.  * Data defined here:
  36.  */
  37. static Widget aboutShell;
  38. static Widget picture;
  39. static Window window;
  40. static XtIntervalId timer;
  41. static Boolean isPoppedUp;
  42.  
  43. static XtActionsRec actionTable[] = {
  44.     { "about",        aboutAction },
  45.     { "about-done",    aboutDoneAction },
  46. };
  47.  
  48. static XPoint lines[3][4] = {
  49.     { {14,36}, {14,24}, {17,27}, {17,18} },
  50.     { {23,36}, {33,28}, {33,32}, {40,26} },
  51.     { {25,43}, {36,43}, {33,46}, {44,46} }};
  52. static GC gcs[2];
  53.  
  54. /*    -    -    -    -    -    -    -    -    */
  55.  
  56. void
  57. initAboutActions()
  58. {
  59.     XtAppAddActions(appContext,actionTable,XtNumber(actionTable));
  60. }
  61.  
  62. /*ARGSUSED*/
  63. static void
  64. aboutAction(w,event,params,num_params)
  65. Widget w;
  66. XEvent *event;
  67. String *params;
  68. Cardinal *num_params;
  69. {
  70.     popupAboutPanel();
  71. }
  72.  
  73. /*ARGSUSED*/
  74. static void
  75. aboutDoneAction(w,event,params,num_params)
  76. Widget w;
  77. XEvent *event;
  78. String *params;
  79. Cardinal *num_params;
  80. {
  81.     XtRemoveTimeOut(timer);
  82.     isPoppedUp = False;
  83.     XtPopdown(aboutShell);
  84. }
  85.  
  86. /*    -    -    -    -    -    -    -    -    */
  87.  
  88. void
  89. popupAboutPanel()
  90. {
  91.     XGCValues values;
  92.     Arg args[1];
  93.     Pixel fg,bg;
  94.  
  95.     if (isPoppedUp) {
  96.     XRaiseWindow(display,XtWindow(aboutShell));
  97.     return;
  98.     }
  99.     if (aboutShell == NULL) {
  100.     initAboutWidgets();
  101.     window = XtWindow(picture);
  102.     XtSetArg(args[0],XtNforeground,&fg);
  103.     XtSetArg(args[1],XtNbackground,&bg);
  104.     XtGetValues(picture,args,2);
  105.     values.function = GXcopy;
  106.     values.foreground = fg;
  107.     gcs[0] = XCreateGC(display,root,GCFunction|GCForeground,&values);
  108.     values.foreground = bg;
  109.     gcs[1] = XCreateGC(display,root,GCFunction|GCForeground,&values);
  110.     }
  111.     isPoppedUp = True;
  112.     XtPopup(aboutShell,XtGrabNone);
  113. #if defined(HAVE_RANDOM) || defined(HAVE_RAND)
  114.     timer = XtAppAddTimeOut(appContext,(unsigned long)TIMER_LENGTH,
  115.                 timeoutProc,NULL);
  116. #else
  117.     XDrawLines(display,window,gcs[0],lines[0],4,CoordModeOrigin);
  118.     XDrawLines(display,window,gcs[0],lines[1],4,CoordModeOrigin);
  119.     XDrawLines(display,window,gcs[0],lines[2],4,CoordModeOrigin);
  120. #endif
  121. }
  122.  
  123. static void
  124. initAboutWidgets()
  125. {
  126.     Pixmap bitmap;
  127.     Widget form;
  128.     Arg args[1];
  129.     char buf[64];
  130.  
  131.     bitmap = XCreateBitmapFromData(display,root,(char *)about_bits,
  132.                    about_width,about_height);
  133.     aboutShell = XtCreatePopupShell("aboutShell",topLevelShellWidgetClass,
  134.                     toplevel,NULL,0);
  135.     form = XtCreateManagedWidget("aboutForm",formWidgetClass,
  136.                  aboutShell,NULL,0);
  137. #ifdef BETA
  138.     sprintf(buf,"Xarchie %.2fb%d",VERSION,PATCHLEVEL);
  139. #else
  140.     sprintf(buf,"Xarchie %.2f.%d",VERSION,PATCHLEVEL);
  141. #endif
  142.     XtSetArg(args[0],XtNlabel,buf);
  143.     (void)XtCreateManagedWidget("aboutLabel0",labelWidgetClass,form,args,1);
  144.     (void)XtCreateManagedWidget("aboutLabel1",labelWidgetClass,form,NULL,0);
  145.     (void)XtCreateManagedWidget("aboutLabel2",labelWidgetClass,form,NULL,0);
  146.     XtSetArg(args[0],XtNbitmap,bitmap);
  147.     picture = XtCreateManagedWidget("aboutLabel3",labelWidgetClass,
  148.                     form,args,1);
  149.     (void)XtCreateManagedWidget("aboutLabel4",labelWidgetClass,form,NULL,0);
  150.     (void)XtCreateManagedWidget("aboutLabel5",labelWidgetClass,form,NULL,0);
  151.     (void)XtCreateManagedWidget("aboutDoneButton",commandWidgetClass,
  152.                 form,NULL,0);
  153.     XtRealizeWidget(aboutShell);
  154.     (void)XSetWMProtocols(XtDisplay(aboutShell),XtWindow(aboutShell),
  155.               &WM_DELETE_WINDOW,1);
  156. }
  157.  
  158. /* This will never get called unless HAVE_RANDOM or HAVE_RAND is defined. */
  159. /*ARGSUSED*/
  160. static void
  161. timeoutProc(client_data,id)
  162. XtPointer client_data;
  163. XtIntervalId *id;
  164. {
  165.     int line,state;
  166.  
  167. #ifdef HAVE_RANDOM
  168.     line = random() % 3;
  169.     state = random() % 2;
  170. #else
  171. # ifdef HAVE_RAND
  172.     line = rand() % 3;
  173.     state = rand() % 2;
  174. # endif
  175. #endif
  176.     XDrawLines(display,window,gcs[state],lines[line],4,CoordModeOrigin);
  177.     timer = XtAppAddTimeOut(appContext,(unsigned long)TIMER_LENGTH,
  178.                 timeoutProc,NULL);
  179. }
  180.  
  181. void
  182. setAboutShellState(state)
  183. int state;
  184. {
  185.     if (!isPoppedUp)
  186.     return;
  187.     switch (state) {
  188.     case NormalState:
  189.         XtMapWidget(aboutShell);
  190.         timer = XtAppAddTimeOut(appContext,(unsigned long)TIMER_LENGTH,
  191.                     timeoutProc,NULL);
  192.         break;
  193.     case IconicState:
  194.         XtRemoveTimeOut(timer);
  195.         XtUnmapWidget(aboutShell);
  196.         break;
  197.     }
  198. }
  199.