+(defcustom mime-use-widget nil
+ "If t, use widget to display buttons."
+ :group 'mime
+ :type 'boolean)
+
+(defun mime-create-widget-button (string function)
+ "Display STRING as a widget button with the callback FUNCTION.
+Under XEmacs, the function `mime-create-xpm-button' might be identical
+to the function `mime-create-widget-button' if the feature `xpm' is not
+provided or the TTY frame is used."
+ (let ((start (point)))
+ (widget-create
+ 'push-button
+ :action `(lambda (widget &optional event) (,function))
+ :mouse-down-action `(lambda (widget event)
+ (let (buf point)
+ (save-window-excursion
+ (mouse-set-point event)
+ (setq buf (current-buffer)
+ point (point)))
+ (save-excursion
+ (set-buffer buf)
+ (goto-char point)
+ (,function))))
+ string)
+ ;; #### ???
+;; (static-when (featurep 'xemacs)
+;; (let ((end (point))
+;; extent)
+;; (insert "[" string "]")
+;; (while (setq extent (extent-at start nil nil extent))
+;; (set-extent-endpoints extent end (point)))
+;; (delete-region start end))))
+ (add-text-properties start (point)
+ (list 'start-open t
+ 'mime-button t)))
+ (insert "\n"))
+
+(static-when (featurep 'xemacs)
+ (defcustom mime-xpm-button-shadow-thickness 3
+ "A number of pixels should be used for the shadows on the edges of
+the buttons."
+ :group 'mime
+ :type 'integer)
+
+ (defcustom mime-xpm-button-foreground "Yellow"
+ "A color used to display the text."
+ :group 'mime
+ :type 'string)
+
+ (defcustom mime-xpm-button-background "#a0a0d0"
+ "A background color the text will be displayed upon."
+ :group 'mime
+ :type 'string)
+
+ (defvar mime-xpm-button-glyph-cache nil)
+
+ ;; #### device-on-widow-system-p must be checked at run-time.
+ (if (and (featurep 'xpm) (device-on-window-system-p))
+ (defun mime-create-xpm-button (string function)
+ "Display STRING as a XPM button with the callback FUNCTION.
+It might be identical to the function `mime-create-widget-button'
+if the feature `xpm' is not provided or the TTY frame is used."
+ (set-extent-properties (make-extent (point)
+ (progn
+ (insert "[" string "]")
+ (point)))
+ '(invisible t intangible t))
+ (let* ((spec (list string
+ mime-xpm-button-shadow-thickness
+ mime-xpm-button-foreground
+ mime-xpm-button-background))
+ (button (cdr (assoc spec mime-xpm-button-glyph-cache))))
+ (or button
+ (set-alist 'mime-xpm-button-glyph-cache spec
+ (setq button (apply (function xpm-button-create)
+ spec))))
+ (let* ((extent (make-extent (point) (point)))
+ (down-glyph (make-glyph (car (cdr button))))
+ (up-glyph (make-glyph (car button)))
+ (down-func `(lambda (event)
+ (interactive "e")
+ (set-extent-begin-glyph ,extent ,down-glyph)))
+ (up-func `(lambda (event)
+ (interactive "e")
+ (mouse-set-point event)
+ (set-extent-begin-glyph ,extent ,up-glyph)
+ (,function)))
+ (keymap (make-sparse-keymap)))
+ (define-key keymap 'button1 down-func)
+ (define-key keymap 'button2 down-func)
+ (define-key keymap 'button1up up-func)
+ (define-key keymap 'button2up up-func)
+ (set-extent-begin-glyph extent up-glyph)
+ (set-extent-property extent 'keymap keymap))
+ (insert "\n")))
+ (fset 'mime-create-xpm-button 'mime-create-widget-button)))
+
+(defcustom mime-create-button-function 'mime-create-widget-button
+ "A function called to create the content button."
+ :group 'mime
+ :type (list
+ 'cons
+ :convert-widget
+ (function
+ (lambda (widget)
+ (list
+ 'radio
+ :args
+ (append
+ '((const :tag "Widget button" mime-create-widget-button))
+ (static-when (featurep 'xemacs)
+ '((const :tag "Xpm button" mime-create-xpm-button)))
+ '((function :tag "Other"))))))))
+