1 ;;; glyphs.el --- Lisp interface to C glyphs
3 ;; Copyright (C) 1994, 1997 Free Software Foundation, Inc.
4 ;; Copyright (C) 1995, 1996, 2000 Ben Wing.
5 ;; Copyright (C) 2004 Steve Youngs
7 ;; Author: Chuck Thompson <cthomp@cs.uiuc.edu>, Ben Wing <ben@xemacs.org>
8 ;; Maintainer: SXEmacs Development Team
9 ;; Keywords: extensions, internal, dumped
11 ;; This file is part of SXEmacs.
13 ;; SXEmacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; SXEmacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
26 ;;; Synched up with: Not in FSF.
30 ;; Prototype created 1995 by Chuck Thompson.
31 ;; Completely rewritten by Ben Wing, 1995.
32 ;; Various cleanups (esp. doc strings) by Ben Wing, May 2000.
36 ;; This file is dumped with SXEmacs.
40 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; image specifiers
42 (defun make-image-specifier (spec-list)
43 "Return a new `image' specifier object with the specification list SPEC-LIST.
44 SPEC-LIST can be a list of specifications (each of which is a cons of a
45 locale and a list of instantiators), a single instantiator, or a list
46 of instantiators. See `make-specifier' for more information about
49 An image specifier is used for images (pixmaps, widgets and the like).
50 It is used to describe the actual image in a glyph. It is instanced
51 as an image-instance. Note that \"image\" as used in XEmacs does not
52 actually refer to what the term \"image\" normally means (a picture,
53 e.g. in .GIF or .JPG format, and called a \"pixmap\" in XEmacs), but
54 includes all types of graphical elements, including pixmaps, widgets
55 \(buttons, sliders, text fields, etc.) and even strings of text.
57 Note that, in practice, you rarely, if ever, need to actually create
58 an image specifier! (The function `make-image-specifier' exists mainly
59 for completeness.) Pretty much the only use for image specifiers is to
60 control how glyphs are displayed, and the image specifier associated
61 with a glyph (the `image' property of a glyph) is created
62 automatically when a glyph is created (see `make-glyph') and need not
63 \(and cannot, for that matter) ever be changed. In fact, the design
64 decision to create a separate image specifier type, rather than make
65 glyphs themselves be specifiers, is debatable -- the other properties
66 of glyphs are rarely used and could conceivably have been incorporated
67 into the glyph's instantiator. The rarely used glyph types (buffer,
68 pointer, icon) could also have been incorporated into the instantiator.
70 Image instantiators come in many formats: `xbm', `xpm', `gif', `jpeg',
71 etc. This describes the format of the data describing the image. The
72 resulting image instances also come in many types -- `mono-pixmap',
73 `color-pixmap', `text', `pointer', etc. This refers to the behavior of
74 the image and the sorts of places it can appear. (For example, a
75 color-pixmap image has fixed colors specified for it, while a
76 mono-pixmap image comes in two unspecified shades \"foreground\" and
77 \"background\" that are determined from the face of the glyph or
78 surrounding text; a text image appears as a string of text and has an
79 unspecified foreground, background, and font; a pointer image behaves
80 like a mono-pixmap image but can only be used as a mouse pointer
81 \[mono-pixmap images cannot be used as mouse pointers]; etc.) It is
82 important to keep the distinction between image instantiator format and
83 image instance type in mind. Typically, a given image instantiator
84 format can result in many different image instance types (for example,
85 `xpm' can be instanced as `color-pixmap', `mono-pixmap', or `pointer';
86 whereas `cursor-font' can be instanced only as `pointer'), and a
87 particular image instance type can be generated by many different
88 image instantiator formats (e.g. `color-pixmap' can be generated by `xpm',
91 See `make-image-instance' for a more detailed discussion of image
94 An image instantiator should be a string or a vector of the form
96 [FORMAT :KEYWORD VALUE ...]
98 i.e. a format symbol followed by zero or more alternating keyword-value
99 pairs. FORMAT should be one of
102 Don't display anything; no keywords are valid for this.
103 Can only be instanced as `nothing'.
105 Display this image as a text string. Can only be instanced
106 as `text', although support for instancing as `mono-pixmap'
107 and `color-pixmap' should be added.
109 Display this image as a text string, with replaceable fields;
110 not currently implemented. (It is, instead, equivalent to `string'.)
112 An X bitmap; only if X or MS Windows support was compiled into this
113 XEmacs. Can be instanced as `mono-pixmap', `color-pixmap', or `pointer'.
115 An XPM pixmap; only if XPM support was compiled into this XEmacs.
116 Can be instanced as `color-pixmap', `mono-pixmap', or `pointer'.
118 An X-Face bitmap, used to encode people's faces in e-mail messages;
119 only if X-Face support was compiled into this XEmacs. Can be
120 instanced as `mono-pixmap', `color-pixmap', or `pointer'.
122 A GIF87 or GIF89 image; only if GIF support was compiled into this
123 XEmacs. NOTE: only the first frame of animated gifs will be displayed.
124 Can be instanced as `color-pixmap'.
126 A JPEG image; only if JPEG support was compiled into this XEmacs.
127 Can be instanced as `color-pixmap'.
129 A PNG image; only if PNG support was compiled into this XEmacs.
130 Can be instanced as `color-pixmap'.
132 A TIFF image; only if TIFF support was compiled into this XEmacs.
133 Can be instanced as `color-pixmap'.
135 A MS Windows BMP image; only if MS Windows support was compiled into
136 this XEmacs. Can be instanced as `color-pixmap'.
138 One of the standard cursor-font names, such as \"watch\" or
139 \"right_ptr\" under X. Under X, this is, more specifically, any
140 of the standard cursor names from appendix B of the Xlib manual
141 [also known as the file <X11/cursorfont.h>] minus the XC_ prefix.
142 On other window systems, the valid names will be specific to the
143 type of window system. Can only be instanced as `pointer'.
145 A glyph from a font; i.e. the name of a font, and glyph index into it
146 of the form \"FONT fontname index [[mask-font] mask-index]\".
147 Currently can only be instanced as `pointer', although this should
150 An embedded windowing system window. Can only be instanced as
153 A button widget; either a push button, radio button or toggle button.
154 Can only be instanced as `widget'.
156 A drop list of selectable items in a widget, for editing text.
157 Can only be instanced as `widget'.
159 A text editing widget. Can only be instanced as `widget'.
161 A static, text-only, widget; for displaying text. Can only be instanced
164 A widget for controlling the positioning of children underneath it.
165 Through the use of nested layouts, a widget hierarchy can be created
166 which can have the appearance of any standard dialog box or similar
167 arrangement; all of this is counted as one \"glyph\" and could appear
168 in many of the places that expect a single glyph. Can only be instanced
171 The native version of a layout widget. #### Document me better!
172 Can only be instanced as `widget'.
174 A sliding widget, for showing progress. Can only be instanced as
177 A tab widget; a series of user selectable tabs. Can only be instanced
180 A folding widget. Can only be instanced as `widget'.
182 A scrollbar widget. Can only be instanced as `widget'.
184 XEmacs tries to guess what format the data is in. If X support
185 exists, the data string will be checked to see if it names a filename.
186 If so, and this filename contains XBM or XPM data, the appropriate
187 sort of pixmap or pointer will be created. [This includes picking up
188 any specified hotspot or associated mask file.] Otherwise, if `pointer'
189 is one of the allowable image-instance types and the string names a
190 valid cursor-font name, the image will be created as a pointer.
191 Otherwise, the image will be displayed as text. If no X support
192 exists, the image will always be displayed as text. Can be instanced as
193 `mono-pixmap', `color-pixmap', `pointer', or `text'.
195 Inherit from the background-pixmap property of a face. Can only be
196 instanced as `mono-pixmap'.
198 The valid keywords are:
201 Inline data. For most formats above, this should be a string. For
202 XBM images, this should be a list of three elements: width, height, and
203 a string of bit data. This keyword is valid for all of the bitmap/pixmap
204 formats, as well as `string', `formatted-string', `font', `cursor-font',
207 Data is contained in a file. The value is the name of this file.
208 If both :data and :file are specified, the image is created from
209 what is specified in :data and the string in :file becomes the
210 value of the `image-instance-file-name' function when applied to
211 the resulting image-instance. This keyword is valid for all of the
212 bitmap/pixmap formats.
215 For `xbm', `xface', `cursor-font', `widget' and `font'. These keywords
216 allow you to explicitly specify foreground and background colors.
217 The argument should be anything acceptable to `make-color-instance'.
218 This will cause what would be a `mono-pixmap' to instead be colorized
219 as a two-color color-pixmap, and specifies the foreground and/or
220 background colors for a pointer instead of black and white.
222 For `xbm' and `xface'. This specifies a mask to be used with the
223 bitmap. The format is a list of width, height, and bits, like for
226 For `xbm' and `xface'. This specifies a file containing the mask data.
227 If neither a mask file nor inline mask data is given for an XBM image,
228 and the XBM image comes from a file, XEmacs will look for a mask file
229 with the same name as the image file but with \"Mask\" or \"msk\"
230 appended. For example, if you specify the XBM file \"left_ptr\"
231 [usually located in \"/usr/include/X11/bitmaps\"], the associated
232 mask file \"left_ptrmsk\" will automatically be picked up.
235 For `xbm' and `xface'. These keywords specify a hotspot if the image
236 is instantiated as a `pointer'. Note that if the XBM image file
237 specifies a hotspot, it will automatically be picked up if no
238 explicit hotspot is given.
240 Only for `xpm'. This specifies an alist that maps strings
241 that specify symbolic color names to the actual color to be used
242 for that symbolic color (in the form of a string or a color-specifier
243 object). If this is not specified, the contents of `xpm-color-symbols'
244 are used to generate the alist.
248 \"close\", \"uparrow\", \"dnarrow\", \"rgarrow\", \"lfarrow\",
249 \"reduce\", \"zoom\", \"restore\", \"reduced\", \"zoomd\",
250 \"restored\", \"uparrowd\", \"dnarrowd\", \"rgarrowd\", \"lfarrowd\",
251 \"mnarrow\", \"combo\", \"uparrowi\", \"dnarrowi\", \"rgarrowi\",
252 \"lfarrowi\", \"size\", \"btsize\", \"check\", \"checkboxes\", and
257 \"normal\", \"ibeam\", \"wait\", \"cross\", \"up\", \"sizenwse\",
258 \"sizenesw\", \"sizewe\", \"sizens\", \"sizeall\", and \"no\".
262 \"sample\", \"hand\", \"ques\", \"bang\", \"note\", and \"winlogo\".
264 Only for `inherit'. This specifies the face to inherit from.
265 For widgets this also specifies the face to use for display. It defaults
268 Keywords accepted as menu item specs are also accepted by widgets.
269 These are `:selected', `:active', `:suffix', `:keys', `:style',
270 `:filter', `:config', `:included', `:key-sequence', `:accelerator',
271 `:label' and `:callback'.
273 If instead of a vector, the instantiator is a string, it will be
274 converted into a vector by looking it up according to the specs in the
275 `console-type-image-conversion-list' (q.v.) for the console type of
276 the domain (usually a window; sometimes a frame or device) over which
277 the image is being instantiated.
279 If the instantiator specifies data from a file, the data will be read
280 in at the time that the instantiator is added to the image (which may
281 be well before when the image is actually displayed), and the
282 instantiator will be converted into one of the inline-data forms, with
283 the filename retained using a :file keyword. This implies that the
284 file must exist when the instantiator is added to the image, but does
285 not need to exist at any other time (e.g. it may safely be a temporary
288 (make-specifier-and-init 'image spec-list))
290 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; glyphs
292 (defconst built-in-glyph-specifiers
293 '(image contrib-p baseline)
294 "A list of the built-in glyph properties that are specifiers.")
296 (defun glyph-property (glyph property &optional locale)
297 "Return GLYPH's value of PROPERTY in LOCALE.
299 If LOCALE is omitted, the GLYPH's actual value for PROPERTY will be
300 returned. For built-in properties, this will be a specifier object
301 of a type appropriate to the property (e.g. a font or color
302 specifier). For other properties, this could be anything.
304 If LOCALE is supplied, then instead of returning the actual value,
305 the specification(s) for the given locale or locale type will
306 be returned. This will only work if the actual value of
307 PROPERTY is a specifier (this will always be the case for built-in
308 properties, but not or not may apply to user-defined properties).
309 If the actual value of PROPERTY is not a specifier, this value
310 will simply be returned regardless of LOCALE.
312 The return value will be a list of instantiators (e.g. strings
313 specifying a font or color name), or a list of specifications, each
314 of which is a cons of a locale and a list of instantiators.
315 Specifically, if LOCALE is a particular locale (a buffer, window,
316 frame, device, or 'global), a list of instantiators for that locale
317 will be returned. Otherwise, if LOCALE is a locale type (one of
318 the symbols 'buffer, 'window, 'frame, 'device, 'device-class, or
319 'device-type), the specifications for all locales of that type will
320 be returned. Finally, if LOCALE is 'all, the specifications for all
321 locales of all types will be returned.
323 The specifications in a specifier determine what the value of
324 PROPERTY will be in a particular \"domain\" or set of circumstances,
325 which is typically a particular Emacs window along with the buffer
326 it contains and the frame and device it lies within. The value
327 is derived from the instantiator associated with the most specific
328 locale (in the order buffer, window, frame, device, and 'global)
329 that matches the domain in question. In other words, given a domain
330 (i.e. an Emacs window, usually), the specifier for PROPERTY will first
331 be searched for a specification whose locale is the buffer contained
332 within that window; then for a specification whose locale is the window
333 itself; then for a specification whose locale is the frame that the
334 window is contained within; etc. The first instantiator that is
335 valid for the domain (usually this means that the instantiator is
336 recognized by the device [i.e. the X server or TTY device] that the
337 domain is on. The function `glyph-property-instance' actually does
338 all this, and is used to determine how to display the glyph.
340 See `set-glyph-property' for the built-in property-names."
341 (check-argument-type 'glyphp glyph)
342 (let ((value (get glyph property)))
344 (or (memq property built-in-glyph-specifiers)
346 (setq value (specifier-specs value locale)))
349 (defun convert-glyph-property-into-specifier (glyph property)
350 "Convert PROPERTY on GLYPH into a specifier, if it's not already."
351 (check-argument-type 'glyphp glyph)
352 (let ((specifier (get glyph property)))
353 ;; if a user-property does not have a specifier but a
354 ;; locale was specified, put a specifier there.
355 ;; If there was already a value there, convert it to a
356 ;; specifier with the value as its 'global instantiator.
357 (if (not (specifierp specifier))
358 (let ((new-specifier (make-specifier 'generic)))
359 (if (or (not (null specifier))
360 ;; make sure the nil returned from `get' wasn't
361 ;; actually the value of the property
362 (null (get glyph property t)))
363 (add-spec-to-specifier new-specifier specifier))
364 (setq specifier new-specifier)
365 (put glyph property specifier)))))
367 (defun glyph-property-instance (glyph property
368 &optional domain default no-fallback)
369 "Return the instance of GLYPH's PROPERTY in the specified DOMAIN.
371 Under most circumstances, DOMAIN will be a particular window,
372 and the returned instance describes how the specified property
373 actually is displayed for that window and the particular buffer
374 in it. Note that this may not be the same as how the property
375 appears when the buffer is displayed in a different window or
376 frame, or how the property appears in the same window if you
377 switch to another buffer in that window; and in those cases,
378 the returned instance would be different.
380 DOMAIN defaults to the selected window if omitted.
382 DOMAIN can be a frame or device, instead of a window. The value
383 returned for a such a domain is used in special circumstances
384 when a more specific domain does not apply; for example, a frame
385 value might be used for coloring a toolbar, which is conceptually
386 attached to a frame rather than a particular window. The value
387 is also useful in determining what the value would be for a
388 particular window within the frame or device, if it is not
389 overridden by a more specific specification.
391 If PROPERTY does not name a built-in property, its value will
392 simply be returned unless it is a specifier object, in which case
393 it will be instanced using `specifier-instance'.
395 Optional arguments DEFAULT and NO-FALLBACK are the same as in
396 `specifier-instance'."
397 (check-argument-type 'glyphp glyph)
398 (let ((value (get glyph property)))
399 (if (specifierp value)
400 (setq value (specifier-instance value domain default no-fallback)))
403 (defun set-glyph-property (glyph property value &optional locale tag-set
405 "Change a property of a GLYPH.
407 NOTE: If you want to remove a property from a glyph, use
408 `remove-glyph-property' rather than attempting to set a value of nil
411 For built-in properties, the actual value of the property is a
412 specifier and you cannot change this; but you can change the
413 specifications within the specifier, and that is what this function
414 will do. For user-defined properties, you can use this function
415 to either change the actual value of the property or, if this value
416 is a specifier, change the specifications within it.
418 If PROPERTY is a built-in property, the specifications to be added to
419 this property can be supplied in many different ways:
421 -- If VALUE is a simple instantiator (e.g. a string naming a font or
422 color) or a list of instantiators, then the instantiator(s) will
423 be added as a specification of the property for the given LOCALE
424 (which defaults to 'global if omitted).
425 -- If VALUE is a list of specifications (each of which is a cons of
426 a locale and a list of instantiators), then LOCALE must be nil
427 (it does not make sense to explicitly specify a locale in this
428 case), and specifications will be added as given.
429 -- If VALUE is a specifier (as would be returned by `glyph-property'
430 if no LOCALE argument is given), then some or all of the
431 specifications in the specifier will be added to the property.
432 In this case, the function is really equivalent to
433 `copy-specifier' and LOCALE has the same semantics (if it is
434 a particular locale, the specification for the locale will be
435 copied; if a locale type, specifications for all locales of
436 that type will be copied; if nil or 'all, then all
437 specifications will be copied).
439 HOW-TO-ADD should be either nil or one of the symbols 'prepend,
440 'append, 'remove-tag-set-prepend, 'remove-tag-set-append, 'remove-locale,
441 'remove-locale-type, or 'remove-all. See `copy-specifier' and
442 `add-spec-to-specifier' for a description of what each of
443 these means. Most of the time, you do not need to worry about
444 this argument; the default behavior usually is fine.
446 In general, it is OK to pass an instance object (e.g. as returned
447 by `glyph-property-instance') as an instantiator in place of
448 an actual instantiator. In such a case, the instantiator used
449 to create that instance object will be used (for example, if
450 you set a font-instance object as the value of the 'font
451 property, then the font name used to create that object will
452 be used instead). If some cases, however, doing this
453 conversion does not make sense, and this will be noted in
454 the documentation for particular types of instance objects.
456 If PROPERTY is not a built-in property, then this function will
457 simply set its value if LOCALE is nil. However, if LOCALE is
458 given, then this function will attempt to add VALUE as the
459 instantiator for the given LOCALE, using `add-spec-to-specifier'.
460 If the value of the property is not a specifier, it will
461 automatically be converted into a 'generic specifier.
464 The following symbols have predefined meanings:
466 image The image used to display the glyph.
468 baseline Percent above baseline that glyph is to be
471 contrib-p Whether the glyph contributes to the
472 height of the line it's on.
474 face Face of this glyph (*not* a specifier)."
475 (check-argument-type 'glyphp glyph)
476 (if (memq property built-in-glyph-specifiers)
477 (set-specifier (get glyph property) value locale tag-set how-to-add)
479 ;; This section adds user defined properties.
481 (put glyph property value)
482 (convert-glyph-property-into-specifier glyph property)
483 (add-spec-to-specifier (get glyph property) value locale tag-set
487 (defun remove-glyph-property (glyph property &optional locale tag-set exact-p)
488 "Remove a property from a glyph.
489 For built-in properties, this is analogous to `remove-specifier'.
490 See `remove-specifier' for the meaning of the LOCALE, TAG-SET, and EXACT-P
492 (or locale (setq locale 'all))
493 (if (memq property built-in-glyph-specifiers)
494 (remove-specifier (glyph-property glyph property) locale tag-set exact-p)
496 (remprop glyph property)
497 (convert-glyph-property-into-specifier glyph property)
498 (remove-specifier (glyph-property glyph property) locale tag-set
501 (defun glyph-face (glyph)
502 "Return the face of GLYPH."
503 (glyph-property glyph 'face))
505 (defun set-glyph-face (glyph face)
506 "Change the face of GLYPH to FACE."
507 ; (interactive (glyph-interactive "face"))
508 (set-glyph-property glyph 'face face))
510 (defun glyph-image (glyph &optional locale)
511 "Return the image of GLYPH in LOCALE, or nil if it is unspecified.
513 LOCALE may be a locale (the instantiators for that particular locale
514 will be returned), a locale type (the specifications for all locales
515 of that type will be returned), 'all (all specifications will be
516 returned), or nil (the actual specifier object will be returned).
518 See `glyph-property' for more information."
519 (glyph-property glyph 'image locale))
521 (defun glyph-image-instance (glyph &optional domain default no-fallback)
522 "Return the instance of GLYPH's image in DOMAIN.
524 Normally DOMAIN will be a window or nil (meaning the selected window),
525 and an instance object describing how the image appears in that
526 particular window and buffer will be returned.
528 See `glyph-property-instance' for more information."
529 (glyph-property-instance glyph 'image domain default no-fallback))
531 (defun glyph-image-property (glyph prop &optional domain default no-fallback)
532 "Return property PROP of the instance of GLYPH's image in DOMAIN.
534 Normally DOMAIN will be a window or nil (meaning the selected window).
535 The value returned is dependent on the image instance type."
536 (image-instance-property
537 (glyph-image-instance glyph domain default no-fallback) prop))
539 (defun set-glyph-image (glyph spec &optional locale tag-set how-to-add)
540 "Change the image of GLYPH in LOCALE.
542 SPEC should be an instantiator (a string or vector; see
543 `make-image-specifier' for a description of possible values here),
544 a list of (possibly tagged) instantiators, an alist of specifications
545 (each mapping a locale to an instantiator list), or an image specifier
548 If SPEC is an alist, LOCALE must be omitted. If SPEC is a
549 specifier object, LOCALE can be a locale, a locale type, 'all,
550 or nil; see `copy-specifier' for its semantics. Otherwise LOCALE
551 specifies the locale under which the specified instantiator(s)
552 will be added, and defaults to 'global.
554 See `set-glyph-property' for more information."
555 ; (interactive (glyph-interactive "image"))
556 (set-glyph-property glyph 'image spec locale tag-set how-to-add))
558 (defun glyph-contrib-p (glyph &optional locale)
559 "Return whether GLYPH contributes to its line height.
561 LOCALE may be a locale (the instantiators for that particular locale
562 will be returned), a locale type (the specifications for all locales
563 of that type will be returned), 'all (all specifications will be
564 returned), or nil (the actual specifier object will be returned).
566 See `glyph-property' for more information."
567 (glyph-property glyph 'contrib-p locale))
569 (defun glyph-contrib-p-instance (glyph &optional domain default no-fallback)
570 "Return the instance of GLYPH's 'contrib-p property in DOMAIN.
572 Normally DOMAIN will be a window or nil (meaning the selected window),
573 and an instance object describing what the 'contrib-p property is in
574 that particular window and buffer will be returned.
576 See `glyph-property-instance' for more information."
577 (glyph-property-instance glyph 'contrib-p domain default no-fallback))
579 (defun set-glyph-contrib-p (glyph spec &optional locale tag-set how-to-add)
580 "Change the contrib-p property of GLYPH in LOCALE.
582 SPEC should be an instantiator (t or nil), a list of (possibly
583 tagged) instantiators, an alist of specifications (each mapping a
584 locale to an instantiator list), or a boolean specifier object.
586 If SPEC is an alist, LOCALE must be omitted. If SPEC is a
587 specifier object, LOCALE can be a locale, a locale type, 'all,
588 or nil; see `copy-specifier' for its semantics. Otherwise LOCALE
589 specifies the locale under which the specified instantiator(s)
590 will be added, and defaults to 'global.
592 See `set-glyph-property' for more information."
593 ; (interactive (glyph-interactive "contrib-p"))
594 (set-glyph-property glyph 'contrib-p spec locale tag-set how-to-add))
596 (defun glyph-baseline (glyph &optional locale)
597 "Return the baseline of GLYPH in LOCALE, or nil if it is unspecified.
599 LOCALE may be a locale (the instantiators for that particular locale
600 will be returned), a locale type (the specifications for all locales
601 of that type will be returned), 'all (all specifications will be
602 returned), or nil (the actual specifier object will be returned).
604 See `glyph-property' for more information."
605 (glyph-property glyph 'baseline locale))
607 (defun glyph-baseline-instance (glyph &optional domain default no-fallback)
608 "Return the instance of GLYPH's baseline in DOMAIN.
610 Normally DOMAIN will be a window or nil (meaning the selected window),
611 and an integer or nil (specifying the baseline in that particular
612 window and buffer) will be returned.
614 See `glyph-property-instance' for more information."
615 (glyph-property-instance glyph 'baseline domain default no-fallback))
617 (defun set-glyph-baseline (glyph spec &optional locale tag-set how-to-add)
618 "Change the baseline of GLYPH to SPEC in LOCALE.
620 SPEC should be an instantiator (an integer [a percentage above the
621 baseline of the line the glyph is on] or nil), a list of (possibly
622 tagged) instantiators, an alist of specifications (each mapping a
623 locale to an instantiator list), or a generic specifier object.
625 If SPEC is an alist, LOCALE must be omitted. If SPEC is a
626 specifier object, LOCALE can be a locale, a locale type, 'all,
627 or nil; see `copy-specifier' for its semantics. Otherwise LOCALE
628 specifies the locale under which the specified instantiator(s)
629 will be added, and defaults to 'global.
631 See `set-glyph-property' for more information."
632 ; (interactive (glyph-interactive "baseline"))
633 (set-glyph-property glyph 'baseline spec locale tag-set how-to-add))
635 (defun make-glyph (&optional spec-list type)
636 "Create a new glyph of type TYPE.
638 A glyph in XEmacs does NOT refer to a single unit of textual display (the
639 XEmacs term for this is \"rune\"), but rather is an object encapsulating
640 a graphical element, such as an image or widget (an element such as a
641 button or text field; \"widget\" is the term for this under X Windows,
642 and it's called a \"control\" under MS Windows). This graphical element
643 could appear in a buffer, a margin, a gutter, or a toolbar, or as a mouse
644 pointer or an icon, for example.
646 Creating a glyph using `make-glyph' does not specify *where* the glyph
647 will be used, but it does specify *what* the glyph will look like. In
648 particular, SPEC-LIST is used to specify this, and it's used to
649 initialize the glyph's `image' property, which is an image
650 specifier. (Note that \"image\" as used in the context of a glyph's
651 `image' property or in the terms \"image specifier\", \"image
652 instantiator\", or \"image instance\" does not refer to what people
653 normally think of as an image (which in XEmacs is called a
654 \"pixmap\"), but to any graphical element -- a pixmap, a widget, or
655 even a block of text, when used in the places that call for a glyph.)
656 The format of the SPEC-LIST is typically an image instantiator (a
657 string or a vector; see `make-image-specifier' for a detailed description
658 of the valid image instantiators), but can also be a list of such
659 instantiators (each one in turn is tried until an image is
660 successfully produced), a cons of a locale (frame, buffer, etc.) and
661 an instantiator, a list of such conses, or any other form accepted by
662 `canonicalize-spec-list'.
664 If you're not familiar with specifiers, you should be in order to
665 understand how glyphs work. The clearest introduction to specifiers
666 is in the Lispref manual, available under Info. (Choose
667 Help->Info->Info Contents on the menubar or type \\[info].) You can
668 also see `make-specifier' for a capsule summary. What's important to
669 keep in mind is that a specifier lets you set a different value for
670 any particular buffer, window, frame, device, or console. This allows
671 for a great deal of flexibility; in particular, only one global glyph
672 needs to exist for a particular purpose (e.g. the icon used to represent
673 an iconified frame, the mouse pointer used over particular areas of a
674 frame, etc.), and in these cases you do not create your own glyph, but
675 rather modify the existing one.
677 As well as using SPEC-LIST to initialize the glyph, you can set
678 specifications using `set-glyph-image'. Note that, due to a possibly
679 questionable historical design decision, a glyph itself is not
680 actually a specifier, but rather is an object containing an image
681 specifier (as well as other, seldom-used properties). Therefore, you
682 cannot set or access specifications for the glyph's image by directly
683 using `set-specifier', `specifier-instance' or the like on the glyph;
684 instead use them on `(glyph-image GLYPH)' or use the convenience
685 functions `set-glyph-image', `glyph-image-instance', and
688 Once you have created a glyph, you specify where it will be used as follows:
690 -- To insert a glyph into a buffer, create an extent in the buffer and then
691 use `set-extent-begin-glyph' or `set-extent-end-glyph' to set a glyph
692 to be displayed at the corresponding edge of the extent. (It is common
693 to create zero-width extents for this purpose.)
695 -- To insert a glyph into the left or right margin of a buffer, first
696 make sure the margin is visible by setting a value for the specifiers
697 `left-margin-width' or `right-margin-width'. (Not strictly necessary
698 when using margin glyphs with layout policy `whitespace'.) Then follow
699 the same procedure above for inserting a glyph in a buffer, and then
700 set a non-default layout policy for the glyph using
701 `set-extent-begin-glyph-layout' or `set-extent-end-glyph-layout'.
702 Alternatively, use the high-level annotations API (see
703 `make-annotation'). (In point of fact, you can also use the annotations
704 API for glyphs in a buffer, by setting a layout policy of `text'.)
706 -- To insert a glyph into the modeline, just put the glyph directly as
707 one of the modeline elements. (Unfortunately you can't currently
708 put a begin glyph or end glyph on one of the modeline extents --
711 -- To insert a glyph into a toolbar, specify it as part of a toolbar
712 instantiator (typically set on the specifier `default-toolbar').
713 See `default-toolbar' for more information. (Note that it is standard
714 practice to use a symbol in place of the glyph list in the toolbar
715 instantiator; the symbol is evalled to get the glyph list. This
716 facilitates both creating the toolbar instantiator and modifying
717 individual glyphs in a toolbar later on. For example, you can
718 change the way that the Mail toolbar button looks by modifying the
719 value of the variable `toolbar-mail-icon' (in general, `toolbar-*-icon')
720 and then calling `(set-specifier-dirty-flag default-toolbar)'.
721 (#### Unfortunately this doesn't quite work the way it should; the
722 change will appear in new frames, but not existing ones.
724 -- To insert a glyph into a gutter, create or modify a gutter instantiator
725 (typically set on the specifier `default-gutter'). Gutter instantiators
726 consist of strings or lists of strings, so to insert a glyph, create an
727 extent over the string, and use `set-extent-begin-glyph' or
728 `set-extent-end-glyph' to set a glyph to be displayed at the corresponding
729 edge of the extent, just like for glyphs in a buffer.
731 -- To use a glyph as the icon for a frame, you do not actually create a new
732 glyph; rather, you change the specifications for the existing glyph
733 `frame-icon-glyph'. (Remember that, because of the specifier nature of
734 glyphs, you can set different values for any particular buffer or frame.)
736 -- To use a glyph as the mouse pointer, in general you do not create a
737 new glyph, but rather you change the specifications of various existing
738 glyphs, such as `text-pointer-glyph' for the pointer used over text,
739 `modeline-pointer-glyph' for the pointer used over the modeline, etc.
740 Do an apropos over `*-pointer-glyph' to find all of them. (Note also
741 that you can temporarily set the mouse pointer to some specific shape
742 by using `set-frame-pointer', which takes an image instance, as obtained
743 from calling `glyph-image-instance' on a glyph of type `pointer' --
744 either one of the above-mentioned variables or one you created yourself.
745 (See below for what it means to create a glyph of type `pointer'.)
746 This pointer will last only until the next mouse motion event is
747 processed or certain other things happen, such as creating or deleting
748 a window. (In fact, the above-mentioned pointer glyph variables are
749 implemented as part of the default handler for mouse motion events.
750 If you want to customize this behavior, take a look at `mode-motion-hook',
751 or `mouse-motion-handler' if you really want to get low-level.)
753 -- To use a glyph to control the shape of miscellaneous redisplay effects
754 such as the truncation and continuation markers, set the appropriate
755 existing glyph variables, as for icons and pointers above. See
756 `continuation-glyph', `control-arrow-glyph', `hscroll-glyph',
757 `invisible-text-glyph', `octal-escape-glyph', and `truncation-glyph'.
758 See also `overlay-arrow-string', an odd redisplay leftover which can
759 be set to a glyph you created, and will cause the glyph to be displayed
760 on top of the text position specified in the marker stored in
761 `overlay-arrow-position'.
763 -- To use a glyph in a display table (i.e. to control the appearance of
764 any individual character), create the appropriate character glyphs
765 and then set a specification for the specifier `current-display-table',
766 which controls the appearance of characters. You can also set an
767 overriding display table for use with text displayed in a particular
768 face; see `set-face-display-table' and `make-display-table'.
769 #### Note: Display tables do not currently support general Mule
770 characters. They will be overhauled at some point to support this
771 and to provide other features required under Mule.
773 -- To use a glyph as the background pixmap of a face: Note that the
774 background pixmap of a face is actually an image specifier -- probably
775 the only place in XEmacs where an image specifier occurs outside of
776 a glyph. Similarly to how the glyph's image specifier works, you
777 don't create your own image specifier, but rather add specifications
778 to the existing one (using `set-face-background-pixmap'). Note that
779 the image instance that is generated in order to actually display the
780 background pixmap is of type `mono-pixmap', meaning that it's a two-color
781 image and the foreground and background of the image get filled in with
782 the corresponding colors from the face.
784 It is extremely rare that you will ever have to specify a value for TYPE,
785 which should be one of `buffer' (used for glyphs in an extent, the modeline,
786 the toolbar, or elsewhere in a buffer), `pointer' (used for the mouse-pointer),
787 or `icon' (used for a frame's icon), and defaults to `buffer'. The only cases
788 where it needs to be specified is when creating icon or pointer glyphs, and
789 in both cases the necessary glyphs have already been created at startup and
790 are accessed through the appropriate variables, e.g. `text-pointer-glyph'
791 (or in general, `*-pointer-glyph') and `frame-icon-glyph'."
792 (let ((glyph (make-glyph-internal type)))
793 (and spec-list (set-glyph-image glyph spec-list))
796 (defun buffer-glyph-p (object)
797 "Return t if OBJECT is a glyph of type `buffer'."
798 (and (glyphp object) (eq 'buffer (glyph-type object))))
800 (defun pointer-glyph-p (object)
801 "Return t if OBJECT is a glyph of type `pointer'."
802 (and (glyphp object) (eq 'pointer (glyph-type object))))
804 (defun icon-glyph-p (object)
805 "Return t if OBJECT is a glyph of type `icon'."
806 (and (glyphp object) (eq 'icon (glyph-type object))))
808 (defun make-pointer-glyph (&optional spec-list)
809 "Return a new `pointer-glyph' object with the specification list SPEC-LIST.
810 This is equivalent to calling `make-glyph', specifying a type of `pointer'.
811 See `make-glyph' for more information.
813 It is extremely unlikely that you will ever need to create a pointer glyph.
814 Instead, you probably want to be calling `set-glyph-image' on an existing
815 glyph, e.g. `text-pointer-glyph'."
816 (make-glyph spec-list 'pointer))
818 (defun make-icon-glyph (&optional spec-list)
819 "Return a new `icon-glyph' object with the specification list SPEC-LIST.
820 This is equivalent to calling `make-glyph', specifying a type of `icon'.
821 See `make-glyph' for more information.
823 It is extremely unlikely that you will ever need to create a icon glyph.
824 Instead, you probably want to be calling `set-glyph-image' on
826 (make-glyph spec-list 'icon))
828 (defun nothing-image-instance-p (object)
829 "Return t if OBJECT is an image instance of type `nothing'."
830 (and (image-instance-p object) (eq 'nothing (image-instance-type object))))
832 (defun text-image-instance-p (object)
833 "Return t if OBJECT is an image instance of type `text'."
834 (and (image-instance-p object) (eq 'text (image-instance-type object))))
836 (defun mono-pixmap-image-instance-p (object)
837 "Return t if OBJECT is an image instance of type `mono-pixmap'."
838 (and (image-instance-p object) (eq 'mono-pixmap
839 (image-instance-type object))))
841 (defun color-pixmap-image-instance-p (object)
842 "Return t if OBJECT is an image instance of type `color-pixmap'."
843 (and (image-instance-p object) (eq 'color-pixmap
844 (image-instance-type object))))
846 (defun pointer-image-instance-p (object)
847 "Return t if OBJECT is an image instance of type `pointer'."
848 (and (image-instance-p object) (eq 'pointer (image-instance-type object))))
850 (defun widget-image-instance-p (object)
851 "Return t if OBJECT is an image instance of type `widget'."
852 (and (image-instance-p object) (eq 'widget (image-instance-type object))))
854 (defun subwindow-image-instance-p (object)
855 "Return t if OBJECT is an image instance of type `subwindow'."
856 (and (image-instance-p object) (eq 'subwindow (image-instance-type object))))
858 ;;;;;;;;;; the built-in glyphs
860 (defvar text-pointer-glyph (make-pointer-glyph)
861 "*The shape of the mouse-pointer when over text.
862 This is a glyph; use `set-glyph-image' to change it.")
863 (set-glyph-face text-pointer-glyph 'pointer)
865 (defvar nontext-pointer-glyph (make-pointer-glyph)
866 "*The shape of the mouse-pointer when over a buffer, but not over text.
867 This is a glyph; use `set-glyph-image' to change it.
868 If unspecified in a particular domain, `text-pointer-glyph' is used.")
869 (set-glyph-face nontext-pointer-glyph 'pointer)
871 (defvar modeline-pointer-glyph (make-pointer-glyph)
872 "*The shape of the mouse-pointer when over the modeline.
873 This is a glyph; use `set-glyph-image' to change it.
874 If unspecified in a particular domain, `nontext-pointer-glyph' is used.")
875 (set-glyph-face modeline-pointer-glyph 'pointer)
877 (defvar selection-pointer-glyph (make-pointer-glyph)
878 "*The shape of the mouse-pointer when over a selectable text region.
879 This is a glyph; use `set-glyph-image' to change it.
880 If unspecified in a particular domain, `text-pointer-glyph' is used.")
881 (set-glyph-face selection-pointer-glyph 'pointer)
883 (defvar busy-pointer-glyph (make-pointer-glyph)
884 "*The shape of the mouse-pointer when XEmacs is busy.
885 This is a glyph; use `set-glyph-image' to change it.
886 If unspecified in a particular domain, the pointer is not changed
887 when XEmacs is busy.")
888 (set-glyph-face busy-pointer-glyph 'pointer)
890 (defvar toolbar-pointer-glyph (make-pointer-glyph)
891 "*The shape of the mouse-pointer when over a toolbar.
892 This is a glyph; use `set-glyph-image' to change it.
893 If unspecified in a particular domain, `nontext-pointer-glyph' is used.")
894 (set-glyph-face toolbar-pointer-glyph 'pointer)
896 (defvar divider-pointer-glyph (make-pointer-glyph)
897 "*The shape of the mouse-pointer when over a window divider.
898 This is a glyph; use `set-glyph-image' to change it.
899 If unspecified in a particular domain, `nontext-pointer-glyph' is used.")
900 (set-glyph-face divider-pointer-glyph 'pointer)
902 ;; The following three are in C.
903 (if (featurep 'menubar)
904 (set-glyph-face menubar-pointer-glyph 'pointer))
905 (if (featurep 'scrollbar)
906 (set-glyph-face scrollbar-pointer-glyph 'pointer))
907 (set-glyph-face gc-pointer-glyph 'pointer)
909 ;; Now add the magic access/set behavior.
911 (defun dontusethis-set-value-glyph-handler (sym args fun harg handler)
912 (error "Use `set-glyph-image' to set `%s'" sym))
913 (defun dontusethis-make-unbound-glyph-handler (sym args fun harg handler)
914 (error "Can't `makunbound' `%s'" sym))
915 (defun dontusethis-make-local-glyph-handler (sym args fun harg handler)
916 (error "Use `set-glyph-image' to make local values for `%s'" sym))
918 (defun define-constant-glyph (sym)
919 (dontusethis-set-symbol-value-handler
921 'dontusethis-set-value-glyph-handler)
922 (dontusethis-set-symbol-value-handler
924 'dontusethis-make-unbound-glyph-handler)
925 (dontusethis-set-symbol-value-handler
927 'dontusethis-make-local-glyph-handler)
928 ;; Make frame properties magically work with glyph variables.
929 (put sym 'const-glyph-variable t))
931 (define-constant-glyph 'text-pointer-glyph)
932 (define-constant-glyph 'nontext-pointer-glyph)
933 (define-constant-glyph 'modeline-pointer-glyph)
934 (define-constant-glyph 'selection-pointer-glyph)
935 (define-constant-glyph 'busy-pointer-glyph)
936 (define-constant-glyph 'gc-pointer-glyph)
937 (define-constant-glyph 'divider-pointer-glyph)
938 (define-constant-glyph 'toolbar-pointer-glyph)
939 (define-constant-glyph 'menubar-pointer-glyph)
940 (define-constant-glyph 'scrollbar-pointer-glyph)
942 (define-constant-glyph 'octal-escape-glyph)
943 (define-constant-glyph 'control-arrow-glyph)
944 (define-constant-glyph 'invisible-text-glyph)
945 (define-constant-glyph 'hscroll-glyph)
946 (define-constant-glyph 'truncation-glyph)
947 (define-constant-glyph 'continuation-glyph)
949 (define-constant-glyph 'frame-icon-glyph)
951 ;; backwards compatibility garbage
953 (defun dontusethis-old-pointer-shape-handler (sym args fun harg handler)
954 (let ((value (car args)))
956 (remove-specifier harg 'global)
957 (set-glyph-image (symbol-value harg) value))))
959 ;; It might or might not be garbage, but it's rude. Make these
960 ;; 'compatible instead of 'obsolete. -slb
961 (defun define-obsolete-pointer-glyph (old new)
962 (define-compatible-variable-alias old new)
963 (dontusethis-set-symbol-value-handler
964 old 'set-value 'dontusethis-old-pointer-shape-handler new))
966 ;;; (defvar x-pointer-shape nil)
967 (define-obsolete-pointer-glyph 'x-pointer-shape 'text-pointer-glyph)
969 ;;; (defvar x-nontext-pointer-shape nil)
970 (define-obsolete-pointer-glyph 'x-nontext-pointer-shape 'nontext-pointer-glyph)
972 ;;; (defvar x-mode-pointer-shape nil)
973 (define-obsolete-pointer-glyph 'x-mode-pointer-shape 'modeline-pointer-glyph)
975 ;;; (defvar x-selection-pointer-shape nil)
976 (define-obsolete-pointer-glyph 'x-selection-pointer-shape
977 'selection-pointer-glyph)
979 ;;; (defvar x-busy-pointer-shape nil)
980 (define-obsolete-pointer-glyph 'x-busy-pointer-shape 'busy-pointer-glyph)
982 ;;; (defvar x-gc-pointer-shape nil)
983 (define-obsolete-pointer-glyph 'x-gc-pointer-shape 'gc-pointer-glyph)
985 ;;; (defvar x-toolbar-pointer-shape nil)
986 (define-obsolete-pointer-glyph 'x-toolbar-pointer-shape 'toolbar-pointer-glyph)
989 (defalias 'subwindow-xid 'image-instance-subwindow-id)
990 (defalias 'subwindow-width 'image-instance-width)
991 (defalias 'subwindow-height 'image-instance-height)
992 ;;;;;;;;;; initialization
994 (defun init-glyphs ()
995 ;; initialize default image types
997 (set-console-type-image-conversion-list 'x
998 `(,@(if (featurep 'xpm) '((#r"\.xpm\'" [xpm :file nil] 2)))
999 (#r"\.xbm\'" [xbm :file nil] 2)
1000 ,@(if (featurep 'xpm) '((#r"\`/\* XPM \*/" [xpm :data nil] 2)))
1001 ,@(if (featurep 'xface) '(("\\`X-Face:" [xface :data nil] 2)))
1002 ,@(if (featurep 'gif) '((#r"\.gif\'" [gif :file nil] 2)
1003 ("\\`GIF8[79]" [gif :data nil] 2)))
1004 ,@(if (featurep 'jpeg) '((#r"\.jpe?g\'" [jpeg :file nil] 2)))
1005 ;; all of the JFIF-format JPEG's that I've seen begin with
1006 ;; the following. I have no idea if this is standard.
1007 ,@(if (featurep 'jpeg) '(("\\`\377\330\377\340\000\020JFIF"
1008 [jpeg :data nil] 2)))
1009 ,@(if (featurep 'png) '((#r"\.png\'" [png :file nil] 2)))
1010 ,@(if (featurep 'png) '(("\\`\211PNG" [png :data nil] 2)))
1011 ("" [string :data nil] 2)
1013 ;; #### this should really be formatted-string, not string but we
1014 ;; don't have it implemented yet
1016 ;; #define could also mean a bitmap as well as a version 1 XPM. Who
1017 ;; cares. We don't want the file contents getting converted to a
1018 ;; string in either case which is why the entry is there.
1021 (set-console-type-image-conversion-list
1023 '(("^#define" [string :data "[xpm]"])
1024 ("\\`X-Face:" [string :data "[xface]"])
1025 (#r"\`/\* XPM \*/" [string :data "[xpm]"])
1026 ("\\`GIF87" [string :data "[gif]"])
1027 ("\\`\377\330\340\000\020JFIF" [string :data "[jpeg]"])
1028 ("" [string :data nil] 2)
1029 ;; this last one is here for pointers and icons and such --
1030 ;; strings are not allowed so they will be ignored.
1033 ;; finish initializing truncation glyph -- created internally
1034 ;; because it has a built-in bitmap
1035 (set-glyph-image truncation-glyph "$" 'global 'tty)
1037 ;; finish initializing continuation glyph -- created internally
1038 ;; because it has a built-in bitmap
1039 (set-glyph-image continuation-glyph "\\" 'global 'tty)
1041 ;; finish initializing hscroll glyph -- created internally
1042 ;; because it has a built-in bitmap
1043 (set-glyph-image hscroll-glyph "$" 'global 'tty)))
1045 (set-glyph-image octal-escape-glyph "\\")
1046 (set-glyph-image control-arrow-glyph "^")
1047 (set-glyph-image invisible-text-glyph " ...")
1048 ;; (set-glyph-image hscroll-glyph "$")
1050 (let ((face (make-face 'border-glyph
1051 "Truncation and continuation glyphs face")))
1052 (set-glyph-face continuation-glyph face)
1053 (set-glyph-face truncation-glyph face)
1054 (set-glyph-face hscroll-glyph face))
1056 ;; finish initializing sxemacs logo -- created internally because it
1057 ;; has a built-in bitmap
1059 (if (getenv "SOURCE_TREE_ROOT")
1060 (expand-file-name "etc/" (getenv "SOURCE_TREE_ROOT"))
1061 (expand-file-name "etc/" ".."))))
1064 (princ (format "tempetc: %s\n" temp-etcdir)
1065 'external-debugging-output))
1068 (set-glyph-image sxemacs-logo
1070 (if emacs-beta-version
1072 "sxemacs.xpm") temp-etcdir)
1074 (cond ((featurep 'xpm)
1075 (set-glyph-image frame-icon-glyph
1076 (expand-file-name "sxemacs-icon.xpm" temp-etcdir)
1079 (set-glyph-image frame-icon-glyph
1080 (expand-file-name "xemacs-icon2.xbm" temp-etcdir)
1084 (set-glyph-image sxemacs-logo
1085 "SXEmacs <insert spiffy graphic logo here>"
1090 ;;; glyphs.el ends here.