home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / clients / xclock / xclock.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-19  |  4.7 KB  |  142 lines

  1. /* $XConsortium: xclock.c,v 1.32 91/04/19 13:46:20 converse Exp $ */
  2.  
  3. /*
  4.  * xclock --  Hacked from Tony Della Fera's much hacked clock program.
  5.  */
  6.  
  7. /*
  8.  * Copyright 1989 Massachusetts Institute of Technology
  9.  *
  10.  * Permission to use, copy, modify, distribute, and sell this software and its
  11.  * documentation for any purpose is hereby granted without fee, provided that
  12.  * the above copyright notice appear in all copies and that both that
  13.  * copyright notice and this permission notice appear in supporting
  14.  * documentation, and that the name of M.I.T. not be used in advertising or
  15.  * publicity pertaining to distribution of the software without specific,
  16.  * written prior permission.  M.I.T. makes no representations about the
  17.  * suitability of this software for any purpose.  It is provided "as is"
  18.  * without express or implied warranty.
  19.  *
  20.  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  21.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  22.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  23.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  24.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
  25.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  26.  */
  27.  
  28. #include <X11/Xatom.h>
  29. #include <X11/Intrinsic.h>
  30. #include <X11/StringDefs.h>
  31. #include <X11/Shell.h>
  32. #include <X11/Xaw/Clock.h>
  33. #include <X11/Xaw/Cardinals.h>
  34. #include "clock.bit"
  35. #include "clmask.bit"
  36.  
  37. extern void exit();
  38. static void quit();
  39.  
  40. /* Command line options table.  Only resources are entered here...there is a
  41.    pass over the remaining options after XtParseCommand is let loose. */
  42.  
  43. static XrmOptionDescRec options[] = {
  44. {"-chime",    "*clock.chime",        XrmoptionNoArg,        "TRUE"},
  45. {"-hd",        "*clock.hands",        XrmoptionSepArg,    NULL},
  46. {"-hands",    "*clock.hands",        XrmoptionSepArg,    NULL},
  47. {"-hl",        "*clock.highlight",    XrmoptionSepArg,    NULL},
  48. {"-highlight",    "*clock.highlight",    XrmoptionSepArg,    NULL},
  49. {"-update",    "*clock.update",    XrmoptionSepArg,    NULL},
  50. {"-padding",    "*clock.padding",    XrmoptionSepArg,    NULL},
  51. {"-d",        "*clock.analog",    XrmoptionNoArg,        "FALSE"},
  52. {"-digital",    "*clock.analog",    XrmoptionNoArg,        "FALSE"},
  53. {"-analog",    "*clock.analog",    XrmoptionNoArg,        "TRUE"},
  54. };
  55.  
  56.  
  57. static XtActionsRec xclock_actions[] = {
  58.     { "quit",    quit },
  59. };
  60.  
  61. static Atom wm_delete_window;
  62.  
  63. /*
  64.  * Report the syntax for calling xclock.
  65.  */
  66. Syntax(call)
  67.     char *call;
  68. {
  69.     (void) printf ("Usage: %s [-analog] [-bw <pixels>] [-digital]\n", call);
  70.     (void) printf ("       [-fg <color>] [-bg <color>] [-hd <color>]\n");
  71.     (void) printf ("       [-hl <color>] [-bd <color>]\n");
  72.     (void) printf ("       [-fn <font_name>] [-help] [-padding <pixels>]\n");
  73.     (void) printf ("       [-rv] [-update <seconds>] [-display displayname]\n");
  74.     (void) printf ("       [-geometry geom]\n\n");
  75.     exit(1);
  76. }
  77.  
  78. void main(argc, argv)
  79.     int argc;
  80.     char **argv;
  81. {
  82.     Widget toplevel;
  83.     Arg arg;
  84.     Pixmap icon_pixmap = None;
  85.     XtAppContext app_con;
  86.  
  87.     toplevel = XtAppInitialize (&app_con, "XClock", options, XtNumber(options),
  88.                 &argc, argv, NULL, NULL, ZERO);
  89.     if (argc != 1) Syntax(argv[0]);
  90.  
  91.     XtAppAddActions (app_con, xclock_actions, XtNumber(xclock_actions));
  92.  
  93.     /*
  94.      * This is a hack so that f.delete will do something useful in this
  95.      * single-window application.
  96.      */
  97.     XtOverrideTranslations(toplevel, 
  98.             XtParseTranslationTable ("<Message>WM_PROTOCOLS: quit()"));
  99.  
  100.     XtSetArg(arg, XtNiconPixmap, &icon_pixmap);
  101.     XtGetValues(toplevel, &arg, ONE);
  102.     if (icon_pixmap == None) {
  103.     arg.value = (XtArgVal)XCreateBitmapFromData(XtDisplay(toplevel),
  104.                        XtScreen(toplevel)->root,
  105.                        (char *)clock_bits, clock_width, clock_height);
  106.     XtSetValues (toplevel, &arg, ONE);
  107.     }
  108.     XtSetArg(arg, XtNiconMask, &icon_pixmap);
  109.     XtGetValues(toplevel, &arg, ONE);
  110.     if (icon_pixmap == None) {
  111.     arg.value = (XtArgVal)XCreateBitmapFromData(XtDisplay(toplevel),
  112.                        XtScreen(toplevel)->root,
  113.                        (char *)clock_mask_bits, clock_mask_width, 
  114.                        clock_mask_height);
  115.     XtSetValues (toplevel, &arg, ONE);
  116.     }
  117.  
  118.     XtCreateManagedWidget ("clock", clockWidgetClass, toplevel, NULL, ZERO);
  119.     XtRealizeWidget (toplevel);
  120.     wm_delete_window = XInternAtom (XtDisplay(toplevel), "WM_DELETE_WINDOW",
  121.                     False);
  122.     (void) XSetWMProtocols (XtDisplay(toplevel), XtWindow(toplevel),
  123.                 &wm_delete_window, 1);
  124.     XtAppMainLoop (app_con);
  125. }
  126.  
  127.  
  128. static void quit (w, event, params, num_params)
  129.     Widget w;
  130.     XEvent *event;
  131.     String *params;
  132.     Cardinal *num_params;
  133. {
  134.     if (event->type == ClientMessage &&
  135.     event->xclient.data.l[0] != wm_delete_window) {
  136.     XBell (XtDisplay(w), 0);
  137.     return;
  138.     }
  139.     XCloseDisplay (XtDisplay(w));
  140.     exit (0);
  141. }
  142.