+;;; Glyphs.
+
+(defcustom widget-glyph-directory (concat data-directory "custom/")
+ "Where widget glyphs are located.
+If this variable is nil, widget will try to locate the directory
+automatically. This does not work yet."
+ :group 'widgets
+ :type 'directory)
+
+(defcustom widget-glyph-enable t
+ "If non nil, use glyphs in images when available."
+ :group 'widgets
+ :type 'boolean)
+
+(defun widget-glyph-insert (widget tag image)
+ "In WIDGET, insert the text TAG or, if supported, IMAGE.
+IMAGE should be a name sans extension of an xpm or xbm file located in
+`widget-glyph-directory'"
+ (if (and (string-match "XEmacs" emacs-version)
+ widget-glyph-enable
+ (fboundp 'make-glyph)
+ image)
+ (let ((file (concat widget-glyph-directory
+ (if (string-match "/\\'" widget-glyph-directory)
+ ""
+ "/")
+ image
+ (if (featurep 'xpm) ".xpm" ".xbm"))))
+ (if (file-readable-p file)
+ (widget-glyph-insert-glyph widget tag (make-glyph file))
+ ;; File not readable, give up.
+ (insert tag)))
+ ;; We don't want or can't use glyphs.
+ (insert tag)))
+
+(defun widget-glyph-insert-glyph (widget tag glyph)
+ "In WIDGET, with alternative text TAG, insert GLYPH."
+ (set-glyph-image glyph (cons 'tty tag))
+ (set-glyph-property glyph 'widget widget)
+ (insert "*")
+ (add-text-properties (1- (point)) (point)
+ (list 'invisible t
+ 'end-glyph glyph)))
+