1 /* Generic Objects and Functions.
2 Copyright (C) 1995 Free Software Foundation, Inc.
3 Copyright (C) 1995 Board of Trustees, University of Illinois.
4 Copyright (C) 1995, 1996 Ben Wing.
6 This file is part of SXEmacs
8 SXEmacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 SXEmacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 /* Synched up with: Not in FSF. */
27 #include "ui/device.h"
31 #include "ui/objects.h"
32 #include "specifier.h"
33 #include "ui/window.h"
35 /* Objects that are substituted when an instantiation fails.
36 If we leave in the Qunbound value, we will probably get crashes. */
37 Lisp_Object Vthe_null_color_instance, Vthe_null_font_instance;
39 /* Authors: Ben Wing, Chuck Thompson */
41 void finalose(void *ptr)
47 ("Can't dump an emacs containing window system objects", obj);
50 /****************************************************************************
51 * Color-Instance Object *
52 ****************************************************************************/
54 Lisp_Object Qcolor_instancep;
56 static Lisp_Object mark_color_instance(Lisp_Object obj)
58 Lisp_Color_Instance *c = XCOLOR_INSTANCE(obj);
60 if (!NILP(c->device)) /* Vthe_null_color_instance */
61 MAYBE_DEVMETH(XDEVICE(c->device), mark_color_instance, (c));
67 print_color_instance(Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
69 Lisp_Color_Instance *c = XCOLOR_INSTANCE(obj);
71 error("printing unreadable object #<color-instance 0x%x>",
73 write_c_string("#<color-instance ", printcharfun);
74 print_internal(c->name, printcharfun, 0);
75 write_c_string(" on ", printcharfun);
76 print_internal(c->device, printcharfun, 0);
77 if (!NILP(c->device)) /* Vthe_null_color_instance */
78 MAYBE_DEVMETH(XDEVICE(c->device), print_color_instance,
79 (c, printcharfun, escapeflag));
80 write_fmt_str(printcharfun, " 0x%x>", c->header.uid);
83 static void finalize_color_instance(void *header, int for_disksave)
85 Lisp_Color_Instance *c = (Lisp_Color_Instance *) header;
87 if (!NILP(c->device)) {
90 MAYBE_DEVMETH(XDEVICE(c->device), finalize_color_instance, (c));
94 static int color_instance_equal(Lisp_Object obj1, Lisp_Object obj2, int depth)
96 Lisp_Color_Instance *c1 = XCOLOR_INSTANCE(obj1);
97 Lisp_Color_Instance *c2 = XCOLOR_INSTANCE(obj2);
100 (EQ(c1->device, c2->device) &&
101 DEVICEP(c1->device) &&
102 HAS_DEVMETH_P(XDEVICE(c1->device), color_instance_equal) &&
103 DEVMETH(XDEVICE(c1->device), color_instance_equal,
107 static unsigned long color_instance_hash(Lisp_Object obj, int depth)
109 Lisp_Color_Instance *c = XCOLOR_INSTANCE(obj);
110 struct device *d = DEVICEP(c->device) ? XDEVICE(c->device) : 0;
112 return HASH2((unsigned long)d, !d ? LISP_HASH(obj)
113 : DEVMETH_OR_GIVEN(d, color_instance_hash, (c, depth),
117 DEFINE_LRECORD_IMPLEMENTATION("color-instance", color_instance,
118 mark_color_instance, print_color_instance,
119 finalize_color_instance, color_instance_equal,
120 color_instance_hash, 0, Lisp_Color_Instance);
122 DEFUN("make-color-instance", Fmake_color_instance, 1, 3, 0, /*
123 Return a new `color-instance' object named NAME (a string).
125 Optional argument DEVICE specifies the device this object applies to
126 and defaults to the selected device.
128 An error is signaled if the color is unknown or cannot be allocated;
129 however, if optional argument NOERROR is non-nil, nil is simply
130 returned in this case. (And if NOERROR is other than t, a warning may
133 The returned object is a normal, first-class lisp object. The way you
134 `deallocate' the color is the way you deallocate any other lisp object:
135 you drop all pointers to it and allow it to be garbage collected. When
136 these objects are GCed, the underlying window-system data (e.g. X object)
137 is deallocated as well.
139 (name, device, noerror))
141 Lisp_Color_Instance *c;
142 Lisp_Object val = Qnil;
143 Lisp_Object dev = Qnil;
145 int count = specpdl_depth();
146 struct gcpro gcpro1, gcpro2;
149 XSETDEVICE(dev, decode_device(device));
151 c = alloc_lcrecord_type(Lisp_Color_Instance, &lrecord_color_instance);
156 XSETCOLOR_INSTANCE(val, c);
158 retval = MAYBE_INT_DEVMETH(XDEVICE(dev), initialize_color_instance,
160 decode_error_behavior_flag(noerror)));
162 unbind_to(count, Qnil);
167 XSETCOLOR_INSTANCE(val, c);
168 unbind_to(count, Qnil);
173 DEFUN("color-instance-p", Fcolor_instance_p, 1, 1, 0, /*
174 Return non-nil if OBJECT is a color instance.
178 return COLOR_INSTANCEP(object) ? Qt : Qnil;
181 DEFUN("color-instance-name", Fcolor_instance_name, 1, 1, 0, /*
182 Return the name used to allocate COLOR-INSTANCE.
186 CHECK_COLOR_INSTANCE(color_instance);
187 return XCOLOR_INSTANCE(color_instance)->name;
190 DEFUN("color-instance-rgb-components", Fcolor_instance_rgb_components, 1, 1, 0, /*
191 Return a three element list containing the red, green, and blue
192 color components of COLOR-INSTANCE, or nil if unknown.
193 Component values range from 0 to 65535.
197 Lisp_Color_Instance *c;
199 CHECK_COLOR_INSTANCE(color_instance);
200 c = XCOLOR_INSTANCE(color_instance);
205 return MAYBE_LISP_DEVMETH(XDEVICE(c->device),
206 color_instance_rgb_components, (c));
209 DEFUN("valid-color-name-p", Fvalid_color_name_p, 1, 2, 0, /*
210 Return true if COLOR names a valid color for the current device.
212 Valid color names for X are listed in the file /usr/lib/X11/rgb.txt, or
213 whatever the equivalent is on your system.
215 Valid color names for TTY are those which have an ISO 6429 (ANSI) sequence.
216 In addition to being a color this may be one of a number of attributes
221 struct device *d = decode_device(device);
224 return MAYBE_INT_DEVMETH(d, valid_color_name_p, (d, color)) ? Qt : Qnil;
227 /***************************************************************************
228 * Font-Instance Object *
229 ***************************************************************************/
231 Lisp_Object Qfont_instancep;
233 static Lisp_Object font_instance_truename_internal(Lisp_Object xfont,
234 Error_behavior errb);
236 static Lisp_Object mark_font_instance(Lisp_Object obj)
238 Lisp_Font_Instance *f = XFONT_INSTANCE(obj);
240 mark_object(f->name);
241 if (!NILP(f->device)) /* Vthe_null_font_instance */
242 MAYBE_DEVMETH(XDEVICE(f->device), mark_font_instance, (f));
248 print_font_instance(Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
250 Lisp_Font_Instance *f = XFONT_INSTANCE(obj);
252 error("printing unreadable object #<font-instance 0x%x>",
254 write_c_string("#<font-instance ", printcharfun);
255 print_internal(f->name, printcharfun, 1);
256 write_c_string(" on ", printcharfun);
257 print_internal(f->device, printcharfun, 0);
258 if (!NILP(f->device))
259 MAYBE_DEVMETH(XDEVICE(f->device), print_font_instance,
260 (f, printcharfun, escapeflag));
261 write_fmt_str(printcharfun, " 0x%x>", f->header.uid);
264 static void finalize_font_instance(void *header, int for_disksave)
266 Lisp_Font_Instance *f = (Lisp_Font_Instance *) header;
268 if (!NILP(f->device)) {
271 MAYBE_DEVMETH(XDEVICE(f->device), finalize_font_instance, (f));
275 /* Fonts are equal if they resolve to the same name.
276 Since we call `font-truename' to do this, and since font-truename is lazy,
277 this means the `equal' could cause XListFonts to be run the first time.
279 static int font_instance_equal(Lisp_Object obj1, Lisp_Object obj2, int depth)
281 /* #### should this be moved into a device method? */
283 internal_equal(font_instance_truename_internal(obj1, ERROR_ME_NOT),
284 font_instance_truename_internal(obj2, ERROR_ME_NOT),
288 static unsigned long font_instance_hash(Lisp_Object obj, int depth)
290 return internal_hash(font_instance_truename_internal(obj, ERROR_ME_NOT),
294 DEFINE_LRECORD_IMPLEMENTATION("font-instance", font_instance,
295 mark_font_instance, print_font_instance,
296 finalize_font_instance, font_instance_equal,
297 font_instance_hash, 0, Lisp_Font_Instance);
299 DEFUN("make-font-instance", Fmake_font_instance, 1, 3, 0, /*
300 Return a new `font-instance' object named NAME.
301 DEVICE specifies the device this object applies to and defaults to the
302 selected device. An error is signalled if the font is unknown or cannot
303 be allocated; however, if NOERROR is non-nil, nil is simply returned in
306 The returned object is a normal, first-class lisp object. The way you
307 `deallocate' the font is the way you deallocate any other lisp object:
308 you drop all pointers to it and allow it to be garbage collected. When
309 these objects are GCed, the underlying X data is deallocated as well.
311 (name, device, noerror))
313 Lisp_Font_Instance *f;
316 Error_behavior errb = decode_error_behavior_flag(noerror);
318 if (ERRB_EQ(errb, ERROR_ME))
320 else if (!STRINGP(name))
323 XSETDEVICE(device, decode_device(device));
325 f = alloc_lcrecord_type(Lisp_Font_Instance, &lrecord_font_instance);
331 /* Stick some default values here ... */
332 f->ascent = f->height = 1;
335 f->proportional_p = 0;
337 retval = MAYBE_INT_DEVMETH(XDEVICE(device), initialize_font_instance,
338 (f, name, device, errb));
343 XSETFONT_INSTANCE(val, f);
347 DEFUN("font-instance-p", Ffont_instance_p, 1, 1, 0, /*
348 Return non-nil if OBJECT is a font instance.
352 return FONT_INSTANCEP(object) ? Qt : Qnil;
355 DEFUN("font-instance-name", Ffont_instance_name, 1, 1, 0, /*
356 Return the name used to allocate FONT-INSTANCE.
360 CHECK_FONT_INSTANCE(font_instance);
361 return XFONT_INSTANCE(font_instance)->name;
364 DEFUN("font-instance-ascent", Ffont_instance_ascent, 1, 1, 0, /*
365 Return the ascent in pixels of FONT-INSTANCE.
366 The returned value is the maximum ascent for all characters in the font,
367 where a character's ascent is the number of pixels above (and including)
372 CHECK_FONT_INSTANCE(font_instance);
373 return make_int(XFONT_INSTANCE(font_instance)->ascent);
376 DEFUN("font-instance-descent", Ffont_instance_descent, 1, 1, 0, /*
377 Return the descent in pixels of FONT-INSTANCE.
378 The returned value is the maximum descent for all characters in the font,
379 where a character's descent is the number of pixels below the baseline.
380 \(Many characters to do not have any descent. Typical characters with a
381 descent are lowercase p and lowercase g.)
385 CHECK_FONT_INSTANCE(font_instance);
386 return make_int(XFONT_INSTANCE(font_instance)->descent);
389 DEFUN("font-instance-width", Ffont_instance_width, 1, 1, 0, /*
390 Return the width in pixels of FONT-INSTANCE.
391 The returned value is the average width for all characters in the font.
395 CHECK_FONT_INSTANCE(font_instance);
396 return make_int(XFONT_INSTANCE(font_instance)->width);
399 DEFUN("font-instance-proportional-p", Ffont_instance_proportional_p, 1, 1, 0, /*
400 Return whether FONT-INSTANCE is proportional.
401 This means that different characters in the font have different widths.
405 CHECK_FONT_INSTANCE(font_instance);
406 return XFONT_INSTANCE(font_instance)->proportional_p ? Qt : Qnil;
410 font_instance_truename_internal(Lisp_Object font_instance, Error_behavior errb)
412 Lisp_Font_Instance *f = XFONT_INSTANCE(font_instance);
414 if (NILP(f->device)) {
415 maybe_signal_simple_error("Couldn't determine font truename",
416 font_instance, Qfont, errb);
420 return DEVMETH_OR_GIVEN(XDEVICE(f->device),
421 font_instance_truename, (f, errb), f->name);
424 DEFUN("font-instance-truename", Ffont_instance_truename, 1, 1, 0, /*
425 Return the canonical name of FONT-INSTANCE.
426 Font names are patterns which may match any number of fonts, of which
427 the first found is used. This returns an unambiguous name for that font
428 \(but not necessarily its only unambiguous name).
432 CHECK_FONT_INSTANCE(font_instance);
433 return font_instance_truename_internal(font_instance, ERROR_ME);
436 DEFUN("font-instance-properties", Ffont_instance_properties, 1, 1, 0, /*
437 Return the properties (an alist or nil) of FONT-INSTANCE.
441 Lisp_Font_Instance *f;
443 CHECK_FONT_INSTANCE(font_instance);
444 f = XFONT_INSTANCE(font_instance);
449 return MAYBE_LISP_DEVMETH(XDEVICE(f->device),
450 font_instance_properties, (f));
453 DEFUN("list-fonts", Flist_fonts, 1, 2, 0, /*
454 Return a list of font names matching the given pattern.
455 DEVICE specifies which device to search for names, and defaults to the
456 currently selected device.
460 CHECK_STRING(pattern);
461 XSETDEVICE(device, decode_device(device));
463 return MAYBE_LISP_DEVMETH(XDEVICE(device), list_fonts,
467 /****************************************************************************
469 ***************************************************************************/
470 DEFINE_SPECIFIER_TYPE(color);
471 /* Qcolor defined in general.c */
473 static void color_create(Lisp_Object obj)
475 Lisp_Specifier *color = XCOLOR_SPECIFIER(obj);
477 COLOR_SPECIFIER_FACE(color) = Qnil;
478 COLOR_SPECIFIER_FACE_PROPERTY(color) = Qnil;
481 static void color_mark(Lisp_Object obj)
483 Lisp_Specifier *color = XCOLOR_SPECIFIER(obj);
485 mark_object(COLOR_SPECIFIER_FACE(color));
486 mark_object(COLOR_SPECIFIER_FACE_PROPERTY(color));
489 /* No equal or hash methods; ignore the face the color is based off
493 color_instantiate(Lisp_Object specifier, Lisp_Object matchspec,
494 Lisp_Object domain, Lisp_Object instantiator,
497 /* When called, we're inside of call_with_suspended_errors(),
498 so we can freely error. */
499 Lisp_Object device = DOMAIN_DEVICE(domain);
500 struct device *d = XDEVICE(device);
502 if (COLOR_INSTANCEP(instantiator)) {
503 /* If we are on the same device then we're done. Otherwise change
504 the instantiator to the name used to generate the pixel and let the
505 STRINGP case deal with it. */
506 if (NILP(device) /* Vthe_null_color_instance */
507 ||EQ(device, XCOLOR_INSTANCE(instantiator)->device))
510 instantiator = Fcolor_instance_name(instantiator);
513 if (STRINGP(instantiator)) {
514 /* First, look to see if we can retrieve a cached value. */
515 Lisp_Object instance =
516 Fgethash(instantiator, d->color_instance_cache, Qunbound);
517 /* Otherwise, make a new one. */
518 if (UNBOUNDP(instance)) {
519 /* make sure we cache the failures, too. */
521 Fmake_color_instance(instantiator, device, Qt);
522 Fputhash(instantiator, instance,
523 d->color_instance_cache);
526 return NILP(instance) ? Qunbound : instance;
527 } else if (VECTORP(instantiator)) {
528 switch (XVECTOR_LENGTH(instantiator)) {
531 return Vthe_null_color_instance;
534 ("Color instantiator [] only valid on TTY's",
539 (COLOR_SPECIFIER_FACE(XCOLOR_SPECIFIER(specifier))))
541 ("Color specifier not attached to a face",
543 return (FACE_PROPERTY_INSTANCE_1
544 (Fget_face(XVECTOR_DATA(instantiator)[0]),
545 COLOR_SPECIFIER_FACE_PROPERTY(XCOLOR_SPECIFIER
547 domain, ERROR_ME, 0, depth));
550 return (FACE_PROPERTY_INSTANCE_1
551 (Fget_face(XVECTOR_DATA(instantiator)[0]),
552 XVECTOR_DATA(instantiator)[1], domain,
553 ERROR_ME, 0, depth));
558 } else if (NILP(instantiator)) {
560 return Vthe_null_color_instance;
563 ("Color instantiator [] only valid on TTY's",
566 abort(); /* The spec validation routines are screwed up. */
571 static void color_validate(Lisp_Object instantiator)
573 if (COLOR_INSTANCEP(instantiator) || STRINGP(instantiator))
575 if (VECTORP(instantiator)) {
576 if (XVECTOR_LENGTH(instantiator) > 2)
578 ("Inheritance vector must be of size 0 - 2",
580 else if (XVECTOR_LENGTH(instantiator) > 0) {
581 Lisp_Object face = XVECTOR_DATA(instantiator)[0];
584 if (XVECTOR_LENGTH(instantiator) == 2) {
586 XVECTOR_DATA(instantiator)[1];
587 if (!EQ(field, Qforeground)
588 && !EQ(field, Qbackground))
590 ("Inheritance field must be `foreground' or `background'",
595 signal_simple_error("Invalid color instantiator", instantiator);
598 static void color_after_change(Lisp_Object specifier, Lisp_Object locale)
600 Lisp_Object face = COLOR_SPECIFIER_FACE(XCOLOR_SPECIFIER(specifier));
601 Lisp_Object property =
602 COLOR_SPECIFIER_FACE_PROPERTY(XCOLOR_SPECIFIER(specifier));
604 face_property_was_changed(face, property, locale);
606 XBUFFER(locale)->buffer_local_face_property = 1;
611 set_color_attached_to(Lisp_Object obj, Lisp_Object face, Lisp_Object property)
613 Lisp_Specifier *color = XCOLOR_SPECIFIER(obj);
615 COLOR_SPECIFIER_FACE(color) = face;
616 COLOR_SPECIFIER_FACE_PROPERTY(color) = property;
619 DEFUN("color-specifier-p", Fcolor_specifier_p, 1, 1, 0, /*
620 Return t if OBJECT is a color specifier.
622 See `make-color-specifier' for a description of possible color instantiators.
626 return COLOR_SPECIFIERP(object) ? Qt : Qnil;
629 /****************************************************************************
631 ***************************************************************************/
632 DEFINE_SPECIFIER_TYPE(font);
633 /* Qfont defined in general.c */
635 static void font_create(Lisp_Object obj)
637 Lisp_Specifier *font = XFONT_SPECIFIER(obj);
639 FONT_SPECIFIER_FACE(font) = Qnil;
640 FONT_SPECIFIER_FACE_PROPERTY(font) = Qnil;
643 static void font_mark(Lisp_Object obj)
645 Lisp_Specifier *font = XFONT_SPECIFIER(obj);
647 mark_object(FONT_SPECIFIER_FACE(font));
648 mark_object(FONT_SPECIFIER_FACE_PROPERTY(font));
651 /* No equal or hash methods; ignore the face the font is based off
657 font_spec_matches_charset(struct device *d, Lisp_Object charset,
658 const Bufbyte * nonreloc, Lisp_Object reloc,
659 Bytecount offset, Bytecount length)
661 return DEVMETH_OR_GIVEN(d, font_spec_matches_charset,
662 (d, charset, nonreloc, reloc, offset, length),
666 static void font_validate_matchspec(Lisp_Object matchspec)
668 Fget_charset(matchspec);
674 font_instantiate(Lisp_Object specifier, Lisp_Object matchspec,
675 Lisp_Object domain, Lisp_Object instantiator,
678 /* When called, we're inside of call_with_suspended_errors(),
679 so we can freely error. */
680 Lisp_Object device = DOMAIN_DEVICE(domain);
681 struct device *d = XDEVICE(device);
682 Lisp_Object instance;
685 if (!UNBOUNDP(matchspec))
686 matchspec = Fget_charset(matchspec);
689 if (FONT_INSTANCEP(instantiator)) {
691 || EQ(device, XFONT_INSTANCE(instantiator)->device)) {
693 if (font_spec_matches_charset(d, matchspec, 0,
694 Ffont_instance_truename
695 (instantiator), 0, -1))
701 instantiator = Ffont_instance_name(instantiator);
704 if (STRINGP(instantiator)) {
706 if (!UNBOUNDP(matchspec)) {
707 /* The instantiator is a font spec that could match many
708 different fonts. We need to find one of those fonts
709 whose registry matches the registry of the charset in
710 MATCHSPEC. This is potentially a very slow operation,
711 as it involves doing an XListFonts() or equivalent to
712 iterate over all possible fonts, and a regexp match
713 on each one. So we cache the results. */
714 Lisp_Object matching_font = Qunbound;
715 Lisp_Object hash_table =
716 Fgethash(matchspec, d->charset_font_cache,
718 if (UNBOUNDP(hash_table)) {
719 /* need to make a sub hash table. */
721 make_lisp_hash_table(20,
724 Fputhash(matchspec, hash_table,
725 d->charset_font_cache);
728 Fgethash(instantiator, hash_table,
731 if (UNBOUNDP(matching_font)) {
732 /* make sure we cache the failures, too. */
734 DEVMETH_OR_GIVEN(d, find_charset_font,
735 (device, instantiator,
736 matchspec), instantiator);
737 Fputhash(instantiator, matching_font,
740 if (NILP(matching_font))
742 instantiator = matching_font;
746 /* First, look to see if we can retrieve a cached value. */
748 Fgethash(instantiator, d->font_instance_cache, Qunbound);
749 /* Otherwise, make a new one. */
750 if (UNBOUNDP(instance)) {
751 /* make sure we cache the failures, too. */
753 Fmake_font_instance(instantiator, device, Qt);
754 Fputhash(instantiator, instance,
755 d->font_instance_cache);
758 return NILP(instance) ? Qunbound : instance;
759 } else if (VECTORP(instantiator)) {
760 assert(XVECTOR_LENGTH(instantiator) == 1);
761 return (face_property_matching_instance
762 (Fget_face(XVECTOR_DATA(instantiator)[0]), Qfont,
763 matchspec, domain, ERROR_ME, 0, depth));
764 } else if (NILP(instantiator))
772 static void font_validate(Lisp_Object instantiator)
774 if (FONT_INSTANCEP(instantiator) || STRINGP(instantiator))
776 if (VECTORP(instantiator)) {
777 if (XVECTOR_LENGTH(instantiator) != 1) {
779 ("Vector length must be one for font inheritance",
782 Fget_face(XVECTOR_DATA(instantiator)[0]);
784 signal_simple_error("Must be string, vector, or font-instance",
788 static void font_after_change(Lisp_Object specifier, Lisp_Object locale)
790 Lisp_Object face = FONT_SPECIFIER_FACE(XFONT_SPECIFIER(specifier));
791 Lisp_Object property =
792 FONT_SPECIFIER_FACE_PROPERTY(XFONT_SPECIFIER(specifier));
794 face_property_was_changed(face, property, locale);
796 XBUFFER(locale)->buffer_local_face_property = 1;
801 set_font_attached_to(Lisp_Object obj, Lisp_Object face, Lisp_Object property)
803 Lisp_Specifier *font = XFONT_SPECIFIER(obj);
805 FONT_SPECIFIER_FACE(font) = face;
806 FONT_SPECIFIER_FACE_PROPERTY(font) = property;
809 DEFUN("font-specifier-p", Ffont_specifier_p, 1, 1, 0, /*
810 Return non-nil if OBJECT is a font specifier.
812 See `make-font-specifier' for a description of possible font instantiators.
816 return FONT_SPECIFIERP(object) ? Qt : Qnil;
819 /*****************************************************************************
821 ****************************************************************************/
822 DEFINE_SPECIFIER_TYPE(face_boolean);
823 Lisp_Object Qface_boolean;
825 static void face_boolean_create(Lisp_Object obj)
827 Lisp_Specifier *face_boolean = XFACE_BOOLEAN_SPECIFIER(obj);
829 FACE_BOOLEAN_SPECIFIER_FACE(face_boolean) = Qnil;
830 FACE_BOOLEAN_SPECIFIER_FACE_PROPERTY(face_boolean) = Qnil;
833 static void face_boolean_mark(Lisp_Object obj)
835 Lisp_Specifier *face_boolean = XFACE_BOOLEAN_SPECIFIER(obj);
837 mark_object(FACE_BOOLEAN_SPECIFIER_FACE(face_boolean));
838 mark_object(FACE_BOOLEAN_SPECIFIER_FACE_PROPERTY(face_boolean));
841 /* No equal or hash methods; ignore the face the face-boolean is based off
845 face_boolean_instantiate(Lisp_Object specifier, Lisp_Object matchspec,
846 Lisp_Object domain, Lisp_Object instantiator,
849 /* When called, we're inside of call_with_suspended_errors(),
850 so we can freely error. */
851 if (NILP(instantiator) || EQ(instantiator, Qt))
853 else if (VECTORP(instantiator)) {
856 int instantiator_len = XVECTOR_LENGTH(instantiator);
858 assert(instantiator_len >= 1 && instantiator_len <= 3);
859 if (instantiator_len > 1)
860 prop = XVECTOR_DATA(instantiator)[1];
862 if (NILP(FACE_BOOLEAN_SPECIFIER_FACE
863 (XFACE_BOOLEAN_SPECIFIER(specifier))))
865 ("Face-boolean specifier not attached to a face",
868 FACE_BOOLEAN_SPECIFIER_FACE_PROPERTY
869 (XFACE_BOOLEAN_SPECIFIER(specifier));
872 retval = (FACE_PROPERTY_INSTANCE_1
873 (Fget_face(XVECTOR_DATA(instantiator)[0]),
874 prop, domain, ERROR_ME, 0, depth));
876 if (instantiator_len == 3
877 && !NILP(XVECTOR_DATA(instantiator)[2]))
878 retval = NILP(retval) ? Qt : Qnil;
887 static void face_boolean_validate(Lisp_Object instantiator)
889 if (NILP(instantiator) || EQ(instantiator, Qt))
891 else if (VECTORP(instantiator) &&
892 (XVECTOR_LENGTH(instantiator) >= 1 &&
893 XVECTOR_LENGTH(instantiator) <= 3)) {
894 Lisp_Object face = XVECTOR_DATA(instantiator)[0];
898 if (XVECTOR_LENGTH(instantiator) > 1) {
899 Lisp_Object field = XVECTOR_DATA(instantiator)[1];
900 if (!EQ(field, Qunderline)
901 && !EQ(field, Qstrikethru)
902 && !EQ(field, Qhighlight)
904 && !EQ(field, Qblinking)
905 && !EQ(field, Qreverse))
907 ("Invalid face-boolean inheritance field",
910 } else if (VECTORP(instantiator))
912 ("Wrong length for face-boolean inheritance spec",
916 ("Face-boolean instantiator must be nil, t, or vector",
920 static void face_boolean_after_change(Lisp_Object specifier, Lisp_Object locale)
923 FACE_BOOLEAN_SPECIFIER_FACE(XFACE_BOOLEAN_SPECIFIER(specifier));
924 Lisp_Object property =
925 FACE_BOOLEAN_SPECIFIER_FACE_PROPERTY(XFACE_BOOLEAN_SPECIFIER
928 face_property_was_changed(face, property, locale);
930 XBUFFER(locale)->buffer_local_face_property = 1;
935 set_face_boolean_attached_to(Lisp_Object obj, Lisp_Object face,
936 Lisp_Object property)
938 Lisp_Specifier *face_boolean = XFACE_BOOLEAN_SPECIFIER(obj);
940 FACE_BOOLEAN_SPECIFIER_FACE(face_boolean) = face;
941 FACE_BOOLEAN_SPECIFIER_FACE_PROPERTY(face_boolean) = property;
944 DEFUN("face-boolean-specifier-p", Fface_boolean_specifier_p, 1, 1, 0, /*
945 Return non-nil if OBJECT is a face-boolean specifier.
947 See `make-face-boolean-specifier' for a description of possible
948 face-boolean instantiators.
952 return FACE_BOOLEAN_SPECIFIERP(object) ? Qt : Qnil;
955 /************************************************************************/
957 /************************************************************************/
959 void syms_of_objects(void)
961 INIT_LRECORD_IMPLEMENTATION(color_instance);
962 INIT_LRECORD_IMPLEMENTATION(font_instance);
964 DEFSUBR(Fcolor_specifier_p);
965 DEFSUBR(Ffont_specifier_p);
966 DEFSUBR(Fface_boolean_specifier_p);
968 defsymbol(&Qcolor_instancep, "color-instance-p");
969 DEFSUBR(Fmake_color_instance);
970 DEFSUBR(Fcolor_instance_p);
971 DEFSUBR(Fcolor_instance_name);
972 DEFSUBR(Fcolor_instance_rgb_components);
973 DEFSUBR(Fvalid_color_name_p);
975 defsymbol(&Qfont_instancep, "font-instance-p");
976 DEFSUBR(Fmake_font_instance);
977 DEFSUBR(Ffont_instance_p);
978 DEFSUBR(Ffont_instance_name);
979 DEFSUBR(Ffont_instance_ascent);
980 DEFSUBR(Ffont_instance_descent);
981 DEFSUBR(Ffont_instance_width);
982 DEFSUBR(Ffont_instance_proportional_p);
983 DEFSUBR(Ffont_instance_truename);
984 DEFSUBR(Ffont_instance_properties);
985 DEFSUBR(Flist_fonts);
987 /* Qcolor, Qfont defined in general.c */
988 defsymbol(&Qface_boolean, "face-boolean");
991 static const struct lrecord_description color_specifier_description[] = {
993 specifier_data_offset + offsetof(struct color_specifier, face)},
995 specifier_data_offset + offsetof(struct color_specifier,
1000 static const struct lrecord_description font_specifier_description[] = {
1002 specifier_data_offset + offsetof(struct font_specifier, face)},
1004 specifier_data_offset + offsetof(struct font_specifier,
1009 static const struct lrecord_description face_boolean_specifier_description[] = {
1011 specifier_data_offset + offsetof(struct face_boolean_specifier, face)},
1013 specifier_data_offset + offsetof(struct face_boolean_specifier,
1018 void specifier_type_create_objects(void)
1020 INITIALIZE_SPECIFIER_TYPE_WITH_DATA(color, "color",
1021 "color-specifier-p");
1022 INITIALIZE_SPECIFIER_TYPE_WITH_DATA(font, "font", "font-specifier-p");
1023 INITIALIZE_SPECIFIER_TYPE_WITH_DATA(face_boolean, "face-boolean",
1024 "face-boolean-specifier-p");
1026 SPECIFIER_HAS_METHOD(color, instantiate);
1027 SPECIFIER_HAS_METHOD(font, instantiate);
1028 SPECIFIER_HAS_METHOD(face_boolean, instantiate);
1030 SPECIFIER_HAS_METHOD(color, validate);
1031 SPECIFIER_HAS_METHOD(font, validate);
1032 SPECIFIER_HAS_METHOD(face_boolean, validate);
1034 SPECIFIER_HAS_METHOD(color, create);
1035 SPECIFIER_HAS_METHOD(font, create);
1036 SPECIFIER_HAS_METHOD(face_boolean, create);
1038 SPECIFIER_HAS_METHOD(color, mark);
1039 SPECIFIER_HAS_METHOD(font, mark);
1040 SPECIFIER_HAS_METHOD(face_boolean, mark);
1042 SPECIFIER_HAS_METHOD(color, after_change);
1043 SPECIFIER_HAS_METHOD(font, after_change);
1044 SPECIFIER_HAS_METHOD(face_boolean, after_change);
1047 SPECIFIER_HAS_METHOD(font, validate_matchspec);
1051 void reinit_specifier_type_create_objects(void)
1053 REINITIALIZE_SPECIFIER_TYPE(color);
1054 REINITIALIZE_SPECIFIER_TYPE(font);
1055 REINITIALIZE_SPECIFIER_TYPE(face_boolean);
1058 void reinit_vars_of_objects(void)
1060 staticpro_nodump(&Vthe_null_color_instance);
1062 Lisp_Color_Instance *c =
1063 alloc_lcrecord_type(Lisp_Color_Instance,
1064 &lrecord_color_instance);
1069 XSETCOLOR_INSTANCE(Vthe_null_color_instance, c);
1072 staticpro_nodump(&Vthe_null_font_instance);
1074 Lisp_Font_Instance *f =
1075 alloc_lcrecord_type(Lisp_Font_Instance,
1076 &lrecord_font_instance);
1081 f->ascent = f->height = 0;
1084 f->proportional_p = 0;
1086 XSETFONT_INSTANCE(Vthe_null_font_instance, f);
1090 void vars_of_objects(void)
1092 reinit_vars_of_objects();