comparison src/glyphs.c @ 276:6330739388db r21-0b36

Import from CVS: tag r21-0b36
author cvs
date Mon, 13 Aug 2007 10:30:37 +0200
parents c5d627a313b1
children 90d73dddcdc4
comparison
equal deleted inserted replaced
275:a68ae4439f57 276:6330739388db
31 #include "buffer.h" 31 #include "buffer.h"
32 #include "device.h" 32 #include "device.h"
33 #include "elhash.h" 33 #include "elhash.h"
34 #include "faces.h" 34 #include "faces.h"
35 #include "frame.h" 35 #include "frame.h"
36 #include "insdel.h"
36 #include "glyphs.h" 37 #include "glyphs.h"
37 #include "objects.h" 38 #include "objects.h"
38 #include "redisplay.h" 39 #include "redisplay.h"
39 #include "window.h" 40 #include "window.h"
41
42 #ifdef HAVE_XPM
43 #include <X11/xpm.h>
44 #endif
40 45
41 Lisp_Object Qimage_conversion_error; 46 Lisp_Object Qimage_conversion_error;
42 47
43 Lisp_Object Qglyphp, Qcontrib_p, Qbaseline; 48 Lisp_Object Qglyphp, Qcontrib_p, Qbaseline;
44 Lisp_Object Qbuffer_glyph_p, Qpointer_glyph_p, Qicon_glyph_p; 49 Lisp_Object Qbuffer_glyph_p, Qpointer_glyph_p, Qicon_glyph_p;
64 69
65 DEFINE_IMAGE_INSTANTIATOR_FORMAT (nothing); 70 DEFINE_IMAGE_INSTANTIATOR_FORMAT (nothing);
66 DEFINE_IMAGE_INSTANTIATOR_FORMAT (inherit); 71 DEFINE_IMAGE_INSTANTIATOR_FORMAT (inherit);
67 DEFINE_IMAGE_INSTANTIATOR_FORMAT (string); 72 DEFINE_IMAGE_INSTANTIATOR_FORMAT (string);
68 DEFINE_IMAGE_INSTANTIATOR_FORMAT (formatted_string); 73 DEFINE_IMAGE_INSTANTIATOR_FORMAT (formatted_string);
74
75 #ifdef HAVE_XPM
76 DEFINE_IMAGE_INSTANTIATOR_FORMAT (xpm);
77 Lisp_Object Qxpm;
78 Lisp_Object Q_color_symbols;
79 void x_xpm_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
80 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
81 int dest_mask, Lisp_Object domain);
82 void mswindows_xpm_instantiate (Lisp_Object image_instance,
83 Lisp_Object instantiator,
84 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
85 int dest_mask, Lisp_Object domain);
86 Lisp_Object x_xpm_normalize (Lisp_Object inst, Lisp_Object console_type);
87 Lisp_Object mswindows_xpm_normalize (Lisp_Object inst,
88 Lisp_Object console_type);
89 #endif
69 90
70 typedef struct image_instantiator_format_entry image_instantiator_format_entry; 91 typedef struct image_instantiator_format_entry image_instantiator_format_entry;
71 struct image_instantiator_format_entry 92 struct image_instantiator_format_entry
72 { 93 {
73 Lisp_Object symbol; 94 Lisp_Object symbol;
584 !NILP (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii))) 605 !NILP (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii)))
585 { 606 {
586 write_c_string (" @", printcharfun); 607 write_c_string (" @", printcharfun);
587 if (!NILP (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii))) 608 if (!NILP (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii)))
588 { 609 {
589 sprintf (buf, "%ld", 610 long_to_string (buf, XINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii)));
590 (long) XINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii)));
591 write_c_string (buf, printcharfun); 611 write_c_string (buf, printcharfun);
592 } 612 }
593 else 613 else
594 write_c_string ("??", printcharfun); 614 write_c_string ("??", printcharfun);
595 write_c_string (",", printcharfun); 615 write_c_string (",", printcharfun);
596 if (!NILP (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii))) 616 if (!NILP (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii)))
597 { 617 {
598 sprintf (buf, "%ld", 618 long_to_string (buf, XINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii)));
599 (long) XINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii)));
600 write_c_string (buf, printcharfun); 619 write_c_string (buf, printcharfun);
601 } 620 }
602 else 621 else
603 write_c_string ("??", printcharfun); 622 write_c_string ("??", printcharfun);
604 } 623 }
1275 return image_instance; 1294 return image_instance;
1276 return new; 1295 return new;
1277 } 1296 }
1278 1297
1279 1298
1299 /************************************************************************/
1300 /* error helpers */
1301 /************************************************************************/
1302 DOESNT_RETURN
1303 signal_image_error (CONST char *reason, Lisp_Object frob)
1304 {
1305 signal_error (Qimage_conversion_error,
1306 list2 (build_translated_string (reason), frob));
1307 }
1308
1309 DOESNT_RETURN
1310 signal_image_error_2 (CONST char *reason, Lisp_Object frob0, Lisp_Object frob1)
1311 {
1312 signal_error (Qimage_conversion_error,
1313 list3 (build_translated_string (reason), frob0, frob1));
1314 }
1315
1280 /**************************************************************************** 1316 /****************************************************************************
1281 * nothing * 1317 * nothing *
1282 ****************************************************************************/ 1318 ****************************************************************************/
1283 1319
1284 static int 1320 static int
1410 IMAGE_INSTANCE_TEXT_STRING (ii) = data; 1446 IMAGE_INSTANCE_TEXT_STRING (ii) = data;
1411 } 1447 }
1412 else 1448 else
1413 incompatible_image_types (instantiator, dest_mask, IMAGE_TEXT_MASK); 1449 incompatible_image_types (instantiator, dest_mask, IMAGE_TEXT_MASK);
1414 } 1450 }
1451
1452
1453 #ifdef HAVE_XPM
1454
1455 /**********************************************************************
1456 * XPM *
1457 **********************************************************************/
1458
1459 static void
1460 check_valid_xpm_color_symbols (Lisp_Object data)
1461 {
1462 Lisp_Object rest;
1463
1464 for (rest = data; !NILP (rest); rest = XCDR (rest))
1465 {
1466 if (!CONSP (rest) ||
1467 !CONSP (XCAR (rest)) ||
1468 !STRINGP (XCAR (XCAR (rest))) ||
1469 (!STRINGP (XCDR (XCAR (rest))) &&
1470 !COLOR_SPECIFIERP (XCDR (XCAR (rest)))))
1471 signal_simple_error ("Invalid color symbol alist", data);
1472 }
1473 }
1474
1475 static void
1476 xpm_validate (Lisp_Object instantiator)
1477 {
1478 file_or_data_must_be_present (instantiator);
1479 }
1480
1481 Lisp_Object Vxpm_color_symbols;
1482
1483 Lisp_Object
1484 evaluate_xpm_color_symbols (void)
1485 {
1486 Lisp_Object rest, results = Qnil;
1487 struct gcpro gcpro1, gcpro2;
1488
1489 GCPRO2 (rest, results);
1490 for (rest = Vxpm_color_symbols; !NILP (rest); rest = XCDR (rest))
1491 {
1492 Lisp_Object name, value, cons;
1493
1494 CHECK_CONS (rest);
1495 cons = XCAR (rest);
1496 CHECK_CONS (cons);
1497 name = XCAR (cons);
1498 CHECK_STRING (name);
1499 value = XCDR (cons);
1500 CHECK_CONS (value);
1501 value = XCAR (value);
1502 value = Feval (value);
1503 if (NILP (value))
1504 continue;
1505 if (!STRINGP (value) && !COLOR_SPECIFIERP (value))
1506 signal_simple_error
1507 ("Result from xpm-color-symbols eval must be nil, string, or color",
1508 value);
1509 results = Fcons (Fcons (name, value), results);
1510 }
1511 UNGCPRO; /* no more evaluation */
1512 return results;
1513 }
1514
1515 static Lisp_Object
1516 xpm_normalize (Lisp_Object inst, Lisp_Object console_type)
1517 {
1518 #ifdef HAVE_X_WINDOWS
1519 if (CONSOLE_TYPESYM_X_P (console_type))
1520 return x_xpm_normalize (inst, console_type);
1521 else
1522 #endif
1523 #ifdef HAVE_MS_WINDOWS
1524 if (CONSOLE_TYPESYM_MSWINDOWS_P (console_type))
1525 return mswindows_xpm_normalize (inst, console_type);
1526 else
1527 #endif
1528 signal_image_error ("Can't display XPM images on this console",
1529 console_type);
1530 }
1531
1532 static int
1533 xpm_possible_dest_types (void)
1534 {
1535 return
1536 IMAGE_MONO_PIXMAP_MASK |
1537 IMAGE_COLOR_PIXMAP_MASK |
1538 IMAGE_POINTER_MASK;
1539 }
1540
1541 static void
1542 xpm_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
1543 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
1544 int dest_mask, Lisp_Object domain)
1545 {
1546 Lisp_Object device= IMAGE_INSTANCE_DEVICE (XIMAGE_INSTANCE (image_instance));
1547 #ifdef HAVE_X_WINDOWS
1548 if (DEVICE_X_P (XDEVICE (device)))
1549 {
1550 x_xpm_instantiate (image_instance, instantiator,
1551 pointer_fg, pointer_bg,
1552 dest_mask, domain);
1553 return;
1554 }
1555 else
1556 #endif
1557 #ifdef HAVE_MS_WINDOWS
1558 if (DEVICE_MSWINDOWS_P (XDEVICE (device)))
1559 {
1560 mswindows_xpm_instantiate (image_instance, instantiator,
1561 pointer_fg, pointer_bg,
1562 dest_mask, domain);
1563 return;
1564 }
1565 else
1566 #endif
1567 signal_image_error ("Can't display XPM images on this device", device);
1568 }
1569
1570 #endif /* HAVE_XPM */
1415 1571
1416 1572
1417 /**************************************************************************** 1573 /****************************************************************************
1418 * Image Specifier Object * 1574 * Image Specifier Object *
1419 ****************************************************************************/ 1575 ****************************************************************************/
2651 2807
2652 defkeyword (&Q_file, ":file"); 2808 defkeyword (&Q_file, ":file");
2653 defkeyword (&Q_data, ":data"); 2809 defkeyword (&Q_data, ":data");
2654 defkeyword (&Q_face, ":face"); 2810 defkeyword (&Q_face, ":face");
2655 2811
2812 #ifdef HAVE_XPM
2813 defkeyword (&Q_color_symbols, ":color-symbols");
2814 #endif
2815
2656 /* image specifiers */ 2816 /* image specifiers */
2657 2817
2658 DEFSUBR (Fimage_specifier_p); 2818 DEFSUBR (Fimage_specifier_p);
2659 /* Qimage in general.c */ 2819 /* Qimage in general.c */
2660 2820
2781 IIFORMAT_HAS_METHOD (formatted_string, validate); 2941 IIFORMAT_HAS_METHOD (formatted_string, validate);
2782 IIFORMAT_HAS_METHOD (formatted_string, possible_dest_types); 2942 IIFORMAT_HAS_METHOD (formatted_string, possible_dest_types);
2783 IIFORMAT_HAS_METHOD (formatted_string, instantiate); 2943 IIFORMAT_HAS_METHOD (formatted_string, instantiate);
2784 2944
2785 IIFORMAT_VALID_KEYWORD (formatted_string, Q_data, check_valid_string); 2945 IIFORMAT_VALID_KEYWORD (formatted_string, Q_data, check_valid_string);
2946
2947 #ifdef HAVE_XPM
2948 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (xpm, "xpm");
2949
2950 IIFORMAT_HAS_METHOD (xpm, validate);
2951 IIFORMAT_HAS_METHOD (xpm, normalize);
2952 IIFORMAT_HAS_METHOD (xpm, possible_dest_types);
2953 IIFORMAT_HAS_METHOD (xpm, instantiate);
2954
2955 IIFORMAT_VALID_KEYWORD (xpm, Q_data, check_valid_string);
2956 IIFORMAT_VALID_KEYWORD (xpm, Q_file, check_valid_string);
2957 IIFORMAT_VALID_KEYWORD (xpm, Q_color_symbols, check_valid_xpm_color_symbols);
2958 #endif
2786 } 2959 }
2787 2960
2788 void 2961 void
2789 vars_of_glyphs (void) 2962 vars_of_glyphs (void)
2790 { 2963 {
2828 /* Partially initialized in glyphs.el */ 3001 /* Partially initialized in glyphs.el */
2829 DEFVAR_LISP ("hscroll-glyph", &Vhscroll_glyph /* 3002 DEFVAR_LISP ("hscroll-glyph", &Vhscroll_glyph /*
2830 What to display at the beginning of horizontally scrolled lines. 3003 What to display at the beginning of horizontally scrolled lines.
2831 */); 3004 */);
2832 Vhscroll_glyph = allocate_glyph (GLYPH_BUFFER, redisplay_glyph_changed); 3005 Vhscroll_glyph = allocate_glyph (GLYPH_BUFFER, redisplay_glyph_changed);
3006
3007 #ifdef HAVE_XPM
3008 Fprovide (Qxpm);
3009
3010 DEFVAR_LISP ("xpm-color-symbols", &Vxpm_color_symbols /*
3011 Definitions of logical color-names used when reading XPM files.
3012 Elements of this list should be of the form (COLOR-NAME FORM-TO-EVALUATE).
3013 The COLOR-NAME should be a string, which is the name of the color to define;
3014 the FORM should evaluate to a `color' specifier object, or a string to be
3015 passed to `make-color-instance'. If a loaded XPM file references a symbolic
3016 color called COLOR-NAME, it will display as the computed color instead.
3017
3018 The default value of this variable defines the logical color names
3019 \"foreground\" and \"background\" to be the colors of the `default' face.
3020 */ );
3021 Vxpm_color_symbols = Qnil; /* initialized in x-faces.el */
3022 #endif
2833 } 3023 }
2834 3024
2835 void 3025 void
2836 specifier_vars_of_glyphs (void) 3026 specifier_vars_of_glyphs (void)
2837 { 3027 {