home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / gwm18a.zip / wl_cursor.c < prev    next >
C/C++ Source or Header  |  1995-07-03  |  3KB  |  122 lines

  1. /* Copyright 1989 GROUPE BULL -- See license conditions in file COPYRIGHT
  2.  * Copyright 1989 Massachusetts Institute of Technology
  3.  */
  4. /***********************\
  5. *                 *
  6. *  WOOL_OBJECT: Cursor  *
  7. *  BODY                *
  8. *                 *
  9. \***********************/
  10.  
  11. #include "EXTERN.h"
  12. #include <stdio.h>
  13. #include "wool.h"
  14. #include "wl_string.h"
  15. #include "wl_number.h"
  16. #include "gwm.h"
  17. #include <X11/Xatom.h>
  18. #include <X11/Xutil.h>
  19. #include "wl_pixmap.h"
  20. #include "INTERN.h"
  21. #include "wl_cursor.h"
  22.  
  23. /*
  24.  * Constructor: wool_cursor_make
  25.  *   arguments: bitmap & mask
  26.  * font cursor code contributed by Bill Trost <trost@scott.labs.tek.com>
  27.  */
  28.  
  29. WOOL_OBJECT
  30. wool_cursor_make(argc, argv)
  31. int argc;
  32. WOOL_String    argv[];
  33. {
  34.     WOOL_Cursor     object = (WOOL_Cursor)
  35.     Malloc(sizeof(struct _WOOL_Cursor));
  36.     XColor          colors[2];
  37.     WOOL_Pixmap     bitmap, mask;
  38.     WOOL_String     temp_string;
  39.     int             cursor_number;
  40.     int         use_cursor_font = 0;
  41.  
  42.     switch (argc) {
  43.     case 2:
  44.     bitmap = (WOOL_Pixmap) wool_raw_bitmap_make(argv[0]);
  45.     mask = (WOOL_Pixmap) wool_raw_bitmap_make(argv[1]);
  46.     break;
  47.     case 1:
  48.     if (argv[0] -> type == WLNumber) {
  49.         use_cursor_font = 1;
  50.         cursor_number = ((WOOL_Number) argv[0]) -> number;
  51.         break;
  52.     } else {
  53.         must_be_string(argv[0], 0);
  54.         temp_string = WLString_n_make(strlen(argv[0] -> string) + 2);
  55.         strcpy(temp_string -> string, argv[0] -> string);
  56.         strcat(temp_string -> string, "-f");
  57.         bitmap = (WOOL_Pixmap) wool_raw_bitmap_make(temp_string);
  58.         strcpy(temp_string -> string, argv[0] -> string);
  59.         strcat(temp_string -> string, "-m");
  60.         mask = (WOOL_Pixmap) wool_raw_bitmap_make(temp_string);
  61.         break;
  62.     }
  63.     default:
  64.     return wool_error(BAD_NUMBER_OF_ARGS, argc);
  65.     }
  66.     zrt_put(object);
  67.     object -> type = WLCursor;
  68.     colors[0].pixel = Context -> pixel.Fore;
  69.     colors[1].pixel = Context -> pixel.Back;
  70.     XQueryColors(dpy, DefaultColormap(dpy, Context -> screen), colors, 2);
  71.  
  72.     if (use_cursor_font) {
  73.     object -> cursor = XCreateFontCursor(dpy, cursor_number);
  74.     XRecolorCursor(dpy, object -> cursor, &colors[0], &colors[1]);
  75.     return (WOOL_OBJECT) object;
  76.     } else {
  77.     if ((bitmap -> x_hot < 0) || (bitmap -> x_hot >= bitmap -> width))
  78.         bitmap -> x_hot = 0;
  79.     if ((bitmap -> y_hot < 0) || (bitmap -> y_hot >= bitmap -> height))
  80.         bitmap -> y_hot = 0;
  81.     if (!GWM_InvertCursors) {
  82.         XFillRectangle(dpy, bitmap -> pixmap, Context -> gc.Bitmap,
  83.                0, 0, bitmap -> width, bitmap -> height);
  84.         XFillRectangle(dpy, mask -> pixmap, Context -> gc.Bitmap,
  85.                0, 0, mask -> width, mask -> height);
  86.     }
  87.     object -> cursor = XCreatePixmapCursor(dpy, bitmap -> pixmap,
  88.                            mask -> pixmap,
  89.                            &colors[0], &colors[1],
  90.                       bitmap -> x_hot, bitmap -> y_hot);
  91.     return (WOOL_OBJECT) object;
  92.     }
  93. }
  94.  
  95.  
  96. /*
  97.  * WLCursor_print:
  98.  * a cursor prints as [CURSOR widthxheight]
  99.  */
  100.  
  101. WOOL_OBJECT 
  102. WLCursor_print(obj)
  103. WOOL_Cursor     obj;
  104. {
  105.     wool_printf("{CURSOR %x}", obj);
  106.     return (WOOL_OBJECT) obj;
  107. }
  108.  
  109. /*
  110.  * WLCursor_free:
  111.  * The structure is just freed, and string released.
  112.  */
  113.  
  114. WOOL_OBJECT 
  115. WLCursor_free(obj)
  116. WOOL_Cursor     obj;
  117. {
  118.     XFreeCursor(dpy, obj -> cursor);
  119.     Free(obj);
  120.     return NULL;
  121. }
  122.