Mercurial > hg > xemacs-beta
comparison src/glyphs-gtk.c @ 2959:4eb2a8c07cb3
[xemacs-hg @ 2005-09-27 05:48:22 by ben]
Implement color pixmap cursors
glyphs.c, glyphs-eimage.c, glyphs-x.c, glyphs-gtk.c, glyphs-msw.c, console-impl.h: Allow all kinds of color images (GIF, JPEG, ...) to be mouse pointers.
new -> new_, 'foo -> `foo'.
author | ben |
---|---|
date | Tue, 27 Sep 2005 05:48:27 +0000 |
parents | de9952d2ed18 |
children | dbd2a866e38a |
comparison
equal
deleted
inserted
replaced
2958:9e04ad6a1ac6 | 2959:4eb2a8c07cb3 |
---|---|
1 /* GTK-specific Lisp objects. | 1 /* GTK-specific Lisp objects. |
2 Copyright (C) 1993, 1994 Free Software Foundation, Inc. | 2 Copyright (C) 1993, 1994 Free Software Foundation, Inc. |
3 Copyright (C) 1995 Board of Trustees, University of Illinois. | 3 Copyright (C) 1995 Board of Trustees, University of Illinois. |
4 Copyright (C) 1995 Tinker Systems | 4 Copyright (C) 1995 Tinker Systems |
5 Copyright (C) 1995, 1996, 2001, 2002, 2004 Ben Wing | 5 Copyright (C) 1995, 1996, 2001, 2002, 2004, 2005 Ben Wing |
6 Copyright (C) 1995 Sun Microsystems | 6 Copyright (C) 1995 Sun Microsystems |
7 | 7 |
8 This file is part of XEmacs. | 8 This file is part of XEmacs. |
9 | 9 |
10 XEmacs is free software; you can redistribute it and/or modify it | 10 XEmacs is free software; you can redistribute it and/or modify it |
675 | 675 |
676 /************************************************************************/ | 676 /************************************************************************/ |
677 /* color pixmap functions */ | 677 /* color pixmap functions */ |
678 /************************************************************************/ | 678 /************************************************************************/ |
679 | 679 |
680 /* Create a pointer from a color pixmap. */ | |
681 | |
682 static void | |
683 image_instance_convert_to_pointer (Lisp_Image_Instance *ii, | |
684 Lisp_Object instantiator, | |
685 Lisp_Object pointer_fg, | |
686 Lisp_Object pointer_bg) | |
687 { | |
688 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii); | |
689 GdkPixmap *pixmap = IMAGE_INSTANCE_X_PIXMAP (ii); | |
690 GdkPixmap *mask = (GdkPixmap *) IMAGE_INSTANCE_PIXMAP_MASK (ii); | |
691 GdkColor fg, bg; | |
692 int xhot = 0, yhot = 0; | |
693 int w, h; | |
694 | |
695 if (INTP (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii))) | |
696 xhot = XINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii)); | |
697 if (INTP (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii))) | |
698 yhot = XINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii)); | |
699 w = IMAGE_INSTANCE_PIXMAP_WIDTH (ii); | |
700 h = IMAGE_INSTANCE_PIXMAP_HEIGHT (ii); | |
701 | |
702 check_pointer_sizes (w, h, instantiator); | |
703 | |
704 /* If the loaded pixmap has colors allocated (meaning it came from an | |
705 XPM file), then use those as the default colors for the cursor we | |
706 create. Otherwise, default to pointer_fg and pointer_bg. | |
707 */ | |
708 if (DEVICE_GTK_DEPTH (XDEVICE (device)) > 1) | |
709 { | |
710 warn_when_safe (Qunimplemented, Qnotice, | |
711 "GTK does not support XPM cursors...\n"); | |
712 IMAGE_INSTANCE_GTK_CURSOR (ii) = gdk_cursor_new (GDK_COFFEE_MUG); | |
713 } | |
714 else | |
715 { | |
716 generate_cursor_fg_bg (device, &pointer_fg, &pointer_bg, | |
717 &fg, &bg); | |
718 IMAGE_INSTANCE_PIXMAP_FG (ii) = pointer_fg; | |
719 IMAGE_INSTANCE_PIXMAP_BG (ii) = pointer_bg; | |
720 IMAGE_INSTANCE_GTK_CURSOR (ii) = | |
721 gdk_cursor_new_from_pixmap (pixmap, mask, &fg, &bg, xhot, yhot); | |
722 } | |
723 } | |
724 | |
680 /* Initialize an image instance from an XImage. | 725 /* Initialize an image instance from an XImage. |
681 | 726 |
682 DEST_MASK specifies the mask of allowed image types. | 727 DEST_MASK specifies the mask of allowed image types. |
683 | 728 |
684 PIXELS and NPIXELS specify an array of pixels that are used in | 729 PIXELS and NPIXELS specify an array of pixels that are used in |
703 int dest_mask, | 748 int dest_mask, |
704 GdkColormap *cmap, | 749 GdkColormap *cmap, |
705 unsigned long *pixels, | 750 unsigned long *pixels, |
706 int npixels, | 751 int npixels, |
707 int slices, | 752 int slices, |
708 Lisp_Object instantiator) | 753 Lisp_Object instantiator, |
754 Lisp_Object pointer_fg, | |
755 Lisp_Object pointer_bg) | |
709 { | 756 { |
710 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii); | 757 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii); |
711 GdkGC *gc; | 758 GdkGC *gc; |
712 GdkWindow *d; | 759 GdkWindow *d; |
713 GdkPixmap *pixmap; | 760 GdkPixmap *pixmap; |
761 enum image_instance_type type; | |
714 | 762 |
715 if (!DEVICE_GTK_P (XDEVICE (device))) | 763 if (!DEVICE_GTK_P (XDEVICE (device))) |
716 gui_error ("Not a Gtk device", device); | 764 gui_error ("Not a Gtk device", device); |
717 | 765 |
718 d = GET_GTK_WIDGET_WINDOW (DEVICE_GTK_APP_SHELL (XDEVICE (device))); | 766 d = GET_GTK_WIDGET_WINDOW (DEVICE_GTK_APP_SHELL (XDEVICE (device))); |
719 | 767 |
720 if (!(dest_mask & IMAGE_COLOR_PIXMAP_MASK)) | 768 if (dest_mask & IMAGE_COLOR_PIXMAP_MASK) |
769 type = IMAGE_COLOR_PIXMAP; | |
770 else if (dest_mask & IMAGE_POINTER_MASK) | |
771 type = IMAGE_POINTER; | |
772 else | |
721 incompatible_image_types (instantiator, dest_mask, | 773 incompatible_image_types (instantiator, dest_mask, |
722 IMAGE_COLOR_PIXMAP_MASK); | 774 IMAGE_COLOR_PIXMAP_MASK |
775 | IMAGE_POINTER_MASK); | |
723 | 776 |
724 pixmap = gdk_pixmap_new (d, gdk_image->width, gdk_image->height, gdk_image->depth); | 777 pixmap = gdk_pixmap_new (d, gdk_image->width, gdk_image->height, gdk_image->depth); |
725 if (!pixmap) | 778 if (!pixmap) |
726 gui_error ("Unable to create pixmap", instantiator); | 779 gui_error ("Unable to create pixmap", instantiator); |
727 | 780 |
748 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = gdk_image->height; | 801 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = gdk_image->height; |
749 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = gdk_image->depth; | 802 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = gdk_image->depth; |
750 IMAGE_INSTANCE_GTK_COLORMAP (ii) = cmap; | 803 IMAGE_INSTANCE_GTK_COLORMAP (ii) = cmap; |
751 IMAGE_INSTANCE_GTK_PIXELS (ii) = pixels; | 804 IMAGE_INSTANCE_GTK_PIXELS (ii) = pixels; |
752 IMAGE_INSTANCE_GTK_NPIXELS (ii) = npixels; | 805 IMAGE_INSTANCE_GTK_NPIXELS (ii) = npixels; |
806 | |
807 if (type == IMAGE_POINTER) | |
808 image_instance_convert_to_pointer (ii, instantiator, pointer_fg, | |
809 pointer_bg); | |
753 } | 810 } |
754 | 811 |
755 #if 0 | 812 #if 0 |
756 void init_image_instance_from_gdk_pixmap (struct Lisp_Image_Instance *ii, | 813 void init_image_instance_from_gdk_pixmap (struct Lisp_Image_Instance *ii, |
757 struct device *device, | 814 struct device *device, |
829 int width, int height, | 886 int width, int height, |
830 int slices, | 887 int slices, |
831 unsigned char *eimage, | 888 unsigned char *eimage, |
832 int dest_mask, | 889 int dest_mask, |
833 Lisp_Object instantiator, | 890 Lisp_Object instantiator, |
891 Lisp_Object pointer_fg, | |
892 Lisp_Object pointer_bg, | |
834 Lisp_Object UNUSED (domain)) | 893 Lisp_Object UNUSED (domain)) |
835 { | 894 { |
836 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii); | 895 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii); |
837 GdkColormap *cmap = DEVICE_GTK_COLORMAP (XDEVICE(device)); | 896 GdkColormap *cmap = DEVICE_GTK_COLORMAP (XDEVICE(device)); |
838 unsigned long *pixtbl = NULL; | 897 unsigned long *pixtbl = NULL; |
854 | 913 |
855 if (slice == 0) | 914 if (slice == 0) |
856 /* Now create the pixmap and set up the image instance */ | 915 /* Now create the pixmap and set up the image instance */ |
857 init_image_instance_from_gdk_image (ii, gdk_image, dest_mask, | 916 init_image_instance_from_gdk_image (ii, gdk_image, dest_mask, |
858 cmap, pixtbl, npixels, slices, | 917 cmap, pixtbl, npixels, slices, |
859 instantiator); | 918 instantiator, pointer_fg, |
919 pointer_bg); | |
860 else | 920 else |
861 image_instance_add_gdk_image (ii, gdk_image, slice, instantiator); | 921 image_instance_add_gdk_image (ii, gdk_image, slice, instantiator); |
862 | 922 |
863 if (gdk_image) | 923 if (gdk_image) |
864 { | 924 { |
1267 case IMAGE_COLOR_PIXMAP: | 1327 case IMAGE_COLOR_PIXMAP: |
1268 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = depth; | 1328 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = depth; |
1269 break; | 1329 break; |
1270 | 1330 |
1271 case IMAGE_POINTER: | 1331 case IMAGE_POINTER: |
1272 { | 1332 if (xpmattrs.valuemask & XpmHotspot) |
1273 GdkColor fg, bg; | 1333 IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii) = make_int (xpmattrs.x_hotspot); |
1274 unsigned int xhot, yhot; | 1334 if (xpmattrs.valuemask & XpmHotspot) |
1275 | 1335 IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii) = make_int (xpmattrs.y_hotspot); |
1276 /* #### Gtk does not give us access to the hotspots of a pixmap */ | 1336 |
1277 xhot = yhot = 1; | 1337 image_instance_convert_to_pointer (ii, instantiator, pointer_fg, |
1278 IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii) = make_int (xhot); | 1338 pointer_bg); |
1279 IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii) = make_int (yhot); | |
1280 | |
1281 check_pointer_sizes (w, h, instantiator); | |
1282 | |
1283 /* If the loaded pixmap has colors allocated (meaning it came from an | |
1284 XPM file), then use those as the default colors for the cursor we | |
1285 create. Otherwise, default to pointer_fg and pointer_bg. | |
1286 */ | |
1287 if (depth > 1) | |
1288 { | |
1289 warn_when_safe (Qunimplemented, Qnotice, | |
1290 "GTK does not support XPM cursors...\n"); | |
1291 IMAGE_INSTANCE_GTK_CURSOR (ii) = gdk_cursor_new (GDK_COFFEE_MUG); | |
1292 } | |
1293 else | |
1294 { | |
1295 generate_cursor_fg_bg (device, &pointer_fg, &pointer_bg, | |
1296 &fg, &bg); | |
1297 IMAGE_INSTANCE_PIXMAP_FG (ii) = pointer_fg; | |
1298 IMAGE_INSTANCE_PIXMAP_BG (ii) = pointer_bg; | |
1299 IMAGE_INSTANCE_GTK_CURSOR (ii) = | |
1300 gdk_cursor_new_from_pixmap (pixmap, mask, &fg, &bg, xhot, yhot); | |
1301 } | |
1302 } | |
1303 | |
1304 break; | 1339 break; |
1305 | 1340 |
1306 default: | 1341 default: |
1307 ABORT (); | 1342 ABORT (); |
1308 } | 1343 } |