comparison src/glyphs.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 6fa9919a9a0b
children 1e7cc382eb16
comparison
equal deleted inserted replaced
2958:9e04ad6a1ac6 2959:4eb2a8c07cb3
1 /* Generic glyph/image implementation + display tables 1 /* Generic glyph/image implementation + display tables
2 Copyright (C) 1994, 1995 Board of Trustees, University of Illinois. 2 Copyright (C) 1994, 1995 Board of Trustees, University of Illinois.
3 Copyright (C) 1995 Tinker Systems 3 Copyright (C) 1995 Tinker Systems
4 Copyright (C) 1995, 1996, 2000, 2001, 2002, 2004 Ben Wing 4 Copyright (C) 1995, 1996, 2000, 2001, 2002, 2004, 2005 Ben Wing
5 Copyright (C) 1995 Sun Microsystems 5 Copyright (C) 1995 Sun Microsystems
6 Copyright (C) 1998, 1999, 2000 Andy Piper 6 Copyright (C) 1998, 1999, 2000 Andy Piper
7 7
8 This file is part of XEmacs. 8 This file is part of XEmacs.
9 9
22 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 22 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */ 23 Boston, MA 02111-1307, USA. */
24 24
25 /* Synched up with: Not in FSF. */ 25 /* Synched up with: Not in FSF. */
26 26
27 /* Written by Ben Wing and Chuck Thompson. Heavily modified / 27 /* This file mostly written by Ben Wing, with some code by Chuck Thompson.
28 rewritten by Andy Piper. */ 28 Heavily modified / rewritten by Andy Piper.
29
30 Earliest glyph support, Jamie Zawinski for 19.8?
31 subwindow support added by Chuck Thompson
32 additional XPM support added by Chuck Thompson
33 initial X-Face support added by Stig
34 Majorly rewritten/restructured by Ben Wing, including creation of
35 glyph and image-instance objects, for 19.12/19.13
36 GIF/JPEG/etc. support originally in this file -- see glyph-eimage.c
37 Pointer/icon overhaul, more restructuring by Ben Wing for 19.14
38 Many changes for color work and optimizations by Jareth Hein for 21.0
39 Switch of GIF/JPEG/PNG to new EImage intermediate code by Jareth Hein for 21.0
40 TIFF code by Jareth Hein for 21.0
41 Generalization for ms-windows by Andy Piper for 21.0
42 TODO:
43 Convert images.el to C and stick it in here?
44 */
29 45
30 #include <config.h> 46 #include <config.h>
31 #include "lisp.h" 47 #include "lisp.h"
32 48
33 #include "blocktype.h" 49 #include "blocktype.h"
230 1, 2, 0, /* 246 1, 2, 0, /*
231 Given an IMAGE-INSTANTIATOR-FORMAT, return non-nil if it is valid. 247 Given an IMAGE-INSTANTIATOR-FORMAT, return non-nil if it is valid.
232 If LOCALE is non-nil then the format is checked in that locale. 248 If LOCALE is non-nil then the format is checked in that locale.
233 If LOCALE is nil the current console is used. 249 If LOCALE is nil the current console is used.
234 250
235 Valid formats are some subset of 'nothing, 'string, 'formatted-string, 251 Valid formats are some subset of `nothing', `string', `formatted-string',
236 'xpm, 'xbm, 'xface, 'gif, 'jpeg, 'png, 'tiff, 'cursor-font, 'font, 252 `xpm', `xbm', `xface', `gif', `jpeg', `png', `tiff', `cursor-font', `font',
237 'autodetect, 'subwindow, 'inherit, 'mswindows-resource, 'bmp, 253 `autodetect', `subwindow', `inherit', `mswindows-resource', `bmp',
238 'native-layout, 'layout, 'label, 'tab-control, 'tree-view, 254 `native-layout', `layout', `label', `tab-control', `tree-view',
239 'progress-gauge, 'scrollbar, 'combo-box, 'edit-field, 'button, 255 `progress-gauge', `scrollbar', `combo-box', `edit-field', `button',
240 'widget, 'pointer, and 'text, depending on how XEmacs was compiled. 256 `widget', `pointer', and `text', depending on how XEmacs was compiled.
241 */ 257 */
242 (image_instantiator_format, locale)) 258 (image_instantiator_format, locale))
243 { 259 {
244 return valid_image_instantiator_format_p (image_instantiator_format, 260 return valid_image_instantiator_format_p (image_instantiator_format,
245 locale) ? 261 locale) ?
435 { 451 {
436 return find_keyword_in_vector_or_given (vector, keyword, Qnil); 452 return find_keyword_in_vector_or_given (vector, keyword, Qnil);
437 } 453 }
438 454
439 static Lisp_Object 455 static Lisp_Object
440 find_instantiator_differences (Lisp_Object new, Lisp_Object old) 456 find_instantiator_differences (Lisp_Object new_, Lisp_Object old)
441 { 457 {
442 Lisp_Object alist = Qnil; 458 Lisp_Object alist = Qnil;
443 Lisp_Object *elt = XVECTOR_DATA (new); 459 Lisp_Object *elt = XVECTOR_DATA (new_);
444 Lisp_Object *old_elt = XVECTOR_DATA (old); 460 Lisp_Object *old_elt = XVECTOR_DATA (old);
445 int len = XVECTOR_LENGTH (new); 461 int len = XVECTOR_LENGTH (new_);
446 struct gcpro gcpro1; 462 struct gcpro gcpro1;
447 463
448 /* If the vector length has changed then consider everything 464 /* If the vector length has changed then consider everything
449 changed. We could try and figure out what properties have 465 changed. We could try and figure out what properties have
450 disappeared or been added, but this code is only used as an 466 disappeared or been added, but this code is only used as an
451 optimization anyway so lets not bother. */ 467 optimization anyway so lets not bother. */
452 if (len != XVECTOR_LENGTH (old)) 468 if (len != XVECTOR_LENGTH (old))
453 return new; 469 return new_;
454 470
455 GCPRO1 (alist); 471 GCPRO1 (alist);
456 472
457 for (len -= 2; len >= 1; len -= 2) 473 for (len -= 2; len >= 1; len -= 2)
458 { 474 {
1448 return !NILP (memq_no_quit (type, Vimage_instance_type_list)); 1464 return !NILP (memq_no_quit (type, Vimage_instance_type_list));
1449 } 1465 }
1450 1466
1451 DEFUN ("valid-image-instance-type-p", Fvalid_image_instance_type_p, 1, 1, 0, /* 1467 DEFUN ("valid-image-instance-type-p", Fvalid_image_instance_type_p, 1, 1, 0, /*
1452 Given an IMAGE-INSTANCE-TYPE, return non-nil if it is valid. 1468 Given an IMAGE-INSTANCE-TYPE, return non-nil if it is valid.
1453 Valid types are some subset of 'nothing, 'text, 'mono-pixmap, 'color-pixmap, 1469 Valid types are some subset of `nothing', `text', `mono-pixmap',
1454 'pointer, 'subwindow, and 'widget, depending on how XEmacs was compiled. 1470 `color-pixmap', `pointer', `subwindow', and `widget', depending on how
1471 XEmacs was compiled.
1455 */ 1472 */
1456 (image_instance_type)) 1473 (image_instance_type))
1457 { 1474 {
1458 return valid_image_instance_type_p (image_instance_type) ? Qt : Qnil; 1475 return valid_image_instance_type_p (image_instance_type) ? Qt : Qnil;
1459 } 1476 }
1548 `make-image-specifier' for a description of the allowed values. 1565 `make-image-specifier' for a description of the allowed values.
1549 1566
1550 DEST-TYPES should be a list of allowed image instance types that can 1567 DEST-TYPES should be a list of allowed image instance types that can
1551 be generated. The recognized image instance types are 1568 be generated. The recognized image instance types are
1552 1569
1553 'nothing 1570 `nothing'
1554 Nothing is displayed. 1571 Nothing is displayed.
1555 'text 1572 `text'
1556 Displayed as text. The foreground and background colors and the 1573 Displayed as text. The foreground and background colors and the
1557 font of the text are specified independent of the pixmap. Typically 1574 font of the text are specified independent of the pixmap. Typically
1558 these attributes will come from the face of the surrounding text, 1575 these attributes will come from the face of the surrounding text,
1559 unless a face is specified for the glyph in which the image appears. 1576 unless a face is specified for the glyph in which the image appears.
1560 'mono-pixmap 1577 `mono-pixmap'
1561 Displayed as a mono pixmap (a pixmap with only two colors where the 1578 Displayed as a mono pixmap (a pixmap with only two colors where the
1562 foreground and background can be specified independent of the pixmap; 1579 foreground and background can be specified independent of the pixmap;
1563 typically the pixmap assumes the foreground and background colors of 1580 typically the pixmap assumes the foreground and background colors of
1564 the text around it, unless a face is specified for the glyph in which 1581 the text around it, unless a face is specified for the glyph in which
1565 the image appears). 1582 the image appears).
1566 'color-pixmap 1583 `color-pixmap'
1567 Displayed as a color pixmap. 1584 Displayed as a color pixmap.
1568 'pointer 1585 `pointer'
1569 Used as the mouse pointer for a window. 1586 Used as the mouse pointer for a window.
1570 'subwindow 1587 `subwindow'
1571 A child window that is treated as an image. This allows (e.g.) 1588 A child window that is treated as an image. This allows (e.g.)
1572 another program to be responsible for drawing into the window. 1589 another program to be responsible for drawing into the window.
1573 'widget 1590 `widget'
1574 A child window that contains a window-system widget, e.g. a push 1591 A child window that contains a window-system widget, e.g. a push
1575 button, text field, or slider. 1592 button, text field, or slider.
1576 1593
1577 The DEST-TYPES list is unordered. If multiple destination types are 1594 The DEST-TYPES list is unordered. If multiple destination types are
1578 possible for a given instantiator, the "most natural" type for the 1595 possible for a given instantiator, the "most natural" type for the
1646 return IMAGE_INSTANCEP (object) ? Qt : Qnil; 1663 return IMAGE_INSTANCEP (object) ? Qt : Qnil;
1647 } 1664 }
1648 1665
1649 DEFUN ("image-instance-type", Fimage_instance_type, 1, 1, 0, /* 1666 DEFUN ("image-instance-type", Fimage_instance_type, 1, 1, 0, /*
1650 Return the type of the given image instance. 1667 Return the type of the given image instance.
1651 The return value will be one of 'nothing, 'text, 'mono-pixmap, 1668 The return value will be one of `nothing', `text', `mono-pixmap',
1652 'color-pixmap, 'pointer, 'subwindow, or 'widget. 1669 `color-pixmap', `pointer', `subwindow', or `widget'.
1653 */ 1670 */
1654 (image_instance)) 1671 (image_instance))
1655 { 1672 {
1656 CHECK_IMAGE_INSTANCE (image_instance); 1673 CHECK_IMAGE_INSTANCE (image_instance);
1657 ERROR_CHECK_IMAGE_INSTANCE (image_instance); 1674 ERROR_CHECK_IMAGE_INSTANCE (image_instance);
1962 colors and as specified. Currently, this only does anything if the image 1979 colors and as specified. Currently, this only does anything if the image
1963 instance is a mono pixmap; otherwise, the same image instance is returned. 1980 instance is a mono pixmap; otherwise, the same image instance is returned.
1964 */ 1981 */
1965 (image_instance, foreground, background)) 1982 (image_instance, foreground, background))
1966 { 1983 {
1967 Lisp_Object new; 1984 Lisp_Object new_;
1968 Lisp_Object device; 1985 Lisp_Object device;
1969 1986
1970 CHECK_IMAGE_INSTANCE (image_instance); 1987 CHECK_IMAGE_INSTANCE (image_instance);
1971 ERROR_CHECK_IMAGE_INSTANCE (image_instance); 1988 ERROR_CHECK_IMAGE_INSTANCE (image_instance);
1972 CHECK_COLOR_INSTANCE (foreground); 1989 CHECK_COLOR_INSTANCE (foreground);
1976 if (!HAS_DEVMETH_P (XDEVICE (device), colorize_image_instance)) 1993 if (!HAS_DEVMETH_P (XDEVICE (device), colorize_image_instance))
1977 return image_instance; 1994 return image_instance;
1978 1995
1979 /* #### There should be a copy_image_instance(), which calls a 1996 /* #### There should be a copy_image_instance(), which calls a
1980 device-specific method to copy the window-system subobject. */ 1997 device-specific method to copy the window-system subobject. */
1981 new = allocate_image_instance (XIMAGE_INSTANCE_DOMAIN (image_instance), 1998 new_ = allocate_image_instance (XIMAGE_INSTANCE_DOMAIN (image_instance),
1982 Qnil, Qnil); 1999 Qnil, Qnil);
1983 #ifdef MC_ALLOC 2000 #ifdef MC_ALLOC
1984 copy_lrecord (XIMAGE_INSTANCE (new), XIMAGE_INSTANCE (image_instance)); 2001 copy_lrecord (XIMAGE_INSTANCE (new_), XIMAGE_INSTANCE (image_instance));
1985 #else /* not MC_ALLOC */ 2002 #else /* not MC_ALLOC */
1986 copy_lcrecord (XIMAGE_INSTANCE (new), XIMAGE_INSTANCE (image_instance)); 2003 copy_lcrecord (XIMAGE_INSTANCE (new_), XIMAGE_INSTANCE (image_instance));
1987 #endif /* not MC_ALLOC */ 2004 #endif /* not MC_ALLOC */
1988 /* note that if this method returns non-zero, this method MUST 2005 /* note that if this method returns non-zero, this method MUST
1989 copy any window-system resources, so that when one image instance is 2006 copy any window-system resources, so that when one image instance is
1990 freed, the other one is not hosed. */ 2007 freed, the other one is not hosed. */
1991 if (!DEVMETH (XDEVICE (device), colorize_image_instance, (new, foreground, 2008 if (!DEVMETH (XDEVICE (device), colorize_image_instance, (new_, foreground,
1992 background))) 2009 background)))
1993 return image_instance; 2010 return image_instance;
1994 return new; 2011 return new_;
1995 } 2012 }
1996 2013
1997 2014
1998 /************************************************************************/ 2015 /************************************************************************/
1999 /* Geometry calculations */ 2016 /* Geometry calculations */
3940 return GLYPHP (object) ? Qt : Qnil; 3957 return GLYPHP (object) ? Qt : Qnil;
3941 } 3958 }
3942 3959
3943 DEFUN ("glyph-type", Fglyph_type, 1, 1, 0, /* 3960 DEFUN ("glyph-type", Fglyph_type, 1, 1, 0, /*
3944 Return the type of the given glyph. 3961 Return the type of the given glyph.
3945 The return value will be one of 'buffer, 'pointer, or 'icon. 3962 The return value will be one of `buffer', `pointer', or `icon'.
3946 */ 3963 */
3947 (glyph)) 3964 (glyph))
3948 { 3965 {
3949 CHECK_GLYPH (glyph); 3966 CHECK_GLYPH (glyph);
3950 switch (XGLYPH_TYPE (glyph)) 3967 switch (XGLYPH_TYPE (glyph))
3960 glyph_image_instance (Lisp_Object glyph, Lisp_Object domain, 3977 glyph_image_instance (Lisp_Object glyph, Lisp_Object domain,
3961 Error_Behavior errb, int no_quit) 3978 Error_Behavior errb, int no_quit)
3962 { 3979 {
3963 Lisp_Object specifier = GLYPH_IMAGE (XGLYPH (glyph)); 3980 Lisp_Object specifier = GLYPH_IMAGE (XGLYPH (glyph));
3964 3981
3965 /* This can never return Qunbound. All glyphs have 'nothing as 3982 /* This can never return Qunbound. All glyphs have `nothing' as
3966 a fallback. */ 3983 a fallback. */
3967 Lisp_Object image_instance = specifier_instance (specifier, Qunbound, 3984 Lisp_Object image_instance = specifier_instance (specifier, Qunbound,
3968 domain, errb, no_quit, 0, 3985 domain, errb, no_quit, 0,
3969 Qzero); 3986 Qzero);
3970 assert (!UNBOUNDP (image_instance)); 3987 assert (!UNBOUNDP (image_instance));
5399 IIFORMAT_HAS_METHOD (xface, normalize); 5416 IIFORMAT_HAS_METHOD (xface, normalize);
5400 IIFORMAT_HAS_METHOD (xface, possible_dest_types); 5417 IIFORMAT_HAS_METHOD (xface, possible_dest_types);
5401 5418
5402 IIFORMAT_VALID_KEYWORD (xface, Q_data, check_valid_string); 5419 IIFORMAT_VALID_KEYWORD (xface, Q_data, check_valid_string);
5403 IIFORMAT_VALID_KEYWORD (xface, Q_file, check_valid_string); 5420 IIFORMAT_VALID_KEYWORD (xface, Q_file, check_valid_string);
5421 IIFORMAT_VALID_KEYWORD (xface, Q_mask_data, check_valid_xbm_inline);
5422 IIFORMAT_VALID_KEYWORD (xface, Q_mask_file, check_valid_string);
5404 IIFORMAT_VALID_KEYWORD (xface, Q_hotspot_x, check_valid_int); 5423 IIFORMAT_VALID_KEYWORD (xface, Q_hotspot_x, check_valid_int);
5405 IIFORMAT_VALID_KEYWORD (xface, Q_hotspot_y, check_valid_int); 5424 IIFORMAT_VALID_KEYWORD (xface, Q_hotspot_y, check_valid_int);
5406 IIFORMAT_VALID_KEYWORD (xface, Q_foreground, check_valid_string); 5425 IIFORMAT_VALID_KEYWORD (xface, Q_foreground, check_valid_string);
5407 IIFORMAT_VALID_KEYWORD (xface, Q_background, check_valid_string); 5426 IIFORMAT_VALID_KEYWORD (xface, Q_background, check_valid_string);
5408 #endif 5427 #endif